Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * LED Class Core |
| 3 | * |
| 4 | * Copyright 2005-2006 Openedhand Ltd. |
| 5 | * |
| 6 | * Author: Richard Purdie <rpurdie@openedhand.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
Jacek Anaszewski | 0471330 | 2014-08-07 05:10:22 -0700 | [diff] [blame] | 15 | #include <linux/leds.h> |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 16 | #include <linux/list.h> |
| 17 | #include <linux/module.h> |
Jacek Anaszewski | 0471330 | 2014-08-07 05:10:22 -0700 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Richard Purdie | 72f8da3 | 2007-12-31 23:09:44 +0000 | [diff] [blame] | 19 | #include <linux/rwsem.h> |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 20 | #include "leds.h" |
| 21 | |
Richard Purdie | 72f8da3 | 2007-12-31 23:09:44 +0000 | [diff] [blame] | 22 | DECLARE_RWSEM(leds_list_lock); |
Richard Purdie | c72a1d6 | 2006-03-31 02:31:04 -0800 | [diff] [blame] | 23 | EXPORT_SYMBOL_GPL(leds_list_lock); |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 24 | |
| 25 | LIST_HEAD(leds_list); |
| 26 | EXPORT_SYMBOL_GPL(leds_list); |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 27 | |
Heiner Kallweit | d4887af | 2016-02-16 20:21:56 +0100 | [diff] [blame] | 28 | static int __led_set_brightness(struct led_classdev *led_cdev, |
| 29 | enum led_brightness value) |
| 30 | { |
| 31 | if (!led_cdev->brightness_set) |
| 32 | return -ENOTSUPP; |
| 33 | |
| 34 | led_cdev->brightness_set(led_cdev, value); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static int __led_set_brightness_blocking(struct led_classdev *led_cdev, |
| 40 | enum led_brightness value) |
| 41 | { |
| 42 | if (!led_cdev->brightness_set_blocking) |
| 43 | return -ENOTSUPP; |
| 44 | |
| 45 | return led_cdev->brightness_set_blocking(led_cdev, value); |
| 46 | } |
| 47 | |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 48 | static void led_timer_function(unsigned long data) |
| 49 | { |
| 50 | struct led_classdev *led_cdev = (void *)data; |
| 51 | unsigned long brightness; |
| 52 | unsigned long delay; |
| 53 | |
| 54 | if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) { |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 55 | led_set_brightness_nosleep(led_cdev, LED_OFF); |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 56 | clear_bit(LED_BLINK_SW, &led_cdev->work_flags); |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 57 | return; |
| 58 | } |
| 59 | |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 60 | if (test_and_clear_bit(LED_BLINK_ONESHOT_STOP, |
| 61 | &led_cdev->work_flags)) { |
| 62 | clear_bit(LED_BLINK_SW, &led_cdev->work_flags); |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
| 66 | brightness = led_get_brightness(led_cdev); |
| 67 | if (!brightness) { |
| 68 | /* Time to switch the LED on. */ |
Hans de Goede | eb1610b | 2016-10-23 21:47:26 +0200 | [diff] [blame] | 69 | if (test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE, |
| 70 | &led_cdev->work_flags)) |
| 71 | brightness = led_cdev->new_blink_brightness; |
| 72 | else |
| 73 | brightness = led_cdev->blink_brightness; |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 74 | delay = led_cdev->blink_delay_on; |
| 75 | } else { |
| 76 | /* Store the current brightness value to be able |
| 77 | * to restore it when the delay_off period is over. |
| 78 | */ |
Hans de Goede | eb1610b | 2016-10-23 21:47:26 +0200 | [diff] [blame] | 79 | led_cdev->blink_brightness = brightness; |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 80 | brightness = LED_OFF; |
| 81 | delay = led_cdev->blink_delay_off; |
| 82 | } |
| 83 | |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 84 | led_set_brightness_nosleep(led_cdev, brightness); |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 85 | |
| 86 | /* Return in next iteration if led is in one-shot mode and we are in |
| 87 | * the final blink state so that the led is toggled each delay_on + |
| 88 | * delay_off milliseconds in worst case. |
| 89 | */ |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 90 | if (test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags)) { |
| 91 | if (test_bit(LED_BLINK_INVERT, &led_cdev->work_flags)) { |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 92 | if (brightness) |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 93 | set_bit(LED_BLINK_ONESHOT_STOP, |
| 94 | &led_cdev->work_flags); |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 95 | } else { |
| 96 | if (!brightness) |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 97 | set_bit(LED_BLINK_ONESHOT_STOP, |
| 98 | &led_cdev->work_flags); |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay)); |
| 103 | } |
| 104 | |
| 105 | static void set_brightness_delayed(struct work_struct *ws) |
| 106 | { |
| 107 | struct led_classdev *led_cdev = |
| 108 | container_of(ws, struct led_classdev, set_brightness_work); |
Jacek Anaszewski | 1afcadf | 2015-10-19 09:04:01 +0200 | [diff] [blame] | 109 | int ret = 0; |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 110 | |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 111 | if (test_and_clear_bit(LED_BLINK_DISABLE, &led_cdev->work_flags)) { |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 112 | led_cdev->delayed_set_value = LED_OFF; |
| 113 | led_stop_software_blink(led_cdev); |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 114 | } |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 115 | |
Heiner Kallweit | d4887af | 2016-02-16 20:21:56 +0100 | [diff] [blame] | 116 | ret = __led_set_brightness(led_cdev, led_cdev->delayed_set_value); |
| 117 | if (ret == -ENOTSUPP) |
| 118 | ret = __led_set_brightness_blocking(led_cdev, |
| 119 | led_cdev->delayed_set_value); |
Heiner Kallweit | d84d80f | 2016-01-22 21:43:48 +0100 | [diff] [blame] | 120 | if (ret < 0 && |
| 121 | /* LED HW might have been unplugged, therefore don't warn */ |
| 122 | !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) && |
| 123 | (led_cdev->flags & LED_HW_PLUGGABLE))) |
Jacek Anaszewski | 1afcadf | 2015-10-19 09:04:01 +0200 | [diff] [blame] | 124 | dev_err(led_cdev->dev, |
| 125 | "Setting an LED's brightness failed (%d)\n", ret); |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 128 | static void led_set_software_blink(struct led_classdev *led_cdev, |
| 129 | unsigned long delay_on, |
| 130 | unsigned long delay_off) |
| 131 | { |
| 132 | int current_brightness; |
| 133 | |
| 134 | current_brightness = led_get_brightness(led_cdev); |
| 135 | if (current_brightness) |
| 136 | led_cdev->blink_brightness = current_brightness; |
| 137 | if (!led_cdev->blink_brightness) |
| 138 | led_cdev->blink_brightness = led_cdev->max_brightness; |
| 139 | |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 140 | led_cdev->blink_delay_on = delay_on; |
| 141 | led_cdev->blink_delay_off = delay_off; |
| 142 | |
Stefan Sørensen | 8d82fef | 2014-02-04 00:11:42 -0800 | [diff] [blame] | 143 | /* never on - just set to off */ |
| 144 | if (!delay_on) { |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 145 | led_set_brightness_nosleep(led_cdev, LED_OFF); |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 146 | return; |
Stefan Sørensen | 8d82fef | 2014-02-04 00:11:42 -0800 | [diff] [blame] | 147 | } |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 148 | |
| 149 | /* never off - just set to brightness */ |
| 150 | if (!delay_off) { |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 151 | led_set_brightness_nosleep(led_cdev, |
| 152 | led_cdev->blink_brightness); |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 153 | return; |
| 154 | } |
| 155 | |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 156 | set_bit(LED_BLINK_SW, &led_cdev->work_flags); |
Jiri Kosina | 9067359 | 2014-09-02 02:03:12 -0700 | [diff] [blame] | 157 | mod_timer(&led_cdev->blink_timer, jiffies + 1); |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
Bryan Wu | 20c0e6b | 2012-06-15 22:15:27 +0800 | [diff] [blame] | 161 | static void led_blink_setup(struct led_classdev *led_cdev, |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 162 | unsigned long *delay_on, |
| 163 | unsigned long *delay_off) |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 164 | { |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 165 | if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) && |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 166 | led_cdev->blink_set && |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 167 | !led_cdev->blink_set(led_cdev, delay_on, delay_off)) |
| 168 | return; |
| 169 | |
| 170 | /* blink with 1 Hz as default if nothing specified */ |
| 171 | if (!*delay_on && !*delay_off) |
| 172 | *delay_on = *delay_off = 500; |
| 173 | |
| 174 | led_set_software_blink(led_cdev, *delay_on, *delay_off); |
| 175 | } |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 176 | |
Jacek Anaszewski | 757b06a | 2015-09-28 14:38:04 +0200 | [diff] [blame] | 177 | void led_init_core(struct led_classdev *led_cdev) |
| 178 | { |
| 179 | INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); |
| 180 | |
| 181 | setup_timer(&led_cdev->blink_timer, led_timer_function, |
| 182 | (unsigned long)led_cdev); |
| 183 | } |
| 184 | EXPORT_SYMBOL_GPL(led_init_core); |
| 185 | |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 186 | void led_blink_set(struct led_classdev *led_cdev, |
| 187 | unsigned long *delay_on, |
| 188 | unsigned long *delay_off) |
| 189 | { |
Jiri Kosina | 9067359 | 2014-09-02 02:03:12 -0700 | [diff] [blame] | 190 | del_timer_sync(&led_cdev->blink_timer); |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 191 | |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 192 | clear_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags); |
| 193 | clear_bit(LED_BLINK_ONESHOT_STOP, &led_cdev->work_flags); |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 194 | |
| 195 | led_blink_setup(led_cdev, delay_on, delay_off); |
| 196 | } |
Jacek Anaszewski | 2806e2f | 2015-09-28 15:07:10 +0200 | [diff] [blame] | 197 | EXPORT_SYMBOL_GPL(led_blink_set); |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 198 | |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 199 | void led_blink_set_oneshot(struct led_classdev *led_cdev, |
| 200 | unsigned long *delay_on, |
| 201 | unsigned long *delay_off, |
| 202 | int invert) |
| 203 | { |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 204 | if (test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) && |
Jiri Kosina | 9067359 | 2014-09-02 02:03:12 -0700 | [diff] [blame] | 205 | timer_pending(&led_cdev->blink_timer)) |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 206 | return; |
| 207 | |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 208 | set_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags); |
| 209 | clear_bit(LED_BLINK_ONESHOT_STOP, &led_cdev->work_flags); |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 210 | |
| 211 | if (invert) |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 212 | set_bit(LED_BLINK_INVERT, &led_cdev->work_flags); |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 213 | else |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 214 | clear_bit(LED_BLINK_INVERT, &led_cdev->work_flags); |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 215 | |
| 216 | led_blink_setup(led_cdev, delay_on, delay_off); |
| 217 | } |
Jacek Anaszewski | 2806e2f | 2015-09-28 15:07:10 +0200 | [diff] [blame] | 218 | EXPORT_SYMBOL_GPL(led_blink_set_oneshot); |
Fabio Baltieri | 5bb629c | 2012-05-27 07:19:22 +0800 | [diff] [blame] | 219 | |
Fabio Baltieri | d23a22a | 2012-08-15 21:44:34 +0800 | [diff] [blame] | 220 | void led_stop_software_blink(struct led_classdev *led_cdev) |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 221 | { |
Jiri Kosina | 9067359 | 2014-09-02 02:03:12 -0700 | [diff] [blame] | 222 | del_timer_sync(&led_cdev->blink_timer); |
Fabio Baltieri | 4378648 | 2012-06-07 03:12:34 +0800 | [diff] [blame] | 223 | led_cdev->blink_delay_on = 0; |
| 224 | led_cdev->blink_delay_off = 0; |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 225 | clear_bit(LED_BLINK_SW, &led_cdev->work_flags); |
Fabio Baltieri | d23a22a | 2012-08-15 21:44:34 +0800 | [diff] [blame] | 226 | } |
| 227 | EXPORT_SYMBOL_GPL(led_stop_software_blink); |
| 228 | |
| 229 | void led_set_brightness(struct led_classdev *led_cdev, |
| 230 | enum led_brightness brightness) |
| 231 | { |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 232 | /* |
Tony Makkiel | 7cfe749 | 2016-05-18 17:22:45 +0100 | [diff] [blame] | 233 | * If software blink is active, delay brightness setting |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 234 | * until the next timer tick. |
| 235 | */ |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 236 | if (test_bit(LED_BLINK_SW, &led_cdev->work_flags)) { |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 237 | /* |
| 238 | * If we need to disable soft blinking delegate this to the |
| 239 | * work queue task to avoid problems in case we are called |
| 240 | * from hard irq context. |
| 241 | */ |
| 242 | if (brightness == LED_OFF) { |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 243 | set_bit(LED_BLINK_DISABLE, &led_cdev->work_flags); |
Stas Sergeev | 76931ed | 2015-05-14 08:24:02 -0700 | [diff] [blame] | 244 | schedule_work(&led_cdev->set_brightness_work); |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 245 | } else { |
Hans de Goede | a9c6ce5 | 2016-11-08 14:38:46 +0100 | [diff] [blame] | 246 | set_bit(LED_BLINK_BRIGHTNESS_CHANGE, |
| 247 | &led_cdev->work_flags); |
Hans de Goede | eb1610b | 2016-10-23 21:47:26 +0200 | [diff] [blame] | 248 | led_cdev->new_blink_brightness = brightness; |
Jacek Anaszewski | f1e80c0 | 2015-10-07 11:10:39 +0200 | [diff] [blame] | 249 | } |
Fabio Baltieri | d23a22a | 2012-08-15 21:44:34 +0800 | [diff] [blame] | 250 | return; |
| 251 | } |
Fabio Baltieri | 4378648 | 2012-06-07 03:12:34 +0800 | [diff] [blame] | 252 | |
Jacek Anaszewski | 13ae79b | 2015-10-07 11:10:43 +0200 | [diff] [blame] | 253 | led_set_brightness_nosleep(led_cdev, brightness); |
Bryan Wu | a403d93 | 2012-03-23 15:02:14 -0700 | [diff] [blame] | 254 | } |
Jacek Anaszewski | 2806e2f | 2015-09-28 15:07:10 +0200 | [diff] [blame] | 255 | EXPORT_SYMBOL_GPL(led_set_brightness); |
Jacek Anaszewski | 3ef7de5 | 2014-08-20 06:41:55 -0700 | [diff] [blame] | 256 | |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 257 | void led_set_brightness_nopm(struct led_classdev *led_cdev, |
| 258 | enum led_brightness value) |
| 259 | { |
| 260 | /* Use brightness_set op if available, it is guaranteed not to sleep */ |
Heiner Kallweit | d4887af | 2016-02-16 20:21:56 +0100 | [diff] [blame] | 261 | if (!__led_set_brightness(led_cdev, value)) |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 262 | return; |
Jacek Anaszewski | 81fe8e5 | 2015-10-07 11:10:41 +0200 | [diff] [blame] | 263 | |
| 264 | /* If brightness setting can sleep, delegate it to a work queue task */ |
| 265 | led_cdev->delayed_set_value = value; |
| 266 | schedule_work(&led_cdev->set_brightness_work); |
| 267 | } |
| 268 | EXPORT_SYMBOL_GPL(led_set_brightness_nopm); |
| 269 | |
| 270 | void led_set_brightness_nosleep(struct led_classdev *led_cdev, |
| 271 | enum led_brightness value) |
| 272 | { |
| 273 | led_cdev->brightness = min(value, led_cdev->max_brightness); |
| 274 | |
| 275 | if (led_cdev->flags & LED_SUSPENDED) |
| 276 | return; |
| 277 | |
| 278 | led_set_brightness_nopm(led_cdev, led_cdev->brightness); |
| 279 | } |
| 280 | EXPORT_SYMBOL_GPL(led_set_brightness_nosleep); |
| 281 | |
Jacek Anaszewski | 13ae79b | 2015-10-07 11:10:43 +0200 | [diff] [blame] | 282 | int led_set_brightness_sync(struct led_classdev *led_cdev, |
| 283 | enum led_brightness value) |
| 284 | { |
| 285 | if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) |
| 286 | return -EBUSY; |
| 287 | |
| 288 | led_cdev->brightness = min(value, led_cdev->max_brightness); |
| 289 | |
| 290 | if (led_cdev->flags & LED_SUSPENDED) |
| 291 | return 0; |
| 292 | |
Heiner Kallweit | d4887af | 2016-02-16 20:21:56 +0100 | [diff] [blame] | 293 | return __led_set_brightness_blocking(led_cdev, led_cdev->brightness); |
Jacek Anaszewski | 13ae79b | 2015-10-07 11:10:43 +0200 | [diff] [blame] | 294 | } |
| 295 | EXPORT_SYMBOL_GPL(led_set_brightness_sync); |
| 296 | |
Jacek Anaszewski | 3ef7de5 | 2014-08-20 06:41:55 -0700 | [diff] [blame] | 297 | int led_update_brightness(struct led_classdev *led_cdev) |
| 298 | { |
| 299 | int ret = 0; |
| 300 | |
| 301 | if (led_cdev->brightness_get) { |
| 302 | ret = led_cdev->brightness_get(led_cdev); |
| 303 | if (ret >= 0) { |
| 304 | led_cdev->brightness = ret; |
| 305 | return 0; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | return ret; |
| 310 | } |
Jacek Anaszewski | 2806e2f | 2015-09-28 15:07:10 +0200 | [diff] [blame] | 311 | EXPORT_SYMBOL_GPL(led_update_brightness); |
Jacek Anaszewski | acd899e | 2014-09-22 08:21:04 -0700 | [diff] [blame] | 312 | |
| 313 | /* Caller must ensure led_cdev->led_access held */ |
| 314 | void led_sysfs_disable(struct led_classdev *led_cdev) |
| 315 | { |
| 316 | lockdep_assert_held(&led_cdev->led_access); |
| 317 | |
| 318 | led_cdev->flags |= LED_SYSFS_DISABLE; |
| 319 | } |
| 320 | EXPORT_SYMBOL_GPL(led_sysfs_disable); |
| 321 | |
| 322 | /* Caller must ensure led_cdev->led_access held */ |
| 323 | void led_sysfs_enable(struct led_classdev *led_cdev) |
| 324 | { |
| 325 | lockdep_assert_held(&led_cdev->led_access); |
| 326 | |
| 327 | led_cdev->flags &= ~LED_SYSFS_DISABLE; |
| 328 | } |
| 329 | EXPORT_SYMBOL_GPL(led_sysfs_enable); |