blob: 85db9403cc14bae21fe838cd2eee9c3ad4be90ef [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002/*
3 * Acer WMI Laptop Extras
4 *
Carlos Corbacho4f0175d2009-04-04 09:33:39 +01005 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
Carlos Corbacho745a5d22008-02-05 02:17:10 +00006 *
7 * Based on acer_acpi:
8 * Copyright (C) 2005-2007 E.M. Smith
9 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000010 */
11
Lee, Chun-Yicae15702011-03-16 18:52:36 +080012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
Carlos Corbacho745a5d22008-02-05 02:17:10 +000014#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/types.h>
18#include <linux/dmi.h>
Carlos Corbachof2b585b2008-06-21 09:09:27 +010019#include <linux/fb.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000020#include <linux/backlight.h>
21#include <linux/leds.h>
22#include <linux/platform_device.h>
23#include <linux/acpi.h>
24#include <linux/i8042.h>
Carlos Corbacho0606e1a2008-10-08 21:40:21 +010025#include <linux/rfkill.h>
26#include <linux/workqueue.h>
Carlos Corbacho81143522008-06-21 09:09:53 +010027#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080029#include <linux/input.h>
30#include <linux/input/sparse-keymap.h>
Lee, Chun-Yi86924de2012-03-26 15:47:58 -040031#include <acpi/video.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000032
33MODULE_AUTHOR("Carlos Corbacho");
34MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
35MODULE_LICENSE("GPL");
36
Carlos Corbacho745a5d22008-02-05 02:17:10 +000037/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000038 * Magic Number
39 * Meaning is unknown - this number is required for writing to ACPI for AMW0
40 * (it's also used in acerhk when directly accessing the BIOS)
41 */
42#define ACER_AMW0_WRITE 0x9610
43
44/*
45 * Bit masks for the AMW0 interface
46 */
47#define ACER_AMW0_WIRELESS_MASK 0x35
48#define ACER_AMW0_BLUETOOTH_MASK 0x34
49#define ACER_AMW0_MAILLED_MASK 0x31
50
51/*
52 * Method IDs for WMID interface
53 */
54#define ACER_WMID_GET_WIRELESS_METHODID 1
55#define ACER_WMID_GET_BLUETOOTH_METHODID 2
56#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
57#define ACER_WMID_SET_WIRELESS_METHODID 4
58#define ACER_WMID_SET_BLUETOOTH_METHODID 5
59#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
60#define ACER_WMID_GET_THREEG_METHODID 10
61#define ACER_WMID_SET_THREEG_METHODID 11
62
63/*
64 * Acer ACPI method GUIDs
65 */
66#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010067#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Matthew Garrettbbb70602011-02-09 16:39:40 -050068#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
Pali Rohár298f19b2011-03-11 12:36:43 -050069#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080070#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000071
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080072/*
73 * Acer ACPI event GUIDs
74 */
75#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
76
Carlos Corbacho745a5d22008-02-05 02:17:10 +000077MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
Lee, Chun-Yi08a07992011-04-06 17:40:06 +080078MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080079MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
80
81enum acer_wmi_event_ids {
82 WMID_HOTKEY_EVENT = 0x1,
Hans de Goede5c54cb62020-10-19 20:56:28 +020083 WMID_ACCEL_OR_KBD_DOCK_EVENT = 0x5,
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080084};
85
Mathias Krause87e44842014-07-16 19:43:05 +020086static const struct key_entry acer_wmi_keymap[] __initconst = {
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080087 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +020088 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
Seth Forshee1a04d8f2011-06-21 12:00:32 -050089 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080090 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
91 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
92 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
93 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
94 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
Merlin Schumacher67e1d342012-01-24 04:35:35 +080095 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +020096 {KE_IGNORE, 0x41, {KEY_MUTE} },
97 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +030098 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +020099 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300100 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200101 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300102 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200103 {KE_IGNORE, 0x45, {KEY_STOP} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300104 {KE_IGNORE, 0x50, {KEY_STOP} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200105 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
106 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300107 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200108 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
109 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
110 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800111 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200112 {KE_IGNORE, 0x81, {KEY_SLEEP} },
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800113 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */
Timo Witte19cf7052020-08-04 02:14:23 +0200114 {KE_IGNORE, 0x84, {KEY_KBDILLUMTOGGLE} }, /* Automatic Keyboard background light toggle */
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800115 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
116 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200117 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
Sergey Senozhatsky68825ce2012-11-26 21:35:02 +0300118 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
Chris Chiu5ffa5722017-02-08 07:51:41 -0600119 {KE_KEY, 0x86, {KEY_WLAN} },
Antonio Rosario Intilisanoc7a437f2018-04-27 23:50:21 +0200120 {KE_KEY, 0x87, {KEY_POWER} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800121 {KE_END, 0}
122};
123
124static struct input_dev *acer_wmi_input_dev;
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200125static struct input_dev *acer_wmi_accel_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800126
127struct event_return_value {
128 u8 function;
129 u8 key_num;
130 u16 device_state;
Hans de Goede5c54cb62020-10-19 20:56:28 +0200131 u16 reserved1;
132 u8 kbd_dock_state;
133 u8 reserved2;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800134} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000135
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000136/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800137 * GUID3 Get Device Status device flags
138 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800139#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800140#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800141#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800142#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
João Paulo Rechi Vita3e2bc5c2017-06-06 13:07:22 -0700143#define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
144
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800145#define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800146
Chris Chiu280642c2017-02-08 07:51:40 -0600147/* Hotkey Customized Setting and Acer Application Status.
148 * Set Device Default Value and Report Acer Application Status.
149 * When Acer Application starts, it will run this method to inform
150 * BIOS/EC that Acer Application is on.
151 * App Status
152 * Bit[0]: Launch Manager Status
153 * Bit[1]: ePM Status
154 * Bit[2]: Device Control Status
155 * Bit[3]: Acer Power Button Utility Status
156 * Bit[4]: RF Button Status
157 * Bit[5]: ODD PM Status
158 * Bit[6]: Device Default Value Control
159 * Bit[7]: Hall Sensor Application Status
160 */
161struct func_input_params {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500162 u8 function_num; /* Function Number */
163 u16 commun_devices; /* Communication type devices default status */
164 u16 devices; /* Other type devices default status */
Chris Chiu280642c2017-02-08 07:51:40 -0600165 u8 app_status; /* Acer Device Status. LM, ePM, RF Button... */
166 u8 app_mask; /* Bit mask to app_status */
167 u8 reserved;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500168} __attribute__((packed));
169
Chris Chiu280642c2017-02-08 07:51:40 -0600170struct func_return_value {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500171 u8 error_code; /* Error Code */
172 u8 ec_return_value; /* EC Return Value */
173 u16 reserved;
174} __attribute__((packed));
175
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800176struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
177 u8 function_num; /* Function Number */
178 u8 hotkey_number; /* Hotkey Number */
179 u16 devices; /* Set Device */
180 u8 volume_value; /* Volume Value */
181} __attribute__((packed));
182
183struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800184 u8 function_num; /* Function Number */
185 u8 hotkey_number; /* Hotkey Number */
186 u16 devices; /* Get Device */
187} __attribute__((packed));
188
189struct wmid3_gds_return_value { /* Get Device Status return value*/
190 u8 error_code; /* Error Code */
191 u8 ec_return_value; /* EC Return Value */
192 u16 devices; /* Current Device Status */
193 u32 reserved;
194} __attribute__((packed));
195
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800196struct hotkey_function_type_aa {
197 u8 type;
198 u8 length;
199 u16 handle;
200 u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800201 u16 application_func_bitmap;
202 u16 media_func_bitmap;
203 u16 display_func_bitmap;
204 u16 others_func_bitmap;
205 u8 commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800206} __attribute__((packed));
207
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800208/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000209 * Interface capability flags
210 */
Hans de Goede7c936d82020-10-19 20:56:24 +0200211#define ACER_CAP_MAILLED BIT(0)
212#define ACER_CAP_WIRELESS BIT(1)
213#define ACER_CAP_BLUETOOTH BIT(2)
214#define ACER_CAP_BRIGHTNESS BIT(3)
215#define ACER_CAP_THREEG BIT(4)
Hans de Goede82cb8a52020-10-19 20:56:27 +0200216#define ACER_CAP_SET_FUNCTION_MODE BIT(5)
Hans de Goede5c54cb62020-10-19 20:56:28 +0200217#define ACER_CAP_KBD_DOCK BIT(6)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000218
219/*
220 * Interface type flags
221 */
222enum interface_flags {
223 ACER_AMW0,
224 ACER_AMW0_V2,
225 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800226 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000227};
228
229#define ACER_DEFAULT_WIRELESS 0
230#define ACER_DEFAULT_BLUETOOTH 0
231#define ACER_DEFAULT_MAILLED 0
232#define ACER_DEFAULT_THREEG 0
233
234static int max_brightness = 0xF;
235
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000236static int mailled = -1;
237static int brightness = -1;
238static int threeg = -1;
239static int force_series;
Hans de Goede39aa0092020-10-19 20:56:26 +0200240static int force_caps = -1;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500241static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800242static bool has_type_aa;
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +0800243static u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800244static u8 commun_fn_key_number;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000245
246module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000247module_param(brightness, int, 0444);
248module_param(threeg, int, 0444);
249module_param(force_series, int, 0444);
Hans de Goede39aa0092020-10-19 20:56:26 +0200250module_param(force_caps, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500251module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000252MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
253MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
254MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
255MODULE_PARM_DESC(force_series, "Force a different laptop series");
Hans de Goede39aa0092020-10-19 20:56:26 +0200256MODULE_PARM_DESC(force_caps, "Force the capability bitmask to this value");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500257MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000258
259struct acer_data {
260 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000261 int threeg;
262 int brightness;
263};
264
Carlos Corbacho81143522008-06-21 09:09:53 +0100265struct acer_debug {
266 struct dentry *root;
Carlos Corbacho81143522008-06-21 09:09:53 +0100267 u32 wmid_devices;
268};
269
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100270static struct rfkill *wireless_rfkill;
271static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800272static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800273static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100274
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000275/* Each low-level interface must define at least some of the following */
276struct wmi_interface {
277 /* The WMI device type */
278 u32 type;
279
280 /* The capabilities this interface provides */
281 u32 capability;
282
283 /* Private data for the current interface */
284 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100285
286 /* debugfs entries associated with this interface */
287 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000288};
289
290/* The static interface pointer, points to the currently detected interface */
291static struct wmi_interface *interface;
292
293/*
294 * Embedded Controller quirks
295 * Some laptops require us to directly access the EC to either enable or query
296 * features that are not available through WMI.
297 */
298
299struct quirk_entry {
300 u8 wireless;
301 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100302 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000303 u8 bluetooth;
304};
305
306static struct quirk_entry *quirks;
307
Mathias Krause76d51dd2014-07-16 19:43:04 +0200308static void __init set_quirks(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000309{
310 if (quirks->mailled)
311 interface->capability |= ACER_CAP_MAILLED;
312
313 if (quirks->brightness)
314 interface->capability |= ACER_CAP_BRIGHTNESS;
315}
316
Mathias Krause76d51dd2014-07-16 19:43:04 +0200317static int __init dmi_matched(const struct dmi_system_id *dmi)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000318{
319 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800320 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000321}
322
Hans de Goede5c54cb62020-10-19 20:56:28 +0200323static int __init set_force_caps(const struct dmi_system_id *dmi)
324{
325 if (force_caps == -1) {
326 force_caps = (uintptr_t)dmi->driver_data;
327 pr_info("Found %s, set force_caps to 0x%x\n", dmi->ident, force_caps);
328 }
329 return 1;
330}
331
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000332static struct quirk_entry quirk_unknown = {
333};
334
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100335static struct quirk_entry quirk_acer_aspire_1520 = {
336 .brightness = -1,
337};
338
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000339static struct quirk_entry quirk_acer_travelmate_2490 = {
340 .mailled = 1,
341};
342
343/* This AMW0 laptop has no bluetooth */
344static struct quirk_entry quirk_medion_md_98300 = {
345 .wireless = 1,
346};
347
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100348static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
349 .wireless = 2,
350};
351
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800352static struct quirk_entry quirk_lenovo_ideapad_s205 = {
353 .wireless = 3,
354};
355
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100356/* The Aspire One has a dummy ACPI-WMI interface - disable it */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200357static const struct dmi_system_id acer_blacklist[] __initconst = {
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100358 {
359 .ident = "Acer Aspire One (SSD)",
360 .matches = {
361 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
362 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
363 },
364 },
365 {
366 .ident = "Acer Aspire One (HDD)",
367 .matches = {
368 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
369 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
370 },
371 },
372 {}
373};
374
Lee, Chun-Yi5241b192016-11-01 12:30:58 +0800375static const struct dmi_system_id amw0_whitelist[] __initconst = {
376 {
377 .ident = "Acer",
378 .matches = {
379 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
380 },
381 },
382 {
383 .ident = "Gateway",
384 .matches = {
385 DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
386 },
387 },
388 {
389 .ident = "Packard Bell",
390 .matches = {
391 DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"),
392 },
393 },
394 {}
395};
396
397/*
398 * This quirk table is only for Acer/Gateway/Packard Bell family
399 * that those machines are supported by acer-wmi driver.
400 */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200401static const struct dmi_system_id acer_quirks[] __initconst = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000402 {
403 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100404 .ident = "Acer Aspire 1360",
405 .matches = {
406 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
407 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
408 },
409 .driver_data = &quirk_acer_aspire_1520,
410 },
411 {
412 .callback = dmi_matched,
413 .ident = "Acer Aspire 1520",
414 .matches = {
415 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
416 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
417 },
418 .driver_data = &quirk_acer_aspire_1520,
419 },
420 {
421 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000422 .ident = "Acer Aspire 3100",
423 .matches = {
424 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
425 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
426 },
427 .driver_data = &quirk_acer_travelmate_2490,
428 },
429 {
430 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000431 .ident = "Acer Aspire 3610",
432 .matches = {
433 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
434 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
435 },
436 .driver_data = &quirk_acer_travelmate_2490,
437 },
438 {
439 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000440 .ident = "Acer Aspire 5100",
441 .matches = {
442 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
443 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
444 },
445 .driver_data = &quirk_acer_travelmate_2490,
446 },
447 {
448 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000449 .ident = "Acer Aspire 5610",
450 .matches = {
451 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
452 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
453 },
454 .driver_data = &quirk_acer_travelmate_2490,
455 },
456 {
457 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000458 .ident = "Acer Aspire 5630",
459 .matches = {
460 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
461 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
462 },
463 .driver_data = &quirk_acer_travelmate_2490,
464 },
465 {
466 .callback = dmi_matched,
467 .ident = "Acer Aspire 5650",
468 .matches = {
469 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
470 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
471 },
472 .driver_data = &quirk_acer_travelmate_2490,
473 },
474 {
475 .callback = dmi_matched,
476 .ident = "Acer Aspire 5680",
477 .matches = {
478 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
479 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
480 },
481 .driver_data = &quirk_acer_travelmate_2490,
482 },
483 {
484 .callback = dmi_matched,
485 .ident = "Acer Aspire 9110",
486 .matches = {
487 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
488 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
489 },
490 .driver_data = &quirk_acer_travelmate_2490,
491 },
492 {
493 .callback = dmi_matched,
494 .ident = "Acer TravelMate 2490",
495 .matches = {
496 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
497 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
498 },
499 .driver_data = &quirk_acer_travelmate_2490,
500 },
501 {
502 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000503 .ident = "Acer TravelMate 4200",
504 .matches = {
505 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
506 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
507 },
508 .driver_data = &quirk_acer_travelmate_2490,
509 },
Hans de Goede5c54cb62020-10-19 20:56:28 +0200510 {
511 .callback = set_force_caps,
Hans de Goedebf753402020-11-23 16:16:25 +0100512 .ident = "Acer Aspire Switch 10E SW3-016",
513 .matches = {
514 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
515 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW3-016"),
516 },
517 .driver_data = (void *)ACER_CAP_KBD_DOCK,
518 },
519 {
520 .callback = set_force_caps,
Hans de Goede5c54cb62020-10-19 20:56:28 +0200521 .ident = "Acer Aspire Switch 10 SW5-012",
522 .matches = {
523 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
524 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
525 },
526 .driver_data = (void *)ACER_CAP_KBD_DOCK,
527 },
528 {
529 .callback = set_force_caps,
530 .ident = "Acer One 10 (S1003)",
531 .matches = {
532 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
533 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "One S1003"),
534 },
535 .driver_data = (void *)ACER_CAP_KBD_DOCK,
536 },
Lee, Chun-Yi5241b192016-11-01 12:30:58 +0800537 {}
538};
539
540/*
541 * This quirk list is for those non-acer machines that have AMW0_GUID1
542 * but supported by acer-wmi in past days. Keeping this quirk list here
543 * is only for backward compatible. Please do not add new machine to
544 * here anymore. Those non-acer machines should be supported by
545 * appropriate wmi drivers.
546 */
547static const struct dmi_system_id non_acer_quirks[] __initconst = {
Carlos Corbacho262ee352008-02-16 00:02:56 +0000548 {
549 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100550 .ident = "Fujitsu Siemens Amilo Li 1718",
551 .matches = {
552 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
553 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
554 },
555 .driver_data = &quirk_fujitsu_amilo_li_1718,
556 },
557 {
558 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000559 .ident = "Medion MD 98300",
560 .matches = {
561 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
562 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
563 },
564 .driver_data = &quirk_medion_md_98300,
565 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800566 {
567 .callback = dmi_matched,
568 .ident = "Lenovo Ideapad S205",
569 .matches = {
570 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
571 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
572 },
573 .driver_data = &quirk_lenovo_ideapad_s205,
574 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500575 {
576 .callback = dmi_matched,
Lee, Chun-Yic08f2082012-03-20 11:32:49 +0800577 .ident = "Lenovo Ideapad S205 (Brazos)",
578 .matches = {
579 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
580 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
581 },
582 .driver_data = &quirk_lenovo_ideapad_s205,
583 },
584 {
585 .callback = dmi_matched,
Seth Forsheebe3128b2011-10-06 15:01:55 -0500586 .ident = "Lenovo 3000 N200",
587 .matches = {
588 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
589 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
590 },
591 .driver_data = &quirk_fujitsu_amilo_li_1718,
592 },
Lee, Chun-Yie6c33f12012-12-14 16:14:25 +0800593 {
594 .callback = dmi_matched,
595 .ident = "Lenovo Ideapad S205-10382JG",
596 .matches = {
597 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
598 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
599 },
600 .driver_data = &quirk_lenovo_ideapad_s205,
601 },
Lee, Chun-Yi5f3511d2012-12-14 16:14:28 +0800602 {
603 .callback = dmi_matched,
604 .ident = "Lenovo Ideapad S205-1038DPG",
605 .matches = {
606 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
607 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
608 },
609 .driver_data = &quirk_lenovo_ideapad_s205,
610 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000611 {}
612};
613
Mathias Krause76d51dd2014-07-16 19:43:04 +0200614static int __init
615video_set_backlight_video_vendor(const struct dmi_system_id *d)
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400616{
617 interface->capability &= ~ACER_CAP_BRIGHTNESS;
618 pr_info("Brightness must be controlled by generic video driver\n");
619 return 0;
620}
621
Mathias Krause76d51dd2014-07-16 19:43:04 +0200622static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400623 {
624 .callback = video_set_backlight_video_vendor,
625 .ident = "Acer TravelMate 4750",
626 .matches = {
627 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
628 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
629 },
630 },
Lee, Chun-Yi050eff32012-05-21 23:19:51 +0800631 {
632 .callback = video_set_backlight_video_vendor,
633 .ident = "Acer Extensa 5235",
634 .matches = {
635 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
636 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
637 },
638 },
639 {
640 .callback = video_set_backlight_video_vendor,
641 .ident = "Acer TravelMate 5760",
642 .matches = {
643 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
644 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
645 },
646 },
647 {
648 .callback = video_set_backlight_video_vendor,
649 .ident = "Acer Aspire 5750",
650 .matches = {
651 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
652 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
653 },
654 },
Hans de Goede9404cd952014-05-17 10:48:03 +0200655 {
656 .callback = video_set_backlight_video_vendor,
657 .ident = "Acer Aspire 5741",
658 .matches = {
659 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
660 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
661 },
662 },
Hans de Goede183fd8f2014-10-22 16:06:38 +0200663 {
664 /*
665 * Note no video_set_backlight_video_vendor, we must use the
666 * acer interface, as there is no native backlight interface.
667 */
668 .ident = "Acer KAV80",
669 .matches = {
670 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
671 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
672 },
673 },
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400674 {}
675};
676
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000677/* Find which quirks are needed for a particular vendor/ model pair */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200678static void __init find_quirks(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000679{
680 if (!force_series) {
681 dmi_check_system(acer_quirks);
Lee, Chun-Yi5241b192016-11-01 12:30:58 +0800682 dmi_check_system(non_acer_quirks);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000683 } else if (force_series == 2490) {
684 quirks = &quirk_acer_travelmate_2490;
685 }
686
687 if (quirks == NULL)
688 quirks = &quirk_unknown;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000689}
690
691/*
692 * General interface convenience methods
693 */
694
695static bool has_cap(u32 cap)
696{
Gustavo A. R. Silvaaa7d16b2018-08-06 15:38:32 -0500697 return interface->capability & cap;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000698}
699
700/*
701 * AMW0 (V1) interface
702 */
703struct wmab_args {
704 u32 eax;
705 u32 ebx;
706 u32 ecx;
707 u32 edx;
708};
709
710struct wmab_ret {
711 u32 eax;
712 u32 ebx;
713 u32 ecx;
714 u32 edx;
715 u32 eex;
716};
717
718static acpi_status wmab_execute(struct wmab_args *regbuf,
719struct acpi_buffer *result)
720{
721 struct acpi_buffer input;
722 acpi_status status;
723 input.length = sizeof(struct wmab_args);
724 input.pointer = (u8 *)regbuf;
725
Lee, Chun-Yi62fc7432017-06-20 17:06:23 +0800726 status = wmi_evaluate_method(AMW0_GUID1, 0, 1, &input, result);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000727
728 return status;
729}
730
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800731static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000732{
733 int err;
734 u8 result;
735
736 switch (cap) {
737 case ACER_CAP_MAILLED:
738 switch (quirks->mailled) {
739 default:
740 err = ec_read(0xA, &result);
741 if (err)
742 return AE_ERROR;
743 *value = (result >> 7) & 0x1;
744 return AE_OK;
745 }
746 break;
747 case ACER_CAP_WIRELESS:
748 switch (quirks->wireless) {
749 case 1:
750 err = ec_read(0x7B, &result);
751 if (err)
752 return AE_ERROR;
753 *value = result & 0x1;
754 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100755 case 2:
756 err = ec_read(0x71, &result);
757 if (err)
758 return AE_ERROR;
759 *value = result & 0x1;
760 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800761 case 3:
762 err = ec_read(0x78, &result);
763 if (err)
764 return AE_ERROR;
765 *value = result & 0x1;
766 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000767 default:
768 err = ec_read(0xA, &result);
769 if (err)
770 return AE_ERROR;
771 *value = (result >> 2) & 0x1;
772 return AE_OK;
773 }
774 break;
775 case ACER_CAP_BLUETOOTH:
776 switch (quirks->bluetooth) {
777 default:
778 err = ec_read(0xA, &result);
779 if (err)
780 return AE_ERROR;
781 *value = (result >> 4) & 0x1;
782 return AE_OK;
783 }
784 break;
785 case ACER_CAP_BRIGHTNESS:
786 switch (quirks->brightness) {
787 default:
788 err = ec_read(0x83, &result);
789 if (err)
790 return AE_ERROR;
791 *value = result;
792 return AE_OK;
793 }
794 break;
795 default:
Lin Ming08237972008-08-08 11:57:11 +0800796 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000797 }
798 return AE_OK;
799}
800
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800801static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000802{
803 struct wmab_args args;
804
805 args.eax = ACER_AMW0_WRITE;
806 args.ebx = value ? (1<<8) : 0;
807 args.ecx = args.edx = 0;
808
809 switch (cap) {
810 case ACER_CAP_MAILLED:
811 if (value > 1)
812 return AE_BAD_PARAMETER;
813 args.ebx |= ACER_AMW0_MAILLED_MASK;
814 break;
815 case ACER_CAP_WIRELESS:
816 if (value > 1)
817 return AE_BAD_PARAMETER;
818 args.ebx |= ACER_AMW0_WIRELESS_MASK;
819 break;
820 case ACER_CAP_BLUETOOTH:
821 if (value > 1)
822 return AE_BAD_PARAMETER;
823 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
824 break;
825 case ACER_CAP_BRIGHTNESS:
826 if (value > max_brightness)
827 return AE_BAD_PARAMETER;
828 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000829 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000830 return ec_write(0x83, value);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000831 }
832 default:
Lin Ming08237972008-08-08 11:57:11 +0800833 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000834 }
835
836 /* Actually do the set */
837 return wmab_execute(&args, NULL);
838}
839
Mathias Krause76d51dd2014-07-16 19:43:04 +0200840static acpi_status __init AMW0_find_mailled(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000841{
842 struct wmab_args args;
843 struct wmab_ret ret;
844 acpi_status status = AE_OK;
845 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
846 union acpi_object *obj;
847
848 args.eax = 0x86;
849 args.ebx = args.ecx = args.edx = 0;
850
851 status = wmab_execute(&args, &out);
852 if (ACPI_FAILURE(status))
853 return status;
854
855 obj = (union acpi_object *) out.pointer;
856 if (obj && obj->type == ACPI_TYPE_BUFFER &&
857 obj->buffer.length == sizeof(struct wmab_ret)) {
858 ret = *((struct wmab_ret *) obj->buffer.pointer);
859 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700860 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000861 return AE_ERROR;
862 }
863
864 if (ret.eex & 0x1)
865 interface->capability |= ACER_CAP_MAILLED;
866
867 kfree(out.pointer);
868
869 return AE_OK;
870}
871
Mathias Krause76d51dd2014-07-16 19:43:04 +0200872static const struct acpi_device_id norfkill_ids[] __initconst = {
Ike Panhc461e7432012-02-03 16:46:39 +0800873 { "VPC2004", 0},
874 { "IBM0068", 0},
875 { "LEN0068", 0},
Lee, Chun-Yi5719b812012-03-23 12:36:44 +0800876 { "SNY5001", 0}, /* sony-laptop in charge */
Michael Powell628b31982015-08-02 22:59:29 +0000877 { "HPQ6601", 0},
Ike Panhc461e7432012-02-03 16:46:39 +0800878 { "", 0},
879};
880
Mathias Krause76d51dd2014-07-16 19:43:04 +0200881static int __init AMW0_set_cap_acpi_check_device(void)
Ike Panhc461e7432012-02-03 16:46:39 +0800882{
883 const struct acpi_device_id *id;
884
885 for (id = norfkill_ids; id->id[0]; id++)
Lukas Wunner8c92a752016-03-24 13:15:20 +0100886 if (acpi_dev_found(id->id))
887 return true;
888
889 return false;
Ike Panhc461e7432012-02-03 16:46:39 +0800890}
891
Mathias Krause76d51dd2014-07-16 19:43:04 +0200892static acpi_status __init AMW0_set_capabilities(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000893{
894 struct wmab_args args;
895 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700896 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000897 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
898 union acpi_object *obj;
899
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100900 /*
901 * On laptops with this strange GUID (non Acer), normal probing doesn't
902 * work.
903 */
904 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800905 if ((quirks != &quirk_unknown) ||
906 !AMW0_set_cap_acpi_check_device())
907 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100908 return AE_OK;
909 }
910
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000911 args.eax = ACER_AMW0_WRITE;
912 args.ecx = args.edx = 0;
913
914 args.ebx = 0xa2 << 8;
915 args.ebx |= ACER_AMW0_WIRELESS_MASK;
916
917 status = wmab_execute(&args, &out);
918 if (ACPI_FAILURE(status))
919 return status;
920
Axel Lin7677fbd2010-07-20 15:19:53 -0700921 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000922 if (obj && obj->type == ACPI_TYPE_BUFFER &&
923 obj->buffer.length == sizeof(struct wmab_ret)) {
924 ret = *((struct wmab_ret *) obj->buffer.pointer);
925 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700926 status = AE_ERROR;
927 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000928 }
929
930 if (ret.eax & 0x1)
931 interface->capability |= ACER_CAP_WIRELESS;
932
933 args.ebx = 2 << 8;
934 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
935
Axel Lin7677fbd2010-07-20 15:19:53 -0700936 /*
937 * It's ok to use existing buffer for next wmab_execute call.
938 * But we need to kfree(out.pointer) if next wmab_execute fail.
939 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000940 status = wmab_execute(&args, &out);
941 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700942 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000943
944 obj = (union acpi_object *) out.pointer;
945 if (obj && obj->type == ACPI_TYPE_BUFFER
946 && obj->buffer.length == sizeof(struct wmab_ret)) {
947 ret = *((struct wmab_ret *) obj->buffer.pointer);
948 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700949 status = AE_ERROR;
950 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000951 }
952
953 if (ret.eax & 0x1)
954 interface->capability |= ACER_CAP_BLUETOOTH;
955
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000956 /*
957 * This appears to be safe to enable, since all Wistron based laptops
958 * appear to use the same EC register for brightness, even if they
959 * differ for wireless, etc
960 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100961 if (quirks->brightness >= 0)
962 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000963
Axel Lin7677fbd2010-07-20 15:19:53 -0700964 status = AE_OK;
965out:
966 kfree(out.pointer);
967 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000968}
969
970static struct wmi_interface AMW0_interface = {
971 .type = ACER_AMW0,
972};
973
974static struct wmi_interface AMW0_V2_interface = {
975 .type = ACER_AMW0_V2,
976};
977
978/*
979 * New interface (The WMID interface)
980 */
981static acpi_status
982WMI_execute_u32(u32 method_id, u32 in, u32 *out)
983{
984 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
985 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
986 union acpi_object *obj;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800987 u32 tmp = 0;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000988 acpi_status status;
989
Lee, Chun-Yi62fc7432017-06-20 17:06:23 +0800990 status = wmi_evaluate_method(WMID_GUID1, 0, method_id, &input, &result);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000991
992 if (ACPI_FAILURE(status))
993 return status;
994
995 obj = (union acpi_object *) result.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800996 if (obj) {
997 if (obj->type == ACPI_TYPE_BUFFER &&
998 (obj->buffer.length == sizeof(u32) ||
999 obj->buffer.length == sizeof(u64))) {
1000 tmp = *((u32 *) obj->buffer.pointer);
1001 } else if (obj->type == ACPI_TYPE_INTEGER) {
1002 tmp = (u32) obj->integer.value;
1003 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001004 }
1005
1006 if (out)
1007 *out = tmp;
1008
1009 kfree(result.pointer);
1010
1011 return status;
1012}
1013
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001014static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001015{
1016 acpi_status status;
1017 u8 tmp;
1018 u32 result, method_id = 0;
1019
1020 switch (cap) {
1021 case ACER_CAP_WIRELESS:
1022 method_id = ACER_WMID_GET_WIRELESS_METHODID;
1023 break;
1024 case ACER_CAP_BLUETOOTH:
1025 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
1026 break;
1027 case ACER_CAP_BRIGHTNESS:
1028 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
1029 break;
1030 case ACER_CAP_THREEG:
1031 method_id = ACER_WMID_GET_THREEG_METHODID;
1032 break;
1033 case ACER_CAP_MAILLED:
1034 if (quirks->mailled == 1) {
1035 ec_read(0x9f, &tmp);
1036 *value = tmp & 0x1;
1037 return 0;
1038 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001039 fallthrough;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001040 default:
Lin Ming08237972008-08-08 11:57:11 +08001041 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001042 }
1043 status = WMI_execute_u32(method_id, 0, &result);
1044
1045 if (ACPI_SUCCESS(status))
1046 *value = (u8)result;
1047
1048 return status;
1049}
1050
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001051static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001052{
1053 u32 method_id = 0;
1054 char param;
1055
1056 switch (cap) {
1057 case ACER_CAP_BRIGHTNESS:
1058 if (value > max_brightness)
1059 return AE_BAD_PARAMETER;
1060 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
1061 break;
1062 case ACER_CAP_WIRELESS:
1063 if (value > 1)
1064 return AE_BAD_PARAMETER;
1065 method_id = ACER_WMID_SET_WIRELESS_METHODID;
1066 break;
1067 case ACER_CAP_BLUETOOTH:
1068 if (value > 1)
1069 return AE_BAD_PARAMETER;
1070 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
1071 break;
1072 case ACER_CAP_THREEG:
1073 if (value > 1)
1074 return AE_BAD_PARAMETER;
1075 method_id = ACER_WMID_SET_THREEG_METHODID;
1076 break;
1077 case ACER_CAP_MAILLED:
1078 if (value > 1)
1079 return AE_BAD_PARAMETER;
1080 if (quirks->mailled == 1) {
1081 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -07001082 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001083 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -07001084 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001085 return 0;
1086 }
1087 break;
1088 default:
Lin Ming08237972008-08-08 11:57:11 +08001089 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001090 }
1091 return WMI_execute_u32(method_id, (u32)value, NULL);
1092}
1093
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001094static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1095{
1096 struct wmid3_gds_return_value return_value;
1097 acpi_status status;
1098 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001099 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001100 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001101 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001102 .devices = device,
1103 };
1104 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001105 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001106 &params
1107 };
1108 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1109
1110 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1111 if (ACPI_FAILURE(status))
1112 return status;
1113
1114 obj = output.pointer;
1115
1116 if (!obj)
1117 return AE_ERROR;
1118 else if (obj->type != ACPI_TYPE_BUFFER) {
1119 kfree(obj);
1120 return AE_ERROR;
1121 }
1122 if (obj->buffer.length != 8) {
1123 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1124 kfree(obj);
1125 return AE_ERROR;
1126 }
1127
1128 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1129 kfree(obj);
1130
1131 if (return_value.error_code || return_value.ec_return_value)
1132 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1133 device,
1134 return_value.error_code,
1135 return_value.ec_return_value);
1136 else
1137 *value = !!(return_value.devices & device);
1138
1139 return status;
1140}
1141
1142static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1143{
1144 u16 device;
1145
1146 switch (cap) {
1147 case ACER_CAP_WIRELESS:
1148 device = ACER_WMID3_GDS_WIRELESS;
1149 break;
1150 case ACER_CAP_BLUETOOTH:
1151 device = ACER_WMID3_GDS_BLUETOOTH;
1152 break;
1153 case ACER_CAP_THREEG:
1154 device = ACER_WMID3_GDS_THREEG;
1155 break;
1156 default:
1157 return AE_ERROR;
1158 }
1159 return wmid3_get_device_status(value, device);
1160}
1161
1162static acpi_status wmid3_set_device_status(u32 value, u16 device)
1163{
1164 struct wmid3_gds_return_value return_value;
1165 acpi_status status;
1166 union acpi_object *obj;
1167 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001168 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001169 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001170 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001171 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001172 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001173 struct acpi_buffer get_input = {
1174 sizeof(struct wmid3_gds_get_input_param),
1175 &get_params
1176 };
1177 struct wmid3_gds_set_input_param set_params = {
1178 .function_num = 0x2,
1179 .hotkey_number = commun_fn_key_number,
1180 .devices = commun_func_bitmap,
1181 };
1182 struct acpi_buffer set_input = {
1183 sizeof(struct wmid3_gds_set_input_param),
1184 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001185 };
1186 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1187 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1188
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001189 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001190 if (ACPI_FAILURE(status))
1191 return status;
1192
1193 obj = output.pointer;
1194
1195 if (!obj)
1196 return AE_ERROR;
1197 else if (obj->type != ACPI_TYPE_BUFFER) {
1198 kfree(obj);
1199 return AE_ERROR;
1200 }
1201 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001202 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001203 kfree(obj);
1204 return AE_ERROR;
1205 }
1206
1207 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1208 kfree(obj);
1209
1210 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001211 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1212 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001213 return_value.ec_return_value);
1214 return status;
1215 }
1216
1217 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001218 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001219
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001220 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001221 if (ACPI_FAILURE(status))
1222 return status;
1223
1224 obj = output2.pointer;
1225
1226 if (!obj)
1227 return AE_ERROR;
1228 else if (obj->type != ACPI_TYPE_BUFFER) {
1229 kfree(obj);
1230 return AE_ERROR;
1231 }
1232 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001233 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001234 kfree(obj);
1235 return AE_ERROR;
1236 }
1237
1238 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1239 kfree(obj);
1240
1241 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001242 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1243 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001244 return_value.ec_return_value);
1245
1246 return status;
1247}
1248
1249static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1250{
1251 u16 device;
1252
1253 switch (cap) {
1254 case ACER_CAP_WIRELESS:
1255 device = ACER_WMID3_GDS_WIRELESS;
1256 break;
1257 case ACER_CAP_BLUETOOTH:
1258 device = ACER_WMID3_GDS_BLUETOOTH;
1259 break;
1260 case ACER_CAP_THREEG:
1261 device = ACER_WMID3_GDS_THREEG;
1262 break;
1263 default:
1264 return AE_ERROR;
1265 }
1266 return wmid3_set_device_status(value, device);
1267}
1268
Mathias Krause76d51dd2014-07-16 19:43:04 +02001269static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001270{
1271 struct hotkey_function_type_aa *type_aa;
1272
1273 /* We are looking for OEM-specific Type AAh */
1274 if (header->type != 0xAA)
1275 return;
1276
1277 has_type_aa = true;
1278 type_aa = (struct hotkey_function_type_aa *) header;
1279
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001280 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001281 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001282 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001283
1284 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1285 interface->capability |= ACER_CAP_WIRELESS;
1286 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1287 interface->capability |= ACER_CAP_THREEG;
1288 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1289 interface->capability |= ACER_CAP_BLUETOOTH;
Hans de Goede7c936d82020-10-19 20:56:24 +02001290 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_RFBTN)
João Paulo Rechi Vita3e2bc5c2017-06-06 13:07:22 -07001291 commun_func_bitmap &= ~ACER_WMID3_GDS_RFBTN;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001292
1293 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001294}
1295
Mathias Krause76d51dd2014-07-16 19:43:04 +02001296static acpi_status __init WMID_set_capabilities(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001297{
1298 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1299 union acpi_object *obj;
1300 acpi_status status;
1301 u32 devices;
1302
Lee, Chun-Yi62fc7432017-06-20 17:06:23 +08001303 status = wmi_query_block(WMID_GUID2, 0, &out);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001304 if (ACPI_FAILURE(status))
1305 return status;
1306
1307 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001308 if (obj) {
1309 if (obj->type == ACPI_TYPE_BUFFER &&
1310 (obj->buffer.length == sizeof(u32) ||
1311 obj->buffer.length == sizeof(u64))) {
1312 devices = *((u32 *) obj->buffer.pointer);
1313 } else if (obj->type == ACPI_TYPE_INTEGER) {
1314 devices = (u32) obj->integer.value;
Lee, Chun-Yif24c96e2013-01-03 10:37:45 +08001315 } else {
1316 kfree(out.pointer);
1317 return AE_ERROR;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001318 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001319 } else {
Axel Lin66904862010-07-20 15:19:52 -07001320 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001321 return AE_ERROR;
1322 }
1323
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001324 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1325 if (devices & 0x07)
1326 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001327 if (devices & 0x40)
1328 interface->capability |= ACER_CAP_THREEG;
1329 if (devices & 0x10)
1330 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001331
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001332 if (!(devices & 0x20))
1333 max_brightness = 0x9;
1334
Axel Lin66904862010-07-20 15:19:52 -07001335 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001336 return status;
1337}
1338
1339static struct wmi_interface wmid_interface = {
1340 .type = ACER_WMID,
1341};
1342
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001343static struct wmi_interface wmid_v2_interface = {
1344 .type = ACER_WMID_v2,
1345};
1346
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001347/*
1348 * Generic Device (interface-independent)
1349 */
1350
1351static acpi_status get_u32(u32 *value, u32 cap)
1352{
Lin Ming08237972008-08-08 11:57:11 +08001353 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001354
1355 switch (interface->type) {
1356 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001357 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001358 break;
1359 case ACER_AMW0_V2:
1360 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001361 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001362 break;
1363 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001364 fallthrough;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001365 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001366 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001367 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001368 case ACER_WMID_v2:
1369 if (cap & (ACER_CAP_WIRELESS |
1370 ACER_CAP_BLUETOOTH |
1371 ACER_CAP_THREEG))
1372 status = wmid_v2_get_u32(value, cap);
1373 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001374 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001375 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001376 }
1377
1378 return status;
1379}
1380
1381static acpi_status set_u32(u32 value, u32 cap)
1382{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001383 acpi_status status;
1384
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001385 if (interface->capability & cap) {
1386 switch (interface->type) {
1387 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001388 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001389 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001390 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001391 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001392
1393 /*
1394 * On some models, some WMID methods don't toggle
1395 * properly. For those cases, we want to run the AMW0
1396 * method afterwards to be certain we've really toggled
1397 * the device state.
1398 */
1399 if (cap == ACER_CAP_WIRELESS ||
1400 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001401 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001402 if (ACPI_FAILURE(status))
1403 return status;
1404
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001405 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001406 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001407 fallthrough;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001408 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001409 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001410 case ACER_WMID_v2:
1411 if (cap & (ACER_CAP_WIRELESS |
1412 ACER_CAP_BLUETOOTH |
1413 ACER_CAP_THREEG))
1414 return wmid_v2_set_u32(value, cap);
1415 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001416 return WMID_set_u32(value, cap);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001417 fallthrough;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001418 default:
1419 return AE_BAD_PARAMETER;
1420 }
1421 }
1422 return AE_BAD_PARAMETER;
1423}
1424
1425static void __init acer_commandline_init(void)
1426{
1427 /*
1428 * These will all fail silently if the value given is invalid, or the
1429 * capability isn't available on the given interface
1430 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001431 if (mailled >= 0)
1432 set_u32(mailled, ACER_CAP_MAILLED);
1433 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001434 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001435 if (brightness >= 0)
1436 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001437}
1438
1439/*
1440 * LED device (Mail LED only, no other LEDs known yet)
1441 */
1442static void mail_led_set(struct led_classdev *led_cdev,
1443enum led_brightness value)
1444{
1445 set_u32(value, ACER_CAP_MAILLED);
1446}
1447
1448static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001449 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001450 .brightness_set = mail_led_set,
1451};
1452
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001453static int acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001454{
1455 return led_classdev_register(dev, &mail_led);
1456}
1457
1458static void acer_led_exit(void)
1459{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001460 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001461 led_classdev_unregister(&mail_led);
1462}
1463
1464/*
1465 * Backlight device
1466 */
1467static struct backlight_device *acer_backlight_device;
1468
1469static int read_brightness(struct backlight_device *bd)
1470{
1471 u32 value;
1472 get_u32(&value, ACER_CAP_BRIGHTNESS);
1473 return value;
1474}
1475
1476static int update_bl_status(struct backlight_device *bd)
1477{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001478 int intensity = bd->props.brightness;
1479
1480 if (bd->props.power != FB_BLANK_UNBLANK)
1481 intensity = 0;
1482 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1483 intensity = 0;
1484
1485 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1486
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001487 return 0;
1488}
1489
Lionel Debrouxacc24722010-11-16 14:14:02 +01001490static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001491 .get_brightness = read_brightness,
1492 .update_status = update_bl_status,
1493};
1494
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001495static int acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001496{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001497 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001498 struct backlight_device *bd;
1499
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001500 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001501 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001502 props.max_brightness = max_brightness;
1503 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1504 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001505 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001506 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001507 acer_backlight_device = NULL;
1508 return PTR_ERR(bd);
1509 }
1510
1511 acer_backlight_device = bd;
1512
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001513 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001514 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001515 backlight_update_status(bd);
1516 return 0;
1517}
1518
Sam Ravnborg7560e382008-02-17 13:22:54 +01001519static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001520{
1521 backlight_device_unregister(acer_backlight_device);
1522}
1523
1524/*
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001525 * Accelerometer device
1526 */
1527static acpi_handle gsensor_handle;
1528
1529static int acer_gsensor_init(void)
1530{
1531 acpi_status status;
1532 struct acpi_buffer output;
1533 union acpi_object out_obj;
1534
1535 output.length = sizeof(out_obj);
1536 output.pointer = &out_obj;
1537 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1538 if (ACPI_FAILURE(status))
1539 return -1;
1540
1541 return 0;
1542}
1543
1544static int acer_gsensor_open(struct input_dev *input)
1545{
1546 return acer_gsensor_init();
1547}
1548
1549static int acer_gsensor_event(void)
1550{
1551 acpi_status status;
1552 struct acpi_buffer output;
1553 union acpi_object out_obj[5];
1554
Hans de Goede9feb0762020-10-19 20:56:25 +02001555 if (!acer_wmi_accel_dev)
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001556 return -1;
1557
1558 output.length = sizeof(out_obj);
1559 output.pointer = out_obj;
1560
1561 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1562 if (ACPI_FAILURE(status))
1563 return -1;
1564
1565 if (out_obj->package.count != 4)
1566 return -1;
1567
1568 input_report_abs(acer_wmi_accel_dev, ABS_X,
1569 (s16)out_obj->package.elements[0].integer.value);
1570 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1571 (s16)out_obj->package.elements[1].integer.value);
1572 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1573 (s16)out_obj->package.elements[2].integer.value);
1574 input_sync(acer_wmi_accel_dev);
1575 return 0;
1576}
1577
1578/*
Hans de Goede5c54cb62020-10-19 20:56:28 +02001579 * Switch series keyboard dock status
1580 */
1581static int acer_kbd_dock_state_to_sw_tablet_mode(u8 kbd_dock_state)
1582{
1583 switch (kbd_dock_state) {
1584 case 0x01: /* Docked, traditional clamshell laptop mode */
1585 return 0;
1586 case 0x04: /* Stand-alone tablet */
1587 case 0x40: /* Docked, tent mode, keyboard not usable */
1588 return 1;
1589 default:
1590 pr_warn("Unknown kbd_dock_state 0x%02x\n", kbd_dock_state);
1591 }
1592
1593 return 0;
1594}
1595
1596static void acer_kbd_dock_get_initial_state(void)
1597{
1598 u8 *output, input[8] = { 0x05, 0x00, };
1599 struct acpi_buffer input_buf = { sizeof(input), input };
1600 struct acpi_buffer output_buf = { ACPI_ALLOCATE_BUFFER, NULL };
1601 union acpi_object *obj;
1602 acpi_status status;
1603 int sw_tablet_mode;
1604
1605 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input_buf, &output_buf);
1606 if (ACPI_FAILURE(status)) {
Hans de Goedeef14f0e2021-02-04 15:02:05 +01001607 pr_err("Error getting keyboard-dock initial status: %s\n",
1608 acpi_format_exception(status));
Hans de Goede5c54cb62020-10-19 20:56:28 +02001609 return;
1610 }
1611
1612 obj = output_buf.pointer;
1613 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
1614 pr_err("Unexpected output format getting keyboard-dock initial status\n");
1615 goto out_free_obj;
1616 }
1617
1618 output = obj->buffer.pointer;
1619 if (output[0] != 0x00 || (output[3] != 0x05 && output[3] != 0x45)) {
1620 pr_err("Unexpected output [0]=0x%02x [3]=0x%02x getting keyboard-dock initial status\n",
1621 output[0], output[3]);
1622 goto out_free_obj;
1623 }
1624
1625 sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(output[4]);
1626 input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode);
1627
1628out_free_obj:
1629 kfree(obj);
1630}
1631
1632static void acer_kbd_dock_event(const struct event_return_value *event)
1633{
1634 int sw_tablet_mode;
1635
1636 if (!has_cap(ACER_CAP_KBD_DOCK))
1637 return;
1638
1639 sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(event->kbd_dock_state);
1640 input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode);
1641 input_sync(acer_wmi_input_dev);
1642}
1643
1644/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001645 * Rfkill devices
1646 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001647static void acer_rfkill_update(struct work_struct *ignored);
1648static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1649static void acer_rfkill_update(struct work_struct *ignored)
1650{
1651 u32 state;
1652 acpi_status status;
1653
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001654 if (has_cap(ACER_CAP_WIRELESS)) {
1655 status = get_u32(&state, ACER_CAP_WIRELESS);
1656 if (ACPI_SUCCESS(status)) {
1657 if (quirks->wireless == 3)
1658 rfkill_set_hw_state(wireless_rfkill, !state);
1659 else
1660 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001661 }
1662 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001663
1664 if (has_cap(ACER_CAP_BLUETOOTH)) {
1665 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1666 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001667 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001668 }
1669
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001670 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001671 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001672 if (ACPI_SUCCESS(status))
1673 rfkill_set_sw_state(threeg_rfkill, !state);
1674 }
1675
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001676 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001677}
1678
Johannes Berg19d337d2009-06-02 13:01:37 +02001679static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001680{
1681 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001682 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001683
1684 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001685 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001686 if (ACPI_FAILURE(status))
1687 return -ENODEV;
1688 }
1689
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001690 return 0;
1691}
1692
Johannes Berg19d337d2009-06-02 13:01:37 +02001693static const struct rfkill_ops acer_rfkill_ops = {
1694 .set_block = acer_rfkill_set,
1695};
1696
1697static struct rfkill *acer_rfkill_register(struct device *dev,
1698 enum rfkill_type type,
1699 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001700{
1701 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001702 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001703 u32 state;
1704 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001705
Johannes Berg19d337d2009-06-02 13:01:37 +02001706 rfkill_dev = rfkill_alloc(name, dev, type,
1707 &acer_rfkill_ops,
1708 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001709 if (!rfkill_dev)
1710 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001711
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001712 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001713
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001714 err = rfkill_register(rfkill_dev);
1715 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001716 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001717 return ERR_PTR(err);
1718 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001719
1720 if (ACPI_SUCCESS(status))
1721 rfkill_set_sw_state(rfkill_dev, !state);
1722
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001723 return rfkill_dev;
1724}
1725
1726static int acer_rfkill_init(struct device *dev)
1727{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001728 int err;
1729
1730 if (has_cap(ACER_CAP_WIRELESS)) {
1731 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1732 "acer-wireless", ACER_CAP_WIRELESS);
1733 if (IS_ERR(wireless_rfkill)) {
1734 err = PTR_ERR(wireless_rfkill);
1735 goto error_wireless;
1736 }
1737 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001738
1739 if (has_cap(ACER_CAP_BLUETOOTH)) {
1740 bluetooth_rfkill = acer_rfkill_register(dev,
1741 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1742 ACER_CAP_BLUETOOTH);
1743 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001744 err = PTR_ERR(bluetooth_rfkill);
1745 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001746 }
1747 }
1748
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001749 if (has_cap(ACER_CAP_THREEG)) {
1750 threeg_rfkill = acer_rfkill_register(dev,
1751 RFKILL_TYPE_WWAN, "acer-threeg",
1752 ACER_CAP_THREEG);
1753 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001754 err = PTR_ERR(threeg_rfkill);
1755 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001756 }
1757 }
1758
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001759 rfkill_inited = true;
1760
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001761 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1762 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001763 schedule_delayed_work(&acer_rfkill_work,
1764 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001765
1766 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001767
1768error_threeg:
1769 if (has_cap(ACER_CAP_BLUETOOTH)) {
1770 rfkill_unregister(bluetooth_rfkill);
1771 rfkill_destroy(bluetooth_rfkill);
1772 }
1773error_bluetooth:
1774 if (has_cap(ACER_CAP_WIRELESS)) {
1775 rfkill_unregister(wireless_rfkill);
1776 rfkill_destroy(wireless_rfkill);
1777 }
1778error_wireless:
1779 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001780}
1781
1782static void acer_rfkill_exit(void)
1783{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001784 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1785 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001786 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001787
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001788 if (has_cap(ACER_CAP_WIRELESS)) {
1789 rfkill_unregister(wireless_rfkill);
1790 rfkill_destroy(wireless_rfkill);
1791 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001792
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001793 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001794 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001795 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001796 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001797
1798 if (has_cap(ACER_CAP_THREEG)) {
1799 rfkill_unregister(threeg_rfkill);
1800 rfkill_destroy(threeg_rfkill);
1801 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001802 return;
1803}
1804
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001805static void acer_wmi_notify(u32 value, void *context)
1806{
1807 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1808 union acpi_object *obj;
1809 struct event_return_value return_value;
1810 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001811 u16 device_state;
1812 const struct key_entry *key;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001813 u32 scancode;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001814
1815 status = wmi_get_event_data(value, &response);
1816 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001817 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001818 return;
1819 }
1820
1821 obj = (union acpi_object *)response.pointer;
1822
1823 if (!obj)
1824 return;
1825 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001826 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001827 kfree(obj);
1828 return;
1829 }
1830 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001831 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001832 kfree(obj);
1833 return;
1834 }
1835
1836 return_value = *((struct event_return_value *)obj->buffer.pointer);
1837 kfree(obj);
1838
1839 switch (return_value.function) {
1840 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001841 device_state = return_value.device_state;
1842 pr_debug("device state: 0x%x\n", device_state);
1843
1844 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1845 return_value.key_num);
1846 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001847 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001848 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001849 } else {
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001850 scancode = return_value.key_num;
Seth Forshee92530662011-06-21 12:00:33 -05001851 switch (key->keycode) {
1852 case KEY_WLAN:
1853 case KEY_BLUETOOTH:
1854 if (has_cap(ACER_CAP_WIRELESS))
1855 rfkill_set_sw_state(wireless_rfkill,
1856 !(device_state & ACER_WMID3_GDS_WIRELESS));
1857 if (has_cap(ACER_CAP_THREEG))
1858 rfkill_set_sw_state(threeg_rfkill,
1859 !(device_state & ACER_WMID3_GDS_THREEG));
1860 if (has_cap(ACER_CAP_BLUETOOTH))
1861 rfkill_set_sw_state(bluetooth_rfkill,
1862 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1863 break;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001864 case KEY_TOUCHPAD_TOGGLE:
1865 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1866 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
Seth Forshee92530662011-06-21 12:00:33 -05001867 }
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001868 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
Seth Forshee92530662011-06-21 12:00:33 -05001869 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001870 break;
Hans de Goede5c54cb62020-10-19 20:56:28 +02001871 case WMID_ACCEL_OR_KBD_DOCK_EVENT:
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001872 acer_gsensor_event();
Hans de Goede5c54cb62020-10-19 20:56:28 +02001873 acer_kbd_dock_event(&return_value);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001874 break;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001875 default:
Joe Perches249c7202011-03-29 15:21:34 -07001876 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001877 return_value.function, return_value.key_num);
1878 break;
1879 }
1880}
1881
Mathias Krause76d51dd2014-07-16 19:43:04 +02001882static acpi_status __init
Chris Chiu280642c2017-02-08 07:51:40 -06001883wmid3_set_function_mode(struct func_input_params *params,
1884 struct func_return_value *return_value)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001885{
1886 acpi_status status;
1887 union acpi_object *obj;
1888
Chris Chiu280642c2017-02-08 07:51:40 -06001889 struct acpi_buffer input = { sizeof(struct func_input_params), params };
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001890 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1891
1892 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1893 if (ACPI_FAILURE(status))
1894 return status;
1895
1896 obj = output.pointer;
1897
1898 if (!obj)
1899 return AE_ERROR;
1900 else if (obj->type != ACPI_TYPE_BUFFER) {
1901 kfree(obj);
1902 return AE_ERROR;
1903 }
1904 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001905 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001906 kfree(obj);
1907 return AE_ERROR;
1908 }
1909
Chris Chiu280642c2017-02-08 07:51:40 -06001910 *return_value = *((struct func_return_value *)obj->buffer.pointer);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001911 kfree(obj);
1912
1913 return status;
1914}
1915
Mathias Krause76d51dd2014-07-16 19:43:04 +02001916static int __init acer_wmi_enable_ec_raw(void)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001917{
Chris Chiu280642c2017-02-08 07:51:40 -06001918 struct func_return_value return_value;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001919 acpi_status status;
Chris Chiu280642c2017-02-08 07:51:40 -06001920 struct func_input_params params = {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001921 .function_num = 0x1,
1922 .commun_devices = 0xFFFF,
1923 .devices = 0xFFFF,
Chris Chiu280642c2017-02-08 07:51:40 -06001924 .app_status = 0x00, /* Launch Manager Deactive */
1925 .app_mask = 0x01,
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001926 };
1927
Chris Chiu280642c2017-02-08 07:51:40 -06001928 status = wmid3_set_function_mode(&params, &return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001929
1930 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001931 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1932 return_value.error_code,
1933 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001934 else
Joe Perches249c7202011-03-29 15:21:34 -07001935 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001936
1937 return status;
1938}
1939
Mathias Krause76d51dd2014-07-16 19:43:04 +02001940static int __init acer_wmi_enable_lm(void)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001941{
Chris Chiu280642c2017-02-08 07:51:40 -06001942 struct func_return_value return_value;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001943 acpi_status status;
Chris Chiu280642c2017-02-08 07:51:40 -06001944 struct func_input_params params = {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001945 .function_num = 0x1,
1946 .commun_devices = 0xFFFF,
1947 .devices = 0xFFFF,
Chris Chiu280642c2017-02-08 07:51:40 -06001948 .app_status = 0x01, /* Launch Manager Active */
1949 .app_mask = 0x01,
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001950 };
1951
Chris Chiu280642c2017-02-08 07:51:40 -06001952 status = wmid3_set_function_mode(&params, &return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001953
1954 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001955 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1956 return_value.error_code,
1957 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001958
1959 return status;
1960}
1961
Chris Chiu280642c2017-02-08 07:51:40 -06001962static int __init acer_wmi_enable_rf_button(void)
1963{
1964 struct func_return_value return_value;
1965 acpi_status status;
1966 struct func_input_params params = {
1967 .function_num = 0x1,
1968 .commun_devices = 0xFFFF,
1969 .devices = 0xFFFF,
1970 .app_status = 0x10, /* RF Button Active */
1971 .app_mask = 0x10,
1972 };
1973
1974 status = wmid3_set_function_mode(&params, &return_value);
1975
1976 if (return_value.error_code || return_value.ec_return_value)
1977 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1978 return_value.error_code,
1979 return_value.ec_return_value);
1980
1981 return status;
1982}
1983
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001984static int __init acer_wmi_accel_setup(void)
1985{
Andy Shevchenko6fe93632019-07-23 23:34:11 +03001986 struct acpi_device *adev;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001987 int err;
1988
Andy Shevchenko6fe93632019-07-23 23:34:11 +03001989 adev = acpi_dev_get_first_match_dev("BST0001", NULL, -1);
1990 if (!adev)
1991 return -ENODEV;
1992
1993 gsensor_handle = acpi_device_handle(adev);
1994 acpi_dev_put(adev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001995
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001996 acer_wmi_accel_dev = input_allocate_device();
1997 if (!acer_wmi_accel_dev)
1998 return -ENOMEM;
1999
2000 acer_wmi_accel_dev->open = acer_gsensor_open;
2001
2002 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
2003 acer_wmi_accel_dev->phys = "wmi/input1";
2004 acer_wmi_accel_dev->id.bustype = BUS_HOST;
2005 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
2006 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
2007 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
2008 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
2009
2010 err = input_register_device(acer_wmi_accel_dev);
2011 if (err)
2012 goto err_free_dev;
2013
2014 return 0;
2015
2016err_free_dev:
2017 input_free_device(acer_wmi_accel_dev);
2018 return err;
2019}
2020
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002021static int __init acer_wmi_input_setup(void)
2022{
2023 acpi_status status;
2024 int err;
2025
2026 acer_wmi_input_dev = input_allocate_device();
2027 if (!acer_wmi_input_dev)
2028 return -ENOMEM;
2029
2030 acer_wmi_input_dev->name = "Acer WMI hotkeys";
2031 acer_wmi_input_dev->phys = "wmi/input0";
2032 acer_wmi_input_dev->id.bustype = BUS_HOST;
2033
2034 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
2035 if (err)
2036 goto err_free_dev;
2037
Hans de Goede5c54cb62020-10-19 20:56:28 +02002038 if (has_cap(ACER_CAP_KBD_DOCK))
2039 input_set_capability(acer_wmi_input_dev, EV_SW, SW_TABLET_MODE);
2040
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002041 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
2042 acer_wmi_notify, NULL);
2043 if (ACPI_FAILURE(status)) {
2044 err = -EIO;
Michał Kępieńcd1aaef2017-03-09 13:11:37 +01002045 goto err_free_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002046 }
2047
Hans de Goede5c54cb62020-10-19 20:56:28 +02002048 if (has_cap(ACER_CAP_KBD_DOCK))
2049 acer_kbd_dock_get_initial_state();
2050
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002051 err = input_register_device(acer_wmi_input_dev);
2052 if (err)
2053 goto err_uninstall_notifier;
2054
2055 return 0;
2056
2057err_uninstall_notifier:
2058 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002059err_free_dev:
2060 input_free_device(acer_wmi_input_dev);
2061 return err;
2062}
2063
2064static void acer_wmi_input_destroy(void)
2065{
2066 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002067 input_unregister_device(acer_wmi_input_dev);
2068}
2069
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002070/*
Carlos Corbacho81143522008-06-21 09:09:53 +01002071 * debugfs functions
2072 */
2073static u32 get_wmid_devices(void)
2074{
2075 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
2076 union acpi_object *obj;
2077 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07002078 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01002079
Lee, Chun-Yi62fc7432017-06-20 17:06:23 +08002080 status = wmi_query_block(WMID_GUID2, 0, &out);
Carlos Corbacho81143522008-06-21 09:09:53 +01002081 if (ACPI_FAILURE(status))
2082 return 0;
2083
2084 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08002085 if (obj) {
2086 if (obj->type == ACPI_TYPE_BUFFER &&
2087 (obj->buffer.length == sizeof(u32) ||
2088 obj->buffer.length == sizeof(u64))) {
2089 devices = *((u32 *) obj->buffer.pointer);
2090 } else if (obj->type == ACPI_TYPE_INTEGER) {
2091 devices = (u32) obj->integer.value;
2092 }
Carlos Corbacho81143522008-06-21 09:09:53 +01002093 }
Axel Lin66904862010-07-20 15:19:52 -07002094
2095 kfree(out.pointer);
2096 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01002097}
2098
2099/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002100 * Platform device
2101 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002102static int acer_platform_probe(struct platform_device *device)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002103{
2104 int err;
2105
2106 if (has_cap(ACER_CAP_MAILLED)) {
2107 err = acer_led_init(&device->dev);
2108 if (err)
2109 goto error_mailled;
2110 }
2111
2112 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2113 err = acer_backlight_init(&device->dev);
2114 if (err)
2115 goto error_brightness;
2116 }
2117
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002118 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01002119 if (err)
2120 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002121
2122 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002123
Andy Whitcroft350e3292009-04-04 09:33:34 +01002124error_rfkill:
2125 if (has_cap(ACER_CAP_BRIGHTNESS))
2126 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002127error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01002128 if (has_cap(ACER_CAP_MAILLED))
2129 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002130error_mailled:
2131 return err;
2132}
2133
2134static int acer_platform_remove(struct platform_device *device)
2135{
2136 if (has_cap(ACER_CAP_MAILLED))
2137 acer_led_exit();
2138 if (has_cap(ACER_CAP_BRIGHTNESS))
2139 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002140
2141 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002142 return 0;
2143}
2144
Mathias Krause80f65552014-07-16 19:43:06 +02002145#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002146static int acer_suspend(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002147{
2148 u32 value;
2149 struct acer_data *data = &interface->data;
2150
2151 if (!data)
2152 return -ENOMEM;
2153
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002154 if (has_cap(ACER_CAP_MAILLED)) {
2155 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002156 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002157 data->mailled = value;
2158 }
2159
2160 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2161 get_u32(&value, ACER_CAP_BRIGHTNESS);
2162 data->brightness = value;
2163 }
2164
2165 return 0;
2166}
2167
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002168static int acer_resume(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002169{
2170 struct acer_data *data = &interface->data;
2171
2172 if (!data)
2173 return -ENOMEM;
2174
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002175 if (has_cap(ACER_CAP_MAILLED))
2176 set_u32(data->mailled, ACER_CAP_MAILLED);
2177
2178 if (has_cap(ACER_CAP_BRIGHTNESS))
2179 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2180
Hans de Goede9feb0762020-10-19 20:56:25 +02002181 if (acer_wmi_accel_dev)
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002182 acer_gsensor_init();
2183
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002184 return 0;
2185}
Mathias Krause80f65552014-07-16 19:43:06 +02002186#else
2187#define acer_suspend NULL
2188#define acer_resume NULL
2189#endif
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002190
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002191static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2192
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002193static void acer_platform_shutdown(struct platform_device *device)
2194{
2195 struct acer_data *data = &interface->data;
2196
2197 if (!data)
2198 return;
2199
2200 if (has_cap(ACER_CAP_MAILLED))
2201 set_u32(LED_OFF, ACER_CAP_MAILLED);
2202}
2203
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002204static struct platform_driver acer_platform_driver = {
2205 .driver = {
2206 .name = "acer-wmi",
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002207 .pm = &acer_pm,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002208 },
2209 .probe = acer_platform_probe,
2210 .remove = acer_platform_remove,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002211 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002212};
2213
2214static struct platform_device *acer_platform_device;
2215
Carlos Corbacho81143522008-06-21 09:09:53 +01002216static void remove_debugfs(void)
2217{
Greg Kroah-Hartman0b9dd932019-06-12 14:12:51 +02002218 debugfs_remove_recursive(interface->debug.root);
Carlos Corbacho81143522008-06-21 09:09:53 +01002219}
2220
Greg Kroah-Hartman0b9dd932019-06-12 14:12:51 +02002221static void __init create_debugfs(void)
Carlos Corbacho81143522008-06-21 09:09:53 +01002222{
2223 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
Carlos Corbacho81143522008-06-21 09:09:53 +01002224
Greg Kroah-Hartman0b9dd932019-06-12 14:12:51 +02002225 debugfs_create_u32("devices", S_IRUGO, interface->debug.root,
2226 &interface->debug.wmid_devices);
Carlos Corbacho81143522008-06-21 09:09:53 +01002227}
2228
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002229static int __init acer_wmi_init(void)
2230{
2231 int err;
2232
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002233 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002234
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002235 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002236 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002237 return -ENODEV;
2238 }
2239
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01002240 find_quirks();
2241
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002242 /*
Lee, Chun-Yi5241b192016-11-01 12:30:58 +08002243 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2244 * machines like Lenovo, Fujitsu and Medion. In the past days,
2245 * acer-wmi driver handled those non-Acer machines by quirks list.
2246 * But actually acer-wmi driver was loaded on any machines that have
2247 * AMW0_GUID1. This behavior is strange because those machines should
2248 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2249 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2250 * should be in Acer/Gateway/Packard Bell white list, or it's already
2251 * in the past quirk list.
2252 */
2253 if (wmi_has_guid(AMW0_GUID1) &&
2254 !dmi_check_system(amw0_whitelist) &&
2255 quirks == &quirk_unknown) {
Benjamin Herrenschmidt9bd51962018-08-16 09:27:10 +10002256 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
Lee, Chun-Yi5241b192016-11-01 12:30:58 +08002257 return -ENODEV;
2258 }
2259
2260 /*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002261 * Detect which ACPI-WMI interface we're using.
2262 */
2263 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2264 interface = &AMW0_V2_interface;
2265
2266 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2267 interface = &wmid_interface;
2268
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002269 if (wmi_has_guid(WMID_GUID3))
2270 interface = &wmid_v2_interface;
2271
2272 if (interface)
2273 dmi_walk(type_aa_dmi_decode, NULL);
2274
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002275 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002276 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002277 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002278 return -ENODEV;
2279 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002280 /* WMID always provides brightness methods */
2281 interface->capability |= ACER_CAP_BRIGHTNESS;
Hans de Goede39aa0092020-10-19 20:56:26 +02002282 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa && force_caps == -1) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002283 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002284 return -ENODEV;
2285 }
2286
2287 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2288 interface = &AMW0_interface;
2289
2290 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002291 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002292 return -ENODEV;
2293 }
2294 }
2295
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002296 if (wmi_has_guid(AMW0_GUID1))
2297 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002298
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002299 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002300 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002301 return -ENODEV;
2302 }
2303
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002304 set_quirks();
2305
Corentin Charya60b2172012-06-13 09:32:02 +02002306 if (dmi_check_system(video_vendor_dmi_table))
Hans de Goede9a65f0d2015-06-16 16:27:55 +02002307 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2308
2309 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Corentin Charya60b2172012-06-13 09:32:02 +02002310 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002311
Hans de Goede82cb8a52020-10-19 20:56:27 +02002312 if (wmi_has_guid(WMID_GUID3))
2313 interface->capability |= ACER_CAP_SET_FUNCTION_MODE;
2314
Hans de Goede39aa0092020-10-19 20:56:26 +02002315 if (force_caps != -1)
2316 interface->capability = force_caps;
2317
Hans de Goede82cb8a52020-10-19 20:56:27 +02002318 if (wmi_has_guid(WMID_GUID3) &&
2319 (interface->capability & ACER_CAP_SET_FUNCTION_MODE)) {
Chris Chiu280642c2017-02-08 07:51:40 -06002320 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2321 pr_warn("Cannot enable RF Button Driver\n");
2322
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002323 if (ec_raw_mode) {
2324 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002325 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002326 return -ENODEV;
2327 }
2328 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002329 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002330 return -ENODEV;
2331 }
2332 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002333 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002334 }
2335
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002336 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2337 err = acer_wmi_input_setup();
2338 if (err)
2339 return err;
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08002340 err = acer_wmi_accel_setup();
Lee, Chun-Yif9ac89f2017-04-28 16:23:59 +08002341 if (err && err != -ENODEV)
2342 pr_warn("Cannot enable accelerometer\n");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002343 }
2344
Axel Lin1c796322010-06-22 16:17:38 +08002345 err = platform_driver_register(&acer_platform_driver);
2346 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002347 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002348 goto error_platform_register;
2349 }
Axel Lin1c796322010-06-22 16:17:38 +08002350
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002351 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002352 if (!acer_platform_device) {
2353 err = -ENOMEM;
2354 goto error_device_alloc;
2355 }
2356
2357 err = platform_device_add(acer_platform_device);
2358 if (err)
2359 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002360
Carlos Corbacho81143522008-06-21 09:09:53 +01002361 if (wmi_has_guid(WMID_GUID2)) {
2362 interface->debug.wmid_devices = get_wmid_devices();
Greg Kroah-Hartman0b9dd932019-06-12 14:12:51 +02002363 create_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01002364 }
2365
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002366 /* Override any initial settings with values from the commandline */
2367 acer_commandline_init();
2368
2369 return 0;
2370
Axel Lin1c796322010-06-22 16:17:38 +08002371error_device_add:
2372 platform_device_put(acer_platform_device);
2373error_device_alloc:
2374 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002375error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002376 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2377 acer_wmi_input_destroy();
Hans de Goede9feb0762020-10-19 20:56:25 +02002378 if (acer_wmi_accel_dev)
2379 input_unregister_device(acer_wmi_accel_dev);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002380
Axel Lin1c796322010-06-22 16:17:38 +08002381 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002382}
2383
2384static void __exit acer_wmi_exit(void)
2385{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002386 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2387 acer_wmi_input_destroy();
2388
Hans de Goede9feb0762020-10-19 20:56:25 +02002389 if (acer_wmi_accel_dev)
2390 input_unregister_device(acer_wmi_accel_dev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002391
Russ Dill39dbbb42008-09-02 14:35:40 -07002392 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002393 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002394 platform_driver_unregister(&acer_platform_driver);
2395
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002396 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002397 return;
2398}
2399
2400module_init(acer_wmi_init);
2401module_exit(acer_wmi_exit);