diff mbox series

[2/2] pwm: brcmstb: Do not assume open drain configuration

Message ID 20241012025603.1644451-3-florian.fainelli@broadcom.com
State New
Headers show
Series pwm: brcmstb: Support configurable open-drain mode | expand

Commit Message

Florian Fainelli Oct. 12, 2024, 2:56 a.m. UTC
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")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 drivers/pwm/pwm-brcmstb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-brcmstb.c b/drivers/pwm/pwm-brcmstb.c
index 0fdeb0b2dbf3..b7cecd36ed57 100644
--- a/drivers/pwm/pwm-brcmstb.c
+++ b/drivers/pwm/pwm-brcmstb.c
@@ -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;