Skip to contentSkip to conversation

arm64: renesas: r8a78000: Add PWM support

PATCH In review Geert Uytterhoeven 4 participants 25 messages Oct 26 – Nov 3

Subsystems (6)
lore
Share & tools
lore

Geert Uytterhoeven

author maintainer
#0 lore raw

cover arm64: renesas: r8a78000: Add PWM support

Hi all,

This patch series enables PWM support for the Renesas R-Car X5H SoC, as found on the Renesas Ironhide development board. On this board, clocks, power-domains, and resets must be accessed only through SCMI firmware.

Just like its GPIO counterpart[1], this series is a bit special, in that several patches are not meant to be applied upstream yet:
1. The first patch, targeting the PWM tree, documents support for the 16-Bit Timer Pulse Unit (TPU) on R-Car X5H; no driver changes are needed,
2. Patches 2-6, targeting the PWM tree too, document and add support for the PWM instances on R-Car X5H, after a few customary refactorings,
3. Patch 7, targeting a shared DT bindings branch, adds PWM clock definitions,
4. Patch 8, targeting renesas-devel, adds the various PWM device nodes to the R-Car X5H .dtsi file,
5. The remaining patches are marked DNI, and depend on code or DTS that is not yet upstream. More detail can be found in the individual patches.

PWM instances 0 to 5 and TPU channels 0 and 1 have been tested on Ironhide using a set of blinkenlights and a logic analyzer.

Thanks for your comments!

[1] "[PATCH 0/7] arm64: renesas: r8a78000: Enable GPIO support"

    https://lore.kernel.org/[email protected]

Geert Uytterhoeven (10):
dt-bindings: pwm: renesas,pwm-rcar: Add support for R-Car X5H
pwm: rcar: Use FIELD_PREP() for PWMCR_CC0 access
pwm: rcar: Add helper variable dev to rcar_pwm_probe()
pwm: rcar: Parametrize cycle counter field size
pwm: rcar: Add support for R-Car Gen5
dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks
arm64: dts: renesas: r8a78000: Add PWM nodes
[DNI] clk: renesas: r8a78000: Add PWM clocks
[DNI] pmdomain: renesas: r8a78000: Add PWM support [DNI] arm64: dts: renesas: ironhide: Enable PWM

Khanh Le (1):
dt-bindings: pwm: renesas,tpu-pwm: Add support for R-Car X5H

 .../bindings/pwm/renesas,pwm-rcar.yaml        |  61 +++++----
 .../bindings/pwm/renesas,tpu-pwm.yaml         |   1 +
 .../boot/dts/renesas/r8a78000-ironhide.dts    |  84 ++++++++++++
 arch/arm64/boot/dts/renesas/r8a78000.dtsi     | 121 ++++++++++++++++++
 drivers/clk/renesas/r8a78000-cpg.c            |   6 +
 drivers/pmdomain/renesas/r8a78000-mdlc.c      |   2 +
 drivers/pwm/pwm-rcar.c                        |  92 ++++++++-----
 .../dt-bindings/clock/renesas,r8a78000-cpg.h  |   3 +
 8 files changed, 312 insertions(+), 58 deletions(-)
Signature · 12 lines
2.43.0

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
author maintainer
#1 lore raw

PATCH 1/11 dt-bindings: pwm: renesas,tpu-pwm: Add support for R-Car X5H

From: Khanh Le <[email protected]>

Document support for the 16-Bit Timer Pulse Unit (TPU) in the Renesas R-Car X5H (R8A78000) SoC.

---
 Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml +1 -0
index f85ee5d20ccbb3f9..144a88ff53e5633b 100644
@@ -33,6 +33,7 @@ properties:
           - renesas,tpu-r8a779a0  # R-Car V3U
           - renesas,tpu-r8a779g0  # R-Car V4H
           - renesas,tpu-r8a779h0  # R-Car V4M
+          - renesas,tpu-r8a78000  # R-Car X5H
       - const: renesas,tpu
 
   reg:
Signature · 1 line
2.43.0
Acked-by on v1 1/11
#2 lore raw

Re: [PATCH 01/11] dt-bindings: pwm: renesas,tpu-pwm: Add support for R-Car X5H

Quoted 10 lines · Geert Uytterhoeven

From: Khanh Le <[email protected]>

Document support for the 16-Bit Timer Pulse Unit (TPU) in the Renesas R-Car X5H (R8A78000) SoC.

---
 Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml | 1 +
 1 file changed, 1 insertion(+)

Best regards,
Krzysztof

author maintainer
#3 lore raw

PATCH 2/11 dt-bindings: pwm: renesas,pwm-rcar: Add support for R-Car X5H

In reply to Geert Uytterhoeven

Document support for the Pulse Width Modulation (PWM) module in the Renesas R-Car X5H (R8A78000) SoC.

R-Car Gen5 enlarged the PWM output cycle and high-level period fields from 10 to 24 bits. While the added register bits have initial states of all-zeroes, and thus look compatible with previous generations, the register bits may have been modified before Linux boots. Hence no fallback to renesas,pwm-rcar is included.

---
 .../bindings/pwm/renesas,pwm-rcar.yaml        | 61 ++++++++++---------
 1 file changed, 33 insertions(+), 28 deletions(-)
Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.yaml +33 -28
index 2fe1992e29088c9a..424ca1e2df15354c 100644
@@ -11,34 +11,39 @@ maintainers:
 
 properties:
   compatible:
-    items:
-      - enum:
-          - renesas,pwm-r8a7742   # RZ/G1H
-          - renesas,pwm-r8a7743   # RZ/G1M
-          - renesas,pwm-r8a7744   # RZ/G1N
-          - renesas,pwm-r8a7745   # RZ/G1E
-          - renesas,pwm-r8a77470  # RZ/G1C
-          - renesas,pwm-r8a774a1  # RZ/G2M
-          - renesas,pwm-r8a774b1  # RZ/G2N
-          - renesas,pwm-r8a774c0  # RZ/G2E
-          - renesas,pwm-r8a774e1  # RZ/G2H
-          - renesas,pwm-r8a7778   # R-Car M1A
-          - renesas,pwm-r8a7779   # R-Car H1
-          - renesas,pwm-r8a7790   # R-Car H2
-          - renesas,pwm-r8a7791   # R-Car M2-W
-          - renesas,pwm-r8a7794   # R-Car E2
-          - renesas,pwm-r8a7795   # R-Car H3
-          - renesas,pwm-r8a7796   # R-Car M3-W
-          - renesas,pwm-r8a77961  # R-Car M3-W+
-          - renesas,pwm-r8a77965  # R-Car M3-N
-          - renesas,pwm-r8a77970  # R-Car V3M
-          - renesas,pwm-r8a77980  # R-Car V3H
-          - renesas,pwm-r8a77990  # R-Car E3
-          - renesas,pwm-r8a77995  # R-Car D3
-          - renesas,pwm-r8a779a0  # R-Car V3U
-          - renesas,pwm-r8a779g0  # R-Car V4H
-          - renesas,pwm-r8a779h0  # R-Car V4M
-      - const: renesas,pwm-rcar
+    oneOf:
+      - items:
+          - enum:
+              - renesas,pwm-r8a7742   # RZ/G1H
+              - renesas,pwm-r8a7743   # RZ/G1M
+              - renesas,pwm-r8a7744   # RZ/G1N
+              - renesas,pwm-r8a7745   # RZ/G1E
+              - renesas,pwm-r8a77470  # RZ/G1C
+              - renesas,pwm-r8a774a1  # RZ/G2M
+              - renesas,pwm-r8a774b1  # RZ/G2N
+              - renesas,pwm-r8a774c0  # RZ/G2E
+              - renesas,pwm-r8a774e1  # RZ/G2H
+              - renesas,pwm-r8a7778   # R-Car M1A
+              - renesas,pwm-r8a7779   # R-Car H1
+              - renesas,pwm-r8a7790   # R-Car H2
+              - renesas,pwm-r8a7791   # R-Car M2-W
+              - renesas,pwm-r8a7794   # R-Car E2
+              - renesas,pwm-r8a7795   # R-Car H3
+              - renesas,pwm-r8a7796   # R-Car M3-W
+              - renesas,pwm-r8a77961  # R-Car M3-W+
+              - renesas,pwm-r8a77965  # R-Car M3-N
+              - renesas,pwm-r8a77970  # R-Car V3M
+              - renesas,pwm-r8a77980  # R-Car V3H
+              - renesas,pwm-r8a77990  # R-Car E3
+              - renesas,pwm-r8a77995  # R-Car D3
+              - renesas,pwm-r8a779a0  # R-Car V3U
+              - renesas,pwm-r8a779g0  # R-Car V4H
+              - renesas,pwm-r8a779h0  # R-Car V4M
+          - const: renesas,pwm-rcar
+      - items:
+          - enum:
+              - renesas,pwm-r8a78000  # R-Car X5H
+          - const: renesas,rcar-gen5-pwm
 
   reg:
     # base address and length of the registers block for the PWM.
Signature · 1 line
2.43.0
Reviewed-by on v1 2/11
#4 lore raw

Re: [PATCH 02/11] dt-bindings: pwm: renesas,pwm-rcar: Add support for R-Car X5H

Quoted 9 lines · Geert Uytterhoeven

Document support for the Pulse Width Modulation (PWM) module in the Renesas R-Car X5H (R8A78000) SoC.

R-Car Gen5 enlarged the PWM output cycle and high-level period fields from 10 to 24 bits. While the added register bits have initial states of all-zeroes, and thus look compatible with previous generations, the register bits may have been modified before Linux boots. Hence no fallback to renesas,pwm-rcar is included.

Quoted 4 lines
---
 .../bindings/pwm/renesas,pwm-rcar.yaml        | 61 ++++++++++---------
 1 file changed, 33 insertions(+), 28 deletions(-)

Best regards,
Krzysztof

author maintainer
#5 lore raw

PATCH 3/11 pwm: rcar: Use FIELD_PREP() for PWMCR_CC0 access

In reply to Geert Uytterhoeven

Use the FIELD_PREP() helper instead of open-coding the same operation. Drop the now unused RCAR_PWMCR_CC0_SHIFT definition, and redefine RCAR_PWMCR_CC0_SHIFT using GENMASK() while at it.

---
 drivers/pwm/pwm-rcar.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pwm/pwm-rcar.c +2 -3
index 1733cd700693713e..4641f258df531baf 100644
@@ -25,8 +25,7 @@
 #define RCAR_PWM_MAX_CYCLE	1023
 
 #define RCAR_PWMCR		0x00
-#define  RCAR_PWMCR_CC0_MASK	0x000f0000
-#define  RCAR_PWMCR_CC0_SHIFT	16
+#define  RCAR_PWMCR_CC0_MASK	GENMASK(19, 16)
 #define  RCAR_PWMCR_CCMD	BIT(15)
 #define  RCAR_PWMCR_SYNC	BIT(11)
 #define  RCAR_PWMCR_SS0		BIT(4)
