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