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