@@ -99,7 +98,7 @@ static void rcar_pwm_set_clock_control(struct rcar_pwm_chip *rp,
 
 	div >>= 1;
 
-	value |= div << RCAR_PWMCR_CC0_SHIFT;
+	value |= FIELD_PREP(RCAR_PWMCR_CC0_MASK, div);
 	rcar_pwm_write(rp, value, RCAR_PWMCR);
 }
 
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 4/11 pwm: rcar: Add helper variable dev to rcar_pwm_probe()

In reply to Geert Uytterhoeven

rcar_pwm_probe() has many users of "&pdev->dev".
Introduce a shorthand to simplify the code.

---
 drivers/pwm/pwm-rcar.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/pwm/pwm-rcar.c +8 -7
index 4641f258df531baf..f1f68bfe016f729f 100644
@@ -202,11 +202,12 @@ static const struct pwm_ops rcar_pwm_ops = {
 
 static int rcar_pwm_probe(struct platform_device *pdev)
 {
-	struct pwm_chip *chip;
+	struct device *dev = &pdev->dev;
 	struct rcar_pwm_chip *rcar_pwm;
+	struct pwm_chip *chip;
 	int ret;
 
-	chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*rcar_pwm));
+	chip = devm_pwmchip_alloc(dev, 1, sizeof(*rcar_pwm));
 	if (IS_ERR(chip))
 		return PTR_ERR(chip);
 	rcar_pwm = to_rcar_pwm_chip(chip);
@@ -215,9 +216,9 @@ static int rcar_pwm_probe(struct platform_device *pdev)
 	if (IS_ERR(rcar_pwm->base))
 		return PTR_ERR(rcar_pwm->base);
 
-	rcar_pwm->clk = devm_clk_get(&pdev->dev, NULL);
+	rcar_pwm->clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(rcar_pwm->clk)) {
-		dev_err(&pdev->dev, "cannot get clock\n");
+		dev_err(dev, "cannot get clock\n");
 		return PTR_ERR(rcar_pwm->clk);
 	}
 
@@ -225,12 +226,12 @@ static int rcar_pwm_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, chip);
 
-	pm_runtime_enable(&pdev->dev);
+	pm_runtime_enable(dev);
 
 	ret = pwmchip_add(chip);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to register PWM chip: %d\n", ret);
-		pm_runtime_disable(&pdev->dev);
+		dev_err(dev, "failed to register PWM chip: %d\n", ret);
+		pm_runtime_disable(dev);
 		return ret;
 	}
 
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 5/11 pwm: rcar: Parametrize cycle counter field size

In reply to Geert Uytterhoeven

Prepare for the advent of PWM blocks with output cycle and high-level period fields larger than 10 bits by parametrizing the field size.

---
 drivers/pwm/pwm-rcar.c | 51 +++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 18 deletions(-)
drivers/pwm/pwm-rcar.c +33 -18
index f1f68bfe016f729f..3813094c601efc8c 100644
@@ -22,7 +22,7 @@
 #include <linux/slab.h>
 
 #define RCAR_PWM_MAX_DIVISION	24
-#define RCAR_PWM_MAX_CYCLE	1023
+#define RCAR_PWM_MAX_CYCLE(rp)	GENMASK(rp->cycle_bits - 1, 0)
 
 #define RCAR_PWMCR		0x00
 #define  RCAR_PWMCR_CC0_MASK	GENMASK(19, 16)
@@ -32,14 +32,17 @@
 #define  RCAR_PWMCR_EN0		BIT(0)
 
 #define RCAR_PWMCNT		0x04
-#define  RCAR_PWMCNT_CYC0_MASK	0x03ff0000
-#define  RCAR_PWMCNT_CYC0_SHIFT	16
-#define  RCAR_PWMCNT_PH0_MASK	0x000003ff
-#define  RCAR_PWMCNT_PH0_SHIFT	0
+#define  RCAR_PWMCNT_CYC0_MASK	GENMASK(31, 16)
+#define  RCAR_PWMCNT_PH0_MASK	GENMASK(15, 0)
 
 struct rcar_pwm_chip {
 	void __iomem *base;
 	struct clk *clk;
+	unsigned int cycle_bits;
+};
+
+struct rcar_pwm_info {
+	unsigned int cycle_bits;
 };
 
 static inline struct rcar_pwm_chip *to_rcar_pwm_chip(struct pwm_chip *chip)
@@ -77,7 +80,7 @@ static int rcar_pwm_get_clock_division(struct rcar_pwm_chip *rp, int period_ns)
 	if (clk_rate == 0)
 		return -EINVAL;
 
-	div = (u64)NSEC_PER_SEC * RCAR_PWM_MAX_CYCLE;
+	div = mul_u32_u32(NSEC_PER_SEC, RCAR_PWM_MAX_CYCLE(rp));
 	tmp = (u64)period_ns * clk_rate + div - 1;
 	tmp = div64_u64(tmp, div);
 	div = ilog2(tmp - 1) + 1;
@@ -111,21 +114,19 @@ static int rcar_pwm_set_counter(struct rcar_pwm_chip *rp, int div, u64 duty_ns,
 
 	/* div <= 24 == RCAR_PWM_MAX_DIVISION, so the shift doesn't overflow. */
 	tmp = mul_u64_u64_div_u64(period_ns, clk_rate, (u64)NSEC_PER_SEC << div);
-	if (tmp > FIELD_MAX(RCAR_PWMCNT_CYC0_MASK))
-		tmp = FIELD_MAX(RCAR_PWMCNT_CYC0_MASK);
-
-	cyc = FIELD_PREP(RCAR_PWMCNT_CYC0_MASK, tmp);
+	cyc = min(tmp, RCAR_PWM_MAX_CYCLE(rp));
 
 	tmp = mul_u64_u64_div_u64(duty_ns, clk_rate, (u64)NSEC_PER_SEC << div);
-	if (tmp > FIELD_MAX(RCAR_PWMCNT_PH0_MASK))
-		tmp = FIELD_MAX(RCAR_PWMCNT_PH0_MASK);
-	ph = FIELD_PREP(RCAR_PWMCNT_PH0_MASK, tmp);
+	ph = min(tmp, RCAR_PWM_MAX_CYCLE(rp));
 
 	/* Avoid prohibited setting */
 	if (cyc == 0 || ph == 0)
 		return -EINVAL;
 
-	rcar_pwm_write(rp, cyc | ph, RCAR_PWMCNT);
+	rcar_pwm_write(rp,
+		       FIELD_PREP(RCAR_PWMCNT_CYC0_MASK, cyc) |
+		       FIELD_PREP(RCAR_PWMCNT_PH0_MASK, ph),
+		       RCAR_PWMCNT);
 
 	return 0;
 }
