blob: ca52639af2d1a9560a61c40cdd4c13fd121737ce [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 */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200108 {KE_IGNORE, 0x41, {KEY_MUTE} },
109 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
110 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
111 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
112 {KE_IGNORE, 0x45, {KEY_STOP} },
113 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
114 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
115 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
116 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
117 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800118 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200119 {KE_IGNORE, 0x81, {KEY_SLEEP} },
Lee, Chun-Yi89411782011-03-02 01:07:11 +0800120 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200121 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800122 {KE_END, 0}
123};
124
125static struct input_dev *acer_wmi_input_dev;
126
127struct event_return_value {
128 u8 function;
129 u8 key_num;
130 u16 device_state;
131 u32 reserved;
132} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000133
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000134/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800135 * GUID3 Get Device Status device flags
136 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800137#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800138#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800139#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800140#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800141
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500142struct lm_input_params {
143 u8 function_num; /* Function Number */
144 u16 commun_devices; /* Communication type devices default status */
145 u16 devices; /* Other type devices default status */
146 u8 lm_status; /* Launch Manager Status */
147 u16 reserved;
148} __attribute__((packed));
149
150struct lm_return_value {
151 u8 error_code; /* Error Code */
152 u8 ec_return_value; /* EC Return Value */
153 u16 reserved;
154} __attribute__((packed));
155
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800156struct wmid3_gds_input_param { /* Get Device Status input parameter */
157 u8 function_num; /* Function Number */
158 u8 hotkey_number; /* Hotkey Number */
159 u16 devices; /* Get Device */
160} __attribute__((packed));
161
162struct wmid3_gds_return_value { /* Get Device Status return value*/
163 u8 error_code; /* Error Code */
164 u8 ec_return_value; /* EC Return Value */
165 u16 devices; /* Current Device Status */
166 u32 reserved;
167} __attribute__((packed));
168
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800169struct hotkey_function_type_aa {
170 u8 type;
171 u8 length;
172 u16 handle;
173 u16 commun_func_bitmap;
174} __attribute__((packed));
175
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800176/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000177 * Interface capability flags
178 */
179#define ACER_CAP_MAILLED (1<<0)
180#define ACER_CAP_WIRELESS (1<<1)
181#define ACER_CAP_BLUETOOTH (1<<2)
182#define ACER_CAP_BRIGHTNESS (1<<3)
183#define ACER_CAP_THREEG (1<<4)
184#define ACER_CAP_ANY (0xFFFFFFFF)
185
186/*
187 * Interface type flags
188 */
189enum interface_flags {
190 ACER_AMW0,
191 ACER_AMW0_V2,
192 ACER_WMID,
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800193 ACER_WMID_v2,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000194};
195
196#define ACER_DEFAULT_WIRELESS 0
197#define ACER_DEFAULT_BLUETOOTH 0
198#define ACER_DEFAULT_MAILLED 0
199#define ACER_DEFAULT_THREEG 0
200
201static int max_brightness = 0xF;
202
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000203static int mailled = -1;
204static int brightness = -1;
205static int threeg = -1;
206static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500207static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800208static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000209
210module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000211module_param(brightness, int, 0444);
212module_param(threeg, int, 0444);
213module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500214module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000215MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
216MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
217MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
218MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500219MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000220
221struct acer_data {
222 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000223 int threeg;
224 int brightness;
225};
226
Carlos Corbacho81143522008-06-21 09:09:53 +0100227struct acer_debug {
228 struct dentry *root;
229 struct dentry *devices;
230 u32 wmid_devices;
231};
232
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100233static struct rfkill *wireless_rfkill;
234static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800235static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800236static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100237
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000238/* Each low-level interface must define at least some of the following */
239struct wmi_interface {
240 /* The WMI device type */
241 u32 type;
242
243 /* The capabilities this interface provides */
244 u32 capability;
245
246 /* Private data for the current interface */
247 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100248
249 /* debugfs entries associated with this interface */
250 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000251};
252
253/* The static interface pointer, points to the currently detected interface */
254static struct wmi_interface *interface;
255
256/*
257 * Embedded Controller quirks
258 * Some laptops require us to directly access the EC to either enable or query
259 * features that are not available through WMI.
260 */
261
262struct quirk_entry {
263 u8 wireless;
264 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100265 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000266 u8 bluetooth;
267};
268
269static struct quirk_entry *quirks;
270
271static void set_quirks(void)
272{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700273 if (!interface)
274 return;
275
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000276 if (quirks->mailled)
277 interface->capability |= ACER_CAP_MAILLED;
278
279 if (quirks->brightness)
280 interface->capability |= ACER_CAP_BRIGHTNESS;
281}
282
283static int dmi_matched(const struct dmi_system_id *dmi)
284{
285 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800286 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000287}
288
289static struct quirk_entry quirk_unknown = {
290};
291
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100292static struct quirk_entry quirk_acer_aspire_1520 = {
293 .brightness = -1,
294};
295
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000296static struct quirk_entry quirk_acer_travelmate_2490 = {
297 .mailled = 1,
298};
299
300/* This AMW0 laptop has no bluetooth */
301static struct quirk_entry quirk_medion_md_98300 = {
302 .wireless = 1,
303};
304
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100305static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
306 .wireless = 2,
307};
308
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800309static struct quirk_entry quirk_lenovo_ideapad_s205 = {
310 .wireless = 3,
311};
312
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100313/* The Aspire One has a dummy ACPI-WMI interface - disable it */
314static struct dmi_system_id __devinitdata acer_blacklist[] = {
315 {
316 .ident = "Acer Aspire One (SSD)",
317 .matches = {
318 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
319 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
320 },
321 },
322 {
323 .ident = "Acer Aspire One (HDD)",
324 .matches = {
325 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
326 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
327 },
328 },
329 {}
330};
331
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000332static struct dmi_system_id acer_quirks[] = {
333 {
334 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100335 .ident = "Acer Aspire 1360",
336 .matches = {
337 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
338 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
339 },
340 .driver_data = &quirk_acer_aspire_1520,
341 },
342 {
343 .callback = dmi_matched,
344 .ident = "Acer Aspire 1520",
345 .matches = {
346 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
347 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
348 },
349 .driver_data = &quirk_acer_aspire_1520,
350 },
351 {
352 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000353 .ident = "Acer Aspire 3100",
354 .matches = {
355 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
356 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
357 },
358 .driver_data = &quirk_acer_travelmate_2490,
359 },
360 {
361 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000362 .ident = "Acer Aspire 3610",
363 .matches = {
364 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
365 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
366 },
367 .driver_data = &quirk_acer_travelmate_2490,
368 },
369 {
370 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000371 .ident = "Acer Aspire 5100",
372 .matches = {
373 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
374 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
375 },
376 .driver_data = &quirk_acer_travelmate_2490,
377 },
378 {
379 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000380 .ident = "Acer Aspire 5610",
381 .matches = {
382 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
383 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
384 },
385 .driver_data = &quirk_acer_travelmate_2490,
386 },
387 {
388 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000389 .ident = "Acer Aspire 5630",
390 .matches = {
391 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
392 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
393 },
394 .driver_data = &quirk_acer_travelmate_2490,
395 },
396 {
397 .callback = dmi_matched,
398 .ident = "Acer Aspire 5650",
399 .matches = {
400 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
401 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
402 },
403 .driver_data = &quirk_acer_travelmate_2490,
404 },
405 {
406 .callback = dmi_matched,
407 .ident = "Acer Aspire 5680",
408 .matches = {
409 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
410 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
411 },
412 .driver_data = &quirk_acer_travelmate_2490,
413 },
414 {
415 .callback = dmi_matched,
416 .ident = "Acer Aspire 9110",
417 .matches = {
418 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
419 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
420 },
421 .driver_data = &quirk_acer_travelmate_2490,
422 },
423 {
424 .callback = dmi_matched,
425 .ident = "Acer TravelMate 2490",
426 .matches = {
427 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
428 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
429 },
430 .driver_data = &quirk_acer_travelmate_2490,
431 },
432 {
433 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000434 .ident = "Acer TravelMate 4200",
435 .matches = {
436 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
437 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
438 },
439 .driver_data = &quirk_acer_travelmate_2490,
440 },
441 {
442 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100443 .ident = "Fujitsu Siemens Amilo Li 1718",
444 .matches = {
445 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
446 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
447 },
448 .driver_data = &quirk_fujitsu_amilo_li_1718,
449 },
450 {
451 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000452 .ident = "Medion MD 98300",
453 .matches = {
454 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
455 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
456 },
457 .driver_data = &quirk_medion_md_98300,
458 },
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800459 {
460 .callback = dmi_matched,
461 .ident = "Lenovo Ideapad S205",
462 .matches = {
463 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
464 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
465 },
466 .driver_data = &quirk_lenovo_ideapad_s205,
467 },
Seth Forsheebe3128b2011-10-06 15:01:55 -0500468 {
469 .callback = dmi_matched,
470 .ident = "Lenovo 3000 N200",
471 .matches = {
472 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
473 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
474 },
475 .driver_data = &quirk_fujitsu_amilo_li_1718,
476 },
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000477 {}
478};
479
480/* Find which quirks are needed for a particular vendor/ model pair */
481static void find_quirks(void)
482{
483 if (!force_series) {
484 dmi_check_system(acer_quirks);
485 } else if (force_series == 2490) {
486 quirks = &quirk_acer_travelmate_2490;
487 }
488
489 if (quirks == NULL)
490 quirks = &quirk_unknown;
491
492 set_quirks();
493}
494
495/*
496 * General interface convenience methods
497 */
498
499static bool has_cap(u32 cap)
500{
501 if ((interface->capability & cap) != 0)
502 return 1;
503
504 return 0;
505}
506
507/*
508 * AMW0 (V1) interface
509 */
510struct wmab_args {
511 u32 eax;
512 u32 ebx;
513 u32 ecx;
514 u32 edx;
515};
516
517struct wmab_ret {
518 u32 eax;
519 u32 ebx;
520 u32 ecx;
521 u32 edx;
522 u32 eex;
523};
524
525static acpi_status wmab_execute(struct wmab_args *regbuf,
526struct acpi_buffer *result)
527{
528 struct acpi_buffer input;
529 acpi_status status;
530 input.length = sizeof(struct wmab_args);
531 input.pointer = (u8 *)regbuf;
532
533 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
534
535 return status;
536}
537
538static acpi_status AMW0_get_u32(u32 *value, u32 cap,
539struct wmi_interface *iface)
540{
541 int err;
542 u8 result;
543
544 switch (cap) {
545 case ACER_CAP_MAILLED:
546 switch (quirks->mailled) {
547 default:
548 err = ec_read(0xA, &result);
549 if (err)
550 return AE_ERROR;
551 *value = (result >> 7) & 0x1;
552 return AE_OK;
553 }
554 break;
555 case ACER_CAP_WIRELESS:
556 switch (quirks->wireless) {
557 case 1:
558 err = ec_read(0x7B, &result);
559 if (err)
560 return AE_ERROR;
561 *value = result & 0x1;
562 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100563 case 2:
564 err = ec_read(0x71, &result);
565 if (err)
566 return AE_ERROR;
567 *value = result & 0x1;
568 return AE_OK;
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +0800569 case 3:
570 err = ec_read(0x78, &result);
571 if (err)
572 return AE_ERROR;
573 *value = result & 0x1;
574 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000575 default:
576 err = ec_read(0xA, &result);
577 if (err)
578 return AE_ERROR;
579 *value = (result >> 2) & 0x1;
580 return AE_OK;
581 }
582 break;
583 case ACER_CAP_BLUETOOTH:
584 switch (quirks->bluetooth) {
585 default:
586 err = ec_read(0xA, &result);
587 if (err)
588 return AE_ERROR;
589 *value = (result >> 4) & 0x1;
590 return AE_OK;
591 }
592 break;
593 case ACER_CAP_BRIGHTNESS:
594 switch (quirks->brightness) {
595 default:
596 err = ec_read(0x83, &result);
597 if (err)
598 return AE_ERROR;
599 *value = result;
600 return AE_OK;
601 }
602 break;
603 default:
Lin Ming08237972008-08-08 11:57:11 +0800604 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000605 }
606 return AE_OK;
607}
608
609static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
610{
611 struct wmab_args args;
612
613 args.eax = ACER_AMW0_WRITE;
614 args.ebx = value ? (1<<8) : 0;
615 args.ecx = args.edx = 0;
616
617 switch (cap) {
618 case ACER_CAP_MAILLED:
619 if (value > 1)
620 return AE_BAD_PARAMETER;
621 args.ebx |= ACER_AMW0_MAILLED_MASK;
622 break;
623 case ACER_CAP_WIRELESS:
624 if (value > 1)
625 return AE_BAD_PARAMETER;
626 args.ebx |= ACER_AMW0_WIRELESS_MASK;
627 break;
628 case ACER_CAP_BLUETOOTH:
629 if (value > 1)
630 return AE_BAD_PARAMETER;
631 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
632 break;
633 case ACER_CAP_BRIGHTNESS:
634 if (value > max_brightness)
635 return AE_BAD_PARAMETER;
636 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000637 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000638 return ec_write(0x83, value);
639 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000640 }
641 default:
Lin Ming08237972008-08-08 11:57:11 +0800642 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000643 }
644
645 /* Actually do the set */
646 return wmab_execute(&args, NULL);
647}
648
649static acpi_status AMW0_find_mailled(void)
650{
651 struct wmab_args args;
652 struct wmab_ret ret;
653 acpi_status status = AE_OK;
654 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
655 union acpi_object *obj;
656
657 args.eax = 0x86;
658 args.ebx = args.ecx = args.edx = 0;
659
660 status = wmab_execute(&args, &out);
661 if (ACPI_FAILURE(status))
662 return status;
663
664 obj = (union acpi_object *) out.pointer;
665 if (obj && obj->type == ACPI_TYPE_BUFFER &&
666 obj->buffer.length == sizeof(struct wmab_ret)) {
667 ret = *((struct wmab_ret *) obj->buffer.pointer);
668 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700669 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000670 return AE_ERROR;
671 }
672
673 if (ret.eex & 0x1)
674 interface->capability |= ACER_CAP_MAILLED;
675
676 kfree(out.pointer);
677
678 return AE_OK;
679}
680
681static acpi_status AMW0_set_capabilities(void)
682{
683 struct wmab_args args;
684 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700685 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000686 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
687 union acpi_object *obj;
688
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100689 /*
690 * On laptops with this strange GUID (non Acer), normal probing doesn't
691 * work.
692 */
693 if (wmi_has_guid(AMW0_GUID2)) {
694 interface->capability |= ACER_CAP_WIRELESS;
695 return AE_OK;
696 }
697
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000698 args.eax = ACER_AMW0_WRITE;
699 args.ecx = args.edx = 0;
700
701 args.ebx = 0xa2 << 8;
702 args.ebx |= ACER_AMW0_WIRELESS_MASK;
703
704 status = wmab_execute(&args, &out);
705 if (ACPI_FAILURE(status))
706 return status;
707
Axel Lin7677fbd2010-07-20 15:19:53 -0700708 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000709 if (obj && obj->type == ACPI_TYPE_BUFFER &&
710 obj->buffer.length == sizeof(struct wmab_ret)) {
711 ret = *((struct wmab_ret *) obj->buffer.pointer);
712 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700713 status = AE_ERROR;
714 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000715 }
716
717 if (ret.eax & 0x1)
718 interface->capability |= ACER_CAP_WIRELESS;
719
720 args.ebx = 2 << 8;
721 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
722
Axel Lin7677fbd2010-07-20 15:19:53 -0700723 /*
724 * It's ok to use existing buffer for next wmab_execute call.
725 * But we need to kfree(out.pointer) if next wmab_execute fail.
726 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000727 status = wmab_execute(&args, &out);
728 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700729 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000730
731 obj = (union acpi_object *) out.pointer;
732 if (obj && obj->type == ACPI_TYPE_BUFFER
733 && obj->buffer.length == sizeof(struct wmab_ret)) {
734 ret = *((struct wmab_ret *) obj->buffer.pointer);
735 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700736 status = AE_ERROR;
737 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000738 }
739
740 if (ret.eax & 0x1)
741 interface->capability |= ACER_CAP_BLUETOOTH;
742
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000743 /*
744 * This appears to be safe to enable, since all Wistron based laptops
745 * appear to use the same EC register for brightness, even if they
746 * differ for wireless, etc
747 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100748 if (quirks->brightness >= 0)
749 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000750
Axel Lin7677fbd2010-07-20 15:19:53 -0700751 status = AE_OK;
752out:
753 kfree(out.pointer);
754 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000755}
756
757static struct wmi_interface AMW0_interface = {
758 .type = ACER_AMW0,
759};
760
761static struct wmi_interface AMW0_V2_interface = {
762 .type = ACER_AMW0_V2,
763};
764
765/*
766 * New interface (The WMID interface)
767 */
768static acpi_status
769WMI_execute_u32(u32 method_id, u32 in, u32 *out)
770{
771 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
772 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
773 union acpi_object *obj;
774 u32 tmp;
775 acpi_status status;
776
777 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
778
779 if (ACPI_FAILURE(status))
780 return status;
781
782 obj = (union acpi_object *) result.pointer;
783 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +0800784 (obj->buffer.length == sizeof(u32) ||
785 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000786 tmp = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +0800787 } else if (obj->type == ACPI_TYPE_INTEGER) {
788 tmp = (u32) obj->integer.value;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000789 } else {
790 tmp = 0;
791 }
792
793 if (out)
794 *out = tmp;
795
796 kfree(result.pointer);
797
798 return status;
799}
800
801static acpi_status WMID_get_u32(u32 *value, u32 cap,
802struct wmi_interface *iface)
803{
804 acpi_status status;
805 u8 tmp;
806 u32 result, method_id = 0;
807
808 switch (cap) {
809 case ACER_CAP_WIRELESS:
810 method_id = ACER_WMID_GET_WIRELESS_METHODID;
811 break;
812 case ACER_CAP_BLUETOOTH:
813 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
814 break;
815 case ACER_CAP_BRIGHTNESS:
816 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
817 break;
818 case ACER_CAP_THREEG:
819 method_id = ACER_WMID_GET_THREEG_METHODID;
820 break;
821 case ACER_CAP_MAILLED:
822 if (quirks->mailled == 1) {
823 ec_read(0x9f, &tmp);
824 *value = tmp & 0x1;
825 return 0;
826 }
827 default:
Lin Ming08237972008-08-08 11:57:11 +0800828 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000829 }
830 status = WMI_execute_u32(method_id, 0, &result);
831
832 if (ACPI_SUCCESS(status))
833 *value = (u8)result;
834
835 return status;
836}
837
838static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
839{
840 u32 method_id = 0;
841 char param;
842
843 switch (cap) {
844 case ACER_CAP_BRIGHTNESS:
845 if (value > max_brightness)
846 return AE_BAD_PARAMETER;
847 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
848 break;
849 case ACER_CAP_WIRELESS:
850 if (value > 1)
851 return AE_BAD_PARAMETER;
852 method_id = ACER_WMID_SET_WIRELESS_METHODID;
853 break;
854 case ACER_CAP_BLUETOOTH:
855 if (value > 1)
856 return AE_BAD_PARAMETER;
857 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
858 break;
859 case ACER_CAP_THREEG:
860 if (value > 1)
861 return AE_BAD_PARAMETER;
862 method_id = ACER_WMID_SET_THREEG_METHODID;
863 break;
864 case ACER_CAP_MAILLED:
865 if (value > 1)
866 return AE_BAD_PARAMETER;
867 if (quirks->mailled == 1) {
868 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700869 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000870 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700871 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000872 return 0;
873 }
874 break;
875 default:
Lin Ming08237972008-08-08 11:57:11 +0800876 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000877 }
878 return WMI_execute_u32(method_id, (u32)value, NULL);
879}
880
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +0800881static acpi_status wmid3_get_device_status(u32 *value, u16 device)
882{
883 struct wmid3_gds_return_value return_value;
884 acpi_status status;
885 union acpi_object *obj;
886 struct wmid3_gds_input_param params = {
887 .function_num = 0x1,
888 .hotkey_number = 0x01,
889 .devices = device,
890 };
891 struct acpi_buffer input = {
892 sizeof(struct wmid3_gds_input_param),
893 &params
894 };
895 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
896
897 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
898 if (ACPI_FAILURE(status))
899 return status;
900
901 obj = output.pointer;
902
903 if (!obj)
904 return AE_ERROR;
905 else if (obj->type != ACPI_TYPE_BUFFER) {
906 kfree(obj);
907 return AE_ERROR;
908 }
909 if (obj->buffer.length != 8) {
910 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
911 kfree(obj);
912 return AE_ERROR;
913 }
914
915 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
916 kfree(obj);
917
918 if (return_value.error_code || return_value.ec_return_value)
919 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
920 device,
921 return_value.error_code,
922 return_value.ec_return_value);
923 else
924 *value = !!(return_value.devices & device);
925
926 return status;
927}
928
929static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
930{
931 u16 device;
932
933 switch (cap) {
934 case ACER_CAP_WIRELESS:
935 device = ACER_WMID3_GDS_WIRELESS;
936 break;
937 case ACER_CAP_BLUETOOTH:
938 device = ACER_WMID3_GDS_BLUETOOTH;
939 break;
940 case ACER_CAP_THREEG:
941 device = ACER_WMID3_GDS_THREEG;
942 break;
943 default:
944 return AE_ERROR;
945 }
946 return wmid3_get_device_status(value, device);
947}
948
949static acpi_status wmid3_set_device_status(u32 value, u16 device)
950{
951 struct wmid3_gds_return_value return_value;
952 acpi_status status;
953 union acpi_object *obj;
954 u16 devices;
955 struct wmid3_gds_input_param params = {
956 .function_num = 0x1,
957 .hotkey_number = 0x01,
958 .devices = ACER_WMID3_GDS_WIRELESS |
959 ACER_WMID3_GDS_THREEG |
960 ACER_WMID3_GDS_WIMAX |
961 ACER_WMID3_GDS_BLUETOOTH,
962 };
963 struct acpi_buffer input = {
964 sizeof(struct wmid3_gds_input_param),
965 &params
966 };
967 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
968 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
969
970 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
971 if (ACPI_FAILURE(status))
972 return status;
973
974 obj = output.pointer;
975
976 if (!obj)
977 return AE_ERROR;
978 else if (obj->type != ACPI_TYPE_BUFFER) {
979 kfree(obj);
980 return AE_ERROR;
981 }
982 if (obj->buffer.length != 8) {
983 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
984 kfree(obj);
985 return AE_ERROR;
986 }
987
988 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
989 kfree(obj);
990
991 if (return_value.error_code || return_value.ec_return_value) {
992 pr_warning("Get Current Device Status failed: "
993 "0x%x - 0x%x\n", return_value.error_code,
994 return_value.ec_return_value);
995 return status;
996 }
997
998 devices = return_value.devices;
999 params.function_num = 0x2;
1000 params.hotkey_number = 0x01;
1001 params.devices = (value) ? (devices | device) : (devices & ~device);
1002
1003 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
1004 if (ACPI_FAILURE(status))
1005 return status;
1006
1007 obj = output2.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 != 4) {
1016 pr_warning("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_warning("Set Device Status failed: "
1026 "0x%x - 0x%x\n", return_value.error_code,
1027 return_value.ec_return_value);
1028
1029 return status;
1030}
1031
1032static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1033{
1034 u16 device;
1035
1036 switch (cap) {
1037 case ACER_CAP_WIRELESS:
1038 device = ACER_WMID3_GDS_WIRELESS;
1039 break;
1040 case ACER_CAP_BLUETOOTH:
1041 device = ACER_WMID3_GDS_BLUETOOTH;
1042 break;
1043 case ACER_CAP_THREEG:
1044 device = ACER_WMID3_GDS_THREEG;
1045 break;
1046 default:
1047 return AE_ERROR;
1048 }
1049 return wmid3_set_device_status(value, device);
1050}
1051
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001052static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
1053{
1054 struct hotkey_function_type_aa *type_aa;
1055
1056 /* We are looking for OEM-specific Type AAh */
1057 if (header->type != 0xAA)
1058 return;
1059
1060 has_type_aa = true;
1061 type_aa = (struct hotkey_function_type_aa *) header;
1062
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001063 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001064 type_aa->commun_func_bitmap);
1065
1066 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1067 interface->capability |= ACER_CAP_WIRELESS;
1068 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1069 interface->capability |= ACER_CAP_THREEG;
1070 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1071 interface->capability |= ACER_CAP_BLUETOOTH;
1072}
1073
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001074static acpi_status WMID_set_capabilities(void)
1075{
1076 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1077 union acpi_object *obj;
1078 acpi_status status;
1079 u32 devices;
1080
1081 status = wmi_query_block(WMID_GUID2, 1, &out);
1082 if (ACPI_FAILURE(status))
1083 return status;
1084
1085 obj = (union acpi_object *) out.pointer;
1086 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +08001087 (obj->buffer.length == sizeof(u32) ||
1088 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001089 devices = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +08001090 } else if (obj->type == ACPI_TYPE_INTEGER) {
1091 devices = (u32) obj->integer.value;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001092 } else {
Axel Lin66904862010-07-20 15:19:52 -07001093 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001094 return AE_ERROR;
1095 }
1096
Lee, Chun-Yi1fbc01a2011-08-18 18:47:34 +08001097 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1098 if (devices & 0x07)
1099 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001100 if (devices & 0x40)
1101 interface->capability |= ACER_CAP_THREEG;
1102 if (devices & 0x10)
1103 interface->capability |= ACER_CAP_BLUETOOTH;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001104
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001105 if (!(devices & 0x20))
1106 max_brightness = 0x9;
1107
Axel Lin66904862010-07-20 15:19:52 -07001108 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001109 return status;
1110}
1111
1112static struct wmi_interface wmid_interface = {
1113 .type = ACER_WMID,
1114};
1115
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001116static struct wmi_interface wmid_v2_interface = {
1117 .type = ACER_WMID_v2,
1118};
1119
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001120/*
1121 * Generic Device (interface-independent)
1122 */
1123
1124static acpi_status get_u32(u32 *value, u32 cap)
1125{
Lin Ming08237972008-08-08 11:57:11 +08001126 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001127
1128 switch (interface->type) {
1129 case ACER_AMW0:
1130 status = AMW0_get_u32(value, cap, interface);
1131 break;
1132 case ACER_AMW0_V2:
1133 if (cap == ACER_CAP_MAILLED) {
1134 status = AMW0_get_u32(value, cap, interface);
1135 break;
1136 }
1137 case ACER_WMID:
1138 status = WMID_get_u32(value, cap, interface);
1139 break;
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001140 case ACER_WMID_v2:
1141 if (cap & (ACER_CAP_WIRELESS |
1142 ACER_CAP_BLUETOOTH |
1143 ACER_CAP_THREEG))
1144 status = wmid_v2_get_u32(value, cap);
1145 else if (wmi_has_guid(WMID_GUID2))
1146 status = WMID_get_u32(value, cap, interface);
1147 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001148 }
1149
1150 return status;
1151}
1152
1153static acpi_status set_u32(u32 value, u32 cap)
1154{
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001155 acpi_status status;
1156
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001157 if (interface->capability & cap) {
1158 switch (interface->type) {
1159 case ACER_AMW0:
1160 return AMW0_set_u32(value, cap, interface);
1161 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +01001162 if (cap == ACER_CAP_MAILLED)
1163 return AMW0_set_u32(value, cap, interface);
1164
1165 /*
1166 * On some models, some WMID methods don't toggle
1167 * properly. For those cases, we want to run the AMW0
1168 * method afterwards to be certain we've really toggled
1169 * the device state.
1170 */
1171 if (cap == ACER_CAP_WIRELESS ||
1172 cap == ACER_CAP_BLUETOOTH) {
1173 status = WMID_set_u32(value, cap, interface);
1174 if (ACPI_FAILURE(status))
1175 return status;
1176
1177 return AMW0_set_u32(value, cap, interface);
1178 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001179 case ACER_WMID:
1180 return WMID_set_u32(value, cap, interface);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001181 case ACER_WMID_v2:
1182 if (cap & (ACER_CAP_WIRELESS |
1183 ACER_CAP_BLUETOOTH |
1184 ACER_CAP_THREEG))
1185 return wmid_v2_set_u32(value, cap);
1186 else if (wmi_has_guid(WMID_GUID2))
1187 return WMID_set_u32(value, cap, interface);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001188 default:
1189 return AE_BAD_PARAMETER;
1190 }
1191 }
1192 return AE_BAD_PARAMETER;
1193}
1194
1195static void __init acer_commandline_init(void)
1196{
1197 /*
1198 * These will all fail silently if the value given is invalid, or the
1199 * capability isn't available on the given interface
1200 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001201 if (mailled >= 0)
1202 set_u32(mailled, ACER_CAP_MAILLED);
1203 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +08001204 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +08001205 if (brightness >= 0)
1206 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001207}
1208
1209/*
1210 * LED device (Mail LED only, no other LEDs known yet)
1211 */
1212static void mail_led_set(struct led_classdev *led_cdev,
1213enum led_brightness value)
1214{
1215 set_u32(value, ACER_CAP_MAILLED);
1216}
1217
1218static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001219 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001220 .brightness_set = mail_led_set,
1221};
1222
Sam Ravnborg7560e382008-02-17 13:22:54 +01001223static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001224{
1225 return led_classdev_register(dev, &mail_led);
1226}
1227
1228static void acer_led_exit(void)
1229{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001230 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001231 led_classdev_unregister(&mail_led);
1232}
1233
1234/*
1235 * Backlight device
1236 */
1237static struct backlight_device *acer_backlight_device;
1238
1239static int read_brightness(struct backlight_device *bd)
1240{
1241 u32 value;
1242 get_u32(&value, ACER_CAP_BRIGHTNESS);
1243 return value;
1244}
1245
1246static int update_bl_status(struct backlight_device *bd)
1247{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001248 int intensity = bd->props.brightness;
1249
1250 if (bd->props.power != FB_BLANK_UNBLANK)
1251 intensity = 0;
1252 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1253 intensity = 0;
1254
1255 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1256
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001257 return 0;
1258}
1259
Lionel Debrouxacc24722010-11-16 14:14:02 +01001260static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001261 .get_brightness = read_brightness,
1262 .update_status = update_bl_status,
1263};
1264
Sam Ravnborg7560e382008-02-17 13:22:54 +01001265static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001266{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001267 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001268 struct backlight_device *bd;
1269
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001270 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001271 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001272 props.max_brightness = max_brightness;
1273 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1274 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001275 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001276 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001277 acer_backlight_device = NULL;
1278 return PTR_ERR(bd);
1279 }
1280
1281 acer_backlight_device = bd;
1282
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001283 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001284 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001285 backlight_update_status(bd);
1286 return 0;
1287}
1288
Sam Ravnborg7560e382008-02-17 13:22:54 +01001289static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001290{
1291 backlight_device_unregister(acer_backlight_device);
1292}
1293
1294/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001295 * Rfkill devices
1296 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001297static void acer_rfkill_update(struct work_struct *ignored);
1298static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1299static void acer_rfkill_update(struct work_struct *ignored)
1300{
1301 u32 state;
1302 acpi_status status;
1303
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001304 if (has_cap(ACER_CAP_WIRELESS)) {
1305 status = get_u32(&state, ACER_CAP_WIRELESS);
1306 if (ACPI_SUCCESS(status)) {
1307 if (quirks->wireless == 3)
1308 rfkill_set_hw_state(wireless_rfkill, !state);
1309 else
1310 rfkill_set_sw_state(wireless_rfkill, !state);
Lee, Chun-Yi15b956a2011-07-30 17:00:45 +08001311 }
1312 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001313
1314 if (has_cap(ACER_CAP_BLUETOOTH)) {
1315 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1316 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001317 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001318 }
1319
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001320 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001321 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001322 if (ACPI_SUCCESS(status))
1323 rfkill_set_sw_state(threeg_rfkill, !state);
1324 }
1325
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001326 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001327}
1328
Johannes Berg19d337d2009-06-02 13:01:37 +02001329static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001330{
1331 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001332 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001333
1334 if (rfkill_inited) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001335 status = set_u32(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001336 if (ACPI_FAILURE(status))
1337 return -ENODEV;
1338 }
1339
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001340 return 0;
1341}
1342
Johannes Berg19d337d2009-06-02 13:01:37 +02001343static const struct rfkill_ops acer_rfkill_ops = {
1344 .set_block = acer_rfkill_set,
1345};
1346
1347static struct rfkill *acer_rfkill_register(struct device *dev,
1348 enum rfkill_type type,
1349 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001350{
1351 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001352 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001353 u32 state;
1354 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001355
Johannes Berg19d337d2009-06-02 13:01:37 +02001356 rfkill_dev = rfkill_alloc(name, dev, type,
1357 &acer_rfkill_ops,
1358 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001359 if (!rfkill_dev)
1360 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001361
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001362 status = get_u32(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001363
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001364 err = rfkill_register(rfkill_dev);
1365 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001366 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001367 return ERR_PTR(err);
1368 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001369
1370 if (ACPI_SUCCESS(status))
1371 rfkill_set_sw_state(rfkill_dev, !state);
1372
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001373 return rfkill_dev;
1374}
1375
1376static int acer_rfkill_init(struct device *dev)
1377{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001378 int err;
1379
1380 if (has_cap(ACER_CAP_WIRELESS)) {
1381 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1382 "acer-wireless", ACER_CAP_WIRELESS);
1383 if (IS_ERR(wireless_rfkill)) {
1384 err = PTR_ERR(wireless_rfkill);
1385 goto error_wireless;
1386 }
1387 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001388
1389 if (has_cap(ACER_CAP_BLUETOOTH)) {
1390 bluetooth_rfkill = acer_rfkill_register(dev,
1391 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1392 ACER_CAP_BLUETOOTH);
1393 if (IS_ERR(bluetooth_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001394 err = PTR_ERR(bluetooth_rfkill);
1395 goto error_bluetooth;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001396 }
1397 }
1398
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001399 if (has_cap(ACER_CAP_THREEG)) {
1400 threeg_rfkill = acer_rfkill_register(dev,
1401 RFKILL_TYPE_WWAN, "acer-threeg",
1402 ACER_CAP_THREEG);
1403 if (IS_ERR(threeg_rfkill)) {
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001404 err = PTR_ERR(threeg_rfkill);
1405 goto error_threeg;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001406 }
1407 }
1408
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001409 rfkill_inited = true;
1410
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001411 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1412 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001413 schedule_delayed_work(&acer_rfkill_work,
1414 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001415
1416 return 0;
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001417
1418error_threeg:
1419 if (has_cap(ACER_CAP_BLUETOOTH)) {
1420 rfkill_unregister(bluetooth_rfkill);
1421 rfkill_destroy(bluetooth_rfkill);
1422 }
1423error_bluetooth:
1424 if (has_cap(ACER_CAP_WIRELESS)) {
1425 rfkill_unregister(wireless_rfkill);
1426 rfkill_destroy(wireless_rfkill);
1427 }
1428error_wireless:
1429 return err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001430}
1431
1432static void acer_rfkill_exit(void)
1433{
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001434 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1435 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001436 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001437
Lee, Chun-Yi1709ada2011-08-18 18:47:33 +08001438 if (has_cap(ACER_CAP_WIRELESS)) {
1439 rfkill_unregister(wireless_rfkill);
1440 rfkill_destroy(wireless_rfkill);
1441 }
Johannes Berg19d337d2009-06-02 13:01:37 +02001442
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001443 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001444 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001445 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001446 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001447
1448 if (has_cap(ACER_CAP_THREEG)) {
1449 rfkill_unregister(threeg_rfkill);
1450 rfkill_destroy(threeg_rfkill);
1451 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001452 return;
1453}
1454
1455/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001456 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001457 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001458static ssize_t show_bool_threeg(struct device *dev,
1459 struct device_attribute *attr, char *buf)
1460{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001461 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001462 acpi_status status;
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001463
1464 pr_info("This threeg sysfs will be removed in 2012"
1465 " - used by: %s\n", current->comm);
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001466 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001467 if (ACPI_SUCCESS(status))
1468 return sprintf(buf, "%u\n", result);
1469 return sprintf(buf, "Read error\n");
1470}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001471
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001472static ssize_t set_bool_threeg(struct device *dev,
1473 struct device_attribute *attr, const char *buf, size_t count)
1474{
1475 u32 tmp = simple_strtoul(buf, NULL, 10);
1476 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001477 pr_info("This threeg sysfs will be removed in 2012"
1478 " - used by: %s\n", current->comm);
1479 if (ACPI_FAILURE(status))
1480 return -EINVAL;
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001481 return count;
1482}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001483static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001484 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001485
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001486static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1487 char *buf)
1488{
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001489 pr_info("This interface sysfs will be removed in 2012"
1490 " - used by: %s\n", current->comm);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001491 switch (interface->type) {
1492 case ACER_AMW0:
1493 return sprintf(buf, "AMW0\n");
1494 case ACER_AMW0_V2:
1495 return sprintf(buf, "AMW0 v2\n");
1496 case ACER_WMID:
1497 return sprintf(buf, "WMID\n");
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001498 case ACER_WMID_v2:
1499 return sprintf(buf, "WMID v2\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001500 default:
1501 return sprintf(buf, "Error!\n");
1502 }
1503}
1504
Axel Lin370525d2010-06-30 10:20:23 +08001505static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001506
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001507static void acer_wmi_notify(u32 value, void *context)
1508{
1509 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1510 union acpi_object *obj;
1511 struct event_return_value return_value;
1512 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001513 u16 device_state;
1514 const struct key_entry *key;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001515
1516 status = wmi_get_event_data(value, &response);
1517 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001518 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001519 return;
1520 }
1521
1522 obj = (union acpi_object *)response.pointer;
1523
1524 if (!obj)
1525 return;
1526 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001527 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001528 kfree(obj);
1529 return;
1530 }
1531 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001532 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001533 kfree(obj);
1534 return;
1535 }
1536
1537 return_value = *((struct event_return_value *)obj->buffer.pointer);
1538 kfree(obj);
1539
1540 switch (return_value.function) {
1541 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001542 device_state = return_value.device_state;
1543 pr_debug("device state: 0x%x\n", device_state);
1544
1545 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1546 return_value.key_num);
1547 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001548 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001549 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001550 } else {
1551 switch (key->keycode) {
1552 case KEY_WLAN:
1553 case KEY_BLUETOOTH:
1554 if (has_cap(ACER_CAP_WIRELESS))
1555 rfkill_set_sw_state(wireless_rfkill,
1556 !(device_state & ACER_WMID3_GDS_WIRELESS));
1557 if (has_cap(ACER_CAP_THREEG))
1558 rfkill_set_sw_state(threeg_rfkill,
1559 !(device_state & ACER_WMID3_GDS_THREEG));
1560 if (has_cap(ACER_CAP_BLUETOOTH))
1561 rfkill_set_sw_state(bluetooth_rfkill,
1562 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1563 break;
1564 }
1565 sparse_keymap_report_entry(acer_wmi_input_dev, key,
1566 1, true);
1567 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001568 break;
1569 default:
Joe Perches249c7202011-03-29 15:21:34 -07001570 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001571 return_value.function, return_value.key_num);
1572 break;
1573 }
1574}
1575
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001576static acpi_status
1577wmid3_set_lm_mode(struct lm_input_params *params,
1578 struct lm_return_value *return_value)
1579{
1580 acpi_status status;
1581 union acpi_object *obj;
1582
1583 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1584 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1585
1586 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1587 if (ACPI_FAILURE(status))
1588 return status;
1589
1590 obj = output.pointer;
1591
1592 if (!obj)
1593 return AE_ERROR;
1594 else if (obj->type != ACPI_TYPE_BUFFER) {
1595 kfree(obj);
1596 return AE_ERROR;
1597 }
1598 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001599 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001600 kfree(obj);
1601 return AE_ERROR;
1602 }
1603
1604 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1605 kfree(obj);
1606
1607 return status;
1608}
1609
1610static int acer_wmi_enable_ec_raw(void)
1611{
1612 struct lm_return_value return_value;
1613 acpi_status status;
1614 struct lm_input_params params = {
1615 .function_num = 0x1,
1616 .commun_devices = 0xFFFF,
1617 .devices = 0xFFFF,
1618 .lm_status = 0x00, /* Launch Manager Deactive */
1619 };
1620
1621 status = wmid3_set_lm_mode(&params, &return_value);
1622
1623 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001624 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1625 return_value.error_code,
1626 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001627 else
Joe Perches249c7202011-03-29 15:21:34 -07001628 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001629
1630 return status;
1631}
1632
1633static int acer_wmi_enable_lm(void)
1634{
1635 struct lm_return_value return_value;
1636 acpi_status status;
1637 struct lm_input_params params = {
1638 .function_num = 0x1,
1639 .commun_devices = 0xFFFF,
1640 .devices = 0xFFFF,
1641 .lm_status = 0x01, /* Launch Manager Active */
1642 };
1643
1644 status = wmid3_set_lm_mode(&params, &return_value);
1645
1646 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001647 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1648 return_value.error_code,
1649 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001650
1651 return status;
1652}
1653
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001654static int __init acer_wmi_input_setup(void)
1655{
1656 acpi_status status;
1657 int err;
1658
1659 acer_wmi_input_dev = input_allocate_device();
1660 if (!acer_wmi_input_dev)
1661 return -ENOMEM;
1662
1663 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1664 acer_wmi_input_dev->phys = "wmi/input0";
1665 acer_wmi_input_dev->id.bustype = BUS_HOST;
1666
1667 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1668 if (err)
1669 goto err_free_dev;
1670
1671 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1672 acer_wmi_notify, NULL);
1673 if (ACPI_FAILURE(status)) {
1674 err = -EIO;
1675 goto err_free_keymap;
1676 }
1677
1678 err = input_register_device(acer_wmi_input_dev);
1679 if (err)
1680 goto err_uninstall_notifier;
1681
1682 return 0;
1683
1684err_uninstall_notifier:
1685 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1686err_free_keymap:
1687 sparse_keymap_free(acer_wmi_input_dev);
1688err_free_dev:
1689 input_free_device(acer_wmi_input_dev);
1690 return err;
1691}
1692
1693static void acer_wmi_input_destroy(void)
1694{
1695 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1696 sparse_keymap_free(acer_wmi_input_dev);
1697 input_unregister_device(acer_wmi_input_dev);
1698}
1699
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001700/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001701 * debugfs functions
1702 */
1703static u32 get_wmid_devices(void)
1704{
1705 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1706 union acpi_object *obj;
1707 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001708 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001709
1710 status = wmi_query_block(WMID_GUID2, 1, &out);
1711 if (ACPI_FAILURE(status))
1712 return 0;
1713
1714 obj = (union acpi_object *) out.pointer;
1715 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +08001716 (obj->buffer.length == sizeof(u32) ||
1717 obj->buffer.length == sizeof(u64))) {
Axel Lin66904862010-07-20 15:19:52 -07001718 devices = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +08001719 } else if (obj->type == ACPI_TYPE_INTEGER) {
1720 devices = (u32) obj->integer.value;
Carlos Corbacho81143522008-06-21 09:09:53 +01001721 }
Axel Lin66904862010-07-20 15:19:52 -07001722
1723 kfree(out.pointer);
1724 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001725}
1726
1727/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001728 * Platform device
1729 */
1730static int __devinit acer_platform_probe(struct platform_device *device)
1731{
1732 int err;
1733
1734 if (has_cap(ACER_CAP_MAILLED)) {
1735 err = acer_led_init(&device->dev);
1736 if (err)
1737 goto error_mailled;
1738 }
1739
1740 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1741 err = acer_backlight_init(&device->dev);
1742 if (err)
1743 goto error_brightness;
1744 }
1745
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001746 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001747 if (err)
1748 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001749
1750 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001751
Andy Whitcroft350e3292009-04-04 09:33:34 +01001752error_rfkill:
1753 if (has_cap(ACER_CAP_BRIGHTNESS))
1754 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001755error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001756 if (has_cap(ACER_CAP_MAILLED))
1757 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001758error_mailled:
1759 return err;
1760}
1761
1762static int acer_platform_remove(struct platform_device *device)
1763{
1764 if (has_cap(ACER_CAP_MAILLED))
1765 acer_led_exit();
1766 if (has_cap(ACER_CAP_BRIGHTNESS))
1767 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001768
1769 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001770 return 0;
1771}
1772
1773static int acer_platform_suspend(struct platform_device *dev,
1774pm_message_t state)
1775{
1776 u32 value;
1777 struct acer_data *data = &interface->data;
1778
1779 if (!data)
1780 return -ENOMEM;
1781
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001782 if (has_cap(ACER_CAP_MAILLED)) {
1783 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001784 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001785 data->mailled = value;
1786 }
1787
1788 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1789 get_u32(&value, ACER_CAP_BRIGHTNESS);
1790 data->brightness = value;
1791 }
1792
1793 return 0;
1794}
1795
1796static int acer_platform_resume(struct platform_device *device)
1797{
1798 struct acer_data *data = &interface->data;
1799
1800 if (!data)
1801 return -ENOMEM;
1802
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001803 if (has_cap(ACER_CAP_MAILLED))
1804 set_u32(data->mailled, ACER_CAP_MAILLED);
1805
1806 if (has_cap(ACER_CAP_BRIGHTNESS))
1807 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1808
1809 return 0;
1810}
1811
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001812static void acer_platform_shutdown(struct platform_device *device)
1813{
1814 struct acer_data *data = &interface->data;
1815
1816 if (!data)
1817 return;
1818
1819 if (has_cap(ACER_CAP_MAILLED))
1820 set_u32(LED_OFF, ACER_CAP_MAILLED);
1821}
1822
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001823static struct platform_driver acer_platform_driver = {
1824 .driver = {
1825 .name = "acer-wmi",
1826 .owner = THIS_MODULE,
1827 },
1828 .probe = acer_platform_probe,
1829 .remove = acer_platform_remove,
1830 .suspend = acer_platform_suspend,
1831 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001832 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001833};
1834
1835static struct platform_device *acer_platform_device;
1836
1837static int remove_sysfs(struct platform_device *device)
1838{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001839 if (has_cap(ACER_CAP_THREEG))
1840 device_remove_file(&device->dev, &dev_attr_threeg);
1841
1842 device_remove_file(&device->dev, &dev_attr_interface);
1843
1844 return 0;
1845}
1846
1847static int create_sysfs(void)
1848{
1849 int retval = -ENOMEM;
1850
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001851 if (has_cap(ACER_CAP_THREEG)) {
1852 retval = device_create_file(&acer_platform_device->dev,
1853 &dev_attr_threeg);
1854 if (retval)
1855 goto error_sysfs;
1856 }
1857
1858 retval = device_create_file(&acer_platform_device->dev,
1859 &dev_attr_interface);
1860 if (retval)
1861 goto error_sysfs;
1862
1863 return 0;
1864
1865error_sysfs:
1866 remove_sysfs(acer_platform_device);
1867 return retval;
1868}
1869
Carlos Corbacho81143522008-06-21 09:09:53 +01001870static void remove_debugfs(void)
1871{
1872 debugfs_remove(interface->debug.devices);
1873 debugfs_remove(interface->debug.root);
1874}
1875
1876static int create_debugfs(void)
1877{
1878 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1879 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001880 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001881 return -ENOMEM;
1882 }
1883
1884 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1885 interface->debug.root,
1886 &interface->debug.wmid_devices);
1887 if (!interface->debug.devices)
1888 goto error_debugfs;
1889
1890 return 0;
1891
1892error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001893 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001894 return -ENOMEM;
1895}
1896
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001897static int __init acer_wmi_init(void)
1898{
1899 int err;
1900
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001901 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001902
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001903 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001904 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001905 return -ENODEV;
1906 }
1907
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001908 find_quirks();
1909
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001910 /*
1911 * Detect which ACPI-WMI interface we're using.
1912 */
1913 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1914 interface = &AMW0_V2_interface;
1915
1916 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1917 interface = &wmid_interface;
1918
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001919 if (wmi_has_guid(WMID_GUID3))
1920 interface = &wmid_v2_interface;
1921
1922 if (interface)
1923 dmi_walk(type_aa_dmi_decode, NULL);
1924
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001925 if (wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001926 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001927 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001928 return -ENODEV;
1929 }
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001930 /* WMID always provides brightness methods */
1931 interface->capability |= ACER_CAP_BRIGHTNESS;
1932 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001933 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001934 return -ENODEV;
1935 }
1936
1937 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1938 interface = &AMW0_interface;
1939
1940 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001941 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001942 return -ENODEV;
1943 }
1944 }
1945
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001946 if (wmi_has_guid(AMW0_GUID1))
1947 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001948
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001949 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001950 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001951 return -ENODEV;
1952 }
1953
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001954 set_quirks();
1955
Lee, Chun-Yi72e71de2011-08-18 18:47:32 +08001956 if (acpi_video_backlight_support()) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001957 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001958 pr_info("Brightness must be controlled by "
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001959 "generic video driver\n");
1960 }
1961
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001962 if (wmi_has_guid(WMID_GUID3)) {
1963 if (ec_raw_mode) {
1964 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001965 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001966 return -ENODEV;
1967 }
1968 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001969 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001970 return -ENODEV;
1971 }
1972 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001973 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001974 }
1975
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001976 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1977 err = acer_wmi_input_setup();
1978 if (err)
1979 return err;
1980 }
1981
Axel Lin1c796322010-06-22 16:17:38 +08001982 err = platform_driver_register(&acer_platform_driver);
1983 if (err) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001984 pr_err("Unable to register platform driver.\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001985 goto error_platform_register;
1986 }
Axel Lin1c796322010-06-22 16:17:38 +08001987
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001988 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001989 if (!acer_platform_device) {
1990 err = -ENOMEM;
1991 goto error_device_alloc;
1992 }
1993
1994 err = platform_device_add(acer_platform_device);
1995 if (err)
1996 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001997
1998 err = create_sysfs();
1999 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002000 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002001
Carlos Corbacho81143522008-06-21 09:09:53 +01002002 if (wmi_has_guid(WMID_GUID2)) {
2003 interface->debug.wmid_devices = get_wmid_devices();
2004 err = create_debugfs();
2005 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08002006 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01002007 }
2008
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002009 /* Override any initial settings with values from the commandline */
2010 acer_commandline_init();
2011
2012 return 0;
2013
Axel Lin1c796322010-06-22 16:17:38 +08002014error_create_debugfs:
2015 remove_sysfs(acer_platform_device);
2016error_create_sys:
2017 platform_device_del(acer_platform_device);
2018error_device_add:
2019 platform_device_put(acer_platform_device);
2020error_device_alloc:
2021 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002022error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002023 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2024 acer_wmi_input_destroy();
2025
Axel Lin1c796322010-06-22 16:17:38 +08002026 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002027}
2028
2029static void __exit acer_wmi_exit(void)
2030{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08002031 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2032 acer_wmi_input_destroy();
2033
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002034 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07002035 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08002036 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002037 platform_driver_unregister(&acer_platform_driver);
2038
Lee, Chun-Yicae15702011-03-16 18:52:36 +08002039 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00002040 return;
2041}
2042
2043module_init(acer_wmi_init);
2044module_exit(acer_wmi_exit);