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