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> | |
4cc8a574 | 24 | #include <linux/rfkill.h> |
ad8f07cc MG |
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 | 92 | static struct backlight_device *dell_backlight_device; |
4cc8a574 HG |
93 | static struct rfkill *wifi_rfkill; |
94 | static struct rfkill *bluetooth_rfkill; | |
95 | static struct rfkill *wwan_rfkill; | |
8e0e668d HG |
96 | static bool force_rfkill; |
97 | ||
98 | module_param(force_rfkill, bool, 0444); | |
99 | MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models"); | |
ad8f07cc | 100 | |
145047de | 101 | static const struct dmi_system_id dell_device_table[] __initconst = { |
ad8f07cc MG |
102 | { |
103 | .ident = "Dell laptop", | |
104 | .matches = { | |
105 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
106 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), | |
107 | }, | |
108 | }, | |
410d44c7 RK |
109 | { |
110 | .matches = { | |
111 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
112 | DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/ | |
113 | }, | |
114 | }, | |
cb6a7937 EA |
115 | { |
116 | .ident = "Dell Computer Corporation", | |
117 | .matches = { | |
118 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), | |
119 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), | |
120 | }, | |
121 | }, | |
ad8f07cc MG |
122 | { } |
123 | }; | |
35ae64fe | 124 | MODULE_DEVICE_TABLE(dmi, dell_device_table); |
ad8f07cc | 125 | |
b859f159 | 126 | static struct dmi_system_id dell_quirks[] = { |
2d8b90be AK |
127 | { |
128 | .callback = dmi_matched, | |
129 | .ident = "Dell Vostro V130", | |
130 | .matches = { | |
131 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
132 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"), | |
133 | }, | |
134 | .driver_data = &quirk_dell_vostro_v130, | |
135 | }, | |
136 | { | |
137 | .callback = dmi_matched, | |
138 | .ident = "Dell Vostro V131", | |
139 | .matches = { | |
140 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
141 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), | |
142 | }, | |
143 | .driver_data = &quirk_dell_vostro_v130, | |
144 | }, | |
57b31b2f AWC |
145 | { |
146 | .callback = dmi_matched, | |
147 | .ident = "Dell Vostro 3350", | |
148 | .matches = { | |
149 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
150 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"), | |
151 | }, | |
152 | .driver_data = &quirk_dell_vostro_v130, | |
153 | }, | |
2a748853 AK |
154 | { |
155 | .callback = dmi_matched, | |
156 | .ident = "Dell Vostro 3555", | |
157 | .matches = { | |
158 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
159 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"), | |
160 | }, | |
161 | .driver_data = &quirk_dell_vostro_v130, | |
162 | }, | |
163 | { | |
164 | .callback = dmi_matched, | |
165 | .ident = "Dell Inspiron N311z", | |
166 | .matches = { | |
167 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
168 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"), | |
169 | }, | |
170 | .driver_data = &quirk_dell_vostro_v130, | |
171 | }, | |
172 | { | |
173 | .callback = dmi_matched, | |
174 | .ident = "Dell Inspiron M5110", | |
175 | .matches = { | |
176 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
177 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), | |
178 | }, | |
179 | .driver_data = &quirk_dell_vostro_v130, | |
180 | }, | |
7f839228 AK |
181 | { |
182 | .callback = dmi_matched, | |
183 | .ident = "Dell Vostro 3360", | |
184 | .matches = { | |
185 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
186 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"), | |
187 | }, | |
188 | .driver_data = &quirk_dell_vostro_v130, | |
189 | }, | |
190 | { | |
191 | .callback = dmi_matched, | |
192 | .ident = "Dell Vostro 3460", | |
193 | .matches = { | |
194 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
195 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"), | |
196 | }, | |
197 | .driver_data = &quirk_dell_vostro_v130, | |
198 | }, | |
199 | { | |
200 | .callback = dmi_matched, | |
201 | .ident = "Dell Vostro 3560", | |
202 | .matches = { | |
203 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
204 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"), | |
205 | }, | |
206 | .driver_data = &quirk_dell_vostro_v130, | |
207 | }, | |
d0e0a477 AK |
208 | { |
209 | .callback = dmi_matched, | |
210 | .ident = "Dell Vostro 3450", | |
211 | .matches = { | |
212 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
213 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"), | |
214 | }, | |
215 | .driver_data = &quirk_dell_vostro_v130, | |
216 | }, | |
5f1e88f4 AK |
217 | { |
218 | .callback = dmi_matched, | |
219 | .ident = "Dell Inspiron 5420", | |
220 | .matches = { | |
221 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
a2174ba2 | 222 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5420"), |
5f1e88f4 AK |
223 | }, |
224 | .driver_data = &quirk_dell_vostro_v130, | |
225 | }, | |
226 | { | |
227 | .callback = dmi_matched, | |
228 | .ident = "Dell Inspiron 5520", | |
229 | .matches = { | |
230 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
a2174ba2 | 231 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5520"), |
5f1e88f4 AK |
232 | }, |
233 | .driver_data = &quirk_dell_vostro_v130, | |
234 | }, | |
235 | { | |
236 | .callback = dmi_matched, | |
237 | .ident = "Dell Inspiron 5720", | |
238 | .matches = { | |
239 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
a2174ba2 | 240 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5720"), |
5f1e88f4 AK |
241 | }, |
242 | .driver_data = &quirk_dell_vostro_v130, | |
243 | }, | |
244 | { | |
245 | .callback = dmi_matched, | |
246 | .ident = "Dell Inspiron 7420", | |
247 | .matches = { | |
248 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
a2174ba2 | 249 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7420"), |
5f1e88f4 AK |
250 | }, |
251 | .driver_data = &quirk_dell_vostro_v130, | |
252 | }, | |
253 | { | |
254 | .callback = dmi_matched, | |
255 | .ident = "Dell Inspiron 7520", | |
256 | .matches = { | |
257 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
a2174ba2 | 258 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7520"), |
5f1e88f4 AK |
259 | }, |
260 | .driver_data = &quirk_dell_vostro_v130, | |
261 | }, | |
262 | { | |
263 | .callback = dmi_matched, | |
264 | .ident = "Dell Inspiron 7720", | |
265 | .matches = { | |
266 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
a2174ba2 | 267 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"), |
5f1e88f4 AK |
268 | }, |
269 | .driver_data = &quirk_dell_vostro_v130, | |
270 | }, | |
d62d421b | 271 | { } |
2d8b90be AK |
272 | }; |
273 | ||
116ee77b | 274 | static struct calling_interface_buffer *buffer; |
94d8f785 IM |
275 | static struct page *bufferpage; |
276 | static DEFINE_MUTEX(buffer_mutex); | |
116ee77b | 277 | |
c6760ac4 MG |
278 | static int hwswitch_state; |
279 | ||
116ee77b SH |
280 | static void get_buffer(void) |
281 | { | |
282 | mutex_lock(&buffer_mutex); | |
283 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); | |
284 | } | |
285 | ||
286 | static void release_buffer(void) | |
287 | { | |
288 | mutex_unlock(&buffer_mutex); | |
289 | } | |
290 | ||
4788df4c | 291 | static void __init parse_da_table(const struct dmi_header *dm) |
ad8f07cc MG |
292 | { |
293 | /* Final token is a terminator, so we don't want to copy it */ | |
294 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; | |
fe9ab00f | 295 | struct calling_interface_token *new_da_tokens; |
ad8f07cc MG |
296 | struct calling_interface_structure *table = |
297 | container_of(dm, struct calling_interface_structure, header); | |
298 | ||
299 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least | |
300 | 6 bytes of entry */ | |
301 | ||
302 | if (dm->length < 17) | |
303 | return; | |
304 | ||
305 | da_command_address = table->cmdIOAddress; | |
306 | da_command_code = table->cmdIOCode; | |
307 | ||
fe9ab00f DW |
308 | new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * |
309 | sizeof(struct calling_interface_token), | |
310 | GFP_KERNEL); | |
ad8f07cc | 311 | |
fe9ab00f | 312 | if (!new_da_tokens) |
ad8f07cc | 313 | return; |
fe9ab00f | 314 | da_tokens = new_da_tokens; |
ad8f07cc MG |
315 | |
316 | memcpy(da_tokens+da_num_tokens, table->tokens, | |
317 | sizeof(struct calling_interface_token) * tokens); | |
318 | ||
319 | da_num_tokens += tokens; | |
320 | } | |
321 | ||
4788df4c | 322 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
ad8f07cc MG |
323 | { |
324 | switch (dm->type) { | |
325 | case 0xd4: /* Indexed IO */ | |
ad8f07cc | 326 | case 0xd5: /* Protected Area Type 1 */ |
ad8f07cc MG |
327 | case 0xd6: /* Protected Area Type 2 */ |
328 | break; | |
329 | case 0xda: /* Calling interface */ | |
330 | parse_da_table(dm); | |
331 | break; | |
332 | } | |
333 | } | |
334 | ||
335 | static int find_token_location(int tokenid) | |
336 | { | |
337 | int i; | |
338 | for (i = 0; i < da_num_tokens; i++) { | |
339 | if (da_tokens[i].tokenID == tokenid) | |
340 | return da_tokens[i].location; | |
341 | } | |
342 | ||
343 | return -1; | |
344 | } | |
345 | ||
346 | static struct calling_interface_buffer * | |
347 | dell_send_request(struct calling_interface_buffer *buffer, int class, | |
348 | int select) | |
349 | { | |
350 | struct smi_cmd command; | |
351 | ||
352 | command.magic = SMI_CMD_MAGIC; | |
353 | command.command_address = da_command_address; | |
354 | command.command_code = da_command_code; | |
355 | command.ebx = virt_to_phys(buffer); | |
356 | command.ecx = 0x42534931; | |
357 | ||
358 | buffer->class = class; | |
359 | buffer->select = select; | |
360 | ||
361 | dcdbas_smi_request(&command); | |
362 | ||
363 | return buffer; | |
364 | } | |
365 | ||
4cc8a574 HG |
366 | /* Derived from information in DellWirelessCtl.cpp: |
367 | Class 17, select 11 is radio control. It returns an array of 32-bit values. | |
368 | ||
369 | Input byte 0 = 0: Wireless information | |
370 | ||
371 | result[0]: return code | |
372 | result[1]: | |
373 | Bit 0: Hardware switch supported | |
374 | Bit 1: Wifi locator supported | |
375 | Bit 2: Wifi is supported | |
376 | Bit 3: Bluetooth is supported | |
377 | Bit 4: WWAN is supported | |
378 | Bit 5: Wireless keyboard supported | |
379 | Bits 6-7: Reserved | |
380 | Bit 8: Wifi is installed | |
381 | Bit 9: Bluetooth is installed | |
382 | Bit 10: WWAN is installed | |
383 | Bits 11-15: Reserved | |
384 | Bit 16: Hardware switch is on | |
385 | Bit 17: Wifi is blocked | |
386 | Bit 18: Bluetooth is blocked | |
387 | Bit 19: WWAN is blocked | |
388 | Bits 20-31: Reserved | |
389 | result[2]: NVRAM size in bytes | |
390 | result[3]: NVRAM format version number | |
391 | ||
392 | Input byte 0 = 2: Wireless switch configuration | |
393 | result[0]: return code | |
394 | result[1]: | |
395 | Bit 0: Wifi controlled by switch | |
396 | Bit 1: Bluetooth controlled by switch | |
397 | Bit 2: WWAN controlled by switch | |
398 | Bits 3-6: Reserved | |
399 | Bit 7: Wireless switch config locked | |
400 | Bit 8: Wifi locator enabled | |
401 | Bits 9-14: Reserved | |
402 | Bit 15: Wifi locator setting locked | |
403 | Bits 16-31: Reserved | |
404 | */ | |
405 | ||
406 | static int dell_rfkill_set(void *data, bool blocked) | |
407 | { | |
408 | int disable = blocked ? 1 : 0; | |
409 | unsigned long radio = (unsigned long)data; | |
410 | int hwswitch_bit = (unsigned long)data - 1; | |
4cc8a574 HG |
411 | |
412 | get_buffer(); | |
413 | dell_send_request(buffer, 17, 11); | |
414 | ||
415 | /* If the hardware switch controls this radio, and the hardware | |
ed112898 | 416 | switch is disabled, always disable the radio */ |
4cc8a574 | 417 | if ((hwswitch_state & BIT(hwswitch_bit)) && |
4d39d88c | 418 | !(buffer->output[1] & BIT(16))) |
ed112898 | 419 | disable = 1; |
4cc8a574 HG |
420 | |
421 | buffer->input[0] = (1 | (radio<<8) | (disable << 16)); | |
422 | dell_send_request(buffer, 17, 11); | |
423 | ||
4cc8a574 | 424 | release_buffer(); |
4d39d88c | 425 | return 0; |
4cc8a574 HG |
426 | } |
427 | ||
04c9a3a0 | 428 | /* Must be called with the buffer held */ |
33f9359a HG |
429 | static void dell_rfkill_update_sw_state(struct rfkill *rfkill, int radio, |
430 | int status) | |
d038880e | 431 | { |
04c9a3a0 HG |
432 | if (status & BIT(0)) { |
433 | /* Has hw-switch, sync sw_state to BIOS */ | |
434 | int block = rfkill_blocked(rfkill); | |
435 | buffer->input[0] = (1 | (radio << 8) | (block << 16)); | |
436 | dell_send_request(buffer, 17, 11); | |
437 | } else { | |
3f56588a HG |
438 | /* No hw-switch, sync BIOS state to sw_state */ |
439 | rfkill_set_sw_state(rfkill, !!(status & BIT(radio + 16))); | |
440 | } | |
33f9359a | 441 | } |
d038880e | 442 | |
33f9359a HG |
443 | static void dell_rfkill_update_hw_state(struct rfkill *rfkill, int radio, |
444 | int status) | |
445 | { | |
d038880e HG |
446 | if (hwswitch_state & (BIT(radio - 1))) |
447 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); | |
448 | } | |
449 | ||
4cc8a574 HG |
450 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) |
451 | { | |
452 | int status; | |
4cc8a574 HG |
453 | |
454 | get_buffer(); | |
455 | dell_send_request(buffer, 17, 11); | |
456 | status = buffer->output[1]; | |
4cc8a574 | 457 | |
33f9359a | 458 | dell_rfkill_update_hw_state(rfkill, (unsigned long)data, status); |
04c9a3a0 HG |
459 | |
460 | release_buffer(); | |
4cc8a574 HG |
461 | } |
462 | ||
463 | static const struct rfkill_ops dell_rfkill_ops = { | |
464 | .set_block = dell_rfkill_set, | |
465 | .query = dell_rfkill_query, | |
466 | }; | |
467 | ||
037accfa KYL |
468 | static struct dentry *dell_laptop_dir; |
469 | ||
470 | static int dell_debugfs_show(struct seq_file *s, void *data) | |
471 | { | |
472 | int status; | |
473 | ||
474 | get_buffer(); | |
475 | dell_send_request(buffer, 17, 11); | |
476 | status = buffer->output[1]; | |
477 | release_buffer(); | |
478 | ||
479 | seq_printf(s, "status:\t0x%X\n", status); | |
480 | seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n", | |
481 | status & BIT(0)); | |
482 | seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n", | |
483 | (status & BIT(1)) >> 1); | |
484 | seq_printf(s, "Bit 2 : Wifi is supported: %lu\n", | |
485 | (status & BIT(2)) >> 2); | |
486 | seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n", | |
487 | (status & BIT(3)) >> 3); | |
488 | seq_printf(s, "Bit 4 : WWAN is supported: %lu\n", | |
489 | (status & BIT(4)) >> 4); | |
490 | seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n", | |
491 | (status & BIT(5)) >> 5); | |
492 | seq_printf(s, "Bit 8 : Wifi is installed: %lu\n", | |
493 | (status & BIT(8)) >> 8); | |
494 | seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n", | |
495 | (status & BIT(9)) >> 9); | |
496 | seq_printf(s, "Bit 10: WWAN is installed: %lu\n", | |
497 | (status & BIT(10)) >> 10); | |
498 | seq_printf(s, "Bit 16: Hardware switch is on: %lu\n", | |
499 | (status & BIT(16)) >> 16); | |
500 | seq_printf(s, "Bit 17: Wifi is blocked: %lu\n", | |
501 | (status & BIT(17)) >> 17); | |
502 | seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n", | |
503 | (status & BIT(18)) >> 18); | |
504 | seq_printf(s, "Bit 19: WWAN is blocked: %lu\n", | |
505 | (status & BIT(19)) >> 19); | |
506 | ||
507 | seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state); | |
508 | seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n", | |
509 | hwswitch_state & BIT(0)); | |
510 | seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n", | |
511 | (hwswitch_state & BIT(1)) >> 1); | |
512 | seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n", | |
513 | (hwswitch_state & BIT(2)) >> 2); | |
514 | seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n", | |
515 | (hwswitch_state & BIT(7)) >> 7); | |
516 | seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n", | |
517 | (hwswitch_state & BIT(8)) >> 8); | |
518 | seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n", | |
519 | (hwswitch_state & BIT(15)) >> 15); | |
520 | ||
521 | return 0; | |
522 | } | |
523 | ||
524 | static int dell_debugfs_open(struct inode *inode, struct file *file) | |
525 | { | |
526 | return single_open(file, dell_debugfs_show, inode->i_private); | |
527 | } | |
528 | ||
529 | static const struct file_operations dell_debugfs_fops = { | |
530 | .owner = THIS_MODULE, | |
531 | .open = dell_debugfs_open, | |
532 | .read = seq_read, | |
533 | .llseek = seq_lseek, | |
534 | .release = single_release, | |
535 | }; | |
536 | ||
4cc8a574 HG |
537 | static void dell_update_rfkill(struct work_struct *ignored) |
538 | { | |
d038880e HG |
539 | int status; |
540 | ||
541 | get_buffer(); | |
542 | dell_send_request(buffer, 17, 11); | |
543 | status = buffer->output[1]; | |
d038880e | 544 | |
33f9359a HG |
545 | if (wifi_rfkill) { |
546 | dell_rfkill_update_hw_state(wifi_rfkill, 1, status); | |
547 | dell_rfkill_update_sw_state(wifi_rfkill, 1, status); | |
548 | } | |
549 | if (bluetooth_rfkill) { | |
550 | dell_rfkill_update_hw_state(bluetooth_rfkill, 2, status); | |
551 | dell_rfkill_update_sw_state(bluetooth_rfkill, 2, status); | |
552 | } | |
553 | if (wwan_rfkill) { | |
554 | dell_rfkill_update_hw_state(wwan_rfkill, 3, status); | |
555 | dell_rfkill_update_sw_state(wwan_rfkill, 3, status); | |
556 | } | |
04c9a3a0 HG |
557 | |
558 | release_buffer(); | |
4cc8a574 HG |
559 | } |
560 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); | |
561 | ||
562 | ||
563 | static int __init dell_setup_rfkill(void) | |
564 | { | |
ba5194f1 | 565 | int status, ret, whitelisted; |
2a925518 HG |
566 | const char *product; |
567 | ||
568 | /* | |
ba5194f1 HG |
569 | * rfkill support causes trouble on various models, mostly Inspirons. |
570 | * So we whitelist certain series, and don't support rfkill on others. | |
2a925518 | 571 | */ |
ba5194f1 | 572 | whitelisted = 0; |
2a925518 | 573 | product = dmi_get_system_info(DMI_PRODUCT_NAME); |
ba5194f1 HG |
574 | if (product && (strncmp(product, "Latitude", 8) == 0 || |
575 | strncmp(product, "Precision", 9) == 0)) | |
576 | whitelisted = 1; | |
577 | if (!force_rfkill && !whitelisted) | |
4cc8a574 | 578 | return 0; |
4cc8a574 HG |
579 | |
580 | get_buffer(); | |
581 | dell_send_request(buffer, 17, 11); | |
582 | status = buffer->output[1]; | |
583 | buffer->input[0] = 0x2; | |
584 | dell_send_request(buffer, 17, 11); | |
585 | hwswitch_state = buffer->output[1]; | |
586 | release_buffer(); | |
587 | ||
2bd4ac13 HG |
588 | if (!(status & BIT(0))) { |
589 | if (force_rfkill) { | |
590 | /* No hwsitch, clear all hw-controlled bits */ | |
591 | hwswitch_state &= ~7; | |
592 | } else { | |
593 | /* rfkill is only tested on laptops with a hwswitch */ | |
594 | return 0; | |
595 | } | |
596 | } | |
597 | ||
4cc8a574 HG |
598 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { |
599 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, | |
600 | RFKILL_TYPE_WLAN, | |
601 | &dell_rfkill_ops, (void *) 1); | |
602 | if (!wifi_rfkill) { | |
603 | ret = -ENOMEM; | |
604 | goto err_wifi; | |
605 | } | |
606 | ret = rfkill_register(wifi_rfkill); | |
607 | if (ret) | |
608 | goto err_wifi; | |
609 | } | |
610 | ||
611 | if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { | |
612 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", | |
613 | &platform_device->dev, | |
614 | RFKILL_TYPE_BLUETOOTH, | |
615 | &dell_rfkill_ops, (void *) 2); | |
616 | if (!bluetooth_rfkill) { | |
617 | ret = -ENOMEM; | |
618 | goto err_bluetooth; | |
619 | } | |
620 | ret = rfkill_register(bluetooth_rfkill); | |
621 | if (ret) | |
622 | goto err_bluetooth; | |
623 | } | |
624 | ||
625 | if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { | |
626 | wwan_rfkill = rfkill_alloc("dell-wwan", | |
627 | &platform_device->dev, | |
628 | RFKILL_TYPE_WWAN, | |
629 | &dell_rfkill_ops, (void *) 3); | |
630 | if (!wwan_rfkill) { | |
631 | ret = -ENOMEM; | |
632 | goto err_wwan; | |
633 | } | |
634 | ret = rfkill_register(wwan_rfkill); | |
635 | if (ret) | |
636 | goto err_wwan; | |
637 | } | |
638 | ||
639 | return 0; | |
640 | err_wwan: | |
641 | rfkill_destroy(wwan_rfkill); | |
642 | if (bluetooth_rfkill) | |
643 | rfkill_unregister(bluetooth_rfkill); | |
644 | err_bluetooth: | |
645 | rfkill_destroy(bluetooth_rfkill); | |
646 | if (wifi_rfkill) | |
647 | rfkill_unregister(wifi_rfkill); | |
648 | err_wifi: | |
649 | rfkill_destroy(wifi_rfkill); | |
650 | ||
651 | return ret; | |
652 | } | |
653 | ||
654 | static void dell_cleanup_rfkill(void) | |
655 | { | |
656 | if (wifi_rfkill) { | |
657 | rfkill_unregister(wifi_rfkill); | |
658 | rfkill_destroy(wifi_rfkill); | |
659 | } | |
660 | if (bluetooth_rfkill) { | |
661 | rfkill_unregister(bluetooth_rfkill); | |
662 | rfkill_destroy(bluetooth_rfkill); | |
663 | } | |
664 | if (wwan_rfkill) { | |
665 | rfkill_unregister(wwan_rfkill); | |
666 | rfkill_destroy(wwan_rfkill); | |
667 | } | |
668 | } | |
669 | ||
ad8f07cc MG |
670 | static int dell_send_intensity(struct backlight_device *bd) |
671 | { | |
116ee77b | 672 | int ret = 0; |
ad8f07cc | 673 | |
116ee77b SH |
674 | get_buffer(); |
675 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | |
676 | buffer->input[1] = bd->props.brightness; | |
ad8f07cc | 677 | |
116ee77b SH |
678 | if (buffer->input[0] == -1) { |
679 | ret = -ENODEV; | |
680 | goto out; | |
681 | } | |
ad8f07cc MG |
682 | |
683 | if (power_supply_is_system_supplied() > 0) | |
116ee77b | 684 | dell_send_request(buffer, 1, 2); |
ad8f07cc | 685 | else |
116ee77b | 686 | dell_send_request(buffer, 1, 1); |
ad8f07cc | 687 | |
116ee77b SH |
688 | out: |
689 | release_buffer(); | |
7da8fb27 | 690 | return ret; |
ad8f07cc MG |
691 | } |
692 | ||
693 | static int dell_get_intensity(struct backlight_device *bd) | |
694 | { | |
116ee77b | 695 | int ret = 0; |
ad8f07cc | 696 | |
116ee77b SH |
697 | get_buffer(); |
698 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | |
ad8f07cc | 699 | |
116ee77b SH |
700 | if (buffer->input[0] == -1) { |
701 | ret = -ENODEV; | |
702 | goto out; | |
703 | } | |
ad8f07cc MG |
704 | |
705 | if (power_supply_is_system_supplied() > 0) | |
116ee77b | 706 | dell_send_request(buffer, 0, 2); |
ad8f07cc | 707 | else |
116ee77b | 708 | dell_send_request(buffer, 0, 1); |
ad8f07cc | 709 | |
b486742a JA |
710 | ret = buffer->output[1]; |
711 | ||
116ee77b SH |
712 | out: |
713 | release_buffer(); | |
b486742a | 714 | return ret; |
ad8f07cc MG |
715 | } |
716 | ||
acc2472e | 717 | static const struct backlight_ops dell_ops = { |
ad8f07cc MG |
718 | .get_brightness = dell_get_intensity, |
719 | .update_status = dell_send_intensity, | |
720 | }; | |
721 | ||
869f8dfa | 722 | static void touchpad_led_on(void) |
2d8b90be AK |
723 | { |
724 | int command = 0x97; | |
725 | char data = 1; | |
726 | i8042_command(&data, command | 1 << 12); | |
727 | } | |
728 | ||
869f8dfa | 729 | static void touchpad_led_off(void) |
2d8b90be AK |
730 | { |
731 | int command = 0x97; | |
732 | char data = 2; | |
733 | i8042_command(&data, command | 1 << 12); | |
734 | } | |
735 | ||
736 | static void touchpad_led_set(struct led_classdev *led_cdev, | |
737 | enum led_brightness value) | |
738 | { | |
739 | if (value > 0) | |
740 | touchpad_led_on(); | |
741 | else | |
742 | touchpad_led_off(); | |
743 | } | |
744 | ||
745 | static struct led_classdev touchpad_led = { | |
746 | .name = "dell-laptop::touchpad", | |
747 | .brightness_set = touchpad_led_set, | |
2d5de9e8 | 748 | .flags = LED_CORE_SUSPENDRESUME, |
2d8b90be AK |
749 | }; |
750 | ||
b859f159 | 751 | static int touchpad_led_init(struct device *dev) |
2d8b90be AK |
752 | { |
753 | return led_classdev_register(dev, &touchpad_led); | |
754 | } | |
755 | ||
756 | static void touchpad_led_exit(void) | |
757 | { | |
758 | led_classdev_unregister(&touchpad_led); | |
759 | } | |
760 | ||
4cc8a574 HG |
761 | static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, |
762 | struct serio *port) | |
763 | { | |
764 | static bool extended; | |
765 | ||
766 | if (str & 0x20) | |
767 | return false; | |
768 | ||
769 | if (unlikely(data == 0xe0)) { | |
770 | extended = true; | |
771 | return false; | |
772 | } else if (unlikely(extended)) { | |
773 | switch (data) { | |
774 | case 0x8: | |
775 | schedule_delayed_work(&dell_rfkill_work, | |
26c22d63 | 776 | round_jiffies_relative(HZ / 4)); |
4cc8a574 HG |
777 | break; |
778 | } | |
779 | extended = false; | |
780 | } | |
781 | ||
782 | return false; | |
783 | } | |
784 | ||
ad8f07cc MG |
785 | static int __init dell_init(void) |
786 | { | |
ad8f07cc MG |
787 | int max_intensity = 0; |
788 | int ret; | |
789 | ||
790 | if (!dmi_check_system(dell_device_table)) | |
791 | return -ENODEV; | |
792 | ||
2d8b90be AK |
793 | quirks = NULL; |
794 | /* find if this machine support other functions */ | |
795 | dmi_check_system(dell_quirks); | |
796 | ||
e7a19c56 | 797 | dmi_walk(find_tokens, NULL); |
ad8f07cc MG |
798 | |
799 | if (!da_tokens) { | |
eb889524 | 800 | pr_info("Unable to find dmi tokens\n"); |
ad8f07cc MG |
801 | return -ENODEV; |
802 | } | |
803 | ||
ada3248a AJ |
804 | ret = platform_driver_register(&platform_driver); |
805 | if (ret) | |
806 | goto fail_platform_driver; | |
807 | platform_device = platform_device_alloc("dell-laptop", -1); | |
808 | if (!platform_device) { | |
809 | ret = -ENOMEM; | |
810 | goto fail_platform_device1; | |
811 | } | |
812 | ret = platform_device_add(platform_device); | |
813 | if (ret) | |
814 | goto fail_platform_device2; | |
815 | ||
116ee77b SH |
816 | /* |
817 | * Allocate buffer below 4GB for SMI data--only 32-bit physical addr | |
818 | * is passed to SMI handler. | |
819 | */ | |
820 | bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32); | |
9f208202 WY |
821 | if (!bufferpage) { |
822 | ret = -ENOMEM; | |
116ee77b | 823 | goto fail_buffer; |
9f208202 | 824 | } |
116ee77b | 825 | buffer = page_address(bufferpage); |
116ee77b | 826 | |
4cc8a574 HG |
827 | ret = dell_setup_rfkill(); |
828 | ||
829 | if (ret) { | |
830 | pr_warn("Unable to setup rfkill\n"); | |
831 | goto fail_rfkill; | |
832 | } | |
833 | ||
834 | ret = i8042_install_filter(dell_laptop_i8042_filter); | |
835 | if (ret) { | |
836 | pr_warn("Unable to install key filter\n"); | |
837 | goto fail_filter; | |
838 | } | |
839 | ||
2d8b90be AK |
840 | if (quirks && quirks->touchpad_led) |
841 | touchpad_led_init(&platform_device->dev); | |
842 | ||
037accfa | 843 | dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); |
4cc8a574 HG |
844 | if (dell_laptop_dir != NULL) |
845 | debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL, | |
846 | &dell_debugfs_fops); | |
037accfa | 847 | |
ad8f07cc MG |
848 | #ifdef CONFIG_ACPI |
849 | /* In the event of an ACPI backlight being available, don't | |
850 | * register the platform controller. | |
851 | */ | |
852 | if (acpi_video_backlight_support()) | |
853 | return 0; | |
854 | #endif | |
855 | ||
116ee77b SH |
856 | get_buffer(); |
857 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | |
858 | if (buffer->input[0] != -1) { | |
859 | dell_send_request(buffer, 0, 2); | |
860 | max_intensity = buffer->output[3]; | |
ad8f07cc | 861 | } |
116ee77b | 862 | release_buffer(); |
ad8f07cc MG |
863 | |
864 | if (max_intensity) { | |
a19a6ee6 MG |
865 | struct backlight_properties props; |
866 | memset(&props, 0, sizeof(struct backlight_properties)); | |
bb7ca747 | 867 | props.type = BACKLIGHT_PLATFORM; |
a19a6ee6 MG |
868 | props.max_brightness = max_intensity; |
869 | dell_backlight_device = backlight_device_register("dell_backlight", | |
870 | &platform_device->dev, | |
871 | NULL, | |
872 | &dell_ops, | |
873 | &props); | |
ad8f07cc MG |
874 | |
875 | if (IS_ERR(dell_backlight_device)) { | |
876 | ret = PTR_ERR(dell_backlight_device); | |
877 | dell_backlight_device = NULL; | |
71e9dc73 | 878 | goto fail_backlight; |
ad8f07cc MG |
879 | } |
880 | ||
ad8f07cc MG |
881 | dell_backlight_device->props.brightness = |
882 | dell_get_intensity(dell_backlight_device); | |
883 | backlight_update_status(dell_backlight_device); | |
884 | } | |
885 | ||
886 | return 0; | |
71e9dc73 AJ |
887 | |
888 | fail_backlight: | |
4cc8a574 HG |
889 | i8042_remove_filter(dell_laptop_i8042_filter); |
890 | cancel_delayed_work_sync(&dell_rfkill_work); | |
891 | fail_filter: | |
892 | dell_cleanup_rfkill(); | |
893 | fail_rfkill: | |
116ee77b SH |
894 | free_page((unsigned long)bufferpage); |
895 | fail_buffer: | |
ada3248a AJ |
896 | platform_device_del(platform_device); |
897 | fail_platform_device2: | |
898 | platform_device_put(platform_device); | |
899 | fail_platform_device1: | |
900 | platform_driver_unregister(&platform_driver); | |
901 | fail_platform_driver: | |
ad8f07cc MG |
902 | kfree(da_tokens); |
903 | return ret; | |
904 | } | |
905 | ||
906 | static void __exit dell_exit(void) | |
907 | { | |
037accfa | 908 | debugfs_remove_recursive(dell_laptop_dir); |
2d8b90be AK |
909 | if (quirks && quirks->touchpad_led) |
910 | touchpad_led_exit(); | |
4cc8a574 HG |
911 | i8042_remove_filter(dell_laptop_i8042_filter); |
912 | cancel_delayed_work_sync(&dell_rfkill_work); | |
ad8f07cc | 913 | backlight_device_unregister(dell_backlight_device); |
4cc8a574 | 914 | dell_cleanup_rfkill(); |
facd61d7 | 915 | if (platform_device) { |
92e00e47 | 916 | platform_device_unregister(platform_device); |
facd61d7 MG |
917 | platform_driver_unregister(&platform_driver); |
918 | } | |
e551260b | 919 | kfree(da_tokens); |
116ee77b | 920 | free_page((unsigned long)buffer); |
ad8f07cc MG |
921 | } |
922 | ||
923 | module_init(dell_init); | |
924 | module_exit(dell_exit); | |
925 | ||
926 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); | |
927 | MODULE_DESCRIPTION("Dell laptop driver"); | |
928 | MODULE_LICENSE("GPL"); |