@@ -142,12 +143,15 @@ static void rcar_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 
 static int rcar_pwm_enable(struct rcar_pwm_chip *rp)
 {
-	u32 value;
+	u32 value, cyc, ph;
 
 	/* Don't enable the PWM device if CYC0 or PH0 is 0 */
 	value = rcar_pwm_read(rp, RCAR_PWMCNT);
-	if ((value & RCAR_PWMCNT_CYC0_MASK) == 0 ||
-	    (value & RCAR_PWMCNT_PH0_MASK) == 0)
+	cyc = FIELD_GET(RCAR_PWMCNT_CYC0_MASK, value);
+	ph = FIELD_GET(RCAR_PWMCNT_PH0_MASK, value);
+
+	if ((cyc & RCAR_PWM_MAX_CYCLE(rp)) == 0 ||
+	    (ph & RCAR_PWM_MAX_CYCLE(rp)) == 0)
 		return -EINVAL;
 
 	rcar_pwm_update(rp, RCAR_PWMCR_EN0, RCAR_PWMCR_EN0, RCAR_PWMCR);
@@ -202,11 +206,16 @@ static const struct pwm_ops rcar_pwm_ops = {
 
 static int rcar_pwm_probe(struct platform_device *pdev)
 {
+	const struct rcar_pwm_info *info;
 	struct device *dev = &pdev->dev;
 	struct rcar_pwm_chip *rcar_pwm;
 	struct pwm_chip *chip;
 	int ret;
 
+	info = of_device_get_match_data(dev);
+	if (!info)
+		return -ENODEV;
+
 	chip = devm_pwmchip_alloc(dev, 1, sizeof(*rcar_pwm));
 	if (IS_ERR(chip))
 		return PTR_ERR(chip);
@@ -222,6 +231,8 @@ static int rcar_pwm_probe(struct platform_device *pdev)
 		return PTR_ERR(rcar_pwm->clk);
 	}
 
+	rcar_pwm->cycle_bits = info->cycle_bits;
+
 	chip->ops = &rcar_pwm_ops;
 
 	platform_set_drvdata(pdev, chip);
@@ -247,8 +258,12 @@ static void rcar_pwm_remove(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 }
 
+static const struct rcar_pwm_info rcar_pwm_info = {
+	.cycle_bits = 10,
+};
+
 static const struct of_device_id rcar_pwm_of_table[] = {
-	{ .compatible = "renesas,pwm-rcar" },
+	{ .compatible = "renesas,pwm-rcar", .data = &rcar_pwm_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, rcar_pwm_of_table);
Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH 6/11 pwm: rcar: Add support for R-Car Gen5

In reply to Geert Uytterhoeven

R-Car Gen5 enlarged the PWM output cycle and high-level period fields from 10 to 24 bits. The high parts of each field are stored in a new register.

---
 drivers/pwm/pwm-rcar.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/pwm/pwm-rcar.c +22 -5
index 3813094c601efc8c..5e91509de7a7c162 100644
@@ -31,7 +31,8 @@
 #define  RCAR_PWMCR_SS0		BIT(4)
 #define  RCAR_PWMCR_EN0		BIT(0)
 
-#define RCAR_PWMCNT		0x04
+#define RCAR_PWMCNTA		0x04		/* Low part */
+#define RCAR_PWMCNTB		0x08		/* High part (R-Car Gen5) */
 #define  RCAR_PWMCNT_CYC0_MASK	GENMASK(31, 16)
 #define  RCAR_PWMCNT_PH0_MASK	GENMASK(15, 0)
 
@@ -124,9 +125,15 @@ static int rcar_pwm_set_counter(struct rcar_pwm_chip *rp, int div, u64 duty_ns,
 		return -EINVAL;
 
 	rcar_pwm_write(rp,
-		       FIELD_PREP(RCAR_PWMCNT_CYC0_MASK, cyc) |
-		       FIELD_PREP(RCAR_PWMCNT_PH0_MASK, ph),
-		       RCAR_PWMCNT);
+		       FIELD_PREP(RCAR_PWMCNT_CYC0_MASK, lower_16_bits(cyc)) |
+		       FIELD_PREP(RCAR_PWMCNT_PH0_MASK, lower_16_bits(ph)),
+		       RCAR_PWMCNTA);
+
+	if (rp->cycle_bits >= 16)
+		rcar_pwm_write(rp,
+		       FIELD_PREP(RCAR_PWMCNT_CYC0_MASK, upper_16_bits(cyc)) |
+		       FIELD_PREP(RCAR_PWMCNT_PH0_MASK, upper_16_bits(ph)),
+		       RCAR_PWMCNTB);
 
 	return 0;
 }
@@ -146,9 +153,14 @@ static int rcar_pwm_enable(struct rcar_pwm_chip *rp)
 	u32 value, cyc, ph;
 
 	/* Don't enable the PWM device if CYC0 or PH0 is 0 */
-	value = rcar_pwm_read(rp, RCAR_PWMCNT);
+	value = rcar_pwm_read(rp, RCAR_PWMCNTA);
 	cyc = FIELD_GET(RCAR_PWMCNT_CYC0_MASK, value);
 	ph = FIELD_GET(RCAR_PWMCNT_PH0_MASK, value);
+	if (rp->cycle_bits >= 16) {
+		value = rcar_pwm_read(rp, RCAR_PWMCNTB);
+		cyc |= FIELD_GET(RCAR_PWMCNT_CYC0_MASK, value) << 16;
+		ph |= FIELD_GET(RCAR_PWMCNT_PH0_MASK, value) << 16;
+	}
 
 	if ((cyc & RCAR_PWM_MAX_CYCLE(rp)) == 0 ||
 	    (ph & RCAR_PWM_MAX_CYCLE(rp)) == 0)
@@ -262,8 +274,13 @@ static const struct rcar_pwm_info rcar_pwm_info = {
 	.cycle_bits = 10,
 };
 
+static const struct rcar_pwm_info rcar_gen5_pwm_info = {
+	.cycle_bits = 24,
+};
+
 static const struct of_device_id rcar_pwm_of_table[] = {
 	{ .compatible = "renesas,pwm-rcar", .data = &rcar_pwm_info },
+	{ .compatible = "renesas,rcar-gen5-pwm", .data = &rcar_gen5_pwm_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, rcar_pwm_of_table);
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 7/11 dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

In reply to Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

---
This depends on "[PATCH 2/7] dt-bindings: clock: renesas,r8a78000-cpg:
Add GPIO clocks"
https://lore.kernel.org/624a9fb09e4ec74b1995797e5121b86e7206f5f2.1792776697.git.geert+renesas@glider.be

---
 include/dt-bindings/clock/renesas,r8a78000-cpg.h | 3 +++
 1 file changed, 3 insertions(+)
include/dt-bindings/clock/renesas,r8a78000-cpg.h +3 -0
index cd7192ccecd4e22c..8c30476d41448cf5 100644
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS		18
 #define R8A78000_CPG_SGD32_PERW_BUS		19
 #define R8A78000_CPG_S0D24_HSCN_OTHER		20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN	21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN	22
+#define R8A78000_CPG_S0ASYNCD8_PERW_MAIN	23
 
 #endif /* __DT_BINDINGS_CLOCK_RENESAS_R8A78000_CPG_H__ */
Signature · 1 line
2.43.0
Acked-by on v1 7/11
#10 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Quoted 5 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 8 lines

---
This depends on "[PATCH 2/7] dt-bindings: clock: renesas,r8a78000-cpg:
Add GPIO clocks"
https://lore.kernel.org/624a9fb09e4ec74b1995797e5121b86e7206f5f2.1792776697.git.geert+renesas@glider.be

---
 include/dt-bindings/clock/renesas,r8a78000-cpg.h | 3 +++
 1 file changed, 3 insertions(+)

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

In reply to Geert Uytterhoeven

Hi Geert,

Thank you for the patch.

Quoted 19 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

---
This depends on "[PATCH 2/7] dt-bindings: clock: renesas,r8a78000-cpg:
Add GPIO clocks"
https://lore.kernel.org/624a9fb09e4ec74b1995797e5121b86e7206f5f2.1792776697.git.geert+renesas@glider.be

---
 include/dt-bindings/clock/renesas,r8a78000-cpg.h | 3 +++
 1 file changed, 3 insertions(+)
include/dt-bindings/clock/renesas,r8a78000-cpg.h +0 -0
index cd7192ccecd4e22c..8c30476d41448cf5 100644

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 5 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS		18
 #define R8A78000_CPG_SGD32_PERW_BUS		19
 #define R8A78000_CPG_S0D24_HSCN_OTHER		20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN	21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN	22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 3 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +1 -0
+#define R8A78000_CPG_S0ASYNCD8_PERW_MAIN	23
 
 #endif /* __DT_BINDINGS_CLOCK_RENESAS_R8A78000_CPG_H__ */
Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Hi Laurent,

Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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
#13 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are not directly controllable. There's a risk of adding clocks that don't exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do you think that's an issue, could it cause ABI problems in the future ?

Signature · 3 lines
Regards,

Laurent Pinchart
#14 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Hi Laurent,

Quoted 30 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

Quoted 7 lines

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.
  - R8A78000_CPG_SCPBUSDn_SCP_MAIN for n=16, and added the ones for
    n=1,2,4,6,8,32, too.
  - R8A78000_CPG_S0Dn_PERE_MAIN for n=24, and added the ones for
    n=1,2,3,4,8, too.

- R8A78000_CPG_SGDn_PERW_BUS for n=32, and added the ones for n=8, too.

I did not includes clocks with values for n that exist according to the documentation, but are not used as suppliers for modules. Of course the documentation may be incorrect or incomplete, and we may need to add them later. As IDs are ABI and the list is append-only, they must be added at the end, which could indeed lead to not all clocks of the same group being located together. From an ABI point of view that is OK, but from a human-readability point of view it is indeed suboptimal.

Before, we tended to add all clocks from the clock tables listed the documentation upfront, ignoring clocks that are clearly internal-only. Some of them turned out not to exist later.
Some new clocks had to be added when the documentation was updated. Nothing new here, except that the list of clocks on R-Car X5H is an order of magnitude longer.

Note that we don't use a linear array of clocks indexed by clock ID in the R-Car X5H CPG driver (yet), so large holes of unused clocks do not hurt (they do hurt in the SCMI driver ;-)

Quoted 1 line

not directly controllable. There's a risk of adding clocks that don't

FTR, the xDn clocks are not directly controllable; clocks like R8A78000_CPG_MSO_SCP_MAIN are. We know the latter exist, as they are used.

Quoted 2 lines

exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do

The direct parent of an MDLC-controlled module clock should be in DT. Higher-up parents should not be needed iff the SCMI firmware exposed and/or implements the proper clock hierarchy (which it does not at the moment). Still, they can be internal enum, starting after the last DT clock, like we did in other R-Car clock drivers.

Quoted 1 line

you think that's an issue, could it cause ABI problems in the future ?

An ABI problem appears only when you refer in DT to a clock that does not exist in hardware. This should be caught by testing before the DT user is added.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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
#15 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Quoted 36 lines · Geert Uytterhoeven
Quoted 35 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

Quoted 6 lines
Quoted 2 lines

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.

That's missing n=4 and n=32. While SGASYNCD32 isn't referenced in the datasheet, SGASYNCD4 is (in SCIF and HSCIF). Maybe that's just an oversight ?

Quoted 27 lines

- R8A78000_CPG_SCPBUSDn_SCP_MAIN for n=16, and added the ones for

    n=1,2,4,6,8,32, too.
  - R8A78000_CPG_S0Dn_PERE_MAIN for n=24, and added the ones for
    n=1,2,3,4,8, too.

- R8A78000_CPG_SGDn_PERW_BUS for n=32, and added the ones for n=8, too.

I did not includes clocks with values for n that exist according to the documentation, but are not used as suppliers for modules. Of course the documentation may be incorrect or incomplete, and we may need to add them later. As IDs are ABI and the list is append-only, they must be added at the end, which could indeed lead to not all clocks of the same group being located together. From an ABI point of view that is OK, but from a human-readability point of view it is indeed suboptimal.

Before, we tended to add all clocks from the clock tables listed the documentation upfront, ignoring clocks that are clearly internal-only. Some of them turned out not to exist later.
Some new clocks had to be added when the documentation was updated. Nothing new here, except that the list of clocks on R-Car X5H is an order of magnitude longer.

Note that we don't use a linear array of clocks indexed by clock ID in the R-Car X5H CPG driver (yet), so large holes of unused clocks do not hurt (they do hurt in the SCMI driver ;-)

Quoted 5 lines
Quoted 1 line

not directly controllable. There's a risk of adding clocks that don't

FTR, the xDn clocks are not directly controllable; clocks like R8A78000_CPG_MSO_SCP_MAIN are. We know the latter exist, as they are used.

Yes, I was talking about the clocks documented in the various non-PLL "hierarchy" sections.

Quoted 4 lines
Quoted 2 lines

exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do

The direct parent of an MDLC-controlled module clock should be in DT.

An additional difficulty is that we don't actually know what clocks the MDLC gates :-/

Quoted 3 lines

Higher-up parents should not be needed iff the SCMI firmware exposed and/or implements the proper clock hierarchy (which it does not at the moment).

A big *iff* :-)

Even in that case, we'll have (at least) two issues:

- Some modules may need to know the rate of the functional clock gated by the MDLC. As those clocks are controlled through power domains, they are only specified as the last cell of the power-domains property, and are not listed in the clocks property. How do you envision this to work ?

- When multiple clocks derive from the same PLL, it's common for the PLL rate to be specified through assigned-clock-rates. If we want to continue doing that, we need to to make the whole clock hierarchy available to DT.

Quoted 8 lines

Still, they can be internal enum, starting after the last DT clock, like we did in other R-Car clock drivers.

Quoted 1 line

you think that's an issue, could it cause ABI problems in the future ?

An ABI problem appears only when you refer in DT to a clock that does not exist in hardware. This should be caught by testing before the DT user is added.

So we could add e.g. SGASYNCD32 already, as long as we don't reference it in DT without testing.

Signature · 3 lines
Regards,

Laurent Pinchart
#16 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Hi Laurent,

Quoted 40 lines · Laurent Pinchart
Quoted 39 lines · Geert Uytterhoeven
Quoted 37 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

Quoted 7 lines
Quoted 3 lines

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.

That's missing n=4 and n=32. While SGASYNCD32 isn't referenced in the datasheet, SGASYNCD4 is (in SCIF and HSCIF). Maybe that's just an oversight ?

We already have the clocks for (H)SCIF (_BUS, not _MAIN!):

    #define R8A78000_CPG_SGASYNCD4_PERW_BUS         0
    #define R8A78000_CPG_SGASYNCD8_PERW_BUS         1
Quoted 36 lines
Quoted 27 lines

- R8A78000_CPG_SCPBUSDn_SCP_MAIN for n=16, and added the ones for

    n=1,2,4,6,8,32, too.
  - R8A78000_CPG_S0Dn_PERE_MAIN for n=24, and added the ones for
    n=1,2,3,4,8, too.

- R8A78000_CPG_SGDn_PERW_BUS for n=32, and added the ones for n=8, too.

I did not includes clocks with values for n that exist according to the documentation, but are not used as suppliers for modules. Of course the documentation may be incorrect or incomplete, and we may need to add them later. As IDs are ABI and the list is append-only, they must be added at the end, which could indeed lead to not all clocks of the same group being located together. From an ABI point of view that is OK, but from a human-readability point of view it is indeed suboptimal.

Before, we tended to add all clocks from the clock tables listed the documentation upfront, ignoring clocks that are clearly internal-only. Some of them turned out not to exist later.
Some new clocks had to be added when the documentation was updated. Nothing new here, except that the list of clocks on R-Car X5H is an order of magnitude longer.

Note that we don't use a linear array of clocks indexed by clock ID in the R-Car X5H CPG driver (yet), so large holes of unused clocks do not hurt (they do hurt in the SCMI driver ;-)

Quoted 5 lines
Quoted 1 line

not directly controllable. There's a risk of adding clocks that don't

FTR, the xDn clocks are not directly controllable; clocks like R8A78000_CPG_MSO_SCP_MAIN are. We know the latter exist, as they are used.

Yes, I was talking about the clocks documented in the various non-PLL "hierarchy" sections.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do

The direct parent of an MDLC-controlled module clock should be in DT.

An additional difficulty is that we don't actually know what clocks the MDLC gates :-/

This hasn't changed much: on other R-Car generations we also didn't know which clock(s) are gated by a single MSTP (Module SToP) bit. Historically (old SH parts), there was only a single clock supplying each module. Modules on later SoCs gained more clock supplies. Hence we always assumed (at least) the functional clock is gated by the MSTP bit, and modelled the gateable SMTP clocks as a child of the functional clock parent. But it's quite possible other clock inputs to the module are gated, too, depending on the actual module (some modules e.g. need a PHY clock running to be able to process wake-up events).

Comparing older R-Car with R-Car Gen5, I actually like how the new MDLC block combines the power domain functionality of the old SYSC block and the clock domain functionality of the old MSSR (Module Standby and Software Reset) block. It improves upon the now imprecise modelling of MSTP clocks, and maps nicely on the Linux PM Domain abstraction:
- power domain: generic_pm_domain.power_{on,off}(domain),
- clock domain: generic_pm_domain.dev_ops.{start,stop}(device).

Quoted 6 lines
Quoted 3 lines

Higher-up parents should not be needed iff the SCMI firmware exposed and/or implements the proper clock hierarchy (which it does not at the moment).

A big *iff* :-)

Quoted 7 lines

Even in that case, we'll have (at least) two issues:

- Some modules may need to know the rate of the functional clock gated by the MDLC. As those clocks are controlled through power domains, they are only specified as the last cell of the power-domains property, and are not listed in the clocks property. How do you envision this to work ?

The functional clock (or its parent) is still listed in the clocks property. Compare e.g. the hscif0 nodes on R-Car V4H:

    clocks = <&cpg CPG_MOD 514>,
             <&cpg CPG_CORE R8A779G0_CLK_SASYNCPERD1>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
    resets = <&cpg 514>;

and R-Car X5H:

    clocks = <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x54>;
    resets = <&mdlc_perw 0x54>;

On R-Car V4H, MSTP514 aka "hscif0" is modelled as a gateable MSTP clock with parent R8A779G0_CLK_SASYNCPERD1, and used as "fck". On R-Car X5H, R8A78000_CPG_SGASYNCD4_PERW_BUS is used as "fck" directly. Calling clk_get_rate() on MSTP514 and R8A78000_CPG_SGASYNCD4_PERW_BUS gives similar results.

Quoted 4 lines

- When multiple clocks derive from the same PLL, it's common for the PLL rate to be specified through assigned-clock-rates. If we want to continue doing that, we need to to make the whole clock hierarchy available to DT.

Yes, you need a public ID to refer to a clock from DT.
Do you have an example where we would assigned-clock-rates it for a PLL? So far all users of assigned-clock-rates on Renesas SoCs use it on clocks that are already public as they are also needed as clock supplies in clocks properties (e.g. CAN-FD and SPI reference clocks).

Quoted 11 lines
Quoted 8 lines

Still, they can be internal enum, starting after the last DT clock, like we did in other R-Car clock drivers.

Quoted 1 line

you think that's an issue, could it cause ABI problems in the future ?

An ABI problem appears only when you refer in DT to a clock that does not exist in hardware. This should be caught by testing before the DT user is added.

So we could add e.g. SGASYNCD32 already, as long as we don't reference it in DT without testing.

We could, but which one: "_PERW_BUS" or "_PERW_MAIN"? Or both? And what's the point if there are no users?

BTW, there are 87 SGD4_* clocks listed in the documentation. They are all sourced from the same PLL, and have all the same clock rate. I don't think any of these can be gated. Hence if I would write a bare metal clock driver, I would just expose and instantiate a single SGD4 clock. But the current SCMI implementation exposes 87 different clocks (and didn't make them usable by Linux until recently)...

