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
} },
135 static struct input_dev
*acer_wmi_input_dev
;
136 static struct input_dev
*acer_wmi_accel_dev
;
138 struct event_return_value
{
143 } __attribute__((packed
));
146 * GUID3 Get Device Status device flags
148 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
149 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
150 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
151 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
152 #define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
154 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
156 /* Hotkey Customized Setting and Acer Application Status.
157 * Set Device Default Value and Report Acer Application Status.
158 * When Acer Application starts, it will run this method to inform
159 * BIOS/EC that Acer Application is on.
161 * Bit[0]: Launch Manager Status
163 * Bit[2]: Device Control Status
164 * Bit[3]: Acer Power Button Utility Status
165 * Bit[4]: RF Button Status
166 * Bit[5]: ODD PM Status
167 * Bit[6]: Device Default Value Control
168 * Bit[7]: Hall Sensor Application Status
170 struct func_input_params
{
171 u8 function_num
; /* Function Number */
172 u16 commun_devices
; /* Communication type devices default status */
173 u16 devices
; /* Other type devices default status */
174 u8 app_status
; /* Acer Device Status. LM, ePM, RF Button... */
175 u8 app_mask
; /* Bit mask to app_status */
177 } __attribute__((packed
));
179 struct func_return_value
{
180 u8 error_code
; /* Error Code */
181 u8 ec_return_value
; /* EC Return Value */
183 } __attribute__((packed
));
185 struct wmid3_gds_set_input_param
{ /* Set Device Status input parameter */
186 u8 function_num
; /* Function Number */
187 u8 hotkey_number
; /* Hotkey Number */
188 u16 devices
; /* Set Device */
189 u8 volume_value
; /* Volume Value */
190 } __attribute__((packed
));
192 struct wmid3_gds_get_input_param
{ /* Get Device Status input parameter */
193 u8 function_num
; /* Function Number */
194 u8 hotkey_number
; /* Hotkey Number */
195 u16 devices
; /* Get Device */
196 } __attribute__((packed
));
198 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
199 u8 error_code
; /* Error Code */
200 u8 ec_return_value
; /* EC Return Value */
201 u16 devices
; /* Current Device Status */
203 } __attribute__((packed
));
205 struct hotkey_function_type_aa
{
209 u16 commun_func_bitmap
;
210 u16 application_func_bitmap
;
211 u16 media_func_bitmap
;
212 u16 display_func_bitmap
;
213 u16 others_func_bitmap
;
214 u8 commun_fn_key_number
;
215 } __attribute__((packed
));
218 * Interface capability flags
220 #define ACER_CAP_MAILLED (1<<0)
221 #define ACER_CAP_WIRELESS (1<<1)
222 #define ACER_CAP_BLUETOOTH (1<<2)
223 #define ACER_CAP_BRIGHTNESS (1<<3)
224 #define ACER_CAP_THREEG (1<<4)
225 #define ACER_CAP_ACCEL (1<<5)
226 #define ACER_CAP_RFBTN (1<<6)
227 #define ACER_CAP_ANY (0xFFFFFFFF)
230 * Interface type flags
232 enum interface_flags
{
239 #define ACER_DEFAULT_WIRELESS 0
240 #define ACER_DEFAULT_BLUETOOTH 0
241 #define ACER_DEFAULT_MAILLED 0
242 #define ACER_DEFAULT_THREEG 0
244 static int max_brightness
= 0xF;
246 static int mailled
= -1;
247 static int brightness
= -1;
248 static int threeg
= -1;
249 static int force_series
;
250 static bool ec_raw_mode
;
251 static bool has_type_aa
;
252 static u16 commun_func_bitmap
;
253 static u8 commun_fn_key_number
;
255 module_param(mailled
, int, 0444);
256 module_param(brightness
, int, 0444);
257 module_param(threeg
, int, 0444);
258 module_param(force_series
, int, 0444);
259 module_param(ec_raw_mode
, bool, 0444);
260 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
261 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
262 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
263 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
264 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
274 struct dentry
*devices
;
278 static struct rfkill
*wireless_rfkill
;
279 static struct rfkill
*bluetooth_rfkill
;
280 static struct rfkill
*threeg_rfkill
;
281 static bool rfkill_inited
;
283 /* Each low-level interface must define at least some of the following */
284 struct wmi_interface
{
285 /* The WMI device type */
288 /* The capabilities this interface provides */
291 /* Private data for the current interface */
292 struct acer_data data
;
294 /* debugfs entries associated with this interface */
295 struct acer_debug debug
;
298 /* The static interface pointer, points to the currently detected interface */
299 static struct wmi_interface
*interface
;
302 * Embedded Controller quirks
303 * Some laptops require us to directly access the EC to either enable or query
304 * features that are not available through WMI.
314 static struct quirk_entry
*quirks
;
316 static void __init
set_quirks(void)
322 interface
->capability
|= ACER_CAP_MAILLED
;
324 if (quirks
->brightness
)
325 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
328 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
330 quirks
= dmi
->driver_data
;
334 static struct quirk_entry quirk_unknown
= {
337 static struct quirk_entry quirk_acer_aspire_1520
= {
341 static struct quirk_entry quirk_acer_travelmate_2490
= {
345 /* This AMW0 laptop has no bluetooth */
346 static struct quirk_entry quirk_medion_md_98300
= {
350 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
354 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
358 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
359 static const struct dmi_system_id acer_blacklist
[] __initconst
= {
361 .ident
= "Acer Aspire One (SSD)",
363 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
364 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
368 .ident
= "Acer Aspire One (HDD)",
370 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
371 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
377 static const struct dmi_system_id amw0_whitelist
[] __initconst
= {
381 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
387 DMI_MATCH(DMI_SYS_VENDOR
, "Gateway"),
391 .ident
= "Packard Bell",
393 DMI_MATCH(DMI_SYS_VENDOR
, "Packard Bell"),
400 * This quirk table is only for Acer/Gateway/Packard Bell family
401 * that those machines are supported by acer-wmi driver.
403 static const struct dmi_system_id acer_quirks
[] __initconst
= {
405 .callback
= dmi_matched
,
406 .ident
= "Acer Aspire 1360",
408 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
409 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
411 .driver_data
= &quirk_acer_aspire_1520
,
414 .callback
= dmi_matched
,
415 .ident
= "Acer Aspire 1520",
417 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
418 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
420 .driver_data
= &quirk_acer_aspire_1520
,
423 .callback
= dmi_matched
,
424 .ident
= "Acer Aspire 3100",
426 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
427 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
429 .driver_data
= &quirk_acer_travelmate_2490
,
432 .callback
= dmi_matched
,
433 .ident
= "Acer Aspire 3610",
435 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
436 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
438 .driver_data
= &quirk_acer_travelmate_2490
,
441 .callback
= dmi_matched
,
442 .ident
= "Acer Aspire 5100",
444 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
445 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
447 .driver_data
= &quirk_acer_travelmate_2490
,
450 .callback
= dmi_matched
,
451 .ident
= "Acer Aspire 5610",
453 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
454 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
456 .driver_data
= &quirk_acer_travelmate_2490
,
459 .callback
= dmi_matched
,
460 .ident
= "Acer Aspire 5630",
462 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
463 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
465 .driver_data
= &quirk_acer_travelmate_2490
,
468 .callback
= dmi_matched
,
469 .ident
= "Acer Aspire 5650",
471 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
472 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
474 .driver_data
= &quirk_acer_travelmate_2490
,
477 .callback
= dmi_matched
,
478 .ident
= "Acer Aspire 5680",
480 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
481 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
483 .driver_data
= &quirk_acer_travelmate_2490
,
486 .callback
= dmi_matched
,
487 .ident
= "Acer Aspire 9110",
489 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
490 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
492 .driver_data
= &quirk_acer_travelmate_2490
,
495 .callback
= dmi_matched
,
496 .ident
= "Acer TravelMate 2490",
498 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
499 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
501 .driver_data
= &quirk_acer_travelmate_2490
,
504 .callback
= dmi_matched
,
505 .ident
= "Acer TravelMate 4200",
507 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
508 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
510 .driver_data
= &quirk_acer_travelmate_2490
,
516 * This quirk list is for those non-acer machines that have AMW0_GUID1
517 * but supported by acer-wmi in past days. Keeping this quirk list here
518 * is only for backward compatible. Please do not add new machine to
519 * here anymore. Those non-acer machines should be supported by
520 * appropriate wmi drivers.
522 static const struct dmi_system_id non_acer_quirks
[] __initconst
= {
524 .callback
= dmi_matched
,
525 .ident
= "Fujitsu Siemens Amilo Li 1718",
527 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
528 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
530 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
533 .callback
= dmi_matched
,
534 .ident
= "Medion MD 98300",
536 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
537 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
539 .driver_data
= &quirk_medion_md_98300
,
542 .callback
= dmi_matched
,
543 .ident
= "Lenovo Ideapad S205",
545 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
546 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
548 .driver_data
= &quirk_lenovo_ideapad_s205
,
551 .callback
= dmi_matched
,
552 .ident
= "Lenovo Ideapad S205 (Brazos)",
554 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
555 DMI_MATCH(DMI_PRODUCT_NAME
, "Brazos"),
557 .driver_data
= &quirk_lenovo_ideapad_s205
,
560 .callback
= dmi_matched
,
561 .ident
= "Lenovo 3000 N200",
563 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
564 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
566 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
569 .callback
= dmi_matched
,
570 .ident
= "Lenovo Ideapad S205-10382JG",
572 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
573 DMI_MATCH(DMI_PRODUCT_NAME
, "10382JG"),
575 .driver_data
= &quirk_lenovo_ideapad_s205
,
578 .callback
= dmi_matched
,
579 .ident
= "Lenovo Ideapad S205-1038DPG",
581 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
582 DMI_MATCH(DMI_PRODUCT_NAME
, "1038DPG"),
584 .driver_data
= &quirk_lenovo_ideapad_s205
,
590 video_set_backlight_video_vendor(const struct dmi_system_id
*d
)
592 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
593 pr_info("Brightness must be controlled by generic video driver\n");
597 static const struct dmi_system_id video_vendor_dmi_table
[] __initconst
= {
599 .callback
= video_set_backlight_video_vendor
,
600 .ident
= "Acer TravelMate 4750",
602 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
603 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4750"),
607 .callback
= video_set_backlight_video_vendor
,
608 .ident
= "Acer Extensa 5235",
610 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
611 DMI_MATCH(DMI_PRODUCT_NAME
, "Extensa 5235"),
615 .callback
= video_set_backlight_video_vendor
,
616 .ident
= "Acer TravelMate 5760",
618 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
619 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5760"),
623 .callback
= video_set_backlight_video_vendor
,
624 .ident
= "Acer Aspire 5750",
626 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
627 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5750"),
631 .callback
= video_set_backlight_video_vendor
,
632 .ident
= "Acer Aspire 5741",
634 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
635 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5741"),
640 * Note no video_set_backlight_video_vendor, we must use the
641 * acer interface, as there is no native backlight interface.
643 .ident
= "Acer KAV80",
645 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
646 DMI_MATCH(DMI_PRODUCT_NAME
, "KAV80"),
652 /* Find which quirks are needed for a particular vendor/ model pair */
653 static void __init
find_quirks(void)
656 dmi_check_system(acer_quirks
);
657 dmi_check_system(non_acer_quirks
);
658 } else if (force_series
== 2490) {
659 quirks
= &quirk_acer_travelmate_2490
;
663 quirks
= &quirk_unknown
;
669 * General interface convenience methods
672 static bool has_cap(u32 cap
)
674 if ((interface
->capability
& cap
) != 0)
681 * AMW0 (V1) interface
698 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
699 struct acpi_buffer
*result
)
701 struct acpi_buffer input
;
703 input
.length
= sizeof(struct wmab_args
);
704 input
.pointer
= (u8
*)regbuf
;
706 status
= wmi_evaluate_method(AMW0_GUID1
, 0, 1, &input
, result
);
711 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
)
717 case ACER_CAP_MAILLED
:
718 switch (quirks
->mailled
) {
720 err
= ec_read(0xA, &result
);
723 *value
= (result
>> 7) & 0x1;
727 case ACER_CAP_WIRELESS
:
728 switch (quirks
->wireless
) {
730 err
= ec_read(0x7B, &result
);
733 *value
= result
& 0x1;
736 err
= ec_read(0x71, &result
);
739 *value
= result
& 0x1;
742 err
= ec_read(0x78, &result
);
745 *value
= result
& 0x1;
748 err
= ec_read(0xA, &result
);
751 *value
= (result
>> 2) & 0x1;
755 case ACER_CAP_BLUETOOTH
:
756 switch (quirks
->bluetooth
) {
758 err
= ec_read(0xA, &result
);
761 *value
= (result
>> 4) & 0x1;
765 case ACER_CAP_BRIGHTNESS
:
766 switch (quirks
->brightness
) {
768 err
= ec_read(0x83, &result
);
781 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
)
783 struct wmab_args args
;
785 args
.eax
= ACER_AMW0_WRITE
;
786 args
.ebx
= value
? (1<<8) : 0;
787 args
.ecx
= args
.edx
= 0;
790 case ACER_CAP_MAILLED
:
792 return AE_BAD_PARAMETER
;
793 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
795 case ACER_CAP_WIRELESS
:
797 return AE_BAD_PARAMETER
;
798 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
800 case ACER_CAP_BLUETOOTH
:
802 return AE_BAD_PARAMETER
;
803 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
805 case ACER_CAP_BRIGHTNESS
:
806 if (value
> max_brightness
)
807 return AE_BAD_PARAMETER
;
808 switch (quirks
->brightness
) {
810 return ec_write(0x83, value
);
817 /* Actually do the set */
818 return wmab_execute(&args
, NULL
);
821 static acpi_status __init
AMW0_find_mailled(void)
823 struct wmab_args args
;
825 acpi_status status
= AE_OK
;
826 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
827 union acpi_object
*obj
;
830 args
.ebx
= args
.ecx
= args
.edx
= 0;
832 status
= wmab_execute(&args
, &out
);
833 if (ACPI_FAILURE(status
))
836 obj
= (union acpi_object
*) out
.pointer
;
837 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
838 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
839 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
846 interface
->capability
|= ACER_CAP_MAILLED
;
853 static const struct acpi_device_id norfkill_ids
[] __initconst
= {
857 { "SNY5001", 0}, /* sony-laptop in charge */
862 static int __init
AMW0_set_cap_acpi_check_device(void)
864 const struct acpi_device_id
*id
;
866 for (id
= norfkill_ids
; id
->id
[0]; id
++)
867 if (acpi_dev_found(id
->id
))
873 static acpi_status __init
AMW0_set_capabilities(void)
875 struct wmab_args args
;
878 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
879 union acpi_object
*obj
;
882 * On laptops with this strange GUID (non Acer), normal probing doesn't
885 if (wmi_has_guid(AMW0_GUID2
)) {
886 if ((quirks
!= &quirk_unknown
) ||
887 !AMW0_set_cap_acpi_check_device())
888 interface
->capability
|= ACER_CAP_WIRELESS
;
892 args
.eax
= ACER_AMW0_WRITE
;
893 args
.ecx
= args
.edx
= 0;
895 args
.ebx
= 0xa2 << 8;
896 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
898 status
= wmab_execute(&args
, &out
);
899 if (ACPI_FAILURE(status
))
903 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
904 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
905 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
912 interface
->capability
|= ACER_CAP_WIRELESS
;
915 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
918 * It's ok to use existing buffer for next wmab_execute call.
919 * But we need to kfree(out.pointer) if next wmab_execute fail.
921 status
= wmab_execute(&args
, &out
);
922 if (ACPI_FAILURE(status
))
925 obj
= (union acpi_object
*) out
.pointer
;
926 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
927 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
928 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
935 interface
->capability
|= ACER_CAP_BLUETOOTH
;
938 * This appears to be safe to enable, since all Wistron based laptops
939 * appear to use the same EC register for brightness, even if they
940 * differ for wireless, etc
942 if (quirks
->brightness
>= 0)
943 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
951 static struct wmi_interface AMW0_interface
= {
955 static struct wmi_interface AMW0_V2_interface
= {
956 .type
= ACER_AMW0_V2
,
960 * New interface (The WMID interface)
963 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
965 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
966 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
967 union acpi_object
*obj
;
971 status
= wmi_evaluate_method(WMID_GUID1
, 0, method_id
, &input
, &result
);
973 if (ACPI_FAILURE(status
))
976 obj
= (union acpi_object
*) result
.pointer
;
978 if (obj
->type
== ACPI_TYPE_BUFFER
&&
979 (obj
->buffer
.length
== sizeof(u32
) ||
980 obj
->buffer
.length
== sizeof(u64
))) {
981 tmp
= *((u32
*) obj
->buffer
.pointer
);
982 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
983 tmp
= (u32
) obj
->integer
.value
;
990 kfree(result
.pointer
);
995 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
)
999 u32 result
, method_id
= 0;
1002 case ACER_CAP_WIRELESS
:
1003 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
1005 case ACER_CAP_BLUETOOTH
:
1006 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
1008 case ACER_CAP_BRIGHTNESS
:
1009 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
1011 case ACER_CAP_THREEG
:
1012 method_id
= ACER_WMID_GET_THREEG_METHODID
;
1014 case ACER_CAP_MAILLED
:
1015 if (quirks
->mailled
== 1) {
1016 ec_read(0x9f, &tmp
);
1023 status
= WMI_execute_u32(method_id
, 0, &result
);
1025 if (ACPI_SUCCESS(status
))
1026 *value
= (u8
)result
;
1031 static acpi_status
WMID_set_u32(u32 value
, u32 cap
)
1037 case ACER_CAP_BRIGHTNESS
:
1038 if (value
> max_brightness
)
1039 return AE_BAD_PARAMETER
;
1040 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
1042 case ACER_CAP_WIRELESS
:
1044 return AE_BAD_PARAMETER
;
1045 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
1047 case ACER_CAP_BLUETOOTH
:
1049 return AE_BAD_PARAMETER
;
1050 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
1052 case ACER_CAP_THREEG
:
1054 return AE_BAD_PARAMETER
;
1055 method_id
= ACER_WMID_SET_THREEG_METHODID
;
1057 case ACER_CAP_MAILLED
:
1059 return AE_BAD_PARAMETER
;
1060 if (quirks
->mailled
== 1) {
1061 param
= value
? 0x92 : 0x93;
1063 i8042_command(¶m
, 0x1059);
1064 i8042_unlock_chip();
1071 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
1074 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1076 struct wmid3_gds_return_value return_value
;
1078 union acpi_object
*obj
;
1079 struct wmid3_gds_get_input_param params
= {
1080 .function_num
= 0x1,
1081 .hotkey_number
= commun_fn_key_number
,
1084 struct acpi_buffer input
= {
1085 sizeof(struct wmid3_gds_get_input_param
),
1088 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1090 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1091 if (ACPI_FAILURE(status
))
1094 obj
= output
.pointer
;
1098 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1102 if (obj
->buffer
.length
!= 8) {
1103 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1108 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1111 if (return_value
.error_code
|| return_value
.ec_return_value
)
1112 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1114 return_value
.error_code
,
1115 return_value
.ec_return_value
);
1117 *value
= !!(return_value
.devices
& device
);
1122 static acpi_status
wmid_v2_get_u32(u32
*value
, u32 cap
)
1127 case ACER_CAP_WIRELESS
:
1128 device
= ACER_WMID3_GDS_WIRELESS
;
1130 case ACER_CAP_BLUETOOTH
:
1131 device
= ACER_WMID3_GDS_BLUETOOTH
;
1133 case ACER_CAP_THREEG
:
1134 device
= ACER_WMID3_GDS_THREEG
;
1139 return wmid3_get_device_status(value
, device
);
1142 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1144 struct wmid3_gds_return_value return_value
;
1146 union acpi_object
*obj
;
1148 struct wmid3_gds_get_input_param get_params
= {
1149 .function_num
= 0x1,
1150 .hotkey_number
= commun_fn_key_number
,
1151 .devices
= commun_func_bitmap
,
1153 struct acpi_buffer get_input
= {
1154 sizeof(struct wmid3_gds_get_input_param
),
1157 struct wmid3_gds_set_input_param set_params
= {
1158 .function_num
= 0x2,
1159 .hotkey_number
= commun_fn_key_number
,
1160 .devices
= commun_func_bitmap
,
1162 struct acpi_buffer set_input
= {
1163 sizeof(struct wmid3_gds_set_input_param
),
1166 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1167 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1169 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &get_input
, &output
);
1170 if (ACPI_FAILURE(status
))
1173 obj
= output
.pointer
;
1177 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1181 if (obj
->buffer
.length
!= 8) {
1182 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1187 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1190 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1191 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1192 return_value
.error_code
,
1193 return_value
.ec_return_value
);
1197 devices
= return_value
.devices
;
1198 set_params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1200 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &set_input
, &output2
);
1201 if (ACPI_FAILURE(status
))
1204 obj
= output2
.pointer
;
1208 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1212 if (obj
->buffer
.length
!= 4) {
1213 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1218 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1221 if (return_value
.error_code
|| return_value
.ec_return_value
)
1222 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1223 return_value
.error_code
,
1224 return_value
.ec_return_value
);
1229 static acpi_status
wmid_v2_set_u32(u32 value
, u32 cap
)
1234 case ACER_CAP_WIRELESS
:
1235 device
= ACER_WMID3_GDS_WIRELESS
;
1237 case ACER_CAP_BLUETOOTH
:
1238 device
= ACER_WMID3_GDS_BLUETOOTH
;
1240 case ACER_CAP_THREEG
:
1241 device
= ACER_WMID3_GDS_THREEG
;
1246 return wmid3_set_device_status(value
, device
);
1249 static void __init
type_aa_dmi_decode(const struct dmi_header
*header
, void *d
)
1251 struct hotkey_function_type_aa
*type_aa
;
1253 /* We are looking for OEM-specific Type AAh */
1254 if (header
->type
!= 0xAA)
1258 type_aa
= (struct hotkey_function_type_aa
*) header
;
1260 pr_info("Function bitmap for Communication Button: 0x%x\n",
1261 type_aa
->commun_func_bitmap
);
1262 commun_func_bitmap
= type_aa
->commun_func_bitmap
;
1264 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
1265 interface
->capability
|= ACER_CAP_WIRELESS
;
1266 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
1267 interface
->capability
|= ACER_CAP_THREEG
;
1268 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
1269 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1270 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_RFBTN
) {
1271 interface
->capability
|= ACER_CAP_RFBTN
;
1272 commun_func_bitmap
&= ~ACER_WMID3_GDS_RFBTN
;
1275 commun_fn_key_number
= type_aa
->commun_fn_key_number
;
1278 static acpi_status __init
WMID_set_capabilities(void)
1280 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1281 union acpi_object
*obj
;
1285 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
1286 if (ACPI_FAILURE(status
))
1289 obj
= (union acpi_object
*) out
.pointer
;
1291 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1292 (obj
->buffer
.length
== sizeof(u32
) ||
1293 obj
->buffer
.length
== sizeof(u64
))) {
1294 devices
= *((u32
*) obj
->buffer
.pointer
);
1295 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1296 devices
= (u32
) obj
->integer
.value
;
1306 pr_info("Function bitmap for Communication Device: 0x%x\n", devices
);
1308 interface
->capability
|= ACER_CAP_WIRELESS
;
1310 interface
->capability
|= ACER_CAP_THREEG
;
1312 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1314 if (!(devices
& 0x20))
1315 max_brightness
= 0x9;
1321 static struct wmi_interface wmid_interface
= {
1325 static struct wmi_interface wmid_v2_interface
= {
1326 .type
= ACER_WMID_v2
,
1330 * Generic Device (interface-independent)
1333 static acpi_status
get_u32(u32
*value
, u32 cap
)
1335 acpi_status status
= AE_ERROR
;
1337 switch (interface
->type
) {
1339 status
= AMW0_get_u32(value
, cap
);
1342 if (cap
== ACER_CAP_MAILLED
) {
1343 status
= AMW0_get_u32(value
, cap
);
1347 status
= WMID_get_u32(value
, cap
);
1350 if (cap
& (ACER_CAP_WIRELESS
|
1351 ACER_CAP_BLUETOOTH
|
1353 status
= wmid_v2_get_u32(value
, cap
);
1354 else if (wmi_has_guid(WMID_GUID2
))
1355 status
= WMID_get_u32(value
, cap
);
1362 static acpi_status
set_u32(u32 value
, u32 cap
)
1366 if (interface
->capability
& cap
) {
1367 switch (interface
->type
) {
1369 return AMW0_set_u32(value
, cap
);
1371 if (cap
== ACER_CAP_MAILLED
)
1372 return AMW0_set_u32(value
, cap
);
1375 * On some models, some WMID methods don't toggle
1376 * properly. For those cases, we want to run the AMW0
1377 * method afterwards to be certain we've really toggled
1380 if (cap
== ACER_CAP_WIRELESS
||
1381 cap
== ACER_CAP_BLUETOOTH
) {
1382 status
= WMID_set_u32(value
, cap
);
1383 if (ACPI_FAILURE(status
))
1386 return AMW0_set_u32(value
, cap
);
1389 return WMID_set_u32(value
, cap
);
1391 if (cap
& (ACER_CAP_WIRELESS
|
1392 ACER_CAP_BLUETOOTH
|
1394 return wmid_v2_set_u32(value
, cap
);
1395 else if (wmi_has_guid(WMID_GUID2
))
1396 return WMID_set_u32(value
, cap
);
1398 return AE_BAD_PARAMETER
;
1401 return AE_BAD_PARAMETER
;
1404 static void __init
acer_commandline_init(void)
1407 * These will all fail silently if the value given is invalid, or the
1408 * capability isn't available on the given interface
1411 set_u32(mailled
, ACER_CAP_MAILLED
);
1412 if (!has_type_aa
&& threeg
>= 0)
1413 set_u32(threeg
, ACER_CAP_THREEG
);
1414 if (brightness
>= 0)
1415 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1419 * LED device (Mail LED only, no other LEDs known yet)
1421 static void mail_led_set(struct led_classdev
*led_cdev
,
1422 enum led_brightness value
)
1424 set_u32(value
, ACER_CAP_MAILLED
);
1427 static struct led_classdev mail_led
= {
1428 .name
= "acer-wmi::mail",
1429 .brightness_set
= mail_led_set
,
1432 static int acer_led_init(struct device
*dev
)
1434 return led_classdev_register(dev
, &mail_led
);
1437 static void acer_led_exit(void)
1439 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1440 led_classdev_unregister(&mail_led
);
1446 static struct backlight_device
*acer_backlight_device
;
1448 static int read_brightness(struct backlight_device
*bd
)
1451 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1455 static int update_bl_status(struct backlight_device
*bd
)
1457 int intensity
= bd
->props
.brightness
;
1459 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1461 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1464 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1469 static const struct backlight_ops acer_bl_ops
= {
1470 .get_brightness
= read_brightness
,
1471 .update_status
= update_bl_status
,
1474 static int acer_backlight_init(struct device
*dev
)
1476 struct backlight_properties props
;
1477 struct backlight_device
*bd
;
1479 memset(&props
, 0, sizeof(struct backlight_properties
));
1480 props
.type
= BACKLIGHT_PLATFORM
;
1481 props
.max_brightness
= max_brightness
;
1482 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1485 pr_err("Could not register Acer backlight device\n");
1486 acer_backlight_device
= NULL
;
1490 acer_backlight_device
= bd
;
1492 bd
->props
.power
= FB_BLANK_UNBLANK
;
1493 bd
->props
.brightness
= read_brightness(bd
);
1494 backlight_update_status(bd
);
1498 static void acer_backlight_exit(void)
1500 backlight_device_unregister(acer_backlight_device
);
1504 * Accelerometer device
1506 static acpi_handle gsensor_handle
;
1508 static int acer_gsensor_init(void)
1511 struct acpi_buffer output
;
1512 union acpi_object out_obj
;
1514 output
.length
= sizeof(out_obj
);
1515 output
.pointer
= &out_obj
;
1516 status
= acpi_evaluate_object(gsensor_handle
, "_INI", NULL
, &output
);
1517 if (ACPI_FAILURE(status
))
1523 static int acer_gsensor_open(struct input_dev
*input
)
1525 return acer_gsensor_init();
1528 static int acer_gsensor_event(void)
1531 struct acpi_buffer output
;
1532 union acpi_object out_obj
[5];
1534 if (!has_cap(ACER_CAP_ACCEL
))
1537 output
.length
= sizeof(out_obj
);
1538 output
.pointer
= out_obj
;
1540 status
= acpi_evaluate_object(gsensor_handle
, "RDVL", NULL
, &output
);
1541 if (ACPI_FAILURE(status
))
1544 if (out_obj
->package
.count
!= 4)
1547 input_report_abs(acer_wmi_accel_dev
, ABS_X
,
1548 (s16
)out_obj
->package
.elements
[0].integer
.value
);
1549 input_report_abs(acer_wmi_accel_dev
, ABS_Y
,
1550 (s16
)out_obj
->package
.elements
[1].integer
.value
);
1551 input_report_abs(acer_wmi_accel_dev
, ABS_Z
,
1552 (s16
)out_obj
->package
.elements
[2].integer
.value
);
1553 input_sync(acer_wmi_accel_dev
);
1560 static void acer_rfkill_update(struct work_struct
*ignored
);
1561 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1562 static void acer_rfkill_update(struct work_struct
*ignored
)
1567 if (has_cap(ACER_CAP_WIRELESS
)) {
1568 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1569 if (ACPI_SUCCESS(status
)) {
1570 if (quirks
->wireless
== 3)
1571 rfkill_set_hw_state(wireless_rfkill
, !state
);
1573 rfkill_set_sw_state(wireless_rfkill
, !state
);
1577 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1578 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1579 if (ACPI_SUCCESS(status
))
1580 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1583 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1584 status
= get_u32(&state
, ACER_WMID3_GDS_THREEG
);
1585 if (ACPI_SUCCESS(status
))
1586 rfkill_set_sw_state(threeg_rfkill
, !state
);
1589 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1592 static int acer_rfkill_set(void *data
, bool blocked
)
1595 u32 cap
= (unsigned long)data
;
1597 if (rfkill_inited
) {
1598 status
= set_u32(!blocked
, cap
);
1599 if (ACPI_FAILURE(status
))
1606 static const struct rfkill_ops acer_rfkill_ops
= {
1607 .set_block
= acer_rfkill_set
,
1610 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1611 enum rfkill_type type
,
1612 char *name
, u32 cap
)
1615 struct rfkill
*rfkill_dev
;
1619 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1621 (void *)(unsigned long)cap
);
1623 return ERR_PTR(-ENOMEM
);
1625 status
= get_u32(&state
, cap
);
1627 err
= rfkill_register(rfkill_dev
);
1629 rfkill_destroy(rfkill_dev
);
1630 return ERR_PTR(err
);
1633 if (ACPI_SUCCESS(status
))
1634 rfkill_set_sw_state(rfkill_dev
, !state
);
1639 static int acer_rfkill_init(struct device
*dev
)
1643 if (has_cap(ACER_CAP_WIRELESS
)) {
1644 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1645 "acer-wireless", ACER_CAP_WIRELESS
);
1646 if (IS_ERR(wireless_rfkill
)) {
1647 err
= PTR_ERR(wireless_rfkill
);
1648 goto error_wireless
;
1652 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1653 bluetooth_rfkill
= acer_rfkill_register(dev
,
1654 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1655 ACER_CAP_BLUETOOTH
);
1656 if (IS_ERR(bluetooth_rfkill
)) {
1657 err
= PTR_ERR(bluetooth_rfkill
);
1658 goto error_bluetooth
;
1662 if (has_cap(ACER_CAP_THREEG
)) {
1663 threeg_rfkill
= acer_rfkill_register(dev
,
1664 RFKILL_TYPE_WWAN
, "acer-threeg",
1666 if (IS_ERR(threeg_rfkill
)) {
1667 err
= PTR_ERR(threeg_rfkill
);
1672 rfkill_inited
= true;
1674 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1675 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1676 schedule_delayed_work(&acer_rfkill_work
,
1677 round_jiffies_relative(HZ
));
1682 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1683 rfkill_unregister(bluetooth_rfkill
);
1684 rfkill_destroy(bluetooth_rfkill
);
1687 if (has_cap(ACER_CAP_WIRELESS
)) {
1688 rfkill_unregister(wireless_rfkill
);
1689 rfkill_destroy(wireless_rfkill
);
1695 static void acer_rfkill_exit(void)
1697 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1698 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1699 cancel_delayed_work_sync(&acer_rfkill_work
);
1701 if (has_cap(ACER_CAP_WIRELESS
)) {
1702 rfkill_unregister(wireless_rfkill
);
1703 rfkill_destroy(wireless_rfkill
);
1706 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1707 rfkill_unregister(bluetooth_rfkill
);
1708 rfkill_destroy(bluetooth_rfkill
);
1711 if (has_cap(ACER_CAP_THREEG
)) {
1712 rfkill_unregister(threeg_rfkill
);
1713 rfkill_destroy(threeg_rfkill
);
1718 static void acer_wmi_notify(u32 value
, void *context
)
1720 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1721 union acpi_object
*obj
;
1722 struct event_return_value return_value
;
1725 const struct key_entry
*key
;
1728 status
= wmi_get_event_data(value
, &response
);
1729 if (status
!= AE_OK
) {
1730 pr_warn("bad event status 0x%x\n", status
);
1734 obj
= (union acpi_object
*)response
.pointer
;
1738 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1739 pr_warn("Unknown response received %d\n", obj
->type
);
1743 if (obj
->buffer
.length
!= 8) {
1744 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1749 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1752 switch (return_value
.function
) {
1753 case WMID_HOTKEY_EVENT
:
1754 device_state
= return_value
.device_state
;
1755 pr_debug("device state: 0x%x\n", device_state
);
1757 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1758 return_value
.key_num
);
1760 pr_warn("Unknown key number - 0x%x\n",
1761 return_value
.key_num
);
1763 scancode
= return_value
.key_num
;
1764 switch (key
->keycode
) {
1767 if (has_cap(ACER_CAP_WIRELESS
))
1768 rfkill_set_sw_state(wireless_rfkill
,
1769 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1770 if (has_cap(ACER_CAP_THREEG
))
1771 rfkill_set_sw_state(threeg_rfkill
,
1772 !(device_state
& ACER_WMID3_GDS_THREEG
));
1773 if (has_cap(ACER_CAP_BLUETOOTH
))
1774 rfkill_set_sw_state(bluetooth_rfkill
,
1775 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1777 case KEY_TOUCHPAD_TOGGLE
:
1778 scancode
= (device_state
& ACER_WMID3_GDS_TOUCHPAD
) ?
1779 KEY_TOUCHPAD_ON
: KEY_TOUCHPAD_OFF
;
1781 sparse_keymap_report_event(acer_wmi_input_dev
, scancode
, 1, true);
1784 case WMID_ACCEL_EVENT
:
1785 acer_gsensor_event();
1788 pr_warn("Unknown function number - %d - %d\n",
1789 return_value
.function
, return_value
.key_num
);
1794 static acpi_status __init
1795 wmid3_set_function_mode(struct func_input_params
*params
,
1796 struct func_return_value
*return_value
)
1799 union acpi_object
*obj
;
1801 struct acpi_buffer input
= { sizeof(struct func_input_params
), params
};
1802 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1804 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1805 if (ACPI_FAILURE(status
))
1808 obj
= output
.pointer
;
1812 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1816 if (obj
->buffer
.length
!= 4) {
1817 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1822 *return_value
= *((struct func_return_value
*)obj
->buffer
.pointer
);
1828 static int __init
acer_wmi_enable_ec_raw(void)
1830 struct func_return_value return_value
;
1832 struct func_input_params params
= {
1833 .function_num
= 0x1,
1834 .commun_devices
= 0xFFFF,
1836 .app_status
= 0x00, /* Launch Manager Deactive */
1840 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1842 if (return_value
.error_code
|| return_value
.ec_return_value
)
1843 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1844 return_value
.error_code
,
1845 return_value
.ec_return_value
);
1847 pr_info("Enabled EC raw mode\n");
1852 static int __init
acer_wmi_enable_lm(void)
1854 struct func_return_value return_value
;
1856 struct func_input_params params
= {
1857 .function_num
= 0x1,
1858 .commun_devices
= 0xFFFF,
1860 .app_status
= 0x01, /* Launch Manager Active */
1864 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1866 if (return_value
.error_code
|| return_value
.ec_return_value
)
1867 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1868 return_value
.error_code
,
1869 return_value
.ec_return_value
);
1874 static int __init
acer_wmi_enable_rf_button(void)
1876 struct func_return_value return_value
;
1878 struct func_input_params params
= {
1879 .function_num
= 0x1,
1880 .commun_devices
= 0xFFFF,
1882 .app_status
= 0x10, /* RF Button Active */
1886 status
= wmid3_set_function_mode(¶ms
, &return_value
);
1888 if (return_value
.error_code
|| return_value
.ec_return_value
)
1889 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1890 return_value
.error_code
,
1891 return_value
.ec_return_value
);
1896 #define ACER_WMID_ACCEL_HID "BST0001"
1898 static acpi_status __init
acer_wmi_get_handle_cb(acpi_handle ah
, u32 level
,
1899 void *ctx
, void **retval
)
1901 struct acpi_device
*dev
;
1903 if (!strcmp(ctx
, "SENR")) {
1904 if (acpi_bus_get_device(ah
, &dev
))
1906 if (strcmp(ACER_WMID_ACCEL_HID
, acpi_device_hid(dev
)))
1911 *(acpi_handle
*)retval
= ah
;
1913 return AE_CTRL_TERMINATE
;
1916 static int __init
acer_wmi_get_handle(const char *name
, const char *prop
,
1922 BUG_ON(!name
|| !ah
);
1925 status
= acpi_get_devices(prop
, acer_wmi_get_handle_cb
,
1926 (void *)name
, &handle
);
1927 if (ACPI_SUCCESS(status
) && handle
) {
1935 static int __init
acer_wmi_accel_setup(void)
1939 err
= acer_wmi_get_handle("SENR", ACER_WMID_ACCEL_HID
, &gsensor_handle
);
1943 interface
->capability
|= ACER_CAP_ACCEL
;
1945 acer_wmi_accel_dev
= input_allocate_device();
1946 if (!acer_wmi_accel_dev
)
1949 acer_wmi_accel_dev
->open
= acer_gsensor_open
;
1951 acer_wmi_accel_dev
->name
= "Acer BMA150 accelerometer";
1952 acer_wmi_accel_dev
->phys
= "wmi/input1";
1953 acer_wmi_accel_dev
->id
.bustype
= BUS_HOST
;
1954 acer_wmi_accel_dev
->evbit
[0] = BIT_MASK(EV_ABS
);
1955 input_set_abs_params(acer_wmi_accel_dev
, ABS_X
, -16384, 16384, 0, 0);
1956 input_set_abs_params(acer_wmi_accel_dev
, ABS_Y
, -16384, 16384, 0, 0);
1957 input_set_abs_params(acer_wmi_accel_dev
, ABS_Z
, -16384, 16384, 0, 0);
1959 err
= input_register_device(acer_wmi_accel_dev
);
1966 input_free_device(acer_wmi_accel_dev
);
1970 static void acer_wmi_accel_destroy(void)
1972 input_unregister_device(acer_wmi_accel_dev
);
1975 static int __init
acer_wmi_input_setup(void)
1980 acer_wmi_input_dev
= input_allocate_device();
1981 if (!acer_wmi_input_dev
)
1984 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1985 acer_wmi_input_dev
->phys
= "wmi/input0";
1986 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1988 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1992 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1993 acer_wmi_notify
, NULL
);
1994 if (ACPI_FAILURE(status
)) {
1999 err
= input_register_device(acer_wmi_input_dev
);
2001 goto err_uninstall_notifier
;
2005 err_uninstall_notifier
:
2006 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
2008 input_free_device(acer_wmi_input_dev
);
2012 static void acer_wmi_input_destroy(void)
2014 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
2015 input_unregister_device(acer_wmi_input_dev
);
2021 static u32
get_wmid_devices(void)
2023 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
2024 union acpi_object
*obj
;
2028 status
= wmi_query_block(WMID_GUID2
, 0, &out
);
2029 if (ACPI_FAILURE(status
))
2032 obj
= (union acpi_object
*) out
.pointer
;
2034 if (obj
->type
== ACPI_TYPE_BUFFER
&&
2035 (obj
->buffer
.length
== sizeof(u32
) ||
2036 obj
->buffer
.length
== sizeof(u64
))) {
2037 devices
= *((u32
*) obj
->buffer
.pointer
);
2038 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
2039 devices
= (u32
) obj
->integer
.value
;
2050 static int acer_platform_probe(struct platform_device
*device
)
2054 if (has_cap(ACER_CAP_MAILLED
)) {
2055 err
= acer_led_init(&device
->dev
);
2060 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2061 err
= acer_backlight_init(&device
->dev
);
2063 goto error_brightness
;
2066 err
= acer_rfkill_init(&device
->dev
);
2073 if (has_cap(ACER_CAP_BRIGHTNESS
))
2074 acer_backlight_exit();
2076 if (has_cap(ACER_CAP_MAILLED
))
2082 static int acer_platform_remove(struct platform_device
*device
)
2084 if (has_cap(ACER_CAP_MAILLED
))
2086 if (has_cap(ACER_CAP_BRIGHTNESS
))
2087 acer_backlight_exit();
2093 #ifdef CONFIG_PM_SLEEP
2094 static int acer_suspend(struct device
*dev
)
2097 struct acer_data
*data
= &interface
->data
;
2102 if (has_cap(ACER_CAP_MAILLED
)) {
2103 get_u32(&value
, ACER_CAP_MAILLED
);
2104 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2105 data
->mailled
= value
;
2108 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2109 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
2110 data
->brightness
= value
;
2116 static int acer_resume(struct device
*dev
)
2118 struct acer_data
*data
= &interface
->data
;
2123 if (has_cap(ACER_CAP_MAILLED
))
2124 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
2126 if (has_cap(ACER_CAP_BRIGHTNESS
))
2127 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
2129 if (has_cap(ACER_CAP_ACCEL
))
2130 acer_gsensor_init();
2135 #define acer_suspend NULL
2136 #define acer_resume NULL
2139 static SIMPLE_DEV_PM_OPS(acer_pm
, acer_suspend
, acer_resume
);
2141 static void acer_platform_shutdown(struct platform_device
*device
)
2143 struct acer_data
*data
= &interface
->data
;
2148 if (has_cap(ACER_CAP_MAILLED
))
2149 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2152 static struct platform_driver acer_platform_driver
= {
2157 .probe
= acer_platform_probe
,
2158 .remove
= acer_platform_remove
,
2159 .shutdown
= acer_platform_shutdown
,
2162 static struct platform_device
*acer_platform_device
;
2164 static void remove_debugfs(void)
2166 debugfs_remove(interface
->debug
.devices
);
2167 debugfs_remove(interface
->debug
.root
);
2170 static int __init
create_debugfs(void)
2172 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
2173 if (!interface
->debug
.root
) {
2174 pr_err("Failed to create debugfs directory");
2178 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
2179 interface
->debug
.root
,
2180 &interface
->debug
.wmid_devices
);
2181 if (!interface
->debug
.devices
)
2191 static int __init
acer_wmi_init(void)
2195 pr_info("Acer Laptop ACPI-WMI Extras\n");
2197 if (dmi_check_system(acer_blacklist
)) {
2198 pr_info("Blacklisted hardware detected - not loading\n");
2205 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2206 * machines like Lenovo, Fujitsu and Medion. In the past days,
2207 * acer-wmi driver handled those non-Acer machines by quirks list.
2208 * But actually acer-wmi driver was loaded on any machines that have
2209 * AMW0_GUID1. This behavior is strange because those machines should
2210 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2211 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2212 * should be in Acer/Gateway/Packard Bell white list, or it's already
2213 * in the past quirk list.
2215 if (wmi_has_guid(AMW0_GUID1
) &&
2216 !dmi_check_system(amw0_whitelist
) &&
2217 quirks
== &quirk_unknown
) {
2218 pr_err("Unsupported machine has AMW0_GUID1, unable to load\n");
2223 * Detect which ACPI-WMI interface we're using.
2225 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2226 interface
= &AMW0_V2_interface
;
2228 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2229 interface
= &wmid_interface
;
2231 if (wmi_has_guid(WMID_GUID3
))
2232 interface
= &wmid_v2_interface
;
2235 dmi_walk(type_aa_dmi_decode
, NULL
);
2237 if (wmi_has_guid(WMID_GUID2
) && interface
) {
2238 if (!has_type_aa
&& ACPI_FAILURE(WMID_set_capabilities())) {
2239 pr_err("Unable to detect available WMID devices\n");
2242 /* WMID always provides brightness methods */
2243 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
2244 } else if (!wmi_has_guid(WMID_GUID2
) && interface
&& !has_type_aa
) {
2245 pr_err("No WMID device detection method found\n");
2249 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
2250 interface
= &AMW0_interface
;
2252 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2253 pr_err("Unable to detect available AMW0 devices\n");
2258 if (wmi_has_guid(AMW0_GUID1
))
2259 AMW0_find_mailled();
2262 pr_err("No or unsupported WMI interface, unable to load\n");
2268 if (dmi_check_system(video_vendor_dmi_table
))
2269 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2271 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2272 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
2274 if (wmi_has_guid(WMID_GUID3
)) {
2275 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2276 pr_warn("Cannot enable RF Button Driver\n");
2279 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2280 pr_err("Cannot enable EC raw mode\n");
2283 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2284 pr_err("Cannot enable Launch Manager mode\n");
2287 } else if (ec_raw_mode
) {
2288 pr_info("No WMID EC raw mode enable method\n");
2291 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
2292 err
= acer_wmi_input_setup();
2295 err
= acer_wmi_accel_setup();
2296 if (err
&& err
!= -ENODEV
)
2297 pr_warn("Cannot enable accelerometer\n");
2300 err
= platform_driver_register(&acer_platform_driver
);
2302 pr_err("Unable to register platform driver\n");
2303 goto error_platform_register
;
2306 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
2307 if (!acer_platform_device
) {
2309 goto error_device_alloc
;
2312 err
= platform_device_add(acer_platform_device
);
2314 goto error_device_add
;
2316 if (wmi_has_guid(WMID_GUID2
)) {
2317 interface
->debug
.wmid_devices
= get_wmid_devices();
2318 err
= create_debugfs();
2320 goto error_create_debugfs
;
2323 /* Override any initial settings with values from the commandline */
2324 acer_commandline_init();
2328 error_create_debugfs
:
2329 platform_device_del(acer_platform_device
);
2331 platform_device_put(acer_platform_device
);
2333 platform_driver_unregister(&acer_platform_driver
);
2334 error_platform_register
:
2335 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2336 acer_wmi_input_destroy();
2337 if (has_cap(ACER_CAP_ACCEL
))
2338 acer_wmi_accel_destroy();
2343 static void __exit
acer_wmi_exit(void)
2345 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2346 acer_wmi_input_destroy();
2348 if (has_cap(ACER_CAP_ACCEL
))
2349 acer_wmi_accel_destroy();
2352 platform_device_unregister(acer_platform_device
);
2353 platform_driver_unregister(&acer_platform_driver
);
2355 pr_info("Acer Laptop WMI Extras unloaded\n");
2359 module_init(acer_wmi_init
);
2360 module_exit(acer_wmi_exit
);