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 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/dmi.h>
31 #include <linux/backlight.h>
32 #include <linux/leds.h>
33 #include <linux/platform_device.h>
34 #include <linux/acpi.h>
35 #include <linux/i8042.h>
36 #include <linux/rfkill.h>
37 #include <linux/workqueue.h>
38 #include <linux/debugfs.h>
39 #include <linux/slab.h>
40 #include <linux/input.h>
41 #include <linux/input/sparse-keymap.h>
42 #include <linux/dmi.h>
44 #include <acpi/acpi_drivers.h>
46 MODULE_AUTHOR("Carlos Corbacho");
47 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
48 MODULE_LICENSE("GPL");
50 #define ACER_LOGPREFIX "acer-wmi: "
51 #define ACER_ERR KERN_ERR ACER_LOGPREFIX
52 #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
53 #define ACER_INFO KERN_INFO ACER_LOGPREFIX
54 #define ACER_WARNING KERN_WARNING ACER_LOGPREFIX
58 * Meaning is unknown - this number is required for writing to ACPI for AMW0
59 * (it's also used in acerhk when directly accessing the BIOS)
61 #define ACER_AMW0_WRITE 0x9610
64 * Bit masks for the AMW0 interface
66 #define ACER_AMW0_WIRELESS_MASK 0x35
67 #define ACER_AMW0_BLUETOOTH_MASK 0x34
68 #define ACER_AMW0_MAILLED_MASK 0x31
71 * Method IDs for WMID interface
73 #define ACER_WMID_GET_WIRELESS_METHODID 1
74 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
75 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
76 #define ACER_WMID_SET_WIRELESS_METHODID 4
77 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
78 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
79 #define ACER_WMID_GET_THREEG_METHODID 10
80 #define ACER_WMID_SET_THREEG_METHODID 11
83 * Acer ACPI method GUIDs
85 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
86 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
87 #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
88 #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
89 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
92 * Acer ACPI event GUIDs
94 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
96 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
97 MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
98 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
100 enum acer_wmi_event_ids {
101 WMID_HOTKEY_EVENT = 0x1,
104 static const struct key_entry acer_wmi_keymap[] = {
105 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
106 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
107 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
108 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
109 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
110 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
111 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
112 {KE_KEY, 0x82, {KEY_F22} }, /* Touch Pad On/Off */
116 static struct input_dev *acer_wmi_input_dev;
118 struct event_return_value {
123 } __attribute__((packed));
126 * GUID3 Get Device Status device flags
128 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
129 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
130 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
132 struct wmid3_gds_input_param { /* Get Device Status input parameter */
133 u8 function_num; /* Function Number */
134 u8 hotkey_number; /* Hotkey Number */
135 u16 devices; /* Get Device */
136 } __attribute__((packed));
138 struct wmid3_gds_return_value { /* Get Device Status return value*/
139 u8 error_code; /* Error Code */
140 u8 ec_return_value; /* EC Return Value */
141 u16 devices; /* Current Device Status */
143 } __attribute__((packed));
145 struct hotkey_function_type_aa {
149 u16 commun_func_bitmap;
150 } __attribute__((packed));
153 * Interface capability flags
155 #define ACER_CAP_MAILLED (1<<0)
156 #define ACER_CAP_WIRELESS (1<<1)
157 #define ACER_CAP_BLUETOOTH (1<<2)
158 #define ACER_CAP_BRIGHTNESS (1<<3)
159 #define ACER_CAP_THREEG (1<<4)
160 #define ACER_CAP_ANY (0xFFFFFFFF)
163 * Interface type flags
165 enum interface_flags {
171 #define ACER_DEFAULT_WIRELESS 0
172 #define ACER_DEFAULT_BLUETOOTH 0
173 #define ACER_DEFAULT_MAILLED 0
174 #define ACER_DEFAULT_THREEG 0
176 static int max_brightness = 0xF;
178 static int mailled = -1;
179 static int brightness = -1;
180 static int threeg = -1;
181 static int force_series;
182 static bool has_type_aa;
184 module_param(mailled, int, 0444);
185 module_param(brightness, int, 0444);
186 module_param(threeg, int, 0444);
187 module_param(force_series, int, 0444);
188 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
189 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
190 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
191 MODULE_PARM_DESC(force_series, "Force a different laptop series");
201 struct dentry *devices;
205 static struct rfkill *wireless_rfkill;
206 static struct rfkill *bluetooth_rfkill;
207 static struct rfkill *threeg_rfkill;
209 /* Each low-level interface must define at least some of the following */
210 struct wmi_interface {
211 /* The WMI device type */
214 /* The capabilities this interface provides */
217 /* Private data for the current interface */
218 struct acer_data data;
220 /* debugfs entries associated with this interface */
221 struct acer_debug debug;
224 /* The static interface pointer, points to the currently detected interface */
225 static struct wmi_interface *interface;
228 * Embedded Controller quirks
229 * Some laptops require us to directly access the EC to either enable or query
230 * features that are not available through WMI.
240 static struct quirk_entry *quirks;
242 static void set_quirks(void)
248 interface->capability |= ACER_CAP_MAILLED;
250 if (quirks->brightness)
251 interface->capability |= ACER_CAP_BRIGHTNESS;
254 static int dmi_matched(const struct dmi_system_id *dmi)
256 quirks = dmi->driver_data;
260 static struct quirk_entry quirk_unknown = {
263 static struct quirk_entry quirk_acer_aspire_1520 = {
267 static struct quirk_entry quirk_acer_travelmate_2490 = {
271 /* This AMW0 laptop has no bluetooth */
272 static struct quirk_entry quirk_medion_md_98300 = {
276 static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
280 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
281 static struct dmi_system_id __devinitdata acer_blacklist[] = {
283 .ident = "Acer Aspire One (SSD)",
285 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
286 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
290 .ident = "Acer Aspire One (HDD)",
292 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
293 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
299 static struct dmi_system_id acer_quirks[] = {
301 .callback = dmi_matched,
302 .ident = "Acer Aspire 1360",
304 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
305 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
307 .driver_data = &quirk_acer_aspire_1520,
310 .callback = dmi_matched,
311 .ident = "Acer Aspire 1520",
313 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
314 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
316 .driver_data = &quirk_acer_aspire_1520,
319 .callback = dmi_matched,
320 .ident = "Acer Aspire 3100",
322 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
323 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
325 .driver_data = &quirk_acer_travelmate_2490,
328 .callback = dmi_matched,
329 .ident = "Acer Aspire 3610",
331 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
332 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
334 .driver_data = &quirk_acer_travelmate_2490,
337 .callback = dmi_matched,
338 .ident = "Acer Aspire 5100",
340 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
341 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
343 .driver_data = &quirk_acer_travelmate_2490,
346 .callback = dmi_matched,
347 .ident = "Acer Aspire 5610",
349 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
350 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
352 .driver_data = &quirk_acer_travelmate_2490,
355 .callback = dmi_matched,
356 .ident = "Acer Aspire 5630",
358 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
359 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
361 .driver_data = &quirk_acer_travelmate_2490,
364 .callback = dmi_matched,
365 .ident = "Acer Aspire 5650",
367 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
368 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
370 .driver_data = &quirk_acer_travelmate_2490,
373 .callback = dmi_matched,
374 .ident = "Acer Aspire 5680",
376 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
377 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
379 .driver_data = &quirk_acer_travelmate_2490,
382 .callback = dmi_matched,
383 .ident = "Acer Aspire 9110",
385 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
386 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
388 .driver_data = &quirk_acer_travelmate_2490,
391 .callback = dmi_matched,
392 .ident = "Acer TravelMate 2490",
394 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
395 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
397 .driver_data = &quirk_acer_travelmate_2490,
400 .callback = dmi_matched,
401 .ident = "Acer TravelMate 4200",
403 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
404 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
406 .driver_data = &quirk_acer_travelmate_2490,
409 .callback = dmi_matched,
410 .ident = "Fujitsu Siemens Amilo Li 1718",
412 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
413 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
415 .driver_data = &quirk_fujitsu_amilo_li_1718,
418 .callback = dmi_matched,
419 .ident = "Medion MD 98300",
421 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
422 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
424 .driver_data = &quirk_medion_md_98300,
429 /* Find which quirks are needed for a particular vendor/ model pair */
430 static void find_quirks(void)
433 dmi_check_system(acer_quirks);
434 } else if (force_series == 2490) {
435 quirks = &quirk_acer_travelmate_2490;
439 quirks = &quirk_unknown;
445 * General interface convenience methods
448 static bool has_cap(u32 cap)
450 if ((interface->capability & cap) != 0)
457 * AMW0 (V1) interface
474 static acpi_status wmab_execute(struct wmab_args *regbuf,
475 struct acpi_buffer *result)
477 struct acpi_buffer input;
479 input.length = sizeof(struct wmab_args);
480 input.pointer = (u8 *)regbuf;
482 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
487 static acpi_status AMW0_get_u32(u32 *value, u32 cap,
488 struct wmi_interface *iface)
494 case ACER_CAP_MAILLED:
495 switch (quirks->mailled) {
497 err = ec_read(0xA, &result);
500 *value = (result >> 7) & 0x1;
504 case ACER_CAP_WIRELESS:
505 switch (quirks->wireless) {
507 err = ec_read(0x7B, &result);
510 *value = result & 0x1;
513 err = ec_read(0x71, &result);
516 *value = result & 0x1;
519 err = ec_read(0xA, &result);
522 *value = (result >> 2) & 0x1;
526 case ACER_CAP_BLUETOOTH:
527 switch (quirks->bluetooth) {
529 err = ec_read(0xA, &result);
532 *value = (result >> 4) & 0x1;
536 case ACER_CAP_BRIGHTNESS:
537 switch (quirks->brightness) {
539 err = ec_read(0x83, &result);
552 static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
554 struct wmab_args args;
556 args.eax = ACER_AMW0_WRITE;
557 args.ebx = value ? (1<<8) : 0;
558 args.ecx = args.edx = 0;
561 case ACER_CAP_MAILLED:
563 return AE_BAD_PARAMETER;
564 args.ebx |= ACER_AMW0_MAILLED_MASK;
566 case ACER_CAP_WIRELESS:
568 return AE_BAD_PARAMETER;
569 args.ebx |= ACER_AMW0_WIRELESS_MASK;
571 case ACER_CAP_BLUETOOTH:
573 return AE_BAD_PARAMETER;
574 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
576 case ACER_CAP_BRIGHTNESS:
577 if (value > max_brightness)
578 return AE_BAD_PARAMETER;
579 switch (quirks->brightness) {
581 return ec_write(0x83, value);
588 /* Actually do the set */
589 return wmab_execute(&args, NULL);
592 static acpi_status AMW0_find_mailled(void)
594 struct wmab_args args;
596 acpi_status status = AE_OK;
597 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
598 union acpi_object *obj;
601 args.ebx = args.ecx = args.edx = 0;
603 status = wmab_execute(&args, &out);
604 if (ACPI_FAILURE(status))
607 obj = (union acpi_object *) out.pointer;
608 if (obj && obj->type == ACPI_TYPE_BUFFER &&
609 obj->buffer.length == sizeof(struct wmab_ret)) {
610 ret = *((struct wmab_ret *) obj->buffer.pointer);
617 interface->capability |= ACER_CAP_MAILLED;
624 static acpi_status AMW0_set_capabilities(void)
626 struct wmab_args args;
629 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
630 union acpi_object *obj;
633 * On laptops with this strange GUID (non Acer), normal probing doesn't
636 if (wmi_has_guid(AMW0_GUID2)) {
637 interface->capability |= ACER_CAP_WIRELESS;
641 args.eax = ACER_AMW0_WRITE;
642 args.ecx = args.edx = 0;
644 args.ebx = 0xa2 << 8;
645 args.ebx |= ACER_AMW0_WIRELESS_MASK;
647 status = wmab_execute(&args, &out);
648 if (ACPI_FAILURE(status))
652 if (obj && obj->type == ACPI_TYPE_BUFFER &&
653 obj->buffer.length == sizeof(struct wmab_ret)) {
654 ret = *((struct wmab_ret *) obj->buffer.pointer);
661 interface->capability |= ACER_CAP_WIRELESS;
664 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
667 * It's ok to use existing buffer for next wmab_execute call.
668 * But we need to kfree(out.pointer) if next wmab_execute fail.
670 status = wmab_execute(&args, &out);
671 if (ACPI_FAILURE(status))
674 obj = (union acpi_object *) out.pointer;
675 if (obj && obj->type == ACPI_TYPE_BUFFER
676 && obj->buffer.length == sizeof(struct wmab_ret)) {
677 ret = *((struct wmab_ret *) obj->buffer.pointer);
684 interface->capability |= ACER_CAP_BLUETOOTH;
687 * This appears to be safe to enable, since all Wistron based laptops
688 * appear to use the same EC register for brightness, even if they
689 * differ for wireless, etc
691 if (quirks->brightness >= 0)
692 interface->capability |= ACER_CAP_BRIGHTNESS;
700 static struct wmi_interface AMW0_interface = {
704 static struct wmi_interface AMW0_V2_interface = {
705 .type = ACER_AMW0_V2,
709 * New interface (The WMID interface)
712 WMI_execute_u32(u32 method_id, u32 in, u32 *out)
714 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
715 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
716 union acpi_object *obj;
720 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
722 if (ACPI_FAILURE(status))
725 obj = (union acpi_object *) result.pointer;
726 if (obj && obj->type == ACPI_TYPE_BUFFER &&
727 obj->buffer.length == sizeof(u32)) {
728 tmp = *((u32 *) obj->buffer.pointer);
736 kfree(result.pointer);
741 static acpi_status WMID_get_u32(u32 *value, u32 cap,
742 struct wmi_interface *iface)
746 u32 result, method_id = 0;
749 case ACER_CAP_WIRELESS:
750 method_id = ACER_WMID_GET_WIRELESS_METHODID;
752 case ACER_CAP_BLUETOOTH:
753 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
755 case ACER_CAP_BRIGHTNESS:
756 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
758 case ACER_CAP_THREEG:
759 method_id = ACER_WMID_GET_THREEG_METHODID;
761 case ACER_CAP_MAILLED:
762 if (quirks->mailled == 1) {
770 status = WMI_execute_u32(method_id, 0, &result);
772 if (ACPI_SUCCESS(status))
778 static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
784 case ACER_CAP_BRIGHTNESS:
785 if (value > max_brightness)
786 return AE_BAD_PARAMETER;
787 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
789 case ACER_CAP_WIRELESS:
791 return AE_BAD_PARAMETER;
792 method_id = ACER_WMID_SET_WIRELESS_METHODID;
794 case ACER_CAP_BLUETOOTH:
796 return AE_BAD_PARAMETER;
797 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
799 case ACER_CAP_THREEG:
801 return AE_BAD_PARAMETER;
802 method_id = ACER_WMID_SET_THREEG_METHODID;
804 case ACER_CAP_MAILLED:
806 return AE_BAD_PARAMETER;
807 if (quirks->mailled == 1) {
808 param = value ? 0x92 : 0x93;
810 i8042_command(¶m, 0x1059);
818 return WMI_execute_u32(method_id, (u32)value, NULL);
821 static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
823 struct hotkey_function_type_aa *type_aa;
825 /* We are looking for OEM-specific Type AAh */
826 if (header->type != 0xAA)
830 type_aa = (struct hotkey_function_type_aa *) header;
832 printk(ACER_INFO "Function bitmap for Communication Button: 0x%x\n",
833 type_aa->commun_func_bitmap);
835 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
836 interface->capability |= ACER_CAP_WIRELESS;
837 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
838 interface->capability |= ACER_CAP_THREEG;
839 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
840 interface->capability |= ACER_CAP_BLUETOOTH;
843 static acpi_status WMID_set_capabilities(void)
845 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
846 union acpi_object *obj;
850 status = wmi_query_block(WMID_GUID2, 1, &out);
851 if (ACPI_FAILURE(status))
854 obj = (union acpi_object *) out.pointer;
855 if (obj && obj->type == ACPI_TYPE_BUFFER &&
856 obj->buffer.length == sizeof(u32)) {
857 devices = *((u32 *) obj->buffer.pointer);
863 dmi_walk(type_aa_dmi_decode, NULL);
865 interface->capability |= ACER_CAP_WIRELESS;
866 interface->capability |= ACER_CAP_THREEG;
868 interface->capability |= ACER_CAP_BLUETOOTH;
871 /* WMID always provides brightness methods */
872 interface->capability |= ACER_CAP_BRIGHTNESS;
874 if (!(devices & 0x20))
875 max_brightness = 0x9;
881 static struct wmi_interface wmid_interface = {
886 * Generic Device (interface-independent)
889 static acpi_status get_u32(u32 *value, u32 cap)
891 acpi_status status = AE_ERROR;
893 switch (interface->type) {
895 status = AMW0_get_u32(value, cap, interface);
898 if (cap == ACER_CAP_MAILLED) {
899 status = AMW0_get_u32(value, cap, interface);
903 status = WMID_get_u32(value, cap, interface);
910 static acpi_status set_u32(u32 value, u32 cap)
914 if (interface->capability & cap) {
915 switch (interface->type) {
917 return AMW0_set_u32(value, cap, interface);
919 if (cap == ACER_CAP_MAILLED)
920 return AMW0_set_u32(value, cap, interface);
923 * On some models, some WMID methods don't toggle
924 * properly. For those cases, we want to run the AMW0
925 * method afterwards to be certain we've really toggled
928 if (cap == ACER_CAP_WIRELESS ||
929 cap == ACER_CAP_BLUETOOTH) {
930 status = WMID_set_u32(value, cap, interface);
931 if (ACPI_FAILURE(status))
934 return AMW0_set_u32(value, cap, interface);
937 return WMID_set_u32(value, cap, interface);
939 return AE_BAD_PARAMETER;
942 return AE_BAD_PARAMETER;
945 static void __init acer_commandline_init(void)
948 * These will all fail silently if the value given is invalid, or the
949 * capability isn't available on the given interface
951 set_u32(mailled, ACER_CAP_MAILLED);
953 set_u32(threeg, ACER_CAP_THREEG);
954 set_u32(brightness, ACER_CAP_BRIGHTNESS);
958 * LED device (Mail LED only, no other LEDs known yet)
960 static void mail_led_set(struct led_classdev *led_cdev,
961 enum led_brightness value)
963 set_u32(value, ACER_CAP_MAILLED);
966 static struct led_classdev mail_led = {
967 .name = "acer-wmi::mail",
968 .brightness_set = mail_led_set,
971 static int __devinit acer_led_init(struct device *dev)
973 return led_classdev_register(dev, &mail_led);
976 static void acer_led_exit(void)
978 led_classdev_unregister(&mail_led);
984 static struct backlight_device *acer_backlight_device;
986 static int read_brightness(struct backlight_device *bd)
989 get_u32(&value, ACER_CAP_BRIGHTNESS);
993 static int update_bl_status(struct backlight_device *bd)
995 int intensity = bd->props.brightness;
997 if (bd->props.power != FB_BLANK_UNBLANK)
999 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1002 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1007 static struct backlight_ops acer_bl_ops = {
1008 .get_brightness = read_brightness,
1009 .update_status = update_bl_status,
1012 static int __devinit acer_backlight_init(struct device *dev)
1014 struct backlight_properties props;
1015 struct backlight_device *bd;
1017 memset(&props, 0, sizeof(struct backlight_properties));
1018 props.max_brightness = max_brightness;
1019 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1022 printk(ACER_ERR "Could not register Acer backlight device\n");
1023 acer_backlight_device = NULL;
1027 acer_backlight_device = bd;
1029 bd->props.power = FB_BLANK_UNBLANK;
1030 bd->props.brightness = read_brightness(bd);
1031 backlight_update_status(bd);
1035 static void acer_backlight_exit(void)
1037 backlight_device_unregister(acer_backlight_device);
1040 static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1042 struct wmid3_gds_return_value return_value;
1044 union acpi_object *obj;
1045 struct wmid3_gds_input_param params = {
1046 .function_num = 0x1,
1047 .hotkey_number = 0x01,
1050 struct acpi_buffer input = {
1051 sizeof(struct wmid3_gds_input_param),
1054 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1056 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1057 if (ACPI_FAILURE(status))
1060 obj = output.pointer;
1064 else if (obj->type != ACPI_TYPE_BUFFER) {
1068 if (obj->buffer.length != 8) {
1069 printk(ACER_WARNING "Unknown buffer length %d\n",
1070 obj->buffer.length);
1075 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1078 if (return_value.error_code || return_value.ec_return_value)
1079 printk(ACER_WARNING "Get Device Status failed: "
1080 "0x%x - 0x%x\n", return_value.error_code,
1081 return_value.ec_return_value);
1083 *value = !!(return_value.devices & device);
1088 static acpi_status get_device_status(u32 *value, u32 cap)
1090 if (wmi_has_guid(WMID_GUID3)) {
1094 case ACER_CAP_WIRELESS:
1095 device = ACER_WMID3_GDS_WIRELESS;
1097 case ACER_CAP_BLUETOOTH:
1098 device = ACER_WMID3_GDS_BLUETOOTH;
1100 case ACER_CAP_THREEG:
1101 device = ACER_WMID3_GDS_THREEG;
1106 return wmid3_get_device_status(value, device);
1109 return get_u32(value, cap);
1116 static void acer_rfkill_update(struct work_struct *ignored);
1117 static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1118 static void acer_rfkill_update(struct work_struct *ignored)
1123 status = get_u32(&state, ACER_CAP_WIRELESS);
1124 if (ACPI_SUCCESS(status))
1125 rfkill_set_sw_state(wireless_rfkill, !state);
1127 if (has_cap(ACER_CAP_BLUETOOTH)) {
1128 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1129 if (ACPI_SUCCESS(status))
1130 rfkill_set_sw_state(bluetooth_rfkill, !state);
1133 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1134 status = wmid3_get_device_status(&state,
1135 ACER_WMID3_GDS_THREEG);
1136 if (ACPI_SUCCESS(status))
1137 rfkill_set_sw_state(threeg_rfkill, !state);
1140 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1143 static int acer_rfkill_set(void *data, bool blocked)
1146 u32 cap = (unsigned long)data;
1147 status = set_u32(!blocked, cap);
1148 if (ACPI_FAILURE(status))
1153 static const struct rfkill_ops acer_rfkill_ops = {
1154 .set_block = acer_rfkill_set,
1157 static struct rfkill *acer_rfkill_register(struct device *dev,
1158 enum rfkill_type type,
1159 char *name, u32 cap)
1162 struct rfkill *rfkill_dev;
1166 rfkill_dev = rfkill_alloc(name, dev, type,
1168 (void *)(unsigned long)cap);
1170 return ERR_PTR(-ENOMEM);
1172 status = get_device_status(&state, cap);
1173 if (ACPI_SUCCESS(status))
1174 rfkill_init_sw_state(rfkill_dev, !state);
1176 err = rfkill_register(rfkill_dev);
1178 rfkill_destroy(rfkill_dev);
1179 return ERR_PTR(err);
1184 static int acer_rfkill_init(struct device *dev)
1186 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1187 "acer-wireless", ACER_CAP_WIRELESS);
1188 if (IS_ERR(wireless_rfkill))
1189 return PTR_ERR(wireless_rfkill);
1191 if (has_cap(ACER_CAP_BLUETOOTH)) {
1192 bluetooth_rfkill = acer_rfkill_register(dev,
1193 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1194 ACER_CAP_BLUETOOTH);
1195 if (IS_ERR(bluetooth_rfkill)) {
1196 rfkill_unregister(wireless_rfkill);
1197 rfkill_destroy(wireless_rfkill);
1198 return PTR_ERR(bluetooth_rfkill);
1202 if (has_cap(ACER_CAP_THREEG)) {
1203 threeg_rfkill = acer_rfkill_register(dev,
1204 RFKILL_TYPE_WWAN, "acer-threeg",
1206 if (IS_ERR(threeg_rfkill)) {
1207 rfkill_unregister(wireless_rfkill);
1208 rfkill_destroy(wireless_rfkill);
1209 rfkill_unregister(bluetooth_rfkill);
1210 rfkill_destroy(bluetooth_rfkill);
1211 return PTR_ERR(threeg_rfkill);
1215 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1220 static void acer_rfkill_exit(void)
1222 cancel_delayed_work_sync(&acer_rfkill_work);
1224 rfkill_unregister(wireless_rfkill);
1225 rfkill_destroy(wireless_rfkill);
1227 if (has_cap(ACER_CAP_BLUETOOTH)) {
1228 rfkill_unregister(bluetooth_rfkill);
1229 rfkill_destroy(bluetooth_rfkill);
1232 if (has_cap(ACER_CAP_THREEG)) {
1233 rfkill_unregister(threeg_rfkill);
1234 rfkill_destroy(threeg_rfkill);
1242 static ssize_t show_bool_threeg(struct device *dev,
1243 struct device_attribute *attr, char *buf)
1247 if (wmi_has_guid(WMID_GUID3))
1248 status = wmid3_get_device_status(&result,
1249 ACER_WMID3_GDS_THREEG);
1251 status = get_u32(&result, ACER_CAP_THREEG);
1252 if (ACPI_SUCCESS(status))
1253 return sprintf(buf, "%u\n", result);
1254 return sprintf(buf, "Read error\n");
1257 static ssize_t set_bool_threeg(struct device *dev,
1258 struct device_attribute *attr, const char *buf, size_t count)
1260 u32 tmp = simple_strtoul(buf, NULL, 10);
1261 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1262 if (ACPI_FAILURE(status))
1266 static DEVICE_ATTR(threeg, S_IWUGO | S_IRUGO | S_IWUSR, show_bool_threeg,
1269 static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1272 switch (interface->type) {
1274 return sprintf(buf, "AMW0\n");
1276 return sprintf(buf, "AMW0 v2\n");
1278 return sprintf(buf, "WMID\n");
1280 return sprintf(buf, "Error!\n");
1284 static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
1286 static void acer_wmi_notify(u32 value, void *context)
1288 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1289 union acpi_object *obj;
1290 struct event_return_value return_value;
1293 status = wmi_get_event_data(value, &response);
1294 if (status != AE_OK) {
1295 printk(ACER_WARNING "bad event status 0x%x\n", status);
1299 obj = (union acpi_object *)response.pointer;
1303 if (obj->type != ACPI_TYPE_BUFFER) {
1304 printk(ACER_WARNING "Unknown response received %d\n",
1309 if (obj->buffer.length != 8) {
1310 printk(ACER_WARNING "Unknown buffer length %d\n",
1311 obj->buffer.length);
1316 return_value = *((struct event_return_value *)obj->buffer.pointer);
1319 switch (return_value.function) {
1320 case WMID_HOTKEY_EVENT:
1321 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1322 return_value.key_num, 1, true))
1323 printk(ACER_WARNING "Unknown key number - 0x%x\n",
1324 return_value.key_num);
1327 printk(ACER_WARNING "Unknown function number - %d - %d\n",
1328 return_value.function, return_value.key_num);
1333 static int __init acer_wmi_input_setup(void)
1338 acer_wmi_input_dev = input_allocate_device();
1339 if (!acer_wmi_input_dev)
1342 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1343 acer_wmi_input_dev->phys = "wmi/input0";
1344 acer_wmi_input_dev->id.bustype = BUS_HOST;
1346 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1350 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1351 acer_wmi_notify, NULL);
1352 if (ACPI_FAILURE(status)) {
1354 goto err_free_keymap;
1357 err = input_register_device(acer_wmi_input_dev);
1359 goto err_uninstall_notifier;
1363 err_uninstall_notifier:
1364 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1366 sparse_keymap_free(acer_wmi_input_dev);
1368 input_free_device(acer_wmi_input_dev);
1372 static void acer_wmi_input_destroy(void)
1374 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1375 sparse_keymap_free(acer_wmi_input_dev);
1376 input_unregister_device(acer_wmi_input_dev);
1382 static u32 get_wmid_devices(void)
1384 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1385 union acpi_object *obj;
1389 status = wmi_query_block(WMID_GUID2, 1, &out);
1390 if (ACPI_FAILURE(status))
1393 obj = (union acpi_object *) out.pointer;
1394 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1395 obj->buffer.length == sizeof(u32)) {
1396 devices = *((u32 *) obj->buffer.pointer);
1406 static int __devinit acer_platform_probe(struct platform_device *device)
1410 if (has_cap(ACER_CAP_MAILLED)) {
1411 err = acer_led_init(&device->dev);
1416 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1417 err = acer_backlight_init(&device->dev);
1419 goto error_brightness;
1422 err = acer_rfkill_init(&device->dev);
1429 if (has_cap(ACER_CAP_BRIGHTNESS))
1430 acer_backlight_exit();
1432 if (has_cap(ACER_CAP_MAILLED))
1438 static int acer_platform_remove(struct platform_device *device)
1440 if (has_cap(ACER_CAP_MAILLED))
1442 if (has_cap(ACER_CAP_BRIGHTNESS))
1443 acer_backlight_exit();
1449 static int acer_platform_suspend(struct platform_device *dev,
1453 struct acer_data *data = &interface->data;
1458 if (has_cap(ACER_CAP_MAILLED)) {
1459 get_u32(&value, ACER_CAP_MAILLED);
1460 data->mailled = value;
1463 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1464 get_u32(&value, ACER_CAP_BRIGHTNESS);
1465 data->brightness = value;
1471 static int acer_platform_resume(struct platform_device *device)
1473 struct acer_data *data = &interface->data;
1478 if (has_cap(ACER_CAP_MAILLED))
1479 set_u32(data->mailled, ACER_CAP_MAILLED);
1481 if (has_cap(ACER_CAP_BRIGHTNESS))
1482 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1487 static struct platform_driver acer_platform_driver = {
1490 .owner = THIS_MODULE,
1492 .probe = acer_platform_probe,
1493 .remove = acer_platform_remove,
1494 .suspend = acer_platform_suspend,
1495 .resume = acer_platform_resume,
1498 static struct platform_device *acer_platform_device;
1500 static int remove_sysfs(struct platform_device *device)
1502 if (has_cap(ACER_CAP_THREEG))
1503 device_remove_file(&device->dev, &dev_attr_threeg);
1505 device_remove_file(&device->dev, &dev_attr_interface);
1510 static int create_sysfs(void)
1512 int retval = -ENOMEM;
1514 if (has_cap(ACER_CAP_THREEG)) {
1515 retval = device_create_file(&acer_platform_device->dev,
1521 retval = device_create_file(&acer_platform_device->dev,
1522 &dev_attr_interface);
1529 remove_sysfs(acer_platform_device);
1533 static void remove_debugfs(void)
1535 debugfs_remove(interface->debug.devices);
1536 debugfs_remove(interface->debug.root);
1539 static int create_debugfs(void)
1541 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1542 if (!interface->debug.root) {
1543 printk(ACER_ERR "Failed to create debugfs directory");
1547 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1548 interface->debug.root,
1549 &interface->debug.wmid_devices);
1550 if (!interface->debug.devices)
1560 static int __init acer_wmi_init(void)
1564 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
1566 if (dmi_check_system(acer_blacklist)) {
1567 printk(ACER_INFO "Blacklisted hardware detected - "
1575 * Detect which ACPI-WMI interface we're using.
1577 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1578 interface = &AMW0_V2_interface;
1580 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1581 interface = &wmid_interface;
1583 if (wmi_has_guid(WMID_GUID2) && interface) {
1584 if (ACPI_FAILURE(WMID_set_capabilities())) {
1585 printk(ACER_ERR "Unable to detect available WMID "
1589 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
1590 printk(ACER_ERR "No WMID device detection method found\n");
1594 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1595 interface = &AMW0_interface;
1597 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1598 printk(ACER_ERR "Unable to detect available AMW0 "
1604 if (wmi_has_guid(AMW0_GUID1))
1605 AMW0_find_mailled();
1608 printk(ACER_INFO "No or unsupported WMI interface, unable to "
1615 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
1616 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1617 printk(ACER_INFO "Brightness must be controlled by "
1618 "generic video driver\n");
1621 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1622 err = acer_wmi_input_setup();
1627 err = platform_driver_register(&acer_platform_driver);
1629 printk(ACER_ERR "Unable to register platform driver.\n");
1630 goto error_platform_register;
1633 acer_platform_device = platform_device_alloc("acer-wmi", -1);
1634 if (!acer_platform_device) {
1636 goto error_device_alloc;
1639 err = platform_device_add(acer_platform_device);
1641 goto error_device_add;
1643 err = create_sysfs();
1645 goto error_create_sys;
1647 if (wmi_has_guid(WMID_GUID2)) {
1648 interface->debug.wmid_devices = get_wmid_devices();
1649 err = create_debugfs();
1651 goto error_create_debugfs;
1654 /* Override any initial settings with values from the commandline */
1655 acer_commandline_init();
1659 error_create_debugfs:
1660 remove_sysfs(acer_platform_device);
1662 platform_device_del(acer_platform_device);
1664 platform_device_put(acer_platform_device);
1666 platform_driver_unregister(&acer_platform_driver);
1667 error_platform_register:
1668 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1669 acer_wmi_input_destroy();
1674 static void __exit acer_wmi_exit(void)
1676 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1677 acer_wmi_input_destroy();
1679 remove_sysfs(acer_platform_device);
1681 platform_device_unregister(acer_platform_device);
1682 platform_driver_unregister(&acer_platform_driver);
1684 printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
1688 module_init(acer_wmi_init);
1689 module_exit(acer_wmi_exit);