summaryrefslogtreecommitdiffstats
path: root/drivers/led
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-03-30 16:57:14 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-03-31 09:48:34 +0200
commit83affc1a6c5e13349d7ea34bd787568aa1c872ff (patch)
treeaa26ee10d703a5ea575af79046699909aaa4d4ea /drivers/led
parent91912a0d5576441db1a4c9a03d309258bd49f149 (diff)
downloadbarebox-83affc1a6c5e13349d7ea34bd787568aa1c872ff.tar.gz
barebox-83affc1a6c5e13349d7ea34bd787568aa1c872ff.tar.xz
led: pwm: use new pwm_apply_state API
To support PWM_POLARITY_INVERTED for PWM LEDs, we need to to use the apply API. Do so. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/led')
-rw-r--r--drivers/led/led-pwm.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/led/led-pwm.c b/drivers/led/led-pwm.c
index 4935572ec2..19d9d4d48a 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)