Perhaps we should drop the domain suffixes from the definitions? Even e.g. MSOCK_PERW_BUS and MSOCK_PERW_MAIN seem to be the same clock...

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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
#17 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Hi Geert,

Quoted 45 lines · Geert Uytterhoeven
Quoted 44 lines · Laurent Pinchart
Quoted 42 lines · Geert Uytterhoeven
Quoted 30 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

Quoted 7 lines

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.
Quoted 8 lines
Quoted 3 lines

That's missing n=4 and n=32. While SGASYNCD32 isn't referenced in the datasheet, SGASYNCD4 is (in SCIF and HSCIF). Maybe that's just an oversight ?

We already have the clocks for (H)SCIF (_BUS, not _MAIN!):

    #define R8A78000_CPG_SGASYNCD4_PERW_BUS         0
    #define R8A78000_CPG_SGASYNCD8_PERW_BUS         1

Wait... Aren't R8A78000_CPG_SGASYNCD8_PERW_MAIN and R8A78000_CPG_SGASYNCD8_PERW_BUS the same clock, just with a different name ? The user manual says _BUS, the clock diagram in the spreadsheet says _MAIN. The SCP firmware defines both, with the same parent (PLL5) and the same frequency. I have a feeling it may "just" be discrepancy between the user manual and the spreadsheets.

*sigh*

Quoted 44 lines
Quoted 36 lines
Quoted 27 lines

- R8A78000_CPG_SCPBUSDn_SCP_MAIN for n=16, and added the ones for

    n=1,2,4,6,8,32, too.
  - R8A78000_CPG_S0Dn_PERE_MAIN for n=24, and added the ones for
    n=1,2,3,4,8, too.

- R8A78000_CPG_SGDn_PERW_BUS for n=32, and added the ones for n=8, too.

I did not includes clocks with values for n that exist according to the documentation, but are not used as suppliers for modules. Of course the documentation may be incorrect or incomplete, and we may need to add them later. As IDs are ABI and the list is append-only, they must be added at the end, which could indeed lead to not all clocks of the same group being located together. From an ABI point of view that is OK, but from a human-readability point of view it is indeed suboptimal.

Before, we tended to add all clocks from the clock tables listed the documentation upfront, ignoring clocks that are clearly internal-only. Some of them turned out not to exist later.
Some new clocks had to be added when the documentation was updated. Nothing new here, except that the list of clocks on R-Car X5H is an order of magnitude longer.

Note that we don't use a linear array of clocks indexed by clock ID in the R-Car X5H CPG driver (yet), so large holes of unused clocks do not hurt (they do hurt in the SCMI driver ;-)

Quoted 5 lines
Quoted 1 line

not directly controllable. There's a risk of adding clocks that don't

FTR, the xDn clocks are not directly controllable; clocks like R8A78000_CPG_MSO_SCP_MAIN are. We know the latter exist, as they are used.

Yes, I was talking about the clocks documented in the various non-PLL "hierarchy" sections.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do

The direct parent of an MDLC-controlled module clock should be in DT.

An additional difficulty is that we don't actually know what clocks the MDLC gates :-/

Quoted 6 lines

This hasn't changed much: on other R-Car generations we also didn't know which clock(s) are gated by a single MSTP (Module SToP) bit. Historically (old SH parts), there was only a single clock supplying each module. Modules on later SoCs gained more clock supplies. Hence we always assumed (at least) the functional clock is gated by the MSTP bit, and modelled the gateable SMTP clocks as a child of the

Sometimes I want to gate everybody's SMTP clocks :D

Quoted 4 lines

functional clock parent. But it's quite possible other clock inputs to the module are gated, too, depending on the actual module (some modules e.g. need a PHY clock running to be able to process wake-up events).

Yes, it's not new.

/me wants to get a copy of the RTL alongside the user manual

Quoted 7 lines

Comparing older R-Car with R-Car Gen5, I actually like how the new MDLC block combines the power domain functionality of the old SYSC block and the clock domain functionality of the old MSSR (Module Standby and Software Reset) block. It improves upon the now imprecise modelling of MSTP clocks, and maps nicely on the Linux PM Domain abstraction:
- power domain: generic_pm_domain.power_{on,off}(domain),
- clock domain: generic_pm_domain.dev_ops.{start,stop}(device).

I *think* I like the resulting DT better. As the module standby feature is now listed in the power-domains property, even if we model it internally as a clock, it doesn't appear as a clock any more in DT. Clocks the drivers need have to be listed independently, which decouples them from the module standby.

Quoted 33 lines
Quoted 6 lines
Quoted 3 lines

Higher-up parents should not be needed iff the SCMI firmware exposed and/or implements the proper clock hierarchy (which it does not at the moment).

A big *iff* :-)

Quoted 7 lines

Even in that case, we'll have (at least) two issues:

- Some modules may need to know the rate of the functional clock gated by the MDLC. As those clocks are controlled through power domains, they are only specified as the last cell of the power-domains property, and are not listed in the clocks property. How do you envision this to work ?

The functional clock (or its parent) is still listed in the clocks property. Compare e.g. the hscif0 nodes on R-Car V4H:

    clocks = <&cpg CPG_MOD 514>,
             <&cpg CPG_CORE R8A779G0_CLK_SASYNCPERD1>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
    resets = <&cpg 514>;

and R-Car X5H:

    clocks = <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x54>;
    resets = <&mdlc_perw 0x54>;
Quoted 5 lines

On R-Car V4H, MSTP514 aka "hscif0" is modelled as a gateable MSTP clock with parent R8A779G0_CLK_SASYNCPERD1, and used as "fck". On R-Car X5H, R8A78000_CPG_SGASYNCD4_PERW_BUS is used as "fck" directly. Calling clk_get_rate() on MSTP514 and R8A78000_CPG_SGASYNCD4_PERW_BUS gives similar results.

On Gen5 we will then end up enabling the clock twice, once through the power domain, and once through the explicit clk_enable(fck) in the driver. I suppose that's fine in theory (there's an extra runtime cost though) as clocks are reference-counted. However, the current SCP firmware reference-counts the clocks based on their SCMI ID, and the MDLC clock (perw 0x54) and its parent (R8A78000_CPG_SGASYNCD4_PERW_BUS) have different IDs. This can cause the clock to be disabled at an unexpected point. In this specific case, however, given that R8A78000_CPG_SGASYNCD4_PERW_BUS isn't controllable, it won't cause an issue, but in the generic case it can fail badly.

