* [PATCH v2 1/6] clk: renesas: rcar-gen3: Add Z clock divider support
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
@ 2017-08-21 13:01 ` Simon Horman
2017-08-24 12:46 ` Geert Uytterhoeven
2017-08-21 13:01 ` [PATCH v2 2/6] clk: renesas: rcar-gen3: Add Z2 " Simon Horman
` (5 subsequent siblings)
6 siblings, 1 reply; 16+ messages in thread
From: Simon Horman @ 2017-08-21 13:01 UTC (permalink / raw)
To: linux-arm-kernel
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>
[simon: divide parent by 2; use bitops macros]
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
v1 [Simon Horman]
* Divide parent clock by 2 to give correct rate
* Use GENMASK, FIELD_{GET,PREP}
* Correct whitespace
* Arrange local variables in reverse christmas tree order
v0 [Takeshi Kihara]
---
drivers/clk/renesas/rcar-gen3-cpg.c | 138 ++++++++++++++++++++++++++++++++++++
drivers/clk/renesas/rcar-gen3-cpg.h | 1 +
2 files changed, 139 insertions(+)
diff --git a/drivers/clk/renesas/rcar-gen3-cpg.c b/drivers/clk/renesas/rcar-gen3-cpg.c
index 951105816547..f688b5f44961 100644
--- a/drivers/clk/renesas/rcar-gen3-cpg.c
+++ b/drivers/clk/renesas/rcar-gen3-cpg.c
@@ -13,6 +13,7 @@
*/
#include <linux/bug.h>
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/device.h>
@@ -29,6 +30,139 @@
#define CPG_PLL2CR 0x002c
#define CPG_PLL4CR 0x01f4
+/* 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 ) / 2
+ * 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 GENMASK(12, 8)
+
+struct cpg_z_clk {
+ struct clk_hw hw;
+ void __iomem *reg;
+ void __iomem *kick_reg;
+};
+
+#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 long rate;
+ unsigned int mult;
+
+ mult = 32 - FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg));
+ /* There is a PLL post-divider of 1/2,
+ * thus the doubling of the divisor below.
+ */
+ rate = div_u64((u64)parent_rate * mult + 16, 32 * 2);
+ /* 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,
+ 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);
+ mult = clamp(mult, 1U, 32U);
+
+ return *parent_rate / 32 * mult;
+}
+
+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;
+ unsigned int i;
+ u32 val, kick;
+
+ 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)
+ return -EBUSY;
+
+ val = clk_readl(zclk->reg) & ~CPG_FRQCRC_ZFC_MASK;
+ val |= FIELD_PREP(CPG_FRQCRC_ZFC_MASK, 32 - mult);
+ clk_writel(val, zclk->reg);
+
+ /*
+ * Set KICK bit in FRQCRB to update hardware setting and wait for
+ * clock change completion.
+ */
+ kick = clk_readl(zclk->kick_reg);
+ kick |= CPG_FRQCRB_KICK;
+ clk_writel(kick, zclk->kick_reg);
+
+ /*
+ * 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
+ * "super" safe value.
+ */
+ for (i = 1000; i; i--) {
+ if (!(clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK))
+ return 0;
+
+ cpu_relax();
+ }
+
+ return -ETIMEDOUT;
+}
+
+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 char *name,
+ const char *parent_name,
+ void __iomem *reg)
+{
+ 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 = name;
+ init.ops = &cpg_z_clk_ops;
+ init.flags = 0;
+ init.parent_names = &parent_name;
+ init.num_parents = 1;
+
+ zclk->reg = reg + CPG_FRQCRC;
+ zclk->kick_reg = reg + CPG_FRQCRB;
+ zclk->hw.init = &init;
+
+ clk = clk_register(NULL, &zclk->hw);
+ if (IS_ERR(clk))
+ kfree(zclk);
+
+ return clk;
+}
/*
* SDn Clock
@@ -373,6 +507,10 @@ struct clk * __init rcar_gen3_cpg_clk_register(struct device *dev,
mult = 1;
break;
+ case CLK_TYPE_GEN3_Z:
+ return cpg_z_clk_register(core->name, __clk_get_name(parent),
+ base);
+
default:
return ERR_PTR(-EINVAL);
}
diff --git a/drivers/clk/renesas/rcar-gen3-cpg.h b/drivers/clk/renesas/rcar-gen3-cpg.h
index d756ef8b78eb..89da28f6f71b 100644
--- a/drivers/clk/renesas/rcar-gen3-cpg.h
+++ b/drivers/clk/renesas/rcar-gen3-cpg.h
@@ -21,6 +21,7 @@ enum rcar_gen3_clk_types {
CLK_TYPE_GEN3_SD,
CLK_TYPE_GEN3_R,
CLK_TYPE_GEN3_PE,
+ CLK_TYPE_GEN3_Z,
};
#define DEF_GEN3_SD(_name, _id, _parent, _offset) \
--
2.1.4
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 1/6] clk: renesas: rcar-gen3: Add Z clock divider support
2017-08-21 13:01 ` [PATCH v2 1/6] clk: renesas: rcar-gen3: Add Z clock divider support Simon Horman
@ 2017-08-24 12:46 ` Geert Uytterhoeven
0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 12:46 UTC (permalink / raw)
To: linux-arm-kernel
Hi Simon,
On Mon, Aug 21, 2017 at 3:01 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>
> [simon: divide parent by 2; use bitops macros]
> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Thanks for this patch!
> --- a/drivers/clk/renesas/rcar-gen3-cpg.c
> +++ b/drivers/clk/renesas/rcar-gen3-cpg.c
> @@ -13,6 +13,7 @@
> */
>
> #include <linux/bug.h>
> +#include <linux/bitfield.h>
> #include <linux/clk.h>
> #include <linux/clk-provider.h>
> #include <linux/device.h>
> @@ -29,6 +30,139 @@
> #define CPG_PLL2CR 0x002c
> #define CPG_PLL4CR 0x01f4
>
> +/* Z Clock
/*
* 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 ) / 2
> + * 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 GENMASK(12, 8)
> +
> +struct cpg_z_clk {
> + struct clk_hw hw;
> + void __iomem *reg;
> + void __iomem *kick_reg;
> +};
> +
> +#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 long rate;
> + unsigned int mult;
> +
> + mult = 32 - FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg));
> + /* There is a PLL post-divider of 1/2,
/*
* There is a PLL post-divider of 1/2,
> + * thus the doubling of the divisor below.
> + */
> + rate = div_u64((u64)parent_rate * mult + 16, 32 * 2);
DIV_ROUND_CLOSEST_ULL()
> + /* Round to closest value at 100MHz unit */
> + rate = 100000000 * DIV_ROUND_CLOSEST(rate, 100000000);
Why?
With this rounding, we can no longer distinguish between e.g.
1218750000 and 1265625000 Hz.
> +
> + 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;
Can this really happen?
> +
> + mult = div_u64((u64)rate * 32 + prate/2, prate);
mult = DIV_ROUND_CLOSEST_ULL(rate * 32ULL, prate);
> + mult = clamp(mult, 1U, 32U);
> +
> + return *parent_rate / 32 * mult;
To avoid losing precision, you should do the multiplication first, using
64-bit math.
> +}
> +
> +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;
> + unsigned int i;
> + u32 val, kick;
> +
> + mult = div_u64((u64)rate * 32 + parent_rate/2, parent_rate);
DIV_ROUND_CLOSEST_ULL()
> + /*
> + * 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 ;-)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 2/6] clk: renesas: rcar-gen3: Add Z2 clock divider support
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
2017-08-21 13:01 ` [PATCH v2 1/6] clk: renesas: rcar-gen3: Add Z clock divider support Simon Horman
@ 2017-08-21 13:01 ` Simon Horman
2017-08-24 13:16 ` Geert Uytterhoeven
2017-08-21 13:01 ` [PATCH v2 3/6] clk: renesas: r8a7795: Add Z clock Simon Horman
` (4 subsequent siblings)
6 siblings, 1 reply; 16+ messages in thread
From: Simon Horman @ 2017-08-21 13:01 UTC (permalink / raw)
To: linux-arm-kernel
From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
This patch adds Z2 clock divider support for R-Car Gen3 SoC.
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
[simon: add recalc_rate() helper; use bitops macros]
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
v1 [Simon Horman]
* Provide __cpg_z_clk_recalc_rate() helper
* Use GENMASK
v0 [Takeshi Kihara]
---
drivers/clk/renesas/rcar-gen3-cpg.c | 76 ++++++++++++++++++++++++++++++++++---
drivers/clk/renesas/rcar-gen3-cpg.h | 1 +
2 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/renesas/rcar-gen3-cpg.c b/drivers/clk/renesas/rcar-gen3-cpg.c
index f688b5f44961..8f44cbf895fb 100644
--- a/drivers/clk/renesas/rcar-gen3-cpg.c
+++ b/drivers/clk/renesas/rcar-gen3-cpg.c
@@ -30,7 +30,7 @@
#define CPG_PLL2CR 0x002c
#define CPG_PLL4CR 0x01f4
-/* Z Clock
+/* Z Clock & Z2 Clock
*
* Traits of this clock:
* prepare - clk_prepare only ensures that parents are prepared
@@ -42,6 +42,7 @@
#define CPG_FRQCRB_KICK BIT(31)
#define CPG_FRQCRC 0x000000e0
#define CPG_FRQCRC_ZFC_MASK GENMASK(12, 8)
+#define CPG_FRQCRC_Z2FC_MASK GENMASK(4, 0)
struct cpg_z_clk {
struct clk_hw hw;
@@ -51,14 +52,13 @@ struct cpg_z_clk {
#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)
+static unsigned long __cpg_z_clk_recalc_rate(unsigned long parent_rate,
+ unsigned int val)
{
- struct cpg_z_clk *zclk = to_z_clk(hw);
unsigned long rate;
unsigned int mult;
- mult = 32 - FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg));
+ mult = 32 - val;
/* There is a PLL post-divider of 1/2,
* thus the doubling of the divisor below.
*/
@@ -69,6 +69,26 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
return rate;
}
+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 val;
+
+ val = FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg));
+ return __cpg_z_clk_recalc_rate(parent_rate, val);
+}
+
+static unsigned long cpg_z2_clk_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+ struct cpg_z_clk *zclk = to_z_clk(hw);
+ unsigned int val;
+
+ val = FIELD_GET(CPG_FRQCRC_Z2FC_MASK, clk_readl(zclk->reg));
+ return __cpg_z_clk_recalc_rate(parent_rate, val);
+}
+
static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
unsigned long *parent_rate)
{
@@ -129,12 +149,25 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
return -ETIMEDOUT;
}
+static int cpg_z2_clk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+ pr_info("Do not support Z2 clock changing\n");
+ return 0;
+}
+
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 const struct clk_ops cpg_z2_clk_ops = {
+ .recalc_rate = cpg_z2_clk_recalc_rate,
+ .round_rate = cpg_z_clk_round_rate,
+ .set_rate = cpg_z2_clk_set_rate,
+};
+
static struct clk * __init cpg_z_clk_register(const char *name,
const char *parent_name,
void __iomem *reg)
@@ -164,6 +197,35 @@ static struct clk * __init cpg_z_clk_register(const char *name,
return clk;
}
+static struct clk * __init cpg_z2_clk_register(const char *name,
+ const char *parent_name,
+ void __iomem *reg)
+{
+ 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 = name;
+ init.ops = &cpg_z2_clk_ops;
+ init.flags = 0;
+ init.parent_names = &parent_name;
+ init.num_parents = 1;
+
+ zclk->reg = reg + CPG_FRQCRC;
+ zclk->kick_reg = reg + CPG_FRQCRB;
+ zclk->hw.init = &init;
+
+ clk = clk_register(NULL, &zclk->hw);
+ if (IS_ERR(clk))
+ kfree(zclk);
+
+ return clk;
+}
+
/*
* SDn Clock
*/
@@ -511,6 +573,10 @@ struct clk * __init rcar_gen3_cpg_clk_register(struct device *dev,
return cpg_z_clk_register(core->name, __clk_get_name(parent),
base);
+ case CLK_TYPE_GEN3_Z2:
+ return cpg_z2_clk_register(core->name, __clk_get_name(parent),
+ base);
+
default:
return ERR_PTR(-EINVAL);
}
diff --git a/drivers/clk/renesas/rcar-gen3-cpg.h b/drivers/clk/renesas/rcar-gen3-cpg.h
index 89da28f6f71b..c03fd498c96b 100644
--- a/drivers/clk/renesas/rcar-gen3-cpg.h
+++ b/drivers/clk/renesas/rcar-gen3-cpg.h
@@ -22,6 +22,7 @@ enum rcar_gen3_clk_types {
CLK_TYPE_GEN3_R,
CLK_TYPE_GEN3_PE,
CLK_TYPE_GEN3_Z,
+ CLK_TYPE_GEN3_Z2,
};
#define DEF_GEN3_SD(_name, _id, _parent, _offset) \
--
2.1.4
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 2/6] clk: renesas: rcar-gen3: Add Z2 clock divider support
2017-08-21 13:01 ` [PATCH v2 2/6] clk: renesas: rcar-gen3: Add Z2 " Simon Horman
@ 2017-08-24 13:16 ` Geert Uytterhoeven
0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 13:16 UTC (permalink / raw)
To: linux-arm-kernel
Hi Simon,
On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
<horms+renesas@verge.net.au> wrote:
> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>
> This patch adds Z2 clock divider support for R-Car Gen3 SoC.
>
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> [simon: add recalc_rate() helper; use bitops macros]
> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Thanks for this patch!
> --- a/drivers/clk/renesas/rcar-gen3-cpg.c
> +++ b/drivers/clk/renesas/rcar-gen3-cpg.c
> @@ -69,6 +69,26 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
> return rate;
> }
>
> +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 val;
> +
> + val = FIELD_GET(CPG_FRQCRC_ZFC_MASK, clk_readl(zclk->reg));
> + return __cpg_z_clk_recalc_rate(parent_rate, val);
> +}
> +
> +static unsigned long cpg_z2_clk_recalc_rate(struct clk_hw *hw,
> + unsigned long parent_rate)
> +{
> + struct cpg_z_clk *zclk = to_z_clk(hw);
> + unsigned int val;
> +
> + val = FIELD_GET(CPG_FRQCRC_Z2FC_MASK, clk_readl(zclk->reg));
> + return __cpg_z_clk_recalc_rate(parent_rate, val);
> +}
> +
> static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
> unsigned long *parent_rate)
> {
> @@ -129,12 +149,25 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
> return -ETIMEDOUT;
> }
>
> +static int cpg_z2_clk_set_rate(struct clk_hw *hw, unsigned long rate,
> + unsigned long parent_rate)
> +{
> + pr_info("Do not support Z2 clock changing\n");
Oops?
This can be handled like the Z clock, can't it?
If not, please ignore some of my comments below.
> + return 0;
> +}
> +
> 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 const struct clk_ops cpg_z2_clk_ops = {
> + .recalc_rate = cpg_z2_clk_recalc_rate,
> + .round_rate = cpg_z_clk_round_rate,
> + .set_rate = cpg_z2_clk_set_rate,
> +};
Apart from the field mask, above ops are identical.
What about storing the field mask in struct cpg_z_clk instead, so the ops
can be unified?
They can even be reused for the ZR (Cortex-R7) clock, which uses yet
another field mask in the same register.
The field mask can be obtained from the r8a7795_core_clks[] table,
cfr. the offset for SD clocks used by DEF_GEN3_SD().
With a new DEF_GEN3_Z() macro, we can use a single CLK_TYPE_GEN3_Z
type for all 3 clocks.
> @@ -164,6 +197,35 @@ static struct clk * __init cpg_z_clk_register(const char *name,
> return clk;
> }
>
> +static struct clk * __init cpg_z2_clk_register(const char *name,
> + const char *parent_name,
> + void __iomem *reg)
> +{
> + init.ops = &cpg_z2_clk_ops;
This is the only difference in this function, compared to cpg_z_clk_register()
(assumed you pass the field mask to this function).
> + zclk->reg = reg + CPG_FRQCRC;
> + zclk->kick_reg = reg + CPG_FRQCRB;
Given the same registers are used for Z and Z2 (and ZR), what about just
storing the base address (reg) here?
And the field mask, of course.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 3/6] clk: renesas: r8a7795: Add Z clock
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
2017-08-21 13:01 ` [PATCH v2 1/6] clk: renesas: rcar-gen3: Add Z clock divider support Simon Horman
2017-08-21 13:01 ` [PATCH v2 2/6] clk: renesas: rcar-gen3: Add Z2 " Simon Horman
@ 2017-08-21 13:01 ` Simon Horman
2017-08-24 11:49 ` Geert Uytterhoeven
2017-08-21 13:01 ` [PATCH v2 4/6] clk: renesas: r8a7795: Add Z2 clock Simon Horman
` (3 subsequent siblings)
6 siblings, 1 reply; 16+ messages in thread
From: Simon Horman @ 2017-08-21 13:01 UTC (permalink / raw)
To: linux-arm-kernel
From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
This patch adds Z clock for R8A7795 SoC.
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
drivers/clk/renesas/r8a7795-cpg-mssr.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/renesas/r8a7795-cpg-mssr.c b/drivers/clk/renesas/r8a7795-cpg-mssr.c
index 762b2f8824f1..2a0546fd47dc 100644
--- a/drivers/clk/renesas/r8a7795-cpg-mssr.c
+++ b/drivers/clk/renesas/r8a7795-cpg-mssr.c
@@ -74,6 +74,7 @@ static struct cpg_core_clk r8a7795_core_clks[] __initdata = {
DEF_FIXED(".sdsrc", CLK_SDSRC, CLK_PLL1_DIV2, 2, 1),
/* Core Clock Outputs */
+ DEF_BASE("z", R8A7795_CLK_Z, CLK_TYPE_GEN3_Z, CLK_PLL0),
DEF_FIXED("ztr", R8A7795_CLK_ZTR, CLK_PLL1_DIV2, 6, 1),
DEF_FIXED("ztrd2", R8A7795_CLK_ZTRD2, CLK_PLL1_DIV2, 12, 1),
DEF_FIXED("zt", R8A7795_CLK_ZT, CLK_PLL1_DIV2, 4, 1),
--
2.1.4
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 3/6] clk: renesas: r8a7795: Add Z clock
2017-08-21 13:01 ` [PATCH v2 3/6] clk: renesas: r8a7795: Add Z clock Simon Horman
@ 2017-08-24 11:49 ` Geert Uytterhoeven
0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 11:49 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
<horms+renesas@verge.net.au> wrote:
> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>
> This patch adds Z clock for R8A7795 SoC.
>
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
(queue up pending acceptance of patch 1/6)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 4/6] clk: renesas: r8a7795: Add Z2 clock
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
` (2 preceding siblings ...)
2017-08-21 13:01 ` [PATCH v2 3/6] clk: renesas: r8a7795: Add Z clock Simon Horman
@ 2017-08-21 13:01 ` Simon Horman
2017-08-24 11:50 ` Geert Uytterhoeven
2017-08-21 13:01 ` [PATCH v2 5/6] clk: renesas: r8a7796: Add Z clock Simon Horman
` (2 subsequent siblings)
6 siblings, 1 reply; 16+ messages in thread
From: Simon Horman @ 2017-08-21 13:01 UTC (permalink / raw)
To: linux-arm-kernel
From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
This patch adds Z2 clock for r8a7795 SoC.
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
---
drivers/clk/renesas/r8a7795-cpg-mssr.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/renesas/r8a7795-cpg-mssr.c b/drivers/clk/renesas/r8a7795-cpg-mssr.c
index 2a0546fd47dc..1c931d8ec0cc 100644
--- a/drivers/clk/renesas/r8a7795-cpg-mssr.c
+++ b/drivers/clk/renesas/r8a7795-cpg-mssr.c
@@ -75,6 +75,7 @@ static struct cpg_core_clk r8a7795_core_clks[] __initdata = {
/* Core Clock Outputs */
DEF_BASE("z", R8A7795_CLK_Z, CLK_TYPE_GEN3_Z, CLK_PLL0),
+ DEF_BASE("z2", R8A7795_CLK_Z2, CLK_TYPE_GEN3_Z2, CLK_PLL2),
DEF_FIXED("ztr", R8A7795_CLK_ZTR, CLK_PLL1_DIV2, 6, 1),
DEF_FIXED("ztrd2", R8A7795_CLK_ZTRD2, CLK_PLL1_DIV2, 12, 1),
DEF_FIXED("zt", R8A7795_CLK_ZT, CLK_PLL1_DIV2, 4, 1),
--
2.1.4
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 4/6] clk: renesas: r8a7795: Add Z2 clock
2017-08-21 13:01 ` [PATCH v2 4/6] clk: renesas: r8a7795: Add Z2 clock Simon Horman
@ 2017-08-24 11:50 ` Geert Uytterhoeven
0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 11:50 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
<horms+renesas@verge.net.au> wrote:
> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>
> This patch adds Z2 clock for r8a7795 SoC.
>
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
(queue up pending acceptance of patch 2/6)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 5/6] clk: renesas: r8a7796: Add Z clock
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
` (3 preceding siblings ...)
2017-08-21 13:01 ` [PATCH v2 4/6] clk: renesas: r8a7795: Add Z2 clock Simon Horman
@ 2017-08-21 13:01 ` Simon Horman
2017-08-24 11:49 ` Geert Uytterhoeven
2017-08-21 13:01 ` [PATCH v2 6/6] clk: renesas: r8a7796: Add Z2 clock Simon Horman
2017-08-23 15:20 ` [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Geert Uytterhoeven
6 siblings, 1 reply; 16+ messages in thread
From: Simon Horman @ 2017-08-21 13:01 UTC (permalink / raw)
To: linux-arm-kernel
From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
This patch adds Z clock for R8A7796 SoC.
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
drivers/clk/renesas/r8a7796-cpg-mssr.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/renesas/r8a7796-cpg-mssr.c b/drivers/clk/renesas/r8a7796-cpg-mssr.c
index e5e7fb212288..e8d5e75afc65 100644
--- a/drivers/clk/renesas/r8a7796-cpg-mssr.c
+++ b/drivers/clk/renesas/r8a7796-cpg-mssr.c
@@ -74,6 +74,7 @@ static const struct cpg_core_clk r8a7796_core_clks[] __initconst = {
DEF_FIXED(".sdsrc", CLK_SDSRC, CLK_PLL1_DIV2, 2, 1),
/* Core Clock Outputs */
+ DEF_BASE("z", R8A7796_CLK_Z, CLK_TYPE_GEN3_Z, CLK_PLL0),
DEF_FIXED("ztr", R8A7796_CLK_ZTR, CLK_PLL1_DIV2, 6, 1),
DEF_FIXED("ztrd2", R8A7796_CLK_ZTRD2, CLK_PLL1_DIV2, 12, 1),
DEF_FIXED("zt", R8A7796_CLK_ZT, CLK_PLL1_DIV2, 4, 1),
--
2.1.4
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 5/6] clk: renesas: r8a7796: Add Z clock
2017-08-21 13:01 ` [PATCH v2 5/6] clk: renesas: r8a7796: Add Z clock Simon Horman
@ 2017-08-24 11:49 ` Geert Uytterhoeven
0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 11:49 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
<horms+renesas@verge.net.au> wrote:
> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>
> This patch adds Z clock for R8A7796 SoC.
>
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
(queue up pending acceptance of patch 1/6)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 6/6] clk: renesas: r8a7796: Add Z2 clock
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
` (4 preceding siblings ...)
2017-08-21 13:01 ` [PATCH v2 5/6] clk: renesas: r8a7796: Add Z clock Simon Horman
@ 2017-08-21 13:01 ` Simon Horman
2017-08-24 11:50 ` Geert Uytterhoeven
2017-08-23 15:20 ` [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Geert Uytterhoeven
6 siblings, 1 reply; 16+ messages in thread
From: Simon Horman @ 2017-08-21 13:01 UTC (permalink / raw)
To: linux-arm-kernel
From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
This patch adds Z2 clock for R8A7796 SoC.
Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
drivers/clk/renesas/r8a7796-cpg-mssr.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/renesas/r8a7796-cpg-mssr.c b/drivers/clk/renesas/r8a7796-cpg-mssr.c
index e8d5e75afc65..48731741b59e 100644
--- a/drivers/clk/renesas/r8a7796-cpg-mssr.c
+++ b/drivers/clk/renesas/r8a7796-cpg-mssr.c
@@ -75,6 +75,7 @@ static const struct cpg_core_clk r8a7796_core_clks[] __initconst = {
/* Core Clock Outputs */
DEF_BASE("z", R8A7796_CLK_Z, CLK_TYPE_GEN3_Z, CLK_PLL0),
+ DEF_BASE("z2", R8A7796_CLK_Z2, CLK_TYPE_GEN3_Z2, CLK_PLL2),
DEF_FIXED("ztr", R8A7796_CLK_ZTR, CLK_PLL1_DIV2, 6, 1),
DEF_FIXED("ztrd2", R8A7796_CLK_ZTRD2, CLK_PLL1_DIV2, 12, 1),
DEF_FIXED("zt", R8A7796_CLK_ZT, CLK_PLL1_DIV2, 4, 1),
--
2.1.4
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2 6/6] clk: renesas: r8a7796: Add Z2 clock
2017-08-21 13:01 ` [PATCH v2 6/6] clk: renesas: r8a7796: Add Z2 clock Simon Horman
@ 2017-08-24 11:50 ` Geert Uytterhoeven
2017-08-24 11:51 ` Geert Uytterhoeven
0 siblings, 1 reply; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 11:50 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
<horms+renesas@verge.net.au> wrote:
> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>
> This patch adds Z2 clock for R8A7796 SoC.
>
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
(queue up pending acceptance of patch 1/6)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v2 6/6] clk: renesas: r8a7796: Add Z2 clock
2017-08-24 11:50 ` Geert Uytterhoeven
@ 2017-08-24 11:51 ` Geert Uytterhoeven
0 siblings, 0 replies; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-24 11:51 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Aug 24, 2017 at 1:50 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
> <horms+renesas@verge.net.au> wrote:
>> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>>
>> This patch adds Z2 clock for R8A7796 SoC.
>>
>> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
>> Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> (queue up pending acceptance of patch 1/6)
2/6, of course.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support
2017-08-21 13:01 [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Simon Horman
` (5 preceding siblings ...)
2017-08-21 13:01 ` [PATCH v2 6/6] clk: renesas: r8a7796: Add Z2 clock Simon Horman
@ 2017-08-23 15:20 ` Geert Uytterhoeven
2017-08-24 10:12 ` Simon Horman
6 siblings, 1 reply; 16+ messages in thread
From: Geert Uytterhoeven @ 2017-08-23 15:20 UTC (permalink / raw)
To: linux-arm-kernel
Hi Simon,
On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
<horms+renesas@verge.net.au> wrote:
> this patch-set adds Z and Z2 clock support.
>
> These are dependencies for supporting CPUFreq. The remainder of that
> work is being posted separately and can be found at:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git topic/rcar-gen3-cpufreq
>
> A description of steps taken to lightly exercise the same feature for the
> r88a7795 the above can be found at the link below. The results are the same
> for the r8a7796 with the exception that it has two active CPU cores rather
> than four.
>
> http://elinux.org/Tests:R-CAR-GEN3-CPUFreq
Thanks for your patches, and the wiki page!
I gave it a try on R-Car H3 (ES1.0 and ES2.0) and M3-W (ES1.0), and the
off-by-two factor of the Z clock frequency is gone.
I couldn't test on R-Car H3 ES1.1. Probably it's OK, too (ES1.1 fixed the
missing PLL0/2/4 post-divider in ES1.0).
1. After boot-up, the CPU clock frequency is 1.5 GHz, and
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq and
/sys/kernel/debug/clk/z/clk_rate agree. Good.
2. After switching to the conservative governor, scaling_cur_freq reports
either a 500 MHz or 1 GHz clock rate.
But /sys/kernel/debug/clk/z/clk_rate disagrees: it reports either a 200
or 700 MHz clock rate.
Ah, there's also cpuinfo_cur_freq. That value matches the Z clock.
Interestingly, cpuinfo_cur_freq is lower than cpuinfo_min_freq?
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq:200000
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq:1500000
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq:500000
3. After switching back to the performance governor, scaling_cur_freq reports
1.5 GHz again.
But cpuinfo_cur_freq is still only 700 MHz, just like z/clk_rate.
Do you know what's wrong?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support
2017-08-23 15:20 ` [PATCH v2 0/6] clk: renesas: r8a779[56]: Add Z and Z2 clock support Geert Uytterhoeven
@ 2017-08-24 10:12 ` Simon Horman
0 siblings, 0 replies; 16+ messages in thread
From: Simon Horman @ 2017-08-24 10:12 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Aug 23, 2017 at 05:20:55PM +0200, Geert Uytterhoeven wrote:
> Hi Simon,
>
> On Mon, Aug 21, 2017 at 3:01 PM, Simon Horman
> <horms+renesas@verge.net.au> wrote:
> > this patch-set adds Z and Z2 clock support.
> >
> > These are dependencies for supporting CPUFreq. The remainder of that
> > work is being posted separately and can be found at:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git topic/rcar-gen3-cpufreq
> >
> > A description of steps taken to lightly exercise the same feature for the
> > r88a7795 the above can be found at the link below. The results are the same
> > for the r8a7796 with the exception that it has two active CPU cores rather
> > than four.
> >
> > http://elinux.org/Tests:R-CAR-GEN3-CPUFreq
>
> Thanks for your patches, and the wiki page!
>
> I gave it a try on R-Car H3 (ES1.0 and ES2.0) and M3-W (ES1.0), and the
> off-by-two factor of the Z clock frequency is gone.
> I couldn't test on R-Car H3 ES1.1. Probably it's OK, too (ES1.1 fixed the
> missing PLL0/2/4 post-divider in ES1.0).
>
> 1. After boot-up, the CPU clock frequency is 1.5 GHz, and
> /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq and
> /sys/kernel/debug/clk/z/clk_rate agree. Good.
>
> 2. After switching to the conservative governor, scaling_cur_freq reports
> either a 500 MHz or 1 GHz clock rate.
> But /sys/kernel/debug/clk/z/clk_rate disagrees: it reports either a 200
> or 700 MHz clock rate.
>
> Ah, there's also cpuinfo_cur_freq. That value matches the Z clock.
> Interestingly, cpuinfo_cur_freq is lower than cpuinfo_min_freq?
> /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq:200000
> /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq:1500000
> /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq:500000
>
> 3. After switching back to the performance governor, scaling_cur_freq reports
> 1.5 GHz again.
> But cpuinfo_cur_freq is still only 700 MHz, just like z/clk_rate.
>
> Do you know what's wrong?
Unfortunately not. I will look into this.
^ permalink raw reply [flat|nested] 16+ messages in thread