Commit 3dd7ed58 authored by Emil Renner Berthing's avatar Emil Renner Berthing Committed by Pavel Machek

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: default avatarEmil Renner Berthing <emil.renner.berthing@canonical.com>
Reviewed-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent 83543c6e
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
struct pwm_led { struct pwm_led {
struct pwm_device *pwm; struct pwm_device *pwm;
struct pwm_state state; struct pwm_state state;
bool active_low;
}; };
struct pwm_mc_led { struct pwm_mc_led {
...@@ -45,6 +46,9 @@ static int led_pwm_mc_set(struct led_classdev *cdev, ...@@ -45,6 +46,9 @@ static int led_pwm_mc_set(struct led_classdev *cdev,
duty *= mc_cdev->subled_info[i].brightness; duty *= mc_cdev->subled_info[i].brightness;
do_div(duty, cdev->max_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.duty_cycle = duty;
priv->leds[i].state.enabled = duty > 0; priv->leds[i].state.enabled = duty > 0;
ret = pwm_apply_state(priv->leds[i].pwm, ret = pwm_apply_state(priv->leds[i].pwm,
...@@ -76,6 +80,7 @@ static int iterate_subleds(struct device *dev, struct pwm_mc_led *priv, ...@@ -76,6 +80,7 @@ static int iterate_subleds(struct device *dev, struct pwm_mc_led *priv,
goto release_fwnode; goto release_fwnode;
} }
pwm_init_state(pwmled->pwm, &pwmled->state); 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); ret = fwnode_property_read_u32(fwnode, "color", &color);
if (ret) { if (ret) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment