aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/ledtrig-timer.c
diff options
context:
space:
mode:
authorNémeth Márton <nm127@freemail.hu>2008-03-09 16:54:37 -0400
committerRichard Purdie <rpurdie@rpsys.net>2008-04-24 18:34:18 -0400
commit0013b23d66a2768f5babbb0ea9f03ab067a990d8 (patch)
tree14d60a50bb68e422767a268cd737f70ef4e6e19d /drivers/leds/ledtrig-timer.c
parentb3ba31f84ea041c0945b5904d4c407ce14b2b72c (diff)
leds: disable triggers on brightness set
Disable any active triggers when the brightness attribute is set to zero. Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Márton Németh <nm127@freemail.hu> Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Diffstat (limited to 'drivers/leds/ledtrig-timer.c')
-rw-r--r--drivers/leds/ledtrig-timer.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index 82c55d6e4902..706297765d93 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -25,6 +25,9 @@
25#include "leds.h" 25#include "leds.h"
26 26
27struct timer_trig_data { 27struct timer_trig_data {
28 int brightness_on; /* LED brightness during "on" period.
29 * (LED_OFF < brightness_on <= LED_FULL)
30 */
28 unsigned long delay_on; /* milliseconds on */ 31 unsigned long delay_on; /* milliseconds on */
29 unsigned long delay_off; /* milliseconds off */ 32 unsigned long delay_off; /* milliseconds off */
30 struct timer_list timer; 33 struct timer_list timer;
@@ -34,17 +37,26 @@ static void led_timer_function(unsigned long data)
34{ 37{
35 struct led_classdev *led_cdev = (struct led_classdev *) data; 38 struct led_classdev *led_cdev = (struct led_classdev *) data;
36 struct timer_trig_data *timer_data = led_cdev->trigger_data; 39 struct timer_trig_data *timer_data = led_cdev->trigger_data;
37 unsigned long brightness = LED_OFF; 40 unsigned long brightness;
38 unsigned long delay = timer_data->delay_off; 41 unsigned long delay;
39 42
40 if (!timer_data->delay_on || !timer_data->delay_off) { 43 if (!timer_data->delay_on || !timer_data->delay_off) {
41 led_set_brightness(led_cdev, LED_OFF); 44 led_set_brightness(led_cdev, LED_OFF);
42 return; 45 return;
43 } 46 }
44 47
45 if (!led_cdev->brightness) { 48 brightness = led_get_brightness(led_cdev);
46 brightness = LED_FULL; 49 if (!brightness) {
50 /* Time to switch the LED on. */
51 brightness = timer_data->brightness_on;
47 delay = timer_data->delay_on; 52 delay = timer_data->delay_on;
53 } else {
54 /* Store the current brightness value to be able
55 * to restore it when the delay_off period is over.
56 */
57 timer_data->brightness_on = brightness;
58 brightness = LED_OFF;
59 delay = timer_data->delay_off;
48 } 60 }
49 61
50 led_set_brightness(led_cdev, brightness); 62 led_set_brightness(led_cdev, brightness);
@@ -156,6 +168,9 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
156 if (!timer_data) 168 if (!timer_data)
157 return; 169 return;
158 170
171 timer_data->brightness_on = led_get_brightness(led_cdev);
172 if (timer_data->brightness_on == LED_OFF)
173 timer_data->brightness_on = LED_FULL;
159 led_cdev->trigger_data = timer_data; 174 led_cdev->trigger_data = timer_data;
160 175
161 init_timer(&timer_data->timer); 176 init_timer(&timer_data->timer);