blob: 3b3cd070b9dc88424df04d64714362df3bad5079 [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>
46
47MODULE_AUTHOR("Carlos Corbacho");
48MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
49MODULE_LICENSE("GPL");
50
Carlos Corbacho745a5d22008-02-05 02:17:10 +000051/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000052 * Magic Number
53 * Meaning is unknown - this number is required for writing to ACPI for AMW0
54 * (it's also used in acerhk when directly accessing the BIOS)
55 */
56#define ACER_AMW0_WRITE 0x9610
57
58/*
59 * Bit masks for the AMW0 interface
60 */
61#define ACER_AMW0_WIRELESS_MASK 0x35
62#define ACER_AMW0_BLUETOOTH_MASK 0x34
63#define ACER_AMW0_MAILLED_MASK 0x31
64
65/*
66 * Method IDs for WMID interface
67 */
68#define ACER_WMID_GET_WIRELESS_METHODID 1
69#define ACER_WMID_GET_BLUETOOTH_METHODID 2
70#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
71#define ACER_WMID_SET_WIRELESS_METHODID 4
72#define ACER_WMID_SET_BLUETOOTH_METHODID 5
73#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
74#define ACER_WMID_GET_THREEG_METHODID 10
75#define ACER_WMID_SET_THREEG_METHODID 11
76
77/*
78 * Acer ACPI method GUIDs
79 */
80#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010081#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Matthew Garrettbbb70602011-02-09 16:39:40 -050082#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
Pali Rohár298f19b2011-03-11 12:36:43 -050083#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080084#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000085
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080086/*
87 * Acer ACPI event GUIDs
88 */
89#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
90
Carlos Corbacho745a5d22008-02-05 02:17:10 +000091MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
Lee, Chun-Yi08a07992011-04-06 17:40:06 +080092MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080093MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
94
95enum acer_wmi_event_ids {
96 WMID_HOTKEY_EVENT = 0x1,
97};
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-Yi89411782011-03-02 01:07:11 +0800126 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200127 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800128 {KE_END, 0}
129};
130
131static struct input_dev *acer_wmi_input_dev;
132
133struct event_return_value {
134 u8 function;
135 u8 key_num;
136 u16 device_state;
137 u32 reserved;
138} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000139
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000140/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800141 * GUID3 Get Device Status device flags
142 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800143#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800144#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800145#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800146#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800147
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500148struct lm_input_params {
149 u8 function_num; /* Function Number */
150 u16 commun_devices; /* Communication type devices default status */
151 u16 devices; /* Other type devices default status */
152 u8 lm_status; /* Launch Manager Status */
153 u16 reserved;
154} __attribute__((packed));
155
156struct lm_return_value {
157 u8 error_code; /* Error Code */
158 u8 ec_return_value; /* EC Return Value */
159 u16 reserved;
160} __attribute__((packed));
161
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800162struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
163 u8 function_num; /* Function Number */
164 u8 hotkey_number; /* Hotkey Number */
165 u16 devices; /* Set Device */
166 u8 volume_value; /* Volume Value */
167} __attribute__((packed));
168
169struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800170 u8 function_num; /* Function Number */
171 u8 hotkey_number; /* Hotkey Number */
172 u16 devices; /* Get Device */
173} __attribute__((packed));
174
175struct wmid3_gds_return_value { /* Get Device Status return value*/
176 u8 error_code; /* Error Code */
177 u8 ec_return_value; /* EC Return Value */
178 u16 devices; /* Current Device Status */
179 u32 reserved;
180} __attribute__((packed));
181
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800182struct hotkey_function_type_aa {
183 u8 type;
184 u8 length;
185 u16 handle;
186 u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800187 u16 application_func_bitmap;
188 u16 media_func_bitmap;
189 u16 display_func_bitmap;
190 u16 others_func_bitmap;
191 u8 commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800192} __attribute__((packed));
193
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800194/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000195 * Interface capability flags
196 */
197#define ACER_CAP_MAILLED (1<<0)
198#define ACER_CAP_WIRELESS (1<<1)
199#define ACER_CAP_BLUETOOTH (1<<2)
200#define ACER_CAP_BRIGHTNESS (1<<3)
201#define ACER_CAP_THREEG (1<<4)
202#define ACER_CAP_ANY (0xFFFFFFFF)
203
204/*
205 * Interface type flags
206 */
207enum interface_flags {
208 ACER_AMW0,
209 ACER_AMW0_V2,
210 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800211 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000212};
213
214#define ACER_DEFAULT_WIRELESS 0
215#define ACER_DEFAULT_BLUETOOTH 0
216#define ACER_DEFAULT_MAILLED 0
217#define ACER_DEFAULT_THREEG 0
218
219static int max_brightness = 0xF;
220
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000221static int mailled = -1;
222static int brightness = -1;
223static int threeg = -1;
224static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500225static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800226static bool has_type_aa;
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +0800227static u16 commun_func_bitmap;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800228static u8 commun_fn_key_number;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000229
230module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000231module_param(brightness, int, 0444);
232module_param(threeg, int, 0444);
233module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500234module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000235MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
236MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
237MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
238MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500239MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000240
241struct acer_data {
242 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000243 int threeg;
244 int brightness;
245};
246
Carlos Corbacho81143522008-06-21 09:09:53 +0100247struct acer_debug {
248 struct dentry *root;
249 struct dentry *devices;
250 u32 wmid_devices;
251};
252
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100253static struct rfkill *wireless_rfkill;
254static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800255static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800256static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100257
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000258/* Each low-level interface must define at least some of the following */
259struct wmi_interface {
260 /* The WMI device type */
261 u32 type;
262
263 /* The capabilities this interface provides */
264 u32 capability;
265
266 /* Private data for the current interface */
267 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100268
269 /* debugfs entries associated with this interface */
270 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000271};
272
273/* The static interface pointer, points to the currently detected interface */
274static struct wmi_interface *interface;
275
276/*
277 * Embedded Controller quirks
278 * Some laptops require us to directly access the EC to either enable or query
279 * features that are not available through WMI.
280 */
281
282struct quirk_entry {
283 u8 wireless;
284 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100285 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000286 u8 bluetooth;
287};
288
289static struct quirk_entry *quirks;
290
291static void set_quirks(void)
292{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700293 if (!interface)
294 return;
295
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000296 if (quirks->mailled)
297 interface->capability |= ACER_CAP_MAILLED;
298
299 if (quirks->brightness)
300 interface->capability |= ACER_CAP_BRIGHTNESS;
301}
302
303static int dmi_matched(const struct dmi_system_id *dmi)
304{
305 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800306 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000307}
308
309static struct quirk_entry quirk_unknown = {
310};
311
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100312static struct quirk_entry quirk_acer_aspire_1520 = {
313 .brightness = -1,
314};
315
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000316static struct quirk_entry quirk_acer_travelmate_2490 = {
317 .mailled = 1,
318};
319
320/* This AMW0 laptop has no bluetooth */
321static struct quirk_entry quirk_medion_md_98300 = {
322 .wireless = 1,
323};
324
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100325static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
326 .wireless = 2,
327};
328
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800329static struct quirk_entry quirk_lenovo_ideapad_s205 = {
330 .wireless = 3,
331};
332
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100333/* The Aspire One has a dummy ACPI-WMI interface - disable it */
334static struct dmi_system_id __devinitdata acer_blacklist[] = {
335 {
336 .ident = "Acer Aspire One (SSD)",
337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
340 },
341 },
342 {
343 .ident = "Acer Aspire One (HDD)",
344 .matches = {
345 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
346 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
347 },
348 },
349 {}
350};
351
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000352static struct dmi_system_id acer_quirks[] = {
353 {
354 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100355 .ident = "Acer Aspire 1360",
356 .matches = {
357 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
358 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
359 },
360 .driver_data = &quirk_acer_aspire_1520,
361 },
362 {
363 .callback = dmi_matched,
364 .ident = "Acer Aspire 1520",
365 .matches = {
366 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
367 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
368 },
369 .driver_data = &quirk_acer_aspire_1520,
370 },
371 {
372 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000373 .ident = "Acer Aspire 3100",
374 .matches = {
375 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
376 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
377 },
378 .driver_data = &quirk_acer_travelmate_2490,
379 },
380 {
381 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000382 .ident = "Acer Aspire 3610",
383 .matches = {
384 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
385 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
386 },
387 .driver_data = &quirk_acer_travelmate_2490,
388 },
389 {
390 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000391 .ident = "Acer Aspire 5100",
392 .matches = {
393 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
394 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
395 },
396 .driver_data = &quirk_acer_travelmate_2490,
397 },
398 {
399 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000400 .ident = "Acer Aspire 5610",
401 .matches = {
402 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
403 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
404 },
405 .driver_data = &quirk_acer_travelmate_2490,
406 },
407 {
408 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000409 .ident = "Acer Aspire 5630",
410 .matches = {
411 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
412 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
413 },
414 .driver_data = &quirk_acer_travelmate_2490,
415 },
416 {
417 .callback = dmi_matched,
418 .ident = "Acer Aspire 5650",
419 .matches = {
420 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
421 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
422 },
423 .driver_data = &quirk_acer_travelmate_2490,
424 },
425 {
426 .callback = dmi_matched,
427 .ident = "Acer Aspire 5680",
428 .matches = {
429 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
430 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
431 },
432 .driver_data = &quirk_acer_travelmate_2490,
433 },
434 {
435 .callback = dmi_matched,
436 .ident = "Acer Aspire 9110",
437 .matches = {
438 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
439 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
440 },
441 .driver_data = &quirk_acer_travelmate_2490,
442 },
443 {
444 .callback = dmi_matched,
445 .ident = "Acer TravelMate 2490",
446 .matches = {
447 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
448 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
449 },
450 .driver_data = &quirk_acer_travelmate_2490,
451 },
452 {
453 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000454 .ident = "Acer TravelMate 4200",
455 .matches = {
456 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
457 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
458 },
459 .driver_data = &quirk_acer_travelmate_2490,
460 },
461 {
462 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100463 .ident = "Fujitsu Siemens Amilo Li 1718",
464 .matches = {
465 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
466 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
467 },
468 .driver_data = &quirk_fujitsu_amilo_li_1718,
469 },
470 {
471 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000472 .ident = "Medion MD 98300",
473 .matches = {
474 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
475 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
476 },
477 .driver_data = &quirk_medion_md_98300,
478 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800479 {
480 .callback = dmi_matched,
481 .ident = "Lenovo Ideapad S205",
482 .matches = {
483 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
484 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
485 },
486 .driver_data = &quirk_lenovo_ideapad_s205,
487 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500488 {
489 .callback = dmi_matched,
Lee, Chun-Yic08f2082012-03-20 11:32:49 +0800490 .ident = "Lenovo Ideapad S205 (Brazos)",
491 .matches = {
492 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
493 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
494 },
495 .driver_data = &quirk_lenovo_ideapad_s205,
496 },
497 {
498 .callback = dmi_matched,
Seth Forsheebe3128b2011-10-06 15:01:55 -0500499 .ident = "Lenovo 3000 N200",
500 .matches = {
501 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
502 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
503 },
504 .driver_data = &quirk_fujitsu_amilo_li_1718,
505 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000506 {}
507};
508
509/* Find which quirks are needed for a particular vendor/ model pair */
510static void find_quirks(void)
511{
512 if (!force_series) {
513 dmi_check_system(acer_quirks);
514 } else if (force_series == 2490) {
515 quirks = &quirk_acer_travelmate_2490;
516 }
517
518 if (quirks == NULL)
519 quirks = &quirk_unknown;
520
521 set_quirks();
522}
523
524/*
525 * General interface convenience methods
526 */
527
528static bool has_cap(u32 cap)
529{
530 if ((interface->capability & cap) != 0)
531 return 1;
532
533 return 0;
534}
535
536/*
537 * AMW0 (V1) interface
538 */
539struct wmab_args {
540 u32 eax;
541 u32 ebx;
542 u32 ecx;
543 u32 edx;
544};
545
546struct wmab_ret {
547 u32 eax;
548 u32 ebx;
549 u32 ecx;
550 u32 edx;
551 u32 eex;
552};
553
554static acpi_status wmab_execute(struct wmab_args *regbuf,
555struct acpi_buffer *result)
556{
557 struct acpi_buffer input;
558 acpi_status status;
559 input.length = sizeof(struct wmab_args);
560 input.pointer = (u8 *)regbuf;
561
562 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
563
564 return status;
565}
566
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800567static acpi_status AMW0_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000568{
569 int err;
570 u8 result;
571
572 switch (cap) {
573 case ACER_CAP_MAILLED:
574 switch (quirks->mailled) {
575 default:
576 err = ec_read(0xA, &result);
577 if (err)
578 return AE_ERROR;
579 *value = (result >> 7) & 0x1;
580 return AE_OK;
581 }
582 break;
583 case ACER_CAP_WIRELESS:
584 switch (quirks->wireless) {
585 case 1:
586 err = ec_read(0x7B, &result);
587 if (err)
588 return AE_ERROR;
589 *value = result & 0x1;
590 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100591 case 2:
592 err = ec_read(0x71, &result);
593 if (err)
594 return AE_ERROR;
595 *value = result & 0x1;
596 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800597 case 3:
598 err = ec_read(0x78, &result);
599 if (err)
600 return AE_ERROR;
601 *value = result & 0x1;
602 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000603 default:
604 err = ec_read(0xA, &result);
605 if (err)
606 return AE_ERROR;
607 *value = (result >> 2) & 0x1;
608 return AE_OK;
609 }
610 break;
611 case ACER_CAP_BLUETOOTH:
612 switch (quirks->bluetooth) {
613 default:
614 err = ec_read(0xA, &result);
615 if (err)
616 return AE_ERROR;
617 *value = (result >> 4) & 0x1;
618 return AE_OK;
619 }
620 break;
621 case ACER_CAP_BRIGHTNESS:
622 switch (quirks->brightness) {
623 default:
624 err = ec_read(0x83, &result);
625 if (err)
626 return AE_ERROR;
627 *value = result;
628 return AE_OK;
629 }
630 break;
631 default:
Lin Ming08237972008-08-08 11:57:11 +0800632 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000633 }
634 return AE_OK;
635}
636
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800637static acpi_status AMW0_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000638{
639 struct wmab_args args;
640
641 args.eax = ACER_AMW0_WRITE;
642 args.ebx = value ? (1<<8) : 0;
643 args.ecx = args.edx = 0;
644
645 switch (cap) {
646 case ACER_CAP_MAILLED:
647 if (value > 1)
648 return AE_BAD_PARAMETER;
649 args.ebx |= ACER_AMW0_MAILLED_MASK;
650 break;
651 case ACER_CAP_WIRELESS:
652 if (value > 1)
653 return AE_BAD_PARAMETER;
654 args.ebx |= ACER_AMW0_WIRELESS_MASK;
655 break;
656 case ACER_CAP_BLUETOOTH:
657 if (value > 1)
658 return AE_BAD_PARAMETER;
659 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
660 break;
661 case ACER_CAP_BRIGHTNESS:
662 if (value > max_brightness)
663 return AE_BAD_PARAMETER;
664 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000665 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000666 return ec_write(0x83, value);
667 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000668 }
669 default:
Lin Ming08237972008-08-08 11:57:11 +0800670 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000671 }
672
673 /* Actually do the set */
674 return wmab_execute(&args, NULL);
675}
676
677static acpi_status AMW0_find_mailled(void)
678{
679 struct wmab_args args;
680 struct wmab_ret ret;
681 acpi_status status = AE_OK;
682 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
683 union acpi_object *obj;
684
685 args.eax = 0x86;
686 args.ebx = args.ecx = args.edx = 0;
687
688 status = wmab_execute(&args, &out);
689 if (ACPI_FAILURE(status))
690 return status;
691
692 obj = (union acpi_object *) out.pointer;
693 if (obj && obj->type == ACPI_TYPE_BUFFER &&
694 obj->buffer.length == sizeof(struct wmab_ret)) {
695 ret = *((struct wmab_ret *) obj->buffer.pointer);
696 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700697 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000698 return AE_ERROR;
699 }
700
701 if (ret.eex & 0x1)
702 interface->capability |= ACER_CAP_MAILLED;
703
704 kfree(out.pointer);
705
706 return AE_OK;
707}
708
Ike Panhc461e7432012-02-03 16:46:39 +0800709static int AMW0_set_cap_acpi_check_device_found;
710
711static acpi_status AMW0_set_cap_acpi_check_device_cb(acpi_handle handle,
712 u32 level, void *context, void **retval)
713{
714 AMW0_set_cap_acpi_check_device_found = 1;
715 return AE_OK;
716}
717
718static const struct acpi_device_id norfkill_ids[] = {
719 { "VPC2004", 0},
720 { "IBM0068", 0},
721 { "LEN0068", 0},
722 { "", 0},
723};
724
725static int AMW0_set_cap_acpi_check_device(void)
726{
727 const struct acpi_device_id *id;
728
729 for (id = norfkill_ids; id->id[0]; id++)
730 acpi_get_devices(id->id, AMW0_set_cap_acpi_check_device_cb,
731 NULL, NULL);
732 return AMW0_set_cap_acpi_check_device_found;
733}
734
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000735static acpi_status AMW0_set_capabilities(void)
736{
737 struct wmab_args args;
738 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700739 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000740 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
741 union acpi_object *obj;
742
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100743 /*
744 * On laptops with this strange GUID (non Acer), normal probing doesn't
745 * work.
746 */
747 if (wmi_has_guid(AMW0_GUID2)) {
Ike Panhc461e7432012-02-03 16:46:39 +0800748 if ((quirks != &quirk_unknown) ||
749 !AMW0_set_cap_acpi_check_device())
750 interface->capability |= ACER_CAP_WIRELESS;
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100751 return AE_OK;
752 }
753
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000754 args.eax = ACER_AMW0_WRITE;
755 args.ecx = args.edx = 0;
756
757 args.ebx = 0xa2 << 8;
758 args.ebx |= ACER_AMW0_WIRELESS_MASK;
759
760 status = wmab_execute(&args, &out);
761 if (ACPI_FAILURE(status))
762 return status;
763
Axel Lin7677fbd2010-07-20 15:19:53 -0700764 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000765 if (obj && obj->type == ACPI_TYPE_BUFFER &&
766 obj->buffer.length == sizeof(struct wmab_ret)) {
767 ret = *((struct wmab_ret *) obj->buffer.pointer);
768 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700769 status = AE_ERROR;
770 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000771 }
772
773 if (ret.eax & 0x1)
774 interface->capability |= ACER_CAP_WIRELESS;
775
776 args.ebx = 2 << 8;
777 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
778
Axel Lin7677fbd2010-07-20 15:19:53 -0700779 /*
780 * It's ok to use existing buffer for next wmab_execute call.
781 * But we need to kfree(out.pointer) if next wmab_execute fail.
782 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000783 status = wmab_execute(&args, &out);
784 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700785 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000786
787 obj = (union acpi_object *) out.pointer;
788 if (obj && obj->type == ACPI_TYPE_BUFFER
789 && obj->buffer.length == sizeof(struct wmab_ret)) {
790 ret = *((struct wmab_ret *) obj->buffer.pointer);
791 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700792 status = AE_ERROR;
793 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000794 }
795
796 if (ret.eax & 0x1)
797 interface->capability |= ACER_CAP_BLUETOOTH;
798
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000799 /*
800 * This appears to be safe to enable, since all Wistron based laptops
801 * appear to use the same EC register for brightness, even if they
802 * differ for wireless, etc
803 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100804 if (quirks->brightness >= 0)
805 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000806
Axel Lin7677fbd2010-07-20 15:19:53 -0700807 status = AE_OK;
808out:
809 kfree(out.pointer);
810 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000811}
812
813static struct wmi_interface AMW0_interface = {
814 .type = ACER_AMW0,
815};
816
817static struct wmi_interface AMW0_V2_interface = {
818 .type = ACER_AMW0_V2,
819};
820
821/*
822 * New interface (The WMID interface)
823 */
824static acpi_status
825WMI_execute_u32(u32 method_id, u32 in, u32 *out)
826{
827 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
828 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
829 union acpi_object *obj;
830 u32 tmp;
831 acpi_status status;
832
833 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
834
835 if (ACPI_FAILURE(status))
836 return status;
837
838 obj = (union acpi_object *) result.pointer;
839 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +0800840 (obj->buffer.length == sizeof(u32) ||
841 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000842 tmp = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +0800843 } else if (obj->type == ACPI_TYPE_INTEGER) {
844 tmp = (u32) obj->integer.value;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000845 } else {
846 tmp = 0;
847 }
848
849 if (out)
850 *out = tmp;
851
852 kfree(result.pointer);
853
854 return status;
855}
856
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800857static acpi_status WMID_get_u32(u32 *value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000858{
859 acpi_status status;
860 u8 tmp;
861 u32 result, method_id = 0;
862
863 switch (cap) {
864 case ACER_CAP_WIRELESS:
865 method_id = ACER_WMID_GET_WIRELESS_METHODID;
866 break;
867 case ACER_CAP_BLUETOOTH:
868 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
869 break;
870 case ACER_CAP_BRIGHTNESS:
871 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
872 break;
873 case ACER_CAP_THREEG:
874 method_id = ACER_WMID_GET_THREEG_METHODID;
875 break;
876 case ACER_CAP_MAILLED:
877 if (quirks->mailled == 1) {
878 ec_read(0x9f, &tmp);
879 *value = tmp & 0x1;
880 return 0;
881 }
882 default:
Lin Ming08237972008-08-08 11:57:11 +0800883 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000884 }
885 status = WMI_execute_u32(method_id, 0, &result);
886
887 if (ACPI_SUCCESS(status))
888 *value = (u8)result;
889
890 return status;
891}
892
Lee, Chun-Yi38db1572012-01-09 14:26:44 +0800893static acpi_status WMID_set_u32(u32 value, u32 cap)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000894{
895 u32 method_id = 0;
896 char param;
897
898 switch (cap) {
899 case ACER_CAP_BRIGHTNESS:
900 if (value > max_brightness)
901 return AE_BAD_PARAMETER;
902 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
903 break;
904 case ACER_CAP_WIRELESS:
905 if (value > 1)
906 return AE_BAD_PARAMETER;
907 method_id = ACER_WMID_SET_WIRELESS_METHODID;
908 break;
909 case ACER_CAP_BLUETOOTH:
910 if (value > 1)
911 return AE_BAD_PARAMETER;
912 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
913 break;
914 case ACER_CAP_THREEG:
915 if (value > 1)
916 return AE_BAD_PARAMETER;
917 method_id = ACER_WMID_SET_THREEG_METHODID;
918 break;
919 case ACER_CAP_MAILLED:
920 if (value > 1)
921 return AE_BAD_PARAMETER;
922 if (quirks->mailled == 1) {
923 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700924 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000925 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700926 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000927 return 0;
928 }
929 break;
930 default:
Lin Ming08237972008-08-08 11:57:11 +0800931 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000932 }
933 return WMI_execute_u32(method_id, (u32)value, NULL);
934}
935
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800936static acpi_status wmid3_get_device_status(u32 *value, u16 device)
937{
938 struct wmid3_gds_return_value return_value;
939 acpi_status status;
940 union acpi_object *obj;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800941 struct wmid3_gds_get_input_param params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800942 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +0800943 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800944 .devices = device,
945 };
946 struct acpi_buffer input = {
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +0800947 sizeof(struct wmid3_gds_get_input_param),
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800948 &params
949 };
950 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
951
952 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
953 if (ACPI_FAILURE(status))
954 return status;
955
956 obj = output.pointer;
957
958 if (!obj)
959 return AE_ERROR;
960 else if (obj->type != ACPI_TYPE_BUFFER) {
961 kfree(obj);
962 return AE_ERROR;
963 }
964 if (obj->buffer.length != 8) {
965 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
966 kfree(obj);
967 return AE_ERROR;
968 }
969
970 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
971 kfree(obj);
972
973 if (return_value.error_code || return_value.ec_return_value)
974 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
975 device,
976 return_value.error_code,
977 return_value.ec_return_value);
978 else
979 *value = !!(return_value.devices & device);
980
981 return status;
982}
983
984static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
985{
986 u16 device;
987
988 switch (cap) {
989 case ACER_CAP_WIRELESS:
990 device = ACER_WMID3_GDS_WIRELESS;
991 break;
992 case ACER_CAP_BLUETOOTH:
993 device = ACER_WMID3_GDS_BLUETOOTH;
994 break;
995 case ACER_CAP_THREEG:
996 device = ACER_WMID3_GDS_THREEG;
997 break;
998 default:
999 return AE_ERROR;
1000 }
1001 return wmid3_get_device_status(value, device);
1002}
1003
1004static acpi_status wmid3_set_device_status(u32 value, u16 device)
1005{
1006 struct wmid3_gds_return_value return_value;
1007 acpi_status status;
1008 union acpi_object *obj;
1009 u16 devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001010 struct wmid3_gds_get_input_param get_params = {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001011 .function_num = 0x1,
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001012 .hotkey_number = commun_fn_key_number,
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001013 .devices = commun_func_bitmap,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001014 };
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001015 struct acpi_buffer get_input = {
1016 sizeof(struct wmid3_gds_get_input_param),
1017 &get_params
1018 };
1019 struct wmid3_gds_set_input_param set_params = {
1020 .function_num = 0x2,
1021 .hotkey_number = commun_fn_key_number,
1022 .devices = commun_func_bitmap,
1023 };
1024 struct acpi_buffer set_input = {
1025 sizeof(struct wmid3_gds_set_input_param),
1026 &set_params
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001027 };
1028 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1029 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1030
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001031 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001032 if (ACPI_FAILURE(status))
1033 return status;
1034
1035 obj = output.pointer;
1036
1037 if (!obj)
1038 return AE_ERROR;
1039 else if (obj->type != ACPI_TYPE_BUFFER) {
1040 kfree(obj);
1041 return AE_ERROR;
1042 }
1043 if (obj->buffer.length != 8) {
Joe Perches6e71f382011-11-29 11:04:05 -08001044 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001045 kfree(obj);
1046 return AE_ERROR;
1047 }
1048
1049 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1050 kfree(obj);
1051
1052 if (return_value.error_code || return_value.ec_return_value) {
Joe Perches6e71f382011-11-29 11:04:05 -08001053 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1054 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001055 return_value.ec_return_value);
1056 return status;
1057 }
1058
1059 devices = return_value.devices;
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001060 set_params.devices = (value) ? (devices | device) : (devices & ~device);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001061
Lee, Chun-Yi996d23b2012-03-19 17:37:33 +08001062 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001063 if (ACPI_FAILURE(status))
1064 return status;
1065
1066 obj = output2.pointer;
1067
1068 if (!obj)
1069 return AE_ERROR;
1070 else if (obj->type != ACPI_TYPE_BUFFER) {
1071 kfree(obj);
1072 return AE_ERROR;
1073 }
1074 if (obj->buffer.length != 4) {
Joe Perches6e71f382011-11-29 11:04:05 -08001075 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001076 kfree(obj);
1077 return AE_ERROR;
1078 }
1079
1080 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1081 kfree(obj);
1082
1083 if (return_value.error_code || return_value.ec_return_value)
Joe Perches6e71f382011-11-29 11:04:05 -08001084 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1085 return_value.error_code,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001086 return_value.ec_return_value);
1087
1088 return status;
1089}
1090
1091static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1092{
1093 u16 device;
1094
1095 switch (cap) {
1096 case ACER_CAP_WIRELESS:
1097 device = ACER_WMID3_GDS_WIRELESS;
1098 break;
1099 case ACER_CAP_BLUETOOTH:
1100 device = ACER_WMID3_GDS_BLUETOOTH;
1101 break;
1102 case ACER_CAP_THREEG:
1103 device = ACER_WMID3_GDS_THREEG;
1104 break;
1105 default:
1106 return AE_ERROR;
1107 }
1108 return wmid3_set_device_status(value, device);
1109}
1110
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001111static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1112{
1113 struct hotkey_function_type_aa *type_aa;
1114
1115 /* We are looking for OEM-specific Type AAh */
1116 if (header->type != 0xAA)
1117 return;
1118
1119 has_type_aa = true;
1120 type_aa = (struct hotkey_function_type_aa *) header;
1121
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001122 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001123 type_aa->commun_func_bitmap);
Lee, Chun-Yi1d1fc8a2011-10-06 19:06:13 +08001124 commun_func_bitmap = type_aa->commun_func_bitmap;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001125
1126 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1127 interface->capability |= ACER_CAP_WIRELESS;
1128 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1129 interface->capability |= ACER_CAP_THREEG;
1130 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1131 interface->capability |= ACER_CAP_BLUETOOTH;
Lee, Chun-Yi34b6cfa2012-03-19 17:37:32 +08001132
1133 commun_fn_key_number = type_aa->commun_fn_key_number;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001134}
1135
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001136static acpi_status WMID_set_capabilities(void)
1137{
1138 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1139 union acpi_object *obj;
1140 acpi_status status;
1141 u32 devices;
1142
1143 status = wmi_query_block(WMID_GUID2, 1, &out);
1144 if (ACPI_FAILURE(status))
1145 return status;
1146
1147 obj = (union acpi_object *) out.pointer;
1148 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +08001149 (obj->buffer.length == sizeof(u32) ||
1150 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001151 devices = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +08001152 } else if (obj->type == ACPI_TYPE_INTEGER) {
1153 devices = (u32) obj->integer.value;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001154 } else {
Axel Lin66904862010-07-20 15:19:52 -07001155 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001156 return AE_ERROR;
1157 }
1158
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001159 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1160 if (devices & 0x07)
1161 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001162 if (devices & 0x40)
1163 interface->capability |= ACER_CAP_THREEG;
1164 if (devices & 0x10)
1165 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001166
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001167 if (!(devices & 0x20))
1168 max_brightness = 0x9;
1169
Axel Lin66904862010-07-20 15:19:52 -07001170 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001171 return status;
1172}
1173
1174static struct wmi_interface wmid_interface = {
1175 .type = ACER_WMID,
1176};
1177
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001178static struct wmi_interface wmid_v2_interface = {
1179 .type = ACER_WMID_v2,
1180};
1181
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001182/*
1183 * Generic Device (interface-independent)
1184 */
1185
1186static acpi_status get_u32(u32 *value, u32 cap)
1187{
Lin Ming08237972008-08-08 11:57:11 +08001188 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001189
1190 switch (interface->type) {
1191 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001192 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001193 break;
1194 case ACER_AMW0_V2:
1195 if (cap == ACER_CAP_MAILLED) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001196 status = AMW0_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001197 break;
1198 }
1199 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001200 status = WMID_get_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001201 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001202 case ACER_WMID_v2:
1203 if (cap & (ACER_CAP_WIRELESS |
1204 ACER_CAP_BLUETOOTH |
1205 ACER_CAP_THREEG))
1206 status = wmid_v2_get_u32(value, cap);
1207 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001208 status = WMID_get_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001209 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001210 }
1211
1212 return status;
1213}
1214
1215static acpi_status set_u32(u32 value, u32 cap)
1216{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001217 acpi_status status;
1218
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001219 if (interface->capability & cap) {
1220 switch (interface->type) {
1221 case ACER_AMW0:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001222 return AMW0_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001223 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001224 if (cap == ACER_CAP_MAILLED)
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001225 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001226
1227 /*
1228 * On some models, some WMID methods don't toggle
1229 * properly. For those cases, we want to run the AMW0
1230 * method afterwards to be certain we've really toggled
1231 * the device state.
1232 */
1233 if (cap == ACER_CAP_WIRELESS ||
1234 cap == ACER_CAP_BLUETOOTH) {
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001235 status = WMID_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001236 if (ACPI_FAILURE(status))
1237 return status;
1238
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001239 return AMW0_set_u32(value, cap);
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001240 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001241 case ACER_WMID:
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001242 return WMID_set_u32(value, cap);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001243 case ACER_WMID_v2:
1244 if (cap & (ACER_CAP_WIRELESS |
1245 ACER_CAP_BLUETOOTH |
1246 ACER_CAP_THREEG))
1247 return wmid_v2_set_u32(value, cap);
1248 else if (wmi_has_guid(WMID_GUID2))
Lee, Chun-Yi38db1572012-01-09 14:26:44 +08001249 return WMID_set_u32(value, cap);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001250 default:
1251 return AE_BAD_PARAMETER;
1252 }
1253 }
1254 return AE_BAD_PARAMETER;
1255}
1256
1257static void __init acer_commandline_init(void)
1258{
1259 /*
1260 * These will all fail silently if the value given is invalid, or the
1261 * capability isn't available on the given interface
1262 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001263 if (mailled >= 0)
1264 set_u32(mailled, ACER_CAP_MAILLED);
1265 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001266 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001267 if (brightness >= 0)
1268 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001269}
1270
1271/*
1272 * LED device (Mail LED only, no other LEDs known yet)
1273 */
1274static void mail_led_set(struct led_classdev *led_cdev,
1275enum led_brightness value)
1276{
1277 set_u32(value, ACER_CAP_MAILLED);
1278}
1279
1280static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001281 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001282 .brightness_set = mail_led_set,
1283};
1284
Sam Ravnborg7560e382008-02-17 13:22:54 +01001285static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001286{
1287 return led_classdev_register(dev, &mail_led);
1288}
1289
1290static void acer_led_exit(void)
1291{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001292 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001293 led_classdev_unregister(&mail_led);
1294}
1295
1296/*
1297 * Backlight device
1298 */
1299static struct backlight_device *acer_backlight_device;
1300
1301static int read_brightness(struct backlight_device *bd)
1302{
1303 u32 value;
1304 get_u32(&value, ACER_CAP_BRIGHTNESS);
1305 return value;
1306}
1307
1308static int update_bl_status(struct backlight_device *bd)
1309{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001310 int intensity = bd->props.brightness;
1311
1312 if (bd->props.power != FB_BLANK_UNBLANK)
1313 intensity = 0;
1314 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1315 intensity = 0;
1316
1317 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1318
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001319 return 0;
1320}
1321
Lionel Debrouxacc24722010-11-16 14:14:02 +01001322static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001323 .get_brightness = read_brightness,
1324 .update_status = update_bl_status,
1325};
1326
Sam Ravnborg7560e382008-02-17 13:22:54 +01001327static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001328{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001329 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001330 struct backlight_device *bd;
1331
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001332 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001333 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001334 props.max_brightness = max_brightness;
1335 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1336 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001337 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001338 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001339 acer_backlight_device = NULL;
1340 return PTR_ERR(bd);
1341 }
1342
1343 acer_backlight_device = bd;
1344
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001345 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001346 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001347 backlight_update_status(bd);
1348 return 0;
1349}
1350
Sam Ravnborg7560e382008-02-17 13:22:54 +01001351static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001352{
1353 backlight_device_unregister(acer_backlight_device);
1354}
1355
1356/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001357 * Rfkill devices
1358 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001359static void acer_rfkill_update(struct work_struct *ignored);
1360static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1361static void acer_rfkill_update(struct work_struct *ignored)
1362{
1363 u32 state;
1364 acpi_status status;
1365
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001366 if (has_cap(ACER_CAP_WIRELESS)) {
1367 status = get_u32(&state, ACER_CAP_WIRELESS);
1368 if (ACPI_SUCCESS(status)) {
1369 if (quirks->wireless == 3)
1370 rfkill_set_hw_state(wireless_rfkill, !state);
1371 else
1372 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001373 }
1374 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001375
1376 if (has_cap(ACER_CAP_BLUETOOTH)) {
1377 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1378 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001379 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001380 }
1381
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001382 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001383 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001384 if (ACPI_SUCCESS(status))
1385 rfkill_set_sw_state(threeg_rfkill, !state);
1386 }
1387
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001388 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001389}
1390
Johannes Berg19d337d2009-06-02 13:01:37 +02001391static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001392{
1393 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001394 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001395
1396 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001397 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001398 if (ACPI_FAILURE(status))
1399 return -ENODEV;
1400 }
1401
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001402 return 0;
1403}
1404
Johannes Berg19d337d2009-06-02 13:01:37 +02001405static const struct rfkill_ops acer_rfkill_ops = {
1406 .set_block = acer_rfkill_set,
1407};
1408
1409static struct rfkill *acer_rfkill_register(struct device *dev,
1410 enum rfkill_type type,
1411 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001412{
1413 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001414 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001415 u32 state;
1416 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001417
Johannes Berg19d337d2009-06-02 13:01:37 +02001418 rfkill_dev = rfkill_alloc(name, dev, type,
1419 &acer_rfkill_ops,
1420 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001421 if (!rfkill_dev)
1422 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001423
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001424 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001425
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001426 err = rfkill_register(rfkill_dev);
1427 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001428 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001429 return ERR_PTR(err);
1430 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001431
1432 if (ACPI_SUCCESS(status))
1433 rfkill_set_sw_state(rfkill_dev, !state);
1434
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001435 return rfkill_dev;
1436}
1437
1438static int acer_rfkill_init(struct device *dev)
1439{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001440 int err;
1441
1442 if (has_cap(ACER_CAP_WIRELESS)) {
1443 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1444 "acer-wireless", ACER_CAP_WIRELESS);
1445 if (IS_ERR(wireless_rfkill)) {
1446 err = PTR_ERR(wireless_rfkill);
1447 goto error_wireless;
1448 }
1449 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001450
1451 if (has_cap(ACER_CAP_BLUETOOTH)) {
1452 bluetooth_rfkill = acer_rfkill_register(dev,
1453 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1454 ACER_CAP_BLUETOOTH);
1455 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001456 err = PTR_ERR(bluetooth_rfkill);
1457 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001458 }
1459 }
1460
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001461 if (has_cap(ACER_CAP_THREEG)) {
1462 threeg_rfkill = acer_rfkill_register(dev,
1463 RFKILL_TYPE_WWAN, "acer-threeg",
1464 ACER_CAP_THREEG);
1465 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001466 err = PTR_ERR(threeg_rfkill);
1467 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001468 }
1469 }
1470
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001471 rfkill_inited = true;
1472
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001473 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1474 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001475 schedule_delayed_work(&acer_rfkill_work,
1476 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001477
1478 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001479
1480error_threeg:
1481 if (has_cap(ACER_CAP_BLUETOOTH)) {
1482 rfkill_unregister(bluetooth_rfkill);
1483 rfkill_destroy(bluetooth_rfkill);
1484 }
1485error_bluetooth:
1486 if (has_cap(ACER_CAP_WIRELESS)) {
1487 rfkill_unregister(wireless_rfkill);
1488 rfkill_destroy(wireless_rfkill);
1489 }
1490error_wireless:
1491 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001492}
1493
1494static void acer_rfkill_exit(void)
1495{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001496 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1497 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001498 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001499
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001500 if (has_cap(ACER_CAP_WIRELESS)) {
1501 rfkill_unregister(wireless_rfkill);
1502 rfkill_destroy(wireless_rfkill);
1503 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001504
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001505 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001506 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001507 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001508 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001509
1510 if (has_cap(ACER_CAP_THREEG)) {
1511 rfkill_unregister(threeg_rfkill);
1512 rfkill_destroy(threeg_rfkill);
1513 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001514 return;
1515}
1516
1517/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001518 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001519 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001520static ssize_t show_bool_threeg(struct device *dev,
1521 struct device_attribute *attr, char *buf)
1522{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001523 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001524 acpi_status status;
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001525
Joe Perches6e71f382011-11-29 11:04:05 -08001526 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1527 current->comm);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001528 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001529 if (ACPI_SUCCESS(status))
1530 return sprintf(buf, "%u\n", result);
1531 return sprintf(buf, "Read error\n");
1532}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001533
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001534static ssize_t set_bool_threeg(struct device *dev,
1535 struct device_attribute *attr, const char *buf, size_t count)
1536{
1537 u32 tmp = simple_strtoul(buf, NULL, 10);
1538 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
Joe Perches6e71f382011-11-29 11:04:05 -08001539 pr_info("This threeg sysfs will be removed in 2012 - used by: %s\n",
1540 current->comm);
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001541 if (ACPI_FAILURE(status))
1542 return -EINVAL;
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001543 return count;
1544}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001545static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001546 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001547
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001548static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1549 char *buf)
1550{
Joe Perches6e71f382011-11-29 11:04:05 -08001551 pr_info("This interface sysfs will be removed in 2012 - used by: %s\n",
1552 current->comm);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001553 switch (interface->type) {
1554 case ACER_AMW0:
1555 return sprintf(buf, "AMW0\n");
1556 case ACER_AMW0_V2:
1557 return sprintf(buf, "AMW0 v2\n");
1558 case ACER_WMID:
1559 return sprintf(buf, "WMID\n");
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001560 case ACER_WMID_v2:
1561 return sprintf(buf, "WMID v2\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001562 default:
1563 return sprintf(buf, "Error!\n");
1564 }
1565}
1566
Axel Lin370525d2010-06-30 10:20:23 +08001567static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001568
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001569static void acer_wmi_notify(u32 value, void *context)
1570{
1571 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1572 union acpi_object *obj;
1573 struct event_return_value return_value;
1574 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001575 u16 device_state;
1576 const struct key_entry *key;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001577
1578 status = wmi_get_event_data(value, &response);
1579 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001580 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001581 return;
1582 }
1583
1584 obj = (union acpi_object *)response.pointer;
1585
1586 if (!obj)
1587 return;
1588 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001589 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001590 kfree(obj);
1591 return;
1592 }
1593 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001594 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001595 kfree(obj);
1596 return;
1597 }
1598
1599 return_value = *((struct event_return_value *)obj->buffer.pointer);
1600 kfree(obj);
1601
1602 switch (return_value.function) {
1603 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001604 device_state = return_value.device_state;
1605 pr_debug("device state: 0x%x\n", device_state);
1606
1607 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1608 return_value.key_num);
1609 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001610 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001611 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001612 } else {
1613 switch (key->keycode) {
1614 case KEY_WLAN:
1615 case KEY_BLUETOOTH:
1616 if (has_cap(ACER_CAP_WIRELESS))
1617 rfkill_set_sw_state(wireless_rfkill,
1618 !(device_state & ACER_WMID3_GDS_WIRELESS));
1619 if (has_cap(ACER_CAP_THREEG))
1620 rfkill_set_sw_state(threeg_rfkill,
1621 !(device_state & ACER_WMID3_GDS_THREEG));
1622 if (has_cap(ACER_CAP_BLUETOOTH))
1623 rfkill_set_sw_state(bluetooth_rfkill,
1624 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1625 break;
1626 }
1627 sparse_keymap_report_entry(acer_wmi_input_dev, key,
1628 1, true);
1629 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001630 break;
1631 default:
Joe Perches249c7202011-03-29 15:21:34 -07001632 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001633 return_value.function, return_value.key_num);
1634 break;
1635 }
1636}
1637
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001638static acpi_status
1639wmid3_set_lm_mode(struct lm_input_params *params,
1640 struct lm_return_value *return_value)
1641{
1642 acpi_status status;
1643 union acpi_object *obj;
1644
1645 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1646 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1647
1648 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1649 if (ACPI_FAILURE(status))
1650 return status;
1651
1652 obj = output.pointer;
1653
1654 if (!obj)
1655 return AE_ERROR;
1656 else if (obj->type != ACPI_TYPE_BUFFER) {
1657 kfree(obj);
1658 return AE_ERROR;
1659 }
1660 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001661 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001662 kfree(obj);
1663 return AE_ERROR;
1664 }
1665
1666 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1667 kfree(obj);
1668
1669 return status;
1670}
1671
1672static int acer_wmi_enable_ec_raw(void)
1673{
1674 struct lm_return_value return_value;
1675 acpi_status status;
1676 struct lm_input_params params = {
1677 .function_num = 0x1,
1678 .commun_devices = 0xFFFF,
1679 .devices = 0xFFFF,
1680 .lm_status = 0x00, /* Launch Manager Deactive */
1681 };
1682
1683 status = wmid3_set_lm_mode(&params, &return_value);
1684
1685 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001686 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1687 return_value.error_code,
1688 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001689 else
Joe Perches249c7202011-03-29 15:21:34 -07001690 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001691
1692 return status;
1693}
1694
1695static int acer_wmi_enable_lm(void)
1696{
1697 struct lm_return_value return_value;
1698 acpi_status status;
1699 struct lm_input_params params = {
1700 .function_num = 0x1,
1701 .commun_devices = 0xFFFF,
1702 .devices = 0xFFFF,
1703 .lm_status = 0x01, /* Launch Manager Active */
1704 };
1705
1706 status = wmid3_set_lm_mode(&params, &return_value);
1707
1708 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001709 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1710 return_value.error_code,
1711 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001712
1713 return status;
1714}
1715
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001716static int __init acer_wmi_input_setup(void)
1717{
1718 acpi_status status;
1719 int err;
1720
1721 acer_wmi_input_dev = input_allocate_device();
1722 if (!acer_wmi_input_dev)
1723 return -ENOMEM;
1724
1725 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1726 acer_wmi_input_dev->phys = "wmi/input0";
1727 acer_wmi_input_dev->id.bustype = BUS_HOST;
1728
1729 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1730 if (err)
1731 goto err_free_dev;
1732
1733 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1734 acer_wmi_notify, NULL);
1735 if (ACPI_FAILURE(status)) {
1736 err = -EIO;
1737 goto err_free_keymap;
1738 }
1739
1740 err = input_register_device(acer_wmi_input_dev);
1741 if (err)
1742 goto err_uninstall_notifier;
1743
1744 return 0;
1745
1746err_uninstall_notifier:
1747 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1748err_free_keymap:
1749 sparse_keymap_free(acer_wmi_input_dev);
1750err_free_dev:
1751 input_free_device(acer_wmi_input_dev);
1752 return err;
1753}
1754
1755static void acer_wmi_input_destroy(void)
1756{
1757 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1758 sparse_keymap_free(acer_wmi_input_dev);
1759 input_unregister_device(acer_wmi_input_dev);
1760}
1761
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001762/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001763 * debugfs functions
1764 */
1765static u32 get_wmid_devices(void)
1766{
1767 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1768 union acpi_object *obj;
1769 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001770 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001771
1772 status = wmi_query_block(WMID_GUID2, 1, &out);
1773 if (ACPI_FAILURE(status))
1774 return 0;
1775
1776 obj = (union acpi_object *) out.pointer;
1777 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +08001778 (obj->buffer.length == sizeof(u32) ||
1779 obj->buffer.length == sizeof(u64))) {
Axel Lin66904862010-07-20 15:19:52 -07001780 devices = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +08001781 } else if (obj->type == ACPI_TYPE_INTEGER) {
1782 devices = (u32) obj->integer.value;
Carlos Corbacho81143522008-06-21 09:09:53 +01001783 }
Axel Lin66904862010-07-20 15:19:52 -07001784
1785 kfree(out.pointer);
1786 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001787}
1788
1789/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001790 * Platform device
1791 */
1792static int __devinit acer_platform_probe(struct platform_device *device)
1793{
1794 int err;
1795
1796 if (has_cap(ACER_CAP_MAILLED)) {
1797 err = acer_led_init(&device->dev);
1798 if (err)
1799 goto error_mailled;
1800 }
1801
1802 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1803 err = acer_backlight_init(&device->dev);
1804 if (err)
1805 goto error_brightness;
1806 }
1807
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001808 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001809 if (err)
1810 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001811
1812 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001813
Andy Whitcroft350e3292009-04-04 09:33:34 +01001814error_rfkill:
1815 if (has_cap(ACER_CAP_BRIGHTNESS))
1816 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001817error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001818 if (has_cap(ACER_CAP_MAILLED))
1819 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001820error_mailled:
1821 return err;
1822}
1823
1824static int acer_platform_remove(struct platform_device *device)
1825{
1826 if (has_cap(ACER_CAP_MAILLED))
1827 acer_led_exit();
1828 if (has_cap(ACER_CAP_BRIGHTNESS))
1829 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001830
1831 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001832 return 0;
1833}
1834
1835static int acer_platform_suspend(struct platform_device *dev,
1836pm_message_t state)
1837{
1838 u32 value;
1839 struct acer_data *data = &interface->data;
1840
1841 if (!data)
1842 return -ENOMEM;
1843
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001844 if (has_cap(ACER_CAP_MAILLED)) {
1845 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001846 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001847 data->mailled = value;
1848 }
1849
1850 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1851 get_u32(&value, ACER_CAP_BRIGHTNESS);
1852 data->brightness = value;
1853 }
1854
1855 return 0;
1856}
1857
1858static int acer_platform_resume(struct platform_device *device)
1859{
1860 struct acer_data *data = &interface->data;
1861
1862 if (!data)
1863 return -ENOMEM;
1864
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001865 if (has_cap(ACER_CAP_MAILLED))
1866 set_u32(data->mailled, ACER_CAP_MAILLED);
1867
1868 if (has_cap(ACER_CAP_BRIGHTNESS))
1869 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1870
1871 return 0;
1872}
1873
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001874static void acer_platform_shutdown(struct platform_device *device)
1875{
1876 struct acer_data *data = &interface->data;
1877
1878 if (!data)
1879 return;
1880
1881 if (has_cap(ACER_CAP_MAILLED))
1882 set_u32(LED_OFF, ACER_CAP_MAILLED);
1883}
1884
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001885static struct platform_driver acer_platform_driver = {
1886 .driver = {
1887 .name = "acer-wmi",
1888 .owner = THIS_MODULE,
1889 },
1890 .probe = acer_platform_probe,
1891 .remove = acer_platform_remove,
1892 .suspend = acer_platform_suspend,
1893 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001894 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001895};
1896
1897static struct platform_device *acer_platform_device;
1898
1899static int remove_sysfs(struct platform_device *device)
1900{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001901 if (has_cap(ACER_CAP_THREEG))
1902 device_remove_file(&device->dev, &dev_attr_threeg);
1903
1904 device_remove_file(&device->dev, &dev_attr_interface);
1905
1906 return 0;
1907}
1908
1909static int create_sysfs(void)
1910{
1911 int retval = -ENOMEM;
1912
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001913 if (has_cap(ACER_CAP_THREEG)) {
1914 retval = device_create_file(&acer_platform_device->dev,
1915 &dev_attr_threeg);
1916 if (retval)
1917 goto error_sysfs;
1918 }
1919
1920 retval = device_create_file(&acer_platform_device->dev,
1921 &dev_attr_interface);
1922 if (retval)
1923 goto error_sysfs;
1924
1925 return 0;
1926
1927error_sysfs:
1928 remove_sysfs(acer_platform_device);
1929 return retval;
1930}
1931
Carlos Corbacho81143522008-06-21 09:09:53 +01001932static void remove_debugfs(void)
1933{
1934 debugfs_remove(interface->debug.devices);
1935 debugfs_remove(interface->debug.root);
1936}
1937
1938static int create_debugfs(void)
1939{
1940 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1941 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001942 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001943 return -ENOMEM;
1944 }
1945
1946 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1947 interface->debug.root,
1948 &interface->debug.wmid_devices);
1949 if (!interface->debug.devices)
1950 goto error_debugfs;
1951
1952 return 0;
1953
1954error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001955 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001956 return -ENOMEM;
1957}
1958
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001959static int __init acer_wmi_init(void)
1960{
1961 int err;
1962
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001963 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001964
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001965 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001966 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001967 return -ENODEV;
1968 }
1969
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001970 find_quirks();
1971
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001972 /*
1973 * Detect which ACPI-WMI interface we're using.
1974 */
1975 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1976 interface = &AMW0_V2_interface;
1977
1978 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1979 interface = &wmid_interface;
1980
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001981 if (wmi_has_guid(WMID_GUID3))
1982 interface = &wmid_v2_interface;
1983
1984 if (interface)
1985 dmi_walk(type_aa_dmi_decode, NULL);
1986
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001987 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001988 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001989 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001990 return -ENODEV;
1991 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001992 /* WMID always provides brightness methods */
1993 interface->capability |= ACER_CAP_BRIGHTNESS;
1994 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001995 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001996 return -ENODEV;
1997 }
1998
1999 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2000 interface = &AMW0_interface;
2001
2002 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002003 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002004 return -ENODEV;
2005 }
2006 }
2007
Carlos Corbacho9b963c42008-02-24 13:34:29 +00002008 if (wmi_has_guid(AMW0_GUID1))
2009 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002010
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002011 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002012 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002013 return -ENODEV;
2014 }
2015
Arjan van de Ven83097ac2008-08-23 21:45:21 -07002016 set_quirks();
2017
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08002018 if (acpi_video_backlight_support()) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002019 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Joe Perches6e71f382011-11-29 11:04:05 -08002020 pr_info("Brightness must be controlled by generic video driver\n");
Thomas Renningerfebf2d92008-08-01 17:37:56 +02002021 }
2022
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002023 if (wmi_has_guid(WMID_GUID3)) {
2024 if (ec_raw_mode) {
2025 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002026 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002027 return -ENODEV;
2028 }
2029 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002030 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002031 return -ENODEV;
2032 }
2033 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002034 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05002035 }
2036
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002037 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2038 err = acer_wmi_input_setup();
2039 if (err)
2040 return err;
2041 }
2042
Axel Lin1c796322010-06-22 16:17:38 +08002043 err = platform_driver_register(&acer_platform_driver);
2044 if (err) {
Joe Perches6e71f382011-11-29 11:04:05 -08002045 pr_err("Unable to register platform driver\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002046 goto error_platform_register;
2047 }
Axel Lin1c796322010-06-22 16:17:38 +08002048
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002049 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08002050 if (!acer_platform_device) {
2051 err = -ENOMEM;
2052 goto error_device_alloc;
2053 }
2054
2055 err = platform_device_add(acer_platform_device);
2056 if (err)
2057 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002058
2059 err = create_sysfs();
2060 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002061 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002062
Carlos Corbacho81143522008-06-21 09:09:53 +01002063 if (wmi_has_guid(WMID_GUID2)) {
2064 interface->debug.wmid_devices = get_wmid_devices();
2065 err = create_debugfs();
2066 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002067 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002068 }
2069
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002070 /* Override any initial settings with values from the commandline */
2071 acer_commandline_init();
2072
2073 return 0;
2074
Axel Lin1c796322010-06-22 16:17:38 +08002075error_create_debugfs:
2076 remove_sysfs(acer_platform_device);
2077error_create_sys:
2078 platform_device_del(acer_platform_device);
2079error_device_add:
2080 platform_device_put(acer_platform_device);
2081error_device_alloc:
2082 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002083error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002084 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2085 acer_wmi_input_destroy();
2086
Axel Lin1c796322010-06-22 16:17:38 +08002087 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002088}
2089
2090static void __exit acer_wmi_exit(void)
2091{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002092 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2093 acer_wmi_input_destroy();
2094
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002095 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07002096 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002097 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002098 platform_driver_unregister(&acer_platform_driver);
2099
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002100 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002101 return;
2102}
2103
2104module_init(acer_wmi_init);
2105module_exit(acer_wmi_exit);