From: Ahmad Fatoum <a.fat...@pengutronix.de>

To support PWM_POLARITY_INVERTED for PWM LEDs, we need to to use the
apply API.  Do so.

Signed-off-by: Ahmad Fatoum <a.fat...@pengutronix.de>
---
 drivers/led/led-pwm.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 4935572ec2d2..19d9d4d48a3d 100644
--- a/drivers/led/led-pwm.c
+++ b/drivers/led/led-pwm.c
@@ -29,22 +29,27 @@ struct pwmled {
        bool active_low;
        struct led led;
        struct pwm_device *pwm;
-       uint32_t period;
 };
 
 static void led_pwm_set(struct led *led, unsigned int brightness)
 {
        struct pwmled *pwmled = container_of(led, struct pwmled, led);
-       unsigned long long duty =  pwmled->period;
+       unsigned long long duty;
+       struct pwm_state state;
        unsigned int max = pwmled->led.max_value;
 
-        duty *= brightness;
+       pwm_get_state(pwmled->pwm, &state);
+
+       duty = state.period_ns * brightness;
         do_div(duty, max);
 
        if (pwmled->active_low)
-               duty = pwmled->period - duty;
+               duty = state.period_ns - duty;
+
+       state.p_enable = true;
+       state.duty_ns = duty;
 
-       pwm_config(pwmled->pwm, duty, pwmled->period);
+       pwm_apply_state(pwmled->pwm, &state);
 }
 
 static int led_pwm_of_probe(struct device_d *dev)
@@ -68,13 +73,11 @@ static int led_pwm_of_probe(struct device_d *dev)
                if (ret)
                        return ret;
 
-               pwmled->period = pwm_get_period(pwmled->pwm);
                pwmled->active_low = of_property_read_bool(child, "active-low");
 
                pwmled->led.set = led_pwm_set;
 
                led_pwm_set(&pwmled->led, 0);
-               pwm_enable(pwmled->pwm);
 
                ret = led_register(&pwmled->led);
                if (ret)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to