Skip to contentSkip to conversation

pwm: brcmstb: Support configurable open-drain mode

PATCH In review Florian Fainelli 5 participants 10 messages Oct 12, 2024 – Nov 28, 2024

Subsystems (4)
lore
Share & tools
lore

Florian Fainelli

author maintainer
#0 lore raw

cover pwm: brcmstb: Support configurable open-drain mode

This patch series updates the pwm-brcmstb driver to not assume an open-drain mode, but instead get that sort of configuration from Device Tree using the 'open-drain' property.

Florian Fainelli (2):
dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property
pwm: brcmstb: Do not assume open drain configuration

 .../devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml          | 6 ++++++
 drivers/pwm/pwm-brcmstb.c                                  | 7 +++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/2 dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property

Document the 'open-drain' property that allows configuring the PWM controller outputs in open drain versus totem pole.

---
 Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +6 -0
index 119de3d7f9dd..12851c43a612 100644
@@ -25,6 +25,12 @@ properties:
   clocks:
     maxItems: 1
 
+  open-drain:
+    type: boolean
+    description:
+      Configure the outputs with open-drain structure, if omitted totem pole
+      structure is used.
+
 required:
   - compatible
   - reg
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 1/2] dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property

Quoted 13 lines · Florian Fainelli

Document the 'open-drain' property that allows configuring the PWM controller outputs in open drain versus totem pole.

---
 Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +0 -0
index 119de3d7f9dd..12851c43a612 100644

Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml properties: · line 33

Quoted 9 lines
Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +6 -0
@@ -25,6 +25,12 @@ properties:
   clocks:
     maxItems: 1
 
+  open-drain:
+    type: boolean
+    description:
+      Configure the outputs with open-drain structure, if omitted totem pole
+      structure is used.
+

There's one other PWM with 'open-drain' so move the definition to pwm.yaml.

Alternatively, 'drive-open-drain' is a much more commonly used variation.

Another thing to consider is for any PWM controller with more than 1 output, you might want this to be per output and therefore should be a flag in the cells.

Rob

#3 lore raw

Re: [PATCH 1/2] dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property

Quoted 17 lines · Rob Herring
Quoted 16 lines · Florian Fainelli

Document the 'open-drain' property that allows configuring the PWM controller outputs in open drain versus totem pole.

---
  Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml | 6 ++++++
  1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +0 -0
index 119de3d7f9dd..12851c43a612 100644
@@ -25,6 +25,12 @@ properties:
    clocks:
      maxItems: 1
 
Quoted 9 lines

Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml properties: · line 33

Quoted 6 lines
Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +6 -0
+  open-drain:
+    type: boolean
+    description:
+      Configure the outputs with open-drain structure, if omitted totem pole
+      structure is used.
+

There's one other PWM with 'open-drain' so move the definition to pwm.yaml.

Ah indeed, there is one now, great.

Quoted 3 lines

Alternatively, 'drive-open-drain' is a much more commonly used variation.

That name works just as well.

Quoted 4 lines

Another thing to consider is for any PWM controller with more than 1 output, you might want this to be per output and therefore should be a flag in the cells.

Yes, that is a good point, this controller has two channels, so it seems like increasing the #pwm-cells might be the way to go.

Thanks!

Signature · 1 line
Florian
#4 lore raw

Re: [PATCH 1/2] dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property

Hello,

Quoted 7 lines · Florian Fainelli
Quoted 3 lines · Rob Herring

Another thing to consider is for any PWM controller with more than 1 output, you might want this to be per output and therefore should be a flag in the cells.

Yes, that is a good point, this controller has two channels, so it seems like increasing the #pwm-cells might be the way to go.

So the idea is something like:

include/dt-bindings/pwm/pwm.h +1 -0
index ab9a077e3c7d..d18b006a7399 100644
@@ -11,5 +11,6 @@
 #define _DT_BINDINGS_PWM_PWM_H
 
 #define PWM_POLARITY_INVERTED			(1 << 0)
+#define PWM_OUTPUT_OPEN_DRAIN			(1 << 1)
 
 #endif

and then add support for that to the core and drivers? There is some intersection with pinctrl (depending on hardware). I wonder if abstracting this somehow using the typical pinctrl properties would be a saner option??

Best regards
Uwe

author maintainer
#5 lore raw

Re: [PATCH 1/2] dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property

Quoted 25 lines · Uwe Kleine-König

Hello,

Quoted 7 lines · Florian Fainelli
Quoted 3 lines · Rob Herring

Another thing to consider is for any PWM controller with more than 1 output, you might want this to be per output and therefore should be a flag in the cells.

Yes, that is a good point, this controller has two channels, so it seems like increasing the #pwm-cells might be the way to go.

So the idea is something like:

include/dt-bindings/pwm/pwm.h +1 -0
index ab9a077e3c7d..d18b006a7399 100644
@@ -11,5 +11,6 @@
  #define _DT_BINDINGS_PWM_PWM_H
 
  #define PWM_POLARITY_INVERTED			(1 << 0)
+#define PWM_OUTPUT_OPEN_DRAIN			(1 << 1)
 
  #endif
Quoted 4 lines

and then add support for that to the core and drivers? There is some intersection with pinctrl (depending on hardware). I wonder if abstracting this somehow using the typical pinctrl properties would be a saner option??

But what if the pin is not managed by a pinctrl provider? I have started going the route of implementing the PWM_OUTPUT_OPEN_DRAIN bit as an additional specifier in the #pwm-cells, but I am not sure to what extent this should be allowed to be changed at runtime.

Signature · 1 line
Florian
#6 lore raw

