blob: 79fa5ab3fd000d8cefe83fce929f132540ee5a98 [file] [log] [blame]
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001/*
2 * Acer WMI Laptop Extras
3 *
Carlos Corbacho4f0175d2009-04-04 09:33:39 +01004 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
Carlos Corbacho745a5d22008-02-05 02:17:10 +00005 *
6 * Based on acer_acpi:
7 * Copyright (C) 2005-2007 E.M. Smith
8 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
Lee, Chun-Yicae15702011-03-16 18:52:36 +080025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Carlos Corbacho745a5d22008-02-05 02:17:10 +000027#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/dmi.h>
Carlos Corbachof2b585b2008-06-21 09:09:27 +010032#include <linux/fb.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000033#include <linux/backlight.h>
34#include <linux/leds.h>
35#include <linux/platform_device.h>
36#include <linux/acpi.h>
37#include <linux/i8042.h>
Carlos Corbacho0606e1a2008-10-08 21:40:21 +010038#include <linux/rfkill.h>
39#include <linux/workqueue.h>
Carlos Corbacho81143522008-06-21 09:09:53 +010040#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080042#include <linux/input.h>
43#include <linux/input/sparse-keymap.h>
Lee, Chun-Yi86924de2012-03-26 15:47:58 -040044#include <acpi/video.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000045
46MODULE_AUTHOR("Carlos Corbacho");
47MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
48MODULE_LICENSE("GPL");
49
Carlos Corbacho745a5d22008-02-05 02:17:10 +000050/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000051 * Magic Number
52 * Meaning is unknown - this number is required for writing to ACPI for AMW0
53 * (it's also used in acerhk when directly accessing the BIOS)
54 */
55#define ACER_AMW0_WRITE 0x9610
56
57/*
58 * Bit masks for the AMW0 interface
59 */
60#define ACER_AMW0_WIRELESS_MASK 0x35
61#define ACER_AMW0_BLUETOOTH_MASK 0x34
62#define ACER_AMW0_MAILLED_MASK 0x31
63
64/*
65 * Method IDs for WMID interface
66 */
67#define ACER_WMID_GET_WIRELESS_METHODID 1
68#define ACER_WMID_GET_BLUETOOTH_METHODID 2
69#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
70#define ACER_WMID_SET_WIRELESS_METHODID 4
71#define ACER_WMID_SET_BLUETOOTH_METHODID 5
72#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
73#define ACER_WMID_GET_THREEG_METHODID 10
74#define ACER_WMID_SET_THREEG_METHODID 11
75
76/*
77 * Acer ACPI method GUIDs
78 */
79#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010080#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Matthew Garrettbbb70602011-02-09 16:39:40 -050081#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
Pali Rohár298f19b2011-03-11 12:36:43 -050082#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080083#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000084
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080085/*
86 * Acer ACPI event GUIDs
87 */
88#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
89
Carlos Corbacho745a5d22008-02-05 02:17:10 +000090MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
Lee, Chun-Yi08a07992011-04-06 17:40:06 +080091MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080092MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
93
94enum acer_wmi_event_ids {
95 WMID_HOTKEY_EVENT = 0x1,
Marek Vasut1eb3fe12012-06-01 19:11:22 +020096 WMID_ACCEL_EVENT = 0x5,
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080097};
98
Mathias Krause87e44842014-07-16 19:43:05 +020099static const struct key_entry acer_wmi_keymap[] __initconst = {
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800100 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200101 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
Seth Forshee1a04d8f2011-06-21 12:00:32 -0500102 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800103 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
104 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
105 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
106 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
107 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
Merlin Schumacher67e1d342012-01-24 04:35:35 +0800108 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200109 {KE_IGNORE, 0x41, {KEY_MUTE} },
110 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300111 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200112 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300113 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200114 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300115 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200116 {KE_IGNORE, 0x45, {KEY_STOP} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300117 {KE_IGNORE, 0x50, {KEY_STOP} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200118 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
119 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300120 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200121 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
122 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
123 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800124 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200125 {KE_IGNORE, 0x81, {KEY_SLEEP} },
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800126 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */
127 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
128 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200129 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
Sergey Senozhatsky68825ce2012-11-26 21:35:02 +0300130 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
Chris Chiu5ffa5722017-02-08 07:51:41 -0600131 {KE_KEY, 0x86, {KEY_WLAN} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800132 {KE_END, 0}
133};
134
135static struct input_dev *acer_wmi_input_dev;
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200136static struct input_dev *acer_wmi_accel_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800137
138struct event_return_value {
139 u8 function;
140 u8 key_num;
141 u16 device_state;
142 u32 reserved;
143} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000144
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000145/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800146 * GUID3 Get Device Status device flags
147 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800148#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800149#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800150#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800151#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800152#define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800153
Chris Chiu280642c2017-02-08 07:51:40 -0600154/* Hotkey Customized Setting and Acer Application Status.
155 * Set Device Default Value and Report Acer Application Status.
156 * When Acer Application starts, it will run this method to inform
157 * BIOS/EC that Acer Application is on.
158 * App Status
159 * Bit[0]: Launch Manager Status
160 * Bit[1]: ePM Status
161 * Bit[2]: Device Control Status
162 * Bit[3]: Acer Power Button Utility Status
163 * Bit[4]: RF Button Status
164 * Bit[5]: ODD PM Status
165 * Bit[6]: Device Default Value Control
166 * Bit[7]: Hall Sensor Application Status
167 */
168struct func_input_params {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500169 u8 function_num; /* Function Number */
170 u16 commun_devices; /* Communication type devices default status */
171 u16 devices; /* Other type devices default status */
Chris Chiu280642c2017-02-08 07:51:40 -0600172 u8 app_status; /* Acer Device Status. LM, ePM, RF Button... */
173 u8 app_mask; /* Bit mask to app_status */
174 u8 reserved;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500175} __attribute__((packed));
176
Chris Chiu280642c2017-02-08 07:51:40 -0600177struct func_return_value {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500178 u8 error_code; /* Error Code */
179 u8 ec_return_value; /* EC Return Value */
180 u16 reserved;
181} __attribute__((packed));
182
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800183struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
184 u8 function_num; /* Function Number */
185 u8 hotkey_number; /* Hotkey Number */
186 u16 devices; /* Set Device */
187 u8 volume_value; /* Volume Value */
188} __attribute__((packed));
189
190struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800191 u8 function_num; /* Function Number */
192 u8 hotkey_number; /* Hotkey Number */
193 u16 devices; /* Get Device */
194} __attribute__((packed));
195
196struct wmid3_gds_return_value { /* Get Device Status return value*/
197 u8 error_code; /* Error Code */
198 u8 ec_return_value; /* EC Return Value */
199 u16 devices; /* Current Device Status */
200 u32 reserved;
201} __attribute__((packed));
202
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800203struct hotkey_function_type_aa {
204 u8 type;
205 u8 length;
206 u16 handle;
207 u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800208 u16 application_func_bitmap;
209 u16 media_func_bitmap;
210 u16 display_func_bitmap;
211 u16 others_func_bitmap;
212 u8 commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800213} __attribute__((packed));
214
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800215/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000216 * Interface capability flags
217 */
218#define ACER_CAP_MAILLED (1<<0)
219#define ACER_CAP_WIRELESS (1<<1)
220#define ACER_CAP_BLUETOOTH (1<<2)
221#define ACER_CAP_BRIGHTNESS (1<<3)
222#define ACER_CAP_THREEG (1<<4)
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200223#define ACER_CAP_ACCEL (1<<5)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000224#define ACER_CAP_ANY (0xFFFFFFFF)
225
226/*
227 * Interface type flags
228 */
229enum interface_flags {
230 ACER_AMW0,
231 ACER_AMW0_V2,
232 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800233 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000234};
235
236#define ACER_DEFAULT_WIRELESS 0
237#define ACER_DEFAULT_BLUETOOTH 0
238#define ACER_DEFAULT_MAILLED 0
239#define ACER_DEFAULT_THREEG 0
240
241static int max_brightness = 0xF;
242
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000243static int mailled = -1;
244static int brightness = -1;
245static int threeg = -1;
246static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500247static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800248static bool has_type_aa;
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +0800249static u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800250static u8 commun_fn_key_number;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000251
252module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000253module_param(brightness, int, 0444);
254module_param(threeg, int, 0444);
255module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500256module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000257MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
258MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
259MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
260MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500261MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000262
263struct acer_data {
264 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000265 int threeg;
266 int brightness;
267};
268
Carlos Corbacho81143522008-06-21 09:09:53 +0100269struct acer_debug {
270 struct dentry *root;
271 struct dentry *devices;
272 u32 wmid_devices;
273};
274
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100275static struct rfkill *wireless_rfkill;
276static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800277static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800278static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100279
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000280/* Each low-level interface must define at least some of the following */
281struct wmi_interface {
282 /* The WMI device type */
283 u32 type;
284
285 /* The capabilities this interface provides */
286 u32 capability;
287
288 /* Private data for the current interface */
289 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100290
291 /* debugfs entries associated with this interface */
292 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000293};
294
295/* The static interface pointer, points to the currently detected interface */
296static struct wmi_interface *interface;
297
298/*
299 * Embedded Controller quirks
300 * Some laptops require us to directly access the EC to either enable or query
301 * features that are not available through WMI.
302 */
303
304struct quirk_entry {
305 u8 wireless;
306 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100307 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000308 u8 bluetooth;
309};
310
311static struct quirk_entry *quirks;
312
Mathias Krause76d51dd2014-07-16 19:43:04 +0200313static void __init set_quirks(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000314{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700315 if (!interface)
316 return;
317
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000318 if (quirks->mailled)
319 interface->capability |= ACER_CAP_MAILLED;
320
321 if (quirks->brightness)
322 interface->capability |= ACER_CAP_BRIGHTNESS;
323}
324
Mathias Krause76d51dd2014-07-16 19:43:04 +0200325static int __init dmi_matched(const struct dmi_system_id *dmi)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000326{
327 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800328 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000329}
330
331static struct quirk_entry quirk_unknown = {
332};
333
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100334static struct quirk_entry quirk_acer_aspire_1520 = {
335 .brightness = -1,
336};
337
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000338static struct quirk_entry quirk_acer_travelmate_2490 = {
339 .mailled = 1,
340};
341
342/* This AMW0 laptop has no bluetooth */
343static struct quirk_entry quirk_medion_md_98300 = {
344 .wireless = 1,
345};
346
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100347static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
348 .wireless = 2,
349};
350
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800351static struct quirk_entry quirk_lenovo_ideapad_s205 = {
352 .wireless = 3,
353};
354
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100355/* The Aspire One has a dummy ACPI-WMI interface - disable it */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200356static const struct dmi_system_id acer_blacklist[] __initconst = {
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100357 {
358 .ident = "Acer Aspire One (SSD)",
359 .matches = {
360 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
361 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
362 },
363 },
364 {
365 .ident = "Acer Aspire One (HDD)",
366 .matches = {
367 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
368 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
369 },
370 },
371 {}
372};
373
Lee, Chun-Yi5241b192016-11-01 12:30:58 +0800374static const struct dmi_system_id amw0_whitelist[] __initconst = {
375 {
376 .ident = "Acer",
377 .matches = {
378 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
379 },
380 },
381 {
382 .ident = "Gateway",
383 .matches = {
384 DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
385 },
386 },
387 {
388 .ident = "Packard Bell",
389 .matches = {
390 DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"),
391 },
392 },
393 {}
394};
395
396/*
397 * This quirk table is only for Acer/Gateway/Packard Bell family
398 * that those machines are supported by acer-wmi driver.
399 */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200400static const struct dmi_system_id acer_quirks[] __initconst = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000401 {
402 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100403 .ident = "Acer Aspire 1360",
404 .matches = {
405 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
406 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
407 },
408 .driver_data = &quirk_acer_aspire_1520,
409 },
410 {
411 .callback = dmi_matched,
412 .ident = "Acer Aspire 1520",
413 .matches = {
414 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
415 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
416 },
417 .driver_data = &quirk_acer_aspire_1520,
418 },
419 {
420 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000421 .ident = "Acer Aspire 3100",
422 .matches = {
423 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
424 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
425 },
426 .driver_data = &quirk_acer_travelmate_2490,
427 },
428 {
429 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000430 .ident = "Acer Aspire 3610",
431 .matches = {
432 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
433 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
434 },
435 .driver_data = &quirk_acer_travelmate_2490,
436 },
437 {
438 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000439 .ident = "Acer Aspire 5100",
440 .matches = {
441 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
442 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
443 },
444 .driver_data = &quirk_acer_travelmate_2490,
445 },
446 {
447 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000448 .ident = "Acer Aspire 5610",
449 .matches = {
450 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
451 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
452 },
453 .driver_data = &quirk_acer_travelmate_2490,
454 },
455 {
456 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000457 .ident = "Acer Aspire 5630",
458 .matches = {
459 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
460 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
461 },
462 .driver_data = &quirk_acer_travelmate_2490,
463 },
464 {
465 .callback = dmi_matched,
466 .ident = "Acer Aspire 5650",
467 .matches = {
468 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
469 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
470 },
471 .driver_data = &quirk_acer_travelmate_2490,
472 },
473 {
474 .callback = dmi_matched,
475 .ident = "Acer Aspire 5680",
476 .matches = {
477 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
478 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
479 },
480 .driver_data = &quirk_acer_travelmate_2490,
481 },
482 {
483 .callback = dmi_matched,
484 .ident = "Acer Aspire 9110",
485 .matches = {
486 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
487 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
488 },
489 .driver_data = &quirk_acer_travelmate_2490,
490 },
491 {
492 .callback = dmi_matched,
493 .ident = "Acer TravelMate 2490",
494 .matches = {
495 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
496 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
497 },
498 .driver_data = &quirk_acer_travelmate_2490,
499 },
500 {
501 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000502 .ident = "Acer TravelMate 4200",
503 .matches = {
504 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
505 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
506 },
507 .driver_data = &quirk_acer_travelmate_2490,
508 },
Lee, Chun-Yi5241b192016-11-01 12:30:58 +0800509 {}
510};
511
512/*
513 * This quirk list is for those non-acer machines that have AMW0_GUID1
514 * but supported by acer-wmi in past days. Keeping this quirk list here
515 * is only for backward compatible. Please do not add new machine to
516 * here anymore. Those non-acer machines should be supported by
517 * appropriate wmi drivers.
518 */
519static const struct dmi_system_id non_acer_quirks[] __initconst = {
Carlos Corbacho262ee352008-02-16 00:02:56 +0000520 {
521 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100522 .ident = "Fujitsu Siemens Amilo Li 1718",
523 .matches = {
524 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
525 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
526 },
527 .driver_data = &quirk_fujitsu_amilo_li_1718,
528 },
529 {
530 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000531 .ident = "Medion MD 98300",
532 .matches = {
533 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
534 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
535 },
536 .driver_data = &quirk_medion_md_98300,
537 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800538 {
539 .callback = dmi_matched,
540 .ident = "Lenovo Ideapad S205",
541 .matches = {
542 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
543 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
544 },
545 .driver_data = &quirk_lenovo_ideapad_s205,
546 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500547 {
548 .callback = dmi_matched,
Lee, Chun-Yic08f2082012-03-20 11:32:49 +0800549 .ident = "Lenovo Ideapad S205 (Brazos)",
550 .matches = {
551 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
552 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
553 },
554 .driver_data = &quirk_lenovo_ideapad_s205,
555 },
556 {
557 .callback = dmi_matched,
Seth Forsheebe3128b2011-10-06 15:01:55 -0500558 .ident = "Lenovo 3000 N200",
559 .matches = {
560 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
561 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
562 },
563 .driver_data = &quirk_fujitsu_amilo_li_1718,
564 },
Lee, Chun-Yie6c33f12012-12-14 16:14:25 +0800565 {
566 .callback = dmi_matched,
567 .ident = "Lenovo Ideapad S205-10382JG",
568 .matches = {
569 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
570 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
571 },
572 .driver_data = &quirk_lenovo_ideapad_s205,
573 },
Lee, Chun-Yi5f3511d2012-12-14 16:14:28 +0800574 {
575 .callback = dmi_matched,
576 .ident = "Lenovo Ideapad S205-1038DPG",
577 .matches = {
578 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
579 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
580 },
581 .driver_data = &quirk_lenovo_ideapad_s205,
582 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000583 {}
584};
585
Mathias Krause76d51dd2014-07-16 19:43:04 +0200586static int __init
587video_set_backlight_video_vendor(const struct dmi_system_id *d)
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400588{
589 interface->capability &= ~ACER_CAP_BRIGHTNESS;
590 pr_info("Brightness must be controlled by generic video driver\n");
591 return 0;
592}
593
Mathias Krause76d51dd2014-07-16 19:43:04 +0200594static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400595 {
596 .callback = video_set_backlight_video_vendor,
597 .ident = "Acer TravelMate 4750",
598 .matches = {
599 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
600 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
601 },
602 },
Lee, Chun-Yi050eff32012-05-21 23:19:51 +0800603 {
604 .callback = video_set_backlight_video_vendor,
605 .ident = "Acer Extensa 5235",
606 .matches = {
607 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
608 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
609 },
610 },
611 {
612 .callback = video_set_backlight_video_vendor,
613 .ident = "Acer TravelMate 5760",
614 .matches = {
615 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
616 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
617 },
618 },
619 {
620 .callback = video_set_backlight_video_vendor,
621 .ident = "Acer Aspire 5750",
622 .matches = {
623 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
624 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
625 },
626 },
Hans de Goede9404cd952014-05-17 10:48:03 +0200627 {
628 .callback = video_set_backlight_video_vendor,
629 .ident = "Acer Aspire 5741",
630 .matches = {
631 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
632 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
633 },
634 },
Hans de Goede183fd8f2014-10-22 16:06:38 +0200635 {
636 /*
637 * Note no video_set_backlight_video_vendor, we must use the
638 * acer interface, as there is no native backlight interface.
639 */
640 .ident = "Acer KAV80",
641 .matches = {
642 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
643 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
644 },
645 },
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400646 {}
647};
648
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000649/* Find which quirks are needed for a particular vendor/ model pair */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200650static void __init find_quirks(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000651{
652 if (!force_series) {
653 dmi_check_system(acer_quirks);
Lee, Chun-Yi5241b192016-11-01 12:30:58 +0800654 dmi_check_system(non_acer_quirks);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000655 } else if (force_series == 2490) {
656 quirks = &quirk_acer_travelmate_2490;
657 }
658
659 if (quirks == NULL)
660 quirks = &quirk_unknown;
661
662 set_quirks();
663}
664
665/*
666 * General interface convenience methods
667 */
668
669static bool has_cap(u32 cap)
670{
671 if ((interface->capability & cap) != 0)
672 return 1;
673
674 return 0;
675}
676
677/*
678 * AMW0 (V1) interface
679 */
680struct wmab_args {
681 u32 eax;
682 u32 ebx;
683 u32 ecx;
684 u32 edx;
685};
686
687struct wmab_ret {
688 u32 eax;
689 u32 ebx;
690 u32 ecx;
691 u32 edx;
692 u32 eex;
693};
694
695static acpi_status wmab_execute(struct wmab_args *regbuf,
696struct acpi_buffer *result)
697{
698 struct acpi_buffer input;
699 acpi_status status;
700 input.length = sizeof(struct wmab_args);
701 input.pointer = (u8 *)regbuf;
702
703 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
704
705 return status;
706}
707
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800708static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000709{
710 int err;
711 u8 result;
712
713 switch (cap) {
714 case ACER_CAP_MAILLED:
715 switch (quirks->mailled) {
716 default:
717 err = ec_read(0xA, &result);
718 if (err)
719 return AE_ERROR;
720 *value = (result >> 7) & 0x1;
721 return AE_OK;
722 }
723 break;
724 case ACER_CAP_WIRELESS:
725 switch (quirks->wireless) {
726 case 1:
727 err = ec_read(0x7B, &result);
728 if (err)
729 return AE_ERROR;
730 *value = result & 0x1;
731 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100732 case 2:
733 err = ec_read(0x71, &result);
734 if (err)
735 return AE_ERROR;
736 *value = result & 0x1;
737 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800738 case 3:
739 err = ec_read(0x78, &result);
740 if (err)
741 return AE_ERROR;
742 *value = result & 0x1;
743 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000744 default:
745 err = ec_read(0xA, &result);
746 if (err)
747 return AE_ERROR;
748 *value = (result >> 2) & 0x1;
749 return AE_OK;
750 }
751 break;
752 case ACER_CAP_BLUETOOTH:
753 switch (quirks->bluetooth) {
754 default:
755 err = ec_read(0xA, &result);
756 if (err)
757 return AE_ERROR;
758 *value = (result >> 4) & 0x1;
759 return AE_OK;
760 }
761 break;
762 case ACER_CAP_BRIGHTNESS:
763 switch (quirks->brightness) {
764 default:
765 err = ec_read(0x83, &result);
766 if (err)
767 return AE_ERROR;
768 *value = result;
769 return AE_OK;
770 }
771 break;
772 default:
Lin Ming08237972008-08-08 11:57:11 +0800773 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000774 }
775 return AE_OK;
776}
777
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800778static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000779{
780 struct wmab_args args;
781
782 args.eax = ACER_AMW0_WRITE;
783 args.ebx = value ? (1<<8) : 0;
784 args.ecx = args.edx = 0;
785
786 switch (cap) {
787 case ACER_CAP_MAILLED:
788 if (value > 1)
789 return AE_BAD_PARAMETER;
790 args.ebx |= ACER_AMW0_MAILLED_MASK;
791 break;
792 case ACER_CAP_WIRELESS:
793 if (value > 1)
794 return AE_BAD_PARAMETER;
795 args.ebx |= ACER_AMW0_WIRELESS_MASK;
796 break;
797 case ACER_CAP_BLUETOOTH:
798 if (value > 1)
799 return AE_BAD_PARAMETER;
800 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
801 break;
802 case ACER_CAP_BRIGHTNESS:
803 if (value > max_brightness)
804 return AE_BAD_PARAMETER;
805 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000806 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000807 return ec_write(0x83, value);
808 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000809 }
810 default:
Lin Ming08237972008-08-08 11:57:11 +0800811 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000812 }
813
814 /* Actually do the set */
815 return wmab_execute(&args, NULL);
816}
817
Mathias Krause76d51dd2014-07-16 19:43:04 +0200818static acpi_status __init AMW0_find_mailled(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000819{
820 struct wmab_args args;
821 struct wmab_ret ret;
822 acpi_status status = AE_OK;
823 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
824 union acpi_object *obj;
825
826 args.eax = 0x86;
827 args.ebx = args.ecx = args.edx = 0;
828
829 status = wmab_execute(&args, &out);
830 if (ACPI_FAILURE(status))
831 return status;
832
833 obj = (union acpi_object *) out.pointer;
834 if (obj && obj->type == ACPI_TYPE_BUFFER &&
835 obj->buffer.length == sizeof(struct wmab_ret)) {
836 ret = *((struct wmab_ret *) obj->buffer.pointer);
837 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700838 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000839 return AE_ERROR;
840 }
841
842 if (ret.eex & 0x1)
843 interface->capability |= ACER_CAP_MAILLED;
844
845 kfree(out.pointer);
846
847 return AE_OK;
848}
849
Mathias Krause76d51dd2014-07-16 19:43:04 +0200850static const struct acpi_device_id norfkill_ids[] __initconst = {
Ike Panhc461e7432012-02-03 16:46:39 +0800851 { "VPC2004", 0},
852 { "IBM0068", 0},
853 { "LEN0068", 0},
Lee, Chun-Yi5719b812012-03-23 12:36:44 +0800854 { "SNY5001", 0}, /* sony-laptop in charge */
Michael Powell628b31982015-08-02 22:59:29 +0000855 { "HPQ6601", 0},
Ike Panhc461e7432012-02-03 16:46:39 +0800856 { "", 0},
857};
858
Mathias Krause76d51dd2014-07-16 19:43:04 +0200859static int __init AMW0_set_cap_acpi_check_device(void)
Ike Panhc461e7432012-02-03 16:46:39 +0800860{
861 const struct acpi_device_id *id;
862
863 for (id = norfkill_ids; id->id[0]; id++)
Lukas Wunner8c92a752016-03-24 13:15:20 +0100864 if (acpi_dev_found(id->id))
865 return true;
866
867 return false;
Ike Panhc461e7432012-02-03 16:46:39 +0800868}
869
Mathias Krause76d51dd2014-07-16 19:43:04 +0200870static acpi_status __init AMW0_set_capabilities(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000871{
872 struct wmab_args args;
873 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700874 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000875 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
876 union acpi_object *obj;
877
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100878 /*
879 * On laptops with this strange GUID (non Acer), normal probing doesn't
880 * work.
881 */
882 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800883 if ((quirks != &quirk_unknown) ||
884 !AMW0_set_cap_acpi_check_device())
885 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100886 return AE_OK;
887 }
888
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000889 args.eax = ACER_AMW0_WRITE;
890 args.ecx = args.edx = 0;
891
892 args.ebx = 0xa2 << 8;
893 args.ebx |= ACER_AMW0_WIRELESS_MASK;
894
895 status = wmab_execute(&args, &out);
896 if (ACPI_FAILURE(status))
897 return status;
898
Axel Lin7677fbd2010-07-20 15:19:53 -0700899 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000900 if (obj && obj->type == ACPI_TYPE_BUFFER &&
901 obj->buffer.length == sizeof(struct wmab_ret)) {
902 ret = *((struct wmab_ret *) obj->buffer.pointer);
903 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700904 status = AE_ERROR;
905 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000906 }
907
908 if (ret.eax & 0x1)
909 interface->capability |= ACER_CAP_WIRELESS;
910
911 args.ebx = 2 << 8;
912 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
913
Axel Lin7677fbd2010-07-20 15:19:53 -0700914 /*
915 * It's ok to use existing buffer for next wmab_execute call.
916 * But we need to kfree(out.pointer) if next wmab_execute fail.
917 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000918 status = wmab_execute(&args, &out);
919 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700920 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000921
922 obj = (union acpi_object *) out.pointer;
923 if (obj && obj->type == ACPI_TYPE_BUFFER
924 && obj->buffer.length == sizeof(struct wmab_ret)) {
925 ret = *((struct wmab_ret *) obj->buffer.pointer);
926 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700927 status = AE_ERROR;
928 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000929 }
930
931 if (ret.eax & 0x1)
932 interface->capability |= ACER_CAP_BLUETOOTH;
933
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000934 /*
935 * This appears to be safe to enable, since all Wistron based laptops
936 * appear to use the same EC register for brightness, even if they
937 * differ for wireless, etc
938 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100939 if (quirks->brightness >= 0)
940 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000941
Axel Lin7677fbd2010-07-20 15:19:53 -0700942 status = AE_OK;
943out:
944 kfree(out.pointer);
945 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000946}
947
948static struct wmi_interface AMW0_interface = {
949 .type = ACER_AMW0,
950};
951
952static struct wmi_interface AMW0_V2_interface = {
953 .type = ACER_AMW0_V2,
954};
955
956/*
957 * New interface (The WMID interface)
958 */
959static acpi_status
960WMI_execute_u32(u32 method_id, u32 in, u32 *out)
961{
962 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
963 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
964 union acpi_object *obj;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800965 u32 tmp = 0;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000966 acpi_status status;
967
968 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
969
970 if (ACPI_FAILURE(status))
971 return status;
972
973 obj = (union acpi_object *) result.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800974 if (obj) {
975 if (obj->type == ACPI_TYPE_BUFFER &&
976 (obj->buffer.length == sizeof(u32) ||
977 obj->buffer.length == sizeof(u64))) {
978 tmp = *((u32 *) obj->buffer.pointer);
979 } else if (obj->type == ACPI_TYPE_INTEGER) {
980 tmp = (u32) obj->integer.value;
981 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000982 }
983
984 if (out)
985 *out = tmp;
986
987 kfree(result.pointer);
988
989 return status;
990}
991
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800992static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000993{
994 acpi_status status;
995 u8 tmp;
996 u32 result, method_id = 0;
997
998 switch (cap) {
999 case ACER_CAP_WIRELESS:
1000 method_id = ACER_WMID_GET_WIRELESS_METHODID;
1001 break;
1002 case ACER_CAP_BLUETOOTH:
1003 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
1004 break;
1005 case ACER_CAP_BRIGHTNESS:
1006 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
1007 break;
1008 case ACER_CAP_THREEG:
1009 method_id = ACER_WMID_GET_THREEG_METHODID;
1010 break;
1011 case ACER_CAP_MAILLED:
1012 if (quirks->mailled == 1) {
1013 ec_read(0x9f, &tmp);
1014 *value = tmp & 0x1;
1015 return 0;
1016 }
1017 default:
Lin Ming08237972008-08-08 11:57:11 +08001018 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001019 }
1020 status = WMI_execute_u32(method_id, 0, &result);
1021
1022 if (ACPI_SUCCESS(status))
1023 *value = (u8)result;
1024
1025 return status;
1026}
1027
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001028static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001029{
1030 u32 method_id = 0;
1031 char param;
1032
1033 switch (cap) {
1034 case ACER_CAP_BRIGHTNESS:
1035 if (value > max_brightness)
1036 return AE_BAD_PARAMETER;
1037 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
1038 break;
1039 case ACER_CAP_WIRELESS:
1040 if (value > 1)
1041 return AE_BAD_PARAMETER;
1042 method_id = ACER_WMID_SET_WIRELESS_METHODID;
1043 break;
1044 case ACER_CAP_BLUETOOTH:
1045 if (value > 1)
1046 return AE_BAD_PARAMETER;
1047 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
1048 break;
1049 case ACER_CAP_THREEG:
1050 if (value > 1)
1051 return AE_BAD_PARAMETER;
1052 method_id = ACER_WMID_SET_THREEG_METHODID;
1053 break;
1054 case ACER_CAP_MAILLED:
1055 if (value > 1)
1056 return AE_BAD_PARAMETER;
1057 if (quirks->mailled == 1) {
1058 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -07001059 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001060 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -07001061 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001062 return 0;
1063 }
1064 break;
1065 default:
Lin Ming08237972008-08-08 11:57:11 +08001066 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001067 }
1068 return WMI_execute_u32(method_id, (u32)value, NULL);
1069}
1070
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001071static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1072{
1073 struct wmid3_gds_return_value return_value;
1074 acpi_status status;
1075 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001076 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001077 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001078 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001079 .devices = device,
1080 };
1081 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001082 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001083 &params
1084 };
1085 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1086
1087 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1088 if (ACPI_FAILURE(status))
1089 return status;
1090
1091 obj = output.pointer;
1092
1093 if (!obj)
1094 return AE_ERROR;
1095 else if (obj->type != ACPI_TYPE_BUFFER) {
1096 kfree(obj);
1097 return AE_ERROR;
1098 }
1099 if (obj->buffer.length != 8) {
1100 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1101 kfree(obj);
1102 return AE_ERROR;
1103 }
1104
1105 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1106 kfree(obj);
1107
1108 if (return_value.error_code || return_value.ec_return_value)
1109 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1110 device,
1111 return_value.error_code,
1112 return_value.ec_return_value);
1113 else
1114 *value = !!(return_value.devices & device);
1115
1116 return status;
1117}
1118
1119static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1120{
1121 u16 device;
1122
1123 switch (cap) {
1124 case ACER_CAP_WIRELESS:
1125 device = ACER_WMID3_GDS_WIRELESS;
1126 break;
1127 case ACER_CAP_BLUETOOTH:
1128 device = ACER_WMID3_GDS_BLUETOOTH;
1129 break;
1130 case ACER_CAP_THREEG:
1131 device = ACER_WMID3_GDS_THREEG;
1132 break;
1133 default:
1134 return AE_ERROR;
1135 }
1136 return wmid3_get_device_status(value, device);
1137}
1138
1139static acpi_status wmid3_set_device_status(u32 value, u16 device)
1140{
1141 struct wmid3_gds_return_value return_value;
1142 acpi_status status;
1143 union acpi_object *obj;
1144 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001145 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001146 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001147 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001148 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001149 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001150 struct acpi_buffer get_input = {
1151 sizeof(struct wmid3_gds_get_input_param),
1152 &get_params
1153 };
1154 struct wmid3_gds_set_input_param set_params = {
1155 .function_num = 0x2,
1156 .hotkey_number = commun_fn_key_number,
1157 .devices = commun_func_bitmap,
1158 };
1159 struct acpi_buffer set_input = {
1160 sizeof(struct wmid3_gds_set_input_param),
1161 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001162 };
1163 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1164 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1165
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001166 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001167 if (ACPI_FAILURE(status))
1168 return status;
1169
1170 obj = output.pointer;
1171
1172 if (!obj)
1173 return AE_ERROR;
1174 else if (obj->type != ACPI_TYPE_BUFFER) {
1175 kfree(obj);
1176 return AE_ERROR;
1177 }
1178 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001179 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001180 kfree(obj);
1181 return AE_ERROR;
1182 }
1183
1184 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1185 kfree(obj);
1186
1187 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001188 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1189 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001190 return_value.ec_return_value);
1191 return status;
1192 }
1193
1194 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001195 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001196
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001197 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001198 if (ACPI_FAILURE(status))
1199 return status;
1200
1201 obj = output2.pointer;
1202
1203 if (!obj)
1204 return AE_ERROR;
1205 else if (obj->type != ACPI_TYPE_BUFFER) {
1206 kfree(obj);
1207 return AE_ERROR;
1208 }
1209 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001210 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001211 kfree(obj);
1212 return AE_ERROR;
1213 }
1214
1215 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1216 kfree(obj);
1217
1218 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001219 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1220 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001221 return_value.ec_return_value);
1222
1223 return status;
1224}
1225
1226static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1227{
1228 u16 device;
1229
1230 switch (cap) {
1231 case ACER_CAP_WIRELESS:
1232 device = ACER_WMID3_GDS_WIRELESS;
1233 break;
1234 case ACER_CAP_BLUETOOTH:
1235 device = ACER_WMID3_GDS_BLUETOOTH;
1236 break;
1237 case ACER_CAP_THREEG:
1238 device = ACER_WMID3_GDS_THREEG;
1239 break;
1240 default:
1241 return AE_ERROR;
1242 }
1243 return wmid3_set_device_status(value, device);
1244}
1245
Mathias Krause76d51dd2014-07-16 19:43:04 +02001246static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001247{
1248 struct hotkey_function_type_aa *type_aa;
1249
1250 /* We are looking for OEM-specific Type AAh */
1251 if (header->type != 0xAA)
1252 return;
1253
1254 has_type_aa = true;
1255 type_aa = (struct hotkey_function_type_aa *) header;
1256
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001257 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001258 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001259 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001260
1261 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1262 interface->capability |= ACER_CAP_WIRELESS;
1263 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1264 interface->capability |= ACER_CAP_THREEG;
1265 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1266 interface->capability |= ACER_CAP_BLUETOOTH;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001267
1268 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001269}
1270
Mathias Krause76d51dd2014-07-16 19:43:04 +02001271static acpi_status __init WMID_set_capabilities(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001272{
1273 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1274 union acpi_object *obj;
1275 acpi_status status;
1276 u32 devices;
1277
1278 status = wmi_query_block(WMID_GUID2, 1, &out);
1279 if (ACPI_FAILURE(status))
1280 return status;
1281
1282 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001283 if (obj) {
1284 if (obj->type == ACPI_TYPE_BUFFER &&
1285 (obj->buffer.length == sizeof(u32) ||
1286 obj->buffer.length == sizeof(u64))) {
1287 devices = *((u32 *) obj->buffer.pointer);
1288 } else if (obj->type == ACPI_TYPE_INTEGER) {
1289 devices = (u32) obj->integer.value;
Lee, Chun-Yif24c96e2013-01-03 10:37:45 +08001290 } else {
1291 kfree(out.pointer);
1292 return AE_ERROR;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001293 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001294 } else {
Axel Lin66904862010-07-20 15:19:52 -07001295 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001296 return AE_ERROR;
1297 }
1298
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001299 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1300 if (devices & 0x07)
1301 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001302 if (devices & 0x40)
1303 interface->capability |= ACER_CAP_THREEG;
1304 if (devices & 0x10)
1305 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001306
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001307 if (!(devices & 0x20))
1308 max_brightness = 0x9;
1309
Axel Lin66904862010-07-20 15:19:52 -07001310 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001311 return status;
1312}
1313
1314static struct wmi_interface wmid_interface = {
1315 .type = ACER_WMID,
1316};
1317
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001318static struct wmi_interface wmid_v2_interface = {
1319 .type = ACER_WMID_v2,
1320};
1321
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001322/*
1323 * Generic Device (interface-independent)
1324 */
1325
1326static acpi_status get_u32(u32 *value, u32 cap)
1327{
Lin Ming08237972008-08-08 11:57:11 +08001328 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001329
1330 switch (interface->type) {
1331 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001332 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001333 break;
1334 case ACER_AMW0_V2:
1335 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001336 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001337 break;
1338 }
1339 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001340 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001341 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001342 case ACER_WMID_v2:
1343 if (cap & (ACER_CAP_WIRELESS |
1344 ACER_CAP_BLUETOOTH |
1345 ACER_CAP_THREEG))
1346 status = wmid_v2_get_u32(value, cap);
1347 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001348 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001349 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001350 }
1351
1352 return status;
1353}
1354
1355static acpi_status set_u32(u32 value, u32 cap)
1356{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001357 acpi_status status;
1358
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001359 if (interface->capability & cap) {
1360 switch (interface->type) {
1361 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001362 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001363 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001364 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001365 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001366
1367 /*
1368 * On some models, some WMID methods don't toggle
1369 * properly. For those cases, we want to run the AMW0
1370 * method afterwards to be certain we've really toggled
1371 * the device state.
1372 */
1373 if (cap == ACER_CAP_WIRELESS ||
1374 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001375 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001376 if (ACPI_FAILURE(status))
1377 return status;
1378
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001379 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001380 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001381 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001382 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001383 case ACER_WMID_v2:
1384 if (cap & (ACER_CAP_WIRELESS |
1385 ACER_CAP_BLUETOOTH |
1386 ACER_CAP_THREEG))
1387 return wmid_v2_set_u32(value, cap);
1388 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001389 return WMID_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001390 default:
1391 return AE_BAD_PARAMETER;
1392 }
1393 }
1394 return AE_BAD_PARAMETER;
1395}
1396
1397static void __init acer_commandline_init(void)
1398{
1399 /*
1400 * These will all fail silently if the value given is invalid, or the
1401 * capability isn't available on the given interface
1402 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001403 if (mailled >= 0)
1404 set_u32(mailled, ACER_CAP_MAILLED);
1405 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001406 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001407 if (brightness >= 0)
1408 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001409}
1410
1411/*
1412 * LED device (Mail LED only, no other LEDs known yet)
1413 */
1414static void mail_led_set(struct led_classdev *led_cdev,
1415enum led_brightness value)
1416{
1417 set_u32(value, ACER_CAP_MAILLED);
1418}
1419
1420static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001421 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001422 .brightness_set = mail_led_set,
1423};
1424
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001425static int acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001426{
1427 return led_classdev_register(dev, &mail_led);
1428}
1429
1430static void acer_led_exit(void)
1431{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001432 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001433 led_classdev_unregister(&mail_led);
1434}
1435
1436/*
1437 * Backlight device
1438 */
1439static struct backlight_device *acer_backlight_device;
1440
1441static int read_brightness(struct backlight_device *bd)
1442{
1443 u32 value;
1444 get_u32(&value, ACER_CAP_BRIGHTNESS);
1445 return value;
1446}
1447
1448static int update_bl_status(struct backlight_device *bd)
1449{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001450 int intensity = bd->props.brightness;
1451
1452 if (bd->props.power != FB_BLANK_UNBLANK)
1453 intensity = 0;
1454 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1455 intensity = 0;
1456
1457 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1458
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001459 return 0;
1460}
1461
Lionel Debrouxacc24722010-11-16 14:14:02 +01001462static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001463 .get_brightness = read_brightness,
1464 .update_status = update_bl_status,
1465};
1466
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001467static int acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001468{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001469 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001470 struct backlight_device *bd;
1471
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001472 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001473 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001474 props.max_brightness = max_brightness;
1475 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1476 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001477 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001478 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001479 acer_backlight_device = NULL;
1480 return PTR_ERR(bd);
1481 }
1482
1483 acer_backlight_device = bd;
1484
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001485 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001486 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001487 backlight_update_status(bd);
1488 return 0;
1489}
1490
Sam Ravnborg7560e382008-02-17 13:22:54 +01001491static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001492{
1493 backlight_device_unregister(acer_backlight_device);
1494}
1495
1496/*
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001497 * Accelerometer device
1498 */
1499static acpi_handle gsensor_handle;
1500
1501static int acer_gsensor_init(void)
1502{
1503 acpi_status status;
1504 struct acpi_buffer output;
1505 union acpi_object out_obj;
1506
1507 output.length = sizeof(out_obj);
1508 output.pointer = &out_obj;
1509 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1510 if (ACPI_FAILURE(status))
1511 return -1;
1512
1513 return 0;
1514}
1515
1516static int acer_gsensor_open(struct input_dev *input)
1517{
1518 return acer_gsensor_init();
1519}
1520
1521static int acer_gsensor_event(void)
1522{
1523 acpi_status status;
1524 struct acpi_buffer output;
1525 union acpi_object out_obj[5];
1526
1527 if (!has_cap(ACER_CAP_ACCEL))
1528 return -1;
1529
1530 output.length = sizeof(out_obj);
1531 output.pointer = out_obj;
1532
1533 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1534 if (ACPI_FAILURE(status))
1535 return -1;
1536
1537 if (out_obj->package.count != 4)
1538 return -1;
1539
1540 input_report_abs(acer_wmi_accel_dev, ABS_X,
1541 (s16)out_obj->package.elements[0].integer.value);
1542 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1543 (s16)out_obj->package.elements[1].integer.value);
1544 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1545 (s16)out_obj->package.elements[2].integer.value);
1546 input_sync(acer_wmi_accel_dev);
1547 return 0;
1548}
1549
1550/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001551 * Rfkill devices
1552 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001553static void acer_rfkill_update(struct work_struct *ignored);
1554static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1555static void acer_rfkill_update(struct work_struct *ignored)
1556{
1557 u32 state;
1558 acpi_status status;
1559
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001560 if (has_cap(ACER_CAP_WIRELESS)) {
1561 status = get_u32(&state, ACER_CAP_WIRELESS);
1562 if (ACPI_SUCCESS(status)) {
1563 if (quirks->wireless == 3)
1564 rfkill_set_hw_state(wireless_rfkill, !state);
1565 else
1566 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001567 }
1568 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001569
1570 if (has_cap(ACER_CAP_BLUETOOTH)) {
1571 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1572 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001573 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001574 }
1575
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001576 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001577 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001578 if (ACPI_SUCCESS(status))
1579 rfkill_set_sw_state(threeg_rfkill, !state);
1580 }
1581
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001582 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001583}
1584
Johannes Berg19d337d2009-06-02 13:01:37 +02001585static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001586{
1587 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001588 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001589
1590 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001591 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001592 if (ACPI_FAILURE(status))
1593 return -ENODEV;
1594 }
1595
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001596 return 0;
1597}
1598
Johannes Berg19d337d2009-06-02 13:01:37 +02001599static const struct rfkill_ops acer_rfkill_ops = {
1600 .set_block = acer_rfkill_set,
1601};
1602
1603static struct rfkill *acer_rfkill_register(struct device *dev,
1604 enum rfkill_type type,
1605 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001606{
1607 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001608 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001609 u32 state;
1610 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001611
Johannes Berg19d337d2009-06-02 13:01:37 +02001612 rfkill_dev = rfkill_alloc(name, dev, type,
1613 &acer_rfkill_ops,
1614 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001615 if (!rfkill_dev)
1616 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001617
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001618 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001619
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001620 err = rfkill_register(rfkill_dev);
1621 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001622 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001623 return ERR_PTR(err);
1624 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001625
1626 if (ACPI_SUCCESS(status))
1627 rfkill_set_sw_state(rfkill_dev, !state);
1628
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001629 return rfkill_dev;
1630}
1631
1632static int acer_rfkill_init(struct device *dev)
1633{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001634 int err;
1635
1636 if (has_cap(ACER_CAP_WIRELESS)) {
1637 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1638 "acer-wireless", ACER_CAP_WIRELESS);
1639 if (IS_ERR(wireless_rfkill)) {
1640 err = PTR_ERR(wireless_rfkill);
1641 goto error_wireless;
1642 }
1643 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001644
1645 if (has_cap(ACER_CAP_BLUETOOTH)) {
1646 bluetooth_rfkill = acer_rfkill_register(dev,
1647 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1648 ACER_CAP_BLUETOOTH);
1649 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001650 err = PTR_ERR(bluetooth_rfkill);
1651 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001652 }
1653 }
1654
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001655 if (has_cap(ACER_CAP_THREEG)) {
1656 threeg_rfkill = acer_rfkill_register(dev,
1657 RFKILL_TYPE_WWAN, "acer-threeg",
1658 ACER_CAP_THREEG);
1659 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001660 err = PTR_ERR(threeg_rfkill);
1661 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001662 }
1663 }
1664
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001665 rfkill_inited = true;
1666
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001667 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1668 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001669 schedule_delayed_work(&acer_rfkill_work,
1670 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001671
1672 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001673
1674error_threeg:
1675 if (has_cap(ACER_CAP_BLUETOOTH)) {
1676 rfkill_unregister(bluetooth_rfkill);
1677 rfkill_destroy(bluetooth_rfkill);
1678 }
1679error_bluetooth:
1680 if (has_cap(ACER_CAP_WIRELESS)) {
1681 rfkill_unregister(wireless_rfkill);
1682 rfkill_destroy(wireless_rfkill);
1683 }
1684error_wireless:
1685 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001686}
1687
1688static void acer_rfkill_exit(void)
1689{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001690 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1691 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001692 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001693
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001694 if (has_cap(ACER_CAP_WIRELESS)) {
1695 rfkill_unregister(wireless_rfkill);
1696 rfkill_destroy(wireless_rfkill);
1697 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001698
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001699 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001700 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001701 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001702 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001703
1704 if (has_cap(ACER_CAP_THREEG)) {
1705 rfkill_unregister(threeg_rfkill);
1706 rfkill_destroy(threeg_rfkill);
1707 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001708 return;
1709}
1710
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001711static void acer_wmi_notify(u32 value, void *context)
1712{
1713 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1714 union acpi_object *obj;
1715 struct event_return_value return_value;
1716 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001717 u16 device_state;
1718 const struct key_entry *key;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001719 u32 scancode;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001720
1721 status = wmi_get_event_data(value, &response);
1722 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001723 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001724 return;
1725 }
1726
1727 obj = (union acpi_object *)response.pointer;
1728
1729 if (!obj)
1730 return;
1731 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001732 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001733 kfree(obj);
1734 return;
1735 }
1736 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001737 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001738 kfree(obj);
1739 return;
1740 }
1741
1742 return_value = *((struct event_return_value *)obj->buffer.pointer);
1743 kfree(obj);
1744
1745 switch (return_value.function) {
1746 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001747 device_state = return_value.device_state;
1748 pr_debug("device state: 0x%x\n", device_state);
1749
1750 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1751 return_value.key_num);
1752 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001753 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001754 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001755 } else {
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001756 scancode = return_value.key_num;
Seth Forshee92530662011-06-21 12:00:33 -05001757 switch (key->keycode) {
1758 case KEY_WLAN:
1759 case KEY_BLUETOOTH:
1760 if (has_cap(ACER_CAP_WIRELESS))
1761 rfkill_set_sw_state(wireless_rfkill,
1762 !(device_state & ACER_WMID3_GDS_WIRELESS));
1763 if (has_cap(ACER_CAP_THREEG))
1764 rfkill_set_sw_state(threeg_rfkill,
1765 !(device_state & ACER_WMID3_GDS_THREEG));
1766 if (has_cap(ACER_CAP_BLUETOOTH))
1767 rfkill_set_sw_state(bluetooth_rfkill,
1768 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1769 break;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001770 case KEY_TOUCHPAD_TOGGLE:
1771 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1772 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
Seth Forshee92530662011-06-21 12:00:33 -05001773 }
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001774 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
Seth Forshee92530662011-06-21 12:00:33 -05001775 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001776 break;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001777 case WMID_ACCEL_EVENT:
1778 acer_gsensor_event();
1779 break;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001780 default:
Joe Perches249c7202011-03-29 15:21:34 -07001781 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001782 return_value.function, return_value.key_num);
1783 break;
1784 }
1785}
1786
Mathias Krause76d51dd2014-07-16 19:43:04 +02001787static acpi_status __init
Chris Chiu280642c2017-02-08 07:51:40 -06001788wmid3_set_function_mode(struct func_input_params *params,
1789 struct func_return_value *return_value)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001790{
1791 acpi_status status;
1792 union acpi_object *obj;
1793
Chris Chiu280642c2017-02-08 07:51:40 -06001794 struct acpi_buffer input = { sizeof(struct func_input_params), params };
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001795 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1796
1797 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1798 if (ACPI_FAILURE(status))
1799 return status;
1800
1801 obj = output.pointer;
1802
1803 if (!obj)
1804 return AE_ERROR;
1805 else if (obj->type != ACPI_TYPE_BUFFER) {
1806 kfree(obj);
1807 return AE_ERROR;
1808 }
1809 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001810 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001811 kfree(obj);
1812 return AE_ERROR;
1813 }
1814
Chris Chiu280642c2017-02-08 07:51:40 -06001815 *return_value = *((struct func_return_value *)obj->buffer.pointer);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001816 kfree(obj);
1817
1818 return status;
1819}
1820
Mathias Krause76d51dd2014-07-16 19:43:04 +02001821static int __init acer_wmi_enable_ec_raw(void)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001822{
Chris Chiu280642c2017-02-08 07:51:40 -06001823 struct func_return_value return_value;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001824 acpi_status status;
Chris Chiu280642c2017-02-08 07:51:40 -06001825 struct func_input_params params = {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001826 .function_num = 0x1,
1827 .commun_devices = 0xFFFF,
1828 .devices = 0xFFFF,
Chris Chiu280642c2017-02-08 07:51:40 -06001829 .app_status = 0x00, /* Launch Manager Deactive */
1830 .app_mask = 0x01,
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001831 };
1832
Chris Chiu280642c2017-02-08 07:51:40 -06001833 status = wmid3_set_function_mode(&params, &return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001834
1835 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001836 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1837 return_value.error_code,
1838 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001839 else
Joe Perches249c7202011-03-29 15:21:34 -07001840 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001841
1842 return status;
1843}
1844
Mathias Krause76d51dd2014-07-16 19:43:04 +02001845static int __init acer_wmi_enable_lm(void)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001846{
Chris Chiu280642c2017-02-08 07:51:40 -06001847 struct func_return_value return_value;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001848 acpi_status status;
Chris Chiu280642c2017-02-08 07:51:40 -06001849 struct func_input_params params = {
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001850 .function_num = 0x1,
1851 .commun_devices = 0xFFFF,
1852 .devices = 0xFFFF,
Chris Chiu280642c2017-02-08 07:51:40 -06001853 .app_status = 0x01, /* Launch Manager Active */
1854 .app_mask = 0x01,
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001855 };
1856
Chris Chiu280642c2017-02-08 07:51:40 -06001857 status = wmid3_set_function_mode(&params, &return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001858
1859 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001860 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1861 return_value.error_code,
1862 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001863
1864 return status;
1865}
1866
Chris Chiu280642c2017-02-08 07:51:40 -06001867static int __init acer_wmi_enable_rf_button(void)
1868{
1869 struct func_return_value return_value;
1870 acpi_status status;
1871 struct func_input_params params = {
1872 .function_num = 0x1,
1873 .commun_devices = 0xFFFF,
1874 .devices = 0xFFFF,
1875 .app_status = 0x10, /* RF Button Active */
1876 .app_mask = 0x10,
1877 };
1878
1879 status = wmid3_set_function_mode(&params, &return_value);
1880
1881 if (return_value.error_code || return_value.ec_return_value)
1882 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1883 return_value.error_code,
1884 return_value.ec_return_value);
1885
1886 return status;
1887}
1888
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08001889#define ACER_WMID_ACCEL_HID "BST0001"
1890
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001891static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1892 void *ctx, void **retval)
1893{
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08001894 struct acpi_device *dev;
1895
1896 if (!strcmp(ctx, "SENR")) {
1897 if (acpi_bus_get_device(ah, &dev))
1898 return AE_OK;
Lee, Chun-Yif9ac89f2017-04-28 16:23:59 +08001899 if (strcmp(ACER_WMID_ACCEL_HID, acpi_device_hid(dev)))
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08001900 return AE_OK;
1901 } else
1902 return AE_OK;
1903
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001904 *(acpi_handle *)retval = ah;
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08001905
1906 return AE_CTRL_TERMINATE;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001907}
1908
1909static int __init acer_wmi_get_handle(const char *name, const char *prop,
1910 acpi_handle *ah)
1911{
1912 acpi_status status;
1913 acpi_handle handle;
1914
1915 BUG_ON(!name || !ah);
1916
Marek Vasut24237c42012-07-05 01:30:09 +02001917 handle = NULL;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001918 status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1919 (void *)name, &handle);
Lee, Chun-Yif9ac89f2017-04-28 16:23:59 +08001920 if (ACPI_SUCCESS(status) && handle) {
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001921 *ah = handle;
1922 return 0;
1923 } else {
1924 return -ENODEV;
1925 }
1926}
1927
1928static int __init acer_wmi_accel_setup(void)
1929{
1930 int err;
1931
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08001932 err = acer_wmi_get_handle("SENR", ACER_WMID_ACCEL_HID, &gsensor_handle);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001933 if (err)
1934 return err;
1935
1936 interface->capability |= ACER_CAP_ACCEL;
1937
1938 acer_wmi_accel_dev = input_allocate_device();
1939 if (!acer_wmi_accel_dev)
1940 return -ENOMEM;
1941
1942 acer_wmi_accel_dev->open = acer_gsensor_open;
1943
1944 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1945 acer_wmi_accel_dev->phys = "wmi/input1";
1946 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1947 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1948 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1949 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1950 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1951
1952 err = input_register_device(acer_wmi_accel_dev);
1953 if (err)
1954 goto err_free_dev;
1955
1956 return 0;
1957
1958err_free_dev:
1959 input_free_device(acer_wmi_accel_dev);
1960 return err;
1961}
1962
1963static void acer_wmi_accel_destroy(void)
1964{
1965 input_unregister_device(acer_wmi_accel_dev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001966}
1967
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001968static int __init acer_wmi_input_setup(void)
1969{
1970 acpi_status status;
1971 int err;
1972
1973 acer_wmi_input_dev = input_allocate_device();
1974 if (!acer_wmi_input_dev)
1975 return -ENOMEM;
1976
1977 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1978 acer_wmi_input_dev->phys = "wmi/input0";
1979 acer_wmi_input_dev->id.bustype = BUS_HOST;
1980
1981 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1982 if (err)
1983 goto err_free_dev;
1984
1985 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1986 acer_wmi_notify, NULL);
1987 if (ACPI_FAILURE(status)) {
1988 err = -EIO;
Michał Kępieńcd1aaef2017-03-09 13:11:37 +01001989 goto err_free_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001990 }
1991
1992 err = input_register_device(acer_wmi_input_dev);
1993 if (err)
1994 goto err_uninstall_notifier;
1995
1996 return 0;
1997
1998err_uninstall_notifier:
1999 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002000err_free_dev:
2001 input_free_device(acer_wmi_input_dev);
2002 return err;
2003}
2004
2005static void acer_wmi_input_destroy(void)
2006{
2007 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002008 input_unregister_device(acer_wmi_input_dev);
2009}
2010
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002011/*
Carlos Corbacho81143522008-06-21 09:09:53 +01002012 * debugfs functions
2013 */
2014static u32 get_wmid_devices(void)
2015{
2016 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
2017 union acpi_object *obj;
2018 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07002019 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01002020
2021 status = wmi_query_block(WMID_GUID2, 1, &out);
2022 if (ACPI_FAILURE(status))
2023 return 0;
2024
2025 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08002026 if (obj) {
2027 if (obj->type == ACPI_TYPE_BUFFER &&
2028 (obj->buffer.length == sizeof(u32) ||
2029 obj->buffer.length == sizeof(u64))) {
2030 devices = *((u32 *) obj->buffer.pointer);
2031 } else if (obj->type == ACPI_TYPE_INTEGER) {
2032 devices = (u32) obj->integer.value;
2033 }
Carlos Corbacho81143522008-06-21 09:09:53 +01002034 }
Axel Lin66904862010-07-20 15:19:52 -07002035
2036 kfree(out.pointer);
2037 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01002038}
2039
2040/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002041 * Platform device
2042 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002043static int acer_platform_probe(struct platform_device *device)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002044{
2045 int err;
2046
2047 if (has_cap(ACER_CAP_MAILLED)) {
2048 err = acer_led_init(&device->dev);
2049 if (err)
2050 goto error_mailled;
2051 }
2052
2053 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2054 err = acer_backlight_init(&device->dev);
2055 if (err)
2056 goto error_brightness;
2057 }
2058
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002059 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01002060 if (err)
2061 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002062
2063 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002064
Andy Whitcroft350e3292009-04-04 09:33:34 +01002065error_rfkill:
2066 if (has_cap(ACER_CAP_BRIGHTNESS))
2067 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002068error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01002069 if (has_cap(ACER_CAP_MAILLED))
2070 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002071error_mailled:
2072 return err;
2073}
2074
2075static int acer_platform_remove(struct platform_device *device)
2076{
2077 if (has_cap(ACER_CAP_MAILLED))
2078 acer_led_exit();
2079 if (has_cap(ACER_CAP_BRIGHTNESS))
2080 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002081
2082 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002083 return 0;
2084}
2085
Mathias Krause80f65552014-07-16 19:43:06 +02002086#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002087static int acer_suspend(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002088{
2089 u32 value;
2090 struct acer_data *data = &interface->data;
2091
2092 if (!data)
2093 return -ENOMEM;
2094
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002095 if (has_cap(ACER_CAP_MAILLED)) {
2096 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002097 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002098 data->mailled = value;
2099 }
2100
2101 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2102 get_u32(&value, ACER_CAP_BRIGHTNESS);
2103 data->brightness = value;
2104 }
2105
2106 return 0;
2107}
2108
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002109static int acer_resume(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002110{
2111 struct acer_data *data = &interface->data;
2112
2113 if (!data)
2114 return -ENOMEM;
2115
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002116 if (has_cap(ACER_CAP_MAILLED))
2117 set_u32(data->mailled, ACER_CAP_MAILLED);
2118
2119 if (has_cap(ACER_CAP_BRIGHTNESS))
2120 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2121
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002122 if (has_cap(ACER_CAP_ACCEL))
2123 acer_gsensor_init();
2124
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002125 return 0;
2126}
Mathias Krause80f65552014-07-16 19:43:06 +02002127#else
2128#define acer_suspend NULL
2129#define acer_resume NULL
2130#endif
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002131
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002132static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2133
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002134static void acer_platform_shutdown(struct platform_device *device)
2135{
2136 struct acer_data *data = &interface->data;
2137
2138 if (!data)
2139 return;
2140
2141 if (has_cap(ACER_CAP_MAILLED))
2142 set_u32(LED_OFF, ACER_CAP_MAILLED);
2143}
2144
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002145static struct platform_driver acer_platform_driver = {
2146 .driver = {
2147 .name = "acer-wmi",
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002148 .pm = &acer_pm,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002149 },
2150 .probe = acer_platform_probe,
2151 .remove = acer_platform_remove,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002152 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002153};
2154
2155static struct platform_device *acer_platform_device;
2156
Carlos Corbacho81143522008-06-21 09:09:53 +01002157static void remove_debugfs(void)
2158{
2159 debugfs_remove(interface->debug.devices);
2160 debugfs_remove(interface->debug.root);
2161}
2162
Mathias Krause76d51dd2014-07-16 19:43:04 +02002163static int __init create_debugfs(void)
Carlos Corbacho81143522008-06-21 09:09:53 +01002164{
2165 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2166 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002167 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01002168 return -ENOMEM;
2169 }
2170
2171 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2172 interface->debug.root,
2173 &interface->debug.wmid_devices);
2174 if (!interface->debug.devices)
2175 goto error_debugfs;
2176
2177 return 0;
2178
2179error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07002180 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01002181 return -ENOMEM;
2182}
2183
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002184static int __init acer_wmi_init(void)
2185{
2186 int err;
2187
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002188 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002189
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002190 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002191 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002192 return -ENODEV;
2193 }
2194
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01002195 find_quirks();
2196
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002197 /*
Lee, Chun-Yi5241b192016-11-01 12:30:58 +08002198 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2199 * machines like Lenovo, Fujitsu and Medion. In the past days,
2200 * acer-wmi driver handled those non-Acer machines by quirks list.
2201 * But actually acer-wmi driver was loaded on any machines that have
2202 * AMW0_GUID1. This behavior is strange because those machines should
2203 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2204 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2205 * should be in Acer/Gateway/Packard Bell white list, or it's already
2206 * in the past quirk list.
2207 */
2208 if (wmi_has_guid(AMW0_GUID1) &&
2209 !dmi_check_system(amw0_whitelist) &&
2210 quirks == &quirk_unknown) {
2211 pr_err("Unsupported machine has AMW0_GUID1, unable to load\n");
2212 return -ENODEV;
2213 }
2214
2215 /*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002216 * Detect which ACPI-WMI interface we're using.
2217 */
2218 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2219 interface = &AMW0_V2_interface;
2220
2221 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2222 interface = &wmid_interface;
2223
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002224 if (wmi_has_guid(WMID_GUID3))
2225 interface = &wmid_v2_interface;
2226
2227 if (interface)
2228 dmi_walk(type_aa_dmi_decode, NULL);
2229
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002230 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002231 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002232 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002233 return -ENODEV;
2234 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002235 /* WMID always provides brightness methods */
2236 interface->capability |= ACER_CAP_BRIGHTNESS;
2237 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002238 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002239 return -ENODEV;
2240 }
2241
2242 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2243 interface = &AMW0_interface;
2244
2245 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002246 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002247 return -ENODEV;
2248 }
2249 }
2250
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002251 if (wmi_has_guid(AMW0_GUID1))
2252 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002253
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002254 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002255 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002256 return -ENODEV;
2257 }
2258
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002259 set_quirks();
2260
Corentin Charya60b2172012-06-13 09:32:02 +02002261 if (dmi_check_system(video_vendor_dmi_table))
Hans de Goede9a65f0d2015-06-16 16:27:55 +02002262 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2263
2264 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Corentin Charya60b2172012-06-13 09:32:02 +02002265 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002266
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002267 if (wmi_has_guid(WMID_GUID3)) {
Chris Chiu280642c2017-02-08 07:51:40 -06002268 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2269 pr_warn("Cannot enable RF Button Driver\n");
2270
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002271 if (ec_raw_mode) {
2272 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002273 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002274 return -ENODEV;
2275 }
2276 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002277 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002278 return -ENODEV;
2279 }
2280 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002281 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002282 }
2283
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002284 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2285 err = acer_wmi_input_setup();
2286 if (err)
2287 return err;
Lee, Chun-Yi98d610c2016-11-03 08:18:52 +08002288 err = acer_wmi_accel_setup();
Lee, Chun-Yif9ac89f2017-04-28 16:23:59 +08002289 if (err && err != -ENODEV)
2290 pr_warn("Cannot enable accelerometer\n");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002291 }
2292
Axel Lin1c796322010-06-22 16:17:38 +08002293 err = platform_driver_register(&acer_platform_driver);
2294 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002295 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002296 goto error_platform_register;
2297 }
Axel Lin1c796322010-06-22 16:17:38 +08002298
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002299 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002300 if (!acer_platform_device) {
2301 err = -ENOMEM;
2302 goto error_device_alloc;
2303 }
2304
2305 err = platform_device_add(acer_platform_device);
2306 if (err)
2307 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002308
Carlos Corbacho81143522008-06-21 09:09:53 +01002309 if (wmi_has_guid(WMID_GUID2)) {
2310 interface->debug.wmid_devices = get_wmid_devices();
2311 err = create_debugfs();
2312 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002313 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002314 }
2315
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002316 /* Override any initial settings with values from the commandline */
2317 acer_commandline_init();
2318
2319 return 0;
2320
Axel Lin1c796322010-06-22 16:17:38 +08002321error_create_debugfs:
Axel Lin1c796322010-06-22 16:17:38 +08002322 platform_device_del(acer_platform_device);
2323error_device_add:
2324 platform_device_put(acer_platform_device);
2325error_device_alloc:
2326 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002327error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002328 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2329 acer_wmi_input_destroy();
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002330 if (has_cap(ACER_CAP_ACCEL))
2331 acer_wmi_accel_destroy();
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002332
Axel Lin1c796322010-06-22 16:17:38 +08002333 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002334}
2335
2336static void __exit acer_wmi_exit(void)
2337{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002338 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2339 acer_wmi_input_destroy();
2340
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002341 if (has_cap(ACER_CAP_ACCEL))
2342 acer_wmi_accel_destroy();
2343
Russ Dill39dbbb42008-09-02 14:35:40 -07002344 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002345 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002346 platform_driver_unregister(&acer_platform_driver);
2347
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002348 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002349 return;
2350}
2351
2352module_init(acer_wmi_init);
2353module_exit(acer_wmi_exit);