2 * Acer WMI Laptop Extras
4 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
7 * Copyright (C) 2005-2007 E.M. Smith
8 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/dmi.h>
33 #include <linux/backlight.h>
34 #include <linux/leds.h>
35 #include <linux/platform_device.h>
36 #include <linux/acpi.h>
37 #include <linux/i8042.h>
38 #include <linux/rfkill.h>
39 #include <linux/workqueue.h>
40 #include <linux/debugfs.h>
41 #include <linux/slab.h>
42 #include <linux/input.h>
43 #include <linux/input/sparse-keymap.h>
45 #include <acpi/acpi_drivers.h>
46 #include <acpi/video.h>
48 MODULE_AUTHOR("Carlos Corbacho");
49 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
50 MODULE_LICENSE("GPL");
54 * Meaning is unknown - this number is required for writing to ACPI for AMW0
55 * (it's also used in acerhk when directly accessing the BIOS)
57 #define ACER_AMW0_WRITE 0x9610
60 * Bit masks for the AMW0 interface
62 #define ACER_AMW0_WIRELESS_MASK 0x35
63 #define ACER_AMW0_BLUETOOTH_MASK 0x34
64 #define ACER_AMW0_MAILLED_MASK 0x31
67 * Method IDs for WMID interface
69 #define ACER_WMID_GET_WIRELESS_METHODID 1
70 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
71 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
72 #define ACER_WMID_SET_WIRELESS_METHODID 4
73 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
74 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
75 #define ACER_WMID_GET_THREEG_METHODID 10
76 #define ACER_WMID_SET_THREEG_METHODID 11
79 * Acer ACPI method GUIDs
81 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
82 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
83 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
84 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
85 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
88 * Acer ACPI event GUIDs
90 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
92 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
93 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
94 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
96 enum acer_wmi_event_ids {
97 WMID_HOTKEY_EVENT = 0x1,
98 WMID_ACCEL_EVENT = 0x5,
101 static const struct key_entry acer_wmi_keymap[] = {
102 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
103 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
104 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
105 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
106 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
107 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
108 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
109 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
110 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */
111 {KE_IGNORE, 0x41, {KEY_MUTE} },
112 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
113 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
114 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
115 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
116 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
117 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
118 {KE_IGNORE, 0x45, {KEY_STOP} },
119 {KE_IGNORE, 0x50, {KEY_STOP} },
120 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
121 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
122 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
123 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
124 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
125 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
126 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
127 {KE_IGNORE, 0x81, {KEY_SLEEP} },
128 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */
129 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
130 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
131 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
132 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
136 static struct input_dev *acer_wmi_input_dev;
137 static struct input_dev *acer_wmi_accel_dev;
139 struct event_return_value {
144 } __attribute__((packed));
147 * GUID3 Get Device Status device flags
149 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
150 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
151 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
152 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
153 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
155 struct lm_input_params {
156 u8 function_num; /* Function Number */
157 u16 commun_devices; /* Communication type devices default status */
158 u16 devices; /* Other type devices default status */
159 u8 lm_status; /* Launch Manager Status */
161 } __attribute__((packed));
163 struct lm_return_value {
164 u8 error_code; /* Error Code */
165 u8 ec_return_value; /* EC Return Value */
167 } __attribute__((packed));
169 struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
170 u8 function_num; /* Function Number */
171 u8 hotkey_number; /* Hotkey Number */
172 u16 devices; /* Set Device */
173 u8 volume_value; /* Volume Value */
174 } __attribute__((packed));
176 struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
177 u8 function_num; /* Function Number */
178 u8 hotkey_number; /* Hotkey Number */
179 u16 devices; /* Get Device */
180 } __attribute__((packed));
182 struct wmid3_gds_return_value { /* Get Device Status return value*/
183 u8 error_code; /* Error Code */
184 u8 ec_return_value; /* EC Return Value */
185 u16 devices; /* Current Device Status */
187 } __attribute__((packed));
189 struct hotkey_function_type_aa {
193 u16 commun_func_bitmap;
194 u16 application_func_bitmap;
195 u16 media_func_bitmap;
196 u16 display_func_bitmap;
197 u16 others_func_bitmap;
198 u8 commun_fn_key_number;
199 } __attribute__((packed));
202 * Interface capability flags
204 #define ACER_CAP_MAILLED (1<<0)
205 #define ACER_CAP_WIRELESS (1<<1)
206 #define ACER_CAP_BLUETOOTH (1<<2)
207 #define ACER_CAP_BRIGHTNESS (1<<3)
208 #define ACER_CAP_THREEG (1<<4)
209 #define ACER_CAP_ACCEL (1<<5)
210 #define ACER_CAP_ANY (0xFFFFFFFF)
213 * Interface type flags
215 enum interface_flags {
222 #define ACER_DEFAULT_WIRELESS 0
223 #define ACER_DEFAULT_BLUETOOTH 0
224 #define ACER_DEFAULT_MAILLED 0
225 #define ACER_DEFAULT_THREEG 0
227 static int max_brightness = 0xF;
229 static int mailled = -1;
230 static int brightness = -1;
231 static int threeg = -1;
232 static int force_series;
233 static bool ec_raw_mode;
234 static bool has_type_aa;
235 static u16 commun_func_bitmap;
236 static u8 commun_fn_key_number;
238 module_param(mailled, int, 0444);
239 module_param(brightness, int, 0444);
240 module_param(threeg, int, 0444);
241 module_param(force_series, int, 0444);
242 module_param(ec_raw_mode, bool, 0444);
243 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
244 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
245 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
246 MODULE_PARM_DESC(force_series, "Force a different laptop series");
247 MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
257 struct dentry *devices;
261 static struct rfkill *wireless_rfkill;
262 static struct rfkill *bluetooth_rfkill;
263 static struct rfkill *threeg_rfkill;
264 static bool rfkill_inited;
266 /* Each low-level interface must define at least some of the following */
267 struct wmi_interface {
268 /* The WMI device type */
271 /* The capabilities this interface provides */
274 /* Private data for the current interface */
275 struct acer_data data;
277 /* debugfs entries associated with this interface */
278 struct acer_debug debug;
281 /* The static interface pointer, points to the currently detected interface */
282 static struct wmi_interface *interface;
285 * Embedded Controller quirks
286 * Some laptops require us to directly access the EC to either enable or query
287 * features that are not available through WMI.
297 static struct quirk_entry *quirks;
299 static void set_quirks(void)
305 interface->capability |= ACER_CAP_MAILLED;
307 if (quirks->brightness)
308 interface->capability |= ACER_CAP_BRIGHTNESS;
311 static int dmi_matched(const struct dmi_system_id *dmi)
313 quirks = dmi->driver_data;
317 static struct quirk_entry quirk_unknown = {
320 static struct quirk_entry quirk_acer_aspire_1520 = {
324 static struct quirk_entry quirk_acer_travelmate_2490 = {
328 /* This AMW0 laptop has no bluetooth */
329 static struct quirk_entry quirk_medion_md_98300 = {
333 static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
337 static struct quirk_entry quirk_lenovo_ideapad_s205 = {
341 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
342 static struct dmi_system_id acer_blacklist[] = {
344 .ident = "Acer Aspire One (SSD)",
346 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
347 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
351 .ident = "Acer Aspire One (HDD)",
353 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
354 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
360 static struct dmi_system_id acer_quirks[] = {
362 .callback = dmi_matched,
363 .ident = "Acer Aspire 1360",
365 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
366 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
368 .driver_data = &quirk_acer_aspire_1520,
371 .callback = dmi_matched,
372 .ident = "Acer Aspire 1520",
374 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
375 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
377 .driver_data = &quirk_acer_aspire_1520,
380 .callback = dmi_matched,
381 .ident = "Acer Aspire 3100",
383 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
384 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
386 .driver_data = &quirk_acer_travelmate_2490,
389 .callback = dmi_matched,
390 .ident = "Acer Aspire 3610",
392 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
393 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
395 .driver_data = &quirk_acer_travelmate_2490,
398 .callback = dmi_matched,
399 .ident = "Acer Aspire 5100",
401 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
402 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
404 .driver_data = &quirk_acer_travelmate_2490,
407 .callback = dmi_matched,
408 .ident = "Acer Aspire 5610",
410 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
411 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
413 .driver_data = &quirk_acer_travelmate_2490,
416 .callback = dmi_matched,
417 .ident = "Acer Aspire 5630",
419 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
420 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
422 .driver_data = &quirk_acer_travelmate_2490,
425 .callback = dmi_matched,
426 .ident = "Acer Aspire 5650",
428 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
431 .driver_data = &quirk_acer_travelmate_2490,
434 .callback = dmi_matched,
435 .ident = "Acer Aspire 5680",
437 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
440 .driver_data = &quirk_acer_travelmate_2490,
443 .callback = dmi_matched,
444 .ident = "Acer Aspire 9110",
446 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
447 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
449 .driver_data = &quirk_acer_travelmate_2490,
452 .callback = dmi_matched,
453 .ident = "Acer TravelMate 2490",
455 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
456 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
458 .driver_data = &quirk_acer_travelmate_2490,
461 .callback = dmi_matched,
462 .ident = "Acer TravelMate 4200",
464 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
465 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
467 .driver_data = &quirk_acer_travelmate_2490,
470 .callback = dmi_matched,
471 .ident = "Fujitsu Siemens Amilo Li 1718",
473 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
474 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
476 .driver_data = &quirk_fujitsu_amilo_li_1718,
479 .callback = dmi_matched,
480 .ident = "Medion MD 98300",
482 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
483 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
485 .driver_data = &quirk_medion_md_98300,
488 .callback = dmi_matched,
489 .ident = "Lenovo Ideapad S205",
491 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
492 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
494 .driver_data = &quirk_lenovo_ideapad_s205,
497 .callback = dmi_matched,
498 .ident = "Lenovo Ideapad S205 (Brazos)",
500 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
501 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
503 .driver_data = &quirk_lenovo_ideapad_s205,
506 .callback = dmi_matched,
507 .ident = "Lenovo 3000 N200",
509 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
510 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
512 .driver_data = &quirk_fujitsu_amilo_li_1718,
515 .callback = dmi_matched,
516 .ident = "Lenovo Ideapad S205-10382JG",
518 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
519 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
521 .driver_data = &quirk_lenovo_ideapad_s205,
524 .callback = dmi_matched,
525 .ident = "Lenovo Ideapad S205-1038DPG",
527 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
528 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
530 .driver_data = &quirk_lenovo_ideapad_s205,
535 static int video_set_backlight_video_vendor(const struct dmi_system_id *d)
537 interface->capability &= ~ACER_CAP_BRIGHTNESS;
538 pr_info("Brightness must be controlled by generic video driver\n");
542 static const struct dmi_system_id video_vendor_dmi_table[] = {
544 .callback = video_set_backlight_video_vendor,
545 .ident = "Acer TravelMate 4750",
547 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
548 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
552 .callback = video_set_backlight_video_vendor,
553 .ident = "Acer Extensa 5235",
555 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
556 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
560 .callback = video_set_backlight_video_vendor,
561 .ident = "Acer TravelMate 5760",
563 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
564 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
568 .callback = video_set_backlight_video_vendor,
569 .ident = "Acer Aspire 5750",
571 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
572 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
578 /* Find which quirks are needed for a particular vendor/ model pair */
579 static void find_quirks(void)
582 dmi_check_system(acer_quirks);
583 } else if (force_series == 2490) {
584 quirks = &quirk_acer_travelmate_2490;
588 quirks = &quirk_unknown;
594 * General interface convenience methods
597 static bool has_cap(u32 cap)
599 if ((interface->capability & cap) != 0)
606 * AMW0 (V1) interface
623 static acpi_status wmab_execute(struct wmab_args *regbuf,
624 struct acpi_buffer *result)
626 struct acpi_buffer input;
628 input.length = sizeof(struct wmab_args);
629 input.pointer = (u8 *)regbuf;
631 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
636 static acpi_status AMW0_get_u32(u32 *value, u32 cap)
642 case ACER_CAP_MAILLED:
643 switch (quirks->mailled) {
645 err = ec_read(0xA, &result);
648 *value = (result >> 7) & 0x1;
652 case ACER_CAP_WIRELESS:
653 switch (quirks->wireless) {
655 err = ec_read(0x7B, &result);
658 *value = result & 0x1;
661 err = ec_read(0x71, &result);
664 *value = result & 0x1;
667 err = ec_read(0x78, &result);
670 *value = result & 0x1;
673 err = ec_read(0xA, &result);
676 *value = (result >> 2) & 0x1;
680 case ACER_CAP_BLUETOOTH:
681 switch (quirks->bluetooth) {
683 err = ec_read(0xA, &result);
686 *value = (result >> 4) & 0x1;
690 case ACER_CAP_BRIGHTNESS:
691 switch (quirks->brightness) {
693 err = ec_read(0x83, &result);
706 static acpi_status AMW0_set_u32(u32 value, u32 cap)
708 struct wmab_args args;
710 args.eax = ACER_AMW0_WRITE;
711 args.ebx = value ? (1<<8) : 0;
712 args.ecx = args.edx = 0;
715 case ACER_CAP_MAILLED:
717 return AE_BAD_PARAMETER;
718 args.ebx |= ACER_AMW0_MAILLED_MASK;
720 case ACER_CAP_WIRELESS:
722 return AE_BAD_PARAMETER;
723 args.ebx |= ACER_AMW0_WIRELESS_MASK;
725 case ACER_CAP_BLUETOOTH:
727 return AE_BAD_PARAMETER;
728 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
730 case ACER_CAP_BRIGHTNESS:
731 if (value > max_brightness)
732 return AE_BAD_PARAMETER;
733 switch (quirks->brightness) {
735 return ec_write(0x83, value);
742 /* Actually do the set */
743 return wmab_execute(&args, NULL);
746 static acpi_status AMW0_find_mailled(void)
748 struct wmab_args args;
750 acpi_status status = AE_OK;
751 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
752 union acpi_object *obj;
755 args.ebx = args.ecx = args.edx = 0;
757 status = wmab_execute(&args, &out);
758 if (ACPI_FAILURE(status))
761 obj = (union acpi_object *) out.pointer;
762 if (obj && obj->type == ACPI_TYPE_BUFFER &&
763 obj->buffer.length == sizeof(struct wmab_ret)) {
764 ret = *((struct wmab_ret *) obj->buffer.pointer);
771 interface->capability |= ACER_CAP_MAILLED;
778 static int AMW0_set_cap_acpi_check_device_found;
780 static acpi_status AMW0_set_cap_acpi_check_device_cb(acpi_handle handle,
781 u32 level, void *context, void **retval)
783 AMW0_set_cap_acpi_check_device_found = 1;
787 static const struct acpi_device_id norfkill_ids[] = {
791 { "SNY5001", 0}, /* sony-laptop in charge */
795 static int AMW0_set_cap_acpi_check_device(void)
797 const struct acpi_device_id *id;
799 for (id = norfkill_ids; id->id[0]; id++)
800 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb,
802 return AMW0_set_cap_acpi_check_device_found;
805 static acpi_status AMW0_set_capabilities(void)
807 struct wmab_args args;
810 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
811 union acpi_object *obj;
814 * On laptops with this strange GUID (non Acer), normal probing doesn't
817 if (wmi_has_guid(AMW0_GUID2)) {
818 if ((quirks != &quirk_unknown) ||
819 !AMW0_set_cap_acpi_check_device())
820 interface->capability |= ACER_CAP_WIRELESS;
824 args.eax = ACER_AMW0_WRITE;
825 args.ecx = args.edx = 0;
827 args.ebx = 0xa2 << 8;
828 args.ebx |= ACER_AMW0_WIRELESS_MASK;
830 status = wmab_execute(&args, &out);
831 if (ACPI_FAILURE(status))
835 if (obj && obj->type == ACPI_TYPE_BUFFER &&
836 obj->buffer.length == sizeof(struct wmab_ret)) {
837 ret = *((struct wmab_ret *) obj->buffer.pointer);
844 interface->capability |= ACER_CAP_WIRELESS;
847 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
850 * It's ok to use existing buffer for next wmab_execute call.
851 * But we need to kfree(out.pointer) if next wmab_execute fail.
853 status = wmab_execute(&args, &out);
854 if (ACPI_FAILURE(status))
857 obj = (union acpi_object *) out.pointer;
858 if (obj && obj->type == ACPI_TYPE_BUFFER
859 && obj->buffer.length == sizeof(struct wmab_ret)) {
860 ret = *((struct wmab_ret *) obj->buffer.pointer);
867 interface->capability |= ACER_CAP_BLUETOOTH;
870 * This appears to be safe to enable, since all Wistron based laptops
871 * appear to use the same EC register for brightness, even if they
872 * differ for wireless, etc
874 if (quirks->brightness >= 0)
875 interface->capability |= ACER_CAP_BRIGHTNESS;
883 static struct wmi_interface AMW0_interface = {
887 static struct wmi_interface AMW0_V2_interface = {
888 .type = ACER_AMW0_V2,
892 * New interface (The WMID interface)
895 WMI_execute_u32(u32 method_id, u32 in, u32 *out)
897 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
898 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
899 union acpi_object *obj;
903 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
905 if (ACPI_FAILURE(status))
908 obj = (union acpi_object *) result.pointer;
910 if (obj->type == ACPI_TYPE_BUFFER &&
911 (obj->buffer.length == sizeof(u32) ||
912 obj->buffer.length == sizeof(u64))) {
913 tmp = *((u32 *) obj->buffer.pointer);
914 } else if (obj->type == ACPI_TYPE_INTEGER) {
915 tmp = (u32) obj->integer.value;
922 kfree(result.pointer);
927 static acpi_status WMID_get_u32(u32 *value, u32 cap)
931 u32 result, method_id = 0;
934 case ACER_CAP_WIRELESS:
935 method_id = ACER_WMID_GET_WIRELESS_METHODID;
937 case ACER_CAP_BLUETOOTH:
938 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
940 case ACER_CAP_BRIGHTNESS:
941 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
943 case ACER_CAP_THREEG:
944 method_id = ACER_WMID_GET_THREEG_METHODID;
946 case ACER_CAP_MAILLED:
947 if (quirks->mailled == 1) {
955 status = WMI_execute_u32(method_id, 0, &result);
957 if (ACPI_SUCCESS(status))
963 static acpi_status WMID_set_u32(u32 value, u32 cap)
969 case ACER_CAP_BRIGHTNESS:
970 if (value > max_brightness)
971 return AE_BAD_PARAMETER;
972 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
974 case ACER_CAP_WIRELESS:
976 return AE_BAD_PARAMETER;
977 method_id = ACER_WMID_SET_WIRELESS_METHODID;
979 case ACER_CAP_BLUETOOTH:
981 return AE_BAD_PARAMETER;
982 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
984 case ACER_CAP_THREEG:
986 return AE_BAD_PARAMETER;
987 method_id = ACER_WMID_SET_THREEG_METHODID;
989 case ACER_CAP_MAILLED:
991 return AE_BAD_PARAMETER;
992 if (quirks->mailled == 1) {
993 param = value ? 0x92 : 0x93;
995 i8042_command(¶m, 0x1059);
1003 return WMI_execute_u32(method_id, (u32)value, NULL);
1006 static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1008 struct wmid3_gds_return_value return_value;
1010 union acpi_object *obj;
1011 struct wmid3_gds_get_input_param params = {
1012 .function_num = 0x1,
1013 .hotkey_number = commun_fn_key_number,
1016 struct acpi_buffer input = {
1017 sizeof(struct wmid3_gds_get_input_param),
1020 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1022 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1023 if (ACPI_FAILURE(status))
1026 obj = output.pointer;
1030 else if (obj->type != ACPI_TYPE_BUFFER) {
1034 if (obj->buffer.length != 8) {
1035 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1040 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1043 if (return_value.error_code || return_value.ec_return_value)
1044 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1046 return_value.error_code,
1047 return_value.ec_return_value);
1049 *value = !!(return_value.devices & device);
1054 static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1059 case ACER_CAP_WIRELESS:
1060 device = ACER_WMID3_GDS_WIRELESS;
1062 case ACER_CAP_BLUETOOTH:
1063 device = ACER_WMID3_GDS_BLUETOOTH;
1065 case ACER_CAP_THREEG:
1066 device = ACER_WMID3_GDS_THREEG;
1071 return wmid3_get_device_status(value, device);
1074 static acpi_status wmid3_set_device_status(u32 value, u16 device)
1076 struct wmid3_gds_return_value return_value;
1078 union acpi_object *obj;
1080 struct wmid3_gds_get_input_param get_params = {
1081 .function_num = 0x1,
1082 .hotkey_number = commun_fn_key_number,
1083 .devices = commun_func_bitmap,
1085 struct acpi_buffer get_input = {
1086 sizeof(struct wmid3_gds_get_input_param),
1089 struct wmid3_gds_set_input_param set_params = {
1090 .function_num = 0x2,
1091 .hotkey_number = commun_fn_key_number,
1092 .devices = commun_func_bitmap,
1094 struct acpi_buffer set_input = {
1095 sizeof(struct wmid3_gds_set_input_param),
1098 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1099 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1101 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
1102 if (ACPI_FAILURE(status))
1105 obj = output.pointer;
1109 else if (obj->type != ACPI_TYPE_BUFFER) {
1113 if (obj->buffer.length != 8) {
1114 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1119 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1122 if (return_value.error_code || return_value.ec_return_value) {
1123 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1124 return_value.error_code,
1125 return_value.ec_return_value);
1129 devices = return_value.devices;
1130 set_params.devices = (value) ? (devices | device) : (devices & ~device);
1132 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
1133 if (ACPI_FAILURE(status))
1136 obj = output2.pointer;
1140 else if (obj->type != ACPI_TYPE_BUFFER) {
1144 if (obj->buffer.length != 4) {
1145 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1150 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1153 if (return_value.error_code || return_value.ec_return_value)
1154 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1155 return_value.error_code,
1156 return_value.ec_return_value);
1161 static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1166 case ACER_CAP_WIRELESS:
1167 device = ACER_WMID3_GDS_WIRELESS;
1169 case ACER_CAP_BLUETOOTH:
1170 device = ACER_WMID3_GDS_BLUETOOTH;
1172 case ACER_CAP_THREEG:
1173 device = ACER_WMID3_GDS_THREEG;
1178 return wmid3_set_device_status(value, device);
1181 static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1183 struct hotkey_function_type_aa *type_aa;
1185 /* We are looking for OEM-specific Type AAh */
1186 if (header->type != 0xAA)
1190 type_aa = (struct hotkey_function_type_aa *) header;
1192 pr_info("Function bitmap for Communication Button: 0x%x\n",
1193 type_aa->commun_func_bitmap);
1194 commun_func_bitmap = type_aa->commun_func_bitmap;
1196 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1197 interface->capability |= ACER_CAP_WIRELESS;
1198 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1199 interface->capability |= ACER_CAP_THREEG;
1200 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1201 interface->capability |= ACER_CAP_BLUETOOTH;
1203 commun_fn_key_number = type_aa->commun_fn_key_number;
1206 static acpi_status WMID_set_capabilities(void)
1208 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1209 union acpi_object *obj;
1213 status = wmi_query_block(WMID_GUID2, 1, &out);
1214 if (ACPI_FAILURE(status))
1217 obj = (union acpi_object *) out.pointer;
1219 if (obj->type == ACPI_TYPE_BUFFER &&
1220 (obj->buffer.length == sizeof(u32) ||
1221 obj->buffer.length == sizeof(u64))) {
1222 devices = *((u32 *) obj->buffer.pointer);
1223 } else if (obj->type == ACPI_TYPE_INTEGER) {
1224 devices = (u32) obj->integer.value;
1231 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1233 interface->capability |= ACER_CAP_WIRELESS;
1235 interface->capability |= ACER_CAP_THREEG;
1237 interface->capability |= ACER_CAP_BLUETOOTH;
1239 if (!(devices & 0x20))
1240 max_brightness = 0x9;
1246 static struct wmi_interface wmid_interface = {
1250 static struct wmi_interface wmid_v2_interface = {
1251 .type = ACER_WMID_v2,
1255 * Generic Device (interface-independent)
1258 static acpi_status get_u32(u32 *value, u32 cap)
1260 acpi_status status = AE_ERROR;
1262 switch (interface->type) {
1264 status = AMW0_get_u32(value, cap);
1267 if (cap == ACER_CAP_MAILLED) {
1268 status = AMW0_get_u32(value, cap);
1272 status = WMID_get_u32(value, cap);
1275 if (cap & (ACER_CAP_WIRELESS |
1276 ACER_CAP_BLUETOOTH |
1278 status = wmid_v2_get_u32(value, cap);
1279 else if (wmi_has_guid(WMID_GUID2))
1280 status = WMID_get_u32(value, cap);
1287 static acpi_status set_u32(u32 value, u32 cap)
1291 if (interface->capability & cap) {
1292 switch (interface->type) {
1294 return AMW0_set_u32(value, cap);
1296 if (cap == ACER_CAP_MAILLED)
1297 return AMW0_set_u32(value, cap);
1300 * On some models, some WMID methods don't toggle
1301 * properly. For those cases, we want to run the AMW0
1302 * method afterwards to be certain we've really toggled
1305 if (cap == ACER_CAP_WIRELESS ||
1306 cap == ACER_CAP_BLUETOOTH) {
1307 status = WMID_set_u32(value, cap);
1308 if (ACPI_FAILURE(status))
1311 return AMW0_set_u32(value, cap);
1314 return WMID_set_u32(value, cap);
1316 if (cap & (ACER_CAP_WIRELESS |
1317 ACER_CAP_BLUETOOTH |
1319 return wmid_v2_set_u32(value, cap);
1320 else if (wmi_has_guid(WMID_GUID2))
1321 return WMID_set_u32(value, cap);
1323 return AE_BAD_PARAMETER;
1326 return AE_BAD_PARAMETER;
1329 static void __init acer_commandline_init(void)
1332 * These will all fail silently if the value given is invalid, or the
1333 * capability isn't available on the given interface
1336 set_u32(mailled, ACER_CAP_MAILLED);
1337 if (!has_type_aa && threeg >= 0)
1338 set_u32(threeg, ACER_CAP_THREEG);
1339 if (brightness >= 0)
1340 set_u32(brightness, ACER_CAP_BRIGHTNESS);
1344 * LED device (Mail LED only, no other LEDs known yet)
1346 static void mail_led_set(struct led_classdev *led_cdev,
1347 enum led_brightness value)
1349 set_u32(value, ACER_CAP_MAILLED);
1352 static struct led_classdev mail_led = {
1353 .name = "acer-wmi::mail",
1354 .brightness_set = mail_led_set,
1357 static int acer_led_init(struct device *dev)
1359 return led_classdev_register(dev, &mail_led);
1362 static void acer_led_exit(void)
1364 set_u32(LED_OFF, ACER_CAP_MAILLED);
1365 led_classdev_unregister(&mail_led);
1371 static struct backlight_device *acer_backlight_device;
1373 static int read_brightness(struct backlight_device *bd)
1376 get_u32(&value, ACER_CAP_BRIGHTNESS);
1380 static int update_bl_status(struct backlight_device *bd)
1382 int intensity = bd->props.brightness;
1384 if (bd->props.power != FB_BLANK_UNBLANK)
1386 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1389 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1394 static const struct backlight_ops acer_bl_ops = {
1395 .get_brightness = read_brightness,
1396 .update_status = update_bl_status,
1399 static int acer_backlight_init(struct device *dev)
1401 struct backlight_properties props;
1402 struct backlight_device *bd;
1404 memset(&props, 0, sizeof(struct backlight_properties));
1405 props.type = BACKLIGHT_PLATFORM;
1406 props.max_brightness = max_brightness;
1407 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1410 pr_err("Could not register Acer backlight device\n");
1411 acer_backlight_device = NULL;
1415 acer_backlight_device = bd;
1417 bd->props.power = FB_BLANK_UNBLANK;
1418 bd->props.brightness = read_brightness(bd);
1419 backlight_update_status(bd);
1423 static void acer_backlight_exit(void)
1425 backlight_device_unregister(acer_backlight_device);
1429 * Accelerometer device
1431 static acpi_handle gsensor_handle;
1433 static int acer_gsensor_init(void)
1436 struct acpi_buffer output;
1437 union acpi_object out_obj;
1439 output.length = sizeof(out_obj);
1440 output.pointer = &out_obj;
1441 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1442 if (ACPI_FAILURE(status))
1448 static int acer_gsensor_open(struct input_dev *input)
1450 return acer_gsensor_init();
1453 static int acer_gsensor_event(void)
1456 struct acpi_buffer output;
1457 union acpi_object out_obj[5];
1459 if (!has_cap(ACER_CAP_ACCEL))
1462 output.length = sizeof(out_obj);
1463 output.pointer = out_obj;
1465 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1466 if (ACPI_FAILURE(status))
1469 if (out_obj->package.count != 4)
1472 input_report_abs(acer_wmi_accel_dev, ABS_X,
1473 (s16)out_obj->package.elements[0].integer.value);
1474 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1475 (s16)out_obj->package.elements[1].integer.value);
1476 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1477 (s16)out_obj->package.elements[2].integer.value);
1478 input_sync(acer_wmi_accel_dev);
1485 static void acer_rfkill_update(struct work_struct *ignored);
1486 static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1487 static void acer_rfkill_update(struct work_struct *ignored)
1492 if (has_cap(ACER_CAP_WIRELESS)) {
1493 status = get_u32(&state, ACER_CAP_WIRELESS);
1494 if (ACPI_SUCCESS(status)) {
1495 if (quirks->wireless == 3)
1496 rfkill_set_hw_state(wireless_rfkill, !state);
1498 rfkill_set_sw_state(wireless_rfkill, !state);
1502 if (has_cap(ACER_CAP_BLUETOOTH)) {
1503 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1504 if (ACPI_SUCCESS(status))
1505 rfkill_set_sw_state(bluetooth_rfkill, !state);
1508 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1509 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
1510 if (ACPI_SUCCESS(status))
1511 rfkill_set_sw_state(threeg_rfkill, !state);
1514 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1517 static int acer_rfkill_set(void *data, bool blocked)
1520 u32 cap = (unsigned long)data;
1522 if (rfkill_inited) {
1523 status = set_u32(!blocked, cap);
1524 if (ACPI_FAILURE(status))
1531 static const struct rfkill_ops acer_rfkill_ops = {
1532 .set_block = acer_rfkill_set,
1535 static struct rfkill *acer_rfkill_register(struct device *dev,
1536 enum rfkill_type type,
1537 char *name, u32 cap)
1540 struct rfkill *rfkill_dev;
1544 rfkill_dev = rfkill_alloc(name, dev, type,
1546 (void *)(unsigned long)cap);
1548 return ERR_PTR(-ENOMEM);
1550 status = get_u32(&state, cap);
1552 err = rfkill_register(rfkill_dev);
1554 rfkill_destroy(rfkill_dev);
1555 return ERR_PTR(err);
1558 if (ACPI_SUCCESS(status))
1559 rfkill_set_sw_state(rfkill_dev, !state);
1564 static int acer_rfkill_init(struct device *dev)
1568 if (has_cap(ACER_CAP_WIRELESS)) {
1569 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1570 "acer-wireless", ACER_CAP_WIRELESS);
1571 if (IS_ERR(wireless_rfkill)) {
1572 err = PTR_ERR(wireless_rfkill);
1573 goto error_wireless;
1577 if (has_cap(ACER_CAP_BLUETOOTH)) {
1578 bluetooth_rfkill = acer_rfkill_register(dev,
1579 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1580 ACER_CAP_BLUETOOTH);
1581 if (IS_ERR(bluetooth_rfkill)) {
1582 err = PTR_ERR(bluetooth_rfkill);
1583 goto error_bluetooth;
1587 if (has_cap(ACER_CAP_THREEG)) {
1588 threeg_rfkill = acer_rfkill_register(dev,
1589 RFKILL_TYPE_WWAN, "acer-threeg",
1591 if (IS_ERR(threeg_rfkill)) {
1592 err = PTR_ERR(threeg_rfkill);
1597 rfkill_inited = true;
1599 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1600 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1601 schedule_delayed_work(&acer_rfkill_work,
1602 round_jiffies_relative(HZ));
1607 if (has_cap(ACER_CAP_BLUETOOTH)) {
1608 rfkill_unregister(bluetooth_rfkill);
1609 rfkill_destroy(bluetooth_rfkill);
1612 if (has_cap(ACER_CAP_WIRELESS)) {
1613 rfkill_unregister(wireless_rfkill);
1614 rfkill_destroy(wireless_rfkill);
1620 static void acer_rfkill_exit(void)
1622 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1623 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1624 cancel_delayed_work_sync(&acer_rfkill_work);
1626 if (has_cap(ACER_CAP_WIRELESS)) {
1627 rfkill_unregister(wireless_rfkill);
1628 rfkill_destroy(wireless_rfkill);
1631 if (has_cap(ACER_CAP_BLUETOOTH)) {
1632 rfkill_unregister(bluetooth_rfkill);
1633 rfkill_destroy(bluetooth_rfkill);
1636 if (has_cap(ACER_CAP_THREEG)) {
1637 rfkill_unregister(threeg_rfkill);
1638 rfkill_destroy(threeg_rfkill);
1646 static ssize_t show_bool_threeg(struct device *dev,
1647 struct device_attribute *attr, char *buf)
1652 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1654 status = get_u32(&result, ACER_CAP_THREEG);
1655 if (ACPI_SUCCESS(status))
1656 return sprintf(buf, "%u\n", result);
1657 return sprintf(buf, "Read error\n");
1660 static ssize_t set_bool_threeg(struct device *dev,
1661 struct device_attribute *attr, const char *buf, size_t count)
1663 u32 tmp = simple_strtoul(buf, NULL, 10);
1664 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1665 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1667 if (ACPI_FAILURE(status))
1671 static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
1674 static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1677 pr_info("This interface sysfs will be removed in 2012 - used by: %s\n",
1679 switch (interface->type) {
1681 return sprintf(buf, "AMW0\n");
1683 return sprintf(buf, "AMW0 v2\n");
1685 return sprintf(buf, "WMID\n");
1687 return sprintf(buf, "WMID v2\n");
1689 return sprintf(buf, "Error!\n");
1693 static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
1695 static void acer_wmi_notify(u32 value, void *context)
1697 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1698 union acpi_object *obj;
1699 struct event_return_value return_value;
1702 const struct key_entry *key;
1705 status = wmi_get_event_data(value, &response);
1706 if (status != AE_OK) {
1707 pr_warn("bad event status 0x%x\n", status);
1711 obj = (union acpi_object *)response.pointer;
1715 if (obj->type != ACPI_TYPE_BUFFER) {
1716 pr_warn("Unknown response received %d\n", obj->type);
1720 if (obj->buffer.length != 8) {
1721 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1726 return_value = *((struct event_return_value *)obj->buffer.pointer);
1729 switch (return_value.function) {
1730 case WMID_HOTKEY_EVENT:
1731 device_state = return_value.device_state;
1732 pr_debug("device state: 0x%x\n", device_state);
1734 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1735 return_value.key_num);
1737 pr_warn("Unknown key number - 0x%x\n",
1738 return_value.key_num);
1740 scancode = return_value.key_num;
1741 switch (key->keycode) {
1744 if (has_cap(ACER_CAP_WIRELESS))
1745 rfkill_set_sw_state(wireless_rfkill,
1746 !(device_state & ACER_WMID3_GDS_WIRELESS));
1747 if (has_cap(ACER_CAP_THREEG))
1748 rfkill_set_sw_state(threeg_rfkill,
1749 !(device_state & ACER_WMID3_GDS_THREEG));
1750 if (has_cap(ACER_CAP_BLUETOOTH))
1751 rfkill_set_sw_state(bluetooth_rfkill,
1752 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1754 case KEY_TOUCHPAD_TOGGLE:
1755 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1756 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
1758 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
1761 case WMID_ACCEL_EVENT:
1762 acer_gsensor_event();
1765 pr_warn("Unknown function number - %d - %d\n",
1766 return_value.function, return_value.key_num);
1772 wmid3_set_lm_mode(struct lm_input_params *params,
1773 struct lm_return_value *return_value)
1776 union acpi_object *obj;
1778 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1779 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1781 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1782 if (ACPI_FAILURE(status))
1785 obj = output.pointer;
1789 else if (obj->type != ACPI_TYPE_BUFFER) {
1793 if (obj->buffer.length != 4) {
1794 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1799 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1805 static int acer_wmi_enable_ec_raw(void)
1807 struct lm_return_value return_value;
1809 struct lm_input_params params = {
1810 .function_num = 0x1,
1811 .commun_devices = 0xFFFF,
1813 .lm_status = 0x00, /* Launch Manager Deactive */
1816 status = wmid3_set_lm_mode(¶ms, &return_value);
1818 if (return_value.error_code || return_value.ec_return_value)
1819 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1820 return_value.error_code,
1821 return_value.ec_return_value);
1823 pr_info("Enabled EC raw mode\n");
1828 static int acer_wmi_enable_lm(void)
1830 struct lm_return_value return_value;
1832 struct lm_input_params params = {
1833 .function_num = 0x1,
1834 .commun_devices = 0xFFFF,
1836 .lm_status = 0x01, /* Launch Manager Active */
1839 status = wmid3_set_lm_mode(¶ms, &return_value);
1841 if (return_value.error_code || return_value.ec_return_value)
1842 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1843 return_value.error_code,
1844 return_value.ec_return_value);
1849 static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1850 void *ctx, void **retval)
1852 *(acpi_handle *)retval = ah;
1856 static int __init acer_wmi_get_handle(const char *name, const char *prop,
1862 BUG_ON(!name || !ah);
1865 status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1866 (void *)name, &handle);
1868 if (ACPI_SUCCESS(status)) {
1876 static int __init acer_wmi_accel_setup(void)
1880 err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle);
1884 interface->capability |= ACER_CAP_ACCEL;
1886 acer_wmi_accel_dev = input_allocate_device();
1887 if (!acer_wmi_accel_dev)
1890 acer_wmi_accel_dev->open = acer_gsensor_open;
1892 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1893 acer_wmi_accel_dev->phys = "wmi/input1";
1894 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1895 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1896 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1897 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1898 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1900 err = input_register_device(acer_wmi_accel_dev);
1907 input_free_device(acer_wmi_accel_dev);
1911 static void acer_wmi_accel_destroy(void)
1913 input_unregister_device(acer_wmi_accel_dev);
1916 static int __init acer_wmi_input_setup(void)
1921 acer_wmi_input_dev = input_allocate_device();
1922 if (!acer_wmi_input_dev)
1925 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1926 acer_wmi_input_dev->phys = "wmi/input0";
1927 acer_wmi_input_dev->id.bustype = BUS_HOST;
1929 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1933 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1934 acer_wmi_notify, NULL);
1935 if (ACPI_FAILURE(status)) {
1937 goto err_free_keymap;
1940 err = input_register_device(acer_wmi_input_dev);
1942 goto err_uninstall_notifier;
1946 err_uninstall_notifier:
1947 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1949 sparse_keymap_free(acer_wmi_input_dev);
1951 input_free_device(acer_wmi_input_dev);
1955 static void acer_wmi_input_destroy(void)
1957 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1958 sparse_keymap_free(acer_wmi_input_dev);
1959 input_unregister_device(acer_wmi_input_dev);
1965 static u32 get_wmid_devices(void)
1967 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1968 union acpi_object *obj;
1972 status = wmi_query_block(WMID_GUID2, 1, &out);
1973 if (ACPI_FAILURE(status))
1976 obj = (union acpi_object *) out.pointer;
1978 if (obj->type == ACPI_TYPE_BUFFER &&
1979 (obj->buffer.length == sizeof(u32) ||
1980 obj->buffer.length == sizeof(u64))) {
1981 devices = *((u32 *) obj->buffer.pointer);
1982 } else if (obj->type == ACPI_TYPE_INTEGER) {
1983 devices = (u32) obj->integer.value;
1994 static int acer_platform_probe(struct platform_device *device)
1998 if (has_cap(ACER_CAP_MAILLED)) {
1999 err = acer_led_init(&device->dev);
2004 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2005 err = acer_backlight_init(&device->dev);
2007 goto error_brightness;
2010 err = acer_rfkill_init(&device->dev);
2017 if (has_cap(ACER_CAP_BRIGHTNESS))
2018 acer_backlight_exit();
2020 if (has_cap(ACER_CAP_MAILLED))
2026 static int acer_platform_remove(struct platform_device *device)
2028 if (has_cap(ACER_CAP_MAILLED))
2030 if (has_cap(ACER_CAP_BRIGHTNESS))
2031 acer_backlight_exit();
2037 static int acer_suspend(struct device *dev)
2040 struct acer_data *data = &interface->data;
2045 if (has_cap(ACER_CAP_MAILLED)) {
2046 get_u32(&value, ACER_CAP_MAILLED);
2047 set_u32(LED_OFF, ACER_CAP_MAILLED);
2048 data->mailled = value;
2051 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2052 get_u32(&value, ACER_CAP_BRIGHTNESS);
2053 data->brightness = value;
2059 static int acer_resume(struct device *dev)
2061 struct acer_data *data = &interface->data;
2066 if (has_cap(ACER_CAP_MAILLED))
2067 set_u32(data->mailled, ACER_CAP_MAILLED);
2069 if (has_cap(ACER_CAP_BRIGHTNESS))
2070 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2072 if (has_cap(ACER_CAP_ACCEL))
2073 acer_gsensor_init();
2078 static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2080 static void acer_platform_shutdown(struct platform_device *device)
2082 struct acer_data *data = &interface->data;
2087 if (has_cap(ACER_CAP_MAILLED))
2088 set_u32(LED_OFF, ACER_CAP_MAILLED);
2091 static struct platform_driver acer_platform_driver = {
2094 .owner = THIS_MODULE,
2097 .probe = acer_platform_probe,
2098 .remove = acer_platform_remove,
2099 .shutdown = acer_platform_shutdown,
2102 static struct platform_device *acer_platform_device;
2104 static int remove_sysfs(struct platform_device *device)
2106 if (has_cap(ACER_CAP_THREEG))
2107 device_remove_file(&device->dev, &dev_attr_threeg);
2109 device_remove_file(&device->dev, &dev_attr_interface);
2114 static int create_sysfs(void)
2116 int retval = -ENOMEM;
2118 if (has_cap(ACER_CAP_THREEG)) {
2119 retval = device_create_file(&acer_platform_device->dev,
2125 retval = device_create_file(&acer_platform_device->dev,
2126 &dev_attr_interface);
2133 remove_sysfs(acer_platform_device);
2137 static void remove_debugfs(void)
2139 debugfs_remove(interface->debug.devices);
2140 debugfs_remove(interface->debug.root);
2143 static int create_debugfs(void)
2145 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2146 if (!interface->debug.root) {
2147 pr_err("Failed to create debugfs directory");
2151 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2152 interface->debug.root,
2153 &interface->debug.wmid_devices);
2154 if (!interface->debug.devices)
2164 static int __init acer_wmi_init(void)
2168 pr_info("Acer Laptop ACPI-WMI Extras\n");
2170 if (dmi_check_system(acer_blacklist)) {
2171 pr_info("Blacklisted hardware detected - not loading\n");
2178 * Detect which ACPI-WMI interface we're using.
2180 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2181 interface = &AMW0_V2_interface;
2183 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2184 interface = &wmid_interface;
2186 if (wmi_has_guid(WMID_GUID3))
2187 interface = &wmid_v2_interface;
2190 dmi_walk(type_aa_dmi_decode, NULL);
2192 if (wmi_has_guid(WMID_GUID2) && interface) {
2193 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
2194 pr_err("Unable to detect available WMID devices\n");
2197 /* WMID always provides brightness methods */
2198 interface->capability |= ACER_CAP_BRIGHTNESS;
2199 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
2200 pr_err("No WMID device detection method found\n");
2204 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2205 interface = &AMW0_interface;
2207 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2208 pr_err("Unable to detect available AMW0 devices\n");
2213 if (wmi_has_guid(AMW0_GUID1))
2214 AMW0_find_mailled();
2217 pr_err("No or unsupported WMI interface, unable to load\n");
2223 if (dmi_check_system(video_vendor_dmi_table))
2224 acpi_video_dmi_promote_vendor();
2225 if (acpi_video_backlight_support()) {
2226 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2227 pr_info("Brightness must be controlled by acpi video driver\n");
2229 pr_info("Disabling ACPI video driver\n");
2230 acpi_video_unregister();
2233 if (wmi_has_guid(WMID_GUID3)) {
2235 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2236 pr_err("Cannot enable EC raw mode\n");
2239 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2240 pr_err("Cannot enable Launch Manager mode\n");
2243 } else if (ec_raw_mode) {
2244 pr_info("No WMID EC raw mode enable method\n");
2247 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2248 err = acer_wmi_input_setup();
2253 acer_wmi_accel_setup();
2255 err = platform_driver_register(&acer_platform_driver);
2257 pr_err("Unable to register platform driver\n");
2258 goto error_platform_register;
2261 acer_platform_device = platform_device_alloc("acer-wmi", -1);
2262 if (!acer_platform_device) {
2264 goto error_device_alloc;
2267 err = platform_device_add(acer_platform_device);
2269 goto error_device_add;
2271 err = create_sysfs();
2273 goto error_create_sys;
2275 if (wmi_has_guid(WMID_GUID2)) {
2276 interface->debug.wmid_devices = get_wmid_devices();
2277 err = create_debugfs();
2279 goto error_create_debugfs;
2282 /* Override any initial settings with values from the commandline */
2283 acer_commandline_init();
2287 error_create_debugfs:
2288 remove_sysfs(acer_platform_device);
2290 platform_device_del(acer_platform_device);
2292 platform_device_put(acer_platform_device);
2294 platform_driver_unregister(&acer_platform_driver);
2295 error_platform_register:
2296 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2297 acer_wmi_input_destroy();
2298 if (has_cap(ACER_CAP_ACCEL))
2299 acer_wmi_accel_destroy();
2304 static void __exit acer_wmi_exit(void)
2306 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2307 acer_wmi_input_destroy();
2309 if (has_cap(ACER_CAP_ACCEL))
2310 acer_wmi_accel_destroy();
2312 remove_sysfs(acer_platform_device);
2314 platform_device_unregister(acer_platform_device);
2315 platform_driver_unregister(&acer_platform_driver);
2317 pr_info("Acer Laptop WMI Extras unloaded\n");
2321 module_init(acer_wmi_init);
2322 module_exit(acer_wmi_exit);