aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique de Moraes Holschuh <hmh@hmh.eng.br>2008-03-18 05:47:48 -0400
committerRichard Purdie <rpurdie@rpsys.net>2008-04-24 18:37:42 -0400
commit29d76dfa29fe22583aefddccda0bc56aa81035dc (patch)
treefbae9207af63cb270b715a29ee7dc053d7b8a037
parentca3259b3603539e72faacc6821050ee889a52103 (diff)
leds: Add support to leds with readable status
Some led hardware allows drivers to query the led state, and this patch adds a hook to let the led class take advantage of that information when available. Without this functionality, when access to the led hardware is not exclusive (i.e. firmware or hardware might change its state behind the kernel's back), reality goes out of sync with the led class' idea of what the led is doing, which is annoying at best. Behaviour for drivers that do not or cannot read the led status is unchanged. Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
-rw-r--r--drivers/leds/led-class.c9
-rw-r--r--include/linux/leds.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index a8dd59ebedf8..ac05a928f764 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -24,6 +24,12 @@
24 24
25static struct class *leds_class; 25static struct class *leds_class;
26 26
27static void led_update_brightness(struct led_classdev *led_cdev)
28{
29 if (led_cdev->brightness_get)
30 led_cdev->brightness = led_cdev->brightness_get(led_cdev);
31}
32
27static ssize_t led_brightness_show(struct device *dev, 33static ssize_t led_brightness_show(struct device *dev,
28 struct device_attribute *attr, char *buf) 34 struct device_attribute *attr, char *buf)
29{ 35{
@@ -31,6 +37,7 @@ static ssize_t led_brightness_show(struct device *dev,
31 ssize_t ret = 0; 37 ssize_t ret = 0;
32 38
33 /* no lock needed for this */ 39 /* no lock needed for this */
40 led_update_brightness(led_cdev);
34 sprintf(buf, "%u\n", led_cdev->brightness); 41 sprintf(buf, "%u\n", led_cdev->brightness);
35 ret = strlen(buf) + 1; 42 ret = strlen(buf) + 1;
36 43
@@ -113,6 +120,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
113 list_add_tail(&led_cdev->node, &leds_list); 120 list_add_tail(&led_cdev->node, &leds_list);
114 up_write(&leds_list_lock); 121 up_write(&leds_list_lock);
115 122
123 led_update_brightness(led_cdev);
124
116#ifdef CONFIG_LEDS_TRIGGERS 125#ifdef CONFIG_LEDS_TRIGGERS
117 init_rwsem(&led_cdev->trigger_lock); 126 init_rwsem(&led_cdev->trigger_lock);
118 127
diff --git a/include/linux/leds.h b/include/linux/leds.h
index c195a674b6ca..ff1570f97045 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -37,6 +37,8 @@ struct led_classdev {
37 /* Set LED brightness level */ 37 /* Set LED brightness level */
38 void (*brightness_set)(struct led_classdev *led_cdev, 38 void (*brightness_set)(struct led_classdev *led_cdev,
39 enum led_brightness brightness); 39 enum led_brightness brightness);
40 /* Get LED brightness level */
41 enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
40 42
41 /* Activate hardware accelerated blink */ 43 /* Activate hardware accelerated blink */
42 int (*blink_set)(struct led_classdev *led_cdev, 44 int (*blink_set)(struct led_classdev *led_cdev,