blob: 563dc3f0e3e7a5cc420d908e86eb8c34b856a6aa [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>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000044
45#include <acpi/acpi_drivers.h>
Lee, Chun-Yi86924de2012-03-26 15:47:58 -040046#include <acpi/video.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000047
48MODULE_AUTHOR("Carlos Corbacho");
49MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
50MODULE_LICENSE("GPL");
51
Carlos Corbacho745a5d22008-02-05 02:17:10 +000052/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000053 * Magic Number
54 * Meaning is unknown - this number is required for writing to ACPI for AMW0
55 * (it's also used in acerhk when directly accessing the BIOS)
56 */
57#define ACER_AMW0_WRITE 0x9610
58
59/*
60 * Bit masks for the AMW0 interface
61 */
62#define ACER_AMW0_WIRELESS_MASK 0x35
63#define ACER_AMW0_BLUETOOTH_MASK 0x34
64#define ACER_AMW0_MAILLED_MASK 0x31
65
66/*
67 * Method IDs for WMID interface
68 */
69#define ACER_WMID_GET_WIRELESS_METHODID 1
70#define ACER_WMID_GET_BLUETOOTH_METHODID 2
71#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
72#define ACER_WMID_SET_WIRELESS_METHODID 4
73#define ACER_WMID_SET_BLUETOOTH_METHODID 5
74#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
75#define ACER_WMID_GET_THREEG_METHODID 10
76#define ACER_WMID_SET_THREEG_METHODID 11
77
78/*
79 * Acer ACPI method GUIDs
80 */
81#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010082#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Matthew Garrettbbb70602011-02-09 16:39:40 -050083#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
Pali Rohár298f19b2011-03-11 12:36:43 -050084#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080085#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000086
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080087/*
88 * Acer ACPI event GUIDs
89 */
90#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
91
Carlos Corbacho745a5d22008-02-05 02:17:10 +000092MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
Lee, Chun-Yi08a07992011-04-06 17:40:06 +080093MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080094MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
95
96enum acer_wmi_event_ids {
97 WMID_HOTKEY_EVENT = 0x1,
Marek Vasut1eb3fe12012-06-01 19:11:22 +020098 WMID_ACCEL_EVENT = 0x5,
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080099};
100
101static const struct key_entry acer_wmi_keymap[] = {
102 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200103 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
Seth Forshee1a04d8f2011-06-21 12:00:32 -0500104 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800105 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
106 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
107 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
108 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
109 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
Merlin Schumacher67e1d342012-01-24 04:35:35 +0800110 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200111 {KE_IGNORE, 0x41, {KEY_MUTE} },
112 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300113 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200114 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300115 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200116 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300117 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200118 {KE_IGNORE, 0x45, {KEY_STOP} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300119 {KE_IGNORE, 0x50, {KEY_STOP} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200120 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
121 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
Sergey Senozhatskyca1469f2012-03-12 13:07:13 +0300122 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200123 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
124 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
125 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800126 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200127 {KE_IGNORE, 0x81, {KEY_SLEEP} },
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800128 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */
129 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
130 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200131 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
Sergey Senozhatsky68825ce2012-11-26 21:35:02 +0300132 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800133 {KE_END, 0}
134};
135
136static struct input_dev *acer_wmi_input_dev;
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200137static struct input_dev *acer_wmi_accel_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800138
139struct event_return_value {
140 u8 function;
141 u8 key_num;
142 u16 device_state;
143 u32 reserved;
144} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000145
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000146/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800147 * GUID3 Get Device Status device flags
148 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800149#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800150#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800151#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800152#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800153#define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800154
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500155struct lm_input_params {
156 u8 function_num; /* Function Number */
157 u16 commun_devices; /* Communication type devices default status */
158 u16 devices; /* Other type devices default status */
159 u8 lm_status; /* Launch Manager Status */
160 u16 reserved;
161} __attribute__((packed));
162
163struct lm_return_value {
164 u8 error_code; /* Error Code */
165 u8 ec_return_value; /* EC Return Value */
166 u16 reserved;
167} __attribute__((packed));
168
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800169struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
170 u8 function_num; /* Function Number */
171 u8 hotkey_number; /* Hotkey Number */
172 u16 devices; /* Set Device */
173 u8 volume_value; /* Volume Value */
174} __attribute__((packed));
175
176struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800177 u8 function_num; /* Function Number */
178 u8 hotkey_number; /* Hotkey Number */
179 u16 devices; /* Get Device */
180} __attribute__((packed));
181
182struct wmid3_gds_return_value { /* Get Device Status return value*/
183 u8 error_code; /* Error Code */
184 u8 ec_return_value; /* EC Return Value */
185 u16 devices; /* Current Device Status */
186 u32 reserved;
187} __attribute__((packed));
188
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800189struct hotkey_function_type_aa {
190 u8 type;
191 u8 length;
192 u16 handle;
193 u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800194 u16 application_func_bitmap;
195 u16 media_func_bitmap;
196 u16 display_func_bitmap;
197 u16 others_func_bitmap;
198 u8 commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800199} __attribute__((packed));
200
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800201/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000202 * Interface capability flags
203 */
204#define ACER_CAP_MAILLED (1<<0)
205#define ACER_CAP_WIRELESS (1<<1)
206#define ACER_CAP_BLUETOOTH (1<<2)
207#define ACER_CAP_BRIGHTNESS (1<<3)
208#define ACER_CAP_THREEG (1<<4)
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200209#define ACER_CAP_ACCEL (1<<5)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000210#define ACER_CAP_ANY (0xFFFFFFFF)
211
212/*
213 * Interface type flags
214 */
215enum interface_flags {
216 ACER_AMW0,
217 ACER_AMW0_V2,
218 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800219 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000220};
221
222#define ACER_DEFAULT_WIRELESS 0
223#define ACER_DEFAULT_BLUETOOTH 0
224#define ACER_DEFAULT_MAILLED 0
225#define ACER_DEFAULT_THREEG 0
226
227static int max_brightness = 0xF;
228
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000229static int mailled = -1;
230static int brightness = -1;
231static int threeg = -1;
232static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500233static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800234static bool has_type_aa;
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +0800235static u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800236static u8 commun_fn_key_number;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000237
238module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000239module_param(brightness, int, 0444);
240module_param(threeg, int, 0444);
241module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500242module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000243MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
244MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
245MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
246MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500247MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000248
249struct acer_data {
250 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000251 int threeg;
252 int brightness;
253};
254
Carlos Corbacho81143522008-06-21 09:09:53 +0100255struct acer_debug {
256 struct dentry *root;
257 struct dentry *devices;
258 u32 wmid_devices;
259};
260
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100261static struct rfkill *wireless_rfkill;
262static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800263static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800264static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100265
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000266/* Each low-level interface must define at least some of the following */
267struct wmi_interface {
268 /* The WMI device type */
269 u32 type;
270
271 /* The capabilities this interface provides */
272 u32 capability;
273
274 /* Private data for the current interface */
275 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100276
277 /* debugfs entries associated with this interface */
278 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000279};
280
281/* The static interface pointer, points to the currently detected interface */
282static struct wmi_interface *interface;
283
284/*
285 * Embedded Controller quirks
286 * Some laptops require us to directly access the EC to either enable or query
287 * features that are not available through WMI.
288 */
289
290struct quirk_entry {
291 u8 wireless;
292 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100293 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000294 u8 bluetooth;
295};
296
297static struct quirk_entry *quirks;
298
299static void set_quirks(void)
300{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700301 if (!interface)
302 return;
303
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000304 if (quirks->mailled)
305 interface->capability |= ACER_CAP_MAILLED;
306
307 if (quirks->brightness)
308 interface->capability |= ACER_CAP_BRIGHTNESS;
309}
310
311static int dmi_matched(const struct dmi_system_id *dmi)
312{
313 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800314 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000315}
316
317static struct quirk_entry quirk_unknown = {
318};
319
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100320static struct quirk_entry quirk_acer_aspire_1520 = {
321 .brightness = -1,
322};
323
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000324static struct quirk_entry quirk_acer_travelmate_2490 = {
325 .mailled = 1,
326};
327
328/* This AMW0 laptop has no bluetooth */
329static struct quirk_entry quirk_medion_md_98300 = {
330 .wireless = 1,
331};
332
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100333static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
334 .wireless = 2,
335};
336
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800337static struct quirk_entry quirk_lenovo_ideapad_s205 = {
338 .wireless = 3,
339};
340
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100341/* The Aspire One has a dummy ACPI-WMI interface - disable it */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800342static struct dmi_system_id acer_blacklist[] = {
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100343 {
344 .ident = "Acer Aspire One (SSD)",
345 .matches = {
346 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
347 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
348 },
349 },
350 {
351 .ident = "Acer Aspire One (HDD)",
352 .matches = {
353 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
354 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
355 },
356 },
357 {}
358};
359
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000360static struct dmi_system_id acer_quirks[] = {
361 {
362 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100363 .ident = "Acer Aspire 1360",
364 .matches = {
365 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
366 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
367 },
368 .driver_data = &quirk_acer_aspire_1520,
369 },
370 {
371 .callback = dmi_matched,
372 .ident = "Acer Aspire 1520",
373 .matches = {
374 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
375 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
376 },
377 .driver_data = &quirk_acer_aspire_1520,
378 },
379 {
380 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000381 .ident = "Acer Aspire 3100",
382 .matches = {
383 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
384 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
385 },
386 .driver_data = &quirk_acer_travelmate_2490,
387 },
388 {
389 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000390 .ident = "Acer Aspire 3610",
391 .matches = {
392 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
393 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
394 },
395 .driver_data = &quirk_acer_travelmate_2490,
396 },
397 {
398 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000399 .ident = "Acer Aspire 5100",
400 .matches = {
401 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
402 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
403 },
404 .driver_data = &quirk_acer_travelmate_2490,
405 },
406 {
407 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000408 .ident = "Acer Aspire 5610",
409 .matches = {
410 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
411 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
412 },
413 .driver_data = &quirk_acer_travelmate_2490,
414 },
415 {
416 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000417 .ident = "Acer Aspire 5630",
418 .matches = {
419 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
420 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
421 },
422 .driver_data = &quirk_acer_travelmate_2490,
423 },
424 {
425 .callback = dmi_matched,
426 .ident = "Acer Aspire 5650",
427 .matches = {
428 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
430 },
431 .driver_data = &quirk_acer_travelmate_2490,
432 },
433 {
434 .callback = dmi_matched,
435 .ident = "Acer Aspire 5680",
436 .matches = {
437 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
439 },
440 .driver_data = &quirk_acer_travelmate_2490,
441 },
442 {
443 .callback = dmi_matched,
444 .ident = "Acer Aspire 9110",
445 .matches = {
446 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
447 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
448 },
449 .driver_data = &quirk_acer_travelmate_2490,
450 },
451 {
452 .callback = dmi_matched,
453 .ident = "Acer TravelMate 2490",
454 .matches = {
455 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
456 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
457 },
458 .driver_data = &quirk_acer_travelmate_2490,
459 },
460 {
461 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000462 .ident = "Acer TravelMate 4200",
463 .matches = {
464 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
465 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
466 },
467 .driver_data = &quirk_acer_travelmate_2490,
468 },
469 {
470 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100471 .ident = "Fujitsu Siemens Amilo Li 1718",
472 .matches = {
473 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
474 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
475 },
476 .driver_data = &quirk_fujitsu_amilo_li_1718,
477 },
478 {
479 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000480 .ident = "Medion MD 98300",
481 .matches = {
482 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
483 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
484 },
485 .driver_data = &quirk_medion_md_98300,
486 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800487 {
488 .callback = dmi_matched,
489 .ident = "Lenovo Ideapad S205",
490 .matches = {
491 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
492 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
493 },
494 .driver_data = &quirk_lenovo_ideapad_s205,
495 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500496 {
497 .callback = dmi_matched,
Lee, Chun-Yic08f2082012-03-20 11:32:49 +0800498 .ident = "Lenovo Ideapad S205 (Brazos)",
499 .matches = {
500 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
501 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
502 },
503 .driver_data = &quirk_lenovo_ideapad_s205,
504 },
505 {
506 .callback = dmi_matched,
Seth Forsheebe3128b2011-10-06 15:01:55 -0500507 .ident = "Lenovo 3000 N200",
508 .matches = {
509 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
510 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
511 },
512 .driver_data = &quirk_fujitsu_amilo_li_1718,
513 },
Lee, Chun-Yie6c33f12012-12-14 16:14:25 +0800514 {
515 .callback = dmi_matched,
516 .ident = "Lenovo Ideapad S205-10382JG",
517 .matches = {
518 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
519 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
520 },
521 .driver_data = &quirk_lenovo_ideapad_s205,
522 },
Lee, Chun-Yi5f3511d2012-12-14 16:14:28 +0800523 {
524 .callback = dmi_matched,
525 .ident = "Lenovo Ideapad S205-1038DPG",
526 .matches = {
527 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
528 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
529 },
530 .driver_data = &quirk_lenovo_ideapad_s205,
531 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000532 {}
533};
534
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400535static int video_set_backlight_video_vendor(const struct dmi_system_id *d)
536{
537 interface->capability &= ~ACER_CAP_BRIGHTNESS;
538 pr_info("Brightness must be controlled by generic video driver\n");
539 return 0;
540}
541
542static const struct dmi_system_id video_vendor_dmi_table[] = {
543 {
544 .callback = video_set_backlight_video_vendor,
545 .ident = "Acer TravelMate 4750",
546 .matches = {
547 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
548 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
549 },
550 },
Lee, Chun-Yi050eff32012-05-21 23:19:51 +0800551 {
552 .callback = video_set_backlight_video_vendor,
553 .ident = "Acer Extensa 5235",
554 .matches = {
555 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
556 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
557 },
558 },
559 {
560 .callback = video_set_backlight_video_vendor,
561 .ident = "Acer TravelMate 5760",
562 .matches = {
563 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
564 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
565 },
566 },
567 {
568 .callback = video_set_backlight_video_vendor,
569 .ident = "Acer Aspire 5750",
570 .matches = {
571 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
572 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
573 },
574 },
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400575 {}
576};
577
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000578/* Find which quirks are needed for a particular vendor/ model pair */
579static void find_quirks(void)
580{
581 if (!force_series) {
582 dmi_check_system(acer_quirks);
583 } else if (force_series == 2490) {
584 quirks = &quirk_acer_travelmate_2490;
585 }
586
587 if (quirks == NULL)
588 quirks = &quirk_unknown;
589
590 set_quirks();
591}
592
593/*
594 * General interface convenience methods
595 */
596
597static bool has_cap(u32 cap)
598{
599 if ((interface->capability & cap) != 0)
600 return 1;
601
602 return 0;
603}
604
605/*
606 * AMW0 (V1) interface
607 */
608struct wmab_args {
609 u32 eax;
610 u32 ebx;
611 u32 ecx;
612 u32 edx;
613};
614
615struct wmab_ret {
616 u32 eax;
617 u32 ebx;
618 u32 ecx;
619 u32 edx;
620 u32 eex;
621};
622
623static acpi_status wmab_execute(struct wmab_args *regbuf,
624struct acpi_buffer *result)
625{
626 struct acpi_buffer input;
627 acpi_status status;
628 input.length = sizeof(struct wmab_args);
629 input.pointer = (u8 *)regbuf;
630
631 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
632
633 return status;
634}
635
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800636static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000637{
638 int err;
639 u8 result;
640
641 switch (cap) {
642 case ACER_CAP_MAILLED:
643 switch (quirks->mailled) {
644 default:
645 err = ec_read(0xA, &result);
646 if (err)
647 return AE_ERROR;
648 *value = (result >> 7) & 0x1;
649 return AE_OK;
650 }
651 break;
652 case ACER_CAP_WIRELESS:
653 switch (quirks->wireless) {
654 case 1:
655 err = ec_read(0x7B, &result);
656 if (err)
657 return AE_ERROR;
658 *value = result & 0x1;
659 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100660 case 2:
661 err = ec_read(0x71, &result);
662 if (err)
663 return AE_ERROR;
664 *value = result & 0x1;
665 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800666 case 3:
667 err = ec_read(0x78, &result);
668 if (err)
669 return AE_ERROR;
670 *value = result & 0x1;
671 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000672 default:
673 err = ec_read(0xA, &result);
674 if (err)
675 return AE_ERROR;
676 *value = (result >> 2) & 0x1;
677 return AE_OK;
678 }
679 break;
680 case ACER_CAP_BLUETOOTH:
681 switch (quirks->bluetooth) {
682 default:
683 err = ec_read(0xA, &result);
684 if (err)
685 return AE_ERROR;
686 *value = (result >> 4) & 0x1;
687 return AE_OK;
688 }
689 break;
690 case ACER_CAP_BRIGHTNESS:
691 switch (quirks->brightness) {
692 default:
693 err = ec_read(0x83, &result);
694 if (err)
695 return AE_ERROR;
696 *value = result;
697 return AE_OK;
698 }
699 break;
700 default:
Lin Ming08237972008-08-08 11:57:11 +0800701 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000702 }
703 return AE_OK;
704}
705
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800706static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000707{
708 struct wmab_args args;
709
710 args.eax = ACER_AMW0_WRITE;
711 args.ebx = value ? (1<<8) : 0;
712 args.ecx = args.edx = 0;
713
714 switch (cap) {
715 case ACER_CAP_MAILLED:
716 if (value > 1)
717 return AE_BAD_PARAMETER;
718 args.ebx |= ACER_AMW0_MAILLED_MASK;
719 break;
720 case ACER_CAP_WIRELESS:
721 if (value > 1)
722 return AE_BAD_PARAMETER;
723 args.ebx |= ACER_AMW0_WIRELESS_MASK;
724 break;
725 case ACER_CAP_BLUETOOTH:
726 if (value > 1)
727 return AE_BAD_PARAMETER;
728 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
729 break;
730 case ACER_CAP_BRIGHTNESS:
731 if (value > max_brightness)
732 return AE_BAD_PARAMETER;
733 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000734 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000735 return ec_write(0x83, value);
736 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000737 }
738 default:
Lin Ming08237972008-08-08 11:57:11 +0800739 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000740 }
741
742 /* Actually do the set */
743 return wmab_execute(&args, NULL);
744}
745
746static acpi_status AMW0_find_mailled(void)
747{
748 struct wmab_args args;
749 struct wmab_ret ret;
750 acpi_status status = AE_OK;
751 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
752 union acpi_object *obj;
753
754 args.eax = 0x86;
755 args.ebx = args.ecx = args.edx = 0;
756
757 status = wmab_execute(&args, &out);
758 if (ACPI_FAILURE(status))
759 return status;
760
761 obj = (union acpi_object *) out.pointer;
762 if (obj && obj->type == ACPI_TYPE_BUFFER &&
763 obj->buffer.length == sizeof(struct wmab_ret)) {
764 ret = *((struct wmab_ret *) obj->buffer.pointer);
765 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700766 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000767 return AE_ERROR;
768 }
769
770 if (ret.eex & 0x1)
771 interface->capability |= ACER_CAP_MAILLED;
772
773 kfree(out.pointer);
774
775 return AE_OK;
776}
777
Ike Panhc461e7432012-02-03 16:46:39 +0800778static int AMW0_set_cap_acpi_check_device_found;
779
780static acpi_status AMW0_set_cap_acpi_check_device_cb(acpi_handle handle,
781 u32 level, void *context, void **retval)
782{
783 AMW0_set_cap_acpi_check_device_found = 1;
784 return AE_OK;
785}
786
787static const struct acpi_device_id norfkill_ids[] = {
788 { "VPC2004", 0},
789 { "IBM0068", 0},
790 { "LEN0068", 0},
Lee, Chun-Yi5719b812012-03-23 12:36:44 +0800791 { "SNY5001", 0}, /* sony-laptop in charge */
Ike Panhc461e7432012-02-03 16:46:39 +0800792 { "", 0},
793};
794
795static int AMW0_set_cap_acpi_check_device(void)
796{
797 const struct acpi_device_id *id;
798
799 for (id = norfkill_ids; id->id[0]; id++)
800 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb,
801 NULL, NULL);
802 return AMW0_set_cap_acpi_check_device_found;
803}
804
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000805static acpi_status AMW0_set_capabilities(void)
806{
807 struct wmab_args args;
808 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700809 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000810 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
811 union acpi_object *obj;
812
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100813 /*
814 * On laptops with this strange GUID (non Acer), normal probing doesn't
815 * work.
816 */
817 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800818 if ((quirks != &quirk_unknown) ||
819 !AMW0_set_cap_acpi_check_device())
820 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100821 return AE_OK;
822 }
823
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000824 args.eax = ACER_AMW0_WRITE;
825 args.ecx = args.edx = 0;
826
827 args.ebx = 0xa2 << 8;
828 args.ebx |= ACER_AMW0_WIRELESS_MASK;
829
830 status = wmab_execute(&args, &out);
831 if (ACPI_FAILURE(status))
832 return status;
833
Axel Lin7677fbd2010-07-20 15:19:53 -0700834 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000835 if (obj && obj->type == ACPI_TYPE_BUFFER &&
836 obj->buffer.length == sizeof(struct wmab_ret)) {
837 ret = *((struct wmab_ret *) obj->buffer.pointer);
838 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700839 status = AE_ERROR;
840 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000841 }
842
843 if (ret.eax & 0x1)
844 interface->capability |= ACER_CAP_WIRELESS;
845
846 args.ebx = 2 << 8;
847 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
848
Axel Lin7677fbd2010-07-20 15:19:53 -0700849 /*
850 * It's ok to use existing buffer for next wmab_execute call.
851 * But we need to kfree(out.pointer) if next wmab_execute fail.
852 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000853 status = wmab_execute(&args, &out);
854 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700855 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000856
857 obj = (union acpi_object *) out.pointer;
858 if (obj && obj->type == ACPI_TYPE_BUFFER
859 && obj->buffer.length == sizeof(struct wmab_ret)) {
860 ret = *((struct wmab_ret *) obj->buffer.pointer);
861 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700862 status = AE_ERROR;
863 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000864 }
865
866 if (ret.eax & 0x1)
867 interface->capability |= ACER_CAP_BLUETOOTH;
868
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000869 /*
870 * This appears to be safe to enable, since all Wistron based laptops
871 * appear to use the same EC register for brightness, even if they
872 * differ for wireless, etc
873 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100874 if (quirks->brightness >= 0)
875 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000876
Axel Lin7677fbd2010-07-20 15:19:53 -0700877 status = AE_OK;
878out:
879 kfree(out.pointer);
880 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000881}
882
883static struct wmi_interface AMW0_interface = {
884 .type = ACER_AMW0,
885};
886
887static struct wmi_interface AMW0_V2_interface = {
888 .type = ACER_AMW0_V2,
889};
890
891/*
892 * New interface (The WMID interface)
893 */
894static acpi_status
895WMI_execute_u32(u32 method_id, u32 in, u32 *out)
896{
897 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
898 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
899 union acpi_object *obj;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800900 u32 tmp = 0;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000901 acpi_status status;
902
903 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
904
905 if (ACPI_FAILURE(status))
906 return status;
907
908 obj = (union acpi_object *) result.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800909 if (obj) {
910 if (obj->type == ACPI_TYPE_BUFFER &&
911 (obj->buffer.length == sizeof(u32) ||
912 obj->buffer.length == sizeof(u64))) {
913 tmp = *((u32 *) obj->buffer.pointer);
914 } else if (obj->type == ACPI_TYPE_INTEGER) {
915 tmp = (u32) obj->integer.value;
916 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000917 }
918
919 if (out)
920 *out = tmp;
921
922 kfree(result.pointer);
923
924 return status;
925}
926
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800927static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000928{
929 acpi_status status;
930 u8 tmp;
931 u32 result, method_id = 0;
932
933 switch (cap) {
934 case ACER_CAP_WIRELESS:
935 method_id = ACER_WMID_GET_WIRELESS_METHODID;
936 break;
937 case ACER_CAP_BLUETOOTH:
938 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
939 break;
940 case ACER_CAP_BRIGHTNESS:
941 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
942 break;
943 case ACER_CAP_THREEG:
944 method_id = ACER_WMID_GET_THREEG_METHODID;
945 break;
946 case ACER_CAP_MAILLED:
947 if (quirks->mailled == 1) {
948 ec_read(0x9f, &tmp);
949 *value = tmp & 0x1;
950 return 0;
951 }
952 default:
Lin Ming08237972008-08-08 11:57:11 +0800953 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000954 }
955 status = WMI_execute_u32(method_id, 0, &result);
956
957 if (ACPI_SUCCESS(status))
958 *value = (u8)result;
959
960 return status;
961}
962
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800963static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000964{
965 u32 method_id = 0;
966 char param;
967
968 switch (cap) {
969 case ACER_CAP_BRIGHTNESS:
970 if (value > max_brightness)
971 return AE_BAD_PARAMETER;
972 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
973 break;
974 case ACER_CAP_WIRELESS:
975 if (value > 1)
976 return AE_BAD_PARAMETER;
977 method_id = ACER_WMID_SET_WIRELESS_METHODID;
978 break;
979 case ACER_CAP_BLUETOOTH:
980 if (value > 1)
981 return AE_BAD_PARAMETER;
982 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
983 break;
984 case ACER_CAP_THREEG:
985 if (value > 1)
986 return AE_BAD_PARAMETER;
987 method_id = ACER_WMID_SET_THREEG_METHODID;
988 break;
989 case ACER_CAP_MAILLED:
990 if (value > 1)
991 return AE_BAD_PARAMETER;
992 if (quirks->mailled == 1) {
993 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700994 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000995 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700996 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000997 return 0;
998 }
999 break;
1000 default:
Lin Ming08237972008-08-08 11:57:11 +08001001 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001002 }
1003 return WMI_execute_u32(method_id, (u32)value, NULL);
1004}
1005
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001006static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1007{
1008 struct wmid3_gds_return_value return_value;
1009 acpi_status status;
1010 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001011 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001012 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001013 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001014 .devices = device,
1015 };
1016 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001017 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001018 &params
1019 };
1020 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1021
1022 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1023 if (ACPI_FAILURE(status))
1024 return status;
1025
1026 obj = output.pointer;
1027
1028 if (!obj)
1029 return AE_ERROR;
1030 else if (obj->type != ACPI_TYPE_BUFFER) {
1031 kfree(obj);
1032 return AE_ERROR;
1033 }
1034 if (obj->buffer.length != 8) {
1035 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1036 kfree(obj);
1037 return AE_ERROR;
1038 }
1039
1040 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1041 kfree(obj);
1042
1043 if (return_value.error_code || return_value.ec_return_value)
1044 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1045 device,
1046 return_value.error_code,
1047 return_value.ec_return_value);
1048 else
1049 *value = !!(return_value.devices & device);
1050
1051 return status;
1052}
1053
1054static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1055{
1056 u16 device;
1057
1058 switch (cap) {
1059 case ACER_CAP_WIRELESS:
1060 device = ACER_WMID3_GDS_WIRELESS;
1061 break;
1062 case ACER_CAP_BLUETOOTH:
1063 device = ACER_WMID3_GDS_BLUETOOTH;
1064 break;
1065 case ACER_CAP_THREEG:
1066 device = ACER_WMID3_GDS_THREEG;
1067 break;
1068 default:
1069 return AE_ERROR;
1070 }
1071 return wmid3_get_device_status(value, device);
1072}
1073
1074static acpi_status wmid3_set_device_status(u32 value, u16 device)
1075{
1076 struct wmid3_gds_return_value return_value;
1077 acpi_status status;
1078 union acpi_object *obj;
1079 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001080 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001081 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001082 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001083 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001084 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001085 struct acpi_buffer get_input = {
1086 sizeof(struct wmid3_gds_get_input_param),
1087 &get_params
1088 };
1089 struct wmid3_gds_set_input_param set_params = {
1090 .function_num = 0x2,
1091 .hotkey_number = commun_fn_key_number,
1092 .devices = commun_func_bitmap,
1093 };
1094 struct acpi_buffer set_input = {
1095 sizeof(struct wmid3_gds_set_input_param),
1096 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001097 };
1098 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1099 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1100
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001101 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001102 if (ACPI_FAILURE(status))
1103 return status;
1104
1105 obj = output.pointer;
1106
1107 if (!obj)
1108 return AE_ERROR;
1109 else if (obj->type != ACPI_TYPE_BUFFER) {
1110 kfree(obj);
1111 return AE_ERROR;
1112 }
1113 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001114 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001115 kfree(obj);
1116 return AE_ERROR;
1117 }
1118
1119 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1120 kfree(obj);
1121
1122 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001123 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1124 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001125 return_value.ec_return_value);
1126 return status;
1127 }
1128
1129 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001130 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001131
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001132 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001133 if (ACPI_FAILURE(status))
1134 return status;
1135
1136 obj = output2.pointer;
1137
1138 if (!obj)
1139 return AE_ERROR;
1140 else if (obj->type != ACPI_TYPE_BUFFER) {
1141 kfree(obj);
1142 return AE_ERROR;
1143 }
1144 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001145 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001146 kfree(obj);
1147 return AE_ERROR;
1148 }
1149
1150 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1151 kfree(obj);
1152
1153 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001154 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1155 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001156 return_value.ec_return_value);
1157
1158 return status;
1159}
1160
1161static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1162{
1163 u16 device;
1164
1165 switch (cap) {
1166 case ACER_CAP_WIRELESS:
1167 device = ACER_WMID3_GDS_WIRELESS;
1168 break;
1169 case ACER_CAP_BLUETOOTH:
1170 device = ACER_WMID3_GDS_BLUETOOTH;
1171 break;
1172 case ACER_CAP_THREEG:
1173 device = ACER_WMID3_GDS_THREEG;
1174 break;
1175 default:
1176 return AE_ERROR;
1177 }
1178 return wmid3_set_device_status(value, device);
1179}
1180
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001181static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1182{
1183 struct hotkey_function_type_aa *type_aa;
1184
1185 /* We are looking for OEM-specific Type AAh */
1186 if (header->type != 0xAA)
1187 return;
1188
1189 has_type_aa = true;
1190 type_aa = (struct hotkey_function_type_aa *) header;
1191
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001192 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001193 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001194 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001195
1196 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1197 interface->capability |= ACER_CAP_WIRELESS;
1198 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1199 interface->capability |= ACER_CAP_THREEG;
1200 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1201 interface->capability |= ACER_CAP_BLUETOOTH;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001202
1203 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001204}
1205
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001206static acpi_status WMID_set_capabilities(void)
1207{
1208 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1209 union acpi_object *obj;
1210 acpi_status status;
1211 u32 devices;
1212
1213 status = wmi_query_block(WMID_GUID2, 1, &out);
1214 if (ACPI_FAILURE(status))
1215 return status;
1216
1217 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001218 if (obj) {
1219 if (obj->type == ACPI_TYPE_BUFFER &&
1220 (obj->buffer.length == sizeof(u32) ||
1221 obj->buffer.length == sizeof(u64))) {
1222 devices = *((u32 *) obj->buffer.pointer);
1223 } else if (obj->type == ACPI_TYPE_INTEGER) {
1224 devices = (u32) obj->integer.value;
1225 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001226 } else {
Axel Lin66904862010-07-20 15:19:52 -07001227 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001228 return AE_ERROR;
1229 }
1230
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001231 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1232 if (devices & 0x07)
1233 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001234 if (devices & 0x40)
1235 interface->capability |= ACER_CAP_THREEG;
1236 if (devices & 0x10)
1237 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001238
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001239 if (!(devices & 0x20))
1240 max_brightness = 0x9;
1241
Axel Lin66904862010-07-20 15:19:52 -07001242 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001243 return status;
1244}
1245
1246static struct wmi_interface wmid_interface = {
1247 .type = ACER_WMID,
1248};
1249
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001250static struct wmi_interface wmid_v2_interface = {
1251 .type = ACER_WMID_v2,
1252};
1253
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001254/*
1255 * Generic Device (interface-independent)
1256 */
1257
1258static acpi_status get_u32(u32 *value, u32 cap)
1259{
Lin Ming08237972008-08-08 11:57:11 +08001260 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001261
1262 switch (interface->type) {
1263 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001264 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001265 break;
1266 case ACER_AMW0_V2:
1267 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001268 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001269 break;
1270 }
1271 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001272 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001273 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001274 case ACER_WMID_v2:
1275 if (cap & (ACER_CAP_WIRELESS |
1276 ACER_CAP_BLUETOOTH |
1277 ACER_CAP_THREEG))
1278 status = wmid_v2_get_u32(value, cap);
1279 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001280 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001281 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001282 }
1283
1284 return status;
1285}
1286
1287static acpi_status set_u32(u32 value, u32 cap)
1288{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001289 acpi_status status;
1290
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001291 if (interface->capability & cap) {
1292 switch (interface->type) {
1293 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001294 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001295 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001296 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001297 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001298
1299 /*
1300 * On some models, some WMID methods don't toggle
1301 * properly. For those cases, we want to run the AMW0
1302 * method afterwards to be certain we've really toggled
1303 * the device state.
1304 */
1305 if (cap == ACER_CAP_WIRELESS ||
1306 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001307 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001308 if (ACPI_FAILURE(status))
1309 return status;
1310
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001311 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001312 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001313 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001314 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001315 case ACER_WMID_v2:
1316 if (cap & (ACER_CAP_WIRELESS |
1317 ACER_CAP_BLUETOOTH |
1318 ACER_CAP_THREEG))
1319 return wmid_v2_set_u32(value, cap);
1320 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001321 return WMID_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001322 default:
1323 return AE_BAD_PARAMETER;
1324 }
1325 }
1326 return AE_BAD_PARAMETER;
1327}
1328
1329static void __init acer_commandline_init(void)
1330{
1331 /*
1332 * These will all fail silently if the value given is invalid, or the
1333 * capability isn't available on the given interface
1334 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001335 if (mailled >= 0)
1336 set_u32(mailled, ACER_CAP_MAILLED);
1337 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001338 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001339 if (brightness >= 0)
1340 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001341}
1342
1343/*
1344 * LED device (Mail LED only, no other LEDs known yet)
1345 */
1346static void mail_led_set(struct led_classdev *led_cdev,
1347enum led_brightness value)
1348{
1349 set_u32(value, ACER_CAP_MAILLED);
1350}
1351
1352static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001353 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001354 .brightness_set = mail_led_set,
1355};
1356
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001357static int acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001358{
1359 return led_classdev_register(dev, &mail_led);
1360}
1361
1362static void acer_led_exit(void)
1363{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001364 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001365 led_classdev_unregister(&mail_led);
1366}
1367
1368/*
1369 * Backlight device
1370 */
1371static struct backlight_device *acer_backlight_device;
1372
1373static int read_brightness(struct backlight_device *bd)
1374{
1375 u32 value;
1376 get_u32(&value, ACER_CAP_BRIGHTNESS);
1377 return value;
1378}
1379
1380static int update_bl_status(struct backlight_device *bd)
1381{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001382 int intensity = bd->props.brightness;
1383
1384 if (bd->props.power != FB_BLANK_UNBLANK)
1385 intensity = 0;
1386 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1387 intensity = 0;
1388
1389 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1390
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001391 return 0;
1392}
1393
Lionel Debrouxacc24722010-11-16 14:14:02 +01001394static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001395 .get_brightness = read_brightness,
1396 .update_status = update_bl_status,
1397};
1398
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001399static int acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001400{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001401 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001402 struct backlight_device *bd;
1403
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001404 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001405 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001406 props.max_brightness = max_brightness;
1407 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1408 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001409 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001410 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001411 acer_backlight_device = NULL;
1412 return PTR_ERR(bd);
1413 }
1414
1415 acer_backlight_device = bd;
1416
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001417 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001418 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001419 backlight_update_status(bd);
1420 return 0;
1421}
1422
Sam Ravnborg7560e382008-02-17 13:22:54 +01001423static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001424{
1425 backlight_device_unregister(acer_backlight_device);
1426}
1427
1428/*
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001429 * Accelerometer device
1430 */
1431static acpi_handle gsensor_handle;
1432
1433static int acer_gsensor_init(void)
1434{
1435 acpi_status status;
1436 struct acpi_buffer output;
1437 union acpi_object out_obj;
1438
1439 output.length = sizeof(out_obj);
1440 output.pointer = &out_obj;
1441 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1442 if (ACPI_FAILURE(status))
1443 return -1;
1444
1445 return 0;
1446}
1447
1448static int acer_gsensor_open(struct input_dev *input)
1449{
1450 return acer_gsensor_init();
1451}
1452
1453static int acer_gsensor_event(void)
1454{
1455 acpi_status status;
1456 struct acpi_buffer output;
1457 union acpi_object out_obj[5];
1458
1459 if (!has_cap(ACER_CAP_ACCEL))
1460 return -1;
1461
1462 output.length = sizeof(out_obj);
1463 output.pointer = out_obj;
1464
1465 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1466 if (ACPI_FAILURE(status))
1467 return -1;
1468
1469 if (out_obj->package.count != 4)
1470 return -1;
1471
1472 input_report_abs(acer_wmi_accel_dev, ABS_X,
1473 (s16)out_obj->package.elements[0].integer.value);
1474 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1475 (s16)out_obj->package.elements[1].integer.value);
1476 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1477 (s16)out_obj->package.elements[2].integer.value);
1478 input_sync(acer_wmi_accel_dev);
1479 return 0;
1480}
1481
1482/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001483 * Rfkill devices
1484 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001485static void acer_rfkill_update(struct work_struct *ignored);
1486static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1487static void acer_rfkill_update(struct work_struct *ignored)
1488{
1489 u32 state;
1490 acpi_status status;
1491
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001492 if (has_cap(ACER_CAP_WIRELESS)) {
1493 status = get_u32(&state, ACER_CAP_WIRELESS);
1494 if (ACPI_SUCCESS(status)) {
1495 if (quirks->wireless == 3)
1496 rfkill_set_hw_state(wireless_rfkill, !state);
1497 else
1498 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001499 }
1500 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001501
1502 if (has_cap(ACER_CAP_BLUETOOTH)) {
1503 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1504 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001505 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001506 }
1507
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001508 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001509 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001510 if (ACPI_SUCCESS(status))
1511 rfkill_set_sw_state(threeg_rfkill, !state);
1512 }
1513
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001514 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001515}
1516
Johannes Berg19d337d2009-06-02 13:01:37 +02001517static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001518{
1519 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001520 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001521
1522 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001523 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001524 if (ACPI_FAILURE(status))
1525 return -ENODEV;
1526 }
1527
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001528 return 0;
1529}
1530
Johannes Berg19d337d2009-06-02 13:01:37 +02001531static const struct rfkill_ops acer_rfkill_ops = {
1532 .set_block = acer_rfkill_set,
1533};
1534
1535static struct rfkill *acer_rfkill_register(struct device *dev,
1536 enum rfkill_type type,
1537 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001538{
1539 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001540 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001541 u32 state;
1542 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001543
Johannes Berg19d337d2009-06-02 13:01:37 +02001544 rfkill_dev = rfkill_alloc(name, dev, type,
1545 &acer_rfkill_ops,
1546 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001547 if (!rfkill_dev)
1548 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001549
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001550 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001551
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001552 err = rfkill_register(rfkill_dev);
1553 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001554 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001555 return ERR_PTR(err);
1556 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001557
1558 if (ACPI_SUCCESS(status))
1559 rfkill_set_sw_state(rfkill_dev, !state);
1560
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001561 return rfkill_dev;
1562}
1563
1564static int acer_rfkill_init(struct device *dev)
1565{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001566 int err;
1567
1568 if (has_cap(ACER_CAP_WIRELESS)) {
1569 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1570 "acer-wireless", ACER_CAP_WIRELESS);
1571 if (IS_ERR(wireless_rfkill)) {
1572 err = PTR_ERR(wireless_rfkill);
1573 goto error_wireless;
1574 }
1575 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001576
1577 if (has_cap(ACER_CAP_BLUETOOTH)) {
1578 bluetooth_rfkill = acer_rfkill_register(dev,
1579 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1580 ACER_CAP_BLUETOOTH);
1581 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001582 err = PTR_ERR(bluetooth_rfkill);
1583 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001584 }
1585 }
1586
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001587 if (has_cap(ACER_CAP_THREEG)) {
1588 threeg_rfkill = acer_rfkill_register(dev,
1589 RFKILL_TYPE_WWAN, "acer-threeg",
1590 ACER_CAP_THREEG);
1591 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001592 err = PTR_ERR(threeg_rfkill);
1593 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001594 }
1595 }
1596
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001597 rfkill_inited = true;
1598
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001599 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1600 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001601 schedule_delayed_work(&acer_rfkill_work,
1602 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001603
1604 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001605
1606error_threeg:
1607 if (has_cap(ACER_CAP_BLUETOOTH)) {
1608 rfkill_unregister(bluetooth_rfkill);
1609 rfkill_destroy(bluetooth_rfkill);
1610 }
1611error_bluetooth:
1612 if (has_cap(ACER_CAP_WIRELESS)) {
1613 rfkill_unregister(wireless_rfkill);
1614 rfkill_destroy(wireless_rfkill);
1615 }
1616error_wireless:
1617 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001618}
1619
1620static void acer_rfkill_exit(void)
1621{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001622 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1623 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001624 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001625
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001626 if (has_cap(ACER_CAP_WIRELESS)) {
1627 rfkill_unregister(wireless_rfkill);
1628 rfkill_destroy(wireless_rfkill);
1629 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001630
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001631 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001632 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001633 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001634 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001635
1636 if (has_cap(ACER_CAP_THREEG)) {
1637 rfkill_unregister(threeg_rfkill);
1638 rfkill_destroy(threeg_rfkill);
1639 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001640 return;
1641}
1642
1643/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001644 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001645 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001646static ssize_t show_bool_threeg(struct device *dev,
1647 struct device_attribute *attr, char *buf)
1648{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001649 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001650 acpi_status status;
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001651
Joe Perches6e71f382011-11-29 11:04:05 -08001652 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1653 current->comm);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001654 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001655 if (ACPI_SUCCESS(status))
1656 return sprintf(buf, "%u\n", result);
1657 return sprintf(buf, "Read error\n");
1658}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001659
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001660static ssize_t set_bool_threeg(struct device *dev,
1661 struct device_attribute *attr, const char *buf, size_t count)
1662{
1663 u32 tmp = simple_strtoul(buf, NULL, 10);
1664 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
Joe Perches6e71f382011-11-29 11:04:05 -08001665 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1666 current->comm);
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001667 if (ACPI_FAILURE(status))
1668 return -EINVAL;
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001669 return count;
1670}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001671static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001672 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001673
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001674static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1675 char *buf)
1676{
Joe Perches6e71f382011-11-29 11:04:05 -08001677 pr_info("This interface sysfs will be removed in 2012 - used by: %s\n",
1678 current->comm);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001679 switch (interface->type) {
1680 case ACER_AMW0:
1681 return sprintf(buf, "AMW0\n");
1682 case ACER_AMW0_V2:
1683 return sprintf(buf, "AMW0 v2\n");
1684 case ACER_WMID:
1685 return sprintf(buf, "WMID\n");
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001686 case ACER_WMID_v2:
1687 return sprintf(buf, "WMID v2\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001688 default:
1689 return sprintf(buf, "Error!\n");
1690 }
1691}
1692
Axel Lin370525d2010-06-30 10:20:23 +08001693static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001694
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001695static void acer_wmi_notify(u32 value, void *context)
1696{
1697 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1698 union acpi_object *obj;
1699 struct event_return_value return_value;
1700 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001701 u16 device_state;
1702 const struct key_entry *key;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001703 u32 scancode;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001704
1705 status = wmi_get_event_data(value, &response);
1706 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001707 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001708 return;
1709 }
1710
1711 obj = (union acpi_object *)response.pointer;
1712
1713 if (!obj)
1714 return;
1715 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001716 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001717 kfree(obj);
1718 return;
1719 }
1720 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001721 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001722 kfree(obj);
1723 return;
1724 }
1725
1726 return_value = *((struct event_return_value *)obj->buffer.pointer);
1727 kfree(obj);
1728
1729 switch (return_value.function) {
1730 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001731 device_state = return_value.device_state;
1732 pr_debug("device state: 0x%x\n", device_state);
1733
1734 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1735 return_value.key_num);
1736 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001737 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001738 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001739 } else {
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001740 scancode = return_value.key_num;
Seth Forshee92530662011-06-21 12:00:33 -05001741 switch (key->keycode) {
1742 case KEY_WLAN:
1743 case KEY_BLUETOOTH:
1744 if (has_cap(ACER_CAP_WIRELESS))
1745 rfkill_set_sw_state(wireless_rfkill,
1746 !(device_state & ACER_WMID3_GDS_WIRELESS));
1747 if (has_cap(ACER_CAP_THREEG))
1748 rfkill_set_sw_state(threeg_rfkill,
1749 !(device_state & ACER_WMID3_GDS_THREEG));
1750 if (has_cap(ACER_CAP_BLUETOOTH))
1751 rfkill_set_sw_state(bluetooth_rfkill,
1752 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1753 break;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001754 case KEY_TOUCHPAD_TOGGLE:
1755 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1756 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
Seth Forshee92530662011-06-21 12:00:33 -05001757 }
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001758 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
Seth Forshee92530662011-06-21 12:00:33 -05001759 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001760 break;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001761 case WMID_ACCEL_EVENT:
1762 acer_gsensor_event();
1763 break;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001764 default:
Joe Perches249c7202011-03-29 15:21:34 -07001765 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001766 return_value.function, return_value.key_num);
1767 break;
1768 }
1769}
1770
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001771static acpi_status
1772wmid3_set_lm_mode(struct lm_input_params *params,
1773 struct lm_return_value *return_value)
1774{
1775 acpi_status status;
1776 union acpi_object *obj;
1777
1778 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1779 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1780
1781 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1782 if (ACPI_FAILURE(status))
1783 return status;
1784
1785 obj = output.pointer;
1786
1787 if (!obj)
1788 return AE_ERROR;
1789 else if (obj->type != ACPI_TYPE_BUFFER) {
1790 kfree(obj);
1791 return AE_ERROR;
1792 }
1793 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001794 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001795 kfree(obj);
1796 return AE_ERROR;
1797 }
1798
1799 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1800 kfree(obj);
1801
1802 return status;
1803}
1804
1805static int acer_wmi_enable_ec_raw(void)
1806{
1807 struct lm_return_value return_value;
1808 acpi_status status;
1809 struct lm_input_params params = {
1810 .function_num = 0x1,
1811 .commun_devices = 0xFFFF,
1812 .devices = 0xFFFF,
1813 .lm_status = 0x00, /* Launch Manager Deactive */
1814 };
1815
1816 status = wmid3_set_lm_mode(&params, &return_value);
1817
1818 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001819 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1820 return_value.error_code,
1821 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001822 else
Joe Perches249c7202011-03-29 15:21:34 -07001823 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001824
1825 return status;
1826}
1827
1828static int acer_wmi_enable_lm(void)
1829{
1830 struct lm_return_value return_value;
1831 acpi_status status;
1832 struct lm_input_params params = {
1833 .function_num = 0x1,
1834 .commun_devices = 0xFFFF,
1835 .devices = 0xFFFF,
1836 .lm_status = 0x01, /* Launch Manager Active */
1837 };
1838
1839 status = wmid3_set_lm_mode(&params, &return_value);
1840
1841 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001842 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1843 return_value.error_code,
1844 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001845
1846 return status;
1847}
1848
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001849static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1850 void *ctx, void **retval)
1851{
1852 *(acpi_handle *)retval = ah;
1853 return AE_OK;
1854}
1855
1856static int __init acer_wmi_get_handle(const char *name, const char *prop,
1857 acpi_handle *ah)
1858{
1859 acpi_status status;
1860 acpi_handle handle;
1861
1862 BUG_ON(!name || !ah);
1863
Marek Vasut24237c42012-07-05 01:30:09 +02001864 handle = NULL;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001865 status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1866 (void *)name, &handle);
1867
1868 if (ACPI_SUCCESS(status)) {
1869 *ah = handle;
1870 return 0;
1871 } else {
1872 return -ENODEV;
1873 }
1874}
1875
1876static int __init acer_wmi_accel_setup(void)
1877{
1878 int err;
1879
1880 err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle);
1881 if (err)
1882 return err;
1883
1884 interface->capability |= ACER_CAP_ACCEL;
1885
1886 acer_wmi_accel_dev = input_allocate_device();
1887 if (!acer_wmi_accel_dev)
1888 return -ENOMEM;
1889
1890 acer_wmi_accel_dev->open = acer_gsensor_open;
1891
1892 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1893 acer_wmi_accel_dev->phys = "wmi/input1";
1894 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1895 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1896 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1897 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1898 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1899
1900 err = input_register_device(acer_wmi_accel_dev);
1901 if (err)
1902 goto err_free_dev;
1903
1904 return 0;
1905
1906err_free_dev:
1907 input_free_device(acer_wmi_accel_dev);
1908 return err;
1909}
1910
1911static void acer_wmi_accel_destroy(void)
1912{
1913 input_unregister_device(acer_wmi_accel_dev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001914}
1915
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001916static int __init acer_wmi_input_setup(void)
1917{
1918 acpi_status status;
1919 int err;
1920
1921 acer_wmi_input_dev = input_allocate_device();
1922 if (!acer_wmi_input_dev)
1923 return -ENOMEM;
1924
1925 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1926 acer_wmi_input_dev->phys = "wmi/input0";
1927 acer_wmi_input_dev->id.bustype = BUS_HOST;
1928
1929 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1930 if (err)
1931 goto err_free_dev;
1932
1933 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1934 acer_wmi_notify, NULL);
1935 if (ACPI_FAILURE(status)) {
1936 err = -EIO;
1937 goto err_free_keymap;
1938 }
1939
1940 err = input_register_device(acer_wmi_input_dev);
1941 if (err)
1942 goto err_uninstall_notifier;
1943
1944 return 0;
1945
1946err_uninstall_notifier:
1947 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1948err_free_keymap:
1949 sparse_keymap_free(acer_wmi_input_dev);
1950err_free_dev:
1951 input_free_device(acer_wmi_input_dev);
1952 return err;
1953}
1954
1955static void acer_wmi_input_destroy(void)
1956{
1957 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1958 sparse_keymap_free(acer_wmi_input_dev);
1959 input_unregister_device(acer_wmi_input_dev);
1960}
1961
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001962/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001963 * debugfs functions
1964 */
1965static u32 get_wmid_devices(void)
1966{
1967 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1968 union acpi_object *obj;
1969 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001970 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001971
1972 status = wmi_query_block(WMID_GUID2, 1, &out);
1973 if (ACPI_FAILURE(status))
1974 return 0;
1975
1976 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001977 if (obj) {
1978 if (obj->type == ACPI_TYPE_BUFFER &&
1979 (obj->buffer.length == sizeof(u32) ||
1980 obj->buffer.length == sizeof(u64))) {
1981 devices = *((u32 *) obj->buffer.pointer);
1982 } else if (obj->type == ACPI_TYPE_INTEGER) {
1983 devices = (u32) obj->integer.value;
1984 }
Carlos Corbacho81143522008-06-21 09:09:53 +01001985 }
Axel Lin66904862010-07-20 15:19:52 -07001986
1987 kfree(out.pointer);
1988 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001989}
1990
1991/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001992 * Platform device
1993 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001994static int acer_platform_probe(struct platform_device *device)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001995{
1996 int err;
1997
1998 if (has_cap(ACER_CAP_MAILLED)) {
1999 err = acer_led_init(&device->dev);
2000 if (err)
2001 goto error_mailled;
2002 }
2003
2004 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2005 err = acer_backlight_init(&device->dev);
2006 if (err)
2007 goto error_brightness;
2008 }
2009
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002010 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01002011 if (err)
2012 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002013
2014 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002015
Andy Whitcroft350e3292009-04-04 09:33:34 +01002016error_rfkill:
2017 if (has_cap(ACER_CAP_BRIGHTNESS))
2018 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002019error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01002020 if (has_cap(ACER_CAP_MAILLED))
2021 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002022error_mailled:
2023 return err;
2024}
2025
2026static int acer_platform_remove(struct platform_device *device)
2027{
2028 if (has_cap(ACER_CAP_MAILLED))
2029 acer_led_exit();
2030 if (has_cap(ACER_CAP_BRIGHTNESS))
2031 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002032
2033 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002034 return 0;
2035}
2036
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002037static int acer_suspend(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002038{
2039 u32 value;
2040 struct acer_data *data = &interface->data;
2041
2042 if (!data)
2043 return -ENOMEM;
2044
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002045 if (has_cap(ACER_CAP_MAILLED)) {
2046 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002047 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002048 data->mailled = value;
2049 }
2050
2051 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2052 get_u32(&value, ACER_CAP_BRIGHTNESS);
2053 data->brightness = value;
2054 }
2055
2056 return 0;
2057}
2058
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002059static int acer_resume(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002060{
2061 struct acer_data *data = &interface->data;
2062
2063 if (!data)
2064 return -ENOMEM;
2065
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002066 if (has_cap(ACER_CAP_MAILLED))
2067 set_u32(data->mailled, ACER_CAP_MAILLED);
2068
2069 if (has_cap(ACER_CAP_BRIGHTNESS))
2070 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2071
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002072 if (has_cap(ACER_CAP_ACCEL))
2073 acer_gsensor_init();
2074
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002075 return 0;
2076}
2077
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002078static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2079
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002080static void acer_platform_shutdown(struct platform_device *device)
2081{
2082 struct acer_data *data = &interface->data;
2083
2084 if (!data)
2085 return;
2086
2087 if (has_cap(ACER_CAP_MAILLED))
2088 set_u32(LED_OFF, ACER_CAP_MAILLED);
2089}
2090
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002091static struct platform_driver acer_platform_driver = {
2092 .driver = {
2093 .name = "acer-wmi",
2094 .owner = THIS_MODULE,
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002095 .pm = &acer_pm,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002096 },
2097 .probe = acer_platform_probe,
2098 .remove = acer_platform_remove,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002099 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002100};
2101
2102static struct platform_device *acer_platform_device;
2103
2104static int remove_sysfs(struct platform_device *device)
2105{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002106 if (has_cap(ACER_CAP_THREEG))
2107 device_remove_file(&device->dev, &dev_attr_threeg);
2108
2109 device_remove_file(&device->dev, &dev_attr_interface);
2110
2111 return 0;
2112}
2113
2114static int create_sysfs(void)
2115{
2116 int retval = -ENOMEM;
2117
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002118 if (has_cap(ACER_CAP_THREEG)) {
2119 retval = device_create_file(&acer_platform_device->dev,
2120 &dev_attr_threeg);
2121 if (retval)
2122 goto error_sysfs;
2123 }
2124
2125 retval = device_create_file(&acer_platform_device->dev,
2126 &dev_attr_interface);
2127 if (retval)
2128 goto error_sysfs;
2129
2130 return 0;
2131
2132error_sysfs:
2133 remove_sysfs(acer_platform_device);
2134 return retval;
2135}
2136
Carlos Corbacho81143522008-06-21 09:09:53 +01002137static void remove_debugfs(void)
2138{
2139 debugfs_remove(interface->debug.devices);
2140 debugfs_remove(interface->debug.root);
2141}
2142
2143static int create_debugfs(void)
2144{
2145 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2146 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002147 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01002148 return -ENOMEM;
2149 }
2150
2151 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2152 interface->debug.root,
2153 &interface->debug.wmid_devices);
2154 if (!interface->debug.devices)
2155 goto error_debugfs;
2156
2157 return 0;
2158
2159error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07002160 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01002161 return -ENOMEM;
2162}
2163
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002164static int __init acer_wmi_init(void)
2165{
2166 int err;
2167
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002168 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002169
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002170 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002171 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002172 return -ENODEV;
2173 }
2174
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01002175 find_quirks();
2176
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002177 /*
2178 * Detect which ACPI-WMI interface we're using.
2179 */
2180 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2181 interface = &AMW0_V2_interface;
2182
2183 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2184 interface = &wmid_interface;
2185
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002186 if (wmi_has_guid(WMID_GUID3))
2187 interface = &wmid_v2_interface;
2188
2189 if (interface)
2190 dmi_walk(type_aa_dmi_decode, NULL);
2191
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002192 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002193 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002194 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002195 return -ENODEV;
2196 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002197 /* WMID always provides brightness methods */
2198 interface->capability |= ACER_CAP_BRIGHTNESS;
2199 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002200 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002201 return -ENODEV;
2202 }
2203
2204 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2205 interface = &AMW0_interface;
2206
2207 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002208 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002209 return -ENODEV;
2210 }
2211 }
2212
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002213 if (wmi_has_guid(AMW0_GUID1))
2214 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002215
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002216 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002217 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002218 return -ENODEV;
2219 }
2220
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002221 set_quirks();
2222
Corentin Charya60b2172012-06-13 09:32:02 +02002223 if (dmi_check_system(video_vendor_dmi_table))
2224 acpi_video_dmi_promote_vendor();
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002225 if (acpi_video_backlight_support()) {
Corentin Charya60b2172012-06-13 09:32:02 +02002226 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2227 pr_info("Brightness must be controlled by acpi video driver\n");
2228 } else {
Corentin Charya60b2172012-06-13 09:32:02 +02002229 pr_info("Disabling ACPI video driver\n");
2230 acpi_video_unregister();
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002231 }
2232
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002233 if (wmi_has_guid(WMID_GUID3)) {
2234 if (ec_raw_mode) {
2235 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002236 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002237 return -ENODEV;
2238 }
2239 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002240 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002241 return -ENODEV;
2242 }
2243 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002244 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002245 }
2246
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002247 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2248 err = acer_wmi_input_setup();
2249 if (err)
2250 return err;
2251 }
2252
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002253 acer_wmi_accel_setup();
2254
Axel Lin1c796322010-06-22 16:17:38 +08002255 err = platform_driver_register(&acer_platform_driver);
2256 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002257 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002258 goto error_platform_register;
2259 }
Axel Lin1c796322010-06-22 16:17:38 +08002260
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002261 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002262 if (!acer_platform_device) {
2263 err = -ENOMEM;
2264 goto error_device_alloc;
2265 }
2266
2267 err = platform_device_add(acer_platform_device);
2268 if (err)
2269 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002270
2271 err = create_sysfs();
2272 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002273 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002274
Carlos Corbacho81143522008-06-21 09:09:53 +01002275 if (wmi_has_guid(WMID_GUID2)) {
2276 interface->debug.wmid_devices = get_wmid_devices();
2277 err = create_debugfs();
2278 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002279 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002280 }
2281
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002282 /* Override any initial settings with values from the commandline */
2283 acer_commandline_init();
2284
2285 return 0;
2286
Axel Lin1c796322010-06-22 16:17:38 +08002287error_create_debugfs:
2288 remove_sysfs(acer_platform_device);
2289error_create_sys:
2290 platform_device_del(acer_platform_device);
2291error_device_add:
2292 platform_device_put(acer_platform_device);
2293error_device_alloc:
2294 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002295error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002296 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2297 acer_wmi_input_destroy();
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002298 if (has_cap(ACER_CAP_ACCEL))
2299 acer_wmi_accel_destroy();
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002300
Axel Lin1c796322010-06-22 16:17:38 +08002301 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002302}
2303
2304static void __exit acer_wmi_exit(void)
2305{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002306 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2307 acer_wmi_input_destroy();
2308
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002309 if (has_cap(ACER_CAP_ACCEL))
2310 acer_wmi_accel_destroy();
2311
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002312 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07002313 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002314 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002315 platform_driver_unregister(&acer_platform_driver);
2316
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002317 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002318 return;
2319}
2320
2321module_init(acer_wmi_init);
2322module_exit(acer_wmi_exit);