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 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
308 static struct dmi_system_id __devinitdata acer_blacklist
[] = {
310 .ident
= "Acer Aspire One (SSD)",
312 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
313 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
317 .ident
= "Acer Aspire One (HDD)",
319 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
320 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
326 static struct dmi_system_id acer_quirks
[] = {
328 .callback
= dmi_matched
,
329 .ident
= "Acer Aspire 1360",
331 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
332 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
334 .driver_data
= &quirk_acer_aspire_1520
,
337 .callback
= dmi_matched
,
338 .ident
= "Acer Aspire 1520",
340 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
341 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
343 .driver_data
= &quirk_acer_aspire_1520
,
346 .callback
= dmi_matched
,
347 .ident
= "Acer Aspire 3100",
349 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
350 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
352 .driver_data
= &quirk_acer_travelmate_2490
,
355 .callback
= dmi_matched
,
356 .ident
= "Acer Aspire 3610",
358 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
359 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
361 .driver_data
= &quirk_acer_travelmate_2490
,
364 .callback
= dmi_matched
,
365 .ident
= "Acer Aspire 5100",
367 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
368 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
370 .driver_data
= &quirk_acer_travelmate_2490
,
373 .callback
= dmi_matched
,
374 .ident
= "Acer Aspire 5610",
376 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
377 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
379 .driver_data
= &quirk_acer_travelmate_2490
,
382 .callback
= dmi_matched
,
383 .ident
= "Acer Aspire 5630",
385 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
386 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
388 .driver_data
= &quirk_acer_travelmate_2490
,
391 .callback
= dmi_matched
,
392 .ident
= "Acer Aspire 5650",
394 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
395 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
397 .driver_data
= &quirk_acer_travelmate_2490
,
400 .callback
= dmi_matched
,
401 .ident
= "Acer Aspire 5680",
403 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
404 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
406 .driver_data
= &quirk_acer_travelmate_2490
,
409 .callback
= dmi_matched
,
410 .ident
= "Acer Aspire 9110",
412 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
413 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
415 .driver_data
= &quirk_acer_travelmate_2490
,
418 .callback
= dmi_matched
,
419 .ident
= "Acer TravelMate 2490",
421 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
422 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
424 .driver_data
= &quirk_acer_travelmate_2490
,
427 .callback
= dmi_matched
,
428 .ident
= "Acer TravelMate 4200",
430 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
431 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
433 .driver_data
= &quirk_acer_travelmate_2490
,
436 .callback
= dmi_matched
,
437 .ident
= "Fujitsu Siemens Amilo Li 1718",
439 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
440 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
442 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
445 .callback
= dmi_matched
,
446 .ident
= "Medion MD 98300",
448 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
449 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
451 .driver_data
= &quirk_medion_md_98300
,
456 /* Find which quirks are needed for a particular vendor/ model pair */
457 static void find_quirks(void)
460 dmi_check_system(acer_quirks
);
461 } else if (force_series
== 2490) {
462 quirks
= &quirk_acer_travelmate_2490
;
466 quirks
= &quirk_unknown
;
472 * General interface convenience methods
475 static bool has_cap(u32 cap
)
477 if ((interface
->capability
& cap
) != 0)
484 * AMW0 (V1) interface
501 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
502 struct acpi_buffer
*result
)
504 struct acpi_buffer input
;
506 input
.length
= sizeof(struct wmab_args
);
507 input
.pointer
= (u8
*)regbuf
;
509 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
514 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
,
515 struct wmi_interface
*iface
)
521 case ACER_CAP_MAILLED
:
522 switch (quirks
->mailled
) {
524 err
= ec_read(0xA, &result
);
527 *value
= (result
>> 7) & 0x1;
531 case ACER_CAP_WIRELESS
:
532 switch (quirks
->wireless
) {
534 err
= ec_read(0x7B, &result
);
537 *value
= result
& 0x1;
540 err
= ec_read(0x71, &result
);
543 *value
= result
& 0x1;
546 err
= ec_read(0xA, &result
);
549 *value
= (result
>> 2) & 0x1;
553 case ACER_CAP_BLUETOOTH
:
554 switch (quirks
->bluetooth
) {
556 err
= ec_read(0xA, &result
);
559 *value
= (result
>> 4) & 0x1;
563 case ACER_CAP_BRIGHTNESS
:
564 switch (quirks
->brightness
) {
566 err
= ec_read(0x83, &result
);
579 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
581 struct wmab_args args
;
583 args
.eax
= ACER_AMW0_WRITE
;
584 args
.ebx
= value
? (1<<8) : 0;
585 args
.ecx
= args
.edx
= 0;
588 case ACER_CAP_MAILLED
:
590 return AE_BAD_PARAMETER
;
591 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
593 case ACER_CAP_WIRELESS
:
595 return AE_BAD_PARAMETER
;
596 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
598 case ACER_CAP_BLUETOOTH
:
600 return AE_BAD_PARAMETER
;
601 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
603 case ACER_CAP_BRIGHTNESS
:
604 if (value
> max_brightness
)
605 return AE_BAD_PARAMETER
;
606 switch (quirks
->brightness
) {
608 return ec_write(0x83, value
);
615 /* Actually do the set */
616 return wmab_execute(&args
, NULL
);
619 static acpi_status
AMW0_find_mailled(void)
621 struct wmab_args args
;
623 acpi_status status
= AE_OK
;
624 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
625 union acpi_object
*obj
;
628 args
.ebx
= args
.ecx
= args
.edx
= 0;
630 status
= wmab_execute(&args
, &out
);
631 if (ACPI_FAILURE(status
))
634 obj
= (union acpi_object
*) out
.pointer
;
635 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
636 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
637 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
644 interface
->capability
|= ACER_CAP_MAILLED
;
651 static acpi_status
AMW0_set_capabilities(void)
653 struct wmab_args args
;
656 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
657 union acpi_object
*obj
;
660 * On laptops with this strange GUID (non Acer), normal probing doesn't
663 if (wmi_has_guid(AMW0_GUID2
)) {
664 interface
->capability
|= ACER_CAP_WIRELESS
;
668 args
.eax
= ACER_AMW0_WRITE
;
669 args
.ecx
= args
.edx
= 0;
671 args
.ebx
= 0xa2 << 8;
672 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
674 status
= wmab_execute(&args
, &out
);
675 if (ACPI_FAILURE(status
))
679 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
680 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
681 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
688 interface
->capability
|= ACER_CAP_WIRELESS
;
691 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
694 * It's ok to use existing buffer for next wmab_execute call.
695 * But we need to kfree(out.pointer) if next wmab_execute fail.
697 status
= wmab_execute(&args
, &out
);
698 if (ACPI_FAILURE(status
))
701 obj
= (union acpi_object
*) out
.pointer
;
702 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
703 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
704 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
711 interface
->capability
|= ACER_CAP_BLUETOOTH
;
714 * This appears to be safe to enable, since all Wistron based laptops
715 * appear to use the same EC register for brightness, even if they
716 * differ for wireless, etc
718 if (quirks
->brightness
>= 0)
719 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
727 static struct wmi_interface AMW0_interface
= {
731 static struct wmi_interface AMW0_V2_interface
= {
732 .type
= ACER_AMW0_V2
,
736 * New interface (The WMID interface)
739 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
741 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
742 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
743 union acpi_object
*obj
;
747 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
749 if (ACPI_FAILURE(status
))
752 obj
= (union acpi_object
*) result
.pointer
;
753 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
754 (obj
->buffer
.length
== sizeof(u32
) ||
755 obj
->buffer
.length
== sizeof(u64
))) {
756 tmp
= *((u32
*) obj
->buffer
.pointer
);
757 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
758 tmp
= (u32
) obj
->integer
.value
;
766 kfree(result
.pointer
);
771 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
,
772 struct wmi_interface
*iface
)
776 u32 result
, method_id
= 0;
779 case ACER_CAP_WIRELESS
:
780 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
782 case ACER_CAP_BLUETOOTH
:
783 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
785 case ACER_CAP_BRIGHTNESS
:
786 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
788 case ACER_CAP_THREEG
:
789 method_id
= ACER_WMID_GET_THREEG_METHODID
;
791 case ACER_CAP_MAILLED
:
792 if (quirks
->mailled
== 1) {
800 status
= WMI_execute_u32(method_id
, 0, &result
);
802 if (ACPI_SUCCESS(status
))
808 static acpi_status
WMID_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
814 case ACER_CAP_BRIGHTNESS
:
815 if (value
> max_brightness
)
816 return AE_BAD_PARAMETER
;
817 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
819 case ACER_CAP_WIRELESS
:
821 return AE_BAD_PARAMETER
;
822 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
824 case ACER_CAP_BLUETOOTH
:
826 return AE_BAD_PARAMETER
;
827 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
829 case ACER_CAP_THREEG
:
831 return AE_BAD_PARAMETER
;
832 method_id
= ACER_WMID_SET_THREEG_METHODID
;
834 case ACER_CAP_MAILLED
:
836 return AE_BAD_PARAMETER
;
837 if (quirks
->mailled
== 1) {
838 param
= value
? 0x92 : 0x93;
840 i8042_command(¶m
, 0x1059);
848 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
851 static void type_aa_dmi_decode(const struct dmi_header
*header
, void *dummy
)
853 struct hotkey_function_type_aa
*type_aa
;
855 /* We are looking for OEM-specific Type AAh */
856 if (header
->type
!= 0xAA)
860 type_aa
= (struct hotkey_function_type_aa
*) header
;
862 pr_info("Function bitmap for Communication Button: 0x%x\n",
863 type_aa
->commun_func_bitmap
);
865 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
866 interface
->capability
|= ACER_CAP_WIRELESS
;
867 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
868 interface
->capability
|= ACER_CAP_THREEG
;
869 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
870 interface
->capability
|= ACER_CAP_BLUETOOTH
;
873 static acpi_status
WMID_set_capabilities(void)
875 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
876 union acpi_object
*obj
;
880 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
881 if (ACPI_FAILURE(status
))
884 obj
= (union acpi_object
*) out
.pointer
;
885 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
886 (obj
->buffer
.length
== sizeof(u32
) ||
887 obj
->buffer
.length
== sizeof(u64
))) {
888 devices
= *((u32
*) obj
->buffer
.pointer
);
889 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
890 devices
= (u32
) obj
->integer
.value
;
896 dmi_walk(type_aa_dmi_decode
, NULL
);
898 interface
->capability
|= ACER_CAP_WIRELESS
;
900 interface
->capability
|= ACER_CAP_THREEG
;
902 interface
->capability
|= ACER_CAP_BLUETOOTH
;
905 /* WMID always provides brightness methods */
906 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
908 if (!(devices
& 0x20))
909 max_brightness
= 0x9;
915 static struct wmi_interface wmid_interface
= {
920 * Generic Device (interface-independent)
923 static acpi_status
get_u32(u32
*value
, u32 cap
)
925 acpi_status status
= AE_ERROR
;
927 switch (interface
->type
) {
929 status
= AMW0_get_u32(value
, cap
, interface
);
932 if (cap
== ACER_CAP_MAILLED
) {
933 status
= AMW0_get_u32(value
, cap
, interface
);
937 status
= WMID_get_u32(value
, cap
, interface
);
944 static acpi_status
set_u32(u32 value
, u32 cap
)
948 if (interface
->capability
& cap
) {
949 switch (interface
->type
) {
951 return AMW0_set_u32(value
, cap
, interface
);
953 if (cap
== ACER_CAP_MAILLED
)
954 return AMW0_set_u32(value
, cap
, interface
);
957 * On some models, some WMID methods don't toggle
958 * properly. For those cases, we want to run the AMW0
959 * method afterwards to be certain we've really toggled
962 if (cap
== ACER_CAP_WIRELESS
||
963 cap
== ACER_CAP_BLUETOOTH
) {
964 status
= WMID_set_u32(value
, cap
, interface
);
965 if (ACPI_FAILURE(status
))
968 return AMW0_set_u32(value
, cap
, interface
);
971 return WMID_set_u32(value
, cap
, interface
);
973 return AE_BAD_PARAMETER
;
976 return AE_BAD_PARAMETER
;
979 static void __init
acer_commandline_init(void)
982 * These will all fail silently if the value given is invalid, or the
983 * capability isn't available on the given interface
986 set_u32(mailled
, ACER_CAP_MAILLED
);
987 if (!has_type_aa
&& threeg
>= 0)
988 set_u32(threeg
, ACER_CAP_THREEG
);
990 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
994 * LED device (Mail LED only, no other LEDs known yet)
996 static void mail_led_set(struct led_classdev
*led_cdev
,
997 enum led_brightness value
)
999 set_u32(value
, ACER_CAP_MAILLED
);
1002 static struct led_classdev mail_led
= {
1003 .name
= "acer-wmi::mail",
1004 .brightness_set
= mail_led_set
,
1007 static int __devinit
acer_led_init(struct device
*dev
)
1009 return led_classdev_register(dev
, &mail_led
);
1012 static void acer_led_exit(void)
1014 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1015 led_classdev_unregister(&mail_led
);
1021 static struct backlight_device
*acer_backlight_device
;
1023 static int read_brightness(struct backlight_device
*bd
)
1026 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1030 static int update_bl_status(struct backlight_device
*bd
)
1032 int intensity
= bd
->props
.brightness
;
1034 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1036 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1039 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1044 static const struct backlight_ops acer_bl_ops
= {
1045 .get_brightness
= read_brightness
,
1046 .update_status
= update_bl_status
,
1049 static int __devinit
acer_backlight_init(struct device
*dev
)
1051 struct backlight_properties props
;
1052 struct backlight_device
*bd
;
1054 memset(&props
, 0, sizeof(struct backlight_properties
));
1055 props
.type
= BACKLIGHT_PLATFORM
;
1056 props
.max_brightness
= max_brightness
;
1057 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1060 pr_err("Could not register Acer backlight device\n");
1061 acer_backlight_device
= NULL
;
1065 acer_backlight_device
= bd
;
1067 bd
->props
.power
= FB_BLANK_UNBLANK
;
1068 bd
->props
.brightness
= read_brightness(bd
);
1069 backlight_update_status(bd
);
1073 static void acer_backlight_exit(void)
1075 backlight_device_unregister(acer_backlight_device
);
1078 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1080 struct wmid3_gds_return_value return_value
;
1082 union acpi_object
*obj
;
1083 struct wmid3_gds_input_param params
= {
1084 .function_num
= 0x1,
1085 .hotkey_number
= 0x01,
1088 struct acpi_buffer input
= {
1089 sizeof(struct wmid3_gds_input_param
),
1092 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1094 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1095 if (ACPI_FAILURE(status
))
1098 obj
= output
.pointer
;
1102 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1106 if (obj
->buffer
.length
!= 8) {
1107 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1112 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1115 if (return_value
.error_code
|| return_value
.ec_return_value
)
1116 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1117 return_value
.error_code
,
1118 return_value
.ec_return_value
);
1120 *value
= !!(return_value
.devices
& device
);
1125 static acpi_status
get_device_status(u32
*value
, u32 cap
)
1127 if (wmi_has_guid(WMID_GUID3
)) {
1131 case ACER_CAP_WIRELESS
:
1132 device
= ACER_WMID3_GDS_WIRELESS
;
1134 case ACER_CAP_BLUETOOTH
:
1135 device
= ACER_WMID3_GDS_BLUETOOTH
;
1137 case ACER_CAP_THREEG
:
1138 device
= ACER_WMID3_GDS_THREEG
;
1143 return wmid3_get_device_status(value
, device
);
1146 return get_u32(value
, cap
);
1150 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1152 struct wmid3_gds_return_value return_value
;
1154 union acpi_object
*obj
;
1156 struct wmid3_gds_input_param params
= {
1157 .function_num
= 0x1,
1158 .hotkey_number
= 0x01,
1159 .devices
= ACER_WMID3_GDS_WIRELESS
&
1160 ACER_WMID3_GDS_THREEG
&
1161 ACER_WMID3_GDS_WIMAX
&
1162 ACER_WMID3_GDS_BLUETOOTH
,
1164 struct acpi_buffer input
= {
1165 sizeof(struct wmid3_gds_input_param
),
1168 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1169 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1171 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1172 if (ACPI_FAILURE(status
))
1175 obj
= output
.pointer
;
1179 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1183 if (obj
->buffer
.length
!= 8) {
1184 pr_warning("Unknown buffer length %d\n", obj
->buffer
.length
);
1189 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1192 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1193 pr_warning("Get Current Device Status failed: "
1194 "0x%x - 0x%x\n", return_value
.error_code
,
1195 return_value
.ec_return_value
);
1199 devices
= return_value
.devices
;
1200 params
.function_num
= 0x2;
1201 params
.hotkey_number
= 0x01;
1202 params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1204 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output2
);
1205 if (ACPI_FAILURE(status
))
1208 obj
= output2
.pointer
;
1212 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1216 if (obj
->buffer
.length
!= 4) {
1217 pr_warning("Unknown buffer length %d\n", obj
->buffer
.length
);
1222 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1225 if (return_value
.error_code
|| return_value
.ec_return_value
)
1226 pr_warning("Set Device Status failed: "
1227 "0x%x - 0x%x\n", return_value
.error_code
,
1228 return_value
.ec_return_value
);
1233 static acpi_status
set_device_status(u32 value
, u32 cap
)
1235 if (wmi_has_guid(WMID_GUID3
)) {
1239 case ACER_CAP_WIRELESS
:
1240 device
= ACER_WMID3_GDS_WIRELESS
;
1242 case ACER_CAP_BLUETOOTH
:
1243 device
= ACER_WMID3_GDS_BLUETOOTH
;
1245 case ACER_CAP_THREEG
:
1246 device
= ACER_WMID3_GDS_THREEG
;
1251 return wmid3_set_device_status(value
, device
);
1254 return set_u32(value
, cap
);
1261 static void acer_rfkill_update(struct work_struct
*ignored
);
1262 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1263 static void acer_rfkill_update(struct work_struct
*ignored
)
1268 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1269 if (ACPI_SUCCESS(status
))
1270 rfkill_set_sw_state(wireless_rfkill
, !state
);
1272 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1273 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1274 if (ACPI_SUCCESS(status
))
1275 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1278 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1279 status
= wmid3_get_device_status(&state
,
1280 ACER_WMID3_GDS_THREEG
);
1281 if (ACPI_SUCCESS(status
))
1282 rfkill_set_sw_state(threeg_rfkill
, !state
);
1285 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1288 static int acer_rfkill_set(void *data
, bool blocked
)
1291 u32 cap
= (unsigned long)data
;
1293 if (rfkill_inited
) {
1294 status
= set_device_status(!blocked
, cap
);
1295 if (ACPI_FAILURE(status
))
1302 static const struct rfkill_ops acer_rfkill_ops
= {
1303 .set_block
= acer_rfkill_set
,
1306 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1307 enum rfkill_type type
,
1308 char *name
, u32 cap
)
1311 struct rfkill
*rfkill_dev
;
1315 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1317 (void *)(unsigned long)cap
);
1319 return ERR_PTR(-ENOMEM
);
1321 status
= get_device_status(&state
, cap
);
1323 err
= rfkill_register(rfkill_dev
);
1325 rfkill_destroy(rfkill_dev
);
1326 return ERR_PTR(err
);
1329 if (ACPI_SUCCESS(status
))
1330 rfkill_set_sw_state(rfkill_dev
, !state
);
1335 static int acer_rfkill_init(struct device
*dev
)
1337 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1338 "acer-wireless", ACER_CAP_WIRELESS
);
1339 if (IS_ERR(wireless_rfkill
))
1340 return PTR_ERR(wireless_rfkill
);
1342 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1343 bluetooth_rfkill
= acer_rfkill_register(dev
,
1344 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1345 ACER_CAP_BLUETOOTH
);
1346 if (IS_ERR(bluetooth_rfkill
)) {
1347 rfkill_unregister(wireless_rfkill
);
1348 rfkill_destroy(wireless_rfkill
);
1349 return PTR_ERR(bluetooth_rfkill
);
1353 if (has_cap(ACER_CAP_THREEG
)) {
1354 threeg_rfkill
= acer_rfkill_register(dev
,
1355 RFKILL_TYPE_WWAN
, "acer-threeg",
1357 if (IS_ERR(threeg_rfkill
)) {
1358 rfkill_unregister(wireless_rfkill
);
1359 rfkill_destroy(wireless_rfkill
);
1360 rfkill_unregister(bluetooth_rfkill
);
1361 rfkill_destroy(bluetooth_rfkill
);
1362 return PTR_ERR(threeg_rfkill
);
1366 rfkill_inited
= true;
1368 if (ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
))
1369 schedule_delayed_work(&acer_rfkill_work
,
1370 round_jiffies_relative(HZ
));
1375 static void acer_rfkill_exit(void)
1377 if (ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
))
1378 cancel_delayed_work_sync(&acer_rfkill_work
);
1380 rfkill_unregister(wireless_rfkill
);
1381 rfkill_destroy(wireless_rfkill
);
1383 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1384 rfkill_unregister(bluetooth_rfkill
);
1385 rfkill_destroy(bluetooth_rfkill
);
1388 if (has_cap(ACER_CAP_THREEG
)) {
1389 rfkill_unregister(threeg_rfkill
);
1390 rfkill_destroy(threeg_rfkill
);
1398 static ssize_t
show_bool_threeg(struct device
*dev
,
1399 struct device_attribute
*attr
, char *buf
)
1403 if (wmi_has_guid(WMID_GUID3
))
1404 status
= wmid3_get_device_status(&result
,
1405 ACER_WMID3_GDS_THREEG
);
1407 status
= get_u32(&result
, ACER_CAP_THREEG
);
1408 if (ACPI_SUCCESS(status
))
1409 return sprintf(buf
, "%u\n", result
);
1410 return sprintf(buf
, "Read error\n");
1413 static ssize_t
set_bool_threeg(struct device
*dev
,
1414 struct device_attribute
*attr
, const char *buf
, size_t count
)
1416 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
1417 acpi_status status
= set_u32(tmp
, ACER_CAP_THREEG
);
1418 if (ACPI_FAILURE(status
))
1422 static DEVICE_ATTR(threeg
, S_IRUGO
| S_IWUSR
, show_bool_threeg
,
1425 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1428 switch (interface
->type
) {
1430 return sprintf(buf
, "AMW0\n");
1432 return sprintf(buf
, "AMW0 v2\n");
1434 return sprintf(buf
, "WMID\n");
1436 return sprintf(buf
, "Error!\n");
1440 static DEVICE_ATTR(interface
, S_IRUGO
, show_interface
, NULL
);
1442 static void acer_wmi_notify(u32 value
, void *context
)
1444 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1445 union acpi_object
*obj
;
1446 struct event_return_value return_value
;
1449 status
= wmi_get_event_data(value
, &response
);
1450 if (status
!= AE_OK
) {
1451 pr_warn("bad event status 0x%x\n", status
);
1455 obj
= (union acpi_object
*)response
.pointer
;
1459 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1460 pr_warn("Unknown response received %d\n", obj
->type
);
1464 if (obj
->buffer
.length
!= 8) {
1465 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1470 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1473 switch (return_value
.function
) {
1474 case WMID_HOTKEY_EVENT
:
1475 if (return_value
.device_state
) {
1476 u16 device_state
= return_value
.device_state
;
1477 pr_debug("device state: 0x%x\n", device_state
);
1478 if (has_cap(ACER_CAP_WIRELESS
))
1479 rfkill_set_sw_state(wireless_rfkill
,
1480 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1481 if (has_cap(ACER_CAP_BLUETOOTH
))
1482 rfkill_set_sw_state(bluetooth_rfkill
,
1483 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1484 if (has_cap(ACER_CAP_THREEG
))
1485 rfkill_set_sw_state(threeg_rfkill
,
1486 !(device_state
& ACER_WMID3_GDS_THREEG
));
1488 if (!sparse_keymap_report_event(acer_wmi_input_dev
,
1489 return_value
.key_num
, 1, true))
1490 pr_warn("Unknown key number - 0x%x\n",
1491 return_value
.key_num
);
1494 pr_warn("Unknown function number - %d - %d\n",
1495 return_value
.function
, return_value
.key_num
);
1501 wmid3_set_lm_mode(struct lm_input_params
*params
,
1502 struct lm_return_value
*return_value
)
1505 union acpi_object
*obj
;
1507 struct acpi_buffer input
= { sizeof(struct lm_input_params
), params
};
1508 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1510 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1511 if (ACPI_FAILURE(status
))
1514 obj
= output
.pointer
;
1518 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1522 if (obj
->buffer
.length
!= 4) {
1523 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1528 *return_value
= *((struct lm_return_value
*)obj
->buffer
.pointer
);
1534 static int acer_wmi_enable_ec_raw(void)
1536 struct lm_return_value return_value
;
1538 struct lm_input_params params
= {
1539 .function_num
= 0x1,
1540 .commun_devices
= 0xFFFF,
1542 .lm_status
= 0x00, /* Launch Manager Deactive */
1545 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1547 if (return_value
.error_code
|| return_value
.ec_return_value
)
1548 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1549 return_value
.error_code
,
1550 return_value
.ec_return_value
);
1552 pr_info("Enabled EC raw mode\n");
1557 static int acer_wmi_enable_lm(void)
1559 struct lm_return_value return_value
;
1561 struct lm_input_params params
= {
1562 .function_num
= 0x1,
1563 .commun_devices
= 0xFFFF,
1565 .lm_status
= 0x01, /* Launch Manager Active */
1568 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1570 if (return_value
.error_code
|| return_value
.ec_return_value
)
1571 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1572 return_value
.error_code
,
1573 return_value
.ec_return_value
);
1578 static int __init
acer_wmi_input_setup(void)
1583 acer_wmi_input_dev
= input_allocate_device();
1584 if (!acer_wmi_input_dev
)
1587 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1588 acer_wmi_input_dev
->phys
= "wmi/input0";
1589 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1591 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1595 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1596 acer_wmi_notify
, NULL
);
1597 if (ACPI_FAILURE(status
)) {
1599 goto err_free_keymap
;
1602 err
= input_register_device(acer_wmi_input_dev
);
1604 goto err_uninstall_notifier
;
1608 err_uninstall_notifier
:
1609 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1611 sparse_keymap_free(acer_wmi_input_dev
);
1613 input_free_device(acer_wmi_input_dev
);
1617 static void acer_wmi_input_destroy(void)
1619 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1620 sparse_keymap_free(acer_wmi_input_dev
);
1621 input_unregister_device(acer_wmi_input_dev
);
1627 static u32
get_wmid_devices(void)
1629 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1630 union acpi_object
*obj
;
1634 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1635 if (ACPI_FAILURE(status
))
1638 obj
= (union acpi_object
*) out
.pointer
;
1639 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1640 (obj
->buffer
.length
== sizeof(u32
) ||
1641 obj
->buffer
.length
== sizeof(u64
))) {
1642 devices
= *((u32
*) obj
->buffer
.pointer
);
1643 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1644 devices
= (u32
) obj
->integer
.value
;
1654 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1658 if (has_cap(ACER_CAP_MAILLED
)) {
1659 err
= acer_led_init(&device
->dev
);
1664 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1665 err
= acer_backlight_init(&device
->dev
);
1667 goto error_brightness
;
1670 err
= acer_rfkill_init(&device
->dev
);
1677 if (has_cap(ACER_CAP_BRIGHTNESS
))
1678 acer_backlight_exit();
1680 if (has_cap(ACER_CAP_MAILLED
))
1686 static int acer_platform_remove(struct platform_device
*device
)
1688 if (has_cap(ACER_CAP_MAILLED
))
1690 if (has_cap(ACER_CAP_BRIGHTNESS
))
1691 acer_backlight_exit();
1697 static int acer_platform_suspend(struct platform_device
*dev
,
1701 struct acer_data
*data
= &interface
->data
;
1706 if (has_cap(ACER_CAP_MAILLED
)) {
1707 get_u32(&value
, ACER_CAP_MAILLED
);
1708 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1709 data
->mailled
= value
;
1712 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1713 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1714 data
->brightness
= value
;
1720 static int acer_platform_resume(struct platform_device
*device
)
1722 struct acer_data
*data
= &interface
->data
;
1727 if (has_cap(ACER_CAP_MAILLED
))
1728 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
1730 if (has_cap(ACER_CAP_BRIGHTNESS
))
1731 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
1736 static void acer_platform_shutdown(struct platform_device
*device
)
1738 struct acer_data
*data
= &interface
->data
;
1743 if (has_cap(ACER_CAP_MAILLED
))
1744 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1747 static struct platform_driver acer_platform_driver
= {
1750 .owner
= THIS_MODULE
,
1752 .probe
= acer_platform_probe
,
1753 .remove
= acer_platform_remove
,
1754 .suspend
= acer_platform_suspend
,
1755 .resume
= acer_platform_resume
,
1756 .shutdown
= acer_platform_shutdown
,
1759 static struct platform_device
*acer_platform_device
;
1761 static int remove_sysfs(struct platform_device
*device
)
1763 if (has_cap(ACER_CAP_THREEG
))
1764 device_remove_file(&device
->dev
, &dev_attr_threeg
);
1766 device_remove_file(&device
->dev
, &dev_attr_interface
);
1771 static int create_sysfs(void)
1773 int retval
= -ENOMEM
;
1775 if (has_cap(ACER_CAP_THREEG
)) {
1776 retval
= device_create_file(&acer_platform_device
->dev
,
1782 retval
= device_create_file(&acer_platform_device
->dev
,
1783 &dev_attr_interface
);
1790 remove_sysfs(acer_platform_device
);
1794 static void remove_debugfs(void)
1796 debugfs_remove(interface
->debug
.devices
);
1797 debugfs_remove(interface
->debug
.root
);
1800 static int create_debugfs(void)
1802 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
1803 if (!interface
->debug
.root
) {
1804 pr_err("Failed to create debugfs directory");
1808 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
1809 interface
->debug
.root
,
1810 &interface
->debug
.wmid_devices
);
1811 if (!interface
->debug
.devices
)
1821 static int __init
acer_wmi_init(void)
1825 pr_info("Acer Laptop ACPI-WMI Extras\n");
1827 if (dmi_check_system(acer_blacklist
)) {
1828 pr_info("Blacklisted hardware detected - not loading\n");
1835 * Detect which ACPI-WMI interface we're using.
1837 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1838 interface
= &AMW0_V2_interface
;
1840 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1841 interface
= &wmid_interface
;
1843 if (wmi_has_guid(WMID_GUID2
) && interface
) {
1844 if (ACPI_FAILURE(WMID_set_capabilities())) {
1845 pr_err("Unable to detect available WMID devices\n");
1848 } else if (!wmi_has_guid(WMID_GUID2
) && interface
) {
1849 pr_err("No WMID device detection method found\n");
1853 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
1854 interface
= &AMW0_interface
;
1856 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1857 pr_err("Unable to detect available AMW0 devices\n");
1862 if (wmi_has_guid(AMW0_GUID1
))
1863 AMW0_find_mailled();
1866 pr_err("No or unsupported WMI interface, unable to load\n");
1872 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS
)) {
1873 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
1874 pr_info("Brightness must be controlled by "
1875 "generic video driver\n");
1878 if (wmi_has_guid(WMID_GUID3
)) {
1880 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
1881 pr_err("Cannot enable EC raw mode\n");
1884 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
1885 pr_err("Cannot enable Launch Manager mode\n");
1888 } else if (ec_raw_mode
) {
1889 pr_info("No WMID EC raw mode enable method\n");
1892 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
1893 err
= acer_wmi_input_setup();
1898 err
= platform_driver_register(&acer_platform_driver
);
1900 pr_err("Unable to register platform driver.\n");
1901 goto error_platform_register
;
1904 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
1905 if (!acer_platform_device
) {
1907 goto error_device_alloc
;
1910 err
= platform_device_add(acer_platform_device
);
1912 goto error_device_add
;
1914 err
= create_sysfs();
1916 goto error_create_sys
;
1918 if (wmi_has_guid(WMID_GUID2
)) {
1919 interface
->debug
.wmid_devices
= get_wmid_devices();
1920 err
= create_debugfs();
1922 goto error_create_debugfs
;
1925 /* Override any initial settings with values from the commandline */
1926 acer_commandline_init();
1930 error_create_debugfs
:
1931 remove_sysfs(acer_platform_device
);
1933 platform_device_del(acer_platform_device
);
1935 platform_device_put(acer_platform_device
);
1937 platform_driver_unregister(&acer_platform_driver
);
1938 error_platform_register
:
1939 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
1940 acer_wmi_input_destroy();
1945 static void __exit
acer_wmi_exit(void)
1947 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
1948 acer_wmi_input_destroy();
1950 remove_sysfs(acer_platform_device
);
1952 platform_device_unregister(acer_platform_device
);
1953 platform_driver_unregister(&acer_platform_driver
);
1955 pr_info("Acer Laptop WMI Extras unloaded\n");
1959 module_init(acer_wmi_init
);
1960 module_exit(acer_wmi_exit
);