All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Khiem Nguyen <khiem.nguyen.xt@rvc.renesas.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Simon Horman <horms+renesas@verge.net.au>,
	Magnus Damm <damm+renesas@opensource.se>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	"linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
	"linux-renesas-soc@vger.kernel.org"
	<linux-renesas-soc@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Toru Oishi <toru.oishi.zj@rvc.renesas.com>
Subject: Re: [RFC 1/4] clk: renesas: rcar-gen3-cpg: Add Z clock
Date: Fri, 13 May 2016 10:54:03 +0200	[thread overview]
Message-ID: <CAMuHMdV-N1WNju+n3ErQVKHqiofm+0RWUx+MQZZ8qjDr-q1w3g@mail.gmail.com> (raw)
In-Reply-To: <573166A8.1030101@rvc.renesas.com>

Hi Khiem,

On Tue, May 10, 2016 at 6:42 AM, Khiem Nguyen
<khiem.nguyen.xt@rvc.renesas.com> wrote:
> Base on Dien Pham work.
>
> Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@rvc.renesas.com>

Thanks for your patch!

> ---
>  drivers/clk/renesas/rcar-gen3-cpg.c | 143
> ++++++++++++++++++++++++++++++++++++
>  drivers/clk/renesas/rcar-gen3-cpg.h |   1 +
>  2 files changed, 144 insertions(+)
>
> diff --git a/drivers/clk/renesas/rcar-gen3-cpg.c
> b/drivers/clk/renesas/rcar-gen3-cpg.c
> index bb4f2f9..45209ac 100644
> --- a/drivers/clk/renesas/rcar-gen3-cpg.c
> +++ b/drivers/clk/renesas/rcar-gen3-cpg.c
> @@ -28,6 +28,146 @@
>  #define CPG_PLL2CR             0x002c
>  #define CPG_PLL4CR             0x01f4
>
> +/** Modify for Z-clock

Please drop this comment

> + *
> -----------------------------------------------------------------------------
> + * Z Clock
> + *
> + * Traits of this clock:
> + * prepare - clk_prepare only ensures that parents are prepared
> + * enable - clk_enable only ensures that parents are enabled
> + * rate - rate is adjustable.  clk->rate = parent->rate * mult / 32
> + * parent - fixed parent.  No clk_set_parent support
> + */
> +#define CPG_FRQCRB                     0x00000004
> +#define CPG_FRQCRB_KICK                        BIT(31)
> +#define CPG_FRQCRC                     0x000000e0
> +#define CPG_FRQCRC_ZFC_MASK            (0x1f << 8)
> +#define CPG_FRQCRC_ZFC_SHIFT           8
> +
> +
> +struct cpg_z_clk {
> +       struct clk_hw hw;
> +       void __iomem *reg;
> +       void __iomem *kick_reg;

I would just store the base address, and always use "zclk->base + CPG_FRQCRB"
or "zclk->base + CPG_FRQCRC".

> +};
> +
> +#define to_z_clk(_hw)  container_of(_hw, struct cpg_z_clk, hw)
> +
> +static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
> +                                          unsigned long parent_rate)
> +{
> +       struct cpg_z_clk *zclk = to_z_clk(hw);
> +       unsigned int mult;
> +       unsigned int val;
> +       unsigned long rate;
> +
> +       val = (clk_readl(zclk->reg) & CPG_FRQCRC_ZFC_MASK)
> +           >> CPG_FRQCRC_ZFC_SHIFT;
> +       mult = 32 - val;
> +
> +       rate = div_u64((u64)parent_rate * mult + 16, 32);

The above also does rounding.

> +       /* Round to closest value at 100MHz unit */
> +       rate = 100000000*DIV_ROUND_CLOSEST(rate, 100000000);

Why rounding to the closest 100MHz unit?

> +       return rate;
> +}
> +
> +static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
> +                                unsigned long *parent_rate)
> +{
> +       unsigned long prate  = *parent_rate;
> +       unsigned int mult;
> +
> +       if (!prate)
> +               prate = 1;
> +
> +       mult = div_u64((u64)rate * 32 + prate/2, prate);

DIV_ROUND_CLOSEST_ULL()

> +       mult = clamp(mult, 1U, 32U);
> +
> +       return *parent_rate / 32 * mult;

Doing the division first reduces accuracy.
Please do the multiplication first (in 64-bit arithmetic).

> +}
> +
> +static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
> +                             unsigned long parent_rate)
> +{
> +       struct cpg_z_clk *zclk = to_z_clk(hw);
> +       unsigned int mult;
> +       u32 val, kick;
> +       unsigned int i;
> +
> +       mult = div_u64((u64)rate * 32 + parent_rate/2, parent_rate);

DIV_ROUND_CLOSEST_ULL()

> +}
> +
> +static const struct clk_ops cpg_z_clk_ops = {
> +       .recalc_rate = cpg_z_clk_recalc_rate,
> +       .round_rate = cpg_z_clk_round_rate,
> +       .set_rate = cpg_z_clk_set_rate,
> +};
> +
> +static struct clk * __init cpg_z_clk_register(const struct cpg_core_clk
> *core,
> +                                             void __iomem *base,
> +                                             const char *parent_name)
> +{
> +       struct clk_init_data init;
> +       struct cpg_z_clk *zclk;
> +       struct clk *clk;
> +
> +       zclk = kzalloc(sizeof(*zclk), GFP_KERNEL);
> +       if (!zclk)
> +               return ERR_PTR(-ENOMEM);
> +
> +       init.name = core->name;
> +       init.ops = &cpg_z_clk_ops;
> +       init.flags = CLK_SET_RATE_GATE;

#define CLK_SET_RATE_GATE       BIT(0) /* must be gated across rate change */

Given you don't implement clk_ops.disable() and clk_ops.unprepare(),
CLK_SET_RATE_GATE doesn't sound like the right flag to use.

> +       init.parent_names = &parent_name;
> +       init.num_parents = 1;
> +
> +       zclk->reg = base + CPG_FRQCRC;
> +       zclk->kick_reg = base + CPG_FRQCRB;
> +       zclk->hw.init = &init;
> +
> +       clk = clk_register(NULL, &zclk->hw);
> +       if (IS_ERR(clk))
> +               kfree(zclk);
> +
> +       return clk;
> +}
> +
> +/** End of modifying for Z-clock */

