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