From: Simon Horman <horms@verge.net.au> To: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Linux-Renesas <linux-renesas-soc@vger.kernel.org>, "linux-arm-kernel@lists.infradead.org" <linux-arm-kernel@lists.infradead.org>, Magnus Damm <magnus.damm@gmail.com> Subject: Re: [PATCH v3 1/6] clk: renesas: rcar-gen3: Add Z clock divider support Date: Tue, 10 Oct 2017 09:23:37 +0200 [thread overview] Message-ID: <20171010072336.GH2518@verge.net.au> (raw) In-Reply-To: <CAMuHMdUKEP1BvzLBBJmARUz2PcsmwHsruumXqt+csY5gkUDmcw@mail.gmail.com> On Mon, Oct 09, 2017 at 10:02:34AM +0200, Geert Uytterhoeven wrote: > Hi Simon, > > On Thu, Oct 5, 2017 at 3:23 PM, Simon Horman <horms+renesas@verge.net.au> wrote: > > From: Takeshi Kihara <takeshi.kihara.df@renesas.com> > > > > This patch adds Z clock divider support for R-Car Gen3 SoC. > > > > Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com> > > Signed-off-by: Simon Horman <horms+renesas@verge.net.au> > > --- > > > > v2 [Simon Horman] > > * Use DIV_ROUND_CLOSEST_ULL instead of open-coding the same behaviour > > using div_u64() > > * Do not round rate to 100MHz in cpg_z_clk_recalc_rate > > * Remove calculation for PLL post-divider, this is bogus. > > Instead do not round to closest in cpg_z_clk_round_rate() > > * Drop check for !prate in cpg_z_clk_round_rate > > Thanks for the updates! > > > --- a/drivers/clk/renesas/rcar-gen3-cpg.c > > +++ b/drivers/clk/renesas/rcar-gen3-cpg.c > > > +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; > > + > > + mult = 32 - FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg)); > > + return DIV_ROUND_CLOSEST_ULL(parent_rate * mult, 32); > > While parent_rate is unsigned long and thus 64-bit on arm64, this will work > fine on R-Car Gen3. However, if someone ever tries to reuse this on a > 32-bit platform, the multiplication may overflow. > Hence I recommend to make this a 64-bit multiplication explicitly, i.e. > > return DIV_ROUND_CLOSEST_ULL((u64)parent_rate * mult, 32); Thanks, will do. > > +} > > + > > +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; > > + > > + mult = div_u64((u64)rate * 32, prate); > > You can avoid the cast by making the constant 64-bit: > > mult = div_u64(rate * 32ULL, prate); Thanks, that looks a bit nicer. > > + mult = clamp(mult, 1U, 32U); > > + > > + return *parent_rate * mult / 32; > > Again, *parent_rate is 64-bit on arm64, but not on 32-bit platforms. > > > + /* > > + * Note: There is no HW information about the worst case latency. > > + * > > + * Using experimental measurements, it seems that no more than > > + * ~10 iterations are needed, independently of the CPU rate. > > + * Since this value might be dependent of external xtal rate, pll1 > > + * rate or even the other emulation clocks rate, use 1000 as a > > another emulated clock rate? > (Yeah, copied from Gen2 ;-) It seem so. > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
WARNING: multiple messages have this Message-ID (diff)
From: horms@verge.net.au (Simon Horman) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/6] clk: renesas: rcar-gen3: Add Z clock divider support Date: Tue, 10 Oct 2017 09:23:37 +0200 [thread overview] Message-ID: <20171010072336.GH2518@verge.net.au> (raw) In-Reply-To: <CAMuHMdUKEP1BvzLBBJmARUz2PcsmwHsruumXqt+csY5gkUDmcw@mail.gmail.com> On Mon, Oct 09, 2017 at 10:02:34AM +0200, Geert Uytterhoeven wrote: > Hi Simon, > > On Thu, Oct 5, 2017 at 3:23 PM, Simon Horman <horms+renesas@verge.net.au> wrote: > > From: Takeshi Kihara <takeshi.kihara.df@renesas.com> > > > > This patch adds Z clock divider support for R-Car Gen3 SoC. > > > > Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com> > > Signed-off-by: Simon Horman <horms+renesas@verge.net.au> > > --- > > > > v2 [Simon Horman] > > * Use DIV_ROUND_CLOSEST_ULL instead of open-coding the same behaviour > > using div_u64() > > * Do not round rate to 100MHz in cpg_z_clk_recalc_rate > > * Remove calculation for PLL post-divider, this is bogus. > > Instead do not round to closest in cpg_z_clk_round_rate() > > * Drop check for !prate in cpg_z_clk_round_rate > > Thanks for the updates! > > > --- a/drivers/clk/renesas/rcar-gen3-cpg.c > > +++ b/drivers/clk/renesas/rcar-gen3-cpg.c > > > +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; > > + > > + mult = 32 - FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg)); > > + return DIV_ROUND_CLOSEST_ULL(parent_rate * mult, 32); > > While parent_rate is unsigned long and thus 64-bit on arm64, this will work > fine on R-Car Gen3. However, if someone ever tries to reuse this on a > 32-bit platform, the multiplication may overflow. > Hence I recommend to make this a 64-bit multiplication explicitly, i.e. > > return DIV_ROUND_CLOSEST_ULL((u64)parent_rate * mult, 32); Thanks, will do. > > +} > > + > > +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; > > + > > + mult = div_u64((u64)rate * 32, prate); > > You can avoid the cast by making the constant 64-bit: > > mult = div_u64(rate * 32ULL, prate); Thanks, that looks a bit nicer. > > + mult = clamp(mult, 1U, 32U); > > + > > + return *parent_rate * mult / 32; > > Again, *parent_rate is 64-bit on arm64, but not on 32-bit platforms. > > > + /* > > + * Note: There is no HW information about the worst case latency. > > + * > > + * Using experimental measurements, it seems that no more than > > + * ~10 iterations are needed, independently of the CPU rate. > > + * Since this value might be dependent of external xtal rate, pll1 > > + * rate or even the other emulation clocks rate, use 1000 as a > > another emulated clock rate? > (Yeah, copied from Gen2 ;-) It seem so. > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
next prev parent reply other threads:[~2017-10-10 7:23 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-10-05 13:23 [PATCH v3 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-05 13:23 ` [PATCH v3 1/6] clk: renesas: rcar-gen3: Add Z clock divider support Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-09 8:02 ` Geert Uytterhoeven 2017-10-09 8:02 ` Geert Uytterhoeven 2017-10-10 7:23 ` Simon Horman [this message] 2017-10-10 7:23 ` Simon Horman 2017-10-05 13:23 ` [PATCH v3 2/6] clk: renesas: rcar-gen3: Add Z2 " Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-09 8:02 ` Geert Uytterhoeven 2017-10-09 8:02 ` Geert Uytterhoeven 2017-10-10 6:56 ` Geert Uytterhoeven 2017-10-10 6:56 ` Geert Uytterhoeven 2017-10-10 7:22 ` Simon Horman 2017-10-10 7:22 ` Simon Horman 2017-10-05 13:23 ` [PATCH v3 3/6] clk: renesas: r8a7795: Add Z clock Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-05 13:23 ` [PATCH v3 4/6] clk: renesas: r8a7795: Add Z2 clock Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-05 13:23 ` [PATCH v3 5/6] clk: renesas: r8a7796: Add Z clock Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-05 13:23 ` [PATCH v3 6/6] clk: renesas: r8a7796: Add Z2 clock Simon Horman 2017-10-05 13:23 ` Simon Horman 2017-10-09 13:05 ` [PATCH v3 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Geert Uytterhoeven 2017-10-09 13:05 ` Geert Uytterhoeven
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=20171010072336.GH2518@verge.net.au \ --to=horms@verge.net.au \ --cc=geert@linux-m68k.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-renesas-soc@vger.kernel.org \ --cc=magnus.damm@gmail.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: linkBe 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.