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 585 /* Find which quirks are needed for a particular vendor/ model pair */ 586 static void __init find_quirks(void) 587 { 588 if (!force_series) { 589 dmi_check_system(acer_quirks); 590 } else if (force_series == 2490) { 591 quirks = &quirk_acer_travelmate_2490; 592 } 593 594 if (quirks == NULL) 595 quirks = &quirk_unknown; 596 597 set_quirks(); 598 } 599 600 /* 601 * General interface convenience methods 602 */ 603 604 static bool has_cap(u32 cap) 605 { 606 if ((interface->capability & cap) != 0) 607 return 1; 608 609 return 0; 610 } 611 612 /* 613 * AMW0 (V1) interface 614 */ 615 struct wmab_args { 616 u32 eax; 617 u32 ebx; 618 u32 ecx; 619 u32 edx; 620 }; 621 622 struct wmab_ret { 623 u32 eax; 624 u32 ebx; 625 u32 ecx; 626 u32 edx; 627 u32 eex; 628 }; 629 630 static acpi_status wmab_execute(struct wmab_args *regbuf, 631 struct acpi_buffer *result) 632 { 633 struct acpi_buffer input; 634 acpi_status status; 635 input.length = sizeof(struct wmab_args); 636 input.pointer = (u8 *)regbuf; 637 638 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result); 639 640 return status; 641 } 642 643 static acpi_status AMW0_get_u32(u32 *value, u32 cap) 644 { 645 int err; 646 u8 result; 647 648 switch (cap) { 649 case ACER_CAP_MAILLED: 650 switch (quirks->mailled) { 651 default: 652 err = ec_read(0xA, &result); 653 if (err) 654 return AE_ERROR; 655 *value = (result >> 7) & 0x1; 656 return AE_OK; 657 } 658 break; 659 case ACER_CAP_WIRELESS: 660 switch (quirks->wireless) { 661 case 1: 662 err = ec_read(0x7B, &result); 663 if (err) 664 return AE_ERROR; 665 *value = result & 0x1; 666 return AE_OK; 667 case 2: 668 err = ec_read(0x71, &result); 669 if (err) 670 return AE_ERROR; 671 *value = result & 0x1; 672 return AE_OK; 673 case 3: 674 err = ec_read(0x78, &result); 675 if (err) 676 return AE_ERROR; 677 *value = result & 0x1; 678 return AE_OK; 679 default: 680 err = ec_read(0xA, &result); 681 if (err) 682 return AE_ERROR; 683 *value = (result >> 2) & 0x1; 684 return AE_OK; 685 } 686 break; 687 case ACER_CAP_BLUETOOTH: 688 switch (quirks->bluetooth) { 689 default: 690 err = ec_read(0xA, &result); 691 if (err) 692 return AE_ERROR; 693 *value = (result >> 4) & 0x1; 694 return AE_OK; 695 } 696 break; 697 case ACER_CAP_BRIGHTNESS: 698 switch (quirks->brightness) { 699 default: 700 err = ec_read(0x83, &result); 701 if (err) 702 return AE_ERROR; 703 *value = result; 704 return AE_OK; 705 } 706 break; 707 default: 708 return AE_ERROR; 709 } 710 return AE_OK; 711 } 712 713 static acpi_status AMW0_set_u32(u32 value, u32 cap) 714 { 715 struct wmab_args args; 716 717 args.eax = ACER_AMW0_WRITE; 718 args.ebx = value ? (1<<8) : 0; 719 args.ecx = args.edx = 0; 720 721 switch (cap) { 722 case ACER_CAP_MAILLED: 723 if (value > 1) 724 return AE_BAD_PARAMETER; 725 args.ebx |= ACER_AMW0_MAILLED_MASK; 726 break; 727 case ACER_CAP_WIRELESS: 728 if (value > 1) 729 return AE_BAD_PARAMETER; 730 args.ebx |= ACER_AMW0_WIRELESS_MASK; 731 break; 732 case ACER_CAP_BLUETOOTH: 733 if (value > 1) 734 return AE_BAD_PARAMETER; 735 args.ebx |= ACER_AMW0_BLUETOOTH_MASK; 736 break; 737 case ACER_CAP_BRIGHTNESS: 738 if (value > max_brightness) 739 return AE_BAD_PARAMETER; 740 switch (quirks->brightness) { 741 default: 742 return ec_write(0x83, value); 743 break; 744 } 745 default: 746 return AE_ERROR; 747 } 748 749 /* Actually do the set */ 750 return wmab_execute(&args, NULL); 751 } 752 753 static acpi_status __init AMW0_find_mailled(void) 754 { 755 struct wmab_args args; 756 struct wmab_ret ret; 757 acpi_status status = AE_OK; 758 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; 759 union acpi_object *obj; 760 761 args.eax = 0x86; 762 args.ebx = args.ecx = args.edx = 0; 763 764 status = wmab_execute(&args, &out); 765 if (ACPI_FAILURE(status)) 766 return status; 767 768 obj = (union acpi_object *) out.pointer; 769 if (obj && obj->type == ACPI_TYPE_BUFFER && 770 obj->buffer.length == sizeof(struct wmab_ret)) { 771 ret = *((struct wmab_ret *) obj->buffer.pointer); 772 } else { 773 kfree(out.pointer); 774 return AE_ERROR; 775 } 776 777 if (ret.eex & 0x1) 778 interface->capability |= ACER_CAP_MAILLED; 779 780 kfree(out.pointer); 781 782 return AE_OK; 783 } 784 785 static int AMW0_set_cap_acpi_check_device_found __initdata; 786 787 static acpi_status __init AMW0_set_cap_acpi_check_device_cb(acpi_handle handle, 788 u32 level, void *context, void **retval) 789 { 790 AMW0_set_cap_acpi_check_device_found = 1; 791 return AE_OK; 792 } 793 794 static const struct acpi_device_id norfkill_ids[] __initconst = { 795 { "VPC2004", 0}, 796 { "IBM0068", 0}, 797 { "LEN0068", 0}, 798 { "SNY5001", 0}, /* sony-laptop in charge */ 799 { "", 0}, 800 }; 801 802 static int __init AMW0_set_cap_acpi_check_device(void) 803 { 804 const struct acpi_device_id *id; 805 806 for (id = norfkill_ids; id->id[0]; id++) 807 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb, 808 NULL, NULL); 809 return AMW0_set_cap_acpi_check_device_found; 810 } 811 812 static acpi_status __init AMW0_set_capabilities(void) 813 { 814 struct wmab_args args; 815 struct wmab_ret ret; 816 acpi_status status; 817 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; 818 union acpi_object *obj; 819 820 /* 821 * On laptops with this strange GUID (non Acer), normal probing doesn't 822 * work. 823 */ 824 if (wmi_has_guid(AMW0_GUID2)) { 825 if ((quirks != &quirk_unknown) || 826 !AMW0_set_cap_acpi_check_device()) 827 interface->capability |= ACER_CAP_WIRELESS; 828 return AE_OK; 829 } 830 831 args.eax = ACER_AMW0_WRITE; 832 args.ecx = args.edx = 0; 833 834 args.ebx = 0xa2 << 8; 835 args.ebx |= ACER_AMW0_WIRELESS_MASK; 836 837 status = wmab_execute(&args, &out); 838 if (ACPI_FAILURE(status)) 839 return status; 840 841 obj = out.pointer; 842 if (obj && obj->type == ACPI_TYPE_BUFFER && 843 obj->buffer.length == sizeof(struct wmab_ret)) { 844 ret = *((struct wmab_ret *) obj->buffer.pointer); 845 } else { 846 status = AE_ERROR; 847 goto out; 848 } 849 850 if (ret.eax & 0x1) 851 interface->capability |= ACER_CAP_WIRELESS; 852 853 args.ebx = 2 << 8; 854 args.ebx |= ACER_AMW0_BLUETOOTH_MASK; 855 856 /* 857 * It's ok to use existing buffer for next wmab_execute call. 858 * But we need to kfree(out.pointer) if next wmab_execute fail. 859 */ 860 status = wmab_execute(&args, &out); 861 if (ACPI_FAILURE(status)) 862 goto out; 863 864 obj = (union acpi_object *) out.pointer; 865 if (obj && obj->type == ACPI_TYPE_BUFFER 866 && obj->buffer.length == sizeof(struct wmab_ret)) { 867 ret = *((struct wmab_ret *) obj->buffer.pointer); 868 } else { 869 status = AE_ERROR; 870 goto out; 871 } 872 873 if (ret.eax & 0x1) 874 interface->capability |= ACER_CAP_BLUETOOTH; 875 876 /* 877 * This appears to be safe to enable, since all Wistron based laptops 878 * appear to use the same EC register for brightness, even if they 879 * differ for wireless, etc 880 */ 881 if (quirks->brightness >= 0) 882 interface->capability |= ACER_CAP_BRIGHTNESS; 883 884 status = AE_OK; 885 out: 886 kfree(out.pointer); 887 return status; 888 } 889 890 static struct wmi_interface AMW0_interface = { 891 .type = ACER_AMW0, 892 }; 893 894 static struct wmi_interface AMW0_V2_interface = { 895 .type = ACER_AMW0_V2, 896 }; 897 898 /* 899 * New interface (The WMID interface) 900 */ 901 static acpi_status 902 WMI_execute_u32(u32 method_id, u32 in, u32 *out) 903 { 904 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) }; 905 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL }; 906 union acpi_object *obj; 907 u32 tmp = 0; 908 acpi_status status; 909 910 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result); 911 912 if (ACPI_FAILURE(status)) 913 return status; 914 915 obj = (union acpi_object *) result.pointer; 916 if (obj) { 917 if (obj->type == ACPI_TYPE_BUFFER && 918 (obj->buffer.length == sizeof(u32) || 919 obj->buffer.length == sizeof(u64))) { 920 tmp = *((u32 *) obj->buffer.pointer); 921 } else if (obj->type == ACPI_TYPE_INTEGER) { 922 tmp = (u32) obj->integer.value; 923 } 924 } 925 926 if (out) 927 *out = tmp; 928 929 kfree(result.pointer); 930 931 return status; 932 } 933 934 static acpi_status WMID_get_u32(u32 *value, u32 cap) 935 { 936 acpi_status status; 937 u8 tmp; 938 u32 result, method_id = 0; 939 940 switch (cap) { 941 case ACER_CAP_WIRELESS: 942 method_id = ACER_WMID_GET_WIRELESS_METHODID; 943 break; 944 case ACER_CAP_BLUETOOTH: 945 method_id = ACER_WMID_GET_BLUETOOTH_METHODID; 946 break; 947 case ACER_CAP_BRIGHTNESS: 948 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID; 949 break; 950 case ACER_CAP_THREEG: 951 method_id = ACER_WMID_GET_THREEG_METHODID; 952 break; 953 case ACER_CAP_MAILLED: 954 if (quirks->mailled == 1) { 955 ec_read(0x9f, &tmp); 956 *value = tmp & 0x1; 957 return 0; 958 } 959 default: 960 return AE_ERROR; 961 } 962 status = WMI_execute_u32(method_id, 0, &result); 963 964 if (ACPI_SUCCESS(status)) 965 *value = (u8)result; 966 967 return status; 968 } 969 970 static acpi_status WMID_set_u32(u32 value, u32 cap) 971 { 972 u32 method_id = 0; 973 char param; 974 975 switch (cap) { 976 case ACER_CAP_BRIGHTNESS: 977 if (value > max_brightness) 978 return AE_BAD_PARAMETER; 979 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID; 980 break; 981 case ACER_CAP_WIRELESS: 982 if (value > 1) 983 return AE_BAD_PARAMETER; 984 method_id = ACER_WMID_SET_WIRELESS_METHODID; 985 break; 986 case ACER_CAP_BLUETOOTH: 987 if (value > 1) 988 return AE_BAD_PARAMETER; 989 method_id = ACER_WMID_SET_BLUETOOTH_METHODID; 990 break; 991 case ACER_CAP_THREEG: 992 if (value > 1) 993 return AE_BAD_PARAMETER; 994 method_id = ACER_WMID_SET_THREEG_METHODID; 995 break; 996 case ACER_CAP_MAILLED: 997 if (value > 1) 998 return AE_BAD_PARAMETER; 999 if (quirks->mailled == 1) { 1000 param = value ? 0x92 : 0x93; 1001 i8042_lock_chip(); 1002 i8042_command(¶m, 0x1059); 1003 i8042_unlock_chip(); 1004 return 0; 1005 } 1006 break; 1007 default: 1008 return AE_ERROR; 1009 } 1010 return WMI_execute_u32(method_id, (u32)value, NULL); 1011 } 1012 1013 static acpi_status wmid3_get_device_status(u32 *value, u16 device) 1014 { 1015 struct wmid3_gds_return_value return_value; 1016 acpi_status status; 1017 union acpi_object *obj; 1018 struct wmid3_gds_get_input_param params = { 1019 .function_num = 0x1, 1020 .hotkey_number = commun_fn_key_number, 1021 .devices = device, 1022 }; 1023 struct acpi_buffer input = { 1024 sizeof(struct wmid3_gds_get_input_param), 1025 ¶ms 1026 }; 1027 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 1028 1029 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output); 1030 if (ACPI_FAILURE(status)) 1031 return status; 1032 1033 obj = output.pointer; 1034 1035 if (!obj) 1036 return AE_ERROR; 1037 else if (obj->type != ACPI_TYPE_BUFFER) { 1038 kfree(obj); 1039 return AE_ERROR; 1040 } 1041 if (obj->buffer.length != 8) { 1042 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1043 kfree(obj); 1044 return AE_ERROR; 1045 } 1046 1047 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); 1048 kfree(obj); 1049 1050 if (return_value.error_code || return_value.ec_return_value) 1051 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n", 1052 device, 1053 return_value.error_code, 1054 return_value.ec_return_value); 1055 else 1056 *value = !!(return_value.devices & device); 1057 1058 return status; 1059 } 1060 1061 static acpi_status wmid_v2_get_u32(u32 *value, u32 cap) 1062 { 1063 u16 device; 1064 1065 switch (cap) { 1066 case ACER_CAP_WIRELESS: 1067 device = ACER_WMID3_GDS_WIRELESS; 1068 break; 1069 case ACER_CAP_BLUETOOTH: 1070 device = ACER_WMID3_GDS_BLUETOOTH; 1071 break; 1072 case ACER_CAP_THREEG: 1073 device = ACER_WMID3_GDS_THREEG; 1074 break; 1075 default: 1076 return AE_ERROR; 1077 } 1078 return wmid3_get_device_status(value, device); 1079 } 1080 1081 static acpi_status wmid3_set_device_status(u32 value, u16 device) 1082 { 1083 struct wmid3_gds_return_value return_value; 1084 acpi_status status; 1085 union acpi_object *obj; 1086 u16 devices; 1087 struct wmid3_gds_get_input_param get_params = { 1088 .function_num = 0x1, 1089 .hotkey_number = commun_fn_key_number, 1090 .devices = commun_func_bitmap, 1091 }; 1092 struct acpi_buffer get_input = { 1093 sizeof(struct wmid3_gds_get_input_param), 1094 &get_params 1095 }; 1096 struct wmid3_gds_set_input_param set_params = { 1097 .function_num = 0x2, 1098 .hotkey_number = commun_fn_key_number, 1099 .devices = commun_func_bitmap, 1100 }; 1101 struct acpi_buffer set_input = { 1102 sizeof(struct wmid3_gds_set_input_param), 1103 &set_params 1104 }; 1105 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 1106 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL }; 1107 1108 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output); 1109 if (ACPI_FAILURE(status)) 1110 return status; 1111 1112 obj = output.pointer; 1113 1114 if (!obj) 1115 return AE_ERROR; 1116 else if (obj->type != ACPI_TYPE_BUFFER) { 1117 kfree(obj); 1118 return AE_ERROR; 1119 } 1120 if (obj->buffer.length != 8) { 1121 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1122 kfree(obj); 1123 return AE_ERROR; 1124 } 1125 1126 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); 1127 kfree(obj); 1128 1129 if (return_value.error_code || return_value.ec_return_value) { 1130 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n", 1131 return_value.error_code, 1132 return_value.ec_return_value); 1133 return status; 1134 } 1135 1136 devices = return_value.devices; 1137 set_params.devices = (value) ? (devices | device) : (devices & ~device); 1138 1139 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2); 1140 if (ACPI_FAILURE(status)) 1141 return status; 1142 1143 obj = output2.pointer; 1144 1145 if (!obj) 1146 return AE_ERROR; 1147 else if (obj->type != ACPI_TYPE_BUFFER) { 1148 kfree(obj); 1149 return AE_ERROR; 1150 } 1151 if (obj->buffer.length != 4) { 1152 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1153 kfree(obj); 1154 return AE_ERROR; 1155 } 1156 1157 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer); 1158 kfree(obj); 1159 1160 if (return_value.error_code || return_value.ec_return_value) 1161 pr_warn("Set Device Status failed: 0x%x - 0x%x\n", 1162 return_value.error_code, 1163 return_value.ec_return_value); 1164 1165 return status; 1166 } 1167 1168 static acpi_status wmid_v2_set_u32(u32 value, u32 cap) 1169 { 1170 u16 device; 1171 1172 switch (cap) { 1173 case ACER_CAP_WIRELESS: 1174 device = ACER_WMID3_GDS_WIRELESS; 1175 break; 1176 case ACER_CAP_BLUETOOTH: 1177 device = ACER_WMID3_GDS_BLUETOOTH; 1178 break; 1179 case ACER_CAP_THREEG: 1180 device = ACER_WMID3_GDS_THREEG; 1181 break; 1182 default: 1183 return AE_ERROR; 1184 } 1185 return wmid3_set_device_status(value, device); 1186 } 1187 1188 static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d) 1189 { 1190 struct hotkey_function_type_aa *type_aa; 1191 1192 /* We are looking for OEM-specific Type AAh */ 1193 if (header->type != 0xAA) 1194 return; 1195 1196 has_type_aa = true; 1197 type_aa = (struct hotkey_function_type_aa *) header; 1198 1199 pr_info("Function bitmap for Communication Button: 0x%x\n", 1200 type_aa->commun_func_bitmap); 1201 commun_func_bitmap = type_aa->commun_func_bitmap; 1202 1203 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS) 1204 interface->capability |= ACER_CAP_WIRELESS; 1205 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG) 1206 interface->capability |= ACER_CAP_THREEG; 1207 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH) 1208 interface->capability |= ACER_CAP_BLUETOOTH; 1209 1210 commun_fn_key_number = type_aa->commun_fn_key_number; 1211 } 1212 1213 static acpi_status __init WMID_set_capabilities(void) 1214 { 1215 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; 1216 union acpi_object *obj; 1217 acpi_status status; 1218 u32 devices; 1219 1220 status = wmi_query_block(WMID_GUID2, 1, &out); 1221 if (ACPI_FAILURE(status)) 1222 return status; 1223 1224 obj = (union acpi_object *) out.pointer; 1225 if (obj) { 1226 if (obj->type == ACPI_TYPE_BUFFER && 1227 (obj->buffer.length == sizeof(u32) || 1228 obj->buffer.length == sizeof(u64))) { 1229 devices = *((u32 *) obj->buffer.pointer); 1230 } else if (obj->type == ACPI_TYPE_INTEGER) { 1231 devices = (u32) obj->integer.value; 1232 } else { 1233 kfree(out.pointer); 1234 return AE_ERROR; 1235 } 1236 } else { 1237 kfree(out.pointer); 1238 return AE_ERROR; 1239 } 1240 1241 pr_info("Function bitmap for Communication Device: 0x%x\n", devices); 1242 if (devices & 0x07) 1243 interface->capability |= ACER_CAP_WIRELESS; 1244 if (devices & 0x40) 1245 interface->capability |= ACER_CAP_THREEG; 1246 if (devices & 0x10) 1247 interface->capability |= ACER_CAP_BLUETOOTH; 1248 1249 if (!(devices & 0x20)) 1250 max_brightness = 0x9; 1251 1252 kfree(out.pointer); 1253 return status; 1254 } 1255 1256 static struct wmi_interface wmid_interface = { 1257 .type = ACER_WMID, 1258 }; 1259 1260 static struct wmi_interface wmid_v2_interface = { 1261 .type = ACER_WMID_v2, 1262 }; 1263 1264 /* 1265 * Generic Device (interface-independent) 1266 */ 1267 1268 static acpi_status get_u32(u32 *value, u32 cap) 1269 { 1270 acpi_status status = AE_ERROR; 1271 1272 switch (interface->type) { 1273 case ACER_AMW0: 1274 status = AMW0_get_u32(value, cap); 1275 break; 1276 case ACER_AMW0_V2: 1277 if (cap == ACER_CAP_MAILLED) { 1278 status = AMW0_get_u32(value, cap); 1279 break; 1280 } 1281 case ACER_WMID: 1282 status = WMID_get_u32(value, cap); 1283 break; 1284 case ACER_WMID_v2: 1285 if (cap & (ACER_CAP_WIRELESS | 1286 ACER_CAP_BLUETOOTH | 1287 ACER_CAP_THREEG)) 1288 status = wmid_v2_get_u32(value, cap); 1289 else if (wmi_has_guid(WMID_GUID2)) 1290 status = WMID_get_u32(value, cap); 1291 break; 1292 } 1293 1294 return status; 1295 } 1296 1297 static acpi_status set_u32(u32 value, u32 cap) 1298 { 1299 acpi_status status; 1300 1301 if (interface->capability & cap) { 1302 switch (interface->type) { 1303 case ACER_AMW0: 1304 return AMW0_set_u32(value, cap); 1305 case ACER_AMW0_V2: 1306 if (cap == ACER_CAP_MAILLED) 1307 return AMW0_set_u32(value, cap); 1308 1309 /* 1310 * On some models, some WMID methods don't toggle 1311 * properly. For those cases, we want to run the AMW0 1312 * method afterwards to be certain we've really toggled 1313 * the device state. 1314 */ 1315 if (cap == ACER_CAP_WIRELESS || 1316 cap == ACER_CAP_BLUETOOTH) { 1317 status = WMID_set_u32(value, cap); 1318 if (ACPI_FAILURE(status)) 1319 return status; 1320 1321 return AMW0_set_u32(value, cap); 1322 } 1323 case ACER_WMID: 1324 return WMID_set_u32(value, cap); 1325 case ACER_WMID_v2: 1326 if (cap & (ACER_CAP_WIRELESS | 1327 ACER_CAP_BLUETOOTH | 1328 ACER_CAP_THREEG)) 1329 return wmid_v2_set_u32(value, cap); 1330 else if (wmi_has_guid(WMID_GUID2)) 1331 return WMID_set_u32(value, cap); 1332 default: 1333 return AE_BAD_PARAMETER; 1334 } 1335 } 1336 return AE_BAD_PARAMETER; 1337 } 1338 1339 static void __init acer_commandline_init(void) 1340 { 1341 /* 1342 * These will all fail silently if the value given is invalid, or the 1343 * capability isn't available on the given interface 1344 */ 1345 if (mailled >= 0) 1346 set_u32(mailled, ACER_CAP_MAILLED); 1347 if (!has_type_aa && threeg >= 0) 1348 set_u32(threeg, ACER_CAP_THREEG); 1349 if (brightness >= 0) 1350 set_u32(brightness, ACER_CAP_BRIGHTNESS); 1351 } 1352 1353 /* 1354 * LED device (Mail LED only, no other LEDs known yet) 1355 */ 1356 static void mail_led_set(struct led_classdev *led_cdev, 1357 enum led_brightness value) 1358 { 1359 set_u32(value, ACER_CAP_MAILLED); 1360 } 1361 1362 static struct led_classdev mail_led = { 1363 .name = "acer-wmi::mail", 1364 .brightness_set = mail_led_set, 1365 }; 1366 1367 static int acer_led_init(struct device *dev) 1368 { 1369 return led_classdev_register(dev, &mail_led); 1370 } 1371 1372 static void acer_led_exit(void) 1373 { 1374 set_u32(LED_OFF, ACER_CAP_MAILLED); 1375 led_classdev_unregister(&mail_led); 1376 } 1377 1378 /* 1379 * Backlight device 1380 */ 1381 static struct backlight_device *acer_backlight_device; 1382 1383 static int read_brightness(struct backlight_device *bd) 1384 { 1385 u32 value; 1386 get_u32(&value, ACER_CAP_BRIGHTNESS); 1387 return value; 1388 } 1389 1390 static int update_bl_status(struct backlight_device *bd) 1391 { 1392 int intensity = bd->props.brightness; 1393 1394 if (bd->props.power != FB_BLANK_UNBLANK) 1395 intensity = 0; 1396 if (bd->props.fb_blank != FB_BLANK_UNBLANK) 1397 intensity = 0; 1398 1399 set_u32(intensity, ACER_CAP_BRIGHTNESS); 1400 1401 return 0; 1402 } 1403 1404 static const struct backlight_ops acer_bl_ops = { 1405 .get_brightness = read_brightness, 1406 .update_status = update_bl_status, 1407 }; 1408 1409 static int acer_backlight_init(struct device *dev) 1410 { 1411 struct backlight_properties props; 1412 struct backlight_device *bd; 1413 1414 memset(&props, 0, sizeof(struct backlight_properties)); 1415 props.type = BACKLIGHT_PLATFORM; 1416 props.max_brightness = max_brightness; 1417 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops, 1418 &props); 1419 if (IS_ERR(bd)) { 1420 pr_err("Could not register Acer backlight device\n"); 1421 acer_backlight_device = NULL; 1422 return PTR_ERR(bd); 1423 } 1424 1425 acer_backlight_device = bd; 1426 1427 bd->props.power = FB_BLANK_UNBLANK; 1428 bd->props.brightness = read_brightness(bd); 1429 backlight_update_status(bd); 1430 return 0; 1431 } 1432 1433 static void acer_backlight_exit(void) 1434 { 1435 backlight_device_unregister(acer_backlight_device); 1436 } 1437 1438 /* 1439 * Accelerometer device 1440 */ 1441 static acpi_handle gsensor_handle; 1442 1443 static int acer_gsensor_init(void) 1444 { 1445 acpi_status status; 1446 struct acpi_buffer output; 1447 union acpi_object out_obj; 1448 1449 output.length = sizeof(out_obj); 1450 output.pointer = &out_obj; 1451 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output); 1452 if (ACPI_FAILURE(status)) 1453 return -1; 1454 1455 return 0; 1456 } 1457 1458 static int acer_gsensor_open(struct input_dev *input) 1459 { 1460 return acer_gsensor_init(); 1461 } 1462 1463 static int acer_gsensor_event(void) 1464 { 1465 acpi_status status; 1466 struct acpi_buffer output; 1467 union acpi_object out_obj[5]; 1468 1469 if (!has_cap(ACER_CAP_ACCEL)) 1470 return -1; 1471 1472 output.length = sizeof(out_obj); 1473 output.pointer = out_obj; 1474 1475 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output); 1476 if (ACPI_FAILURE(status)) 1477 return -1; 1478 1479 if (out_obj->package.count != 4) 1480 return -1; 1481 1482 input_report_abs(acer_wmi_accel_dev, ABS_X, 1483 (s16)out_obj->package.elements[0].integer.value); 1484 input_report_abs(acer_wmi_accel_dev, ABS_Y, 1485 (s16)out_obj->package.elements[1].integer.value); 1486 input_report_abs(acer_wmi_accel_dev, ABS_Z, 1487 (s16)out_obj->package.elements[2].integer.value); 1488 input_sync(acer_wmi_accel_dev); 1489 return 0; 1490 } 1491 1492 /* 1493 * Rfkill devices 1494 */ 1495 static void acer_rfkill_update(struct work_struct *ignored); 1496 static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update); 1497 static void acer_rfkill_update(struct work_struct *ignored) 1498 { 1499 u32 state; 1500 acpi_status status; 1501 1502 if (has_cap(ACER_CAP_WIRELESS)) { 1503 status = get_u32(&state, ACER_CAP_WIRELESS); 1504 if (ACPI_SUCCESS(status)) { 1505 if (quirks->wireless == 3) 1506 rfkill_set_hw_state(wireless_rfkill, !state); 1507 else 1508 rfkill_set_sw_state(wireless_rfkill, !state); 1509 } 1510 } 1511 1512 if (has_cap(ACER_CAP_BLUETOOTH)) { 1513 status = get_u32(&state, ACER_CAP_BLUETOOTH); 1514 if (ACPI_SUCCESS(status)) 1515 rfkill_set_sw_state(bluetooth_rfkill, !state); 1516 } 1517 1518 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) { 1519 status = get_u32(&state, ACER_WMID3_GDS_THREEG); 1520 if (ACPI_SUCCESS(status)) 1521 rfkill_set_sw_state(threeg_rfkill, !state); 1522 } 1523 1524 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); 1525 } 1526 1527 static int acer_rfkill_set(void *data, bool blocked) 1528 { 1529 acpi_status status; 1530 u32 cap = (unsigned long)data; 1531 1532 if (rfkill_inited) { 1533 status = set_u32(!blocked, cap); 1534 if (ACPI_FAILURE(status)) 1535 return -ENODEV; 1536 } 1537 1538 return 0; 1539 } 1540 1541 static const struct rfkill_ops acer_rfkill_ops = { 1542 .set_block = acer_rfkill_set, 1543 }; 1544 1545 static struct rfkill *acer_rfkill_register(struct device *dev, 1546 enum rfkill_type type, 1547 char *name, u32 cap) 1548 { 1549 int err; 1550 struct rfkill *rfkill_dev; 1551 u32 state; 1552 acpi_status status; 1553 1554 rfkill_dev = rfkill_alloc(name, dev, type, 1555 &acer_rfkill_ops, 1556 (void *)(unsigned long)cap); 1557 if (!rfkill_dev) 1558 return ERR_PTR(-ENOMEM); 1559 1560 status = get_u32(&state, cap); 1561 1562 err = rfkill_register(rfkill_dev); 1563 if (err) { 1564 rfkill_destroy(rfkill_dev); 1565 return ERR_PTR(err); 1566 } 1567 1568 if (ACPI_SUCCESS(status)) 1569 rfkill_set_sw_state(rfkill_dev, !state); 1570 1571 return rfkill_dev; 1572 } 1573 1574 static int acer_rfkill_init(struct device *dev) 1575 { 1576 int err; 1577 1578 if (has_cap(ACER_CAP_WIRELESS)) { 1579 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN, 1580 "acer-wireless", ACER_CAP_WIRELESS); 1581 if (IS_ERR(wireless_rfkill)) { 1582 err = PTR_ERR(wireless_rfkill); 1583 goto error_wireless; 1584 } 1585 } 1586 1587 if (has_cap(ACER_CAP_BLUETOOTH)) { 1588 bluetooth_rfkill = acer_rfkill_register(dev, 1589 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth", 1590 ACER_CAP_BLUETOOTH); 1591 if (IS_ERR(bluetooth_rfkill)) { 1592 err = PTR_ERR(bluetooth_rfkill); 1593 goto error_bluetooth; 1594 } 1595 } 1596 1597 if (has_cap(ACER_CAP_THREEG)) { 1598 threeg_rfkill = acer_rfkill_register(dev, 1599 RFKILL_TYPE_WWAN, "acer-threeg", 1600 ACER_CAP_THREEG); 1601 if (IS_ERR(threeg_rfkill)) { 1602 err = PTR_ERR(threeg_rfkill); 1603 goto error_threeg; 1604 } 1605 } 1606 1607 rfkill_inited = true; 1608 1609 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) && 1610 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG)) 1611 schedule_delayed_work(&acer_rfkill_work, 1612 round_jiffies_relative(HZ)); 1613 1614 return 0; 1615 1616 error_threeg: 1617 if (has_cap(ACER_CAP_BLUETOOTH)) { 1618 rfkill_unregister(bluetooth_rfkill); 1619 rfkill_destroy(bluetooth_rfkill); 1620 } 1621 error_bluetooth: 1622 if (has_cap(ACER_CAP_WIRELESS)) { 1623 rfkill_unregister(wireless_rfkill); 1624 rfkill_destroy(wireless_rfkill); 1625 } 1626 error_wireless: 1627 return err; 1628 } 1629 1630 static void acer_rfkill_exit(void) 1631 { 1632 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) && 1633 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG)) 1634 cancel_delayed_work_sync(&acer_rfkill_work); 1635 1636 if (has_cap(ACER_CAP_WIRELESS)) { 1637 rfkill_unregister(wireless_rfkill); 1638 rfkill_destroy(wireless_rfkill); 1639 } 1640 1641 if (has_cap(ACER_CAP_BLUETOOTH)) { 1642 rfkill_unregister(bluetooth_rfkill); 1643 rfkill_destroy(bluetooth_rfkill); 1644 } 1645 1646 if (has_cap(ACER_CAP_THREEG)) { 1647 rfkill_unregister(threeg_rfkill); 1648 rfkill_destroy(threeg_rfkill); 1649 } 1650 return; 1651 } 1652 1653 /* 1654 * sysfs interface 1655 */ 1656 static ssize_t show_bool_threeg(struct device *dev, 1657 struct device_attribute *attr, char *buf) 1658 { 1659 u32 result; \ 1660 acpi_status status; 1661 1662 pr_info("This threeg sysfs will be removed in 2014 - used by: %s\n", 1663 current->comm); 1664 status = get_u32(&result, ACER_CAP_THREEG); 1665 if (ACPI_SUCCESS(status)) 1666 return sprintf(buf, "%u\n", result); 1667 return sprintf(buf, "Read error\n"); 1668 } 1669 1670 static ssize_t set_bool_threeg(struct device *dev, 1671 struct device_attribute *attr, const char *buf, size_t count) 1672 { 1673 u32 tmp = simple_strtoul(buf, NULL, 10); 1674 acpi_status status = set_u32(tmp, ACER_CAP_THREEG); 1675 pr_info("This threeg sysfs will be removed in 2014 - used by: %s\n", 1676 current->comm); 1677 if (ACPI_FAILURE(status)) 1678 return -EINVAL; 1679 return count; 1680 } 1681 static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg, 1682 set_bool_threeg); 1683 1684 static ssize_t show_interface(struct device *dev, struct device_attribute *attr, 1685 char *buf) 1686 { 1687 pr_info("This interface sysfs will be removed in 2014 - used by: %s\n", 1688 current->comm); 1689 switch (interface->type) { 1690 case ACER_AMW0: 1691 return sprintf(buf, "AMW0\n"); 1692 case ACER_AMW0_V2: 1693 return sprintf(buf, "AMW0 v2\n"); 1694 case ACER_WMID: 1695 return sprintf(buf, "WMID\n"); 1696 case ACER_WMID_v2: 1697 return sprintf(buf, "WMID v2\n"); 1698 default: 1699 return sprintf(buf, "Error!\n"); 1700 } 1701 } 1702 1703 static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL); 1704 1705 static void acer_wmi_notify(u32 value, void *context) 1706 { 1707 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; 1708 union acpi_object *obj; 1709 struct event_return_value return_value; 1710 acpi_status status; 1711 u16 device_state; 1712 const struct key_entry *key; 1713 u32 scancode; 1714 1715 status = wmi_get_event_data(value, &response); 1716 if (status != AE_OK) { 1717 pr_warn("bad event status 0x%x\n", status); 1718 return; 1719 } 1720 1721 obj = (union acpi_object *)response.pointer; 1722 1723 if (!obj) 1724 return; 1725 if (obj->type != ACPI_TYPE_BUFFER) { 1726 pr_warn("Unknown response received %d\n", obj->type); 1727 kfree(obj); 1728 return; 1729 } 1730 if (obj->buffer.length != 8) { 1731 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1732 kfree(obj); 1733 return; 1734 } 1735 1736 return_value = *((struct event_return_value *)obj->buffer.pointer); 1737 kfree(obj); 1738 1739 switch (return_value.function) { 1740 case WMID_HOTKEY_EVENT: 1741 device_state = return_value.device_state; 1742 pr_debug("device state: 0x%x\n", device_state); 1743 1744 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev, 1745 return_value.key_num); 1746 if (!key) { 1747 pr_warn("Unknown key number - 0x%x\n", 1748 return_value.key_num); 1749 } else { 1750 scancode = return_value.key_num; 1751 switch (key->keycode) { 1752 case KEY_WLAN: 1753 case KEY_BLUETOOTH: 1754 if (has_cap(ACER_CAP_WIRELESS)) 1755 rfkill_set_sw_state(wireless_rfkill, 1756 !(device_state & ACER_WMID3_GDS_WIRELESS)); 1757 if (has_cap(ACER_CAP_THREEG)) 1758 rfkill_set_sw_state(threeg_rfkill, 1759 !(device_state & ACER_WMID3_GDS_THREEG)); 1760 if (has_cap(ACER_CAP_BLUETOOTH)) 1761 rfkill_set_sw_state(bluetooth_rfkill, 1762 !(device_state & ACER_WMID3_GDS_BLUETOOTH)); 1763 break; 1764 case KEY_TOUCHPAD_TOGGLE: 1765 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ? 1766 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF; 1767 } 1768 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true); 1769 } 1770 break; 1771 case WMID_ACCEL_EVENT: 1772 acer_gsensor_event(); 1773 break; 1774 default: 1775 pr_warn("Unknown function number - %d - %d\n", 1776 return_value.function, return_value.key_num); 1777 break; 1778 } 1779 } 1780 1781 static acpi_status __init 1782 wmid3_set_lm_mode(struct lm_input_params *params, 1783 struct lm_return_value *return_value) 1784 { 1785 acpi_status status; 1786 union acpi_object *obj; 1787 1788 struct acpi_buffer input = { sizeof(struct lm_input_params), params }; 1789 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; 1790 1791 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output); 1792 if (ACPI_FAILURE(status)) 1793 return status; 1794 1795 obj = output.pointer; 1796 1797 if (!obj) 1798 return AE_ERROR; 1799 else if (obj->type != ACPI_TYPE_BUFFER) { 1800 kfree(obj); 1801 return AE_ERROR; 1802 } 1803 if (obj->buffer.length != 4) { 1804 pr_warn("Unknown buffer length %d\n", obj->buffer.length); 1805 kfree(obj); 1806 return AE_ERROR; 1807 } 1808 1809 *return_value = *((struct lm_return_value *)obj->buffer.pointer); 1810 kfree(obj); 1811 1812 return status; 1813 } 1814 1815 static int __init acer_wmi_enable_ec_raw(void) 1816 { 1817 struct lm_return_value return_value; 1818 acpi_status status; 1819 struct lm_input_params params = { 1820 .function_num = 0x1, 1821 .commun_devices = 0xFFFF, 1822 .devices = 0xFFFF, 1823 .lm_status = 0x00, /* Launch Manager Deactive */ 1824 }; 1825 1826 status = wmid3_set_lm_mode(¶ms, &return_value); 1827 1828 if (return_value.error_code || return_value.ec_return_value) 1829 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n", 1830 return_value.error_code, 1831 return_value.ec_return_value); 1832 else 1833 pr_info("Enabled EC raw mode\n"); 1834 1835 return status; 1836 } 1837 1838 static int __init acer_wmi_enable_lm(void) 1839 { 1840 struct lm_return_value return_value; 1841 acpi_status status; 1842 struct lm_input_params params = { 1843 .function_num = 0x1, 1844 .commun_devices = 0xFFFF, 1845 .devices = 0xFFFF, 1846 .lm_status = 0x01, /* Launch Manager Active */ 1847 }; 1848 1849 status = wmid3_set_lm_mode(¶ms, &return_value); 1850 1851 if (return_value.error_code || return_value.ec_return_value) 1852 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n", 1853 return_value.error_code, 1854 return_value.ec_return_value); 1855 1856 return status; 1857 } 1858 1859 static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level, 1860 void *ctx, void **retval) 1861 { 1862 *(acpi_handle *)retval = ah; 1863 return AE_OK; 1864 } 1865 1866 static int __init acer_wmi_get_handle(const char *name, const char *prop, 1867 acpi_handle *ah) 1868 { 1869 acpi_status status; 1870 acpi_handle handle; 1871 1872 BUG_ON(!name || !ah); 1873 1874 handle = NULL; 1875 status = acpi_get_devices(prop, acer_wmi_get_handle_cb, 1876 (void *)name, &handle); 1877 1878 if (ACPI_SUCCESS(status)) { 1879 *ah = handle; 1880 return 0; 1881 } else { 1882 return -ENODEV; 1883 } 1884 } 1885 1886 static int __init acer_wmi_accel_setup(void) 1887 { 1888 int err; 1889 1890 err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle); 1891 if (err) 1892 return err; 1893 1894 interface->capability |= ACER_CAP_ACCEL; 1895 1896 acer_wmi_accel_dev = input_allocate_device(); 1897 if (!acer_wmi_accel_dev) 1898 return -ENOMEM; 1899 1900 acer_wmi_accel_dev->open = acer_gsensor_open; 1901 1902 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer"; 1903 acer_wmi_accel_dev->phys = "wmi/input1"; 1904 acer_wmi_accel_dev->id.bustype = BUS_HOST; 1905 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS); 1906 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0); 1907 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0); 1908 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0); 1909 1910 err = input_register_device(acer_wmi_accel_dev); 1911 if (err) 1912 goto err_free_dev; 1913 1914 return 0; 1915 1916 err_free_dev: 1917 input_free_device(acer_wmi_accel_dev); 1918 return err; 1919 } 1920 1921 static void acer_wmi_accel_destroy(void) 1922 { 1923 input_unregister_device(acer_wmi_accel_dev); 1924 } 1925 1926 static int __init acer_wmi_input_setup(void) 1927 { 1928 acpi_status status; 1929 int err; 1930 1931 acer_wmi_input_dev = input_allocate_device(); 1932 if (!acer_wmi_input_dev) 1933 return -ENOMEM; 1934 1935 acer_wmi_input_dev->name = "Acer WMI hotkeys"; 1936 acer_wmi_input_dev->phys = "wmi/input0"; 1937 acer_wmi_input_dev->id.bustype = BUS_HOST; 1938 1939 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL); 1940 if (err) 1941 goto err_free_dev; 1942 1943 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID, 1944 acer_wmi_notify, NULL); 1945 if (ACPI_FAILURE(status)) { 1946 err = -EIO; 1947 goto err_free_keymap; 1948 } 1949 1950 err = input_register_device(acer_wmi_input_dev); 1951 if (err) 1952 goto err_uninstall_notifier; 1953 1954 return 0; 1955 1956 err_uninstall_notifier: 1957 wmi_remove_notify_handler(ACERWMID_EVENT_GUID); 1958 err_free_keymap: 1959 sparse_keymap_free(acer_wmi_input_dev); 1960 err_free_dev: 1961 input_free_device(acer_wmi_input_dev); 1962 return err; 1963 } 1964 1965 static void acer_wmi_input_destroy(void) 1966 { 1967 wmi_remove_notify_handler(ACERWMID_EVENT_GUID); 1968 sparse_keymap_free(acer_wmi_input_dev); 1969 input_unregister_device(acer_wmi_input_dev); 1970 } 1971 1972 /* 1973 * debugfs functions 1974 */ 1975 static u32 get_wmid_devices(void) 1976 { 1977 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; 1978 union acpi_object *obj; 1979 acpi_status status; 1980 u32 devices = 0; 1981 1982 status = wmi_query_block(WMID_GUID2, 1, &out); 1983 if (ACPI_FAILURE(status)) 1984 return 0; 1985 1986 obj = (union acpi_object *) out.pointer; 1987 if (obj) { 1988 if (obj->type == ACPI_TYPE_BUFFER && 1989 (obj->buffer.length == sizeof(u32) || 1990 obj->buffer.length == sizeof(u64))) { 1991 devices = *((u32 *) obj->buffer.pointer); 1992 } else if (obj->type == ACPI_TYPE_INTEGER) { 1993 devices = (u32) obj->integer.value; 1994 } 1995 } 1996 1997 kfree(out.pointer); 1998 return devices; 1999 } 2000 2001 /* 2002 * Platform device 2003 */ 2004 static int acer_platform_probe(struct platform_device *device) 2005 { 2006 int err; 2007 2008 if (has_cap(ACER_CAP_MAILLED)) { 2009 err = acer_led_init(&device->dev); 2010 if (err) 2011 goto error_mailled; 2012 } 2013 2014 if (has_cap(ACER_CAP_BRIGHTNESS)) { 2015 err = acer_backlight_init(&device->dev); 2016 if (err) 2017 goto error_brightness; 2018 } 2019 2020 err = acer_rfkill_init(&device->dev); 2021 if (err) 2022 goto error_rfkill; 2023 2024 return err; 2025 2026 error_rfkill: 2027 if (has_cap(ACER_CAP_BRIGHTNESS)) 2028 acer_backlight_exit(); 2029 error_brightness: 2030 if (has_cap(ACER_CAP_MAILLED)) 2031 acer_led_exit(); 2032 error_mailled: 2033 return err; 2034 } 2035 2036 static int acer_platform_remove(struct platform_device *device) 2037 { 2038 if (has_cap(ACER_CAP_MAILLED)) 2039 acer_led_exit(); 2040 if (has_cap(ACER_CAP_BRIGHTNESS)) 2041 acer_backlight_exit(); 2042 2043 acer_rfkill_exit(); 2044 return 0; 2045 } 2046 2047 #ifdef CONFIG_PM_SLEEP 2048 static int acer_suspend(struct device *dev) 2049 { 2050 u32 value; 2051 struct acer_data *data = &interface->data; 2052 2053 if (!data) 2054 return -ENOMEM; 2055 2056 if (has_cap(ACER_CAP_MAILLED)) { 2057 get_u32(&value, ACER_CAP_MAILLED); 2058 set_u32(LED_OFF, ACER_CAP_MAILLED); 2059 data->mailled = value; 2060 } 2061 2062 if (has_cap(ACER_CAP_BRIGHTNESS)) { 2063 get_u32(&value, ACER_CAP_BRIGHTNESS); 2064 data->brightness = value; 2065 } 2066 2067 return 0; 2068 } 2069 2070 static int acer_resume(struct device *dev) 2071 { 2072 struct acer_data *data = &interface->data; 2073 2074 if (!data) 2075 return -ENOMEM; 2076 2077 if (has_cap(ACER_CAP_MAILLED)) 2078 set_u32(data->mailled, ACER_CAP_MAILLED); 2079 2080 if (has_cap(ACER_CAP_BRIGHTNESS)) 2081 set_u32(data->brightness, ACER_CAP_BRIGHTNESS); 2082 2083 if (has_cap(ACER_CAP_ACCEL)) 2084 acer_gsensor_init(); 2085 2086 return 0; 2087 } 2088 #else 2089 #define acer_suspend NULL 2090 #define acer_resume NULL 2091 #endif 2092 2093 static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume); 2094 2095 static void acer_platform_shutdown(struct platform_device *device) 2096 { 2097 struct acer_data *data = &interface->data; 2098 2099 if (!data) 2100 return; 2101 2102 if (has_cap(ACER_CAP_MAILLED)) 2103 set_u32(LED_OFF, ACER_CAP_MAILLED); 2104 } 2105 2106 static struct platform_driver acer_platform_driver = { 2107 .driver = { 2108 .name = "acer-wmi", 2109 .owner = THIS_MODULE, 2110 .pm = &acer_pm, 2111 }, 2112 .probe = acer_platform_probe, 2113 .remove = acer_platform_remove, 2114 .shutdown = acer_platform_shutdown, 2115 }; 2116 2117 static struct platform_device *acer_platform_device; 2118 2119 static int remove_sysfs(struct platform_device *device) 2120 { 2121 if (has_cap(ACER_CAP_THREEG)) 2122 device_remove_file(&device->dev, &dev_attr_threeg); 2123 2124 device_remove_file(&device->dev, &dev_attr_interface); 2125 2126 return 0; 2127 } 2128 2129 static int __init create_sysfs(void) 2130 { 2131 int retval = -ENOMEM; 2132 2133 if (has_cap(ACER_CAP_THREEG)) { 2134 retval = device_create_file(&acer_platform_device->dev, 2135 &dev_attr_threeg); 2136 if (retval) 2137 goto error_sysfs; 2138 } 2139 2140 retval = device_create_file(&acer_platform_device->dev, 2141 &dev_attr_interface); 2142 if (retval) 2143 goto error_sysfs; 2144 2145 return 0; 2146 2147 error_sysfs: 2148 remove_sysfs(acer_platform_device); 2149 return retval; 2150 } 2151 2152 static void remove_debugfs(void) 2153 { 2154 debugfs_remove(interface->debug.devices); 2155 debugfs_remove(interface->debug.root); 2156 } 2157 2158 static int __init create_debugfs(void) 2159 { 2160 interface->debug.root = debugfs_create_dir("acer-wmi", NULL); 2161 if (!interface->debug.root) { 2162 pr_err("Failed to create debugfs directory"); 2163 return -ENOMEM; 2164 } 2165 2166 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO, 2167 interface->debug.root, 2168 &interface->debug.wmid_devices); 2169 if (!interface->debug.devices) 2170 goto error_debugfs; 2171 2172 return 0; 2173 2174 error_debugfs: 2175 remove_debugfs(); 2176 return -ENOMEM; 2177 } 2178 2179 static int __init acer_wmi_init(void) 2180 { 2181 int err; 2182 2183 pr_info("Acer Laptop ACPI-WMI Extras\n"); 2184 2185 if (dmi_check_system(acer_blacklist)) { 2186 pr_info("Blacklisted hardware detected - not loading\n"); 2187 return -ENODEV; 2188 } 2189 2190 find_quirks(); 2191 2192 /* 2193 * Detect which ACPI-WMI interface we're using. 2194 */ 2195 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) 2196 interface = &AMW0_V2_interface; 2197 2198 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) 2199 interface = &wmid_interface; 2200 2201 if (wmi_has_guid(WMID_GUID3)) 2202 interface = &wmid_v2_interface; 2203 2204 if (interface) 2205 dmi_walk(type_aa_dmi_decode, NULL); 2206 2207 if (wmi_has_guid(WMID_GUID2) && interface) { 2208 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) { 2209 pr_err("Unable to detect available WMID devices\n"); 2210 return -ENODEV; 2211 } 2212 /* WMID always provides brightness methods */ 2213 interface->capability |= ACER_CAP_BRIGHTNESS; 2214 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) { 2215 pr_err("No WMID device detection method found\n"); 2216 return -ENODEV; 2217 } 2218 2219 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) { 2220 interface = &AMW0_interface; 2221 2222 if (ACPI_FAILURE(AMW0_set_capabilities())) { 2223 pr_err("Unable to detect available AMW0 devices\n"); 2224 return -ENODEV; 2225 } 2226 } 2227 2228 if (wmi_has_guid(AMW0_GUID1)) 2229 AMW0_find_mailled(); 2230 2231 if (!interface) { 2232 pr_err("No or unsupported WMI interface, unable to load\n"); 2233 return -ENODEV; 2234 } 2235 2236 set_quirks(); 2237 2238 if (dmi_check_system(video_vendor_dmi_table)) 2239 acpi_video_dmi_promote_vendor(); 2240 if (acpi_video_backlight_support()) { 2241 interface->capability &= ~ACER_CAP_BRIGHTNESS; 2242 pr_info("Brightness must be controlled by acpi video driver\n"); 2243 } else { 2244 pr_info("Disabling ACPI video driver\n"); 2245 acpi_video_unregister_backlight(); 2246 } 2247 2248 if (wmi_has_guid(WMID_GUID3)) { 2249 if (ec_raw_mode) { 2250 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) { 2251 pr_err("Cannot enable EC raw mode\n"); 2252 return -ENODEV; 2253 } 2254 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) { 2255 pr_err("Cannot enable Launch Manager mode\n"); 2256 return -ENODEV; 2257 } 2258 } else if (ec_raw_mode) { 2259 pr_info("No WMID EC raw mode enable method\n"); 2260 } 2261 2262 if (wmi_has_guid(ACERWMID_EVENT_GUID)) { 2263 err = acer_wmi_input_setup(); 2264 if (err) 2265 return err; 2266 } 2267 2268 acer_wmi_accel_setup(); 2269 2270 err = platform_driver_register(&acer_platform_driver); 2271 if (err) { 2272 pr_err("Unable to register platform driver\n"); 2273 goto error_platform_register; 2274 } 2275 2276 acer_platform_device = platform_device_alloc("acer-wmi", -1); 2277 if (!acer_platform_device) { 2278 err = -ENOMEM; 2279 goto error_device_alloc; 2280 } 2281 2282 err = platform_device_add(acer_platform_device); 2283 if (err) 2284 goto error_device_add; 2285 2286 err = create_sysfs(); 2287 if (err) 2288 goto error_create_sys; 2289 2290 if (wmi_has_guid(WMID_GUID2)) { 2291 interface->debug.wmid_devices = get_wmid_devices(); 2292 err = create_debugfs(); 2293 if (err) 2294 goto error_create_debugfs; 2295 } 2296 2297 /* Override any initial settings with values from the commandline */ 2298 acer_commandline_init(); 2299 2300 return 0; 2301 2302 error_create_debugfs: 2303 remove_sysfs(acer_platform_device); 2304 error_create_sys: 2305 platform_device_del(acer_platform_device); 2306 error_device_add: 2307 platform_device_put(acer_platform_device); 2308 error_device_alloc: 2309 platform_driver_unregister(&acer_platform_driver); 2310 error_platform_register: 2311 if (wmi_has_guid(ACERWMID_EVENT_GUID)) 2312 acer_wmi_input_destroy(); 2313 if (has_cap(ACER_CAP_ACCEL)) 2314 acer_wmi_accel_destroy(); 2315 2316 return err; 2317 } 2318 2319 static void __exit acer_wmi_exit(void) 2320 { 2321 if (wmi_has_guid(ACERWMID_EVENT_GUID)) 2322 acer_wmi_input_destroy(); 2323 2324 if (has_cap(ACER_CAP_ACCEL)) 2325 acer_wmi_accel_destroy(); 2326 2327 remove_sysfs(acer_platform_device); 2328 remove_debugfs(); 2329 platform_device_unregister(acer_platform_device); 2330 platform_driver_unregister(&acer_platform_driver); 2331 2332 pr_info("Acer Laptop WMI Extras unloaded\n"); 2333 return; 2334 } 2335 2336 module_init(acer_wmi_init); 2337 module_exit(acer_wmi_exit); 2338