Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 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 | |
| 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> |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 25 | #include <linux/i8042.h> |
Len Brown | cad7312 | 2009-01-09 17:23:38 -0500 | [diff] [blame] | 26 | #include "../../firmware/dcdbas.h" |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 27 | |
| 28 | #define BRIGHTNESS_TOKEN 0x7d |
| 29 | |
| 30 | /* This structure will be modified by the firmware when we enter |
| 31 | * system management mode, hence the volatiles */ |
| 32 | |
| 33 | struct calling_interface_buffer { |
| 34 | u16 class; |
| 35 | u16 select; |
| 36 | volatile u32 input[4]; |
| 37 | volatile u32 output[4]; |
| 38 | } __packed; |
| 39 | |
| 40 | struct calling_interface_token { |
| 41 | u16 tokenID; |
| 42 | u16 location; |
| 43 | union { |
| 44 | u16 value; |
| 45 | u16 stringlength; |
| 46 | }; |
| 47 | }; |
| 48 | |
| 49 | struct calling_interface_structure { |
| 50 | struct dmi_header header; |
| 51 | u16 cmdIOAddress; |
| 52 | u8 cmdIOCode; |
| 53 | u32 supportedCmds; |
| 54 | struct calling_interface_token tokens[]; |
| 55 | } __packed; |
| 56 | |
| 57 | static int da_command_address; |
| 58 | static int da_command_code; |
| 59 | static int da_num_tokens; |
| 60 | static struct calling_interface_token *da_tokens; |
| 61 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 62 | static struct platform_driver platform_driver = { |
| 63 | .driver = { |
| 64 | .name = "dell-laptop", |
| 65 | .owner = THIS_MODULE, |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | static struct platform_device *platform_device; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 70 | static struct backlight_device *dell_backlight_device; |
| 71 | static struct rfkill *wifi_rfkill; |
| 72 | static struct rfkill *bluetooth_rfkill; |
| 73 | static struct rfkill *wwan_rfkill; |
| 74 | |
| 75 | static const struct dmi_system_id __initdata dell_device_table[] = { |
| 76 | { |
| 77 | .ident = "Dell laptop", |
| 78 | .matches = { |
| 79 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 80 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 81 | }, |
| 82 | }, |
| 83 | { } |
| 84 | }; |
| 85 | |
Mario Limonciello | e5fefd0 | 2010-02-09 17:41:03 -0500 | [diff] [blame^] | 86 | static struct dmi_system_id __devinitdata dell_blacklist[] = { |
| 87 | /* Supported by compal-laptop */ |
| 88 | { |
| 89 | .ident = "Dell Mini 9", |
| 90 | .matches = { |
| 91 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 92 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"), |
| 93 | }, |
| 94 | }, |
| 95 | { |
| 96 | .ident = "Dell Mini 10", |
| 97 | .matches = { |
| 98 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 99 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"), |
| 100 | }, |
| 101 | }, |
| 102 | { |
| 103 | .ident = "Dell Mini 10v", |
| 104 | .matches = { |
| 105 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 106 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"), |
| 107 | }, |
| 108 | }, |
| 109 | { |
| 110 | .ident = "Dell Inspiron 11z", |
| 111 | .matches = { |
| 112 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 113 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"), |
| 114 | }, |
| 115 | }, |
| 116 | { |
| 117 | .ident = "Dell Mini 12", |
| 118 | .matches = { |
| 119 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 120 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"), |
| 121 | }, |
| 122 | }, |
| 123 | {} |
| 124 | }; |
| 125 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 126 | static void __init parse_da_table(const struct dmi_header *dm) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 127 | { |
| 128 | /* Final token is a terminator, so we don't want to copy it */ |
| 129 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; |
| 130 | struct calling_interface_structure *table = |
| 131 | container_of(dm, struct calling_interface_structure, header); |
| 132 | |
| 133 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least |
| 134 | 6 bytes of entry */ |
| 135 | |
| 136 | if (dm->length < 17) |
| 137 | return; |
| 138 | |
| 139 | da_command_address = table->cmdIOAddress; |
| 140 | da_command_code = table->cmdIOCode; |
| 141 | |
| 142 | da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * |
| 143 | sizeof(struct calling_interface_token), |
| 144 | GFP_KERNEL); |
| 145 | |
| 146 | if (!da_tokens) |
| 147 | return; |
| 148 | |
| 149 | memcpy(da_tokens+da_num_tokens, table->tokens, |
| 150 | sizeof(struct calling_interface_token) * tokens); |
| 151 | |
| 152 | da_num_tokens += tokens; |
| 153 | } |
| 154 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 155 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 156 | { |
| 157 | switch (dm->type) { |
| 158 | case 0xd4: /* Indexed IO */ |
| 159 | break; |
| 160 | case 0xd5: /* Protected Area Type 1 */ |
| 161 | break; |
| 162 | case 0xd6: /* Protected Area Type 2 */ |
| 163 | break; |
| 164 | case 0xda: /* Calling interface */ |
| 165 | parse_da_table(dm); |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | static int find_token_location(int tokenid) |
| 171 | { |
| 172 | int i; |
| 173 | for (i = 0; i < da_num_tokens; i++) { |
| 174 | if (da_tokens[i].tokenID == tokenid) |
| 175 | return da_tokens[i].location; |
| 176 | } |
| 177 | |
| 178 | return -1; |
| 179 | } |
| 180 | |
| 181 | static struct calling_interface_buffer * |
| 182 | dell_send_request(struct calling_interface_buffer *buffer, int class, |
| 183 | int select) |
| 184 | { |
| 185 | struct smi_cmd command; |
| 186 | |
| 187 | command.magic = SMI_CMD_MAGIC; |
| 188 | command.command_address = da_command_address; |
| 189 | command.command_code = da_command_code; |
| 190 | command.ebx = virt_to_phys(buffer); |
| 191 | command.ecx = 0x42534931; |
| 192 | |
| 193 | buffer->class = class; |
| 194 | buffer->select = select; |
| 195 | |
| 196 | dcdbas_smi_request(&command); |
| 197 | |
| 198 | return buffer; |
| 199 | } |
| 200 | |
| 201 | /* Derived from information in DellWirelessCtl.cpp: |
| 202 | Class 17, select 11 is radio control. It returns an array of 32-bit values. |
| 203 | |
| 204 | result[0]: return code |
| 205 | result[1]: |
| 206 | Bit 0: Hardware switch supported |
| 207 | Bit 1: Wifi locator supported |
| 208 | Bit 2: Wifi is supported |
| 209 | Bit 3: Bluetooth is supported |
| 210 | Bit 4: WWAN is supported |
| 211 | Bit 5: Wireless keyboard supported |
| 212 | Bits 6-7: Reserved |
| 213 | Bit 8: Wifi is installed |
| 214 | Bit 9: Bluetooth is installed |
| 215 | Bit 10: WWAN is installed |
| 216 | Bits 11-15: Reserved |
| 217 | Bit 16: Hardware switch is on |
| 218 | Bit 17: Wifi is blocked |
| 219 | Bit 18: Bluetooth is blocked |
| 220 | Bit 19: WWAN is blocked |
| 221 | Bits 20-31: Reserved |
| 222 | result[2]: NVRAM size in bytes |
| 223 | result[3]: NVRAM format version number |
| 224 | */ |
| 225 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 226 | static int dell_rfkill_set(void *data, bool blocked) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 227 | { |
| 228 | struct calling_interface_buffer buffer; |
Johannes Berg | 624f0de | 2009-06-15 16:26:47 +0200 | [diff] [blame] | 229 | int disable = blocked ? 1 : 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 230 | unsigned long radio = (unsigned long)data; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 231 | |
| 232 | memset(&buffer, 0, sizeof(struct calling_interface_buffer)); |
Mario Limonciello | ec1722a | 2010-02-09 14:11:05 -0500 | [diff] [blame] | 233 | dell_send_request(&buffer, 17, 11); |
| 234 | if (!(buffer.output[1] & BIT(16))) |
| 235 | return -EINVAL; |
| 236 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 237 | buffer.input[0] = (1 | (radio<<8) | (disable << 16)); |
| 238 | dell_send_request(&buffer, 17, 11); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 243 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 244 | { |
| 245 | struct calling_interface_buffer buffer; |
| 246 | int status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 247 | int bit = (unsigned long)data + 16; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 248 | |
| 249 | memset(&buffer, 0, sizeof(struct calling_interface_buffer)); |
| 250 | dell_send_request(&buffer, 17, 11); |
| 251 | status = buffer.output[1]; |
| 252 | |
Matthew Garrett | e1fbf34 | 2009-07-31 03:25:38 +0100 | [diff] [blame] | 253 | rfkill_set_sw_state(rfkill, !!(status & BIT(bit))); |
| 254 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 257 | static const struct rfkill_ops dell_rfkill_ops = { |
| 258 | .set_block = dell_rfkill_set, |
| 259 | .query = dell_rfkill_query, |
| 260 | }; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 261 | |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 262 | static void dell_update_rfkill(struct work_struct *ignored) |
| 263 | { |
| 264 | if (wifi_rfkill) |
| 265 | dell_rfkill_query(wifi_rfkill, (void *)1); |
| 266 | if (bluetooth_rfkill) |
| 267 | dell_rfkill_query(bluetooth_rfkill, (void *)2); |
| 268 | if (wwan_rfkill) |
| 269 | dell_rfkill_query(wwan_rfkill, (void *)3); |
| 270 | } |
| 271 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); |
| 272 | |
| 273 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 274 | static int __init dell_setup_rfkill(void) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 275 | { |
| 276 | struct calling_interface_buffer buffer; |
| 277 | int status; |
| 278 | int ret; |
| 279 | |
Mario Limonciello | e5fefd0 | 2010-02-09 17:41:03 -0500 | [diff] [blame^] | 280 | if (dmi_check_system(dell_blacklist)) { |
| 281 | printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - " |
| 282 | "not enabling rfkill\n"); |
| 283 | return 0; |
| 284 | } |
| 285 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 286 | memset(&buffer, 0, sizeof(struct calling_interface_buffer)); |
| 287 | dell_send_request(&buffer, 17, 11); |
| 288 | status = buffer.output[1]; |
| 289 | |
| 290 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 291 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, |
| 292 | RFKILL_TYPE_WLAN, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 293 | &dell_rfkill_ops, (void *) 1); |
| 294 | if (!wifi_rfkill) { |
| 295 | ret = -ENOMEM; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 296 | goto err_wifi; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 297 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 298 | ret = rfkill_register(wifi_rfkill); |
| 299 | if (ret) |
| 300 | goto err_wifi; |
| 301 | } |
| 302 | |
| 303 | if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 304 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", |
| 305 | &platform_device->dev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 306 | RFKILL_TYPE_BLUETOOTH, |
| 307 | &dell_rfkill_ops, (void *) 2); |
| 308 | if (!bluetooth_rfkill) { |
| 309 | ret = -ENOMEM; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 310 | goto err_bluetooth; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 311 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 312 | ret = rfkill_register(bluetooth_rfkill); |
| 313 | if (ret) |
| 314 | goto err_bluetooth; |
| 315 | } |
| 316 | |
| 317 | if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 318 | wwan_rfkill = rfkill_alloc("dell-wwan", |
| 319 | &platform_device->dev, |
| 320 | RFKILL_TYPE_WWAN, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 321 | &dell_rfkill_ops, (void *) 3); |
| 322 | if (!wwan_rfkill) { |
| 323 | ret = -ENOMEM; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 324 | goto err_wwan; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 325 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 326 | ret = rfkill_register(wwan_rfkill); |
| 327 | if (ret) |
| 328 | goto err_wwan; |
| 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | err_wwan: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 333 | rfkill_destroy(wwan_rfkill); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 334 | if (bluetooth_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 335 | rfkill_unregister(bluetooth_rfkill); |
| 336 | err_bluetooth: |
| 337 | rfkill_destroy(bluetooth_rfkill); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 338 | if (wifi_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 339 | rfkill_unregister(wifi_rfkill); |
| 340 | err_wifi: |
| 341 | rfkill_destroy(wifi_rfkill); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 342 | |
| 343 | return ret; |
| 344 | } |
| 345 | |
Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 346 | static void dell_cleanup_rfkill(void) |
| 347 | { |
| 348 | if (wifi_rfkill) { |
| 349 | rfkill_unregister(wifi_rfkill); |
| 350 | rfkill_destroy(wifi_rfkill); |
| 351 | } |
| 352 | if (bluetooth_rfkill) { |
| 353 | rfkill_unregister(bluetooth_rfkill); |
| 354 | rfkill_destroy(bluetooth_rfkill); |
| 355 | } |
| 356 | if (wwan_rfkill) { |
| 357 | rfkill_unregister(wwan_rfkill); |
| 358 | rfkill_destroy(wwan_rfkill); |
| 359 | } |
| 360 | } |
| 361 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 362 | static int dell_send_intensity(struct backlight_device *bd) |
| 363 | { |
| 364 | struct calling_interface_buffer buffer; |
| 365 | |
| 366 | memset(&buffer, 0, sizeof(struct calling_interface_buffer)); |
| 367 | buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 368 | buffer.input[1] = bd->props.brightness; |
| 369 | |
| 370 | if (buffer.input[0] == -1) |
| 371 | return -ENODEV; |
| 372 | |
| 373 | if (power_supply_is_system_supplied() > 0) |
| 374 | dell_send_request(&buffer, 1, 2); |
| 375 | else |
| 376 | dell_send_request(&buffer, 1, 1); |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static int dell_get_intensity(struct backlight_device *bd) |
| 382 | { |
| 383 | struct calling_interface_buffer buffer; |
| 384 | |
| 385 | memset(&buffer, 0, sizeof(struct calling_interface_buffer)); |
| 386 | buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 387 | |
| 388 | if (buffer.input[0] == -1) |
| 389 | return -ENODEV; |
| 390 | |
| 391 | if (power_supply_is_system_supplied() > 0) |
| 392 | dell_send_request(&buffer, 0, 2); |
| 393 | else |
| 394 | dell_send_request(&buffer, 0, 1); |
| 395 | |
| 396 | return buffer.output[1]; |
| 397 | } |
| 398 | |
| 399 | static struct backlight_ops dell_ops = { |
| 400 | .get_brightness = dell_get_intensity, |
| 401 | .update_status = dell_send_intensity, |
| 402 | }; |
| 403 | |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 404 | bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, |
| 405 | struct serio *port) |
| 406 | { |
| 407 | static bool extended; |
| 408 | |
| 409 | if (str & 0x20) |
| 410 | return false; |
| 411 | |
| 412 | if (unlikely(data == 0xe0)) { |
| 413 | extended = true; |
| 414 | return false; |
| 415 | } else if (unlikely(extended)) { |
| 416 | switch (data) { |
| 417 | case 0x8: |
| 418 | schedule_delayed_work(&dell_rfkill_work, |
| 419 | round_jiffies_relative(HZ)); |
| 420 | break; |
| 421 | } |
| 422 | extended = false; |
| 423 | } |
| 424 | |
| 425 | return false; |
| 426 | } |
| 427 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 428 | static int __init dell_init(void) |
| 429 | { |
| 430 | struct calling_interface_buffer buffer; |
| 431 | int max_intensity = 0; |
| 432 | int ret; |
| 433 | |
| 434 | if (!dmi_check_system(dell_device_table)) |
| 435 | return -ENODEV; |
| 436 | |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 437 | dmi_walk(find_tokens, NULL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 438 | |
| 439 | if (!da_tokens) { |
| 440 | printk(KERN_INFO "dell-laptop: Unable to find dmi tokens\n"); |
| 441 | return -ENODEV; |
| 442 | } |
| 443 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 444 | ret = platform_driver_register(&platform_driver); |
| 445 | if (ret) |
| 446 | goto fail_platform_driver; |
| 447 | platform_device = platform_device_alloc("dell-laptop", -1); |
| 448 | if (!platform_device) { |
| 449 | ret = -ENOMEM; |
| 450 | goto fail_platform_device1; |
| 451 | } |
| 452 | ret = platform_device_add(platform_device); |
| 453 | if (ret) |
| 454 | goto fail_platform_device2; |
| 455 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 456 | ret = dell_setup_rfkill(); |
| 457 | |
| 458 | if (ret) { |
| 459 | printk(KERN_WARNING "dell-laptop: Unable to setup rfkill\n"); |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 460 | goto fail_rfkill; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 463 | ret = i8042_install_filter(dell_laptop_i8042_filter); |
| 464 | if (ret) { |
| 465 | printk(KERN_WARNING |
| 466 | "dell-laptop: Unable to install key filter\n"); |
| 467 | goto fail_filter; |
| 468 | } |
| 469 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 470 | #ifdef CONFIG_ACPI |
| 471 | /* In the event of an ACPI backlight being available, don't |
| 472 | * register the platform controller. |
| 473 | */ |
| 474 | if (acpi_video_backlight_support()) |
| 475 | return 0; |
| 476 | #endif |
| 477 | |
| 478 | memset(&buffer, 0, sizeof(struct calling_interface_buffer)); |
| 479 | buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 480 | |
| 481 | if (buffer.input[0] != -1) { |
| 482 | dell_send_request(&buffer, 0, 2); |
| 483 | max_intensity = buffer.output[3]; |
| 484 | } |
| 485 | |
| 486 | if (max_intensity) { |
| 487 | dell_backlight_device = backlight_device_register( |
| 488 | "dell_backlight", |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 489 | &platform_device->dev, NULL, |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 490 | &dell_ops); |
| 491 | |
| 492 | if (IS_ERR(dell_backlight_device)) { |
| 493 | ret = PTR_ERR(dell_backlight_device); |
| 494 | dell_backlight_device = NULL; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 495 | goto fail_backlight; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | dell_backlight_device->props.max_brightness = max_intensity; |
| 499 | dell_backlight_device->props.brightness = |
| 500 | dell_get_intensity(dell_backlight_device); |
| 501 | backlight_update_status(dell_backlight_device); |
| 502 | } |
| 503 | |
| 504 | return 0; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 505 | |
| 506 | fail_backlight: |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 507 | i8042_remove_filter(dell_laptop_i8042_filter); |
| 508 | fail_filter: |
Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 509 | dell_cleanup_rfkill(); |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 510 | fail_rfkill: |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 511 | platform_device_del(platform_device); |
| 512 | fail_platform_device2: |
| 513 | platform_device_put(platform_device); |
| 514 | fail_platform_device1: |
| 515 | platform_driver_unregister(&platform_driver); |
| 516 | fail_platform_driver: |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 517 | kfree(da_tokens); |
| 518 | return ret; |
| 519 | } |
| 520 | |
| 521 | static void __exit dell_exit(void) |
| 522 | { |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 523 | cancel_delayed_work_sync(&dell_rfkill_work); |
| 524 | i8042_remove_filter(dell_laptop_i8042_filter); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 525 | backlight_device_unregister(dell_backlight_device); |
Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 526 | dell_cleanup_rfkill(); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 527 | if (platform_device) { |
| 528 | platform_device_del(platform_device); |
| 529 | platform_driver_unregister(&platform_driver); |
| 530 | } |
Matthew Garrett | e551260 | 2010-02-09 14:05:01 -0500 | [diff] [blame] | 531 | kfree(da_tokens); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | module_init(dell_init); |
| 535 | module_exit(dell_exit); |
| 536 | |
| 537 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
| 538 | MODULE_DESCRIPTION("Dell laptop driver"); |
| 539 | MODULE_LICENSE("GPL"); |
| 540 | MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*"); |