Skip to contentSkip to conversation

pwm: pxa: Use #pwm-cells = <3>

PATCH In review Uwe Kleine-König 2 participants 7 messages Feb 6, 2025 – Feb 11, 2025

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

v2 cover pwm: pxa: Use #pwm-cells = <3>

Hello,

this series' goal is to soften the special device-tree binding of marvel,pxa-pwm devices. This is the only binding that doesn't pass the line index as first parameter.

Here the #pwm-cells value is bumped from 1 to 3, keeping compatibility with the old binding.

The motivation for this was that Hervé sent a patch introducing pwm nexus nodes which don't work nicely with the marvel,pxa-pwm particularities.

Changes since (implicit) v1, available at
https://lore.kernel.org/linux-pwm/[email protected]:

- Use #pwm-cells = <3> also in the binding example (*sigh*), pointed out by Rob
- Add review, ack and test tags by Hervé Codina, Conor Dooley, Duje Mihanović and Daniel Mack. Thanks!

I intend to take the first patch via my pwm tree. Assuming the pxa and device tree maintainers and bots are happy now: Dear pxa maintainers, please tell if I should take the whole series via pwm, or if you want to take patches #2 and #3. If the latter: Do you want to delay application or should I provide an immutable branch for patch #1?

Best regards
Uwe

Uwe Kleine-König (3):
pwm: Add upgrade path to #pwm-cells = <3> for users of
of_pwm_single_xlate()
dt-bindings: pwm: marvell,pxa-pwm: Update to use #pwm-cells = <3>
ARM: dts: pxa: Use #pwm-cells = <3> for marvell,pxa-pwm devices

 .../devicetree/bindings/pwm/marvell,pxa-pwm.yaml |  5 ++---
 arch/arm/boot/dts/intel/pxa/pxa25x.dtsi          |  4 ++--
 arch/arm/boot/dts/intel/pxa/pxa27x.dtsi          |  8 ++++----
 .../dts/intel/pxa/pxa300-raumfeld-controller.dts |  2 +-
 arch/arm/boot/dts/intel/pxa/pxa3xx.dtsi          |  8 ++++----
 drivers/pwm/core.c                               | 16 ++++++++++++++++
 6 files changed, 29 insertions(+), 14 deletions(-)

base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b

Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 1/3 pwm: Add upgrade path to #pwm-cells = <3> for users of of_pwm_single_xlate()

The PWM chip on PXA only has a single output. Back when the device tree binding was defined it was considered a good idea to not pass the PWM line index as is done for all other PWM types as it would be always zero anyhow and so doesn't add any value.

However for consistency reasons it is nice when all PWMs use the same binding. For that reason let of_pwm_single_xlate() (i.e. the function that implements the PXA behaviour) behave in the same way as of_pwm_xlate_with_flags() for 3 (or more) parameters. With that in place, the pxa-pwm binding can be updated to #pwm-cells = <3> without breaking old device trees that stick to #pwm-cells = <1>.

---
 drivers/pwm/core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/pwm/core.c +16 -0
index ccd54c089bab..bc05818fa370 100644
@@ -1000,11 +1000,27 @@ of_pwm_xlate_with_flags(struct pwm_chip *chip, const struct of_phandle_args *arg
 }
 EXPORT_SYMBOL_GPL(of_pwm_xlate_with_flags);
 
