diff options
author | Fabio Baltieri <fabio.baltieri@gmail.com> | 2012-08-15 09:44:34 -0400 |
---|---|---|
committer | Bryan Wu <bryan.wu@canonical.com> | 2012-09-11 06:32:40 -0400 |
commit | d23a22a74fded23a12434c9463fe66cec2b0afcd (patch) | |
tree | 65b61353a251d780a7b5f854d1b56cb8d8ca4764 /drivers/leds | |
parent | 490dcee9b433302da4ec5325c3e69a0be1201473 (diff) |
leds: delay led_set_brightness if stopping soft-blink
Delay execution of led_set_brightness() if need to stop soft-blink
timer.
This allows led_set_brightness to be called in hard-irq context even if
soft-blink was activated on that LED.
Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Cc: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/led-class.c | 15 | ||||
-rw-r--r-- | drivers/leds/led-core.c | 16 | ||||
-rw-r--r-- | drivers/leds/led-triggers.c | 4 | ||||
-rw-r--r-- | drivers/leds/leds.h | 2 |
4 files changed, 33 insertions, 4 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index c599095bc005..48cce18e9d6d 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c | |||
@@ -124,6 +124,16 @@ static void led_timer_function(unsigned long data) | |||
124 | mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); | 124 | mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); |
125 | } | 125 | } |
126 | 126 | ||
127 | static void set_brightness_delayed(struct work_struct *ws) | ||
128 | { | ||
129 | struct led_classdev *led_cdev = | ||
130 | container_of(ws, struct led_classdev, set_brightness_work); | ||
131 | |||
132 | led_stop_software_blink(led_cdev); | ||
133 | |||
134 | __led_set_brightness(led_cdev, led_cdev->delayed_set_value); | ||
135 | } | ||
136 | |||
127 | /** | 137 | /** |
128 | * led_classdev_suspend - suspend an led_classdev. | 138 | * led_classdev_suspend - suspend an led_classdev. |
129 | * @led_cdev: the led_classdev to suspend. | 139 | * @led_cdev: the led_classdev to suspend. |
@@ -191,6 +201,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) | |||
191 | 201 | ||
192 | led_update_brightness(led_cdev); | 202 | led_update_brightness(led_cdev); |
193 | 203 | ||
204 | INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); | ||
205 | |||
194 | init_timer(&led_cdev->blink_timer); | 206 | init_timer(&led_cdev->blink_timer); |
195 | led_cdev->blink_timer.function = led_timer_function; | 207 | led_cdev->blink_timer.function = led_timer_function; |
196 | led_cdev->blink_timer.data = (unsigned long)led_cdev; | 208 | led_cdev->blink_timer.data = (unsigned long)led_cdev; |
@@ -221,7 +233,10 @@ void led_classdev_unregister(struct led_classdev *led_cdev) | |||
221 | up_write(&led_cdev->trigger_lock); | 233 | up_write(&led_cdev->trigger_lock); |
222 | #endif | 234 | #endif |
223 | 235 | ||
236 | cancel_work_sync(&led_cdev->set_brightness_work); | ||
237 | |||
224 | /* Stop blinking */ | 238 | /* Stop blinking */ |
239 | led_stop_software_blink(led_cdev); | ||
225 | led_set_brightness(led_cdev, LED_OFF); | 240 | led_set_brightness(led_cdev, LED_OFF); |
226 | 241 | ||
227 | device_unregister(led_cdev->dev); | 242 | device_unregister(led_cdev->dev); |
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 2ab05af3de31..ce8921a753a3 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c | |||
@@ -103,13 +103,23 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev, | |||
103 | } | 103 | } |
104 | EXPORT_SYMBOL(led_blink_set_oneshot); | 104 | EXPORT_SYMBOL(led_blink_set_oneshot); |
105 | 105 | ||
106 | void led_set_brightness(struct led_classdev *led_cdev, | 106 | void led_stop_software_blink(struct led_classdev *led_cdev) |
107 | enum led_brightness brightness) | ||
108 | { | 107 | { |
109 | /* stop and clear soft-blink timer */ | ||
110 | del_timer_sync(&led_cdev->blink_timer); | 108 | del_timer_sync(&led_cdev->blink_timer); |
111 | led_cdev->blink_delay_on = 0; | 109 | led_cdev->blink_delay_on = 0; |
112 | led_cdev->blink_delay_off = 0; | 110 | led_cdev->blink_delay_off = 0; |
111 | } | ||
112 | EXPORT_SYMBOL_GPL(led_stop_software_blink); | ||
113 | |||
114 | void led_set_brightness(struct led_classdev *led_cdev, | ||
115 | enum led_brightness brightness) | ||
116 | { | ||
117 | /* delay brightness setting if need to stop soft-blink timer */ | ||
118 | if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) { | ||
119 | led_cdev->delayed_set_value = brightness; | ||
120 | schedule_work(&led_cdev->set_brightness_work); | ||
121 | return; | ||
122 | } | ||
113 | 123 | ||
114 | __led_set_brightness(led_cdev, brightness); | 124 | __led_set_brightness(led_cdev, brightness); |
115 | } | 125 | } |
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 363975b3c925..b53bf54023f6 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c | |||
@@ -109,6 +109,8 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) | |||
109 | list_del(&led_cdev->trig_list); | 109 | list_del(&led_cdev->trig_list); |
110 | write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, | 110 | write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, |
111 | flags); | 111 | flags); |
112 | cancel_work_sync(&led_cdev->set_brightness_work); | ||
113 | led_stop_software_blink(led_cdev); | ||
112 | if (led_cdev->trigger->deactivate) | 114 | if (led_cdev->trigger->deactivate) |
113 | led_cdev->trigger->deactivate(led_cdev); | 115 | led_cdev->trigger->deactivate(led_cdev); |
114 | led_cdev->trigger = NULL; | 116 | led_cdev->trigger = NULL; |
@@ -224,7 +226,7 @@ void led_trigger_event(struct led_trigger *trig, | |||
224 | struct led_classdev *led_cdev; | 226 | struct led_classdev *led_cdev; |
225 | 227 | ||
226 | led_cdev = list_entry(entry, struct led_classdev, trig_list); | 228 | led_cdev = list_entry(entry, struct led_classdev, trig_list); |
227 | __led_set_brightness(led_cdev, brightness); | 229 | led_set_brightness(led_cdev, brightness); |
228 | } | 230 | } |
229 | read_unlock(&trig->leddev_list_lock); | 231 | read_unlock(&trig->leddev_list_lock); |
230 | } | 232 | } |
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index d02acd496126..4c50365344a9 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h | |||
@@ -32,6 +32,8 @@ static inline int led_get_brightness(struct led_classdev *led_cdev) | |||
32 | return led_cdev->brightness; | 32 | return led_cdev->brightness; |
33 | } | 33 | } |
34 | 34 | ||
35 | void led_stop_software_blink(struct led_classdev *led_cdev); | ||
36 | |||
35 | extern struct rw_semaphore leds_list_lock; | 37 | extern struct rw_semaphore leds_list_lock; |
36 | extern struct list_head leds_list; | 38 | extern struct list_head leds_list; |
37 | 39 | ||