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>
44 #include <acpi/video.h>
46 MODULE_AUTHOR("Carlos Corbacho");
47 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
48 MODULE_LICENSE("GPL");
52 * Meaning is unknown - this number is required for writing to ACPI for AMW0
53 * (it's also used in acerhk when directly accessing the BIOS)
55 #define ACER_AMW0_WRITE 0x9610
58 * Bit masks for the AMW0 interface
60 #define ACER_AMW0_WIRELESS_MASK 0x35
61 #define ACER_AMW0_BLUETOOTH_MASK 0x34
62 #define ACER_AMW0_MAILLED_MASK 0x31
65 * Method IDs for WMID interface
67 #define ACER_WMID_GET_WIRELESS_METHODID 1
68 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
69 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
70 #define ACER_WMID_SET_WIRELESS_METHODID 4
71 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
72 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
73 #define ACER_WMID_GET_THREEG_METHODID 10
74 #define ACER_WMID_SET_THREEG_METHODID 11
77 * Acer ACPI method GUIDs
79 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
80 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
81 #define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
82 #define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
83 #define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
86 * Acer ACPI event GUIDs
88 #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
90 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
91 MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
92 MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
94 enum acer_wmi_event_ids
{
95 WMID_HOTKEY_EVENT
= 0x1,
96 WMID_ACCEL_EVENT
= 0x5,
99 static const struct key_entry acer_wmi_keymap
[] __initconst
= {
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_KEY
, 0x29, {KEY_PROG3
} }, /* P_Key for TM8372 */
109 {KE_IGNORE
, 0x41, {KEY_MUTE
} },
110 {KE_IGNORE
, 0x42, {KEY_PREVIOUSSONG
} },
111 {KE_IGNORE
, 0x4d, {KEY_PREVIOUSSONG
} },
112 {KE_IGNORE
, 0x43, {KEY_NEXTSONG
} },
113 {KE_IGNORE
, 0x4e, {KEY_NEXTSONG
} },
114 {KE_IGNORE
, 0x44, {KEY_PLAYPAUSE
} },
115 {KE_IGNORE
, 0x4f, {KEY_PLAYPAUSE
} },
116 {KE_IGNORE
, 0x45, {KEY_STOP
} },
117 {KE_IGNORE
, 0x50, {KEY_STOP
} },
118 {KE_IGNORE
, 0x48, {KEY_VOLUMEUP
} },
119 {KE_IGNORE
, 0x49, {KEY_VOLUMEDOWN
} },
120 {KE_IGNORE
, 0x4a, {KEY_VOLUMEDOWN
} },
121 {KE_IGNORE
, 0x61, {KEY_SWITCHVIDEOMODE
} },
122 {KE_IGNORE
, 0x62, {KEY_BRIGHTNESSUP
} },
123 {KE_IGNORE
, 0x63, {KEY_BRIGHTNESSDOWN
} },
124 {KE_KEY
, 0x64, {KEY_SWITCHVIDEOMODE
} }, /* Display Switch */
125 {KE_IGNORE
, 0x81, {KEY_SLEEP
} },
126 {KE_KEY
, 0x82, {KEY_TOUCHPAD_TOGGLE
} }, /* Touch Pad Toggle */
127 {KE_KEY
, KEY_TOUCHPAD_ON
, {KEY_TOUCHPAD_ON
} },
128 {KE_KEY
, KEY_TOUCHPAD_OFF
, {KEY_TOUCHPAD_OFF
} },
129 {KE_IGNORE
, 0x83, {KEY_TOUCHPAD_TOGGLE
} },
130 {KE_KEY
, 0x85, {KEY_TOUCHPAD_TOGGLE
} },
134 static struct input_dev
*acer_wmi_input_dev
;
135 static struct input_dev
*acer_wmi_accel_dev
;
137 struct event_return_value
{
142 } __attribute__((packed
));
145 * GUID3 Get Device Status device flags
147 #define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
148 #define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
149 #define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
150 #define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
151 #define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
153 struct lm_input_params
{
154 u8 function_num
; /* Function Number */
155 u16 commun_devices
; /* Communication type devices default status */
156 u16 devices
; /* Other type devices default status */
157 u8 lm_status
; /* Launch Manager Status */
159 } __attribute__((packed
));
161 struct lm_return_value
{
162 u8 error_code
; /* Error Code */
163 u8 ec_return_value
; /* EC Return Value */
165 } __attribute__((packed
));
167 struct wmid3_gds_set_input_param
{ /* Set Device Status input parameter */
168 u8 function_num
; /* Function Number */
169 u8 hotkey_number
; /* Hotkey Number */
170 u16 devices
; /* Set Device */
171 u8 volume_value
; /* Volume Value */
172 } __attribute__((packed
));
174 struct wmid3_gds_get_input_param
{ /* Get Device Status input parameter */
175 u8 function_num
; /* Function Number */
176 u8 hotkey_number
; /* Hotkey Number */
177 u16 devices
; /* Get Device */
178 } __attribute__((packed
));
180 struct wmid3_gds_return_value
{ /* Get Device Status return value*/
181 u8 error_code
; /* Error Code */
182 u8 ec_return_value
; /* EC Return Value */
183 u16 devices
; /* Current Device Status */
185 } __attribute__((packed
));
187 struct hotkey_function_type_aa
{
191 u16 commun_func_bitmap
;
192 u16 application_func_bitmap
;
193 u16 media_func_bitmap
;
194 u16 display_func_bitmap
;
195 u16 others_func_bitmap
;
196 u8 commun_fn_key_number
;
197 } __attribute__((packed
));
200 * Interface capability flags
202 #define ACER_CAP_MAILLED (1<<0)
203 #define ACER_CAP_WIRELESS (1<<1)
204 #define ACER_CAP_BLUETOOTH (1<<2)
205 #define ACER_CAP_BRIGHTNESS (1<<3)
206 #define ACER_CAP_THREEG (1<<4)
207 #define ACER_CAP_ACCEL (1<<5)
208 #define ACER_CAP_ANY (0xFFFFFFFF)
211 * Interface type flags
213 enum interface_flags
{
220 #define ACER_DEFAULT_WIRELESS 0
221 #define ACER_DEFAULT_BLUETOOTH 0
222 #define ACER_DEFAULT_MAILLED 0
223 #define ACER_DEFAULT_THREEG 0
225 static int max_brightness
= 0xF;
227 static int mailled
= -1;
228 static int brightness
= -1;
229 static int threeg
= -1;
230 static int force_series
;
231 static bool ec_raw_mode
;
232 static bool has_type_aa
;
233 static u16 commun_func_bitmap
;
234 static u8 commun_fn_key_number
;
236 module_param(mailled
, int, 0444);
237 module_param(brightness
, int, 0444);
238 module_param(threeg
, int, 0444);
239 module_param(force_series
, int, 0444);
240 module_param(ec_raw_mode
, bool, 0444);
241 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
242 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
243 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
244 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
245 MODULE_PARM_DESC(ec_raw_mode
, "Enable EC raw mode");
255 struct dentry
*devices
;
259 static struct rfkill
*wireless_rfkill
;
260 static struct rfkill
*bluetooth_rfkill
;
261 static struct rfkill
*threeg_rfkill
;
262 static bool rfkill_inited
;
264 /* Each low-level interface must define at least some of the following */
265 struct wmi_interface
{
266 /* The WMI device type */
269 /* The capabilities this interface provides */
272 /* Private data for the current interface */
273 struct acer_data data
;
275 /* debugfs entries associated with this interface */
276 struct acer_debug debug
;
279 /* The static interface pointer, points to the currently detected interface */
280 static struct wmi_interface
*interface
;
283 * Embedded Controller quirks
284 * Some laptops require us to directly access the EC to either enable or query
285 * features that are not available through WMI.
295 static struct quirk_entry
*quirks
;
297 static void __init
set_quirks(void)
303 interface
->capability
|= ACER_CAP_MAILLED
;
305 if (quirks
->brightness
)
306 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
309 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
311 quirks
= dmi
->driver_data
;
315 static struct quirk_entry quirk_unknown
= {
318 static struct quirk_entry quirk_acer_aspire_1520
= {
322 static struct quirk_entry quirk_acer_travelmate_2490
= {
326 /* This AMW0 laptop has no bluetooth */
327 static struct quirk_entry quirk_medion_md_98300
= {
331 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
335 static struct quirk_entry quirk_lenovo_ideapad_s205
= {
339 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
340 static const struct dmi_system_id acer_blacklist
[] __initconst
= {
342 .ident
= "Acer Aspire One (SSD)",
344 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
345 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
349 .ident
= "Acer Aspire One (HDD)",
351 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
352 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
358 static const struct dmi_system_id acer_quirks
[] __initconst
= {
360 .callback
= dmi_matched
,
361 .ident
= "Acer Aspire 1360",
363 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
364 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
366 .driver_data
= &quirk_acer_aspire_1520
,
369 .callback
= dmi_matched
,
370 .ident
= "Acer Aspire 1520",
372 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
373 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
375 .driver_data
= &quirk_acer_aspire_1520
,
378 .callback
= dmi_matched
,
379 .ident
= "Acer Aspire 3100",
381 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
382 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
384 .driver_data
= &quirk_acer_travelmate_2490
,
387 .callback
= dmi_matched
,
388 .ident
= "Acer Aspire 3610",
390 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
391 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
393 .driver_data
= &quirk_acer_travelmate_2490
,
396 .callback
= dmi_matched
,
397 .ident
= "Acer Aspire 5100",
399 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
400 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
402 .driver_data
= &quirk_acer_travelmate_2490
,
405 .callback
= dmi_matched
,
406 .ident
= "Acer Aspire 5610",
408 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
409 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
411 .driver_data
= &quirk_acer_travelmate_2490
,
414 .callback
= dmi_matched
,
415 .ident
= "Acer Aspire 5630",
417 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
418 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
420 .driver_data
= &quirk_acer_travelmate_2490
,
423 .callback
= dmi_matched
,
424 .ident
= "Acer Aspire 5650",
426 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
427 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
429 .driver_data
= &quirk_acer_travelmate_2490
,
432 .callback
= dmi_matched
,
433 .ident
= "Acer Aspire 5680",
435 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
436 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
438 .driver_data
= &quirk_acer_travelmate_2490
,
441 .callback
= dmi_matched
,
442 .ident
= "Acer Aspire 9110",
444 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
445 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
447 .driver_data
= &quirk_acer_travelmate_2490
,
450 .callback
= dmi_matched
,
451 .ident
= "Acer TravelMate 2490",
453 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
454 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
456 .driver_data
= &quirk_acer_travelmate_2490
,
459 .callback
= dmi_matched
,
460 .ident
= "Acer TravelMate 4200",
462 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
463 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
465 .driver_data
= &quirk_acer_travelmate_2490
,
468 .callback
= dmi_matched
,
469 .ident
= "Fujitsu Siemens Amilo Li 1718",
471 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
472 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
474 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
477 .callback
= dmi_matched
,
478 .ident
= "Medion MD 98300",
480 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
481 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
483 .driver_data
= &quirk_medion_md_98300
,
486 .callback
= dmi_matched
,
487 .ident
= "Lenovo Ideapad S205",
489 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
490 DMI_MATCH(DMI_PRODUCT_NAME
, "10382LG"),
492 .driver_data
= &quirk_lenovo_ideapad_s205
,
495 .callback
= dmi_matched
,
496 .ident
= "Lenovo Ideapad S205 (Brazos)",
498 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
499 DMI_MATCH(DMI_PRODUCT_NAME
, "Brazos"),
501 .driver_data
= &quirk_lenovo_ideapad_s205
,
504 .callback
= dmi_matched
,
505 .ident
= "Lenovo 3000 N200",
507 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
508 DMI_MATCH(DMI_PRODUCT_NAME
, "0687A31"),
510 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
513 .callback
= dmi_matched
,
514 .ident
= "Lenovo Ideapad S205-10382JG",
516 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
517 DMI_MATCH(DMI_PRODUCT_NAME
, "10382JG"),
519 .driver_data
= &quirk_lenovo_ideapad_s205
,
522 .callback
= dmi_matched
,
523 .ident
= "Lenovo Ideapad S205-1038DPG",
525 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
526 DMI_MATCH(DMI_PRODUCT_NAME
, "1038DPG"),
528 .driver_data
= &quirk_lenovo_ideapad_s205
,
534 video_set_backlight_video_vendor(const struct dmi_system_id
*d
)
536 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
537 pr_info("Brightness must be controlled by generic video driver\n");
541 static const struct dmi_system_id video_vendor_dmi_table
[] __initconst
= {
543 .callback
= video_set_backlight_video_vendor
,
544 .ident
= "Acer TravelMate 4750",
546 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
547 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4750"),
551 .callback
= video_set_backlight_video_vendor
,
552 .ident
= "Acer Extensa 5235",
554 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
555 DMI_MATCH(DMI_PRODUCT_NAME
, "Extensa 5235"),
559 .callback
= video_set_backlight_video_vendor
,
560 .ident
= "Acer TravelMate 5760",
562 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
563 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5760"),
567 .callback
= video_set_backlight_video_vendor
,
568 .ident
= "Acer Aspire 5750",
570 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
571 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5750"),
575 .callback
= video_set_backlight_video_vendor
,
576 .ident
= "Acer Aspire 5741",
578 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
579 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5741"),
584 * Note no video_set_backlight_video_vendor, we must use the
585 * acer interface, as there is no native backlight interface.
587 .ident
= "Acer KAV80",
589 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
590 DMI_MATCH(DMI_PRODUCT_NAME
, "KAV80"),
596 /* Find which quirks are needed for a particular vendor/ model pair */
597 static void __init
find_quirks(void)
600 dmi_check_system(acer_quirks
);
601 } else if (force_series
== 2490) {
602 quirks
= &quirk_acer_travelmate_2490
;
606 quirks
= &quirk_unknown
;
612 * General interface convenience methods
615 static bool has_cap(u32 cap
)
617 if ((interface
->capability
& cap
) != 0)
624 * AMW0 (V1) interface
641 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
642 struct acpi_buffer
*result
)
644 struct acpi_buffer input
;
646 input
.length
= sizeof(struct wmab_args
);
647 input
.pointer
= (u8
*)regbuf
;
649 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
654 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
)
660 case ACER_CAP_MAILLED
:
661 switch (quirks
->mailled
) {
663 err
= ec_read(0xA, &result
);
666 *value
= (result
>> 7) & 0x1;
670 case ACER_CAP_WIRELESS
:
671 switch (quirks
->wireless
) {
673 err
= ec_read(0x7B, &result
);
676 *value
= result
& 0x1;
679 err
= ec_read(0x71, &result
);
682 *value
= result
& 0x1;
685 err
= ec_read(0x78, &result
);
688 *value
= result
& 0x1;
691 err
= ec_read(0xA, &result
);
694 *value
= (result
>> 2) & 0x1;
698 case ACER_CAP_BLUETOOTH
:
699 switch (quirks
->bluetooth
) {
701 err
= ec_read(0xA, &result
);
704 *value
= (result
>> 4) & 0x1;
708 case ACER_CAP_BRIGHTNESS
:
709 switch (quirks
->brightness
) {
711 err
= ec_read(0x83, &result
);
724 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
)
726 struct wmab_args args
;
728 args
.eax
= ACER_AMW0_WRITE
;
729 args
.ebx
= value
? (1<<8) : 0;
730 args
.ecx
= args
.edx
= 0;
733 case ACER_CAP_MAILLED
:
735 return AE_BAD_PARAMETER
;
736 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
738 case ACER_CAP_WIRELESS
:
740 return AE_BAD_PARAMETER
;
741 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
743 case ACER_CAP_BLUETOOTH
:
745 return AE_BAD_PARAMETER
;
746 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
748 case ACER_CAP_BRIGHTNESS
:
749 if (value
> max_brightness
)
750 return AE_BAD_PARAMETER
;
751 switch (quirks
->brightness
) {
753 return ec_write(0x83, value
);
760 /* Actually do the set */
761 return wmab_execute(&args
, NULL
);
764 static acpi_status __init
AMW0_find_mailled(void)
766 struct wmab_args args
;
768 acpi_status status
= AE_OK
;
769 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
770 union acpi_object
*obj
;
773 args
.ebx
= args
.ecx
= args
.edx
= 0;
775 status
= wmab_execute(&args
, &out
);
776 if (ACPI_FAILURE(status
))
779 obj
= (union acpi_object
*) out
.pointer
;
780 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
781 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
782 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
789 interface
->capability
|= ACER_CAP_MAILLED
;
796 static const struct acpi_device_id norfkill_ids
[] __initconst
= {
800 { "SNY5001", 0}, /* sony-laptop in charge */
805 static int __init
AMW0_set_cap_acpi_check_device(void)
807 const struct acpi_device_id
*id
;
809 for (id
= norfkill_ids
; id
->id
[0]; id
++)
810 if (acpi_dev_found(id
->id
))
816 static acpi_status __init
AMW0_set_capabilities(void)
818 struct wmab_args args
;
821 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
822 union acpi_object
*obj
;
825 * On laptops with this strange GUID (non Acer), normal probing doesn't
828 if (wmi_has_guid(AMW0_GUID2
)) {
829 if ((quirks
!= &quirk_unknown
) ||
830 !AMW0_set_cap_acpi_check_device())
831 interface
->capability
|= ACER_CAP_WIRELESS
;
835 args
.eax
= ACER_AMW0_WRITE
;
836 args
.ecx
= args
.edx
= 0;
838 args
.ebx
= 0xa2 << 8;
839 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
841 status
= wmab_execute(&args
, &out
);
842 if (ACPI_FAILURE(status
))
846 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
847 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
848 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
855 interface
->capability
|= ACER_CAP_WIRELESS
;
858 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
861 * It's ok to use existing buffer for next wmab_execute call.
862 * But we need to kfree(out.pointer) if next wmab_execute fail.
864 status
= wmab_execute(&args
, &out
);
865 if (ACPI_FAILURE(status
))
868 obj
= (union acpi_object
*) out
.pointer
;
869 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
870 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
871 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
878 interface
->capability
|= ACER_CAP_BLUETOOTH
;
881 * This appears to be safe to enable, since all Wistron based laptops
882 * appear to use the same EC register for brightness, even if they
883 * differ for wireless, etc
885 if (quirks
->brightness
>= 0)
886 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
894 static struct wmi_interface AMW0_interface
= {
898 static struct wmi_interface AMW0_V2_interface
= {
899 .type
= ACER_AMW0_V2
,
903 * New interface (The WMID interface)
906 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
908 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
909 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
910 union acpi_object
*obj
;
914 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
916 if (ACPI_FAILURE(status
))
919 obj
= (union acpi_object
*) result
.pointer
;
921 if (obj
->type
== ACPI_TYPE_BUFFER
&&
922 (obj
->buffer
.length
== sizeof(u32
) ||
923 obj
->buffer
.length
== sizeof(u64
))) {
924 tmp
= *((u32
*) obj
->buffer
.pointer
);
925 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
926 tmp
= (u32
) obj
->integer
.value
;
933 kfree(result
.pointer
);
938 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
)
942 u32 result
, method_id
= 0;
945 case ACER_CAP_WIRELESS
:
946 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
948 case ACER_CAP_BLUETOOTH
:
949 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
951 case ACER_CAP_BRIGHTNESS
:
952 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
954 case ACER_CAP_THREEG
:
955 method_id
= ACER_WMID_GET_THREEG_METHODID
;
957 case ACER_CAP_MAILLED
:
958 if (quirks
->mailled
== 1) {
966 status
= WMI_execute_u32(method_id
, 0, &result
);
968 if (ACPI_SUCCESS(status
))
974 static acpi_status
WMID_set_u32(u32 value
, u32 cap
)
980 case ACER_CAP_BRIGHTNESS
:
981 if (value
> max_brightness
)
982 return AE_BAD_PARAMETER
;
983 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
985 case ACER_CAP_WIRELESS
:
987 return AE_BAD_PARAMETER
;
988 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
990 case ACER_CAP_BLUETOOTH
:
992 return AE_BAD_PARAMETER
;
993 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
995 case ACER_CAP_THREEG
:
997 return AE_BAD_PARAMETER
;
998 method_id
= ACER_WMID_SET_THREEG_METHODID
;
1000 case ACER_CAP_MAILLED
:
1002 return AE_BAD_PARAMETER
;
1003 if (quirks
->mailled
== 1) {
1004 param
= value
? 0x92 : 0x93;
1006 i8042_command(¶m
, 0x1059);
1007 i8042_unlock_chip();
1014 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
1017 static acpi_status
wmid3_get_device_status(u32
*value
, u16 device
)
1019 struct wmid3_gds_return_value return_value
;
1021 union acpi_object
*obj
;
1022 struct wmid3_gds_get_input_param params
= {
1023 .function_num
= 0x1,
1024 .hotkey_number
= commun_fn_key_number
,
1027 struct acpi_buffer input
= {
1028 sizeof(struct wmid3_gds_get_input_param
),
1031 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1033 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &input
, &output
);
1034 if (ACPI_FAILURE(status
))
1037 obj
= output
.pointer
;
1041 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1045 if (obj
->buffer
.length
!= 8) {
1046 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1051 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1054 if (return_value
.error_code
|| return_value
.ec_return_value
)
1055 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1057 return_value
.error_code
,
1058 return_value
.ec_return_value
);
1060 *value
= !!(return_value
.devices
& device
);
1065 static acpi_status
wmid_v2_get_u32(u32
*value
, u32 cap
)
1070 case ACER_CAP_WIRELESS
:
1071 device
= ACER_WMID3_GDS_WIRELESS
;
1073 case ACER_CAP_BLUETOOTH
:
1074 device
= ACER_WMID3_GDS_BLUETOOTH
;
1076 case ACER_CAP_THREEG
:
1077 device
= ACER_WMID3_GDS_THREEG
;
1082 return wmid3_get_device_status(value
, device
);
1085 static acpi_status
wmid3_set_device_status(u32 value
, u16 device
)
1087 struct wmid3_gds_return_value return_value
;
1089 union acpi_object
*obj
;
1091 struct wmid3_gds_get_input_param get_params
= {
1092 .function_num
= 0x1,
1093 .hotkey_number
= commun_fn_key_number
,
1094 .devices
= commun_func_bitmap
,
1096 struct acpi_buffer get_input
= {
1097 sizeof(struct wmid3_gds_get_input_param
),
1100 struct wmid3_gds_set_input_param set_params
= {
1101 .function_num
= 0x2,
1102 .hotkey_number
= commun_fn_key_number
,
1103 .devices
= commun_func_bitmap
,
1105 struct acpi_buffer set_input
= {
1106 sizeof(struct wmid3_gds_set_input_param
),
1109 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1110 struct acpi_buffer output2
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1112 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x2, &get_input
, &output
);
1113 if (ACPI_FAILURE(status
))
1116 obj
= output
.pointer
;
1120 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1124 if (obj
->buffer
.length
!= 8) {
1125 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1130 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1133 if (return_value
.error_code
|| return_value
.ec_return_value
) {
1134 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1135 return_value
.error_code
,
1136 return_value
.ec_return_value
);
1140 devices
= return_value
.devices
;
1141 set_params
.devices
= (value
) ? (devices
| device
) : (devices
& ~device
);
1143 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &set_input
, &output2
);
1144 if (ACPI_FAILURE(status
))
1147 obj
= output2
.pointer
;
1151 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1155 if (obj
->buffer
.length
!= 4) {
1156 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1161 return_value
= *((struct wmid3_gds_return_value
*)obj
->buffer
.pointer
);
1164 if (return_value
.error_code
|| return_value
.ec_return_value
)
1165 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1166 return_value
.error_code
,
1167 return_value
.ec_return_value
);
1172 static acpi_status
wmid_v2_set_u32(u32 value
, u32 cap
)
1177 case ACER_CAP_WIRELESS
:
1178 device
= ACER_WMID3_GDS_WIRELESS
;
1180 case ACER_CAP_BLUETOOTH
:
1181 device
= ACER_WMID3_GDS_BLUETOOTH
;
1183 case ACER_CAP_THREEG
:
1184 device
= ACER_WMID3_GDS_THREEG
;
1189 return wmid3_set_device_status(value
, device
);
1192 static void __init
type_aa_dmi_decode(const struct dmi_header
*header
, void *d
)
1194 struct hotkey_function_type_aa
*type_aa
;
1196 /* We are looking for OEM-specific Type AAh */
1197 if (header
->type
!= 0xAA)
1201 type_aa
= (struct hotkey_function_type_aa
*) header
;
1203 pr_info("Function bitmap for Communication Button: 0x%x\n",
1204 type_aa
->commun_func_bitmap
);
1205 commun_func_bitmap
= type_aa
->commun_func_bitmap
;
1207 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_WIRELESS
)
1208 interface
->capability
|= ACER_CAP_WIRELESS
;
1209 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_THREEG
)
1210 interface
->capability
|= ACER_CAP_THREEG
;
1211 if (type_aa
->commun_func_bitmap
& ACER_WMID3_GDS_BLUETOOTH
)
1212 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1214 commun_fn_key_number
= type_aa
->commun_fn_key_number
;
1217 static acpi_status __init
WMID_set_capabilities(void)
1219 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1220 union acpi_object
*obj
;
1224 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1225 if (ACPI_FAILURE(status
))
1228 obj
= (union acpi_object
*) out
.pointer
;
1230 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1231 (obj
->buffer
.length
== sizeof(u32
) ||
1232 obj
->buffer
.length
== sizeof(u64
))) {
1233 devices
= *((u32
*) obj
->buffer
.pointer
);
1234 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1235 devices
= (u32
) obj
->integer
.value
;
1245 pr_info("Function bitmap for Communication Device: 0x%x\n", devices
);
1247 interface
->capability
|= ACER_CAP_WIRELESS
;
1249 interface
->capability
|= ACER_CAP_THREEG
;
1251 interface
->capability
|= ACER_CAP_BLUETOOTH
;
1253 if (!(devices
& 0x20))
1254 max_brightness
= 0x9;
1260 static struct wmi_interface wmid_interface
= {
1264 static struct wmi_interface wmid_v2_interface
= {
1265 .type
= ACER_WMID_v2
,
1269 * Generic Device (interface-independent)
1272 static acpi_status
get_u32(u32
*value
, u32 cap
)
1274 acpi_status status
= AE_ERROR
;
1276 switch (interface
->type
) {
1278 status
= AMW0_get_u32(value
, cap
);
1281 if (cap
== ACER_CAP_MAILLED
) {
1282 status
= AMW0_get_u32(value
, cap
);
1286 status
= WMID_get_u32(value
, cap
);
1289 if (cap
& (ACER_CAP_WIRELESS
|
1290 ACER_CAP_BLUETOOTH
|
1292 status
= wmid_v2_get_u32(value
, cap
);
1293 else if (wmi_has_guid(WMID_GUID2
))
1294 status
= WMID_get_u32(value
, cap
);
1301 static acpi_status
set_u32(u32 value
, u32 cap
)
1305 if (interface
->capability
& cap
) {
1306 switch (interface
->type
) {
1308 return AMW0_set_u32(value
, cap
);
1310 if (cap
== ACER_CAP_MAILLED
)
1311 return AMW0_set_u32(value
, cap
);
1314 * On some models, some WMID methods don't toggle
1315 * properly. For those cases, we want to run the AMW0
1316 * method afterwards to be certain we've really toggled
1319 if (cap
== ACER_CAP_WIRELESS
||
1320 cap
== ACER_CAP_BLUETOOTH
) {
1321 status
= WMID_set_u32(value
, cap
);
1322 if (ACPI_FAILURE(status
))
1325 return AMW0_set_u32(value
, cap
);
1328 return WMID_set_u32(value
, cap
);
1330 if (cap
& (ACER_CAP_WIRELESS
|
1331 ACER_CAP_BLUETOOTH
|
1333 return wmid_v2_set_u32(value
, cap
);
1334 else if (wmi_has_guid(WMID_GUID2
))
1335 return WMID_set_u32(value
, cap
);
1337 return AE_BAD_PARAMETER
;
1340 return AE_BAD_PARAMETER
;
1343 static void __init
acer_commandline_init(void)
1346 * These will all fail silently if the value given is invalid, or the
1347 * capability isn't available on the given interface
1350 set_u32(mailled
, ACER_CAP_MAILLED
);
1351 if (!has_type_aa
&& threeg
>= 0)
1352 set_u32(threeg
, ACER_CAP_THREEG
);
1353 if (brightness
>= 0)
1354 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
1358 * LED device (Mail LED only, no other LEDs known yet)
1360 static void mail_led_set(struct led_classdev
*led_cdev
,
1361 enum led_brightness value
)
1363 set_u32(value
, ACER_CAP_MAILLED
);
1366 static struct led_classdev mail_led
= {
1367 .name
= "acer-wmi::mail",
1368 .brightness_set
= mail_led_set
,
1371 static int acer_led_init(struct device
*dev
)
1373 return led_classdev_register(dev
, &mail_led
);
1376 static void acer_led_exit(void)
1378 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
1379 led_classdev_unregister(&mail_led
);
1385 static struct backlight_device
*acer_backlight_device
;
1387 static int read_brightness(struct backlight_device
*bd
)
1390 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1394 static int update_bl_status(struct backlight_device
*bd
)
1396 int intensity
= bd
->props
.brightness
;
1398 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
1400 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
1403 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
1408 static const struct backlight_ops acer_bl_ops
= {
1409 .get_brightness
= read_brightness
,
1410 .update_status
= update_bl_status
,
1413 static int acer_backlight_init(struct device
*dev
)
1415 struct backlight_properties props
;
1416 struct backlight_device
*bd
;
1418 memset(&props
, 0, sizeof(struct backlight_properties
));
1419 props
.type
= BACKLIGHT_PLATFORM
;
1420 props
.max_brightness
= max_brightness
;
1421 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
,
1424 pr_err("Could not register Acer backlight device\n");
1425 acer_backlight_device
= NULL
;
1429 acer_backlight_device
= bd
;
1431 bd
->props
.power
= FB_BLANK_UNBLANK
;
1432 bd
->props
.brightness
= read_brightness(bd
);
1433 backlight_update_status(bd
);
1437 static void acer_backlight_exit(void)
1439 backlight_device_unregister(acer_backlight_device
);
1443 * Accelerometer device
1445 static acpi_handle gsensor_handle
;
1447 static int acer_gsensor_init(void)
1450 struct acpi_buffer output
;
1451 union acpi_object out_obj
;
1453 output
.length
= sizeof(out_obj
);
1454 output
.pointer
= &out_obj
;
1455 status
= acpi_evaluate_object(gsensor_handle
, "_INI", NULL
, &output
);
1456 if (ACPI_FAILURE(status
))
1462 static int acer_gsensor_open(struct input_dev
*input
)
1464 return acer_gsensor_init();
1467 static int acer_gsensor_event(void)
1470 struct acpi_buffer output
;
1471 union acpi_object out_obj
[5];
1473 if (!has_cap(ACER_CAP_ACCEL
))
1476 output
.length
= sizeof(out_obj
);
1477 output
.pointer
= out_obj
;
1479 status
= acpi_evaluate_object(gsensor_handle
, "RDVL", NULL
, &output
);
1480 if (ACPI_FAILURE(status
))
1483 if (out_obj
->package
.count
!= 4)
1486 input_report_abs(acer_wmi_accel_dev
, ABS_X
,
1487 (s16
)out_obj
->package
.elements
[0].integer
.value
);
1488 input_report_abs(acer_wmi_accel_dev
, ABS_Y
,
1489 (s16
)out_obj
->package
.elements
[1].integer
.value
);
1490 input_report_abs(acer_wmi_accel_dev
, ABS_Z
,
1491 (s16
)out_obj
->package
.elements
[2].integer
.value
);
1492 input_sync(acer_wmi_accel_dev
);
1499 static void acer_rfkill_update(struct work_struct
*ignored
);
1500 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
1501 static void acer_rfkill_update(struct work_struct
*ignored
)
1506 if (has_cap(ACER_CAP_WIRELESS
)) {
1507 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
1508 if (ACPI_SUCCESS(status
)) {
1509 if (quirks
->wireless
== 3)
1510 rfkill_set_hw_state(wireless_rfkill
, !state
);
1512 rfkill_set_sw_state(wireless_rfkill
, !state
);
1516 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1517 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
1518 if (ACPI_SUCCESS(status
))
1519 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
1522 if (has_cap(ACER_CAP_THREEG
) && wmi_has_guid(WMID_GUID3
)) {
1523 status
= get_u32(&state
, ACER_WMID3_GDS_THREEG
);
1524 if (ACPI_SUCCESS(status
))
1525 rfkill_set_sw_state(threeg_rfkill
, !state
);
1528 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1531 static int acer_rfkill_set(void *data
, bool blocked
)
1534 u32 cap
= (unsigned long)data
;
1536 if (rfkill_inited
) {
1537 status
= set_u32(!blocked
, cap
);
1538 if (ACPI_FAILURE(status
))
1545 static const struct rfkill_ops acer_rfkill_ops
= {
1546 .set_block
= acer_rfkill_set
,
1549 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
1550 enum rfkill_type type
,
1551 char *name
, u32 cap
)
1554 struct rfkill
*rfkill_dev
;
1558 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
1560 (void *)(unsigned long)cap
);
1562 return ERR_PTR(-ENOMEM
);
1564 status
= get_u32(&state
, cap
);
1566 err
= rfkill_register(rfkill_dev
);
1568 rfkill_destroy(rfkill_dev
);
1569 return ERR_PTR(err
);
1572 if (ACPI_SUCCESS(status
))
1573 rfkill_set_sw_state(rfkill_dev
, !state
);
1578 static int acer_rfkill_init(struct device
*dev
)
1582 if (has_cap(ACER_CAP_WIRELESS
)) {
1583 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1584 "acer-wireless", ACER_CAP_WIRELESS
);
1585 if (IS_ERR(wireless_rfkill
)) {
1586 err
= PTR_ERR(wireless_rfkill
);
1587 goto error_wireless
;
1591 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1592 bluetooth_rfkill
= acer_rfkill_register(dev
,
1593 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1594 ACER_CAP_BLUETOOTH
);
1595 if (IS_ERR(bluetooth_rfkill
)) {
1596 err
= PTR_ERR(bluetooth_rfkill
);
1597 goto error_bluetooth
;
1601 if (has_cap(ACER_CAP_THREEG
)) {
1602 threeg_rfkill
= acer_rfkill_register(dev
,
1603 RFKILL_TYPE_WWAN
, "acer-threeg",
1605 if (IS_ERR(threeg_rfkill
)) {
1606 err
= PTR_ERR(threeg_rfkill
);
1611 rfkill_inited
= true;
1613 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1614 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1615 schedule_delayed_work(&acer_rfkill_work
,
1616 round_jiffies_relative(HZ
));
1621 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1622 rfkill_unregister(bluetooth_rfkill
);
1623 rfkill_destroy(bluetooth_rfkill
);
1626 if (has_cap(ACER_CAP_WIRELESS
)) {
1627 rfkill_unregister(wireless_rfkill
);
1628 rfkill_destroy(wireless_rfkill
);
1634 static void acer_rfkill_exit(void)
1636 if ((ec_raw_mode
|| !wmi_has_guid(ACERWMID_EVENT_GUID
)) &&
1637 has_cap(ACER_CAP_WIRELESS
| ACER_CAP_BLUETOOTH
| ACER_CAP_THREEG
))
1638 cancel_delayed_work_sync(&acer_rfkill_work
);
1640 if (has_cap(ACER_CAP_WIRELESS
)) {
1641 rfkill_unregister(wireless_rfkill
);
1642 rfkill_destroy(wireless_rfkill
);
1645 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1646 rfkill_unregister(bluetooth_rfkill
);
1647 rfkill_destroy(bluetooth_rfkill
);
1650 if (has_cap(ACER_CAP_THREEG
)) {
1651 rfkill_unregister(threeg_rfkill
);
1652 rfkill_destroy(threeg_rfkill
);
1657 static void acer_wmi_notify(u32 value
, void *context
)
1659 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1660 union acpi_object
*obj
;
1661 struct event_return_value return_value
;
1664 const struct key_entry
*key
;
1667 status
= wmi_get_event_data(value
, &response
);
1668 if (status
!= AE_OK
) {
1669 pr_warn("bad event status 0x%x\n", status
);
1673 obj
= (union acpi_object
*)response
.pointer
;
1677 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1678 pr_warn("Unknown response received %d\n", obj
->type
);
1682 if (obj
->buffer
.length
!= 8) {
1683 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1688 return_value
= *((struct event_return_value
*)obj
->buffer
.pointer
);
1691 switch (return_value
.function
) {
1692 case WMID_HOTKEY_EVENT
:
1693 device_state
= return_value
.device_state
;
1694 pr_debug("device state: 0x%x\n", device_state
);
1696 key
= sparse_keymap_entry_from_scancode(acer_wmi_input_dev
,
1697 return_value
.key_num
);
1699 pr_warn("Unknown key number - 0x%x\n",
1700 return_value
.key_num
);
1702 scancode
= return_value
.key_num
;
1703 switch (key
->keycode
) {
1706 if (has_cap(ACER_CAP_WIRELESS
))
1707 rfkill_set_sw_state(wireless_rfkill
,
1708 !(device_state
& ACER_WMID3_GDS_WIRELESS
));
1709 if (has_cap(ACER_CAP_THREEG
))
1710 rfkill_set_sw_state(threeg_rfkill
,
1711 !(device_state
& ACER_WMID3_GDS_THREEG
));
1712 if (has_cap(ACER_CAP_BLUETOOTH
))
1713 rfkill_set_sw_state(bluetooth_rfkill
,
1714 !(device_state
& ACER_WMID3_GDS_BLUETOOTH
));
1716 case KEY_TOUCHPAD_TOGGLE
:
1717 scancode
= (device_state
& ACER_WMID3_GDS_TOUCHPAD
) ?
1718 KEY_TOUCHPAD_ON
: KEY_TOUCHPAD_OFF
;
1720 sparse_keymap_report_event(acer_wmi_input_dev
, scancode
, 1, true);
1723 case WMID_ACCEL_EVENT
:
1724 acer_gsensor_event();
1727 pr_warn("Unknown function number - %d - %d\n",
1728 return_value
.function
, return_value
.key_num
);
1733 static acpi_status __init
1734 wmid3_set_lm_mode(struct lm_input_params
*params
,
1735 struct lm_return_value
*return_value
)
1738 union acpi_object
*obj
;
1740 struct acpi_buffer input
= { sizeof(struct lm_input_params
), params
};
1741 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1743 status
= wmi_evaluate_method(WMID_GUID3
, 0, 0x1, &input
, &output
);
1744 if (ACPI_FAILURE(status
))
1747 obj
= output
.pointer
;
1751 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
1755 if (obj
->buffer
.length
!= 4) {
1756 pr_warn("Unknown buffer length %d\n", obj
->buffer
.length
);
1761 *return_value
= *((struct lm_return_value
*)obj
->buffer
.pointer
);
1767 static int __init
acer_wmi_enable_ec_raw(void)
1769 struct lm_return_value return_value
;
1771 struct lm_input_params params
= {
1772 .function_num
= 0x1,
1773 .commun_devices
= 0xFFFF,
1775 .lm_status
= 0x00, /* Launch Manager Deactive */
1778 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1780 if (return_value
.error_code
|| return_value
.ec_return_value
)
1781 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1782 return_value
.error_code
,
1783 return_value
.ec_return_value
);
1785 pr_info("Enabled EC raw mode\n");
1790 static int __init
acer_wmi_enable_lm(void)
1792 struct lm_return_value return_value
;
1794 struct lm_input_params params
= {
1795 .function_num
= 0x1,
1796 .commun_devices
= 0xFFFF,
1798 .lm_status
= 0x01, /* Launch Manager Active */
1801 status
= wmid3_set_lm_mode(¶ms
, &return_value
);
1803 if (return_value
.error_code
|| return_value
.ec_return_value
)
1804 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1805 return_value
.error_code
,
1806 return_value
.ec_return_value
);
1811 static acpi_status __init
acer_wmi_get_handle_cb(acpi_handle ah
, u32 level
,
1812 void *ctx
, void **retval
)
1814 *(acpi_handle
*)retval
= ah
;
1818 static int __init
acer_wmi_get_handle(const char *name
, const char *prop
,
1824 BUG_ON(!name
|| !ah
);
1827 status
= acpi_get_devices(prop
, acer_wmi_get_handle_cb
,
1828 (void *)name
, &handle
);
1830 if (ACPI_SUCCESS(status
)) {
1838 static int __init
acer_wmi_accel_setup(void)
1842 err
= acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle
);
1846 interface
->capability
|= ACER_CAP_ACCEL
;
1848 acer_wmi_accel_dev
= input_allocate_device();
1849 if (!acer_wmi_accel_dev
)
1852 acer_wmi_accel_dev
->open
= acer_gsensor_open
;
1854 acer_wmi_accel_dev
->name
= "Acer BMA150 accelerometer";
1855 acer_wmi_accel_dev
->phys
= "wmi/input1";
1856 acer_wmi_accel_dev
->id
.bustype
= BUS_HOST
;
1857 acer_wmi_accel_dev
->evbit
[0] = BIT_MASK(EV_ABS
);
1858 input_set_abs_params(acer_wmi_accel_dev
, ABS_X
, -16384, 16384, 0, 0);
1859 input_set_abs_params(acer_wmi_accel_dev
, ABS_Y
, -16384, 16384, 0, 0);
1860 input_set_abs_params(acer_wmi_accel_dev
, ABS_Z
, -16384, 16384, 0, 0);
1862 err
= input_register_device(acer_wmi_accel_dev
);
1869 input_free_device(acer_wmi_accel_dev
);
1873 static void acer_wmi_accel_destroy(void)
1875 input_unregister_device(acer_wmi_accel_dev
);
1878 static int __init
acer_wmi_input_setup(void)
1883 acer_wmi_input_dev
= input_allocate_device();
1884 if (!acer_wmi_input_dev
)
1887 acer_wmi_input_dev
->name
= "Acer WMI hotkeys";
1888 acer_wmi_input_dev
->phys
= "wmi/input0";
1889 acer_wmi_input_dev
->id
.bustype
= BUS_HOST
;
1891 err
= sparse_keymap_setup(acer_wmi_input_dev
, acer_wmi_keymap
, NULL
);
1895 status
= wmi_install_notify_handler(ACERWMID_EVENT_GUID
,
1896 acer_wmi_notify
, NULL
);
1897 if (ACPI_FAILURE(status
)) {
1899 goto err_free_keymap
;
1902 err
= input_register_device(acer_wmi_input_dev
);
1904 goto err_uninstall_notifier
;
1908 err_uninstall_notifier
:
1909 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1911 sparse_keymap_free(acer_wmi_input_dev
);
1913 input_free_device(acer_wmi_input_dev
);
1917 static void acer_wmi_input_destroy(void)
1919 wmi_remove_notify_handler(ACERWMID_EVENT_GUID
);
1920 sparse_keymap_free(acer_wmi_input_dev
);
1921 input_unregister_device(acer_wmi_input_dev
);
1927 static u32
get_wmid_devices(void)
1929 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1930 union acpi_object
*obj
;
1934 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1935 if (ACPI_FAILURE(status
))
1938 obj
= (union acpi_object
*) out
.pointer
;
1940 if (obj
->type
== ACPI_TYPE_BUFFER
&&
1941 (obj
->buffer
.length
== sizeof(u32
) ||
1942 obj
->buffer
.length
== sizeof(u64
))) {
1943 devices
= *((u32
*) obj
->buffer
.pointer
);
1944 } else if (obj
->type
== ACPI_TYPE_INTEGER
) {
1945 devices
= (u32
) obj
->integer
.value
;
1956 static int acer_platform_probe(struct platform_device
*device
)
1960 if (has_cap(ACER_CAP_MAILLED
)) {
1961 err
= acer_led_init(&device
->dev
);
1966 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1967 err
= acer_backlight_init(&device
->dev
);
1969 goto error_brightness
;
1972 err
= acer_rfkill_init(&device
->dev
);
1979 if (has_cap(ACER_CAP_BRIGHTNESS
))
1980 acer_backlight_exit();
1982 if (has_cap(ACER_CAP_MAILLED
))
1988 static int acer_platform_remove(struct platform_device
*device
)
1990 if (has_cap(ACER_CAP_MAILLED
))
1992 if (has_cap(ACER_CAP_BRIGHTNESS
))
1993 acer_backlight_exit();
1999 #ifdef CONFIG_PM_SLEEP
2000 static int acer_suspend(struct device
*dev
)
2003 struct acer_data
*data
= &interface
->data
;
2008 if (has_cap(ACER_CAP_MAILLED
)) {
2009 get_u32(&value
, ACER_CAP_MAILLED
);
2010 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2011 data
->mailled
= value
;
2014 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
2015 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
2016 data
->brightness
= value
;
2022 static int acer_resume(struct device
*dev
)
2024 struct acer_data
*data
= &interface
->data
;
2029 if (has_cap(ACER_CAP_MAILLED
))
2030 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
2032 if (has_cap(ACER_CAP_BRIGHTNESS
))
2033 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
2035 if (has_cap(ACER_CAP_ACCEL
))
2036 acer_gsensor_init();
2041 #define acer_suspend NULL
2042 #define acer_resume NULL
2045 static SIMPLE_DEV_PM_OPS(acer_pm
, acer_suspend
, acer_resume
);
2047 static void acer_platform_shutdown(struct platform_device
*device
)
2049 struct acer_data
*data
= &interface
->data
;
2054 if (has_cap(ACER_CAP_MAILLED
))
2055 set_u32(LED_OFF
, ACER_CAP_MAILLED
);
2058 static struct platform_driver acer_platform_driver
= {
2063 .probe
= acer_platform_probe
,
2064 .remove
= acer_platform_remove
,
2065 .shutdown
= acer_platform_shutdown
,
2068 static struct platform_device
*acer_platform_device
;
2070 static void remove_debugfs(void)
2072 debugfs_remove(interface
->debug
.devices
);
2073 debugfs_remove(interface
->debug
.root
);
2076 static int __init
create_debugfs(void)
2078 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
2079 if (!interface
->debug
.root
) {
2080 pr_err("Failed to create debugfs directory");
2084 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
2085 interface
->debug
.root
,
2086 &interface
->debug
.wmid_devices
);
2087 if (!interface
->debug
.devices
)
2097 static int __init
acer_wmi_init(void)
2101 pr_info("Acer Laptop ACPI-WMI Extras\n");
2103 if (dmi_check_system(acer_blacklist
)) {
2104 pr_info("Blacklisted hardware detected - not loading\n");
2111 * Detect which ACPI-WMI interface we're using.
2113 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2114 interface
= &AMW0_V2_interface
;
2116 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
2117 interface
= &wmid_interface
;
2119 if (wmi_has_guid(WMID_GUID3
))
2120 interface
= &wmid_v2_interface
;
2123 dmi_walk(type_aa_dmi_decode
, NULL
);
2125 if (wmi_has_guid(WMID_GUID2
) && interface
) {
2126 if (!has_type_aa
&& ACPI_FAILURE(WMID_set_capabilities())) {
2127 pr_err("Unable to detect available WMID devices\n");
2130 /* WMID always provides brightness methods */
2131 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
2132 } else if (!wmi_has_guid(WMID_GUID2
) && interface
&& !has_type_aa
) {
2133 pr_err("No WMID device detection method found\n");
2137 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
2138 interface
= &AMW0_interface
;
2140 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2141 pr_err("Unable to detect available AMW0 devices\n");
2146 if (wmi_has_guid(AMW0_GUID1
))
2147 AMW0_find_mailled();
2150 pr_err("No or unsupported WMI interface, unable to load\n");
2156 if (dmi_check_system(video_vendor_dmi_table
))
2157 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2159 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2160 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
2162 if (wmi_has_guid(WMID_GUID3
)) {
2164 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2165 pr_err("Cannot enable EC raw mode\n");
2168 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2169 pr_err("Cannot enable Launch Manager mode\n");
2172 } else if (ec_raw_mode
) {
2173 pr_info("No WMID EC raw mode enable method\n");
2176 if (wmi_has_guid(ACERWMID_EVENT_GUID
)) {
2177 err
= acer_wmi_input_setup();
2182 acer_wmi_accel_setup();
2184 err
= platform_driver_register(&acer_platform_driver
);
2186 pr_err("Unable to register platform driver\n");
2187 goto error_platform_register
;
2190 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
2191 if (!acer_platform_device
) {
2193 goto error_device_alloc
;
2196 err
= platform_device_add(acer_platform_device
);
2198 goto error_device_add
;
2200 if (wmi_has_guid(WMID_GUID2
)) {
2201 interface
->debug
.wmid_devices
= get_wmid_devices();
2202 err
= create_debugfs();
2204 goto error_create_debugfs
;
2207 /* Override any initial settings with values from the commandline */
2208 acer_commandline_init();
2212 error_create_debugfs
:
2213 platform_device_del(acer_platform_device
);
2215 platform_device_put(acer_platform_device
);
2217 platform_driver_unregister(&acer_platform_driver
);
2218 error_platform_register
:
2219 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2220 acer_wmi_input_destroy();
2221 if (has_cap(ACER_CAP_ACCEL
))
2222 acer_wmi_accel_destroy();
2227 static void __exit
acer_wmi_exit(void)
2229 if (wmi_has_guid(ACERWMID_EVENT_GUID
))
2230 acer_wmi_input_destroy();
2232 if (has_cap(ACER_CAP_ACCEL
))
2233 acer_wmi_accel_destroy();
2236 platform_device_unregister(acer_platform_device
);
2237 platform_driver_unregister(&acer_platform_driver
);
2239 pr_info("Acer Laptop WMI Extras unloaded\n");
2243 module_init(acer_wmi_init
);
2244 module_exit(acer_wmi_exit
);