aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorBob Rodgers <Robert_Rodgers@dell.com>2010-02-17 16:23:31 -0500
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-16 15:49:21 -0400
commit72dcd8d08aca4ac6154dc37243880ee306c7ea73 (patch)
tree7df03c727adb82dd8b2fb2bc2dd32f5667d7cfbc /drivers/leds
parentd09e16664be88dc8463fe7508a2123460bf6d676 (diff)
leds: Add Dell Business Class Netbook LED driver
This patch adds an LED driver to support the Dell Activity LED on the Dell Latitude 2100 netbook and future products to come. The Activity LED is visible externally in the lid so classroom instructors can observe it from a distance. The driver uses the sysfs led_class and provides a standard LED interface. Signed-off by: Bob Rodgers <Robert_Rodgers@dell.com> Signed-off-by: Louis Davis <Louis_Davis@dell.com> Signed-off-by: Jim Dailey <Jim_Dailey@dell.com>, Developers Acked-by: Matthew Garrett <mjg@redhat.com> Acked-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/Kconfig7
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/dell-led.c200
3 files changed, 208 insertions, 0 deletions
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index d86e1a3ee0b7..505eb64c329c 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -278,6 +278,13 @@ config LEDS_ADP5520
278 To compile this driver as a module, choose M here: the module will 278 To compile this driver as a module, choose M here: the module will
279 be called leds-adp5520. 279 be called leds-adp5520.
280 280
281config LEDS_DELL_NETBOOKS
282 tristate "External LED on Dell Business Netbooks"
283 depends on X86 && ACPI_WMI
284 help
285 This adds support for the Latitude 2100 and similar
286 notebooks that have an external LED.
287
281config LEDS_TRIGGERS 288config LEDS_TRIGGERS
282 bool "LED Trigger support" 289 bool "LED Trigger support"
283 help 290 help
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index d76fb32b77c0..0cd8b9957380 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_LEDS_REGULATOR) += leds-regulator.o
34obj-$(CONFIG_LEDS_INTEL_SS4200) += leds-ss4200.o 34obj-$(CONFIG_LEDS_INTEL_SS4200) += leds-ss4200.o
35obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o 35obj-$(CONFIG_LEDS_LT3593) += leds-lt3593.o
36obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o 36obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o
37obj-$(CONFIG_LEDS_DELL_NETBOOKS) += dell-led.o
37 38
38# LED SPI Drivers 39# LED SPI Drivers
39obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o 40obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
new file mode 100644
index 000000000000..ee310891fff8
--- /dev/null
+++ b/drivers/leds/dell-led.c
@@ -0,0 +1,200 @@
1/*
2 * dell_led.c - Dell LED Driver
3 *
4 * Copyright (C) 2010 Dell Inc.
5 * Louis Davis <louis_davis@dell.com>
6 * Jim Dailey <jim_dailey@dell.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 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/acpi.h>
15#include <linux/leds.h>
16
17MODULE_AUTHOR("Louis Davis/Jim Dailey");
18MODULE_DESCRIPTION("Dell LED Control Driver");
19MODULE_LICENSE("GPL");
20
21#define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
22MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
23
24/* Error Result Codes: */
25#define INVALID_DEVICE_ID 250
26#define INVALID_PARAMETER 251
27#define INVALID_BUFFER 252
28#define INTERFACE_ERROR 253
29#define UNSUPPORTED_COMMAND 254
30#define UNSPECIFIED_ERROR 255
31
32/* Device ID */
33#define DEVICE_ID_PANEL_BACK 1
34
35/* LED Commands */
36#define CMD_LED_ON 16
37#define CMD_LED_OFF 17
38#define CMD_LED_BLINK 18
39
40struct bios_args {
41 unsigned char length;
42 unsigned char result_code;
43 unsigned char device_id;
44 unsigned char command;
45 unsigned char on_time;
46 unsigned char off_time;
47};
48
49static int dell_led_perform_fn(u8 length,
50 u8 result_code,
51 u8 device_id,
52 u8 command,
53 u8 on_time,
54 u8 off_time)
55{
56 struct bios_args *bios_return;
57 u8 return_code;
58 union acpi_object *obj;
59 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
60 struct acpi_buffer input;
61 acpi_status status;
62
63 struct bios_args args;
64 args.length = length;
65 args.result_code = result_code;
66 args.device_id = device_id;
67 args.command = command;
68 args.on_time = on_time;
69 args.off_time = off_time;
70
71 input.length = sizeof(struct bios_args);
72 input.pointer = &args;
73
74 status = wmi_evaluate_method(DELL_LED_BIOS_GUID,
75 1,
76 1,
77 &input,
78 &output);
79
80 if (ACPI_FAILURE(status))
81 return status;
82
83 obj = output.pointer;
84
85 if (!obj)
86 return -EINVAL;
87 else if (obj->type != ACPI_TYPE_BUFFER) {
88 kfree(obj);
89 return -EINVAL;
90 }
91
92 bios_return = ((struct bios_args *)obj->buffer.pointer);
93 return_code = bios_return->result_code;
94
95 kfree(obj);
96
97 return return_code;
98}
99
100static int led_on(void)
101{
102 return dell_led_perform_fn(3, /* Length of command */
103 INTERFACE_ERROR, /* Init to INTERFACE_ERROR */
104 DEVICE_ID_PANEL_BACK, /* Device ID */
105 CMD_LED_ON, /* Command */
106 0, /* not used */
107 0); /* not used */
108}
109
110static int led_off(void)
111{
112 return dell_led_perform_fn(3, /* Length of command */
113 INTERFACE_ERROR, /* Init to INTERFACE_ERROR */
114 DEVICE_ID_PANEL_BACK, /* Device ID */
115 CMD_LED_OFF, /* Command */
116 0, /* not used */
117 0); /* not used */
118}
119
120static int led_blink(unsigned char on_eighths,
121 unsigned char off_eighths)
122{
123 return dell_led_perform_fn(5, /* Length of command */
124 INTERFACE_ERROR, /* Init to INTERFACE_ERROR */
125 DEVICE_ID_PANEL_BACK, /* Device ID */
126 CMD_LED_BLINK, /* Command */
127 on_eighths, /* blink on in eigths of a second */
128 off_eighths); /* blink off in eights of a second */
129}
130
131static void dell_led_set(struct led_classdev *led_cdev,
132 enum led_brightness value)
133{
134 if (value == LED_OFF)
135 led_off();
136 else
137 led_on();
138}
139
140static int dell_led_blink(struct led_classdev *led_cdev,
141 unsigned long *delay_on,
142 unsigned long *delay_off)
143{
144 unsigned long on_eighths;
145 unsigned long off_eighths;
146
147 /* The Dell LED delay is based on 125ms intervals.
148 Need to round up to next interval. */
149
150 on_eighths = (*delay_on + 124) / 125;
151 if (0 == on_eighths)
152 on_eighths = 1;
153 if (on_eighths > 255)
154 on_eighths = 255;
155 *delay_on = on_eighths * 125;
156
157 off_eighths = (*delay_off + 124) / 125;
158 if (0 == off_eighths)
159 off_eighths = 1;
160 if (off_eighths > 255)
161 off_eighths = 255;
162 *delay_off = off_eighths * 125;
163
164 led_blink(on_eighths, off_eighths);
165
166 return 0;
167}
168
169static struct led_classdev dell_led = {
170 .name = "dell::lid",
171 .brightness = LED_OFF,
172 .max_brightness = 1,
173 .brightness_set = dell_led_set,
174 .blink_set = dell_led_blink,
175 .flags = LED_CORE_SUSPENDRESUME,
176};
177
178static int __init dell_led_init(void)
179{
180 int error = 0;
181
182 if (!wmi_has_guid(DELL_LED_BIOS_GUID))
183 return -ENODEV;
184
185 error = led_off();
186 if (error != 0)
187 return -ENODEV;
188
189 return led_classdev_register(NULL, &dell_led);
190}
191
192static void __exit dell_led_exit(void)
193{
194 led_classdev_unregister(&dell_led);
195
196 led_off();
197}
198
199module_init(dell_led_init);
200module_exit(dell_led_exit);