* [PATCH/RFC 0/2] clk: renesas: r8a7795: improve z clock rate
@ 2016-08-07 17:58 Yoshihiro Kaneko
2016-08-07 17:58 ` [PATCH/RFC 1/2] clk: renesas: r8a7795: Improve the calculated value of Clock Yoshihiro Kaneko
2016-08-07 17:58 ` [PATCH/RFC 2/2] clk: renesas: r8a7795: Do rounding for calculated frequency value Yoshihiro Kaneko
0 siblings, 2 replies; 3+ messages in thread
From: Yoshihiro Kaneko @ 2016-08-07 17:58 UTC (permalink / raw)
To: linux-clk
Cc: Michael Turquette, Stephen Boyd, Geert Uytterhoeven, Simon Horman,
Magnus Damm, linux-renesas-soc
These patches improve the calculated value of Z clock.
This series is based on the clk-next branch.
Dien Pham (2):
clk: renesas: r8a7795: Improve the calculated value of Clock.
clk: renesas: r8a7795: Do rounding for calculated frequency value
drivers/clk/renesas/clk-rcar-gen2.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH/RFC 1/2] clk: renesas: r8a7795: Improve the calculated value of Clock.
2016-08-07 17:58 [PATCH/RFC 0/2] clk: renesas: r8a7795: improve z clock rate Yoshihiro Kaneko
@ 2016-08-07 17:58 ` Yoshihiro Kaneko
2016-08-07 17:58 ` [PATCH/RFC 2/2] clk: renesas: r8a7795: Do rounding for calculated frequency value Yoshihiro Kaneko
1 sibling, 0 replies; 3+ messages in thread
From: Yoshihiro Kaneko @ 2016-08-07 17:58 UTC (permalink / raw)
To: linux-clk
Cc: Michael Turquette, Stephen Boyd, Geert Uytterhoeven, Simon Horman,
Magnus Damm, linux-renesas-soc
From: Dien Pham <dien.pham.ry@rvc.renesas.com>
This patch improves the calculated value of Z Clock when odd frequency
(as 33.33 MHz) is inputted.
Signed-off-by: Dien Pham <dien.pham.ry@rvc.renesas.com>
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
---
drivers/clk/renesas/clk-rcar-gen2.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/renesas/clk-rcar-gen2.c b/drivers/clk/renesas/clk-rcar-gen2.c
index 00e6aba..7519f71 100644
--- a/drivers/clk/renesas/clk-rcar-gen2.c
+++ b/drivers/clk/renesas/clk-rcar-gen2.c
@@ -65,7 +65,8 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
>> CPG_FRQCRC_ZFC_SHIFT;
mult = 32 - val;
- return div_u64((u64)parent_rate * mult, 32);
+ /* Add 1/2 to reduce the math error that raises by math rounding */
+ return div_u64((u64)parent_rate * mult + 16, 32);
}
static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
@@ -77,7 +78,7 @@ static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
if (!prate)
prate = 1;
- mult = div_u64((u64)rate * 32, prate);
+ mult = div_u64((u64)rate * 32 + prate / 2, prate);
mult = clamp(mult, 1U, 32U);
return *parent_rate / 32 * mult;
@@ -91,7 +92,7 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
u32 val, kick;
unsigned int i;
- mult = div_u64((u64)rate * 32, parent_rate);
+ mult = div_u64((u64)rate * 32 + parent_rate / 2, parent_rate);
mult = clamp(mult, 1U, 32U);
if (clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK)
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH/RFC 2/2] clk: renesas: r8a7795: Do rounding for calculated frequency value
2016-08-07 17:58 [PATCH/RFC 0/2] clk: renesas: r8a7795: improve z clock rate Yoshihiro Kaneko
2016-08-07 17:58 ` [PATCH/RFC 1/2] clk: renesas: r8a7795: Improve the calculated value of Clock Yoshihiro Kaneko
@ 2016-08-07 17:58 ` Yoshihiro Kaneko
1 sibling, 0 replies; 3+ messages in thread
From: Yoshihiro Kaneko @ 2016-08-07 17:58 UTC (permalink / raw)
To: linux-clk
Cc: Michael Turquette, Stephen Boyd, Geert Uytterhoeven, Simon Horman,
Magnus Damm, linux-renesas-soc
From: Dien Pham <dien.pham.ry@rvc.renesas.com>
The calculation value has some errors after some calculation,
especially, when one of the input value is odd value.
This patch applies rounding to closest frequency at 100Mhz unit.
Signed-off-by: Dien Pham <dien.pham.ry@rvc.renesas.com>
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
---
drivers/clk/renesas/clk-rcar-gen2.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/renesas/clk-rcar-gen2.c b/drivers/clk/renesas/clk-rcar-gen2.c
index 7519f71..5c4dcc7 100644
--- a/drivers/clk/renesas/clk-rcar-gen2.c
+++ b/drivers/clk/renesas/clk-rcar-gen2.c
@@ -60,13 +60,16 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
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;
- /* Add 1/2 to reduce the math error that raises by math rounding */
- return div_u64((u64)parent_rate * mult + 16, 32);
+ rate = div_u64((u64)parent_rate * mult + 16, 32);
+ /* Round to closest value at 100MHz unit */
+ rate = 100000000 * DIV_ROUND_CLOSEST(rate, 100000000);
+ return rate;
}
static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-07 17:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-07 17:58 [PATCH/RFC 0/2] clk: renesas: r8a7795: improve z clock rate Yoshihiro Kaneko
2016-08-07 17:58 ` [PATCH/RFC 1/2] clk: renesas: r8a7795: Improve the calculated value of Clock Yoshihiro Kaneko
2016-08-07 17:58 ` [PATCH/RFC 2/2] clk: renesas: r8a7795: Do rounding for calculated frequency value Yoshihiro Kaneko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox