aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorVincent Donnefort <vdonnefort@gmail.com>2014-06-14 05:21:40 -0400
committerBryan Wu <cooloney@gmail.com>2014-07-03 15:02:14 -0400
commit8b37e1bef5a6b60e949e28a4db3006e4b00bd758 (patch)
tree3d9e31e6cb46cfa4bfc8f746b15dd737c0e068b2 /drivers/leds
parent7e7743901b53dd71bb7332b16b14bcce15ebcd69 (diff)
leds: convert blink timer to workqueue
This patch converts the blink timer from led-core to workqueue which is more suitable for this kind of non-priority operations. Moreover, timer may lead to errors when a LED setting function use a scheduling function such as pinctrl which is using mutex. Signed-off-by: Vincent Donnefort <vdonnefort@gmail.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/led-class.c14
-rw-r--r--drivers/leds/led-core.c11
2 files changed, 13 insertions, 12 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index aa29198fca3e..129729d35478 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -15,10 +15,10 @@
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/timer.h>
19#include <linux/err.h> 18#include <linux/err.h>
20#include <linux/ctype.h> 19#include <linux/ctype.h>
21#include <linux/leds.h> 20#include <linux/leds.h>
21#include <linux/workqueue.h>
22#include "leds.h" 22#include "leds.h"
23 23
24static struct class *leds_class; 24static struct class *leds_class;
@@ -97,9 +97,10 @@ static const struct attribute_group *led_groups[] = {
97 NULL, 97 NULL,
98}; 98};
99 99
100static void led_timer_function(unsigned long data) 100static void led_work_function(struct work_struct *ws)
101{ 101{
102 struct led_classdev *led_cdev = (void *)data; 102 struct led_classdev *led_cdev =
103 container_of(ws, struct led_classdev, blink_work.work);
103 unsigned long brightness; 104 unsigned long brightness;
104 unsigned long delay; 105 unsigned long delay;
105 106
@@ -143,7 +144,8 @@ static void led_timer_function(unsigned long data)
143 } 144 }
144 } 145 }
145 146
146 mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); 147 queue_delayed_work(system_wq, &led_cdev->blink_work,
148 msecs_to_jiffies(delay));
147} 149}
148 150
149static void set_brightness_delayed(struct work_struct *ws) 151static void set_brightness_delayed(struct work_struct *ws)
@@ -231,9 +233,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
231 233
232 INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); 234 INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
233 235
234 init_timer(&led_cdev->blink_timer); 236 INIT_DELAYED_WORK(&led_cdev->blink_work, led_work_function);
235 led_cdev->blink_timer.function = led_timer_function;
236 led_cdev->blink_timer.data = (unsigned long)led_cdev;
237 237
238#ifdef CONFIG_LEDS_TRIGGERS 238#ifdef CONFIG_LEDS_TRIGGERS
239 led_trigger_set_default(led_cdev); 239 led_trigger_set_default(led_cdev);
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 71b40d3bf776..4bb116867b88 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -16,6 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/rwsem.h> 17#include <linux/rwsem.h>
18#include <linux/leds.h> 18#include <linux/leds.h>
19#include <linux/workqueue.h>
19#include "leds.h" 20#include "leds.h"
20 21
21DECLARE_RWSEM(leds_list_lock); 22DECLARE_RWSEM(leds_list_lock);
@@ -51,7 +52,7 @@ static void led_set_software_blink(struct led_classdev *led_cdev,
51 return; 52 return;
52 } 53 }
53 54
54 mod_timer(&led_cdev->blink_timer, jiffies + 1); 55 queue_delayed_work(system_wq, &led_cdev->blink_work, 1);
55} 56}
56 57
57 58
@@ -75,7 +76,7 @@ void led_blink_set(struct led_classdev *led_cdev,
75 unsigned long *delay_on, 76 unsigned long *delay_on,
76 unsigned long *delay_off) 77 unsigned long *delay_off)
77{ 78{
78 del_timer_sync(&led_cdev->blink_timer); 79 cancel_delayed_work_sync(&led_cdev->blink_work);
79 80
80 led_cdev->flags &= ~LED_BLINK_ONESHOT; 81 led_cdev->flags &= ~LED_BLINK_ONESHOT;
81 led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP; 82 led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP;
@@ -90,7 +91,7 @@ void led_blink_set_oneshot(struct led_classdev *led_cdev,
90 int invert) 91 int invert)
91{ 92{
92 if ((led_cdev->flags & LED_BLINK_ONESHOT) && 93 if ((led_cdev->flags & LED_BLINK_ONESHOT) &&
93 timer_pending(&led_cdev->blink_timer)) 94 delayed_work_pending(&led_cdev->blink_work))
94 return; 95 return;
95 96
96 led_cdev->flags |= LED_BLINK_ONESHOT; 97 led_cdev->flags |= LED_BLINK_ONESHOT;
@@ -107,7 +108,7 @@ EXPORT_SYMBOL(led_blink_set_oneshot);
107 108
108void led_stop_software_blink(struct led_classdev *led_cdev) 109void led_stop_software_blink(struct led_classdev *led_cdev)
109{ 110{
110 del_timer_sync(&led_cdev->blink_timer); 111 cancel_delayed_work_sync(&led_cdev->blink_work);
111 led_cdev->blink_delay_on = 0; 112 led_cdev->blink_delay_on = 0;
112 led_cdev->blink_delay_off = 0; 113 led_cdev->blink_delay_off = 0;
113} 114}
@@ -116,7 +117,7 @@ EXPORT_SYMBOL_GPL(led_stop_software_blink);
116void led_set_brightness(struct led_classdev *led_cdev, 117void led_set_brightness(struct led_classdev *led_cdev,
117 enum led_brightness brightness) 118 enum led_brightness brightness)
118{ 119{
119 /* delay brightness setting if need to stop soft-blink timer */ 120 /* delay brightness setting if need to stop soft-blink work */
120 if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) { 121 if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) {
121 led_cdev->delayed_set_value = brightness; 122 led_cdev->delayed_set_value = brightness;
122 schedule_work(&led_cdev->set_brightness_work); 123 schedule_work(&led_cdev->set_brightness_work);