Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / platform / x86 / acer-wmi.c
blob110e4af07640a9eda7e3ebc92f01380977510778
1 /*
2 * Acer WMI Laptop Extras
4 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
6 * Based on acer_acpi:
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>
32 #include <linux/fb.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>
47 MODULE_AUTHOR("Carlos Corbacho");
48 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
49 MODULE_LICENSE("GPL");
52 * Magic Number
53 * Meaning is unknown - this number is required for writing to ACPI for AMW0
54 * (it's also used in acerhk when directly accessing the BIOS)
56 #define ACER_AMW0_WRITE 0x9610
59 * Bit masks for the AMW0 interface
61 #define ACER_AMW0_WIRELESS_MASK 0x35
62 #define ACER_AMW0_BLUETOOTH_MASK 0x34
63 #define ACER_AMW0_MAILLED_MASK 0x31
66 * Method IDs for WMID interface
68 #define ACER_WMID_GET_WIRELESS_METHODID 1
69 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
70 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
71 #define ACER_WMID_SET_WIRELESS_METHODID 4
72 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
73 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
74 #define ACER_WMID_GET_THREEG_METHODID 10
75 #define ACER_WMID_SET_THREEG_METHODID 11
78 * Acer ACPI method GUIDs
80 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
81 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
82 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
83 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
84 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
87 * Acer ACPI event GUIDs
89 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
91 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
92 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
93 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
95 enum acer_wmi_event_ids {
96 WMID_HOTKEY_EVENT = 0x1,
99 static const struct key_entry acer_wmi_keymap[] = {
100 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
101 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
102 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
103 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
104 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
105 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
106 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
107 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
108 {KE_IGNORE, 0x41, {KEY_MUTE} },
109 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
110 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
111 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
112 {KE_IGNORE, 0x45, {KEY_STOP} },
113 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
114 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
115 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
116 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
117 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
118 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
119 {KE_IGNORE, 0x81, {KEY_SLEEP} },
120 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
121 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
122 {KE_END, 0}
125 static struct input_dev *acer_wmi_input_dev;
127 struct event_return_value {
128 u8 function;
129 u8 key_num;
130 u16 device_state;
131 u32 reserved;
132 } __attribute__((packed));
135 * GUID3 Get Device Status device flags
137 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
138 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
139 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
140 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
142 struct lm_input_params {
143 u8 function_num; /* Function Number */
144 u16 commun_devices; /* Communication type devices default status */
145 u16 devices; /* Other type devices default status */
146 u8 lm_status; /* Launch Manager Status */
147 u16 reserved;
148 } __attribute__((packed));
150 struct lm_return_value {
151 u8 error_code; /* Error Code */
152 u8 ec_return_value; /* EC Return Value */
153 u16 reserved;
154 } __attribute__((packed));
156 struct wmid3_gds_input_param { /* Get Device Status input parameter */
157 u8 function_num; /* Function Number */
158 u8 hotkey_number; /* Hotkey Number */
159 u16 devices; /* Get Device */
160 } __attribute__((packed));
162 struct wmid3_gds_return_value { /* Get Device Status return value*/
163 u8 error_code; /* Error Code */
164 u8 ec_return_value; /* EC Return Value */
165 u16 devices; /* Current Device Status */
166 u32 reserved;
167 } __attribute__((packed));
169 struct hotkey_function_type_aa {
170 u8 type;
171 u8 length;
172 u16 handle;
173 u16 commun_func_bitmap;
174 } __attribute__((packed));
177 * Interface capability flags
179 #define ACER_CAP_MAILLED (1<<0)
180 #define ACER_CAP_WIRELESS (1<<1)
181 #define ACER_CAP_BLUETOOTH (1<<2)
182 #define ACER_CAP_BRIGHTNESS (1<<3)
183 #define ACER_CAP_THREEG (1<<4)
184 #define ACER_CAP_ANY (0xFFFFFFFF)
187 * Interface type flags
189 enum interface_flags {
190 ACER_AMW0,
191 ACER_AMW0_V2,
192 ACER_WMID,
193 ACER_WMID_v2,
196 #define ACER_DEFAULT_WIRELESS 0
197 #define ACER_DEFAULT_BLUETOOTH 0
198 #define ACER_DEFAULT_MAILLED 0
199 #define ACER_DEFAULT_THREEG 0
201 static int max_brightness = 0xF;
203 static int mailled = -1;
204 static int brightness = -1;
205 static int threeg = -1;
206 static int force_series;
207 static bool ec_raw_mode;
208 static bool has_type_aa;
209 static u16 commun_func_bitmap;
211 module_param(mailled, int, 0444);
212 module_param(brightness, int, 0444);
213 module_param(threeg, int, 0444);
214 module_param(force_series, int, 0444);
215 module_param(ec_raw_mode, bool, 0444);
216 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
217 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
218 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
219 MODULE_PARM_DESC(force_series, "Force a different laptop series");
220 MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
222 struct acer_data {
223 int mailled;
224 int threeg;
225 int brightness;
228 struct acer_debug {
229 struct dentry *root;
230 struct dentry *devices;
231 u32 wmid_devices;
234 static struct rfkill *wireless_rfkill;
235 static struct rfkill *bluetooth_rfkill;
236 static struct rfkill *threeg_rfkill;
237 static bool rfkill_inited;
239 /* Each low-level interface must define at least some of the following */
240 struct wmi_interface {
241 /* The WMI device type */
242 u32 type;
244 /* The capabilities this interface provides */
245 u32 capability;
247 /* Private data for the current interface */
248 struct acer_data data;
250 /* debugfs entries associated with this interface */
251 struct acer_debug debug;
254 /* The static interface pointer, points to the currently detected interface */
255 static struct wmi_interface *interface;
258 * Embedded Controller quirks
259 * Some laptops require us to directly access the EC to either enable or query
260 * features that are not available through WMI.
263 struct quirk_entry {
264 u8 wireless;
265 u8 mailled;
266 s8 brightness;
267 u8 bluetooth;
270 static struct quirk_entry *quirks;
272 static void set_quirks(void)
274 if (!interface)
275 return;
277 if (quirks->mailled)
278 interface->capability |= ACER_CAP_MAILLED;
280 if (quirks->brightness)
281 interface->capability |= ACER_CAP_BRIGHTNESS;
284 static int dmi_matched(const struct dmi_system_id *dmi)
286 quirks = dmi->driver_data;
287 return 1;
290 static struct quirk_entry quirk_unknown = {
293 static struct quirk_entry quirk_acer_aspire_1520 = {
294 .brightness = -1,
297 static struct quirk_entry quirk_acer_travelmate_2490 = {
298 .mailled = 1,
301 /* This AMW0 laptop has no bluetooth */
302 static struct quirk_entry quirk_medion_md_98300 = {
303 .wireless = 1,
306 static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
307 .wireless = 2,
310 static struct quirk_entry quirk_lenovo_ideapad_s205 = {
311 .wireless = 3,
314 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
315 static struct dmi_system_id __devinitdata acer_blacklist[] = {
317 .ident = "Acer Aspire One (SSD)",
318 .matches = {
319 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
320 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
324 .ident = "Acer Aspire One (HDD)",
325 .matches = {
326 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
327 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
333 static struct dmi_system_id acer_quirks[] = {
335 .callback = dmi_matched,
336 .ident = "Acer Aspire 1360",
337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
341 .driver_data = &quirk_acer_aspire_1520,
344 .callback = dmi_matched,
345 .ident = "Acer Aspire 1520",
346 .matches = {
347 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
348 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
350 .driver_data = &quirk_acer_aspire_1520,
353 .callback = dmi_matched,
354 .ident = "Acer Aspire 3100",
355 .matches = {
356 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
357 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
359 .driver_data = &quirk_acer_travelmate_2490,
362 .callback = dmi_matched,
363 .ident = "Acer Aspire 3610",
364 .matches = {
365 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
366 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
368 .driver_data = &quirk_acer_travelmate_2490,
371 .callback = dmi_matched,
372 .ident = "Acer Aspire 5100",
373 .matches = {
374 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
375 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
377 .driver_data = &quirk_acer_travelmate_2490,
380 .callback = dmi_matched,
381 .ident = "Acer Aspire 5610",
382 .matches = {
383 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
384 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
386 .driver_data = &quirk_acer_travelmate_2490,
389 .callback = dmi_matched,
390 .ident = "Acer Aspire 5630",
391 .matches = {
392 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
393 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
395 .driver_data = &quirk_acer_travelmate_2490,
398 .callback = dmi_matched,
399 .ident = "Acer Aspire 5650",
400 .matches = {
401 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
402 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
404 .driver_data = &quirk_acer_travelmate_2490,
407 .callback = dmi_matched,
408 .ident = "Acer Aspire 5680",
409 .matches = {
410 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
411 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
413 .driver_data = &quirk_acer_travelmate_2490,
416 .callback = dmi_matched,
417 .ident = "Acer Aspire 9110",
418 .matches = {
419 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
420 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
422 .driver_data = &quirk_acer_travelmate_2490,
425 .callback = dmi_matched,
426 .ident = "Acer TravelMate 2490",
427 .matches = {
428 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
431 .driver_data = &quirk_acer_travelmate_2490,
434 .callback = dmi_matched,
435 .ident = "Acer TravelMate 4200",
436 .matches = {
437 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
440 .driver_data = &quirk_acer_travelmate_2490,
443 .callback = dmi_matched,
444 .ident = "Fujitsu Siemens Amilo Li 1718",
445 .matches = {
446 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
447 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
449 .driver_data = &quirk_fujitsu_amilo_li_1718,
452 .callback = dmi_matched,
453 .ident = "Medion MD 98300",
454 .matches = {
455 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
456 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
458 .driver_data = &quirk_medion_md_98300,
461 .callback = dmi_matched,
462 .ident = "Lenovo Ideapad S205",
463 .matches = {
464 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
465 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
467 .driver_data = &quirk_lenovo_ideapad_s205,
470 .callback = dmi_matched,
471 .ident = "Lenovo 3000 N200",
472 .matches = {
473 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
474 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
476 .driver_data = &quirk_fujitsu_amilo_li_1718,
481 /* Find which quirks are needed for a particular vendor/ model pair */
482 static void find_quirks(void)
484 if (!force_series) {
485 dmi_check_system(acer_quirks);
486 } else if (force_series == 2490) {
487 quirks = &quirk_acer_travelmate_2490;
490 if (quirks == NULL)
491 quirks = &quirk_unknown;
493 set_quirks();
497 * General interface convenience methods
500 static bool has_cap(u32 cap)
502 if ((interface->capability & cap) != 0)
503 return 1;
505 return 0;
509 * AMW0 (V1) interface
511 struct wmab_args {
512 u32 eax;
513 u32 ebx;
514 u32 ecx;
515 u32 edx;
518 struct wmab_ret {
519 u32 eax;
520 u32 ebx;
521 u32 ecx;
522 u32 edx;
523 u32 eex;
526 static acpi_status wmab_execute(struct wmab_args *regbuf,
527 struct acpi_buffer *result)
529 struct acpi_buffer input;
530 acpi_status status;
531 input.length = sizeof(struct wmab_args);
532 input.pointer = (u8 *)regbuf;
534 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
536 return status;
539 static acpi_status AMW0_get_u32(u32 *value, u32 cap,
540 struct wmi_interface *iface)
542 int err;
543 u8 result;
545 switch (cap) {
546 case ACER_CAP_MAILLED:
547 switch (quirks->mailled) {
548 default:
549 err = ec_read(0xA, &result);
550 if (err)
551 return AE_ERROR;
552 *value = (result >> 7) & 0x1;
553 return AE_OK;
555 break;
556 case ACER_CAP_WIRELESS:
557 switch (quirks->wireless) {
558 case 1:
559 err = ec_read(0x7B, &result);
560 if (err)
561 return AE_ERROR;
562 *value = result & 0x1;
563 return AE_OK;
564 case 2:
565 err = ec_read(0x71, &result);
566 if (err)
567 return AE_ERROR;
568 *value = result & 0x1;
569 return AE_OK;
570 case 3:
571 err = ec_read(0x78, &result);
572 if (err)
573 return AE_ERROR;
574 *value = result & 0x1;
575 return AE_OK;
576 default:
577 err = ec_read(0xA, &result);
578 if (err)
579 return AE_ERROR;
580 *value = (result >> 2) & 0x1;
581 return AE_OK;
583 break;
584 case ACER_CAP_BLUETOOTH:
585 switch (quirks->bluetooth) {
586 default:
587 err = ec_read(0xA, &result);
588 if (err)
589 return AE_ERROR;
590 *value = (result >> 4) & 0x1;
591 return AE_OK;
593 break;
594 case ACER_CAP_BRIGHTNESS:
595 switch (quirks->brightness) {
596 default:
597 err = ec_read(0x83, &result);
598 if (err)
599 return AE_ERROR;
600 *value = result;
601 return AE_OK;
603 break;
604 default:
605 return AE_ERROR;
607 return AE_OK;
610 static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
612 struct wmab_args args;
614 args.eax = ACER_AMW0_WRITE;
615 args.ebx = value ? (1<<8) : 0;
616 args.ecx = args.edx = 0;
618 switch (cap) {
619 case ACER_CAP_MAILLED:
620 if (value > 1)
621 return AE_BAD_PARAMETER;
622 args.ebx |= ACER_AMW0_MAILLED_MASK;
623 break;
624 case ACER_CAP_WIRELESS:
625 if (value > 1)
626 return AE_BAD_PARAMETER;
627 args.ebx |= ACER_AMW0_WIRELESS_MASK;
628 break;
629 case ACER_CAP_BLUETOOTH:
630 if (value > 1)
631 return AE_BAD_PARAMETER;
632 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
633 break;
634 case ACER_CAP_BRIGHTNESS:
635 if (value > max_brightness)
636 return AE_BAD_PARAMETER;
637 switch (quirks->brightness) {
638 default:
639 return ec_write(0x83, value);
640 break;
642 default:
643 return AE_ERROR;
646 /* Actually do the set */
647 return wmab_execute(&args, NULL);
650 static acpi_status AMW0_find_mailled(void)
652 struct wmab_args args;
653 struct wmab_ret ret;
654 acpi_status status = AE_OK;
655 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
656 union acpi_object *obj;
658 args.eax = 0x86;
659 args.ebx = args.ecx = args.edx = 0;
661 status = wmab_execute(&args, &out);
662 if (ACPI_FAILURE(status))
663 return status;
665 obj = (union acpi_object *) out.pointer;
666 if (obj && obj->type == ACPI_TYPE_BUFFER &&
667 obj->buffer.length == sizeof(struct wmab_ret)) {
668 ret = *((struct wmab_ret *) obj->buffer.pointer);
669 } else {
670 kfree(out.pointer);
671 return AE_ERROR;
674 if (ret.eex & 0x1)
675 interface->capability |= ACER_CAP_MAILLED;
677 kfree(out.pointer);
679 return AE_OK;
682 static int AMW0_set_cap_acpi_check_device_found;
684 static acpi_status AMW0_set_cap_acpi_check_device_cb(acpi_handle handle,
685 u32 level, void *context, void **retval)
687 AMW0_set_cap_acpi_check_device_found = 1;
688 return AE_OK;
691 static const struct acpi_device_id norfkill_ids[] = {
692 { "VPC2004", 0},
693 { "IBM0068", 0},
694 { "LEN0068", 0},
695 { "SNY5001", 0}, /* sony-laptop in charge */
696 { "", 0},
699 static int AMW0_set_cap_acpi_check_device(void)
701 const struct acpi_device_id *id;
703 for (id = norfkill_ids; id->id[0]; id++)
704 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb,
705 NULL, NULL);
706 return AMW0_set_cap_acpi_check_device_found;
709 static acpi_status AMW0_set_capabilities(void)
711 struct wmab_args args;
712 struct wmab_ret ret;
713 acpi_status status;
714 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
715 union acpi_object *obj;
718 * On laptops with this strange GUID (non Acer), normal probing doesn't
719 * work.
721 if (wmi_has_guid(AMW0_GUID2)) {
722 if ((quirks != &quirk_unknown) ||
723 !AMW0_set_cap_acpi_check_device())
724 interface->capability |= ACER_CAP_WIRELESS;
725 return AE_OK;
728 args.eax = ACER_AMW0_WRITE;
729 args.ecx = args.edx = 0;
731 args.ebx = 0xa2 << 8;
732 args.ebx |= ACER_AMW0_WIRELESS_MASK;
734 status = wmab_execute(&args, &out);
735 if (ACPI_FAILURE(status))
736 return status;
738 obj = out.pointer;
739 if (obj && obj->type == ACPI_TYPE_BUFFER &&
740 obj->buffer.length == sizeof(struct wmab_ret)) {
741 ret = *((struct wmab_ret *) obj->buffer.pointer);
742 } else {
743 status = AE_ERROR;
744 goto out;
747 if (ret.eax & 0x1)
748 interface->capability |= ACER_CAP_WIRELESS;
750 args.ebx = 2 << 8;
751 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
754 * It's ok to use existing buffer for next wmab_execute call.
755 * But we need to kfree(out.pointer) if next wmab_execute fail.
757 status = wmab_execute(&args, &out);
758 if (ACPI_FAILURE(status))
759 goto out;
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);
765 } else {
766 status = AE_ERROR;
767 goto out;
770 if (ret.eax & 0x1)
771 interface->capability |= ACER_CAP_BLUETOOTH;
774 * This appears to be safe to enable, since all Wistron based laptops
775 * appear to use the same EC register for brightness, even if they
776 * differ for wireless, etc
778 if (quirks->brightness >= 0)
779 interface->capability |= ACER_CAP_BRIGHTNESS;
781 status = AE_OK;
782 out:
783 kfree(out.pointer);
784 return status;
787 static struct wmi_interface AMW0_interface = {
788 .type = ACER_AMW0,
791 static struct wmi_interface AMW0_V2_interface = {
792 .type = ACER_AMW0_V2,
796 * New interface (The WMID interface)
798 static acpi_status
799 WMI_execute_u32(u32 method_id, u32 in, u32 *out)
801 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
802 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
803 union acpi_object *obj;
804 u32 tmp;
805 acpi_status status;
807 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
809 if (ACPI_FAILURE(status))
810 return status;
812 obj = (union acpi_object *) result.pointer;
813 if (obj && obj->type == ACPI_TYPE_BUFFER &&
814 (obj->buffer.length == sizeof(u32) ||
815 obj->buffer.length == sizeof(u64))) {
816 tmp = *((u32 *) obj->buffer.pointer);
817 } else if (obj->type == ACPI_TYPE_INTEGER) {
818 tmp = (u32) obj->integer.value;
819 } else {
820 tmp = 0;
823 if (out)
824 *out = tmp;
826 kfree(result.pointer);
828 return status;
831 static acpi_status WMID_get_u32(u32 *value, u32 cap,
832 struct wmi_interface *iface)
834 acpi_status status;
835 u8 tmp;
836 u32 result, method_id = 0;
838 switch (cap) {
839 case ACER_CAP_WIRELESS:
840 method_id = ACER_WMID_GET_WIRELESS_METHODID;
841 break;
842 case ACER_CAP_BLUETOOTH:
843 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
844 break;
845 case ACER_CAP_BRIGHTNESS:
846 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
847 break;
848 case ACER_CAP_THREEG:
849 method_id = ACER_WMID_GET_THREEG_METHODID;
850 break;
851 case ACER_CAP_MAILLED:
852 if (quirks->mailled == 1) {
853 ec_read(0x9f, &tmp);
854 *value = tmp & 0x1;
855 return 0;
857 default:
858 return AE_ERROR;
860 status = WMI_execute_u32(method_id, 0, &result);
862 if (ACPI_SUCCESS(status))
863 *value = (u8)result;
865 return status;
868 static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
870 u32 method_id = 0;
871 char param;
873 switch (cap) {
874 case ACER_CAP_BRIGHTNESS:
875 if (value > max_brightness)
876 return AE_BAD_PARAMETER;
877 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
878 break;
879 case ACER_CAP_WIRELESS:
880 if (value > 1)
881 return AE_BAD_PARAMETER;
882 method_id = ACER_WMID_SET_WIRELESS_METHODID;
883 break;
884 case ACER_CAP_BLUETOOTH:
885 if (value > 1)
886 return AE_BAD_PARAMETER;
887 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
888 break;
889 case ACER_CAP_THREEG:
890 if (value > 1)
891 return AE_BAD_PARAMETER;
892 method_id = ACER_WMID_SET_THREEG_METHODID;
893 break;
894 case ACER_CAP_MAILLED:
895 if (value > 1)
896 return AE_BAD_PARAMETER;
897 if (quirks->mailled == 1) {
898 param = value ? 0x92 : 0x93;
899 i8042_lock_chip();
900 i8042_command(&param, 0x1059);
901 i8042_unlock_chip();
902 return 0;
904 break;
905 default:
906 return AE_ERROR;
908 return WMI_execute_u32(method_id, (u32)value, NULL);
911 static acpi_status wmid3_get_device_status(u32 *value, u16 device)
913 struct wmid3_gds_return_value return_value;
914 acpi_status status;
915 union acpi_object *obj;
916 struct wmid3_gds_input_param params = {
917 .function_num = 0x1,
918 .hotkey_number = 0x01,
919 .devices = device,
921 struct acpi_buffer input = {
922 sizeof(struct wmid3_gds_input_param),
923 &params
925 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
927 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
928 if (ACPI_FAILURE(status))
929 return status;
931 obj = output.pointer;
933 if (!obj)
934 return AE_ERROR;
935 else if (obj->type != ACPI_TYPE_BUFFER) {
936 kfree(obj);
937 return AE_ERROR;
939 if (obj->buffer.length != 8) {
940 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
941 kfree(obj);
942 return AE_ERROR;
945 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
946 kfree(obj);
948 if (return_value.error_code || return_value.ec_return_value)
949 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
950 device,
951 return_value.error_code,
952 return_value.ec_return_value);
953 else
954 *value = !!(return_value.devices & device);
956 return status;
959 static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
961 u16 device;
963 switch (cap) {
964 case ACER_CAP_WIRELESS:
965 device = ACER_WMID3_GDS_WIRELESS;
966 break;
967 case ACER_CAP_BLUETOOTH:
968 device = ACER_WMID3_GDS_BLUETOOTH;
969 break;
970 case ACER_CAP_THREEG:
971 device = ACER_WMID3_GDS_THREEG;
972 break;
973 default:
974 return AE_ERROR;
976 return wmid3_get_device_status(value, device);
979 static acpi_status wmid3_set_device_status(u32 value, u16 device)
981 struct wmid3_gds_return_value return_value;
982 acpi_status status;
983 union acpi_object *obj;
984 u16 devices;
985 struct wmid3_gds_input_param params = {
986 .function_num = 0x1,
987 .hotkey_number = 0x01,
988 .devices = commun_func_bitmap,
990 struct acpi_buffer input = {
991 sizeof(struct wmid3_gds_input_param),
992 &params
994 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
995 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
997 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
998 if (ACPI_FAILURE(status))
999 return status;
1001 obj = output.pointer;
1003 if (!obj)
1004 return AE_ERROR;
1005 else if (obj->type != ACPI_TYPE_BUFFER) {
1006 kfree(obj);
1007 return AE_ERROR;
1009 if (obj->buffer.length != 8) {
1010 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1011 kfree(obj);
1012 return AE_ERROR;
1015 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1016 kfree(obj);
1018 if (return_value.error_code || return_value.ec_return_value) {
1019 pr_warning("Get Current Device Status failed: "
1020 "0x%x - 0x%x\n", return_value.error_code,
1021 return_value.ec_return_value);
1022 return status;
1025 devices = return_value.devices;
1026 params.function_num = 0x2;
1027 params.hotkey_number = 0x01;
1028 params.devices = (value) ? (devices | device) : (devices & ~device);
1030 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
1031 if (ACPI_FAILURE(status))
1032 return status;
1034 obj = output2.pointer;
1036 if (!obj)
1037 return AE_ERROR;
1038 else if (obj->type != ACPI_TYPE_BUFFER) {
1039 kfree(obj);
1040 return AE_ERROR;
1042 if (obj->buffer.length != 4) {
1043 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1044 kfree(obj);
1045 return AE_ERROR;
1048 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1049 kfree(obj);
1051 if (return_value.error_code || return_value.ec_return_value)
1052 pr_warning("Set Device Status failed: "
1053 "0x%x - 0x%x\n", return_value.error_code,
1054 return_value.ec_return_value);
1056 return status;
1059 static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1061 u16 device;
1063 switch (cap) {
1064 case ACER_CAP_WIRELESS:
1065 device = ACER_WMID3_GDS_WIRELESS;
1066 break;
1067 case ACER_CAP_BLUETOOTH:
1068 device = ACER_WMID3_GDS_BLUETOOTH;
1069 break;
1070 case ACER_CAP_THREEG:
1071 device = ACER_WMID3_GDS_THREEG;
1072 break;
1073 default:
1074 return AE_ERROR;
1076 return wmid3_set_device_status(value, device);
1079 static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1081 struct hotkey_function_type_aa *type_aa;
1083 /* We are looking for OEM-specific Type AAh */
1084 if (header->type != 0xAA)
1085 return;
1087 has_type_aa = true;
1088 type_aa = (struct hotkey_function_type_aa *) header;
1090 pr_info("Function bitmap for Communication Button: 0x%x\n",
1091 type_aa->commun_func_bitmap);
1092 commun_func_bitmap = type_aa->commun_func_bitmap;
1094 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1095 interface->capability |= ACER_CAP_WIRELESS;
1096 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1097 interface->capability |= ACER_CAP_THREEG;
1098 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1099 interface->capability |= ACER_CAP_BLUETOOTH;
1102 static acpi_status WMID_set_capabilities(void)
1104 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1105 union acpi_object *obj;
1106 acpi_status status;
1107 u32 devices;
1109 status = wmi_query_block(WMID_GUID2, 1, &out);
1110 if (ACPI_FAILURE(status))
1111 return status;
1113 obj = (union acpi_object *) out.pointer;
1114 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1115 (obj->buffer.length == sizeof(u32) ||
1116 obj->buffer.length == sizeof(u64))) {
1117 devices = *((u32 *) obj->buffer.pointer);
1118 } else if (obj->type == ACPI_TYPE_INTEGER) {
1119 devices = (u32) obj->integer.value;
1120 } else {
1121 kfree(out.pointer);
1122 return AE_ERROR;
1125 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1126 if (devices & 0x07)
1127 interface->capability |= ACER_CAP_WIRELESS;
1128 if (devices & 0x40)
1129 interface->capability |= ACER_CAP_THREEG;
1130 if (devices & 0x10)
1131 interface->capability |= ACER_CAP_BLUETOOTH;
1133 if (!(devices & 0x20))
1134 max_brightness = 0x9;
1136 kfree(out.pointer);
1137 return status;
1140 static struct wmi_interface wmid_interface = {
1141 .type = ACER_WMID,
1144 static struct wmi_interface wmid_v2_interface = {
1145 .type = ACER_WMID_v2,
1149 * Generic Device (interface-independent)
1152 static acpi_status get_u32(u32 *value, u32 cap)
1154 acpi_status status = AE_ERROR;
1156 switch (interface->type) {
1157 case ACER_AMW0:
1158 status = AMW0_get_u32(value, cap, interface);
1159 break;
1160 case ACER_AMW0_V2:
1161 if (cap == ACER_CAP_MAILLED) {
1162 status = AMW0_get_u32(value, cap, interface);
1163 break;
1165 case ACER_WMID:
1166 status = WMID_get_u32(value, cap, interface);
1167 break;
1168 case ACER_WMID_v2:
1169 if (cap & (ACER_CAP_WIRELESS |
1170 ACER_CAP_BLUETOOTH |
1171 ACER_CAP_THREEG))
1172 status = wmid_v2_get_u32(value, cap);
1173 else if (wmi_has_guid(WMID_GUID2))
1174 status = WMID_get_u32(value, cap, interface);
1175 break;
1178 return status;
1181 static acpi_status set_u32(u32 value, u32 cap)
1183 acpi_status status;
1185 if (interface->capability & cap) {
1186 switch (interface->type) {
1187 case ACER_AMW0:
1188 return AMW0_set_u32(value, cap, interface);
1189 case ACER_AMW0_V2:
1190 if (cap == ACER_CAP_MAILLED)
1191 return AMW0_set_u32(value, cap, interface);
1194 * On some models, some WMID methods don't toggle
1195 * properly. For those cases, we want to run the AMW0
1196 * method afterwards to be certain we've really toggled
1197 * the device state.
1199 if (cap == ACER_CAP_WIRELESS ||
1200 cap == ACER_CAP_BLUETOOTH) {
1201 status = WMID_set_u32(value, cap, interface);
1202 if (ACPI_FAILURE(status))
1203 return status;
1205 return AMW0_set_u32(value, cap, interface);
1207 case ACER_WMID:
1208 return WMID_set_u32(value, cap, interface);
1209 case ACER_WMID_v2:
1210 if (cap & (ACER_CAP_WIRELESS |
1211 ACER_CAP_BLUETOOTH |
1212 ACER_CAP_THREEG))
1213 return wmid_v2_set_u32(value, cap);
1214 else if (wmi_has_guid(WMID_GUID2))
1215 return WMID_set_u32(value, cap, interface);
1216 default:
1217 return AE_BAD_PARAMETER;
1220 return AE_BAD_PARAMETER;
1223 static void __init acer_commandline_init(void)
1226 * These will all fail silently if the value given is invalid, or the
1227 * capability isn't available on the given interface
1229 if (mailled >= 0)
1230 set_u32(mailled, ACER_CAP_MAILLED);
1231 if (!has_type_aa && threeg >= 0)
1232 set_u32(threeg, ACER_CAP_THREEG);
1233 if (brightness >= 0)
1234 set_u32(brightness, ACER_CAP_BRIGHTNESS);
1238 * LED device (Mail LED only, no other LEDs known yet)
1240 static void mail_led_set(struct led_classdev *led_cdev,
1241 enum led_brightness value)
1243 set_u32(value, ACER_CAP_MAILLED);
1246 static struct led_classdev mail_led = {
1247 .name = "acer-wmi::mail",
1248 .brightness_set = mail_led_set,
1251 static int __devinit acer_led_init(struct device *dev)
1253 return led_classdev_register(dev, &mail_led);
1256 static void acer_led_exit(void)
1258 set_u32(LED_OFF, ACER_CAP_MAILLED);
1259 led_classdev_unregister(&mail_led);
1263 * Backlight device
1265 static struct backlight_device *acer_backlight_device;
1267 static int read_brightness(struct backlight_device *bd)
1269 u32 value;
1270 get_u32(&value, ACER_CAP_BRIGHTNESS);
1271 return value;
1274 static int update_bl_status(struct backlight_device *bd)
1276 int intensity = bd->props.brightness;
1278 if (bd->props.power != FB_BLANK_UNBLANK)
1279 intensity = 0;
1280 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1281 intensity = 0;
1283 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1285 return 0;
1288 static const struct backlight_ops acer_bl_ops = {
1289 .get_brightness = read_brightness,
1290 .update_status = update_bl_status,
1293 static int __devinit acer_backlight_init(struct device *dev)
1295 struct backlight_properties props;
1296 struct backlight_device *bd;
1298 memset(&props, 0, sizeof(struct backlight_properties));
1299 props.type = BACKLIGHT_PLATFORM;
1300 props.max_brightness = max_brightness;
1301 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1302 &props);
1303 if (IS_ERR(bd)) {
1304 pr_err("Could not register Acer backlight device\n");
1305 acer_backlight_device = NULL;
1306 return PTR_ERR(bd);
1309 acer_backlight_device = bd;
1311 bd->props.power = FB_BLANK_UNBLANK;
1312 bd->props.brightness = read_brightness(bd);
1313 backlight_update_status(bd);
1314 return 0;
1317 static void acer_backlight_exit(void)
1319 backlight_device_unregister(acer_backlight_device);
1323 * Rfkill devices
1325 static void acer_rfkill_update(struct work_struct *ignored);
1326 static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1327 static void acer_rfkill_update(struct work_struct *ignored)
1329 u32 state;
1330 acpi_status status;
1332 if (has_cap(ACER_CAP_WIRELESS)) {
1333 status = get_u32(&state, ACER_CAP_WIRELESS);
1334 if (ACPI_SUCCESS(status)) {
1335 if (quirks->wireless == 3)
1336 rfkill_set_hw_state(wireless_rfkill, !state);
1337 else
1338 rfkill_set_sw_state(wireless_rfkill, !state);
1342 if (has_cap(ACER_CAP_BLUETOOTH)) {
1343 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1344 if (ACPI_SUCCESS(status))
1345 rfkill_set_sw_state(bluetooth_rfkill, !state);
1348 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1349 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
1350 if (ACPI_SUCCESS(status))
1351 rfkill_set_sw_state(threeg_rfkill, !state);
1354 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1357 static int acer_rfkill_set(void *data, bool blocked)
1359 acpi_status status;
1360 u32 cap = (unsigned long)data;
1362 if (rfkill_inited) {
1363 status = set_u32(!blocked, cap);
1364 if (ACPI_FAILURE(status))
1365 return -ENODEV;
1368 return 0;
1371 static const struct rfkill_ops acer_rfkill_ops = {
1372 .set_block = acer_rfkill_set,
1375 static struct rfkill *acer_rfkill_register(struct device *dev,
1376 enum rfkill_type type,
1377 char *name, u32 cap)
1379 int err;
1380 struct rfkill *rfkill_dev;
1381 u32 state;
1382 acpi_status status;
1384 rfkill_dev = rfkill_alloc(name, dev, type,
1385 &acer_rfkill_ops,
1386 (void *)(unsigned long)cap);
1387 if (!rfkill_dev)
1388 return ERR_PTR(-ENOMEM);
1390 status = get_u32(&state, cap);
1392 err = rfkill_register(rfkill_dev);
1393 if (err) {
1394 rfkill_destroy(rfkill_dev);
1395 return ERR_PTR(err);
1398 if (ACPI_SUCCESS(status))
1399 rfkill_set_sw_state(rfkill_dev, !state);
1401 return rfkill_dev;
1404 static int acer_rfkill_init(struct device *dev)
1406 int err;
1408 if (has_cap(ACER_CAP_WIRELESS)) {
1409 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1410 "acer-wireless", ACER_CAP_WIRELESS);
1411 if (IS_ERR(wireless_rfkill)) {
1412 err = PTR_ERR(wireless_rfkill);
1413 goto error_wireless;
1417 if (has_cap(ACER_CAP_BLUETOOTH)) {
1418 bluetooth_rfkill = acer_rfkill_register(dev,
1419 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1420 ACER_CAP_BLUETOOTH);
1421 if (IS_ERR(bluetooth_rfkill)) {
1422 err = PTR_ERR(bluetooth_rfkill);
1423 goto error_bluetooth;
1427 if (has_cap(ACER_CAP_THREEG)) {
1428 threeg_rfkill = acer_rfkill_register(dev,
1429 RFKILL_TYPE_WWAN, "acer-threeg",
1430 ACER_CAP_THREEG);
1431 if (IS_ERR(threeg_rfkill)) {
1432 err = PTR_ERR(threeg_rfkill);
1433 goto error_threeg;
1437 rfkill_inited = true;
1439 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1440 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1441 schedule_delayed_work(&acer_rfkill_work,
1442 round_jiffies_relative(HZ));
1444 return 0;
1446 error_threeg:
1447 if (has_cap(ACER_CAP_BLUETOOTH)) {
1448 rfkill_unregister(bluetooth_rfkill);
1449 rfkill_destroy(bluetooth_rfkill);
1451 error_bluetooth:
1452 if (has_cap(ACER_CAP_WIRELESS)) {
1453 rfkill_unregister(wireless_rfkill);
1454 rfkill_destroy(wireless_rfkill);
1456 error_wireless:
1457 return err;
1460 static void acer_rfkill_exit(void)
1462 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1463 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1464 cancel_delayed_work_sync(&acer_rfkill_work);
1466 if (has_cap(ACER_CAP_WIRELESS)) {
1467 rfkill_unregister(wireless_rfkill);
1468 rfkill_destroy(wireless_rfkill);
1471 if (has_cap(ACER_CAP_BLUETOOTH)) {
1472 rfkill_unregister(bluetooth_rfkill);
1473 rfkill_destroy(bluetooth_rfkill);
1476 if (has_cap(ACER_CAP_THREEG)) {
1477 rfkill_unregister(threeg_rfkill);
1478 rfkill_destroy(threeg_rfkill);
1480 return;
1484 * sysfs interface
1486 static ssize_t show_bool_threeg(struct device *dev,
1487 struct device_attribute *attr, char *buf)
1489 u32 result; \
1490 acpi_status status;
1492 pr_info("This threeg sysfs will be removed in 2012"
1493 " - used by: %s\n", current->comm);
1494 status = get_u32(&result, ACER_CAP_THREEG);
1495 if (ACPI_SUCCESS(status))
1496 return sprintf(buf, "%u\n", result);
1497 return sprintf(buf, "Read error\n");
1500 static ssize_t set_bool_threeg(struct device *dev,
1501 struct device_attribute *attr, const char *buf, size_t count)
1503 u32 tmp = simple_strtoul(buf, NULL, 10);
1504 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1505 pr_info("This threeg sysfs will be removed in 2012"
1506 " - used by: %s\n", current->comm);
1507 if (ACPI_FAILURE(status))
1508 return -EINVAL;
1509 return count;
1511 static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
1512 set_bool_threeg);
1514 static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1515 char *buf)
1517 pr_info("This interface sysfs will be removed in 2012"
1518 " - used by: %s\n", current->comm);
1519 switch (interface->type) {
1520 case ACER_AMW0:
1521 return sprintf(buf, "AMW0\n");
1522 case ACER_AMW0_V2:
1523 return sprintf(buf, "AMW0 v2\n");
1524 case ACER_WMID:
1525 return sprintf(buf, "WMID\n");
1526 case ACER_WMID_v2:
1527 return sprintf(buf, "WMID v2\n");
1528 default:
1529 return sprintf(buf, "Error!\n");
1533 static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
1535 static void acer_wmi_notify(u32 value, void *context)
1537 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1538 union acpi_object *obj;
1539 struct event_return_value return_value;
1540 acpi_status status;
1541 u16 device_state;
1542 const struct key_entry *key;
1544 status = wmi_get_event_data(value, &response);
1545 if (status != AE_OK) {
1546 pr_warn("bad event status 0x%x\n", status);
1547 return;
1550 obj = (union acpi_object *)response.pointer;
1552 if (!obj)
1553 return;
1554 if (obj->type != ACPI_TYPE_BUFFER) {
1555 pr_warn("Unknown response received %d\n", obj->type);
1556 kfree(obj);
1557 return;
1559 if (obj->buffer.length != 8) {
1560 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1561 kfree(obj);
1562 return;
1565 return_value = *((struct event_return_value *)obj->buffer.pointer);
1566 kfree(obj);
1568 switch (return_value.function) {
1569 case WMID_HOTKEY_EVENT:
1570 device_state = return_value.device_state;
1571 pr_debug("device state: 0x%x\n", device_state);
1573 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1574 return_value.key_num);
1575 if (!key) {
1576 pr_warn("Unknown key number - 0x%x\n",
1577 return_value.key_num);
1578 } else {
1579 switch (key->keycode) {
1580 case KEY_WLAN:
1581 case KEY_BLUETOOTH:
1582 if (has_cap(ACER_CAP_WIRELESS))
1583 rfkill_set_sw_state(wireless_rfkill,
1584 !(device_state & ACER_WMID3_GDS_WIRELESS));
1585 if (has_cap(ACER_CAP_THREEG))
1586 rfkill_set_sw_state(threeg_rfkill,
1587 !(device_state & ACER_WMID3_GDS_THREEG));
1588 if (has_cap(ACER_CAP_BLUETOOTH))
1589 rfkill_set_sw_state(bluetooth_rfkill,
1590 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1591 break;
1593 sparse_keymap_report_entry(acer_wmi_input_dev, key,
1594 1, true);
1596 break;
1597 default:
1598 pr_warn("Unknown function number - %d - %d\n",
1599 return_value.function, return_value.key_num);
1600 break;
1604 static acpi_status
1605 wmid3_set_lm_mode(struct lm_input_params *params,
1606 struct lm_return_value *return_value)
1608 acpi_status status;
1609 union acpi_object *obj;
1611 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1612 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1614 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1615 if (ACPI_FAILURE(status))
1616 return status;
1618 obj = output.pointer;
1620 if (!obj)
1621 return AE_ERROR;
1622 else if (obj->type != ACPI_TYPE_BUFFER) {
1623 kfree(obj);
1624 return AE_ERROR;
1626 if (obj->buffer.length != 4) {
1627 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1628 kfree(obj);
1629 return AE_ERROR;
1632 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1633 kfree(obj);
1635 return status;
1638 static int acer_wmi_enable_ec_raw(void)
1640 struct lm_return_value return_value;
1641 acpi_status status;
1642 struct lm_input_params params = {
1643 .function_num = 0x1,
1644 .commun_devices = 0xFFFF,
1645 .devices = 0xFFFF,
1646 .lm_status = 0x00, /* Launch Manager Deactive */
1649 status = wmid3_set_lm_mode(&params, &return_value);
1651 if (return_value.error_code || return_value.ec_return_value)
1652 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1653 return_value.error_code,
1654 return_value.ec_return_value);
1655 else
1656 pr_info("Enabled EC raw mode\n");
1658 return status;
1661 static int acer_wmi_enable_lm(void)
1663 struct lm_return_value return_value;
1664 acpi_status status;
1665 struct lm_input_params params = {
1666 .function_num = 0x1,
1667 .commun_devices = 0xFFFF,
1668 .devices = 0xFFFF,
1669 .lm_status = 0x01, /* Launch Manager Active */
1672 status = wmid3_set_lm_mode(&params, &return_value);
1674 if (return_value.error_code || return_value.ec_return_value)
1675 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1676 return_value.error_code,
1677 return_value.ec_return_value);
1679 return status;
1682 static int __init acer_wmi_input_setup(void)
1684 acpi_status status;
1685 int err;
1687 acer_wmi_input_dev = input_allocate_device();
1688 if (!acer_wmi_input_dev)
1689 return -ENOMEM;
1691 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1692 acer_wmi_input_dev->phys = "wmi/input0";
1693 acer_wmi_input_dev->id.bustype = BUS_HOST;
1695 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1696 if (err)
1697 goto err_free_dev;
1699 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1700 acer_wmi_notify, NULL);
1701 if (ACPI_FAILURE(status)) {
1702 err = -EIO;
1703 goto err_free_keymap;
1706 err = input_register_device(acer_wmi_input_dev);
1707 if (err)
1708 goto err_uninstall_notifier;
1710 return 0;
1712 err_uninstall_notifier:
1713 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1714 err_free_keymap:
1715 sparse_keymap_free(acer_wmi_input_dev);
1716 err_free_dev:
1717 input_free_device(acer_wmi_input_dev);
1718 return err;
1721 static void acer_wmi_input_destroy(void)
1723 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1724 sparse_keymap_free(acer_wmi_input_dev);
1725 input_unregister_device(acer_wmi_input_dev);
1729 * debugfs functions
1731 static u32 get_wmid_devices(void)
1733 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1734 union acpi_object *obj;
1735 acpi_status status;
1736 u32 devices = 0;
1738 status = wmi_query_block(WMID_GUID2, 1, &out);
1739 if (ACPI_FAILURE(status))
1740 return 0;
1742 obj = (union acpi_object *) out.pointer;
1743 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1744 (obj->buffer.length == sizeof(u32) ||
1745 obj->buffer.length == sizeof(u64))) {
1746 devices = *((u32 *) obj->buffer.pointer);
1747 } else if (obj->type == ACPI_TYPE_INTEGER) {
1748 devices = (u32) obj->integer.value;
1751 kfree(out.pointer);
1752 return devices;
1756 * Platform device
1758 static int __devinit acer_platform_probe(struct platform_device *device)
1760 int err;
1762 if (has_cap(ACER_CAP_MAILLED)) {
1763 err = acer_led_init(&device->dev);
1764 if (err)
1765 goto error_mailled;
1768 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1769 err = acer_backlight_init(&device->dev);
1770 if (err)
1771 goto error_brightness;
1774 err = acer_rfkill_init(&device->dev);
1775 if (err)
1776 goto error_rfkill;
1778 return err;
1780 error_rfkill:
1781 if (has_cap(ACER_CAP_BRIGHTNESS))
1782 acer_backlight_exit();
1783 error_brightness:
1784 if (has_cap(ACER_CAP_MAILLED))
1785 acer_led_exit();
1786 error_mailled:
1787 return err;
1790 static int acer_platform_remove(struct platform_device *device)
1792 if (has_cap(ACER_CAP_MAILLED))
1793 acer_led_exit();
1794 if (has_cap(ACER_CAP_BRIGHTNESS))
1795 acer_backlight_exit();
1797 acer_rfkill_exit();
1798 return 0;
1801 static int acer_platform_suspend(struct platform_device *dev,
1802 pm_message_t state)
1804 u32 value;
1805 struct acer_data *data = &interface->data;
1807 if (!data)
1808 return -ENOMEM;
1810 if (has_cap(ACER_CAP_MAILLED)) {
1811 get_u32(&value, ACER_CAP_MAILLED);
1812 set_u32(LED_OFF, ACER_CAP_MAILLED);
1813 data->mailled = value;
1816 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1817 get_u32(&value, ACER_CAP_BRIGHTNESS);
1818 data->brightness = value;
1821 return 0;
1824 static int acer_platform_resume(struct platform_device *device)
1826 struct acer_data *data = &interface->data;
1828 if (!data)
1829 return -ENOMEM;
1831 if (has_cap(ACER_CAP_MAILLED))
1832 set_u32(data->mailled, ACER_CAP_MAILLED);
1834 if (has_cap(ACER_CAP_BRIGHTNESS))
1835 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1837 return 0;
1840 static void acer_platform_shutdown(struct platform_device *device)
1842 struct acer_data *data = &interface->data;
1844 if (!data)
1845 return;
1847 if (has_cap(ACER_CAP_MAILLED))
1848 set_u32(LED_OFF, ACER_CAP_MAILLED);
1851 static struct platform_driver acer_platform_driver = {
1852 .driver = {
1853 .name = "acer-wmi",
1854 .owner = THIS_MODULE,
1856 .probe = acer_platform_probe,
1857 .remove = acer_platform_remove,
1858 .suspend = acer_platform_suspend,
1859 .resume = acer_platform_resume,
1860 .shutdown = acer_platform_shutdown,
1863 static struct platform_device *acer_platform_device;
1865 static int remove_sysfs(struct platform_device *device)
1867 if (has_cap(ACER_CAP_THREEG))
1868 device_remove_file(&device->dev, &dev_attr_threeg);
1870 device_remove_file(&device->dev, &dev_attr_interface);
1872 return 0;
1875 static int create_sysfs(void)
1877 int retval = -ENOMEM;
1879 if (has_cap(ACER_CAP_THREEG)) {
1880 retval = device_create_file(&acer_platform_device->dev,
1881 &dev_attr_threeg);
1882 if (retval)
1883 goto error_sysfs;
1886 retval = device_create_file(&acer_platform_device->dev,
1887 &dev_attr_interface);
1888 if (retval)
1889 goto error_sysfs;
1891 return 0;
1893 error_sysfs:
1894 remove_sysfs(acer_platform_device);
1895 return retval;
1898 static void remove_debugfs(void)
1900 debugfs_remove(interface->debug.devices);
1901 debugfs_remove(interface->debug.root);
1904 static int create_debugfs(void)
1906 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1907 if (!interface->debug.root) {
1908 pr_err("Failed to create debugfs directory");
1909 return -ENOMEM;
1912 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1913 interface->debug.root,
1914 &interface->debug.wmid_devices);
1915 if (!interface->debug.devices)
1916 goto error_debugfs;
1918 return 0;
1920 error_debugfs:
1921 remove_debugfs();
1922 return -ENOMEM;
1925 static int __init acer_wmi_init(void)
1927 int err;
1929 pr_info("Acer Laptop ACPI-WMI Extras\n");
1931 if (dmi_check_system(acer_blacklist)) {
1932 pr_info("Blacklisted hardware detected - not loading\n");
1933 return -ENODEV;
1936 find_quirks();
1939 * Detect which ACPI-WMI interface we're using.
1941 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1942 interface = &AMW0_V2_interface;
1944 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1945 interface = &wmid_interface;
1947 if (wmi_has_guid(WMID_GUID3))
1948 interface = &wmid_v2_interface;
1950 if (interface)
1951 dmi_walk(type_aa_dmi_decode, NULL);
1953 if (wmi_has_guid(WMID_GUID2) && interface) {
1954 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
1955 pr_err("Unable to detect available WMID devices\n");
1956 return -ENODEV;
1958 /* WMID always provides brightness methods */
1959 interface->capability |= ACER_CAP_BRIGHTNESS;
1960 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
1961 pr_err("No WMID device detection method found\n");
1962 return -ENODEV;
1965 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1966 interface = &AMW0_interface;
1968 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1969 pr_err("Unable to detect available AMW0 devices\n");
1970 return -ENODEV;
1974 if (wmi_has_guid(AMW0_GUID1))
1975 AMW0_find_mailled();
1977 if (!interface) {
1978 pr_err("No or unsupported WMI interface, unable to load\n");
1979 return -ENODEV;
1982 set_quirks();
1984 if (acpi_video_backlight_support()) {
1985 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1986 pr_info("Brightness must be controlled by "
1987 "generic video driver\n");
1990 if (wmi_has_guid(WMID_GUID3)) {
1991 if (ec_raw_mode) {
1992 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
1993 pr_err("Cannot enable EC raw mode\n");
1994 return -ENODEV;
1996 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
1997 pr_err("Cannot enable Launch Manager mode\n");
1998 return -ENODEV;
2000 } else if (ec_raw_mode) {
2001 pr_info("No WMID EC raw mode enable method\n");
2004 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2005 err = acer_wmi_input_setup();
2006 if (err)
2007 return err;
2010 err = platform_driver_register(&acer_platform_driver);
2011 if (err) {
2012 pr_err("Unable to register platform driver.\n");
2013 goto error_platform_register;
2016 acer_platform_device = platform_device_alloc("acer-wmi", -1);
2017 if (!acer_platform_device) {
2018 err = -ENOMEM;
2019 goto error_device_alloc;
2022 err = platform_device_add(acer_platform_device);
2023 if (err)
2024 goto error_device_add;
2026 err = create_sysfs();
2027 if (err)
2028 goto error_create_sys;
2030 if (wmi_has_guid(WMID_GUID2)) {
2031 interface->debug.wmid_devices = get_wmid_devices();
2032 err = create_debugfs();
2033 if (err)
2034 goto error_create_debugfs;
2037 /* Override any initial settings with values from the commandline */
2038 acer_commandline_init();
2040 return 0;
2042 error_create_debugfs:
2043 remove_sysfs(acer_platform_device);
2044 error_create_sys:
2045 platform_device_del(acer_platform_device);
2046 error_device_add:
2047 platform_device_put(acer_platform_device);
2048 error_device_alloc:
2049 platform_driver_unregister(&acer_platform_driver);
2050 error_platform_register:
2051 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2052 acer_wmi_input_destroy();
2054 return err;
2057 static void __exit acer_wmi_exit(void)
2059 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2060 acer_wmi_input_destroy();
2062 remove_sysfs(acer_platform_device);
2063 remove_debugfs();
2064 platform_device_unregister(acer_platform_device);
2065 platform_driver_unregister(&acer_platform_driver);
2067 pr_info("Acer Laptop WMI Extras unloaded\n");
2068 return;
2071 module_init(acer_wmi_init);
2072 module_exit(acer_wmi_exit);