blob: 04b2ddbe63d28ba6f4d9baffd7c0a3de39ac063f [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>
Len Browncad73122009-01-09 17:23:38 -050027#include "../../firmware/dcdbas.h"
Matthew Garrettad8f07c2009-01-07 18:08:56 -080028
29#define BRIGHTNESS_TOKEN 0x7d
30
31/* This structure will be modified by the firmware when we enter
32 * system management mode, hence the volatiles */
33
34struct calling_interface_buffer {
35 u16 class;
36 u16 select;
37 volatile u32 input[4];
38 volatile u32 output[4];
39} __packed;
40
41struct calling_interface_token {
42 u16 tokenID;
43 u16 location;
44 union {
45 u16 value;
46 u16 stringlength;
47 };
48};
49
50struct calling_interface_structure {
51 struct dmi_header header;
52 u16 cmdIOAddress;
53 u8 cmdIOCode;
54 u32 supportedCmds;
55 struct calling_interface_token tokens[];
56} __packed;
57
58static int da_command_address;
59static int da_command_code;
60static int da_num_tokens;
61static struct calling_interface_token *da_tokens;
62
Alan Jenkinsada32482009-08-19 15:06:49 +010063static struct platform_driver platform_driver = {
64 .driver = {
65 .name = "dell-laptop",
66 .owner = THIS_MODULE,
67 }
68};
69
70static struct platform_device *platform_device;
Matthew Garrettad8f07c2009-01-07 18:08:56 -080071static struct backlight_device *dell_backlight_device;
72static struct rfkill *wifi_rfkill;
73static struct rfkill *bluetooth_rfkill;
74static struct rfkill *wwan_rfkill;
75
76static const struct dmi_system_id __initdata dell_device_table[] = {
77 {
78 .ident = "Dell laptop",
79 .matches = {
80 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
81 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
82 },
83 },
84 { }
85};
86
Mario Limoncielloe5fefd02010-02-09 17:41:03 -050087static struct dmi_system_id __devinitdata dell_blacklist[] = {
88 /* Supported by compal-laptop */
89 {
90 .ident = "Dell Mini 9",
91 .matches = {
92 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
93 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
94 },
95 },
96 {
97 .ident = "Dell Mini 10",
98 .matches = {
99 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
100 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
101 },
102 },
103 {
104 .ident = "Dell Mini 10v",
105 .matches = {
106 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
107 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
108 },
109 },
110 {
111 .ident = "Dell Inspiron 11z",
112 .matches = {
113 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
114 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
115 },
116 },
117 {
118 .ident = "Dell Mini 12",
119 .matches = {
120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
121 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
122 },
123 },
124 {}
125};
126
Stuart Hayes116ee772010-02-10 14:12:13 -0500127static struct calling_interface_buffer *buffer;
128struct page *bufferpage;
129DEFINE_MUTEX(buffer_mutex);
130
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500131static int hwswitch_state;
132
Stuart Hayes116ee772010-02-10 14:12:13 -0500133static void get_buffer(void)
134{
135 mutex_lock(&buffer_mutex);
136 memset(buffer, 0, sizeof(struct calling_interface_buffer));
137}
138
139static void release_buffer(void)
140{
141 mutex_unlock(&buffer_mutex);
142}
143
Alan Jenkins4788df42009-08-19 15:06:50 +0100144static void __init parse_da_table(const struct dmi_header *dm)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800145{
146 /* Final token is a terminator, so we don't want to copy it */
147 int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
148 struct calling_interface_structure *table =
149 container_of(dm, struct calling_interface_structure, header);
150
151 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
152 6 bytes of entry */
153
154 if (dm->length < 17)
155 return;
156
157 da_command_address = table->cmdIOAddress;
158 da_command_code = table->cmdIOCode;
159
160 da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
161 sizeof(struct calling_interface_token),
162 GFP_KERNEL);
163
164 if (!da_tokens)
165 return;
166
167 memcpy(da_tokens+da_num_tokens, table->tokens,
168 sizeof(struct calling_interface_token) * tokens);
169
170 da_num_tokens += tokens;
171}
172
Alan Jenkins4788df42009-08-19 15:06:50 +0100173static void __init find_tokens(const struct dmi_header *dm, void *dummy)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800174{
175 switch (dm->type) {
176 case 0xd4: /* Indexed IO */
177 break;
178 case 0xd5: /* Protected Area Type 1 */
179 break;
180 case 0xd6: /* Protected Area Type 2 */
181 break;
182 case 0xda: /* Calling interface */
183 parse_da_table(dm);
184 break;
185 }
186}
187
188static int find_token_location(int tokenid)
189{
190 int i;
191 for (i = 0; i < da_num_tokens; i++) {
192 if (da_tokens[i].tokenID == tokenid)
193 return da_tokens[i].location;
194 }
195
196 return -1;
197}
198
199static struct calling_interface_buffer *
200dell_send_request(struct calling_interface_buffer *buffer, int class,
201 int select)
202{
203 struct smi_cmd command;
204
205 command.magic = SMI_CMD_MAGIC;
206 command.command_address = da_command_address;
207 command.command_code = da_command_code;
208 command.ebx = virt_to_phys(buffer);
209 command.ecx = 0x42534931;
210
211 buffer->class = class;
212 buffer->select = select;
213
214 dcdbas_smi_request(&command);
215
216 return buffer;
217}
218
219/* Derived from information in DellWirelessCtl.cpp:
220 Class 17, select 11 is radio control. It returns an array of 32-bit values.
221
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500222 Input byte 0 = 0: Wireless information
223
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800224 result[0]: return code
225 result[1]:
226 Bit 0: Hardware switch supported
227 Bit 1: Wifi locator supported
228 Bit 2: Wifi is supported
229 Bit 3: Bluetooth is supported
230 Bit 4: WWAN is supported
231 Bit 5: Wireless keyboard supported
232 Bits 6-7: Reserved
233 Bit 8: Wifi is installed
234 Bit 9: Bluetooth is installed
235 Bit 10: WWAN is installed
236 Bits 11-15: Reserved
237 Bit 16: Hardware switch is on
238 Bit 17: Wifi is blocked
239 Bit 18: Bluetooth is blocked
240 Bit 19: WWAN is blocked
241 Bits 20-31: Reserved
242 result[2]: NVRAM size in bytes
243 result[3]: NVRAM format version number
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500244
245 Input byte 0 = 2: Wireless switch configuration
246 result[0]: return code
247 result[1]:
248 Bit 0: Wifi controlled by switch
249 Bit 1: Bluetooth controlled by switch
250 Bit 2: WWAN controlled by switch
251 Bits 3-6: Reserved
252 Bit 7: Wireless switch config locked
253 Bit 8: Wifi locator enabled
254 Bits 9-14: Reserved
255 Bit 15: Wifi locator setting locked
256 Bits 16-31: Reserved
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800257*/
258
Johannes Berg19d337d2009-06-02 13:01:37 +0200259static int dell_rfkill_set(void *data, bool blocked)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800260{
Johannes Berg624f0de2009-06-15 16:26:47 +0200261 int disable = blocked ? 1 : 0;
Johannes Berg19d337d2009-06-02 13:01:37 +0200262 unsigned long radio = (unsigned long)data;
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500263 int hwswitch_bit = (unsigned long)data - 1;
Stuart Hayes116ee772010-02-10 14:12:13 -0500264 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800265
Stuart Hayes116ee772010-02-10 14:12:13 -0500266 get_buffer();
267 dell_send_request(buffer, 17, 11);
Mario Limoncielloec1722a22010-02-09 14:11:05 -0500268
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500269 /* If the hardware switch controls this radio, and the hardware
270 switch is disabled, don't allow changing the software state */
271 if ((hwswitch_state & BIT(hwswitch_bit)) &&
272 !(buffer->output[1] & BIT(16))) {
Stuart Hayes116ee772010-02-10 14:12:13 -0500273 ret = -EINVAL;
274 goto out;
275 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800276
Stuart Hayes116ee772010-02-10 14:12:13 -0500277 buffer->input[0] = (1 | (radio<<8) | (disable << 16));
278 dell_send_request(buffer, 17, 11);
279
280out:
281 release_buffer();
282 return ret;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800283}
284
Johannes Berg19d337d2009-06-02 13:01:37 +0200285static void dell_rfkill_query(struct rfkill *rfkill, void *data)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800286{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800287 int status;
Johannes Berg19d337d2009-06-02 13:01:37 +0200288 int bit = (unsigned long)data + 16;
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500289 int hwswitch_bit = (unsigned long)data - 1;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800290
Stuart Hayes116ee772010-02-10 14:12:13 -0500291 get_buffer();
292 dell_send_request(buffer, 17, 11);
293 status = buffer->output[1];
294 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800295
Matthew Garrette1fbf342009-07-31 03:25:38 +0100296 rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500297
298 if (hwswitch_state & (BIT(hwswitch_bit)))
299 rfkill_set_hw_state(rfkill, !(status & BIT(16)));
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800300}
301
Johannes Berg19d337d2009-06-02 13:01:37 +0200302static const struct rfkill_ops dell_rfkill_ops = {
303 .set_block = dell_rfkill_set,
304 .query = dell_rfkill_query,
305};
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800306
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000307static void dell_update_rfkill(struct work_struct *ignored)
308{
309 if (wifi_rfkill)
310 dell_rfkill_query(wifi_rfkill, (void *)1);
311 if (bluetooth_rfkill)
312 dell_rfkill_query(bluetooth_rfkill, (void *)2);
313 if (wwan_rfkill)
314 dell_rfkill_query(wwan_rfkill, (void *)3);
315}
316static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
317
318
Alan Jenkins4788df42009-08-19 15:06:50 +0100319static int __init dell_setup_rfkill(void)
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800320{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800321 int status;
322 int ret;
323
Mario Limoncielloe5fefd02010-02-09 17:41:03 -0500324 if (dmi_check_system(dell_blacklist)) {
325 printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - "
326 "not enabling rfkill\n");
327 return 0;
328 }
329
Stuart Hayes116ee772010-02-10 14:12:13 -0500330 get_buffer();
331 dell_send_request(buffer, 17, 11);
332 status = buffer->output[1];
Matthew Garrettc6760ac2010-02-10 14:44:03 -0500333 buffer->input[0] = 0x2;
334 dell_send_request(buffer, 17, 11);
335 hwswitch_state = buffer->output[1];
Stuart Hayes116ee772010-02-10 14:12:13 -0500336 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800337
338 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100339 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
340 RFKILL_TYPE_WLAN,
Johannes Berg19d337d2009-06-02 13:01:37 +0200341 &dell_rfkill_ops, (void *) 1);
342 if (!wifi_rfkill) {
343 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800344 goto err_wifi;
Johannes Berg19d337d2009-06-02 13:01:37 +0200345 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800346 ret = rfkill_register(wifi_rfkill);
347 if (ret)
348 goto err_wifi;
349 }
350
351 if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100352 bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
353 &platform_device->dev,
Johannes Berg19d337d2009-06-02 13:01:37 +0200354 RFKILL_TYPE_BLUETOOTH,
355 &dell_rfkill_ops, (void *) 2);
356 if (!bluetooth_rfkill) {
357 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800358 goto err_bluetooth;
Johannes Berg19d337d2009-06-02 13:01:37 +0200359 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800360 ret = rfkill_register(bluetooth_rfkill);
361 if (ret)
362 goto err_bluetooth;
363 }
364
365 if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
Alan Jenkinsada32482009-08-19 15:06:49 +0100366 wwan_rfkill = rfkill_alloc("dell-wwan",
367 &platform_device->dev,
368 RFKILL_TYPE_WWAN,
Johannes Berg19d337d2009-06-02 13:01:37 +0200369 &dell_rfkill_ops, (void *) 3);
370 if (!wwan_rfkill) {
371 ret = -ENOMEM;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800372 goto err_wwan;
Johannes Berg19d337d2009-06-02 13:01:37 +0200373 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800374 ret = rfkill_register(wwan_rfkill);
375 if (ret)
376 goto err_wwan;
377 }
378
379 return 0;
380err_wwan:
Johannes Berg19d337d2009-06-02 13:01:37 +0200381 rfkill_destroy(wwan_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800382 if (bluetooth_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200383 rfkill_unregister(bluetooth_rfkill);
384err_bluetooth:
385 rfkill_destroy(bluetooth_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800386 if (wifi_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200387 rfkill_unregister(wifi_rfkill);
388err_wifi:
389 rfkill_destroy(wifi_rfkill);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800390
391 return ret;
392}
393
Alan Jenkins4311bb22009-08-19 15:06:48 +0100394static void dell_cleanup_rfkill(void)
395{
396 if (wifi_rfkill) {
397 rfkill_unregister(wifi_rfkill);
398 rfkill_destroy(wifi_rfkill);
399 }
400 if (bluetooth_rfkill) {
401 rfkill_unregister(bluetooth_rfkill);
402 rfkill_destroy(bluetooth_rfkill);
403 }
404 if (wwan_rfkill) {
405 rfkill_unregister(wwan_rfkill);
406 rfkill_destroy(wwan_rfkill);
407 }
408}
409
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800410static int dell_send_intensity(struct backlight_device *bd)
411{
Stuart Hayes116ee772010-02-10 14:12:13 -0500412 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800413
Stuart Hayes116ee772010-02-10 14:12:13 -0500414 get_buffer();
415 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
416 buffer->input[1] = bd->props.brightness;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800417
Stuart Hayes116ee772010-02-10 14:12:13 -0500418 if (buffer->input[0] == -1) {
419 ret = -ENODEV;
420 goto out;
421 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800422
423 if (power_supply_is_system_supplied() > 0)
Stuart Hayes116ee772010-02-10 14:12:13 -0500424 dell_send_request(buffer, 1, 2);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800425 else
Stuart Hayes116ee772010-02-10 14:12:13 -0500426 dell_send_request(buffer, 1, 1);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800427
Stuart Hayes116ee772010-02-10 14:12:13 -0500428out:
429 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800430 return 0;
431}
432
433static int dell_get_intensity(struct backlight_device *bd)
434{
Stuart Hayes116ee772010-02-10 14:12:13 -0500435 int ret = 0;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800436
Stuart Hayes116ee772010-02-10 14:12:13 -0500437 get_buffer();
438 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800439
Stuart Hayes116ee772010-02-10 14:12:13 -0500440 if (buffer->input[0] == -1) {
441 ret = -ENODEV;
442 goto out;
443 }
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800444
445 if (power_supply_is_system_supplied() > 0)
Stuart Hayes116ee772010-02-10 14:12:13 -0500446 dell_send_request(buffer, 0, 2);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800447 else
Stuart Hayes116ee772010-02-10 14:12:13 -0500448 dell_send_request(buffer, 0, 1);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800449
Stuart Hayes116ee772010-02-10 14:12:13 -0500450out:
451 release_buffer();
452 if (ret)
453 return ret;
454 return buffer->output[1];
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800455}
456
457static struct backlight_ops dell_ops = {
458 .get_brightness = dell_get_intensity,
459 .update_status = dell_send_intensity,
460};
461
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000462bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
463 struct serio *port)
464{
465 static bool extended;
466
467 if (str & 0x20)
468 return false;
469
470 if (unlikely(data == 0xe0)) {
471 extended = true;
472 return false;
473 } else if (unlikely(extended)) {
474 switch (data) {
475 case 0x8:
476 schedule_delayed_work(&dell_rfkill_work,
477 round_jiffies_relative(HZ));
478 break;
479 }
480 extended = false;
481 }
482
483 return false;
484}
485
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800486static int __init dell_init(void)
487{
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800488 int max_intensity = 0;
489 int ret;
490
491 if (!dmi_check_system(dell_device_table))
492 return -ENODEV;
493
Jean Delvaree7a19c52009-03-30 21:46:44 +0200494 dmi_walk(find_tokens, NULL);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800495
496 if (!da_tokens) {
497 printk(KERN_INFO "dell-laptop: Unable to find dmi tokens\n");
498 return -ENODEV;
499 }
500
Alan Jenkinsada32482009-08-19 15:06:49 +0100501 ret = platform_driver_register(&platform_driver);
502 if (ret)
503 goto fail_platform_driver;
504 platform_device = platform_device_alloc("dell-laptop", -1);
505 if (!platform_device) {
506 ret = -ENOMEM;
507 goto fail_platform_device1;
508 }
509 ret = platform_device_add(platform_device);
510 if (ret)
511 goto fail_platform_device2;
512
Stuart Hayes116ee772010-02-10 14:12:13 -0500513 /*
514 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
515 * is passed to SMI handler.
516 */
517 bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
518
519 if (!bufferpage)
520 goto fail_buffer;
521 buffer = page_address(bufferpage);
522 mutex_init(&buffer_mutex);
523
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800524 ret = dell_setup_rfkill();
525
526 if (ret) {
527 printk(KERN_WARNING "dell-laptop: Unable to setup rfkill\n");
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100528 goto fail_rfkill;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800529 }
530
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000531 ret = i8042_install_filter(dell_laptop_i8042_filter);
532 if (ret) {
533 printk(KERN_WARNING
534 "dell-laptop: Unable to install key filter\n");
535 goto fail_filter;
536 }
537
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800538#ifdef CONFIG_ACPI
539 /* In the event of an ACPI backlight being available, don't
540 * register the platform controller.
541 */
542 if (acpi_video_backlight_support())
543 return 0;
544#endif
545
Stuart Hayes116ee772010-02-10 14:12:13 -0500546 get_buffer();
547 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
548 if (buffer->input[0] != -1) {
549 dell_send_request(buffer, 0, 2);
550 max_intensity = buffer->output[3];
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800551 }
Stuart Hayes116ee772010-02-10 14:12:13 -0500552 release_buffer();
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800553
554 if (max_intensity) {
555 dell_backlight_device = backlight_device_register(
556 "dell_backlight",
Alan Jenkinsada32482009-08-19 15:06:49 +0100557 &platform_device->dev, NULL,
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800558 &dell_ops);
559
560 if (IS_ERR(dell_backlight_device)) {
561 ret = PTR_ERR(dell_backlight_device);
562 dell_backlight_device = NULL;
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100563 goto fail_backlight;
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800564 }
565
566 dell_backlight_device->props.max_brightness = max_intensity;
567 dell_backlight_device->props.brightness =
568 dell_get_intensity(dell_backlight_device);
569 backlight_update_status(dell_backlight_device);
570 }
571
572 return 0;
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100573
574fail_backlight:
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000575 i8042_remove_filter(dell_laptop_i8042_filter);
576fail_filter:
Alan Jenkins4311bb22009-08-19 15:06:48 +0100577 dell_cleanup_rfkill();
Alan Jenkins71e9dc72009-08-19 15:06:47 +0100578fail_rfkill:
Stuart Hayes116ee772010-02-10 14:12:13 -0500579 free_page((unsigned long)bufferpage);
580fail_buffer:
Alan Jenkinsada32482009-08-19 15:06:49 +0100581 platform_device_del(platform_device);
582fail_platform_device2:
583 platform_device_put(platform_device);
584fail_platform_device1:
585 platform_driver_unregister(&platform_driver);
586fail_platform_driver:
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800587 kfree(da_tokens);
588 return ret;
589}
590
591static void __exit dell_exit(void)
592{
Matthew Garrett814cb8a2009-12-09 18:23:36 +0000593 cancel_delayed_work_sync(&dell_rfkill_work);
594 i8042_remove_filter(dell_laptop_i8042_filter);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800595 backlight_device_unregister(dell_backlight_device);
Alan Jenkins4311bb22009-08-19 15:06:48 +0100596 dell_cleanup_rfkill();
Matthew Garrettfacd61d2010-02-09 14:03:04 -0500597 if (platform_device) {
598 platform_device_del(platform_device);
599 platform_driver_unregister(&platform_driver);
600 }
Matthew Garrette5512602010-02-09 14:05:01 -0500601 kfree(da_tokens);
Stuart Hayes116ee772010-02-10 14:12:13 -0500602 free_page((unsigned long)buffer);
Matthew Garrettad8f07c2009-01-07 18:08:56 -0800603}
604
605module_init(dell_init);
606module_exit(dell_exit);
607
608MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
609MODULE_DESCRIPTION("Dell laptop driver");
610MODULE_LICENSE("GPL");
611MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");