From: Jonas Schwöbel Date: Tue, 11 Mar 2025 22:06:46 +0000 (+0100) Subject: pwm: tegra: add set_invert PWM operation X-Git-Tag: v2026.07-rc1~63^2~17^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0623b8512e2d9128100949ca80ede990ed80f741;p=thirdparty%2Fu-boot.git pwm: tegra: add set_invert PWM operation Add active-low support to the PWM controller, useful for active-low pwm-leds. Signed-off-by: Jonas Schwöbel Signed-off-by: Svyatoslav Ryhel --- diff --git a/drivers/pwm/tegra_pwm.c b/drivers/pwm/tegra_pwm.c index 919728b821f..4b57751f73f 100644 --- a/drivers/pwm/tegra_pwm.c +++ b/drivers/pwm/tegra_pwm.c @@ -13,8 +13,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) { @@ -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[] = {