[PATCH v1 2/4] pwm: tegra: add set_invert PWM operation

Svyatoslav Ryhel clamor95 at gmail.com
Mon Feb 9 19:03:24 CET 2026


From: Jonas Schwöbel <jonasschwoebel at yahoo.de>

Add active-low support to the PWM controller, useful for active-low
pwm-leds.

Signed-off-by: Jonas Schwöbel <jonasschwoebel at yahoo.de>
Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
---
 drivers/pwm/tegra_pwm.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/pwm/tegra_pwm.c b/drivers/pwm/tegra_pwm.c
index 7105d6db90d..3d398490408 100644
--- a/drivers/pwm/tegra_pwm.c
+++ b/drivers/pwm/tegra_pwm.c
@@ -12,8 +12,21 @@
 
 struct tegra_pwm_priv {
 	struct pwm_ctlr *regs;
+	u8 polarity;
 };
 
+static int tegra_pwm_set_invert(struct udevice *dev, uint channel, bool polarity)
+{
+	struct tegra_pwm_priv *priv = dev_get_priv(dev);
+
+	if (channel >= 4)
+		return -EINVAL;
+
+	clrsetbits_8(&priv->polarity, BIT(channel), (polarity << channel));
+
+	return 0;
+}
+
 static int tegra_pwm_set_config(struct udevice *dev, uint channel,
 				uint period_ns, uint duty_ns)
 {
@@ -28,6 +41,9 @@ static int tegra_pwm_set_config(struct udevice *dev, uint channel,
 
 	pulse_width = duty_ns * 255 / period_ns;
 
+	if (priv->polarity & BIT(channel))
+		pulse_width = 256 - pulse_width;
+
 	reg = pulse_width << PWM_WIDTH_SHIFT;
 	reg |= 1 << PWM_DIVIDER_SHIFT;
 	reg |= PWM_ENABLE_MASK;
@@ -72,6 +88,7 @@ static int tegra_pwm_probe(struct udevice *dev)
 static const struct pwm_ops tegra_pwm_ops = {
 	.set_config	= tegra_pwm_set_config,
 	.set_enable	= tegra_pwm_set_enable,
+	.set_invert	= tegra_pwm_set_invert,
 };
 
 static const struct udevice_id tegra_pwm_ids[] = {
-- 
2.51.0



More information about the U-Boot mailing list