blob: c91f69b39db4b8c637d5182eb5f8f85aed1bf79b [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
99static const struct key_entry acer_wmi_keymap[] = {
100 {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
297static void set_quirks(void)
298{
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
309static int dmi_matched(const struct dmi_system_id *dmi)
310{
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 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800340static struct dmi_system_id acer_blacklist[] = {
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
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000358static struct dmi_system_id acer_quirks[] = {
359 {
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
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400533static int video_set_backlight_video_vendor(const struct dmi_system_id *d)
534{
535 interface->capability &= ~ACER_CAP_BRIGHTNESS;
536 pr_info("Brightness must be controlled by generic video driver\n");
537 return 0;
538}
539
540static const struct dmi_system_id video_vendor_dmi_table[] = {
541 {
542 .callback = video_set_backlight_video_vendor,
543 .ident = "Acer TravelMate 4750",
544 .matches = {
545 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
546 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
547 },
548 },
Lee, Chun-Yi050eff32012-05-21 23:19:51 +0800549 {
550 .callback = video_set_backlight_video_vendor,
551 .ident = "Acer Extensa 5235",
552 .matches = {
553 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
554 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
555 },
556 },
557 {
558 .callback = video_set_backlight_video_vendor,
559 .ident = "Acer TravelMate 5760",
560 .matches = {
561 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
562 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
563 },
564 },
565 {
566 .callback = video_set_backlight_video_vendor,
567 .ident = "Acer Aspire 5750",
568 .matches = {
569 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
570 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
571 },
572 },
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400573 {}
574};
575
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000576/* Find which quirks are needed for a particular vendor/ model pair */
577static void find_quirks(void)
578{
579 if (!force_series) {
580 dmi_check_system(acer_quirks);
581 } else if (force_series == 2490) {
582 quirks = &quirk_acer_travelmate_2490;
583 }
584
585 if (quirks == NULL)
586 quirks = &quirk_unknown;
587
588 set_quirks();
589}
590
591/*
592 * General interface convenience methods
593 */
594
595static bool has_cap(u32 cap)
596{
597 if ((interface->capability & cap) != 0)
598 return 1;
599
600 return 0;
601}
602
603/*
604 * AMW0 (V1) interface
605 */
606struct wmab_args {
607 u32 eax;
608 u32 ebx;
609 u32 ecx;
610 u32 edx;
611};
612
613struct wmab_ret {
614 u32 eax;
615 u32 ebx;
616 u32 ecx;
617 u32 edx;
618 u32 eex;
619};
620
621static acpi_status wmab_execute(struct wmab_args *regbuf,
622struct acpi_buffer *result)
623{
624 struct acpi_buffer input;
625 acpi_status status;
626 input.length = sizeof(struct wmab_args);
627 input.pointer = (u8 *)regbuf;
628
629 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
630
631 return status;
632}
633
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800634static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000635{
636 int err;
637 u8 result;
638
639 switch (cap) {
640 case ACER_CAP_MAILLED:
641 switch (quirks->mailled) {
642 default:
643 err = ec_read(0xA, &result);
644 if (err)
645 return AE_ERROR;
646 *value = (result >> 7) & 0x1;
647 return AE_OK;
648 }
649 break;
650 case ACER_CAP_WIRELESS:
651 switch (quirks->wireless) {
652 case 1:
653 err = ec_read(0x7B, &result);
654 if (err)
655 return AE_ERROR;
656 *value = result & 0x1;
657 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100658 case 2:
659 err = ec_read(0x71, &result);
660 if (err)
661 return AE_ERROR;
662 *value = result & 0x1;
663 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800664 case 3:
665 err = ec_read(0x78, &result);
666 if (err)
667 return AE_ERROR;
668 *value = result & 0x1;
669 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000670 default:
671 err = ec_read(0xA, &result);
672 if (err)
673 return AE_ERROR;
674 *value = (result >> 2) & 0x1;
675 return AE_OK;
676 }
677 break;
678 case ACER_CAP_BLUETOOTH:
679 switch (quirks->bluetooth) {
680 default:
681 err = ec_read(0xA, &result);
682 if (err)
683 return AE_ERROR;
684 *value = (result >> 4) & 0x1;
685 return AE_OK;
686 }
687 break;
688 case ACER_CAP_BRIGHTNESS:
689 switch (quirks->brightness) {
690 default:
691 err = ec_read(0x83, &result);
692 if (err)
693 return AE_ERROR;
694 *value = result;
695 return AE_OK;
696 }
697 break;
698 default:
Lin Ming08237972008-08-08 11:57:11 +0800699 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000700 }
701 return AE_OK;
702}
703
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800704static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000705{
706 struct wmab_args args;
707
708 args.eax = ACER_AMW0_WRITE;
709 args.ebx = value ? (1<<8) : 0;
710 args.ecx = args.edx = 0;
711
712 switch (cap) {
713 case ACER_CAP_MAILLED:
714 if (value > 1)
715 return AE_BAD_PARAMETER;
716 args.ebx |= ACER_AMW0_MAILLED_MASK;
717 break;
718 case ACER_CAP_WIRELESS:
719 if (value > 1)
720 return AE_BAD_PARAMETER;
721 args.ebx |= ACER_AMW0_WIRELESS_MASK;
722 break;
723 case ACER_CAP_BLUETOOTH:
724 if (value > 1)
725 return AE_BAD_PARAMETER;
726 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
727 break;
728 case ACER_CAP_BRIGHTNESS:
729 if (value > max_brightness)
730 return AE_BAD_PARAMETER;
731 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000732 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000733 return ec_write(0x83, value);
734 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000735 }
736 default:
Lin Ming08237972008-08-08 11:57:11 +0800737 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000738 }
739
740 /* Actually do the set */
741 return wmab_execute(&args, NULL);
742}
743
744static acpi_status AMW0_find_mailled(void)
745{
746 struct wmab_args args;
747 struct wmab_ret ret;
748 acpi_status status = AE_OK;
749 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
750 union acpi_object *obj;
751
752 args.eax = 0x86;
753 args.ebx = args.ecx = args.edx = 0;
754
755 status = wmab_execute(&args, &out);
756 if (ACPI_FAILURE(status))
757 return status;
758
759 obj = (union acpi_object *) out.pointer;
760 if (obj && obj->type == ACPI_TYPE_BUFFER &&
761 obj->buffer.length == sizeof(struct wmab_ret)) {
762 ret = *((struct wmab_ret *) obj->buffer.pointer);
763 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700764 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000765 return AE_ERROR;
766 }
767
768 if (ret.eex & 0x1)
769 interface->capability |= ACER_CAP_MAILLED;
770
771 kfree(out.pointer);
772
773 return AE_OK;
774}
775
Ike Panhc461e7432012-02-03 16:46:39 +0800776static int AMW0_set_cap_acpi_check_device_found;
777
778static acpi_status AMW0_set_cap_acpi_check_device_cb(acpi_handle handle,
779 u32 level, void *context, void **retval)
780{
781 AMW0_set_cap_acpi_check_device_found = 1;
782 return AE_OK;
783}
784
785static const struct acpi_device_id norfkill_ids[] = {
786 { "VPC2004", 0},
787 { "IBM0068", 0},
788 { "LEN0068", 0},
Lee, Chun-Yi5719b812012-03-23 12:36:44 +0800789 { "SNY5001", 0}, /* sony-laptop in charge */
Ike Panhc461e7432012-02-03 16:46:39 +0800790 { "", 0},
791};
792
793static int AMW0_set_cap_acpi_check_device(void)
794{
795 const struct acpi_device_id *id;
796
797 for (id = norfkill_ids; id->id[0]; id++)
798 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb,
799 NULL, NULL);
800 return AMW0_set_cap_acpi_check_device_found;
801}
802
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000803static acpi_status AMW0_set_capabilities(void)
804{
805 struct wmab_args args;
806 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700807 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000808 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
809 union acpi_object *obj;
810
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100811 /*
812 * On laptops with this strange GUID (non Acer), normal probing doesn't
813 * work.
814 */
815 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800816 if ((quirks != &quirk_unknown) ||
817 !AMW0_set_cap_acpi_check_device())
818 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100819 return AE_OK;
820 }
821
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000822 args.eax = ACER_AMW0_WRITE;
823 args.ecx = args.edx = 0;
824
825 args.ebx = 0xa2 << 8;
826 args.ebx |= ACER_AMW0_WIRELESS_MASK;
827
828 status = wmab_execute(&args, &out);
829 if (ACPI_FAILURE(status))
830 return status;
831
Axel Lin7677fbd2010-07-20 15:19:53 -0700832 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000833 if (obj && obj->type == ACPI_TYPE_BUFFER &&
834 obj->buffer.length == sizeof(struct wmab_ret)) {
835 ret = *((struct wmab_ret *) obj->buffer.pointer);
836 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700837 status = AE_ERROR;
838 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000839 }
840
841 if (ret.eax & 0x1)
842 interface->capability |= ACER_CAP_WIRELESS;
843
844 args.ebx = 2 << 8;
845 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
846
Axel Lin7677fbd2010-07-20 15:19:53 -0700847 /*
848 * It's ok to use existing buffer for next wmab_execute call.
849 * But we need to kfree(out.pointer) if next wmab_execute fail.
850 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000851 status = wmab_execute(&args, &out);
852 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700853 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000854
855 obj = (union acpi_object *) out.pointer;
856 if (obj && obj->type == ACPI_TYPE_BUFFER
857 && obj->buffer.length == sizeof(struct wmab_ret)) {
858 ret = *((struct wmab_ret *) obj->buffer.pointer);
859 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700860 status = AE_ERROR;
861 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000862 }
863
864 if (ret.eax & 0x1)
865 interface->capability |= ACER_CAP_BLUETOOTH;
866
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000867 /*
868 * This appears to be safe to enable, since all Wistron based laptops
869 * appear to use the same EC register for brightness, even if they
870 * differ for wireless, etc
871 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100872 if (quirks->brightness >= 0)
873 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000874
Axel Lin7677fbd2010-07-20 15:19:53 -0700875 status = AE_OK;
876out:
877 kfree(out.pointer);
878 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000879}
880
881static struct wmi_interface AMW0_interface = {
882 .type = ACER_AMW0,
883};
884
885static struct wmi_interface AMW0_V2_interface = {
886 .type = ACER_AMW0_V2,
887};
888
889/*
890 * New interface (The WMID interface)
891 */
892static acpi_status
893WMI_execute_u32(u32 method_id, u32 in, u32 *out)
894{
895 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
896 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
897 union acpi_object *obj;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800898 u32 tmp = 0;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000899 acpi_status status;
900
901 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
902
903 if (ACPI_FAILURE(status))
904 return status;
905
906 obj = (union acpi_object *) result.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800907 if (obj) {
908 if (obj->type == ACPI_TYPE_BUFFER &&
909 (obj->buffer.length == sizeof(u32) ||
910 obj->buffer.length == sizeof(u64))) {
911 tmp = *((u32 *) obj->buffer.pointer);
912 } else if (obj->type == ACPI_TYPE_INTEGER) {
913 tmp = (u32) obj->integer.value;
914 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000915 }
916
917 if (out)
918 *out = tmp;
919
920 kfree(result.pointer);
921
922 return status;
923}
924
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800925static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000926{
927 acpi_status status;
928 u8 tmp;
929 u32 result, method_id = 0;
930
931 switch (cap) {
932 case ACER_CAP_WIRELESS:
933 method_id = ACER_WMID_GET_WIRELESS_METHODID;
934 break;
935 case ACER_CAP_BLUETOOTH:
936 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
937 break;
938 case ACER_CAP_BRIGHTNESS:
939 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
940 break;
941 case ACER_CAP_THREEG:
942 method_id = ACER_WMID_GET_THREEG_METHODID;
943 break;
944 case ACER_CAP_MAILLED:
945 if (quirks->mailled == 1) {
946 ec_read(0x9f, &tmp);
947 *value = tmp & 0x1;
948 return 0;
949 }
950 default:
Lin Ming08237972008-08-08 11:57:11 +0800951 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000952 }
953 status = WMI_execute_u32(method_id, 0, &result);
954
955 if (ACPI_SUCCESS(status))
956 *value = (u8)result;
957
958 return status;
959}
960
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800961static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000962{
963 u32 method_id = 0;
964 char param;
965
966 switch (cap) {
967 case ACER_CAP_BRIGHTNESS:
968 if (value > max_brightness)
969 return AE_BAD_PARAMETER;
970 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
971 break;
972 case ACER_CAP_WIRELESS:
973 if (value > 1)
974 return AE_BAD_PARAMETER;
975 method_id = ACER_WMID_SET_WIRELESS_METHODID;
976 break;
977 case ACER_CAP_BLUETOOTH:
978 if (value > 1)
979 return AE_BAD_PARAMETER;
980 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
981 break;
982 case ACER_CAP_THREEG:
983 if (value > 1)
984 return AE_BAD_PARAMETER;
985 method_id = ACER_WMID_SET_THREEG_METHODID;
986 break;
987 case ACER_CAP_MAILLED:
988 if (value > 1)
989 return AE_BAD_PARAMETER;
990 if (quirks->mailled == 1) {
991 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700992 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000993 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700994 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000995 return 0;
996 }
997 break;
998 default:
Lin Ming08237972008-08-08 11:57:11 +0800999 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001000 }
1001 return WMI_execute_u32(method_id, (u32)value, NULL);
1002}
1003
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001004static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1005{
1006 struct wmid3_gds_return_value return_value;
1007 acpi_status status;
1008 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001009 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001010 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001011 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001012 .devices = device,
1013 };
1014 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001015 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001016 &params
1017 };
1018 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1019
1020 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1021 if (ACPI_FAILURE(status))
1022 return status;
1023
1024 obj = output.pointer;
1025
1026 if (!obj)
1027 return AE_ERROR;
1028 else if (obj->type != ACPI_TYPE_BUFFER) {
1029 kfree(obj);
1030 return AE_ERROR;
1031 }
1032 if (obj->buffer.length != 8) {
1033 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1034 kfree(obj);
1035 return AE_ERROR;
1036 }
1037
1038 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1039 kfree(obj);
1040
1041 if (return_value.error_code || return_value.ec_return_value)
1042 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1043 device,
1044 return_value.error_code,
1045 return_value.ec_return_value);
1046 else
1047 *value = !!(return_value.devices & device);
1048
1049 return status;
1050}
1051
1052static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1053{
1054 u16 device;
1055
1056 switch (cap) {
1057 case ACER_CAP_WIRELESS:
1058 device = ACER_WMID3_GDS_WIRELESS;
1059 break;
1060 case ACER_CAP_BLUETOOTH:
1061 device = ACER_WMID3_GDS_BLUETOOTH;
1062 break;
1063 case ACER_CAP_THREEG:
1064 device = ACER_WMID3_GDS_THREEG;
1065 break;
1066 default:
1067 return AE_ERROR;
1068 }
1069 return wmid3_get_device_status(value, device);
1070}
1071
1072static acpi_status wmid3_set_device_status(u32 value, u16 device)
1073{
1074 struct wmid3_gds_return_value return_value;
1075 acpi_status status;
1076 union acpi_object *obj;
1077 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001078 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001079 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001080 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001081 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001082 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001083 struct acpi_buffer get_input = {
1084 sizeof(struct wmid3_gds_get_input_param),
1085 &get_params
1086 };
1087 struct wmid3_gds_set_input_param set_params = {
1088 .function_num = 0x2,
1089 .hotkey_number = commun_fn_key_number,
1090 .devices = commun_func_bitmap,
1091 };
1092 struct acpi_buffer set_input = {
1093 sizeof(struct wmid3_gds_set_input_param),
1094 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001095 };
1096 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1097 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1098
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001099 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001100 if (ACPI_FAILURE(status))
1101 return status;
1102
1103 obj = output.pointer;
1104
1105 if (!obj)
1106 return AE_ERROR;
1107 else if (obj->type != ACPI_TYPE_BUFFER) {
1108 kfree(obj);
1109 return AE_ERROR;
1110 }
1111 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001112 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001113 kfree(obj);
1114 return AE_ERROR;
1115 }
1116
1117 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1118 kfree(obj);
1119
1120 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001121 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1122 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001123 return_value.ec_return_value);
1124 return status;
1125 }
1126
1127 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001128 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001129
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001130 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001131 if (ACPI_FAILURE(status))
1132 return status;
1133
1134 obj = output2.pointer;
1135
1136 if (!obj)
1137 return AE_ERROR;
1138 else if (obj->type != ACPI_TYPE_BUFFER) {
1139 kfree(obj);
1140 return AE_ERROR;
1141 }
1142 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001143 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001144 kfree(obj);
1145 return AE_ERROR;
1146 }
1147
1148 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1149 kfree(obj);
1150
1151 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001152 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1153 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001154 return_value.ec_return_value);
1155
1156 return status;
1157}
1158
1159static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1160{
1161 u16 device;
1162
1163 switch (cap) {
1164 case ACER_CAP_WIRELESS:
1165 device = ACER_WMID3_GDS_WIRELESS;
1166 break;
1167 case ACER_CAP_BLUETOOTH:
1168 device = ACER_WMID3_GDS_BLUETOOTH;
1169 break;
1170 case ACER_CAP_THREEG:
1171 device = ACER_WMID3_GDS_THREEG;
1172 break;
1173 default:
1174 return AE_ERROR;
1175 }
1176 return wmid3_set_device_status(value, device);
1177}
1178
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001179static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1180{
1181 struct hotkey_function_type_aa *type_aa;
1182
1183 /* We are looking for OEM-specific Type AAh */
1184 if (header->type != 0xAA)
1185 return;
1186
1187 has_type_aa = true;
1188 type_aa = (struct hotkey_function_type_aa *) header;
1189
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001190 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001191 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001192 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001193
1194 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1195 interface->capability |= ACER_CAP_WIRELESS;
1196 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1197 interface->capability |= ACER_CAP_THREEG;
1198 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1199 interface->capability |= ACER_CAP_BLUETOOTH;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001200
1201 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001202}
1203
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001204static acpi_status WMID_set_capabilities(void)
1205{
1206 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1207 union acpi_object *obj;
1208 acpi_status status;
1209 u32 devices;
1210
1211 status = wmi_query_block(WMID_GUID2, 1, &out);
1212 if (ACPI_FAILURE(status))
1213 return status;
1214
1215 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001216 if (obj) {
1217 if (obj->type == ACPI_TYPE_BUFFER &&
1218 (obj->buffer.length == sizeof(u32) ||
1219 obj->buffer.length == sizeof(u64))) {
1220 devices = *((u32 *) obj->buffer.pointer);
1221 } else if (obj->type == ACPI_TYPE_INTEGER) {
1222 devices = (u32) obj->integer.value;
Lee, Chun-Yif24c96e2013-01-03 10:37:45 +08001223 } else {
1224 kfree(out.pointer);
1225 return AE_ERROR;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001226 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001227 } else {
Axel Lin66904862010-07-20 15:19:52 -07001228 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001229 return AE_ERROR;
1230 }
1231
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001232 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1233 if (devices & 0x07)
1234 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001235 if (devices & 0x40)
1236 interface->capability |= ACER_CAP_THREEG;
1237 if (devices & 0x10)
1238 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001239
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001240 if (!(devices & 0x20))
1241 max_brightness = 0x9;
1242
Axel Lin66904862010-07-20 15:19:52 -07001243 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001244 return status;
1245}
1246
1247static struct wmi_interface wmid_interface = {
1248 .type = ACER_WMID,
1249};
1250
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001251static struct wmi_interface wmid_v2_interface = {
1252 .type = ACER_WMID_v2,
1253};
1254
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001255/*
1256 * Generic Device (interface-independent)
1257 */
1258
1259static acpi_status get_u32(u32 *value, u32 cap)
1260{
Lin Ming08237972008-08-08 11:57:11 +08001261 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001262
1263 switch (interface->type) {
1264 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001265 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001266 break;
1267 case ACER_AMW0_V2:
1268 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001269 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001270 break;
1271 }
1272 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001273 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001274 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001275 case ACER_WMID_v2:
1276 if (cap & (ACER_CAP_WIRELESS |
1277 ACER_CAP_BLUETOOTH |
1278 ACER_CAP_THREEG))
1279 status = wmid_v2_get_u32(value, cap);
1280 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001281 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001282 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001283 }
1284
1285 return status;
1286}
1287
1288static acpi_status set_u32(u32 value, u32 cap)
1289{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001290 acpi_status status;
1291
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001292 if (interface->capability & cap) {
1293 switch (interface->type) {
1294 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001295 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001296 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001297 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001298 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001299
1300 /*
1301 * On some models, some WMID methods don't toggle
1302 * properly. For those cases, we want to run the AMW0
1303 * method afterwards to be certain we've really toggled
1304 * the device state.
1305 */
1306 if (cap == ACER_CAP_WIRELESS ||
1307 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001308 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001309 if (ACPI_FAILURE(status))
1310 return status;
1311
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001312 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001313 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001314 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001315 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001316 case ACER_WMID_v2:
1317 if (cap & (ACER_CAP_WIRELESS |
1318 ACER_CAP_BLUETOOTH |
1319 ACER_CAP_THREEG))
1320 return wmid_v2_set_u32(value, cap);
1321 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001322 return WMID_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001323 default:
1324 return AE_BAD_PARAMETER;
1325 }
1326 }
1327 return AE_BAD_PARAMETER;
1328}
1329
1330static void __init acer_commandline_init(void)
1331{
1332 /*
1333 * These will all fail silently if the value given is invalid, or the
1334 * capability isn't available on the given interface
1335 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001336 if (mailled >= 0)
1337 set_u32(mailled, ACER_CAP_MAILLED);
1338 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001339 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001340 if (brightness >= 0)
1341 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001342}
1343
1344/*
1345 * LED device (Mail LED only, no other LEDs known yet)
1346 */
1347static void mail_led_set(struct led_classdev *led_cdev,
1348enum led_brightness value)
1349{
1350 set_u32(value, ACER_CAP_MAILLED);
1351}
1352
1353static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001354 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001355 .brightness_set = mail_led_set,
1356};
1357
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001358static int acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001359{
1360 return led_classdev_register(dev, &mail_led);
1361}
1362
1363static void acer_led_exit(void)
1364{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001365 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001366 led_classdev_unregister(&mail_led);
1367}
1368
1369/*
1370 * Backlight device
1371 */
1372static struct backlight_device *acer_backlight_device;
1373
1374static int read_brightness(struct backlight_device *bd)
1375{
1376 u32 value;
1377 get_u32(&value, ACER_CAP_BRIGHTNESS);
1378 return value;
1379}
1380
1381static int update_bl_status(struct backlight_device *bd)
1382{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001383 int intensity = bd->props.brightness;
1384
1385 if (bd->props.power != FB_BLANK_UNBLANK)
1386 intensity = 0;
1387 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1388 intensity = 0;
1389
1390 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1391
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001392 return 0;
1393}
1394
Lionel Debrouxacc24722010-11-16 14:14:02 +01001395static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001396 .get_brightness = read_brightness,
1397 .update_status = update_bl_status,
1398};
1399
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001400static int acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001401{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001402 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001403 struct backlight_device *bd;
1404
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001405 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001406 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001407 props.max_brightness = max_brightness;
1408 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1409 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001410 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001411 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001412 acer_backlight_device = NULL;
1413 return PTR_ERR(bd);
1414 }
1415
1416 acer_backlight_device = bd;
1417
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001418 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001419 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001420 backlight_update_status(bd);
1421 return 0;
1422}
1423
Sam Ravnborg7560e382008-02-17 13:22:54 +01001424static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001425{
1426 backlight_device_unregister(acer_backlight_device);
1427}
1428
1429/*
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001430 * Accelerometer device
1431 */
1432static acpi_handle gsensor_handle;
1433
1434static int acer_gsensor_init(void)
1435{
1436 acpi_status status;
1437 struct acpi_buffer output;
1438 union acpi_object out_obj;
1439
1440 output.length = sizeof(out_obj);
1441 output.pointer = &out_obj;
1442 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1443 if (ACPI_FAILURE(status))
1444 return -1;
1445
1446 return 0;
1447}
1448
1449static int acer_gsensor_open(struct input_dev *input)
1450{
1451 return acer_gsensor_init();
1452}
1453
1454static int acer_gsensor_event(void)
1455{
1456 acpi_status status;
1457 struct acpi_buffer output;
1458 union acpi_object out_obj[5];
1459
1460 if (!has_cap(ACER_CAP_ACCEL))
1461 return -1;
1462
1463 output.length = sizeof(out_obj);
1464 output.pointer = out_obj;
1465
1466 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1467 if (ACPI_FAILURE(status))
1468 return -1;
1469
1470 if (out_obj->package.count != 4)
1471 return -1;
1472
1473 input_report_abs(acer_wmi_accel_dev, ABS_X,
1474 (s16)out_obj->package.elements[0].integer.value);
1475 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1476 (s16)out_obj->package.elements[1].integer.value);
1477 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1478 (s16)out_obj->package.elements[2].integer.value);
1479 input_sync(acer_wmi_accel_dev);
1480 return 0;
1481}
1482
1483/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001484 * Rfkill devices
1485 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001486static void acer_rfkill_update(struct work_struct *ignored);
1487static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1488static void acer_rfkill_update(struct work_struct *ignored)
1489{
1490 u32 state;
1491 acpi_status status;
1492
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001493 if (has_cap(ACER_CAP_WIRELESS)) {
1494 status = get_u32(&state, ACER_CAP_WIRELESS);
1495 if (ACPI_SUCCESS(status)) {
1496 if (quirks->wireless == 3)
1497 rfkill_set_hw_state(wireless_rfkill, !state);
1498 else
1499 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001500 }
1501 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001502
1503 if (has_cap(ACER_CAP_BLUETOOTH)) {
1504 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1505 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001506 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001507 }
1508
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001509 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001510 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001511 if (ACPI_SUCCESS(status))
1512 rfkill_set_sw_state(threeg_rfkill, !state);
1513 }
1514
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001515 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001516}
1517
Johannes Berg19d337d2009-06-02 13:01:37 +02001518static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001519{
1520 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001521 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001522
1523 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001524 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001525 if (ACPI_FAILURE(status))
1526 return -ENODEV;
1527 }
1528
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001529 return 0;
1530}
1531
Johannes Berg19d337d2009-06-02 13:01:37 +02001532static const struct rfkill_ops acer_rfkill_ops = {
1533 .set_block = acer_rfkill_set,
1534};
1535
1536static struct rfkill *acer_rfkill_register(struct device *dev,
1537 enum rfkill_type type,
1538 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001539{
1540 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001541 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001542 u32 state;
1543 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001544
Johannes Berg19d337d2009-06-02 13:01:37 +02001545 rfkill_dev = rfkill_alloc(name, dev, type,
1546 &acer_rfkill_ops,
1547 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001548 if (!rfkill_dev)
1549 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001550
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001551 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001552
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001553 err = rfkill_register(rfkill_dev);
1554 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001555 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001556 return ERR_PTR(err);
1557 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001558
1559 if (ACPI_SUCCESS(status))
1560 rfkill_set_sw_state(rfkill_dev, !state);
1561
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001562 return rfkill_dev;
1563}
1564
1565static int acer_rfkill_init(struct device *dev)
1566{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001567 int err;
1568
1569 if (has_cap(ACER_CAP_WIRELESS)) {
1570 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1571 "acer-wireless", ACER_CAP_WIRELESS);
1572 if (IS_ERR(wireless_rfkill)) {
1573 err = PTR_ERR(wireless_rfkill);
1574 goto error_wireless;
1575 }
1576 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001577
1578 if (has_cap(ACER_CAP_BLUETOOTH)) {
1579 bluetooth_rfkill = acer_rfkill_register(dev,
1580 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1581 ACER_CAP_BLUETOOTH);
1582 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001583 err = PTR_ERR(bluetooth_rfkill);
1584 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001585 }
1586 }
1587
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001588 if (has_cap(ACER_CAP_THREEG)) {
1589 threeg_rfkill = acer_rfkill_register(dev,
1590 RFKILL_TYPE_WWAN, "acer-threeg",
1591 ACER_CAP_THREEG);
1592 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001593 err = PTR_ERR(threeg_rfkill);
1594 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001595 }
1596 }
1597
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001598 rfkill_inited = true;
1599
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001600 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1601 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001602 schedule_delayed_work(&acer_rfkill_work,
1603 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001604
1605 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001606
1607error_threeg:
1608 if (has_cap(ACER_CAP_BLUETOOTH)) {
1609 rfkill_unregister(bluetooth_rfkill);
1610 rfkill_destroy(bluetooth_rfkill);
1611 }
1612error_bluetooth:
1613 if (has_cap(ACER_CAP_WIRELESS)) {
1614 rfkill_unregister(wireless_rfkill);
1615 rfkill_destroy(wireless_rfkill);
1616 }
1617error_wireless:
1618 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001619}
1620
1621static void acer_rfkill_exit(void)
1622{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001623 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1624 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001625 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001626
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001627 if (has_cap(ACER_CAP_WIRELESS)) {
1628 rfkill_unregister(wireless_rfkill);
1629 rfkill_destroy(wireless_rfkill);
1630 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001631
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001632 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001633 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001634 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001635 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001636
1637 if (has_cap(ACER_CAP_THREEG)) {
1638 rfkill_unregister(threeg_rfkill);
1639 rfkill_destroy(threeg_rfkill);
1640 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001641 return;
1642}
1643
1644/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001645 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001646 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001647static ssize_t show_bool_threeg(struct device *dev,
1648 struct device_attribute *attr, char *buf)
1649{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001650 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001651 acpi_status status;
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001652
Joe Perches6e71f382011-11-29 11:04:05 -08001653 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1654 current->comm);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001655 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001656 if (ACPI_SUCCESS(status))
1657 return sprintf(buf, "%u\n", result);
1658 return sprintf(buf, "Read error\n");
1659}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001660
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001661static ssize_t set_bool_threeg(struct device *dev,
1662 struct device_attribute *attr, const char *buf, size_t count)
1663{
1664 u32 tmp = simple_strtoul(buf, NULL, 10);
1665 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
Joe Perches6e71f382011-11-29 11:04:05 -08001666 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1667 current->comm);
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001668 if (ACPI_FAILURE(status))
1669 return -EINVAL;
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001670 return count;
1671}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001672static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001673 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001674
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001675static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1676 char *buf)
1677{
Joe Perches6e71f382011-11-29 11:04:05 -08001678 pr_info("This interface sysfs will be removed in 2012 - used by: %s\n",
1679 current->comm);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001680 switch (interface->type) {
1681 case ACER_AMW0:
1682 return sprintf(buf, "AMW0\n");
1683 case ACER_AMW0_V2:
1684 return sprintf(buf, "AMW0 v2\n");
1685 case ACER_WMID:
1686 return sprintf(buf, "WMID\n");
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001687 case ACER_WMID_v2:
1688 return sprintf(buf, "WMID v2\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001689 default:
1690 return sprintf(buf, "Error!\n");
1691 }
1692}
1693
Axel Lin370525d2010-06-30 10:20:23 +08001694static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001695
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001696static void acer_wmi_notify(u32 value, void *context)
1697{
1698 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1699 union acpi_object *obj;
1700 struct event_return_value return_value;
1701 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001702 u16 device_state;
1703 const struct key_entry *key;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001704 u32 scancode;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001705
1706 status = wmi_get_event_data(value, &response);
1707 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001708 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001709 return;
1710 }
1711
1712 obj = (union acpi_object *)response.pointer;
1713
1714 if (!obj)
1715 return;
1716 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001717 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001718 kfree(obj);
1719 return;
1720 }
1721 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001722 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001723 kfree(obj);
1724 return;
1725 }
1726
1727 return_value = *((struct event_return_value *)obj->buffer.pointer);
1728 kfree(obj);
1729
1730 switch (return_value.function) {
1731 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001732 device_state = return_value.device_state;
1733 pr_debug("device state: 0x%x\n", device_state);
1734
1735 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1736 return_value.key_num);
1737 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001738 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001739 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001740 } else {
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001741 scancode = return_value.key_num;
Seth Forshee92530662011-06-21 12:00:33 -05001742 switch (key->keycode) {
1743 case KEY_WLAN:
1744 case KEY_BLUETOOTH:
1745 if (has_cap(ACER_CAP_WIRELESS))
1746 rfkill_set_sw_state(wireless_rfkill,
1747 !(device_state & ACER_WMID3_GDS_WIRELESS));
1748 if (has_cap(ACER_CAP_THREEG))
1749 rfkill_set_sw_state(threeg_rfkill,
1750 !(device_state & ACER_WMID3_GDS_THREEG));
1751 if (has_cap(ACER_CAP_BLUETOOTH))
1752 rfkill_set_sw_state(bluetooth_rfkill,
1753 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1754 break;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001755 case KEY_TOUCHPAD_TOGGLE:
1756 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1757 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
Seth Forshee92530662011-06-21 12:00:33 -05001758 }
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001759 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
Seth Forshee92530662011-06-21 12:00:33 -05001760 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001761 break;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001762 case WMID_ACCEL_EVENT:
1763 acer_gsensor_event();
1764 break;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001765 default:
Joe Perches249c7202011-03-29 15:21:34 -07001766 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001767 return_value.function, return_value.key_num);
1768 break;
1769 }
1770}
1771
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001772static acpi_status
1773wmid3_set_lm_mode(struct lm_input_params *params,
1774 struct lm_return_value *return_value)
1775{
1776 acpi_status status;
1777 union acpi_object *obj;
1778
1779 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1780 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1781
1782 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1783 if (ACPI_FAILURE(status))
1784 return status;
1785
1786 obj = output.pointer;
1787
1788 if (!obj)
1789 return AE_ERROR;
1790 else if (obj->type != ACPI_TYPE_BUFFER) {
1791 kfree(obj);
1792 return AE_ERROR;
1793 }
1794 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001795 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001796 kfree(obj);
1797 return AE_ERROR;
1798 }
1799
1800 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1801 kfree(obj);
1802
1803 return status;
1804}
1805
1806static int acer_wmi_enable_ec_raw(void)
1807{
1808 struct lm_return_value return_value;
1809 acpi_status status;
1810 struct lm_input_params params = {
1811 .function_num = 0x1,
1812 .commun_devices = 0xFFFF,
1813 .devices = 0xFFFF,
1814 .lm_status = 0x00, /* Launch Manager Deactive */
1815 };
1816
1817 status = wmid3_set_lm_mode(&params, &return_value);
1818
1819 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001820 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1821 return_value.error_code,
1822 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001823 else
Joe Perches249c7202011-03-29 15:21:34 -07001824 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001825
1826 return status;
1827}
1828
1829static int acer_wmi_enable_lm(void)
1830{
1831 struct lm_return_value return_value;
1832 acpi_status status;
1833 struct lm_input_params params = {
1834 .function_num = 0x1,
1835 .commun_devices = 0xFFFF,
1836 .devices = 0xFFFF,
1837 .lm_status = 0x01, /* Launch Manager Active */
1838 };
1839
1840 status = wmid3_set_lm_mode(&params, &return_value);
1841
1842 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001843 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1844 return_value.error_code,
1845 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001846
1847 return status;
1848}
1849
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001850static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1851 void *ctx, void **retval)
1852{
1853 *(acpi_handle *)retval = ah;
1854 return AE_OK;
1855}
1856
1857static int __init acer_wmi_get_handle(const char *name, const char *prop,
1858 acpi_handle *ah)
1859{
1860 acpi_status status;
1861 acpi_handle handle;
1862
1863 BUG_ON(!name || !ah);
1864
Marek Vasut24237c42012-07-05 01:30:09 +02001865 handle = NULL;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001866 status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1867 (void *)name, &handle);
1868
1869 if (ACPI_SUCCESS(status)) {
1870 *ah = handle;
1871 return 0;
1872 } else {
1873 return -ENODEV;
1874 }
1875}
1876
1877static int __init acer_wmi_accel_setup(void)
1878{
1879 int err;
1880
1881 err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle);
1882 if (err)
1883 return err;
1884
1885 interface->capability |= ACER_CAP_ACCEL;
1886
1887 acer_wmi_accel_dev = input_allocate_device();
1888 if (!acer_wmi_accel_dev)
1889 return -ENOMEM;
1890
1891 acer_wmi_accel_dev->open = acer_gsensor_open;
1892
1893 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1894 acer_wmi_accel_dev->phys = "wmi/input1";
1895 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1896 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1897 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1898 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1899 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1900
1901 err = input_register_device(acer_wmi_accel_dev);
1902 if (err)
1903 goto err_free_dev;
1904
1905 return 0;
1906
1907err_free_dev:
1908 input_free_device(acer_wmi_accel_dev);
1909 return err;
1910}
1911
1912static void acer_wmi_accel_destroy(void)
1913{
1914 input_unregister_device(acer_wmi_accel_dev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001915}
1916
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001917static int __init acer_wmi_input_setup(void)
1918{
1919 acpi_status status;
1920 int err;
1921
1922 acer_wmi_input_dev = input_allocate_device();
1923 if (!acer_wmi_input_dev)
1924 return -ENOMEM;
1925
1926 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1927 acer_wmi_input_dev->phys = "wmi/input0";
1928 acer_wmi_input_dev->id.bustype = BUS_HOST;
1929
1930 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1931 if (err)
1932 goto err_free_dev;
1933
1934 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1935 acer_wmi_notify, NULL);
1936 if (ACPI_FAILURE(status)) {
1937 err = -EIO;
1938 goto err_free_keymap;
1939 }
1940
1941 err = input_register_device(acer_wmi_input_dev);
1942 if (err)
1943 goto err_uninstall_notifier;
1944
1945 return 0;
1946
1947err_uninstall_notifier:
1948 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1949err_free_keymap:
1950 sparse_keymap_free(acer_wmi_input_dev);
1951err_free_dev:
1952 input_free_device(acer_wmi_input_dev);
1953 return err;
1954}
1955
1956static void acer_wmi_input_destroy(void)
1957{
1958 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1959 sparse_keymap_free(acer_wmi_input_dev);
1960 input_unregister_device(acer_wmi_input_dev);
1961}
1962
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001963/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001964 * debugfs functions
1965 */
1966static u32 get_wmid_devices(void)
1967{
1968 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1969 union acpi_object *obj;
1970 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001971 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001972
1973 status = wmi_query_block(WMID_GUID2, 1, &out);
1974 if (ACPI_FAILURE(status))
1975 return 0;
1976
1977 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001978 if (obj) {
1979 if (obj->type == ACPI_TYPE_BUFFER &&
1980 (obj->buffer.length == sizeof(u32) ||
1981 obj->buffer.length == sizeof(u64))) {
1982 devices = *((u32 *) obj->buffer.pointer);
1983 } else if (obj->type == ACPI_TYPE_INTEGER) {
1984 devices = (u32) obj->integer.value;
1985 }
Carlos Corbacho81143522008-06-21 09:09:53 +01001986 }
Axel Lin66904862010-07-20 15:19:52 -07001987
1988 kfree(out.pointer);
1989 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001990}
1991
1992/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001993 * Platform device
1994 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001995static int acer_platform_probe(struct platform_device *device)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001996{
1997 int err;
1998
1999 if (has_cap(ACER_CAP_MAILLED)) {
2000 err = acer_led_init(&device->dev);
2001 if (err)
2002 goto error_mailled;
2003 }
2004
2005 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2006 err = acer_backlight_init(&device->dev);
2007 if (err)
2008 goto error_brightness;
2009 }
2010
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002011 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01002012 if (err)
2013 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002014
2015 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002016
Andy Whitcroft350e3292009-04-04 09:33:34 +01002017error_rfkill:
2018 if (has_cap(ACER_CAP_BRIGHTNESS))
2019 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002020error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01002021 if (has_cap(ACER_CAP_MAILLED))
2022 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002023error_mailled:
2024 return err;
2025}
2026
2027static int acer_platform_remove(struct platform_device *device)
2028{
2029 if (has_cap(ACER_CAP_MAILLED))
2030 acer_led_exit();
2031 if (has_cap(ACER_CAP_BRIGHTNESS))
2032 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002033
2034 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002035 return 0;
2036}
2037
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002038static int acer_suspend(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002039{
2040 u32 value;
2041 struct acer_data *data = &interface->data;
2042
2043 if (!data)
2044 return -ENOMEM;
2045
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002046 if (has_cap(ACER_CAP_MAILLED)) {
2047 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002048 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002049 data->mailled = value;
2050 }
2051
2052 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2053 get_u32(&value, ACER_CAP_BRIGHTNESS);
2054 data->brightness = value;
2055 }
2056
2057 return 0;
2058}
2059
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002060static int acer_resume(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002061{
2062 struct acer_data *data = &interface->data;
2063
2064 if (!data)
2065 return -ENOMEM;
2066
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002067 if (has_cap(ACER_CAP_MAILLED))
2068 set_u32(data->mailled, ACER_CAP_MAILLED);
2069
2070 if (has_cap(ACER_CAP_BRIGHTNESS))
2071 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2072
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002073 if (has_cap(ACER_CAP_ACCEL))
2074 acer_gsensor_init();
2075
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002076 return 0;
2077}
2078
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002079static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2080
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002081static void acer_platform_shutdown(struct platform_device *device)
2082{
2083 struct acer_data *data = &interface->data;
2084
2085 if (!data)
2086 return;
2087
2088 if (has_cap(ACER_CAP_MAILLED))
2089 set_u32(LED_OFF, ACER_CAP_MAILLED);
2090}
2091
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002092static struct platform_driver acer_platform_driver = {
2093 .driver = {
2094 .name = "acer-wmi",
2095 .owner = THIS_MODULE,
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002096 .pm = &acer_pm,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002097 },
2098 .probe = acer_platform_probe,
2099 .remove = acer_platform_remove,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002100 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002101};
2102
2103static struct platform_device *acer_platform_device;
2104
2105static int remove_sysfs(struct platform_device *device)
2106{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002107 if (has_cap(ACER_CAP_THREEG))
2108 device_remove_file(&device->dev, &dev_attr_threeg);
2109
2110 device_remove_file(&device->dev, &dev_attr_interface);
2111
2112 return 0;
2113}
2114
2115static int create_sysfs(void)
2116{
2117 int retval = -ENOMEM;
2118
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002119 if (has_cap(ACER_CAP_THREEG)) {
2120 retval = device_create_file(&acer_platform_device->dev,
2121 &dev_attr_threeg);
2122 if (retval)
2123 goto error_sysfs;
2124 }
2125
2126 retval = device_create_file(&acer_platform_device->dev,
2127 &dev_attr_interface);
2128 if (retval)
2129 goto error_sysfs;
2130
2131 return 0;
2132
2133error_sysfs:
2134 remove_sysfs(acer_platform_device);
2135 return retval;
2136}
2137
Carlos Corbacho81143522008-06-21 09:09:53 +01002138static void remove_debugfs(void)
2139{
2140 debugfs_remove(interface->debug.devices);
2141 debugfs_remove(interface->debug.root);
2142}
2143
2144static int create_debugfs(void)
2145{
2146 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2147 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002148 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01002149 return -ENOMEM;
2150 }
2151
2152 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2153 interface->debug.root,
2154 &interface->debug.wmid_devices);
2155 if (!interface->debug.devices)
2156 goto error_debugfs;
2157
2158 return 0;
2159
2160error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07002161 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01002162 return -ENOMEM;
2163}
2164
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002165static int __init acer_wmi_init(void)
2166{
2167 int err;
2168
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002169 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002170
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002171 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002172 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002173 return -ENODEV;
2174 }
2175
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01002176 find_quirks();
2177
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002178 /*
2179 * Detect which ACPI-WMI interface we're using.
2180 */
2181 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2182 interface = &AMW0_V2_interface;
2183
2184 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2185 interface = &wmid_interface;
2186
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002187 if (wmi_has_guid(WMID_GUID3))
2188 interface = &wmid_v2_interface;
2189
2190 if (interface)
2191 dmi_walk(type_aa_dmi_decode, NULL);
2192
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002193 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002194 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002195 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002196 return -ENODEV;
2197 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002198 /* WMID always provides brightness methods */
2199 interface->capability |= ACER_CAP_BRIGHTNESS;
2200 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002201 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002202 return -ENODEV;
2203 }
2204
2205 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2206 interface = &AMW0_interface;
2207
2208 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002209 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002210 return -ENODEV;
2211 }
2212 }
2213
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002214 if (wmi_has_guid(AMW0_GUID1))
2215 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002216
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002217 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002218 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002219 return -ENODEV;
2220 }
2221
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002222 set_quirks();
2223
Corentin Charya60b2172012-06-13 09:32:02 +02002224 if (dmi_check_system(video_vendor_dmi_table))
2225 acpi_video_dmi_promote_vendor();
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002226 if (acpi_video_backlight_support()) {
Corentin Charya60b2172012-06-13 09:32:02 +02002227 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2228 pr_info("Brightness must be controlled by acpi video driver\n");
2229 } else {
Corentin Charya60b2172012-06-13 09:32:02 +02002230 pr_info("Disabling ACPI video driver\n");
2231 acpi_video_unregister();
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002232 }
2233
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002234 if (wmi_has_guid(WMID_GUID3)) {
2235 if (ec_raw_mode) {
2236 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002237 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002238 return -ENODEV;
2239 }
2240 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002241 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002242 return -ENODEV;
2243 }
2244 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002245 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002246 }
2247
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002248 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2249 err = acer_wmi_input_setup();
2250 if (err)
2251 return err;
2252 }
2253
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002254 acer_wmi_accel_setup();
2255
Axel Lin1c796322010-06-22 16:17:38 +08002256 err = platform_driver_register(&acer_platform_driver);
2257 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002258 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002259 goto error_platform_register;
2260 }
Axel Lin1c796322010-06-22 16:17:38 +08002261
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002262 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002263 if (!acer_platform_device) {
2264 err = -ENOMEM;
2265 goto error_device_alloc;
2266 }
2267
2268 err = platform_device_add(acer_platform_device);
2269 if (err)
2270 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002271
2272 err = create_sysfs();
2273 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002274 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002275
Carlos Corbacho81143522008-06-21 09:09:53 +01002276 if (wmi_has_guid(WMID_GUID2)) {
2277 interface->debug.wmid_devices = get_wmid_devices();
2278 err = create_debugfs();
2279 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002280 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002281 }
2282
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002283 /* Override any initial settings with values from the commandline */
2284 acer_commandline_init();
2285
2286 return 0;
2287
Axel Lin1c796322010-06-22 16:17:38 +08002288error_create_debugfs:
2289 remove_sysfs(acer_platform_device);
2290error_create_sys:
2291 platform_device_del(acer_platform_device);
2292error_device_add:
2293 platform_device_put(acer_platform_device);
2294error_device_alloc:
2295 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002296error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002297 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2298 acer_wmi_input_destroy();
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002299 if (has_cap(ACER_CAP_ACCEL))
2300 acer_wmi_accel_destroy();
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002301
Axel Lin1c796322010-06-22 16:17:38 +08002302 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002303}
2304
2305static void __exit acer_wmi_exit(void)
2306{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002307 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2308 acer_wmi_input_destroy();
2309
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002310 if (has_cap(ACER_CAP_ACCEL))
2311 acer_wmi_accel_destroy();
2312
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002313 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07002314 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002315 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002316 platform_driver_unregister(&acer_platform_driver);
2317
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002318 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002319 return;
2320}
2321
2322module_init(acer_wmi_init);
2323module_exit(acer_wmi_exit);