Re: [PATCH 1/2] dt-bindings: pwm: brcm,bcm7038: Document the 'open-drain' property

Hello Florian,

[adding Linus and linux-gpio to Cc:]

Quoted 22 lines · Florian Fainelli
Quoted 21 lines · Uwe Kleine-König
Quoted 7 lines · Florian Fainelli
Quoted 3 lines · Rob Herring

Another thing to consider is for any PWM controller with more than 1 output, you might want this to be per output and therefore should be a flag in the cells.

Yes, that is a good point, this controller has two channels, so it seems like increasing the #pwm-cells might be the way to go.

So the idea is something like:

include/dt-bindings/pwm/pwm.h +1 -0
index ab9a077e3c7d..d18b006a7399 100644
@@ -11,5 +11,6 @@
  #define _DT_BINDINGS_PWM_PWM_H
  #define PWM_POLARITY_INVERTED			(1 << 0)
+#define PWM_OUTPUT_OPEN_DRAIN			(1 << 1)
  #endif
 
Quoted 6 lines
Quoted 4 lines

and then add support for that to the core and drivers? There is some intersection with pinctrl (depending on hardware). I wonder if abstracting this somehow using the typical pinctrl properties would be a saner option??

But what if the pin is not managed by a pinctrl provider?

Then create one? If that's the PWM itself that is the pinctrl device it would look as follows:

	pwm@f0408000 {
		compatible = "brcm,bcm7038-pwm";
		pinctrl-0 = <&pwm_pins>;
		reg = <0xf0408000 0x28>;
		#pwm-cells = <2>;
		#pinctrl-cells = <0>;
		clocks = <&upg_fixed>;
		
		pinctrl {
			pwm_pins: pwm-pins {
				pins = "A", "B";
				drive-open-drain;
			};
		};
	};

Maybe this is difficult if there is a pinctrl that configures the output as "PWM" and then there is that additional register in the PWM IP to make this pin open drain? One could just use

	pinctrl-0 = <&pwm_pins>, <&system_pinctrl_pwm>;

then. Not entirely sure this is overengineered, but the dt representation would be nice (IMHO). Thoughts?

Quoted 4 lines

I have started
going the route of implementing the PWM_OUTPUT_OPEN_DRAIN bit as an additional specifier in the #pwm-cells, but I am not sure to what extent this should be allowed to be changed at runtime.

I would not expect that the open-drainness needs to change at runtime.

Best regards
Uwe

author maintainer
#7 lore raw

PATCH 2/2 pwm: brcmstb: Do not assume open drain configuration

In reply to Florian Fainelli

Read the 'open-drain' property to determine whether the PWM controller output(s) should be configured in open-drain versus totem pole mode.

Fixes 3a9f5957020f ("pwm: Add Broadcom BCM7038 PWM controller support")
---
 drivers/pwm/pwm-brcmstb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/pwm/pwm-brcmstb.c +5 -2
index 0fdeb0b2dbf3..b7cecd36ed57 100644
@@ -55,6 +55,7 @@ struct brcmstb_pwm {
 	void __iomem *base;
 	struct clk *clk;
 	struct pwm_chip chip;
+	bool open_drain;
 };
 
 static inline u32 brcmstb_pwm_readl(struct brcmstb_pwm *p,
@@ -176,6 +177,7 @@ static int brcmstb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 static inline void brcmstb_pwm_enable_set(struct brcmstb_pwm *p,
 					  unsigned int channel, bool enable)
 {
+	u32 oe_mask = p->open_drain ? CTRL_OPENDRAIN : 0;
 	unsigned int shift = channel * CTRL_CHAN_OFFS;
 	u32 value;
 
@@ -183,9 +185,9 @@ static inline void brcmstb_pwm_enable_set(struct brcmstb_pwm *p,
 
 	if (enable) {
 		value &= ~(CTRL_OEB << shift);
-		value |= (CTRL_START | CTRL_OPENDRAIN) << shift;
+		value |= (CTRL_START | oe_mask) << shift;
 	} else {
-		value &= ~((CTRL_START | CTRL_OPENDRAIN) << shift);
+		value &= ~((CTRL_START | oe_mask) << shift);
 		value |= CTRL_OEB << shift;
 	}
 
@@ -244,6 +246,7 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, p);
 
+	p->open_drain = device_property_read_bool(&pdev->dev, "open-drain");
 	p->chip.dev = &pdev->dev;
 	p->chip.ops = &brcmstb_pwm_ops;
 	p->chip.npwm = 2;
Signature · 1 line
2.34.1
#8 lore raw
In reply to Florian Fainelli

Hello Florian,

Quoted 3 lines · Florian Fainelli

This patch series updates the pwm-brcmstb driver to not assume an open-drain mode, but instead get that sort of configuration from Device Tree using the 'open-drain' property.

Just for me to be sure to understand correctly: A kernel without your patch #2 behaves identical to a kernel with that patch if the open-drain property is present, right?

It's not clear to me why totem-pole is the better default and the commit logs don't justify the updated default. Can you improve here?

Best regards
Uwe

#9 lore raw
Quoted 10 lines · Uwe Kleine-König

Hello Florian,

Quoted 3 lines · Florian Fainelli

This patch series updates the pwm-brcmstb driver to not assume an open-drain mode, but instead get that sort of configuration from Device Tree using the 'open-drain' property.

Just for me to be sure to understand correctly: A kernel without your patch #2 behaves identical to a kernel with that patch if the open-drain property is present, right?

I don't think it does. Patch #2 breaks the ABI, IMO.

Quoted 4 lines

It's not clear to me why totem-pole is the better default and the commit logs don't justify the updated default. Can you improve here?

Best regards,
Krzysztof