Quoted 7 lines
Quoted 4 lines

- When multiple clocks derive from the same PLL, it's common for the PLL rate to be specified through assigned-clock-rates. If we want to continue doing that, we need to to make the whole clock hierarchy available to DT.

Yes, you need a public ID to refer to a clock from DT.
Do you have an example where we would assigned-clock-rates it for a PLL?

Not on Renesas platforms so far. I can imagine this being used to control for instance the whole VIO hierarchy. Depending on the bandwidth used by image sensors, system integrators may want to tweak the PLL frequency.

Quoted 9 lines

So far all users of assigned-clock-rates on Renesas SoCs use it on clocks that are already public as they are also needed as clock supplies in clocks properties (e.g. CAN-FD and SPI reference clocks).

Quoted 5 lines
Quoted 5 lines

Still, they can be internal enum, starting after the last DT clock, like we did in other R-Car clock drivers.

Quoted 1 line

you think that's an issue, could it cause ABI problems in the future ?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

An ABI problem appears only when you refer in DT to a clock that does not exist in hardware. This should be caught by testing before the DT user is added.

So we could add e.g. SGASYNCD32 already, as long as we don't reference it in DT without testing.

We could, but which one: "_PERW_BUS" or "_PERW_MAIN"? Or both?

See above :-)

Quoted 1 line

And what's the point if there are no users?

Future-proofing, to avoid adding the SGASYNCD32 clock later with a non-consecutive ID.

Quoted 9 lines

BTW, there are 87 SGD4_* clocks listed in the documentation. They are all sourced from the same PLL, and have all the same clock rate. I don't think any of these can be gated. Hence if I would write a bare metal clock driver, I would just expose and instantiate a single SGD4 clock. But the current SCMI implementation exposes 87 different clocks (and didn't make them usable by Linux until recently)...

Perhaps we should drop the domain suffixes from the definitions? Even e.g. MSOCK_PERW_BUS and MSOCK_PERW_MAIN seem to be the same clock...

I think we should also ask for names to be double-checked and fixed in the next version of the documentation.

Signature · 3 lines
Regards,

Laurent Pinchart
#18 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Hi Laurent,

Quoted 55 lines · Laurent Pinchart
Quoted 45 lines · Geert Uytterhoeven
Quoted 44 lines · Laurent Pinchart
Quoted 42 lines · Geert Uytterhoeven
Quoted 30 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

Quoted 7 lines

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.
Quoted 8 lines
Quoted 3 lines

That's missing n=4 and n=32. While SGASYNCD32 isn't referenced in the datasheet, SGASYNCD4 is (in SCIF and HSCIF). Maybe that's just an oversight ?

We already have the clocks for (H)SCIF (_BUS, not _MAIN!):

    #define R8A78000_CPG_SGASYNCD4_PERW_BUS         0
    #define R8A78000_CPG_SGASYNCD8_PERW_BUS         1
Quoted 8 lines

Wait... Aren't R8A78000_CPG_SGASYNCD8_PERW_MAIN and R8A78000_CPG_SGASYNCD8_PERW_BUS the same clock, just with a different name ? The user manual says _BUS, the clock diagram in the spreadsheet says _MAIN. The SCP firmware defines both, with the same parent (PLL5) and the same frequency. I have a feeling it may "just" be discrepancy between the user manual and the spreadsheets.

*sigh*

After my previous comment about "87 SGD4_* clocks" (quoted at the end), I started wondering if they are really identical and ungateable. The documentation calls each clock list a "clock hierarchy" (e.g. the PERW hierarchy), and each sublist another "clock hiearchy" (e.g. PERW_BUS vs. PERW_MAIN) which sounds like they are different. I also wouldn't be surprised if each (sub)hierarchy is gateable, too. So unless we can get clear confirmation, I'd rather be safe than sorry.

Quoted 70 lines
Quoted 44 lines
Quoted 36 lines
Quoted 27 lines

- R8A78000_CPG_SCPBUSDn_SCP_MAIN for n=16, and added the ones for

    n=1,2,4,6,8,32, too.
  - R8A78000_CPG_S0Dn_PERE_MAIN for n=24, and added the ones for
    n=1,2,3,4,8, too.

- R8A78000_CPG_SGDn_PERW_BUS for n=32, and added the ones for n=8, too.

I did not includes clocks with values for n that exist according to the documentation, but are not used as suppliers for modules. Of course the documentation may be incorrect or incomplete, and we may need to add them later. As IDs are ABI and the list is append-only, they must be added at the end, which could indeed lead to not all clocks of the same group being located together. From an ABI point of view that is OK, but from a human-readability point of view it is indeed suboptimal.

Before, we tended to add all clocks from the clock tables listed the documentation upfront, ignoring clocks that are clearly internal-only. Some of them turned out not to exist later.
Some new clocks had to be added when the documentation was updated. Nothing new here, except that the list of clocks on R-Car X5H is an order of magnitude longer.

Note that we don't use a linear array of clocks indexed by clock ID in the R-Car X5H CPG driver (yet), so large holes of unused clocks do not hurt (they do hurt in the SCMI driver ;-)

Quoted 5 lines
Quoted 1 line

not directly controllable. There's a risk of adding clocks that don't

FTR, the xDn clocks are not directly controllable; clocks like R8A78000_CPG_MSO_SCP_MAIN are. We know the latter exist, as they are used.

Yes, I was talking about the clocks documented in the various non-PLL "hierarchy" sections.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do

The direct parent of an MDLC-controlled module clock should be in DT.

An additional difficulty is that we don't actually know what clocks the MDLC gates :-/

Quoted 6 lines

This hasn't changed much: on other R-Car generations we also didn't know which clock(s) are gated by a single MSTP (Module SToP) bit. Historically (old SH parts), there was only a single clock supplying each module. Modules on later SoCs gained more clock supplies. Hence we always assumed (at least) the functional clock is gated by the MSTP bit, and modelled the gateable SMTP clocks as a child of the

Sometimes I want to gate everybody's SMTP clocks :D

Quoted 4 lines

functional clock parent. But it's quite possible other clock inputs to the module are gated, too, depending on the actual module (some modules e.g. need a PHY clock running to be able to process wake-up events).

Yes, it's not new.

/me wants to get a copy of the RTL alongside the user manual

Quoted 7 lines

Comparing older R-Car with R-Car Gen5, I actually like how the new MDLC block combines the power domain functionality of the old SYSC block and the clock domain functionality of the old MSSR (Module Standby and Software Reset) block. It improves upon the now imprecise modelling of MSTP clocks, and maps nicely on the Linux PM Domain abstraction:
- power domain: generic_pm_domain.power_{on,off}(domain),
- clock domain: generic_pm_domain.dev_ops.{start,stop}(device).

Quoted 5 lines

I *think* I like the resulting DT better. As the module standby feature is now listed in the power-domains property, even if we model it internally as a clock, it doesn't appear as a clock any more in DT. Clocks the drivers need have to be listed independently, which decouples them from the module standby.

Agreed.

Quoted 39 lines
Quoted 33 lines
Quoted 6 lines
Quoted 3 lines

Higher-up parents should not be needed iff the SCMI firmware exposed and/or implements the proper clock hierarchy (which it does not at the moment).

A big *iff* :-)

Quoted 7 lines

Even in that case, we'll have (at least) two issues:

- Some modules may need to know the rate of the functional clock gated by the MDLC. As those clocks are controlled through power domains, they are only specified as the last cell of the power-domains property, and are not listed in the clocks property. How do you envision this to work ?

The functional clock (or its parent) is still listed in the clocks property. Compare e.g. the hscif0 nodes on R-Car V4H:

    clocks = <&cpg CPG_MOD 514>,
             <&cpg CPG_CORE R8A779G0_CLK_SASYNCPERD1>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
    resets = <&cpg 514>;

and R-Car X5H:

    clocks = <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x54>;
    resets = <&mdlc_perw 0x54>;
Quoted 5 lines

On R-Car V4H, MSTP514 aka "hscif0" is modelled as a gateable MSTP clock with parent R8A779G0_CLK_SASYNCPERD1, and used as "fck". On R-Car X5H, R8A78000_CPG_SGASYNCD4_PERW_BUS is used as "fck" directly. Calling clk_get_rate() on MSTP514 and R8A78000_CPG_SGASYNCD4_PERW_BUS gives similar results.

Quoted 3 lines

On Gen5 we will then end up enabling the clock twice, once through the power domain, and once through the explicit clk_enable(fck) in the driver. I suppose that's fine in theory (there's an extra runtime cost

It depends, and can only be true for drivers that still do explicit clock management. Many drivers that don't need to know anything (e.g. the rate) about the clock have been modified to delegate this fully to Runtime PM.

On R-Car Gen5, the (now purely internal) module clock used for module standby is different from the "fck" clock in DT. So perw 0x54 is controlled through Runtime PM, and SGASYNCD4_PERW_BUS is controlled by the SCIF driver directly (but it is a no-op as the bus clock is always-on).

On previous R-Car generations, "fck" is the module clock, and is enabled twice.

Quoted 7 lines

though) as clocks are reference-counted. However, the current SCP firmware reference-counts the clocks based on their SCMI ID, and the MDLC clock (perw 0x54) and its parent (R8A78000_CPG_SGASYNCD4_PERW_BUS) have different IDs. This can cause the clock to be disabled at an unexpected point. In this specific case, however, given that R8A78000_CPG_SGASYNCD4_PERW_BUS isn't controllable, it won't cause an issue, but in the generic case it can fail badly.

Current SCP firmware indeed doesn't handle parent-child relations:
e.g. perw 0x54 has a clock rate of zero, and is not a child of SGASYNCD4_PERW_BUS. So the MDLC remapping driver ended up becoming responsible for controlling the parent clock if it is gateable, which is the case for e.g. MSIOF (see mod_map_in.fw_fck_parent).

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

- When multiple clocks derive from the same PLL, it's common for the PLL rate to be specified through assigned-clock-rates. If we want to continue doing that, we need to to make the whole clock hierarchy available to DT.

Quoted 7 lines
Quoted 2 lines

Yes, you need a public ID to refer to a clock from DT.
Do you have an example where we would assigned-clock-rates it for a PLL?

Not on Renesas platforms so far. I can imagine this being used to control for instance the whole VIO hierarchy. Depending on the bandwidth used by image sensors, system integrators may want to tweak the PLL frequency.

A definition can be added when needed. Note that SCMI does not expose the PLLs to any agent anyway...

Quoted 16 lines
Quoted 16 lines

So far all users of assigned-clock-rates on Renesas SoCs use it on clocks that are already public as they are also needed as clock supplies in clocks properties (e.g. CAN-FD and SPI reference clocks).

Quoted 11 lines
Quoted 8 lines

Still, they can be internal enum, starting after the last DT clock, like we did in other R-Car clock drivers.

Quoted 1 line

you think that's an issue, could it cause ABI problems in the future ?

An ABI problem appears only when you refer in DT to a clock that does not exist in hardware. This should be caught by testing before the DT user is added.

