Skip to contentSkip to conversation

r8a7796 bits required for out-of-tree GSX module

PATCH In review Ulrich Hecht 3 participants 10 messages Dec 15, 2017 – Dec 19, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover r8a7796 bits required for out-of-tree GSX module

Hi!

This is a minimized set of patches required to get the PowerVR GPU driver to work on mainline (based on renesas-drivers-2017-12-12-v4.15-rc3).

I suppose the GSX-related DT entries are not upstreamable, but what about the ZG clock?

CU
Uli

Gaku Inami (1):
arm64: dts: r8a7796: Add DEVFREQ support for GSX

Takeshi Kihara (3):
clk: renesas: r8a7796: Add ZG clock
clk: renesas: rcar-gen3: Add ZG clock divider support
arm64: dts: r8a7796: Add GSX device node

 arch/arm64/boot/dts/renesas/r8a7796.dtsi |  30 ++++++++
 drivers/clk/renesas/r8a7796-cpg-mssr.c   |   2 +
 drivers/clk/renesas/rcar-gen3-cpg.c      | 120 +++++++++++++++++++++++++++++++
 drivers/clk/renesas/rcar-gen3-cpg.h      |   1 +
 4 files changed, 153 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/4 clk: renesas: r8a7796: Add ZG clock

From: Takeshi Kihara <[email protected]>

This patch adds ZG clock for R8A7796 SoC.

---
 drivers/clk/renesas/r8a7796-cpg-mssr.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/renesas/r8a7796-cpg-mssr.c +2 -0
index 83a68e5..61247b5 100644
@@ -76,6 +76,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("zg",         R8A7796_CLK_ZG,    CLK_PLL4,       4, 1),
 	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),
@@ -117,6 +118,7 @@ static const struct cpg_core_clk r8a7796_core_clks[] __initconst = {
 };
 
 static const struct mssr_mod_clk r8a7796_mod_clks[] __initconst = {
+	DEF_MOD("3dge",			 112,	R8A7796_CLK_ZG),
 	DEF_MOD("scif5",		 202,	R8A7796_CLK_S3D4),
 	DEF_MOD("scif4",		 203,	R8A7796_CLK_S3D4),
 	DEF_MOD("scif3",		 204,	R8A7796_CLK_S3D4),
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/4] clk: renesas: r8a7796: Add ZG clock

Hi Uli,

Quoted 5 lines · Ulrich Hecht

From: Takeshi Kihara <[email protected]>

This patch adds ZG clock for R8A7796 SoC.

Forgot to add you're own SoB?

