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