pwm: brcmstb: Support configurable open-drain mode
Subsystems (4)
Florian Fainelli
maintainercover 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
Florian Fainelli
maintainerPATCH 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
@@ -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
Rob Herring
maintainerRe: [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.
Signed-off-by Florian Fainelli <[email protected]>--- Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +0
-0
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
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.
Signed-off-by Florian Fainelli <[email protected]>--- Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml +0
-0@@ -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
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
@@ -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
Florian Fainelli
maintainerRe: [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@@ -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
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@@ -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 thePWM_OUTPUT_OPEN_DRAINbit 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
Florian Fainelli
maintainerPATCH 2/2 pwm: brcmstb: Do not assume open drain configuration
In reply to Florian FainelliRead the 'open-drain' property to determine whether the PWM controller output(s) should be configured in open-drain versus totem pole mode.
--- drivers/pwm/pwm-brcmstb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/pwm/pwm-brcmstb.c +5 -2
@@ -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
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
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