blob: 44f62b24f0a12a0053e6a3c282f37028bc878009 [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} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800132 {KE_END, 0}
133};
134
135static struct input_dev *acer_wmi_input_dev;
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200136static struct input_dev *acer_wmi_accel_dev;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800137
138struct event_return_value {
139 u8 function;
140 u8 key_num;
141 u16 device_state;
142 u32 reserved;
143} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000144
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000145/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800146 * GUID3 Get Device Status device flags
147 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800148#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800149#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800150#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800151#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +0800152#define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800153
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500154struct lm_input_params {
155 u8 function_num; /* Function Number */
156 u16 commun_devices; /* Communication type devices default status */
157 u16 devices; /* Other type devices default status */
158 u8 lm_status; /* Launch Manager Status */
159 u16 reserved;
160} __attribute__((packed));
161
162struct lm_return_value {
163 u8 error_code; /* Error Code */
164 u8 ec_return_value; /* EC Return Value */
165 u16 reserved;
166} __attribute__((packed));
167
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800168struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
169 u8 function_num; /* Function Number */
170 u8 hotkey_number; /* Hotkey Number */
171 u16 devices; /* Set Device */
172 u8 volume_value; /* Volume Value */
173} __attribute__((packed));
174
175struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800176 u8 function_num; /* Function Number */
177 u8 hotkey_number; /* Hotkey Number */
178 u16 devices; /* Get Device */
179} __attribute__((packed));
180
181struct wmid3_gds_return_value { /* Get Device Status return value*/
182 u8 error_code; /* Error Code */
183 u8 ec_return_value; /* EC Return Value */
184 u16 devices; /* Current Device Status */
185 u32 reserved;
186} __attribute__((packed));
187
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800188struct hotkey_function_type_aa {
189 u8 type;
190 u8 length;
191 u16 handle;
192 u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800193 u16 application_func_bitmap;
194 u16 media_func_bitmap;
195 u16 display_func_bitmap;
196 u16 others_func_bitmap;
197 u8 commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800198} __attribute__((packed));
199
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800200/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000201 * Interface capability flags
202 */
203#define ACER_CAP_MAILLED (1<<0)
204#define ACER_CAP_WIRELESS (1<<1)
205#define ACER_CAP_BLUETOOTH (1<<2)
206#define ACER_CAP_BRIGHTNESS (1<<3)
207#define ACER_CAP_THREEG (1<<4)
Marek Vasut1eb3fe12012-06-01 19:11:22 +0200208#define ACER_CAP_ACCEL (1<<5)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000209#define ACER_CAP_ANY (0xFFFFFFFF)
210
211/*
212 * Interface type flags
213 */
214enum interface_flags {
215 ACER_AMW0,
216 ACER_AMW0_V2,
217 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800218 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000219};
220
221#define ACER_DEFAULT_WIRELESS 0
222#define ACER_DEFAULT_BLUETOOTH 0
223#define ACER_DEFAULT_MAILLED 0
224#define ACER_DEFAULT_THREEG 0
225
226static int max_brightness = 0xF;
227
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000228static int mailled = -1;
229static int brightness = -1;
230static int threeg = -1;
231static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500232static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800233static bool has_type_aa;
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +0800234static u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800235static u8 commun_fn_key_number;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000236
237module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000238module_param(brightness, int, 0444);
239module_param(threeg, int, 0444);
240module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500241module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000242MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
243MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
244MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
245MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500246MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000247
248struct acer_data {
249 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000250 int threeg;
251 int brightness;
252};
253
Carlos Corbacho81143522008-06-21 09:09:53 +0100254struct acer_debug {
255 struct dentry *root;
256 struct dentry *devices;
257 u32 wmid_devices;
258};
259
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100260static struct rfkill *wireless_rfkill;
261static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800262static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800263static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100264
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000265/* Each low-level interface must define at least some of the following */
266struct wmi_interface {
267 /* The WMI device type */
268 u32 type;
269
270 /* The capabilities this interface provides */
271 u32 capability;
272
273 /* Private data for the current interface */
274 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100275
276 /* debugfs entries associated with this interface */
277 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000278};
279
280/* The static interface pointer, points to the currently detected interface */
281static struct wmi_interface *interface;
282
283/*
284 * Embedded Controller quirks
285 * Some laptops require us to directly access the EC to either enable or query
286 * features that are not available through WMI.
287 */
288
289struct quirk_entry {
290 u8 wireless;
291 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100292 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000293 u8 bluetooth;
294};
295
296static struct quirk_entry *quirks;
297
298static void set_quirks(void)
299{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700300 if (!interface)
301 return;
302
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000303 if (quirks->mailled)
304 interface->capability |= ACER_CAP_MAILLED;
305
306 if (quirks->brightness)
307 interface->capability |= ACER_CAP_BRIGHTNESS;
308}
309
310static int dmi_matched(const struct dmi_system_id *dmi)
311{
312 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800313 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000314}
315
316static struct quirk_entry quirk_unknown = {
317};
318
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100319static struct quirk_entry quirk_acer_aspire_1520 = {
320 .brightness = -1,
321};
322
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000323static struct quirk_entry quirk_acer_travelmate_2490 = {
324 .mailled = 1,
325};
326
327/* This AMW0 laptop has no bluetooth */
328static struct quirk_entry quirk_medion_md_98300 = {
329 .wireless = 1,
330};
331
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100332static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
333 .wireless = 2,
334};
335
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800336static struct quirk_entry quirk_lenovo_ideapad_s205 = {
337 .wireless = 3,
338};
339
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100340/* The Aspire One has a dummy ACPI-WMI interface - disable it */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800341static struct dmi_system_id acer_blacklist[] = {
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100342 {
343 .ident = "Acer Aspire One (SSD)",
344 .matches = {
345 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
346 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
347 },
348 },
349 {
350 .ident = "Acer Aspire One (HDD)",
351 .matches = {
352 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
353 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
354 },
355 },
356 {}
357};
358
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000359static struct dmi_system_id acer_quirks[] = {
360 {
361 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100362 .ident = "Acer Aspire 1360",
363 .matches = {
364 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
365 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
366 },
367 .driver_data = &quirk_acer_aspire_1520,
368 },
369 {
370 .callback = dmi_matched,
371 .ident = "Acer Aspire 1520",
372 .matches = {
373 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
374 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
375 },
376 .driver_data = &quirk_acer_aspire_1520,
377 },
378 {
379 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000380 .ident = "Acer Aspire 3100",
381 .matches = {
382 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
383 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
384 },
385 .driver_data = &quirk_acer_travelmate_2490,
386 },
387 {
388 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000389 .ident = "Acer Aspire 3610",
390 .matches = {
391 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
392 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
393 },
394 .driver_data = &quirk_acer_travelmate_2490,
395 },
396 {
397 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000398 .ident = "Acer Aspire 5100",
399 .matches = {
400 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
401 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
402 },
403 .driver_data = &quirk_acer_travelmate_2490,
404 },
405 {
406 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000407 .ident = "Acer Aspire 5610",
408 .matches = {
409 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
410 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
411 },
412 .driver_data = &quirk_acer_travelmate_2490,
413 },
414 {
415 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000416 .ident = "Acer Aspire 5630",
417 .matches = {
418 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
419 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
420 },
421 .driver_data = &quirk_acer_travelmate_2490,
422 },
423 {
424 .callback = dmi_matched,
425 .ident = "Acer Aspire 5650",
426 .matches = {
427 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
428 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
429 },
430 .driver_data = &quirk_acer_travelmate_2490,
431 },
432 {
433 .callback = dmi_matched,
434 .ident = "Acer Aspire 5680",
435 .matches = {
436 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
437 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
438 },
439 .driver_data = &quirk_acer_travelmate_2490,
440 },
441 {
442 .callback = dmi_matched,
443 .ident = "Acer Aspire 9110",
444 .matches = {
445 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
446 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
447 },
448 .driver_data = &quirk_acer_travelmate_2490,
449 },
450 {
451 .callback = dmi_matched,
452 .ident = "Acer TravelMate 2490",
453 .matches = {
454 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
455 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
456 },
457 .driver_data = &quirk_acer_travelmate_2490,
458 },
459 {
460 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000461 .ident = "Acer TravelMate 4200",
462 .matches = {
463 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
464 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
465 },
466 .driver_data = &quirk_acer_travelmate_2490,
467 },
468 {
469 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100470 .ident = "Fujitsu Siemens Amilo Li 1718",
471 .matches = {
472 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
473 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
474 },
475 .driver_data = &quirk_fujitsu_amilo_li_1718,
476 },
477 {
478 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000479 .ident = "Medion MD 98300",
480 .matches = {
481 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
482 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
483 },
484 .driver_data = &quirk_medion_md_98300,
485 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800486 {
487 .callback = dmi_matched,
488 .ident = "Lenovo Ideapad S205",
489 .matches = {
490 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
491 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
492 },
493 .driver_data = &quirk_lenovo_ideapad_s205,
494 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500495 {
496 .callback = dmi_matched,
Lee, Chun-Yic08f2082012-03-20 11:32:49 +0800497 .ident = "Lenovo Ideapad S205 (Brazos)",
498 .matches = {
499 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
500 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
501 },
502 .driver_data = &quirk_lenovo_ideapad_s205,
503 },
504 {
505 .callback = dmi_matched,
Seth Forsheebe3128b2011-10-06 15:01:55 -0500506 .ident = "Lenovo 3000 N200",
507 .matches = {
508 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
509 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
510 },
511 .driver_data = &quirk_fujitsu_amilo_li_1718,
512 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000513 {}
514};
515
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400516static int video_set_backlight_video_vendor(const struct dmi_system_id *d)
517{
518 interface->capability &= ~ACER_CAP_BRIGHTNESS;
519 pr_info("Brightness must be controlled by generic video driver\n");
520 return 0;
521}
522
523static const struct dmi_system_id video_vendor_dmi_table[] = {
524 {
525 .callback = video_set_backlight_video_vendor,
526 .ident = "Acer TravelMate 4750",
527 .matches = {
528 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
529 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
530 },
531 },
Lee, Chun-Yi050eff32012-05-21 23:19:51 +0800532 {
533 .callback = video_set_backlight_video_vendor,
534 .ident = "Acer Extensa 5235",
535 .matches = {
536 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
537 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
538 },
539 },
540 {
541 .callback = video_set_backlight_video_vendor,
542 .ident = "Acer TravelMate 5760",
543 .matches = {
544 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
545 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
546 },
547 },
548 {
549 .callback = video_set_backlight_video_vendor,
550 .ident = "Acer Aspire 5750",
551 .matches = {
552 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
553 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
554 },
555 },
Lee, Chun-Yi86924de2012-03-26 15:47:58 -0400556 {}
557};
558
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000559/* Find which quirks are needed for a particular vendor/ model pair */
560static void find_quirks(void)
561{
562 if (!force_series) {
563 dmi_check_system(acer_quirks);
564 } else if (force_series == 2490) {
565 quirks = &quirk_acer_travelmate_2490;
566 }
567
568 if (quirks == NULL)
569 quirks = &quirk_unknown;
570
571 set_quirks();
572}
573
574/*
575 * General interface convenience methods
576 */
577
578static bool has_cap(u32 cap)
579{
580 if ((interface->capability & cap) != 0)
581 return 1;
582
583 return 0;
584}
585
586/*
587 * AMW0 (V1) interface
588 */
589struct wmab_args {
590 u32 eax;
591 u32 ebx;
592 u32 ecx;
593 u32 edx;
594};
595
596struct wmab_ret {
597 u32 eax;
598 u32 ebx;
599 u32 ecx;
600 u32 edx;
601 u32 eex;
602};
603
604static acpi_status wmab_execute(struct wmab_args *regbuf,
605struct acpi_buffer *result)
606{
607 struct acpi_buffer input;
608 acpi_status status;
609 input.length = sizeof(struct wmab_args);
610 input.pointer = (u8 *)regbuf;
611
612 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
613
614 return status;
615}
616
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800617static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000618{
619 int err;
620 u8 result;
621
622 switch (cap) {
623 case ACER_CAP_MAILLED:
624 switch (quirks->mailled) {
625 default:
626 err = ec_read(0xA, &result);
627 if (err)
628 return AE_ERROR;
629 *value = (result >> 7) & 0x1;
630 return AE_OK;
631 }
632 break;
633 case ACER_CAP_WIRELESS:
634 switch (quirks->wireless) {
635 case 1:
636 err = ec_read(0x7B, &result);
637 if (err)
638 return AE_ERROR;
639 *value = result & 0x1;
640 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100641 case 2:
642 err = ec_read(0x71, &result);
643 if (err)
644 return AE_ERROR;
645 *value = result & 0x1;
646 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800647 case 3:
648 err = ec_read(0x78, &result);
649 if (err)
650 return AE_ERROR;
651 *value = result & 0x1;
652 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000653 default:
654 err = ec_read(0xA, &result);
655 if (err)
656 return AE_ERROR;
657 *value = (result >> 2) & 0x1;
658 return AE_OK;
659 }
660 break;
661 case ACER_CAP_BLUETOOTH:
662 switch (quirks->bluetooth) {
663 default:
664 err = ec_read(0xA, &result);
665 if (err)
666 return AE_ERROR;
667 *value = (result >> 4) & 0x1;
668 return AE_OK;
669 }
670 break;
671 case ACER_CAP_BRIGHTNESS:
672 switch (quirks->brightness) {
673 default:
674 err = ec_read(0x83, &result);
675 if (err)
676 return AE_ERROR;
677 *value = result;
678 return AE_OK;
679 }
680 break;
681 default:
Lin Ming08237972008-08-08 11:57:11 +0800682 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000683 }
684 return AE_OK;
685}
686
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800687static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000688{
689 struct wmab_args args;
690
691 args.eax = ACER_AMW0_WRITE;
692 args.ebx = value ? (1<<8) : 0;
693 args.ecx = args.edx = 0;
694
695 switch (cap) {
696 case ACER_CAP_MAILLED:
697 if (value > 1)
698 return AE_BAD_PARAMETER;
699 args.ebx |= ACER_AMW0_MAILLED_MASK;
700 break;
701 case ACER_CAP_WIRELESS:
702 if (value > 1)
703 return AE_BAD_PARAMETER;
704 args.ebx |= ACER_AMW0_WIRELESS_MASK;
705 break;
706 case ACER_CAP_BLUETOOTH:
707 if (value > 1)
708 return AE_BAD_PARAMETER;
709 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
710 break;
711 case ACER_CAP_BRIGHTNESS:
712 if (value > max_brightness)
713 return AE_BAD_PARAMETER;
714 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000715 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000716 return ec_write(0x83, value);
717 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000718 }
719 default:
Lin Ming08237972008-08-08 11:57:11 +0800720 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000721 }
722
723 /* Actually do the set */
724 return wmab_execute(&args, NULL);
725}
726
727static acpi_status AMW0_find_mailled(void)
728{
729 struct wmab_args args;
730 struct wmab_ret ret;
731 acpi_status status = AE_OK;
732 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
733 union acpi_object *obj;
734
735 args.eax = 0x86;
736 args.ebx = args.ecx = args.edx = 0;
737
738 status = wmab_execute(&args, &out);
739 if (ACPI_FAILURE(status))
740 return status;
741
742 obj = (union acpi_object *) out.pointer;
743 if (obj && obj->type == ACPI_TYPE_BUFFER &&
744 obj->buffer.length == sizeof(struct wmab_ret)) {
745 ret = *((struct wmab_ret *) obj->buffer.pointer);
746 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700747 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000748 return AE_ERROR;
749 }
750
751 if (ret.eex & 0x1)
752 interface->capability |= ACER_CAP_MAILLED;
753
754 kfree(out.pointer);
755
756 return AE_OK;
757}
758
Ike Panhc461e7432012-02-03 16:46:39 +0800759static int AMW0_set_cap_acpi_check_device_found;
760
761static acpi_status AMW0_set_cap_acpi_check_device_cb(acpi_handle handle,
762 u32 level, void *context, void **retval)
763{
764 AMW0_set_cap_acpi_check_device_found = 1;
765 return AE_OK;
766}
767
768static const struct acpi_device_id norfkill_ids[] = {
769 { "VPC2004", 0},
770 { "IBM0068", 0},
771 { "LEN0068", 0},
Lee, Chun-Yi5719b812012-03-23 12:36:44 +0800772 { "SNY5001", 0}, /* sony-laptop in charge */
Ike Panhc461e7432012-02-03 16:46:39 +0800773 { "", 0},
774};
775
776static int AMW0_set_cap_acpi_check_device(void)
777{
778 const struct acpi_device_id *id;
779
780 for (id = norfkill_ids; id->id[0]; id++)
781 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb,
782 NULL, NULL);
783 return AMW0_set_cap_acpi_check_device_found;
784}
785
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000786static acpi_status AMW0_set_capabilities(void)
787{
788 struct wmab_args args;
789 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700790 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000791 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
792 union acpi_object *obj;
793
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100794 /*
795 * On laptops with this strange GUID (non Acer), normal probing doesn't
796 * work.
797 */
798 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800799 if ((quirks != &quirk_unknown) ||
800 !AMW0_set_cap_acpi_check_device())
801 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100802 return AE_OK;
803 }
804
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000805 args.eax = ACER_AMW0_WRITE;
806 args.ecx = args.edx = 0;
807
808 args.ebx = 0xa2 << 8;
809 args.ebx |= ACER_AMW0_WIRELESS_MASK;
810
811 status = wmab_execute(&args, &out);
812 if (ACPI_FAILURE(status))
813 return status;
814
Axel Lin7677fbd2010-07-20 15:19:53 -0700815 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000816 if (obj && obj->type == ACPI_TYPE_BUFFER &&
817 obj->buffer.length == sizeof(struct wmab_ret)) {
818 ret = *((struct wmab_ret *) obj->buffer.pointer);
819 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700820 status = AE_ERROR;
821 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000822 }
823
824 if (ret.eax & 0x1)
825 interface->capability |= ACER_CAP_WIRELESS;
826
827 args.ebx = 2 << 8;
828 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
829
Axel Lin7677fbd2010-07-20 15:19:53 -0700830 /*
831 * It's ok to use existing buffer for next wmab_execute call.
832 * But we need to kfree(out.pointer) if next wmab_execute fail.
833 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000834 status = wmab_execute(&args, &out);
835 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700836 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000837
838 obj = (union acpi_object *) out.pointer;
839 if (obj && obj->type == ACPI_TYPE_BUFFER
840 && obj->buffer.length == sizeof(struct wmab_ret)) {
841 ret = *((struct wmab_ret *) obj->buffer.pointer);
842 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700843 status = AE_ERROR;
844 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000845 }
846
847 if (ret.eax & 0x1)
848 interface->capability |= ACER_CAP_BLUETOOTH;
849
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000850 /*
851 * This appears to be safe to enable, since all Wistron based laptops
852 * appear to use the same EC register for brightness, even if they
853 * differ for wireless, etc
854 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100855 if (quirks->brightness >= 0)
856 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000857
Axel Lin7677fbd2010-07-20 15:19:53 -0700858 status = AE_OK;
859out:
860 kfree(out.pointer);
861 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000862}
863
864static struct wmi_interface AMW0_interface = {
865 .type = ACER_AMW0,
866};
867
868static struct wmi_interface AMW0_V2_interface = {
869 .type = ACER_AMW0_V2,
870};
871
872/*
873 * New interface (The WMID interface)
874 */
875static acpi_status
876WMI_execute_u32(u32 method_id, u32 in, u32 *out)
877{
878 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
879 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
880 union acpi_object *obj;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800881 u32 tmp = 0;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000882 acpi_status status;
883
884 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
885
886 if (ACPI_FAILURE(status))
887 return status;
888
889 obj = (union acpi_object *) result.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +0800890 if (obj) {
891 if (obj->type == ACPI_TYPE_BUFFER &&
892 (obj->buffer.length == sizeof(u32) ||
893 obj->buffer.length == sizeof(u64))) {
894 tmp = *((u32 *) obj->buffer.pointer);
895 } else if (obj->type == ACPI_TYPE_INTEGER) {
896 tmp = (u32) obj->integer.value;
897 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000898 }
899
900 if (out)
901 *out = tmp;
902
903 kfree(result.pointer);
904
905 return status;
906}
907
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800908static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000909{
910 acpi_status status;
911 u8 tmp;
912 u32 result, method_id = 0;
913
914 switch (cap) {
915 case ACER_CAP_WIRELESS:
916 method_id = ACER_WMID_GET_WIRELESS_METHODID;
917 break;
918 case ACER_CAP_BLUETOOTH:
919 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
920 break;
921 case ACER_CAP_BRIGHTNESS:
922 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
923 break;
924 case ACER_CAP_THREEG:
925 method_id = ACER_WMID_GET_THREEG_METHODID;
926 break;
927 case ACER_CAP_MAILLED:
928 if (quirks->mailled == 1) {
929 ec_read(0x9f, &tmp);
930 *value = tmp & 0x1;
931 return 0;
932 }
933 default:
Lin Ming08237972008-08-08 11:57:11 +0800934 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000935 }
936 status = WMI_execute_u32(method_id, 0, &result);
937
938 if (ACPI_SUCCESS(status))
939 *value = (u8)result;
940
941 return status;
942}
943
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800944static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000945{
946 u32 method_id = 0;
947 char param;
948
949 switch (cap) {
950 case ACER_CAP_BRIGHTNESS:
951 if (value > max_brightness)
952 return AE_BAD_PARAMETER;
953 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
954 break;
955 case ACER_CAP_WIRELESS:
956 if (value > 1)
957 return AE_BAD_PARAMETER;
958 method_id = ACER_WMID_SET_WIRELESS_METHODID;
959 break;
960 case ACER_CAP_BLUETOOTH:
961 if (value > 1)
962 return AE_BAD_PARAMETER;
963 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
964 break;
965 case ACER_CAP_THREEG:
966 if (value > 1)
967 return AE_BAD_PARAMETER;
968 method_id = ACER_WMID_SET_THREEG_METHODID;
969 break;
970 case ACER_CAP_MAILLED:
971 if (value > 1)
972 return AE_BAD_PARAMETER;
973 if (quirks->mailled == 1) {
974 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700975 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000976 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700977 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000978 return 0;
979 }
980 break;
981 default:
Lin Ming08237972008-08-08 11:57:11 +0800982 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000983 }
984 return WMI_execute_u32(method_id, (u32)value, NULL);
985}
986
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800987static acpi_status wmid3_get_device_status(u32 *value, u16 device)
988{
989 struct wmid3_gds_return_value return_value;
990 acpi_status status;
991 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800992 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800993 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800994 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800995 .devices = device,
996 };
997 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800998 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800999 &params
1000 };
1001 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1002
1003 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1004 if (ACPI_FAILURE(status))
1005 return status;
1006
1007 obj = output.pointer;
1008
1009 if (!obj)
1010 return AE_ERROR;
1011 else if (obj->type != ACPI_TYPE_BUFFER) {
1012 kfree(obj);
1013 return AE_ERROR;
1014 }
1015 if (obj->buffer.length != 8) {
1016 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1017 kfree(obj);
1018 return AE_ERROR;
1019 }
1020
1021 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1022 kfree(obj);
1023
1024 if (return_value.error_code || return_value.ec_return_value)
1025 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1026 device,
1027 return_value.error_code,
1028 return_value.ec_return_value);
1029 else
1030 *value = !!(return_value.devices & device);
1031
1032 return status;
1033}
1034
1035static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1036{
1037 u16 device;
1038
1039 switch (cap) {
1040 case ACER_CAP_WIRELESS:
1041 device = ACER_WMID3_GDS_WIRELESS;
1042 break;
1043 case ACER_CAP_BLUETOOTH:
1044 device = ACER_WMID3_GDS_BLUETOOTH;
1045 break;
1046 case ACER_CAP_THREEG:
1047 device = ACER_WMID3_GDS_THREEG;
1048 break;
1049 default:
1050 return AE_ERROR;
1051 }
1052 return wmid3_get_device_status(value, device);
1053}
1054
1055static acpi_status wmid3_set_device_status(u32 value, u16 device)
1056{
1057 struct wmid3_gds_return_value return_value;
1058 acpi_status status;
1059 union acpi_object *obj;
1060 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001061 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001062 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001063 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001064 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001065 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001066 struct acpi_buffer get_input = {
1067 sizeof(struct wmid3_gds_get_input_param),
1068 &get_params
1069 };
1070 struct wmid3_gds_set_input_param set_params = {
1071 .function_num = 0x2,
1072 .hotkey_number = commun_fn_key_number,
1073 .devices = commun_func_bitmap,
1074 };
1075 struct acpi_buffer set_input = {
1076 sizeof(struct wmid3_gds_set_input_param),
1077 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001078 };
1079 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1080 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1081
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001082 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001083 if (ACPI_FAILURE(status))
1084 return status;
1085
1086 obj = output.pointer;
1087
1088 if (!obj)
1089 return AE_ERROR;
1090 else if (obj->type != ACPI_TYPE_BUFFER) {
1091 kfree(obj);
1092 return AE_ERROR;
1093 }
1094 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001095 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001096 kfree(obj);
1097 return AE_ERROR;
1098 }
1099
1100 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1101 kfree(obj);
1102
1103 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001104 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1105 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001106 return_value.ec_return_value);
1107 return status;
1108 }
1109
1110 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001111 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001112
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001113 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001114 if (ACPI_FAILURE(status))
1115 return status;
1116
1117 obj = output2.pointer;
1118
1119 if (!obj)
1120 return AE_ERROR;
1121 else if (obj->type != ACPI_TYPE_BUFFER) {
1122 kfree(obj);
1123 return AE_ERROR;
1124 }
1125 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001126 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001127 kfree(obj);
1128 return AE_ERROR;
1129 }
1130
1131 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1132 kfree(obj);
1133
1134 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001135 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1136 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001137 return_value.ec_return_value);
1138
1139 return status;
1140}
1141
1142static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1143{
1144 u16 device;
1145
1146 switch (cap) {
1147 case ACER_CAP_WIRELESS:
1148 device = ACER_WMID3_GDS_WIRELESS;
1149 break;
1150 case ACER_CAP_BLUETOOTH:
1151 device = ACER_WMID3_GDS_BLUETOOTH;
1152 break;
1153 case ACER_CAP_THREEG:
1154 device = ACER_WMID3_GDS_THREEG;
1155 break;
1156 default:
1157 return AE_ERROR;
1158 }
1159 return wmid3_set_device_status(value, device);
1160}
1161
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001162static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1163{
1164 struct hotkey_function_type_aa *type_aa;
1165
1166 /* We are looking for OEM-specific Type AAh */
1167 if (header->type != 0xAA)
1168 return;
1169
1170 has_type_aa = true;
1171 type_aa = (struct hotkey_function_type_aa *) header;
1172
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001173 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001174 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001175 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001176
1177 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1178 interface->capability |= ACER_CAP_WIRELESS;
1179 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1180 interface->capability |= ACER_CAP_THREEG;
1181 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1182 interface->capability |= ACER_CAP_BLUETOOTH;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001183
1184 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001185}
1186
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001187static acpi_status WMID_set_capabilities(void)
1188{
1189 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1190 union acpi_object *obj;
1191 acpi_status status;
1192 u32 devices;
1193
1194 status = wmi_query_block(WMID_GUID2, 1, &out);
1195 if (ACPI_FAILURE(status))
1196 return status;
1197
1198 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001199 if (obj) {
1200 if (obj->type == ACPI_TYPE_BUFFER &&
1201 (obj->buffer.length == sizeof(u32) ||
1202 obj->buffer.length == sizeof(u64))) {
1203 devices = *((u32 *) obj->buffer.pointer);
1204 } else if (obj->type == ACPI_TYPE_INTEGER) {
1205 devices = (u32) obj->integer.value;
1206 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001207 } else {
Axel Lin66904862010-07-20 15:19:52 -07001208 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001209 return AE_ERROR;
1210 }
1211
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001212 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1213 if (devices & 0x07)
1214 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001215 if (devices & 0x40)
1216 interface->capability |= ACER_CAP_THREEG;
1217 if (devices & 0x10)
1218 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001219
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001220 if (!(devices & 0x20))
1221 max_brightness = 0x9;
1222
Axel Lin66904862010-07-20 15:19:52 -07001223 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001224 return status;
1225}
1226
1227static struct wmi_interface wmid_interface = {
1228 .type = ACER_WMID,
1229};
1230
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001231static struct wmi_interface wmid_v2_interface = {
1232 .type = ACER_WMID_v2,
1233};
1234
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001235/*
1236 * Generic Device (interface-independent)
1237 */
1238
1239static acpi_status get_u32(u32 *value, u32 cap)
1240{
Lin Ming08237972008-08-08 11:57:11 +08001241 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001242
1243 switch (interface->type) {
1244 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001245 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001246 break;
1247 case ACER_AMW0_V2:
1248 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001249 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001250 break;
1251 }
1252 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001253 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001254 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001255 case ACER_WMID_v2:
1256 if (cap & (ACER_CAP_WIRELESS |
1257 ACER_CAP_BLUETOOTH |
1258 ACER_CAP_THREEG))
1259 status = wmid_v2_get_u32(value, cap);
1260 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001261 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001262 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001263 }
1264
1265 return status;
1266}
1267
1268static acpi_status set_u32(u32 value, u32 cap)
1269{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001270 acpi_status status;
1271
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001272 if (interface->capability & cap) {
1273 switch (interface->type) {
1274 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001275 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001276 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001277 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001278 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001279
1280 /*
1281 * On some models, some WMID methods don't toggle
1282 * properly. For those cases, we want to run the AMW0
1283 * method afterwards to be certain we've really toggled
1284 * the device state.
1285 */
1286 if (cap == ACER_CAP_WIRELESS ||
1287 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001288 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001289 if (ACPI_FAILURE(status))
1290 return status;
1291
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001292 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001293 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001294 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001295 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001296 case ACER_WMID_v2:
1297 if (cap & (ACER_CAP_WIRELESS |
1298 ACER_CAP_BLUETOOTH |
1299 ACER_CAP_THREEG))
1300 return wmid_v2_set_u32(value, cap);
1301 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001302 return WMID_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001303 default:
1304 return AE_BAD_PARAMETER;
1305 }
1306 }
1307 return AE_BAD_PARAMETER;
1308}
1309
1310static void __init acer_commandline_init(void)
1311{
1312 /*
1313 * These will all fail silently if the value given is invalid, or the
1314 * capability isn't available on the given interface
1315 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001316 if (mailled >= 0)
1317 set_u32(mailled, ACER_CAP_MAILLED);
1318 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001319 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001320 if (brightness >= 0)
1321 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001322}
1323
1324/*
1325 * LED device (Mail LED only, no other LEDs known yet)
1326 */
1327static void mail_led_set(struct led_classdev *led_cdev,
1328enum led_brightness value)
1329{
1330 set_u32(value, ACER_CAP_MAILLED);
1331}
1332
1333static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001334 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001335 .brightness_set = mail_led_set,
1336};
1337
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001338static int acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001339{
1340 return led_classdev_register(dev, &mail_led);
1341}
1342
1343static void acer_led_exit(void)
1344{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001345 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001346 led_classdev_unregister(&mail_led);
1347}
1348
1349/*
1350 * Backlight device
1351 */
1352static struct backlight_device *acer_backlight_device;
1353
1354static int read_brightness(struct backlight_device *bd)
1355{
1356 u32 value;
1357 get_u32(&value, ACER_CAP_BRIGHTNESS);
1358 return value;
1359}
1360
1361static int update_bl_status(struct backlight_device *bd)
1362{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001363 int intensity = bd->props.brightness;
1364
1365 if (bd->props.power != FB_BLANK_UNBLANK)
1366 intensity = 0;
1367 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1368 intensity = 0;
1369
1370 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1371
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001372 return 0;
1373}
1374
Lionel Debrouxacc24722010-11-16 14:14:02 +01001375static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001376 .get_brightness = read_brightness,
1377 .update_status = update_bl_status,
1378};
1379
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001380static int acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001381{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001382 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001383 struct backlight_device *bd;
1384
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001385 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001386 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001387 props.max_brightness = max_brightness;
1388 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1389 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001390 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001391 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001392 acer_backlight_device = NULL;
1393 return PTR_ERR(bd);
1394 }
1395
1396 acer_backlight_device = bd;
1397
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001398 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001399 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001400 backlight_update_status(bd);
1401 return 0;
1402}
1403
Sam Ravnborg7560e382008-02-17 13:22:54 +01001404static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001405{
1406 backlight_device_unregister(acer_backlight_device);
1407}
1408
1409/*
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001410 * Accelerometer device
1411 */
1412static acpi_handle gsensor_handle;
1413
1414static int acer_gsensor_init(void)
1415{
1416 acpi_status status;
1417 struct acpi_buffer output;
1418 union acpi_object out_obj;
1419
1420 output.length = sizeof(out_obj);
1421 output.pointer = &out_obj;
1422 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1423 if (ACPI_FAILURE(status))
1424 return -1;
1425
1426 return 0;
1427}
1428
1429static int acer_gsensor_open(struct input_dev *input)
1430{
1431 return acer_gsensor_init();
1432}
1433
1434static int acer_gsensor_event(void)
1435{
1436 acpi_status status;
1437 struct acpi_buffer output;
1438 union acpi_object out_obj[5];
1439
1440 if (!has_cap(ACER_CAP_ACCEL))
1441 return -1;
1442
1443 output.length = sizeof(out_obj);
1444 output.pointer = out_obj;
1445
1446 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1447 if (ACPI_FAILURE(status))
1448 return -1;
1449
1450 if (out_obj->package.count != 4)
1451 return -1;
1452
1453 input_report_abs(acer_wmi_accel_dev, ABS_X,
1454 (s16)out_obj->package.elements[0].integer.value);
1455 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1456 (s16)out_obj->package.elements[1].integer.value);
1457 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1458 (s16)out_obj->package.elements[2].integer.value);
1459 input_sync(acer_wmi_accel_dev);
1460 return 0;
1461}
1462
1463/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001464 * Rfkill devices
1465 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001466static void acer_rfkill_update(struct work_struct *ignored);
1467static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1468static void acer_rfkill_update(struct work_struct *ignored)
1469{
1470 u32 state;
1471 acpi_status status;
1472
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001473 if (has_cap(ACER_CAP_WIRELESS)) {
1474 status = get_u32(&state, ACER_CAP_WIRELESS);
1475 if (ACPI_SUCCESS(status)) {
1476 if (quirks->wireless == 3)
1477 rfkill_set_hw_state(wireless_rfkill, !state);
1478 else
1479 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001480 }
1481 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001482
1483 if (has_cap(ACER_CAP_BLUETOOTH)) {
1484 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1485 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001486 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001487 }
1488
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001489 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001490 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001491 if (ACPI_SUCCESS(status))
1492 rfkill_set_sw_state(threeg_rfkill, !state);
1493 }
1494
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001495 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001496}
1497
Johannes Berg19d337d2009-06-02 13:01:37 +02001498static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001499{
1500 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001501 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001502
1503 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001504 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001505 if (ACPI_FAILURE(status))
1506 return -ENODEV;
1507 }
1508
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001509 return 0;
1510}
1511
Johannes Berg19d337d2009-06-02 13:01:37 +02001512static const struct rfkill_ops acer_rfkill_ops = {
1513 .set_block = acer_rfkill_set,
1514};
1515
1516static struct rfkill *acer_rfkill_register(struct device *dev,
1517 enum rfkill_type type,
1518 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001519{
1520 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001521 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001522 u32 state;
1523 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001524
Johannes Berg19d337d2009-06-02 13:01:37 +02001525 rfkill_dev = rfkill_alloc(name, dev, type,
1526 &acer_rfkill_ops,
1527 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001528 if (!rfkill_dev)
1529 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001530
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001531 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001532
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001533 err = rfkill_register(rfkill_dev);
1534 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001535 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001536 return ERR_PTR(err);
1537 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001538
1539 if (ACPI_SUCCESS(status))
1540 rfkill_set_sw_state(rfkill_dev, !state);
1541
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001542 return rfkill_dev;
1543}
1544
1545static int acer_rfkill_init(struct device *dev)
1546{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001547 int err;
1548
1549 if (has_cap(ACER_CAP_WIRELESS)) {
1550 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1551 "acer-wireless", ACER_CAP_WIRELESS);
1552 if (IS_ERR(wireless_rfkill)) {
1553 err = PTR_ERR(wireless_rfkill);
1554 goto error_wireless;
1555 }
1556 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001557
1558 if (has_cap(ACER_CAP_BLUETOOTH)) {
1559 bluetooth_rfkill = acer_rfkill_register(dev,
1560 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1561 ACER_CAP_BLUETOOTH);
1562 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001563 err = PTR_ERR(bluetooth_rfkill);
1564 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001565 }
1566 }
1567
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001568 if (has_cap(ACER_CAP_THREEG)) {
1569 threeg_rfkill = acer_rfkill_register(dev,
1570 RFKILL_TYPE_WWAN, "acer-threeg",
1571 ACER_CAP_THREEG);
1572 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001573 err = PTR_ERR(threeg_rfkill);
1574 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001575 }
1576 }
1577
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001578 rfkill_inited = true;
1579
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001580 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1581 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001582 schedule_delayed_work(&acer_rfkill_work,
1583 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001584
1585 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001586
1587error_threeg:
1588 if (has_cap(ACER_CAP_BLUETOOTH)) {
1589 rfkill_unregister(bluetooth_rfkill);
1590 rfkill_destroy(bluetooth_rfkill);
1591 }
1592error_bluetooth:
1593 if (has_cap(ACER_CAP_WIRELESS)) {
1594 rfkill_unregister(wireless_rfkill);
1595 rfkill_destroy(wireless_rfkill);
1596 }
1597error_wireless:
1598 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001599}
1600
1601static void acer_rfkill_exit(void)
1602{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001603 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1604 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001605 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001606
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001607 if (has_cap(ACER_CAP_WIRELESS)) {
1608 rfkill_unregister(wireless_rfkill);
1609 rfkill_destroy(wireless_rfkill);
1610 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001611
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001612 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001613 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001614 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001615 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001616
1617 if (has_cap(ACER_CAP_THREEG)) {
1618 rfkill_unregister(threeg_rfkill);
1619 rfkill_destroy(threeg_rfkill);
1620 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001621 return;
1622}
1623
1624/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001625 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001626 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001627static ssize_t show_bool_threeg(struct device *dev,
1628 struct device_attribute *attr, char *buf)
1629{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001630 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001631 acpi_status status;
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001632
Joe Perches6e71f382011-11-29 11:04:05 -08001633 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1634 current->comm);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001635 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001636 if (ACPI_SUCCESS(status))
1637 return sprintf(buf, "%u\n", result);
1638 return sprintf(buf, "Read error\n");
1639}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001640
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001641static ssize_t set_bool_threeg(struct device *dev,
1642 struct device_attribute *attr, const char *buf, size_t count)
1643{
1644 u32 tmp = simple_strtoul(buf, NULL, 10);
1645 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
Joe Perches6e71f382011-11-29 11:04:05 -08001646 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1647 current->comm);
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001648 if (ACPI_FAILURE(status))
1649 return -EINVAL;
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001650 return count;
1651}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001652static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001653 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001654
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001655static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1656 char *buf)
1657{
Joe Perches6e71f382011-11-29 11:04:05 -08001658 pr_info("This interface sysfs will be removed in 2012 - used by: %s\n",
1659 current->comm);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001660 switch (interface->type) {
1661 case ACER_AMW0:
1662 return sprintf(buf, "AMW0\n");
1663 case ACER_AMW0_V2:
1664 return sprintf(buf, "AMW0 v2\n");
1665 case ACER_WMID:
1666 return sprintf(buf, "WMID\n");
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001667 case ACER_WMID_v2:
1668 return sprintf(buf, "WMID v2\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001669 default:
1670 return sprintf(buf, "Error!\n");
1671 }
1672}
1673
Axel Lin370525d2010-06-30 10:20:23 +08001674static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001675
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001676static void acer_wmi_notify(u32 value, void *context)
1677{
1678 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1679 union acpi_object *obj;
1680 struct event_return_value return_value;
1681 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001682 u16 device_state;
1683 const struct key_entry *key;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001684 u32 scancode;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001685
1686 status = wmi_get_event_data(value, &response);
1687 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001688 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001689 return;
1690 }
1691
1692 obj = (union acpi_object *)response.pointer;
1693
1694 if (!obj)
1695 return;
1696 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001697 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001698 kfree(obj);
1699 return;
1700 }
1701 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001702 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001703 kfree(obj);
1704 return;
1705 }
1706
1707 return_value = *((struct event_return_value *)obj->buffer.pointer);
1708 kfree(obj);
1709
1710 switch (return_value.function) {
1711 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001712 device_state = return_value.device_state;
1713 pr_debug("device state: 0x%x\n", device_state);
1714
1715 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1716 return_value.key_num);
1717 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001718 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001719 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001720 } else {
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001721 scancode = return_value.key_num;
Seth Forshee92530662011-06-21 12:00:33 -05001722 switch (key->keycode) {
1723 case KEY_WLAN:
1724 case KEY_BLUETOOTH:
1725 if (has_cap(ACER_CAP_WIRELESS))
1726 rfkill_set_sw_state(wireless_rfkill,
1727 !(device_state & ACER_WMID3_GDS_WIRELESS));
1728 if (has_cap(ACER_CAP_THREEG))
1729 rfkill_set_sw_state(threeg_rfkill,
1730 !(device_state & ACER_WMID3_GDS_THREEG));
1731 if (has_cap(ACER_CAP_BLUETOOTH))
1732 rfkill_set_sw_state(bluetooth_rfkill,
1733 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1734 break;
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001735 case KEY_TOUCHPAD_TOGGLE:
1736 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1737 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
Seth Forshee92530662011-06-21 12:00:33 -05001738 }
Lee, Chun-Yi8e2286c2012-12-14 16:14:27 +08001739 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
Seth Forshee92530662011-06-21 12:00:33 -05001740 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001741 break;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001742 case WMID_ACCEL_EVENT:
1743 acer_gsensor_event();
1744 break;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001745 default:
Joe Perches249c7202011-03-29 15:21:34 -07001746 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001747 return_value.function, return_value.key_num);
1748 break;
1749 }
1750}
1751
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001752static acpi_status
1753wmid3_set_lm_mode(struct lm_input_params *params,
1754 struct lm_return_value *return_value)
1755{
1756 acpi_status status;
1757 union acpi_object *obj;
1758
1759 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1760 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1761
1762 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1763 if (ACPI_FAILURE(status))
1764 return status;
1765
1766 obj = output.pointer;
1767
1768 if (!obj)
1769 return AE_ERROR;
1770 else if (obj->type != ACPI_TYPE_BUFFER) {
1771 kfree(obj);
1772 return AE_ERROR;
1773 }
1774 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001775 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001776 kfree(obj);
1777 return AE_ERROR;
1778 }
1779
1780 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1781 kfree(obj);
1782
1783 return status;
1784}
1785
1786static int acer_wmi_enable_ec_raw(void)
1787{
1788 struct lm_return_value return_value;
1789 acpi_status status;
1790 struct lm_input_params params = {
1791 .function_num = 0x1,
1792 .commun_devices = 0xFFFF,
1793 .devices = 0xFFFF,
1794 .lm_status = 0x00, /* Launch Manager Deactive */
1795 };
1796
1797 status = wmid3_set_lm_mode(&params, &return_value);
1798
1799 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001800 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1801 return_value.error_code,
1802 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001803 else
Joe Perches249c7202011-03-29 15:21:34 -07001804 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001805
1806 return status;
1807}
1808
1809static int acer_wmi_enable_lm(void)
1810{
1811 struct lm_return_value return_value;
1812 acpi_status status;
1813 struct lm_input_params params = {
1814 .function_num = 0x1,
1815 .commun_devices = 0xFFFF,
1816 .devices = 0xFFFF,
1817 .lm_status = 0x01, /* Launch Manager Active */
1818 };
1819
1820 status = wmid3_set_lm_mode(&params, &return_value);
1821
1822 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001823 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1824 return_value.error_code,
1825 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001826
1827 return status;
1828}
1829
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001830static acpi_status __init acer_wmi_get_handle_cb(acpi_handle ah, u32 level,
1831 void *ctx, void **retval)
1832{
1833 *(acpi_handle *)retval = ah;
1834 return AE_OK;
1835}
1836
1837static int __init acer_wmi_get_handle(const char *name, const char *prop,
1838 acpi_handle *ah)
1839{
1840 acpi_status status;
1841 acpi_handle handle;
1842
1843 BUG_ON(!name || !ah);
1844
Marek Vasut24237c42012-07-05 01:30:09 +02001845 handle = NULL;
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001846 status = acpi_get_devices(prop, acer_wmi_get_handle_cb,
1847 (void *)name, &handle);
1848
1849 if (ACPI_SUCCESS(status)) {
1850 *ah = handle;
1851 return 0;
1852 } else {
1853 return -ENODEV;
1854 }
1855}
1856
1857static int __init acer_wmi_accel_setup(void)
1858{
1859 int err;
1860
1861 err = acer_wmi_get_handle("SENR", "BST0001", &gsensor_handle);
1862 if (err)
1863 return err;
1864
1865 interface->capability |= ACER_CAP_ACCEL;
1866
1867 acer_wmi_accel_dev = input_allocate_device();
1868 if (!acer_wmi_accel_dev)
1869 return -ENOMEM;
1870
1871 acer_wmi_accel_dev->open = acer_gsensor_open;
1872
1873 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
1874 acer_wmi_accel_dev->phys = "wmi/input1";
1875 acer_wmi_accel_dev->id.bustype = BUS_HOST;
1876 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
1877 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
1878 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
1879 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
1880
1881 err = input_register_device(acer_wmi_accel_dev);
1882 if (err)
1883 goto err_free_dev;
1884
1885 return 0;
1886
1887err_free_dev:
1888 input_free_device(acer_wmi_accel_dev);
1889 return err;
1890}
1891
1892static void acer_wmi_accel_destroy(void)
1893{
1894 input_unregister_device(acer_wmi_accel_dev);
Marek Vasut1eb3fe12012-06-01 19:11:22 +02001895}
1896
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001897static int __init acer_wmi_input_setup(void)
1898{
1899 acpi_status status;
1900 int err;
1901
1902 acer_wmi_input_dev = input_allocate_device();
1903 if (!acer_wmi_input_dev)
1904 return -ENOMEM;
1905
1906 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1907 acer_wmi_input_dev->phys = "wmi/input0";
1908 acer_wmi_input_dev->id.bustype = BUS_HOST;
1909
1910 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1911 if (err)
1912 goto err_free_dev;
1913
1914 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1915 acer_wmi_notify, NULL);
1916 if (ACPI_FAILURE(status)) {
1917 err = -EIO;
1918 goto err_free_keymap;
1919 }
1920
1921 err = input_register_device(acer_wmi_input_dev);
1922 if (err)
1923 goto err_uninstall_notifier;
1924
1925 return 0;
1926
1927err_uninstall_notifier:
1928 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1929err_free_keymap:
1930 sparse_keymap_free(acer_wmi_input_dev);
1931err_free_dev:
1932 input_free_device(acer_wmi_input_dev);
1933 return err;
1934}
1935
1936static void acer_wmi_input_destroy(void)
1937{
1938 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1939 sparse_keymap_free(acer_wmi_input_dev);
1940 input_unregister_device(acer_wmi_input_dev);
1941}
1942
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001943/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001944 * debugfs functions
1945 */
1946static u32 get_wmid_devices(void)
1947{
1948 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1949 union acpi_object *obj;
1950 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001951 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001952
1953 status = wmi_query_block(WMID_GUID2, 1, &out);
1954 if (ACPI_FAILURE(status))
1955 return 0;
1956
1957 obj = (union acpi_object *) out.pointer;
Lee, Chun-Yif20aaba2012-12-14 16:14:26 +08001958 if (obj) {
1959 if (obj->type == ACPI_TYPE_BUFFER &&
1960 (obj->buffer.length == sizeof(u32) ||
1961 obj->buffer.length == sizeof(u64))) {
1962 devices = *((u32 *) obj->buffer.pointer);
1963 } else if (obj->type == ACPI_TYPE_INTEGER) {
1964 devices = (u32) obj->integer.value;
1965 }
Carlos Corbacho81143522008-06-21 09:09:53 +01001966 }
Axel Lin66904862010-07-20 15:19:52 -07001967
1968 kfree(out.pointer);
1969 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001970}
1971
1972/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001973 * Platform device
1974 */
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001975static int acer_platform_probe(struct platform_device *device)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001976{
1977 int err;
1978
1979 if (has_cap(ACER_CAP_MAILLED)) {
1980 err = acer_led_init(&device->dev);
1981 if (err)
1982 goto error_mailled;
1983 }
1984
1985 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1986 err = acer_backlight_init(&device->dev);
1987 if (err)
1988 goto error_brightness;
1989 }
1990
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001991 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001992 if (err)
1993 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001994
1995 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001996
Andy Whitcroft350e3292009-04-04 09:33:34 +01001997error_rfkill:
1998 if (has_cap(ACER_CAP_BRIGHTNESS))
1999 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002000error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01002001 if (has_cap(ACER_CAP_MAILLED))
2002 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002003error_mailled:
2004 return err;
2005}
2006
2007static int acer_platform_remove(struct platform_device *device)
2008{
2009 if (has_cap(ACER_CAP_MAILLED))
2010 acer_led_exit();
2011 if (has_cap(ACER_CAP_BRIGHTNESS))
2012 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01002013
2014 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002015 return 0;
2016}
2017
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002018static int acer_suspend(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002019{
2020 u32 value;
2021 struct acer_data *data = &interface->data;
2022
2023 if (!data)
2024 return -ENOMEM;
2025
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002026 if (has_cap(ACER_CAP_MAILLED)) {
2027 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002028 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002029 data->mailled = value;
2030 }
2031
2032 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2033 get_u32(&value, ACER_CAP_BRIGHTNESS);
2034 data->brightness = value;
2035 }
2036
2037 return 0;
2038}
2039
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002040static int acer_resume(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002041{
2042 struct acer_data *data = &interface->data;
2043
2044 if (!data)
2045 return -ENOMEM;
2046
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002047 if (has_cap(ACER_CAP_MAILLED))
2048 set_u32(data->mailled, ACER_CAP_MAILLED);
2049
2050 if (has_cap(ACER_CAP_BRIGHTNESS))
2051 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2052
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002053 if (has_cap(ACER_CAP_ACCEL))
2054 acer_gsensor_init();
2055
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002056 return 0;
2057}
2058
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002059static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2060
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002061static void acer_platform_shutdown(struct platform_device *device)
2062{
2063 struct acer_data *data = &interface->data;
2064
2065 if (!data)
2066 return;
2067
2068 if (has_cap(ACER_CAP_MAILLED))
2069 set_u32(LED_OFF, ACER_CAP_MAILLED);
2070}
2071
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002072static struct platform_driver acer_platform_driver = {
2073 .driver = {
2074 .name = "acer-wmi",
2075 .owner = THIS_MODULE,
Rafael J. Wysocki3c33be0b2012-06-27 23:19:35 +02002076 .pm = &acer_pm,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002077 },
2078 .probe = acer_platform_probe,
2079 .remove = acer_platform_remove,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01002080 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002081};
2082
2083static struct platform_device *acer_platform_device;
2084
2085static int remove_sysfs(struct platform_device *device)
2086{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002087 if (has_cap(ACER_CAP_THREEG))
2088 device_remove_file(&device->dev, &dev_attr_threeg);
2089
2090 device_remove_file(&device->dev, &dev_attr_interface);
2091
2092 return 0;
2093}
2094
2095static int create_sysfs(void)
2096{
2097 int retval = -ENOMEM;
2098
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002099 if (has_cap(ACER_CAP_THREEG)) {
2100 retval = device_create_file(&acer_platform_device->dev,
2101 &dev_attr_threeg);
2102 if (retval)
2103 goto error_sysfs;
2104 }
2105
2106 retval = device_create_file(&acer_platform_device->dev,
2107 &dev_attr_interface);
2108 if (retval)
2109 goto error_sysfs;
2110
2111 return 0;
2112
2113error_sysfs:
2114 remove_sysfs(acer_platform_device);
2115 return retval;
2116}
2117
Carlos Corbacho81143522008-06-21 09:09:53 +01002118static void remove_debugfs(void)
2119{
2120 debugfs_remove(interface->debug.devices);
2121 debugfs_remove(interface->debug.root);
2122}
2123
2124static int create_debugfs(void)
2125{
2126 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2127 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002128 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01002129 return -ENOMEM;
2130 }
2131
2132 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
2133 interface->debug.root,
2134 &interface->debug.wmid_devices);
2135 if (!interface->debug.devices)
2136 goto error_debugfs;
2137
2138 return 0;
2139
2140error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07002141 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01002142 return -ENOMEM;
2143}
2144
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002145static int __init acer_wmi_init(void)
2146{
2147 int err;
2148
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002149 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002150
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002151 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002152 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01002153 return -ENODEV;
2154 }
2155
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01002156 find_quirks();
2157
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002158 /*
2159 * Detect which ACPI-WMI interface we're using.
2160 */
2161 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2162 interface = &AMW0_V2_interface;
2163
2164 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2165 interface = &wmid_interface;
2166
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002167 if (wmi_has_guid(WMID_GUID3))
2168 interface = &wmid_v2_interface;
2169
2170 if (interface)
2171 dmi_walk(type_aa_dmi_decode, NULL);
2172
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002173 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002174 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002175 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002176 return -ENODEV;
2177 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002178 /* WMID always provides brightness methods */
2179 interface->capability |= ACER_CAP_BRIGHTNESS;
2180 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002181 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002182 return -ENODEV;
2183 }
2184
2185 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2186 interface = &AMW0_interface;
2187
2188 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002189 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002190 return -ENODEV;
2191 }
2192 }
2193
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002194 if (wmi_has_guid(AMW0_GUID1))
2195 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002196
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002197 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002198 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002199 return -ENODEV;
2200 }
2201
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002202 set_quirks();
2203
Corentin Charya60b2172012-06-13 09:32:02 +02002204 if (dmi_check_system(video_vendor_dmi_table))
2205 acpi_video_dmi_promote_vendor();
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002206 if (acpi_video_backlight_support()) {
Corentin Charya60b2172012-06-13 09:32:02 +02002207 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2208 pr_info("Brightness must be controlled by acpi video driver\n");
2209 } else {
Corentin Charya60b2172012-06-13 09:32:02 +02002210 pr_info("Disabling ACPI video driver\n");
2211 acpi_video_unregister();
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002212 }
2213
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002214 if (wmi_has_guid(WMID_GUID3)) {
2215 if (ec_raw_mode) {
2216 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002217 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002218 return -ENODEV;
2219 }
2220 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002221 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002222 return -ENODEV;
2223 }
2224 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002225 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002226 }
2227
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002228 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2229 err = acer_wmi_input_setup();
2230 if (err)
2231 return err;
2232 }
2233
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002234 acer_wmi_accel_setup();
2235
Axel Lin1c796322010-06-22 16:17:38 +08002236 err = platform_driver_register(&acer_platform_driver);
2237 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002238 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002239 goto error_platform_register;
2240 }
Axel Lin1c796322010-06-22 16:17:38 +08002241
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002242 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002243 if (!acer_platform_device) {
2244 err = -ENOMEM;
2245 goto error_device_alloc;
2246 }
2247
2248 err = platform_device_add(acer_platform_device);
2249 if (err)
2250 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002251
2252 err = create_sysfs();
2253 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002254 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002255
Carlos Corbacho81143522008-06-21 09:09:53 +01002256 if (wmi_has_guid(WMID_GUID2)) {
2257 interface->debug.wmid_devices = get_wmid_devices();
2258 err = create_debugfs();
2259 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002260 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002261 }
2262
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002263 /* Override any initial settings with values from the commandline */
2264 acer_commandline_init();
2265
2266 return 0;
2267
Axel Lin1c796322010-06-22 16:17:38 +08002268error_create_debugfs:
2269 remove_sysfs(acer_platform_device);
2270error_create_sys:
2271 platform_device_del(acer_platform_device);
2272error_device_add:
2273 platform_device_put(acer_platform_device);
2274error_device_alloc:
2275 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002276error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002277 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2278 acer_wmi_input_destroy();
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002279 if (has_cap(ACER_CAP_ACCEL))
2280 acer_wmi_accel_destroy();
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002281
Axel Lin1c796322010-06-22 16:17:38 +08002282 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002283}
2284
2285static void __exit acer_wmi_exit(void)
2286{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002287 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2288 acer_wmi_input_destroy();
2289
Marek Vasut1eb3fe12012-06-01 19:11:22 +02002290 if (has_cap(ACER_CAP_ACCEL))
2291 acer_wmi_accel_destroy();
2292
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002293 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07002294 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002295 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002296 platform_driver_unregister(&acer_platform_driver);
2297
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002298 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002299 return;
2300}
2301
2302module_init(acer_wmi_init);
2303module_exit(acer_wmi_exit);