drivers/clk/renesas/r8a7796-cpg-mssr.c static const struct cpg_core_clk r8a7796_core_clks[] __initconst = { · line 79

Quoted 7 lines
drivers/clk/renesas/r8a7796-cpg-mssr.c +1 -0
@@ -76,6 +76,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("zg",         R8A7796_CLK_ZG,    CLK_PLL4,       4, 1),

Shouldn't this be a variable clock of type CLK_TYPE_GEN3_ZG? What else is the purpose of "[PATCH 2/4] clk: renesas: rcar-gen3: Add ZG clock divider support"?

drivers/clk/renesas/r8a7796-cpg-mssr.c static const struct cpg_core_clk r8a7796_core_clks[] __initconst = {

Quoted 9 lines
drivers/clk/renesas/r8a7796-cpg-mssr.c +1 -1
@@ -117,6 +118,7 @@ static const struct cpg_core_clk r8a7796_core_clks[] __initconst = {
 };
 
 static const struct mssr_mod_clk r8a7796_mod_clks[] __initconst = {
+       DEF_MOD("3dge",                  112,   R8A7796_CLK_ZG),
        DEF_MOD("scif5",                 202,   R8A7796_CLK_S3D4),
        DEF_MOD("scif4",                 203,   R8A7796_CLK_S3D4),
        DEF_MOD("scif3",                 204,   R8A7796_CLK_S3D4),
--

This part is fine.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#3 lore raw

PATCH 2/4 clk: renesas: rcar-gen3: Add ZG clock divider support

In reply to Ulrich Hecht

From: Takeshi Kihara <[email protected]>

This patch adds ZG clock divider support for R-Car Gen3 SoC.

---
 drivers/clk/renesas/rcar-gen3-cpg.c | 120 ++++++++++++++++++++++++++++++++++++
 drivers/clk/renesas/rcar-gen3-cpg.h |   1 +
 2 files changed, 121 insertions(+)
drivers/clk/renesas/rcar-gen3-cpg.c +120 -0
index 102cfc2..6b5d5ec 100644
@@ -73,6 +73,8 @@ static void cpg_simple_notifier_register(struct raw_notifier_head *notifiers,
  */
 #define CPG_FRQCRB			0x00000004
 #define CPG_FRQCRB_KICK			BIT(31)
+#define CPG_FRQCRB_ZGFC_MASK		(0x1f << 24)
+#define CPG_FRQCRB_ZGFC_SHIFT		24
 #define CPG_FRQCRC			0x000000e0
 #define CPG_FRQCRC_ZFC_MASK		GENMASK(12, 8)
 #define CPG_FRQCRC_Z2FC_MASK		GENMASK(4, 0)
@@ -197,6 +199,120 @@ static struct clk * __init cpg_z_clk_register(const char *name,
 	return clk;
 }
 
+static unsigned long cpg_zg_clk_recalc_rate(struct clk_hw *hw,
+					    unsigned long parent_rate)
+{
+	struct cpg_z_clk *zclk = to_z_clk(hw);
+	unsigned long prate  = parent_rate / 2; /* PLL4 clock divided by 2 */
+	unsigned int mult;
+	unsigned int val;
+	unsigned long rate;
+
+	val = (clk_readl(zclk->reg) & CPG_FRQCRB_ZGFC_MASK)
+	    >> CPG_FRQCRB_ZGFC_SHIFT;
+	mult = 32 - val;
+
+	rate = div_u64((u64)prate * mult + 16, 32);
+	/* Round to closest value at 10MHz unit */
+	rate = 10000000 * DIV_ROUND_CLOSEST(rate, 10000000);
+
+	return rate;
+}
+
+static long cpg_zg_clk_round_rate(struct clk_hw *hw, unsigned long rate,
+				  unsigned long *parent_rate)
+{
+	unsigned long prate  = *parent_rate / 2; /* PLL4 clock divided by 2 */
+	unsigned int mult;
+
+	mult = div_u64((u64)rate * 32 + prate / 2, prate);
+	mult = clamp(mult, 1U, 32U);
+
+	return prate / 32 * mult;
+}
+
+static int cpg_zg_clk_set_rate(struct clk_hw *hw, unsigned long rate,
+			       unsigned long parent_rate)
+{
+	struct cpg_z_clk *zclk = to_z_clk(hw);
+	unsigned long prate  = parent_rate / 2; /* PLL4 clock divided by 2 */
+	unsigned int mult;
+	u32 val, kick;
+	unsigned int i;
+
+	mult = div_u64((u64)rate * 32 + prate / 2, prate);
+	mult = clamp(mult, 1U, 32U);
+
+	if (clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK)
+		return -EBUSY;
+
+	val = clk_readl(zclk->reg);
+	val &= ~CPG_FRQCRB_ZGFC_MASK;
+	val |= (32 - mult) << CPG_FRQCRB_ZGFC_SHIFT;
+	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_zg_clk_ops = {
+	.recalc_rate = cpg_zg_clk_recalc_rate,
+	.round_rate = cpg_zg_clk_round_rate,
+	.set_rate = cpg_zg_clk_set_rate,
+};
+
+static struct clk * __init cpg_zg_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_zg_clk_ops;
+	init.flags = 0;
+	init.parent_names = &parent_name;
+	init.num_parents = 1;
+
+	zclk->reg = reg + CPG_FRQCRB;
+	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
  */
@@ -564,6 +680,10 @@ struct clk * __init rcar_gen3_cpg_clk_register(struct device *dev,
 		return cpg_z_clk_register(core->name, __clk_get_name(parent),
 					  base, CPG_FRQCRC_Z2FC_MASK);
 
+	case CLK_TYPE_GEN3_ZG:
+		return cpg_zg_clk_register(core->name, __clk_get_name(parent),
+					   base);
+
 	default:
 		return ERR_PTR(-EINVAL);
 	}
drivers/clk/renesas/rcar-gen3-cpg.h +1 -0
index ea4f8fc..3ae9fe6d 100644
@@ -23,6 +23,7 @@ enum rcar_gen3_clk_types {
 	CLK_TYPE_GEN3_PE,
 	CLK_TYPE_GEN3_Z,
 	CLK_TYPE_GEN3_Z2,
+	CLK_TYPE_GEN3_ZG,
 };
 
 #define DEF_GEN3_SD(_name, _id, _parent, _offset)	\
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH 2/4] clk: renesas: rcar-gen3: Add ZG clock divider support

Hi Uli,

Quoted 5 lines · Ulrich Hecht

From: Takeshi Kihara <[email protected]>

This patch adds ZG clock divider support for R-Car Gen3 SoC.

SoB?

Quoted 12 lines
drivers/clk/renesas/rcar-gen3-cpg.c +2 -0
@@ -73,6 +73,8 @@ static void cpg_simple_notifier_register(struct raw_notifier_head *notifiers,
  */
 #define CPG_FRQCRB                     0x00000004
 #define CPG_FRQCRB_KICK                        BIT(31)
+#define CPG_FRQCRB_ZGFC_MASK           (0x1f << 24)
+#define CPG_FRQCRB_ZGFC_SHIFT          24
 #define CPG_FRQCRC                     0x000000e0
 #define CPG_FRQCRC_ZFC_MASK            GENMASK(12, 8)
 #define CPG_FRQCRC_Z2FC_MASK           GENMASK(4, 0)

drivers/clk/renesas/rcar-gen3-cpg.c static struct clk * __init cpg_z_clk_register(const char *name, · line 204

Quoted 6 lines
drivers/clk/renesas/rcar-gen3-cpg.c +3 -0
@@ -197,6 +199,120 @@ static struct clk * __init cpg_z_clk_register(const char *name,
        return clk;
 }
 
+static unsigned long cpg_zg_clk_recalc_rate(struct clk_hw *hw,
+                                           unsigned long parent_rate)
+{

I think this can be consolidated with the Z/Z2 clock support, like Simon did for the Z2 clock:
https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas.git/commit/?h=topic/rcar-gen3-z-clk-v3&id=fda8dbe29dd1f04b61c443147a106962cf5d3f14

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#5 lore raw

PATCH 3/4 arm64: dts: r8a7796: Add GSX device node

In reply to Ulrich Hecht

From: Takeshi Kihara <[email protected]>

This patch adds GSX device node for R8A7796 SoC.

---
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/renesas/r8a7796.dtsi +8 -0
index 0b8558d..d3264e7 100644
@@ -2241,6 +2241,14 @@
 			};
 		};
 
+		gsx: gsx@fd000000 {
+			compatible = "renesas,gsx";
+			reg = <0 0xfd000000 0 0x3ffff>;
+			interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cpg CPG_MOD 112>;
+			power-domains = <&sysc R8A7796_PD_3DG_B>;
+		};
+
 		pciec0: pcie@fe000000 {
 			/* placeholder */
 		};
Signature · 1 line
2.7.4
#6 lore raw

Re: [PATCH 3/4] arm64: dts: r8a7796: Add GSX device node

Hi Uli,

Quoted 5 lines · Ulrich Hecht

From: Takeshi Kihara <[email protected]>

This patch adds GSX device node for R8A7796 SoC.

SoB?

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 2244

Quoted 7 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +1 -0
@@ -2241,6 +2241,14 @@
                        };
                };
 
+               gsx: gsx@fd000000 {

gpu@fd000000?

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 2245

Quoted 1 line
arch/arm64/boot/dts/renesas/r8a7796.dtsi +1 -0
+                       compatible = "renesas,gsx";

That compatible value sounds a bit simplistic to me. In addition, it's not yet documented.

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 2246

Quoted 1 line
arch/arm64/boot/dts/renesas/r8a7796.dtsi +1 -0
+                       reg = <0 0xfd000000 0 0x3ffff>;

reg = <0 0xfd000000 0 0x40000>;

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 2248

Quoted 2 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +2 -0
+                       interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
+                       clocks = <&cpg CPG_MOD 112>;

According to Figure 23.2, there's an incoming reset signal, but it's not listed in Table 8A.28.

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 2249

Quoted 1 line
arch/arm64/boot/dts/renesas/r8a7796.dtsi +1 -0
+                       power-domains = <&sysc R8A7796_PD_3DG_B>;

iommus?

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 2254

Quoted 5 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +2 -0
+               };
+
                pciec0: pcie@fe000000 {
                        /* placeholder */
                };

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#7 lore raw

PATCH 4/4 arm64: dts: r8a7796: Add DEVFREQ support for GSX

In reply to Ulrich Hecht

From: Gaku Inami <[email protected]>

This patch supports GSX frequency scaling using devfreq.

Includes update of the OPP tables for GSX because the typical voltage of VDD_DVFS (power optimized) was updated to 0.83V by R-Car Gen3 EC Rev0.54E specification.

---
 arch/arm64/boot/dts/renesas/r8a7796.dtsi | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/arm64/boot/dts/renesas/r8a7796.dtsi +22 -0
index d3264e7..fb30390 100644
@@ -166,6 +166,27 @@
 		};
 	};
 
+	gsx_opp_table: gsx_opp_table {
+		compatible = "operating-points-v2";
+
+		opp@200000000 {
+			opp-hz = /bits/ 64 <200000000>;
+			opp-microvolt = <830000>;
+		};
+		opp@300000000 {
+			opp-hz = /bits/ 64 <300000000>;
+			opp-microvolt = <830000>;
+		};
+		opp@400000000 {
+			opp-hz = /bits/ 64 <400000000>;
+			opp-microvolt = <830000>;
+		};
+		opp@600000000 {
+			opp-hz = /bits/ 64 <600000000>;
+			opp-microvolt = <830000>;
+		};
+	};
+
 	extal_clk: extal {
 		compatible = "fixed-clock";
 		#clock-cells = <0>;
@@ -2246,6 +2267,7 @@
 			reg = <0 0xfd000000 0 0x3ffff>;
 			interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cpg CPG_MOD 112>;
+			operating-points-v2 = <&gsx_opp_table>;
 			power-domains = <&sysc R8A7796_PD_3DG_B>;
 		};
 
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH 4/4] arm64: dts: r8a7796: Add DEVFREQ support for GSX

