2 * Acer WMI Laptop Extras
4 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
7 * Copyright (C) 2005-2007 E.M. Smith
8 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/dmi.h>
33 #include <linux/backlight.h>
34 #include <linux/leds.h>
35 #include <linux/platform_device.h>
36 #include <linux/acpi.h>
37 #include <linux/i8042.h>
38 #include <linux/rfkill.h>
39 #include <linux/workqueue.h>
40 #include <linux/debugfs.h>
41 #include <linux/slab.h>
42 #include <linux/input.h>
43 #include <linux/input/sparse-keymap.h>
44 #include <acpi/video.h>
46 MODULE_AUTHOR("Carlos Corbacho");
47 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
48 MODULE_LICENSE("GPL");
52 * Meaning is unknown - this number is required for writing to ACPI for AMW0
53 * (it's also used in acerhk when directly accessing the BIOS)
55 #define ACER_AMW0_WRITE 0x9610
58 * Bit masks for the AMW0 interface
60 #define ACER_AMW0_WIRELESS_MASK 0x35
61 #define ACER_AMW0_BLUETOOTH_MASK 0x34
62 #define ACER_AMW0_MAILLED_MASK 0x31
65 * Method IDs for WMID interface
67 #define ACER_WMID_GET_WIRELESS_METHODID 1
68 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
69 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
70 #define ACER_WMID_SET_WIRELESS_METHODID 4
71 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
72 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
73 #define ACER_WMID_GET_THREEG_METHODID 10
74 #define ACER_WMID_SET_THREEG_METHODID 11
77 * Acer ACPI method GUIDs
79 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
80 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
81 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
82 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
83 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
86 * Acer ACPI event GUIDs
88 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
90 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
91 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
92 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
94 enum acer_wmi_event_ids
{
95 WMID_HOTKEY_EVENT
= 0x1,
96 WMID_ACCEL_EVENT
= 0x5,
99 static const struct key_entry acer_wmi_keymap
[] __initconst
= {
100 {KE_KEY
, 0x01, {KEY_WLAN
} }, /* WiFi */
101 {KE_KEY
, 0x03, {KEY_WLAN
} }, /* WiFi */
102 {KE_KEY
, 0x04, {KEY_WLAN
} }, /* WiFi */
103 {KE_KEY
, 0x12, {KEY_BLUETOOTH
} }, /* BT */
104 {KE_KEY
, 0x21, {KEY_PROG1
} }, /* Backup */
105 {KE_KEY
, 0x22, {KEY_PROG2
} }, /* Arcade */
106 {KE_KEY
, 0x23, {KEY_PROG3
} }, /* P_Key */
107 {KE_KEY
, 0x24, {KEY_PROG4
} }, /* Social networking_Key */
108 {KE_KEY
, 0x29, {KEY_PROG3
} }, /* P_Key for TM8372 */
109 {KE_IGNORE
, 0x41, {KEY_MUTE
} },
110 {KE_IGNORE
, 0x42, {KEY_PREVIOUSSONG
} },
111 {KE_IGNORE
, 0x4d, {KEY_PREVIOUSSONG
} },
112 {KE_IGNORE
, 0x43, {KEY_NEXTSONG
} },
113 {KE_IGNORE
, 0x4e, {KEY_NEXTSONG
} },
114 {KE_IGNORE
, 0x44, {KEY_PLAYPAUSE
} },
115 {KE_IGNORE
, 0x4f, {KEY_PLAYPAUSE
} },
116 {KE_IGNORE
, 0x45, {KEY_STOP
} },
117 {KE_IGNORE
, 0x50, {KEY_STOP
} },
118 {KE_IGNORE
, 0x48, {KEY_VOLUMEUP
} },
119 {KE_IGNORE
, 0x49, {KEY_VOLUMEDOWN
} },
120 {KE_IGNORE
, 0x4a, {KEY_VOLUMEDOWN
} },
121 {KE_IGNORE
, 0x61, {KEY_SWITCHVIDEOMODE
} },
122 {KE_IGNORE
, 0x62, {KEY_BRIGHTNESSUP
} },
123 {KE_IGNORE
, 0x63, {KEY_BRIGHTNESSDOWN
} },
124 {KE_KEY
, 0x64, {KEY_SWITCHVIDEOMODE
} }, /* Display Switch */
125 {KE_IGNORE
, 0x81, {KEY_SLEEP
} },
126 {KE_KEY
, 0x82, {KEY_TOUCHPAD_TOGGLE
} }, /* Touch Pad Toggle */
127 {KE_KEY
, KEY_TOUCHPAD_ON
, {KEY_TOUCHPAD_ON
} },
128 {KE_KEY
, KEY_TOUCHPAD_OFF
, {KEY_TOUCHPAD_OFF
} },
129 {KE_IGNORE
, 0x83, {KEY_TOUCHPAD_TOGGLE
} },
130 {KE_KEY
, 0x85, {KEY_TOUCHPAD_TOGGLE
} },
131 {KE_KEY
, 0x86, {KEY_WLAN
} },
132 {KE_KEY
, 0x87, {KEY_POWER
} },
136 static struct input_dev
*acer_wmi_input_dev
;
137 static struct input_dev
*acer_wmi_accel_dev
;
139 struct event_return_value
{
144 } __attribute__((packed
));
147 * GUID3 Get Device Status device flags
149 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
150 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
151 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
152 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
153 #define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
155 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
157 /* Hotkey Customized Setting and Acer Application Status.
158 * Set Device Default Value and Report Acer Application Status.
159 * When Acer Application starts, it will run this method to inform
160 * BIOS/EC that Acer Application is on.
162 * Bit[0]: Launch Manager Status
164 * Bit[2]: Device Control Status
165 * Bit[3]: Acer Power Button Utility Status
166 * Bit[4]: RF Button Status
167 * Bit[5]: ODD PM Status
168 * Bit[6]: Device Default Value Control
169 * Bit[7]: Hall Sensor Application Status
171 struct func_input_params
{
172 u8 function_num
; /* Function Number */
173 u16 commun_devices
; /* Communication type devices default status */
174 u16 devices
; /* Other type devices default status */
175 u8 app_status
; /* Acer Device Status. LM, ePM, RF Button... */
176 u8 app_mask
; /* Bit mask to app_status */
178 } __attribute__((packed
));
180 struct func_return_value
{
181 u8 error_code
; /* Error Code */
182 u8 ec_return_value
; /* EC Return Value */
184 } __attribute__((packed
));
186 struct wmid3_gds_set_input_param
{ /* Set Device Status input parameter */
187 u8 function_num
; /* Function Number */
188 u8 hotkey_number
; /* Hotkey Number */
189 u16 devices
; /* Set Device */
190 u8 volume_value
; /* Volume Value */
191 } __attribute__((packed
));
193 struct wmid3_gds_get_input_param
{ /* Get Device Status input parameter */
194 u8 function_num
; /* Function Number */
195 u8 hotkey_number
; /* Hotkey Number */
196 u16 devices
; /* Get Device */
197 } __attribute__((packed
));
199 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
200 u8 error_code
; /* Error Code */
201 u8 ec_return_value
; /* EC Return Value */
202 u16 devices
; /* Current Device Status */
204 } __attribute__((packed
));
206 struct hotkey_function_type_aa
{
210 u16 commun_func_bitmap
;
211 u16 application_func_bitmap
;
212 u16 media_func_bitmap
;
213 u16 display_func_bitmap
;
214 u16 others_func_bitmap
;
215 u8 commun_fn_key_number
;
216 } __attribute__((packed
));
219 * Interface capability flags
221 #define ACER_CAP_MAILLED (1<<0)
222 #define ACER_CAP_WIRELESS (1<<1)
223 #define ACER_CAP_BLUETOOTH (1<<2)
224 #define ACER_CAP_BRIGHTNESS (1<<3)
225 #define ACER_CAP_THREEG (1<<4)
226 #define ACER_CAP_ACCEL (1<<5)
227 #define ACER_CAP_RFBTN (1<<6)
228 #define ACER_CAP_ANY (0xFFFFFFFF)
231 * Interface type flags
233 enum interface_flags
{
240 #define ACER_DEFAULT_WIRELESS 0
241 #define ACER_DEFAULT_BLUETOOTH 0
242 #define ACER_DEFAULT_MAILLED 0
243 #define ACER_DEFAULT_THREEG 0
245 static int max_brightness
= 0xF;
247 static int mailled
= -1;
248 static int brightness
= -1;
249 static int threeg
= -1;
250 static int force_series
;
251 static bool ec_raw_mode
;
252 static bool has_type_aa
;
253 static u16 commun_func_bitmap
;
254 static u8 commun_fn_key_number
;
256 module_param(mailled
, int, 0444);
257 module_param(brightness
, int, 0444);
258 module_param(threeg
, int, 0444);
259 module_param(force_series
, int, 0444);
260 module_param(ec_raw_mode
, bool, 0444);
261 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
262 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
263 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
264 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
265 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
275 struct dentry
*devices
;
279 static struct rfkill
*wireless_rfkill
;
280 static struct rfkill
*bluetooth_rfkill
;
281 static struct rfkill
*threeg_rfkill
;
282 static bool rfkill_inited
;
284 /* Each low-level interface must define at least some of the following */
285 struct wmi_interface
{
286 /* The WMI device type */
289 /* The capabilities this interface provides */
292 /* Private data for the current interface */
293 struct acer_data data
;
295 /* debugfs entries associated with this interface */
296 struct acer_debug debug
;
299 /* The static interface pointer, points to the currently detected interface */
300 static struct wmi_interface
*interface
;
303 * Embedded Controller quirks
304 * Some laptops require us to directly access the EC to either enable or query
305 * features that are not available through WMI.
315 static struct quirk_entry
*quirks
;
317 static void __init
set_quirks(void)
323 interface
->capability
|= ACER_CAP_MAILLED
;
325 if (quirks
->brightness
)
326 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
329 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
331 quirks
= dmi
->driver_data
;
335 static struct quirk_entry quirk_unknown
= {
338 static struct quirk_entry quirk_acer_aspire_1520
= {
342 static struct quirk_entry quirk_acer_travelmate_2490
= {
346 /* This AMW0 laptop has no bluetooth */
347 static struct quirk_entry quirk_medion_md_98300
= {
351 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
355 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
359 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
360 static const struct dmi_system_id acer_blacklist
[] __initconst
= {
362 .ident
= "Acer Aspire One (SSD)",
364 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
365 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
369 .ident
= "Acer Aspire One (HDD)",
371 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
372 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
378 static const struct dmi_system_id amw0_whitelist
[] __initconst
= {
382 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
388 DMI_MATCH(DMI_SYS_VENDOR
, "Gateway"),
392 .ident
= "Packard Bell",
394 DMI_MATCH(DMI_SYS_VENDOR
, "Packard Bell"),
401 * This quirk table is only for Acer/Gateway/Packard Bell family
402 * that those machines are supported by acer-wmi driver.
404 static const struct dmi_system_id acer_quirks
[] __initconst
= {
406 .callback
= dmi_matched
,
407 .ident
= "Acer Aspire 1360",
409 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
410 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
412 .driver_data
= &quirk_acer_aspire_1520
,
415 .callback
= dmi_matched
,
416 .ident
= "Acer Aspire 1520",
418 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
419 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
421 .driver_data
= &quirk_acer_aspire_1520
,
424 .callback
= dmi_matched
,
425 .ident
= "Acer Aspire 3100",
427 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
428 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
430 .driver_data
= &quirk_acer_travelmate_2490
,
433 .callback
= dmi_matched
,
434 .ident
= "Acer Aspire 3610",
436 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
437 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
439 .driver_data
= &quirk_acer_travelmate_2490
,
442 .callback
= dmi_matched
,
443 .ident
= "Acer Aspire 5100",
445 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
446 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
448 .driver_data
= &quirk_acer_travelmate_2490
,
451 .callback
= dmi_matched
,
452 .ident
= "Acer Aspire 5610",
454 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
455 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
457 .driver_data
= &quirk_acer_travelmate_2490
,
460 .callback
= dmi_matched
,
461 .ident
= "Acer Aspire 5630",
463 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
464 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
466 .driver_data
= &quirk_acer_travelmate_2490
,
469 .callback
= dmi_matched
,
470 .ident
= "Acer Aspire 5650",
472 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
473 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
475 .driver_data
= &quirk_acer_travelmate_2490
,
478 .callback
= dmi_matched
,
479 .ident
= "Acer Aspire 5680",
481 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
482 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
484 .driver_data
= &quirk_acer_travelmate_2490
,
487 .callback
= dmi_matched
,
488 .ident
= "Acer Aspire 9110",
490 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
491 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
493 .driver_data
= &quirk_acer_travelmate_2490
,
496 .callback
= dmi_matched
,
497 .ident
= "Acer TravelMate 2490",
499 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
500 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
502 .driver_data
= &quirk_acer_travelmate_2490
,
505 .callback
= dmi_matched
,
506 .ident
= "Acer TravelMate 4200",
508 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
509 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
511 .driver_data
= &quirk_acer_travelmate_2490
,
517 * This quirk list is for those non-acer machines that have AMW0_GUID1
518 * but supported by acer-wmi in past days. Keeping this quirk list here
519 * is only for backward compatible. Please do not add new machine to
520 * here anymore. Those non-acer machines should be supported by
521 * appropriate wmi drivers.
523 static const struct dmi_system_id non_acer_quirks
[] __initconst
= {
525 .callback
= dmi_matched
,
526 .ident
= "Fujitsu Siemens Amilo Li 1718",
528 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
529 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
531 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
534 .callback
= dmi_matched
,
535 .ident
= "Medion MD 98300",
537 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
538 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
540 .driver_data
= &quirk_medion_md_98300
,
543 .callback
= dmi_matched
,
544 .ident
= "Lenovo Ideapad S205",
546 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
547 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
549 .driver_data
= &quirk_lenovo_ideapad_s205
,
552 .callback
= dmi_matched
,
553 .ident
= "Lenovo Ideapad S205 (Brazos)",
555 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
556 DMI_MATCH(DMI_PRODUCT_NAME
, "Brazos"),
558 .driver_data
= &quirk_lenovo_ideapad_s205
,
561 .callback
= dmi_matched
,
562 .ident
= "Lenovo 3000 N200",
564 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
565 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
567 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
570 .callback
= dmi_matched
,
571 .ident
= "Lenovo Ideapad S205-10382JG",
573 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
574 DMI_MATCH(DMI_PRODUCT_NAME
, "10382JG"),
576 .driver_data
= &quirk_lenovo_ideapad_s205
,
579 .callback
= dmi_matched
,
580 .ident
= "Lenovo Ideapad S205-1038DPG",
582 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
583 DMI_MATCH(DMI_PRODUCT_NAME
, "1038DPG"),
585 .driver_data
= &quirk_lenovo_ideapad_s205
,
591 video_set_backlight_video_vendor(const struct dmi_system_id
*d
)
593 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
594 pr_info("Brightness must be controlled by generic video driver\n");
598 static const struct dmi_system_id video_vendor_dmi_table
[] __initconst
= {
600 .callback
= video_set_backlight_video_vendor
,
601 .ident
= "Acer TravelMate 4750",
603 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
604 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4750"),
608 .callback
= video_set_backlight_video_vendor
,
609 .ident
= "Acer Extensa 5235",
611 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
612 DMI_MATCH(DMI_PRODUCT_NAME
, "Extensa 5235"),
616 .callback
= video_set_backlight_video_vendor
,
617 .ident
= "Acer TravelMate 5760",
619 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
620 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5760"),
624 .callback
= video_set_backlight_video_vendor
,
625 .ident
= "Acer Aspire 5750",
627 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
628 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5750"),
632 .callback
= video_set_backlight_video_vendor
,
633 .ident
= "Acer Aspire 5741",
635 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
636 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5741"),
641 * Note no video_set_backlight_video_vendor, we must use the
642 * acer interface, as there is no native backlight interface.
644 .ident
= "Acer KAV80",
646 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
647 DMI_MATCH(DMI_PRODUCT_NAME
, "KAV80"),
653 /* Find which quirks are needed for a particular vendor/ model pair */
654 static void __init
find_quirks(void)
657 dmi_check_system(acer_quirks
);
658 dmi_check_system(non_acer_quirks
);
659 } else if (force_series
== 2490) {
660 quirks
= &quirk_acer_travelmate_2490
;
664 quirks
= &quirk_unknown
;
670 * General interface convenience methods
673 static bool has_cap(u32 cap
)
675 return interface
->capability
& cap
;
679 * AMW0 (V1) interface
696 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
697 struct acpi_buffer
*result
)
699 struct acpi_buffer input
;
701 input
.length
= sizeof(struct wmab_args
);
702 input
.pointer
= (u8
*)regbuf
;
704 status
= wmi_evaluate_method(AMW0_GUID1
, 0, 1, &input
, result
);
709 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
)
715 case ACER_CAP_MAILLED
:
716 switch (quirks
->mailled
) {
718 err
= ec_read(0xA, &result
);
721 *value
= (result
>> 7) & 0x1;
725 case ACER_CAP_WIRELESS
:
726 switch (quirks
->wireless
) {
728 err
= ec_read(0x7B, &result
);
731 *value
= result
& 0x1;
734 err
= ec_read(0x71, &result
);
737 *value
= result
& 0x1;
740 err
= ec_read(0x78, &result
);
743 *value
= result
& 0x1;
746 err
= ec_read(0xA, &result
);
749 *value
= (result
>> 2) & 0x1;
753 case ACER_CAP_BLUETOOTH
:
754 switch (quirks
->bluetooth
) {
756 err
= ec_read(0xA, &result
);
759 *value
= (result
>> 4) & 0x1;
763 case ACER_CAP_BRIGHTNESS
:
764 switch (quirks
->brightness
) {
766 err
= ec_read(0x83, &result
);
779 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
)
781 struct wmab_args args
;
783 args
.eax
= ACER_AMW0_WRITE
;
784 args
.ebx
= value
? (1<<8) : 0;
785 args
.ecx
= args
.edx
= 0;
788 case ACER_CAP_MAILLED
:
790 return AE_BAD_PARAMETER
;
791 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
793 case ACER_CAP_WIRELESS
:
795 return AE_BAD_PARAMETER
;
796 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
798 case ACER_CAP_BLUETOOTH
:
800 return AE_BAD_PARAMETER
;
801 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
803 case ACER_CAP_BRIGHTNESS
:
804 if (value
> max_brightness
)
805 return AE_BAD_PARAMETER
;
806 switch (quirks
->brightness
) {
808 return ec_write(0x83, value
);
815 /* Actually do the set */
816 return wmab_execute(&args
, NULL
);
819 static acpi_status __init
AMW0_find_mailled(void)
821 struct wmab_args args
;
823 acpi_status status
= AE_OK
;
824 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
825 union acpi_object
*obj
;
828 args
.ebx
= args
.ecx
= args
.edx
= 0;
830 status
= wmab_execute(&args
, &out
);
831 if (ACPI_FAILURE(status
))
834 obj
= (union acpi_object
*) out
.pointer
;
835 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
836 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
837 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
844 interface
->capability
|= ACER_CAP_MAILLED
;
851 static const struct acpi_device_id norfkill_ids
[] __initconst
= {
855 { "SNY5001", 0}, /* sony-laptop in charge */
860 static int __init
AMW0_set_cap_acpi_check_device(void)
862 const struct acpi_device_id
*id
;
864 for (id
= norfkill_ids
; id
->id
[0]; id
++)
865 if (acpi_dev_found(id
->id
))
871 static acpi_status __init
AMW0_set_capabilities(void)
873 struct wmab_args args
;
876 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
877 union acpi_object
*obj
;
880 * On laptops with this strange GUID (non Acer), normal probing doesn't
883 if (wmi_has_guid(AMW0_GUID2
)) {
884 if ((quirks
!= &quirk_unknown
) ||
885 !AMW0_set_cap_acpi_check_device())
886 interface
->capability
|= ACER_CAP_WIRELESS
;
890 args
.eax
= ACER_AMW0_WRITE
;
891 args
.ecx
= args
.edx
= 0;
893 args
.ebx
= 0xa2 << 8;
894 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
896 status
= wmab_execute(&args
, &out
);
897 if (ACPI_FAILURE(status
))
901 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
902 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
903 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
910 interface
->capability
|= ACER_CAP_WIRELESS
;
913 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
916 * It's ok to use existing buffer for next wmab_execute call.
917 * But we need to kfree(out.pointer) if next wmab_execute fail.
919 status
= wmab_execute(&args
, &out
);
920 if (ACPI_FAILURE(status
))
923 obj
= (union acpi_object
*) out
.pointer
;
924 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
925 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
926 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
933 interface
->capability
|= ACER_CAP_BLUETOOTH
;
936 * This appears to be safe to enable, since all Wistron based laptops
937 * appear to use the same EC register for brightness, even if they
938 * differ for wireless, etc
940 if (quirks
->brightness
>= 0)
941 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
949 static struct wmi_interface AMW0_interface
= {
953 static struct wmi_interface AMW0_V2_interface
= {
954 .type
= ACER_AMW0_V2
,
958 * New interface (The WMID interface)
961 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
963 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
964 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
965 union acpi_object
*obj
;
969 status
= wmi_evaluate_method(WMID_GUID1
, 0, method_id
, &input
, &result
);
971 if (ACPI_FAILURE(status
))
974 obj
= (union acpi_object
*) result
.pointer
;
976 if (obj
->type
== ACPI_TYPE_BUFFER
&&
977 (obj
->buffer
.length
== sizeof(u32
) ||
978 obj
->buffer
.length
== sizeof(u64
))) {
979 tmp
= *((u32
*) obj
->buffer
.pointer
);
980 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
981 tmp
= (u32
) obj
->integer
.value
;
988 kfree(result
.pointer
);
993 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
)
997 u32 result
, method_id
= 0;
1000 case ACER_CAP_WIRELESS
:
1001 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
1003 case ACER_CAP_BLUETOOTH
:
1004 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
1006 case ACER_CAP_BRIGHTNESS
:
1007 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
1009 case ACER_CAP_THREEG
:
1010 method_id
= ACER_WMID_GET_THREEG_METHODID
;
1012 case ACER_CAP_MAILLED
:
1013 if (quirks
->mailled
== 1) {
1014 ec_read(0x9f, &tmp
);
1021 status
= WMI_execute_u32(method_id
, 0, &result
);
1023 if (ACPI_SUCCESS(status
))
1024 *value
= (u8
)result
;
1029 static acpi_status
WMID_set_u32(u32 value
, u32 cap
)
1035 case ACER_CAP_BRIGHTNESS
:
1036 if (value
> max_brightness
)
1037 return AE_BAD_PARAMETER
;
1038 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
1040 case ACER_CAP_WIRELESS
:
1042 return AE_BAD_PARAMETER
;
1043 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
1045 case ACER_CAP_BLUETOOTH
:
1047 return AE_BAD_PARAMETER
;
1048 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
1050 case ACER_CAP_THREEG
:
1052 return AE_BAD_PARAMETER
;
1053 method_id
= ACER_WMID_SET_THREEG_METHODID
;
1055 case ACER_CAP_MAILLED
:
1057 return AE_BAD_PARAMETER
;
1058 if (quirks
->mailled
== 1) {
1059 param
= value
? 0x92 : 0x93;
1061 i8042_command(¶m
, 0x1059);
1062 i8042_unlock_chip();
1069 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
1072 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1074 struct wmid3_gds_return_value return_value
;
1076 union acpi_object
*obj
;
1077 struct wmid3_gds_get_input_param params
= {
1078 .function_num
= 0x1,
1079 .hotkey_number
= commun_fn_key_number
,
1082 struct acpi_buffer input
= {
1083 sizeof(struct wmid3_gds_get_input_param
),
1086 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1088 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1089 if (ACPI_FAILURE(status
))
1092 obj
= output
.pointer
;
1096 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1100 if (obj
->buffer
.length
!= 8) {
1101 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1106 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1109 if (return_value
.error_code
|| return_value
.ec_return_value
)
1110 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1112 return_value
.error_code
,
1113 return_value
.ec_return_value
);
1115 *value
= !!(return_value
.devices
& device
);
1120 static acpi_status
wmid_v2_get_u32(u32
*value
, u32 cap
)
1125 case ACER_CAP_WIRELESS
:
1126 device
= ACER_WMID3_GDS_WIRELESS
;
1128 case ACER_CAP_BLUETOOTH
:
1129 device
= ACER_WMID3_GDS_BLUETOOTH
;
1131 case ACER_CAP_THREEG
:
1132 device
= ACER_WMID3_GDS_THREEG
;
1137 return wmid3_get_device_status(value
, device
);
1140 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1142 struct wmid3_gds_return_value return_value
;
1144 union acpi_object
*obj
;
1146 struct wmid3_gds_get_input_param get_params
= {
1147 .function_num
= 0x1,
1148 .hotkey_number
= commun_fn_key_number
,
1149 .devices
= commun_func_bitmap
,
1151 struct acpi_buffer get_input
= {
1152 sizeof(struct wmid3_gds_get_input_param
),
1155 struct wmid3_gds_set_input_param set_params
= {
1156 .function_num
= 0x2,
1157 .hotkey_number
= commun_fn_key_number
,
1158 .devices
= commun_func_bitmap
,
1160 struct acpi_buffer set_input
= {
1161 sizeof(struct wmid3_gds_set_input_param
),
1164 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1165 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1167 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &get_input
, &output
);
1168 if (ACPI_FAILURE(status
))
1171 obj
= output
.pointer
;
1175 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1179 if (obj
->buffer
.length
!= 8) {
1180 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1185 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1188 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1189 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1190 return_value
.error_code
,
1191 return_value
.ec_return_value
);
1195 devices
= return_value
.devices
;
1196 set_params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1198 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &set_input
, &output2
);
1199 if (ACPI_FAILURE(status
))
1202 obj
= output2
.pointer
;
1206 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1210 if (obj
->buffer
.length
!= 4) {
1211 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1216 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1219 if (return_value
.error_code
|| return_value
.ec_return_value
)
1220 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1221 return_value
.error_code
,
1222 return_value
.ec_return_value
);
1227 static acpi_status
wmid_v2_set_u32(u32 value
, u32 cap
)
1232 case ACER_CAP_WIRELESS
:
1233 device
= ACER_WMID3_GDS_WIRELESS
;
1235 case ACER_CAP_BLUETOOTH
:
1236 device
= ACER_WMID3_GDS_BLUETOOTH
;
1238 case ACER_CAP_THREEG
:
1239 device
= ACER_WMID3_GDS_THREEG
;
1244 return wmid3_set_device_status(value
, device
);
1247 static void __init
type_aa_dmi_decode(const struct dmi_header
*header
, void *d
)
1249 struct hotkey_function_type_aa
*type_aa
;
1251 /* We are looking for OEM-specific Type AAh */
1252 if (header
->type
!= 0xAA)
1256 type_aa
= (struct hotkey_function_type_aa
*) header
;
1258 pr_info("Function bitmap for Communication Button: 0x%x\n",
1259 type_aa
->commun_func_bitmap
);
1260 commun_func_bitmap
= type_aa
->commun_func_bitmap
;
1262 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
1263 interface
->capability
|= ACER_CAP_WIRELESS
;
1264 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
1265 interface
->capability
|= ACER_CAP_THREEG
;
1266 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
1267 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1268 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_RFBTN
) {
1269 interface
->capability
|= ACER_CAP_RFBTN
;
1270 commun_func_bitmap
&= ~ACER_WMID3_GDS_RFBTN
;
1273 commun_fn_key_number
= type_aa
->commun_fn_key_number
;
1276 static acpi_status __init
WMID_set_capabilities(void)
1278 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1279 union acpi_object
*obj
;
1283 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
1284 if (ACPI_FAILURE(status
))
1287 obj
= (union acpi_object
*) out
.pointer
;
1289 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1290 (obj
->buffer
.length
== sizeof(u32
) ||
1291 obj
->buffer
.length
== sizeof(u64
))) {
1292 devices
= *((u32
*) obj
->buffer
.pointer
);
1293 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1294 devices
= (u32
) obj
->integer
.value
;
1304 pr_info("Function bitmap for Communication Device: 0x%x\n", devices
);
1306 interface
->capability
|= ACER_CAP_WIRELESS
;
1308 interface
->capability
|= ACER_CAP_THREEG
;
1310 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1312 if (!(devices
& 0x20))
1313 max_brightness
= 0x9;
1319 static struct wmi_interface wmid_interface
= {
1323 static struct wmi_interface wmid_v2_interface
= {
1324 .type
= ACER_WMID_v2
,
1328 * Generic Device (interface-independent)
1331 static acpi_status
get_u32(u32
*value
, u32 cap
)
1333 acpi_status status
= AE_ERROR
;
1335 switch (interface
->type
) {
1337 status
= AMW0_get_u32(value
, cap
);
1340 if (cap
== ACER_CAP_MAILLED
) {
1341 status
= AMW0_get_u32(value
, cap
);
1345 status
= WMID_get_u32(value
, cap
);
1348 if (cap
& (ACER_CAP_WIRELESS
|
1349 ACER_CAP_BLUETOOTH
|
1351 status
= wmid_v2_get_u32(value
, cap
);
1352 else if (wmi_has_guid(WMID_GUID2
))
1353 status
= WMID_get_u32(value
, cap
);
1360 static acpi_status
set_u32(u32 value
, u32 cap
)
1364 if (interface
->capability
& cap
) {
1365 switch (interface
->type
) {
1367 return AMW0_set_u32(value
, cap
);
1369 if (cap
== ACER_CAP_MAILLED
)
1370 return AMW0_set_u32(value
, cap
);
1373 * On some models, some WMID methods don't toggle
1374 * properly. For those cases, we want to run the AMW0
1375 * method afterwards to be certain we've really toggled
1378 if (cap
== ACER_CAP_WIRELESS
||
1379 cap
== ACER_CAP_BLUETOOTH
) {
1380 status
= WMID_set_u32(value
, cap
);
1381 if (ACPI_FAILURE(status
))
1384 return AMW0_set_u32(value
, cap
);
1387 return WMID_set_u32(value
, cap
);
1389 if (cap
& (ACER_CAP_WIRELESS
|
1390 ACER_CAP_BLUETOOTH
|
1392 return wmid_v2_set_u32(value
, cap
);
1393 else if (wmi_has_guid(WMID_GUID2
))
1394 return WMID_set_u32(value
, cap
);
1396 return AE_BAD_PARAMETER
;
1399 return AE_BAD_PARAMETER
;
1402 static void __init
acer_commandline_init(void)
1405 * These will all fail silently if the value given is invalid, or the
1406 * capability isn't available on the given interface
1409 set_u32(mailled
, ACER_CAP_MAILLED
);
1410 if (!has_type_aa
&& threeg
>= 0)
1411 set_u32(threeg
, ACER_CAP_THREEG
);
1412 if (brightness
>= 0)
1413 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1417 * LED device (Mail LED only, no other LEDs known yet)
1419 static void mail_led_set(struct led_classdev
*led_cdev
,
1420 enum led_brightness value
)
1422 set_u32(value
, ACER_CAP_MAILLED
);
1425 static struct led_classdev mail_led
= {
1426 .name
= "acer-wmi::mail",
1427 .brightness_set
= mail_led_set
,
1430 static int acer_led_init(struct device
*dev
)
1432 return led_classdev_register(dev
, &mail_led
);
1435 static void acer_led_exit(void)
1437 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1438 led_classdev_unregister(&mail_led
);
1444 static struct backlight_device
*acer_backlight_device
;
1446 static int read_brightness(struct backlight_device
*bd
)
1449 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1453 static int update_bl_status(struct backlight_device
*bd
)
1455 int intensity
= bd
->props
.brightness
;
1457 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1459 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1462 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1467 static const struct backlight_ops acer_bl_ops
= {
1468 .get_brightness
= read_brightness
,
1469 .update_status
= update_bl_status
,
1472 static int acer_backlight_init(struct device
*dev
)
1474 struct backlight_properties props
;
1475 struct backlight_device
*bd
;
1477 memset(&props
, 0, sizeof(struct backlight_properties
));
1478 props
.type
= BACKLIGHT_PLATFORM
;
1479 props
.max_brightness
= max_brightness
;
1480 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1483 pr_err("Could not register Acer backlight device\n");
1484 acer_backlight_device
= NULL
;
1488 acer_backlight_device
= bd
;
1490 bd
->props
.power
= FB_BLANK_UNBLANK
;
1491 bd
->props
.brightness
= read_brightness(bd
);
1492 backlight_update_status(bd
);
1496 static void acer_backlight_exit(void)
1498 backlight_device_unregister(acer_backlight_device
);
1502 * Accelerometer device
1504 static acpi_handle gsensor_handle
;
1506 static int acer_gsensor_init(void)
1509 struct acpi_buffer output
;
1510 union acpi_object out_obj
;
1512 output
.length
= sizeof(out_obj
);
1513 output
.pointer
= &out_obj
;
1514 status
= acpi_evaluate_object(gsensor_handle
, "_INI", NULL
, &output
);
1515 if (ACPI_FAILURE(status
))
1521 static int acer_gsensor_open(struct input_dev
*input
)
1523 return acer_gsensor_init();
1526 static int acer_gsensor_event(void)
1529 struct acpi_buffer output
;
1530 union acpi_object out_obj
[5];
1532 if (!has_cap(ACER_CAP_ACCEL
))
1535 output
.length
= sizeof(out_obj
);
1536 output
.pointer
= out_obj
;
1538 status
= acpi_evaluate_object(gsensor_handle
, "RDVL", NULL
, &output
);
1539 if (ACPI_FAILURE(status
))
1542 if (out_obj
->package
.count
!= 4)
1545 input_report_abs(acer_wmi_accel_dev
, ABS_X
,
1546 (s16
)out_obj
->package
.elements
[0].integer
.value
);
1547 input_report_abs(acer_wmi_accel_dev
, ABS_Y
,
1548 (s16
)out_obj
->package
.elements
[1].integer
.value
);
1549 input_report_abs(acer_wmi_accel_dev
, ABS_Z
,
1550 (s16
)out_obj
->package
.elements
[2].integer
.value
);
1551 input_sync(acer_wmi_accel_dev
);
1558 static void acer_rfkill_update(struct work_struct
*ignored
);
1559 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1560 static void acer_rfkill_update(struct work_struct
*ignored
)
1565 if (has_cap(ACER_CAP_WIRELESS
)) {
1566 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1567 if (ACPI_SUCCESS(status
)) {
1568 if (quirks
->wireless
== 3)
1569 rfkill_set_hw_state(wireless_rfkill
, !state
);
1571 rfkill_set_sw_state(wireless_rfkill
, !state
);
1575 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1576 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1577 if (ACPI_SUCCESS(status
))
1578 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1581 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1582 status
= get_u32(&state
, ACER_WMID3_GDS_THREEG
);
1583 if (ACPI_SUCCESS(status
))
1584 rfkill_set_sw_state(threeg_rfkill
, !state
);
1587 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1590 static int acer_rfkill_set(void *data
, bool blocked
)
1593 u32 cap
= (unsigned long)data
;
1595 if (rfkill_inited
) {
1596 status
= set_u32(!blocked
, cap
);
1597 if (ACPI_FAILURE(status
))
1604 static const struct rfkill_ops acer_rfkill_ops
= {
1605 .set_block
= acer_rfkill_set
,
1608 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1609 enum rfkill_type type
,
1610 char *name
, u32 cap
)
1613 struct rfkill
*rfkill_dev
;
1617 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1619 (void *)(unsigned long)cap
);
1621 return ERR_PTR(-ENOMEM
);
1623 status
= get_u32(&state
, cap
);
1625 err
= rfkill_register(rfkill_dev
);
1627 rfkill_destroy(rfkill_dev
);
1628 return ERR_PTR(err
);
1631 if (ACPI_SUCCESS(status
))
1632 rfkill_set_sw_state(rfkill_dev
, !state
);
1637 static int acer_rfkill_init(struct device
*dev
)
1641 if (has_cap(ACER_CAP_WIRELESS
)) {
1642 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1643 "acer-wireless", ACER_CAP_WIRELESS
);
1644 if (IS_ERR(wireless_rfkill
)) {
1645 err
= PTR_ERR(wireless_rfkill
);
1646 goto error_wireless
;
1650 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1651 bluetooth_rfkill
= acer_rfkill_register(dev
,
1652 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1653 ACER_CAP_BLUETOOTH
);
1654 if (IS_ERR(bluetooth_rfkill
)) {
1655 err
= PTR_ERR(bluetooth_rfkill
);
1656 goto error_bluetooth
;
1660 if (has_cap(ACER_CAP_THREEG
)) {
1661 threeg_rfkill
= acer_rfkill_register(dev
,
1662 RFKILL_TYPE_WWAN
, "acer-threeg",
1664 if (IS_ERR(threeg_rfkill
)) {
1665 err
= PTR_ERR(threeg_rfkill
);
1670 rfkill_inited
= true;
1672 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1673 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1674 schedule_delayed_work(&acer_rfkill_work
,
1675 round_jiffies_relative(HZ
));
1680 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1681 rfkill_unregister(bluetooth_rfkill
);
1682 rfkill_destroy(bluetooth_rfkill
);
1685 if (has_cap(ACER_CAP_WIRELESS
)) {
1686 rfkill_unregister(wireless_rfkill
);
1687 rfkill_destroy(wireless_rfkill
);
1693 static void acer_rfkill_exit(void)
1695 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1696 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1697 cancel_delayed_work_sync(&acer_rfkill_work
);
1699 if (has_cap(ACER_CAP_WIRELESS
)) {
1700 rfkill_unregister(wireless_rfkill
);
1701 rfkill_destroy(wireless_rfkill
);
1704 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1705 rfkill_unregister(bluetooth_rfkill
);
1706 rfkill_destroy(bluetooth_rfkill
);
1709 if (has_cap(ACER_CAP_THREEG
)) {
1710 rfkill_unregister(threeg_rfkill
);
1711 rfkill_destroy(threeg_rfkill
);
1716 static void acer_wmi_notify(u32 value
, void *context
)
1718 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1719 union acpi_object
*obj
;
1720 struct event_return_value return_value
;
1723 const struct key_entry
*key
;
1726 status
= wmi_get_event_data(value
, &response
);
1727 if (status
!= AE_OK
) {
1728 pr_warn("bad event status 0x%x\n", status
);
1732 obj
= (union acpi_object
*)response
.pointer
;
1736 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1737 pr_warn("Unknown response received %d\n", obj
->type
);
1741 if (obj
->buffer
.length
!= 8) {
1742 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1747 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1750 switch (return_value
.function
) {
1751 case WMID_HOTKEY_EVENT
:
1752 device_state
= return_value
.device_state
;
1753 pr_debug("device state: 0x%x\n", device_state
);
1755 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1756 return_value
.key_num
);
1758 pr_warn("Unknown key number - 0x%x\n",
1759 return_value
.key_num
);
1761 scancode
= return_value
.key_num
;
1762 switch (key
->keycode
) {
1765 if (has_cap(ACER_CAP_WIRELESS
))
1766 rfkill_set_sw_state(wireless_rfkill
,
1767 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1768 if (has_cap(ACER_CAP_THREEG
))
1769 rfkill_set_sw_state(threeg_rfkill
,
1770 !(device_state
& ACER_WMID3_GDS_THREEG
));
1771 if (has_cap(ACER_CAP_BLUETOOTH
))
1772 rfkill_set_sw_state(bluetooth_rfkill
,
1773 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1775 case KEY_TOUCHPAD_TOGGLE
:
1776 scancode
= (device_state
& ACER_WMID3_GDS_TOUCHPAD
) ?
1777 KEY_TOUCHPAD_ON
: KEY_TOUCHPAD_OFF
;
1779 sparse_keymap_report_event(acer_wmi_input_dev
, scancode
, 1, true);
1782 case WMID_ACCEL_EVENT
:
1783 acer_gsensor_event();
1786 pr_warn("Unknown function number - %d - %d\n",
1787 return_value
.function
, return_value
.key_num
);
1792 static acpi_status __init
1793 wmid3_set_function_mode(struct func_input_params
*params
,
1794 struct func_return_value
*return_value
)
1797 union acpi_object
*obj
;
1799 struct acpi_buffer input
= { sizeof(struct func_input_params
), params
};
1800 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1802 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1803 if (ACPI_FAILURE(status
))
1806 obj
= output
.pointer
;
1810 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1814 if (obj
->buffer
.length
!= 4) {
1815 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1820 *return_value
= *((struct func_return_value
*)obj
->buffer
.pointer
);
1826 static int __init
acer_wmi_enable_ec_raw(void)
1828 struct func_return_value return_value
;
1830 struct func_input_params params
= {
1831 .function_num
= 0x1,
1832 .commun_devices
= 0xFFFF,
1834 .app_status
= 0x00, /* Launch Manager Deactive */
1838 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1840 if (return_value
.error_code
|| return_value
.ec_return_value
)
1841 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1842 return_value
.error_code
,
1843 return_value
.ec_return_value
);
1845 pr_info("Enabled EC raw mode\n");
1850 static int __init
acer_wmi_enable_lm(void)
1852 struct func_return_value return_value
;
1854 struct func_input_params params
= {
1855 .function_num
= 0x1,
1856 .commun_devices
= 0xFFFF,
1858 .app_status
= 0x01, /* Launch Manager Active */
1862 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1864 if (return_value
.error_code
|| return_value
.ec_return_value
)
1865 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1866 return_value
.error_code
,
1867 return_value
.ec_return_value
);
1872 static int __init
acer_wmi_enable_rf_button(void)
1874 struct func_return_value return_value
;
1876 struct func_input_params params
= {
1877 .function_num
= 0x1,
1878 .commun_devices
= 0xFFFF,
1880 .app_status
= 0x10, /* RF Button Active */
1884 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1886 if (return_value
.error_code
|| return_value
.ec_return_value
)
1887 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1888 return_value
.error_code
,
1889 return_value
.ec_return_value
);
1894 #define ACER_WMID_ACCEL_HID "BST0001"
1896 static acpi_status __init
acer_wmi_get_handle_cb(acpi_handle ah
, u32 level
,
1897 void *ctx
, void **retval
)
1899 struct acpi_device
*dev
;
1901 if (!strcmp(ctx
, "SENR")) {
1902 if (acpi_bus_get_device(ah
, &dev
))
1904 if (strcmp(ACER_WMID_ACCEL_HID
, acpi_device_hid(dev
)))
1909 *(acpi_handle
*)retval
= ah
;
1911 return AE_CTRL_TERMINATE
;
1914 static int __init
acer_wmi_get_handle(const char *name
, const char *prop
,
1920 BUG_ON(!name
|| !ah
);
1923 status
= acpi_get_devices(prop
, acer_wmi_get_handle_cb
,
1924 (void *)name
, &handle
);
1925 if (ACPI_SUCCESS(status
) && handle
) {
1933 static int __init
acer_wmi_accel_setup(void)
1937 err
= acer_wmi_get_handle("SENR", ACER_WMID_ACCEL_HID
, &gsensor_handle
);
1941 interface
->capability
|= ACER_CAP_ACCEL
;
1943 acer_wmi_accel_dev
= input_allocate_device();
1944 if (!acer_wmi_accel_dev
)
1947 acer_wmi_accel_dev
->open
= acer_gsensor_open
;
1949 acer_wmi_accel_dev
->name
= "Acer BMA150 accelerometer";
1950 acer_wmi_accel_dev
->phys
= "wmi/input1";
1951 acer_wmi_accel_dev
->id
.bustype
= BUS_HOST
;
1952 acer_wmi_accel_dev
->evbit
[0] = BIT_MASK(EV_ABS
);
1953 input_set_abs_params(acer_wmi_accel_dev
, ABS_X
, -16384, 16384, 0, 0);
1954 input_set_abs_params(acer_wmi_accel_dev
, ABS_Y
, -16384, 16384, 0, 0);
1955 input_set_abs_params(acer_wmi_accel_dev
, ABS_Z
, -16384, 16384, 0, 0);
1957 err
= input_register_device(acer_wmi_accel_dev
);
1964 input_free_device(acer_wmi_accel_dev
);
1968 static void acer_wmi_accel_destroy(void)
1970 input_unregister_device(acer_wmi_accel_dev
);
1973 static int __init
acer_wmi_input_setup(void)
1978 acer_wmi_input_dev
= input_allocate_device();
1979 if (!acer_wmi_input_dev
)
1982 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1983 acer_wmi_input_dev
->phys
= "wmi/input0";
1984 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1986 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1990 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1991 acer_wmi_notify
, NULL
);
1992 if (ACPI_FAILURE(status
)) {
1997 err
= input_register_device(acer_wmi_input_dev
);
1999 goto err_uninstall_notifier
;
2003 err_uninstall_notifier
:
2004 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
2006 input_free_device(acer_wmi_input_dev
);
2010 static void acer_wmi_input_destroy(void)
2012 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
2013 input_unregister_device(acer_wmi_input_dev
);
2019 static u32
get_wmid_devices(void)
2021 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
2022 union acpi_object
*obj
;
2026 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
2027 if (ACPI_FAILURE(status
))
2030 obj
= (union acpi_object
*) out
.pointer
;
2032 if (obj
->type
== ACPI_TYPE_BUFFER
&&
2033 (obj
->buffer
.length
== sizeof(u32
) ||
2034 obj
->buffer
.length
== sizeof(u64
))) {
2035 devices
= *((u32
*) obj
->buffer
.pointer
);
2036 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
2037 devices
= (u32
) obj
->integer
.value
;
2048 static int acer_platform_probe(struct platform_device
*device
)
2052 if (has_cap(ACER_CAP_MAILLED
)) {
2053 err
= acer_led_init(&device
->dev
);
2058 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2059 err
= acer_backlight_init(&device
->dev
);
2061 goto error_brightness
;
2064 err
= acer_rfkill_init(&device
->dev
);
2071 if (has_cap(ACER_CAP_BRIGHTNESS
))
2072 acer_backlight_exit();
2074 if (has_cap(ACER_CAP_MAILLED
))
2080 static int acer_platform_remove(struct platform_device
*device
)
2082 if (has_cap(ACER_CAP_MAILLED
))
2084 if (has_cap(ACER_CAP_BRIGHTNESS
))
2085 acer_backlight_exit();
2091 #ifdef CONFIG_PM_SLEEP
2092 static int acer_suspend(struct device
*dev
)
2095 struct acer_data
*data
= &interface
->data
;
2100 if (has_cap(ACER_CAP_MAILLED
)) {
2101 get_u32(&value
, ACER_CAP_MAILLED
);
2102 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2103 data
->mailled
= value
;
2106 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2107 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
2108 data
->brightness
= value
;
2114 static int acer_resume(struct device
*dev
)
2116 struct acer_data
*data
= &interface
->data
;
2121 if (has_cap(ACER_CAP_MAILLED
))
2122 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
2124 if (has_cap(ACER_CAP_BRIGHTNESS
))
2125 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
2127 if (has_cap(ACER_CAP_ACCEL
))
2128 acer_gsensor_init();
2133 #define acer_suspend NULL
2134 #define acer_resume NULL
2137 static SIMPLE_DEV_PM_OPS(acer_pm
, acer_suspend
, acer_resume
);
2139 static void acer_platform_shutdown(struct platform_device
*device
)
2141 struct acer_data
*data
= &interface
->data
;
2146 if (has_cap(ACER_CAP_MAILLED
))
2147 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2150 static struct platform_driver acer_platform_driver
= {
2155 .probe
= acer_platform_probe
,
2156 .remove
= acer_platform_remove
,
2157 .shutdown
= acer_platform_shutdown
,
2160 static struct platform_device
*acer_platform_device
;
2162 static void remove_debugfs(void)
2164 debugfs_remove(interface
->debug
.devices
);
2165 debugfs_remove(interface
->debug
.root
);
2168 static int __init
create_debugfs(void)
2170 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
2171 if (!interface
->debug
.root
) {
2172 pr_err("Failed to create debugfs directory");
2176 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
2177 interface
->debug
.root
,
2178 &interface
->debug
.wmid_devices
);
2179 if (!interface
->debug
.devices
)
2189 static int __init
acer_wmi_init(void)
2193 pr_info("Acer Laptop ACPI-WMI Extras\n");
2195 if (dmi_check_system(acer_blacklist
)) {
2196 pr_info("Blacklisted hardware detected - not loading\n");
2203 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2204 * machines like Lenovo, Fujitsu and Medion. In the past days,
2205 * acer-wmi driver handled those non-Acer machines by quirks list.
2206 * But actually acer-wmi driver was loaded on any machines that have
2207 * AMW0_GUID1. This behavior is strange because those machines should
2208 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2209 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2210 * should be in Acer/Gateway/Packard Bell white list, or it's already
2211 * in the past quirk list.
2213 if (wmi_has_guid(AMW0_GUID1
) &&
2214 !dmi_check_system(amw0_whitelist
) &&
2215 quirks
== &quirk_unknown
) {
2216 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
2221 * Detect which ACPI-WMI interface we're using.
2223 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2224 interface
= &AMW0_V2_interface
;
2226 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2227 interface
= &wmid_interface
;
2229 if (wmi_has_guid(WMID_GUID3
))
2230 interface
= &wmid_v2_interface
;
2233 dmi_walk(type_aa_dmi_decode
, NULL
);
2235 if (wmi_has_guid(WMID_GUID2
) && interface
) {
2236 if (!has_type_aa
&& ACPI_FAILURE(WMID_set_capabilities())) {
2237 pr_err("Unable to detect available WMID devices\n");
2240 /* WMID always provides brightness methods */
2241 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
2242 } else if (!wmi_has_guid(WMID_GUID2
) && interface
&& !has_type_aa
) {
2243 pr_err("No WMID device detection method found\n");
2247 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
2248 interface
= &AMW0_interface
;
2250 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2251 pr_err("Unable to detect available AMW0 devices\n");
2256 if (wmi_has_guid(AMW0_GUID1
))
2257 AMW0_find_mailled();
2260 pr_err("No or unsupported WMI interface, unable to load\n");
2266 if (dmi_check_system(video_vendor_dmi_table
))
2267 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2269 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2270 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
2272 if (wmi_has_guid(WMID_GUID3
)) {
2273 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2274 pr_warn("Cannot enable RF Button Driver\n");
2277 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2278 pr_err("Cannot enable EC raw mode\n");
2281 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2282 pr_err("Cannot enable Launch Manager mode\n");
2285 } else if (ec_raw_mode
) {
2286 pr_info("No WMID EC raw mode enable method\n");
2289 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
2290 err
= acer_wmi_input_setup();
2293 err
= acer_wmi_accel_setup();
2294 if (err
&& err
!= -ENODEV
)
2295 pr_warn("Cannot enable accelerometer\n");
2298 err
= platform_driver_register(&acer_platform_driver
);
2300 pr_err("Unable to register platform driver\n");
2301 goto error_platform_register
;
2304 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
2305 if (!acer_platform_device
) {
2307 goto error_device_alloc
;
2310 err
= platform_device_add(acer_platform_device
);
2312 goto error_device_add
;
2314 if (wmi_has_guid(WMID_GUID2
)) {
2315 interface
->debug
.wmid_devices
= get_wmid_devices();
2316 err
= create_debugfs();
2318 goto error_create_debugfs
;
2321 /* Override any initial settings with values from the commandline */
2322 acer_commandline_init();
2326 error_create_debugfs
:
2327 platform_device_del(acer_platform_device
);
2329 platform_device_put(acer_platform_device
);
2331 platform_driver_unregister(&acer_platform_driver
);
2332 error_platform_register
:
2333 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2334 acer_wmi_input_destroy();
2335 if (has_cap(ACER_CAP_ACCEL
))
2336 acer_wmi_accel_destroy();
2341 static void __exit
acer_wmi_exit(void)
2343 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2344 acer_wmi_input_destroy();
2346 if (has_cap(ACER_CAP_ACCEL
))
2347 acer_wmi_accel_destroy();
2350 platform_device_unregister(acer_platform_device
);
2351 platform_driver_unregister(&acer_platform_driver
);
2353 pr_info("Acer Laptop WMI Extras unloaded\n");
2357 module_init(acer_wmi_init
);
2358 module_exit(acer_wmi_exit
);