diff options
-rw-r--r-- | drivers/leds/led-class.c | 23 | ||||
-rw-r--r-- | drivers/leds/led-core.c | 19 | ||||
-rw-r--r-- | drivers/leds/leds-gpio-register.c | 5 | ||||
-rw-r--r-- | drivers/leds/leds-gpio.c | 14 | ||||
-rw-r--r-- | drivers/leds/leds-lp3944.c | 3 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-gpio.c | 2 | ||||
-rw-r--r-- | include/linux/leds.h | 16 |
7 files changed, 53 insertions, 29 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index aa29198fca3e..7440c58b8e6f 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c | |||
@@ -9,26 +9,21 @@ | |||
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/ctype.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/device.h> |
14 | #include <linux/err.h> | ||
14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/kernel.h> | ||
17 | #include <linux/leds.h> | ||
15 | #include <linux/list.h> | 18 | #include <linux/list.h> |
19 | #include <linux/module.h> | ||
20 | #include <linux/slab.h> | ||
16 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
17 | #include <linux/device.h> | ||
18 | #include <linux/timer.h> | 22 | #include <linux/timer.h> |
19 | #include <linux/err.h> | ||
20 | #include <linux/ctype.h> | ||
21 | #include <linux/leds.h> | ||
22 | #include "leds.h" | 23 | #include "leds.h" |
23 | 24 | ||
24 | static struct class *leds_class; | 25 | static struct class *leds_class; |
25 | 26 | ||
26 | static void led_update_brightness(struct led_classdev *led_cdev) | ||
27 | { | ||
28 | if (led_cdev->brightness_get) | ||
29 | led_cdev->brightness = led_cdev->brightness_get(led_cdev); | ||
30 | } | ||
31 | |||
32 | static ssize_t brightness_show(struct device *dev, | 27 | static ssize_t brightness_show(struct device *dev, |
33 | struct device_attribute *attr, char *buf) | 28 | struct device_attribute *attr, char *buf) |
34 | { | 29 | { |
@@ -59,14 +54,14 @@ static ssize_t brightness_store(struct device *dev, | |||
59 | } | 54 | } |
60 | static DEVICE_ATTR_RW(brightness); | 55 | static DEVICE_ATTR_RW(brightness); |
61 | 56 | ||
62 | static ssize_t led_max_brightness_show(struct device *dev, | 57 | static ssize_t max_brightness_show(struct device *dev, |
63 | struct device_attribute *attr, char *buf) | 58 | struct device_attribute *attr, char *buf) |
64 | { | 59 | { |
65 | struct led_classdev *led_cdev = dev_get_drvdata(dev); | 60 | struct led_classdev *led_cdev = dev_get_drvdata(dev); |
66 | 61 | ||
67 | return sprintf(buf, "%u\n", led_cdev->max_brightness); | 62 | return sprintf(buf, "%u\n", led_cdev->max_brightness); |
68 | } | 63 | } |
69 | static DEVICE_ATTR(max_brightness, 0444, led_max_brightness_show, NULL); | 64 | static DEVICE_ATTR_RO(max_brightness); |
70 | 65 | ||
71 | #ifdef CONFIG_LEDS_TRIGGERS | 66 | #ifdef CONFIG_LEDS_TRIGGERS |
72 | static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store); | 67 | static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store); |
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 71b40d3bf776..aaa8eba9099f 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c | |||
@@ -12,10 +12,11 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/leds.h> | ||
15 | #include <linux/list.h> | 16 | #include <linux/list.h> |
16 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/mutex.h> | ||
17 | #include <linux/rwsem.h> | 19 | #include <linux/rwsem.h> |
18 | #include <linux/leds.h> | ||
19 | #include "leds.h" | 20 | #include "leds.h" |
20 | 21 | ||
21 | DECLARE_RWSEM(leds_list_lock); | 22 | DECLARE_RWSEM(leds_list_lock); |
@@ -126,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev, | |||
126 | __led_set_brightness(led_cdev, brightness); | 127 | __led_set_brightness(led_cdev, brightness); |
127 | } | 128 | } |
128 | EXPORT_SYMBOL(led_set_brightness); | 129 | EXPORT_SYMBOL(led_set_brightness); |
130 | |||
131 | int led_update_brightness(struct led_classdev *led_cdev) | ||
132 | { | ||
133 | int ret = 0; | ||
134 | |||
135 | if (led_cdev->brightness_get) { | ||
136 | ret = led_cdev->brightness_get(led_cdev); | ||
137 | if (ret >= 0) { | ||
138 | led_cdev->brightness = ret; | ||
139 | return 0; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | return ret; | ||
144 | } | ||
145 | EXPORT_SYMBOL(led_update_brightness); | ||
diff --git a/drivers/leds/leds-gpio-register.c b/drivers/leds/leds-gpio-register.c index 1c4ed5510f35..75717ba68ae0 100644 --- a/drivers/leds/leds-gpio-register.c +++ b/drivers/leds/leds-gpio-register.c | |||
@@ -7,9 +7,9 @@ | |||
7 | * Free Software Foundation. | 7 | * Free Software Foundation. |
8 | */ | 8 | */ |
9 | #include <linux/err.h> | 9 | #include <linux/err.h> |
10 | #include <linux/leds.h> | ||
10 | #include <linux/platform_device.h> | 11 | #include <linux/platform_device.h> |
11 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
12 | #include <linux/leds.h> | ||
13 | 13 | ||
14 | /** | 14 | /** |
15 | * gpio_led_register_device - register a gpio-led device | 15 | * gpio_led_register_device - register a gpio-led device |
@@ -28,6 +28,9 @@ struct platform_device *__init gpio_led_register_device( | |||
28 | struct platform_device *ret; | 28 | struct platform_device *ret; |
29 | struct gpio_led_platform_data _pdata = *pdata; | 29 | struct gpio_led_platform_data _pdata = *pdata; |
30 | 30 | ||
31 | if (!pdata->num_leds) | ||
32 | return ERR_PTR(-EINVAL); | ||
33 | |||
31 | _pdata.leds = kmemdup(pdata->leds, | 34 | _pdata.leds = kmemdup(pdata->leds, |
32 | pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL); | 35 | pdata->num_leds * sizeof(*pdata->leds), GFP_KERNEL); |
33 | if (!_pdata.leds) | 36 | if (!_pdata.leds) |
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index 57ff20fecf57..b4518c8751c8 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c | |||
@@ -10,17 +10,17 @@ | |||
10 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
11 | * | 11 | * |
12 | */ | 12 | */ |
13 | #include <linux/kernel.h> | 13 | #include <linux/err.h> |
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/gpio.h> | 14 | #include <linux/gpio.h> |
15 | #include <linux/kernel.h> | ||
16 | #include <linux/leds.h> | 16 | #include <linux/leds.h> |
17 | #include <linux/module.h> | ||
17 | #include <linux/of.h> | 18 | #include <linux/of.h> |
18 | #include <linux/of_platform.h> | ||
19 | #include <linux/of_gpio.h> | 19 | #include <linux/of_gpio.h> |
20 | #include <linux/of_platform.h> | ||
21 | #include <linux/platform_device.h> | ||
20 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
21 | #include <linux/workqueue.h> | 23 | #include <linux/workqueue.h> |
22 | #include <linux/module.h> | ||
23 | #include <linux/err.h> | ||
24 | 24 | ||
25 | struct gpio_led_data { | 25 | struct gpio_led_data { |
26 | struct led_classdev cdev; | 26 | struct led_classdev cdev; |
@@ -36,7 +36,7 @@ struct gpio_led_data { | |||
36 | 36 | ||
37 | static void gpio_led_work(struct work_struct *work) | 37 | static void gpio_led_work(struct work_struct *work) |
38 | { | 38 | { |
39 | struct gpio_led_data *led_dat = | 39 | struct gpio_led_data *led_dat = |
40 | container_of(work, struct gpio_led_data, work); | 40 | container_of(work, struct gpio_led_data, work); |
41 | 41 | ||
42 | if (led_dat->blinking) { | 42 | if (led_dat->blinking) { |
@@ -235,14 +235,12 @@ static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) | |||
235 | } | 235 | } |
236 | #endif /* CONFIG_OF_GPIO */ | 236 | #endif /* CONFIG_OF_GPIO */ |
237 | 237 | ||
238 | |||
239 | static int gpio_led_probe(struct platform_device *pdev) | 238 | static int gpio_led_probe(struct platform_device *pdev) |
240 | { | 239 | { |
241 | struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev); | 240 | struct gpio_led_platform_data *pdata = dev_get_platdata(&pdev->dev); |
242 | struct gpio_leds_priv *priv; | 241 | struct gpio_leds_priv *priv; |
243 | int i, ret = 0; | 242 | int i, ret = 0; |
244 | 243 | ||
245 | |||
246 | if (pdata && pdata->num_leds) { | 244 | if (pdata && pdata->num_leds) { |
247 | priv = devm_kzalloc(&pdev->dev, | 245 | priv = devm_kzalloc(&pdev->dev, |
248 | sizeof_gpio_leds_priv(pdata->num_leds), | 246 | sizeof_gpio_leds_priv(pdata->num_leds), |
diff --git a/drivers/leds/leds-lp3944.c b/drivers/leds/leds-lp3944.c index 8e1abdcd4c9d..53144fb96167 100644 --- a/drivers/leds/leds-lp3944.c +++ b/drivers/leds/leds-lp3944.c | |||
@@ -335,7 +335,8 @@ static int lp3944_configure(struct i2c_client *client, | |||
335 | } | 335 | } |
336 | 336 | ||
337 | /* to expose the default value to userspace */ | 337 | /* to expose the default value to userspace */ |
338 | led->ldev.brightness = led->status; | 338 | led->ldev.brightness = |
339 | (enum led_brightness) led->status; | ||
339 | 340 | ||
340 | /* Set the default led status */ | 341 | /* Set the default led status */ |
341 | err = lp3944_led_set(led, led->status); | 342 | err = lp3944_led_set(led, led->status); |
diff --git a/drivers/leds/trigger/ledtrig-gpio.c b/drivers/leds/trigger/ledtrig-gpio.c index 35812e3a37f2..c86c41826476 100644 --- a/drivers/leds/trigger/ledtrig-gpio.c +++ b/drivers/leds/trigger/ledtrig-gpio.c | |||
@@ -48,7 +48,7 @@ static void gpio_trig_work(struct work_struct *work) | |||
48 | if (!gpio_data->gpio) | 48 | if (!gpio_data->gpio) |
49 | return; | 49 | return; |
50 | 50 | ||
51 | tmp = gpio_get_value(gpio_data->gpio); | 51 | tmp = gpio_get_value_cansleep(gpio_data->gpio); |
52 | if (gpio_data->inverted) | 52 | if (gpio_data->inverted) |
53 | tmp = !tmp; | 53 | tmp = !tmp; |
54 | 54 | ||
diff --git a/include/linux/leds.h b/include/linux/leds.h index e43686472197..a57611d0c94e 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h | |||
@@ -13,8 +13,8 @@ | |||
13 | #define __LINUX_LEDS_H_INCLUDED | 13 | #define __LINUX_LEDS_H_INCLUDED |
14 | 14 | ||
15 | #include <linux/list.h> | 15 | #include <linux/list.h> |
16 | #include <linux/spinlock.h> | ||
17 | #include <linux/rwsem.h> | 16 | #include <linux/rwsem.h> |
17 | #include <linux/spinlock.h> | ||
18 | #include <linux/timer.h> | 18 | #include <linux/timer.h> |
19 | #include <linux/workqueue.h> | 19 | #include <linux/workqueue.h> |
20 | 20 | ||
@@ -31,8 +31,8 @@ enum led_brightness { | |||
31 | 31 | ||
32 | struct led_classdev { | 32 | struct led_classdev { |
33 | const char *name; | 33 | const char *name; |
34 | int brightness; | 34 | enum led_brightness brightness; |
35 | int max_brightness; | 35 | enum led_brightness max_brightness; |
36 | int flags; | 36 | int flags; |
37 | 37 | ||
38 | /* Lower 16 bits reflect status */ | 38 | /* Lower 16 bits reflect status */ |
@@ -140,6 +140,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev, | |||
140 | */ | 140 | */ |
141 | extern void led_set_brightness(struct led_classdev *led_cdev, | 141 | extern void led_set_brightness(struct led_classdev *led_cdev, |
142 | enum led_brightness brightness); | 142 | enum led_brightness brightness); |
143 | /** | ||
144 | * led_update_brightness - update LED brightness | ||
145 | * @led_cdev: the LED to query | ||
146 | * | ||
147 | * Get an LED's current brightness and update led_cdev->brightness | ||
148 | * member with the obtained value. | ||
149 | * | ||
150 | * Returns: 0 on success or negative error value on failure | ||
151 | */ | ||
152 | extern int led_update_brightness(struct led_classdev *led_cdev); | ||
143 | 153 | ||
144 | /* | 154 | /* |
145 | * LED Triggers | 155 | * LED Triggers |