blob: 79d64ea00bfb7e17fa908020e62c029dd01ff483 [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} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800131 {KE_END, 0}
132};
133
134static struct input_dev *acer_wmi_input_dev;
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200135static struct input_dev *acer_wmi_accel_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800136
137struct event_return_value {
138 u8 function;
139 u8 key_num;
140 u16 device_state;
141 u32 reserved;
142} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000143
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000144/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800145 * GUID3 Get Device Status device flags
146 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800147#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800148#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800149#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800150#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800151#define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800152
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500153struct lm_input_params {
154 u8 function_num; /* Function Number */
155 u16 commun_devices; /* Communication type devices default status */
156 u16 devices; /* Other type devices default status */
157 u8 lm_status; /* Launch Manager Status */
158 u16 reserved;
159} __attribute__((packed));
160
161struct lm_return_value {
162 u8 error_code; /* Error Code */
163 u8 ec_return_value; /* EC Return Value */
164 u16 reserved;
165} __attribute__((packed));
166
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800167struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
168 u8 function_num; /* Function Number */
169 u8 hotkey_number; /* Hotkey Number */
170 u16 devices; /* Set Device */
171 u8 volume_value; /* Volume Value */
172} __attribute__((packed));
173
174struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800175 u8 function_num; /* Function Number */
176 u8 hotkey_number; /* Hotkey Number */
177 u16 devices; /* Get Device */
178} __attribute__((packed));
179
180struct wmid3_gds_return_value { /* Get Device Status return value*/
181 u8 error_code; /* Error Code */
182 u8 ec_return_value; /* EC Return Value */
183 u16 devices; /* Current Device Status */
184 u32 reserved;
185} __attribute__((packed));
186
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800187struct hotkey_function_type_aa {
188 u8 type;
189 u8 length;
190 u16 handle;
191 u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800192 u16 application_func_bitmap;
193 u16 media_func_bitmap;
194 u16 display_func_bitmap;
195 u16 others_func_bitmap;
196 u8 commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800197} __attribute__((packed));
198
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800199/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000200 * Interface capability flags
201 */
202#define ACER_CAP_MAILLED (1<<0)
203#define ACER_CAP_WIRELESS (1<<1)
204#define ACER_CAP_BLUETOOTH (1<<2)
205#define ACER_CAP_BRIGHTNESS (1<<3)
206#define ACER_CAP_THREEG (1<<4)
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200207#define ACER_CAP_ACCEL (1<<5)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000208#define ACER_CAP_ANY (0xFFFFFFFF)
209
210/*
211 * Interface type flags
212 */
213enum interface_flags {
214 ACER_AMW0,
215 ACER_AMW0_V2,
216 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800217 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000218};
219
220#define ACER_DEFAULT_WIRELESS 0
221#define ACER_DEFAULT_BLUETOOTH 0
222#define ACER_DEFAULT_MAILLED 0
223#define ACER_DEFAULT_THREEG 0
224
225static int max_brightness = 0xF;
226
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000227static int mailled = -1;
228static int brightness = -1;
229static int threeg = -1;
230static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500231static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800232static bool has_type_aa;
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +0800233static u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800234static u8 commun_fn_key_number;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000235
236module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000237module_param(brightness, int, 0444);
238module_param(threeg, int, 0444);
239module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500240module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000241MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
242MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
243MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
244MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500245MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000246
247struct acer_data {
248 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000249 int threeg;
250 int brightness;
251};
252
Carlos Corbacho81143522008-06-21 09:09:53 +0100253struct acer_debug {
254 struct dentry *root;
255 struct dentry *devices;
256 u32 wmid_devices;
257};
258
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100259static struct rfkill *wireless_rfkill;
260static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800261static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800262static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100263
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000264/* Each low-level interface must define at least some of the following */
265struct wmi_interface {
266 /* The WMI device type */
267 u32 type;
268
269 /* The capabilities this interface provides */
270 u32 capability;
271
272 /* Private data for the current interface */
273 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100274
275 /* debugfs entries associated with this interface */
276 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000277};
278
279/* The static interface pointer, points to the currently detected interface */
280static struct wmi_interface *interface;
281
282/*
283 * Embedded Controller quirks
284 * Some laptops require us to directly access the EC to either enable or query
285 * features that are not available through WMI.
286 */
287
288struct quirk_entry {
289 u8 wireless;
290 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100291 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000292 u8 bluetooth;
293};
294
295static struct quirk_entry *quirks;
296
Mathias Krause76d51dd2014-07-16 19:43:04 +0200297static void __init set_quirks(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000298{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700299 if (!interface)
300 return;
301
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000302 if (quirks->mailled)
303 interface->capability |= ACER_CAP_MAILLED;
304
305 if (quirks->brightness)
306 interface->capability |= ACER_CAP_BRIGHTNESS;
307}
308
Mathias Krause76d51dd2014-07-16 19:43:04 +0200309static int __init dmi_matched(const struct dmi_system_id *dmi)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000310{
311 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800312 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000313}
314
315static struct quirk_entry quirk_unknown = {
316};
317
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100318static struct quirk_entry quirk_acer_aspire_1520 = {
319 .brightness = -1,
320};
321
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000322static struct quirk_entry quirk_acer_travelmate_2490 = {
323 .mailled = 1,
324};
325
326/* This AMW0 laptop has no bluetooth */
327static struct quirk_entry quirk_medion_md_98300 = {
328 .wireless = 1,
329};
330
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100331static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
332 .wireless = 2,
333};
334
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800335static struct quirk_entry quirk_lenovo_ideapad_s205 = {
336 .wireless = 3,
337};
338
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100339/* The Aspire One has a dummy ACPI-WMI interface - disable it */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200340static const struct dmi_system_id acer_blacklist[] __initconst = {
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100341 {
342 .ident = "Acer Aspire One (SSD)",
343 .matches = {
344 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
345 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
346 },
347 },
348 {
349 .ident = "Acer Aspire One (HDD)",
350 .matches = {
351 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
352 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
353 },
354 },
355 {}
356};
357
Mathias Krause76d51dd2014-07-16 19:43:04 +0200358static const struct dmi_system_id acer_quirks[] __initconst = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000359 {
360 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100361 .ident = "Acer Aspire 1360",
362 .matches = {
363 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
364 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
365 },
366 .driver_data = &quirk_acer_aspire_1520,
367 },
368 {
369 .callback = dmi_matched,
370 .ident = "Acer Aspire 1520",
371 .matches = {
372 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
373 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
374 },
375 .driver_data = &quirk_acer_aspire_1520,
376 },
377 {
378 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000379 .ident = "Acer Aspire 3100",
380 .matches = {
381 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
382 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
383 },
384 .driver_data = &quirk_acer_travelmate_2490,
385 },
386 {
387 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000388 .ident = "Acer Aspire 3610",
389 .matches = {
390 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
391 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
392 },
393 .driver_data = &quirk_acer_travelmate_2490,
394 },
395 {
396 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000397 .ident = "Acer Aspire 5100",
398 .matches = {
399 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
400 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
401 },
402 .driver_data = &quirk_acer_travelmate_2490,
403 },
404 {
405 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000406 .ident = "Acer Aspire 5610",
407 .matches = {
408 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
409 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
410 },
411 .driver_data = &quirk_acer_travelmate_2490,
412 },
413 {
414 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000415 .ident = "Acer Aspire 5630",
416 .matches = {
417 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
419 },
420 .driver_data = &quirk_acer_travelmate_2490,
421 },
422 {
423 .callback = dmi_matched,
424 .ident = "Acer Aspire 5650",
425 .matches = {
426 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
427 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
428 },
429 .driver_data = &quirk_acer_travelmate_2490,
430 },
431 {
432 .callback = dmi_matched,
433 .ident = "Acer Aspire 5680",
434 .matches = {
435 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
436 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
437 },
438 .driver_data = &quirk_acer_travelmate_2490,
439 },
440 {
441 .callback = dmi_matched,
442 .ident = "Acer Aspire 9110",
443 .matches = {
444 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
445 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
446 },
447 .driver_data = &quirk_acer_travelmate_2490,
448 },
449 {
450 .callback = dmi_matched,
451 .ident = "Acer TravelMate 2490",
452 .matches = {
453 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
454 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
455 },
456 .driver_data = &quirk_acer_travelmate_2490,
457 },
458 {
459 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000460 .ident = "Acer TravelMate 4200",
461 .matches = {
462 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
463 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
464 },
465 .driver_data = &quirk_acer_travelmate_2490,
466 },
467 {
468 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100469 .ident = "Fujitsu Siemens Amilo Li 1718",
470 .matches = {
471 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
472 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
473 },
474 .driver_data = &quirk_fujitsu_amilo_li_1718,
475 },
476 {
477 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000478 .ident = "Medion MD 98300",
479 .matches = {
480 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
481 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
482 },
483 .driver_data = &quirk_medion_md_98300,
484 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800485 {
486 .callback = dmi_matched,
487 .ident = "Lenovo Ideapad S205",
488 .matches = {
489 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
490 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
491 },
492 .driver_data = &quirk_lenovo_ideapad_s205,
493 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500494 {
495 .callback = dmi_matched,
Lee, Chun-Yic08f2082012-03-20 11:32:49 +0800496 .ident = "Lenovo Ideapad S205 (Brazos)",
497 .matches = {
498 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
499 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
500 },
501 .driver_data = &quirk_lenovo_ideapad_s205,
502 },
503 {
504 .callback = dmi_matched,
Seth Forsheebe3128b2011-10-06 15:01:55 -0500505 .ident = "Lenovo 3000 N200",
506 .matches = {
507 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
508 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
509 },
510 .driver_data = &quirk_fujitsu_amilo_li_1718,
511 },
Lee, Chun-Yie6c33f12012-12-14 16:14:25 +0800512 {
513 .callback = dmi_matched,
514 .ident = "Lenovo Ideapad S205-10382JG",
515 .matches = {
516 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
517 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
518 },
519 .driver_data = &quirk_lenovo_ideapad_s205,
520 },
Lee, Chun-Yi5f3511d2012-12-14 16:14:28 +0800521 {
522 .callback = dmi_matched,
523 .ident = "Lenovo Ideapad S205-1038DPG",
524 .matches = {
525 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
526 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
527 },
528 .driver_data = &quirk_lenovo_ideapad_s205,
529 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000530 {}
531};
532
Mathias Krause76d51dd2014-07-16 19:43:04 +0200533static int __init
534video_set_backlight_video_vendor(const struct dmi_system_id *d)
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400535{
536 interface->capability &= ~ACER_CAP_BRIGHTNESS;
537 pr_info("Brightness must be controlled by generic video driver\n");
538 return 0;
539}
540
Mathias Krause76d51dd2014-07-16 19:43:04 +0200541static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400542 {
543 .callback = video_set_backlight_video_vendor,
544 .ident = "Acer TravelMate 4750",
545 .matches = {
546 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
547 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
548 },
549 },
Lee, Chun-Yi050eff32012-05-21 23:19:51 +0800550 {
551 .callback = video_set_backlight_video_vendor,
552 .ident = "Acer Extensa 5235",
553 .matches = {
554 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
555 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
556 },
557 },
558 {
559 .callback = video_set_backlight_video_vendor,
560 .ident = "Acer TravelMate 5760",
561 .matches = {
562 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
563 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
564 },
565 },
566 {
567 .callback = video_set_backlight_video_vendor,
568 .ident = "Acer Aspire 5750",
569 .matches = {
570 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
571 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
572 },
573 },
Hans de Goede9404cd952014-05-17 10:48:03 +0200574 {
575 .callback = video_set_backlight_video_vendor,
576 .ident = "Acer Aspire 5741",
577 .matches = {
578 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
579 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
580 },
581 },
Hans de Goede183fd8f2014-10-22 16:06:38 +0200582 {
583 /*
584 * Note no video_set_backlight_video_vendor, we must use the
585 * acer interface, as there is no native backlight interface.
586 */
587 .ident = "Acer KAV80",
588 .matches = {
589 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
590 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
591 },
592 },
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400593 {}
594};
595
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000596/* Find which quirks are needed for a particular vendor/ model pair */
Mathias Krause76d51dd2014-07-16 19:43:04 +0200597static void __init find_quirks(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000598{
599 if (!force_series) {
600 dmi_check_system(acer_quirks);
601 } else if (force_series == 2490) {
602 quirks = &quirk_acer_travelmate_2490;
603 }
604
605 if (quirks == NULL)
606 quirks = &quirk_unknown;
607
608 set_quirks();
609}
610
611/*
612 * General interface convenience methods
613 */
614
615static bool has_cap(u32 cap)
616{
617 if ((interface->capability & cap) != 0)
618 return 1;
619
620 return 0;
621}
622
623/*
624 * AMW0 (V1) interface
625 */
626struct wmab_args {
627 u32 eax;
628 u32 ebx;
629 u32 ecx;
630 u32 edx;
631};
632
633struct wmab_ret {
634 u32 eax;
635 u32 ebx;
636 u32 ecx;
637 u32 edx;
638 u32 eex;
639};
640
641static acpi_status wmab_execute(struct wmab_args *regbuf,
642struct acpi_buffer *result)
643{
644 struct acpi_buffer input;
645 acpi_status status;
646 input.length = sizeof(struct wmab_args);
647 input.pointer = (u8 *)regbuf;
648
649 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
650
651 return status;
652}
653
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800654static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000655{
656 int err;
657 u8 result;
658
659 switch (cap) {
660 case ACER_CAP_MAILLED:
661 switch (quirks->mailled) {
662 default:
663 err = ec_read(0xA, &result);
664 if (err)
665 return AE_ERROR;
666 *value = (result >> 7) & 0x1;
667 return AE_OK;
668 }
669 break;
670 case ACER_CAP_WIRELESS:
671 switch (quirks->wireless) {
672 case 1:
673 err = ec_read(0x7B, &result);
674 if (err)
675 return AE_ERROR;
676 *value = result & 0x1;
677 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100678 case 2:
679 err = ec_read(0x71, &result);
680 if (err)
681 return AE_ERROR;
682 *value = result & 0x1;
683 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800684 case 3:
685 err = ec_read(0x78, &result);
686 if (err)
687 return AE_ERROR;
688 *value = result & 0x1;
689 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000690 default:
691 err = ec_read(0xA, &result);
692 if (err)
693 return AE_ERROR;
694 *value = (result >> 2) & 0x1;
695 return AE_OK;
696 }
697 break;
698 case ACER_CAP_BLUETOOTH:
699 switch (quirks->bluetooth) {
700 default:
701 err = ec_read(0xA, &result);
702 if (err)
703 return AE_ERROR;
704 *value = (result >> 4) & 0x1;
705 return AE_OK;
706 }
707 break;
708 case ACER_CAP_BRIGHTNESS:
709 switch (quirks->brightness) {
710 default:
711 err = ec_read(0x83, &result);
712 if (err)
713 return AE_ERROR;
714 *value = result;
715 return AE_OK;
716 }
717 break;
718 default:
Lin Ming08237972008-08-08 11:57:11 +0800719 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000720 }
721 return AE_OK;
722}
723
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800724static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000725{
726 struct wmab_args args;
727
728 args.eax = ACER_AMW0_WRITE;
729 args.ebx = value ? (1<<8) : 0;
730 args.ecx = args.edx = 0;
731
732 switch (cap) {
733 case ACER_CAP_MAILLED:
734 if (value > 1)
735 return AE_BAD_PARAMETER;
736 args.ebx |= ACER_AMW0_MAILLED_MASK;
737 break;
738 case ACER_CAP_WIRELESS:
739 if (value > 1)
740 return AE_BAD_PARAMETER;
741 args.ebx |= ACER_AMW0_WIRELESS_MASK;
742 break;
743 case ACER_CAP_BLUETOOTH:
744 if (value > 1)
745 return AE_BAD_PARAMETER;
746 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
747 break;
748 case ACER_CAP_BRIGHTNESS:
749 if (value > max_brightness)
750 return AE_BAD_PARAMETER;
751 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000752 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000753 return ec_write(0x83, value);
754 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000755 }
756 default:
Lin Ming08237972008-08-08 11:57:11 +0800757 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000758 }
759
760 /* Actually do the set */
761 return wmab_execute(&args, NULL);
762}
763
Mathias Krause76d51dd2014-07-16 19:43:04 +0200764static acpi_status __init AMW0_find_mailled(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000765{
766 struct wmab_args args;
767 struct wmab_ret ret;
768 acpi_status status = AE_OK;
769 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
770 union acpi_object *obj;
771
772 args.eax = 0x86;
773 args.ebx = args.ecx = args.edx = 0;
774
775 status = wmab_execute(&args, &out);
776 if (ACPI_FAILURE(status))
777 return status;
778
779 obj = (union acpi_object *) out.pointer;
780 if (obj && obj->type == ACPI_TYPE_BUFFER &&
781 obj->buffer.length == sizeof(struct wmab_ret)) {
782 ret = *((struct wmab_ret *) obj->buffer.pointer);
783 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700784 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000785 return AE_ERROR;
786 }
787
788 if (ret.eex & 0x1)
789 interface->capability |= ACER_CAP_MAILLED;
790
791 kfree(out.pointer);
792
793 return AE_OK;
794}
795
Mathias Krause76d51dd2014-07-16 19:43:04 +0200796static const struct acpi_device_id norfkill_ids[] __initconst = {
Ike Panhc461e7432012-02-03 16:46:39 +0800797 { "VPC2004", 0},
798 { "IBM0068", 0},
799 { "LEN0068", 0},
Lee, Chun-Yi5719b812012-03-23 12:36:44 +0800800 { "SNY5001", 0}, /* sony-laptop in charge */
Michael Powell628b31982015-08-02 22:59:29 +0000801 { "HPQ6601", 0},
Ike Panhc461e7432012-02-03 16:46:39 +0800802 { "", 0},
803};
804
Mathias Krause76d51dd2014-07-16 19:43:04 +0200805static int __init AMW0_set_cap_acpi_check_device(void)
Ike Panhc461e7432012-02-03 16:46:39 +0800806{
807 const struct acpi_device_id *id;
808
809 for (id = norfkill_ids; id->id[0]; id++)
Lukas Wunner8c92a752016-03-24 13:15:20 +0100810 if (acpi_dev_found(id->id))
811 return true;
812
813 return false;
Ike Panhc461e7432012-02-03 16:46:39 +0800814}
815
Mathias Krause76d51dd2014-07-16 19:43:04 +0200816static acpi_status __init AMW0_set_capabilities(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000817{
818 struct wmab_args args;
819 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700820 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000821 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
822 union acpi_object *obj;
823
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100824 /*
825 * On laptops with this strange GUID (non Acer), normal probing doesn't
826 * work.
827 */
828 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800829 if ((quirks != &quirk_unknown) ||
830 !AMW0_set_cap_acpi_check_device())
831 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100832 return AE_OK;
833 }
834
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000835 args.eax = ACER_AMW0_WRITE;
836 args.ecx = args.edx = 0;
837
838 args.ebx = 0xa2 << 8;
839 args.ebx |= ACER_AMW0_WIRELESS_MASK;
840
841 status = wmab_execute(&args, &out);
842 if (ACPI_FAILURE(status))
843 return status;
844
Axel Lin7677fbd2010-07-20 15:19:53 -0700845 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000846 if (obj && obj->type == ACPI_TYPE_BUFFER &&
847 obj->buffer.length == sizeof(struct wmab_ret)) {
848 ret = *((struct wmab_ret *) obj->buffer.pointer);
849 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700850 status = AE_ERROR;
851 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000852 }
853
854 if (ret.eax & 0x1)
855 interface->capability |= ACER_CAP_WIRELESS;
856
857 args.ebx = 2 << 8;
858 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
859
Axel Lin7677fbd2010-07-20 15:19:53 -0700860 /*
861 * It's ok to use existing buffer for next wmab_execute call.
862 * But we need to kfree(out.pointer) if next wmab_execute fail.
863 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000864 status = wmab_execute(&args, &out);
865 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700866 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000867
868 obj = (union acpi_object *) out.pointer;
869 if (obj && obj->type == ACPI_TYPE_BUFFER
870 && obj->buffer.length == sizeof(struct wmab_ret)) {
871 ret = *((struct wmab_ret *) obj->buffer.pointer);
872 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700873 status = AE_ERROR;
874 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000875 }
876
877 if (ret.eax & 0x1)
878 interface->capability |= ACER_CAP_BLUETOOTH;
879
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000880 /*
881 * This appears to be safe to enable, since all Wistron based laptops
882 * appear to use the same EC register for brightness, even if they
883 * differ for wireless, etc
884 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100885 if (quirks->brightness >= 0)
886 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000887
Axel Lin7677fbd2010-07-20 15:19:53 -0700888 status = AE_OK;
889out:
890 kfree(out.pointer);
891 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000892}
893
894static struct wmi_interface AMW0_interface = {
895 .type = ACER_AMW0,
896};
897
898static struct wmi_interface AMW0_V2_interface = {
899 .type = ACER_AMW0_V2,
900};
901
902/*
903 * New interface (The WMID interface)
904 */
905static acpi_status
906WMI_execute_u32(u32 method_id, u32 in, u32 *out)
907{
908 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
909 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
910 union acpi_object *obj;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800911 u32 tmp = 0;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000912 acpi_status status;
913
914 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
915
916 if (ACPI_FAILURE(status))
917 return status;
918
919 obj = (union acpi_object *) result.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800920 if (obj) {
921 if (obj->type == ACPI_TYPE_BUFFER &&
922 (obj->buffer.length == sizeof(u32) ||
923 obj->buffer.length == sizeof(u64))) {
924 tmp = *((u32 *) obj->buffer.pointer);
925 } else if (obj->type == ACPI_TYPE_INTEGER) {
926 tmp = (u32) obj->integer.value;
927 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000928 }
929
930 if (out)
931 *out = tmp;
932
933 kfree(result.pointer);
934
935 return status;
936}
937
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800938static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000939{
940 acpi_status status;
941 u8 tmp;
942 u32 result, method_id = 0;
943
944 switch (cap) {
945 case ACER_CAP_WIRELESS:
946 method_id = ACER_WMID_GET_WIRELESS_METHODID;
947 break;
948 case ACER_CAP_BLUETOOTH:
949 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
950 break;
951 case ACER_CAP_BRIGHTNESS:
952 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
953 break;
954 case ACER_CAP_THREEG:
955 method_id = ACER_WMID_GET_THREEG_METHODID;
956 break;
957 case ACER_CAP_MAILLED:
958 if (quirks->mailled == 1) {
959 ec_read(0x9f, &tmp);
960 *value = tmp & 0x1;
961 return 0;
962 }
963 default:
Lin Ming08237972008-08-08 11:57:11 +0800964 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000965 }
966 status = WMI_execute_u32(method_id, 0, &result);
967
968 if (ACPI_SUCCESS(status))
969 *value = (u8)result;
970
971 return status;
972}
973
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800974static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000975{
976 u32 method_id = 0;
977 char param;
978
979 switch (cap) {
980 case ACER_CAP_BRIGHTNESS:
981 if (value > max_brightness)
982 return AE_BAD_PARAMETER;
983 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
984 break;
985 case ACER_CAP_WIRELESS:
986 if (value > 1)
987 return AE_BAD_PARAMETER;
988 method_id = ACER_WMID_SET_WIRELESS_METHODID;
989 break;
990 case ACER_CAP_BLUETOOTH:
991 if (value > 1)
992 return AE_BAD_PARAMETER;
993 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
994 break;
995 case ACER_CAP_THREEG:
996 if (value > 1)
997 return AE_BAD_PARAMETER;
998 method_id = ACER_WMID_SET_THREEG_METHODID;
999 break;
1000 case ACER_CAP_MAILLED:
1001 if (value > 1)
1002 return AE_BAD_PARAMETER;
1003 if (quirks->mailled == 1) {
1004 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -07001005 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001006 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -07001007 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001008 return 0;
1009 }
1010 break;
1011 default:
Lin Ming08237972008-08-08 11:57:11 +08001012 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001013 }
1014 return WMI_execute_u32(method_id, (u32)value, NULL);
1015}
1016
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001017static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1018{
1019 struct wmid3_gds_return_value return_value;
1020 acpi_status status;
1021 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001022 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001023 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001024 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001025 .devices = device,
1026 };
1027 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001028 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001029 &params
1030 };
1031 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1032
1033 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1034 if (ACPI_FAILURE(status))
1035 return status;
1036
1037 obj = output.pointer;
1038
1039 if (!obj)
1040 return AE_ERROR;
1041 else if (obj->type != ACPI_TYPE_BUFFER) {
1042 kfree(obj);
1043 return AE_ERROR;
1044 }
1045 if (obj->buffer.length != 8) {
1046 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1047 kfree(obj);
1048 return AE_ERROR;
1049 }
1050
1051 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1052 kfree(obj);
1053
1054 if (return_value.error_code || return_value.ec_return_value)
1055 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1056 device,
1057 return_value.error_code,
1058 return_value.ec_return_value);
1059 else
1060 *value = !!(return_value.devices & device);
1061
1062 return status;
1063}
1064
1065static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1066{
1067 u16 device;
1068
1069 switch (cap) {
1070 case ACER_CAP_WIRELESS:
1071 device = ACER_WMID3_GDS_WIRELESS;
1072 break;
1073 case ACER_CAP_BLUETOOTH:
1074 device = ACER_WMID3_GDS_BLUETOOTH;
1075 break;
1076 case ACER_CAP_THREEG:
1077 device = ACER_WMID3_GDS_THREEG;
1078 break;
1079 default:
1080 return AE_ERROR;
1081 }
1082 return wmid3_get_device_status(value, device);
1083}
1084
1085static acpi_status wmid3_set_device_status(u32 value, u16 device)
1086{
1087 struct wmid3_gds_return_value return_value;
1088 acpi_status status;
1089 union acpi_object *obj;
1090 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001091 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001092 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001093 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001094 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001095 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001096 struct acpi_buffer get_input = {
1097 sizeof(struct wmid3_gds_get_input_param),
1098 &get_params
1099 };
1100 struct wmid3_gds_set_input_param set_params = {
1101 .function_num = 0x2,
1102 .hotkey_number = commun_fn_key_number,
1103 .devices = commun_func_bitmap,
1104 };
1105 struct acpi_buffer set_input = {
1106 sizeof(struct wmid3_gds_set_input_param),
1107 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001108 };
1109 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1110 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1111
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001112 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001113 if (ACPI_FAILURE(status))
1114 return status;
1115
1116 obj = output.pointer;
1117
1118 if (!obj)
1119 return AE_ERROR;
1120 else if (obj->type != ACPI_TYPE_BUFFER) {
1121 kfree(obj);
1122 return AE_ERROR;
1123 }
1124 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001125 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001126 kfree(obj);
1127 return AE_ERROR;
1128 }
1129
1130 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1131 kfree(obj);
1132
1133 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001134 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1135 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001136 return_value.ec_return_value);
1137 return status;
1138 }
1139
1140 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001141 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001142
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001143 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001144 if (ACPI_FAILURE(status))
1145 return status;
1146
1147 obj = output2.pointer;
1148
1149 if (!obj)
1150 return AE_ERROR;
1151 else if (obj->type != ACPI_TYPE_BUFFER) {
1152 kfree(obj);
1153 return AE_ERROR;
1154 }
1155 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001156 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001157 kfree(obj);
1158 return AE_ERROR;
1159 }
1160
1161 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1162 kfree(obj);
1163
1164 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001165 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1166 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001167 return_value.ec_return_value);
1168
1169 return status;
1170}
1171
1172static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1173{
1174 u16 device;
1175
1176 switch (cap) {
1177 case ACER_CAP_WIRELESS:
1178 device = ACER_WMID3_GDS_WIRELESS;
1179 break;
1180 case ACER_CAP_BLUETOOTH:
1181 device = ACER_WMID3_GDS_BLUETOOTH;
1182 break;
1183 case ACER_CAP_THREEG:
1184 device = ACER_WMID3_GDS_THREEG;
1185 break;
1186 default:
1187 return AE_ERROR;
1188 }
1189 return wmid3_set_device_status(value, device);
1190}
1191
Mathias Krause76d51dd2014-07-16 19:43:04 +02001192static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001193{
1194 struct hotkey_function_type_aa *type_aa;
1195
1196 /* We are looking for OEM-specific Type AAh */
1197 if (header->type != 0xAA)
1198 return;
1199
1200 has_type_aa = true;
1201 type_aa = (struct hotkey_function_type_aa *) header;
1202
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001203 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001204 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001205 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001206
1207 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1208 interface->capability |= ACER_CAP_WIRELESS;
1209 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1210 interface->capability |= ACER_CAP_THREEG;
1211 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1212 interface->capability |= ACER_CAP_BLUETOOTH;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001213
1214 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001215}
1216
Mathias Krause76d51dd2014-07-16 19:43:04 +02001217static acpi_status __init WMID_set_capabilities(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001218{
1219 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1220 union acpi_object *obj;
1221 acpi_status status;
1222 u32 devices;
1223
1224 status = wmi_query_block(WMID_GUID2, 1, &out);
1225 if (ACPI_FAILURE(status))
1226 return status;
1227
1228 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001229 if (obj) {
1230 if (obj->type == ACPI_TYPE_BUFFER &&
1231 (obj->buffer.length == sizeof(u32) ||
1232 obj->buffer.length == sizeof(u64))) {
1233 devices = *((u32 *) obj->buffer.pointer);
1234 } else if (obj->type == ACPI_TYPE_INTEGER) {
1235 devices = (u32) obj->integer.value;
Lee, Chun-Yif24c96e2013-01-03 10:37:45 +08001236 } else {
1237 kfree(out.pointer);
1238 return AE_ERROR;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001239 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001240 } else {
Axel Lin66904862010-07-20 15:19:52 -07001241 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001242 return AE_ERROR;
1243 }
1244
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001245 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1246 if (devices & 0x07)
1247 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001248 if (devices & 0x40)
1249 interface->capability |= ACER_CAP_THREEG;
1250 if (devices & 0x10)
1251 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001252
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001253 if (!(devices & 0x20))
1254 max_brightness = 0x9;
1255
Axel Lin66904862010-07-20 15:19:52 -07001256 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001257 return status;
1258}
1259
1260static struct wmi_interface wmid_interface = {
1261 .type = ACER_WMID,
1262};
1263
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001264static struct wmi_interface wmid_v2_interface = {
1265 .type = ACER_WMID_v2,
1266};
1267
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001268/*
1269 * Generic Device (interface-independent)
1270 */
1271
1272static acpi_status get_u32(u32 *value, u32 cap)
1273{
Lin Ming08237972008-08-08 11:57:11 +08001274 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001275
1276 switch (interface->type) {
1277 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001278 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001279 break;
1280 case ACER_AMW0_V2:
1281 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001282 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001283 break;
1284 }
1285 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001286 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001287 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001288 case ACER_WMID_v2:
1289 if (cap & (ACER_CAP_WIRELESS |
1290 ACER_CAP_BLUETOOTH |
1291 ACER_CAP_THREEG))
1292 status = wmid_v2_get_u32(value, cap);
1293 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001294 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001295 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001296 }
1297
1298 return status;
1299}
1300
1301static acpi_status set_u32(u32 value, u32 cap)
1302{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001303 acpi_status status;
1304
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001305 if (interface->capability & cap) {
1306 switch (interface->type) {
1307 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001308 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001309 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001310 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001311 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001312
1313 /*
1314 * On some models, some WMID methods don't toggle
1315 * properly. For those cases, we want to run the AMW0
1316 * method afterwards to be certain we've really toggled
1317 * the device state.
1318 */
1319 if (cap == ACER_CAP_WIRELESS ||
1320 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001321 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001322 if (ACPI_FAILURE(status))
1323 return status;
1324
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001325 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001326 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001327 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001328 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001329 case ACER_WMID_v2:
1330 if (cap & (ACER_CAP_WIRELESS |
1331 ACER_CAP_BLUETOOTH |
1332 ACER_CAP_THREEG))
1333 return wmid_v2_set_u32(value, cap);
1334 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001335 return WMID_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001336 default:
1337 return AE_BAD_PARAMETER;
1338 }
1339 }
1340 return AE_BAD_PARAMETER;
1341}
1342
1343static void __init acer_commandline_init(void)
1344{
1345 /*
1346 * These will all fail silently if the value given is invalid, or the
1347 * capability isn't available on the given interface
1348 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001349 if (mailled >= 0)
1350 set_u32(mailled, ACER_CAP_MAILLED);
1351 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001352 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001353 if (brightness >= 0)
1354 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001355}
1356
1357/*
1358 * LED device (Mail LED only, no other LEDs known yet)
1359 */
1360static void mail_led_set(struct led_classdev *led_cdev,
1361enum led_brightness value)
1362{
1363 set_u32(value, ACER_CAP_MAILLED);
1364}
1365
1366static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001367 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001368 .brightness_set = mail_led_set,
1369};
1370
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001371static int acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001372{
1373 return led_classdev_register(dev, &mail_led);
1374}
1375
1376static void acer_led_exit(void)
1377{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001378 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001379 led_classdev_unregister(&mail_led);
1380}
1381
1382/*
1383 * Backlight device
1384 */
1385static struct backlight_device *acer_backlight_device;
1386
1387static int read_brightness(struct backlight_device *bd)
1388{
1389 u32 value;
1390 get_u32(&value, ACER_CAP_BRIGHTNESS);
1391 return value;
1392}
1393
1394static int update_bl_status(struct backlight_device *bd)
1395{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001396 int intensity = bd->props.brightness;
1397
1398 if (bd->props.power != FB_BLANK_UNBLANK)
1399 intensity = 0;
1400 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1401 intensity = 0;
1402
1403 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1404
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001405 return 0;
1406}
1407
Lionel Debrouxacc24722010-11-16 14:14:02 +01001408static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001409 .get_brightness = read_brightness,
1410 .update_status = update_bl_status,
1411};
1412
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001413static int acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001414{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001415 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001416 struct backlight_device *bd;
1417
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001418 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001419 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001420 props.max_brightness = max_brightness;
1421 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1422 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001423 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001424 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001425 acer_backlight_device = NULL;
1426 return PTR_ERR(bd);
1427 }
1428
1429 acer_backlight_device = bd;
1430
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001431 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001432 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001433 backlight_update_status(bd);
1434 return 0;
1435}
1436
Sam Ravnborg7560e382008-02-17 13:22:54 +01001437static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001438{
1439 backlight_device_unregister(acer_backlight_device);
1440}
1441
1442/*
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001443 * Accelerometer device
1444 */
1445static acpi_handle gsensor_handle;
1446
1447static int acer_gsensor_init(void)
1448{
1449 acpi_status status;
1450 struct acpi_buffer output;
1451 union acpi_object out_obj;
1452
1453 output.length = sizeof(out_obj);
1454 output.pointer = &out_obj;
1455 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1456 if (ACPI_FAILURE(status))
1457 return -1;
1458
1459 return 0;
1460}
1461
1462static int acer_gsensor_open(struct input_dev *input)
1463{
1464 return acer_gsensor_init();
1465}
1466
1467static int acer_gsensor_event(void)
1468{
1469 acpi_status status;
1470 struct acpi_buffer output;
1471 union acpi_object out_obj[5];
1472
1473 if (!has_cap(ACER_CAP_ACCEL))
1474 return -1;
1475
1476 output.length = sizeof(out_obj);
1477 output.pointer = out_obj;
1478
1479 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1480 if (ACPI_FAILURE(status))
1481 return -1;
1482
1483 if (out_obj->package.count != 4)
1484 return -1;
1485
1486 input_report_abs(acer_wmi_accel_dev, ABS_X,
1487 (s16)out_obj->package.elements[0].integer.value);
1488 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1489 (s16)out_obj->package.elements[1].integer.value);
1490 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1491 (s16)out_obj->package.elements[2].integer.value);
1492 input_sync(acer_wmi_accel_dev);
1493 return 0;
1494}
1495
1496/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001497 * Rfkill devices
1498 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001499static void acer_rfkill_update(struct work_struct *ignored);
1500static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1501static void acer_rfkill_update(struct work_struct *ignored)
1502{
1503 u32 state;
1504 acpi_status status;
1505
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001506 if (has_cap(ACER_CAP_WIRELESS)) {
1507 status = get_u32(&state, ACER_CAP_WIRELESS);
1508 if (ACPI_SUCCESS(status)) {
1509 if (quirks->wireless == 3)
1510 rfkill_set_hw_state(wireless_rfkill, !state);
1511 else
1512 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001513 }
1514 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001515
1516 if (has_cap(ACER_CAP_BLUETOOTH)) {
1517 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1518 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001519 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001520 }
1521
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001522 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001523 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001524 if (ACPI_SUCCESS(status))
1525 rfkill_set_sw_state(threeg_rfkill, !state);
1526 }
1527
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001528 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001529}
1530
Johannes Berg19d337d2009-06-02 13:01:37 +02001531static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001532{
1533 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001534 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001535
1536 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001537 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001538 if (ACPI_FAILURE(status))
1539 return -ENODEV;
1540 }
1541
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001542 return 0;
1543}
1544
Johannes Berg19d337d2009-06-02 13:01:37 +02001545static const struct rfkill_ops acer_rfkill_ops = {
1546 .set_block = acer_rfkill_set,
1547};
1548
1549static struct rfkill *acer_rfkill_register(struct device *dev,
1550 enum rfkill_type type,
1551 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001552{
1553 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001554 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001555 u32 state;
1556 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001557
Johannes Berg19d337d2009-06-02 13:01:37 +02001558 rfkill_dev = rfkill_alloc(name, dev, type,
1559 &acer_rfkill_ops,
1560 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001561 if (!rfkill_dev)
1562 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001563
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001564 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001565
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001566 err = rfkill_register(rfkill_dev);
1567 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001568 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001569 return ERR_PTR(err);
1570 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001571
1572 if (ACPI_SUCCESS(status))
1573 rfkill_set_sw_state(rfkill_dev, !state);
1574
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001575 return rfkill_dev;
1576}
1577
1578static int acer_rfkill_init(struct device *dev)
1579{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001580 int err;
1581
1582 if (has_cap(ACER_CAP_WIRELESS)) {
1583 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1584 "acer-wireless", ACER_CAP_WIRELESS);
1585 if (IS_ERR(wireless_rfkill)) {
1586 err = PTR_ERR(wireless_rfkill);
1587 goto error_wireless;
1588 }
1589 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001590
1591 if (has_cap(ACER_CAP_BLUETOOTH)) {
1592 bluetooth_rfkill = acer_rfkill_register(dev,
1593 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1594 ACER_CAP_BLUETOOTH);
1595 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001596 err = PTR_ERR(bluetooth_rfkill);
1597 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001598 }
1599 }
1600
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001601 if (has_cap(ACER_CAP_THREEG)) {
1602 threeg_rfkill = acer_rfkill_register(dev,
1603 RFKILL_TYPE_WWAN, "acer-threeg",
1604 ACER_CAP_THREEG);
1605 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001606 err = PTR_ERR(threeg_rfkill);
1607 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001608 }
1609 }
1610
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001611 rfkill_inited = true;
1612
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001613 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1614 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001615 schedule_delayed_work(&acer_rfkill_work,
1616 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001617
1618 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001619
1620error_threeg:
1621 if (has_cap(ACER_CAP_BLUETOOTH)) {
1622 rfkill_unregister(bluetooth_rfkill);
1623 rfkill_destroy(bluetooth_rfkill);
1624 }
1625error_bluetooth:
1626 if (has_cap(ACER_CAP_WIRELESS)) {
1627 rfkill_unregister(wireless_rfkill);
1628 rfkill_destroy(wireless_rfkill);
1629 }
1630error_wireless:
1631 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001632}
1633
1634static void acer_rfkill_exit(void)
1635{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001636 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1637 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001638 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001639
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001640 if (has_cap(ACER_CAP_WIRELESS)) {
1641 rfkill_unregister(wireless_rfkill);
1642 rfkill_destroy(wireless_rfkill);
1643 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001644
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001645 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001646 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001647 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001648 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001649
1650 if (has_cap(ACER_CAP_THREEG)) {
1651 rfkill_unregister(threeg_rfkill);
1652 rfkill_destroy(threeg_rfkill);
1653 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001654 return;
1655}
1656
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001657static void acer_wmi_notify(u32 value, void *context)
1658{
1659 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1660 union acpi_object *obj;
1661 struct event_return_value return_value;
1662 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001663 u16 device_state;
1664 const struct key_entry *key;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001665 u32 scancode;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001666
1667 status = wmi_get_event_data(value, &response);
1668 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001669 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001670 return;
1671 }
1672
1673 obj = (union acpi_object *)response.pointer;
1674
1675 if (!obj)
1676 return;
1677 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001678 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001679 kfree(obj);
1680 return;
1681 }
1682 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001683 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001684 kfree(obj);
1685 return;
1686 }
1687
1688 return_value = *((struct event_return_value *)obj->buffer.pointer);
1689 kfree(obj);
1690
1691 switch (return_value.function) {
1692 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001693 device_state = return_value.device_state;
1694 pr_debug("device state: 0x%x\n", device_state);
1695
1696 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1697 return_value.key_num);
1698 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001699 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001700 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001701 } else {
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001702 scancode = return_value.key_num;
Seth Forshee92530662011-06-21 12:00:33 -05001703 switch (key->keycode) {
1704 case KEY_WLAN:
1705 case KEY_BLUETOOTH:
1706 if (has_cap(ACER_CAP_WIRELESS))
1707 rfkill_set_sw_state(wireless_rfkill,
1708 !(device_state & ACER_WMID3_GDS_WIRELESS));
1709 if (has_cap(ACER_CAP_THREEG))
1710 rfkill_set_sw_state(threeg_rfkill,
1711 !(device_state & ACER_WMID3_GDS_THREEG));
1712 if (has_cap(ACER_CAP_BLUETOOTH))
1713 rfkill_set_sw_state(bluetooth_rfkill,
1714 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1715 break;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001716 case KEY_TOUCHPAD_TOGGLE:
1717 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1718 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
Seth Forshee92530662011-06-21 12:00:33 -05001719 }
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001720 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
Seth Forshee92530662011-06-21 12:00:33 -05001721 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001722 break;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001723 case WMID_ACCEL_EVENT:
1724 acer_gsensor_event();
1725 break;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001726 default:
Joe Perches249c7202011-03-29 15:21:34 -07001727 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001728 return_value.function, return_value.key_num);
1729 break;
1730 }
1731}
1732
Mathias Krause76d51dd2014-07-16 19:43:04 +02001733static acpi_status __init
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001734wmid3_set_lm_mode(struct lm_input_params *params,
1735 struct lm_return_value *return_value)
1736{
1737 acpi_status status;
1738 union acpi_object *obj;
1739
1740 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1741 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1742
1743 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1744 if (ACPI_FAILURE(status))
1745 return status;
1746
1747 obj = output.pointer;
1748
1749 if (!obj)
1750 return AE_ERROR;
1751 else if (obj->type != ACPI_TYPE_BUFFER) {
1752 kfree(obj);
1753 return AE_ERROR;
1754 }
1755 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001756 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001757 kfree(obj);
1758 return AE_ERROR;
1759 }
1760
1761 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1762 kfree(obj);
1763
1764 return status;
1765}
1766
Mathias Krause76d51dd2014-07-16 19:43:04 +02001767static int __init acer_wmi_enable_ec_raw(void)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001768{
1769 struct lm_return_value return_value;
1770 acpi_status status;
1771 struct lm_input_params params = {
1772 .function_num = 0x1,
1773 .commun_devices = 0xFFFF,
1774 .devices = 0xFFFF,
1775 .lm_status = 0x00, /* Launch Manager Deactive */
1776 };
1777
1778 status = wmid3_set_lm_mode(&params, &return_value);
1779
1780 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001781 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1782 return_value.error_code,
1783 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001784 else
Joe Perches249c7202011-03-29 15:21:34 -07001785 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001786
1787 return status;
1788}
1789
Mathias Krause76d51dd2014-07-16 19:43:04 +02001790static int __init acer_wmi_enable_lm(void)
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001791{
1792 struct lm_return_value return_value;
1793 acpi_status status;
1794 struct lm_input_params params = {
1795 .function_num = 0x1,
1796 .commun_devices = 0xFFFF,
1797 .devices = 0xFFFF,
1798 .lm_status = 0x01, /* Launch Manager Active */
1799 };
1800
1801 status = wmid3_set_lm_mode(&params, &return_value);
1802
1803 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001804 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1805 return_value.error_code,
1806 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001807
1808 return status;
1809}
1810
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001811static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1812 void *ctx, void **retval)
1813{
1814 *(acpi_handle *)retval = ah;
1815 return AE_OK;
1816}
1817
1818static int __init acer_wmi_get_handle(const char *name, const char *prop,
1819 acpi_handle *ah)
1820{
1821 acpi_status status;
1822 acpi_handle handle;
1823
1824 BUG_ON(!name || !ah);
1825
Marek Vasut24237c42012-07-05 01:30:09 +02001826 handle = NULL;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001827 status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1828 (void *)name, &handle);
1829
1830 if (ACPI_SUCCESS(status)) {
1831 *ah = handle;
1832 return 0;
1833 } else {
1834 return -ENODEV;
1835 }
1836}
1837
1838static int __init acer_wmi_accel_setup(void)
1839{
1840 int err;
1841
1842 err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle);
1843 if (err)
1844 return err;
1845
1846 interface->capability |= ACER_CAP_ACCEL;
1847
1848 acer_wmi_accel_dev = input_allocate_device();
1849 if (!acer_wmi_accel_dev)
1850 return -ENOMEM;
1851
1852 acer_wmi_accel_dev->open = acer_gsensor_open;
1853
1854 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1855 acer_wmi_accel_dev->phys = "wmi/input1";
1856 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1857 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1858 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1859 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1860 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1861
1862 err = input_register_device(acer_wmi_accel_dev);
1863 if (err)
1864 goto err_free_dev;
1865
1866 return 0;
1867
1868err_free_dev:
1869 input_free_device(acer_wmi_accel_dev);
1870 return err;
1871}
1872
1873static void acer_wmi_accel_destroy(void)
1874{
1875 input_unregister_device(acer_wmi_accel_dev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001876}
1877
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001878static int __init acer_wmi_input_setup(void)
1879{
1880 acpi_status status;
1881 int err;
1882
1883 acer_wmi_input_dev = input_allocate_device();
1884 if (!acer_wmi_input_dev)
1885 return -ENOMEM;
1886
1887 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1888 acer_wmi_input_dev->phys = "wmi/input0";
1889 acer_wmi_input_dev->id.bustype = BUS_HOST;
1890
1891 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1892 if (err)
1893 goto err_free_dev;
1894
1895 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1896 acer_wmi_notify, NULL);
1897 if (ACPI_FAILURE(status)) {
1898 err = -EIO;
1899 goto err_free_keymap;
1900 }
1901
1902 err = input_register_device(acer_wmi_input_dev);
1903 if (err)
1904 goto err_uninstall_notifier;
1905
1906 return 0;
1907
1908err_uninstall_notifier:
1909 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1910err_free_keymap:
1911 sparse_keymap_free(acer_wmi_input_dev);
1912err_free_dev:
1913 input_free_device(acer_wmi_input_dev);
1914 return err;
1915}
1916
1917static void acer_wmi_input_destroy(void)
1918{
1919 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1920 sparse_keymap_free(acer_wmi_input_dev);
1921 input_unregister_device(acer_wmi_input_dev);
1922}
1923
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001924/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001925 * debugfs functions
1926 */
1927static u32 get_wmid_devices(void)
1928{
1929 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1930 union acpi_object *obj;
1931 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001932 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001933
1934 status = wmi_query_block(WMID_GUID2, 1, &out);
1935 if (ACPI_FAILURE(status))
1936 return 0;
1937
1938 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001939 if (obj) {
1940 if (obj->type == ACPI_TYPE_BUFFER &&
1941 (obj->buffer.length == sizeof(u32) ||
1942 obj->buffer.length == sizeof(u64))) {
1943 devices = *((u32 *) obj->buffer.pointer);
1944 } else if (obj->type == ACPI_TYPE_INTEGER) {
1945 devices = (u32) obj->integer.value;
1946 }
Carlos Corbacho81143522008-06-21 09:09:53 +01001947 }
Axel Lin66904862010-07-20 15:19:52 -07001948
1949 kfree(out.pointer);
1950 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001951}
1952
1953/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001954 * Platform device
1955 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001956static int acer_platform_probe(struct platform_device *device)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001957{
1958 int err;
1959
1960 if (has_cap(ACER_CAP_MAILLED)) {
1961 err = acer_led_init(&device->dev);
1962 if (err)
1963 goto error_mailled;
1964 }
1965
1966 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1967 err = acer_backlight_init(&device->dev);
1968 if (err)
1969 goto error_brightness;
1970 }
1971
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001972 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001973 if (err)
1974 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001975
1976 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001977
Andy Whitcroft350e3292009-04-04 09:33:34 +01001978error_rfkill:
1979 if (has_cap(ACER_CAP_BRIGHTNESS))
1980 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001981error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001982 if (has_cap(ACER_CAP_MAILLED))
1983 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001984error_mailled:
1985 return err;
1986}
1987
1988static int acer_platform_remove(struct platform_device *device)
1989{
1990 if (has_cap(ACER_CAP_MAILLED))
1991 acer_led_exit();
1992 if (has_cap(ACER_CAP_BRIGHTNESS))
1993 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001994
1995 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001996 return 0;
1997}
1998
Mathias Krause80f65552014-07-16 19:43:06 +02001999#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002000static int acer_suspend(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002001{
2002 u32 value;
2003 struct acer_data *data = &interface->data;
2004
2005 if (!data)
2006 return -ENOMEM;
2007
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002008 if (has_cap(ACER_CAP_MAILLED)) {
2009 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002010 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002011 data->mailled = value;
2012 }
2013
2014 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2015 get_u32(&value, ACER_CAP_BRIGHTNESS);
2016 data->brightness = value;
2017 }
2018
2019 return 0;
2020}
2021
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002022static int acer_resume(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002023{
2024 struct acer_data *data = &interface->data;
2025
2026 if (!data)
2027 return -ENOMEM;
2028
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002029 if (has_cap(ACER_CAP_MAILLED))
2030 set_u32(data->mailled, ACER_CAP_MAILLED);
2031
2032 if (has_cap(ACER_CAP_BRIGHTNESS))
2033 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2034
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002035 if (has_cap(ACER_CAP_ACCEL))
2036 acer_gsensor_init();
2037
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002038 return 0;
2039}
Mathias Krause80f65552014-07-16 19:43:06 +02002040#else
2041#define acer_suspend NULL
2042#define acer_resume NULL
2043#endif
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002044
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002045static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2046
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002047static void acer_platform_shutdown(struct platform_device *device)
2048{
2049 struct acer_data *data = &interface->data;
2050
2051 if (!data)
2052 return;
2053
2054 if (has_cap(ACER_CAP_MAILLED))
2055 set_u32(LED_OFF, ACER_CAP_MAILLED);
2056}
2057
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002058static struct platform_driver acer_platform_driver = {
2059 .driver = {
2060 .name = "acer-wmi",
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002061 .pm = &acer_pm,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002062 },
2063 .probe = acer_platform_probe,
2064 .remove = acer_platform_remove,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002065 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002066};
2067
2068static struct platform_device *acer_platform_device;
2069
Carlos Corbacho81143522008-06-21 09:09:53 +01002070static void remove_debugfs(void)
2071{
2072 debugfs_remove(interface->debug.devices);
2073 debugfs_remove(interface->debug.root);
2074}
2075
Mathias Krause76d51dd2014-07-16 19:43:04 +02002076static int __init create_debugfs(void)
Carlos Corbacho81143522008-06-21 09:09:53 +01002077{
2078 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2079 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002080 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01002081 return -ENOMEM;
2082 }
2083
2084 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2085 interface->debug.root,
2086 &interface->debug.wmid_devices);
2087 if (!interface->debug.devices)
2088 goto error_debugfs;
2089
2090 return 0;
2091
2092error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07002093 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01002094 return -ENOMEM;
2095}
2096
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002097static int __init acer_wmi_init(void)
2098{
2099 int err;
2100
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002101 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002102
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002103 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002104 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002105 return -ENODEV;
2106 }
2107
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01002108 find_quirks();
2109
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002110 /*
2111 * Detect which ACPI-WMI interface we're using.
2112 */
2113 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2114 interface = &AMW0_V2_interface;
2115
2116 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2117 interface = &wmid_interface;
2118
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002119 if (wmi_has_guid(WMID_GUID3))
2120 interface = &wmid_v2_interface;
2121
2122 if (interface)
2123 dmi_walk(type_aa_dmi_decode, NULL);
2124
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002125 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002126 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002127 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002128 return -ENODEV;
2129 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002130 /* WMID always provides brightness methods */
2131 interface->capability |= ACER_CAP_BRIGHTNESS;
2132 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002133 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002134 return -ENODEV;
2135 }
2136
2137 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2138 interface = &AMW0_interface;
2139
2140 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002141 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002142 return -ENODEV;
2143 }
2144 }
2145
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002146 if (wmi_has_guid(AMW0_GUID1))
2147 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002148
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002149 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002150 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002151 return -ENODEV;
2152 }
2153
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002154 set_quirks();
2155
Corentin Charya60b2172012-06-13 09:32:02 +02002156 if (dmi_check_system(video_vendor_dmi_table))
Hans de Goede9a65f0d2015-06-16 16:27:55 +02002157 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2158
2159 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Corentin Charya60b2172012-06-13 09:32:02 +02002160 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002161
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002162 if (wmi_has_guid(WMID_GUID3)) {
2163 if (ec_raw_mode) {
2164 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002165 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002166 return -ENODEV;
2167 }
2168 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002169 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002170 return -ENODEV;
2171 }
2172 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002173 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002174 }
2175
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002176 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2177 err = acer_wmi_input_setup();
2178 if (err)
2179 return err;
2180 }
2181
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002182 acer_wmi_accel_setup();
2183
Axel Lin1c796322010-06-22 16:17:38 +08002184 err = platform_driver_register(&acer_platform_driver);
2185 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002186 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002187 goto error_platform_register;
2188 }
Axel Lin1c796322010-06-22 16:17:38 +08002189
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002190 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002191 if (!acer_platform_device) {
2192 err = -ENOMEM;
2193 goto error_device_alloc;
2194 }
2195
2196 err = platform_device_add(acer_platform_device);
2197 if (err)
2198 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002199
Carlos Corbacho81143522008-06-21 09:09:53 +01002200 if (wmi_has_guid(WMID_GUID2)) {
2201 interface->debug.wmid_devices = get_wmid_devices();
2202 err = create_debugfs();
2203 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002204 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002205 }
2206
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002207 /* Override any initial settings with values from the commandline */
2208 acer_commandline_init();
2209
2210 return 0;
2211
Axel Lin1c796322010-06-22 16:17:38 +08002212error_create_debugfs:
Axel Lin1c796322010-06-22 16:17:38 +08002213 platform_device_del(acer_platform_device);
2214error_device_add:
2215 platform_device_put(acer_platform_device);
2216error_device_alloc:
2217 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002218error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002219 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2220 acer_wmi_input_destroy();
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002221 if (has_cap(ACER_CAP_ACCEL))
2222 acer_wmi_accel_destroy();
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002223
Axel Lin1c796322010-06-22 16:17:38 +08002224 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002225}
2226
2227static void __exit acer_wmi_exit(void)
2228{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002229 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2230 acer_wmi_input_destroy();
2231
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002232 if (has_cap(ACER_CAP_ACCEL))
2233 acer_wmi_accel_destroy();
2234
Russ Dill39dbbb42008-09-02 14:35:40 -07002235 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002236 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002237 platform_driver_unregister(&acer_platform_driver);
2238
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002239 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002240 return;
2241}
2242
2243module_init(acer_wmi_init);
2244module_exit(acer_wmi_exit);