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
, 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
} },
125 static struct input_dev
*acer_wmi_input_dev
;
127 struct event_return_value
{
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 */
148 } __attribute__((packed
));
150 struct lm_return_value
{
151 u8 error_code
; /* Error Code */
152 u8 ec_return_value
; /* EC Return Value */
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 */
167 } __attribute__((packed
));
169 struct hotkey_function_type_aa
{
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
{
195 #define ACER_DEFAULT_WIRELESS 0
196 #define ACER_DEFAULT_BLUETOOTH 0
197 #define ACER_DEFAULT_MAILLED 0
198 #define ACER_DEFAULT_THREEG 0
200 static int max_brightness
= 0xF;
202 static int mailled
= -1;
203 static int brightness
= -1;
204 static int threeg
= -1;
205 static int force_series
;
206 static bool ec_raw_mode
;
207 static bool has_type_aa
;
209 module_param(mailled
, int, 0444);
210 module_param(brightness
, int, 0444);
211 module_param(threeg
, int, 0444);
212 module_param(force_series
, int, 0444);
213 module_param(ec_raw_mode
, bool, 0444);
214 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
215 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
216 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
217 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
218 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
228 struct dentry
*devices
;
232 static struct rfkill
*wireless_rfkill
;
233 static struct rfkill
*bluetooth_rfkill
;
234 static struct rfkill
*threeg_rfkill
;
235 static bool rfkill_inited
;
237 /* Each low-level interface must define at least some of the following */
238 struct wmi_interface
{
239 /* The WMI device type */
242 /* The capabilities this interface provides */
245 /* Private data for the current interface */
246 struct acer_data data
;
248 /* debugfs entries associated with this interface */
249 struct acer_debug debug
;
252 /* The static interface pointer, points to the currently detected interface */
253 static struct wmi_interface
*interface
;
256 * Embedded Controller quirks
257 * Some laptops require us to directly access the EC to either enable or query
258 * features that are not available through WMI.
268 static struct quirk_entry
*quirks
;
270 static void set_quirks(void)
276 interface
->capability
|= ACER_CAP_MAILLED
;
278 if (quirks
->brightness
)
279 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
282 static int dmi_matched(const struct dmi_system_id
*dmi
)
284 quirks
= dmi
->driver_data
;
288 static struct quirk_entry quirk_unknown
= {
291 static struct quirk_entry quirk_acer_aspire_1520
= {
295 static struct quirk_entry quirk_acer_travelmate_2490
= {
299 /* This AMW0 laptop has no bluetooth */
300 static struct quirk_entry quirk_medion_md_98300
= {
304 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
308 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
312 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
313 static struct dmi_system_id __devinitdata acer_blacklist
[] = {
315 .ident
= "Acer Aspire One (SSD)",
317 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
318 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
322 .ident
= "Acer Aspire One (HDD)",
324 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
325 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
331 static struct dmi_system_id acer_quirks
[] = {
333 .callback
= dmi_matched
,
334 .ident
= "Acer Aspire 1360",
336 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
337 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
339 .driver_data
= &quirk_acer_aspire_1520
,
342 .callback
= dmi_matched
,
343 .ident
= "Acer Aspire 1520",
345 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
346 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
348 .driver_data
= &quirk_acer_aspire_1520
,
351 .callback
= dmi_matched
,
352 .ident
= "Acer Aspire 3100",
354 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
355 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
357 .driver_data
= &quirk_acer_travelmate_2490
,
360 .callback
= dmi_matched
,
361 .ident
= "Acer Aspire 3610",
363 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
364 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
366 .driver_data
= &quirk_acer_travelmate_2490
,
369 .callback
= dmi_matched
,
370 .ident
= "Acer Aspire 5100",
372 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
373 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
375 .driver_data
= &quirk_acer_travelmate_2490
,
378 .callback
= dmi_matched
,
379 .ident
= "Acer Aspire 5610",
381 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
382 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
384 .driver_data
= &quirk_acer_travelmate_2490
,
387 .callback
= dmi_matched
,
388 .ident
= "Acer Aspire 5630",
390 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
391 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
393 .driver_data
= &quirk_acer_travelmate_2490
,
396 .callback
= dmi_matched
,
397 .ident
= "Acer Aspire 5650",
399 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
400 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
402 .driver_data
= &quirk_acer_travelmate_2490
,
405 .callback
= dmi_matched
,
406 .ident
= "Acer Aspire 5680",
408 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
409 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
411 .driver_data
= &quirk_acer_travelmate_2490
,
414 .callback
= dmi_matched
,
415 .ident
= "Acer Aspire 9110",
417 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
418 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
420 .driver_data
= &quirk_acer_travelmate_2490
,
423 .callback
= dmi_matched
,
424 .ident
= "Acer TravelMate 2490",
426 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
427 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
429 .driver_data
= &quirk_acer_travelmate_2490
,
432 .callback
= dmi_matched
,
433 .ident
= "Acer TravelMate 4200",
435 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
436 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
438 .driver_data
= &quirk_acer_travelmate_2490
,
441 .callback
= dmi_matched
,
442 .ident
= "Fujitsu Siemens Amilo Li 1718",
444 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
445 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
447 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
450 .callback
= dmi_matched
,
451 .ident
= "Medion MD 98300",
453 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
454 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
456 .driver_data
= &quirk_medion_md_98300
,
459 .callback
= dmi_matched
,
460 .ident
= "Lenovo Ideapad S205",
462 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
463 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
465 .driver_data
= &quirk_lenovo_ideapad_s205
,
470 /* Find which quirks are needed for a particular vendor/ model pair */
471 static void find_quirks(void)
474 dmi_check_system(acer_quirks
);
475 } else if (force_series
== 2490) {
476 quirks
= &quirk_acer_travelmate_2490
;
480 quirks
= &quirk_unknown
;
486 * General interface convenience methods
489 static bool has_cap(u32 cap
)
491 if ((interface
->capability
& cap
) != 0)
498 * AMW0 (V1) interface
515 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
516 struct acpi_buffer
*result
)
518 struct acpi_buffer input
;
520 input
.length
= sizeof(struct wmab_args
);
521 input
.pointer
= (u8
*)regbuf
;
523 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
528 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
,
529 struct wmi_interface
*iface
)
535 case ACER_CAP_MAILLED
:
536 switch (quirks
->mailled
) {
538 err
= ec_read(0xA, &result
);
541 *value
= (result
>> 7) & 0x1;
545 case ACER_CAP_WIRELESS
:
546 switch (quirks
->wireless
) {
548 err
= ec_read(0x7B, &result
);
551 *value
= result
& 0x1;
554 err
= ec_read(0x71, &result
);
557 *value
= result
& 0x1;
560 err
= ec_read(0x78, &result
);
563 *value
= result
& 0x1;
566 err
= ec_read(0xA, &result
);
569 *value
= (result
>> 2) & 0x1;
573 case ACER_CAP_BLUETOOTH
:
574 switch (quirks
->bluetooth
) {
576 err
= ec_read(0xA, &result
);
579 *value
= (result
>> 4) & 0x1;
583 case ACER_CAP_BRIGHTNESS
:
584 switch (quirks
->brightness
) {
586 err
= ec_read(0x83, &result
);
599 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
601 struct wmab_args args
;
603 args
.eax
= ACER_AMW0_WRITE
;
604 args
.ebx
= value
? (1<<8) : 0;
605 args
.ecx
= args
.edx
= 0;
608 case ACER_CAP_MAILLED
:
610 return AE_BAD_PARAMETER
;
611 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
613 case ACER_CAP_WIRELESS
:
615 return AE_BAD_PARAMETER
;
616 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
618 case ACER_CAP_BLUETOOTH
:
620 return AE_BAD_PARAMETER
;
621 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
623 case ACER_CAP_BRIGHTNESS
:
624 if (value
> max_brightness
)
625 return AE_BAD_PARAMETER
;
626 switch (quirks
->brightness
) {
628 return ec_write(0x83, value
);
635 /* Actually do the set */
636 return wmab_execute(&args
, NULL
);
639 static acpi_status
AMW0_find_mailled(void)
641 struct wmab_args args
;
643 acpi_status status
= AE_OK
;
644 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
645 union acpi_object
*obj
;
648 args
.ebx
= args
.ecx
= args
.edx
= 0;
650 status
= wmab_execute(&args
, &out
);
651 if (ACPI_FAILURE(status
))
654 obj
= (union acpi_object
*) out
.pointer
;
655 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
656 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
657 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
664 interface
->capability
|= ACER_CAP_MAILLED
;
671 static acpi_status
AMW0_set_capabilities(void)
673 struct wmab_args args
;
676 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
677 union acpi_object
*obj
;
680 * On laptops with this strange GUID (non Acer), normal probing doesn't
683 if (wmi_has_guid(AMW0_GUID2
)) {
684 interface
->capability
|= ACER_CAP_WIRELESS
;
688 args
.eax
= ACER_AMW0_WRITE
;
689 args
.ecx
= args
.edx
= 0;
691 args
.ebx
= 0xa2 << 8;
692 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
694 status
= wmab_execute(&args
, &out
);
695 if (ACPI_FAILURE(status
))
699 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
700 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
701 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
708 interface
->capability
|= ACER_CAP_WIRELESS
;
711 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
714 * It's ok to use existing buffer for next wmab_execute call.
715 * But we need to kfree(out.pointer) if next wmab_execute fail.
717 status
= wmab_execute(&args
, &out
);
718 if (ACPI_FAILURE(status
))
721 obj
= (union acpi_object
*) out
.pointer
;
722 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
723 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
724 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
731 interface
->capability
|= ACER_CAP_BLUETOOTH
;
734 * This appears to be safe to enable, since all Wistron based laptops
735 * appear to use the same EC register for brightness, even if they
736 * differ for wireless, etc
738 if (quirks
->brightness
>= 0)
739 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
747 static struct wmi_interface AMW0_interface
= {
751 static struct wmi_interface AMW0_V2_interface
= {
752 .type
= ACER_AMW0_V2
,
756 * New interface (The WMID interface)
759 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
761 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
762 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
763 union acpi_object
*obj
;
767 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
769 if (ACPI_FAILURE(status
))
772 obj
= (union acpi_object
*) result
.pointer
;
773 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
774 (obj
->buffer
.length
== sizeof(u32
) ||
775 obj
->buffer
.length
== sizeof(u64
))) {
776 tmp
= *((u32
*) obj
->buffer
.pointer
);
777 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
778 tmp
= (u32
) obj
->integer
.value
;
786 kfree(result
.pointer
);
791 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
,
792 struct wmi_interface
*iface
)
796 u32 result
, method_id
= 0;
799 case ACER_CAP_WIRELESS
:
800 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
802 case ACER_CAP_BLUETOOTH
:
803 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
805 case ACER_CAP_BRIGHTNESS
:
806 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
808 case ACER_CAP_THREEG
:
809 method_id
= ACER_WMID_GET_THREEG_METHODID
;
811 case ACER_CAP_MAILLED
:
812 if (quirks
->mailled
== 1) {
820 status
= WMI_execute_u32(method_id
, 0, &result
);
822 if (ACPI_SUCCESS(status
))
828 static acpi_status
WMID_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
834 case ACER_CAP_BRIGHTNESS
:
835 if (value
> max_brightness
)
836 return AE_BAD_PARAMETER
;
837 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
839 case ACER_CAP_WIRELESS
:
841 return AE_BAD_PARAMETER
;
842 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
844 case ACER_CAP_BLUETOOTH
:
846 return AE_BAD_PARAMETER
;
847 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
849 case ACER_CAP_THREEG
:
851 return AE_BAD_PARAMETER
;
852 method_id
= ACER_WMID_SET_THREEG_METHODID
;
854 case ACER_CAP_MAILLED
:
856 return AE_BAD_PARAMETER
;
857 if (quirks
->mailled
== 1) {
858 param
= value
? 0x92 : 0x93;
860 i8042_command(¶m
, 0x1059);
868 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
871 static void type_aa_dmi_decode(const struct dmi_header
*header
, void *dummy
)
873 struct hotkey_function_type_aa
*type_aa
;
875 /* We are looking for OEM-specific Type AAh */
876 if (header
->type
!= 0xAA)
880 type_aa
= (struct hotkey_function_type_aa
*) header
;
882 pr_info("Function bitmap for Communication Button: 0x%x\n",
883 type_aa
->commun_func_bitmap
);
885 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
886 interface
->capability
|= ACER_CAP_WIRELESS
;
887 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
888 interface
->capability
|= ACER_CAP_THREEG
;
889 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
890 interface
->capability
|= ACER_CAP_BLUETOOTH
;
893 static acpi_status
WMID_set_capabilities(void)
895 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
896 union acpi_object
*obj
;
900 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
901 if (ACPI_FAILURE(status
))
904 obj
= (union acpi_object
*) out
.pointer
;
905 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
906 (obj
->buffer
.length
== sizeof(u32
) ||
907 obj
->buffer
.length
== sizeof(u64
))) {
908 devices
= *((u32
*) obj
->buffer
.pointer
);
909 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
910 devices
= (u32
) obj
->integer
.value
;
916 dmi_walk(type_aa_dmi_decode
, NULL
);
918 interface
->capability
|= ACER_CAP_WIRELESS
;
920 interface
->capability
|= ACER_CAP_THREEG
;
922 interface
->capability
|= ACER_CAP_BLUETOOTH
;
925 /* WMID always provides brightness methods */
926 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
928 if (!(devices
& 0x20))
929 max_brightness
= 0x9;
935 static struct wmi_interface wmid_interface
= {
940 * Generic Device (interface-independent)
943 static acpi_status
get_u32(u32
*value
, u32 cap
)
945 acpi_status status
= AE_ERROR
;
947 switch (interface
->type
) {
949 status
= AMW0_get_u32(value
, cap
, interface
);
952 if (cap
== ACER_CAP_MAILLED
) {
953 status
= AMW0_get_u32(value
, cap
, interface
);
957 status
= WMID_get_u32(value
, cap
, interface
);
964 static acpi_status
set_u32(u32 value
, u32 cap
)
968 if (interface
->capability
& cap
) {
969 switch (interface
->type
) {
971 return AMW0_set_u32(value
, cap
, interface
);
973 if (cap
== ACER_CAP_MAILLED
)
974 return AMW0_set_u32(value
, cap
, interface
);
977 * On some models, some WMID methods don't toggle
978 * properly. For those cases, we want to run the AMW0
979 * method afterwards to be certain we've really toggled
982 if (cap
== ACER_CAP_WIRELESS
||
983 cap
== ACER_CAP_BLUETOOTH
) {
984 status
= WMID_set_u32(value
, cap
, interface
);
985 if (ACPI_FAILURE(status
))
988 return AMW0_set_u32(value
, cap
, interface
);
991 return WMID_set_u32(value
, cap
, interface
);
993 return AE_BAD_PARAMETER
;
996 return AE_BAD_PARAMETER
;
999 static void __init
acer_commandline_init(void)
1002 * These will all fail silently if the value given is invalid, or the
1003 * capability isn't available on the given interface
1006 set_u32(mailled
, ACER_CAP_MAILLED
);
1007 if (!has_type_aa
&& threeg
>= 0)
1008 set_u32(threeg
, ACER_CAP_THREEG
);
1009 if (brightness
>= 0)
1010 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1014 * LED device (Mail LED only, no other LEDs known yet)
1016 static void mail_led_set(struct led_classdev
*led_cdev
,
1017 enum led_brightness value
)
1019 set_u32(value
, ACER_CAP_MAILLED
);
1022 static struct led_classdev mail_led
= {
1023 .name
= "acer-wmi::mail",
1024 .brightness_set
= mail_led_set
,
1027 static int __devinit
acer_led_init(struct device
*dev
)
1029 return led_classdev_register(dev
, &mail_led
);
1032 static void acer_led_exit(void)
1034 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1035 led_classdev_unregister(&mail_led
);
1041 static struct backlight_device
*acer_backlight_device
;
1043 static int read_brightness(struct backlight_device
*bd
)
1046 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1050 static int update_bl_status(struct backlight_device
*bd
)
1052 int intensity
= bd
->props
.brightness
;
1054 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1056 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1059 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1064 static const struct backlight_ops acer_bl_ops
= {
1065 .get_brightness
= read_brightness
,
1066 .update_status
= update_bl_status
,
1069 static int __devinit
acer_backlight_init(struct device
*dev
)
1071 struct backlight_properties props
;
1072 struct backlight_device
*bd
;
1074 memset(&props
, 0, sizeof(struct backlight_properties
));
1075 props
.type
= BACKLIGHT_PLATFORM
;
1076 props
.max_brightness
= max_brightness
;
1077 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1080 pr_err("Could not register Acer backlight device\n");
1081 acer_backlight_device
= NULL
;
1085 acer_backlight_device
= bd
;
1087 bd
->props
.power
= FB_BLANK_UNBLANK
;
1088 bd
->props
.brightness
= read_brightness(bd
);
1089 backlight_update_status(bd
);
1093 static void acer_backlight_exit(void)
1095 backlight_device_unregister(acer_backlight_device
);
1098 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1100 struct wmid3_gds_return_value return_value
;
1102 union acpi_object
*obj
;
1103 struct wmid3_gds_input_param params
= {
1104 .function_num
= 0x1,
1105 .hotkey_number
= 0x01,
1108 struct acpi_buffer input
= {
1109 sizeof(struct wmid3_gds_input_param
),
1112 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1114 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1115 if (ACPI_FAILURE(status
))
1118 obj
= output
.pointer
;
1122 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1126 if (obj
->buffer
.length
!= 8) {
1127 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1132 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1135 if (return_value
.error_code
|| return_value
.ec_return_value
)
1136 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1137 return_value
.error_code
,
1138 return_value
.ec_return_value
);
1140 *value
= !!(return_value
.devices
& device
);
1145 static acpi_status
get_device_status(u32
*value
, u32 cap
)
1147 if (wmi_has_guid(WMID_GUID3
)) {
1151 case ACER_CAP_WIRELESS
:
1152 device
= ACER_WMID3_GDS_WIRELESS
;
1154 case ACER_CAP_BLUETOOTH
:
1155 device
= ACER_WMID3_GDS_BLUETOOTH
;
1157 case ACER_CAP_THREEG
:
1158 device
= ACER_WMID3_GDS_THREEG
;
1163 return wmid3_get_device_status(value
, device
);
1166 return get_u32(value
, cap
);
1170 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1172 struct wmid3_gds_return_value return_value
;
1174 union acpi_object
*obj
;
1176 struct wmid3_gds_input_param params
= {
1177 .function_num
= 0x1,
1178 .hotkey_number
= 0x01,
1179 .devices
= ACER_WMID3_GDS_WIRELESS
|
1180 ACER_WMID3_GDS_THREEG
|
1181 ACER_WMID3_GDS_WIMAX
|
1182 ACER_WMID3_GDS_BLUETOOTH
,
1184 struct acpi_buffer input
= {
1185 sizeof(struct wmid3_gds_input_param
),
1188 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1189 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1191 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1192 if (ACPI_FAILURE(status
))
1195 obj
= output
.pointer
;
1199 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1203 if (obj
->buffer
.length
!= 8) {
1204 pr_warning("Unknown buffer length %d\n", obj
->buffer
.length
);
1209 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1212 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1213 pr_warning("Get Current Device Status failed: "
1214 "0x%x - 0x%x\n", return_value
.error_code
,
1215 return_value
.ec_return_value
);
1219 devices
= return_value
.devices
;
1220 params
.function_num
= 0x2;
1221 params
.hotkey_number
= 0x01;
1222 params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1224 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output2
);
1225 if (ACPI_FAILURE(status
))
1228 obj
= output2
.pointer
;
1232 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1236 if (obj
->buffer
.length
!= 4) {
1237 pr_warning("Unknown buffer length %d\n", obj
->buffer
.length
);
1242 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1245 if (return_value
.error_code
|| return_value
.ec_return_value
)
1246 pr_warning("Set Device Status failed: "
1247 "0x%x - 0x%x\n", return_value
.error_code
,
1248 return_value
.ec_return_value
);
1253 static acpi_status
set_device_status(u32 value
, u32 cap
)
1255 if (wmi_has_guid(WMID_GUID3
)) {
1259 case ACER_CAP_WIRELESS
:
1260 device
= ACER_WMID3_GDS_WIRELESS
;
1262 case ACER_CAP_BLUETOOTH
:
1263 device
= ACER_WMID3_GDS_BLUETOOTH
;
1265 case ACER_CAP_THREEG
:
1266 device
= ACER_WMID3_GDS_THREEG
;
1271 return wmid3_set_device_status(value
, device
);
1274 return set_u32(value
, cap
);
1281 static void acer_rfkill_update(struct work_struct
*ignored
);
1282 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1283 static void acer_rfkill_update(struct work_struct
*ignored
)
1288 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1289 if (ACPI_SUCCESS(status
)) {
1290 if (quirks
->wireless
== 3) {
1291 rfkill_set_hw_state(wireless_rfkill
, !state
);
1293 rfkill_set_sw_state(wireless_rfkill
, !state
);
1297 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1298 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1299 if (ACPI_SUCCESS(status
))
1300 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1303 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1304 status
= wmid3_get_device_status(&state
,
1305 ACER_WMID3_GDS_THREEG
);
1306 if (ACPI_SUCCESS(status
))
1307 rfkill_set_sw_state(threeg_rfkill
, !state
);
1310 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1313 static int acer_rfkill_set(void *data
, bool blocked
)
1316 u32 cap
= (unsigned long)data
;
1318 if (rfkill_inited
) {
1319 status
= set_device_status(!blocked
, cap
);
1320 if (ACPI_FAILURE(status
))
1327 static const struct rfkill_ops acer_rfkill_ops
= {
1328 .set_block
= acer_rfkill_set
,
1331 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1332 enum rfkill_type type
,
1333 char *name
, u32 cap
)
1336 struct rfkill
*rfkill_dev
;
1340 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1342 (void *)(unsigned long)cap
);
1344 return ERR_PTR(-ENOMEM
);
1346 status
= get_device_status(&state
, cap
);
1348 err
= rfkill_register(rfkill_dev
);
1350 rfkill_destroy(rfkill_dev
);
1351 return ERR_PTR(err
);
1354 if (ACPI_SUCCESS(status
))
1355 rfkill_set_sw_state(rfkill_dev
, !state
);
1360 static int acer_rfkill_init(struct device
*dev
)
1362 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1363 "acer-wireless", ACER_CAP_WIRELESS
);
1364 if (IS_ERR(wireless_rfkill
))
1365 return PTR_ERR(wireless_rfkill
);
1367 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1368 bluetooth_rfkill
= acer_rfkill_register(dev
,
1369 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1370 ACER_CAP_BLUETOOTH
);
1371 if (IS_ERR(bluetooth_rfkill
)) {
1372 rfkill_unregister(wireless_rfkill
);
1373 rfkill_destroy(wireless_rfkill
);
1374 return PTR_ERR(bluetooth_rfkill
);
1378 if (has_cap(ACER_CAP_THREEG
)) {
1379 threeg_rfkill
= acer_rfkill_register(dev
,
1380 RFKILL_TYPE_WWAN
, "acer-threeg",
1382 if (IS_ERR(threeg_rfkill
)) {
1383 rfkill_unregister(wireless_rfkill
);
1384 rfkill_destroy(wireless_rfkill
);
1385 rfkill_unregister(bluetooth_rfkill
);
1386 rfkill_destroy(bluetooth_rfkill
);
1387 return PTR_ERR(threeg_rfkill
);
1391 rfkill_inited
= true;
1393 if (ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
))
1394 schedule_delayed_work(&acer_rfkill_work
,
1395 round_jiffies_relative(HZ
));
1400 static void acer_rfkill_exit(void)
1402 if (ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
))
1403 cancel_delayed_work_sync(&acer_rfkill_work
);
1405 rfkill_unregister(wireless_rfkill
);
1406 rfkill_destroy(wireless_rfkill
);
1408 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1409 rfkill_unregister(bluetooth_rfkill
);
1410 rfkill_destroy(bluetooth_rfkill
);
1413 if (has_cap(ACER_CAP_THREEG
)) {
1414 rfkill_unregister(threeg_rfkill
);
1415 rfkill_destroy(threeg_rfkill
);
1423 static ssize_t
show_bool_threeg(struct device
*dev
,
1424 struct device_attribute
*attr
, char *buf
)
1429 pr_info("This threeg sysfs will be removed in 2012"
1430 " - used by: %s\n", current
->comm
);
1431 if (wmi_has_guid(WMID_GUID3
))
1432 status
= wmid3_get_device_status(&result
,
1433 ACER_WMID3_GDS_THREEG
);
1435 status
= get_u32(&result
, ACER_CAP_THREEG
);
1436 if (ACPI_SUCCESS(status
))
1437 return sprintf(buf
, "%u\n", result
);
1438 return sprintf(buf
, "Read error\n");
1441 static ssize_t
set_bool_threeg(struct device
*dev
,
1442 struct device_attribute
*attr
, const char *buf
, size_t count
)
1444 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
1445 acpi_status status
= set_u32(tmp
, ACER_CAP_THREEG
);
1446 pr_info("This threeg sysfs will be removed in 2012"
1447 " - used by: %s\n", current
->comm
);
1448 if (ACPI_FAILURE(status
))
1452 static DEVICE_ATTR(threeg
, S_IRUGO
| S_IWUSR
, show_bool_threeg
,
1455 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1458 pr_info("This interface sysfs will be removed in 2012"
1459 " - used by: %s\n", current
->comm
);
1460 switch (interface
->type
) {
1462 return sprintf(buf
, "AMW0\n");
1464 return sprintf(buf
, "AMW0 v2\n");
1466 return sprintf(buf
, "WMID\n");
1468 return sprintf(buf
, "Error!\n");
1472 static DEVICE_ATTR(interface
, S_IRUGO
, show_interface
, NULL
);
1474 static void acer_wmi_notify(u32 value
, void *context
)
1476 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1477 union acpi_object
*obj
;
1478 struct event_return_value return_value
;
1481 const struct key_entry
*key
;
1483 status
= wmi_get_event_data(value
, &response
);
1484 if (status
!= AE_OK
) {
1485 pr_warn("bad event status 0x%x\n", status
);
1489 obj
= (union acpi_object
*)response
.pointer
;
1493 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1494 pr_warn("Unknown response received %d\n", obj
->type
);
1498 if (obj
->buffer
.length
!= 8) {
1499 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1504 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1507 switch (return_value
.function
) {
1508 case WMID_HOTKEY_EVENT
:
1509 device_state
= return_value
.device_state
;
1510 pr_debug("device state: 0x%x\n", device_state
);
1512 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1513 return_value
.key_num
);
1515 pr_warn("Unknown key number - 0x%x\n",
1516 return_value
.key_num
);
1518 switch (key
->keycode
) {
1521 if (has_cap(ACER_CAP_WIRELESS
))
1522 rfkill_set_sw_state(wireless_rfkill
,
1523 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1524 if (has_cap(ACER_CAP_THREEG
))
1525 rfkill_set_sw_state(threeg_rfkill
,
1526 !(device_state
& ACER_WMID3_GDS_THREEG
));
1527 if (has_cap(ACER_CAP_BLUETOOTH
))
1528 rfkill_set_sw_state(bluetooth_rfkill
,
1529 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1532 sparse_keymap_report_entry(acer_wmi_input_dev
, key
,
1537 pr_warn("Unknown function number - %d - %d\n",
1538 return_value
.function
, return_value
.key_num
);
1544 wmid3_set_lm_mode(struct lm_input_params
*params
,
1545 struct lm_return_value
*return_value
)
1548 union acpi_object
*obj
;
1550 struct acpi_buffer input
= { sizeof(struct lm_input_params
), params
};
1551 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1553 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1554 if (ACPI_FAILURE(status
))
1557 obj
= output
.pointer
;
1561 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1565 if (obj
->buffer
.length
!= 4) {
1566 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1571 *return_value
= *((struct lm_return_value
*)obj
->buffer
.pointer
);
1577 static int acer_wmi_enable_ec_raw(void)
1579 struct lm_return_value return_value
;
1581 struct lm_input_params params
= {
1582 .function_num
= 0x1,
1583 .commun_devices
= 0xFFFF,
1585 .lm_status
= 0x00, /* Launch Manager Deactive */
1588 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1590 if (return_value
.error_code
|| return_value
.ec_return_value
)
1591 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1592 return_value
.error_code
,
1593 return_value
.ec_return_value
);
1595 pr_info("Enabled EC raw mode\n");
1600 static int acer_wmi_enable_lm(void)
1602 struct lm_return_value return_value
;
1604 struct lm_input_params params
= {
1605 .function_num
= 0x1,
1606 .commun_devices
= 0xFFFF,
1608 .lm_status
= 0x01, /* Launch Manager Active */
1611 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1613 if (return_value
.error_code
|| return_value
.ec_return_value
)
1614 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1615 return_value
.error_code
,
1616 return_value
.ec_return_value
);
1621 static int __init
acer_wmi_input_setup(void)
1626 acer_wmi_input_dev
= input_allocate_device();
1627 if (!acer_wmi_input_dev
)
1630 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1631 acer_wmi_input_dev
->phys
= "wmi/input0";
1632 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1634 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1638 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1639 acer_wmi_notify
, NULL
);
1640 if (ACPI_FAILURE(status
)) {
1642 goto err_free_keymap
;
1645 err
= input_register_device(acer_wmi_input_dev
);
1647 goto err_uninstall_notifier
;
1651 err_uninstall_notifier
:
1652 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1654 sparse_keymap_free(acer_wmi_input_dev
);
1656 input_free_device(acer_wmi_input_dev
);
1660 static void acer_wmi_input_destroy(void)
1662 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1663 sparse_keymap_free(acer_wmi_input_dev
);
1664 input_unregister_device(acer_wmi_input_dev
);
1670 static u32
get_wmid_devices(void)
1672 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1673 union acpi_object
*obj
;
1677 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1678 if (ACPI_FAILURE(status
))
1681 obj
= (union acpi_object
*) out
.pointer
;
1682 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1683 (obj
->buffer
.length
== sizeof(u32
) ||
1684 obj
->buffer
.length
== sizeof(u64
))) {
1685 devices
= *((u32
*) obj
->buffer
.pointer
);
1686 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1687 devices
= (u32
) obj
->integer
.value
;
1697 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1701 if (has_cap(ACER_CAP_MAILLED
)) {
1702 err
= acer_led_init(&device
->dev
);
1707 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1708 err
= acer_backlight_init(&device
->dev
);
1710 goto error_brightness
;
1713 err
= acer_rfkill_init(&device
->dev
);
1720 if (has_cap(ACER_CAP_BRIGHTNESS
))
1721 acer_backlight_exit();
1723 if (has_cap(ACER_CAP_MAILLED
))
1729 static int acer_platform_remove(struct platform_device
*device
)
1731 if (has_cap(ACER_CAP_MAILLED
))
1733 if (has_cap(ACER_CAP_BRIGHTNESS
))
1734 acer_backlight_exit();
1740 static int acer_platform_suspend(struct platform_device
*dev
,
1744 struct acer_data
*data
= &interface
->data
;
1749 if (has_cap(ACER_CAP_MAILLED
)) {
1750 get_u32(&value
, ACER_CAP_MAILLED
);
1751 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1752 data
->mailled
= value
;
1755 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1756 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1757 data
->brightness
= value
;
1763 static int acer_platform_resume(struct platform_device
*device
)
1765 struct acer_data
*data
= &interface
->data
;
1770 if (has_cap(ACER_CAP_MAILLED
))
1771 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
1773 if (has_cap(ACER_CAP_BRIGHTNESS
))
1774 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
1779 static void acer_platform_shutdown(struct platform_device
*device
)
1781 struct acer_data
*data
= &interface
->data
;
1786 if (has_cap(ACER_CAP_MAILLED
))
1787 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1790 static struct platform_driver acer_platform_driver
= {
1793 .owner
= THIS_MODULE
,
1795 .probe
= acer_platform_probe
,
1796 .remove
= acer_platform_remove
,
1797 .suspend
= acer_platform_suspend
,
1798 .resume
= acer_platform_resume
,
1799 .shutdown
= acer_platform_shutdown
,
1802 static struct platform_device
*acer_platform_device
;
1804 static int remove_sysfs(struct platform_device
*device
)
1806 if (has_cap(ACER_CAP_THREEG
))
1807 device_remove_file(&device
->dev
, &dev_attr_threeg
);
1809 device_remove_file(&device
->dev
, &dev_attr_interface
);
1814 static int create_sysfs(void)
1816 int retval
= -ENOMEM
;
1818 if (has_cap(ACER_CAP_THREEG
)) {
1819 retval
= device_create_file(&acer_platform_device
->dev
,
1825 retval
= device_create_file(&acer_platform_device
->dev
,
1826 &dev_attr_interface
);
1833 remove_sysfs(acer_platform_device
);
1837 static void remove_debugfs(void)
1839 debugfs_remove(interface
->debug
.devices
);
1840 debugfs_remove(interface
->debug
.root
);
1843 static int create_debugfs(void)
1845 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
1846 if (!interface
->debug
.root
) {
1847 pr_err("Failed to create debugfs directory");
1851 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
1852 interface
->debug
.root
,
1853 &interface
->debug
.wmid_devices
);
1854 if (!interface
->debug
.devices
)
1864 static int __init
acer_wmi_init(void)
1868 pr_info("Acer Laptop ACPI-WMI Extras\n");
1870 if (dmi_check_system(acer_blacklist
)) {
1871 pr_info("Blacklisted hardware detected - not loading\n");
1878 * Detect which ACPI-WMI interface we're using.
1880 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1881 interface
= &AMW0_V2_interface
;
1883 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1884 interface
= &wmid_interface
;
1886 if (wmi_has_guid(WMID_GUID2
) && interface
) {
1887 if (ACPI_FAILURE(WMID_set_capabilities())) {
1888 pr_err("Unable to detect available WMID devices\n");
1891 } else if (!wmi_has_guid(WMID_GUID2
) && interface
) {
1892 pr_err("No WMID device detection method found\n");
1896 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
1897 interface
= &AMW0_interface
;
1899 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1900 pr_err("Unable to detect available AMW0 devices\n");
1905 if (wmi_has_guid(AMW0_GUID1
))
1906 AMW0_find_mailled();
1909 pr_err("No or unsupported WMI interface, unable to load\n");
1915 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS
)) {
1916 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
1917 pr_info("Brightness must be controlled by "
1918 "generic video driver\n");
1921 if (wmi_has_guid(WMID_GUID3
)) {
1923 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
1924 pr_err("Cannot enable EC raw mode\n");
1927 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
1928 pr_err("Cannot enable Launch Manager mode\n");
1931 } else if (ec_raw_mode
) {
1932 pr_info("No WMID EC raw mode enable method\n");
1935 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
1936 err
= acer_wmi_input_setup();
1941 err
= platform_driver_register(&acer_platform_driver
);
1943 pr_err("Unable to register platform driver.\n");
1944 goto error_platform_register
;
1947 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
1948 if (!acer_platform_device
) {
1950 goto error_device_alloc
;
1953 err
= platform_device_add(acer_platform_device
);
1955 goto error_device_add
;
1957 err
= create_sysfs();
1959 goto error_create_sys
;
1961 if (wmi_has_guid(WMID_GUID2
)) {
1962 interface
->debug
.wmid_devices
= get_wmid_devices();
1963 err
= create_debugfs();
1965 goto error_create_debugfs
;
1968 /* Override any initial settings with values from the commandline */
1969 acer_commandline_init();
1973 error_create_debugfs
:
1974 remove_sysfs(acer_platform_device
);
1976 platform_device_del(acer_platform_device
);
1978 platform_device_put(acer_platform_device
);
1980 platform_driver_unregister(&acer_platform_driver
);
1981 error_platform_register
:
1982 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
1983 acer_wmi_input_destroy();
1988 static void __exit
acer_wmi_exit(void)
1990 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
1991 acer_wmi_input_destroy();
1993 remove_sysfs(acer_platform_device
);
1995 platform_device_unregister(acer_platform_device
);
1996 platform_driver_unregister(&acer_platform_driver
);
1998 pr_info("Acer Laptop WMI Extras unloaded\n");
2002 module_init(acer_wmi_init
);
2003 module_exit(acer_wmi_exit
);