1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Acer WMI Laptop Extras 4 * 5 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk> 6 * 7 * Based on acer_acpi: 8 * Copyright (C) 2005-2007 E.M. Smith 9 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com> 10 */ 11 12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 14 #include <linux/kernel.h> 15 #include <linux/module.h> 16 #include <linux/init.h> 17 #include <linux/types.h> 18 #include <linux/dmi.h> 19 #include <linux/fb.h> 20 #include <linux/backlight.h> 21 #include <linux/leds.h> 22 #include <linux/platform_device.h> 23 #include <linux/acpi.h> 24 #include <linux/i8042.h> 25 #include <linux/rfkill.h> 26 #include <linux/workqueue.h> 27 #include <linux/debugfs.h> 28 #include <linux/slab.h> 29 #include <linux/input.h> 30 #include <linux/input/sparse-keymap.h> 31 #include <acpi/video.h> 32 33 MODULE_AUTHOR("Carlos Corbacho"); 34 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); 35 MODULE_LICENSE("GPL"); 36 37 /* 38 * Magic Number 39 * Meaning is unknown - this number is required for writing to ACPI for AMW0 40 * (it's also used in acerhk when directly accessing the BIOS) 41 */ 42 #define ACER_AMW0_WRITE 0x9610 43 44 /* 45 * Bit masks for the AMW0 interface 46 */ 47 #define ACER_AMW0_WIRELESS_MASK 0x35 48 #define ACER_AMW0_BLUETOOTH_MASK 0x34 49 #define ACER_AMW0_MAILLED_MASK 0x31 50 51 /* 52 * Method IDs for WMID interface 53 */ 54 #define ACER_WMID_GET_WIRELESS_METHODID 1 55 #define ACER_WMID_GET_BLUETOOTH_METHODID 2 56 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3 57 #define ACER_WMID_SET_WIRELESS_METHODID 4 58 #define ACER_WMID_SET_BLUETOOTH_METHODID 5 59 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6 60 #define ACER_WMID_GET_THREEG_METHODID 10 61 #define ACER_WMID_SET_THREEG_METHODID 11 62 63 /* 64 * Acer ACPI method GUIDs 65 */ 66 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" 67 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C" 68 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3" 69 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A" 70 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531" 71 72 /* 73 * Acer ACPI event GUIDs 74 */ 75 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026" 76 77 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB"); 78 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"); 79 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026"); 80 81 enum acer_wmi_event_ids { 82 WMID_HOTKEY_EVENT = 0x1, 83 WMID_ACCEL_OR_KBD_DOCK_EVENT = 0x5, 84 }; 85 86 static const struct key_entry acer_wmi_keymap[] __initconst = { 87 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */ 88 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */ 89 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */ 90 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */ 91 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */ 92 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */ 93 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */ 94 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */ 95 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */ 96 {KE_IGNORE, 0x41, {KEY_MUTE} }, 97 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} }, 98 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} }, 99 {KE_IGNORE, 0x43, {KEY_NEXTSONG} }, 100 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} }, 101 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} }, 102 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} }, 103 {KE_IGNORE, 0x45, {KEY_STOP} }, 104 {KE_IGNORE, 0x50, {KEY_STOP} }, 105 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} }, 106 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} }, 107 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} }, 108 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} }, 109 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} }, 110 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} }, 111 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */ 112 {KE_IGNORE, 0x81, {KEY_SLEEP} }, 113 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */ 114 {KE_IGNORE, 0x84, {KEY_KBDILLUMTOGGLE} }, /* Automatic Keyboard background light toggle */ 115 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} }, 116 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} }, 117 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} }, 118 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} }, 119 {KE_KEY, 0x86, {KEY_WLAN} }, 120 {KE_KEY, 0x87, {KEY_POWER} }, 121 {KE_END, 0} 122 }; 123 124 static struct input_dev *acer_wmi_input_dev; 125 static struct input_dev *acer_wmi_accel_dev; 126 127 struct event_return_value { 128 u8 function; 129 u8 key_num; 130 u16 device_state; 131 u16 reserved1; 132 u8 kbd_dock_state; 133 u8 reserved2; 134 } __attribute__((packed)); 135 136 /* 137 * GUID3 Get Device Status device flags 138 */ 139 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */ 140 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */ 141 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */ 142 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */ 143 #define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */ 144 145 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */ 146 147 /* Hotkey Customized Setting and Acer Application Status. 148 * Set Device Default Value and Report Acer Application Status. 149 * When Acer Application starts, it will run this method to inform 150 * BIOS/EC that Acer Application is on. 151 * App Status 152 * Bit[0]: Launch Manager Status 153 * Bit[1]: ePM Status 154 * Bit[2]: Device Control Status 155 * Bit[3]: Acer Power Button Utility Status 156 * Bit[4]: RF Button Status 157 * Bit[5]: ODD PM Status 158 * Bit[6]: Device Default Value Control 159 * Bit[7]: Hall Sensor Application Status 160 */ 161 struct func_input_params { 162 u8 function_num; /* Function Number */ 163 u16 commun_devices; /* Communication type devices default status */ 164 u16 devices; /* Other type devices default status */ 165 u8 app_status; /* Acer Device Status. LM, ePM, RF Button... */ 166 u8 app_mask; /* Bit mask to app_status */ 167 u8 reserved; 168 } __attribute__((packed)); 169 170 struct func_return_value { 171 u8 error_code; /* Error Code */ 172 u8 ec_return_value; /* EC Return Value */ 173 u16 reserved; 174 } __attribute__((packed)); 175 176 struct wmid3_gds_set_input_param { /* Set Device Status input parameter */ 177 u8 function_num; /* Function Number */ 178 u8 hotkey_number; /* Hotkey Number */ 179 u16 devices; /* Set Device */ 180 u8 volume_value; /* Volume Value */ 181 } __attribute__((packed)); 182 183 struct wmid3_gds_get_input_param { /* Get Device Status input parameter */ 184 u8 function_num; /* Function Number */ 185 u8 hotkey_number; /* Hotkey Number */ 186 u16 devices; /* Get Device */ 187 } __attribute__((packed)); 188 189 struct wmid3_gds_return_value { /* Get Device Status return value*/ 190 u8 error_code; /* Error Code */ 191 u8 ec_return_value; /* EC Return Value */ 192 u16 devices; /* Current Device Status */ 193 u32 reserved; 194 } __attribute__((packed)); 195 196 struct hotkey_function_type_aa { 197 u8 type; 198 u8 length; 199 u16 handle; 200 u16 commun_func_bitmap; 201 u16 application_func_bitmap; 202 u16 media_func_bitmap; 203 u16 display_func_bitmap; 204 u16 others_func_bitmap; 205 u8 commun_fn_key_number; 206 } __attribute__((packed)); 207 208 /* 209 * Interface capability flags 210 */ 211 #define ACER_CAP_MAILLED BIT(0) 212 #define ACER_CAP_WIRELESS BIT(1) 213 #define ACER_CAP_BLUETOOTH BIT(2) 214 #define ACER_CAP_BRIGHTNESS BIT(3) 215 #define ACER_CAP_THREEG BIT(4) 216 #define ACER_CAP_SET_FUNCTION_MODE BIT(5) 217 #define ACER_CAP_KBD_DOCK BIT(6) 218 219 /* 220 * Interface type flags 221 */ 222 enum interface_flags { 223 ACER_AMW0, 224 ACER_AMW0_V2, 225 ACER_WMID, 226 ACER_WMID_v2, 227 }; 228 229 #define ACER_DEFAULT_WIRELESS 0 230 #define ACER_DEFAULT_BLUETOOTH 0 231 #define ACER_DEFAULT_MAILLED 0 232 #define ACER_DEFAULT_THREEG 0 233 234 static int max_brightness = 0xF; 235 236 static int mailled = -1; 237 static int brightness = -1; 238 static int threeg = -1; 239 static int force_series; 240 static int force_caps = -1; 241 static bool ec_raw_mode; 242 static bool has_type_aa; 243 static u16 commun_func_bitmap; 244 static u8 commun_fn_key_number; 245 246 module_param(mailled, int, 0444); 247 module_param(brightness, int, 0444); 248 module_param(threeg, int, 0444); 249 module_param(force_series, int, 0444); 250 module_param(force_caps, int, 0444); 251 module_param(ec_raw_mode, bool, 0444); 252 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED"); 253 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness"); 254 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware"); 255 MODULE_PARM_DESC(force_series, "Force a different laptop series"); 256 MODULE_PARM_DESC(force_caps, "Force the capability bitmask to this value"); 257 MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode"); 258 259 struct acer_data { 260 int mailled; 261 int threeg; 262 int brightness; 263 }; 264 265 struct acer_debug { 266 struct dentry *root; 267 u32 wmid_devices; 268 }; 269 270 static struct rfkill *wireless_rfkill; 271 static struct rfkill *bluetooth_rfkill; 272 static struct rfkill *threeg_rfkill; 273 static bool rfkill_inited; 274 275 /* Each low-level interface must define at least some of the following */ 276 struct wmi_interface { 277 /* The WMI device type */ 278 u32 type; 279 280 /* The capabilities this interface provides */ 281 u32 capability; 282 283 /* Private data for the current interface */ 284 struct acer_data data; 285 286 /* debugfs entries associated with this interface */ 287 struct acer_debug debug; 288 }; 289 290 /* The static interface pointer, points to the currently detected interface */ 291 static struct wmi_interface *interface; 292 293 /* 294 * Embedded Controller quirks 295 * Some laptops require us to directly access the EC to either enable or query 296 * features that are not available through WMI. 297 */ 298 299 struct quirk_entry { 300 u8 wireless; 301 u8 mailled; 302 s8 brightness; 303 u8 bluetooth; 304 }; 305 306 static struct quirk_entry *quirks; 307 308 static void __init set_quirks(void) 309 { 310 if (quirks->mailled) 311 interface->capability |= ACER_CAP_MAILLED; 312 313 if (quirks->brightness) 314 interface->capability |= ACER_CAP_BRIGHTNESS; 315 } 316 317 static int __init dmi_matched(const struct dmi_system_id *dmi) 318 { 319 quirks = dmi->driver_data; 320 return 1; 321 } 322 323 static int __init set_force_caps(const struct dmi_system_id *dmi) 324 { 325 if (force_caps == -1) { 326 force_caps = (uintptr_t)dmi->driver_data; 327 pr_info("Found %s, set force_caps to 0x%x\n", dmi->ident, force_caps); 328 } 329 return 1; 330 } 331 332 static struct quirk_entry quirk_unknown = { 333 }; 334 335 static struct quirk_entry quirk_acer_aspire_1520 = { 336 .brightness = -1, 337 }; 338 339 static struct quirk_entry quirk_acer_travelmate_2490 = { 340 .mailled = 1, 341 }; 342 343 /* This AMW0 laptop has no bluetooth */ 344 static struct quirk_entry quirk_medion_md_98300 = { 345 .wireless = 1, 346 }; 347 348 static struct quirk_entry quirk_fujitsu_amilo_li_1718 = { 349 .wireless = 2, 350 }; 351 352 static struct quirk_entry quirk_lenovo_ideapad_s205 = { 353 .wireless = 3, 354 }; 355 356 /* The Aspire One has a dummy ACPI-WMI interface - disable it */ 357 static const struct dmi_system_id acer_blacklist[] __initconst = { 358 { 359 .ident = "Acer Aspire One (SSD)", 360 .matches = { 361 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 362 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"), 363 }, 364 }, 365 { 366 .ident = "Acer Aspire One (HDD)", 367 .matches = { 368 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 369 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"), 370 }, 371 }, 372 {} 373 }; 374 375 static const struct dmi_system_id amw0_whitelist[] __initconst = { 376 { 377 .ident = "Acer", 378 .matches = { 379 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 380 }, 381 }, 382 { 383 .ident = "Gateway", 384 .matches = { 385 DMI_MATCH(DMI_SYS_VENDOR, "Gateway"), 386 }, 387 }, 388 { 389 .ident = "Packard Bell", 390 .matches = { 391 DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"), 392 }, 393 }, 394 {} 395 }; 396 397 /* 398 * This quirk table is only for Acer/Gateway/Packard Bell family 399 * that those machines are supported by acer-wmi driver. 400 */ 401 static const struct dmi_system_id acer_quirks[] __initconst = { 402 { 403 .callback = dmi_matched, 404 .ident = "Acer Aspire 1360", 405 .matches = { 406 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 407 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"), 408 }, 409 .driver_data = &quirk_acer_aspire_1520, 410 }, 411 { 412 .callback = dmi_matched, 413 .ident = "Acer Aspire 1520", 414 .matches = { 415 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 416 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"), 417 }, 418 .driver_data = &quirk_acer_aspire_1520, 419 }, 420 { 421 .callback = dmi_matched, 422 .ident = "Acer Aspire 3100", 423 .matches = { 424 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 425 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"), 426 }, 427 .driver_data = &quirk_acer_travelmate_2490, 428 }, 429 { 430 .callback = dmi_matched, 431 .ident = "Acer Aspire 3610", 432 .matches = { 433 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 434 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"), 435 }, 436 .driver_data = &quirk_acer_travelmate_2490, 437 }, 438 { 439 .callback = dmi_matched, 440 .ident = "Acer Aspire 5100", 441 .matches = { 442 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 443 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"), 444 }, 445 .driver_data = &quirk_acer_travelmate_2490, 446 }, 447 { 448 .callback = dmi_matched, 449 .ident = "Acer Aspire 5610", 450 .matches = { 451 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 452 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"), 453 }, 454 .driver_data = &quirk_acer_travelmate_2490, 455 }, 456 { 457 .callback = dmi_matched, 458 .ident = "Acer Aspire 5630", 459 .matches = { 460 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 461 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"), 462 }, 463 .driver_data = &quirk_acer_travelmate_2490, 464 }, 465 { 466 .callback = dmi_matched, 467 .ident = "Acer Aspire 5650", 468 .matches = { 469 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 470 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"), 471 }, 472 .driver_data = &quirk_acer_travelmate_2490, 473 }, 474 { 475 .callback = dmi_matched, 476 .ident = "Acer Aspire 5680", 477 .matches = { 478 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 479 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"), 480 }, 481 .driver_data = &quirk_acer_travelmate_2490, 482 }, 483 { 484 .callback = dmi_matched, 485 .ident = "Acer Aspire 9110", 486 .matches = { 487 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 488 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"), 489 }, 490 .driver_data = &quirk_acer_travelmate_2490, 491 }, 492 { 493 .callback = dmi_matched, 494 .ident = "Acer TravelMate 2490", 495 .matches = { 496 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 497 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"), 498 }, 499 .driver_data = &quirk_acer_travelmate_2490, 500 }, 501 { 502 .callback = dmi_matched, 503 .ident = "Acer TravelMate 4200", 504 .matches = { 505 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 506 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"), 507 }, 508 .driver_data = &quirk_acer_travelmate_2490, 509 }, 510 { 511 .callback = set_force_caps, 512 .ident = "Acer Aspire Switch 10E SW3-016", 513 .matches = { 514 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 515 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW3-016"), 516 }, 517 .driver_data = (void *)ACER_CAP_KBD_DOCK, 518 }, 519 { 520 .callback = set_force_caps, 521 .ident = "Acer Aspire Switch 10 SW5-012", 522 .matches = { 523 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 524 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"), 525 }, 526 .driver_data = (void *)ACER_CAP_KBD_DOCK, 527 }, 528 { 529 .callback = set_force_caps, 530 .ident = "Acer One 10 (S1003)", 531 .matches = { 532 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"), 533 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "One S1003"), 534 }, 535 .driver_data = (void *)ACER_CAP_KBD_DOCK, 536 }, 537 {} 538 }; 539 540 /* 541 * This quirk list is for those non-acer machines that have AMW0_GUID1 542 * but supported by acer-wmi in past days. Keeping this quirk list here 543 * is only for backward compatible. Please do not add new machine to 544 * here anymore. Those non-acer machines should be supported by 545 * appropriate wmi drivers. 546 */ 547 static const struct dmi_system_id non_acer_quirks[] __initconst = { 548 { 549 .callback = dmi_matched, 550 .ident = "Fujitsu Siemens Amilo Li 1718", 551 .matches = { 552 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), 553 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"), 554 }, 555 .driver_data = &quirk_fujitsu_amilo_li_1718, 556 }, 557 { 558 .callback = dmi_matched, 559 .ident = "Medion MD 98300", 560 .matches = { 561 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), 562 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"), 563 }, 564 .driver_data = &quirk_medion_md_98300, 565 }, 566 { 567 .callback = dmi_matched, 568 .ident = "Lenovo Ideapad S205", 569 .matches = { 570 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 571 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"), 572 }, 573 .driver_data = &quirk_lenovo_ideapad_s205, 574 }, 575 { 576 .callback = dmi_matched, 577 .ident = "Lenovo Ideapad S205 (Brazos)", 578 .matches = { 579 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 580 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"), 581 }, 582 .driver_data = &quirk_lenovo_ideapad_s205, 583 }, 584 { 585 .callback = dmi_matched, 586 .ident = "Lenovo 3000 N200", 587 .matches = { 588 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 589 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"), 590 }, 591 .driver_data = &quirk_fujitsu_amilo_li_1718, 592 }, 593 { 594 .callback = dmi_matched, 595 .ident = "Lenovo Ideapad S205-10382JG", 596 .matches = { 597 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 598 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"), 599 }, 600 .driver_data = &quirk_lenovo_ideapad_s205, 601 }, 602 { 603 .callback = dmi_matched, 604 .ident = "Lenovo Ideapad S205-1038DPG", 605 .matches = { 606 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 607 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"), 608 }, 609 .driver_data = &quirk_lenovo_ideapad_s205, 610 }, 611 {} 612 }; 613 614 static int __init 615 video_set_backlight_video_vendor(const struct dmi_system_id *d) 616 { 617 interface->capability &= ~ACER_CAP_BRIGHTNESS; 618 pr_info("Brightness must be controlled by generic video driver\n"); 619 return 0; 620 } 621 622 static const struct dmi_system_id video_vendor_dmi_table[] __initconst = { 623 { 624 .callback = video_set_backlight_video_vendor, 625 .ident = "Acer TravelMate 4750", 626 .matches = { 627 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), 628 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"), 629 }, 630 }, 631 { 632 .callback = video_set_backlight_video_vendor, 633 .ident = "Acer Extensa 5235", 634 .matches = { 635 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), 636 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"), 637 }, 638 }, 639 { 640 .callback = video_set_backlight_video_vendor, 641 .ident = "Acer TravelMate 5760", 642 .matches = { 643 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), 644 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"), 645 }, 646 }, 647 { 648 .callback = video_set_backlight_video_vendor, 649 .ident = "Acer Aspire 5750", 650 .matches = { 651 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), 652 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"), 653 }, 654 }, 655 { 656 .callback = video_set_backlight_video_vendor, 657 .ident = "Acer Aspire 5741", 658 .matches = { 659 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), 660 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"), 661 }, 662 }, 663 { 664 /* 665 * Note no video_set_backlight_video_vendor, we must use the 666 * acer interface, as there is no native backlight interface. 667 */ 668 .ident = "Acer KAV80", 669 .matches = { 670 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 671 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"), 672 }, 673 }, 674 {} 675 }; 676 677 /* Find which quirks are needed for a particular vendor/ model pair */ 678 static void __init find_quirks(void) 679 { 680 if (!force_series) { 681 dmi_check_system(acer_quirks); 682 dmi_check_system(non_acer_quirks); 683 } else if (force_series == 2490) { 684 quirks = &quirk_acer_travelmate_2490; 685 } 686 687 if (quirks == NULL) 688 quirks = &quirk_unknown; 689 } 690 691 /* 692 * General interface convenience methods 693 */ 694 695 static bool has_cap(u32 cap) 696 { 697 return interface->capability & cap; 698 } 699 700 /* 701 * AMW0 (V1) interface 702 */ 703 struct wmab_args { 704 u32 eax; 705 u32 ebx; 706 u32 ecx; 707 u32 edx; 708 }; 709 710 struct wmab_ret { 711 u32 eax; 712 u32 ebx; 713 u32 ecx; 714 u32 edx; 715 u32 eex; 716 }; 717 718 static acpi_status wmab_execute(struct wmab_args *regbuf, 719 struct acpi_buffer *result) 720 { 721 struct acpi_buffer input; 722 acpi_status status; 723 input.length = sizeof(struct wmab_args); 724 input.pointer = (u8 *)regbuf; 725 726 status = wmi_evaluate_method(AMW0_GUID1, 0, 1, &input, result); 727 728 return status; 729 } 730 731 static acpi_status AMW0_get_u32(u32 *value, u32 cap) 732 { 733 int err; 734 u8 result; 735 736 switch (cap) { 737 case ACER_CAP_MAILLED: 738 switch (quirks->mailled) { 739 default: 740 err = ec_read(0xA, &result); 741 if (err) 742 return AE_ERROR; 743 *value = (result >> 7) & 0x1; 744 return AE_OK; 745 } 746 break; 747 case ACER_CAP_WIRELESS: 748 switch (quirks->wireless) { 749 case 1: 750 err = ec_read(0x7B, &result); 751 if (err) 752 return AE_ERROR; 753 *value = result & 0x1; 754 return AE_OK; 755 case 2: 756 err = ec_read(0x71, &result); 757 if (err) 758 return AE_ERROR; 759 *value = result & 0x1; 760 return AE_OK; 761 case 3: 762 err = ec_read(0x78, &result); 763 if (err) 764 return AE_ERROR; 765 *value = result & 0x1; 766 return AE_OK; 767 default: 768 err = ec_read(0xA, &result); 769 if (err) 770 return AE_ERROR; 771 *value = (result >> 2) & 0x1; 772 return AE_OK; 773 } 774 break; 775 case ACER_CAP_BLUETOOTH: 776 switch (quirks->bluetooth) { 777 default: 778 err = ec_read(0xA, &result); 779 if (err) 780 return AE_ERROR; 781 *value = (result >> 4) & 0x1; 782 return AE_OK; 783 } 784 break; 785 case ACER_CAP_BRIGHTNESS: 786 switch (quirks->brightness) { 787 default: 788 err = ec_read(0x83, &result); 789 if (err) 790 return AE_ERROR; 791 *value = result; 792 return AE_OK; 793 } 794 break; 795 default: 796 return AE_ERROR; 797 } 798 return AE_OK; 799 } 800 801 static acpi_status AMW0_set_u32(u32 value, u32 cap) 802 { 803 struct wmab_args args; 804 805 args.eax = ACER_AMW0_WRITE; 806 args.ebx = value ? (1<<8) : 0; 807 args.ecx = args.edx = 0; 808 809 switch (cap) { 810 case ACER_CAP_MAILLED: 811 if (value > 1) 812 return AE_BAD_PARAMETER; 813 args.ebx |= ACER_AMW0_MAILLED_MASK; 814 break; 815 case ACER_CAP_WIRELESS: 816 if (value > 1) 817 return AE_BAD_PARAMETER; 818 args.ebx |= ACER_AMW0_WIRELESS_MASK; 819 break; 820 case ACER_CAP_BLUETOOTH: 821 if (value > 1) 822 return AE_BAD_PARAMETER; 823 args.ebx |= ACER_AMW0_BLUETOOTH_MASK; 824 break; 825 case ACER_CAP_BRIGHTNESS: 826 if (value > max_brightness) 827 return AE_BAD_PARAMETER; 828 switch (quirks->brightness) { 829 default: 830 return ec_write(0x83, value); 831 } 832 default: 833 return AE_ERROR; 834 } 835 836 /* Actually do the set */ 837 return wmab_execute(&args, NULL); 838 } 839 840 static acpi_status __init AMW0_find_mailled(void) 841 { 842 struct wmab_args args; 843 struct wmab_ret ret; 844 acpi_status status = AE_OK; 845 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; 846 union acpi_object *obj; 847 848 args.eax = 0x86; 849 args.ebx = args.ecx = args.edx = 0; 850 851 status = wmab_execute(&args, &out); 852 if (ACPI_FAILURE(status)) 853 return status; 854 855 obj = (union acpi_object *) out.pointer; 856 if (obj && obj->type == ACPI_TYPE_BUFFER && 857 obj->buffer.length == sizeof(struct wmab_ret)) { 858 ret = *((struct wmab_ret *) obj->buffer.pointer); 859 } else { 860 kfree(out.pointer); 861 return AE_ERROR; 862 } 863 864 if (ret.eex & 0x1) 865 interface->capability |= ACER_CAP_MAILLED; 866 867 kfree(out.pointer); 868 869 return AE_OK; 870 } 871 872 static const struct acpi_device_id norfkill_ids[] __initconst = { 873 { "VPC2004", 0}, 874 { "IBM0068", 0}, 875 { "LEN0068", 0}, 876 { "SNY5001", 0}, /* sony-laptop in charge */ 877 { "HPQ6601", 0}, 878 { "", 0}, 879 }; 880 881 static int __init AMW0_set_cap_acpi_check_device(void) 882 { 883 const struct acpi_device_id *id; 884 885 for (id = norfkill_ids; id->id[0]; id++) 886 if (acpi_dev_found(id->id)) 887 return true; 888 889 return false; 890 } 891 892 static acpi_status __init AMW0_set_capabilities(void) 893 { 894 struct wmab_args args; 895 struct wmab_ret ret; 896 acpi_status status; 897 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; 898 union acpi_object *obj; 899 900 /* 901 * On laptops with this strange GUID (non Acer), normal probing doesn't 902 * work. 903 */ 904 if (wmi_has_guid(AMW0_GUID2)) { 905 if ((quirks != &quirk_unknown) || 906 !AMW0_set_cap_acpi_check_device()) 907 interface->capability |= ACER_CAP_WIRELESS; 908 return AE_OK; 909 } 910 911 args.eax = ACER_AMW0_WRITE; 912 args.ecx = args.edx = 0; 913 914 args.ebx = 0xa2 << 8; 915 args.ebx |= ACER_AMW0_WIRELESS_MASK; 916 917 status = wmab_execute(&args, &out); 918 if (ACPI_FAILURE(status)) 919 return status; 920 921 obj = out.pointer; 922 if (obj && obj->type == ACPI_TYPE_BUFFER && 923 obj->buffer.length == sizeof(struct wmab_ret)) { 924 ret = *((struct wmab_ret *) obj->buffer.pointer); 925 } else { 926 status = AE_ERROR; 927 goto out; 928 } 929 930 if (ret.eax & 0x1) 931 interface->capability |= ACER_CAP_WIRELESS; 932 933 args.ebx = 2 << 8; 934 args.ebx |= ACER_AMW0_BLUETOOTH_MASK; 935 936 /* 937 * It's ok to use existing buffer for next wmab_execute call. 938 * But we need to kfree(out.pointer) if next wmab_execute fail. 939 */ 940 status = wmab_execute(&args, &out); 941 if (ACPI_FAILURE(status)) 942 goto out; 943 944 obj = (union acpi_object *) out.pointer; 945 if (obj && obj->type == ACPI_TYPE_BUFFER 946 && obj->buffer.length == sizeof(struct wmab_ret)) { 947 ret = *((struct wmab_ret *) obj->buffer.pointer); 948 } else { 949 status = AE_ERROR; 950 goto out; 951 } 952 953 if (ret.eax & 0x1) 954 interface->capability |= ACER_CAP_BLUETOOTH; 955 956 /* 957 * This appears to be safe to enable, since all Wistron based laptops 958 * appear to use the same EC register for brightness, even if they 959 * differ for wireless, etc 960 */ 961 if (quirks->brightness >= 0) 962 interface->capability |= ACER_CAP_BRIGHTNESS; 963 964 status = AE_OK; 965 out: 966 kfree(out.pointer); 967 return status; 968 } 969 970 static struct wmi_interface AMW0_interface = { 971 .type = ACER_AMW0, 972 }; 973 974 static struct wmi_interface AMW0_V2_interface = { 975 .type = ACER_AMW0_V2, 976 }; 977 978 /* 979 * New interface (The WMID interface) 980 */ 981 static acpi_status 982 WMI_execute_u32(u32 method_id, u32 in, u32 *out) 983 { 984 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) }; 985 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL }; 986 union acpi_object *obj; 987 u32 tmp = 0; 988 acpi_status status; 989 990 status = wmi_evaluate_method(WMID_GUID1, 0, method_id, &input, &result); 991 992 if (ACPI_FAILURE(status)) 993 return status; 994 995 obj = (union acpi_object *) result.pointer; 996 if (obj) { 997 if (obj->type == ACPI_TYPE_BUFFER && 998 (obj->buffer.length == sizeof(u32) || 999 obj->buffer.length == sizeof(u64))) { 1000 tmp = *((u32 *) obj->buffer.pointer); 1001 } else if (obj->type == ACPI_TYPE_INTEGER) { 1002 tmp = (u32) obj->integer.value; 1003 } 1004 } 1005 1006 if (out) 1007 *out = tmp; 1008 1009 kfree(result.pointer); 1010 1011 return status; 1012 } 1013 1014 static acpi_status WMID_get_u32(u32 *value, u32 cap) 1015 { 1016 acpi_status status; 1017 u8 tmp; 1018 u32 result, method_id = 0; 1019 1020 switch (cap) { 1021 case ACER_CAP_WIRELESS: 1022 method_id = ACER_WMID_GET_WIRELESS_METHODID; 1023 break; 1024 case ACER_CAP_BLUETOOTH: 1025 method_id = ACER_WMID_GET_BLUETOOTH_METHODID; 1026 break; 1027 case ACER_CAP_BRIGHTNESS: 1028 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID; 1029 break; 1030 case ACER_CAP_THREEG: 1031 method_id = ACER_WMID_GET_THREEG_METHODID; 1032 break; 1033 case ACER_CAP_MAILLED: 1034 if (quirks->mailled == 1) { 1035 ec_read(0x9f, &tmp); 1036 *value = tmp & 0x1; 1037 return 0; 1038 } 1039 fallthrough; 1040 default: 1041 return AE_ERROR; 1042 } 1043 status = WMI_execute_u32(method_id, 0, &result); 1044 1045 if (ACPI_SUCCESS(status)) 1046 *value = (u8)result; 1047 1048 return status; 1049 } 1050 1051 static acpi_status WMID_set_u32(u32 value, u32 cap) 1052 { 1053 u32 method_id = 0; 1054 char param; 1055 1056 switch (cap) { 1057 case ACER_CAP_BRIGHTNESS: 1058 if (value > max_brightness) 1059 return AE_BAD_PARAMETER; 1060 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID; 1061 break; 1062 case ACER_CAP_WIRELESS: 1063 if (value > 1) 1064 return AE_BAD_PARAMETER; 1065 method_id = ACER_WMID_SET_WIRELESS_METHODID; 1066 break; 1067 case ACER_CAP_BLUETOOTH: 1068 if (value > 1) 1069 return AE_BAD_PARAMETER; 1070 method_id = ACER_WMID_SET_BLUETOOTH_METHODID; 1071 break; 1072 case ACER_CAP_THREEG: 1073 if (value > 1) 1074 return AE_BAD_PARAMETER; 1075 method_id = ACER_WMID_SET_THREEG_METHODID; 1076 break; 1077 case ACER_CAP_MAILLED: 1078 if (value > 1) 1079 return AE_BAD_PARAMETER; 1080 if (quirks->mailled == 1) { 1081 param = value ? 0x92 : 0x93; 1082 i8042_lock_chip(); 1083 i8042_command(¶m, 0x1059); 1084 i8042_unlock_chip(); 1085 return 0; 1086 } 1087 break; 1088 default: 1089 return AE_ERROR; 1090 } 1091 return WMI_execute_u32(method_id, (u32)value, NULL); 1092 } 1093 1094 static acpi_status wmid3_get_device_status(u32 *value, u16 device) 1095 { 1096 struct wmid3_gds_return_value return_value; 1097 acpi_status status; 1098 union acpi_object *obj; 1099 struct wmid3_gds_get_input_param params = { 1100 .function_num = 0x1, 1101 .hotkey_number = commun_fn_key_number, 1102 .devices = device, 1103 }; 1104 struct acpi_buffer input = { 1105 sizeof(struct wmid3_gds_get_input_param), 1106 ¶ms 1107 }; 1108 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 1109 1110 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output); 1111 if (ACPI_FAILURE(status)) 1112 return status; 1113 1114 obj = output.pointer; 1115 1116 if (!obj) 1117 return AE_ERROR; 1118 else if (obj->type != ACPI_TYPE_BUFFER) { 1119 kfree(obj); 1120 return AE_ERROR; 1121 } 1122 if (obj->buffer.length != 8) { 1123 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1124 kfree(obj); 1125 return AE_ERROR; 1126 } 1127 1128 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); 1129 kfree(obj); 1130 1131 if (return_value.error_code || return_value.ec_return_value) 1132 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n", 1133 device, 1134 return_value.error_code, 1135 return_value.ec_return_value); 1136 else 1137 *value = !!(return_value.devices & device); 1138 1139 return status; 1140 } 1141 1142 static acpi_status wmid_v2_get_u32(u32 *value, u32 cap) 1143 { 1144 u16 device; 1145 1146 switch (cap) { 1147 case ACER_CAP_WIRELESS: 1148 device = ACER_WMID3_GDS_WIRELESS; 1149 break; 1150 case ACER_CAP_BLUETOOTH: 1151 device = ACER_WMID3_GDS_BLUETOOTH; 1152 break; 1153 case ACER_CAP_THREEG: 1154 device = ACER_WMID3_GDS_THREEG; 1155 break; 1156 default: 1157 return AE_ERROR; 1158 } 1159 return wmid3_get_device_status(value, device); 1160 } 1161 1162 static acpi_status wmid3_set_device_status(u32 value, u16 device) 1163 { 1164 struct wmid3_gds_return_value return_value; 1165 acpi_status status; 1166 union acpi_object *obj; 1167 u16 devices; 1168 struct wmid3_gds_get_input_param get_params = { 1169 .function_num = 0x1, 1170 .hotkey_number = commun_fn_key_number, 1171 .devices = commun_func_bitmap, 1172 }; 1173 struct acpi_buffer get_input = { 1174 sizeof(struct wmid3_gds_get_input_param), 1175 &get_params 1176 }; 1177 struct wmid3_gds_set_input_param set_params = { 1178 .function_num = 0x2, 1179 .hotkey_number = commun_fn_key_number, 1180 .devices = commun_func_bitmap, 1181 }; 1182 struct acpi_buffer set_input = { 1183 sizeof(struct wmid3_gds_set_input_param), 1184 &set_params 1185 }; 1186 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 1187 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL }; 1188 1189 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output); 1190 if (ACPI_FAILURE(status)) 1191 return status; 1192 1193 obj = output.pointer; 1194 1195 if (!obj) 1196 return AE_ERROR; 1197 else if (obj->type != ACPI_TYPE_BUFFER) { 1198 kfree(obj); 1199 return AE_ERROR; 1200 } 1201 if (obj->buffer.length != 8) { 1202 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1203 kfree(obj); 1204 return AE_ERROR; 1205 } 1206 1207 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); 1208 kfree(obj); 1209 1210 if (return_value.error_code || return_value.ec_return_value) { 1211 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n", 1212 return_value.error_code, 1213 return_value.ec_return_value); 1214 return status; 1215 } 1216 1217 devices = return_value.devices; 1218 set_params.devices = (value) ? (devices | device) : (devices & ~device); 1219 1220 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2); 1221 if (ACPI_FAILURE(status)) 1222 return status; 1223 1224 obj = output2.pointer; 1225 1226 if (!obj) 1227 return AE_ERROR; 1228 else if (obj->type != ACPI_TYPE_BUFFER) { 1229 kfree(obj); 1230 return AE_ERROR; 1231 } 1232 if (obj->buffer.length != 4) { 1233 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1234 kfree(obj); 1235 return AE_ERROR; 1236 } 1237 1238 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); 1239 kfree(obj); 1240 1241 if (return_value.error_code || return_value.ec_return_value) 1242 pr_warn("Set Device Status failed: 0x%x - 0x%x\n", 1243 return_value.error_code, 1244 return_value.ec_return_value); 1245 1246 return status; 1247 } 1248 1249 static acpi_status wmid_v2_set_u32(u32 value, u32 cap) 1250 { 1251 u16 device; 1252 1253 switch (cap) { 1254 case ACER_CAP_WIRELESS: 1255 device = ACER_WMID3_GDS_WIRELESS; 1256 break; 1257 case ACER_CAP_BLUETOOTH: 1258 device = ACER_WMID3_GDS_BLUETOOTH; 1259 break; 1260 case ACER_CAP_THREEG: 1261 device = ACER_WMID3_GDS_THREEG; 1262 break; 1263 default: 1264 return AE_ERROR; 1265 } 1266 return wmid3_set_device_status(value, device); 1267 } 1268 1269 static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d) 1270 { 1271 struct hotkey_function_type_aa *type_aa; 1272 1273 /* We are looking for OEM-specific Type AAh */ 1274 if (header->type != 0xAA) 1275 return; 1276 1277 has_type_aa = true; 1278 type_aa = (struct hotkey_function_type_aa *) header; 1279 1280 pr_info("Function bitmap for Communication Button: 0x%x\n", 1281 type_aa->commun_func_bitmap); 1282 commun_func_bitmap = type_aa->commun_func_bitmap; 1283 1284 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS) 1285 interface->capability |= ACER_CAP_WIRELESS; 1286 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG) 1287 interface->capability |= ACER_CAP_THREEG; 1288 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH) 1289 interface->capability |= ACER_CAP_BLUETOOTH; 1290 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_RFBTN) 1291 commun_func_bitmap &= ~ACER_WMID3_GDS_RFBTN; 1292 1293 commun_fn_key_number = type_aa->commun_fn_key_number; 1294 } 1295 1296 static acpi_status __init WMID_set_capabilities(void) 1297 { 1298 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; 1299 union acpi_object *obj; 1300 acpi_status status; 1301 u32 devices; 1302 1303 status = wmi_query_block(WMID_GUID2, 0, &out); 1304 if (ACPI_FAILURE(status)) 1305 return status; 1306 1307 obj = (union acpi_object *) out.pointer; 1308 if (obj) { 1309 if (obj->type == ACPI_TYPE_BUFFER && 1310 (obj->buffer.length == sizeof(u32) || 1311 obj->buffer.length == sizeof(u64))) { 1312 devices = *((u32 *) obj->buffer.pointer); 1313 } else if (obj->type == ACPI_TYPE_INTEGER) { 1314 devices = (u32) obj->integer.value; 1315 } else { 1316 kfree(out.pointer); 1317 return AE_ERROR; 1318 } 1319 } else { 1320 kfree(out.pointer); 1321 return AE_ERROR; 1322 } 1323 1324 pr_info("Function bitmap for Communication Device: 0x%x\n", devices); 1325 if (devices & 0x07) 1326 interface->capability |= ACER_CAP_WIRELESS; 1327 if (devices & 0x40) 1328 interface->capability |= ACER_CAP_THREEG; 1329 if (devices & 0x10) 1330 interface->capability |= ACER_CAP_BLUETOOTH; 1331 1332 if (!(devices & 0x20)) 1333 max_brightness = 0x9; 1334 1335 kfree(out.pointer); 1336 return status; 1337 } 1338 1339 static struct wmi_interface wmid_interface = { 1340 .type = ACER_WMID, 1341 }; 1342 1343 static struct wmi_interface wmid_v2_interface = { 1344 .type = ACER_WMID_v2, 1345 }; 1346 1347 /* 1348 * Generic Device (interface-independent) 1349 */ 1350 1351 static acpi_status get_u32(u32 *value, u32 cap) 1352 { 1353 acpi_status status = AE_ERROR; 1354 1355 switch (interface->type) { 1356 case ACER_AMW0: 1357 status = AMW0_get_u32(value, cap); 1358 break; 1359 case ACER_AMW0_V2: 1360 if (cap == ACER_CAP_MAILLED) { 1361 status = AMW0_get_u32(value, cap); 1362 break; 1363 } 1364 fallthrough; 1365 case ACER_WMID: 1366 status = WMID_get_u32(value, cap); 1367 break; 1368 case ACER_WMID_v2: 1369 if (cap & (ACER_CAP_WIRELESS | 1370 ACER_CAP_BLUETOOTH | 1371 ACER_CAP_THREEG)) 1372 status = wmid_v2_get_u32(value, cap); 1373 else if (wmi_has_guid(WMID_GUID2)) 1374 status = WMID_get_u32(value, cap); 1375 break; 1376 } 1377 1378 return status; 1379 } 1380 1381 static acpi_status set_u32(u32 value, u32 cap) 1382 { 1383 acpi_status status; 1384 1385 if (interface->capability & cap) { 1386 switch (interface->type) { 1387 case ACER_AMW0: 1388 return AMW0_set_u32(value, cap); 1389 case ACER_AMW0_V2: 1390 if (cap == ACER_CAP_MAILLED) 1391 return AMW0_set_u32(value, cap); 1392 1393 /* 1394 * On some models, some WMID methods don't toggle 1395 * properly. For those cases, we want to run the AMW0 1396 * method afterwards to be certain we've really toggled 1397 * the device state. 1398 */ 1399 if (cap == ACER_CAP_WIRELESS || 1400 cap == ACER_CAP_BLUETOOTH) { 1401 status = WMID_set_u32(value, cap); 1402 if (ACPI_FAILURE(status)) 1403 return status; 1404 1405 return AMW0_set_u32(value, cap); 1406 } 1407 fallthrough; 1408 case ACER_WMID: 1409 return WMID_set_u32(value, cap); 1410 case ACER_WMID_v2: 1411 if (cap & (ACER_CAP_WIRELESS | 1412 ACER_CAP_BLUETOOTH | 1413 ACER_CAP_THREEG)) 1414 return wmid_v2_set_u32(value, cap); 1415 else if (wmi_has_guid(WMID_GUID2)) 1416 return WMID_set_u32(value, cap); 1417 fallthrough; 1418 default: 1419 return AE_BAD_PARAMETER; 1420 } 1421 } 1422 return AE_BAD_PARAMETER; 1423 } 1424 1425 static void __init acer_commandline_init(void) 1426 { 1427 /* 1428 * These will all fail silently if the value given is invalid, or the 1429 * capability isn't available on the given interface 1430 */ 1431 if (mailled >= 0) 1432 set_u32(mailled, ACER_CAP_MAILLED); 1433 if (!has_type_aa && threeg >= 0) 1434 set_u32(threeg, ACER_CAP_THREEG); 1435 if (brightness >= 0) 1436 set_u32(brightness, ACER_CAP_BRIGHTNESS); 1437 } 1438 1439 /* 1440 * LED device (Mail LED only, no other LEDs known yet) 1441 */ 1442 static void mail_led_set(struct led_classdev *led_cdev, 1443 enum led_brightness value) 1444 { 1445 set_u32(value, ACER_CAP_MAILLED); 1446 } 1447 1448 static struct led_classdev mail_led = { 1449 .name = "acer-wmi::mail", 1450 .brightness_set = mail_led_set, 1451 }; 1452 1453 static int acer_led_init(struct device *dev) 1454 { 1455 return led_classdev_register(dev, &mail_led); 1456 } 1457 1458 static void acer_led_exit(void) 1459 { 1460 set_u32(LED_OFF, ACER_CAP_MAILLED); 1461 led_classdev_unregister(&mail_led); 1462 } 1463 1464 /* 1465 * Backlight device 1466 */ 1467 static struct backlight_device *acer_backlight_device; 1468 1469 static int read_brightness(struct backlight_device *bd) 1470 { 1471 u32 value; 1472 get_u32(&value, ACER_CAP_BRIGHTNESS); 1473 return value; 1474 } 1475 1476 static int update_bl_status(struct backlight_device *bd) 1477 { 1478 int intensity = bd->props.brightness; 1479 1480 if (bd->props.power != FB_BLANK_UNBLANK) 1481 intensity = 0; 1482 if (bd->props.fb_blank != FB_BLANK_UNBLANK) 1483 intensity = 0; 1484 1485 set_u32(intensity, ACER_CAP_BRIGHTNESS); 1486 1487 return 0; 1488 } 1489 1490 static const struct backlight_ops acer_bl_ops = { 1491 .get_brightness = read_brightness, 1492 .update_status = update_bl_status, 1493 }; 1494 1495 static int acer_backlight_init(struct device *dev) 1496 { 1497 struct backlight_properties props; 1498 struct backlight_device *bd; 1499 1500 memset(&props, 0, sizeof(struct backlight_properties)); 1501 props.type = BACKLIGHT_PLATFORM; 1502 props.max_brightness = max_brightness; 1503 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops, 1504 &props); 1505 if (IS_ERR(bd)) { 1506 pr_err("Could not register Acer backlight device\n"); 1507 acer_backlight_device = NULL; 1508 return PTR_ERR(bd); 1509 } 1510 1511 acer_backlight_device = bd; 1512 1513 bd->props.power = FB_BLANK_UNBLANK; 1514 bd->props.brightness = read_brightness(bd); 1515 backlight_update_status(bd); 1516 return 0; 1517 } 1518 1519 static void acer_backlight_exit(void) 1520 { 1521 backlight_device_unregister(acer_backlight_device); 1522 } 1523 1524 /* 1525 * Accelerometer device 1526 */ 1527 static acpi_handle gsensor_handle; 1528 1529 static int acer_gsensor_init(void) 1530 { 1531 acpi_status status; 1532 struct acpi_buffer output; 1533 union acpi_object out_obj; 1534 1535 output.length = sizeof(out_obj); 1536 output.pointer = &out_obj; 1537 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output); 1538 if (ACPI_FAILURE(status)) 1539 return -1; 1540 1541 return 0; 1542 } 1543 1544 static int acer_gsensor_open(struct input_dev *input) 1545 { 1546 return acer_gsensor_init(); 1547 } 1548 1549 static int acer_gsensor_event(void) 1550 { 1551 acpi_status status; 1552 struct acpi_buffer output; 1553 union acpi_object out_obj[5]; 1554 1555 if (!acer_wmi_accel_dev) 1556 return -1; 1557 1558 output.length = sizeof(out_obj); 1559 output.pointer = out_obj; 1560 1561 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output); 1562 if (ACPI_FAILURE(status)) 1563 return -1; 1564 1565 if (out_obj->package.count != 4) 1566 return -1; 1567 1568 input_report_abs(acer_wmi_accel_dev, ABS_X, 1569 (s16)out_obj->package.elements[0].integer.value); 1570 input_report_abs(acer_wmi_accel_dev, ABS_Y, 1571 (s16)out_obj->package.elements[1].integer.value); 1572 input_report_abs(acer_wmi_accel_dev, ABS_Z, 1573 (s16)out_obj->package.elements[2].integer.value); 1574 input_sync(acer_wmi_accel_dev); 1575 return 0; 1576 } 1577 1578 /* 1579 * Switch series keyboard dock status 1580 */ 1581 static int acer_kbd_dock_state_to_sw_tablet_mode(u8 kbd_dock_state) 1582 { 1583 switch (kbd_dock_state) { 1584 case 0x01: /* Docked, traditional clamshell laptop mode */ 1585 return 0; 1586 case 0x04: /* Stand-alone tablet */ 1587 case 0x40: /* Docked, tent mode, keyboard not usable */ 1588 return 1; 1589 default: 1590 pr_warn("Unknown kbd_dock_state 0x%02x\n", kbd_dock_state); 1591 } 1592 1593 return 0; 1594 } 1595 1596 static void acer_kbd_dock_get_initial_state(void) 1597 { 1598 u8 *output, input[8] = { 0x05, 0x00, }; 1599 struct acpi_buffer input_buf = { sizeof(input), input }; 1600 struct acpi_buffer output_buf = { ACPI_ALLOCATE_BUFFER, NULL }; 1601 union acpi_object *obj; 1602 acpi_status status; 1603 int sw_tablet_mode; 1604 1605 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input_buf, &output_buf); 1606 if (ACPI_FAILURE(status)) { 1607 pr_err("Error getting keyboard-dock initial status: %s\n", 1608 acpi_format_exception(status)); 1609 return; 1610 } 1611 1612 obj = output_buf.pointer; 1613 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) { 1614 pr_err("Unexpected output format getting keyboard-dock initial status\n"); 1615 goto out_free_obj; 1616 } 1617 1618 output = obj->buffer.pointer; 1619 if (output[0] != 0x00 || (output[3] != 0x05 && output[3] != 0x45)) { 1620 pr_err("Unexpected output [0]=0x%02x [3]=0x%02x getting keyboard-dock initial status\n", 1621 output[0], output[3]); 1622 goto out_free_obj; 1623 } 1624 1625 sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(output[4]); 1626 input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode); 1627 1628 out_free_obj: 1629 kfree(obj); 1630 } 1631 1632 static void acer_kbd_dock_event(const struct event_return_value *event) 1633 { 1634 int sw_tablet_mode; 1635 1636 if (!has_cap(ACER_CAP_KBD_DOCK)) 1637 return; 1638 1639 sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(event->kbd_dock_state); 1640 input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode); 1641 input_sync(acer_wmi_input_dev); 1642 } 1643 1644 /* 1645 * Rfkill devices 1646 */ 1647 static void acer_rfkill_update(struct work_struct *ignored); 1648 static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update); 1649 static void acer_rfkill_update(struct work_struct *ignored) 1650 { 1651 u32 state; 1652 acpi_status status; 1653 1654 if (has_cap(ACER_CAP_WIRELESS)) { 1655 status = get_u32(&state, ACER_CAP_WIRELESS); 1656 if (ACPI_SUCCESS(status)) { 1657 if (quirks->wireless == 3) 1658 rfkill_set_hw_state(wireless_rfkill, !state); 1659 else 1660 rfkill_set_sw_state(wireless_rfkill, !state); 1661 } 1662 } 1663 1664 if (has_cap(ACER_CAP_BLUETOOTH)) { 1665 status = get_u32(&state, ACER_CAP_BLUETOOTH); 1666 if (ACPI_SUCCESS(status)) 1667 rfkill_set_sw_state(bluetooth_rfkill, !state); 1668 } 1669 1670 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) { 1671 status = get_u32(&state, ACER_WMID3_GDS_THREEG); 1672 if (ACPI_SUCCESS(status)) 1673 rfkill_set_sw_state(threeg_rfkill, !state); 1674 } 1675 1676 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); 1677 } 1678 1679 static int acer_rfkill_set(void *data, bool blocked) 1680 { 1681 acpi_status status; 1682 u32 cap = (unsigned long)data; 1683 1684 if (rfkill_inited) { 1685 status = set_u32(!blocked, cap); 1686 if (ACPI_FAILURE(status)) 1687 return -ENODEV; 1688 } 1689 1690 return 0; 1691 } 1692 1693 static const struct rfkill_ops acer_rfkill_ops = { 1694 .set_block = acer_rfkill_set, 1695 }; 1696 1697 static struct rfkill *acer_rfkill_register(struct device *dev, 1698 enum rfkill_type type, 1699 char *name, u32 cap) 1700 { 1701 int err; 1702 struct rfkill *rfkill_dev; 1703 u32 state; 1704 acpi_status status; 1705 1706 rfkill_dev = rfkill_alloc(name, dev, type, 1707 &acer_rfkill_ops, 1708 (void *)(unsigned long)cap); 1709 if (!rfkill_dev) 1710 return ERR_PTR(-ENOMEM); 1711 1712 status = get_u32(&state, cap); 1713 1714 err = rfkill_register(rfkill_dev); 1715 if (err) { 1716 rfkill_destroy(rfkill_dev); 1717 return ERR_PTR(err); 1718 } 1719 1720 if (ACPI_SUCCESS(status)) 1721 rfkill_set_sw_state(rfkill_dev, !state); 1722 1723 return rfkill_dev; 1724 } 1725 1726 static int acer_rfkill_init(struct device *dev) 1727 { 1728 int err; 1729 1730 if (has_cap(ACER_CAP_WIRELESS)) { 1731 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN, 1732 "acer-wireless", ACER_CAP_WIRELESS); 1733 if (IS_ERR(wireless_rfkill)) { 1734 err = PTR_ERR(wireless_rfkill); 1735 goto error_wireless; 1736 } 1737 } 1738 1739 if (has_cap(ACER_CAP_BLUETOOTH)) { 1740 bluetooth_rfkill = acer_rfkill_register(dev, 1741 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth", 1742 ACER_CAP_BLUETOOTH); 1743 if (IS_ERR(bluetooth_rfkill)) { 1744 err = PTR_ERR(bluetooth_rfkill); 1745 goto error_bluetooth; 1746 } 1747 } 1748 1749 if (has_cap(ACER_CAP_THREEG)) { 1750 threeg_rfkill = acer_rfkill_register(dev, 1751 RFKILL_TYPE_WWAN, "acer-threeg", 1752 ACER_CAP_THREEG); 1753 if (IS_ERR(threeg_rfkill)) { 1754 err = PTR_ERR(threeg_rfkill); 1755 goto error_threeg; 1756 } 1757 } 1758 1759 rfkill_inited = true; 1760 1761 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) && 1762 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG)) 1763 schedule_delayed_work(&acer_rfkill_work, 1764 round_jiffies_relative(HZ)); 1765 1766 return 0; 1767 1768 error_threeg: 1769 if (has_cap(ACER_CAP_BLUETOOTH)) { 1770 rfkill_unregister(bluetooth_rfkill); 1771 rfkill_destroy(bluetooth_rfkill); 1772 } 1773 error_bluetooth: 1774 if (has_cap(ACER_CAP_WIRELESS)) { 1775 rfkill_unregister(wireless_rfkill); 1776 rfkill_destroy(wireless_rfkill); 1777 } 1778 error_wireless: 1779 return err; 1780 } 1781 1782 static void acer_rfkill_exit(void) 1783 { 1784 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) && 1785 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG)) 1786 cancel_delayed_work_sync(&acer_rfkill_work); 1787 1788 if (has_cap(ACER_CAP_WIRELESS)) { 1789 rfkill_unregister(wireless_rfkill); 1790 rfkill_destroy(wireless_rfkill); 1791 } 1792 1793 if (has_cap(ACER_CAP_BLUETOOTH)) { 1794 rfkill_unregister(bluetooth_rfkill); 1795 rfkill_destroy(bluetooth_rfkill); 1796 } 1797 1798 if (has_cap(ACER_CAP_THREEG)) { 1799 rfkill_unregister(threeg_rfkill); 1800 rfkill_destroy(threeg_rfkill); 1801 } 1802 return; 1803 } 1804 1805 static void acer_wmi_notify(u32 value, void *context) 1806 { 1807 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; 1808 union acpi_object *obj; 1809 struct event_return_value return_value; 1810 acpi_status status; 1811 u16 device_state; 1812 const struct key_entry *key; 1813 u32 scancode; 1814 1815 status = wmi_get_event_data(value, &response); 1816 if (status != AE_OK) { 1817 pr_warn("bad event status 0x%x\n", status); 1818 return; 1819 } 1820 1821 obj = (union acpi_object *)response.pointer; 1822 1823 if (!obj) 1824 return; 1825 if (obj->type != ACPI_TYPE_BUFFER) { 1826 pr_warn("Unknown response received %d\n", obj->type); 1827 kfree(obj); 1828 return; 1829 } 1830 if (obj->buffer.length != 8) { 1831 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1832 kfree(obj); 1833 return; 1834 } 1835 1836 return_value = *((struct event_return_value *)obj->buffer.pointer); 1837 kfree(obj); 1838 1839 switch (return_value.function) { 1840 case WMID_HOTKEY_EVENT: 1841 device_state = return_value.device_state; 1842 pr_debug("device state: 0x%x\n", device_state); 1843 1844 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev, 1845 return_value.key_num); 1846 if (!key) { 1847 pr_warn("Unknown key number - 0x%x\n", 1848 return_value.key_num); 1849 } else { 1850 scancode = return_value.key_num; 1851 switch (key->keycode) { 1852 case KEY_WLAN: 1853 case KEY_BLUETOOTH: 1854 if (has_cap(ACER_CAP_WIRELESS)) 1855 rfkill_set_sw_state(wireless_rfkill, 1856 !(device_state & ACER_WMID3_GDS_WIRELESS)); 1857 if (has_cap(ACER_CAP_THREEG)) 1858 rfkill_set_sw_state(threeg_rfkill, 1859 !(device_state & ACER_WMID3_GDS_THREEG)); 1860 if (has_cap(ACER_CAP_BLUETOOTH)) 1861 rfkill_set_sw_state(bluetooth_rfkill, 1862 !(device_state & ACER_WMID3_GDS_BLUETOOTH)); 1863 break; 1864 case KEY_TOUCHPAD_TOGGLE: 1865 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ? 1866 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF; 1867 } 1868 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true); 1869 } 1870 break; 1871 case WMID_ACCEL_OR_KBD_DOCK_EVENT: 1872 acer_gsensor_event(); 1873 acer_kbd_dock_event(&return_value); 1874 break; 1875 default: 1876 pr_warn("Unknown function number - %d - %d\n", 1877 return_value.function, return_value.key_num); 1878 break; 1879 } 1880 } 1881 1882 static acpi_status __init 1883 wmid3_set_function_mode(struct func_input_params *params, 1884 struct func_return_value *return_value) 1885 { 1886 acpi_status status; 1887 union acpi_object *obj; 1888 1889 struct acpi_buffer input = { sizeof(struct func_input_params), params }; 1890 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 1891 1892 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output); 1893 if (ACPI_FAILURE(status)) 1894 return status; 1895 1896 obj = output.pointer; 1897 1898 if (!obj) 1899 return AE_ERROR; 1900 else if (obj->type != ACPI_TYPE_BUFFER) { 1901 kfree(obj); 1902 return AE_ERROR; 1903 } 1904 if (obj->buffer.length != 4) { 1905 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1906 kfree(obj); 1907 return AE_ERROR; 1908 } 1909 1910 *return_value = *((struct func_return_value *)obj->buffer.pointer); 1911 kfree(obj); 1912 1913 return status; 1914 } 1915 1916 static int __init acer_wmi_enable_ec_raw(void) 1917 { 1918 struct func_return_value return_value; 1919 acpi_status status; 1920 struct func_input_params params = { 1921 .function_num = 0x1, 1922 .commun_devices = 0xFFFF, 1923 .devices = 0xFFFF, 1924 .app_status = 0x00, /* Launch Manager Deactive */ 1925 .app_mask = 0x01, 1926 }; 1927 1928 status = wmid3_set_function_mode(¶ms, &return_value); 1929 1930 if (return_value.error_code || return_value.ec_return_value) 1931 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n", 1932 return_value.error_code, 1933 return_value.ec_return_value); 1934 else 1935 pr_info("Enabled EC raw mode\n"); 1936 1937 return status; 1938 } 1939 1940 static int __init acer_wmi_enable_lm(void) 1941 { 1942 struct func_return_value return_value; 1943 acpi_status status; 1944 struct func_input_params params = { 1945 .function_num = 0x1, 1946 .commun_devices = 0xFFFF, 1947 .devices = 0xFFFF, 1948 .app_status = 0x01, /* Launch Manager Active */ 1949 .app_mask = 0x01, 1950 }; 1951 1952 status = wmid3_set_function_mode(¶ms, &return_value); 1953 1954 if (return_value.error_code || return_value.ec_return_value) 1955 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n", 1956 return_value.error_code, 1957 return_value.ec_return_value); 1958 1959 return status; 1960 } 1961 1962 static int __init acer_wmi_enable_rf_button(void) 1963 { 1964 struct func_return_value return_value; 1965 acpi_status status; 1966 struct func_input_params params = { 1967 .function_num = 0x1, 1968 .commun_devices = 0xFFFF, 1969 .devices = 0xFFFF, 1970 .app_status = 0x10, /* RF Button Active */ 1971 .app_mask = 0x10, 1972 }; 1973 1974 status = wmid3_set_function_mode(¶ms, &return_value); 1975 1976 if (return_value.error_code || return_value.ec_return_value) 1977 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n", 1978 return_value.error_code, 1979 return_value.ec_return_value); 1980 1981 return status; 1982 } 1983 1984 static int __init acer_wmi_accel_setup(void) 1985 { 1986 struct acpi_device *adev; 1987 int err; 1988 1989 adev = acpi_dev_get_first_match_dev("BST0001", NULL, -1); 1990 if (!adev) 1991 return -ENODEV; 1992 1993 gsensor_handle = acpi_device_handle(adev); 1994 acpi_dev_put(adev); 1995 1996 acer_wmi_accel_dev = input_allocate_device(); 1997 if (!acer_wmi_accel_dev) 1998 return -ENOMEM; 1999 2000 acer_wmi_accel_dev->open = acer_gsensor_open; 2001 2002 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer"; 2003 acer_wmi_accel_dev->phys = "wmi/input1"; 2004 acer_wmi_accel_dev->id.bustype = BUS_HOST; 2005 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS); 2006 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0); 2007 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0); 2008 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0); 2009 2010 err = input_register_device(acer_wmi_accel_dev); 2011 if (err) 2012 goto err_free_dev; 2013 2014 return 0; 2015 2016 err_free_dev: 2017 input_free_device(acer_wmi_accel_dev); 2018 return err; 2019 } 2020 2021 static int __init acer_wmi_input_setup(void) 2022 { 2023 acpi_status status; 2024 int err; 2025 2026 acer_wmi_input_dev = input_allocate_device(); 2027 if (!acer_wmi_input_dev) 2028 return -ENOMEM; 2029 2030 acer_wmi_input_dev->name = "Acer WMI hotkeys"; 2031 acer_wmi_input_dev->phys = "wmi/input0"; 2032 acer_wmi_input_dev->id.bustype = BUS_HOST; 2033 2034 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL); 2035 if (err) 2036 goto err_free_dev; 2037 2038 if (has_cap(ACER_CAP_KBD_DOCK)) 2039 input_set_capability(acer_wmi_input_dev, EV_SW, SW_TABLET_MODE); 2040 2041 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID, 2042 acer_wmi_notify, NULL); 2043 if (ACPI_FAILURE(status)) { 2044 err = -EIO; 2045 goto err_free_dev; 2046 } 2047 2048 if (has_cap(ACER_CAP_KBD_DOCK)) 2049 acer_kbd_dock_get_initial_state(); 2050 2051 err = input_register_device(acer_wmi_input_dev); 2052 if (err) 2053 goto err_uninstall_notifier; 2054 2055 return 0; 2056 2057 err_uninstall_notifier: 2058 wmi_remove_notify_handler(ACERWMID_EVENT_GUID); 2059 err_free_dev: 2060 input_free_device(acer_wmi_input_dev); 2061 return err; 2062 } 2063 2064 static void acer_wmi_input_destroy(void) 2065 { 2066 wmi_remove_notify_handler(ACERWMID_EVENT_GUID); 2067 input_unregister_device(acer_wmi_input_dev); 2068 } 2069 2070 /* 2071 * debugfs functions 2072 */ 2073 static u32 get_wmid_devices(void) 2074 { 2075 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; 2076 union acpi_object *obj; 2077 acpi_status status; 2078 u32 devices = 0; 2079 2080 status = wmi_query_block(WMID_GUID2, 0, &out); 2081 if (ACPI_FAILURE(status)) 2082 return 0; 2083 2084 obj = (union acpi_object *) out.pointer; 2085 if (obj) { 2086 if (obj->type == ACPI_TYPE_BUFFER && 2087 (obj->buffer.length == sizeof(u32) || 2088 obj->buffer.length == sizeof(u64))) { 2089 devices = *((u32 *) obj->buffer.pointer); 2090 } else if (obj->type == ACPI_TYPE_INTEGER) { 2091 devices = (u32) obj->integer.value; 2092 } 2093 } 2094 2095 kfree(out.pointer); 2096 return devices; 2097 } 2098 2099 /* 2100 * Platform device 2101 */ 2102 static int acer_platform_probe(struct platform_device *device) 2103 { 2104 int err; 2105 2106 if (has_cap(ACER_CAP_MAILLED)) { 2107 err = acer_led_init(&device->dev); 2108 if (err) 2109 goto error_mailled; 2110 } 2111 2112 if (has_cap(ACER_CAP_BRIGHTNESS)) { 2113 err = acer_backlight_init(&device->dev); 2114 if (err) 2115 goto error_brightness; 2116 } 2117 2118 err = acer_rfkill_init(&device->dev); 2119 if (err) 2120 goto error_rfkill; 2121 2122 return err; 2123 2124 error_rfkill: 2125 if (has_cap(ACER_CAP_BRIGHTNESS)) 2126 acer_backlight_exit(); 2127 error_brightness: 2128 if (has_cap(ACER_CAP_MAILLED)) 2129 acer_led_exit(); 2130 error_mailled: 2131 return err; 2132 } 2133 2134 static int acer_platform_remove(struct platform_device *device) 2135 { 2136 if (has_cap(ACER_CAP_MAILLED)) 2137 acer_led_exit(); 2138 if (has_cap(ACER_CAP_BRIGHTNESS)) 2139 acer_backlight_exit(); 2140 2141 acer_rfkill_exit(); 2142 return 0; 2143 } 2144 2145 #ifdef CONFIG_PM_SLEEP 2146 static int acer_suspend(struct device *dev) 2147 { 2148 u32 value; 2149 struct acer_data *data = &interface->data; 2150 2151 if (!data) 2152 return -ENOMEM; 2153 2154 if (has_cap(ACER_CAP_MAILLED)) { 2155 get_u32(&value, ACER_CAP_MAILLED); 2156 set_u32(LED_OFF, ACER_CAP_MAILLED); 2157 data->mailled = value; 2158 } 2159 2160 if (has_cap(ACER_CAP_BRIGHTNESS)) { 2161 get_u32(&value, ACER_CAP_BRIGHTNESS); 2162 data->brightness = value; 2163 } 2164 2165 return 0; 2166 } 2167 2168 static int acer_resume(struct device *dev) 2169 { 2170 struct acer_data *data = &interface->data; 2171 2172 if (!data) 2173 return -ENOMEM; 2174 2175 if (has_cap(ACER_CAP_MAILLED)) 2176 set_u32(data->mailled, ACER_CAP_MAILLED); 2177 2178 if (has_cap(ACER_CAP_BRIGHTNESS)) 2179 set_u32(data->brightness, ACER_CAP_BRIGHTNESS); 2180 2181 if (acer_wmi_accel_dev) 2182 acer_gsensor_init(); 2183 2184 return 0; 2185 } 2186 #else 2187 #define acer_suspend NULL 2188 #define acer_resume NULL 2189 #endif 2190 2191 static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume); 2192 2193 static void acer_platform_shutdown(struct platform_device *device) 2194 { 2195 struct acer_data *data = &interface->data; 2196 2197 if (!data) 2198 return; 2199 2200 if (has_cap(ACER_CAP_MAILLED)) 2201 set_u32(LED_OFF, ACER_CAP_MAILLED); 2202 } 2203 2204 static struct platform_driver acer_platform_driver = { 2205 .driver = { 2206 .name = "acer-wmi", 2207 .pm = &acer_pm, 2208 }, 2209 .probe = acer_platform_probe, 2210 .remove = acer_platform_remove, 2211 .shutdown = acer_platform_shutdown, 2212 }; 2213 2214 static struct platform_device *acer_platform_device; 2215 2216 static void remove_debugfs(void) 2217 { 2218 debugfs_remove_recursive(interface->debug.root); 2219 } 2220 2221 static void __init create_debugfs(void) 2222 { 2223 interface->debug.root = debugfs_create_dir("acer-wmi", NULL); 2224 2225 debugfs_create_u32("devices", S_IRUGO, interface->debug.root, 2226 &interface->debug.wmid_devices); 2227 } 2228 2229 static int __init acer_wmi_init(void) 2230 { 2231 int err; 2232 2233 pr_info("Acer Laptop ACPI-WMI Extras\n"); 2234 2235 if (dmi_check_system(acer_blacklist)) { 2236 pr_info("Blacklisted hardware detected - not loading\n"); 2237 return -ENODEV; 2238 } 2239 2240 find_quirks(); 2241 2242 /* 2243 * The AMW0_GUID1 wmi is not only found on Acer family but also other 2244 * machines like Lenovo, Fujitsu and Medion. In the past days, 2245 * acer-wmi driver handled those non-Acer machines by quirks list. 2246 * But actually acer-wmi driver was loaded on any machines that have 2247 * AMW0_GUID1. This behavior is strange because those machines should 2248 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop, 2249 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1 2250 * should be in Acer/Gateway/Packard Bell white list, or it's already 2251 * in the past quirk list. 2252 */ 2253 if (wmi_has_guid(AMW0_GUID1) && 2254 !dmi_check_system(amw0_whitelist) && 2255 quirks == &quirk_unknown) { 2256 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n"); 2257 return -ENODEV; 2258 } 2259 2260 /* 2261 * Detect which ACPI-WMI interface we're using. 2262 */ 2263 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) 2264 interface = &AMW0_V2_interface; 2265 2266 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) 2267 interface = &wmid_interface; 2268 2269 if (wmi_has_guid(WMID_GUID3)) 2270 interface = &wmid_v2_interface; 2271 2272 if (interface) 2273 dmi_walk(type_aa_dmi_decode, NULL); 2274 2275 if (wmi_has_guid(WMID_GUID2) && interface) { 2276 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) { 2277 pr_err("Unable to detect available WMID devices\n"); 2278 return -ENODEV; 2279 } 2280 /* WMID always provides brightness methods */ 2281 interface->capability |= ACER_CAP_BRIGHTNESS; 2282 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa && force_caps == -1) { 2283 pr_err("No WMID device detection method found\n"); 2284 return -ENODEV; 2285 } 2286 2287 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) { 2288 interface = &AMW0_interface; 2289 2290 if (ACPI_FAILURE(AMW0_set_capabilities())) { 2291 pr_err("Unable to detect available AMW0 devices\n"); 2292 return -ENODEV; 2293 } 2294 } 2295 2296 if (wmi_has_guid(AMW0_GUID1)) 2297 AMW0_find_mailled(); 2298 2299 if (!interface) { 2300 pr_err("No or unsupported WMI interface, unable to load\n"); 2301 return -ENODEV; 2302 } 2303 2304 set_quirks(); 2305 2306 if (dmi_check_system(video_vendor_dmi_table)) 2307 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); 2308 2309 if (acpi_video_get_backlight_type() != acpi_backlight_vendor) 2310 interface->capability &= ~ACER_CAP_BRIGHTNESS; 2311 2312 if (wmi_has_guid(WMID_GUID3)) 2313 interface->capability |= ACER_CAP_SET_FUNCTION_MODE; 2314 2315 if (force_caps != -1) 2316 interface->capability = force_caps; 2317 2318 if (wmi_has_guid(WMID_GUID3) && 2319 (interface->capability & ACER_CAP_SET_FUNCTION_MODE)) { 2320 if (ACPI_FAILURE(acer_wmi_enable_rf_button())) 2321 pr_warn("Cannot enable RF Button Driver\n"); 2322 2323 if (ec_raw_mode) { 2324 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) { 2325 pr_err("Cannot enable EC raw mode\n"); 2326 return -ENODEV; 2327 } 2328 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) { 2329 pr_err("Cannot enable Launch Manager mode\n"); 2330 return -ENODEV; 2331 } 2332 } else if (ec_raw_mode) { 2333 pr_info("No WMID EC raw mode enable method\n"); 2334 } 2335 2336 if (wmi_has_guid(ACERWMID_EVENT_GUID)) { 2337 err = acer_wmi_input_setup(); 2338 if (err) 2339 return err; 2340 err = acer_wmi_accel_setup(); 2341 if (err && err != -ENODEV) 2342 pr_warn("Cannot enable accelerometer\n"); 2343 } 2344 2345 err = platform_driver_register(&acer_platform_driver); 2346 if (err) { 2347 pr_err("Unable to register platform driver\n"); 2348 goto error_platform_register; 2349 } 2350 2351 acer_platform_device = platform_device_alloc("acer-wmi", -1); 2352 if (!acer_platform_device) { 2353 err = -ENOMEM; 2354 goto error_device_alloc; 2355 } 2356 2357 err = platform_device_add(acer_platform_device); 2358 if (err) 2359 goto error_device_add; 2360 2361 if (wmi_has_guid(WMID_GUID2)) { 2362 interface->debug.wmid_devices = get_wmid_devices(); 2363 create_debugfs(); 2364 } 2365 2366 /* Override any initial settings with values from the commandline */ 2367 acer_commandline_init(); 2368 2369 return 0; 2370 2371 error_device_add: 2372 platform_device_put(acer_platform_device); 2373 error_device_alloc: 2374 platform_driver_unregister(&acer_platform_driver); 2375 error_platform_register: 2376 if (wmi_has_guid(ACERWMID_EVENT_GUID)) 2377 acer_wmi_input_destroy(); 2378 if (acer_wmi_accel_dev) 2379 input_unregister_device(acer_wmi_accel_dev); 2380 2381 return err; 2382 } 2383 2384 static void __exit acer_wmi_exit(void) 2385 { 2386 if (wmi_has_guid(ACERWMID_EVENT_GUID)) 2387 acer_wmi_input_destroy(); 2388 2389 if (acer_wmi_accel_dev) 2390 input_unregister_device(acer_wmi_accel_dev); 2391 2392 remove_debugfs(); 2393 platform_device_unregister(acer_platform_device); 2394 platform_driver_unregister(&acer_platform_driver); 2395 2396 pr_info("Acer Laptop WMI Extras unloaded\n"); 2397 return; 2398 } 2399 2400 module_init(acer_wmi_init); 2401 module_exit(acer_wmi_exit); 2402