aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/leds/dell-led.c171
-rw-r--r--include/linux/dell-led.h10
2 files changed, 174 insertions, 7 deletions
diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
index e5c57389efd6..c36acaf566a6 100644
--- a/drivers/leds/dell-led.c
+++ b/drivers/leds/dell-led.c
@@ -15,12 +15,15 @@
15#include <linux/leds.h> 15#include <linux/leds.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/dmi.h>
19#include <linux/dell-led.h>
18 20
19MODULE_AUTHOR("Louis Davis/Jim Dailey"); 21MODULE_AUTHOR("Louis Davis/Jim Dailey");
20MODULE_DESCRIPTION("Dell LED Control Driver"); 22MODULE_DESCRIPTION("Dell LED Control Driver");
21MODULE_LICENSE("GPL"); 23MODULE_LICENSE("GPL");
22 24
23#define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396" 25#define DELL_LED_BIOS_GUID "F6E4FE6E-909D-47cb-8BAB-C9F6F2F8D396"
26#define DELL_APP_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
24MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID); 27MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
25 28
26/* Error Result Codes: */ 29/* Error Result Codes: */
@@ -39,6 +42,149 @@ MODULE_ALIAS("wmi:" DELL_LED_BIOS_GUID);
39#define CMD_LED_OFF 17 42#define CMD_LED_OFF 17
40#define CMD_LED_BLINK 18 43#define CMD_LED_BLINK 18
41 44
45struct app_wmi_args {
46 u16 class;
47 u16 selector;
48 u32 arg1;
49 u32 arg2;
50 u32 arg3;
51 u32 arg4;
52 u32 res1;
53 u32 res2;
54 u32 res3;
55 u32 res4;
56 char dummy[92];
57};
58
59#define GLOBAL_MIC_MUTE_ENABLE 0x364
60#define GLOBAL_MIC_MUTE_DISABLE 0x365
61
62struct dell_bios_data_token {
63 u16 tokenid;
64 u16 location;
65 u16 value;
66};
67
68struct __attribute__ ((__packed__)) dell_bios_calling_interface {
69 struct dmi_header header;
70 u16 cmd_io_addr;
71 u8 cmd_io_code;
72 u32 supported_cmds;
73 struct dell_bios_data_token damap[];
74};
75
76static struct dell_bios_data_token dell_mic_tokens[2];
77
78static int dell_wmi_perform_query(struct app_wmi_args *args)
79{
80 struct app_wmi_args *bios_return;
81 union acpi_object *obj;
82 struct acpi_buffer input;
83 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
84 acpi_status status;
85 u32 rc = -EINVAL;
86
87 input.length = 128;
88 input.pointer = args;
89
90 status = wmi_evaluate_method(DELL_APP_GUID, 0, 1, &input, &output);
91 if (!ACPI_SUCCESS(status))
92 goto err_out0;
93
94 obj = output.pointer;
95 if (!obj)
96 goto err_out0;
97
98 if (obj->type != ACPI_TYPE_BUFFER)
99 goto err_out1;
100
101 bios_return = (struct app_wmi_args *)obj->buffer.pointer;
102 rc = bios_return->res1;
103 if (rc)
104 goto err_out1;
105
106 memcpy(args, bios_return, sizeof(struct app_wmi_args));
107 rc = 0;
108
109 err_out1:
110 kfree(obj);
111 err_out0:
112 return rc;
113}
114
115static void __init find_micmute_tokens(const struct dmi_header *dm, void *dummy)
116{
117 struct dell_bios_calling_interface *calling_interface;
118 struct dell_bios_data_token *token;
119 int token_size = sizeof(struct dell_bios_data_token);
120 int i = 0;
121
122 if (dm->type == 0xda && dm->length > 17) {
123 calling_interface = container_of(dm,
124 struct dell_bios_calling_interface, header);
125
126 token = &calling_interface->damap[i];
127 while (token->tokenid != 0xffff) {
128 if (token->tokenid == GLOBAL_MIC_MUTE_DISABLE)
129 memcpy(&dell_mic_tokens[0], token, token_size);
130 else if (token->tokenid == GLOBAL_MIC_MUTE_ENABLE)
131 memcpy(&dell_mic_tokens[1], token, token_size);
132
133 i++;
134 token = &calling_interface->damap[i];
135 }
136 }
137}
138
139static int dell_micmute_led_set(int state)
140{
141 struct app_wmi_args args;
142 struct dell_bios_data_token *token;
143
144 if (!wmi_has_guid(DELL_APP_GUID))
145 return -ENODEV;
146
147 if (state == 0 || state == 1)
148 token = &dell_mic_tokens[state];
149 else
150 return -EINVAL;
151
152 memset(&args, 0, sizeof(struct app_wmi_args));
153
154 args.class = 1;
155 args.arg1 = token->location;
156 args.arg2 = token->value;
157
158 dell_wmi_perform_query(&args);
159
160 return state;
161}
162
163int dell_app_wmi_led_set(int whichled, int on)
164{
165 int state = 0;
166
167 switch (whichled) {
168 case DELL_LED_MICMUTE:
169 state = dell_micmute_led_set(on);
170 break;
171 default:
172 pr_warn("led type %x is not supported\n", whichled);
173 break;
174 }
175
176 return state;
177}
178EXPORT_SYMBOL_GPL(dell_app_wmi_led_set);
179
180static int __init dell_micmute_led_init(void)
181{
182 memset(dell_mic_tokens, 0, sizeof(struct dell_bios_data_token) * 2);
183 dmi_walk(find_micmute_tokens, NULL);
184
185 return 0;
186}
187
42struct bios_args { 188struct bios_args {
43 unsigned char length; 189 unsigned char length;
44 unsigned char result_code; 190 unsigned char result_code;
@@ -181,21 +327,32 @@ static int __init dell_led_init(void)
181{ 327{
182 int error = 0; 328 int error = 0;
183 329
184 if (!wmi_has_guid(DELL_LED_BIOS_GUID)) 330 if (!wmi_has_guid(DELL_LED_BIOS_GUID) && !wmi_has_guid(DELL_APP_GUID))
185 return -ENODEV; 331 return -ENODEV;
186 332
187 error = led_off(); 333 if (wmi_has_guid(DELL_APP_GUID))
188 if (error != 0) 334 error = dell_micmute_led_init();
189 return -ENODEV;
190 335
191 return led_classdev_register(NULL, &dell_led); 336 if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
337 error = led_off();
338 if (error != 0)
339 return -ENODEV;
340
341 error = led_classdev_register(NULL, &dell_led);
342 }
343
344 return error;
192} 345}
193 346
194static void __exit dell_led_exit(void) 347static void __exit dell_led_exit(void)
195{ 348{
196 led_classdev_unregister(&dell_led); 349 int error = 0;
197 350
198 led_off(); 351 if (wmi_has_guid(DELL_LED_BIOS_GUID)) {
352 error = led_off();
353 if (error == 0)
354 led_classdev_unregister(&dell_led);
355 }
199} 356}
200 357
201module_init(dell_led_init); 358module_init(dell_led_init);
diff --git a/include/linux/dell-led.h b/include/linux/dell-led.h
new file mode 100644
index 000000000000..7009b8bec77b
--- /dev/null
+++ b/include/linux/dell-led.h
@@ -0,0 +1,10 @@
1#ifndef __DELL_LED_H__
2#define __DELL_LED_H__
3
4enum {
5 DELL_LED_MICMUTE,
6};
7
8int dell_app_wmi_led_set(int whichled, int on);
9
10#endif