summaryrefslogtreecommitdiff
path: root/drivers/leds
diff options
context:
space:
mode:
authorEmil Renner Berthing <emil.renner.berthing@canonical.com>2022-07-06 00:01:42 +0300
committerPavel Machek <pavel@ucw.cz>2022-07-17 14:02:09 +0300
commit3dd7ed589f2eda3904ab4b9fc49bbbc6d450d7f3 (patch)
tree0d676c1067688c3d44f8afc9df6d8ef5788805d7 /drivers/leds
parent83543c6e54b9dd18950533fff730e68c19cc053a (diff)
downloadlinux-3dd7ed589f2eda3904ab4b9fc49bbbc6d450d7f3.tar.xz
leds: pwm-multicolor: Support active-low LEDs
Add support for LEDs wired up to light when the PWM output is low, just like the regular PWM LEDs. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Pavel Machek <pavel@ucw.cz>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/rgb/leds-pwm-multicolor.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/leds/rgb/leds-pwm-multicolor.c b/drivers/leds/rgb/leds-pwm-multicolor.c
index eb67b89d28e9..da9d2218ae18 100644
--- a/drivers/leds/rgb/leds-pwm-multicolor.c
+++ b/drivers/leds/rgb/leds-pwm-multicolor.c
@@ -19,6 +19,7 @@
struct pwm_led {
struct pwm_device *pwm;
struct pwm_state state;
+ bool active_low;
};
struct pwm_mc_led {
@@ -45,6 +46,9 @@ static int led_pwm_mc_set(struct led_classdev *cdev,
duty *= mc_cdev->subled_info[i].brightness;
do_div(duty, cdev->max_brightness);
+ if (priv->leds[i].active_low)
+ duty = priv->leds[i].state.period - duty;
+
priv->leds[i].state.duty_cycle = duty;
priv->leds[i].state.enabled = duty > 0;
ret = pwm_apply_state(priv->leds[i].pwm,
@@ -76,6 +80,7 @@ static int iterate_subleds(struct device *dev, struct pwm_mc_led *priv,
goto release_fwnode;
}
pwm_init_state(pwmled->pwm, &pwmled->state);
+ pwmled->active_low = fwnode_property_read_bool(fwnode, "active-low");
ret = fwnode_property_read_u32(fwnode, "color", &color);
if (ret) {