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