treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / platform / x86 / acer-wmi.c
blob60c18f21588dd5d94a0beb343e8da6d3120d2a7b
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 MODULE_AUTHOR("Carlos Corbacho");
34 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
35 MODULE_LICENSE("GPL");
38 * Magic Number
39 * Meaning is unknown - this number is required for writing to ACPI for AMW0
40 * (it's also used in acerhk when directly accessing the BIOS)
42 #define ACER_AMW0_WRITE 0x9610
45 * Bit masks for the AMW0 interface
47 #define ACER_AMW0_WIRELESS_MASK 0x35
48 #define ACER_AMW0_BLUETOOTH_MASK 0x34
49 #define ACER_AMW0_MAILLED_MASK 0x31
52 * Method IDs for WMID interface
54 #define ACER_WMID_GET_WIRELESS_METHODID 1
55 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
56 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
57 #define ACER_WMID_SET_WIRELESS_METHODID 4
58 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
59 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
60 #define ACER_WMID_GET_THREEG_METHODID 10
61 #define ACER_WMID_SET_THREEG_METHODID 11
64 * Acer ACPI method GUIDs
66 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
67 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
68 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
69 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
70 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
73 * Acer ACPI event GUIDs
75 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
77 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
78 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
79 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
81 enum acer_wmi_event_ids {
82 WMID_HOTKEY_EVENT = 0x1,
83 WMID_ACCEL_EVENT = 0x5,
86 static const struct key_entry acer_wmi_keymap[] __initconst = {
87 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
88 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
89 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
90 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
91 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
92 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
93 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
94 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
95 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */
96 {KE_IGNORE, 0x41, {KEY_MUTE} },
97 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
98 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
99 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
100 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
101 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
102 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
103 {KE_IGNORE, 0x45, {KEY_STOP} },
104 {KE_IGNORE, 0x50, {KEY_STOP} },
105 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
106 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
107 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
108 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
109 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
110 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
111 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
112 {KE_IGNORE, 0x81, {KEY_SLEEP} },
113 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */
114 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
115 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
116 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
117 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
118 {KE_KEY, 0x86, {KEY_WLAN} },
119 {KE_KEY, 0x87, {KEY_POWER} },
120 {KE_END, 0}
123 static struct input_dev *acer_wmi_input_dev;
124 static struct input_dev *acer_wmi_accel_dev;
126 struct event_return_value {
127 u8 function;
128 u8 key_num;
129 u16 device_state;
130 u32 reserved;
131 } __attribute__((packed));
134 * GUID3 Get Device Status device flags
136 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
137 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
138 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
139 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
140 #define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
142 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
144 /* Hotkey Customized Setting and Acer Application Status.
145 * Set Device Default Value and Report Acer Application Status.
146 * When Acer Application starts, it will run this method to inform
147 * BIOS/EC that Acer Application is on.
148 * App Status
149 * Bit[0]: Launch Manager Status
150 * Bit[1]: ePM Status
151 * Bit[2]: Device Control Status
152 * Bit[3]: Acer Power Button Utility Status
153 * Bit[4]: RF Button Status
154 * Bit[5]: ODD PM Status
155 * Bit[6]: Device Default Value Control
156 * Bit[7]: Hall Sensor Application Status
158 struct func_input_params {
159 u8 function_num; /* Function Number */
160 u16 commun_devices; /* Communication type devices default status */
161 u16 devices; /* Other type devices default status */
162 u8 app_status; /* Acer Device Status. LM, ePM, RF Button... */
163 u8 app_mask; /* Bit mask to app_status */
164 u8 reserved;
165 } __attribute__((packed));
167 struct func_return_value {
168 u8 error_code; /* Error Code */
169 u8 ec_return_value; /* EC Return Value */
170 u16 reserved;
171 } __attribute__((packed));
173 struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
174 u8 function_num; /* Function Number */
175 u8 hotkey_number; /* Hotkey Number */
176 u16 devices; /* Set Device */
177 u8 volume_value; /* Volume Value */
178 } __attribute__((packed));
180 struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
181 u8 function_num; /* Function Number */
182 u8 hotkey_number; /* Hotkey Number */
183 u16 devices; /* Get Device */
184 } __attribute__((packed));
186 struct wmid3_gds_return_value { /* Get Device Status return value*/
187 u8 error_code; /* Error Code */
188 u8 ec_return_value; /* EC Return Value */
189 u16 devices; /* Current Device Status */
190 u32 reserved;
191 } __attribute__((packed));
193 struct hotkey_function_type_aa {
194 u8 type;
195 u8 length;
196 u16 handle;
197 u16 commun_func_bitmap;
198 u16 application_func_bitmap;
199 u16 media_func_bitmap;
200 u16 display_func_bitmap;
201 u16 others_func_bitmap;
202 u8 commun_fn_key_number;
203 } __attribute__((packed));
206 * Interface capability flags
208 #define ACER_CAP_MAILLED (1<<0)
209 #define ACER_CAP_WIRELESS (1<<1)
210 #define ACER_CAP_BLUETOOTH (1<<2)
211 #define ACER_CAP_BRIGHTNESS (1<<3)
212 #define ACER_CAP_THREEG (1<<4)
213 #define ACER_CAP_ACCEL (1<<5)
214 #define ACER_CAP_RFBTN (1<<6)
215 #define ACER_CAP_ANY (0xFFFFFFFF)
218 * Interface type flags
220 enum interface_flags {
221 ACER_AMW0,
222 ACER_AMW0_V2,
223 ACER_WMID,
224 ACER_WMID_v2,
227 #define ACER_DEFAULT_WIRELESS 0
228 #define ACER_DEFAULT_BLUETOOTH 0
229 #define ACER_DEFAULT_MAILLED 0
230 #define ACER_DEFAULT_THREEG 0
232 static int max_brightness = 0xF;
234 static int mailled = -1;
235 static int brightness = -1;
236 static int threeg = -1;
237 static int force_series;
238 static bool ec_raw_mode;
239 static bool has_type_aa;
240 static u16 commun_func_bitmap;
241 static u8 commun_fn_key_number;
243 module_param(mailled, int, 0444);
244 module_param(brightness, int, 0444);
245 module_param(threeg, int, 0444);
246 module_param(force_series, int, 0444);
247 module_param(ec_raw_mode, bool, 0444);
248 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
249 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
250 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
251 MODULE_PARM_DESC(force_series, "Force a different laptop series");
252 MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
254 struct acer_data {
255 int mailled;
256 int threeg;
257 int brightness;
260 struct acer_debug {
261 struct dentry *root;
262 u32 wmid_devices;
265 static struct rfkill *wireless_rfkill;
266 static struct rfkill *bluetooth_rfkill;
267 static struct rfkill *threeg_rfkill;
268 static bool rfkill_inited;
270 /* Each low-level interface must define at least some of the following */
271 struct wmi_interface {
272 /* The WMI device type */
273 u32 type;
275 /* The capabilities this interface provides */
276 u32 capability;
278 /* Private data for the current interface */
279 struct acer_data data;
281 /* debugfs entries associated with this interface */
282 struct acer_debug debug;
285 /* The static interface pointer, points to the currently detected interface */
286 static struct wmi_interface *interface;
289 * Embedded Controller quirks
290 * Some laptops require us to directly access the EC to either enable or query
291 * features that are not available through WMI.
294 struct quirk_entry {
295 u8 wireless;
296 u8 mailled;
297 s8 brightness;
298 u8 bluetooth;
301 static struct quirk_entry *quirks;
303 static void __init set_quirks(void)
305 if (!interface)
306 return;
308 if (quirks->mailled)
309 interface->capability |= ACER_CAP_MAILLED;
311 if (quirks->brightness)
312 interface->capability |= ACER_CAP_BRIGHTNESS;
315 static int __init dmi_matched(const struct dmi_system_id *dmi)
317 quirks = dmi->driver_data;
318 return 1;
321 static struct quirk_entry quirk_unknown = {
324 static struct quirk_entry quirk_acer_aspire_1520 = {
325 .brightness = -1,
328 static struct quirk_entry quirk_acer_travelmate_2490 = {
329 .mailled = 1,
332 /* This AMW0 laptop has no bluetooth */
333 static struct quirk_entry quirk_medion_md_98300 = {
334 .wireless = 1,
337 static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
338 .wireless = 2,
341 static struct quirk_entry quirk_lenovo_ideapad_s205 = {
342 .wireless = 3,
345 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
346 static const struct dmi_system_id acer_blacklist[] __initconst = {
348 .ident = "Acer Aspire One (SSD)",
349 .matches = {
350 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
351 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
355 .ident = "Acer Aspire One (HDD)",
356 .matches = {
357 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
358 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
364 static const struct dmi_system_id amw0_whitelist[] __initconst = {
366 .ident = "Acer",
367 .matches = {
368 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
372 .ident = "Gateway",
373 .matches = {
374 DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
378 .ident = "Packard Bell",
379 .matches = {
380 DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"),
387 * This quirk table is only for Acer/Gateway/Packard Bell family
388 * that those machines are supported by acer-wmi driver.
390 static const struct dmi_system_id acer_quirks[] __initconst = {
392 .callback = dmi_matched,
393 .ident = "Acer Aspire 1360",
394 .matches = {
395 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
396 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
398 .driver_data = &quirk_acer_aspire_1520,
401 .callback = dmi_matched,
402 .ident = "Acer Aspire 1520",
403 .matches = {
404 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
405 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
407 .driver_data = &quirk_acer_aspire_1520,
410 .callback = dmi_matched,
411 .ident = "Acer Aspire 3100",
412 .matches = {
413 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
414 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
416 .driver_data = &quirk_acer_travelmate_2490,
419 .callback = dmi_matched,
420 .ident = "Acer Aspire 3610",
421 .matches = {
422 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
423 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
425 .driver_data = &quirk_acer_travelmate_2490,
428 .callback = dmi_matched,
429 .ident = "Acer Aspire 5100",
430 .matches = {
431 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
432 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
434 .driver_data = &quirk_acer_travelmate_2490,
437 .callback = dmi_matched,
438 .ident = "Acer Aspire 5610",
439 .matches = {
440 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
441 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
443 .driver_data = &quirk_acer_travelmate_2490,
446 .callback = dmi_matched,
447 .ident = "Acer Aspire 5630",
448 .matches = {
449 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
450 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
452 .driver_data = &quirk_acer_travelmate_2490,
455 .callback = dmi_matched,
456 .ident = "Acer Aspire 5650",
457 .matches = {
458 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
459 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
461 .driver_data = &quirk_acer_travelmate_2490,
464 .callback = dmi_matched,
465 .ident = "Acer Aspire 5680",
466 .matches = {
467 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
468 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
470 .driver_data = &quirk_acer_travelmate_2490,
473 .callback = dmi_matched,
474 .ident = "Acer Aspire 9110",
475 .matches = {
476 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
477 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
479 .driver_data = &quirk_acer_travelmate_2490,
482 .callback = dmi_matched,
483 .ident = "Acer TravelMate 2490",
484 .matches = {
485 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
486 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
488 .driver_data = &quirk_acer_travelmate_2490,
491 .callback = dmi_matched,
492 .ident = "Acer TravelMate 4200",
493 .matches = {
494 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
495 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
497 .driver_data = &quirk_acer_travelmate_2490,
503 * This quirk list is for those non-acer machines that have AMW0_GUID1
504 * but supported by acer-wmi in past days. Keeping this quirk list here
505 * is only for backward compatible. Please do not add new machine to
506 * here anymore. Those non-acer machines should be supported by
507 * appropriate wmi drivers.
509 static const struct dmi_system_id non_acer_quirks[] __initconst = {
511 .callback = dmi_matched,
512 .ident = "Fujitsu Siemens Amilo Li 1718",
513 .matches = {
514 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
515 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
517 .driver_data = &quirk_fujitsu_amilo_li_1718,
520 .callback = dmi_matched,
521 .ident = "Medion MD 98300",
522 .matches = {
523 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
524 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
526 .driver_data = &quirk_medion_md_98300,
529 .callback = dmi_matched,
530 .ident = "Lenovo Ideapad S205",
531 .matches = {
532 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
533 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
535 .driver_data = &quirk_lenovo_ideapad_s205,
538 .callback = dmi_matched,
539 .ident = "Lenovo Ideapad S205 (Brazos)",
540 .matches = {
541 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
542 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
544 .driver_data = &quirk_lenovo_ideapad_s205,
547 .callback = dmi_matched,
548 .ident = "Lenovo 3000 N200",
549 .matches = {
550 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
551 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
553 .driver_data = &quirk_fujitsu_amilo_li_1718,
556 .callback = dmi_matched,
557 .ident = "Lenovo Ideapad S205-10382JG",
558 .matches = {
559 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
560 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
562 .driver_data = &quirk_lenovo_ideapad_s205,
565 .callback = dmi_matched,
566 .ident = "Lenovo Ideapad S205-1038DPG",
567 .matches = {
568 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
569 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
571 .driver_data = &quirk_lenovo_ideapad_s205,
576 static int __init
577 video_set_backlight_video_vendor(const struct dmi_system_id *d)
579 interface->capability &= ~ACER_CAP_BRIGHTNESS;
580 pr_info("Brightness must be controlled by generic video driver\n");
581 return 0;
584 static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
586 .callback = video_set_backlight_video_vendor,
587 .ident = "Acer TravelMate 4750",
588 .matches = {
589 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
590 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
594 .callback = video_set_backlight_video_vendor,
595 .ident = "Acer Extensa 5235",
596 .matches = {
597 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
598 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
602 .callback = video_set_backlight_video_vendor,
603 .ident = "Acer TravelMate 5760",
604 .matches = {
605 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
606 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
610 .callback = video_set_backlight_video_vendor,
611 .ident = "Acer Aspire 5750",
612 .matches = {
613 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
614 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
618 .callback = video_set_backlight_video_vendor,
619 .ident = "Acer Aspire 5741",
620 .matches = {
621 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
622 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
627 * Note no video_set_backlight_video_vendor, we must use the
628 * acer interface, as there is no native backlight interface.
630 .ident = "Acer KAV80",
631 .matches = {
632 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
633 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
639 /* Find which quirks are needed for a particular vendor/ model pair */
640 static void __init find_quirks(void)
642 if (!force_series) {
643 dmi_check_system(acer_quirks);
644 dmi_check_system(non_acer_quirks);
645 } else if (force_series == 2490) {
646 quirks = &quirk_acer_travelmate_2490;
649 if (quirks == NULL)
650 quirks = &quirk_unknown;
652 set_quirks();
656 * General interface convenience methods
659 static bool has_cap(u32 cap)
661 return interface->capability & cap;
665 * AMW0 (V1) interface
667 struct wmab_args {
668 u32 eax;
669 u32 ebx;
670 u32 ecx;
671 u32 edx;
674 struct wmab_ret {
675 u32 eax;
676 u32 ebx;
677 u32 ecx;
678 u32 edx;
679 u32 eex;
682 static acpi_status wmab_execute(struct wmab_args *regbuf,
683 struct acpi_buffer *result)
685 struct acpi_buffer input;
686 acpi_status status;
687 input.length = sizeof(struct wmab_args);
688 input.pointer = (u8 *)regbuf;
690 status = wmi_evaluate_method(AMW0_GUID1, 0, 1, &input, result);
692 return status;
695 static acpi_status AMW0_get_u32(u32 *value, u32 cap)
697 int err;
698 u8 result;
700 switch (cap) {
701 case ACER_CAP_MAILLED:
702 switch (quirks->mailled) {
703 default:
704 err = ec_read(0xA, &result);
705 if (err)
706 return AE_ERROR;
707 *value = (result >> 7) & 0x1;
708 return AE_OK;
710 break;
711 case ACER_CAP_WIRELESS:
712 switch (quirks->wireless) {
713 case 1:
714 err = ec_read(0x7B, &result);
715 if (err)
716 return AE_ERROR;
717 *value = result & 0x1;
718 return AE_OK;
719 case 2:
720 err = ec_read(0x71, &result);
721 if (err)
722 return AE_ERROR;
723 *value = result & 0x1;
724 return AE_OK;
725 case 3:
726 err = ec_read(0x78, &result);
727 if (err)
728 return AE_ERROR;
729 *value = result & 0x1;
730 return AE_OK;
731 default:
732 err = ec_read(0xA, &result);
733 if (err)
734 return AE_ERROR;
735 *value = (result >> 2) & 0x1;
736 return AE_OK;
738 break;
739 case ACER_CAP_BLUETOOTH:
740 switch (quirks->bluetooth) {
741 default:
742 err = ec_read(0xA, &result);
743 if (err)
744 return AE_ERROR;
745 *value = (result >> 4) & 0x1;
746 return AE_OK;
748 break;
749 case ACER_CAP_BRIGHTNESS:
750 switch (quirks->brightness) {
751 default:
752 err = ec_read(0x83, &result);
753 if (err)
754 return AE_ERROR;
755 *value = result;
756 return AE_OK;
758 break;
759 default:
760 return AE_ERROR;
762 return AE_OK;
765 static acpi_status AMW0_set_u32(u32 value, u32 cap)
767 struct wmab_args args;
769 args.eax = ACER_AMW0_WRITE;
770 args.ebx = value ? (1<<8) : 0;
771 args.ecx = args.edx = 0;
773 switch (cap) {
774 case ACER_CAP_MAILLED:
775 if (value > 1)
776 return AE_BAD_PARAMETER;
777 args.ebx |= ACER_AMW0_MAILLED_MASK;
778 break;
779 case ACER_CAP_WIRELESS:
780 if (value > 1)
781 return AE_BAD_PARAMETER;
782 args.ebx |= ACER_AMW0_WIRELESS_MASK;
783 break;
784 case ACER_CAP_BLUETOOTH:
785 if (value > 1)
786 return AE_BAD_PARAMETER;
787 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
788 break;
789 case ACER_CAP_BRIGHTNESS:
790 if (value > max_brightness)
791 return AE_BAD_PARAMETER;
792 switch (quirks->brightness) {
793 default:
794 return ec_write(0x83, value);
795 break;
797 default:
798 return AE_ERROR;
801 /* Actually do the set */
802 return wmab_execute(&args, NULL);
805 static acpi_status __init AMW0_find_mailled(void)
807 struct wmab_args args;
808 struct wmab_ret ret;
809 acpi_status status = AE_OK;
810 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
811 union acpi_object *obj;
813 args.eax = 0x86;
814 args.ebx = args.ecx = args.edx = 0;
816 status = wmab_execute(&args, &out);
817 if (ACPI_FAILURE(status))
818 return status;
820 obj = (union acpi_object *) out.pointer;
821 if (obj && obj->type == ACPI_TYPE_BUFFER &&
822 obj->buffer.length == sizeof(struct wmab_ret)) {
823 ret = *((struct wmab_ret *) obj->buffer.pointer);
824 } else {
825 kfree(out.pointer);
826 return AE_ERROR;
829 if (ret.eex & 0x1)
830 interface->capability |= ACER_CAP_MAILLED;
832 kfree(out.pointer);
834 return AE_OK;
837 static const struct acpi_device_id norfkill_ids[] __initconst = {
838 { "VPC2004", 0},
839 { "IBM0068", 0},
840 { "LEN0068", 0},
841 { "SNY5001", 0}, /* sony-laptop in charge */
842 { "HPQ6601", 0},
843 { "", 0},
846 static int __init AMW0_set_cap_acpi_check_device(void)
848 const struct acpi_device_id *id;
850 for (id = norfkill_ids; id->id[0]; id++)
851 if (acpi_dev_found(id->id))
852 return true;
854 return false;
857 static acpi_status __init AMW0_set_capabilities(void)
859 struct wmab_args args;
860 struct wmab_ret ret;
861 acpi_status status;
862 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
863 union acpi_object *obj;
866 * On laptops with this strange GUID (non Acer), normal probing doesn't
867 * work.
869 if (wmi_has_guid(AMW0_GUID2)) {
870 if ((quirks != &quirk_unknown) ||
871 !AMW0_set_cap_acpi_check_device())
872 interface->capability |= ACER_CAP_WIRELESS;
873 return AE_OK;
876 args.eax = ACER_AMW0_WRITE;
877 args.ecx = args.edx = 0;
879 args.ebx = 0xa2 << 8;
880 args.ebx |= ACER_AMW0_WIRELESS_MASK;
882 status = wmab_execute(&args, &out);
883 if (ACPI_FAILURE(status))
884 return status;
886 obj = out.pointer;
887 if (obj && obj->type == ACPI_TYPE_BUFFER &&
888 obj->buffer.length == sizeof(struct wmab_ret)) {
889 ret = *((struct wmab_ret *) obj->buffer.pointer);
890 } else {
891 status = AE_ERROR;
892 goto out;
895 if (ret.eax & 0x1)
896 interface->capability |= ACER_CAP_WIRELESS;
898 args.ebx = 2 << 8;
899 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
902 * It's ok to use existing buffer for next wmab_execute call.
903 * But we need to kfree(out.pointer) if next wmab_execute fail.
905 status = wmab_execute(&args, &out);
906 if (ACPI_FAILURE(status))
907 goto out;
909 obj = (union acpi_object *) out.pointer;
910 if (obj && obj->type == ACPI_TYPE_BUFFER
911 && obj->buffer.length == sizeof(struct wmab_ret)) {
912 ret = *((struct wmab_ret *) obj->buffer.pointer);
913 } else {
914 status = AE_ERROR;
915 goto out;
918 if (ret.eax & 0x1)
919 interface->capability |= ACER_CAP_BLUETOOTH;
922 * This appears to be safe to enable, since all Wistron based laptops
923 * appear to use the same EC register for brightness, even if they
924 * differ for wireless, etc
926 if (quirks->brightness >= 0)
927 interface->capability |= ACER_CAP_BRIGHTNESS;
929 status = AE_OK;
930 out:
931 kfree(out.pointer);
932 return status;
935 static struct wmi_interface AMW0_interface = {
936 .type = ACER_AMW0,
939 static struct wmi_interface AMW0_V2_interface = {
940 .type = ACER_AMW0_V2,
944 * New interface (The WMID interface)
946 static acpi_status
947 WMI_execute_u32(u32 method_id, u32 in, u32 *out)
949 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
950 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
951 union acpi_object *obj;
952 u32 tmp = 0;
953 acpi_status status;
955 status = wmi_evaluate_method(WMID_GUID1, 0, method_id, &input, &result);
957 if (ACPI_FAILURE(status))
958 return status;
960 obj = (union acpi_object *) result.pointer;
961 if (obj) {
962 if (obj->type == ACPI_TYPE_BUFFER &&
963 (obj->buffer.length == sizeof(u32) ||
964 obj->buffer.length == sizeof(u64))) {
965 tmp = *((u32 *) obj->buffer.pointer);
966 } else if (obj->type == ACPI_TYPE_INTEGER) {
967 tmp = (u32) obj->integer.value;
971 if (out)
972 *out = tmp;
974 kfree(result.pointer);
976 return status;
979 static acpi_status WMID_get_u32(u32 *value, u32 cap)
981 acpi_status status;
982 u8 tmp;
983 u32 result, method_id = 0;
985 switch (cap) {
986 case ACER_CAP_WIRELESS:
987 method_id = ACER_WMID_GET_WIRELESS_METHODID;
988 break;
989 case ACER_CAP_BLUETOOTH:
990 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
991 break;
992 case ACER_CAP_BRIGHTNESS:
993 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
994 break;
995 case ACER_CAP_THREEG:
996 method_id = ACER_WMID_GET_THREEG_METHODID;
997 break;
998 case ACER_CAP_MAILLED:
999 if (quirks->mailled == 1) {
1000 ec_read(0x9f, &tmp);
1001 *value = tmp & 0x1;
1002 return 0;
1004 /* fall through */
1005 default:
1006 return AE_ERROR;
1008 status = WMI_execute_u32(method_id, 0, &result);
1010 if (ACPI_SUCCESS(status))
1011 *value = (u8)result;
1013 return status;
1016 static acpi_status WMID_set_u32(u32 value, u32 cap)
1018 u32 method_id = 0;
1019 char param;
1021 switch (cap) {
1022 case ACER_CAP_BRIGHTNESS:
1023 if (value > max_brightness)
1024 return AE_BAD_PARAMETER;
1025 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
1026 break;
1027 case ACER_CAP_WIRELESS:
1028 if (value > 1)
1029 return AE_BAD_PARAMETER;
1030 method_id = ACER_WMID_SET_WIRELESS_METHODID;
1031 break;
1032 case ACER_CAP_BLUETOOTH:
1033 if (value > 1)
1034 return AE_BAD_PARAMETER;
1035 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
1036 break;
1037 case ACER_CAP_THREEG:
1038 if (value > 1)
1039 return AE_BAD_PARAMETER;
1040 method_id = ACER_WMID_SET_THREEG_METHODID;
1041 break;
1042 case ACER_CAP_MAILLED:
1043 if (value > 1)
1044 return AE_BAD_PARAMETER;
1045 if (quirks->mailled == 1) {
1046 param = value ? 0x92 : 0x93;
1047 i8042_lock_chip();
1048 i8042_command(&param, 0x1059);
1049 i8042_unlock_chip();
1050 return 0;
1052 break;
1053 default:
1054 return AE_ERROR;
1056 return WMI_execute_u32(method_id, (u32)value, NULL);
1059 static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1061 struct wmid3_gds_return_value return_value;
1062 acpi_status status;
1063 union acpi_object *obj;
1064 struct wmid3_gds_get_input_param params = {
1065 .function_num = 0x1,
1066 .hotkey_number = commun_fn_key_number,
1067 .devices = device,
1069 struct acpi_buffer input = {
1070 sizeof(struct wmid3_gds_get_input_param),
1071 &params
1073 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1075 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1076 if (ACPI_FAILURE(status))
1077 return status;
1079 obj = output.pointer;
1081 if (!obj)
1082 return AE_ERROR;
1083 else if (obj->type != ACPI_TYPE_BUFFER) {
1084 kfree(obj);
1085 return AE_ERROR;
1087 if (obj->buffer.length != 8) {
1088 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1089 kfree(obj);
1090 return AE_ERROR;
1093 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1094 kfree(obj);
1096 if (return_value.error_code || return_value.ec_return_value)
1097 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1098 device,
1099 return_value.error_code,
1100 return_value.ec_return_value);
1101 else
1102 *value = !!(return_value.devices & device);
1104 return status;
1107 static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1109 u16 device;
1111 switch (cap) {
1112 case ACER_CAP_WIRELESS:
1113 device = ACER_WMID3_GDS_WIRELESS;
1114 break;
1115 case ACER_CAP_BLUETOOTH:
1116 device = ACER_WMID3_GDS_BLUETOOTH;
1117 break;
1118 case ACER_CAP_THREEG:
1119 device = ACER_WMID3_GDS_THREEG;
1120 break;
1121 default:
1122 return AE_ERROR;
1124 return wmid3_get_device_status(value, device);
1127 static acpi_status wmid3_set_device_status(u32 value, u16 device)
1129 struct wmid3_gds_return_value return_value;
1130 acpi_status status;
1131 union acpi_object *obj;
1132 u16 devices;
1133 struct wmid3_gds_get_input_param get_params = {
1134 .function_num = 0x1,
1135 .hotkey_number = commun_fn_key_number,
1136 .devices = commun_func_bitmap,
1138 struct acpi_buffer get_input = {
1139 sizeof(struct wmid3_gds_get_input_param),
1140 &get_params
1142 struct wmid3_gds_set_input_param set_params = {
1143 .function_num = 0x2,
1144 .hotkey_number = commun_fn_key_number,
1145 .devices = commun_func_bitmap,
1147 struct acpi_buffer set_input = {
1148 sizeof(struct wmid3_gds_set_input_param),
1149 &set_params
1151 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1152 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1154 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
1155 if (ACPI_FAILURE(status))
1156 return status;
1158 obj = output.pointer;
1160 if (!obj)
1161 return AE_ERROR;
1162 else if (obj->type != ACPI_TYPE_BUFFER) {
1163 kfree(obj);
1164 return AE_ERROR;
1166 if (obj->buffer.length != 8) {
1167 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1168 kfree(obj);
1169 return AE_ERROR;
1172 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1173 kfree(obj);
1175 if (return_value.error_code || return_value.ec_return_value) {
1176 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1177 return_value.error_code,
1178 return_value.ec_return_value);
1179 return status;
1182 devices = return_value.devices;
1183 set_params.devices = (value) ? (devices | device) : (devices & ~device);
1185 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
1186 if (ACPI_FAILURE(status))
1187 return status;
1189 obj = output2.pointer;
1191 if (!obj)
1192 return AE_ERROR;
1193 else if (obj->type != ACPI_TYPE_BUFFER) {
1194 kfree(obj);
1195 return AE_ERROR;
1197 if (obj->buffer.length != 4) {
1198 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1199 kfree(obj);
1200 return AE_ERROR;
1203 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1204 kfree(obj);
1206 if (return_value.error_code || return_value.ec_return_value)
1207 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1208 return_value.error_code,
1209 return_value.ec_return_value);
1211 return status;
1214 static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1216 u16 device;
1218 switch (cap) {
1219 case ACER_CAP_WIRELESS:
1220 device = ACER_WMID3_GDS_WIRELESS;
1221 break;
1222 case ACER_CAP_BLUETOOTH:
1223 device = ACER_WMID3_GDS_BLUETOOTH;
1224 break;
1225 case ACER_CAP_THREEG:
1226 device = ACER_WMID3_GDS_THREEG;
1227 break;
1228 default:
1229 return AE_ERROR;
1231 return wmid3_set_device_status(value, device);
1234 static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
1236 struct hotkey_function_type_aa *type_aa;
1238 /* We are looking for OEM-specific Type AAh */
1239 if (header->type != 0xAA)
1240 return;
1242 has_type_aa = true;
1243 type_aa = (struct hotkey_function_type_aa *) header;
1245 pr_info("Function bitmap for Communication Button: 0x%x\n",
1246 type_aa->commun_func_bitmap);
1247 commun_func_bitmap = type_aa->commun_func_bitmap;
1249 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1250 interface->capability |= ACER_CAP_WIRELESS;
1251 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1252 interface->capability |= ACER_CAP_THREEG;
1253 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1254 interface->capability |= ACER_CAP_BLUETOOTH;
1255 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_RFBTN) {
1256 interface->capability |= ACER_CAP_RFBTN;
1257 commun_func_bitmap &= ~ACER_WMID3_GDS_RFBTN;
1260 commun_fn_key_number = type_aa->commun_fn_key_number;
1263 static acpi_status __init WMID_set_capabilities(void)
1265 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1266 union acpi_object *obj;
1267 acpi_status status;
1268 u32 devices;
1270 status = wmi_query_block(WMID_GUID2, 0, &out);
1271 if (ACPI_FAILURE(status))
1272 return status;
1274 obj = (union acpi_object *) out.pointer;
1275 if (obj) {
1276 if (obj->type == ACPI_TYPE_BUFFER &&
1277 (obj->buffer.length == sizeof(u32) ||
1278 obj->buffer.length == sizeof(u64))) {
1279 devices = *((u32 *) obj->buffer.pointer);
1280 } else if (obj->type == ACPI_TYPE_INTEGER) {
1281 devices = (u32) obj->integer.value;
1282 } else {
1283 kfree(out.pointer);
1284 return AE_ERROR;
1286 } else {
1287 kfree(out.pointer);
1288 return AE_ERROR;
1291 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1292 if (devices & 0x07)
1293 interface->capability |= ACER_CAP_WIRELESS;
1294 if (devices & 0x40)
1295 interface->capability |= ACER_CAP_THREEG;
1296 if (devices & 0x10)
1297 interface->capability |= ACER_CAP_BLUETOOTH;
1299 if (!(devices & 0x20))
1300 max_brightness = 0x9;
1302 kfree(out.pointer);
1303 return status;
1306 static struct wmi_interface wmid_interface = {
1307 .type = ACER_WMID,
1310 static struct wmi_interface wmid_v2_interface = {
1311 .type = ACER_WMID_v2,
1315 * Generic Device (interface-independent)
1318 static acpi_status get_u32(u32 *value, u32 cap)
1320 acpi_status status = AE_ERROR;
1322 switch (interface->type) {
1323 case ACER_AMW0:
1324 status = AMW0_get_u32(value, cap);
1325 break;
1326 case ACER_AMW0_V2:
1327 if (cap == ACER_CAP_MAILLED) {
1328 status = AMW0_get_u32(value, cap);
1329 break;
1331 /* fall through */
1332 case ACER_WMID:
1333 status = WMID_get_u32(value, cap);
1334 break;
1335 case ACER_WMID_v2:
1336 if (cap & (ACER_CAP_WIRELESS |
1337 ACER_CAP_BLUETOOTH |
1338 ACER_CAP_THREEG))
1339 status = wmid_v2_get_u32(value, cap);
1340 else if (wmi_has_guid(WMID_GUID2))
1341 status = WMID_get_u32(value, cap);
1342 break;
1345 return status;
1348 static acpi_status set_u32(u32 value, u32 cap)
1350 acpi_status status;
1352 if (interface->capability & cap) {
1353 switch (interface->type) {
1354 case ACER_AMW0:
1355 return AMW0_set_u32(value, cap);
1356 case ACER_AMW0_V2:
1357 if (cap == ACER_CAP_MAILLED)
1358 return AMW0_set_u32(value, cap);
1361 * On some models, some WMID methods don't toggle
1362 * properly. For those cases, we want to run the AMW0
1363 * method afterwards to be certain we've really toggled
1364 * the device state.
1366 if (cap == ACER_CAP_WIRELESS ||
1367 cap == ACER_CAP_BLUETOOTH) {
1368 status = WMID_set_u32(value, cap);
1369 if (ACPI_FAILURE(status))
1370 return status;
1372 return AMW0_set_u32(value, cap);
1374 /* fall through */
1375 case ACER_WMID:
1376 return WMID_set_u32(value, cap);
1377 case ACER_WMID_v2:
1378 if (cap & (ACER_CAP_WIRELESS |
1379 ACER_CAP_BLUETOOTH |
1380 ACER_CAP_THREEG))
1381 return wmid_v2_set_u32(value, cap);
1382 else if (wmi_has_guid(WMID_GUID2))
1383 return WMID_set_u32(value, cap);
1384 /* fall through */
1385 default:
1386 return AE_BAD_PARAMETER;
1389 return AE_BAD_PARAMETER;
1392 static void __init acer_commandline_init(void)
1395 * These will all fail silently if the value given is invalid, or the
1396 * capability isn't available on the given interface
1398 if (mailled >= 0)
1399 set_u32(mailled, ACER_CAP_MAILLED);
1400 if (!has_type_aa && threeg >= 0)
1401 set_u32(threeg, ACER_CAP_THREEG);
1402 if (brightness >= 0)
1403 set_u32(brightness, ACER_CAP_BRIGHTNESS);
1407 * LED device (Mail LED only, no other LEDs known yet)
1409 static void mail_led_set(struct led_classdev *led_cdev,
1410 enum led_brightness value)
1412 set_u32(value, ACER_CAP_MAILLED);
1415 static struct led_classdev mail_led = {
1416 .name = "acer-wmi::mail",
1417 .brightness_set = mail_led_set,
1420 static int acer_led_init(struct device *dev)
1422 return led_classdev_register(dev, &mail_led);
1425 static void acer_led_exit(void)
1427 set_u32(LED_OFF, ACER_CAP_MAILLED);
1428 led_classdev_unregister(&mail_led);
1432 * Backlight device
1434 static struct backlight_device *acer_backlight_device;
1436 static int read_brightness(struct backlight_device *bd)
1438 u32 value;
1439 get_u32(&value, ACER_CAP_BRIGHTNESS);
1440 return value;
1443 static int update_bl_status(struct backlight_device *bd)
1445 int intensity = bd->props.brightness;
1447 if (bd->props.power != FB_BLANK_UNBLANK)
1448 intensity = 0;
1449 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1450 intensity = 0;
1452 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1454 return 0;
1457 static const struct backlight_ops acer_bl_ops = {
1458 .get_brightness = read_brightness,
1459 .update_status = update_bl_status,
1462 static int acer_backlight_init(struct device *dev)
1464 struct backlight_properties props;
1465 struct backlight_device *bd;
1467 memset(&props, 0, sizeof(struct backlight_properties));
1468 props.type = BACKLIGHT_PLATFORM;
1469 props.max_brightness = max_brightness;
1470 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1471 &props);
1472 if (IS_ERR(bd)) {
1473 pr_err("Could not register Acer backlight device\n");
1474 acer_backlight_device = NULL;
1475 return PTR_ERR(bd);
1478 acer_backlight_device = bd;
1480 bd->props.power = FB_BLANK_UNBLANK;
1481 bd->props.brightness = read_brightness(bd);
1482 backlight_update_status(bd);
1483 return 0;
1486 static void acer_backlight_exit(void)
1488 backlight_device_unregister(acer_backlight_device);
1492 * Accelerometer device
1494 static acpi_handle gsensor_handle;
1496 static int acer_gsensor_init(void)
1498 acpi_status status;
1499 struct acpi_buffer output;
1500 union acpi_object out_obj;
1502 output.length = sizeof(out_obj);
1503 output.pointer = &out_obj;
1504 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1505 if (ACPI_FAILURE(status))
1506 return -1;
1508 return 0;
1511 static int acer_gsensor_open(struct input_dev *input)
1513 return acer_gsensor_init();
1516 static int acer_gsensor_event(void)
1518 acpi_status status;
1519 struct acpi_buffer output;
1520 union acpi_object out_obj[5];
1522 if (!has_cap(ACER_CAP_ACCEL))
1523 return -1;
1525 output.length = sizeof(out_obj);
1526 output.pointer = out_obj;
1528 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1529 if (ACPI_FAILURE(status))
1530 return -1;
1532 if (out_obj->package.count != 4)
1533 return -1;
1535 input_report_abs(acer_wmi_accel_dev, ABS_X,
1536 (s16)out_obj->package.elements[0].integer.value);
1537 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1538 (s16)out_obj->package.elements[1].integer.value);
1539 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1540 (s16)out_obj->package.elements[2].integer.value);
1541 input_sync(acer_wmi_accel_dev);
1542 return 0;
1546 * Rfkill devices
1548 static void acer_rfkill_update(struct work_struct *ignored);
1549 static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1550 static void acer_rfkill_update(struct work_struct *ignored)
1552 u32 state;
1553 acpi_status status;
1555 if (has_cap(ACER_CAP_WIRELESS)) {
1556 status = get_u32(&state, ACER_CAP_WIRELESS);
1557 if (ACPI_SUCCESS(status)) {
1558 if (quirks->wireless == 3)
1559 rfkill_set_hw_state(wireless_rfkill, !state);
1560 else
1561 rfkill_set_sw_state(wireless_rfkill, !state);
1565 if (has_cap(ACER_CAP_BLUETOOTH)) {
1566 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1567 if (ACPI_SUCCESS(status))
1568 rfkill_set_sw_state(bluetooth_rfkill, !state);
1571 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1572 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
1573 if (ACPI_SUCCESS(status))
1574 rfkill_set_sw_state(threeg_rfkill, !state);
1577 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1580 static int acer_rfkill_set(void *data, bool blocked)
1582 acpi_status status;
1583 u32 cap = (unsigned long)data;
1585 if (rfkill_inited) {
1586 status = set_u32(!blocked, cap);
1587 if (ACPI_FAILURE(status))
1588 return -ENODEV;
1591 return 0;
1594 static const struct rfkill_ops acer_rfkill_ops = {
1595 .set_block = acer_rfkill_set,
1598 static struct rfkill *acer_rfkill_register(struct device *dev,
1599 enum rfkill_type type,
1600 char *name, u32 cap)
1602 int err;
1603 struct rfkill *rfkill_dev;
1604 u32 state;
1605 acpi_status status;
1607 rfkill_dev = rfkill_alloc(name, dev, type,
1608 &acer_rfkill_ops,
1609 (void *)(unsigned long)cap);
1610 if (!rfkill_dev)
1611 return ERR_PTR(-ENOMEM);
1613 status = get_u32(&state, cap);
1615 err = rfkill_register(rfkill_dev);
1616 if (err) {
1617 rfkill_destroy(rfkill_dev);
1618 return ERR_PTR(err);
1621 if (ACPI_SUCCESS(status))
1622 rfkill_set_sw_state(rfkill_dev, !state);
1624 return rfkill_dev;
1627 static int acer_rfkill_init(struct device *dev)
1629 int err;
1631 if (has_cap(ACER_CAP_WIRELESS)) {
1632 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1633 "acer-wireless", ACER_CAP_WIRELESS);
1634 if (IS_ERR(wireless_rfkill)) {
1635 err = PTR_ERR(wireless_rfkill);
1636 goto error_wireless;
1640 if (has_cap(ACER_CAP_BLUETOOTH)) {
1641 bluetooth_rfkill = acer_rfkill_register(dev,
1642 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1643 ACER_CAP_BLUETOOTH);
1644 if (IS_ERR(bluetooth_rfkill)) {
1645 err = PTR_ERR(bluetooth_rfkill);
1646 goto error_bluetooth;
1650 if (has_cap(ACER_CAP_THREEG)) {
1651 threeg_rfkill = acer_rfkill_register(dev,
1652 RFKILL_TYPE_WWAN, "acer-threeg",
1653 ACER_CAP_THREEG);
1654 if (IS_ERR(threeg_rfkill)) {
1655 err = PTR_ERR(threeg_rfkill);
1656 goto error_threeg;
1660 rfkill_inited = true;
1662 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1663 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1664 schedule_delayed_work(&acer_rfkill_work,
1665 round_jiffies_relative(HZ));
1667 return 0;
1669 error_threeg:
1670 if (has_cap(ACER_CAP_BLUETOOTH)) {
1671 rfkill_unregister(bluetooth_rfkill);
1672 rfkill_destroy(bluetooth_rfkill);
1674 error_bluetooth:
1675 if (has_cap(ACER_CAP_WIRELESS)) {
1676 rfkill_unregister(wireless_rfkill);
1677 rfkill_destroy(wireless_rfkill);
1679 error_wireless:
1680 return err;
1683 static void acer_rfkill_exit(void)
1685 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1686 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1687 cancel_delayed_work_sync(&acer_rfkill_work);
1689 if (has_cap(ACER_CAP_WIRELESS)) {
1690 rfkill_unregister(wireless_rfkill);
1691 rfkill_destroy(wireless_rfkill);
1694 if (has_cap(ACER_CAP_BLUETOOTH)) {
1695 rfkill_unregister(bluetooth_rfkill);
1696 rfkill_destroy(bluetooth_rfkill);
1699 if (has_cap(ACER_CAP_THREEG)) {
1700 rfkill_unregister(threeg_rfkill);
1701 rfkill_destroy(threeg_rfkill);
1703 return;
1706 static void acer_wmi_notify(u32 value, void *context)
1708 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1709 union acpi_object *obj;
1710 struct event_return_value return_value;
1711 acpi_status status;
1712 u16 device_state;
1713 const struct key_entry *key;
1714 u32 scancode;
1716 status = wmi_get_event_data(value, &response);
1717 if (status != AE_OK) {
1718 pr_warn("bad event status 0x%x\n", status);
1719 return;
1722 obj = (union acpi_object *)response.pointer;
1724 if (!obj)
1725 return;
1726 if (obj->type != ACPI_TYPE_BUFFER) {
1727 pr_warn("Unknown response received %d\n", obj->type);
1728 kfree(obj);
1729 return;
1731 if (obj->buffer.length != 8) {
1732 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1733 kfree(obj);
1734 return;
1737 return_value = *((struct event_return_value *)obj->buffer.pointer);
1738 kfree(obj);
1740 switch (return_value.function) {
1741 case WMID_HOTKEY_EVENT:
1742 device_state = return_value.device_state;
1743 pr_debug("device state: 0x%x\n", device_state);
1745 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1746 return_value.key_num);
1747 if (!key) {
1748 pr_warn("Unknown key number - 0x%x\n",
1749 return_value.key_num);
1750 } else {
1751 scancode = return_value.key_num;
1752 switch (key->keycode) {
1753 case KEY_WLAN:
1754 case KEY_BLUETOOTH:
1755 if (has_cap(ACER_CAP_WIRELESS))
1756 rfkill_set_sw_state(wireless_rfkill,
1757 !(device_state & ACER_WMID3_GDS_WIRELESS));
1758 if (has_cap(ACER_CAP_THREEG))
1759 rfkill_set_sw_state(threeg_rfkill,
1760 !(device_state & ACER_WMID3_GDS_THREEG));
1761 if (has_cap(ACER_CAP_BLUETOOTH))
1762 rfkill_set_sw_state(bluetooth_rfkill,
1763 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1764 break;
1765 case KEY_TOUCHPAD_TOGGLE:
1766 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1767 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
1769 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
1771 break;
1772 case WMID_ACCEL_EVENT:
1773 acer_gsensor_event();
1774 break;
1775 default:
1776 pr_warn("Unknown function number - %d - %d\n",
1777 return_value.function, return_value.key_num);
1778 break;
1782 static acpi_status __init
1783 wmid3_set_function_mode(struct func_input_params *params,
1784 struct func_return_value *return_value)
1786 acpi_status status;
1787 union acpi_object *obj;
1789 struct acpi_buffer input = { sizeof(struct func_input_params), params };
1790 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1792 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1793 if (ACPI_FAILURE(status))
1794 return status;
1796 obj = output.pointer;
1798 if (!obj)
1799 return AE_ERROR;
1800 else if (obj->type != ACPI_TYPE_BUFFER) {
1801 kfree(obj);
1802 return AE_ERROR;
1804 if (obj->buffer.length != 4) {
1805 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1806 kfree(obj);
1807 return AE_ERROR;
1810 *return_value = *((struct func_return_value *)obj->buffer.pointer);
1811 kfree(obj);
1813 return status;
1816 static int __init acer_wmi_enable_ec_raw(void)
1818 struct func_return_value return_value;
1819 acpi_status status;
1820 struct func_input_params params = {
1821 .function_num = 0x1,
1822 .commun_devices = 0xFFFF,
1823 .devices = 0xFFFF,
1824 .app_status = 0x00, /* Launch Manager Deactive */
1825 .app_mask = 0x01,
1828 status = wmid3_set_function_mode(&params, &return_value);
1830 if (return_value.error_code || return_value.ec_return_value)
1831 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1832 return_value.error_code,
1833 return_value.ec_return_value);
1834 else
1835 pr_info("Enabled EC raw mode\n");
1837 return status;
1840 static int __init acer_wmi_enable_lm(void)
1842 struct func_return_value return_value;
1843 acpi_status status;
1844 struct func_input_params params = {
1845 .function_num = 0x1,
1846 .commun_devices = 0xFFFF,
1847 .devices = 0xFFFF,
1848 .app_status = 0x01, /* Launch Manager Active */
1849 .app_mask = 0x01,
1852 status = wmid3_set_function_mode(&params, &return_value);
1854 if (return_value.error_code || return_value.ec_return_value)
1855 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1856 return_value.error_code,
1857 return_value.ec_return_value);
1859 return status;
1862 static int __init acer_wmi_enable_rf_button(void)
1864 struct func_return_value return_value;
1865 acpi_status status;
1866 struct func_input_params params = {
1867 .function_num = 0x1,
1868 .commun_devices = 0xFFFF,
1869 .devices = 0xFFFF,
1870 .app_status = 0x10, /* RF Button Active */
1871 .app_mask = 0x10,
1874 status = wmid3_set_function_mode(&params, &return_value);
1876 if (return_value.error_code || return_value.ec_return_value)
1877 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1878 return_value.error_code,
1879 return_value.ec_return_value);
1881 return status;
1884 static int __init acer_wmi_accel_setup(void)
1886 struct acpi_device *adev;
1887 int err;
1889 adev = acpi_dev_get_first_match_dev("BST0001", NULL, -1);
1890 if (!adev)
1891 return -ENODEV;
1893 gsensor_handle = acpi_device_handle(adev);
1894 acpi_dev_put(adev);
1896 interface->capability |= ACER_CAP_ACCEL;
1898 acer_wmi_accel_dev = input_allocate_device();
1899 if (!acer_wmi_accel_dev)
1900 return -ENOMEM;
1902 acer_wmi_accel_dev->open = acer_gsensor_open;
1904 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1905 acer_wmi_accel_dev->phys = "wmi/input1";
1906 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1907 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1908 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1909 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1910 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1912 err = input_register_device(acer_wmi_accel_dev);
1913 if (err)
1914 goto err_free_dev;
1916 return 0;
1918 err_free_dev:
1919 input_free_device(acer_wmi_accel_dev);
1920 return err;
1923 static void acer_wmi_accel_destroy(void)
1925 input_unregister_device(acer_wmi_accel_dev);
1928 static int __init acer_wmi_input_setup(void)
1930 acpi_status status;
1931 int err;
1933 acer_wmi_input_dev = input_allocate_device();
1934 if (!acer_wmi_input_dev)
1935 return -ENOMEM;
1937 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1938 acer_wmi_input_dev->phys = "wmi/input0";
1939 acer_wmi_input_dev->id.bustype = BUS_HOST;
1941 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1942 if (err)
1943 goto err_free_dev;
1945 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1946 acer_wmi_notify, NULL);
1947 if (ACPI_FAILURE(status)) {
1948 err = -EIO;
1949 goto err_free_dev;
1952 err = input_register_device(acer_wmi_input_dev);
1953 if (err)
1954 goto err_uninstall_notifier;
1956 return 0;
1958 err_uninstall_notifier:
1959 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1960 err_free_dev:
1961 input_free_device(acer_wmi_input_dev);
1962 return err;
1965 static void acer_wmi_input_destroy(void)
1967 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1968 input_unregister_device(acer_wmi_input_dev);
1972 * debugfs functions
1974 static u32 get_wmid_devices(void)
1976 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1977 union acpi_object *obj;
1978 acpi_status status;
1979 u32 devices = 0;
1981 status = wmi_query_block(WMID_GUID2, 0, &out);
1982 if (ACPI_FAILURE(status))
1983 return 0;
1985 obj = (union acpi_object *) out.pointer;
1986 if (obj) {
1987 if (obj->type == ACPI_TYPE_BUFFER &&
1988 (obj->buffer.length == sizeof(u32) ||
1989 obj->buffer.length == sizeof(u64))) {
1990 devices = *((u32 *) obj->buffer.pointer);
1991 } else if (obj->type == ACPI_TYPE_INTEGER) {
1992 devices = (u32) obj->integer.value;
1996 kfree(out.pointer);
1997 return devices;
2001 * Platform device
2003 static int acer_platform_probe(struct platform_device *device)
2005 int err;
2007 if (has_cap(ACER_CAP_MAILLED)) {
2008 err = acer_led_init(&device->dev);
2009 if (err)
2010 goto error_mailled;
2013 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2014 err = acer_backlight_init(&device->dev);
2015 if (err)
2016 goto error_brightness;
2019 err = acer_rfkill_init(&device->dev);
2020 if (err)
2021 goto error_rfkill;
2023 return err;
2025 error_rfkill:
2026 if (has_cap(ACER_CAP_BRIGHTNESS))
2027 acer_backlight_exit();
2028 error_brightness:
2029 if (has_cap(ACER_CAP_MAILLED))
2030 acer_led_exit();
2031 error_mailled:
2032 return err;
2035 static int acer_platform_remove(struct platform_device *device)
2037 if (has_cap(ACER_CAP_MAILLED))
2038 acer_led_exit();
2039 if (has_cap(ACER_CAP_BRIGHTNESS))
2040 acer_backlight_exit();
2042 acer_rfkill_exit();
2043 return 0;
2046 #ifdef CONFIG_PM_SLEEP
2047 static int acer_suspend(struct device *dev)
2049 u32 value;
2050 struct acer_data *data = &interface->data;
2052 if (!data)
2053 return -ENOMEM;
2055 if (has_cap(ACER_CAP_MAILLED)) {
2056 get_u32(&value, ACER_CAP_MAILLED);
2057 set_u32(LED_OFF, ACER_CAP_MAILLED);
2058 data->mailled = value;
2061 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2062 get_u32(&value, ACER_CAP_BRIGHTNESS);
2063 data->brightness = value;
2066 return 0;
2069 static int acer_resume(struct device *dev)
2071 struct acer_data *data = &interface->data;
2073 if (!data)
2074 return -ENOMEM;
2076 if (has_cap(ACER_CAP_MAILLED))
2077 set_u32(data->mailled, ACER_CAP_MAILLED);
2079 if (has_cap(ACER_CAP_BRIGHTNESS))
2080 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2082 if (has_cap(ACER_CAP_ACCEL))
2083 acer_gsensor_init();
2085 return 0;
2087 #else
2088 #define acer_suspend NULL
2089 #define acer_resume NULL
2090 #endif
2092 static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2094 static void acer_platform_shutdown(struct platform_device *device)
2096 struct acer_data *data = &interface->data;
2098 if (!data)
2099 return;
2101 if (has_cap(ACER_CAP_MAILLED))
2102 set_u32(LED_OFF, ACER_CAP_MAILLED);
2105 static struct platform_driver acer_platform_driver = {
2106 .driver = {
2107 .name = "acer-wmi",
2108 .pm = &acer_pm,
2110 .probe = acer_platform_probe,
2111 .remove = acer_platform_remove,
2112 .shutdown = acer_platform_shutdown,
2115 static struct platform_device *acer_platform_device;
2117 static void remove_debugfs(void)
2119 debugfs_remove_recursive(interface->debug.root);
2122 static void __init create_debugfs(void)
2124 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2126 debugfs_create_u32("devices", S_IRUGO, interface->debug.root,
2127 &interface->debug.wmid_devices);
2130 static int __init acer_wmi_init(void)
2132 int err;
2134 pr_info("Acer Laptop ACPI-WMI Extras\n");
2136 if (dmi_check_system(acer_blacklist)) {
2137 pr_info("Blacklisted hardware detected - not loading\n");
2138 return -ENODEV;
2141 find_quirks();
2144 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2145 * machines like Lenovo, Fujitsu and Medion. In the past days,
2146 * acer-wmi driver handled those non-Acer machines by quirks list.
2147 * But actually acer-wmi driver was loaded on any machines that have
2148 * AMW0_GUID1. This behavior is strange because those machines should
2149 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2150 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2151 * should be in Acer/Gateway/Packard Bell white list, or it's already
2152 * in the past quirk list.
2154 if (wmi_has_guid(AMW0_GUID1) &&
2155 !dmi_check_system(amw0_whitelist) &&
2156 quirks == &quirk_unknown) {
2157 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
2158 return -ENODEV;
2162 * Detect which ACPI-WMI interface we're using.
2164 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2165 interface = &AMW0_V2_interface;
2167 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2168 interface = &wmid_interface;
2170 if (wmi_has_guid(WMID_GUID3))
2171 interface = &wmid_v2_interface;
2173 if (interface)
2174 dmi_walk(type_aa_dmi_decode, NULL);
2176 if (wmi_has_guid(WMID_GUID2) && interface) {
2177 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
2178 pr_err("Unable to detect available WMID devices\n");
2179 return -ENODEV;
2181 /* WMID always provides brightness methods */
2182 interface->capability |= ACER_CAP_BRIGHTNESS;
2183 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
2184 pr_err("No WMID device detection method found\n");
2185 return -ENODEV;
2188 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2189 interface = &AMW0_interface;
2191 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2192 pr_err("Unable to detect available AMW0 devices\n");
2193 return -ENODEV;
2197 if (wmi_has_guid(AMW0_GUID1))
2198 AMW0_find_mailled();
2200 if (!interface) {
2201 pr_err("No or unsupported WMI interface, unable to load\n");
2202 return -ENODEV;
2205 set_quirks();
2207 if (dmi_check_system(video_vendor_dmi_table))
2208 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2210 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2211 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2213 if (wmi_has_guid(WMID_GUID3)) {
2214 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2215 pr_warn("Cannot enable RF Button Driver\n");
2217 if (ec_raw_mode) {
2218 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2219 pr_err("Cannot enable EC raw mode\n");
2220 return -ENODEV;
2222 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2223 pr_err("Cannot enable Launch Manager mode\n");
2224 return -ENODEV;
2226 } else if (ec_raw_mode) {
2227 pr_info("No WMID EC raw mode enable method\n");
2230 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2231 err = acer_wmi_input_setup();
2232 if (err)
2233 return err;
2234 err = acer_wmi_accel_setup();
2235 if (err && err != -ENODEV)
2236 pr_warn("Cannot enable accelerometer\n");
2239 err = platform_driver_register(&acer_platform_driver);
2240 if (err) {
2241 pr_err("Unable to register platform driver\n");
2242 goto error_platform_register;
2245 acer_platform_device = platform_device_alloc("acer-wmi", -1);
2246 if (!acer_platform_device) {
2247 err = -ENOMEM;
2248 goto error_device_alloc;
2251 err = platform_device_add(acer_platform_device);
2252 if (err)
2253 goto error_device_add;
2255 if (wmi_has_guid(WMID_GUID2)) {
2256 interface->debug.wmid_devices = get_wmid_devices();
2257 create_debugfs();
2260 /* Override any initial settings with values from the commandline */
2261 acer_commandline_init();
2263 return 0;
2265 error_device_add:
2266 platform_device_put(acer_platform_device);
2267 error_device_alloc:
2268 platform_driver_unregister(&acer_platform_driver);
2269 error_platform_register:
2270 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2271 acer_wmi_input_destroy();
2272 if (has_cap(ACER_CAP_ACCEL))
2273 acer_wmi_accel_destroy();
2275 return err;
2278 static void __exit acer_wmi_exit(void)
2280 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2281 acer_wmi_input_destroy();
2283 if (has_cap(ACER_CAP_ACCEL))
2284 acer_wmi_accel_destroy();
2286 remove_debugfs();
2287 platform_device_unregister(acer_platform_device);
2288 platform_driver_unregister(&acer_platform_driver);
2290 pr_info("Acer Laptop WMI Extras unloaded\n");
2291 return;
2294 module_init(acer_wmi_init);
2295 module_exit(acer_wmi_exit);