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>
47 MODULE_AUTHOR("Carlos Corbacho");
48 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
49 MODULE_LICENSE("GPL");
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
, 0x12, {KEY_BLUETOOTH
} }, /* BT */
103 {KE_KEY
, 0x21, {KEY_PROG1
} }, /* Backup */
104 {KE_KEY
, 0x22, {KEY_PROG2
} }, /* Arcade */
105 {KE_KEY
, 0x23, {KEY_PROG3
} }, /* P_Key */
106 {KE_KEY
, 0x24, {KEY_PROG4
} }, /* Social networking_Key */
107 {KE_IGNORE
, 0x41, {KEY_MUTE
} },
108 {KE_IGNORE
, 0x42, {KEY_PREVIOUSSONG
} },
109 {KE_IGNORE
, 0x43, {KEY_NEXTSONG
} },
110 {KE_IGNORE
, 0x44, {KEY_PLAYPAUSE
} },
111 {KE_IGNORE
, 0x45, {KEY_STOP
} },
112 {KE_IGNORE
, 0x48, {KEY_VOLUMEUP
} },
113 {KE_IGNORE
, 0x49, {KEY_VOLUMEDOWN
} },
114 {KE_IGNORE
, 0x61, {KEY_SWITCHVIDEOMODE
} },
115 {KE_IGNORE
, 0x62, {KEY_BRIGHTNESSUP
} },
116 {KE_IGNORE
, 0x63, {KEY_BRIGHTNESSDOWN
} },
117 {KE_KEY
, 0x64, {KEY_SWITCHVIDEOMODE
} }, /* Display Switch */
118 {KE_IGNORE
, 0x81, {KEY_SLEEP
} },
119 {KE_KEY
, 0x82, {KEY_TOUCHPAD_TOGGLE
} }, /* Touch Pad On/Off */
120 {KE_IGNORE
, 0x83, {KEY_TOUCHPAD_TOGGLE
} },
124 static struct input_dev
*acer_wmi_input_dev
;
126 struct event_return_value
{
131 } __attribute__((packed
));
134 * GUID3 Get Device Status device flags
136 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
137 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
138 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
139 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
141 struct lm_input_params
{
142 u8 function_num
; /* Function Number */
143 u16 commun_devices
; /* Communication type devices default status */
144 u16 devices
; /* Other type devices default status */
145 u8 lm_status
; /* Launch Manager Status */
147 } __attribute__((packed
));
149 struct lm_return_value
{
150 u8 error_code
; /* Error Code */
151 u8 ec_return_value
; /* EC Return Value */
153 } __attribute__((packed
));
155 struct wmid3_gds_input_param
{ /* Get Device Status input parameter */
156 u8 function_num
; /* Function Number */
157 u8 hotkey_number
; /* Hotkey Number */
158 u16 devices
; /* Get Device */
159 } __attribute__((packed
));
161 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
162 u8 error_code
; /* Error Code */
163 u8 ec_return_value
; /* EC Return Value */
164 u16 devices
; /* Current Device Status */
166 } __attribute__((packed
));
168 struct hotkey_function_type_aa
{
172 u16 commun_func_bitmap
;
173 } __attribute__((packed
));
176 * Interface capability flags
178 #define ACER_CAP_MAILLED (1<<0)
179 #define ACER_CAP_WIRELESS (1<<1)
180 #define ACER_CAP_BLUETOOTH (1<<2)
181 #define ACER_CAP_BRIGHTNESS (1<<3)
182 #define ACER_CAP_THREEG (1<<4)
183 #define ACER_CAP_ANY (0xFFFFFFFF)
186 * Interface type flags
188 enum interface_flags
{
194 #define ACER_DEFAULT_WIRELESS 0
195 #define ACER_DEFAULT_BLUETOOTH 0
196 #define ACER_DEFAULT_MAILLED 0
197 #define ACER_DEFAULT_THREEG 0
199 static int max_brightness
= 0xF;
201 static int mailled
= -1;
202 static int brightness
= -1;
203 static int threeg
= -1;
204 static int force_series
;
205 static bool ec_raw_mode
;
206 static bool has_type_aa
;
208 module_param(mailled
, int, 0444);
209 module_param(brightness
, int, 0444);
210 module_param(threeg
, int, 0444);
211 module_param(force_series
, int, 0444);
212 module_param(ec_raw_mode
, bool, 0444);
213 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
214 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
215 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
216 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
217 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
227 struct dentry
*devices
;
231 static struct rfkill
*wireless_rfkill
;
232 static struct rfkill
*bluetooth_rfkill
;
233 static struct rfkill
*threeg_rfkill
;
234 static bool rfkill_inited
;
236 /* Each low-level interface must define at least some of the following */
237 struct wmi_interface
{
238 /* The WMI device type */
241 /* The capabilities this interface provides */
244 /* Private data for the current interface */
245 struct acer_data data
;
247 /* debugfs entries associated with this interface */
248 struct acer_debug debug
;
251 /* The static interface pointer, points to the currently detected interface */
252 static struct wmi_interface
*interface
;
255 * Embedded Controller quirks
256 * Some laptops require us to directly access the EC to either enable or query
257 * features that are not available through WMI.
267 static struct quirk_entry
*quirks
;
269 static void set_quirks(void)
275 interface
->capability
|= ACER_CAP_MAILLED
;
277 if (quirks
->brightness
)
278 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
281 static int dmi_matched(const struct dmi_system_id
*dmi
)
283 quirks
= dmi
->driver_data
;
287 static struct quirk_entry quirk_unknown
= {
290 static struct quirk_entry quirk_acer_aspire_1520
= {
294 static struct quirk_entry quirk_acer_travelmate_2490
= {
298 /* This AMW0 laptop has no bluetooth */
299 static struct quirk_entry quirk_medion_md_98300
= {
303 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
307 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
311 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
312 static struct dmi_system_id __devinitdata acer_blacklist
[] = {
314 .ident
= "Acer Aspire One (SSD)",
316 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
317 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
321 .ident
= "Acer Aspire One (HDD)",
323 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
324 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
330 static struct dmi_system_id acer_quirks
[] = {
332 .callback
= dmi_matched
,
333 .ident
= "Acer Aspire 1360",
335 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
336 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
338 .driver_data
= &quirk_acer_aspire_1520
,
341 .callback
= dmi_matched
,
342 .ident
= "Acer Aspire 1520",
344 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
345 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
347 .driver_data
= &quirk_acer_aspire_1520
,
350 .callback
= dmi_matched
,
351 .ident
= "Acer Aspire 3100",
353 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
354 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
356 .driver_data
= &quirk_acer_travelmate_2490
,
359 .callback
= dmi_matched
,
360 .ident
= "Acer Aspire 3610",
362 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
363 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
365 .driver_data
= &quirk_acer_travelmate_2490
,
368 .callback
= dmi_matched
,
369 .ident
= "Acer Aspire 5100",
371 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
372 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
374 .driver_data
= &quirk_acer_travelmate_2490
,
377 .callback
= dmi_matched
,
378 .ident
= "Acer Aspire 5610",
380 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
381 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
383 .driver_data
= &quirk_acer_travelmate_2490
,
386 .callback
= dmi_matched
,
387 .ident
= "Acer Aspire 5630",
389 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
390 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
392 .driver_data
= &quirk_acer_travelmate_2490
,
395 .callback
= dmi_matched
,
396 .ident
= "Acer Aspire 5650",
398 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
399 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
401 .driver_data
= &quirk_acer_travelmate_2490
,
404 .callback
= dmi_matched
,
405 .ident
= "Acer Aspire 5680",
407 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
408 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
410 .driver_data
= &quirk_acer_travelmate_2490
,
413 .callback
= dmi_matched
,
414 .ident
= "Acer Aspire 9110",
416 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
417 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
419 .driver_data
= &quirk_acer_travelmate_2490
,
422 .callback
= dmi_matched
,
423 .ident
= "Acer TravelMate 2490",
425 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
426 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
428 .driver_data
= &quirk_acer_travelmate_2490
,
431 .callback
= dmi_matched
,
432 .ident
= "Acer TravelMate 4200",
434 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
435 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
437 .driver_data
= &quirk_acer_travelmate_2490
,
440 .callback
= dmi_matched
,
441 .ident
= "Fujitsu Siemens Amilo Li 1718",
443 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
444 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
446 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
449 .callback
= dmi_matched
,
450 .ident
= "Medion MD 98300",
452 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
453 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
455 .driver_data
= &quirk_medion_md_98300
,
458 .callback
= dmi_matched
,
459 .ident
= "Lenovo Ideapad S205",
461 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
462 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
464 .driver_data
= &quirk_lenovo_ideapad_s205
,
467 .callback
= dmi_matched
,
468 .ident
= "Lenovo 3000 N200",
470 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
471 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
473 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
478 /* Find which quirks are needed for a particular vendor/ model pair */
479 static void find_quirks(void)
482 dmi_check_system(acer_quirks
);
483 } else if (force_series
== 2490) {
484 quirks
= &quirk_acer_travelmate_2490
;
488 quirks
= &quirk_unknown
;
494 * General interface convenience methods
497 static bool has_cap(u32 cap
)
499 if ((interface
->capability
& cap
) != 0)
506 * AMW0 (V1) interface
523 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
524 struct acpi_buffer
*result
)
526 struct acpi_buffer input
;
528 input
.length
= sizeof(struct wmab_args
);
529 input
.pointer
= (u8
*)regbuf
;
531 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
536 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
,
537 struct wmi_interface
*iface
)
543 case ACER_CAP_MAILLED
:
544 switch (quirks
->mailled
) {
546 err
= ec_read(0xA, &result
);
549 *value
= (result
>> 7) & 0x1;
553 case ACER_CAP_WIRELESS
:
554 switch (quirks
->wireless
) {
556 err
= ec_read(0x7B, &result
);
559 *value
= result
& 0x1;
562 err
= ec_read(0x71, &result
);
565 *value
= result
& 0x1;
568 err
= ec_read(0x78, &result
);
571 *value
= result
& 0x1;
574 err
= ec_read(0xA, &result
);
577 *value
= (result
>> 2) & 0x1;
581 case ACER_CAP_BLUETOOTH
:
582 switch (quirks
->bluetooth
) {
584 err
= ec_read(0xA, &result
);
587 *value
= (result
>> 4) & 0x1;
591 case ACER_CAP_BRIGHTNESS
:
592 switch (quirks
->brightness
) {
594 err
= ec_read(0x83, &result
);
607 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
609 struct wmab_args args
;
611 args
.eax
= ACER_AMW0_WRITE
;
612 args
.ebx
= value
? (1<<8) : 0;
613 args
.ecx
= args
.edx
= 0;
616 case ACER_CAP_MAILLED
:
618 return AE_BAD_PARAMETER
;
619 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
621 case ACER_CAP_WIRELESS
:
623 return AE_BAD_PARAMETER
;
624 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
626 case ACER_CAP_BLUETOOTH
:
628 return AE_BAD_PARAMETER
;
629 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
631 case ACER_CAP_BRIGHTNESS
:
632 if (value
> max_brightness
)
633 return AE_BAD_PARAMETER
;
634 switch (quirks
->brightness
) {
636 return ec_write(0x83, value
);
643 /* Actually do the set */
644 return wmab_execute(&args
, NULL
);
647 static acpi_status
AMW0_find_mailled(void)
649 struct wmab_args args
;
651 acpi_status status
= AE_OK
;
652 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
653 union acpi_object
*obj
;
656 args
.ebx
= args
.ecx
= args
.edx
= 0;
658 status
= wmab_execute(&args
, &out
);
659 if (ACPI_FAILURE(status
))
662 obj
= (union acpi_object
*) out
.pointer
;
663 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
664 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
665 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
672 interface
->capability
|= ACER_CAP_MAILLED
;
679 static int AMW0_set_cap_acpi_check_device_found
;
681 static acpi_status
AMW0_set_cap_acpi_check_device_cb(acpi_handle handle
,
682 u32 level
, void *context
, void **retval
)
684 AMW0_set_cap_acpi_check_device_found
= 1;
688 static const struct acpi_device_id norfkill_ids
[] = {
692 { "SNY5001", 0}, /* sony-laptop in charge */
696 static int AMW0_set_cap_acpi_check_device(void)
698 const struct acpi_device_id
*id
;
700 for (id
= norfkill_ids
; id
->id
[0]; id
++)
701 acpi_get_devices(id
->id
, AMW0_set_cap_acpi_check_device_cb
,
703 return AMW0_set_cap_acpi_check_device_found
;
706 static acpi_status
AMW0_set_capabilities(void)
708 struct wmab_args args
;
711 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
712 union acpi_object
*obj
;
715 * On laptops with this strange GUID (non Acer), normal probing doesn't
718 if (wmi_has_guid(AMW0_GUID2
)) {
719 if ((quirks
!= &quirk_unknown
) ||
720 !AMW0_set_cap_acpi_check_device())
721 interface
->capability
|= ACER_CAP_WIRELESS
;
725 args
.eax
= ACER_AMW0_WRITE
;
726 args
.ecx
= args
.edx
= 0;
728 args
.ebx
= 0xa2 << 8;
729 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
731 status
= wmab_execute(&args
, &out
);
732 if (ACPI_FAILURE(status
))
736 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
737 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
738 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
745 interface
->capability
|= ACER_CAP_WIRELESS
;
748 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
751 * It's ok to use existing buffer for next wmab_execute call.
752 * But we need to kfree(out.pointer) if next wmab_execute fail.
754 status
= wmab_execute(&args
, &out
);
755 if (ACPI_FAILURE(status
))
758 obj
= (union acpi_object
*) out
.pointer
;
759 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
760 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
761 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
768 interface
->capability
|= ACER_CAP_BLUETOOTH
;
771 * This appears to be safe to enable, since all Wistron based laptops
772 * appear to use the same EC register for brightness, even if they
773 * differ for wireless, etc
775 if (quirks
->brightness
>= 0)
776 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
784 static struct wmi_interface AMW0_interface
= {
788 static struct wmi_interface AMW0_V2_interface
= {
789 .type
= ACER_AMW0_V2
,
793 * New interface (The WMID interface)
796 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
798 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
799 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
800 union acpi_object
*obj
;
804 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
806 if (ACPI_FAILURE(status
))
809 obj
= (union acpi_object
*) result
.pointer
;
810 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
811 (obj
->buffer
.length
== sizeof(u32
) ||
812 obj
->buffer
.length
== sizeof(u64
))) {
813 tmp
= *((u32
*) obj
->buffer
.pointer
);
814 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
815 tmp
= (u32
) obj
->integer
.value
;
823 kfree(result
.pointer
);
828 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
,
829 struct wmi_interface
*iface
)
833 u32 result
, method_id
= 0;
836 case ACER_CAP_WIRELESS
:
837 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
839 case ACER_CAP_BLUETOOTH
:
840 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
842 case ACER_CAP_BRIGHTNESS
:
843 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
845 case ACER_CAP_THREEG
:
846 method_id
= ACER_WMID_GET_THREEG_METHODID
;
848 case ACER_CAP_MAILLED
:
849 if (quirks
->mailled
== 1) {
857 status
= WMI_execute_u32(method_id
, 0, &result
);
859 if (ACPI_SUCCESS(status
))
865 static acpi_status
WMID_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
871 case ACER_CAP_BRIGHTNESS
:
872 if (value
> max_brightness
)
873 return AE_BAD_PARAMETER
;
874 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
876 case ACER_CAP_WIRELESS
:
878 return AE_BAD_PARAMETER
;
879 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
881 case ACER_CAP_BLUETOOTH
:
883 return AE_BAD_PARAMETER
;
884 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
886 case ACER_CAP_THREEG
:
888 return AE_BAD_PARAMETER
;
889 method_id
= ACER_WMID_SET_THREEG_METHODID
;
891 case ACER_CAP_MAILLED
:
893 return AE_BAD_PARAMETER
;
894 if (quirks
->mailled
== 1) {
895 param
= value
? 0x92 : 0x93;
897 i8042_command(¶m
, 0x1059);
905 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
908 static void type_aa_dmi_decode(const struct dmi_header
*header
, void *dummy
)
910 struct hotkey_function_type_aa
*type_aa
;
912 /* We are looking for OEM-specific Type AAh */
913 if (header
->type
!= 0xAA)
917 type_aa
= (struct hotkey_function_type_aa
*) header
;
919 pr_info("Function bitmap for Communication Button: 0x%x\n",
920 type_aa
->commun_func_bitmap
);
922 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
923 interface
->capability
|= ACER_CAP_WIRELESS
;
924 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
925 interface
->capability
|= ACER_CAP_THREEG
;
926 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
927 interface
->capability
|= ACER_CAP_BLUETOOTH
;
930 static acpi_status
WMID_set_capabilities(void)
932 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
933 union acpi_object
*obj
;
937 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
938 if (ACPI_FAILURE(status
))
941 obj
= (union acpi_object
*) out
.pointer
;
942 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
943 (obj
->buffer
.length
== sizeof(u32
) ||
944 obj
->buffer
.length
== sizeof(u64
))) {
945 devices
= *((u32
*) obj
->buffer
.pointer
);
946 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
947 devices
= (u32
) obj
->integer
.value
;
953 dmi_walk(type_aa_dmi_decode
, NULL
);
955 interface
->capability
|= ACER_CAP_WIRELESS
;
957 interface
->capability
|= ACER_CAP_THREEG
;
959 interface
->capability
|= ACER_CAP_BLUETOOTH
;
962 /* WMID always provides brightness methods */
963 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
965 if (!(devices
& 0x20))
966 max_brightness
= 0x9;
972 static struct wmi_interface wmid_interface
= {
977 * Generic Device (interface-independent)
980 static acpi_status
get_u32(u32
*value
, u32 cap
)
982 acpi_status status
= AE_ERROR
;
984 switch (interface
->type
) {
986 status
= AMW0_get_u32(value
, cap
, interface
);
989 if (cap
== ACER_CAP_MAILLED
) {
990 status
= AMW0_get_u32(value
, cap
, interface
);
994 status
= WMID_get_u32(value
, cap
, interface
);
1001 static acpi_status
set_u32(u32 value
, u32 cap
)
1005 if (interface
->capability
& cap
) {
1006 switch (interface
->type
) {
1008 return AMW0_set_u32(value
, cap
, interface
);
1010 if (cap
== ACER_CAP_MAILLED
)
1011 return AMW0_set_u32(value
, cap
, interface
);
1014 * On some models, some WMID methods don't toggle
1015 * properly. For those cases, we want to run the AMW0
1016 * method afterwards to be certain we've really toggled
1019 if (cap
== ACER_CAP_WIRELESS
||
1020 cap
== ACER_CAP_BLUETOOTH
) {
1021 status
= WMID_set_u32(value
, cap
, interface
);
1022 if (ACPI_FAILURE(status
))
1025 return AMW0_set_u32(value
, cap
, interface
);
1028 return WMID_set_u32(value
, cap
, interface
);
1030 return AE_BAD_PARAMETER
;
1033 return AE_BAD_PARAMETER
;
1036 static void __init
acer_commandline_init(void)
1039 * These will all fail silently if the value given is invalid, or the
1040 * capability isn't available on the given interface
1043 set_u32(mailled
, ACER_CAP_MAILLED
);
1044 if (!has_type_aa
&& threeg
>= 0)
1045 set_u32(threeg
, ACER_CAP_THREEG
);
1046 if (brightness
>= 0)
1047 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1051 * LED device (Mail LED only, no other LEDs known yet)
1053 static void mail_led_set(struct led_classdev
*led_cdev
,
1054 enum led_brightness value
)
1056 set_u32(value
, ACER_CAP_MAILLED
);
1059 static struct led_classdev mail_led
= {
1060 .name
= "acer-wmi::mail",
1061 .brightness_set
= mail_led_set
,
1064 static int __devinit
acer_led_init(struct device
*dev
)
1066 return led_classdev_register(dev
, &mail_led
);
1069 static void acer_led_exit(void)
1071 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1072 led_classdev_unregister(&mail_led
);
1078 static struct backlight_device
*acer_backlight_device
;
1080 static int read_brightness(struct backlight_device
*bd
)
1083 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1087 static int update_bl_status(struct backlight_device
*bd
)
1089 int intensity
= bd
->props
.brightness
;
1091 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1093 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1096 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1101 static const struct backlight_ops acer_bl_ops
= {
1102 .get_brightness
= read_brightness
,
1103 .update_status
= update_bl_status
,
1106 static int __devinit
acer_backlight_init(struct device
*dev
)
1108 struct backlight_properties props
;
1109 struct backlight_device
*bd
;
1111 memset(&props
, 0, sizeof(struct backlight_properties
));
1112 props
.type
= BACKLIGHT_PLATFORM
;
1113 props
.max_brightness
= max_brightness
;
1114 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1117 pr_err("Could not register Acer backlight device\n");
1118 acer_backlight_device
= NULL
;
1122 acer_backlight_device
= bd
;
1124 bd
->props
.power
= FB_BLANK_UNBLANK
;
1125 bd
->props
.brightness
= read_brightness(bd
);
1126 backlight_update_status(bd
);
1130 static void acer_backlight_exit(void)
1132 backlight_device_unregister(acer_backlight_device
);
1135 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1137 struct wmid3_gds_return_value return_value
;
1139 union acpi_object
*obj
;
1140 struct wmid3_gds_input_param params
= {
1141 .function_num
= 0x1,
1142 .hotkey_number
= 0x01,
1145 struct acpi_buffer input
= {
1146 sizeof(struct wmid3_gds_input_param
),
1149 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1151 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1152 if (ACPI_FAILURE(status
))
1155 obj
= output
.pointer
;
1159 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1163 if (obj
->buffer
.length
!= 8) {
1164 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1169 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1172 if (return_value
.error_code
|| return_value
.ec_return_value
)
1173 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1174 return_value
.error_code
,
1175 return_value
.ec_return_value
);
1177 *value
= !!(return_value
.devices
& device
);
1182 static acpi_status
get_device_status(u32
*value
, u32 cap
)
1184 if (wmi_has_guid(WMID_GUID3
)) {
1188 case ACER_CAP_WIRELESS
:
1189 device
= ACER_WMID3_GDS_WIRELESS
;
1191 case ACER_CAP_BLUETOOTH
:
1192 device
= ACER_WMID3_GDS_BLUETOOTH
;
1194 case ACER_CAP_THREEG
:
1195 device
= ACER_WMID3_GDS_THREEG
;
1200 return wmid3_get_device_status(value
, device
);
1203 return get_u32(value
, cap
);
1207 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1209 struct wmid3_gds_return_value return_value
;
1211 union acpi_object
*obj
;
1213 struct wmid3_gds_input_param params
= {
1214 .function_num
= 0x1,
1215 .hotkey_number
= 0x01,
1216 .devices
= ACER_WMID3_GDS_WIRELESS
|
1217 ACER_WMID3_GDS_THREEG
|
1218 ACER_WMID3_GDS_WIMAX
|
1219 ACER_WMID3_GDS_BLUETOOTH
,
1221 struct acpi_buffer input
= {
1222 sizeof(struct wmid3_gds_input_param
),
1225 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1226 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1228 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1229 if (ACPI_FAILURE(status
))
1232 obj
= output
.pointer
;
1236 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1240 if (obj
->buffer
.length
!= 8) {
1241 pr_warning("Unknown buffer length %d\n", obj
->buffer
.length
);
1246 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1249 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1250 pr_warning("Get Current Device Status failed: "
1251 "0x%x - 0x%x\n", return_value
.error_code
,
1252 return_value
.ec_return_value
);
1256 devices
= return_value
.devices
;
1257 params
.function_num
= 0x2;
1258 params
.hotkey_number
= 0x01;
1259 params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1261 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output2
);
1262 if (ACPI_FAILURE(status
))
1265 obj
= output2
.pointer
;
1269 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1273 if (obj
->buffer
.length
!= 4) {
1274 pr_warning("Unknown buffer length %d\n", obj
->buffer
.length
);
1279 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1282 if (return_value
.error_code
|| return_value
.ec_return_value
)
1283 pr_warning("Set Device Status failed: "
1284 "0x%x - 0x%x\n", return_value
.error_code
,
1285 return_value
.ec_return_value
);
1290 static acpi_status
set_device_status(u32 value
, u32 cap
)
1292 if (wmi_has_guid(WMID_GUID3
)) {
1296 case ACER_CAP_WIRELESS
:
1297 device
= ACER_WMID3_GDS_WIRELESS
;
1299 case ACER_CAP_BLUETOOTH
:
1300 device
= ACER_WMID3_GDS_BLUETOOTH
;
1302 case ACER_CAP_THREEG
:
1303 device
= ACER_WMID3_GDS_THREEG
;
1308 return wmid3_set_device_status(value
, device
);
1311 return set_u32(value
, cap
);
1318 static void acer_rfkill_update(struct work_struct
*ignored
);
1319 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1320 static void acer_rfkill_update(struct work_struct
*ignored
)
1325 if (has_cap(ACER_CAP_WIRELESS
)) {
1326 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1327 if (ACPI_SUCCESS(status
)) {
1328 if (quirks
->wireless
== 3)
1329 rfkill_set_hw_state(wireless_rfkill
, !state
);
1331 rfkill_set_sw_state(wireless_rfkill
, !state
);
1335 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1336 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1337 if (ACPI_SUCCESS(status
))
1338 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1341 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1342 status
= wmid3_get_device_status(&state
,
1343 ACER_WMID3_GDS_THREEG
);
1344 if (ACPI_SUCCESS(status
))
1345 rfkill_set_sw_state(threeg_rfkill
, !state
);
1348 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1351 static int acer_rfkill_set(void *data
, bool blocked
)
1354 u32 cap
= (unsigned long)data
;
1356 if (rfkill_inited
) {
1357 status
= set_device_status(!blocked
, cap
);
1358 if (ACPI_FAILURE(status
))
1365 static const struct rfkill_ops acer_rfkill_ops
= {
1366 .set_block
= acer_rfkill_set
,
1369 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1370 enum rfkill_type type
,
1371 char *name
, u32 cap
)
1374 struct rfkill
*rfkill_dev
;
1378 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1380 (void *)(unsigned long)cap
);
1382 return ERR_PTR(-ENOMEM
);
1384 status
= get_device_status(&state
, cap
);
1386 err
= rfkill_register(rfkill_dev
);
1388 rfkill_destroy(rfkill_dev
);
1389 return ERR_PTR(err
);
1392 if (ACPI_SUCCESS(status
))
1393 rfkill_set_sw_state(rfkill_dev
, !state
);
1398 static int acer_rfkill_init(struct device
*dev
)
1402 if (has_cap(ACER_CAP_WIRELESS
)) {
1403 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1404 "acer-wireless", ACER_CAP_WIRELESS
);
1405 if (IS_ERR(wireless_rfkill
)) {
1406 err
= PTR_ERR(wireless_rfkill
);
1407 goto error_wireless
;
1411 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1412 bluetooth_rfkill
= acer_rfkill_register(dev
,
1413 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1414 ACER_CAP_BLUETOOTH
);
1415 if (IS_ERR(bluetooth_rfkill
)) {
1416 err
= PTR_ERR(bluetooth_rfkill
);
1417 goto error_bluetooth
;
1421 if (has_cap(ACER_CAP_THREEG
)) {
1422 threeg_rfkill
= acer_rfkill_register(dev
,
1423 RFKILL_TYPE_WWAN
, "acer-threeg",
1425 if (IS_ERR(threeg_rfkill
)) {
1426 err
= PTR_ERR(threeg_rfkill
);
1431 rfkill_inited
= true;
1433 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1434 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1435 schedule_delayed_work(&acer_rfkill_work
,
1436 round_jiffies_relative(HZ
));
1441 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1442 rfkill_unregister(bluetooth_rfkill
);
1443 rfkill_destroy(bluetooth_rfkill
);
1446 if (has_cap(ACER_CAP_WIRELESS
)) {
1447 rfkill_unregister(wireless_rfkill
);
1448 rfkill_destroy(wireless_rfkill
);
1454 static void acer_rfkill_exit(void)
1456 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1457 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1458 cancel_delayed_work_sync(&acer_rfkill_work
);
1460 if (has_cap(ACER_CAP_WIRELESS
)) {
1461 rfkill_unregister(wireless_rfkill
);
1462 rfkill_destroy(wireless_rfkill
);
1465 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1466 rfkill_unregister(bluetooth_rfkill
);
1467 rfkill_destroy(bluetooth_rfkill
);
1470 if (has_cap(ACER_CAP_THREEG
)) {
1471 rfkill_unregister(threeg_rfkill
);
1472 rfkill_destroy(threeg_rfkill
);
1480 static ssize_t
show_bool_threeg(struct device
*dev
,
1481 struct device_attribute
*attr
, char *buf
)
1485 if (wmi_has_guid(WMID_GUID3
))
1486 status
= wmid3_get_device_status(&result
,
1487 ACER_WMID3_GDS_THREEG
);
1489 status
= get_u32(&result
, ACER_CAP_THREEG
);
1490 if (ACPI_SUCCESS(status
))
1491 return sprintf(buf
, "%u\n", result
);
1492 return sprintf(buf
, "Read error\n");
1495 static ssize_t
set_bool_threeg(struct device
*dev
,
1496 struct device_attribute
*attr
, const char *buf
, size_t count
)
1498 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
1499 acpi_status status
= set_u32(tmp
, ACER_CAP_THREEG
);
1500 if (ACPI_FAILURE(status
))
1504 static DEVICE_ATTR(threeg
, S_IRUGO
| S_IWUSR
, show_bool_threeg
,
1507 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1510 switch (interface
->type
) {
1512 return sprintf(buf
, "AMW0\n");
1514 return sprintf(buf
, "AMW0 v2\n");
1516 return sprintf(buf
, "WMID\n");
1518 return sprintf(buf
, "Error!\n");
1522 static DEVICE_ATTR(interface
, S_IRUGO
, show_interface
, NULL
);
1524 static void acer_wmi_notify(u32 value
, void *context
)
1526 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1527 union acpi_object
*obj
;
1528 struct event_return_value return_value
;
1531 const struct key_entry
*key
;
1533 status
= wmi_get_event_data(value
, &response
);
1534 if (status
!= AE_OK
) {
1535 pr_warn("bad event status 0x%x\n", status
);
1539 obj
= (union acpi_object
*)response
.pointer
;
1543 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1544 pr_warn("Unknown response received %d\n", obj
->type
);
1548 if (obj
->buffer
.length
!= 8) {
1549 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1554 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1557 switch (return_value
.function
) {
1558 case WMID_HOTKEY_EVENT
:
1559 device_state
= return_value
.device_state
;
1560 pr_debug("device state: 0x%x\n", device_state
);
1562 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1563 return_value
.key_num
);
1565 pr_warn("Unknown key number - 0x%x\n",
1566 return_value
.key_num
);
1568 switch (key
->keycode
) {
1571 if (has_cap(ACER_CAP_WIRELESS
))
1572 rfkill_set_sw_state(wireless_rfkill
,
1573 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1574 if (has_cap(ACER_CAP_THREEG
))
1575 rfkill_set_sw_state(threeg_rfkill
,
1576 !(device_state
& ACER_WMID3_GDS_THREEG
));
1577 if (has_cap(ACER_CAP_BLUETOOTH
))
1578 rfkill_set_sw_state(bluetooth_rfkill
,
1579 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1582 sparse_keymap_report_entry(acer_wmi_input_dev
, key
,
1587 pr_warn("Unknown function number - %d - %d\n",
1588 return_value
.function
, return_value
.key_num
);
1594 wmid3_set_lm_mode(struct lm_input_params
*params
,
1595 struct lm_return_value
*return_value
)
1598 union acpi_object
*obj
;
1600 struct acpi_buffer input
= { sizeof(struct lm_input_params
), params
};
1601 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1603 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1604 if (ACPI_FAILURE(status
))
1607 obj
= output
.pointer
;
1611 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1615 if (obj
->buffer
.length
!= 4) {
1616 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1621 *return_value
= *((struct lm_return_value
*)obj
->buffer
.pointer
);
1627 static int acer_wmi_enable_ec_raw(void)
1629 struct lm_return_value return_value
;
1631 struct lm_input_params params
= {
1632 .function_num
= 0x1,
1633 .commun_devices
= 0xFFFF,
1635 .lm_status
= 0x00, /* Launch Manager Deactive */
1638 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1640 if (return_value
.error_code
|| return_value
.ec_return_value
)
1641 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1642 return_value
.error_code
,
1643 return_value
.ec_return_value
);
1645 pr_info("Enabled EC raw mode\n");
1650 static int acer_wmi_enable_lm(void)
1652 struct lm_return_value return_value
;
1654 struct lm_input_params params
= {
1655 .function_num
= 0x1,
1656 .commun_devices
= 0xFFFF,
1658 .lm_status
= 0x01, /* Launch Manager Active */
1661 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1663 if (return_value
.error_code
|| return_value
.ec_return_value
)
1664 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1665 return_value
.error_code
,
1666 return_value
.ec_return_value
);
1671 static int __init
acer_wmi_input_setup(void)
1676 acer_wmi_input_dev
= input_allocate_device();
1677 if (!acer_wmi_input_dev
)
1680 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1681 acer_wmi_input_dev
->phys
= "wmi/input0";
1682 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1684 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1688 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1689 acer_wmi_notify
, NULL
);
1690 if (ACPI_FAILURE(status
)) {
1692 goto err_free_keymap
;
1695 err
= input_register_device(acer_wmi_input_dev
);
1697 goto err_uninstall_notifier
;
1701 err_uninstall_notifier
:
1702 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1704 sparse_keymap_free(acer_wmi_input_dev
);
1706 input_free_device(acer_wmi_input_dev
);
1710 static void acer_wmi_input_destroy(void)
1712 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1713 sparse_keymap_free(acer_wmi_input_dev
);
1714 input_unregister_device(acer_wmi_input_dev
);
1720 static u32
get_wmid_devices(void)
1722 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1723 union acpi_object
*obj
;
1727 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1728 if (ACPI_FAILURE(status
))
1731 obj
= (union acpi_object
*) out
.pointer
;
1732 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1733 (obj
->buffer
.length
== sizeof(u32
) ||
1734 obj
->buffer
.length
== sizeof(u64
))) {
1735 devices
= *((u32
*) obj
->buffer
.pointer
);
1736 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1737 devices
= (u32
) obj
->integer
.value
;
1747 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1751 if (has_cap(ACER_CAP_MAILLED
)) {
1752 err
= acer_led_init(&device
->dev
);
1757 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1758 err
= acer_backlight_init(&device
->dev
);
1760 goto error_brightness
;
1763 err
= acer_rfkill_init(&device
->dev
);
1770 if (has_cap(ACER_CAP_BRIGHTNESS
))
1771 acer_backlight_exit();
1773 if (has_cap(ACER_CAP_MAILLED
))
1779 static int acer_platform_remove(struct platform_device
*device
)
1781 if (has_cap(ACER_CAP_MAILLED
))
1783 if (has_cap(ACER_CAP_BRIGHTNESS
))
1784 acer_backlight_exit();
1790 static int acer_platform_suspend(struct platform_device
*dev
,
1794 struct acer_data
*data
= &interface
->data
;
1799 if (has_cap(ACER_CAP_MAILLED
)) {
1800 get_u32(&value
, ACER_CAP_MAILLED
);
1801 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1802 data
->mailled
= value
;
1805 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1806 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1807 data
->brightness
= value
;
1813 static int acer_platform_resume(struct platform_device
*device
)
1815 struct acer_data
*data
= &interface
->data
;
1820 if (has_cap(ACER_CAP_MAILLED
))
1821 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
1823 if (has_cap(ACER_CAP_BRIGHTNESS
))
1824 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
1829 static void acer_platform_shutdown(struct platform_device
*device
)
1831 struct acer_data
*data
= &interface
->data
;
1836 if (has_cap(ACER_CAP_MAILLED
))
1837 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1840 static struct platform_driver acer_platform_driver
= {
1843 .owner
= THIS_MODULE
,
1845 .probe
= acer_platform_probe
,
1846 .remove
= acer_platform_remove
,
1847 .suspend
= acer_platform_suspend
,
1848 .resume
= acer_platform_resume
,
1849 .shutdown
= acer_platform_shutdown
,
1852 static struct platform_device
*acer_platform_device
;
1854 static int remove_sysfs(struct platform_device
*device
)
1856 if (has_cap(ACER_CAP_THREEG
))
1857 device_remove_file(&device
->dev
, &dev_attr_threeg
);
1859 device_remove_file(&device
->dev
, &dev_attr_interface
);
1864 static int create_sysfs(void)
1866 int retval
= -ENOMEM
;
1868 if (has_cap(ACER_CAP_THREEG
)) {
1869 retval
= device_create_file(&acer_platform_device
->dev
,
1875 retval
= device_create_file(&acer_platform_device
->dev
,
1876 &dev_attr_interface
);
1883 remove_sysfs(acer_platform_device
);
1887 static void remove_debugfs(void)
1889 debugfs_remove(interface
->debug
.devices
);
1890 debugfs_remove(interface
->debug
.root
);
1893 static int create_debugfs(void)
1895 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
1896 if (!interface
->debug
.root
) {
1897 pr_err("Failed to create debugfs directory");
1901 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
1902 interface
->debug
.root
,
1903 &interface
->debug
.wmid_devices
);
1904 if (!interface
->debug
.devices
)
1914 static int __init
acer_wmi_init(void)
1918 pr_info("Acer Laptop ACPI-WMI Extras\n");
1920 if (dmi_check_system(acer_blacklist
)) {
1921 pr_info("Blacklisted hardware detected - not loading\n");
1928 * Detect which ACPI-WMI interface we're using.
1930 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1931 interface
= &AMW0_V2_interface
;
1933 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1934 interface
= &wmid_interface
;
1936 if (wmi_has_guid(WMID_GUID2
) && interface
) {
1937 if (ACPI_FAILURE(WMID_set_capabilities())) {
1938 pr_err("Unable to detect available WMID devices\n");
1941 } else if (!wmi_has_guid(WMID_GUID2
) && interface
) {
1942 pr_err("No WMID device detection method found\n");
1946 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
1947 interface
= &AMW0_interface
;
1949 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1950 pr_err("Unable to detect available AMW0 devices\n");
1955 if (wmi_has_guid(AMW0_GUID1
))
1956 AMW0_find_mailled();
1959 pr_err("No or unsupported WMI interface, unable to load\n");
1965 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS
)) {
1966 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
1967 pr_info("Brightness must be controlled by "
1968 "generic video driver\n");
1971 if (wmi_has_guid(WMID_GUID3
)) {
1973 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
1974 pr_err("Cannot enable EC raw mode\n");
1977 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
1978 pr_err("Cannot enable Launch Manager mode\n");
1981 } else if (ec_raw_mode
) {
1982 pr_info("No WMID EC raw mode enable method\n");
1985 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
1986 err
= acer_wmi_input_setup();
1991 err
= platform_driver_register(&acer_platform_driver
);
1993 pr_err("Unable to register platform driver.\n");
1994 goto error_platform_register
;
1997 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
1998 if (!acer_platform_device
) {
2000 goto error_device_alloc
;
2003 err
= platform_device_add(acer_platform_device
);
2005 goto error_device_add
;
2007 err
= create_sysfs();
2009 goto error_create_sys
;
2011 if (wmi_has_guid(WMID_GUID2
)) {
2012 interface
->debug
.wmid_devices
= get_wmid_devices();
2013 err
= create_debugfs();
2015 goto error_create_debugfs
;
2018 /* Override any initial settings with values from the commandline */
2019 acer_commandline_init();
2023 error_create_debugfs
:
2024 remove_sysfs(acer_platform_device
);
2026 platform_device_del(acer_platform_device
);
2028 platform_device_put(acer_platform_device
);
2030 platform_driver_unregister(&acer_platform_driver
);
2031 error_platform_register
:
2032 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2033 acer_wmi_input_destroy();
2038 static void __exit
acer_wmi_exit(void)
2040 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2041 acer_wmi_input_destroy();
2043 remove_sysfs(acer_platform_device
);
2045 platform_device_unregister(acer_platform_device
);
2046 platform_driver_unregister(&acer_platform_driver
);
2048 pr_info("Acer Laptop WMI Extras unloaded\n");
2052 module_init(acer_wmi_init
);
2053 module_exit(acer_wmi_exit
);