So we could add e.g. SGASYNCD32 already, as long as we don't reference it in DT without testing.

Quoted 8 lines
Quoted 1 line

We could, but which one: "_PERW_BUS" or "_PERW_MAIN"? Or both?

See above :-)

Quoted 1 line

And what's the point if there are no users?

Future-proofing, to avoid adding the SGASYNCD32 clock later with a non-consecutive ID.

Then perhaps we should add all clocks from the spreadsheet upfront?

Quoted 7 lines
Quoted 7 lines

BTW, there are 87 SGD4_* clocks listed in the documentation. They are all sourced from the same PLL, and have all the same clock rate. I don't think any of these can be gated. Hence if I would write a bare metal clock driver, I would just expose and instantiate a single SGD4 clock. But the current SCMI implementation exposes 87 different clocks (and didn't make them usable by Linux until recently)...

Quoted 5 lines
Quoted 2 lines

Perhaps we should drop the domain suffixes from the definitions? Even e.g. MSOCK_PERW_BUS and MSOCK_PERW_MAIN seem to be the same clock...

I think we should also ask for names to be double-checked and fixed in the next version of the documentation.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
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
#19 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Quoted 63 lines · Geert Uytterhoeven
Quoted 62 lines · Laurent Pinchart
Quoted 45 lines · Geert Uytterhoeven
Quoted 44 lines · Laurent Pinchart
Quoted 42 lines · Geert Uytterhoeven
Quoted 30 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

Quoted 7 lines

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.
Quoted 8 lines
Quoted 3 lines

That's missing n=4 and n=32. While SGASYNCD32 isn't referenced in the datasheet, SGASYNCD4 is (in SCIF and HSCIF). Maybe that's just an oversight ?

We already have the clocks for (H)SCIF (_BUS, not _MAIN!):

    #define R8A78000_CPG_SGASYNCD4_PERW_BUS         0
    #define R8A78000_CPG_SGASYNCD8_PERW_BUS         1

Wait... Aren't R8A78000_CPG_SGASYNCD8_PERW_MAIN and R8A78000_CPG_SGASYNCD8_PERW_BUS the same clock, just with a different name ? The user manual says _BUS, the clock diagram in the spreadsheet says _MAIN. The SCP firmware defines both, with the same parent (PLL5) and the same frequency. I have a feeling it may "just" be discrepancy between the user manual and the spreadsheets.

Quoted 7 lines
Quoted 1 line

*sigh*

After my previous comment about "87 SGD4_* clocks" (quoted at the end), I started wondering if they are really identical and ungateable. The documentation calls each clock list a "clock hierarchy" (e.g. the PERW hierarchy), and each sublist another "clock hiearchy" (e.g. PERW_BUS vs. PERW_MAIN) which sounds like they are different.

I only see PERW_MAIN, not PERW_BUS. There's a PERW_MAIN_MP sub-hierarchy though. And I'm fairly sure there are errors in the diagrams (at least in the VIO hierarchy).

Quoted 2 lines

I also wouldn't be surprised if each (sub)hierarchy is gateable, too. So unless we can get clear confirmation, I'd rather be safe than sorry.

I haven't found any sign neither in the documentation nor in the SCP firmware sources that those would be gateable. If they are, they are not gated by default.

In any case, I think it would make sense to model in DT all the clocks listed in the diagrams. That should make it possible to properly handle gates after the fact, should there be any.

Quoted 117 lines
Quoted 70 lines
Quoted 44 lines
Quoted 36 lines
Quoted 27 lines

- R8A78000_CPG_SCPBUSDn_SCP_MAIN for n=16, and added the ones for

    n=1,2,4,6,8,32, too.
  - R8A78000_CPG_S0Dn_PERE_MAIN for n=24, and added the ones for
    n=1,2,3,4,8, too.

- R8A78000_CPG_SGDn_PERW_BUS for n=32, and added the ones for n=8, too.

I did not includes clocks with values for n that exist according to the documentation, but are not used as suppliers for modules. Of course the documentation may be incorrect or incomplete, and we may need to add them later. As IDs are ABI and the list is append-only, they must be added at the end, which could indeed lead to not all clocks of the same group being located together. From an ABI point of view that is OK, but from a human-readability point of view it is indeed suboptimal.

Before, we tended to add all clocks from the clock tables listed the documentation upfront, ignoring clocks that are clearly internal-only. Some of them turned out not to exist later.
Some new clocks had to be added when the documentation was updated. Nothing new here, except that the list of clocks on R-Car X5H is an order of magnitude longer.

Note that we don't use a linear array of clocks indexed by clock ID in the R-Car X5H CPG driver (yet), so large holes of unused clocks do not hurt (they do hurt in the SCMI driver ;-)

Quoted 5 lines
Quoted 1 line

not directly controllable. There's a risk of adding clocks that don't

FTR, the xDn clocks are not directly controllable; clocks like R8A78000_CPG_MSO_SCP_MAIN are. We know the latter exist, as they are used.

Yes, I was talking about the clocks documented in the various non-PLL "hierarchy" sections.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

exist, or clocks that we won't need to reference from DT (because they're only used as parents of the MDLC-controlled module clock). Do

The direct parent of an MDLC-controlled module clock should be in DT.

An additional difficulty is that we don't actually know what clocks the MDLC gates :-/

Quoted 6 lines

This hasn't changed much: on other R-Car generations we also didn't know which clock(s) are gated by a single MSTP (Module SToP) bit. Historically (old SH parts), there was only a single clock supplying each module. Modules on later SoCs gained more clock supplies. Hence we always assumed (at least) the functional clock is gated by the MSTP bit, and modelled the gateable SMTP clocks as a child of the

Sometimes I want to gate everybody's SMTP clocks :D

Quoted 4 lines

functional clock parent. But it's quite possible other clock inputs to the module are gated, too, depending on the actual module (some modules e.g. need a PHY clock running to be able to process wake-up events).

Yes, it's not new.

/me wants to get a copy of the RTL alongside the user manual

Quoted 7 lines

Comparing older R-Car with R-Car Gen5, I actually like how the new MDLC block combines the power domain functionality of the old SYSC block and the clock domain functionality of the old MSSR (Module Standby and Software Reset) block. It improves upon the now imprecise modelling of MSTP clocks, and maps nicely on the Linux PM Domain abstraction:
- power domain: generic_pm_domain.power_{on,off}(domain),
- clock domain: generic_pm_domain.dev_ops.{start,stop}(device).

Quoted 5 lines

I *think* I like the resulting DT better. As the module standby feature is now listed in the power-domains property, even if we model it internally as a clock, it doesn't appear as a clock any more in DT. Clocks the drivers need have to be listed independently, which decouples them from the module standby.

Agreed.

Quoted 39 lines
Quoted 38 lines
Quoted 6 lines
Quoted 3 lines

Higher-up parents should not be needed iff the SCMI firmware exposed and/or implements the proper clock hierarchy (which it does not at the moment).

A big *iff* :-)

Quoted 7 lines

Even in that case, we'll have (at least) two issues:

- Some modules may need to know the rate of the functional clock gated by the MDLC. As those clocks are controlled through power domains, they are only specified as the last cell of the power-domains property, and are not listed in the clocks property. How do you envision this to work ?

The functional clock (or its parent) is still listed in the clocks property. Compare e.g. the hscif0 nodes on R-Car V4H:

    clocks = <&cpg CPG_MOD 514>,
             <&cpg CPG_CORE R8A779G0_CLK_SASYNCPERD1>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
    resets = <&cpg 514>;

and R-Car X5H:

    clocks = <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x54>;
    resets = <&mdlc_perw 0x54>;

On R-Car V4H, MSTP514 aka "hscif0" is modelled as a gateable MSTP clock with parent R8A779G0_CLK_SASYNCPERD1, and used as "fck". On R-Car X5H, R8A78000_CPG_SGASYNCD4_PERW_BUS is used as "fck" directly. Calling clk_get_rate() on MSTP514 and R8A78000_CPG_SGASYNCD4_PERW_BUS gives similar results.

Quoted 6 lines
Quoted 3 lines

On Gen5 we will then end up enabling the clock twice, once through the power domain, and once through the explicit clk_enable(fck) in the driver. I suppose that's fine in theory (there's an extra runtime cost

It depends, and can only be true for drivers that still do explicit clock management.

Yes, I forgot to mention that.

Quoted 9 lines

Many drivers that don't need to know anything
(e.g. the rate) about the clock have been modified to delegate this fully to Runtime PM.

On R-Car Gen5, the (now purely internal) module clock used for module standby is different from the "fck" clock in DT. So perw 0x54 is controlled through Runtime PM, and SGASYNCD4_PERW_BUS is controlled by the SCIF driver directly (but it is a no-op as the bus clock is always-on).

I expect the FCK input of the IP core to be connected to the clock gated by the MDLC. Using SGASYNCD4_PERW_BUS in DT is likely inaccurate. It should work fine for now as the SCP firmware doesn't make the clock controllable, but I'm not sure that the bus clock is really always on. The dividers listed in the CPGMA* diagrams typically have clock gating capability.

Quoted 11 lines

On previous R-Car generations, "fck" is the module clock, and is enabled twice.

Quoted 7 lines

though) as clocks are reference-counted. However, the current SCP firmware reference-counts the clocks based on their SCMI ID, and the MDLC clock (perw 0x54) and its parent (R8A78000_CPG_SGASYNCD4_PERW_BUS) have different IDs. This can cause the clock to be disabled at an unexpected point. In this specific case, however, given that R8A78000_CPG_SGASYNCD4_PERW_BUS isn't controllable, it won't cause an issue, but in the generic case it can fail badly.

Quoted 5 lines

Current SCP firmware indeed doesn't handle parent-child relations:
e.g. perw 0x54 has a clock rate of zero, and is not a child of SGASYNCD4_PERW_BUS. So the MDLC remapping driver ended up becoming responsible for controlling the parent clock if it is gateable, which is the case for e.g. MSIOF (see mod_map_in.fw_fck_parent).

