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> |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 25 | #include <linux/mm.h> |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 26 | #include <linux/i8042.h> |
Len Brown | cad7312 | 2009-01-09 17:23:38 -0500 | [diff] [blame] | 27 | #include "../../firmware/dcdbas.h" |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 28 | |
| 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 | |
| 34 | struct calling_interface_buffer { |
| 35 | u16 class; |
| 36 | u16 select; |
| 37 | volatile u32 input[4]; |
| 38 | volatile u32 output[4]; |
| 39 | } __packed; |
| 40 | |
| 41 | struct calling_interface_token { |
| 42 | u16 tokenID; |
| 43 | u16 location; |
| 44 | union { |
| 45 | u16 value; |
| 46 | u16 stringlength; |
| 47 | }; |
| 48 | }; |
| 49 | |
| 50 | struct 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 | |
| 58 | static int da_command_address; |
| 59 | static int da_command_code; |
| 60 | static int da_num_tokens; |
| 61 | static struct calling_interface_token *da_tokens; |
| 62 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 63 | static struct platform_driver platform_driver = { |
| 64 | .driver = { |
| 65 | .name = "dell-laptop", |
| 66 | .owner = THIS_MODULE, |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | static struct platform_device *platform_device; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 71 | static struct backlight_device *dell_backlight_device; |
| 72 | static struct rfkill *wifi_rfkill; |
| 73 | static struct rfkill *bluetooth_rfkill; |
| 74 | static struct rfkill *wwan_rfkill; |
| 75 | |
| 76 | static 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 Limonciello | e5fefd0 | 2010-02-09 17:41:03 -0500 | [diff] [blame] | 87 | static 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 Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 127 | static struct calling_interface_buffer *buffer; |
| 128 | struct page *bufferpage; |
| 129 | DEFINE_MUTEX(buffer_mutex); |
| 130 | |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 131 | static int hwswitch_state; |
| 132 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 133 | static void get_buffer(void) |
| 134 | { |
| 135 | mutex_lock(&buffer_mutex); |
| 136 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); |
| 137 | } |
| 138 | |
| 139 | static void release_buffer(void) |
| 140 | { |
| 141 | mutex_unlock(&buffer_mutex); |
| 142 | } |
| 143 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 144 | static void __init parse_da_table(const struct dmi_header *dm) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 145 | { |
| 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 Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 173 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 174 | { |
| 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 | |
| 188 | static 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 | |
| 199 | static struct calling_interface_buffer * |
| 200 | dell_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 Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 222 | Input byte 0 = 0: Wireless information |
| 223 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 224 | 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 Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 244 | |
| 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 Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 257 | */ |
| 258 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 259 | static int dell_rfkill_set(void *data, bool blocked) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 260 | { |
Johannes Berg | 624f0de | 2009-06-15 16:26:47 +0200 | [diff] [blame] | 261 | int disable = blocked ? 1 : 0; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 262 | unsigned long radio = (unsigned long)data; |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 263 | int hwswitch_bit = (unsigned long)data - 1; |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 264 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 265 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 266 | get_buffer(); |
| 267 | dell_send_request(buffer, 17, 11); |
Mario Limonciello | ec1722a2 | 2010-02-09 14:11:05 -0500 | [diff] [blame] | 268 | |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 269 | /* 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 Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 273 | ret = -EINVAL; |
| 274 | goto out; |
| 275 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 276 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 277 | buffer->input[0] = (1 | (radio<<8) | (disable << 16)); |
| 278 | dell_send_request(buffer, 17, 11); |
| 279 | |
| 280 | out: |
| 281 | release_buffer(); |
| 282 | return ret; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 285 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 286 | { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 287 | int status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 288 | int bit = (unsigned long)data + 16; |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 289 | int hwswitch_bit = (unsigned long)data - 1; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 290 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 291 | get_buffer(); |
| 292 | dell_send_request(buffer, 17, 11); |
| 293 | status = buffer->output[1]; |
| 294 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 295 | |
Matthew Garrett | e1fbf34 | 2009-07-31 03:25:38 +0100 | [diff] [blame] | 296 | rfkill_set_sw_state(rfkill, !!(status & BIT(bit))); |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 297 | |
| 298 | if (hwswitch_state & (BIT(hwswitch_bit))) |
| 299 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 302 | static const struct rfkill_ops dell_rfkill_ops = { |
| 303 | .set_block = dell_rfkill_set, |
| 304 | .query = dell_rfkill_query, |
| 305 | }; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 306 | |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 307 | static 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 | } |
| 316 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); |
| 317 | |
| 318 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 319 | static int __init dell_setup_rfkill(void) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 320 | { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 321 | int status; |
| 322 | int ret; |
| 323 | |
Mario Limonciello | e5fefd0 | 2010-02-09 17:41:03 -0500 | [diff] [blame] | 324 | 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 Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 330 | get_buffer(); |
| 331 | dell_send_request(buffer, 17, 11); |
| 332 | status = buffer->output[1]; |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame^] | 333 | buffer->input[0] = 0x2; |
| 334 | dell_send_request(buffer, 17, 11); |
| 335 | hwswitch_state = buffer->output[1]; |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 336 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 337 | |
| 338 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 339 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, |
| 340 | RFKILL_TYPE_WLAN, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 341 | &dell_rfkill_ops, (void *) 1); |
| 342 | if (!wifi_rfkill) { |
| 343 | ret = -ENOMEM; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 344 | goto err_wifi; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 345 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 346 | 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 Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 352 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", |
| 353 | &platform_device->dev, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 354 | RFKILL_TYPE_BLUETOOTH, |
| 355 | &dell_rfkill_ops, (void *) 2); |
| 356 | if (!bluetooth_rfkill) { |
| 357 | ret = -ENOMEM; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 358 | goto err_bluetooth; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 359 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 360 | 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 Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 366 | wwan_rfkill = rfkill_alloc("dell-wwan", |
| 367 | &platform_device->dev, |
| 368 | RFKILL_TYPE_WWAN, |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 369 | &dell_rfkill_ops, (void *) 3); |
| 370 | if (!wwan_rfkill) { |
| 371 | ret = -ENOMEM; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 372 | goto err_wwan; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 373 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 374 | ret = rfkill_register(wwan_rfkill); |
| 375 | if (ret) |
| 376 | goto err_wwan; |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | err_wwan: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 381 | rfkill_destroy(wwan_rfkill); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 382 | if (bluetooth_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 383 | rfkill_unregister(bluetooth_rfkill); |
| 384 | err_bluetooth: |
| 385 | rfkill_destroy(bluetooth_rfkill); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 386 | if (wifi_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 387 | rfkill_unregister(wifi_rfkill); |
| 388 | err_wifi: |
| 389 | rfkill_destroy(wifi_rfkill); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 390 | |
| 391 | return ret; |
| 392 | } |
| 393 | |
Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 394 | static 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 Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 410 | static int dell_send_intensity(struct backlight_device *bd) |
| 411 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 412 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 413 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 414 | get_buffer(); |
| 415 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 416 | buffer->input[1] = bd->props.brightness; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 417 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 418 | if (buffer->input[0] == -1) { |
| 419 | ret = -ENODEV; |
| 420 | goto out; |
| 421 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 422 | |
| 423 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 424 | dell_send_request(buffer, 1, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 425 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 426 | dell_send_request(buffer, 1, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 427 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 428 | out: |
| 429 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static int dell_get_intensity(struct backlight_device *bd) |
| 434 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 435 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 436 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 437 | get_buffer(); |
| 438 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 439 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 440 | if (buffer->input[0] == -1) { |
| 441 | ret = -ENODEV; |
| 442 | goto out; |
| 443 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 444 | |
| 445 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 446 | dell_send_request(buffer, 0, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 447 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 448 | dell_send_request(buffer, 0, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 449 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 450 | out: |
| 451 | release_buffer(); |
| 452 | if (ret) |
| 453 | return ret; |
| 454 | return buffer->output[1]; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static struct backlight_ops dell_ops = { |
| 458 | .get_brightness = dell_get_intensity, |
| 459 | .update_status = dell_send_intensity, |
| 460 | }; |
| 461 | |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 462 | bool 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 Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 486 | static int __init dell_init(void) |
| 487 | { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 488 | int max_intensity = 0; |
| 489 | int ret; |
| 490 | |
| 491 | if (!dmi_check_system(dell_device_table)) |
| 492 | return -ENODEV; |
| 493 | |
Jean Delvare | e7a19c5 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 494 | dmi_walk(find_tokens, NULL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 495 | |
| 496 | if (!da_tokens) { |
| 497 | printk(KERN_INFO "dell-laptop: Unable to find dmi tokens\n"); |
| 498 | return -ENODEV; |
| 499 | } |
| 500 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 501 | 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 Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 513 | /* |
| 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 Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 524 | ret = dell_setup_rfkill(); |
| 525 | |
| 526 | if (ret) { |
| 527 | printk(KERN_WARNING "dell-laptop: Unable to setup rfkill\n"); |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 528 | goto fail_rfkill; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 529 | } |
| 530 | |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 531 | 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 Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 538 | #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 Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 546 | 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 Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 551 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 552 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 553 | |
| 554 | if (max_intensity) { |
| 555 | dell_backlight_device = backlight_device_register( |
| 556 | "dell_backlight", |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 557 | &platform_device->dev, NULL, |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 558 | &dell_ops); |
| 559 | |
| 560 | if (IS_ERR(dell_backlight_device)) { |
| 561 | ret = PTR_ERR(dell_backlight_device); |
| 562 | dell_backlight_device = NULL; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 563 | goto fail_backlight; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 564 | } |
| 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 Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 573 | |
| 574 | fail_backlight: |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 575 | i8042_remove_filter(dell_laptop_i8042_filter); |
| 576 | fail_filter: |
Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 577 | dell_cleanup_rfkill(); |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 578 | fail_rfkill: |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 579 | free_page((unsigned long)bufferpage); |
| 580 | fail_buffer: |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 581 | platform_device_del(platform_device); |
| 582 | fail_platform_device2: |
| 583 | platform_device_put(platform_device); |
| 584 | fail_platform_device1: |
| 585 | platform_driver_unregister(&platform_driver); |
| 586 | fail_platform_driver: |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 587 | kfree(da_tokens); |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | static void __exit dell_exit(void) |
| 592 | { |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 593 | cancel_delayed_work_sync(&dell_rfkill_work); |
| 594 | i8042_remove_filter(dell_laptop_i8042_filter); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 595 | backlight_device_unregister(dell_backlight_device); |
Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 596 | dell_cleanup_rfkill(); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 597 | if (platform_device) { |
| 598 | platform_device_del(platform_device); |
| 599 | platform_driver_unregister(&platform_driver); |
| 600 | } |
Matthew Garrett | e551260 | 2010-02-09 14:05:01 -0500 | [diff] [blame] | 601 | kfree(da_tokens); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 602 | free_page((unsigned long)buffer); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | module_init(dell_init); |
| 606 | module_exit(dell_exit); |
| 607 | |
| 608 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
| 609 | MODULE_DESCRIPTION("Dell laptop driver"); |
| 610 | MODULE_LICENSE("GPL"); |
| 611 | MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*"); |