[PATCH 09/12] led: pwm: use new pwm_apply_state API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux