1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Acer WMI Laptop Extras
5 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
8 * Copyright (C) 2005-2007 E.M. Smith
9 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/types.h>
18 #include <linux/dmi.h>
20 #include <linux/backlight.h>
21 #include <linux/leds.h>
22 #include <linux/platform_device.h>
23 #include <linux/acpi.h>
24 #include <linux/i8042.h>
25 #include <linux/rfkill.h>
26 #include <linux/workqueue.h>
27 #include <linux/debugfs.h>
28 #include <linux/slab.h>
29 #include <linux/input.h>
30 #include <linux/input/sparse-keymap.h>
31 #include <acpi/video.h>
33 ACPI_MODULE_NAME(KBUILD_MODNAME
);
34 MODULE_AUTHOR("Carlos Corbacho");
35 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
36 MODULE_LICENSE("GPL");
40 * Meaning is unknown - this number is required for writing to ACPI for AMW0
41 * (it's also used in acerhk when directly accessing the BIOS)
43 #define ACER_AMW0_WRITE 0x9610
46 * Bit masks for the AMW0 interface
48 #define ACER_AMW0_WIRELESS_MASK 0x35
49 #define ACER_AMW0_BLUETOOTH_MASK 0x34
50 #define ACER_AMW0_MAILLED_MASK 0x31
53 * Method IDs for WMID interface
55 #define ACER_WMID_GET_WIRELESS_METHODID 1
56 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
57 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
58 #define ACER_WMID_SET_WIRELESS_METHODID 4
59 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
60 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
61 #define ACER_WMID_GET_THREEG_METHODID 10
62 #define ACER_WMID_SET_THREEG_METHODID 11
65 * Acer ACPI method GUIDs
67 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
68 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
69 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
70 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
71 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
74 * Acer ACPI event GUIDs
76 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
78 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
79 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
80 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
82 enum acer_wmi_event_ids
{
83 WMID_HOTKEY_EVENT
= 0x1,
84 WMID_ACCEL_OR_KBD_DOCK_EVENT
= 0x5,
87 static const struct key_entry acer_wmi_keymap
[] __initconst
= {
88 {KE_KEY
, 0x01, {KEY_WLAN
} }, /* WiFi */
89 {KE_KEY
, 0x03, {KEY_WLAN
} }, /* WiFi */
90 {KE_KEY
, 0x04, {KEY_WLAN
} }, /* WiFi */
91 {KE_KEY
, 0x12, {KEY_BLUETOOTH
} }, /* BT */
92 {KE_KEY
, 0x21, {KEY_PROG1
} }, /* Backup */
93 {KE_KEY
, 0x22, {KEY_PROG2
} }, /* Arcade */
94 {KE_KEY
, 0x23, {KEY_PROG3
} }, /* P_Key */
95 {KE_KEY
, 0x24, {KEY_PROG4
} }, /* Social networking_Key */
96 {KE_KEY
, 0x29, {KEY_PROG3
} }, /* P_Key for TM8372 */
97 {KE_IGNORE
, 0x41, {KEY_MUTE
} },
98 {KE_IGNORE
, 0x42, {KEY_PREVIOUSSONG
} },
99 {KE_IGNORE
, 0x4d, {KEY_PREVIOUSSONG
} },
100 {KE_IGNORE
, 0x43, {KEY_NEXTSONG
} },
101 {KE_IGNORE
, 0x4e, {KEY_NEXTSONG
} },
102 {KE_IGNORE
, 0x44, {KEY_PLAYPAUSE
} },
103 {KE_IGNORE
, 0x4f, {KEY_PLAYPAUSE
} },
104 {KE_IGNORE
, 0x45, {KEY_STOP
} },
105 {KE_IGNORE
, 0x50, {KEY_STOP
} },
106 {KE_IGNORE
, 0x48, {KEY_VOLUMEUP
} },
107 {KE_IGNORE
, 0x49, {KEY_VOLUMEDOWN
} },
108 {KE_IGNORE
, 0x4a, {KEY_VOLUMEDOWN
} },
109 {KE_IGNORE
, 0x61, {KEY_SWITCHVIDEOMODE
} },
110 {KE_IGNORE
, 0x62, {KEY_BRIGHTNESSUP
} },
111 {KE_IGNORE
, 0x63, {KEY_BRIGHTNESSDOWN
} },
112 {KE_KEY
, 0x64, {KEY_SWITCHVIDEOMODE
} }, /* Display Switch */
113 {KE_IGNORE
, 0x81, {KEY_SLEEP
} },
114 {KE_KEY
, 0x82, {KEY_TOUCHPAD_TOGGLE
} }, /* Touch Pad Toggle */
115 {KE_IGNORE
, 0x84, {KEY_KBDILLUMTOGGLE
} }, /* Automatic Keyboard background light toggle */
116 {KE_KEY
, KEY_TOUCHPAD_ON
, {KEY_TOUCHPAD_ON
} },
117 {KE_KEY
, KEY_TOUCHPAD_OFF
, {KEY_TOUCHPAD_OFF
} },
118 {KE_IGNORE
, 0x83, {KEY_TOUCHPAD_TOGGLE
} },
119 {KE_KEY
, 0x85, {KEY_TOUCHPAD_TOGGLE
} },
120 {KE_KEY
, 0x86, {KEY_WLAN
} },
121 {KE_KEY
, 0x87, {KEY_POWER
} },
125 static struct input_dev
*acer_wmi_input_dev
;
126 static struct input_dev
*acer_wmi_accel_dev
;
128 struct event_return_value
{
135 } __attribute__((packed
));
138 * GUID3 Get Device Status device flags
140 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
141 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
142 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
143 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
144 #define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
146 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
148 /* Hotkey Customized Setting and Acer Application Status.
149 * Set Device Default Value and Report Acer Application Status.
150 * When Acer Application starts, it will run this method to inform
151 * BIOS/EC that Acer Application is on.
153 * Bit[0]: Launch Manager Status
155 * Bit[2]: Device Control Status
156 * Bit[3]: Acer Power Button Utility Status
157 * Bit[4]: RF Button Status
158 * Bit[5]: ODD PM Status
159 * Bit[6]: Device Default Value Control
160 * Bit[7]: Hall Sensor Application Status
162 struct func_input_params
{
163 u8 function_num
; /* Function Number */
164 u16 commun_devices
; /* Communication type devices default status */
165 u16 devices
; /* Other type devices default status */
166 u8 app_status
; /* Acer Device Status. LM, ePM, RF Button... */
167 u8 app_mask
; /* Bit mask to app_status */
169 } __attribute__((packed
));
171 struct func_return_value
{
172 u8 error_code
; /* Error Code */
173 u8 ec_return_value
; /* EC Return Value */
175 } __attribute__((packed
));
177 struct wmid3_gds_set_input_param
{ /* Set Device Status input parameter */
178 u8 function_num
; /* Function Number */
179 u8 hotkey_number
; /* Hotkey Number */
180 u16 devices
; /* Set Device */
181 u8 volume_value
; /* Volume Value */
182 } __attribute__((packed
));
184 struct wmid3_gds_get_input_param
{ /* Get Device Status input parameter */
185 u8 function_num
; /* Function Number */
186 u8 hotkey_number
; /* Hotkey Number */
187 u16 devices
; /* Get Device */
188 } __attribute__((packed
));
190 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
191 u8 error_code
; /* Error Code */
192 u8 ec_return_value
; /* EC Return Value */
193 u16 devices
; /* Current Device Status */
195 } __attribute__((packed
));
197 struct hotkey_function_type_aa
{
201 u16 commun_func_bitmap
;
202 u16 application_func_bitmap
;
203 u16 media_func_bitmap
;
204 u16 display_func_bitmap
;
205 u16 others_func_bitmap
;
206 u8 commun_fn_key_number
;
207 } __attribute__((packed
));
210 * Interface capability flags
212 #define ACER_CAP_MAILLED BIT(0)
213 #define ACER_CAP_WIRELESS BIT(1)
214 #define ACER_CAP_BLUETOOTH BIT(2)
215 #define ACER_CAP_BRIGHTNESS BIT(3)
216 #define ACER_CAP_THREEG BIT(4)
217 #define ACER_CAP_SET_FUNCTION_MODE BIT(5)
218 #define ACER_CAP_KBD_DOCK BIT(6)
221 * Interface type flags
223 enum interface_flags
{
230 #define ACER_DEFAULT_WIRELESS 0
231 #define ACER_DEFAULT_BLUETOOTH 0
232 #define ACER_DEFAULT_MAILLED 0
233 #define ACER_DEFAULT_THREEG 0
235 static int max_brightness
= 0xF;
237 static int mailled
= -1;
238 static int brightness
= -1;
239 static int threeg
= -1;
240 static int force_series
;
241 static int force_caps
= -1;
242 static bool ec_raw_mode
;
243 static bool has_type_aa
;
244 static u16 commun_func_bitmap
;
245 static u8 commun_fn_key_number
;
247 module_param(mailled
, int, 0444);
248 module_param(brightness
, int, 0444);
249 module_param(threeg
, int, 0444);
250 module_param(force_series
, int, 0444);
251 module_param(force_caps
, int, 0444);
252 module_param(ec_raw_mode
, bool, 0444);
253 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
254 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
255 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
256 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
257 MODULE_PARM_DESC(force_caps
, "Force the capability bitmask to this value");
258 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
271 static struct rfkill
*wireless_rfkill
;
272 static struct rfkill
*bluetooth_rfkill
;
273 static struct rfkill
*threeg_rfkill
;
274 static bool rfkill_inited
;
276 /* Each low-level interface must define at least some of the following */
277 struct wmi_interface
{
278 /* The WMI device type */
281 /* The capabilities this interface provides */
284 /* Private data for the current interface */
285 struct acer_data data
;
287 /* debugfs entries associated with this interface */
288 struct acer_debug debug
;
291 /* The static interface pointer, points to the currently detected interface */
292 static struct wmi_interface
*interface
;
295 * Embedded Controller quirks
296 * Some laptops require us to directly access the EC to either enable or query
297 * features that are not available through WMI.
307 static struct quirk_entry
*quirks
;
309 static void __init
set_quirks(void)
312 interface
->capability
|= ACER_CAP_MAILLED
;
314 if (quirks
->brightness
)
315 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
318 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
320 quirks
= dmi
->driver_data
;
324 static int __init
set_force_caps(const struct dmi_system_id
*dmi
)
326 if (force_caps
== -1) {
327 force_caps
= (uintptr_t)dmi
->driver_data
;
328 pr_info("Found %s, set force_caps to 0x%x\n", dmi
->ident
, force_caps
);
333 static struct quirk_entry quirk_unknown
= {
336 static struct quirk_entry quirk_acer_aspire_1520
= {
340 static struct quirk_entry quirk_acer_travelmate_2490
= {
344 /* This AMW0 laptop has no bluetooth */
345 static struct quirk_entry quirk_medion_md_98300
= {
349 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
353 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
357 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
358 static const struct dmi_system_id acer_blacklist
[] __initconst
= {
360 .ident
= "Acer Aspire One (SSD)",
362 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
363 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
367 .ident
= "Acer Aspire One (HDD)",
369 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
370 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
376 static const struct dmi_system_id amw0_whitelist
[] __initconst
= {
380 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
386 DMI_MATCH(DMI_SYS_VENDOR
, "Gateway"),
390 .ident
= "Packard Bell",
392 DMI_MATCH(DMI_SYS_VENDOR
, "Packard Bell"),
399 * This quirk table is only for Acer/Gateway/Packard Bell family
400 * that those machines are supported by acer-wmi driver.
402 static const struct dmi_system_id acer_quirks
[] __initconst
= {
404 .callback
= dmi_matched
,
405 .ident
= "Acer Aspire 1360",
407 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
408 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
410 .driver_data
= &quirk_acer_aspire_1520
,
413 .callback
= dmi_matched
,
414 .ident
= "Acer Aspire 1520",
416 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
417 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
419 .driver_data
= &quirk_acer_aspire_1520
,
422 .callback
= dmi_matched
,
423 .ident
= "Acer Aspire 3100",
425 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
426 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
428 .driver_data
= &quirk_acer_travelmate_2490
,
431 .callback
= dmi_matched
,
432 .ident
= "Acer Aspire 3610",
434 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
435 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
437 .driver_data
= &quirk_acer_travelmate_2490
,
440 .callback
= dmi_matched
,
441 .ident
= "Acer Aspire 5100",
443 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
444 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
446 .driver_data
= &quirk_acer_travelmate_2490
,
449 .callback
= dmi_matched
,
450 .ident
= "Acer Aspire 5610",
452 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
453 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
455 .driver_data
= &quirk_acer_travelmate_2490
,
458 .callback
= dmi_matched
,
459 .ident
= "Acer Aspire 5630",
461 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
462 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
464 .driver_data
= &quirk_acer_travelmate_2490
,
467 .callback
= dmi_matched
,
468 .ident
= "Acer Aspire 5650",
470 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
471 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
473 .driver_data
= &quirk_acer_travelmate_2490
,
476 .callback
= dmi_matched
,
477 .ident
= "Acer Aspire 5680",
479 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
480 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
482 .driver_data
= &quirk_acer_travelmate_2490
,
485 .callback
= dmi_matched
,
486 .ident
= "Acer Aspire 9110",
488 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
489 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
491 .driver_data
= &quirk_acer_travelmate_2490
,
494 .callback
= dmi_matched
,
495 .ident
= "Acer TravelMate 2490",
497 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
498 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
500 .driver_data
= &quirk_acer_travelmate_2490
,
503 .callback
= dmi_matched
,
504 .ident
= "Acer TravelMate 4200",
506 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
507 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
509 .driver_data
= &quirk_acer_travelmate_2490
,
512 .callback
= set_force_caps
,
513 .ident
= "Acer Aspire Switch 10E SW3-016",
515 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
516 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire SW3-016"),
518 .driver_data
= (void *)ACER_CAP_KBD_DOCK
,
521 .callback
= set_force_caps
,
522 .ident
= "Acer Aspire Switch 10 SW5-012",
524 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
525 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire SW5-012"),
527 .driver_data
= (void *)ACER_CAP_KBD_DOCK
,
530 .callback
= set_force_caps
,
531 .ident
= "Acer One 10 (S1003)",
533 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Acer"),
534 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "One S1003"),
536 .driver_data
= (void *)ACER_CAP_KBD_DOCK
,
542 * This quirk list is for those non-acer machines that have AMW0_GUID1
543 * but supported by acer-wmi in past days. Keeping this quirk list here
544 * is only for backward compatible. Please do not add new machine to
545 * here anymore. Those non-acer machines should be supported by
546 * appropriate wmi drivers.
548 static const struct dmi_system_id non_acer_quirks
[] __initconst
= {
550 .callback
= dmi_matched
,
551 .ident
= "Fujitsu Siemens Amilo Li 1718",
553 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
554 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
556 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
559 .callback
= dmi_matched
,
560 .ident
= "Medion MD 98300",
562 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
563 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
565 .driver_data
= &quirk_medion_md_98300
,
568 .callback
= dmi_matched
,
569 .ident
= "Lenovo Ideapad S205",
571 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
572 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
574 .driver_data
= &quirk_lenovo_ideapad_s205
,
577 .callback
= dmi_matched
,
578 .ident
= "Lenovo Ideapad S205 (Brazos)",
580 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
581 DMI_MATCH(DMI_PRODUCT_NAME
, "Brazos"),
583 .driver_data
= &quirk_lenovo_ideapad_s205
,
586 .callback
= dmi_matched
,
587 .ident
= "Lenovo 3000 N200",
589 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
590 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
592 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
595 .callback
= dmi_matched
,
596 .ident
= "Lenovo Ideapad S205-10382JG",
598 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
599 DMI_MATCH(DMI_PRODUCT_NAME
, "10382JG"),
601 .driver_data
= &quirk_lenovo_ideapad_s205
,
604 .callback
= dmi_matched
,
605 .ident
= "Lenovo Ideapad S205-1038DPG",
607 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
608 DMI_MATCH(DMI_PRODUCT_NAME
, "1038DPG"),
610 .driver_data
= &quirk_lenovo_ideapad_s205
,
616 video_set_backlight_video_vendor(const struct dmi_system_id
*d
)
618 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
619 pr_info("Brightness must be controlled by generic video driver\n");
623 static const struct dmi_system_id video_vendor_dmi_table
[] __initconst
= {
625 .callback
= video_set_backlight_video_vendor
,
626 .ident
= "Acer TravelMate 4750",
628 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
629 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4750"),
633 .callback
= video_set_backlight_video_vendor
,
634 .ident
= "Acer Extensa 5235",
636 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
637 DMI_MATCH(DMI_PRODUCT_NAME
, "Extensa 5235"),
641 .callback
= video_set_backlight_video_vendor
,
642 .ident
= "Acer TravelMate 5760",
644 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
645 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5760"),
649 .callback
= video_set_backlight_video_vendor
,
650 .ident
= "Acer Aspire 5750",
652 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
653 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5750"),
657 .callback
= video_set_backlight_video_vendor
,
658 .ident
= "Acer Aspire 5741",
660 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
661 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5741"),
666 * Note no video_set_backlight_video_vendor, we must use the
667 * acer interface, as there is no native backlight interface.
669 .ident
= "Acer KAV80",
671 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
672 DMI_MATCH(DMI_PRODUCT_NAME
, "KAV80"),
678 /* Find which quirks are needed for a particular vendor/ model pair */
679 static void __init
find_quirks(void)
682 dmi_check_system(acer_quirks
);
683 dmi_check_system(non_acer_quirks
);
684 } else if (force_series
== 2490) {
685 quirks
= &quirk_acer_travelmate_2490
;
689 quirks
= &quirk_unknown
;
693 * General interface convenience methods
696 static bool has_cap(u32 cap
)
698 return interface
->capability
& cap
;
702 * AMW0 (V1) interface
719 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
720 struct acpi_buffer
*result
)
722 struct acpi_buffer input
;
724 input
.length
= sizeof(struct wmab_args
);
725 input
.pointer
= (u8
*)regbuf
;
727 status
= wmi_evaluate_method(AMW0_GUID1
, 0, 1, &input
, result
);
732 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
)
738 case ACER_CAP_MAILLED
:
739 switch (quirks
->mailled
) {
741 err
= ec_read(0xA, &result
);
744 *value
= (result
>> 7) & 0x1;
748 case ACER_CAP_WIRELESS
:
749 switch (quirks
->wireless
) {
751 err
= ec_read(0x7B, &result
);
754 *value
= result
& 0x1;
757 err
= ec_read(0x71, &result
);
760 *value
= result
& 0x1;
763 err
= ec_read(0x78, &result
);
766 *value
= result
& 0x1;
769 err
= ec_read(0xA, &result
);
772 *value
= (result
>> 2) & 0x1;
776 case ACER_CAP_BLUETOOTH
:
777 switch (quirks
->bluetooth
) {
779 err
= ec_read(0xA, &result
);
782 *value
= (result
>> 4) & 0x1;
786 case ACER_CAP_BRIGHTNESS
:
787 switch (quirks
->brightness
) {
789 err
= ec_read(0x83, &result
);
802 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
)
804 struct wmab_args args
;
806 args
.eax
= ACER_AMW0_WRITE
;
807 args
.ebx
= value
? (1<<8) : 0;
808 args
.ecx
= args
.edx
= 0;
811 case ACER_CAP_MAILLED
:
813 return AE_BAD_PARAMETER
;
814 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
816 case ACER_CAP_WIRELESS
:
818 return AE_BAD_PARAMETER
;
819 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
821 case ACER_CAP_BLUETOOTH
:
823 return AE_BAD_PARAMETER
;
824 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
826 case ACER_CAP_BRIGHTNESS
:
827 if (value
> max_brightness
)
828 return AE_BAD_PARAMETER
;
829 switch (quirks
->brightness
) {
831 return ec_write(0x83, value
);
837 /* Actually do the set */
838 return wmab_execute(&args
, NULL
);
841 static acpi_status __init
AMW0_find_mailled(void)
843 struct wmab_args args
;
845 acpi_status status
= AE_OK
;
846 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
847 union acpi_object
*obj
;
850 args
.ebx
= args
.ecx
= args
.edx
= 0;
852 status
= wmab_execute(&args
, &out
);
853 if (ACPI_FAILURE(status
))
856 obj
= (union acpi_object
*) out
.pointer
;
857 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
858 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
859 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
866 interface
->capability
|= ACER_CAP_MAILLED
;
873 static const struct acpi_device_id norfkill_ids
[] __initconst
= {
877 { "SNY5001", 0}, /* sony-laptop in charge */
882 static int __init
AMW0_set_cap_acpi_check_device(void)
884 const struct acpi_device_id
*id
;
886 for (id
= norfkill_ids
; id
->id
[0]; id
++)
887 if (acpi_dev_found(id
->id
))
893 static acpi_status __init
AMW0_set_capabilities(void)
895 struct wmab_args args
;
898 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
899 union acpi_object
*obj
;
902 * On laptops with this strange GUID (non Acer), normal probing doesn't
905 if (wmi_has_guid(AMW0_GUID2
)) {
906 if ((quirks
!= &quirk_unknown
) ||
907 !AMW0_set_cap_acpi_check_device())
908 interface
->capability
|= ACER_CAP_WIRELESS
;
912 args
.eax
= ACER_AMW0_WRITE
;
913 args
.ecx
= args
.edx
= 0;
915 args
.ebx
= 0xa2 << 8;
916 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
918 status
= wmab_execute(&args
, &out
);
919 if (ACPI_FAILURE(status
))
923 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
924 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
925 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
932 interface
->capability
|= ACER_CAP_WIRELESS
;
935 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
938 * It's ok to use existing buffer for next wmab_execute call.
939 * But we need to kfree(out.pointer) if next wmab_execute fail.
941 status
= wmab_execute(&args
, &out
);
942 if (ACPI_FAILURE(status
))
945 obj
= (union acpi_object
*) out
.pointer
;
946 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
947 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
948 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
955 interface
->capability
|= ACER_CAP_BLUETOOTH
;
958 * This appears to be safe to enable, since all Wistron based laptops
959 * appear to use the same EC register for brightness, even if they
960 * differ for wireless, etc
962 if (quirks
->brightness
>= 0)
963 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
971 static struct wmi_interface AMW0_interface
= {
975 static struct wmi_interface AMW0_V2_interface
= {
976 .type
= ACER_AMW0_V2
,
980 * New interface (The WMID interface)
983 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
985 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
986 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
987 union acpi_object
*obj
;
991 status
= wmi_evaluate_method(WMID_GUID1
, 0, method_id
, &input
, &result
);
993 if (ACPI_FAILURE(status
))
996 obj
= (union acpi_object
*) result
.pointer
;
998 if (obj
->type
== ACPI_TYPE_BUFFER
&&
999 (obj
->buffer
.length
== sizeof(u32
) ||
1000 obj
->buffer
.length
== sizeof(u64
))) {
1001 tmp
= *((u32
*) obj
->buffer
.pointer
);
1002 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1003 tmp
= (u32
) obj
->integer
.value
;
1010 kfree(result
.pointer
);
1015 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
)
1019 u32 result
, method_id
= 0;
1022 case ACER_CAP_WIRELESS
:
1023 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
1025 case ACER_CAP_BLUETOOTH
:
1026 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
1028 case ACER_CAP_BRIGHTNESS
:
1029 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
1031 case ACER_CAP_THREEG
:
1032 method_id
= ACER_WMID_GET_THREEG_METHODID
;
1034 case ACER_CAP_MAILLED
:
1035 if (quirks
->mailled
== 1) {
1036 ec_read(0x9f, &tmp
);
1044 status
= WMI_execute_u32(method_id
, 0, &result
);
1046 if (ACPI_SUCCESS(status
))
1047 *value
= (u8
)result
;
1052 static acpi_status
WMID_set_u32(u32 value
, u32 cap
)
1058 case ACER_CAP_BRIGHTNESS
:
1059 if (value
> max_brightness
)
1060 return AE_BAD_PARAMETER
;
1061 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
1063 case ACER_CAP_WIRELESS
:
1065 return AE_BAD_PARAMETER
;
1066 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
1068 case ACER_CAP_BLUETOOTH
:
1070 return AE_BAD_PARAMETER
;
1071 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
1073 case ACER_CAP_THREEG
:
1075 return AE_BAD_PARAMETER
;
1076 method_id
= ACER_WMID_SET_THREEG_METHODID
;
1078 case ACER_CAP_MAILLED
:
1080 return AE_BAD_PARAMETER
;
1081 if (quirks
->mailled
== 1) {
1082 param
= value
? 0x92 : 0x93;
1084 i8042_command(¶m
, 0x1059);
1085 i8042_unlock_chip();
1092 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
1095 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1097 struct wmid3_gds_return_value return_value
;
1099 union acpi_object
*obj
;
1100 struct wmid3_gds_get_input_param params
= {
1101 .function_num
= 0x1,
1102 .hotkey_number
= commun_fn_key_number
,
1105 struct acpi_buffer input
= {
1106 sizeof(struct wmid3_gds_get_input_param
),
1109 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1111 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1112 if (ACPI_FAILURE(status
))
1115 obj
= output
.pointer
;
1119 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1123 if (obj
->buffer
.length
!= 8) {
1124 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1129 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1132 if (return_value
.error_code
|| return_value
.ec_return_value
)
1133 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1135 return_value
.error_code
,
1136 return_value
.ec_return_value
);
1138 *value
= !!(return_value
.devices
& device
);
1143 static acpi_status
wmid_v2_get_u32(u32
*value
, u32 cap
)
1148 case ACER_CAP_WIRELESS
:
1149 device
= ACER_WMID3_GDS_WIRELESS
;
1151 case ACER_CAP_BLUETOOTH
:
1152 device
= ACER_WMID3_GDS_BLUETOOTH
;
1154 case ACER_CAP_THREEG
:
1155 device
= ACER_WMID3_GDS_THREEG
;
1160 return wmid3_get_device_status(value
, device
);
1163 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1165 struct wmid3_gds_return_value return_value
;
1167 union acpi_object
*obj
;
1169 struct wmid3_gds_get_input_param get_params
= {
1170 .function_num
= 0x1,
1171 .hotkey_number
= commun_fn_key_number
,
1172 .devices
= commun_func_bitmap
,
1174 struct acpi_buffer get_input
= {
1175 sizeof(struct wmid3_gds_get_input_param
),
1178 struct wmid3_gds_set_input_param set_params
= {
1179 .function_num
= 0x2,
1180 .hotkey_number
= commun_fn_key_number
,
1181 .devices
= commun_func_bitmap
,
1183 struct acpi_buffer set_input
= {
1184 sizeof(struct wmid3_gds_set_input_param
),
1187 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1188 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1190 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &get_input
, &output
);
1191 if (ACPI_FAILURE(status
))
1194 obj
= output
.pointer
;
1198 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1202 if (obj
->buffer
.length
!= 8) {
1203 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1208 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1211 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1212 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1213 return_value
.error_code
,
1214 return_value
.ec_return_value
);
1218 devices
= return_value
.devices
;
1219 set_params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1221 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &set_input
, &output2
);
1222 if (ACPI_FAILURE(status
))
1225 obj
= output2
.pointer
;
1229 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1233 if (obj
->buffer
.length
!= 4) {
1234 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1239 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1242 if (return_value
.error_code
|| return_value
.ec_return_value
)
1243 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1244 return_value
.error_code
,
1245 return_value
.ec_return_value
);
1250 static acpi_status
wmid_v2_set_u32(u32 value
, u32 cap
)
1255 case ACER_CAP_WIRELESS
:
1256 device
= ACER_WMID3_GDS_WIRELESS
;
1258 case ACER_CAP_BLUETOOTH
:
1259 device
= ACER_WMID3_GDS_BLUETOOTH
;
1261 case ACER_CAP_THREEG
:
1262 device
= ACER_WMID3_GDS_THREEG
;
1267 return wmid3_set_device_status(value
, device
);
1270 static void __init
type_aa_dmi_decode(const struct dmi_header
*header
, void *d
)
1272 struct hotkey_function_type_aa
*type_aa
;
1274 /* We are looking for OEM-specific Type AAh */
1275 if (header
->type
!= 0xAA)
1279 type_aa
= (struct hotkey_function_type_aa
*) header
;
1281 pr_info("Function bitmap for Communication Button: 0x%x\n",
1282 type_aa
->commun_func_bitmap
);
1283 commun_func_bitmap
= type_aa
->commun_func_bitmap
;
1285 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
1286 interface
->capability
|= ACER_CAP_WIRELESS
;
1287 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
1288 interface
->capability
|= ACER_CAP_THREEG
;
1289 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
1290 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1291 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_RFBTN
)
1292 commun_func_bitmap
&= ~ACER_WMID3_GDS_RFBTN
;
1294 commun_fn_key_number
= type_aa
->commun_fn_key_number
;
1297 static acpi_status __init
WMID_set_capabilities(void)
1299 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1300 union acpi_object
*obj
;
1304 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
1305 if (ACPI_FAILURE(status
))
1308 obj
= (union acpi_object
*) out
.pointer
;
1310 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1311 (obj
->buffer
.length
== sizeof(u32
) ||
1312 obj
->buffer
.length
== sizeof(u64
))) {
1313 devices
= *((u32
*) obj
->buffer
.pointer
);
1314 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1315 devices
= (u32
) obj
->integer
.value
;
1325 pr_info("Function bitmap for Communication Device: 0x%x\n", devices
);
1327 interface
->capability
|= ACER_CAP_WIRELESS
;
1329 interface
->capability
|= ACER_CAP_THREEG
;
1331 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1333 if (!(devices
& 0x20))
1334 max_brightness
= 0x9;
1340 static struct wmi_interface wmid_interface
= {
1344 static struct wmi_interface wmid_v2_interface
= {
1345 .type
= ACER_WMID_v2
,
1349 * Generic Device (interface-independent)
1352 static acpi_status
get_u32(u32
*value
, u32 cap
)
1354 acpi_status status
= AE_ERROR
;
1356 switch (interface
->type
) {
1358 status
= AMW0_get_u32(value
, cap
);
1361 if (cap
== ACER_CAP_MAILLED
) {
1362 status
= AMW0_get_u32(value
, cap
);
1367 status
= WMID_get_u32(value
, cap
);
1370 if (cap
& (ACER_CAP_WIRELESS
|
1371 ACER_CAP_BLUETOOTH
|
1373 status
= wmid_v2_get_u32(value
, cap
);
1374 else if (wmi_has_guid(WMID_GUID2
))
1375 status
= WMID_get_u32(value
, cap
);
1382 static acpi_status
set_u32(u32 value
, u32 cap
)
1386 if (interface
->capability
& cap
) {
1387 switch (interface
->type
) {
1389 return AMW0_set_u32(value
, cap
);
1391 if (cap
== ACER_CAP_MAILLED
)
1392 return AMW0_set_u32(value
, cap
);
1395 * On some models, some WMID methods don't toggle
1396 * properly. For those cases, we want to run the AMW0
1397 * method afterwards to be certain we've really toggled
1400 if (cap
== ACER_CAP_WIRELESS
||
1401 cap
== ACER_CAP_BLUETOOTH
) {
1402 status
= WMID_set_u32(value
, cap
);
1403 if (ACPI_FAILURE(status
))
1406 return AMW0_set_u32(value
, cap
);
1410 return WMID_set_u32(value
, cap
);
1412 if (cap
& (ACER_CAP_WIRELESS
|
1413 ACER_CAP_BLUETOOTH
|
1415 return wmid_v2_set_u32(value
, cap
);
1416 else if (wmi_has_guid(WMID_GUID2
))
1417 return WMID_set_u32(value
, cap
);
1420 return AE_BAD_PARAMETER
;
1423 return AE_BAD_PARAMETER
;
1426 static void __init
acer_commandline_init(void)
1429 * These will all fail silently if the value given is invalid, or the
1430 * capability isn't available on the given interface
1433 set_u32(mailled
, ACER_CAP_MAILLED
);
1434 if (!has_type_aa
&& threeg
>= 0)
1435 set_u32(threeg
, ACER_CAP_THREEG
);
1436 if (brightness
>= 0)
1437 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1441 * LED device (Mail LED only, no other LEDs known yet)
1443 static void mail_led_set(struct led_classdev
*led_cdev
,
1444 enum led_brightness value
)
1446 set_u32(value
, ACER_CAP_MAILLED
);
1449 static struct led_classdev mail_led
= {
1450 .name
= "acer-wmi::mail",
1451 .brightness_set
= mail_led_set
,
1454 static int acer_led_init(struct device
*dev
)
1456 return led_classdev_register(dev
, &mail_led
);
1459 static void acer_led_exit(void)
1461 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1462 led_classdev_unregister(&mail_led
);
1468 static struct backlight_device
*acer_backlight_device
;
1470 static int read_brightness(struct backlight_device
*bd
)
1473 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1477 static int update_bl_status(struct backlight_device
*bd
)
1479 int intensity
= bd
->props
.brightness
;
1481 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1483 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1486 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1491 static const struct backlight_ops acer_bl_ops
= {
1492 .get_brightness
= read_brightness
,
1493 .update_status
= update_bl_status
,
1496 static int acer_backlight_init(struct device
*dev
)
1498 struct backlight_properties props
;
1499 struct backlight_device
*bd
;
1501 memset(&props
, 0, sizeof(struct backlight_properties
));
1502 props
.type
= BACKLIGHT_PLATFORM
;
1503 props
.max_brightness
= max_brightness
;
1504 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1507 pr_err("Could not register Acer backlight device\n");
1508 acer_backlight_device
= NULL
;
1512 acer_backlight_device
= bd
;
1514 bd
->props
.power
= FB_BLANK_UNBLANK
;
1515 bd
->props
.brightness
= read_brightness(bd
);
1516 backlight_update_status(bd
);
1520 static void acer_backlight_exit(void)
1522 backlight_device_unregister(acer_backlight_device
);
1526 * Accelerometer device
1528 static acpi_handle gsensor_handle
;
1530 static int acer_gsensor_init(void)
1533 struct acpi_buffer output
;
1534 union acpi_object out_obj
;
1536 output
.length
= sizeof(out_obj
);
1537 output
.pointer
= &out_obj
;
1538 status
= acpi_evaluate_object(gsensor_handle
, "_INI", NULL
, &output
);
1539 if (ACPI_FAILURE(status
))
1545 static int acer_gsensor_open(struct input_dev
*input
)
1547 return acer_gsensor_init();
1550 static int acer_gsensor_event(void)
1553 struct acpi_buffer output
;
1554 union acpi_object out_obj
[5];
1556 if (!acer_wmi_accel_dev
)
1559 output
.length
= sizeof(out_obj
);
1560 output
.pointer
= out_obj
;
1562 status
= acpi_evaluate_object(gsensor_handle
, "RDVL", NULL
, &output
);
1563 if (ACPI_FAILURE(status
))
1566 if (out_obj
->package
.count
!= 4)
1569 input_report_abs(acer_wmi_accel_dev
, ABS_X
,
1570 (s16
)out_obj
->package
.elements
[0].integer
.value
);
1571 input_report_abs(acer_wmi_accel_dev
, ABS_Y
,
1572 (s16
)out_obj
->package
.elements
[1].integer
.value
);
1573 input_report_abs(acer_wmi_accel_dev
, ABS_Z
,
1574 (s16
)out_obj
->package
.elements
[2].integer
.value
);
1575 input_sync(acer_wmi_accel_dev
);
1580 * Switch series keyboard dock status
1582 static int acer_kbd_dock_state_to_sw_tablet_mode(u8 kbd_dock_state
)
1584 switch (kbd_dock_state
) {
1585 case 0x01: /* Docked, traditional clamshell laptop mode */
1587 case 0x04: /* Stand-alone tablet */
1588 case 0x40: /* Docked, tent mode, keyboard not usable */
1591 pr_warn("Unknown kbd_dock_state 0x%02x\n", kbd_dock_state
);
1597 static void acer_kbd_dock_get_initial_state(void)
1599 u8
*output
, input
[8] = { 0x05, 0x00, };
1600 struct acpi_buffer input_buf
= { sizeof(input
), input
};
1601 struct acpi_buffer output_buf
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1602 union acpi_object
*obj
;
1606 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input_buf
, &output_buf
);
1607 if (ACPI_FAILURE(status
)) {
1608 ACPI_EXCEPTION((AE_INFO
, status
, "Error getting keyboard-dock initial status"));
1612 obj
= output_buf
.pointer
;
1613 if (!obj
|| obj
->type
!= ACPI_TYPE_BUFFER
|| obj
->buffer
.length
!= 8) {
1614 pr_err("Unexpected output format getting keyboard-dock initial status\n");
1618 output
= obj
->buffer
.pointer
;
1619 if (output
[0] != 0x00 || (output
[3] != 0x05 && output
[3] != 0x45)) {
1620 pr_err("Unexpected output [0]=0x%02x [3]=0x%02x getting keyboard-dock initial status\n",
1621 output
[0], output
[3]);
1625 sw_tablet_mode
= acer_kbd_dock_state_to_sw_tablet_mode(output
[4]);
1626 input_report_switch(acer_wmi_input_dev
, SW_TABLET_MODE
, sw_tablet_mode
);
1632 static void acer_kbd_dock_event(const struct event_return_value
*event
)
1636 if (!has_cap(ACER_CAP_KBD_DOCK
))
1639 sw_tablet_mode
= acer_kbd_dock_state_to_sw_tablet_mode(event
->kbd_dock_state
);
1640 input_report_switch(acer_wmi_input_dev
, SW_TABLET_MODE
, sw_tablet_mode
);
1641 input_sync(acer_wmi_input_dev
);
1647 static void acer_rfkill_update(struct work_struct
*ignored
);
1648 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1649 static void acer_rfkill_update(struct work_struct
*ignored
)
1654 if (has_cap(ACER_CAP_WIRELESS
)) {
1655 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1656 if (ACPI_SUCCESS(status
)) {
1657 if (quirks
->wireless
== 3)
1658 rfkill_set_hw_state(wireless_rfkill
, !state
);
1660 rfkill_set_sw_state(wireless_rfkill
, !state
);
1664 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1665 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1666 if (ACPI_SUCCESS(status
))
1667 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1670 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1671 status
= get_u32(&state
, ACER_WMID3_GDS_THREEG
);
1672 if (ACPI_SUCCESS(status
))
1673 rfkill_set_sw_state(threeg_rfkill
, !state
);
1676 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1679 static int acer_rfkill_set(void *data
, bool blocked
)
1682 u32 cap
= (unsigned long)data
;
1684 if (rfkill_inited
) {
1685 status
= set_u32(!blocked
, cap
);
1686 if (ACPI_FAILURE(status
))
1693 static const struct rfkill_ops acer_rfkill_ops
= {
1694 .set_block
= acer_rfkill_set
,
1697 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1698 enum rfkill_type type
,
1699 char *name
, u32 cap
)
1702 struct rfkill
*rfkill_dev
;
1706 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1708 (void *)(unsigned long)cap
);
1710 return ERR_PTR(-ENOMEM
);
1712 status
= get_u32(&state
, cap
);
1714 err
= rfkill_register(rfkill_dev
);
1716 rfkill_destroy(rfkill_dev
);
1717 return ERR_PTR(err
);
1720 if (ACPI_SUCCESS(status
))
1721 rfkill_set_sw_state(rfkill_dev
, !state
);
1726 static int acer_rfkill_init(struct device
*dev
)
1730 if (has_cap(ACER_CAP_WIRELESS
)) {
1731 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1732 "acer-wireless", ACER_CAP_WIRELESS
);
1733 if (IS_ERR(wireless_rfkill
)) {
1734 err
= PTR_ERR(wireless_rfkill
);
1735 goto error_wireless
;
1739 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1740 bluetooth_rfkill
= acer_rfkill_register(dev
,
1741 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1742 ACER_CAP_BLUETOOTH
);
1743 if (IS_ERR(bluetooth_rfkill
)) {
1744 err
= PTR_ERR(bluetooth_rfkill
);
1745 goto error_bluetooth
;
1749 if (has_cap(ACER_CAP_THREEG
)) {
1750 threeg_rfkill
= acer_rfkill_register(dev
,
1751 RFKILL_TYPE_WWAN
, "acer-threeg",
1753 if (IS_ERR(threeg_rfkill
)) {
1754 err
= PTR_ERR(threeg_rfkill
);
1759 rfkill_inited
= true;
1761 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1762 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1763 schedule_delayed_work(&acer_rfkill_work
,
1764 round_jiffies_relative(HZ
));
1769 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1770 rfkill_unregister(bluetooth_rfkill
);
1771 rfkill_destroy(bluetooth_rfkill
);
1774 if (has_cap(ACER_CAP_WIRELESS
)) {
1775 rfkill_unregister(wireless_rfkill
);
1776 rfkill_destroy(wireless_rfkill
);
1782 static void acer_rfkill_exit(void)
1784 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1785 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1786 cancel_delayed_work_sync(&acer_rfkill_work
);
1788 if (has_cap(ACER_CAP_WIRELESS
)) {
1789 rfkill_unregister(wireless_rfkill
);
1790 rfkill_destroy(wireless_rfkill
);
1793 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1794 rfkill_unregister(bluetooth_rfkill
);
1795 rfkill_destroy(bluetooth_rfkill
);
1798 if (has_cap(ACER_CAP_THREEG
)) {
1799 rfkill_unregister(threeg_rfkill
);
1800 rfkill_destroy(threeg_rfkill
);
1805 static void acer_wmi_notify(u32 value
, void *context
)
1807 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1808 union acpi_object
*obj
;
1809 struct event_return_value return_value
;
1812 const struct key_entry
*key
;
1815 status
= wmi_get_event_data(value
, &response
);
1816 if (status
!= AE_OK
) {
1817 pr_warn("bad event status 0x%x\n", status
);
1821 obj
= (union acpi_object
*)response
.pointer
;
1825 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1826 pr_warn("Unknown response received %d\n", obj
->type
);
1830 if (obj
->buffer
.length
!= 8) {
1831 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1836 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1839 switch (return_value
.function
) {
1840 case WMID_HOTKEY_EVENT
:
1841 device_state
= return_value
.device_state
;
1842 pr_debug("device state: 0x%x\n", device_state
);
1844 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1845 return_value
.key_num
);
1847 pr_warn("Unknown key number - 0x%x\n",
1848 return_value
.key_num
);
1850 scancode
= return_value
.key_num
;
1851 switch (key
->keycode
) {
1854 if (has_cap(ACER_CAP_WIRELESS
))
1855 rfkill_set_sw_state(wireless_rfkill
,
1856 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1857 if (has_cap(ACER_CAP_THREEG
))
1858 rfkill_set_sw_state(threeg_rfkill
,
1859 !(device_state
& ACER_WMID3_GDS_THREEG
));
1860 if (has_cap(ACER_CAP_BLUETOOTH
))
1861 rfkill_set_sw_state(bluetooth_rfkill
,
1862 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1864 case KEY_TOUCHPAD_TOGGLE
:
1865 scancode
= (device_state
& ACER_WMID3_GDS_TOUCHPAD
) ?
1866 KEY_TOUCHPAD_ON
: KEY_TOUCHPAD_OFF
;
1868 sparse_keymap_report_event(acer_wmi_input_dev
, scancode
, 1, true);
1871 case WMID_ACCEL_OR_KBD_DOCK_EVENT
:
1872 acer_gsensor_event();
1873 acer_kbd_dock_event(&return_value
);
1876 pr_warn("Unknown function number - %d - %d\n",
1877 return_value
.function
, return_value
.key_num
);
1882 static acpi_status __init
1883 wmid3_set_function_mode(struct func_input_params
*params
,
1884 struct func_return_value
*return_value
)
1887 union acpi_object
*obj
;
1889 struct acpi_buffer input
= { sizeof(struct func_input_params
), params
};
1890 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1892 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1893 if (ACPI_FAILURE(status
))
1896 obj
= output
.pointer
;
1900 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1904 if (obj
->buffer
.length
!= 4) {
1905 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1910 *return_value
= *((struct func_return_value
*)obj
->buffer
.pointer
);
1916 static int __init
acer_wmi_enable_ec_raw(void)
1918 struct func_return_value return_value
;
1920 struct func_input_params params
= {
1921 .function_num
= 0x1,
1922 .commun_devices
= 0xFFFF,
1924 .app_status
= 0x00, /* Launch Manager Deactive */
1928 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1930 if (return_value
.error_code
|| return_value
.ec_return_value
)
1931 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1932 return_value
.error_code
,
1933 return_value
.ec_return_value
);
1935 pr_info("Enabled EC raw mode\n");
1940 static int __init
acer_wmi_enable_lm(void)
1942 struct func_return_value return_value
;
1944 struct func_input_params params
= {
1945 .function_num
= 0x1,
1946 .commun_devices
= 0xFFFF,
1948 .app_status
= 0x01, /* Launch Manager Active */
1952 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1954 if (return_value
.error_code
|| return_value
.ec_return_value
)
1955 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1956 return_value
.error_code
,
1957 return_value
.ec_return_value
);
1962 static int __init
acer_wmi_enable_rf_button(void)
1964 struct func_return_value return_value
;
1966 struct func_input_params params
= {
1967 .function_num
= 0x1,
1968 .commun_devices
= 0xFFFF,
1970 .app_status
= 0x10, /* RF Button Active */
1974 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1976 if (return_value
.error_code
|| return_value
.ec_return_value
)
1977 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1978 return_value
.error_code
,
1979 return_value
.ec_return_value
);
1984 static int __init
acer_wmi_accel_setup(void)
1986 struct acpi_device
*adev
;
1989 adev
= acpi_dev_get_first_match_dev("BST0001", NULL
, -1);
1993 gsensor_handle
= acpi_device_handle(adev
);
1996 acer_wmi_accel_dev
= input_allocate_device();
1997 if (!acer_wmi_accel_dev
)
2000 acer_wmi_accel_dev
->open
= acer_gsensor_open
;
2002 acer_wmi_accel_dev
->name
= "Acer BMA150 accelerometer";
2003 acer_wmi_accel_dev
->phys
= "wmi/input1";
2004 acer_wmi_accel_dev
->id
.bustype
= BUS_HOST
;
2005 acer_wmi_accel_dev
->evbit
[0] = BIT_MASK(EV_ABS
);
2006 input_set_abs_params(acer_wmi_accel_dev
, ABS_X
, -16384, 16384, 0, 0);
2007 input_set_abs_params(acer_wmi_accel_dev
, ABS_Y
, -16384, 16384, 0, 0);
2008 input_set_abs_params(acer_wmi_accel_dev
, ABS_Z
, -16384, 16384, 0, 0);
2010 err
= input_register_device(acer_wmi_accel_dev
);
2017 input_free_device(acer_wmi_accel_dev
);
2021 static int __init
acer_wmi_input_setup(void)
2026 acer_wmi_input_dev
= input_allocate_device();
2027 if (!acer_wmi_input_dev
)
2030 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
2031 acer_wmi_input_dev
->phys
= "wmi/input0";
2032 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
2034 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
2038 if (has_cap(ACER_CAP_KBD_DOCK
))
2039 input_set_capability(acer_wmi_input_dev
, EV_SW
, SW_TABLET_MODE
);
2041 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
2042 acer_wmi_notify
, NULL
);
2043 if (ACPI_FAILURE(status
)) {
2048 if (has_cap(ACER_CAP_KBD_DOCK
))
2049 acer_kbd_dock_get_initial_state();
2051 err
= input_register_device(acer_wmi_input_dev
);
2053 goto err_uninstall_notifier
;
2057 err_uninstall_notifier
:
2058 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
2060 input_free_device(acer_wmi_input_dev
);
2064 static void acer_wmi_input_destroy(void)
2066 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
2067 input_unregister_device(acer_wmi_input_dev
);
2073 static u32
get_wmid_devices(void)
2075 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
2076 union acpi_object
*obj
;
2080 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
2081 if (ACPI_FAILURE(status
))
2084 obj
= (union acpi_object
*) out
.pointer
;
2086 if (obj
->type
== ACPI_TYPE_BUFFER
&&
2087 (obj
->buffer
.length
== sizeof(u32
) ||
2088 obj
->buffer
.length
== sizeof(u64
))) {
2089 devices
= *((u32
*) obj
->buffer
.pointer
);
2090 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
2091 devices
= (u32
) obj
->integer
.value
;
2102 static int acer_platform_probe(struct platform_device
*device
)
2106 if (has_cap(ACER_CAP_MAILLED
)) {
2107 err
= acer_led_init(&device
->dev
);
2112 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2113 err
= acer_backlight_init(&device
->dev
);
2115 goto error_brightness
;
2118 err
= acer_rfkill_init(&device
->dev
);
2125 if (has_cap(ACER_CAP_BRIGHTNESS
))
2126 acer_backlight_exit();
2128 if (has_cap(ACER_CAP_MAILLED
))
2134 static int acer_platform_remove(struct platform_device
*device
)
2136 if (has_cap(ACER_CAP_MAILLED
))
2138 if (has_cap(ACER_CAP_BRIGHTNESS
))
2139 acer_backlight_exit();
2145 #ifdef CONFIG_PM_SLEEP
2146 static int acer_suspend(struct device
*dev
)
2149 struct acer_data
*data
= &interface
->data
;
2154 if (has_cap(ACER_CAP_MAILLED
)) {
2155 get_u32(&value
, ACER_CAP_MAILLED
);
2156 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2157 data
->mailled
= value
;
2160 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2161 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
2162 data
->brightness
= value
;
2168 static int acer_resume(struct device
*dev
)
2170 struct acer_data
*data
= &interface
->data
;
2175 if (has_cap(ACER_CAP_MAILLED
))
2176 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
2178 if (has_cap(ACER_CAP_BRIGHTNESS
))
2179 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
2181 if (acer_wmi_accel_dev
)
2182 acer_gsensor_init();
2187 #define acer_suspend NULL
2188 #define acer_resume NULL
2191 static SIMPLE_DEV_PM_OPS(acer_pm
, acer_suspend
, acer_resume
);
2193 static void acer_platform_shutdown(struct platform_device
*device
)
2195 struct acer_data
*data
= &interface
->data
;
2200 if (has_cap(ACER_CAP_MAILLED
))
2201 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2204 static struct platform_driver acer_platform_driver
= {
2209 .probe
= acer_platform_probe
,
2210 .remove
= acer_platform_remove
,
2211 .shutdown
= acer_platform_shutdown
,
2214 static struct platform_device
*acer_platform_device
;
2216 static void remove_debugfs(void)
2218 debugfs_remove_recursive(interface
->debug
.root
);
2221 static void __init
create_debugfs(void)
2223 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
2225 debugfs_create_u32("devices", S_IRUGO
, interface
->debug
.root
,
2226 &interface
->debug
.wmid_devices
);
2229 static int __init
acer_wmi_init(void)
2233 pr_info("Acer Laptop ACPI-WMI Extras\n");
2235 if (dmi_check_system(acer_blacklist
)) {
2236 pr_info("Blacklisted hardware detected - not loading\n");
2243 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2244 * machines like Lenovo, Fujitsu and Medion. In the past days,
2245 * acer-wmi driver handled those non-Acer machines by quirks list.
2246 * But actually acer-wmi driver was loaded on any machines that have
2247 * AMW0_GUID1. This behavior is strange because those machines should
2248 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2249 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2250 * should be in Acer/Gateway/Packard Bell white list, or it's already
2251 * in the past quirk list.
2253 if (wmi_has_guid(AMW0_GUID1
) &&
2254 !dmi_check_system(amw0_whitelist
) &&
2255 quirks
== &quirk_unknown
) {
2256 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
2261 * Detect which ACPI-WMI interface we're using.
2263 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2264 interface
= &AMW0_V2_interface
;
2266 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2267 interface
= &wmid_interface
;
2269 if (wmi_has_guid(WMID_GUID3
))
2270 interface
= &wmid_v2_interface
;
2273 dmi_walk(type_aa_dmi_decode
, NULL
);
2275 if (wmi_has_guid(WMID_GUID2
) && interface
) {
2276 if (!has_type_aa
&& ACPI_FAILURE(WMID_set_capabilities())) {
2277 pr_err("Unable to detect available WMID devices\n");
2280 /* WMID always provides brightness methods */
2281 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
2282 } else if (!wmi_has_guid(WMID_GUID2
) && interface
&& !has_type_aa
&& force_caps
== -1) {
2283 pr_err("No WMID device detection method found\n");
2287 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
2288 interface
= &AMW0_interface
;
2290 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2291 pr_err("Unable to detect available AMW0 devices\n");
2296 if (wmi_has_guid(AMW0_GUID1
))
2297 AMW0_find_mailled();
2300 pr_err("No or unsupported WMI interface, unable to load\n");
2306 if (dmi_check_system(video_vendor_dmi_table
))
2307 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2309 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2310 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
2312 if (wmi_has_guid(WMID_GUID3
))
2313 interface
->capability
|= ACER_CAP_SET_FUNCTION_MODE
;
2315 if (force_caps
!= -1)
2316 interface
->capability
= force_caps
;
2318 if (wmi_has_guid(WMID_GUID3
) &&
2319 (interface
->capability
& ACER_CAP_SET_FUNCTION_MODE
)) {
2320 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2321 pr_warn("Cannot enable RF Button Driver\n");
2324 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2325 pr_err("Cannot enable EC raw mode\n");
2328 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2329 pr_err("Cannot enable Launch Manager mode\n");
2332 } else if (ec_raw_mode
) {
2333 pr_info("No WMID EC raw mode enable method\n");
2336 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
2337 err
= acer_wmi_input_setup();
2340 err
= acer_wmi_accel_setup();
2341 if (err
&& err
!= -ENODEV
)
2342 pr_warn("Cannot enable accelerometer\n");
2345 err
= platform_driver_register(&acer_platform_driver
);
2347 pr_err("Unable to register platform driver\n");
2348 goto error_platform_register
;
2351 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
2352 if (!acer_platform_device
) {
2354 goto error_device_alloc
;
2357 err
= platform_device_add(acer_platform_device
);
2359 goto error_device_add
;
2361 if (wmi_has_guid(WMID_GUID2
)) {
2362 interface
->debug
.wmid_devices
= get_wmid_devices();
2366 /* Override any initial settings with values from the commandline */
2367 acer_commandline_init();
2372 platform_device_put(acer_platform_device
);
2374 platform_driver_unregister(&acer_platform_driver
);
2375 error_platform_register
:
2376 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2377 acer_wmi_input_destroy();
2378 if (acer_wmi_accel_dev
)
2379 input_unregister_device(acer_wmi_accel_dev
);
2384 static void __exit
acer_wmi_exit(void)
2386 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2387 acer_wmi_input_destroy();
2389 if (acer_wmi_accel_dev
)
2390 input_unregister_device(acer_wmi_accel_dev
);
2393 platform_device_unregister(acer_platform_device
);
2394 platform_driver_unregister(&acer_platform_driver
);
2396 pr_info("Acer Laptop WMI Extras unloaded\n");
2400 module_init(acer_wmi_init
);
2401 module_exit(acer_wmi_exit
);