diff options
Diffstat (limited to 'drivers/leds/ledtrig-timer.c')
-rw-r--r-- | drivers/leds/ledtrig-timer.c | 23 |
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 | ||
27 | struct timer_trig_data { | 27 | struct 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); |