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>
46 #include <acpi/video.h>
48 MODULE_AUTHOR("Carlos Corbacho");
49 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
50 MODULE_LICENSE("GPL");
54 * Meaning is unknown - this number is required for writing to ACPI for AMW0
55 * (it's also used in acerhk when directly accessing the BIOS)
57 #define ACER_AMW0_WRITE 0x9610
60 * Bit masks for the AMW0 interface
62 #define ACER_AMW0_WIRELESS_MASK 0x35
63 #define ACER_AMW0_BLUETOOTH_MASK 0x34
64 #define ACER_AMW0_MAILLED_MASK 0x31
67 * Method IDs for WMID interface
69 #define ACER_WMID_GET_WIRELESS_METHODID 1
70 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
71 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
72 #define ACER_WMID_SET_WIRELESS_METHODID 4
73 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
74 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
75 #define ACER_WMID_GET_THREEG_METHODID 10
76 #define ACER_WMID_SET_THREEG_METHODID 11
79 * Acer ACPI method GUIDs
81 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
82 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
83 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
84 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
85 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
88 * Acer ACPI event GUIDs
90 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
92 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
93 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
94 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
96 enum acer_wmi_event_ids
{
97 WMID_HOTKEY_EVENT
= 0x1,
100 static const struct key_entry acer_wmi_keymap
[] = {
101 {KE_KEY
, 0x01, {KEY_WLAN
} }, /* WiFi */
102 {KE_KEY
, 0x03, {KEY_WLAN
} }, /* WiFi */
103 {KE_KEY
, 0x04, {KEY_WLAN
} }, /* WiFi */
104 {KE_KEY
, 0x12, {KEY_BLUETOOTH
} }, /* BT */
105 {KE_KEY
, 0x21, {KEY_PROG1
} }, /* Backup */
106 {KE_KEY
, 0x22, {KEY_PROG2
} }, /* Arcade */
107 {KE_KEY
, 0x23, {KEY_PROG3
} }, /* P_Key */
108 {KE_KEY
, 0x24, {KEY_PROG4
} }, /* Social networking_Key */
109 {KE_KEY
, 0x29, {KEY_PROG3
} }, /* P_Key for TM8372 */
110 {KE_IGNORE
, 0x41, {KEY_MUTE
} },
111 {KE_IGNORE
, 0x42, {KEY_PREVIOUSSONG
} },
112 {KE_IGNORE
, 0x4d, {KEY_PREVIOUSSONG
} },
113 {KE_IGNORE
, 0x43, {KEY_NEXTSONG
} },
114 {KE_IGNORE
, 0x4e, {KEY_NEXTSONG
} },
115 {KE_IGNORE
, 0x44, {KEY_PLAYPAUSE
} },
116 {KE_IGNORE
, 0x4f, {KEY_PLAYPAUSE
} },
117 {KE_IGNORE
, 0x45, {KEY_STOP
} },
118 {KE_IGNORE
, 0x50, {KEY_STOP
} },
119 {KE_IGNORE
, 0x48, {KEY_VOLUMEUP
} },
120 {KE_IGNORE
, 0x49, {KEY_VOLUMEDOWN
} },
121 {KE_IGNORE
, 0x4a, {KEY_VOLUMEDOWN
} },
122 {KE_IGNORE
, 0x61, {KEY_SWITCHVIDEOMODE
} },
123 {KE_IGNORE
, 0x62, {KEY_BRIGHTNESSUP
} },
124 {KE_IGNORE
, 0x63, {KEY_BRIGHTNESSDOWN
} },
125 {KE_KEY
, 0x64, {KEY_SWITCHVIDEOMODE
} }, /* Display Switch */
126 {KE_IGNORE
, 0x81, {KEY_SLEEP
} },
127 {KE_KEY
, 0x82, {KEY_TOUCHPAD_TOGGLE
} }, /* Touch Pad On/Off */
128 {KE_IGNORE
, 0x83, {KEY_TOUCHPAD_TOGGLE
} },
132 static struct input_dev
*acer_wmi_input_dev
;
134 struct event_return_value
{
139 } __attribute__((packed
));
142 * GUID3 Get Device Status device flags
144 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
145 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
146 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
147 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
149 struct lm_input_params
{
150 u8 function_num
; /* Function Number */
151 u16 commun_devices
; /* Communication type devices default status */
152 u16 devices
; /* Other type devices default status */
153 u8 lm_status
; /* Launch Manager Status */
155 } __attribute__((packed
));
157 struct lm_return_value
{
158 u8 error_code
; /* Error Code */
159 u8 ec_return_value
; /* EC Return Value */
161 } __attribute__((packed
));
163 struct wmid3_gds_set_input_param
{ /* Set Device Status input parameter */
164 u8 function_num
; /* Function Number */
165 u8 hotkey_number
; /* Hotkey Number */
166 u16 devices
; /* Set Device */
167 u8 volume_value
; /* Volume Value */
168 } __attribute__((packed
));
170 struct wmid3_gds_get_input_param
{ /* Get Device Status input parameter */
171 u8 function_num
; /* Function Number */
172 u8 hotkey_number
; /* Hotkey Number */
173 u16 devices
; /* Get Device */
174 } __attribute__((packed
));
176 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
177 u8 error_code
; /* Error Code */
178 u8 ec_return_value
; /* EC Return Value */
179 u16 devices
; /* Current Device Status */
181 } __attribute__((packed
));
183 struct hotkey_function_type_aa
{
187 u16 commun_func_bitmap
;
188 u16 application_func_bitmap
;
189 u16 media_func_bitmap
;
190 u16 display_func_bitmap
;
191 u16 others_func_bitmap
;
192 u8 commun_fn_key_number
;
193 } __attribute__((packed
));
196 * Interface capability flags
198 #define ACER_CAP_MAILLED (1<<0)
199 #define ACER_CAP_WIRELESS (1<<1)
200 #define ACER_CAP_BLUETOOTH (1<<2)
201 #define ACER_CAP_BRIGHTNESS (1<<3)
202 #define ACER_CAP_THREEG (1<<4)
203 #define ACER_CAP_ANY (0xFFFFFFFF)
206 * Interface type flags
208 enum interface_flags
{
215 #define ACER_DEFAULT_WIRELESS 0
216 #define ACER_DEFAULT_BLUETOOTH 0
217 #define ACER_DEFAULT_MAILLED 0
218 #define ACER_DEFAULT_THREEG 0
220 static int max_brightness
= 0xF;
222 static int mailled
= -1;
223 static int brightness
= -1;
224 static int threeg
= -1;
225 static int force_series
;
226 static bool ec_raw_mode
;
227 static bool has_type_aa
;
228 static u16 commun_func_bitmap
;
229 static u8 commun_fn_key_number
;
231 module_param(mailled
, int, 0444);
232 module_param(brightness
, int, 0444);
233 module_param(threeg
, int, 0444);
234 module_param(force_series
, int, 0444);
235 module_param(ec_raw_mode
, bool, 0444);
236 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
237 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
238 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
239 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
240 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
250 struct dentry
*devices
;
254 static struct rfkill
*wireless_rfkill
;
255 static struct rfkill
*bluetooth_rfkill
;
256 static struct rfkill
*threeg_rfkill
;
257 static bool rfkill_inited
;
259 /* Each low-level interface must define at least some of the following */
260 struct wmi_interface
{
261 /* The WMI device type */
264 /* The capabilities this interface provides */
267 /* Private data for the current interface */
268 struct acer_data data
;
270 /* debugfs entries associated with this interface */
271 struct acer_debug debug
;
274 /* The static interface pointer, points to the currently detected interface */
275 static struct wmi_interface
*interface
;
278 * Embedded Controller quirks
279 * Some laptops require us to directly access the EC to either enable or query
280 * features that are not available through WMI.
290 static struct quirk_entry
*quirks
;
292 static void set_quirks(void)
298 interface
->capability
|= ACER_CAP_MAILLED
;
300 if (quirks
->brightness
)
301 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
304 static int dmi_matched(const struct dmi_system_id
*dmi
)
306 quirks
= dmi
->driver_data
;
310 static struct quirk_entry quirk_unknown
= {
313 static struct quirk_entry quirk_acer_aspire_1520
= {
317 static struct quirk_entry quirk_acer_travelmate_2490
= {
321 /* This AMW0 laptop has no bluetooth */
322 static struct quirk_entry quirk_medion_md_98300
= {
326 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
330 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
334 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
335 static struct dmi_system_id __devinitdata acer_blacklist
[] = {
337 .ident
= "Acer Aspire One (SSD)",
339 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
340 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
344 .ident
= "Acer Aspire One (HDD)",
346 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
347 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
353 static struct dmi_system_id acer_quirks
[] = {
355 .callback
= dmi_matched
,
356 .ident
= "Acer Aspire 1360",
358 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
359 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
361 .driver_data
= &quirk_acer_aspire_1520
,
364 .callback
= dmi_matched
,
365 .ident
= "Acer Aspire 1520",
367 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
368 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
370 .driver_data
= &quirk_acer_aspire_1520
,
373 .callback
= dmi_matched
,
374 .ident
= "Acer Aspire 3100",
376 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
377 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
379 .driver_data
= &quirk_acer_travelmate_2490
,
382 .callback
= dmi_matched
,
383 .ident
= "Acer Aspire 3610",
385 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
386 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
388 .driver_data
= &quirk_acer_travelmate_2490
,
391 .callback
= dmi_matched
,
392 .ident
= "Acer Aspire 5100",
394 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
395 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
397 .driver_data
= &quirk_acer_travelmate_2490
,
400 .callback
= dmi_matched
,
401 .ident
= "Acer Aspire 5610",
403 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
404 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
406 .driver_data
= &quirk_acer_travelmate_2490
,
409 .callback
= dmi_matched
,
410 .ident
= "Acer Aspire 5630",
412 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
413 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
415 .driver_data
= &quirk_acer_travelmate_2490
,
418 .callback
= dmi_matched
,
419 .ident
= "Acer Aspire 5650",
421 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
422 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
424 .driver_data
= &quirk_acer_travelmate_2490
,
427 .callback
= dmi_matched
,
428 .ident
= "Acer Aspire 5680",
430 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
431 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
433 .driver_data
= &quirk_acer_travelmate_2490
,
436 .callback
= dmi_matched
,
437 .ident
= "Acer Aspire 9110",
439 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
440 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
442 .driver_data
= &quirk_acer_travelmate_2490
,
445 .callback
= dmi_matched
,
446 .ident
= "Acer TravelMate 2490",
448 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
449 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
451 .driver_data
= &quirk_acer_travelmate_2490
,
454 .callback
= dmi_matched
,
455 .ident
= "Acer TravelMate 4200",
457 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
458 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
460 .driver_data
= &quirk_acer_travelmate_2490
,
463 .callback
= dmi_matched
,
464 .ident
= "Fujitsu Siemens Amilo Li 1718",
466 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
467 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
469 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
472 .callback
= dmi_matched
,
473 .ident
= "Medion MD 98300",
475 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
476 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
478 .driver_data
= &quirk_medion_md_98300
,
481 .callback
= dmi_matched
,
482 .ident
= "Lenovo Ideapad S205",
484 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
485 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
487 .driver_data
= &quirk_lenovo_ideapad_s205
,
490 .callback
= dmi_matched
,
491 .ident
= "Lenovo Ideapad S205 (Brazos)",
493 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
494 DMI_MATCH(DMI_PRODUCT_NAME
, "Brazos"),
496 .driver_data
= &quirk_lenovo_ideapad_s205
,
499 .callback
= dmi_matched
,
500 .ident
= "Lenovo 3000 N200",
502 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
503 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
505 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
510 static int video_set_backlight_video_vendor(const struct dmi_system_id
*d
)
512 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
513 pr_info("Brightness must be controlled by generic video driver\n");
517 static const struct dmi_system_id video_vendor_dmi_table
[] = {
519 .callback
= video_set_backlight_video_vendor
,
520 .ident
= "Acer TravelMate 4750",
522 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
523 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4750"),
529 /* Find which quirks are needed for a particular vendor/ model pair */
530 static void find_quirks(void)
533 dmi_check_system(acer_quirks
);
534 } else if (force_series
== 2490) {
535 quirks
= &quirk_acer_travelmate_2490
;
539 quirks
= &quirk_unknown
;
545 * General interface convenience methods
548 static bool has_cap(u32 cap
)
550 if ((interface
->capability
& cap
) != 0)
557 * AMW0 (V1) interface
574 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
575 struct acpi_buffer
*result
)
577 struct acpi_buffer input
;
579 input
.length
= sizeof(struct wmab_args
);
580 input
.pointer
= (u8
*)regbuf
;
582 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
587 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
)
593 case ACER_CAP_MAILLED
:
594 switch (quirks
->mailled
) {
596 err
= ec_read(0xA, &result
);
599 *value
= (result
>> 7) & 0x1;
603 case ACER_CAP_WIRELESS
:
604 switch (quirks
->wireless
) {
606 err
= ec_read(0x7B, &result
);
609 *value
= result
& 0x1;
612 err
= ec_read(0x71, &result
);
615 *value
= result
& 0x1;
618 err
= ec_read(0x78, &result
);
621 *value
= result
& 0x1;
624 err
= ec_read(0xA, &result
);
627 *value
= (result
>> 2) & 0x1;
631 case ACER_CAP_BLUETOOTH
:
632 switch (quirks
->bluetooth
) {
634 err
= ec_read(0xA, &result
);
637 *value
= (result
>> 4) & 0x1;
641 case ACER_CAP_BRIGHTNESS
:
642 switch (quirks
->brightness
) {
644 err
= ec_read(0x83, &result
);
657 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
)
659 struct wmab_args args
;
661 args
.eax
= ACER_AMW0_WRITE
;
662 args
.ebx
= value
? (1<<8) : 0;
663 args
.ecx
= args
.edx
= 0;
666 case ACER_CAP_MAILLED
:
668 return AE_BAD_PARAMETER
;
669 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
671 case ACER_CAP_WIRELESS
:
673 return AE_BAD_PARAMETER
;
674 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
676 case ACER_CAP_BLUETOOTH
:
678 return AE_BAD_PARAMETER
;
679 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
681 case ACER_CAP_BRIGHTNESS
:
682 if (value
> max_brightness
)
683 return AE_BAD_PARAMETER
;
684 switch (quirks
->brightness
) {
686 return ec_write(0x83, value
);
693 /* Actually do the set */
694 return wmab_execute(&args
, NULL
);
697 static acpi_status
AMW0_find_mailled(void)
699 struct wmab_args args
;
701 acpi_status status
= AE_OK
;
702 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
703 union acpi_object
*obj
;
706 args
.ebx
= args
.ecx
= args
.edx
= 0;
708 status
= wmab_execute(&args
, &out
);
709 if (ACPI_FAILURE(status
))
712 obj
= (union acpi_object
*) out
.pointer
;
713 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
714 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
715 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
722 interface
->capability
|= ACER_CAP_MAILLED
;
729 static int AMW0_set_cap_acpi_check_device_found
;
731 static acpi_status
AMW0_set_cap_acpi_check_device_cb(acpi_handle handle
,
732 u32 level
, void *context
, void **retval
)
734 AMW0_set_cap_acpi_check_device_found
= 1;
738 static const struct acpi_device_id norfkill_ids
[] = {
742 { "SNY5001", 0}, /* sony-laptop in charge */
746 static int AMW0_set_cap_acpi_check_device(void)
748 const struct acpi_device_id
*id
;
750 for (id
= norfkill_ids
; id
->id
[0]; id
++)
751 acpi_get_devices(id
->id
, AMW0_set_cap_acpi_check_device_cb
,
753 return AMW0_set_cap_acpi_check_device_found
;
756 static acpi_status
AMW0_set_capabilities(void)
758 struct wmab_args args
;
761 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
762 union acpi_object
*obj
;
765 * On laptops with this strange GUID (non Acer), normal probing doesn't
768 if (wmi_has_guid(AMW0_GUID2
)) {
769 if ((quirks
!= &quirk_unknown
) ||
770 !AMW0_set_cap_acpi_check_device())
771 interface
->capability
|= ACER_CAP_WIRELESS
;
775 args
.eax
= ACER_AMW0_WRITE
;
776 args
.ecx
= args
.edx
= 0;
778 args
.ebx
= 0xa2 << 8;
779 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
781 status
= wmab_execute(&args
, &out
);
782 if (ACPI_FAILURE(status
))
786 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
787 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
788 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
795 interface
->capability
|= ACER_CAP_WIRELESS
;
798 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
801 * It's ok to use existing buffer for next wmab_execute call.
802 * But we need to kfree(out.pointer) if next wmab_execute fail.
804 status
= wmab_execute(&args
, &out
);
805 if (ACPI_FAILURE(status
))
808 obj
= (union acpi_object
*) out
.pointer
;
809 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
810 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
811 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
818 interface
->capability
|= ACER_CAP_BLUETOOTH
;
821 * This appears to be safe to enable, since all Wistron based laptops
822 * appear to use the same EC register for brightness, even if they
823 * differ for wireless, etc
825 if (quirks
->brightness
>= 0)
826 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
834 static struct wmi_interface AMW0_interface
= {
838 static struct wmi_interface AMW0_V2_interface
= {
839 .type
= ACER_AMW0_V2
,
843 * New interface (The WMID interface)
846 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
848 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
849 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
850 union acpi_object
*obj
;
854 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
856 if (ACPI_FAILURE(status
))
859 obj
= (union acpi_object
*) result
.pointer
;
860 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
861 (obj
->buffer
.length
== sizeof(u32
) ||
862 obj
->buffer
.length
== sizeof(u64
))) {
863 tmp
= *((u32
*) obj
->buffer
.pointer
);
864 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
865 tmp
= (u32
) obj
->integer
.value
;
873 kfree(result
.pointer
);
878 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
)
882 u32 result
, method_id
= 0;
885 case ACER_CAP_WIRELESS
:
886 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
888 case ACER_CAP_BLUETOOTH
:
889 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
891 case ACER_CAP_BRIGHTNESS
:
892 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
894 case ACER_CAP_THREEG
:
895 method_id
= ACER_WMID_GET_THREEG_METHODID
;
897 case ACER_CAP_MAILLED
:
898 if (quirks
->mailled
== 1) {
906 status
= WMI_execute_u32(method_id
, 0, &result
);
908 if (ACPI_SUCCESS(status
))
914 static acpi_status
WMID_set_u32(u32 value
, u32 cap
)
920 case ACER_CAP_BRIGHTNESS
:
921 if (value
> max_brightness
)
922 return AE_BAD_PARAMETER
;
923 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
925 case ACER_CAP_WIRELESS
:
927 return AE_BAD_PARAMETER
;
928 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
930 case ACER_CAP_BLUETOOTH
:
932 return AE_BAD_PARAMETER
;
933 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
935 case ACER_CAP_THREEG
:
937 return AE_BAD_PARAMETER
;
938 method_id
= ACER_WMID_SET_THREEG_METHODID
;
940 case ACER_CAP_MAILLED
:
942 return AE_BAD_PARAMETER
;
943 if (quirks
->mailled
== 1) {
944 param
= value
? 0x92 : 0x93;
946 i8042_command(¶m
, 0x1059);
954 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
957 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
959 struct wmid3_gds_return_value return_value
;
961 union acpi_object
*obj
;
962 struct wmid3_gds_get_input_param params
= {
964 .hotkey_number
= commun_fn_key_number
,
967 struct acpi_buffer input
= {
968 sizeof(struct wmid3_gds_get_input_param
),
971 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
973 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
974 if (ACPI_FAILURE(status
))
977 obj
= output
.pointer
;
981 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
985 if (obj
->buffer
.length
!= 8) {
986 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
991 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
994 if (return_value
.error_code
|| return_value
.ec_return_value
)
995 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
997 return_value
.error_code
,
998 return_value
.ec_return_value
);
1000 *value
= !!(return_value
.devices
& device
);
1005 static acpi_status
wmid_v2_get_u32(u32
*value
, u32 cap
)
1010 case ACER_CAP_WIRELESS
:
1011 device
= ACER_WMID3_GDS_WIRELESS
;
1013 case ACER_CAP_BLUETOOTH
:
1014 device
= ACER_WMID3_GDS_BLUETOOTH
;
1016 case ACER_CAP_THREEG
:
1017 device
= ACER_WMID3_GDS_THREEG
;
1022 return wmid3_get_device_status(value
, device
);
1025 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1027 struct wmid3_gds_return_value return_value
;
1029 union acpi_object
*obj
;
1031 struct wmid3_gds_get_input_param get_params
= {
1032 .function_num
= 0x1,
1033 .hotkey_number
= commun_fn_key_number
,
1034 .devices
= commun_func_bitmap
,
1036 struct acpi_buffer get_input
= {
1037 sizeof(struct wmid3_gds_get_input_param
),
1040 struct wmid3_gds_set_input_param set_params
= {
1041 .function_num
= 0x2,
1042 .hotkey_number
= commun_fn_key_number
,
1043 .devices
= commun_func_bitmap
,
1045 struct acpi_buffer set_input
= {
1046 sizeof(struct wmid3_gds_set_input_param
),
1049 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1050 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1052 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &get_input
, &output
);
1053 if (ACPI_FAILURE(status
))
1056 obj
= output
.pointer
;
1060 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1064 if (obj
->buffer
.length
!= 8) {
1065 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1070 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1073 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1074 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1075 return_value
.error_code
,
1076 return_value
.ec_return_value
);
1080 devices
= return_value
.devices
;
1081 set_params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1083 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &set_input
, &output2
);
1084 if (ACPI_FAILURE(status
))
1087 obj
= output2
.pointer
;
1091 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1095 if (obj
->buffer
.length
!= 4) {
1096 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1101 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1104 if (return_value
.error_code
|| return_value
.ec_return_value
)
1105 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1106 return_value
.error_code
,
1107 return_value
.ec_return_value
);
1112 static acpi_status
wmid_v2_set_u32(u32 value
, u32 cap
)
1117 case ACER_CAP_WIRELESS
:
1118 device
= ACER_WMID3_GDS_WIRELESS
;
1120 case ACER_CAP_BLUETOOTH
:
1121 device
= ACER_WMID3_GDS_BLUETOOTH
;
1123 case ACER_CAP_THREEG
:
1124 device
= ACER_WMID3_GDS_THREEG
;
1129 return wmid3_set_device_status(value
, device
);
1132 static void type_aa_dmi_decode(const struct dmi_header
*header
, void *dummy
)
1134 struct hotkey_function_type_aa
*type_aa
;
1136 /* We are looking for OEM-specific Type AAh */
1137 if (header
->type
!= 0xAA)
1141 type_aa
= (struct hotkey_function_type_aa
*) header
;
1143 pr_info("Function bitmap for Communication Button: 0x%x\n",
1144 type_aa
->commun_func_bitmap
);
1145 commun_func_bitmap
= type_aa
->commun_func_bitmap
;
1147 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
1148 interface
->capability
|= ACER_CAP_WIRELESS
;
1149 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
1150 interface
->capability
|= ACER_CAP_THREEG
;
1151 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
1152 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1154 commun_fn_key_number
= type_aa
->commun_fn_key_number
;
1157 static acpi_status
WMID_set_capabilities(void)
1159 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1160 union acpi_object
*obj
;
1164 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1165 if (ACPI_FAILURE(status
))
1168 obj
= (union acpi_object
*) out
.pointer
;
1169 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1170 (obj
->buffer
.length
== sizeof(u32
) ||
1171 obj
->buffer
.length
== sizeof(u64
))) {
1172 devices
= *((u32
*) obj
->buffer
.pointer
);
1173 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1174 devices
= (u32
) obj
->integer
.value
;
1180 pr_info("Function bitmap for Communication Device: 0x%x\n", devices
);
1182 interface
->capability
|= ACER_CAP_WIRELESS
;
1184 interface
->capability
|= ACER_CAP_THREEG
;
1186 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1188 if (!(devices
& 0x20))
1189 max_brightness
= 0x9;
1195 static struct wmi_interface wmid_interface
= {
1199 static struct wmi_interface wmid_v2_interface
= {
1200 .type
= ACER_WMID_v2
,
1204 * Generic Device (interface-independent)
1207 static acpi_status
get_u32(u32
*value
, u32 cap
)
1209 acpi_status status
= AE_ERROR
;
1211 switch (interface
->type
) {
1213 status
= AMW0_get_u32(value
, cap
);
1216 if (cap
== ACER_CAP_MAILLED
) {
1217 status
= AMW0_get_u32(value
, cap
);
1221 status
= WMID_get_u32(value
, cap
);
1224 if (cap
& (ACER_CAP_WIRELESS
|
1225 ACER_CAP_BLUETOOTH
|
1227 status
= wmid_v2_get_u32(value
, cap
);
1228 else if (wmi_has_guid(WMID_GUID2
))
1229 status
= WMID_get_u32(value
, cap
);
1236 static acpi_status
set_u32(u32 value
, u32 cap
)
1240 if (interface
->capability
& cap
) {
1241 switch (interface
->type
) {
1243 return AMW0_set_u32(value
, cap
);
1245 if (cap
== ACER_CAP_MAILLED
)
1246 return AMW0_set_u32(value
, cap
);
1249 * On some models, some WMID methods don't toggle
1250 * properly. For those cases, we want to run the AMW0
1251 * method afterwards to be certain we've really toggled
1254 if (cap
== ACER_CAP_WIRELESS
||
1255 cap
== ACER_CAP_BLUETOOTH
) {
1256 status
= WMID_set_u32(value
, cap
);
1257 if (ACPI_FAILURE(status
))
1260 return AMW0_set_u32(value
, cap
);
1263 return WMID_set_u32(value
, cap
);
1265 if (cap
& (ACER_CAP_WIRELESS
|
1266 ACER_CAP_BLUETOOTH
|
1268 return wmid_v2_set_u32(value
, cap
);
1269 else if (wmi_has_guid(WMID_GUID2
))
1270 return WMID_set_u32(value
, cap
);
1272 return AE_BAD_PARAMETER
;
1275 return AE_BAD_PARAMETER
;
1278 static void __init
acer_commandline_init(void)
1281 * These will all fail silently if the value given is invalid, or the
1282 * capability isn't available on the given interface
1285 set_u32(mailled
, ACER_CAP_MAILLED
);
1286 if (!has_type_aa
&& threeg
>= 0)
1287 set_u32(threeg
, ACER_CAP_THREEG
);
1288 if (brightness
>= 0)
1289 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1293 * LED device (Mail LED only, no other LEDs known yet)
1295 static void mail_led_set(struct led_classdev
*led_cdev
,
1296 enum led_brightness value
)
1298 set_u32(value
, ACER_CAP_MAILLED
);
1301 static struct led_classdev mail_led
= {
1302 .name
= "acer-wmi::mail",
1303 .brightness_set
= mail_led_set
,
1306 static int __devinit
acer_led_init(struct device
*dev
)
1308 return led_classdev_register(dev
, &mail_led
);
1311 static void acer_led_exit(void)
1313 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1314 led_classdev_unregister(&mail_led
);
1320 static struct backlight_device
*acer_backlight_device
;
1322 static int read_brightness(struct backlight_device
*bd
)
1325 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1329 static int update_bl_status(struct backlight_device
*bd
)
1331 int intensity
= bd
->props
.brightness
;
1333 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1335 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1338 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1343 static const struct backlight_ops acer_bl_ops
= {
1344 .get_brightness
= read_brightness
,
1345 .update_status
= update_bl_status
,
1348 static int __devinit
acer_backlight_init(struct device
*dev
)
1350 struct backlight_properties props
;
1351 struct backlight_device
*bd
;
1353 memset(&props
, 0, sizeof(struct backlight_properties
));
1354 props
.type
= BACKLIGHT_PLATFORM
;
1355 props
.max_brightness
= max_brightness
;
1356 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1359 pr_err("Could not register Acer backlight device\n");
1360 acer_backlight_device
= NULL
;
1364 acer_backlight_device
= bd
;
1366 bd
->props
.power
= FB_BLANK_UNBLANK
;
1367 bd
->props
.brightness
= read_brightness(bd
);
1368 backlight_update_status(bd
);
1372 static void acer_backlight_exit(void)
1374 backlight_device_unregister(acer_backlight_device
);
1380 static void acer_rfkill_update(struct work_struct
*ignored
);
1381 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1382 static void acer_rfkill_update(struct work_struct
*ignored
)
1387 if (has_cap(ACER_CAP_WIRELESS
)) {
1388 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1389 if (ACPI_SUCCESS(status
)) {
1390 if (quirks
->wireless
== 3)
1391 rfkill_set_hw_state(wireless_rfkill
, !state
);
1393 rfkill_set_sw_state(wireless_rfkill
, !state
);
1397 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1398 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1399 if (ACPI_SUCCESS(status
))
1400 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1403 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1404 status
= get_u32(&state
, ACER_WMID3_GDS_THREEG
);
1405 if (ACPI_SUCCESS(status
))
1406 rfkill_set_sw_state(threeg_rfkill
, !state
);
1409 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1412 static int acer_rfkill_set(void *data
, bool blocked
)
1415 u32 cap
= (unsigned long)data
;
1417 if (rfkill_inited
) {
1418 status
= set_u32(!blocked
, cap
);
1419 if (ACPI_FAILURE(status
))
1426 static const struct rfkill_ops acer_rfkill_ops
= {
1427 .set_block
= acer_rfkill_set
,
1430 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1431 enum rfkill_type type
,
1432 char *name
, u32 cap
)
1435 struct rfkill
*rfkill_dev
;
1439 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1441 (void *)(unsigned long)cap
);
1443 return ERR_PTR(-ENOMEM
);
1445 status
= get_u32(&state
, cap
);
1447 err
= rfkill_register(rfkill_dev
);
1449 rfkill_destroy(rfkill_dev
);
1450 return ERR_PTR(err
);
1453 if (ACPI_SUCCESS(status
))
1454 rfkill_set_sw_state(rfkill_dev
, !state
);
1459 static int acer_rfkill_init(struct device
*dev
)
1463 if (has_cap(ACER_CAP_WIRELESS
)) {
1464 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1465 "acer-wireless", ACER_CAP_WIRELESS
);
1466 if (IS_ERR(wireless_rfkill
)) {
1467 err
= PTR_ERR(wireless_rfkill
);
1468 goto error_wireless
;
1472 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1473 bluetooth_rfkill
= acer_rfkill_register(dev
,
1474 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1475 ACER_CAP_BLUETOOTH
);
1476 if (IS_ERR(bluetooth_rfkill
)) {
1477 err
= PTR_ERR(bluetooth_rfkill
);
1478 goto error_bluetooth
;
1482 if (has_cap(ACER_CAP_THREEG
)) {
1483 threeg_rfkill
= acer_rfkill_register(dev
,
1484 RFKILL_TYPE_WWAN
, "acer-threeg",
1486 if (IS_ERR(threeg_rfkill
)) {
1487 err
= PTR_ERR(threeg_rfkill
);
1492 rfkill_inited
= true;
1494 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1495 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1496 schedule_delayed_work(&acer_rfkill_work
,
1497 round_jiffies_relative(HZ
));
1502 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1503 rfkill_unregister(bluetooth_rfkill
);
1504 rfkill_destroy(bluetooth_rfkill
);
1507 if (has_cap(ACER_CAP_WIRELESS
)) {
1508 rfkill_unregister(wireless_rfkill
);
1509 rfkill_destroy(wireless_rfkill
);
1515 static void acer_rfkill_exit(void)
1517 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1518 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1519 cancel_delayed_work_sync(&acer_rfkill_work
);
1521 if (has_cap(ACER_CAP_WIRELESS
)) {
1522 rfkill_unregister(wireless_rfkill
);
1523 rfkill_destroy(wireless_rfkill
);
1526 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1527 rfkill_unregister(bluetooth_rfkill
);
1528 rfkill_destroy(bluetooth_rfkill
);
1531 if (has_cap(ACER_CAP_THREEG
)) {
1532 rfkill_unregister(threeg_rfkill
);
1533 rfkill_destroy(threeg_rfkill
);
1541 static ssize_t
show_bool_threeg(struct device
*dev
,
1542 struct device_attribute
*attr
, char *buf
)
1547 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1549 status
= get_u32(&result
, ACER_CAP_THREEG
);
1550 if (ACPI_SUCCESS(status
))
1551 return sprintf(buf
, "%u\n", result
);
1552 return sprintf(buf
, "Read error\n");
1555 static ssize_t
set_bool_threeg(struct device
*dev
,
1556 struct device_attribute
*attr
, const char *buf
, size_t count
)
1558 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
1559 acpi_status status
= set_u32(tmp
, ACER_CAP_THREEG
);
1560 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1562 if (ACPI_FAILURE(status
))
1566 static DEVICE_ATTR(threeg
, S_IRUGO
| S_IWUSR
, show_bool_threeg
,
1569 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1572 pr_info("This interface sysfs will be removed in 2012 - used by: %s\n",
1574 switch (interface
->type
) {
1576 return sprintf(buf
, "AMW0\n");
1578 return sprintf(buf
, "AMW0 v2\n");
1580 return sprintf(buf
, "WMID\n");
1582 return sprintf(buf
, "WMID v2\n");
1584 return sprintf(buf
, "Error!\n");
1588 static DEVICE_ATTR(interface
, S_IRUGO
, show_interface
, NULL
);
1590 static void acer_wmi_notify(u32 value
, void *context
)
1592 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1593 union acpi_object
*obj
;
1594 struct event_return_value return_value
;
1597 const struct key_entry
*key
;
1599 status
= wmi_get_event_data(value
, &response
);
1600 if (status
!= AE_OK
) {
1601 pr_warn("bad event status 0x%x\n", status
);
1605 obj
= (union acpi_object
*)response
.pointer
;
1609 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1610 pr_warn("Unknown response received %d\n", obj
->type
);
1614 if (obj
->buffer
.length
!= 8) {
1615 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1620 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1623 switch (return_value
.function
) {
1624 case WMID_HOTKEY_EVENT
:
1625 device_state
= return_value
.device_state
;
1626 pr_debug("device state: 0x%x\n", device_state
);
1628 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1629 return_value
.key_num
);
1631 pr_warn("Unknown key number - 0x%x\n",
1632 return_value
.key_num
);
1634 switch (key
->keycode
) {
1637 if (has_cap(ACER_CAP_WIRELESS
))
1638 rfkill_set_sw_state(wireless_rfkill
,
1639 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1640 if (has_cap(ACER_CAP_THREEG
))
1641 rfkill_set_sw_state(threeg_rfkill
,
1642 !(device_state
& ACER_WMID3_GDS_THREEG
));
1643 if (has_cap(ACER_CAP_BLUETOOTH
))
1644 rfkill_set_sw_state(bluetooth_rfkill
,
1645 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1648 sparse_keymap_report_entry(acer_wmi_input_dev
, key
,
1653 pr_warn("Unknown function number - %d - %d\n",
1654 return_value
.function
, return_value
.key_num
);
1660 wmid3_set_lm_mode(struct lm_input_params
*params
,
1661 struct lm_return_value
*return_value
)
1664 union acpi_object
*obj
;
1666 struct acpi_buffer input
= { sizeof(struct lm_input_params
), params
};
1667 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1669 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1670 if (ACPI_FAILURE(status
))
1673 obj
= output
.pointer
;
1677 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1681 if (obj
->buffer
.length
!= 4) {
1682 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1687 *return_value
= *((struct lm_return_value
*)obj
->buffer
.pointer
);
1693 static int acer_wmi_enable_ec_raw(void)
1695 struct lm_return_value return_value
;
1697 struct lm_input_params params
= {
1698 .function_num
= 0x1,
1699 .commun_devices
= 0xFFFF,
1701 .lm_status
= 0x00, /* Launch Manager Deactive */
1704 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1706 if (return_value
.error_code
|| return_value
.ec_return_value
)
1707 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1708 return_value
.error_code
,
1709 return_value
.ec_return_value
);
1711 pr_info("Enabled EC raw mode\n");
1716 static int acer_wmi_enable_lm(void)
1718 struct lm_return_value return_value
;
1720 struct lm_input_params params
= {
1721 .function_num
= 0x1,
1722 .commun_devices
= 0xFFFF,
1724 .lm_status
= 0x01, /* Launch Manager Active */
1727 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1729 if (return_value
.error_code
|| return_value
.ec_return_value
)
1730 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1731 return_value
.error_code
,
1732 return_value
.ec_return_value
);
1737 static int __init
acer_wmi_input_setup(void)
1742 acer_wmi_input_dev
= input_allocate_device();
1743 if (!acer_wmi_input_dev
)
1746 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1747 acer_wmi_input_dev
->phys
= "wmi/input0";
1748 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1750 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1754 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1755 acer_wmi_notify
, NULL
);
1756 if (ACPI_FAILURE(status
)) {
1758 goto err_free_keymap
;
1761 err
= input_register_device(acer_wmi_input_dev
);
1763 goto err_uninstall_notifier
;
1767 err_uninstall_notifier
:
1768 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1770 sparse_keymap_free(acer_wmi_input_dev
);
1772 input_free_device(acer_wmi_input_dev
);
1776 static void acer_wmi_input_destroy(void)
1778 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1779 sparse_keymap_free(acer_wmi_input_dev
);
1780 input_unregister_device(acer_wmi_input_dev
);
1786 static u32
get_wmid_devices(void)
1788 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1789 union acpi_object
*obj
;
1793 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1794 if (ACPI_FAILURE(status
))
1797 obj
= (union acpi_object
*) out
.pointer
;
1798 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1799 (obj
->buffer
.length
== sizeof(u32
) ||
1800 obj
->buffer
.length
== sizeof(u64
))) {
1801 devices
= *((u32
*) obj
->buffer
.pointer
);
1802 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1803 devices
= (u32
) obj
->integer
.value
;
1813 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1817 if (has_cap(ACER_CAP_MAILLED
)) {
1818 err
= acer_led_init(&device
->dev
);
1823 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1824 err
= acer_backlight_init(&device
->dev
);
1826 goto error_brightness
;
1829 err
= acer_rfkill_init(&device
->dev
);
1836 if (has_cap(ACER_CAP_BRIGHTNESS
))
1837 acer_backlight_exit();
1839 if (has_cap(ACER_CAP_MAILLED
))
1845 static int acer_platform_remove(struct platform_device
*device
)
1847 if (has_cap(ACER_CAP_MAILLED
))
1849 if (has_cap(ACER_CAP_BRIGHTNESS
))
1850 acer_backlight_exit();
1856 static int acer_platform_suspend(struct platform_device
*dev
,
1860 struct acer_data
*data
= &interface
->data
;
1865 if (has_cap(ACER_CAP_MAILLED
)) {
1866 get_u32(&value
, ACER_CAP_MAILLED
);
1867 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1868 data
->mailled
= value
;
1871 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1872 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1873 data
->brightness
= value
;
1879 static int acer_platform_resume(struct platform_device
*device
)
1881 struct acer_data
*data
= &interface
->data
;
1886 if (has_cap(ACER_CAP_MAILLED
))
1887 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
1889 if (has_cap(ACER_CAP_BRIGHTNESS
))
1890 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
1895 static void acer_platform_shutdown(struct platform_device
*device
)
1897 struct acer_data
*data
= &interface
->data
;
1902 if (has_cap(ACER_CAP_MAILLED
))
1903 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1906 static struct platform_driver acer_platform_driver
= {
1909 .owner
= THIS_MODULE
,
1911 .probe
= acer_platform_probe
,
1912 .remove
= acer_platform_remove
,
1913 .suspend
= acer_platform_suspend
,
1914 .resume
= acer_platform_resume
,
1915 .shutdown
= acer_platform_shutdown
,
1918 static struct platform_device
*acer_platform_device
;
1920 static int remove_sysfs(struct platform_device
*device
)
1922 if (has_cap(ACER_CAP_THREEG
))
1923 device_remove_file(&device
->dev
, &dev_attr_threeg
);
1925 device_remove_file(&device
->dev
, &dev_attr_interface
);
1930 static int create_sysfs(void)
1932 int retval
= -ENOMEM
;
1934 if (has_cap(ACER_CAP_THREEG
)) {
1935 retval
= device_create_file(&acer_platform_device
->dev
,
1941 retval
= device_create_file(&acer_platform_device
->dev
,
1942 &dev_attr_interface
);
1949 remove_sysfs(acer_platform_device
);
1953 static void remove_debugfs(void)
1955 debugfs_remove(interface
->debug
.devices
);
1956 debugfs_remove(interface
->debug
.root
);
1959 static int create_debugfs(void)
1961 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
1962 if (!interface
->debug
.root
) {
1963 pr_err("Failed to create debugfs directory");
1967 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
1968 interface
->debug
.root
,
1969 &interface
->debug
.wmid_devices
);
1970 if (!interface
->debug
.devices
)
1980 static int __init
acer_wmi_init(void)
1984 pr_info("Acer Laptop ACPI-WMI Extras\n");
1986 if (dmi_check_system(acer_blacklist
)) {
1987 pr_info("Blacklisted hardware detected - not loading\n");
1994 * Detect which ACPI-WMI interface we're using.
1996 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1997 interface
= &AMW0_V2_interface
;
1999 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2000 interface
= &wmid_interface
;
2002 if (wmi_has_guid(WMID_GUID3
))
2003 interface
= &wmid_v2_interface
;
2006 dmi_walk(type_aa_dmi_decode
, NULL
);
2008 if (wmi_has_guid(WMID_GUID2
) && interface
) {
2009 if (!has_type_aa
&& ACPI_FAILURE(WMID_set_capabilities())) {
2010 pr_err("Unable to detect available WMID devices\n");
2013 /* WMID always provides brightness methods */
2014 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
2015 } else if (!wmi_has_guid(WMID_GUID2
) && interface
&& !has_type_aa
) {
2016 pr_err("No WMID device detection method found\n");
2020 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
2021 interface
= &AMW0_interface
;
2023 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2024 pr_err("Unable to detect available AMW0 devices\n");
2029 if (wmi_has_guid(AMW0_GUID1
))
2030 AMW0_find_mailled();
2033 pr_err("No or unsupported WMI interface, unable to load\n");
2039 if (acpi_video_backlight_support()) {
2040 if (dmi_check_system(video_vendor_dmi_table
)) {
2041 acpi_video_unregister();
2043 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
2044 pr_info("Brightness must be controlled by "
2045 "acpi video driver\n");
2049 if (wmi_has_guid(WMID_GUID3
)) {
2051 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2052 pr_err("Cannot enable EC raw mode\n");
2055 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2056 pr_err("Cannot enable Launch Manager mode\n");
2059 } else if (ec_raw_mode
) {
2060 pr_info("No WMID EC raw mode enable method\n");
2063 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
2064 err
= acer_wmi_input_setup();
2069 err
= platform_driver_register(&acer_platform_driver
);
2071 pr_err("Unable to register platform driver\n");
2072 goto error_platform_register
;
2075 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
2076 if (!acer_platform_device
) {
2078 goto error_device_alloc
;
2081 err
= platform_device_add(acer_platform_device
);
2083 goto error_device_add
;
2085 err
= create_sysfs();
2087 goto error_create_sys
;
2089 if (wmi_has_guid(WMID_GUID2
)) {
2090 interface
->debug
.wmid_devices
= get_wmid_devices();
2091 err
= create_debugfs();
2093 goto error_create_debugfs
;
2096 /* Override any initial settings with values from the commandline */
2097 acer_commandline_init();
2101 error_create_debugfs
:
2102 remove_sysfs(acer_platform_device
);
2104 platform_device_del(acer_platform_device
);
2106 platform_device_put(acer_platform_device
);
2108 platform_driver_unregister(&acer_platform_driver
);
2109 error_platform_register
:
2110 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2111 acer_wmi_input_destroy();
2116 static void __exit
acer_wmi_exit(void)
2118 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2119 acer_wmi_input_destroy();
2121 remove_sysfs(acer_platform_device
);
2123 platform_device_unregister(acer_platform_device
);
2124 platform_driver_unregister(&acer_platform_driver
);
2126 pr_info("Acer Laptop WMI Extras unloaded\n");
2130 module_init(acer_wmi_init
);
2131 module_exit(acer_wmi_exit
);