blob: 661e3ac4d5b112edfa417b154ae6a60e104c2ffa [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
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/backlight.h>
19#include <linux/err.h>
20#include <linux/dmi.h>
21#include <linux/io.h>
22#include <linux/rfkill.h>
23#include <linux/power_supply.h>
24#include <linux/acpi.h>
Stuart Hayes116ee772010-02-10 14:12:13 -050025#include <linux/mm.h>
Matthew Garrett814cb8a2009-12-09 18:23:36 +000026#include <linux/i8042.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Len Browncad73122009-01-09 17:23:38 -050028#include "../../firmware/dcdbas.h"
Matthew Garrettad8f07c2009-01-07 18:08:56 -080029
30#define BRIGHTNESS_TOKEN 0x7d
31
32/* This structure will be modified by the firmware when we enter
33 * system management mode, hence the volatiles */
34
35struct calling_interface_buffer {
36 u16 class;
37 u16 select;
38 volatile u32 input[4];
39 volatile u32 output[4];
40} __packed;
41
42struct calling_interface_token {
43 u16 tokenID;
44 u16 location;
45 union {
46 u16 value;
47 u16 stringlength;
48 };
49};
50
51struct calling_interface_structure {
52 struct dmi_header header;
53 u16 cmdIOAddress;
54 u8 cmdIOCode;
55 u32 supportedCmds;
56 struct calling_interface_token tokens[];
57} __packed;
58
59static int da_command_address;
60static int da_command_code;
61static int da_num_tokens;
62static struct calling_interface_token *da_tokens;
63
Alan Jenkinsada32482009-08-19 15:06:49 +010064static struct platform_driver platform_driver = {
65 .driver = {
66 .name = "dell-laptop",
67 .owner = THIS_MODULE,
68 }
69};
70
71static struct platform_device *platform_device;
Matthew Garrettad8f07c2009-01-07 18:08:56 -080072static struct backlight_device *dell_backlight_device;
73static struct rfkill *wifi_rfkill;
74static struct rfkill *bluetooth_rfkill;
75static struct rfkill *wwan_rfkill;
76
77static const struct dmi_system_id __initdata dell_device_table[] = {
78 {
79 .ident = "Dell laptop",
80 .matches = {
81 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
82 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
83 },
84 },
Erik Andrencb6a7932010-02-14 11:53:23 -050085 {
86 .ident = "Dell Computer Corporation",
87 .matches = {
88 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
89 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
90 },
91 },
Matthew Garrettad8f07c2009-01-07 18:08:56 -080092 { }
93};
94
Mario Limoncielloe5fefd02010-02-09 17:41:03 -050095static struct dmi_system_id __devinitdata dell_blacklist[] = {
96 /* Supported by compal-laptop */
97 {
98 .ident = "Dell Mini 9",
99 .matches = {
100 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
101 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
102 },
103 },
104 {
105 .ident = "Dell Mini 10",
106 .matches = {
107 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
108 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
109 },
110 },
111 {
112 .ident = "Dell Mini 10v",
113 .matches = {
114 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
115 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
116 },
117 },
118 {
119 .ident = "Dell Inspiron 11z",
120 .matches = {
121 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
122 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
123 },
124 },
125 {
126 .ident = "Dell Mini 12",
127 .matches = {
128 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
129 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
130 },
131 },
132 {}
133};
134
Stuart Hayes116ee772010-02-10 14:12:13 -0500135static struct calling_interface_buffer *buffer;
Ingo Molnar94d8f782010-03-01 09:43:52 -0500136static struct page *bufferpage;
137static DEFINE_MUTEX(buffer_mutex);
Stuart Hayes116ee772010-02-10 14:12:13 -0500138
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500139static int hwswitch_state;
140
Stuart Hayes116ee772010-02-10 14:12:13 -0500141static void get_buffer(void)
142{
143 mutex_lock(&buffer_mutex);
144 memset(buffer, 0, sizeof(struct calling_interface_buffer));
145}
146
147static void release_buffer(void)
148{
149 mutex_unlock(&buffer_mutex);
150}
151
Alan Jenkins4788df42009-08-19 15:06:50 +0100152static void __init parse_da_table(const struct dmi_header *dm)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800153{
154 /* Final token is a terminator, so we don't want to copy it */
155 int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
156 struct calling_interface_structure *table =
157 container_of(dm, struct calling_interface_structure, header);
158
159 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
160 6 bytes of entry */
161
162 if (dm->length < 17)
163 return;
164
165 da_command_address = table->cmdIOAddress;
166 da_command_code = table->cmdIOCode;
167
168 da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
169 sizeof(struct calling_interface_token),
170 GFP_KERNEL);
171
172 if (!da_tokens)
173 return;
174
175 memcpy(da_tokens+da_num_tokens, table->tokens,
176 sizeof(struct calling_interface_token) * tokens);
177
178 da_num_tokens += tokens;
179}
180
Alan Jenkins4788df42009-08-19 15:06:50 +0100181static void __init find_tokens(const struct dmi_header *dm, void *dummy)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800182{
183 switch (dm->type) {
184 case 0xd4: /* Indexed IO */
185 break;
186 case 0xd5: /* Protected Area Type 1 */
187 break;
188 case 0xd6: /* Protected Area Type 2 */
189 break;
190 case 0xda: /* Calling interface */
191 parse_da_table(dm);
192 break;
193 }
194}
195
196static int find_token_location(int tokenid)
197{
198 int i;
199 for (i = 0; i < da_num_tokens; i++) {
200 if (da_tokens[i].tokenID == tokenid)
201 return da_tokens[i].location;
202 }
203
204 return -1;
205}
206
207static struct calling_interface_buffer *
208dell_send_request(struct calling_interface_buffer *buffer, int class,
209 int select)
210{
211 struct smi_cmd command;
212
213 command.magic = SMI_CMD_MAGIC;
214 command.command_address = da_command_address;
215 command.command_code = da_command_code;
216 command.ebx = virt_to_phys(buffer);
217 command.ecx = 0x42534931;
218
219 buffer->class = class;
220 buffer->select = select;
221
222 dcdbas_smi_request(&command);
223
224 return buffer;
225}
226
227/* Derived from information in DellWirelessCtl.cpp:
228 Class 17, select 11 is radio control. It returns an array of 32-bit values.
229
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500230 Input byte 0 = 0: Wireless information
231
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800232 result[0]: return code
233 result[1]:
234 Bit 0: Hardware switch supported
235 Bit 1: Wifi locator supported
236 Bit 2: Wifi is supported
237 Bit 3: Bluetooth is supported
238 Bit 4: WWAN is supported
239 Bit 5: Wireless keyboard supported
240 Bits 6-7: Reserved
241 Bit 8: Wifi is installed
242 Bit 9: Bluetooth is installed
243 Bit 10: WWAN is installed
244 Bits 11-15: Reserved
245 Bit 16: Hardware switch is on
246 Bit 17: Wifi is blocked
247 Bit 18: Bluetooth is blocked
248 Bit 19: WWAN is blocked
249 Bits 20-31: Reserved
250 result[2]: NVRAM size in bytes
251 result[3]: NVRAM format version number
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500252
253 Input byte 0 = 2: Wireless switch configuration
254 result[0]: return code
255 result[1]:
256 Bit 0: Wifi controlled by switch
257 Bit 1: Bluetooth controlled by switch
258 Bit 2: WWAN controlled by switch
259 Bits 3-6: Reserved
260 Bit 7: Wireless switch config locked
261 Bit 8: Wifi locator enabled
262 Bits 9-14: Reserved
263 Bit 15: Wifi locator setting locked
264 Bits 16-31: Reserved
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800265*/
266
Johannes Berg19d337d2009-06-02 13:01:37 +0200267static int dell_rfkill_set(void *data, bool blocked)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800268{
Johannes Berg624f0de2009-06-15 16:26:47 +0200269 int disable = blocked ? 1 : 0;
Johannes Berg19d337d2009-06-02 13:01:37 +0200270 unsigned long radio = (unsigned long)data;
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500271 int hwswitch_bit = (unsigned long)data - 1;
Stuart Hayes116ee772010-02-10 14:12:13 -0500272 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800273
Stuart Hayes116ee772010-02-10 14:12:13 -0500274 get_buffer();
275 dell_send_request(buffer, 17, 11);
Mario Limoncielloec1722a2010-02-09 14:11:05 -0500276
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500277 /* If the hardware switch controls this radio, and the hardware
278 switch is disabled, don't allow changing the software state */
279 if ((hwswitch_state & BIT(hwswitch_bit)) &&
280 !(buffer->output[1] & BIT(16))) {
Stuart Hayes116ee772010-02-10 14:12:13 -0500281 ret = -EINVAL;
282 goto out;
283 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800284
Stuart Hayes116ee772010-02-10 14:12:13 -0500285 buffer->input[0] = (1 | (radio<<8) | (disable << 16));
286 dell_send_request(buffer, 17, 11);
287
288out:
289 release_buffer();
290 return ret;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800291}
292
Johannes Berg19d337d2009-06-02 13:01:37 +0200293static void dell_rfkill_query(struct rfkill *rfkill, void *data)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800294{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800295 int status;
Johannes Berg19d337d2009-06-02 13:01:37 +0200296 int bit = (unsigned long)data + 16;
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500297 int hwswitch_bit = (unsigned long)data - 1;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800298
Stuart Hayes116ee772010-02-10 14:12:13 -0500299 get_buffer();
300 dell_send_request(buffer, 17, 11);
301 status = buffer->output[1];
302 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800303
Matthew Garrette1fbf342009-07-31 03:25:38 +0100304 rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500305
306 if (hwswitch_state & (BIT(hwswitch_bit)))
307 rfkill_set_hw_state(rfkill, !(status & BIT(16)));
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800308}
309
Johannes Berg19d337d2009-06-02 13:01:37 +0200310static const struct rfkill_ops dell_rfkill_ops = {
311 .set_block = dell_rfkill_set,
312 .query = dell_rfkill_query,
313};
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800314
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000315static void dell_update_rfkill(struct work_struct *ignored)
316{
317 if (wifi_rfkill)
318 dell_rfkill_query(wifi_rfkill, (void *)1);
319 if (bluetooth_rfkill)
320 dell_rfkill_query(bluetooth_rfkill, (void *)2);
321 if (wwan_rfkill)
322 dell_rfkill_query(wwan_rfkill, (void *)3);
323}
324static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
325
326
Alan Jenkins4788df42009-08-19 15:06:50 +0100327static int __init dell_setup_rfkill(void)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800328{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800329 int status;
330 int ret;
331
Mario Limoncielloe5fefd02010-02-09 17:41:03 -0500332 if (dmi_check_system(dell_blacklist)) {
333 printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - "
334 "not enabling rfkill\n");
335 return 0;
336 }
337
Stuart Hayes116ee772010-02-10 14:12:13 -0500338 get_buffer();
339 dell_send_request(buffer, 17, 11);
340 status = buffer->output[1];
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500341 buffer->input[0] = 0x2;
342 dell_send_request(buffer, 17, 11);
343 hwswitch_state = buffer->output[1];
Stuart Hayes116ee772010-02-10 14:12:13 -0500344 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800345
346 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100347 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
348 RFKILL_TYPE_WLAN,
Johannes Berg19d337d2009-06-02 13:01:37 +0200349 &dell_rfkill_ops, (void *) 1);
350 if (!wifi_rfkill) {
351 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800352 goto err_wifi;
Johannes Berg19d337d2009-06-02 13:01:37 +0200353 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800354 ret = rfkill_register(wifi_rfkill);
355 if (ret)
356 goto err_wifi;
357 }
358
359 if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100360 bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
361 &platform_device->dev,
Johannes Berg19d337d2009-06-02 13:01:37 +0200362 RFKILL_TYPE_BLUETOOTH,
363 &dell_rfkill_ops, (void *) 2);
364 if (!bluetooth_rfkill) {
365 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800366 goto err_bluetooth;
Johannes Berg19d337d2009-06-02 13:01:37 +0200367 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800368 ret = rfkill_register(bluetooth_rfkill);
369 if (ret)
370 goto err_bluetooth;
371 }
372
373 if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100374 wwan_rfkill = rfkill_alloc("dell-wwan",
375 &platform_device->dev,
376 RFKILL_TYPE_WWAN,
Johannes Berg19d337d2009-06-02 13:01:37 +0200377 &dell_rfkill_ops, (void *) 3);
378 if (!wwan_rfkill) {
379 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800380 goto err_wwan;
Johannes Berg19d337d2009-06-02 13:01:37 +0200381 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800382 ret = rfkill_register(wwan_rfkill);
383 if (ret)
384 goto err_wwan;
385 }
386
387 return 0;
388err_wwan:
Johannes Berg19d337d2009-06-02 13:01:37 +0200389 rfkill_destroy(wwan_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800390 if (bluetooth_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200391 rfkill_unregister(bluetooth_rfkill);
392err_bluetooth:
393 rfkill_destroy(bluetooth_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800394 if (wifi_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200395 rfkill_unregister(wifi_rfkill);
396err_wifi:
397 rfkill_destroy(wifi_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800398
399 return ret;
400}
401
Alan Jenkins4311bb22009-08-19 15:06:48 +0100402static void dell_cleanup_rfkill(void)
403{
404 if (wifi_rfkill) {
405 rfkill_unregister(wifi_rfkill);
406 rfkill_destroy(wifi_rfkill);
407 }
408 if (bluetooth_rfkill) {
409 rfkill_unregister(bluetooth_rfkill);
410 rfkill_destroy(bluetooth_rfkill);
411 }
412 if (wwan_rfkill) {
413 rfkill_unregister(wwan_rfkill);
414 rfkill_destroy(wwan_rfkill);
415 }
416}
417
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800418static int dell_send_intensity(struct backlight_device *bd)
419{
Stuart Hayes116ee772010-02-10 14:12:13 -0500420 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800421
Stuart Hayes116ee772010-02-10 14:12:13 -0500422 get_buffer();
423 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
424 buffer->input[1] = bd->props.brightness;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800425
Stuart Hayes116ee772010-02-10 14:12:13 -0500426 if (buffer->input[0] == -1) {
427 ret = -ENODEV;
428 goto out;
429 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800430
431 if (power_supply_is_system_supplied() > 0)
Stuart Hayes116ee772010-02-10 14:12:13 -0500432 dell_send_request(buffer, 1, 2);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800433 else
Stuart Hayes116ee772010-02-10 14:12:13 -0500434 dell_send_request(buffer, 1, 1);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800435
Stuart Hayes116ee772010-02-10 14:12:13 -0500436out:
437 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800438 return 0;
439}
440
441static int dell_get_intensity(struct backlight_device *bd)
442{
Stuart Hayes116ee772010-02-10 14:12:13 -0500443 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800444
Stuart Hayes116ee772010-02-10 14:12:13 -0500445 get_buffer();
446 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800447
Stuart Hayes116ee772010-02-10 14:12:13 -0500448 if (buffer->input[0] == -1) {
449 ret = -ENODEV;
450 goto out;
451 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800452
453 if (power_supply_is_system_supplied() > 0)
Stuart Hayes116ee772010-02-10 14:12:13 -0500454 dell_send_request(buffer, 0, 2);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800455 else
Stuart Hayes116ee772010-02-10 14:12:13 -0500456 dell_send_request(buffer, 0, 1);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800457
Stuart Hayes116ee772010-02-10 14:12:13 -0500458out:
459 release_buffer();
460 if (ret)
461 return ret;
462 return buffer->output[1];
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800463}
464
465static struct backlight_ops dell_ops = {
466 .get_brightness = dell_get_intensity,
467 .update_status = dell_send_intensity,
468};
469
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000470bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
471 struct serio *port)
472{
473 static bool extended;
474
475 if (str & 0x20)
476 return false;
477
478 if (unlikely(data == 0xe0)) {
479 extended = true;
480 return false;
481 } else if (unlikely(extended)) {
482 switch (data) {
483 case 0x8:
484 schedule_delayed_work(&dell_rfkill_work,
485 round_jiffies_relative(HZ));
486 break;
487 }
488 extended = false;
489 }
490
491 return false;
492}
493
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800494static int __init dell_init(void)
495{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800496 int max_intensity = 0;
497 int ret;
498
499 if (!dmi_check_system(dell_device_table))
500 return -ENODEV;
501
Jean Delvaree7a19c562009-03-30 21:46:44 +0200502 dmi_walk(find_tokens, NULL);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800503
504 if (!da_tokens) {
505 printk(KERN_INFO "dell-laptop: Unable to find dmi tokens\n");
506 return -ENODEV;
507 }
508
Alan Jenkinsada32482009-08-19 15:06:49 +0100509 ret = platform_driver_register(&platform_driver);
510 if (ret)
511 goto fail_platform_driver;
512 platform_device = platform_device_alloc("dell-laptop", -1);
513 if (!platform_device) {
514 ret = -ENOMEM;
515 goto fail_platform_device1;
516 }
517 ret = platform_device_add(platform_device);
518 if (ret)
519 goto fail_platform_device2;
520
Stuart Hayes116ee772010-02-10 14:12:13 -0500521 /*
522 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
523 * is passed to SMI handler.
524 */
525 bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
526
527 if (!bufferpage)
528 goto fail_buffer;
529 buffer = page_address(bufferpage);
530 mutex_init(&buffer_mutex);
531
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800532 ret = dell_setup_rfkill();
533
534 if (ret) {
535 printk(KERN_WARNING "dell-laptop: Unable to setup rfkill\n");
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100536 goto fail_rfkill;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800537 }
538
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000539 ret = i8042_install_filter(dell_laptop_i8042_filter);
540 if (ret) {
541 printk(KERN_WARNING
542 "dell-laptop: Unable to install key filter\n");
543 goto fail_filter;
544 }
545
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800546#ifdef CONFIG_ACPI
547 /* In the event of an ACPI backlight being available, don't
548 * register the platform controller.
549 */
550 if (acpi_video_backlight_support())
551 return 0;
552#endif
553
Stuart Hayes116ee772010-02-10 14:12:13 -0500554 get_buffer();
555 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
556 if (buffer->input[0] != -1) {
557 dell_send_request(buffer, 0, 2);
558 max_intensity = buffer->output[3];
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800559 }
Stuart Hayes116ee772010-02-10 14:12:13 -0500560 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800561
562 if (max_intensity) {
Matthew Garretta19a6ee2010-02-17 16:39:44 -0500563 struct backlight_properties props;
564 memset(&props, 0, sizeof(struct backlight_properties));
565 props.max_brightness = max_intensity;
566 dell_backlight_device = backlight_device_register("dell_backlight",
567 &platform_device->dev,
568 NULL,
569 &dell_ops,
570 &props);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800571
572 if (IS_ERR(dell_backlight_device)) {
573 ret = PTR_ERR(dell_backlight_device);
574 dell_backlight_device = NULL;
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100575 goto fail_backlight;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800576 }
577
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800578 dell_backlight_device->props.brightness =
579 dell_get_intensity(dell_backlight_device);
580 backlight_update_status(dell_backlight_device);
581 }
582
583 return 0;
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100584
585fail_backlight:
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000586 i8042_remove_filter(dell_laptop_i8042_filter);
Matthew Garrett92e00e42010-03-01 09:46:43 -0500587 cancel_delayed_work_sync(&dell_rfkill_work);
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000588fail_filter:
Alan Jenkins4311bb22009-08-19 15:06:48 +0100589 dell_cleanup_rfkill();
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100590fail_rfkill:
Stuart Hayes116ee772010-02-10 14:12:13 -0500591 free_page((unsigned long)bufferpage);
592fail_buffer:
Alan Jenkinsada32482009-08-19 15:06:49 +0100593 platform_device_del(platform_device);
594fail_platform_device2:
595 platform_device_put(platform_device);
596fail_platform_device1:
597 platform_driver_unregister(&platform_driver);
598fail_platform_driver:
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800599 kfree(da_tokens);
600 return ret;
601}
602
603static void __exit dell_exit(void)
604{
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000605 i8042_remove_filter(dell_laptop_i8042_filter);
Matthew Garrett92e00e42010-03-01 09:46:43 -0500606 cancel_delayed_work_sync(&dell_rfkill_work);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800607 backlight_device_unregister(dell_backlight_device);
Alan Jenkins4311bb22009-08-19 15:06:48 +0100608 dell_cleanup_rfkill();
Matthew Garrettfacd61d2010-02-09 14:03:04 -0500609 if (platform_device) {
Matthew Garrett92e00e42010-03-01 09:46:43 -0500610 platform_device_unregister(platform_device);
Matthew Garrettfacd61d2010-02-09 14:03:04 -0500611 platform_driver_unregister(&platform_driver);
612 }
Matthew Garrette5512602010-02-09 14:05:01 -0500613 kfree(da_tokens);
Stuart Hayes116ee772010-02-10 14:12:13 -0500614 free_page((unsigned long)buffer);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800615}
616
617module_init(dell_init);
618module_exit(dell_exit);
619
620MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
621MODULE_DESCRIPTION("Dell laptop driver");
622MODULE_LICENSE("GPL");
623MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
Erik Andrencb6a7932010-02-14 11:53:23 -0500624MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");