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