]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
pwm: tegra: add set_invert PWM operation
authorJonas Schwöbel <jonasschwoebel@yahoo.de>
Tue, 11 Mar 2025 22:06:46 +0000 (23:06 +0100)
committerSvyatoslav Ryhel <clamor95@gmail.com>
Sun, 22 Mar 2026 12:43:26 +0000 (14:43 +0200)
Add active-low support to the PWM controller, useful for active-low
pwm-leds.

Signed-off-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
drivers/pwm/tegra_pwm.c

index 919728b821fa690bbcdc5a662e755c855cad42ca..4b57751f73f1718913c24519c8376125b0f915ad 100644 (file)
 
 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)
 {
@@ -29,6 +42,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;
@@ -80,6 +96,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[] = {