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 MODULE_AUTHOR("Carlos Corbacho");
34 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
35 MODULE_LICENSE("GPL");
39 * Meaning is unknown - this number is required for writing to ACPI for AMW0
40 * (it's also used in acerhk when directly accessing the BIOS)
42 #define ACER_AMW0_WRITE 0x9610
45 * Bit masks for the AMW0 interface
47 #define ACER_AMW0_WIRELESS_MASK 0x35
48 #define ACER_AMW0_BLUETOOTH_MASK 0x34
49 #define ACER_AMW0_MAILLED_MASK 0x31
52 * Method IDs for WMID interface
54 #define ACER_WMID_GET_WIRELESS_METHODID 1
55 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
56 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
57 #define ACER_WMID_SET_WIRELESS_METHODID 4
58 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
59 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
60 #define ACER_WMID_GET_THREEG_METHODID 10
61 #define ACER_WMID_SET_THREEG_METHODID 11
64 * Acer ACPI method GUIDs
66 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
67 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
68 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
69 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
70 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
73 * Acer ACPI event GUIDs
75 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
77 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
78 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
79 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
81 enum acer_wmi_event_ids
{
82 WMID_HOTKEY_EVENT
= 0x1,
83 WMID_ACCEL_EVENT
= 0x5,
86 static const struct key_entry acer_wmi_keymap
[] __initconst
= {
87 {KE_KEY
, 0x01, {KEY_WLAN
} }, /* WiFi */
88 {KE_KEY
, 0x03, {KEY_WLAN
} }, /* WiFi */
89 {KE_KEY
, 0x04, {KEY_WLAN
} }, /* WiFi */
90 {KE_KEY
, 0x12, {KEY_BLUETOOTH
} }, /* BT */
91 {KE_KEY
, 0x21, {KEY_PROG1
} }, /* Backup */
92 {KE_KEY
, 0x22, {KEY_PROG2
} }, /* Arcade */
93 {KE_KEY
, 0x23, {KEY_PROG3
} }, /* P_Key */
94 {KE_KEY
, 0x24, {KEY_PROG4
} }, /* Social networking_Key */
95 {KE_KEY
, 0x29, {KEY_PROG3
} }, /* P_Key for TM8372 */
96 {KE_IGNORE
, 0x41, {KEY_MUTE
} },
97 {KE_IGNORE
, 0x42, {KEY_PREVIOUSSONG
} },
98 {KE_IGNORE
, 0x4d, {KEY_PREVIOUSSONG
} },
99 {KE_IGNORE
, 0x43, {KEY_NEXTSONG
} },
100 {KE_IGNORE
, 0x4e, {KEY_NEXTSONG
} },
101 {KE_IGNORE
, 0x44, {KEY_PLAYPAUSE
} },
102 {KE_IGNORE
, 0x4f, {KEY_PLAYPAUSE
} },
103 {KE_IGNORE
, 0x45, {KEY_STOP
} },
104 {KE_IGNORE
, 0x50, {KEY_STOP
} },
105 {KE_IGNORE
, 0x48, {KEY_VOLUMEUP
} },
106 {KE_IGNORE
, 0x49, {KEY_VOLUMEDOWN
} },
107 {KE_IGNORE
, 0x4a, {KEY_VOLUMEDOWN
} },
108 {KE_IGNORE
, 0x61, {KEY_SWITCHVIDEOMODE
} },
109 {KE_IGNORE
, 0x62, {KEY_BRIGHTNESSUP
} },
110 {KE_IGNORE
, 0x63, {KEY_BRIGHTNESSDOWN
} },
111 {KE_KEY
, 0x64, {KEY_SWITCHVIDEOMODE
} }, /* Display Switch */
112 {KE_IGNORE
, 0x81, {KEY_SLEEP
} },
113 {KE_KEY
, 0x82, {KEY_TOUCHPAD_TOGGLE
} }, /* Touch Pad Toggle */
114 {KE_KEY
, KEY_TOUCHPAD_ON
, {KEY_TOUCHPAD_ON
} },
115 {KE_KEY
, KEY_TOUCHPAD_OFF
, {KEY_TOUCHPAD_OFF
} },
116 {KE_IGNORE
, 0x83, {KEY_TOUCHPAD_TOGGLE
} },
117 {KE_KEY
, 0x85, {KEY_TOUCHPAD_TOGGLE
} },
118 {KE_KEY
, 0x86, {KEY_WLAN
} },
119 {KE_KEY
, 0x87, {KEY_POWER
} },
123 static struct input_dev
*acer_wmi_input_dev
;
124 static struct input_dev
*acer_wmi_accel_dev
;
126 struct event_return_value
{
131 } __attribute__((packed
));
134 * GUID3 Get Device Status device flags
136 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
137 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
138 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
139 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
140 #define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
142 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
144 /* Hotkey Customized Setting and Acer Application Status.
145 * Set Device Default Value and Report Acer Application Status.
146 * When Acer Application starts, it will run this method to inform
147 * BIOS/EC that Acer Application is on.
149 * Bit[0]: Launch Manager Status
151 * Bit[2]: Device Control Status
152 * Bit[3]: Acer Power Button Utility Status
153 * Bit[4]: RF Button Status
154 * Bit[5]: ODD PM Status
155 * Bit[6]: Device Default Value Control
156 * Bit[7]: Hall Sensor Application Status
158 struct func_input_params
{
159 u8 function_num
; /* Function Number */
160 u16 commun_devices
; /* Communication type devices default status */
161 u16 devices
; /* Other type devices default status */
162 u8 app_status
; /* Acer Device Status. LM, ePM, RF Button... */
163 u8 app_mask
; /* Bit mask to app_status */
165 } __attribute__((packed
));
167 struct func_return_value
{
168 u8 error_code
; /* Error Code */
169 u8 ec_return_value
; /* EC Return Value */
171 } __attribute__((packed
));
173 struct wmid3_gds_set_input_param
{ /* Set Device Status input parameter */
174 u8 function_num
; /* Function Number */
175 u8 hotkey_number
; /* Hotkey Number */
176 u16 devices
; /* Set Device */
177 u8 volume_value
; /* Volume Value */
178 } __attribute__((packed
));
180 struct wmid3_gds_get_input_param
{ /* Get Device Status input parameter */
181 u8 function_num
; /* Function Number */
182 u8 hotkey_number
; /* Hotkey Number */
183 u16 devices
; /* Get Device */
184 } __attribute__((packed
));
186 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
187 u8 error_code
; /* Error Code */
188 u8 ec_return_value
; /* EC Return Value */
189 u16 devices
; /* Current Device Status */
191 } __attribute__((packed
));
193 struct hotkey_function_type_aa
{
197 u16 commun_func_bitmap
;
198 u16 application_func_bitmap
;
199 u16 media_func_bitmap
;
200 u16 display_func_bitmap
;
201 u16 others_func_bitmap
;
202 u8 commun_fn_key_number
;
203 } __attribute__((packed
));
206 * Interface capability flags
208 #define ACER_CAP_MAILLED (1<<0)
209 #define ACER_CAP_WIRELESS (1<<1)
210 #define ACER_CAP_BLUETOOTH (1<<2)
211 #define ACER_CAP_BRIGHTNESS (1<<3)
212 #define ACER_CAP_THREEG (1<<4)
213 #define ACER_CAP_ACCEL (1<<5)
214 #define ACER_CAP_RFBTN (1<<6)
215 #define ACER_CAP_ANY (0xFFFFFFFF)
218 * Interface type flags
220 enum interface_flags
{
227 #define ACER_DEFAULT_WIRELESS 0
228 #define ACER_DEFAULT_BLUETOOTH 0
229 #define ACER_DEFAULT_MAILLED 0
230 #define ACER_DEFAULT_THREEG 0
232 static int max_brightness
= 0xF;
234 static int mailled
= -1;
235 static int brightness
= -1;
236 static int threeg
= -1;
237 static int force_series
;
238 static bool ec_raw_mode
;
239 static bool has_type_aa
;
240 static u16 commun_func_bitmap
;
241 static u8 commun_fn_key_number
;
243 module_param(mailled
, int, 0444);
244 module_param(brightness
, int, 0444);
245 module_param(threeg
, int, 0444);
246 module_param(force_series
, int, 0444);
247 module_param(ec_raw_mode
, bool, 0444);
248 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
249 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
250 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
251 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
252 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
265 static struct rfkill
*wireless_rfkill
;
266 static struct rfkill
*bluetooth_rfkill
;
267 static struct rfkill
*threeg_rfkill
;
268 static bool rfkill_inited
;
270 /* Each low-level interface must define at least some of the following */
271 struct wmi_interface
{
272 /* The WMI device type */
275 /* The capabilities this interface provides */
278 /* Private data for the current interface */
279 struct acer_data data
;
281 /* debugfs entries associated with this interface */
282 struct acer_debug debug
;
285 /* The static interface pointer, points to the currently detected interface */
286 static struct wmi_interface
*interface
;
289 * Embedded Controller quirks
290 * Some laptops require us to directly access the EC to either enable or query
291 * features that are not available through WMI.
301 static struct quirk_entry
*quirks
;
303 static void __init
set_quirks(void)
309 interface
->capability
|= ACER_CAP_MAILLED
;
311 if (quirks
->brightness
)
312 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
315 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
317 quirks
= dmi
->driver_data
;
321 static struct quirk_entry quirk_unknown
= {
324 static struct quirk_entry quirk_acer_aspire_1520
= {
328 static struct quirk_entry quirk_acer_travelmate_2490
= {
332 /* This AMW0 laptop has no bluetooth */
333 static struct quirk_entry quirk_medion_md_98300
= {
337 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
341 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
345 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
346 static const struct dmi_system_id acer_blacklist
[] __initconst
= {
348 .ident
= "Acer Aspire One (SSD)",
350 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
351 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
355 .ident
= "Acer Aspire One (HDD)",
357 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
358 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
364 static const struct dmi_system_id amw0_whitelist
[] __initconst
= {
368 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
374 DMI_MATCH(DMI_SYS_VENDOR
, "Gateway"),
378 .ident
= "Packard Bell",
380 DMI_MATCH(DMI_SYS_VENDOR
, "Packard Bell"),
387 * This quirk table is only for Acer/Gateway/Packard Bell family
388 * that those machines are supported by acer-wmi driver.
390 static const struct dmi_system_id acer_quirks
[] __initconst
= {
392 .callback
= dmi_matched
,
393 .ident
= "Acer Aspire 1360",
395 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
396 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
398 .driver_data
= &quirk_acer_aspire_1520
,
401 .callback
= dmi_matched
,
402 .ident
= "Acer Aspire 1520",
404 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
405 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
407 .driver_data
= &quirk_acer_aspire_1520
,
410 .callback
= dmi_matched
,
411 .ident
= "Acer Aspire 3100",
413 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
414 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
416 .driver_data
= &quirk_acer_travelmate_2490
,
419 .callback
= dmi_matched
,
420 .ident
= "Acer Aspire 3610",
422 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
423 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
425 .driver_data
= &quirk_acer_travelmate_2490
,
428 .callback
= dmi_matched
,
429 .ident
= "Acer Aspire 5100",
431 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
432 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
434 .driver_data
= &quirk_acer_travelmate_2490
,
437 .callback
= dmi_matched
,
438 .ident
= "Acer Aspire 5610",
440 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
441 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
443 .driver_data
= &quirk_acer_travelmate_2490
,
446 .callback
= dmi_matched
,
447 .ident
= "Acer Aspire 5630",
449 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
450 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
452 .driver_data
= &quirk_acer_travelmate_2490
,
455 .callback
= dmi_matched
,
456 .ident
= "Acer Aspire 5650",
458 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
459 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
461 .driver_data
= &quirk_acer_travelmate_2490
,
464 .callback
= dmi_matched
,
465 .ident
= "Acer Aspire 5680",
467 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
468 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
470 .driver_data
= &quirk_acer_travelmate_2490
,
473 .callback
= dmi_matched
,
474 .ident
= "Acer Aspire 9110",
476 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
477 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
479 .driver_data
= &quirk_acer_travelmate_2490
,
482 .callback
= dmi_matched
,
483 .ident
= "Acer TravelMate 2490",
485 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
486 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
488 .driver_data
= &quirk_acer_travelmate_2490
,
491 .callback
= dmi_matched
,
492 .ident
= "Acer TravelMate 4200",
494 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
495 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
497 .driver_data
= &quirk_acer_travelmate_2490
,
503 * This quirk list is for those non-acer machines that have AMW0_GUID1
504 * but supported by acer-wmi in past days. Keeping this quirk list here
505 * is only for backward compatible. Please do not add new machine to
506 * here anymore. Those non-acer machines should be supported by
507 * appropriate wmi drivers.
509 static const struct dmi_system_id non_acer_quirks
[] __initconst
= {
511 .callback
= dmi_matched
,
512 .ident
= "Fujitsu Siemens Amilo Li 1718",
514 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
515 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
517 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
520 .callback
= dmi_matched
,
521 .ident
= "Medion MD 98300",
523 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
524 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
526 .driver_data
= &quirk_medion_md_98300
,
529 .callback
= dmi_matched
,
530 .ident
= "Lenovo Ideapad S205",
532 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
533 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
535 .driver_data
= &quirk_lenovo_ideapad_s205
,
538 .callback
= dmi_matched
,
539 .ident
= "Lenovo Ideapad S205 (Brazos)",
541 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
542 DMI_MATCH(DMI_PRODUCT_NAME
, "Brazos"),
544 .driver_data
= &quirk_lenovo_ideapad_s205
,
547 .callback
= dmi_matched
,
548 .ident
= "Lenovo 3000 N200",
550 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
551 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
553 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
556 .callback
= dmi_matched
,
557 .ident
= "Lenovo Ideapad S205-10382JG",
559 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
560 DMI_MATCH(DMI_PRODUCT_NAME
, "10382JG"),
562 .driver_data
= &quirk_lenovo_ideapad_s205
,
565 .callback
= dmi_matched
,
566 .ident
= "Lenovo Ideapad S205-1038DPG",
568 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
569 DMI_MATCH(DMI_PRODUCT_NAME
, "1038DPG"),
571 .driver_data
= &quirk_lenovo_ideapad_s205
,
577 video_set_backlight_video_vendor(const struct dmi_system_id
*d
)
579 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
580 pr_info("Brightness must be controlled by generic video driver\n");
584 static const struct dmi_system_id video_vendor_dmi_table
[] __initconst
= {
586 .callback
= video_set_backlight_video_vendor
,
587 .ident
= "Acer TravelMate 4750",
589 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
590 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4750"),
594 .callback
= video_set_backlight_video_vendor
,
595 .ident
= "Acer Extensa 5235",
597 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
598 DMI_MATCH(DMI_PRODUCT_NAME
, "Extensa 5235"),
602 .callback
= video_set_backlight_video_vendor
,
603 .ident
= "Acer TravelMate 5760",
605 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
606 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5760"),
610 .callback
= video_set_backlight_video_vendor
,
611 .ident
= "Acer Aspire 5750",
613 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
614 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5750"),
618 .callback
= video_set_backlight_video_vendor
,
619 .ident
= "Acer Aspire 5741",
621 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
622 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5741"),
627 * Note no video_set_backlight_video_vendor, we must use the
628 * acer interface, as there is no native backlight interface.
630 .ident
= "Acer KAV80",
632 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
633 DMI_MATCH(DMI_PRODUCT_NAME
, "KAV80"),
639 /* Find which quirks are needed for a particular vendor/ model pair */
640 static void __init
find_quirks(void)
643 dmi_check_system(acer_quirks
);
644 dmi_check_system(non_acer_quirks
);
645 } else if (force_series
== 2490) {
646 quirks
= &quirk_acer_travelmate_2490
;
650 quirks
= &quirk_unknown
;
656 * General interface convenience methods
659 static bool has_cap(u32 cap
)
661 return interface
->capability
& cap
;
665 * AMW0 (V1) interface
682 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
683 struct acpi_buffer
*result
)
685 struct acpi_buffer input
;
687 input
.length
= sizeof(struct wmab_args
);
688 input
.pointer
= (u8
*)regbuf
;
690 status
= wmi_evaluate_method(AMW0_GUID1
, 0, 1, &input
, result
);
695 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
)
701 case ACER_CAP_MAILLED
:
702 switch (quirks
->mailled
) {
704 err
= ec_read(0xA, &result
);
707 *value
= (result
>> 7) & 0x1;
711 case ACER_CAP_WIRELESS
:
712 switch (quirks
->wireless
) {
714 err
= ec_read(0x7B, &result
);
717 *value
= result
& 0x1;
720 err
= ec_read(0x71, &result
);
723 *value
= result
& 0x1;
726 err
= ec_read(0x78, &result
);
729 *value
= result
& 0x1;
732 err
= ec_read(0xA, &result
);
735 *value
= (result
>> 2) & 0x1;
739 case ACER_CAP_BLUETOOTH
:
740 switch (quirks
->bluetooth
) {
742 err
= ec_read(0xA, &result
);
745 *value
= (result
>> 4) & 0x1;
749 case ACER_CAP_BRIGHTNESS
:
750 switch (quirks
->brightness
) {
752 err
= ec_read(0x83, &result
);
765 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
)
767 struct wmab_args args
;
769 args
.eax
= ACER_AMW0_WRITE
;
770 args
.ebx
= value
? (1<<8) : 0;
771 args
.ecx
= args
.edx
= 0;
774 case ACER_CAP_MAILLED
:
776 return AE_BAD_PARAMETER
;
777 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
779 case ACER_CAP_WIRELESS
:
781 return AE_BAD_PARAMETER
;
782 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
784 case ACER_CAP_BLUETOOTH
:
786 return AE_BAD_PARAMETER
;
787 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
789 case ACER_CAP_BRIGHTNESS
:
790 if (value
> max_brightness
)
791 return AE_BAD_PARAMETER
;
792 switch (quirks
->brightness
) {
794 return ec_write(0x83, value
);
801 /* Actually do the set */
802 return wmab_execute(&args
, NULL
);
805 static acpi_status __init
AMW0_find_mailled(void)
807 struct wmab_args args
;
809 acpi_status status
= AE_OK
;
810 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
811 union acpi_object
*obj
;
814 args
.ebx
= args
.ecx
= args
.edx
= 0;
816 status
= wmab_execute(&args
, &out
);
817 if (ACPI_FAILURE(status
))
820 obj
= (union acpi_object
*) out
.pointer
;
821 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
822 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
823 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
830 interface
->capability
|= ACER_CAP_MAILLED
;
837 static const struct acpi_device_id norfkill_ids
[] __initconst
= {
841 { "SNY5001", 0}, /* sony-laptop in charge */
846 static int __init
AMW0_set_cap_acpi_check_device(void)
848 const struct acpi_device_id
*id
;
850 for (id
= norfkill_ids
; id
->id
[0]; id
++)
851 if (acpi_dev_found(id
->id
))
857 static acpi_status __init
AMW0_set_capabilities(void)
859 struct wmab_args args
;
862 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
863 union acpi_object
*obj
;
866 * On laptops with this strange GUID (non Acer), normal probing doesn't
869 if (wmi_has_guid(AMW0_GUID2
)) {
870 if ((quirks
!= &quirk_unknown
) ||
871 !AMW0_set_cap_acpi_check_device())
872 interface
->capability
|= ACER_CAP_WIRELESS
;
876 args
.eax
= ACER_AMW0_WRITE
;
877 args
.ecx
= args
.edx
= 0;
879 args
.ebx
= 0xa2 << 8;
880 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
882 status
= wmab_execute(&args
, &out
);
883 if (ACPI_FAILURE(status
))
887 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
888 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
889 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
896 interface
->capability
|= ACER_CAP_WIRELESS
;
899 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
902 * It's ok to use existing buffer for next wmab_execute call.
903 * But we need to kfree(out.pointer) if next wmab_execute fail.
905 status
= wmab_execute(&args
, &out
);
906 if (ACPI_FAILURE(status
))
909 obj
= (union acpi_object
*) out
.pointer
;
910 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
911 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
912 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
919 interface
->capability
|= ACER_CAP_BLUETOOTH
;
922 * This appears to be safe to enable, since all Wistron based laptops
923 * appear to use the same EC register for brightness, even if they
924 * differ for wireless, etc
926 if (quirks
->brightness
>= 0)
927 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
935 static struct wmi_interface AMW0_interface
= {
939 static struct wmi_interface AMW0_V2_interface
= {
940 .type
= ACER_AMW0_V2
,
944 * New interface (The WMID interface)
947 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
949 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
950 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
951 union acpi_object
*obj
;
955 status
= wmi_evaluate_method(WMID_GUID1
, 0, method_id
, &input
, &result
);
957 if (ACPI_FAILURE(status
))
960 obj
= (union acpi_object
*) result
.pointer
;
962 if (obj
->type
== ACPI_TYPE_BUFFER
&&
963 (obj
->buffer
.length
== sizeof(u32
) ||
964 obj
->buffer
.length
== sizeof(u64
))) {
965 tmp
= *((u32
*) obj
->buffer
.pointer
);
966 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
967 tmp
= (u32
) obj
->integer
.value
;
974 kfree(result
.pointer
);
979 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
)
983 u32 result
, method_id
= 0;
986 case ACER_CAP_WIRELESS
:
987 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
989 case ACER_CAP_BLUETOOTH
:
990 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
992 case ACER_CAP_BRIGHTNESS
:
993 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
995 case ACER_CAP_THREEG
:
996 method_id
= ACER_WMID_GET_THREEG_METHODID
;
998 case ACER_CAP_MAILLED
:
999 if (quirks
->mailled
== 1) {
1000 ec_read(0x9f, &tmp
);
1008 status
= WMI_execute_u32(method_id
, 0, &result
);
1010 if (ACPI_SUCCESS(status
))
1011 *value
= (u8
)result
;
1016 static acpi_status
WMID_set_u32(u32 value
, u32 cap
)
1022 case ACER_CAP_BRIGHTNESS
:
1023 if (value
> max_brightness
)
1024 return AE_BAD_PARAMETER
;
1025 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
1027 case ACER_CAP_WIRELESS
:
1029 return AE_BAD_PARAMETER
;
1030 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
1032 case ACER_CAP_BLUETOOTH
:
1034 return AE_BAD_PARAMETER
;
1035 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
1037 case ACER_CAP_THREEG
:
1039 return AE_BAD_PARAMETER
;
1040 method_id
= ACER_WMID_SET_THREEG_METHODID
;
1042 case ACER_CAP_MAILLED
:
1044 return AE_BAD_PARAMETER
;
1045 if (quirks
->mailled
== 1) {
1046 param
= value
? 0x92 : 0x93;
1048 i8042_command(¶m
, 0x1059);
1049 i8042_unlock_chip();
1056 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
1059 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1061 struct wmid3_gds_return_value return_value
;
1063 union acpi_object
*obj
;
1064 struct wmid3_gds_get_input_param params
= {
1065 .function_num
= 0x1,
1066 .hotkey_number
= commun_fn_key_number
,
1069 struct acpi_buffer input
= {
1070 sizeof(struct wmid3_gds_get_input_param
),
1073 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1075 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1076 if (ACPI_FAILURE(status
))
1079 obj
= output
.pointer
;
1083 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1087 if (obj
->buffer
.length
!= 8) {
1088 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1093 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1096 if (return_value
.error_code
|| return_value
.ec_return_value
)
1097 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1099 return_value
.error_code
,
1100 return_value
.ec_return_value
);
1102 *value
= !!(return_value
.devices
& device
);
1107 static acpi_status
wmid_v2_get_u32(u32
*value
, u32 cap
)
1112 case ACER_CAP_WIRELESS
:
1113 device
= ACER_WMID3_GDS_WIRELESS
;
1115 case ACER_CAP_BLUETOOTH
:
1116 device
= ACER_WMID3_GDS_BLUETOOTH
;
1118 case ACER_CAP_THREEG
:
1119 device
= ACER_WMID3_GDS_THREEG
;
1124 return wmid3_get_device_status(value
, device
);
1127 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1129 struct wmid3_gds_return_value return_value
;
1131 union acpi_object
*obj
;
1133 struct wmid3_gds_get_input_param get_params
= {
1134 .function_num
= 0x1,
1135 .hotkey_number
= commun_fn_key_number
,
1136 .devices
= commun_func_bitmap
,
1138 struct acpi_buffer get_input
= {
1139 sizeof(struct wmid3_gds_get_input_param
),
1142 struct wmid3_gds_set_input_param set_params
= {
1143 .function_num
= 0x2,
1144 .hotkey_number
= commun_fn_key_number
,
1145 .devices
= commun_func_bitmap
,
1147 struct acpi_buffer set_input
= {
1148 sizeof(struct wmid3_gds_set_input_param
),
1151 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1152 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1154 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &get_input
, &output
);
1155 if (ACPI_FAILURE(status
))
1158 obj
= output
.pointer
;
1162 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1166 if (obj
->buffer
.length
!= 8) {
1167 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1172 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1175 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1176 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1177 return_value
.error_code
,
1178 return_value
.ec_return_value
);
1182 devices
= return_value
.devices
;
1183 set_params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1185 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &set_input
, &output2
);
1186 if (ACPI_FAILURE(status
))
1189 obj
= output2
.pointer
;
1193 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1197 if (obj
->buffer
.length
!= 4) {
1198 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1203 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1206 if (return_value
.error_code
|| return_value
.ec_return_value
)
1207 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1208 return_value
.error_code
,
1209 return_value
.ec_return_value
);
1214 static acpi_status
wmid_v2_set_u32(u32 value
, u32 cap
)
1219 case ACER_CAP_WIRELESS
:
1220 device
= ACER_WMID3_GDS_WIRELESS
;
1222 case ACER_CAP_BLUETOOTH
:
1223 device
= ACER_WMID3_GDS_BLUETOOTH
;
1225 case ACER_CAP_THREEG
:
1226 device
= ACER_WMID3_GDS_THREEG
;
1231 return wmid3_set_device_status(value
, device
);
1234 static void __init
type_aa_dmi_decode(const struct dmi_header
*header
, void *d
)
1236 struct hotkey_function_type_aa
*type_aa
;
1238 /* We are looking for OEM-specific Type AAh */
1239 if (header
->type
!= 0xAA)
1243 type_aa
= (struct hotkey_function_type_aa
*) header
;
1245 pr_info("Function bitmap for Communication Button: 0x%x\n",
1246 type_aa
->commun_func_bitmap
);
1247 commun_func_bitmap
= type_aa
->commun_func_bitmap
;
1249 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
1250 interface
->capability
|= ACER_CAP_WIRELESS
;
1251 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
1252 interface
->capability
|= ACER_CAP_THREEG
;
1253 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
1254 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1255 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_RFBTN
) {
1256 interface
->capability
|= ACER_CAP_RFBTN
;
1257 commun_func_bitmap
&= ~ACER_WMID3_GDS_RFBTN
;
1260 commun_fn_key_number
= type_aa
->commun_fn_key_number
;
1263 static acpi_status __init
WMID_set_capabilities(void)
1265 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1266 union acpi_object
*obj
;
1270 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
1271 if (ACPI_FAILURE(status
))
1274 obj
= (union acpi_object
*) out
.pointer
;
1276 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1277 (obj
->buffer
.length
== sizeof(u32
) ||
1278 obj
->buffer
.length
== sizeof(u64
))) {
1279 devices
= *((u32
*) obj
->buffer
.pointer
);
1280 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1281 devices
= (u32
) obj
->integer
.value
;
1291 pr_info("Function bitmap for Communication Device: 0x%x\n", devices
);
1293 interface
->capability
|= ACER_CAP_WIRELESS
;
1295 interface
->capability
|= ACER_CAP_THREEG
;
1297 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1299 if (!(devices
& 0x20))
1300 max_brightness
= 0x9;
1306 static struct wmi_interface wmid_interface
= {
1310 static struct wmi_interface wmid_v2_interface
= {
1311 .type
= ACER_WMID_v2
,
1315 * Generic Device (interface-independent)
1318 static acpi_status
get_u32(u32
*value
, u32 cap
)
1320 acpi_status status
= AE_ERROR
;
1322 switch (interface
->type
) {
1324 status
= AMW0_get_u32(value
, cap
);
1327 if (cap
== ACER_CAP_MAILLED
) {
1328 status
= AMW0_get_u32(value
, cap
);
1333 status
= WMID_get_u32(value
, cap
);
1336 if (cap
& (ACER_CAP_WIRELESS
|
1337 ACER_CAP_BLUETOOTH
|
1339 status
= wmid_v2_get_u32(value
, cap
);
1340 else if (wmi_has_guid(WMID_GUID2
))
1341 status
= WMID_get_u32(value
, cap
);
1348 static acpi_status
set_u32(u32 value
, u32 cap
)
1352 if (interface
->capability
& cap
) {
1353 switch (interface
->type
) {
1355 return AMW0_set_u32(value
, cap
);
1357 if (cap
== ACER_CAP_MAILLED
)
1358 return AMW0_set_u32(value
, cap
);
1361 * On some models, some WMID methods don't toggle
1362 * properly. For those cases, we want to run the AMW0
1363 * method afterwards to be certain we've really toggled
1366 if (cap
== ACER_CAP_WIRELESS
||
1367 cap
== ACER_CAP_BLUETOOTH
) {
1368 status
= WMID_set_u32(value
, cap
);
1369 if (ACPI_FAILURE(status
))
1372 return AMW0_set_u32(value
, cap
);
1376 return WMID_set_u32(value
, cap
);
1378 if (cap
& (ACER_CAP_WIRELESS
|
1379 ACER_CAP_BLUETOOTH
|
1381 return wmid_v2_set_u32(value
, cap
);
1382 else if (wmi_has_guid(WMID_GUID2
))
1383 return WMID_set_u32(value
, cap
);
1386 return AE_BAD_PARAMETER
;
1389 return AE_BAD_PARAMETER
;
1392 static void __init
acer_commandline_init(void)
1395 * These will all fail silently if the value given is invalid, or the
1396 * capability isn't available on the given interface
1399 set_u32(mailled
, ACER_CAP_MAILLED
);
1400 if (!has_type_aa
&& threeg
>= 0)
1401 set_u32(threeg
, ACER_CAP_THREEG
);
1402 if (brightness
>= 0)
1403 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1407 * LED device (Mail LED only, no other LEDs known yet)
1409 static void mail_led_set(struct led_classdev
*led_cdev
,
1410 enum led_brightness value
)
1412 set_u32(value
, ACER_CAP_MAILLED
);
1415 static struct led_classdev mail_led
= {
1416 .name
= "acer-wmi::mail",
1417 .brightness_set
= mail_led_set
,
1420 static int acer_led_init(struct device
*dev
)
1422 return led_classdev_register(dev
, &mail_led
);
1425 static void acer_led_exit(void)
1427 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1428 led_classdev_unregister(&mail_led
);
1434 static struct backlight_device
*acer_backlight_device
;
1436 static int read_brightness(struct backlight_device
*bd
)
1439 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1443 static int update_bl_status(struct backlight_device
*bd
)
1445 int intensity
= bd
->props
.brightness
;
1447 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1449 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1452 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1457 static const struct backlight_ops acer_bl_ops
= {
1458 .get_brightness
= read_brightness
,
1459 .update_status
= update_bl_status
,
1462 static int acer_backlight_init(struct device
*dev
)
1464 struct backlight_properties props
;
1465 struct backlight_device
*bd
;
1467 memset(&props
, 0, sizeof(struct backlight_properties
));
1468 props
.type
= BACKLIGHT_PLATFORM
;
1469 props
.max_brightness
= max_brightness
;
1470 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1473 pr_err("Could not register Acer backlight device\n");
1474 acer_backlight_device
= NULL
;
1478 acer_backlight_device
= bd
;
1480 bd
->props
.power
= FB_BLANK_UNBLANK
;
1481 bd
->props
.brightness
= read_brightness(bd
);
1482 backlight_update_status(bd
);
1486 static void acer_backlight_exit(void)
1488 backlight_device_unregister(acer_backlight_device
);
1492 * Accelerometer device
1494 static acpi_handle gsensor_handle
;
1496 static int acer_gsensor_init(void)
1499 struct acpi_buffer output
;
1500 union acpi_object out_obj
;
1502 output
.length
= sizeof(out_obj
);
1503 output
.pointer
= &out_obj
;
1504 status
= acpi_evaluate_object(gsensor_handle
, "_INI", NULL
, &output
);
1505 if (ACPI_FAILURE(status
))
1511 static int acer_gsensor_open(struct input_dev
*input
)
1513 return acer_gsensor_init();
1516 static int acer_gsensor_event(void)
1519 struct acpi_buffer output
;
1520 union acpi_object out_obj
[5];
1522 if (!has_cap(ACER_CAP_ACCEL
))
1525 output
.length
= sizeof(out_obj
);
1526 output
.pointer
= out_obj
;
1528 status
= acpi_evaluate_object(gsensor_handle
, "RDVL", NULL
, &output
);
1529 if (ACPI_FAILURE(status
))
1532 if (out_obj
->package
.count
!= 4)
1535 input_report_abs(acer_wmi_accel_dev
, ABS_X
,
1536 (s16
)out_obj
->package
.elements
[0].integer
.value
);
1537 input_report_abs(acer_wmi_accel_dev
, ABS_Y
,
1538 (s16
)out_obj
->package
.elements
[1].integer
.value
);
1539 input_report_abs(acer_wmi_accel_dev
, ABS_Z
,
1540 (s16
)out_obj
->package
.elements
[2].integer
.value
);
1541 input_sync(acer_wmi_accel_dev
);
1548 static void acer_rfkill_update(struct work_struct
*ignored
);
1549 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1550 static void acer_rfkill_update(struct work_struct
*ignored
)
1555 if (has_cap(ACER_CAP_WIRELESS
)) {
1556 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1557 if (ACPI_SUCCESS(status
)) {
1558 if (quirks
->wireless
== 3)
1559 rfkill_set_hw_state(wireless_rfkill
, !state
);
1561 rfkill_set_sw_state(wireless_rfkill
, !state
);
1565 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1566 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1567 if (ACPI_SUCCESS(status
))
1568 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1571 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1572 status
= get_u32(&state
, ACER_WMID3_GDS_THREEG
);
1573 if (ACPI_SUCCESS(status
))
1574 rfkill_set_sw_state(threeg_rfkill
, !state
);
1577 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1580 static int acer_rfkill_set(void *data
, bool blocked
)
1583 u32 cap
= (unsigned long)data
;
1585 if (rfkill_inited
) {
1586 status
= set_u32(!blocked
, cap
);
1587 if (ACPI_FAILURE(status
))
1594 static const struct rfkill_ops acer_rfkill_ops
= {
1595 .set_block
= acer_rfkill_set
,
1598 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1599 enum rfkill_type type
,
1600 char *name
, u32 cap
)
1603 struct rfkill
*rfkill_dev
;
1607 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1609 (void *)(unsigned long)cap
);
1611 return ERR_PTR(-ENOMEM
);
1613 status
= get_u32(&state
, cap
);
1615 err
= rfkill_register(rfkill_dev
);
1617 rfkill_destroy(rfkill_dev
);
1618 return ERR_PTR(err
);
1621 if (ACPI_SUCCESS(status
))
1622 rfkill_set_sw_state(rfkill_dev
, !state
);
1627 static int acer_rfkill_init(struct device
*dev
)
1631 if (has_cap(ACER_CAP_WIRELESS
)) {
1632 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1633 "acer-wireless", ACER_CAP_WIRELESS
);
1634 if (IS_ERR(wireless_rfkill
)) {
1635 err
= PTR_ERR(wireless_rfkill
);
1636 goto error_wireless
;
1640 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1641 bluetooth_rfkill
= acer_rfkill_register(dev
,
1642 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1643 ACER_CAP_BLUETOOTH
);
1644 if (IS_ERR(bluetooth_rfkill
)) {
1645 err
= PTR_ERR(bluetooth_rfkill
);
1646 goto error_bluetooth
;
1650 if (has_cap(ACER_CAP_THREEG
)) {
1651 threeg_rfkill
= acer_rfkill_register(dev
,
1652 RFKILL_TYPE_WWAN
, "acer-threeg",
1654 if (IS_ERR(threeg_rfkill
)) {
1655 err
= PTR_ERR(threeg_rfkill
);
1660 rfkill_inited
= true;
1662 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1663 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1664 schedule_delayed_work(&acer_rfkill_work
,
1665 round_jiffies_relative(HZ
));
1670 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1671 rfkill_unregister(bluetooth_rfkill
);
1672 rfkill_destroy(bluetooth_rfkill
);
1675 if (has_cap(ACER_CAP_WIRELESS
)) {
1676 rfkill_unregister(wireless_rfkill
);
1677 rfkill_destroy(wireless_rfkill
);
1683 static void acer_rfkill_exit(void)
1685 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1686 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1687 cancel_delayed_work_sync(&acer_rfkill_work
);
1689 if (has_cap(ACER_CAP_WIRELESS
)) {
1690 rfkill_unregister(wireless_rfkill
);
1691 rfkill_destroy(wireless_rfkill
);
1694 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1695 rfkill_unregister(bluetooth_rfkill
);
1696 rfkill_destroy(bluetooth_rfkill
);
1699 if (has_cap(ACER_CAP_THREEG
)) {
1700 rfkill_unregister(threeg_rfkill
);
1701 rfkill_destroy(threeg_rfkill
);
1706 static void acer_wmi_notify(u32 value
, void *context
)
1708 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1709 union acpi_object
*obj
;
1710 struct event_return_value return_value
;
1713 const struct key_entry
*key
;
1716 status
= wmi_get_event_data(value
, &response
);
1717 if (status
!= AE_OK
) {
1718 pr_warn("bad event status 0x%x\n", status
);
1722 obj
= (union acpi_object
*)response
.pointer
;
1726 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1727 pr_warn("Unknown response received %d\n", obj
->type
);
1731 if (obj
->buffer
.length
!= 8) {
1732 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1737 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1740 switch (return_value
.function
) {
1741 case WMID_HOTKEY_EVENT
:
1742 device_state
= return_value
.device_state
;
1743 pr_debug("device state: 0x%x\n", device_state
);
1745 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1746 return_value
.key_num
);
1748 pr_warn("Unknown key number - 0x%x\n",
1749 return_value
.key_num
);
1751 scancode
= return_value
.key_num
;
1752 switch (key
->keycode
) {
1755 if (has_cap(ACER_CAP_WIRELESS
))
1756 rfkill_set_sw_state(wireless_rfkill
,
1757 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1758 if (has_cap(ACER_CAP_THREEG
))
1759 rfkill_set_sw_state(threeg_rfkill
,
1760 !(device_state
& ACER_WMID3_GDS_THREEG
));
1761 if (has_cap(ACER_CAP_BLUETOOTH
))
1762 rfkill_set_sw_state(bluetooth_rfkill
,
1763 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1765 case KEY_TOUCHPAD_TOGGLE
:
1766 scancode
= (device_state
& ACER_WMID3_GDS_TOUCHPAD
) ?
1767 KEY_TOUCHPAD_ON
: KEY_TOUCHPAD_OFF
;
1769 sparse_keymap_report_event(acer_wmi_input_dev
, scancode
, 1, true);
1772 case WMID_ACCEL_EVENT
:
1773 acer_gsensor_event();
1776 pr_warn("Unknown function number - %d - %d\n",
1777 return_value
.function
, return_value
.key_num
);
1782 static acpi_status __init
1783 wmid3_set_function_mode(struct func_input_params
*params
,
1784 struct func_return_value
*return_value
)
1787 union acpi_object
*obj
;
1789 struct acpi_buffer input
= { sizeof(struct func_input_params
), params
};
1790 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1792 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1793 if (ACPI_FAILURE(status
))
1796 obj
= output
.pointer
;
1800 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1804 if (obj
->buffer
.length
!= 4) {
1805 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1810 *return_value
= *((struct func_return_value
*)obj
->buffer
.pointer
);
1816 static int __init
acer_wmi_enable_ec_raw(void)
1818 struct func_return_value return_value
;
1820 struct func_input_params params
= {
1821 .function_num
= 0x1,
1822 .commun_devices
= 0xFFFF,
1824 .app_status
= 0x00, /* Launch Manager Deactive */
1828 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1830 if (return_value
.error_code
|| return_value
.ec_return_value
)
1831 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1832 return_value
.error_code
,
1833 return_value
.ec_return_value
);
1835 pr_info("Enabled EC raw mode\n");
1840 static int __init
acer_wmi_enable_lm(void)
1842 struct func_return_value return_value
;
1844 struct func_input_params params
= {
1845 .function_num
= 0x1,
1846 .commun_devices
= 0xFFFF,
1848 .app_status
= 0x01, /* Launch Manager Active */
1852 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1854 if (return_value
.error_code
|| return_value
.ec_return_value
)
1855 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1856 return_value
.error_code
,
1857 return_value
.ec_return_value
);
1862 static int __init
acer_wmi_enable_rf_button(void)
1864 struct func_return_value return_value
;
1866 struct func_input_params params
= {
1867 .function_num
= 0x1,
1868 .commun_devices
= 0xFFFF,
1870 .app_status
= 0x10, /* RF Button Active */
1874 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1876 if (return_value
.error_code
|| return_value
.ec_return_value
)
1877 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1878 return_value
.error_code
,
1879 return_value
.ec_return_value
);
1884 static int __init
acer_wmi_accel_setup(void)
1886 struct acpi_device
*adev
;
1889 adev
= acpi_dev_get_first_match_dev("BST0001", NULL
, -1);
1893 gsensor_handle
= acpi_device_handle(adev
);
1896 interface
->capability
|= ACER_CAP_ACCEL
;
1898 acer_wmi_accel_dev
= input_allocate_device();
1899 if (!acer_wmi_accel_dev
)
1902 acer_wmi_accel_dev
->open
= acer_gsensor_open
;
1904 acer_wmi_accel_dev
->name
= "Acer BMA150 accelerometer";
1905 acer_wmi_accel_dev
->phys
= "wmi/input1";
1906 acer_wmi_accel_dev
->id
.bustype
= BUS_HOST
;
1907 acer_wmi_accel_dev
->evbit
[0] = BIT_MASK(EV_ABS
);
1908 input_set_abs_params(acer_wmi_accel_dev
, ABS_X
, -16384, 16384, 0, 0);
1909 input_set_abs_params(acer_wmi_accel_dev
, ABS_Y
, -16384, 16384, 0, 0);
1910 input_set_abs_params(acer_wmi_accel_dev
, ABS_Z
, -16384, 16384, 0, 0);
1912 err
= input_register_device(acer_wmi_accel_dev
);
1919 input_free_device(acer_wmi_accel_dev
);
1923 static void acer_wmi_accel_destroy(void)
1925 input_unregister_device(acer_wmi_accel_dev
);
1928 static int __init
acer_wmi_input_setup(void)
1933 acer_wmi_input_dev
= input_allocate_device();
1934 if (!acer_wmi_input_dev
)
1937 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1938 acer_wmi_input_dev
->phys
= "wmi/input0";
1939 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1941 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1945 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1946 acer_wmi_notify
, NULL
);
1947 if (ACPI_FAILURE(status
)) {
1952 err
= input_register_device(acer_wmi_input_dev
);
1954 goto err_uninstall_notifier
;
1958 err_uninstall_notifier
:
1959 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1961 input_free_device(acer_wmi_input_dev
);
1965 static void acer_wmi_input_destroy(void)
1967 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1968 input_unregister_device(acer_wmi_input_dev
);
1974 static u32
get_wmid_devices(void)
1976 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1977 union acpi_object
*obj
;
1981 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
1982 if (ACPI_FAILURE(status
))
1985 obj
= (union acpi_object
*) out
.pointer
;
1987 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1988 (obj
->buffer
.length
== sizeof(u32
) ||
1989 obj
->buffer
.length
== sizeof(u64
))) {
1990 devices
= *((u32
*) obj
->buffer
.pointer
);
1991 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1992 devices
= (u32
) obj
->integer
.value
;
2003 static int acer_platform_probe(struct platform_device
*device
)
2007 if (has_cap(ACER_CAP_MAILLED
)) {
2008 err
= acer_led_init(&device
->dev
);
2013 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2014 err
= acer_backlight_init(&device
->dev
);
2016 goto error_brightness
;
2019 err
= acer_rfkill_init(&device
->dev
);
2026 if (has_cap(ACER_CAP_BRIGHTNESS
))
2027 acer_backlight_exit();
2029 if (has_cap(ACER_CAP_MAILLED
))
2035 static int acer_platform_remove(struct platform_device
*device
)
2037 if (has_cap(ACER_CAP_MAILLED
))
2039 if (has_cap(ACER_CAP_BRIGHTNESS
))
2040 acer_backlight_exit();
2046 #ifdef CONFIG_PM_SLEEP
2047 static int acer_suspend(struct device
*dev
)
2050 struct acer_data
*data
= &interface
->data
;
2055 if (has_cap(ACER_CAP_MAILLED
)) {
2056 get_u32(&value
, ACER_CAP_MAILLED
);
2057 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2058 data
->mailled
= value
;
2061 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2062 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
2063 data
->brightness
= value
;
2069 static int acer_resume(struct device
*dev
)
2071 struct acer_data
*data
= &interface
->data
;
2076 if (has_cap(ACER_CAP_MAILLED
))
2077 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
2079 if (has_cap(ACER_CAP_BRIGHTNESS
))
2080 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
2082 if (has_cap(ACER_CAP_ACCEL
))
2083 acer_gsensor_init();
2088 #define acer_suspend NULL
2089 #define acer_resume NULL
2092 static SIMPLE_DEV_PM_OPS(acer_pm
, acer_suspend
, acer_resume
);
2094 static void acer_platform_shutdown(struct platform_device
*device
)
2096 struct acer_data
*data
= &interface
->data
;
2101 if (has_cap(ACER_CAP_MAILLED
))
2102 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2105 static struct platform_driver acer_platform_driver
= {
2110 .probe
= acer_platform_probe
,
2111 .remove
= acer_platform_remove
,
2112 .shutdown
= acer_platform_shutdown
,
2115 static struct platform_device
*acer_platform_device
;
2117 static void remove_debugfs(void)
2119 debugfs_remove_recursive(interface
->debug
.root
);
2122 static void __init
create_debugfs(void)
2124 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
2126 debugfs_create_u32("devices", S_IRUGO
, interface
->debug
.root
,
2127 &interface
->debug
.wmid_devices
);
2130 static int __init
acer_wmi_init(void)
2134 pr_info("Acer Laptop ACPI-WMI Extras\n");
2136 if (dmi_check_system(acer_blacklist
)) {
2137 pr_info("Blacklisted hardware detected - not loading\n");
2144 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2145 * machines like Lenovo, Fujitsu and Medion. In the past days,
2146 * acer-wmi driver handled those non-Acer machines by quirks list.
2147 * But actually acer-wmi driver was loaded on any machines that have
2148 * AMW0_GUID1. This behavior is strange because those machines should
2149 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2150 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2151 * should be in Acer/Gateway/Packard Bell white list, or it's already
2152 * in the past quirk list.
2154 if (wmi_has_guid(AMW0_GUID1
) &&
2155 !dmi_check_system(amw0_whitelist
) &&
2156 quirks
== &quirk_unknown
) {
2157 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
2162 * Detect which ACPI-WMI interface we're using.
2164 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2165 interface
= &AMW0_V2_interface
;
2167 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2168 interface
= &wmid_interface
;
2170 if (wmi_has_guid(WMID_GUID3
))
2171 interface
= &wmid_v2_interface
;
2174 dmi_walk(type_aa_dmi_decode
, NULL
);
2176 if (wmi_has_guid(WMID_GUID2
) && interface
) {
2177 if (!has_type_aa
&& ACPI_FAILURE(WMID_set_capabilities())) {
2178 pr_err("Unable to detect available WMID devices\n");
2181 /* WMID always provides brightness methods */
2182 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
2183 } else if (!wmi_has_guid(WMID_GUID2
) && interface
&& !has_type_aa
) {
2184 pr_err("No WMID device detection method found\n");
2188 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
2189 interface
= &AMW0_interface
;
2191 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2192 pr_err("Unable to detect available AMW0 devices\n");
2197 if (wmi_has_guid(AMW0_GUID1
))
2198 AMW0_find_mailled();
2201 pr_err("No or unsupported WMI interface, unable to load\n");
2207 if (dmi_check_system(video_vendor_dmi_table
))
2208 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2210 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2211 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
2213 if (wmi_has_guid(WMID_GUID3
)) {
2214 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2215 pr_warn("Cannot enable RF Button Driver\n");
2218 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2219 pr_err("Cannot enable EC raw mode\n");
2222 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2223 pr_err("Cannot enable Launch Manager mode\n");
2226 } else if (ec_raw_mode
) {
2227 pr_info("No WMID EC raw mode enable method\n");
2230 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
2231 err
= acer_wmi_input_setup();
2234 err
= acer_wmi_accel_setup();
2235 if (err
&& err
!= -ENODEV
)
2236 pr_warn("Cannot enable accelerometer\n");
2239 err
= platform_driver_register(&acer_platform_driver
);
2241 pr_err("Unable to register platform driver\n");
2242 goto error_platform_register
;
2245 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
2246 if (!acer_platform_device
) {
2248 goto error_device_alloc
;
2251 err
= platform_device_add(acer_platform_device
);
2253 goto error_device_add
;
2255 if (wmi_has_guid(WMID_GUID2
)) {
2256 interface
->debug
.wmid_devices
= get_wmid_devices();
2260 /* Override any initial settings with values from the commandline */
2261 acer_commandline_init();
2266 platform_device_put(acer_platform_device
);
2268 platform_driver_unregister(&acer_platform_driver
);
2269 error_platform_register
:
2270 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2271 acer_wmi_input_destroy();
2272 if (has_cap(ACER_CAP_ACCEL
))
2273 acer_wmi_accel_destroy();
2278 static void __exit
acer_wmi_exit(void)
2280 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2281 acer_wmi_input_destroy();
2283 if (has_cap(ACER_CAP_ACCEL
))
2284 acer_wmi_accel_destroy();
2287 platform_device_unregister(acer_platform_device
);
2288 platform_driver_unregister(&acer_platform_driver
);
2290 pr_info("Acer Laptop WMI Extras unloaded\n");
2294 module_init(acer_wmi_init
);
2295 module_exit(acer_wmi_exit
);