]>
Commit | Line | Data |
---|---|---|
ad8f07cc MG |
1 | /* |
2 | * Driver for Dell laptop extras | |
3 | * | |
4 | * Copyright (c) Red Hat <mjg@redhat.com> | |
5 | * | |
6 | * Based on documentation in the libsmbios package, Copyright (C) 2005 Dell | |
7 | * Inc. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
eb889524 JP |
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
15 | ||
ad8f07cc MG |
16 | #include <linux/module.h> |
17 | #include <linux/kernel.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/platform_device.h> | |
20 | #include <linux/backlight.h> | |
21 | #include <linux/err.h> | |
22 | #include <linux/dmi.h> | |
23 | #include <linux/io.h> | |
24 | #include <linux/rfkill.h> | |
25 | #include <linux/power_supply.h> | |
26 | #include <linux/acpi.h> | |
116ee77b | 27 | #include <linux/mm.h> |
814cb8ad | 28 | #include <linux/i8042.h> |
5a0e3ad6 | 29 | #include <linux/slab.h> |
037accfa KYL |
30 | #include <linux/debugfs.h> |
31 | #include <linux/seq_file.h> | |
cad73120 | 32 | #include "../../firmware/dcdbas.h" |
ad8f07cc MG |
33 | |
34 | #define BRIGHTNESS_TOKEN 0x7d | |
35 | ||
36 | /* This structure will be modified by the firmware when we enter | |
37 | * system management mode, hence the volatiles */ | |
38 | ||
39 | struct calling_interface_buffer { | |
40 | u16 class; | |
41 | u16 select; | |
42 | volatile u32 input[4]; | |
43 | volatile u32 output[4]; | |
44 | } __packed; | |
45 | ||
46 | struct calling_interface_token { | |
47 | u16 tokenID; | |
48 | u16 location; | |
49 | union { | |
50 | u16 value; | |
51 | u16 stringlength; | |
52 | }; | |
53 | }; | |
54 | ||
55 | struct calling_interface_structure { | |
56 | struct dmi_header header; | |
57 | u16 cmdIOAddress; | |
58 | u8 cmdIOCode; | |
59 | u32 supportedCmds; | |
60 | struct calling_interface_token tokens[]; | |
61 | } __packed; | |
62 | ||
2d8b90be AK |
63 | struct quirk_entry { |
64 | u8 touchpad_led; | |
65 | }; | |
66 | ||
67 | static struct quirk_entry *quirks; | |
68 | ||
69 | static struct quirk_entry quirk_dell_vostro_v130 = { | |
70 | .touchpad_led = 1, | |
71 | }; | |
72 | ||
73 | static int dmi_matched(const struct dmi_system_id *dmi) | |
74 | { | |
75 | quirks = dmi->driver_data; | |
76 | return 1; | |
77 | } | |
78 | ||
ad8f07cc MG |
79 | static int da_command_address; |
80 | static int da_command_code; | |
81 | static int da_num_tokens; | |
82 | static struct calling_interface_token *da_tokens; | |
83 | ||
ada3248a AJ |
84 | static struct platform_driver platform_driver = { |
85 | .driver = { | |
86 | .name = "dell-laptop", | |
87 | .owner = THIS_MODULE, | |
88 | } | |
89 | }; | |
90 | ||
91 | static struct platform_device *platform_device; | |
ad8f07cc MG |
92 | static struct backlight_device *dell_backlight_device; |
93 | static struct rfkill *wifi_rfkill; | |
94 | static struct rfkill *bluetooth_rfkill; | |
95 | static struct rfkill *wwan_rfkill; | |
96 | ||
97 | static const struct dmi_system_id __initdata dell_device_table[] = { | |
98 | { | |
99 | .ident = "Dell laptop", | |
100 | .matches = { | |
101 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
102 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), | |
103 | }, | |
104 | }, | |
410d44c7 RK |
105 | { |
106 | .matches = { | |
107 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
108 | DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/ | |
109 | }, | |
110 | }, | |
cb6a7937 EA |
111 | { |
112 | .ident = "Dell Computer Corporation", | |
113 | .matches = { | |
114 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), | |
115 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), | |
116 | }, | |
117 | }, | |
ad8f07cc MG |
118 | { } |
119 | }; | |
35ae64fe | 120 | MODULE_DEVICE_TABLE(dmi, dell_device_table); |
ad8f07cc | 121 | |
e5fefd0c ML |
122 | static struct dmi_system_id __devinitdata dell_blacklist[] = { |
123 | /* Supported by compal-laptop */ | |
124 | { | |
125 | .ident = "Dell Mini 9", | |
126 | .matches = { | |
127 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
128 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"), | |
129 | }, | |
130 | }, | |
131 | { | |
132 | .ident = "Dell Mini 10", | |
133 | .matches = { | |
134 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
135 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"), | |
136 | }, | |
137 | }, | |
138 | { | |
139 | .ident = "Dell Mini 10v", | |
140 | .matches = { | |
141 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
142 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"), | |
143 | }, | |
144 | }, | |
c3f755e3 VE |
145 | { |
146 | .ident = "Dell Mini 1012", | |
147 | .matches = { | |
148 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
149 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"), | |
150 | }, | |
151 | }, | |
e5fefd0c ML |
152 | { |
153 | .ident = "Dell Inspiron 11z", | |
154 | .matches = { | |
155 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
156 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"), | |
157 | }, | |
158 | }, | |
159 | { | |
160 | .ident = "Dell Mini 12", | |
161 | .matches = { | |
162 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
163 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"), | |
164 | }, | |
165 | }, | |
166 | {} | |
167 | }; | |
168 | ||
2d8b90be AK |
169 | static struct dmi_system_id __devinitdata dell_quirks[] = { |
170 | { | |
171 | .callback = dmi_matched, | |
172 | .ident = "Dell Vostro V130", | |
173 | .matches = { | |
174 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
175 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"), | |
176 | }, | |
177 | .driver_data = &quirk_dell_vostro_v130, | |
178 | }, | |
179 | { | |
180 | .callback = dmi_matched, | |
181 | .ident = "Dell Vostro V131", | |
182 | .matches = { | |
183 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
184 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), | |
185 | }, | |
186 | .driver_data = &quirk_dell_vostro_v130, | |
187 | }, | |
2a748853 AK |
188 | { |
189 | .callback = dmi_matched, | |
190 | .ident = "Dell Vostro 3555", | |
191 | .matches = { | |
192 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
193 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"), | |
194 | }, | |
195 | .driver_data = &quirk_dell_vostro_v130, | |
196 | }, | |
197 | { | |
198 | .callback = dmi_matched, | |
199 | .ident = "Dell Inspiron N311z", | |
200 | .matches = { | |
201 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
202 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"), | |
203 | }, | |
204 | .driver_data = &quirk_dell_vostro_v130, | |
205 | }, | |
206 | { | |
207 | .callback = dmi_matched, | |
208 | .ident = "Dell Inspiron M5110", | |
209 | .matches = { | |
210 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
211 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), | |
212 | }, | |
213 | .driver_data = &quirk_dell_vostro_v130, | |
214 | }, | |
2d8b90be AK |
215 | }; |
216 | ||
116ee77b | 217 | static struct calling_interface_buffer *buffer; |
94d8f785 IM |
218 | static struct page *bufferpage; |
219 | static DEFINE_MUTEX(buffer_mutex); | |
116ee77b | 220 | |
c6760ac4 MG |
221 | static int hwswitch_state; |
222 | ||
116ee77b SH |
223 | static void get_buffer(void) |
224 | { | |
225 | mutex_lock(&buffer_mutex); | |
226 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); | |
227 | } | |
228 | ||
229 | static void release_buffer(void) | |
230 | { | |
231 | mutex_unlock(&buffer_mutex); | |
232 | } | |
233 | ||
4788df4c | 234 | static void __init parse_da_table(const struct dmi_header *dm) |
ad8f07cc MG |
235 | { |
236 | /* Final token is a terminator, so we don't want to copy it */ | |
237 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; | |
238 | struct calling_interface_structure *table = | |
239 | container_of(dm, struct calling_interface_structure, header); | |
240 | ||
241 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least | |
242 | 6 bytes of entry */ | |
243 | ||
244 | if (dm->length < 17) | |
245 | return; | |
246 | ||
247 | da_command_address = table->cmdIOAddress; | |
248 | da_command_code = table->cmdIOCode; | |
249 | ||
250 | da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * | |
251 | sizeof(struct calling_interface_token), | |
252 | GFP_KERNEL); | |
253 | ||
254 | if (!da_tokens) | |
255 | return; | |
256 | ||
257 | memcpy(da_tokens+da_num_tokens, table->tokens, | |
258 | sizeof(struct calling_interface_token) * tokens); | |
259 | ||
260 | da_num_tokens += tokens; | |
261 | } | |
262 | ||
4788df4c | 263 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
ad8f07cc MG |
264 | { |
265 | switch (dm->type) { | |
266 | case 0xd4: /* Indexed IO */ | |
ad8f07cc | 267 | case 0xd5: /* Protected Area Type 1 */ |
ad8f07cc MG |
268 | case 0xd6: /* Protected Area Type 2 */ |
269 | break; | |
270 | case 0xda: /* Calling interface */ | |
271 | parse_da_table(dm); | |
272 | break; | |
273 | } | |
274 | } | |
275 | ||
276 | static int find_token_location(int tokenid) | |
277 | { | |
278 | int i; | |
279 | for (i = 0; i < da_num_tokens; i++) { | |
280 | if (da_tokens[i].tokenID == tokenid) | |
281 | return da_tokens[i].location; | |
282 | } | |
283 | ||
284 | return -1; | |
285 | } | |
286 | ||
287 | static struct calling_interface_buffer * | |
288 | dell_send_request(struct calling_interface_buffer *buffer, int class, | |
289 | int select) | |
290 | { | |
291 | struct smi_cmd command; | |
292 | ||
293 | command.magic = SMI_CMD_MAGIC; | |
294 | command.command_address = da_command_address; | |
295 | command.command_code = da_command_code; | |
296 | command.ebx = virt_to_phys(buffer); | |
297 | command.ecx = 0x42534931; | |
298 | ||
299 | buffer->class = class; | |
300 | buffer->select = select; | |
301 | ||
302 | dcdbas_smi_request(&command); | |
303 | ||
304 | return buffer; | |
305 | } | |
306 | ||
307 | /* Derived from information in DellWirelessCtl.cpp: | |
308 | Class 17, select 11 is radio control. It returns an array of 32-bit values. | |
309 | ||
c6760ac4 MG |
310 | Input byte 0 = 0: Wireless information |
311 | ||
ad8f07cc MG |
312 | result[0]: return code |
313 | result[1]: | |
314 | Bit 0: Hardware switch supported | |
315 | Bit 1: Wifi locator supported | |
316 | Bit 2: Wifi is supported | |
317 | Bit 3: Bluetooth is supported | |
318 | Bit 4: WWAN is supported | |
319 | Bit 5: Wireless keyboard supported | |
320 | Bits 6-7: Reserved | |
321 | Bit 8: Wifi is installed | |
322 | Bit 9: Bluetooth is installed | |
323 | Bit 10: WWAN is installed | |
324 | Bits 11-15: Reserved | |
325 | Bit 16: Hardware switch is on | |
326 | Bit 17: Wifi is blocked | |
327 | Bit 18: Bluetooth is blocked | |
328 | Bit 19: WWAN is blocked | |
329 | Bits 20-31: Reserved | |
330 | result[2]: NVRAM size in bytes | |
331 | result[3]: NVRAM format version number | |
c6760ac4 MG |
332 | |
333 | Input byte 0 = 2: Wireless switch configuration | |
334 | result[0]: return code | |
335 | result[1]: | |
336 | Bit 0: Wifi controlled by switch | |
337 | Bit 1: Bluetooth controlled by switch | |
338 | Bit 2: WWAN controlled by switch | |
339 | Bits 3-6: Reserved | |
340 | Bit 7: Wireless switch config locked | |
341 | Bit 8: Wifi locator enabled | |
342 | Bits 9-14: Reserved | |
343 | Bit 15: Wifi locator setting locked | |
344 | Bits 16-31: Reserved | |
ad8f07cc MG |
345 | */ |
346 | ||
19d337df | 347 | static int dell_rfkill_set(void *data, bool blocked) |
ad8f07cc | 348 | { |
624f0de4 | 349 | int disable = blocked ? 1 : 0; |
19d337df | 350 | unsigned long radio = (unsigned long)data; |
c6760ac4 | 351 | int hwswitch_bit = (unsigned long)data - 1; |
116ee77b | 352 | int ret = 0; |
ad8f07cc | 353 | |
116ee77b SH |
354 | get_buffer(); |
355 | dell_send_request(buffer, 17, 11); | |
ec1722a2 | 356 | |
c6760ac4 | 357 | /* If the hardware switch controls this radio, and the hardware |
be65dde8 | 358 | switch is disabled, don't allow changing the software state */ |
c6760ac4 | 359 | if ((hwswitch_state & BIT(hwswitch_bit)) && |
be65dde8 | 360 | !(buffer->output[1] & BIT(16))) { |
116ee77b SH |
361 | ret = -EINVAL; |
362 | goto out; | |
363 | } | |
ad8f07cc | 364 | |
116ee77b SH |
365 | buffer->input[0] = (1 | (radio<<8) | (disable << 16)); |
366 | dell_send_request(buffer, 17, 11); | |
367 | ||
368 | out: | |
369 | release_buffer(); | |
370 | return ret; | |
ad8f07cc MG |
371 | } |
372 | ||
19d337df | 373 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) |
ad8f07cc | 374 | { |
ad8f07cc | 375 | int status; |
19d337df | 376 | int bit = (unsigned long)data + 16; |
c6760ac4 | 377 | int hwswitch_bit = (unsigned long)data - 1; |
ad8f07cc | 378 | |
116ee77b SH |
379 | get_buffer(); |
380 | dell_send_request(buffer, 17, 11); | |
381 | status = buffer->output[1]; | |
382 | release_buffer(); | |
ad8f07cc | 383 | |
e1fbf346 | 384 | rfkill_set_sw_state(rfkill, !!(status & BIT(bit))); |
c6760ac4 MG |
385 | |
386 | if (hwswitch_state & (BIT(hwswitch_bit))) | |
387 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); | |
ad8f07cc MG |
388 | } |
389 | ||
19d337df JB |
390 | static const struct rfkill_ops dell_rfkill_ops = { |
391 | .set_block = dell_rfkill_set, | |
392 | .query = dell_rfkill_query, | |
393 | }; | |
ad8f07cc | 394 | |
037accfa KYL |
395 | static struct dentry *dell_laptop_dir; |
396 | ||
397 | static int dell_debugfs_show(struct seq_file *s, void *data) | |
398 | { | |
399 | int status; | |
400 | ||
401 | get_buffer(); | |
402 | dell_send_request(buffer, 17, 11); | |
403 | status = buffer->output[1]; | |
404 | release_buffer(); | |
405 | ||
406 | seq_printf(s, "status:\t0x%X\n", status); | |
407 | seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n", | |
408 | status & BIT(0)); | |
409 | seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n", | |
410 | (status & BIT(1)) >> 1); | |
411 | seq_printf(s, "Bit 2 : Wifi is supported: %lu\n", | |
412 | (status & BIT(2)) >> 2); | |
413 | seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n", | |
414 | (status & BIT(3)) >> 3); | |
415 | seq_printf(s, "Bit 4 : WWAN is supported: %lu\n", | |
416 | (status & BIT(4)) >> 4); | |
417 | seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n", | |
418 | (status & BIT(5)) >> 5); | |
419 | seq_printf(s, "Bit 8 : Wifi is installed: %lu\n", | |
420 | (status & BIT(8)) >> 8); | |
421 | seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n", | |
422 | (status & BIT(9)) >> 9); | |
423 | seq_printf(s, "Bit 10: WWAN is installed: %lu\n", | |
424 | (status & BIT(10)) >> 10); | |
425 | seq_printf(s, "Bit 16: Hardware switch is on: %lu\n", | |
426 | (status & BIT(16)) >> 16); | |
427 | seq_printf(s, "Bit 17: Wifi is blocked: %lu\n", | |
428 | (status & BIT(17)) >> 17); | |
429 | seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n", | |
430 | (status & BIT(18)) >> 18); | |
431 | seq_printf(s, "Bit 19: WWAN is blocked: %lu\n", | |
432 | (status & BIT(19)) >> 19); | |
433 | ||
434 | seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state); | |
435 | seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n", | |
436 | hwswitch_state & BIT(0)); | |
437 | seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n", | |
438 | (hwswitch_state & BIT(1)) >> 1); | |
439 | seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n", | |
440 | (hwswitch_state & BIT(2)) >> 2); | |
441 | seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n", | |
442 | (hwswitch_state & BIT(7)) >> 7); | |
443 | seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n", | |
444 | (hwswitch_state & BIT(8)) >> 8); | |
445 | seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n", | |
446 | (hwswitch_state & BIT(15)) >> 15); | |
447 | ||
448 | return 0; | |
449 | } | |
450 | ||
451 | static int dell_debugfs_open(struct inode *inode, struct file *file) | |
452 | { | |
453 | return single_open(file, dell_debugfs_show, inode->i_private); | |
454 | } | |
455 | ||
456 | static const struct file_operations dell_debugfs_fops = { | |
457 | .owner = THIS_MODULE, | |
458 | .open = dell_debugfs_open, | |
459 | .read = seq_read, | |
460 | .llseek = seq_lseek, | |
461 | .release = single_release, | |
462 | }; | |
463 | ||
814cb8ad MG |
464 | static void dell_update_rfkill(struct work_struct *ignored) |
465 | { | |
466 | if (wifi_rfkill) | |
467 | dell_rfkill_query(wifi_rfkill, (void *)1); | |
468 | if (bluetooth_rfkill) | |
469 | dell_rfkill_query(bluetooth_rfkill, (void *)2); | |
470 | if (wwan_rfkill) | |
471 | dell_rfkill_query(wwan_rfkill, (void *)3); | |
472 | } | |
473 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); | |
474 | ||
475 | ||
4788df4c | 476 | static int __init dell_setup_rfkill(void) |
ad8f07cc | 477 | { |
ad8f07cc MG |
478 | int status; |
479 | int ret; | |
480 | ||
e5fefd0c | 481 | if (dmi_check_system(dell_blacklist)) { |
eb889524 | 482 | pr_info("Blacklisted hardware detected - not enabling rfkill\n"); |
e5fefd0c ML |
483 | return 0; |
484 | } | |
485 | ||
116ee77b SH |
486 | get_buffer(); |
487 | dell_send_request(buffer, 17, 11); | |
488 | status = buffer->output[1]; | |
c6760ac4 MG |
489 | buffer->input[0] = 0x2; |
490 | dell_send_request(buffer, 17, 11); | |
491 | hwswitch_state = buffer->output[1]; | |
116ee77b | 492 | release_buffer(); |
ad8f07cc MG |
493 | |
494 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { | |
ada3248a AJ |
495 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, |
496 | RFKILL_TYPE_WLAN, | |
19d337df JB |
497 | &dell_rfkill_ops, (void *) 1); |
498 | if (!wifi_rfkill) { | |
499 | ret = -ENOMEM; | |
ad8f07cc | 500 | goto err_wifi; |
19d337df | 501 | } |
ad8f07cc MG |
502 | ret = rfkill_register(wifi_rfkill); |
503 | if (ret) | |
504 | goto err_wifi; | |
505 | } | |
506 | ||
507 | if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { | |
ada3248a AJ |
508 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", |
509 | &platform_device->dev, | |
19d337df JB |
510 | RFKILL_TYPE_BLUETOOTH, |
511 | &dell_rfkill_ops, (void *) 2); | |
512 | if (!bluetooth_rfkill) { | |
513 | ret = -ENOMEM; | |
ad8f07cc | 514 | goto err_bluetooth; |
19d337df | 515 | } |
ad8f07cc MG |
516 | ret = rfkill_register(bluetooth_rfkill); |
517 | if (ret) | |
518 | goto err_bluetooth; | |
519 | } | |
520 | ||
521 | if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { | |
ada3248a AJ |
522 | wwan_rfkill = rfkill_alloc("dell-wwan", |
523 | &platform_device->dev, | |
524 | RFKILL_TYPE_WWAN, | |
19d337df JB |
525 | &dell_rfkill_ops, (void *) 3); |
526 | if (!wwan_rfkill) { | |
527 | ret = -ENOMEM; | |
ad8f07cc | 528 | goto err_wwan; |
19d337df | 529 | } |
ad8f07cc MG |
530 | ret = rfkill_register(wwan_rfkill); |
531 | if (ret) | |
532 | goto err_wwan; | |
533 | } | |
534 | ||
535 | return 0; | |
536 | err_wwan: | |
19d337df JB |
537 | rfkill_destroy(wwan_rfkill); |
538 | if (bluetooth_rfkill) | |
ad8f07cc | 539 | rfkill_unregister(bluetooth_rfkill); |
ad8f07cc | 540 | err_bluetooth: |
19d337df JB |
541 | rfkill_destroy(bluetooth_rfkill); |
542 | if (wifi_rfkill) | |
ad8f07cc | 543 | rfkill_unregister(wifi_rfkill); |
ad8f07cc | 544 | err_wifi: |
19d337df | 545 | rfkill_destroy(wifi_rfkill); |
ad8f07cc MG |
546 | |
547 | return ret; | |
548 | } | |
549 | ||
4311bb23 AJ |
550 | static void dell_cleanup_rfkill(void) |
551 | { | |
552 | if (wifi_rfkill) { | |
553 | rfkill_unregister(wifi_rfkill); | |
554 | rfkill_destroy(wifi_rfkill); | |
555 | } | |
556 | if (bluetooth_rfkill) { | |
557 | rfkill_unregister(bluetooth_rfkill); | |
558 | rfkill_destroy(bluetooth_rfkill); | |
559 | } | |
560 | if (wwan_rfkill) { | |
561 | rfkill_unregister(wwan_rfkill); | |
562 | rfkill_destroy(wwan_rfkill); | |
563 | } | |
564 | } | |
565 | ||
ad8f07cc MG |
566 | static int dell_send_intensity(struct backlight_device *bd) |
567 | { | |
116ee77b | 568 | int ret = 0; |
ad8f07cc | 569 | |
116ee77b SH |
570 | get_buffer(); |
571 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | |
572 | buffer->input[1] = bd->props.brightness; | |
ad8f07cc | 573 | |
116ee77b SH |
574 | if (buffer->input[0] == -1) { |
575 | ret = -ENODEV; | |
576 | goto out; | |
577 | } | |
ad8f07cc MG |
578 | |
579 | if (power_supply_is_system_supplied() > 0) | |
116ee77b | 580 | dell_send_request(buffer, 1, 2); |
ad8f07cc | 581 | else |
116ee77b | 582 | dell_send_request(buffer, 1, 1); |
ad8f07cc | 583 | |
116ee77b SH |
584 | out: |
585 | release_buffer(); | |
ad8f07cc MG |
586 | return 0; |
587 | } | |
588 | ||
589 | static int dell_get_intensity(struct backlight_device *bd) | |
590 | { | |
116ee77b | 591 | int ret = 0; |
ad8f07cc | 592 | |
116ee77b SH |
593 | get_buffer(); |
594 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | |
ad8f07cc | 595 | |
116ee77b SH |
596 | if (buffer->input[0] == -1) { |
597 | ret = -ENODEV; | |
598 | goto out; | |
599 | } | |
ad8f07cc MG |
600 | |
601 | if (power_supply_is_system_supplied() > 0) | |
116ee77b | 602 | dell_send_request(buffer, 0, 2); |
ad8f07cc | 603 | else |
116ee77b | 604 | dell_send_request(buffer, 0, 1); |
ad8f07cc | 605 | |
b486742a JA |
606 | ret = buffer->output[1]; |
607 | ||
116ee77b SH |
608 | out: |
609 | release_buffer(); | |
b486742a | 610 | return ret; |
ad8f07cc MG |
611 | } |
612 | ||
acc2472e | 613 | static const struct backlight_ops dell_ops = { |
ad8f07cc MG |
614 | .get_brightness = dell_get_intensity, |
615 | .update_status = dell_send_intensity, | |
616 | }; | |
617 | ||
869f8dfa | 618 | static void touchpad_led_on(void) |
2d8b90be AK |
619 | { |
620 | int command = 0x97; | |
621 | char data = 1; | |
622 | i8042_command(&data, command | 1 << 12); | |
623 | } | |
624 | ||
869f8dfa | 625 | static void touchpad_led_off(void) |
2d8b90be AK |
626 | { |
627 | int command = 0x97; | |
628 | char data = 2; | |
629 | i8042_command(&data, command | 1 << 12); | |
630 | } | |
631 | ||
632 | static void touchpad_led_set(struct led_classdev *led_cdev, | |
633 | enum led_brightness value) | |
634 | { | |
635 | if (value > 0) | |
636 | touchpad_led_on(); | |
637 | else | |
638 | touchpad_led_off(); | |
639 | } | |
640 | ||
641 | static struct led_classdev touchpad_led = { | |
642 | .name = "dell-laptop::touchpad", | |
643 | .brightness_set = touchpad_led_set, | |
644 | }; | |
645 | ||
646 | static int __devinit touchpad_led_init(struct device *dev) | |
647 | { | |
648 | return led_classdev_register(dev, &touchpad_led); | |
649 | } | |
650 | ||
651 | static void touchpad_led_exit(void) | |
652 | { | |
653 | led_classdev_unregister(&touchpad_led); | |
654 | } | |
655 | ||
4519169b | 656 | static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, |
814cb8ad MG |
657 | struct serio *port) |
658 | { | |
659 | static bool extended; | |
660 | ||
661 | if (str & 0x20) | |
662 | return false; | |
663 | ||
664 | if (unlikely(data == 0xe0)) { | |
665 | extended = true; | |
666 | return false; | |
667 | } else if (unlikely(extended)) { | |
668 | switch (data) { | |
669 | case 0x8: | |
670 | schedule_delayed_work(&dell_rfkill_work, | |
671 | round_jiffies_relative(HZ)); | |
672 | break; | |
673 | } | |
674 | extended = false; | |
675 | } | |
676 | ||
677 | return false; | |
678 | } | |
679 | ||
ad8f07cc MG |
680 | static int __init dell_init(void) |
681 | { | |
ad8f07cc MG |
682 | int max_intensity = 0; |
683 | int ret; | |
684 | ||
685 | if (!dmi_check_system(dell_device_table)) | |
686 | return -ENODEV; | |
687 | ||
2d8b90be AK |
688 | quirks = NULL; |
689 | /* find if this machine support other functions */ | |
690 | dmi_check_system(dell_quirks); | |
691 | ||
e7a19c56 | 692 | dmi_walk(find_tokens, NULL); |
ad8f07cc MG |
693 | |
694 | if (!da_tokens) { | |
eb889524 | 695 | pr_info("Unable to find dmi tokens\n"); |
ad8f07cc MG |
696 | return -ENODEV; |
697 | } | |
698 | ||
ada3248a AJ |
699 | ret = platform_driver_register(&platform_driver); |
700 | if (ret) | |
701 | goto fail_platform_driver; | |
702 | platform_device = platform_device_alloc("dell-laptop", -1); | |
703 | if (!platform_device) { | |
704 | ret = -ENOMEM; | |
705 | goto fail_platform_device1; | |
706 | } | |
707 | ret = platform_device_add(platform_device); | |
708 | if (ret) | |
709 | goto fail_platform_device2; | |
710 | ||
116ee77b SH |
711 | /* |
712 | * Allocate buffer below 4GB for SMI data--only 32-bit physical addr | |
713 | * is passed to SMI handler. | |
714 | */ | |
715 | bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32); | |
716 | ||
717 | if (!bufferpage) | |
718 | goto fail_buffer; | |
719 | buffer = page_address(bufferpage); | |
116ee77b | 720 | |
ad8f07cc MG |
721 | ret = dell_setup_rfkill(); |
722 | ||
723 | if (ret) { | |
eb889524 | 724 | pr_warn("Unable to setup rfkill\n"); |
71e9dc73 | 725 | goto fail_rfkill; |
ad8f07cc MG |
726 | } |
727 | ||
814cb8ad MG |
728 | ret = i8042_install_filter(dell_laptop_i8042_filter); |
729 | if (ret) { | |
eb889524 | 730 | pr_warn("Unable to install key filter\n"); |
814cb8ad MG |
731 | goto fail_filter; |
732 | } | |
733 | ||
2d8b90be AK |
734 | if (quirks && quirks->touchpad_led) |
735 | touchpad_led_init(&platform_device->dev); | |
736 | ||
037accfa KYL |
737 | dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); |
738 | if (dell_laptop_dir != NULL) | |
739 | debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL, | |
740 | &dell_debugfs_fops); | |
741 | ||
ad8f07cc MG |
742 | #ifdef CONFIG_ACPI |
743 | /* In the event of an ACPI backlight being available, don't | |
744 | * register the platform controller. | |
745 | */ | |
746 | if (acpi_video_backlight_support()) | |
747 | return 0; | |
748 | #endif | |
749 | ||
116ee77b SH |
750 | get_buffer(); |
751 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | |
752 | if (buffer->input[0] != -1) { | |
753 | dell_send_request(buffer, 0, 2); | |
754 | max_intensity = buffer->output[3]; | |
ad8f07cc | 755 | } |
116ee77b | 756 | release_buffer(); |
ad8f07cc MG |
757 | |
758 | if (max_intensity) { | |
a19a6ee6 MG |
759 | struct backlight_properties props; |
760 | memset(&props, 0, sizeof(struct backlight_properties)); | |
bb7ca747 | 761 | props.type = BACKLIGHT_PLATFORM; |
a19a6ee6 MG |
762 | props.max_brightness = max_intensity; |
763 | dell_backlight_device = backlight_device_register("dell_backlight", | |
764 | &platform_device->dev, | |
765 | NULL, | |
766 | &dell_ops, | |
767 | &props); | |
ad8f07cc MG |
768 | |
769 | if (IS_ERR(dell_backlight_device)) { | |
770 | ret = PTR_ERR(dell_backlight_device); | |
771 | dell_backlight_device = NULL; | |
71e9dc73 | 772 | goto fail_backlight; |
ad8f07cc MG |
773 | } |
774 | ||
ad8f07cc MG |
775 | dell_backlight_device->props.brightness = |
776 | dell_get_intensity(dell_backlight_device); | |
777 | backlight_update_status(dell_backlight_device); | |
778 | } | |
779 | ||
780 | return 0; | |
71e9dc73 AJ |
781 | |
782 | fail_backlight: | |
814cb8ad | 783 | i8042_remove_filter(dell_laptop_i8042_filter); |
92e00e47 | 784 | cancel_delayed_work_sync(&dell_rfkill_work); |
814cb8ad | 785 | fail_filter: |
4311bb23 | 786 | dell_cleanup_rfkill(); |
71e9dc73 | 787 | fail_rfkill: |
116ee77b SH |
788 | free_page((unsigned long)bufferpage); |
789 | fail_buffer: | |
ada3248a AJ |
790 | platform_device_del(platform_device); |
791 | fail_platform_device2: | |
792 | platform_device_put(platform_device); | |
793 | fail_platform_device1: | |
794 | platform_driver_unregister(&platform_driver); | |
795 | fail_platform_driver: | |
ad8f07cc MG |
796 | kfree(da_tokens); |
797 | return ret; | |
798 | } | |
799 | ||
800 | static void __exit dell_exit(void) | |
801 | { | |
037accfa | 802 | debugfs_remove_recursive(dell_laptop_dir); |
2d8b90be AK |
803 | if (quirks && quirks->touchpad_led) |
804 | touchpad_led_exit(); | |
814cb8ad | 805 | i8042_remove_filter(dell_laptop_i8042_filter); |
92e00e47 | 806 | cancel_delayed_work_sync(&dell_rfkill_work); |
ad8f07cc | 807 | backlight_device_unregister(dell_backlight_device); |
4311bb23 | 808 | dell_cleanup_rfkill(); |
facd61d7 | 809 | if (platform_device) { |
92e00e47 | 810 | platform_device_unregister(platform_device); |
facd61d7 MG |
811 | platform_driver_unregister(&platform_driver); |
812 | } | |
e551260b | 813 | kfree(da_tokens); |
116ee77b | 814 | free_page((unsigned long)buffer); |
ad8f07cc MG |
815 | } |
816 | ||
817 | module_init(dell_init); | |
818 | module_exit(dell_exit); | |
819 | ||
820 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); | |
821 | MODULE_DESCRIPTION("Dell laptop driver"); | |
822 | MODULE_LICENSE("GPL"); |