diff options
author | Jacek Anaszewski <j.anaszewski@samsung.com> | 2014-11-14 05:50:18 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2014-11-14 17:29:35 -0500 |
commit | 4d71a4a12b130ad033219e6f58c74a64059415eb (patch) | |
tree | 5b9560719835c5a204b92f4bb7e44aae6793281c /drivers/leds | |
parent | acd899e4f3066b6662f6047da5b795cc762093cb (diff) |
leds: Add support for setting brightness in a synchronous way
There are use cases when setting a LED brightness has to
have immediate effect (e.g. setting a torch LED brightness).
This patch extends LED subsystem to support such operations.
The LED subsystem internal API __led_set_brightness is changed
to led_set_brightness_async and new led_set_brightness_sync API
is added.
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/led-class.c | 10 | ||||
-rw-r--r-- | drivers/leds/led-core.c | 18 | ||||
-rw-r--r-- | drivers/leds/leds.h | 20 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-backlight.c | 8 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-default-on.c | 2 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-gpio.c | 6 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-heartbeat.c | 2 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-oneshot.c | 4 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-transient.c | 10 |
9 files changed, 54 insertions, 26 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 65722deb8d28..dbeebac38d31 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c | |||
@@ -55,7 +55,7 @@ static ssize_t brightness_store(struct device *dev, | |||
55 | 55 | ||
56 | if (state == LED_OFF) | 56 | if (state == LED_OFF) |
57 | led_trigger_remove(led_cdev); | 57 | led_trigger_remove(led_cdev); |
58 | __led_set_brightness(led_cdev, state); | 58 | led_set_brightness(led_cdev, state); |
59 | 59 | ||
60 | ret = size; | 60 | ret = size; |
61 | unlock: | 61 | unlock: |
@@ -109,7 +109,7 @@ static void led_timer_function(unsigned long data) | |||
109 | unsigned long delay; | 109 | unsigned long delay; |
110 | 110 | ||
111 | if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { | 111 | if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { |
112 | __led_set_brightness(led_cdev, LED_OFF); | 112 | led_set_brightness_async(led_cdev, LED_OFF); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | 115 | ||
@@ -132,7 +132,7 @@ static void led_timer_function(unsigned long data) | |||
132 | delay = led_cdev->blink_delay_off; | 132 | delay = led_cdev->blink_delay_off; |
133 | } | 133 | } |
134 | 134 | ||
135 | __led_set_brightness(led_cdev, brightness); | 135 | led_set_brightness_async(led_cdev, brightness); |
136 | 136 | ||
137 | /* Return in next iteration if led is in one-shot mode and we are in | 137 | /* Return in next iteration if led is in one-shot mode and we are in |
138 | * the final blink state so that the led is toggled each delay_on + | 138 | * the final blink state so that the led is toggled each delay_on + |
@@ -158,7 +158,7 @@ static void set_brightness_delayed(struct work_struct *ws) | |||
158 | 158 | ||
159 | led_stop_software_blink(led_cdev); | 159 | led_stop_software_blink(led_cdev); |
160 | 160 | ||
161 | __led_set_brightness(led_cdev, led_cdev->delayed_set_value); | 161 | led_set_brightness_async(led_cdev, led_cdev->delayed_set_value); |
162 | } | 162 | } |
163 | 163 | ||
164 | /** | 164 | /** |
@@ -233,6 +233,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) | |||
233 | if (!led_cdev->max_brightness) | 233 | if (!led_cdev->max_brightness) |
234 | led_cdev->max_brightness = LED_FULL; | 234 | led_cdev->max_brightness = LED_FULL; |
235 | 235 | ||
236 | led_cdev->flags |= SET_BRIGHTNESS_ASYNC; | ||
237 | |||
236 | led_update_brightness(led_cdev); | 238 | led_update_brightness(led_cdev); |
237 | 239 | ||
238 | INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); | 240 | INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); |
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index be6d9fa5e971..9886dace5ad2 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c | |||
@@ -42,13 +42,13 @@ static void led_set_software_blink(struct led_classdev *led_cdev, | |||
42 | 42 | ||
43 | /* never on - just set to off */ | 43 | /* never on - just set to off */ |
44 | if (!delay_on) { | 44 | if (!delay_on) { |
45 | __led_set_brightness(led_cdev, LED_OFF); | 45 | led_set_brightness_async(led_cdev, LED_OFF); |
46 | return; | 46 | return; |
47 | } | 47 | } |
48 | 48 | ||
49 | /* never off - just set to brightness */ | 49 | /* never off - just set to brightness */ |
50 | if (!delay_off) { | 50 | if (!delay_off) { |
51 | __led_set_brightness(led_cdev, led_cdev->blink_brightness); | 51 | led_set_brightness_async(led_cdev, led_cdev->blink_brightness); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | 54 | ||
@@ -117,6 +117,8 @@ EXPORT_SYMBOL_GPL(led_stop_software_blink); | |||
117 | void led_set_brightness(struct led_classdev *led_cdev, | 117 | void led_set_brightness(struct led_classdev *led_cdev, |
118 | enum led_brightness brightness) | 118 | enum led_brightness brightness) |
119 | { | 119 | { |
120 | int ret = 0; | ||
121 | |||
120 | /* delay brightness setting if need to stop soft-blink timer */ | 122 | /* delay brightness setting if need to stop soft-blink timer */ |
121 | if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) { | 123 | if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) { |
122 | led_cdev->delayed_set_value = brightness; | 124 | led_cdev->delayed_set_value = brightness; |
@@ -124,7 +126,17 @@ void led_set_brightness(struct led_classdev *led_cdev, | |||
124 | return; | 126 | return; |
125 | } | 127 | } |
126 | 128 | ||
127 | __led_set_brightness(led_cdev, brightness); | 129 | if (led_cdev->flags & SET_BRIGHTNESS_ASYNC) { |
130 | led_set_brightness_async(led_cdev, brightness); | ||
131 | return; | ||
132 | } else if (led_cdev->flags & SET_BRIGHTNESS_SYNC) | ||
133 | ret = led_set_brightness_sync(led_cdev, brightness); | ||
134 | else | ||
135 | ret = -EINVAL; | ||
136 | |||
137 | if (ret < 0) | ||
138 | dev_dbg(led_cdev->dev, "Setting LED brightness failed (%d)\n", | ||
139 | ret); | ||
128 | } | 140 | } |
129 | EXPORT_SYMBOL(led_set_brightness); | 141 | EXPORT_SYMBOL(led_set_brightness); |
130 | 142 | ||
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index 4c50365344a9..2348dbda5269 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h | |||
@@ -17,16 +17,28 @@ | |||
17 | #include <linux/rwsem.h> | 17 | #include <linux/rwsem.h> |
18 | #include <linux/leds.h> | 18 | #include <linux/leds.h> |
19 | 19 | ||
20 | static inline void __led_set_brightness(struct led_classdev *led_cdev, | 20 | static inline void led_set_brightness_async(struct led_classdev *led_cdev, |
21 | enum led_brightness value) | 21 | enum led_brightness value) |
22 | { | 22 | { |
23 | if (value > led_cdev->max_brightness) | 23 | led_cdev->brightness = min(value, led_cdev->max_brightness); |
24 | value = led_cdev->max_brightness; | 24 | |
25 | led_cdev->brightness = value; | ||
26 | if (!(led_cdev->flags & LED_SUSPENDED)) | 25 | if (!(led_cdev->flags & LED_SUSPENDED)) |
27 | led_cdev->brightness_set(led_cdev, value); | 26 | led_cdev->brightness_set(led_cdev, value); |
28 | } | 27 | } |
29 | 28 | ||
29 | static inline int led_set_brightness_sync(struct led_classdev *led_cdev, | ||
30 | enum led_brightness value) | ||
31 | { | ||
32 | int ret = 0; | ||
33 | |||
34 | led_cdev->brightness = min(value, led_cdev->max_brightness); | ||
35 | |||
36 | if (!(led_cdev->flags & LED_SUSPENDED)) | ||
37 | ret = led_cdev->brightness_set_sync(led_cdev, | ||
38 | led_cdev->brightness); | ||
39 | return ret; | ||
40 | } | ||
41 | |||
30 | static inline int led_get_brightness(struct led_classdev *led_cdev) | 42 | static inline int led_get_brightness(struct led_classdev *led_cdev) |
31 | { | 43 | { |
32 | return led_cdev->brightness; | 44 | return led_cdev->brightness; |
diff --git a/drivers/leds/trigger/ledtrig-backlight.c b/drivers/leds/trigger/ledtrig-backlight.c index 47e55aa9eefa..59eca17d9661 100644 --- a/drivers/leds/trigger/ledtrig-backlight.c +++ b/drivers/leds/trigger/ledtrig-backlight.c | |||
@@ -51,9 +51,9 @@ static int fb_notifier_callback(struct notifier_block *p, | |||
51 | 51 | ||
52 | if ((n->old_status == UNBLANK) ^ n->invert) { | 52 | if ((n->old_status == UNBLANK) ^ n->invert) { |
53 | n->brightness = led->brightness; | 53 | n->brightness = led->brightness; |
54 | __led_set_brightness(led, LED_OFF); | 54 | led_set_brightness_async(led, LED_OFF); |
55 | } else { | 55 | } else { |
56 | __led_set_brightness(led, n->brightness); | 56 | led_set_brightness_async(led, n->brightness); |
57 | } | 57 | } |
58 | 58 | ||
59 | n->old_status = new_status; | 59 | n->old_status = new_status; |
@@ -89,9 +89,9 @@ static ssize_t bl_trig_invert_store(struct device *dev, | |||
89 | 89 | ||
90 | /* After inverting, we need to update the LED. */ | 90 | /* After inverting, we need to update the LED. */ |
91 | if ((n->old_status == BLANK) ^ n->invert) | 91 | if ((n->old_status == BLANK) ^ n->invert) |
92 | __led_set_brightness(led, LED_OFF); | 92 | led_set_brightness_async(led, LED_OFF); |
93 | else | 93 | else |
94 | __led_set_brightness(led, n->brightness); | 94 | led_set_brightness_async(led, n->brightness); |
95 | 95 | ||
96 | return num; | 96 | return num; |
97 | } | 97 | } |
diff --git a/drivers/leds/trigger/ledtrig-default-on.c b/drivers/leds/trigger/ledtrig-default-on.c index 81a91be8e18d..6f38f883aaf1 100644 --- a/drivers/leds/trigger/ledtrig-default-on.c +++ b/drivers/leds/trigger/ledtrig-default-on.c | |||
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | static void defon_trig_activate(struct led_classdev *led_cdev) | 20 | static void defon_trig_activate(struct led_classdev *led_cdev) |
21 | { | 21 | { |
22 | __led_set_brightness(led_cdev, led_cdev->max_brightness); | 22 | led_set_brightness_async(led_cdev, led_cdev->max_brightness); |
23 | } | 23 | } |
24 | 24 | ||
25 | static struct led_trigger defon_led_trigger = { | 25 | static struct led_trigger defon_led_trigger = { |
diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index c86c41826476..4cc7040746c6 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c | |||
@@ -54,12 +54,12 @@ static void gpio_trig_work(struct work_struct *work) | |||
54 | 54 | ||
55 | if (tmp) { | 55 | if (tmp) { |
56 | if (gpio_data->desired_brightness) | 56 | if (gpio_data->desired_brightness) |
57 | __led_set_brightness(gpio_data->led, | 57 | led_set_brightness_async(gpio_data->led, |
58 | gpio_data->desired_brightness); | 58 | gpio_data->desired_brightness); |
59 | else | 59 | else |
60 | __led_set_brightness(gpio_data->led, LED_FULL); | 60 | led_set_brightness_async(gpio_data->led, LED_FULL); |
61 | } else { | 61 | } else { |
62 | __led_set_brightness(gpio_data->led, LED_OFF); | 62 | led_set_brightness_async(gpio_data->led, LED_OFF); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c index 5c8464a33172..fea6871d2609 100644 --- a/drivers/leds/trigger/ledtrig-heartbeat.c +++ b/drivers/leds/trigger/ledtrig-heartbeat.c | |||
@@ -74,7 +74,7 @@ static void led_heartbeat_function(unsigned long data) | |||
74 | break; | 74 | break; |
75 | } | 75 | } |
76 | 76 | ||
77 | __led_set_brightness(led_cdev, brightness); | 77 | led_set_brightness_async(led_cdev, brightness); |
78 | mod_timer(&heartbeat_data->timer, jiffies + delay); | 78 | mod_timer(&heartbeat_data->timer, jiffies + delay); |
79 | } | 79 | } |
80 | 80 | ||
diff --git a/drivers/leds/trigger/ledtrig-oneshot.c b/drivers/leds/trigger/ledtrig-oneshot.c index cb4c7466692a..fbd02cdc3ad7 100644 --- a/drivers/leds/trigger/ledtrig-oneshot.c +++ b/drivers/leds/trigger/ledtrig-oneshot.c | |||
@@ -63,9 +63,9 @@ static ssize_t led_invert_store(struct device *dev, | |||
63 | oneshot_data->invert = !!state; | 63 | oneshot_data->invert = !!state; |
64 | 64 | ||
65 | if (oneshot_data->invert) | 65 | if (oneshot_data->invert) |
66 | __led_set_brightness(led_cdev, LED_FULL); | 66 | led_set_brightness_async(led_cdev, LED_FULL); |
67 | else | 67 | else |
68 | __led_set_brightness(led_cdev, LED_OFF); | 68 | led_set_brightness_async(led_cdev, LED_OFF); |
69 | 69 | ||
70 | return size; | 70 | return size; |
71 | } | 71 | } |
diff --git a/drivers/leds/trigger/ledtrig-transient.c b/drivers/leds/trigger/ledtrig-transient.c index e5abc00bb00c..3c34de404d18 100644 --- a/drivers/leds/trigger/ledtrig-transient.c +++ b/drivers/leds/trigger/ledtrig-transient.c | |||
@@ -41,7 +41,7 @@ static void transient_timer_function(unsigned long data) | |||
41 | struct transient_trig_data *transient_data = led_cdev->trigger_data; | 41 | struct transient_trig_data *transient_data = led_cdev->trigger_data; |
42 | 42 | ||
43 | transient_data->activate = 0; | 43 | transient_data->activate = 0; |
44 | __led_set_brightness(led_cdev, transient_data->restore_state); | 44 | led_set_brightness_async(led_cdev, transient_data->restore_state); |
45 | } | 45 | } |
46 | 46 | ||
47 | static ssize_t transient_activate_show(struct device *dev, | 47 | static ssize_t transient_activate_show(struct device *dev, |
@@ -72,7 +72,8 @@ static ssize_t transient_activate_store(struct device *dev, | |||
72 | if (state == 0 && transient_data->activate == 1) { | 72 | if (state == 0 && transient_data->activate == 1) { |
73 | del_timer(&transient_data->timer); | 73 | del_timer(&transient_data->timer); |
74 | transient_data->activate = state; | 74 | transient_data->activate = state; |
75 | __led_set_brightness(led_cdev, transient_data->restore_state); | 75 | led_set_brightness_async(led_cdev, |
76 | transient_data->restore_state); | ||
76 | return size; | 77 | return size; |
77 | } | 78 | } |
78 | 79 | ||
@@ -80,7 +81,7 @@ static ssize_t transient_activate_store(struct device *dev, | |||
80 | if (state == 1 && transient_data->activate == 0 && | 81 | if (state == 1 && transient_data->activate == 0 && |
81 | transient_data->duration != 0) { | 82 | transient_data->duration != 0) { |
82 | transient_data->activate = state; | 83 | transient_data->activate = state; |
83 | __led_set_brightness(led_cdev, transient_data->state); | 84 | led_set_brightness_async(led_cdev, transient_data->state); |
84 | transient_data->restore_state = | 85 | transient_data->restore_state = |
85 | (transient_data->state == LED_FULL) ? LED_OFF : LED_FULL; | 86 | (transient_data->state == LED_FULL) ? LED_OFF : LED_FULL; |
86 | mod_timer(&transient_data->timer, | 87 | mod_timer(&transient_data->timer, |
@@ -203,7 +204,8 @@ static void transient_trig_deactivate(struct led_classdev *led_cdev) | |||
203 | 204 | ||
204 | if (led_cdev->activated) { | 205 | if (led_cdev->activated) { |
205 | del_timer_sync(&transient_data->timer); | 206 | del_timer_sync(&transient_data->timer); |
206 | __led_set_brightness(led_cdev, transient_data->restore_state); | 207 | led_set_brightness_async(led_cdev, |
208 | transient_data->restore_state); | ||
207 | device_remove_file(led_cdev->dev, &dev_attr_activate); | 209 | device_remove_file(led_cdev->dev, &dev_attr_activate); |
208 | device_remove_file(led_cdev->dev, &dev_attr_duration); | 210 | device_remove_file(led_cdev->dev, &dev_attr_duration); |
209 | device_remove_file(led_cdev->dev, &dev_attr_state); | 211 | device_remove_file(led_cdev->dev, &dev_attr_state); |