aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds/led-class.c
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <lg@denx.de>2009-01-10 13:54:39 -0500
committerRichard Purdie <rpurdie@linux.intel.com>2009-04-06 11:06:25 -0400
commit1bd465e6b0e2b559db47420fea686507a01cfab0 (patch)
tree623c7a906e4ce117873a33f5b1717e150d5f9e59 /drivers/leds/led-class.c
parenta7d878af94b223013a48078e0c8c0a654c24a057 (diff)
leds: allow led-drivers to use a variable range of brightness values
This patch allows drivers to override the default maximum brightness value of 255. We take care to preserve backwards-compatibility as much as possible, so that user-space ABI doesn't change for existing drivers. LED trigger code has also been updated to use the per-LED maximum. Signed-off-by: Guennadi Liakhovetski <lg@denx.de> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'drivers/leds/led-class.c')
-rw-r--r--drivers/leds/led-class.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 52f82e3ea13a..f2cc13d76810 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -64,7 +64,16 @@ static ssize_t led_brightness_store(struct device *dev,
64 return ret; 64 return ret;
65} 65}
66 66
67static ssize_t led_max_brightness_show(struct device *dev,
68 struct device_attribute *attr, char *buf)
69{
70 struct led_classdev *led_cdev = dev_get_drvdata(dev);
71
72 return sprintf(buf, "%u\n", led_cdev->max_brightness);
73}
74
67static DEVICE_ATTR(brightness, 0644, led_brightness_show, led_brightness_store); 75static DEVICE_ATTR(brightness, 0644, led_brightness_show, led_brightness_store);
76static DEVICE_ATTR(max_brightness, 0444, led_max_brightness_show, NULL);
68#ifdef CONFIG_LEDS_TRIGGERS 77#ifdef CONFIG_LEDS_TRIGGERS
69static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store); 78static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);
70#endif 79#endif
@@ -138,6 +147,13 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
138 list_add_tail(&led_cdev->node, &leds_list); 147 list_add_tail(&led_cdev->node, &leds_list);
139 up_write(&leds_list_lock); 148 up_write(&leds_list_lock);
140 149
150 if (!led_cdev->max_brightness)
151 led_cdev->max_brightness = LED_FULL;
152
153 rc = device_create_file(led_cdev->dev, &dev_attr_max_brightness);
154 if (rc)
155 goto err_out_attr_max;
156
141 led_update_brightness(led_cdev); 157 led_update_brightness(led_cdev);
142 158
143#ifdef CONFIG_LEDS_TRIGGERS 159#ifdef CONFIG_LEDS_TRIGGERS
@@ -155,9 +171,11 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
155 171
156#ifdef CONFIG_LEDS_TRIGGERS 172#ifdef CONFIG_LEDS_TRIGGERS
157err_out_led_list: 173err_out_led_list:
174 device_remove_file(led_cdev->dev, &dev_attr_max_brightness);
175#endif
176err_out_attr_max:
158 device_remove_file(led_cdev->dev, &dev_attr_brightness); 177 device_remove_file(led_cdev->dev, &dev_attr_brightness);
159 list_del(&led_cdev->node); 178 list_del(&led_cdev->node);
160#endif
161err_out: 179err_out:
162 device_unregister(led_cdev->dev); 180 device_unregister(led_cdev->dev);
163 return rc; 181 return rc;
@@ -172,6 +190,7 @@ EXPORT_SYMBOL_GPL(led_classdev_register);
172 */ 190 */
173void led_classdev_unregister(struct led_classdev *led_cdev) 191void led_classdev_unregister(struct led_classdev *led_cdev)
174{ 192{
193 device_remove_file(led_cdev->dev, &dev_attr_max_brightness);
175 device_remove_file(led_cdev->dev, &dev_attr_brightness); 194 device_remove_file(led_cdev->dev, &dev_attr_brightness);
176#ifdef CONFIG_LEDS_TRIGGERS 195#ifdef CONFIG_LEDS_TRIGGERS
177 device_remove_file(led_cdev->dev, &dev_attr_trigger); 196 device_remove_file(led_cdev->dev, &dev_attr_trigger);