+/*
+ * This callback is used for PXA PWM chips that only have a single PWM line.
+ * For such chips you could argue that passing the line number (i.e. the first
+ * parameter in the common case) is useless as it's always zero. So compared to
+ * the default xlate function of_pwm_xlate_with_flags() the first parameter is
+ * the default period and the second are flags.
+ *
+ * Note that if #pwm-cells = <3>, the semantic is the same as for
+ * of_pwm_xlate_with_flags() to allow converting the affected driver to
+ * #pwm-cells = <3> without breaking the legacy binding.
+ *
+ * Don't use for new drivers.
+ */
 struct pwm_device *
 of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
 {
 	struct pwm_device *pwm;
 
+	if (args->args_count >= 3)
+		return of_pwm_xlate_with_flags(chip, args);
+
 	pwm = pwm_request_from_chip(chip, 0, NULL);
 	if (IS_ERR(pwm))
 		return pwm;
Signature · 1 line
2.47.1
#2 lore raw

PATCH v2 2/3 dt-bindings: pwm: marvell,pxa-pwm: Update to use #pwm-cells = <3>

In reply to Uwe Kleine-König

The PXA PWM binding is the only one that doesn't pass the PWM line index as first parameter of the parameter cells. However this can be upgraded to the mandatory binding for all new PWM drivers without breaking compatibility for old device trees using #pwm-cells = <1>.

So bump #pwm-cells to 3 with the (undocumented) promise to keep the old behaviour for #pwm-cells = <1>.

---
 Documentation/devicetree/bindings/pwm/marvell,pxa-pwm.yaml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/pwm/marvell,pxa-pwm.yaml +2 -3
index 9ee1946dc2e1..74f2d5964742 100644
@@ -25,8 +25,7 @@ properties:
     maxItems: 1
 
   "#pwm-cells":
-    # Used for specifying the period length in nanoseconds
-    const: 1
+    const: 3
 
   clocks:
     maxItems: 1
@@ -45,6 +44,6 @@ examples:
     pwm0: pwm@40b00000 {
       compatible = "marvell,pxa250-pwm";
       reg = <0x40b00000 0x10>;
-      #pwm-cells = <1>;
+      #pwm-cells = <3>;
       clocks = <&clks CLK_PWM0>;
     };
Signature · 1 line
2.47.1
maintainer
#3 lore raw

Re: [PATCH v2 2/3] dt-bindings: pwm: marvell,pxa-pwm: Update to use #pwm-cells = <3>

Quoted 7 lines · Uwe Kleine-König

The PXA PWM binding is the only one that doesn't pass the PWM line index as first parameter of the parameter cells. However this can be upgraded to the mandatory binding for all new PWM drivers without breaking compatibility for old device trees using #pwm-cells = <1>.

So bump #pwm-cells to 3 with the (undocumented) promise to keep the old behaviour for #pwm-cells = <1>.

Why make that undocumented?

Quoted 14 lines
---
 Documentation/devicetree/bindings/pwm/marvell,pxa-pwm.yaml | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/pwm/marvell,pxa-pwm.yaml +0 -0
index 9ee1946dc2e1..74f2d5964742 100644

Documentation/devicetree/bindings/pwm/marvell,pxa-pwm.yaml properties: · line 28

Quoted 6 lines
Documentation/devicetree/bindings/pwm/marvell,pxa-pwm.yaml +1 -2
@@ -25,8 +25,7 @@ properties:
     maxItems: 1
 
   "#pwm-cells":
-    # Used for specifying the period length in nanoseconds
-    const: 1
+    const: 3

Note that if we apply this and not the dts change, we'll add warnings.

You could instead do:

oneOf:
- const: 1
deprecated: true
- const: 3

#4 lore raw

PATCH v2 3/3 ARM: dts: pxa: Use #pwm-cells = <3> for marvell,pxa-pwm devices

In reply to Uwe Kleine-König

For consistency with most other pwm bindings, also use 3 cells for phandles to PWM devices.

---
 arch/arm/boot/dts/intel/pxa/pxa25x.dtsi                   | 4 ++--
 arch/arm/boot/dts/intel/pxa/pxa27x.dtsi                   | 8 ++++----
 .../arm/boot/dts/intel/pxa/pxa300-raumfeld-controller.dts | 2 +-
 arch/arm/boot/dts/intel/pxa/pxa3xx.dtsi                   | 8 ++++----
 4 files changed, 11 insertions(+), 11 deletions(-)
arch/arm/boot/dts/intel/pxa/pxa25x.dtsi +2 -2
index 5f8300e356ad..d25065caeebc 100644
@@ -67,14 +67,14 @@ gpio: gpio@40e00000 {
 		pwm0: pwm@40b00000 {
 			compatible = "marvell,pxa250-pwm";
 			reg = <0x40b00000 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM0>;
 		};
 
 		pwm1: pwm@40b00010 {
 			compatible = "marvell,pxa250-pwm";
 			reg = <0x40b00010 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM1>;
 		};
 
arch/arm/boot/dts/intel/pxa/pxa27x.dtsi +4 -4
index a2cbfb3be609..ed07b65cc362 100644
@@ -49,28 +49,28 @@ usb0: usb@4c000000 {
 		pwm0: pwm@40b00000 {
 			compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm";
 			reg = <0x40b00000 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM0>;
 		};
 
 		pwm1: pwm@40b00010 {
 			compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm";
 			reg = <0x40b00010 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM1>;
 		};
 
 		pwm2: pwm@40c00000 {
 			compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm";
 			reg = <0x40c00000 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM0>;
 		};
 
 		pwm3: pwm@40c00010 {
 			compatible = "marvell,pxa270-pwm", "marvell,pxa250-pwm";
 			reg = <0x40c00010 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM1>;
 		};
 
arch/arm/boot/dts/intel/pxa/pxa300-raumfeld-controller.dts +1 -1
index 12b15945ac6d..9094ec422577 100644
@@ -56,7 +56,7 @@ backlight-controller-pwm {
 		compatible = "pwm-backlight";
 		pinctrl-names = "default";
 		pinctrl-0 = <&pwm0_pins>;
-		pwms = <&pwm0 10000>;
+		pwms = <&pwm0 0 10000 0>;
 		power-supply = <&reg_vbatt>;
 		status = "disabled";
 
arch/arm/boot/dts/intel/pxa/pxa3xx.dtsi +4 -4
index f9c216f91865..4e69b4da0ba6 100644
@@ -224,7 +224,7 @@ usb0: usb@4c000000 {
 		pwm0: pwm@40b00000 {
 			compatible = "marvell,pxa270-pwm";
 			reg = <0x40b00000 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM0>;
 			status = "disabled";
 		};
@@ -232,7 +232,7 @@ pwm0: pwm@40b00000 {
 		pwm1: pwm@40b00010 {
 			compatible = "marvell,pxa270-pwm";
 			reg = <0x40b00010 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM1>;
 			status = "disabled";
 		};
@@ -240,7 +240,7 @@ pwm1: pwm@40b00010 {
 		pwm2: pwm@40c00000 {
 			compatible = "marvell,pxa270-pwm";
 			reg = <0x40c00000 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM0>;
 			status = "disabled";
 		};
@@ -248,7 +248,7 @@ pwm2: pwm@40c00000 {
 		pwm3: pwm@40c00010 {
 			compatible = "marvell,pxa270-pwm";
 			reg = <0x40c00010 0x10>;
-			#pwm-cells = <1>;
+			#pwm-cells = <3>;
 			clocks = <&clks CLK_PWM1>;
 			status = "disabled";
 		};
Signature · 1 line
2.47.1
#5 lore raw
In reply to Uwe Kleine-König
Quoted 21 lines · Uwe Kleine-König

Hello,

this series' goal is to soften the special device-tree binding of marvel,pxa-pwm devices. This is the only binding that doesn't pass the line index as first parameter.

Here the #pwm-cells value is bumped from 1 to 3, keeping compatibility with the old binding.

The motivation for this was that Hervé sent a patch introducing pwm nexus nodes which don't work nicely with the marvel,pxa-pwm particularities.

Changes since (implicit) v1, available at
https://lore.kernel.org/linux-pwm/[email protected]:

- Use #pwm-cells = <3> also in the binding example (*sigh*), pointed out by Rob
- Add review, ack and test tags by Hervé Codina, Conor Dooley, Duje Mihanović and Daniel Mack. Thanks!

Quoted 5 lines

I intend to take the first patch via my pwm tree. Assuming the pxa and device tree maintainers and bots are happy now: Dear pxa maintainers, please tell if I should take the whole series via pwm, or if you want to take patches #2 and #3. If the latter: Do you want to delay application or should I provide an immutable branch for patch #1?

I applied patch #1 to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next now.

I don't know yet what should happen to the two other patches, but maybe it's a good idea to wait a bit anyhow to have 3 cells working for the pxa driver for a kernel release or two before we switch it.

Best regards
Uwe

maintainer
#6 lore raw
Quoted 28 lines · Uwe Kleine-König
Quoted 21 lines · Uwe Kleine-König

Hello,

this series' goal is to soften the special device-tree binding of marvel,pxa-pwm devices. This is the only binding that doesn't pass the line index as first parameter.

Here the #pwm-cells value is bumped from 1 to 3, keeping compatibility with the old binding.

The motivation for this was that Hervé sent a patch introducing pwm nexus nodes which don't work nicely with the marvel,pxa-pwm particularities.

Changes since (implicit) v1, available at
https://lore.kernel.org/linux-pwm/[email protected]:

- Use #pwm-cells = <3> also in the binding example (*sigh*), pointed out by Rob
- Add review, ack and test tags by Hervé Codina, Conor Dooley, Duje Mihanović and Daniel Mack. Thanks!

Quoted 5 lines

I intend to take the first patch via my pwm tree. Assuming the pxa and device tree maintainers and bots are happy now: Dear pxa maintainers, please tell if I should take the whole series via pwm, or if you want to take patches #2 and #3. If the latter: Do you want to delay application or should I provide an immutable branch for patch #1?

Quoted 7 lines

I applied patch #1 to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next now.

I don't know yet what should happen to the two other patches, but maybe it's a good idea to wait a bit anyhow to have 3 cells working for the pxa driver for a kernel release or two before we switch it.

The dts change will never work with a kernel without patch 1. You can somewhat mitigate that by backporting patch 1 to stable. If users aren't doing stable updates, they might not be doing dtb updates either...

Rob