aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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
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')
-rw-r--r--drivers/leds/led-class.c21
-rw-r--r--drivers/leds/leds.h4
-rw-r--r--drivers/leds/ledtrig-default-on.c2
-rw-r--r--drivers/leds/ledtrig-heartbeat.c4
-rw-r--r--drivers/leds/ledtrig-ide-disk.c3
-rw-r--r--drivers/leds/ledtrig-timer.c2
6 files changed, 28 insertions, 8 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);
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index 5edbf52c4fa7..2dd8ecbfdc31 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -20,8 +20,8 @@
20static inline void led_set_brightness(struct led_classdev *led_cdev, 20static inline void led_set_brightness(struct led_classdev *led_cdev,
21 enum led_brightness value) 21 enum led_brightness value)
22{ 22{
23 if (value > LED_FULL) 23 if (value > led_cdev->max_brightness)
24 value = LED_FULL; 24 value = led_cdev->max_brightness;
25 led_cdev->brightness = value; 25 led_cdev->brightness = value;
26 if (!(led_cdev->flags & LED_SUSPENDED)) 26 if (!(led_cdev->flags & LED_SUSPENDED))
27 led_cdev->brightness_set(led_cdev, value); 27 led_cdev->brightness_set(led_cdev, value);
diff --git a/drivers/leds/ledtrig-default-on.c b/drivers/leds/ledtrig-default-on.c
index 92995e40cfa4..a4ef54b9d508 100644
--- a/drivers/leds/ledtrig-default-on.c
+++ b/drivers/leds/ledtrig-default-on.c
@@ -19,7 +19,7 @@
19 19
20static void defon_trig_activate(struct led_classdev *led_cdev) 20static void defon_trig_activate(struct led_classdev *led_cdev)
21{ 21{
22 led_set_brightness(led_cdev, LED_FULL); 22 led_set_brightness(led_cdev, led_cdev->max_brightness);
23} 23}
24 24
25static struct led_trigger defon_led_trigger = { 25static struct led_trigger defon_led_trigger = {
diff --git a/drivers/leds/ledtrig-heartbeat.c b/drivers/leds/ledtrig-heartbeat.c
index 4bf8cec8b8c1..c1c1ea6f817b 100644
--- a/drivers/leds/ledtrig-heartbeat.c
+++ b/drivers/leds/ledtrig-heartbeat.c
@@ -47,7 +47,7 @@ static void led_heartbeat_function(unsigned long data)
47 msecs_to_jiffies(heartbeat_data->period); 47 msecs_to_jiffies(heartbeat_data->period);
48 delay = msecs_to_jiffies(70); 48 delay = msecs_to_jiffies(70);
49 heartbeat_data->phase++; 49 heartbeat_data->phase++;
50 brightness = LED_FULL; 50 brightness = led_cdev->max_brightness;
51 break; 51 break;
52 case 1: 52 case 1:
53 delay = heartbeat_data->period / 4 - msecs_to_jiffies(70); 53 delay = heartbeat_data->period / 4 - msecs_to_jiffies(70);
@@ -56,7 +56,7 @@ static void led_heartbeat_function(unsigned long data)
56 case 2: 56 case 2:
57 delay = msecs_to_jiffies(70); 57 delay = msecs_to_jiffies(70);
58 heartbeat_data->phase++; 58 heartbeat_data->phase++;
59 brightness = LED_FULL; 59 brightness = led_cdev->max_brightness;
60 break; 60 break;
61 default: 61 default:
62 delay = heartbeat_data->period - heartbeat_data->period / 4 - 62 delay = heartbeat_data->period - heartbeat_data->period / 4 -
diff --git a/drivers/leds/ledtrig-ide-disk.c b/drivers/leds/ledtrig-ide-disk.c
index 883a577b1b97..ec099fcbcb00 100644
--- a/drivers/leds/ledtrig-ide-disk.c
+++ b/drivers/leds/ledtrig-ide-disk.c
@@ -37,7 +37,8 @@ static void ledtrig_ide_timerfunc(unsigned long data)
37{ 37{
38 if (ide_lastactivity != ide_activity) { 38 if (ide_lastactivity != ide_activity) {
39 ide_lastactivity = ide_activity; 39 ide_lastactivity = ide_activity;
40 led_trigger_event(ledtrig_ide, LED_FULL); 40 /* INT_MAX will set each LED to its maximum brightness */
41 led_trigger_event(ledtrig_ide, INT_MAX);
41 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10)); 42 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
42 } else { 43 } else {
43 led_trigger_event(ledtrig_ide, LED_OFF); 44 led_trigger_event(ledtrig_ide, LED_OFF);
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index 3d6531396dda..3b83406de752 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -166,7 +166,7 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
166 166
167 timer_data->brightness_on = led_get_brightness(led_cdev); 167 timer_data->brightness_on = led_get_brightness(led_cdev);
168 if (timer_data->brightness_on == LED_OFF) 168 if (timer_data->brightness_on == LED_OFF)
169 timer_data->brightness_on = LED_FULL; 169 timer_data->brightness_on = led_cdev->max_brightness;
170 led_cdev->trigger_data = timer_data; 170 led_cdev->trigger_data = timer_data;
171 171
172 init_timer(&timer_data->timer); 172 init_timer(&timer_data->timer);