summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJonas Schwöbel <[email protected]>2025-03-11 23:06:46 +0100
committerSvyatoslav Ryhel <[email protected]>2026-03-22 14:43:26 +0200
commit0623b8512e2d9128100949ca80ede990ed80f741 (patch)
tree3115179f7c679c1800275773c2d6b03d9ed84010 /drivers
parent5dcdbcf7833ae762866c43cbd872ba910576d228 (diff)
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 <[email protected]> Signed-off-by: Svyatoslav Ryhel <[email protected]>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/pwm/tegra_pwm.c17
1 files changed, 17 insertions, 0 deletions
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[] = {