From fff26f8141145e01eae8f4d6e642ac8a0d500158 Mon Sep 17 00:00:00 2001 From: Esben Haabendal Date: Tue, 24 May 2011 17:13:22 -0700 Subject: [PATCH] leds: support automatic start of blinking with ledtrig-timer By setting initial values blink_delay_on and blink_delay_off in a led_classdev struct, this change starts the blinking when the led is initialized. With this patch, you can initialize blink_delay_on and blink_delay_off in led_classdev with default_trigger set to "timer", and the led will start up blinking. The current ledtrig-timer implementation ignores any initial blink_delay_on/blink_delay_off settings, and requires setting blink_delay_on/blink_delay_off (typically from userspace) before the led blinks. Signed-off-by: Esben Haabendal Cc: Richard Purdie Cc: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/leds/led-class.c | 3 ++- drivers/leds/leds.h | 7 +++++++ drivers/leds/ledtrig-timer.c | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index d5a4ade88991..dc3d3d83191a 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -131,7 +131,8 @@ static void led_set_software_blink(struct led_classdev *led_cdev, if (!led_cdev->blink_brightness) led_cdev->blink_brightness = led_cdev->max_brightness; - if (delay_on == led_cdev->blink_delay_on && + if (led_get_trigger_data(led_cdev) && + delay_on == led_cdev->blink_delay_on && delay_off == led_cdev->blink_delay_off) return; diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index 2dd8ecbfdc31..e77c7f8dcdd4 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h @@ -40,10 +40,17 @@ void led_trigger_set_default(struct led_classdev *led_cdev); void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger); void led_trigger_remove(struct led_classdev *led_cdev); + +static inline void *led_get_trigger_data(struct led_classdev *led_cdev) +{ + return led_cdev->trigger_data; +} + #else #define led_trigger_set_default(x) do {} while (0) #define led_trigger_set(x, y) do {} while (0) #define led_trigger_remove(x) do {} while (0) +#define led_get_trigger_data(x) (NULL) #endif ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c index b09bcbeade9c..d87c9d02f786 100644 --- a/drivers/leds/ledtrig-timer.c +++ b/drivers/leds/ledtrig-timer.c @@ -91,6 +91,9 @@ static void timer_trig_activate(struct led_classdev *led_cdev) if (rc) goto err_out_delayon; + led_blink_set(led_cdev, &led_cdev->blink_delay_on, + &led_cdev->blink_delay_off); + led_cdev->trigger_data = (void *)1; return; -- 2.20.1