It's worse than that. The firmware doesn't implement parent-child relationships, but sometimes it tries to control the parent independently from different children :-(

Look for instance at the DPCKCR register. bit CKSTP is documented as gating the DP_EXT_VIO_DP[012] clocks. I expect that bit to actually gate the parent clock, DP_EXT_VIO (from CPGMA1). However, the three separate DP_EXT_VIO_DP[012] clocks exposed by the SCMI firmware (and named SCP_CLOCK_ID_CLK_DP_EXT_OTHER[012] because consistent names wouldn't be confusing enough) all map to the DPCKCR.CKSTP bit in the backend, and are reference-counted separately.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

- When multiple clocks derive from the same PLL, it's common for the PLL rate to be specified through assigned-clock-rates. If we want to continue doing that, we need to to make the whole clock hierarchy available to DT.

Yes, you need a public ID to refer to a clock from DT.
Do you have an example where we would assigned-clock-rates it for a PLL?

Quoted 7 lines
Quoted 4 lines

Not on Renesas platforms so far. I can imagine this being used to control for instance the whole VIO hierarchy. Depending on the bandwidth used by image sensors, system integrators may want to tweak the PLL frequency.

A definition can be added when needed. Note that SCMI does not expose the PLLs to any agent anyway...

*sigh* x2

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

So far all users of assigned-clock-rates on Renesas SoCs use it on clocks that are already public as they are also needed as clock supplies in clocks properties (e.g. CAN-FD and SPI reference clocks).

Quoted 11 lines
Quoted 8 lines

Still, they can be internal enum, starting after the last DT clock, like we did in other R-Car clock drivers.

Quoted 1 line

you think that's an issue, could it cause ABI problems in the future ?

An ABI problem appears only when you refer in DT to a clock that does not exist in hardware. This should be caught by testing before the DT user is added.

So we could add e.g. SGASYNCD32 already, as long as we don't reference it in DT without testing.

We could, but which one: "_PERW_BUS" or "_PERW_MAIN"? Or both?

Quoted 8 lines
Quoted 6 lines

See above :-)

Quoted 1 line

And what's the point if there are no users?

Future-proofing, to avoid adding the SGASYNCD32 clock later with a non-consecutive ID.

Then perhaps we should add all clocks from the spreadsheet upfront?

It's tempting. Maybe doing it per-hierarchy ? When enabling devices in the VIO hierachy, I ended up verifying most of the clocks anyway. We can then try to spot all inconsistencies and ask for confirmation.

Quoted 12 lines
Quoted 12 lines
Quoted 9 lines

BTW, there are 87 SGD4_* clocks listed in the documentation. They are all sourced from the same PLL, and have all the same clock rate. I don't think any of these can be gated. Hence if I would write a bare metal clock driver, I would just expose and instantiate a single SGD4 clock. But the current SCMI implementation exposes 87 different clocks (and didn't make them usable by Linux until recently)...

Perhaps we should drop the domain suffixes from the definitions? Even e.g. MSOCK_PERW_BUS and MSOCK_PERW_MAIN seem to be the same clock...

I think we should also ask for names to be double-checked and fixed in the next version of the documentation.

Signature · 3 lines
Regards,

Laurent Pinchart
#20 lore raw

Re: [PATCH 07/11] dt-bindings: clock: renesas,r8a78000-cpg: Add PWM clocks

Hi Laurent,

Quoted 72 lines · Laurent Pinchart
Quoted 63 lines · Geert Uytterhoeven
Quoted 62 lines · Laurent Pinchart
Quoted 45 lines · Geert Uytterhoeven
Quoted 44 lines · Laurent Pinchart
Quoted 42 lines · Geert Uytterhoeven
Quoted 30 lines · Laurent Pinchart
Quoted 24 lines · Geert Uytterhoeven
Quoted 8 lines · Laurent Pinchart
Quoted 6 lines · Geert Uytterhoeven

Add definitions for the clocks used by the PWM modules on R-Car X5H:
- R8A78000_CPG_SGASYNCD16_PERW_MAIN,
- R8A78000_CPG_S0ASYNCD8_PERW_MAIN.
Include R8A78000_CPG_SGASYNCD8_PERW_MAIN for ordering consistency.

Quoted 14 lines

include/dt-bindings/clock/renesas,r8a78000-cpg.h line 32

Quoted 8 lines
include/dt-bindings/clock/renesas,r8a78000-cpg.h +2 -0
@@ -28,5 +28,8 @@
 #define R8A78000_CPG_SGD8_PERW_BUS           18
 #define R8A78000_CPG_SGD32_PERW_BUS          19
 #define R8A78000_CPG_S0D24_HSCN_OTHER                20
+#define R8A78000_CPG_SGASYNCD8_PERW_MAIN     21
+#define R8A78000_CPG_SGASYNCD16_PERW_MAIN    22

Could you also add R8A78000_CPG_SGASYNCD4_PERW_MAIN and R8A78000_CPG_SGASYNCD32_PERW_MAIN for ordering consistency ? The dependency patch should then also include R8A78000_CPG_SGD4_PERW_BUS and R8A78000_CPG_SGD16_PERW_BUS, as well as R8A78000_CPG_S0D{1,2,4,8,12,16}_HSCN_OTHER.

Quoted 4 lines

I could add them, but do you have any need to refer to them from DT? So far I only added clocks that are listed as clock supplies of on-SoC modules, e.g. R8A78000_CPG_SGASYNCD8_PERW_MAIN is supplied to the Timer Unit (TMU)).

Quoted 7 lines

So we have two conflicting goals here. One of them is to only add clocks that we have validated to exist (and ideally work as documented). The other is to keep renesas,r8a78000-cpg.h readable. We won't be able to satisfy them both fully.

I think we previously discussed adding whole groups of dividers in one go, as some sort of middle-ground approach. Those are clocks that are

That is what did in this and the previous patch: we need
- R8A78000_CPG_SGASYNCDn_PERW_MAIN for n=16, and added the one for

    n=8, too.
Quoted 8 lines
Quoted 3 lines

That's missing n=4 and n=32. While SGASYNCD32 isn't referenced in the datasheet, SGASYNCD4 is (in SCIF and HSCIF). Maybe that's just an oversight ?

We already have the clocks for (H)SCIF (_BUS, not _MAIN!):

    #define R8A78000_CPG_SGASYNCD4_PERW_BUS         0
    #define R8A78000_CPG_SGASYNCD8_PERW_BUS         1

Wait... Aren't R8A78000_CPG_SGASYNCD8_PERW_MAIN and R8A78000_CPG_SGASYNCD8_PERW_BUS the same clock, just with a different name ? The user manual says _BUS, the clock diagram in the spreadsheet says _MAIN. The SCP firmware defines both, with the same parent (PLL5) and the same frequency. I have a feeling it may "just" be discrepancy between the user manual and the spreadsheets.

Quoted 7 lines
Quoted 1 line

*sigh*

After my previous comment about "87 SGD4_* clocks" (quoted at the end), I started wondering if they are really identical and ungateable. The documentation calls each clock list a "clock hierarchy" (e.g. the PERW hierarchy), and each sublist another "clock hiearchy" (e.g. PERW_BUS vs. PERW_MAIN) which sounds like they are different.

Quoted 3 lines

I only see PERW_MAIN, not PERW_BUS. There's a PERW_MAIN_MP sub-hierarchy though. And I'm fairly sure there are errors in the diagrams (at least in the VIO hierarchy).

The clock diagram indeed doesn't have PERW_BUS clocks, while the clock list does have both, and the main document refers to them as clock supplies for e.g. (H)SCIF and I2C. Sole exception is LBCK_PERW_MAIN, which is in the diagram, but not in the list; the latter has LBCK_PERW_BUS.

Note that S0ASYNCD8_PERW_{BUS,MAIN} is even listed twice, with different divider chains, but still resulting in the same final rate.

For e.g. VIO, _MAIN in the clock diagram and _BUS in the clock list indeed seem to be synonyms.

Quoted 10 lines
Quoted 2 lines

I also wouldn't be surprised if each (sub)hierarchy is gateable, too. So unless we can get clear confirmation, I'd rather be safe than sorry.

I haven't found any sign neither in the documentation nor in the SCP firmware sources that those would be gateable. If they are, they are not gated by default.

In any case, I think it would make sense to model in DT all the clocks listed in the diagrams. That should make it possible to properly handle gates after the fact, should there be any.

In DT, we only model supplies and consumers, so only tail clocks from the diagrams (i.e. what's in the lists)?

Quoted 44 lines
Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 5 lines

- Some modules may need to know the rate of the functional clock gated by the MDLC. As those clocks are controlled through power domains, they are only specified as the last cell of the power-domains property, and are not listed in the clocks property. How do you envision this to work ?

The functional clock (or its parent) is still listed in the clocks property. Compare e.g. the hscif0 nodes on R-Car V4H:

    clocks = <&cpg CPG_MOD 514>,
             <&cpg CPG_CORE R8A779G0_CLK_SASYNCPERD1>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
    resets = <&cpg 514>;

and R-Car X5H:

    clocks = <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&cpg R8A78000_CPG_SGASYNCD4_PERW_BUS>,
             <&scif_clk>;
    clock-names = "fck", "brg_int", "scif_clk";
    power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x54>;
    resets = <&mdlc_perw 0x54>;

On R-Car V4H, MSTP514 aka "hscif0" is modelled as a gateable MSTP clock with parent R8A779G0_CLK_SASYNCPERD1, and used as "fck". On R-Car X5H, R8A78000_CPG_SGASYNCD4_PERW_BUS is used as "fck" directly. Calling clk_get_rate() on MSTP514 and R8A78000_CPG_SGASYNCD4_PERW_BUS gives similar results.

Quoted 6 lines
Quoted 3 lines

On Gen5 we will then end up enabling the clock twice, once through the power domain, and once through the explicit clk_enable(fck) in the driver. I suppose that's fine in theory (there's an extra runtime cost

It depends, and can only be true for drivers that still do explicit clock management.

Yes, I forgot to mention that.

Quoted 4 lines

Many drivers that don't need to know anything
(e.g. the rate) about the clock have been modified to delegate this fully to Runtime PM.

Quoted 7 lines
Quoted 5 lines

On R-Car Gen5, the (now purely internal) module clock used for module standby is different from the "fck" clock in DT. So perw 0x54 is controlled through Runtime PM, and SGASYNCD4_PERW_BUS is controlled by the SCIF driver directly (but it is a no-op as the bus clock is always-on).

I expect the FCK input of the IP core to be connected to the clock gated

At least the FCK input.

Quoted 5 lines

by the MDLC. Using SGASYNCD4_PERW_BUS in DT is likely inaccurate. It should work fine for now as the SCP firmware doesn't make the clock controllable, but I'm not sure that the bus clock is really always on. The dividers listed in the CPGMA* diagrams typically have clock gating capability.

E.g. DIV6 dividers (like the MSIOF parent) do have clock gating.

Quoted 17 lines
Quoted 11 lines

On previous R-Car generations, "fck" is the module clock, and is enabled twice.

Quoted 7 lines

though) as clocks are reference-counted. However, the current SCP firmware reference-counts the clocks based on their SCMI ID, and the MDLC clock (perw 0x54) and its parent (R8A78000_CPG_SGASYNCD4_PERW_BUS) have different IDs. This can cause the clock to be disabled at an unexpected point. In this specific case, however, given that R8A78000_CPG_SGASYNCD4_PERW_BUS isn't controllable, it won't cause an issue, but in the generic case it can fail badly.

Quoted 5 lines

Current SCP firmware indeed doesn't handle parent-child relations:
e.g. perw 0x54 has a clock rate of zero, and is not a child of SGASYNCD4_PERW_BUS. So the MDLC remapping driver ended up becoming responsible for controlling the parent clock if it is gateable, which is the case for e.g. MSIOF (see mod_map_in.fw_fck_parent).

Quoted 3 lines

It's worse than that. The firmware doesn't implement parent-child relationships, but sometimes it tries to control the parent independently from different children :-(

Bad...

Quoted 3 lines

Look for instance at the DPCKCR register. bit CKSTP is documented as gating the DP_EXT_VIO_DP[012] clocks. I expect that bit to actually gate the parent clock, DP_EXT_VIO (from CPGMA1). However, the three separate

Agreed.

So DP_EXT_VIO_DP[012] are/can be modeled as the same clock?

Quoted 4 lines

DP_EXT_VIO_DP[012] clocks exposed by the SCMI firmware (and named SCP_CLOCK_ID_CLK_DP_EXT_OTHER[012] because consistent names wouldn't be confusing enough) all map to the DPCKCR.CKSTP bit in the backend, and are reference-counted separately.

That is really bad.

Are the DP_EXT_VIO_DP[012] clocks functional clock parents? If yes, the MDLC remapping driver can work around this by always controlling all three together when module standby is controlled. If no, the CPG remapping driver probably has to return a new clock type that controls all three together.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

So we could add e.g. SGASYNCD32 already, as long as we don't reference it in DT without testing.

We could, but which one: "_PERW_BUS" or "_PERW_MAIN"? Or both?

See above :-)

Quoted 1 line

And what's the point if there are no users?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Future-proofing, to avoid adding the SGASYNCD32 clock later with a non-consecutive ID.

Then perhaps we should add all clocks from the spreadsheet upfront?

It's tempting. Maybe doing it per-hierarchy ? When enabling devices in the VIO hierachy, I ended up verifying most of the clocks anyway. We can then try to spot all inconsistencies and ask for confirmation.

It is indeed tempting, and would match what we did for previous R-Car SoCs. Having unused definitions is not that bad, it might just increase a linear table used in an xlate function (which we currently don't have in the CPG driver).

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

author maintainer
#21 lore raw

PATCH 8/11 arm64: dts: renesas: r8a78000: Add PWM nodes

In reply to Geert Uytterhoeven

Add device nodes for the Pulse Width Modulation (PWM) modules and the 16-Bit Timer Pulse Unit (TPU) on the Renesas R-Car X5H (R8A78000) SoC.

---
 arch/arm64/boot/dts/renesas/r8a78000.dtsi | 121 ++++++++++++++++++++++
 1 file changed, 121 insertions(+)
arch/arm64/boot/dts/renesas/r8a78000.dtsi +121 -0
index 946dce6ab38b619d..c5e48eac4c3712d8 100644
@@ -1243,6 +1243,127 @@ hscif3: serial@c071c000 {
 			status = "disabled";
 		};
 
+		tpu: pwm@c0720000 {
+			compatible = "renesas,tpu-r8a78000", "renesas,tpu";
+			reg = <0 0xc0720000 0 0x200>;
+			interrupts = <GIC_ESPI 23 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cpg R8A78000_CPG_SGASYNCD16_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x76>;
+			resets = <&mdlc_perw 0x76>;
+			#pwm-cells = <3>;
+			status = "disabled";
+		};
+
+		pwm0: pwm@c0740000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0740000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_SGASYNCD16_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm1: pwm@c0741000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0741000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_SGASYNCD16_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm2: pwm@c0742000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0742000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_SGASYNCD16_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm3: pwm@c0743000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0743000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_SGASYNCD16_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm4: pwm@c0780000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0780000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_S0ASYNCD8_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm5: pwm@c0781000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0781000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_S0ASYNCD8_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm6: pwm@c0782000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0782000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_S0ASYNCD8_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm7: pwm@c0783000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0783000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_S0ASYNCD8_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm8: pwm@c0784000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0784000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_S0ASYNCD8_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
+		pwm9: pwm@c0785000 {
+			compatible = "renesas,pwm-r8a78000",
+				     "renesas,rcar-gen5-pwm";
+			reg = <0 0xc0785000 0 0x10>;
+			#pwm-cells = <2>;
+			clocks = <&cpg R8A78000_CPG_S0ASYNCD8_PERW_MAIN>;
+			power-domains = <&mdlc_perw R8A78000_MDLC_PD_APL 0x70>;
+			resets = <&mdlc_perw 0x70>;
+			status = "disabled";
+		};
+
 		stcm_transport: sram@c1060000 {
 			compatible = "mmio-sram";
 			reg = <0x0 0xc1060000 0x0 0x1c00>;
Signature · 1 line
2.43.0
author maintainer
#22 lore raw

PATCH 9/11 clk: renesas: r8a78000: Add PWM clocks

In reply to Geert Uytterhoeven

Add support for the clocks used by the PWM modules on R-Car X5H. This includes SCMI remapping tables and fixed-clock fallbacks.

---
This depends on "[PATCH/DNI 4/7] clk: renesas: r8a78000: Add GPIO clocks"
https://lore.kernel.org/34f97dab00c6d98b7afe8d8df38eeb83abf5c19f.1792776697.git.geert+renesas@glider.be

---
 drivers/clk/renesas/r8a78000-cpg.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clk/renesas/r8a78000-cpg.c +6 -0
index 1d66082f6f44b5ba..9b1ff5a8ff1bdc31 100644
@@ -38,6 +38,7 @@ enum fixed_clk {
 	FIXED_CLK_33M,
 	FIXED_CLK_37M5,
 	FIXED_CLK_66M,
+	FIXED_CLK_100M,
 	FIXED_CLK_133M,
 	FIXED_CLK_266M,
 };
@@ -46,6 +47,7 @@ static const unsigned long fixed_clk_rates[] = {
 	[FIXED_CLK_33M] = 33333000,
 	[FIXED_CLK_37M5] = 37500000,
 	[FIXED_CLK_66M] = 66666000,
+	[FIXED_CLK_100M] = 100000000,
 	[FIXED_CLK_133M] = 133330000,
 	[FIXED_CLK_266M] = 266660000,
 };
@@ -299,6 +301,8 @@ static const struct clk_map_in r8a78000_cpg_default[] = {
 	{ R8A78000_CPG_S0D24_PERE_MAIN,		FIXED_CLK(33M) },
 	{ R8A78000_CPG_SGD32_PERW_BUS,		FIXED_CLK(33M) },
 	{ R8A78000_CPG_S0D24_HSCN_OTHER,	FIXED_CLK(33M) },
+	{ R8A78000_CPG_SGASYNCD16_PERW_MAIN,	FIXED_CLK(66M) },
+	{ R8A78000_CPG_S0ASYNCD8_PERW_MAIN,	FIXED_CLK(100M) },
 	{ -1 }
 };
 
@@ -312,6 +316,8 @@ static const struct clk_map_in r8a78000_cpg_fw[] = {
 	{ R8A78000_CPG_S0D24_PERE_MAIN,		1690 },
 	{ R8A78000_CPG_SGD32_PERW_BUS,		1660 },
 	{ R8A78000_CPG_S0D24_HSCN_OTHER,	1499 },
+	{ R8A78000_CPG_SGASYNCD16_PERW_MAIN,	1651 },
+	{ R8A78000_CPG_S0ASYNCD8_PERW_MAIN,	1653 },
 	{ -1 }
 };
 
Signature · 1 line
2.43.0
author maintainer
#23 lore raw

PATCH 10/11 pmdomain: renesas: r8a78000: Add PWM support

In reply to Geert Uytterhoeven

Add support for the Pulse Width Modulation (PWM) modules and the 16-Bit Timer Pulse Unit (TPU) on R-Car X5H.

---
This depends on "[PATCH v4 7/8] pmdomain: renesas: r8a78000: Add SCMI remapping support"
https://lore.kernel.org/2895c8f3cbe718dc597ad25e16c2461f0d681ab6.1792163045.git.geert+renesas@glider.be/

---
 drivers/pmdomain/renesas/r8a78000-mdlc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pmdomain/renesas/r8a78000-mdlc.c +2 -0
index 838566ed821e29e0..62156bfb8080e6e4 100644
@@ -681,6 +681,8 @@ static const struct mod_map_in r8a78000_mdlc_perw_mod_fw[] = {
 	{ 0x55, 225, -1 },	/* HSCIF1 */
 	{ 0x56, 226, -1 },	/* HSCIF2 */
 	{ 0x57, 227, -1 },	/* HSCIF3 */
+	{ 0x70, 244, -1 },	/* PWM0 */
+	{ 0x76, 249, -1 },	/* TPU0 */
 	{ -1 }
 };
 
Signature · 1 line
2.43.0
author maintainer
#24 lore raw

PATCH 11/11 arm64: dts: renesas: ironhide: Enable PWM

In reply to Geert Uytterhoeven

Pulse Width Modulation (PWM) instances 0 to 5 and 16-Bit Timer Pulse Unit (TPU) channels 0 and 1 are wired to PWM CN (CN48).

Note that TPU channels 0 and 1 are mutually-exclusive with PWM instances 4 and 5.

---
This depends on out-of-tree pin control support.

---
 .../boot/dts/renesas/r8a78000-ironhide.dts    | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
arch/arm64/boot/dts/renesas/r8a78000-ironhide.dts +84 -0
index 5d919953efe4970e..c2d814da9fd97802 100644
@@ -242,10 +242,87 @@ msiof6_pins: msiof6 {
 
 	};
 
+	pwm0_pins: pwm0 {
+		groups = "pwm0_a";
+		function = "pwm0";
+	};
+
+	pwm1_pins: pwm1 {
+		groups = "pwm1";
+		function = "pwm1";
+	};
+
+	pwm2_pins: pwm2 {
+		groups = "pwm2";
+		function = "pwm2";
+	};
+
+	pwm3_pins: pwm3 {
+		groups = "pwm3";
+		function = "pwm3";
+	};
+
+	pwm4_pins: pwm4 {
+		groups = "pwm4";
+		function = "pwm4";
+	};
+
+	pwm5_pins: pwm5 {
+		groups = "pwm5";
+		function = "pwm5";
+	};
+
 	scif_clk_pins: scif-clk {
 		groups = "scif_clk";
 		function = "scif_clk";
 	};
+
+	tpu_pins: tpu {
+		groups = "tpu_to0", "tpu_to1";
+		function = "tpu";
+	};
+};
+
+&pwm0 {
+	pinctrl-0 = <&pwm0_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
+};
+
+&pwm1 {
+	pinctrl-0 = <&pwm1_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
+};
+
+&pwm2 {
+	pinctrl-0 = <&pwm2_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
+};
+
+&pwm3 {
+	pinctrl-0 = <&pwm3_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
+};
+
+&pwm4 {
+	pinctrl-0 = <&pwm4_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
+};
+
+&pwm5 {
+	pinctrl-0 = <&pwm5_pins>;
+	pinctrl-names = "default";
+
+	status = "okay";
 };
 
 &scif_clk {
@@ -263,3 +340,10 @@ scmi_rx_shmem: sram@1300 {
 		reg = <0x1300 0x100>;
 	};
 };
+
+&tpu {
+	pinctrl-0 = <&tpu_pins>;
+	pinctrl-names = "default";
+
+	//status = "okay";	// Mutually-exclusive with pwm4 and pwm5
+};
Signature · 1 line
2.43.0