Please drop this comment

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2016-05-13  8:54 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-04 14:35 [PATCH 0/4] clk: renesas: cpg-mssr: Add support for R-Car M3-W Geert Uytterhoeven
2016-05-04 14:35 ` [PATCH 2/4] clk: renesas: Add r8a7796 CPG Core Clock Definitions Geert Uytterhoeven
     [not found] ` <1462372543-31835-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2016-05-04 14:35   ` [PATCH 1/4] clk: renesas: cpg-mssr: Document r8a7796 support Geert Uytterhoeven
2016-05-04 14:35     ` Geert Uytterhoeven
2016-05-05 22:13     ` Rob Herring
2016-05-04 14:35   ` [PATCH 3/4] clk: renesas: cpg-mssr: Extract common R-Car Gen3 support code Geert Uytterhoeven
2016-05-04 14:35     ` Geert Uytterhoeven
2016-05-04 14:35 ` [PATCH 4/4] clk: renesas: cpg-mssr: Add support for R-Car M3-W Geert Uytterhoeven
2016-05-10  4:40 ` [RFC 0/4] Add Z clock support Khiem Nguyen
2016-05-10  4:55   ` [PATCH 0/2] cpufreq: rcar: Enable CPUFreq support Khiem Nguyen
2016-05-10  4:55     ` Khiem Nguyen
2016-05-10  4:55     ` Khiem Nguyen
2016-05-10  4:57     ` [PATCH 1/2] cpufreq: rcar: Add support for R8A7795 SoC Khiem Nguyen
2016-05-10  4:57       ` Khiem Nguyen
2016-05-10  4:59       ` [PATCH 2/2] cpufreq: rcar: Add support for R8A7796 SoC Khiem Nguyen
2016-05-10  4:59         ` Khiem Nguyen
2016-05-10  5:07         ` Viresh Kumar
2016-05-10  5:07           ` Viresh Kumar
2016-05-10  5:07       ` [PATCH 1/2] cpufreq: rcar: Add support for R8A7795 SoC Viresh Kumar
2016-05-10  5:07         ` Viresh Kumar
2016-05-10  8:17         ` Geert Uytterhoeven
2016-05-10  8:17           ` Geert Uytterhoeven
2016-05-10  8:19           ` Viresh Kumar
2016-05-10  8:19             ` Viresh Kumar
2016-05-13  8:55   ` [RFC 0/4] Add Z clock support Geert Uytterhoeven
2016-05-10  4:42 ` [RFC 1/4] clk: renesas: rcar-gen3-cpg: Add Z clock Khiem Nguyen
2016-05-13  8:54   ` Geert Uytterhoeven [this message]
2016-09-23  8:32   ` Geert Uytterhoeven
2016-05-10  4:43 ` [RFC 2/4] clk: renesas: r8a7795: " Khiem Nguyen
2016-05-10  4:44   ` [RFC 3/4] clk: renesas: r8a7796: " Khiem Nguyen
2016-05-10  7:39     ` Geert Uytterhoeven
2016-05-10  4:46   ` [RFC 4/4] arm64: dts: r8a7795: Add Z clock scaling support Khiem Nguyen
2016-05-17 13:03     ` Geert Uytterhoeven
2016-05-13  8:55   ` [RFC 2/4] clk: renesas: r8a7795: Add Z clock Geert Uytterhoeven
2016-05-26  2:35 ` [PATCH 0/4] clk: renesas: cpg-mssr: Add support for R-Car M3-W Simon Horman
2016-05-26  6:55   ` Geert Uytterhoeven
2016-05-27  0:49     ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMuHMdV-N1WNju+n3ErQVKHqiofm+0RWUx+MQZZ8qjDr-q1w3g@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=damm+renesas@opensource.se \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=horms+renesas@verge.net.au \
    --cc=khiem.nguyen.xt@rvc.renesas.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@codeaurora.org \
    --cc=toru.oishi.zj@rvc.renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.