Hi Uli,

Quoted 4 lines · Ulrich Hecht

From: Gaku Inami <[email protected]>

This patch supports GSX frequency scaling using devfreq.

Quoted 8 lines

Includes update of the OPP tables for GSX because the typical voltage of VDD_DVFS (power optimized) was updated to 0.83V by R-Car Gen3 EC Rev0.54E specification.

Thanks for your patch!

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 172

Quoted 10 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +4 -0
@@ -166,6 +166,27 @@
                };
        };
 
+       gsx_opp_table: gsx_opp_table {
+               compatible = "operating-points-v2";
+
+               opp@200000000 {

opp-200000000 (try "make dtbs W=1")

Quoted 4 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +4 -0
+                       opp-hz = /bits/ 64 <200000000>;
+                       opp-microvolt = <830000>;
+               };
+               opp@300000000 {

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 186

Quoted 10 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +10 -0
+                       opp-hz = /bits/ 64 <300000000>;
+                       opp-microvolt = <830000>;
+               };
+               opp@400000000 {
+                       opp-hz = /bits/ 64 <400000000>;
+                       opp-microvolt = <830000>;
+               };
+               opp@600000000 {
+                       opp-hz = /bits/ 64 <600000000>;
+                       opp-microvolt = <830000>;

Do they really all use the same voltage?

And AFAIU, DVFS is shared between CPU and GPU.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#9 lore raw

RE: [PATCH 4/4] arm64: dts: r8a7796: Add DEVFREQ support for GSX

Hi Geert-san, Ulrich-san,

Quoted 3 lines

Do they really all use the same voltage?

And AFAIU, DVFS is shared between CPU and GPU.

We support the opp table of GPU with the same voltage for each in R-Car H3/M3. As you know, DVFS is shared between CA57 and GPU. We understand that arbitration control of the voltage from both cores can't be realized with the current CPUFREQ and DEVFREQ framework. Therefore, we have implemented as above now.

In our test with GPU team, it is fine except power consumption.

Regards,
Inami

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Geert Uytterhoeven
Sent: Monday, December 18, 2017 7:27 PM
To: Ulrich Hecht <[email protected]>
Cc: Linux-Renesas <[email protected]>; Laurent Pinchart <[email protected]>; Magnus Damm <[email protected]>; Gaku Inami <[email protected]>; TAKESHI KIHARA <[email protected]>; Hien Dang <[email protected]>
Subject: Re: [PATCH 4/4] arm64: dts: r8a7796: Add DEVFREQ support for GSX

Hi Uli,

Quoted 4 lines · Ulrich Hecht

From: Gaku Inami <[email protected]>

This patch supports GSX frequency scaling using devfreq.

Quoted 8 lines

Includes update of the OPP tables for GSX because the typical voltage of VDD_DVFS (power optimized) was updated to 0.83V by R-Car Gen3 EC Rev0.54E specification.

Thanks for your patch!

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 172

Quoted 10 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +4 -0
@@ -166,6 +166,27 @@
                };
        };
 
+       gsx_opp_table: gsx_opp_table {
+               compatible = "operating-points-v2";
+
+               opp@200000000 {

opp-200000000 (try "make dtbs W=1")

Quoted 4 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +4 -0
+                       opp-hz = /bits/ 64 <200000000>;
+                       opp-microvolt = <830000>;
+               };
+               opp@300000000 {

arch/arm64/boot/dts/renesas/r8a7796.dtsi line 186

Quoted 10 lines
arch/arm64/boot/dts/renesas/r8a7796.dtsi +10 -0
+                       opp-hz = /bits/ 64 <300000000>;
+                       opp-microvolt = <830000>;
+               };
+               opp@400000000 {
+                       opp-hz = /bits/ 64 <400000000>;
+                       opp-microvolt = <830000>;
+               };
+               opp@600000000 {
+                       opp-hz = /bits/ 64 <600000000>;
+                       opp-microvolt = <830000>;

Do they really all use the same voltage?

And AFAIU, DVFS is shared between CPU and GPU.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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