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