blob: a269e1abe50d24097deb494d0a4d1ab13e226086 [file] [log] [blame]
Matthew Garrettad8f07c2009-01-07 18:08:56 -08001/*
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
Joe Percheseb889522011-03-29 15:21:37 -070014#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
Matthew Garrettad8f07c2009-01-07 18:08:56 -080016#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>
Stuart Hayes116ee772010-02-10 14:12:13 -050027#include <linux/mm.h>
Matthew Garrett814cb8a2009-12-09 18:23:36 +000028#include <linux/i8042.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Keng-Yu Lin037accf2010-09-28 11:43:31 +080030#include <linux/debugfs.h>
31#include <linux/seq_file.h>
Len Browncad73122009-01-09 17:23:38 -050032#include "../../firmware/dcdbas.h"
Matthew Garrettad8f07c2009-01-07 18:08:56 -080033
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
39struct calling_interface_buffer {
40 u16 class;
41 u16 select;
42 volatile u32 input[4];
43 volatile u32 output[4];
44} __packed;
45
46struct calling_interface_token {
47 u16 tokenID;
48 u16 location;
49 union {
50 u16 value;
51 u16 stringlength;
52 };
53};
54
55struct 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
AceLan Kao2d8b90b2011-10-04 16:25:44 +080063struct quirk_entry {
64 u8 touchpad_led;
65};
66
67static struct quirk_entry *quirks;
68
69static struct quirk_entry quirk_dell_vostro_v130 = {
70 .touchpad_led = 1,
71};
72
73static int dmi_matched(const struct dmi_system_id *dmi)
74{
75 quirks = dmi->driver_data;
76 return 1;
77}
78
Matthew Garrettad8f07c2009-01-07 18:08:56 -080079static int da_command_address;
80static int da_command_code;
81static int da_num_tokens;
82static struct calling_interface_token *da_tokens;
83
Alan Jenkinsada32482009-08-19 15:06:49 +010084static struct platform_driver platform_driver = {
85 .driver = {
86 .name = "dell-laptop",
87 .owner = THIS_MODULE,
88 }
89};
90
91static struct platform_device *platform_device;
Matthew Garrettad8f07c2009-01-07 18:08:56 -080092static struct backlight_device *dell_backlight_device;
93static struct rfkill *wifi_rfkill;
94static struct rfkill *bluetooth_rfkill;
95static struct rfkill *wwan_rfkill;
96
97static 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 },
Erik Andrencb6a7932010-02-14 11:53:23 -0500105 {
Rezwanul Kabir410d44c2010-06-23 12:02:43 -0500106 .matches = {
107 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
108 DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/
109 },
110 },
111 {
Erik Andrencb6a7932010-02-14 11:53:23 -0500112 .ident = "Dell Computer Corporation",
113 .matches = {
114 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
115 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
116 },
117 },
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800118 { }
119};
Dmitry Torokhov35ae64f2011-11-14 00:25:00 -0800120MODULE_DEVICE_TABLE(dmi, dell_device_table);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800121
Mario Limoncielloe5fefd02010-02-09 17:41:03 -0500122static 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 },
145 {
Victor van den Elzenc3f755e2010-08-15 01:19:33 +0200146 .ident = "Dell Mini 1012",
147 .matches = {
148 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
149 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"),
150 },
151 },
152 {
Mario Limoncielloe5fefd02010-02-09 17:41:03 -0500153 .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
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800169static 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 },
AceLan Kao2a748852011-11-17 15:30:42 +0800188 {
189 .callback = dmi_matched,
Ang Way Chuang57b31b22012-04-12 13:11:27 +0800190 .ident = "Dell Vostro 3350",
191 .matches = {
192 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
193 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"),
194 },
195 .driver_data = &quirk_dell_vostro_v130,
196 },
197 {
198 .callback = dmi_matched,
AceLan Kao2a748852011-11-17 15:30:42 +0800199 .ident = "Dell Vostro 3555",
200 .matches = {
201 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
202 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"),
203 },
204 .driver_data = &quirk_dell_vostro_v130,
205 },
206 {
207 .callback = dmi_matched,
208 .ident = "Dell Inspiron N311z",
209 .matches = {
210 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
211 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"),
212 },
213 .driver_data = &quirk_dell_vostro_v130,
214 },
215 {
216 .callback = dmi_matched,
217 .ident = "Dell Inspiron M5110",
218 .matches = {
219 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
220 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"),
221 },
222 .driver_data = &quirk_dell_vostro_v130,
223 },
AceLan Kao7f839222012-04-20 11:47:26 +0800224 {
225 .callback = dmi_matched,
226 .ident = "Dell Vostro 3360",
227 .matches = {
228 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
229 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
230 },
231 .driver_data = &quirk_dell_vostro_v130,
232 },
233 {
234 .callback = dmi_matched,
235 .ident = "Dell Vostro 3460",
236 .matches = {
237 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
238 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"),
239 },
240 .driver_data = &quirk_dell_vostro_v130,
241 },
242 {
243 .callback = dmi_matched,
244 .ident = "Dell Vostro 3560",
245 .matches = {
246 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
247 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"),
248 },
249 .driver_data = &quirk_dell_vostro_v130,
250 },
Martin Nyhusd62d4212012-03-15 18:25:48 +0100251 { }
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800252};
253
Stuart Hayes116ee772010-02-10 14:12:13 -0500254static struct calling_interface_buffer *buffer;
Ingo Molnar94d8f782010-03-01 09:43:52 -0500255static struct page *bufferpage;
256static DEFINE_MUTEX(buffer_mutex);
Stuart Hayes116ee772010-02-10 14:12:13 -0500257
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500258static int hwswitch_state;
259
Stuart Hayes116ee772010-02-10 14:12:13 -0500260static void get_buffer(void)
261{
262 mutex_lock(&buffer_mutex);
263 memset(buffer, 0, sizeof(struct calling_interface_buffer));
264}
265
266static void release_buffer(void)
267{
268 mutex_unlock(&buffer_mutex);
269}
270
Alan Jenkins4788df42009-08-19 15:06:50 +0100271static void __init parse_da_table(const struct dmi_header *dm)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800272{
273 /* Final token is a terminator, so we don't want to copy it */
274 int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
275 struct calling_interface_structure *table =
276 container_of(dm, struct calling_interface_structure, header);
277
278 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
279 6 bytes of entry */
280
281 if (dm->length < 17)
282 return;
283
284 da_command_address = table->cmdIOAddress;
285 da_command_code = table->cmdIOCode;
286
287 da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
288 sizeof(struct calling_interface_token),
289 GFP_KERNEL);
290
291 if (!da_tokens)
292 return;
293
294 memcpy(da_tokens+da_num_tokens, table->tokens,
295 sizeof(struct calling_interface_token) * tokens);
296
297 da_num_tokens += tokens;
298}
299
Alan Jenkins4788df42009-08-19 15:06:50 +0100300static void __init find_tokens(const struct dmi_header *dm, void *dummy)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800301{
302 switch (dm->type) {
303 case 0xd4: /* Indexed IO */
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800304 case 0xd5: /* Protected Area Type 1 */
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800305 case 0xd6: /* Protected Area Type 2 */
306 break;
307 case 0xda: /* Calling interface */
308 parse_da_table(dm);
309 break;
310 }
311}
312
313static int find_token_location(int tokenid)
314{
315 int i;
316 for (i = 0; i < da_num_tokens; i++) {
317 if (da_tokens[i].tokenID == tokenid)
318 return da_tokens[i].location;
319 }
320
321 return -1;
322}
323
324static struct calling_interface_buffer *
325dell_send_request(struct calling_interface_buffer *buffer, int class,
326 int select)
327{
328 struct smi_cmd command;
329
330 command.magic = SMI_CMD_MAGIC;
331 command.command_address = da_command_address;
332 command.command_code = da_command_code;
333 command.ebx = virt_to_phys(buffer);
334 command.ecx = 0x42534931;
335
336 buffer->class = class;
337 buffer->select = select;
338
339 dcdbas_smi_request(&command);
340
341 return buffer;
342}
343
344/* Derived from information in DellWirelessCtl.cpp:
345 Class 17, select 11 is radio control. It returns an array of 32-bit values.
346
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500347 Input byte 0 = 0: Wireless information
348
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800349 result[0]: return code
350 result[1]:
351 Bit 0: Hardware switch supported
352 Bit 1: Wifi locator supported
353 Bit 2: Wifi is supported
354 Bit 3: Bluetooth is supported
355 Bit 4: WWAN is supported
356 Bit 5: Wireless keyboard supported
357 Bits 6-7: Reserved
358 Bit 8: Wifi is installed
359 Bit 9: Bluetooth is installed
360 Bit 10: WWAN is installed
361 Bits 11-15: Reserved
362 Bit 16: Hardware switch is on
363 Bit 17: Wifi is blocked
364 Bit 18: Bluetooth is blocked
365 Bit 19: WWAN is blocked
366 Bits 20-31: Reserved
367 result[2]: NVRAM size in bytes
368 result[3]: NVRAM format version number
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500369
370 Input byte 0 = 2: Wireless switch configuration
371 result[0]: return code
372 result[1]:
373 Bit 0: Wifi controlled by switch
374 Bit 1: Bluetooth controlled by switch
375 Bit 2: WWAN controlled by switch
376 Bits 3-6: Reserved
377 Bit 7: Wireless switch config locked
378 Bit 8: Wifi locator enabled
379 Bits 9-14: Reserved
380 Bit 15: Wifi locator setting locked
381 Bits 16-31: Reserved
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800382*/
383
Johannes Berg19d337d2009-06-02 13:01:37 +0200384static int dell_rfkill_set(void *data, bool blocked)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800385{
Johannes Berg624f0de2009-06-15 16:26:47 +0200386 int disable = blocked ? 1 : 0;
Johannes Berg19d337d2009-06-02 13:01:37 +0200387 unsigned long radio = (unsigned long)data;
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500388 int hwswitch_bit = (unsigned long)data - 1;
Stuart Hayes116ee772010-02-10 14:12:13 -0500389 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800390
Stuart Hayes116ee772010-02-10 14:12:13 -0500391 get_buffer();
392 dell_send_request(buffer, 17, 11);
Mario Limoncielloec1722a2010-02-09 14:11:05 -0500393
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500394 /* If the hardware switch controls this radio, and the hardware
Keng-Yu Linbe65dde82011-06-27 11:19:03 +0100395 switch is disabled, don't allow changing the software state */
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500396 if ((hwswitch_state & BIT(hwswitch_bit)) &&
Keng-Yu Linbe65dde82011-06-27 11:19:03 +0100397 !(buffer->output[1] & BIT(16))) {
Stuart Hayes116ee772010-02-10 14:12:13 -0500398 ret = -EINVAL;
399 goto out;
400 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800401
Stuart Hayes116ee772010-02-10 14:12:13 -0500402 buffer->input[0] = (1 | (radio<<8) | (disable << 16));
403 dell_send_request(buffer, 17, 11);
404
405out:
406 release_buffer();
407 return ret;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800408}
409
Johannes Berg19d337d2009-06-02 13:01:37 +0200410static void dell_rfkill_query(struct rfkill *rfkill, void *data)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800411{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800412 int status;
Johannes Berg19d337d2009-06-02 13:01:37 +0200413 int bit = (unsigned long)data + 16;
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500414 int hwswitch_bit = (unsigned long)data - 1;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800415
Stuart Hayes116ee772010-02-10 14:12:13 -0500416 get_buffer();
417 dell_send_request(buffer, 17, 11);
418 status = buffer->output[1];
419 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800420
Matthew Garrette1fbf342009-07-31 03:25:38 +0100421 rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500422
423 if (hwswitch_state & (BIT(hwswitch_bit)))
424 rfkill_set_hw_state(rfkill, !(status & BIT(16)));
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800425}
426
Johannes Berg19d337d2009-06-02 13:01:37 +0200427static const struct rfkill_ops dell_rfkill_ops = {
428 .set_block = dell_rfkill_set,
429 .query = dell_rfkill_query,
430};
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800431
Keng-Yu Lin037accf2010-09-28 11:43:31 +0800432static struct dentry *dell_laptop_dir;
433
434static int dell_debugfs_show(struct seq_file *s, void *data)
435{
436 int status;
437
438 get_buffer();
439 dell_send_request(buffer, 17, 11);
440 status = buffer->output[1];
441 release_buffer();
442
443 seq_printf(s, "status:\t0x%X\n", status);
444 seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n",
445 status & BIT(0));
446 seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n",
447 (status & BIT(1)) >> 1);
448 seq_printf(s, "Bit 2 : Wifi is supported: %lu\n",
449 (status & BIT(2)) >> 2);
450 seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n",
451 (status & BIT(3)) >> 3);
452 seq_printf(s, "Bit 4 : WWAN is supported: %lu\n",
453 (status & BIT(4)) >> 4);
454 seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n",
455 (status & BIT(5)) >> 5);
456 seq_printf(s, "Bit 8 : Wifi is installed: %lu\n",
457 (status & BIT(8)) >> 8);
458 seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n",
459 (status & BIT(9)) >> 9);
460 seq_printf(s, "Bit 10: WWAN is installed: %lu\n",
461 (status & BIT(10)) >> 10);
462 seq_printf(s, "Bit 16: Hardware switch is on: %lu\n",
463 (status & BIT(16)) >> 16);
464 seq_printf(s, "Bit 17: Wifi is blocked: %lu\n",
465 (status & BIT(17)) >> 17);
466 seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n",
467 (status & BIT(18)) >> 18);
468 seq_printf(s, "Bit 19: WWAN is blocked: %lu\n",
469 (status & BIT(19)) >> 19);
470
471 seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state);
472 seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n",
473 hwswitch_state & BIT(0));
474 seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n",
475 (hwswitch_state & BIT(1)) >> 1);
476 seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n",
477 (hwswitch_state & BIT(2)) >> 2);
478 seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n",
479 (hwswitch_state & BIT(7)) >> 7);
480 seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n",
481 (hwswitch_state & BIT(8)) >> 8);
482 seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n",
483 (hwswitch_state & BIT(15)) >> 15);
484
485 return 0;
486}
487
488static int dell_debugfs_open(struct inode *inode, struct file *file)
489{
490 return single_open(file, dell_debugfs_show, inode->i_private);
491}
492
493static const struct file_operations dell_debugfs_fops = {
494 .owner = THIS_MODULE,
495 .open = dell_debugfs_open,
496 .read = seq_read,
497 .llseek = seq_lseek,
498 .release = single_release,
499};
500
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000501static void dell_update_rfkill(struct work_struct *ignored)
502{
503 if (wifi_rfkill)
504 dell_rfkill_query(wifi_rfkill, (void *)1);
505 if (bluetooth_rfkill)
506 dell_rfkill_query(bluetooth_rfkill, (void *)2);
507 if (wwan_rfkill)
508 dell_rfkill_query(wwan_rfkill, (void *)3);
509}
510static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
511
512
Alan Jenkins4788df42009-08-19 15:06:50 +0100513static int __init dell_setup_rfkill(void)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800514{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800515 int status;
516 int ret;
517
Mario Limoncielloe5fefd02010-02-09 17:41:03 -0500518 if (dmi_check_system(dell_blacklist)) {
Joe Percheseb889522011-03-29 15:21:37 -0700519 pr_info("Blacklisted hardware detected - not enabling rfkill\n");
Mario Limoncielloe5fefd02010-02-09 17:41:03 -0500520 return 0;
521 }
522
Stuart Hayes116ee772010-02-10 14:12:13 -0500523 get_buffer();
524 dell_send_request(buffer, 17, 11);
525 status = buffer->output[1];
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500526 buffer->input[0] = 0x2;
527 dell_send_request(buffer, 17, 11);
528 hwswitch_state = buffer->output[1];
Stuart Hayes116ee772010-02-10 14:12:13 -0500529 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800530
531 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100532 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
533 RFKILL_TYPE_WLAN,
Johannes Berg19d337d2009-06-02 13:01:37 +0200534 &dell_rfkill_ops, (void *) 1);
535 if (!wifi_rfkill) {
536 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800537 goto err_wifi;
Johannes Berg19d337d2009-06-02 13:01:37 +0200538 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800539 ret = rfkill_register(wifi_rfkill);
540 if (ret)
541 goto err_wifi;
542 }
543
544 if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100545 bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
546 &platform_device->dev,
Johannes Berg19d337d2009-06-02 13:01:37 +0200547 RFKILL_TYPE_BLUETOOTH,
548 &dell_rfkill_ops, (void *) 2);
549 if (!bluetooth_rfkill) {
550 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800551 goto err_bluetooth;
Johannes Berg19d337d2009-06-02 13:01:37 +0200552 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800553 ret = rfkill_register(bluetooth_rfkill);
554 if (ret)
555 goto err_bluetooth;
556 }
557
558 if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100559 wwan_rfkill = rfkill_alloc("dell-wwan",
560 &platform_device->dev,
561 RFKILL_TYPE_WWAN,
Johannes Berg19d337d2009-06-02 13:01:37 +0200562 &dell_rfkill_ops, (void *) 3);
563 if (!wwan_rfkill) {
564 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800565 goto err_wwan;
Johannes Berg19d337d2009-06-02 13:01:37 +0200566 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800567 ret = rfkill_register(wwan_rfkill);
568 if (ret)
569 goto err_wwan;
570 }
571
572 return 0;
573err_wwan:
Johannes Berg19d337d2009-06-02 13:01:37 +0200574 rfkill_destroy(wwan_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800575 if (bluetooth_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200576 rfkill_unregister(bluetooth_rfkill);
577err_bluetooth:
578 rfkill_destroy(bluetooth_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800579 if (wifi_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200580 rfkill_unregister(wifi_rfkill);
581err_wifi:
582 rfkill_destroy(wifi_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800583
584 return ret;
585}
586
Alan Jenkins4311bb22009-08-19 15:06:48 +0100587static void dell_cleanup_rfkill(void)
588{
589 if (wifi_rfkill) {
590 rfkill_unregister(wifi_rfkill);
591 rfkill_destroy(wifi_rfkill);
592 }
593 if (bluetooth_rfkill) {
594 rfkill_unregister(bluetooth_rfkill);
595 rfkill_destroy(bluetooth_rfkill);
596 }
597 if (wwan_rfkill) {
598 rfkill_unregister(wwan_rfkill);
599 rfkill_destroy(wwan_rfkill);
600 }
601}
602
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800603static int dell_send_intensity(struct backlight_device *bd)
604{
Stuart Hayes116ee772010-02-10 14:12:13 -0500605 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800606
Stuart Hayes116ee772010-02-10 14:12:13 -0500607 get_buffer();
608 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
609 buffer->input[1] = bd->props.brightness;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800610
Stuart Hayes116ee772010-02-10 14:12:13 -0500611 if (buffer->input[0] == -1) {
612 ret = -ENODEV;
613 goto out;
614 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800615
616 if (power_supply_is_system_supplied() > 0)
Stuart Hayes116ee772010-02-10 14:12:13 -0500617 dell_send_request(buffer, 1, 2);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800618 else
Stuart Hayes116ee772010-02-10 14:12:13 -0500619 dell_send_request(buffer, 1, 1);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800620
Stuart Hayes116ee772010-02-10 14:12:13 -0500621out:
622 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800623 return 0;
624}
625
626static int dell_get_intensity(struct backlight_device *bd)
627{
Stuart Hayes116ee772010-02-10 14:12:13 -0500628 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800629
Stuart Hayes116ee772010-02-10 14:12:13 -0500630 get_buffer();
631 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800632
Stuart Hayes116ee772010-02-10 14:12:13 -0500633 if (buffer->input[0] == -1) {
634 ret = -ENODEV;
635 goto out;
636 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800637
638 if (power_supply_is_system_supplied() > 0)
Stuart Hayes116ee772010-02-10 14:12:13 -0500639 dell_send_request(buffer, 0, 2);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800640 else
Stuart Hayes116ee772010-02-10 14:12:13 -0500641 dell_send_request(buffer, 0, 1);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800642
Jose Alonsob4867422011-07-10 15:46:51 -0300643 ret = buffer->output[1];
644
Stuart Hayes116ee772010-02-10 14:12:13 -0500645out:
646 release_buffer();
Jose Alonsob4867422011-07-10 15:46:51 -0300647 return ret;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800648}
649
Lionel Debrouxacc24722010-11-16 14:14:02 +0100650static const struct backlight_ops dell_ops = {
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800651 .get_brightness = dell_get_intensity,
652 .update_status = dell_send_intensity,
653};
654
Randy Dunlap869f8df2011-11-16 18:20:51 -0800655static void touchpad_led_on(void)
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800656{
657 int command = 0x97;
658 char data = 1;
659 i8042_command(&data, command | 1 << 12);
660}
661
Randy Dunlap869f8df2011-11-16 18:20:51 -0800662static void touchpad_led_off(void)
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800663{
664 int command = 0x97;
665 char data = 2;
666 i8042_command(&data, command | 1 << 12);
667}
668
669static void touchpad_led_set(struct led_classdev *led_cdev,
670 enum led_brightness value)
671{
672 if (value > 0)
673 touchpad_led_on();
674 else
675 touchpad_led_off();
676}
677
678static struct led_classdev touchpad_led = {
679 .name = "dell-laptop::touchpad",
680 .brightness_set = touchpad_led_set,
AceLan Kao2d5de9e2012-01-17 16:18:06 +0800681 .flags = LED_CORE_SUSPENDRESUME,
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800682};
683
684static int __devinit touchpad_led_init(struct device *dev)
685{
686 return led_classdev_register(dev, &touchpad_led);
687}
688
689static void touchpad_led_exit(void)
690{
691 led_classdev_unregister(&touchpad_led);
692}
693
Axel Lin45191692010-07-05 17:21:10 +0800694static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000695 struct serio *port)
696{
697 static bool extended;
698
699 if (str & 0x20)
700 return false;
701
702 if (unlikely(data == 0xe0)) {
703 extended = true;
704 return false;
705 } else if (unlikely(extended)) {
706 switch (data) {
707 case 0x8:
708 schedule_delayed_work(&dell_rfkill_work,
709 round_jiffies_relative(HZ));
710 break;
711 }
712 extended = false;
713 }
714
715 return false;
716}
717
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800718static int __init dell_init(void)
719{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800720 int max_intensity = 0;
721 int ret;
722
723 if (!dmi_check_system(dell_device_table))
724 return -ENODEV;
725
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800726 quirks = NULL;
727 /* find if this machine support other functions */
728 dmi_check_system(dell_quirks);
729
Jean Delvaree7a19c52009-03-30 21:46:44 +0200730 dmi_walk(find_tokens, NULL);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800731
732 if (!da_tokens) {
Joe Percheseb889522011-03-29 15:21:37 -0700733 pr_info("Unable to find dmi tokens\n");
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800734 return -ENODEV;
735 }
736
Alan Jenkinsada32482009-08-19 15:06:49 +0100737 ret = platform_driver_register(&platform_driver);
738 if (ret)
739 goto fail_platform_driver;
740 platform_device = platform_device_alloc("dell-laptop", -1);
741 if (!platform_device) {
742 ret = -ENOMEM;
743 goto fail_platform_device1;
744 }
745 ret = platform_device_add(platform_device);
746 if (ret)
747 goto fail_platform_device2;
748
Stuart Hayes116ee772010-02-10 14:12:13 -0500749 /*
750 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
751 * is passed to SMI handler.
752 */
753 bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
754
755 if (!bufferpage)
756 goto fail_buffer;
757 buffer = page_address(bufferpage);
Stuart Hayes116ee772010-02-10 14:12:13 -0500758
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800759 ret = dell_setup_rfkill();
760
761 if (ret) {
Joe Percheseb889522011-03-29 15:21:37 -0700762 pr_warn("Unable to setup rfkill\n");
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100763 goto fail_rfkill;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800764 }
765
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000766 ret = i8042_install_filter(dell_laptop_i8042_filter);
767 if (ret) {
Joe Percheseb889522011-03-29 15:21:37 -0700768 pr_warn("Unable to install key filter\n");
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000769 goto fail_filter;
770 }
771
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800772 if (quirks && quirks->touchpad_led)
773 touchpad_led_init(&platform_device->dev);
774
Keng-Yu Lin037accf2010-09-28 11:43:31 +0800775 dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
776 if (dell_laptop_dir != NULL)
777 debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
778 &dell_debugfs_fops);
779
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800780#ifdef CONFIG_ACPI
781 /* In the event of an ACPI backlight being available, don't
782 * register the platform controller.
783 */
784 if (acpi_video_backlight_support())
785 return 0;
786#endif
787
Stuart Hayes116ee772010-02-10 14:12:13 -0500788 get_buffer();
789 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
790 if (buffer->input[0] != -1) {
791 dell_send_request(buffer, 0, 2);
792 max_intensity = buffer->output[3];
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800793 }
Stuart Hayes116ee772010-02-10 14:12:13 -0500794 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800795
796 if (max_intensity) {
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500797 struct backlight_properties props;
798 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700799 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500800 props.max_brightness = max_intensity;
801 dell_backlight_device = backlight_device_register("dell_backlight",
802 &platform_device->dev,
803 NULL,
804 &dell_ops,
805 &props);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800806
807 if (IS_ERR(dell_backlight_device)) {
808 ret = PTR_ERR(dell_backlight_device);
809 dell_backlight_device = NULL;
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100810 goto fail_backlight;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800811 }
812
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800813 dell_backlight_device->props.brightness =
814 dell_get_intensity(dell_backlight_device);
815 backlight_update_status(dell_backlight_device);
816 }
817
818 return 0;
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100819
820fail_backlight:
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000821 i8042_remove_filter(dell_laptop_i8042_filter);
Matthew Garrett92e00e42010-03-01 09:46:43 -0500822 cancel_delayed_work_sync(&dell_rfkill_work);
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000823fail_filter:
Alan Jenkins4311bb22009-08-19 15:06:48 +0100824 dell_cleanup_rfkill();
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100825fail_rfkill:
Stuart Hayes116ee772010-02-10 14:12:13 -0500826 free_page((unsigned long)bufferpage);
827fail_buffer:
Alan Jenkinsada32482009-08-19 15:06:49 +0100828 platform_device_del(platform_device);
829fail_platform_device2:
830 platform_device_put(platform_device);
831fail_platform_device1:
832 platform_driver_unregister(&platform_driver);
833fail_platform_driver:
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800834 kfree(da_tokens);
835 return ret;
836}
837
838static void __exit dell_exit(void)
839{
Keng-Yu Lin037accf2010-09-28 11:43:31 +0800840 debugfs_remove_recursive(dell_laptop_dir);
AceLan Kao2d8b90b2011-10-04 16:25:44 +0800841 if (quirks && quirks->touchpad_led)
842 touchpad_led_exit();
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000843 i8042_remove_filter(dell_laptop_i8042_filter);
Matthew Garrett92e00e42010-03-01 09:46:43 -0500844 cancel_delayed_work_sync(&dell_rfkill_work);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800845 backlight_device_unregister(dell_backlight_device);
Alan Jenkins4311bb22009-08-19 15:06:48 +0100846 dell_cleanup_rfkill();
Matthew Garrettfacd61d2010-02-09 14:03:04 -0500847 if (platform_device) {
Matthew Garrett92e00e42010-03-01 09:46:43 -0500848 platform_device_unregister(platform_device);
Matthew Garrettfacd61d2010-02-09 14:03:04 -0500849 platform_driver_unregister(&platform_driver);
850 }
Matthew Garrette5512602010-02-09 14:05:01 -0500851 kfree(da_tokens);
Stuart Hayes116ee772010-02-10 14:12:13 -0500852 free_page((unsigned long)buffer);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800853}
854
855module_init(dell_init);
856module_exit(dell_exit);
857
858MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
859MODULE_DESCRIPTION("Dell laptop driver");
860MODULE_LICENSE("GPL");