blob: 5dc843bfc6c22c23337c0e5eaa411142aa25cbcb [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 */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800102 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
103 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
104 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
105 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
106 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200107 {KE_IGNORE, 0x41, {KEY_MUTE} },
108 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
109 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
110 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
111 {KE_IGNORE, 0x45, {KEY_STOP} },
112 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
113 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
114 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
115 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
116 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800117 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200118 {KE_IGNORE, 0x81, {KEY_SLEEP} },
Lee, Chun-Yi89411782011-03-02 01:07:11 +0800119 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
Melchior FRANZ8ae68de2011-05-24 10:35:55 +0200120 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800121 {KE_END, 0}
122};
123
124static struct input_dev *acer_wmi_input_dev;
125
126struct event_return_value {
127 u8 function;
128 u8 key_num;
129 u16 device_state;
130 u32 reserved;
131} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000132
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000133/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800134 * GUID3 Get Device Status device flags
135 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800136#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800137#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +0800138#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800139#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800140
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500141struct lm_input_params {
142 u8 function_num; /* Function Number */
143 u16 commun_devices; /* Communication type devices default status */
144 u16 devices; /* Other type devices default status */
145 u8 lm_status; /* Launch Manager Status */
146 u16 reserved;
147} __attribute__((packed));
148
149struct lm_return_value {
150 u8 error_code; /* Error Code */
151 u8 ec_return_value; /* EC Return Value */
152 u16 reserved;
153} __attribute__((packed));
154
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800155struct wmid3_gds_input_param { /* Get Device Status input parameter */
156 u8 function_num; /* Function Number */
157 u8 hotkey_number; /* Hotkey Number */
158 u16 devices; /* Get Device */
159} __attribute__((packed));
160
161struct wmid3_gds_return_value { /* Get Device Status return value*/
162 u8 error_code; /* Error Code */
163 u8 ec_return_value; /* EC Return Value */
164 u16 devices; /* Current Device Status */
165 u32 reserved;
166} __attribute__((packed));
167
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800168struct hotkey_function_type_aa {
169 u8 type;
170 u8 length;
171 u16 handle;
172 u16 commun_func_bitmap;
173} __attribute__((packed));
174
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800175/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000176 * Interface capability flags
177 */
178#define ACER_CAP_MAILLED (1<<0)
179#define ACER_CAP_WIRELESS (1<<1)
180#define ACER_CAP_BLUETOOTH (1<<2)
181#define ACER_CAP_BRIGHTNESS (1<<3)
182#define ACER_CAP_THREEG (1<<4)
183#define ACER_CAP_ANY (0xFFFFFFFF)
184
185/*
186 * Interface type flags
187 */
188enum interface_flags {
189 ACER_AMW0,
190 ACER_AMW0_V2,
191 ACER_WMID,
192};
193
194#define ACER_DEFAULT_WIRELESS 0
195#define ACER_DEFAULT_BLUETOOTH 0
196#define ACER_DEFAULT_MAILLED 0
197#define ACER_DEFAULT_THREEG 0
198
199static int max_brightness = 0xF;
200
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000201static int mailled = -1;
202static int brightness = -1;
203static int threeg = -1;
204static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500205static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800206static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000207
208module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000209module_param(brightness, int, 0444);
210module_param(threeg, int, 0444);
211module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500212module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000213MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
214MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
215MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
216MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500217MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000218
219struct acer_data {
220 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000221 int threeg;
222 int brightness;
223};
224
Carlos Corbacho81143522008-06-21 09:09:53 +0100225struct acer_debug {
226 struct dentry *root;
227 struct dentry *devices;
228 u32 wmid_devices;
229};
230
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100231static struct rfkill *wireless_rfkill;
232static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800233static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800234static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100235
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000236/* Each low-level interface must define at least some of the following */
237struct wmi_interface {
238 /* The WMI device type */
239 u32 type;
240
241 /* The capabilities this interface provides */
242 u32 capability;
243
244 /* Private data for the current interface */
245 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100246
247 /* debugfs entries associated with this interface */
248 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000249};
250
251/* The static interface pointer, points to the currently detected interface */
252static struct wmi_interface *interface;
253
254/*
255 * Embedded Controller quirks
256 * Some laptops require us to directly access the EC to either enable or query
257 * features that are not available through WMI.
258 */
259
260struct quirk_entry {
261 u8 wireless;
262 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100263 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000264 u8 bluetooth;
265};
266
267static struct quirk_entry *quirks;
268
269static void set_quirks(void)
270{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700271 if (!interface)
272 return;
273
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000274 if (quirks->mailled)
275 interface->capability |= ACER_CAP_MAILLED;
276
277 if (quirks->brightness)
278 interface->capability |= ACER_CAP_BRIGHTNESS;
279}
280
281static int dmi_matched(const struct dmi_system_id *dmi)
282{
283 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800284 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000285}
286
287static struct quirk_entry quirk_unknown = {
288};
289
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100290static struct quirk_entry quirk_acer_aspire_1520 = {
291 .brightness = -1,
292};
293
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000294static struct quirk_entry quirk_acer_travelmate_2490 = {
295 .mailled = 1,
296};
297
298/* This AMW0 laptop has no bluetooth */
299static struct quirk_entry quirk_medion_md_98300 = {
300 .wireless = 1,
301};
302
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100303static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
304 .wireless = 2,
305};
306
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100307/* The Aspire One has a dummy ACPI-WMI interface - disable it */
308static struct dmi_system_id __devinitdata acer_blacklist[] = {
309 {
310 .ident = "Acer Aspire One (SSD)",
311 .matches = {
312 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
313 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
314 },
315 },
316 {
317 .ident = "Acer Aspire One (HDD)",
318 .matches = {
319 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
320 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
321 },
322 },
323 {}
324};
325
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000326static struct dmi_system_id acer_quirks[] = {
327 {
328 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100329 .ident = "Acer Aspire 1360",
330 .matches = {
331 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
332 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
333 },
334 .driver_data = &quirk_acer_aspire_1520,
335 },
336 {
337 .callback = dmi_matched,
338 .ident = "Acer Aspire 1520",
339 .matches = {
340 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
341 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
342 },
343 .driver_data = &quirk_acer_aspire_1520,
344 },
345 {
346 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000347 .ident = "Acer Aspire 3100",
348 .matches = {
349 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
350 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
351 },
352 .driver_data = &quirk_acer_travelmate_2490,
353 },
354 {
355 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000356 .ident = "Acer Aspire 3610",
357 .matches = {
358 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
359 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
360 },
361 .driver_data = &quirk_acer_travelmate_2490,
362 },
363 {
364 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000365 .ident = "Acer Aspire 5100",
366 .matches = {
367 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
368 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
369 },
370 .driver_data = &quirk_acer_travelmate_2490,
371 },
372 {
373 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000374 .ident = "Acer Aspire 5610",
375 .matches = {
376 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
377 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
378 },
379 .driver_data = &quirk_acer_travelmate_2490,
380 },
381 {
382 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000383 .ident = "Acer Aspire 5630",
384 .matches = {
385 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
386 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
387 },
388 .driver_data = &quirk_acer_travelmate_2490,
389 },
390 {
391 .callback = dmi_matched,
392 .ident = "Acer Aspire 5650",
393 .matches = {
394 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
395 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
396 },
397 .driver_data = &quirk_acer_travelmate_2490,
398 },
399 {
400 .callback = dmi_matched,
401 .ident = "Acer Aspire 5680",
402 .matches = {
403 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
404 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
405 },
406 .driver_data = &quirk_acer_travelmate_2490,
407 },
408 {
409 .callback = dmi_matched,
410 .ident = "Acer Aspire 9110",
411 .matches = {
412 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
413 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
414 },
415 .driver_data = &quirk_acer_travelmate_2490,
416 },
417 {
418 .callback = dmi_matched,
419 .ident = "Acer TravelMate 2490",
420 .matches = {
421 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
422 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
423 },
424 .driver_data = &quirk_acer_travelmate_2490,
425 },
426 {
427 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000428 .ident = "Acer TravelMate 4200",
429 .matches = {
430 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
431 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
432 },
433 .driver_data = &quirk_acer_travelmate_2490,
434 },
435 {
436 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100437 .ident = "Fujitsu Siemens Amilo Li 1718",
438 .matches = {
439 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
440 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
441 },
442 .driver_data = &quirk_fujitsu_amilo_li_1718,
443 },
444 {
445 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000446 .ident = "Medion MD 98300",
447 .matches = {
448 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
449 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
450 },
451 .driver_data = &quirk_medion_md_98300,
452 },
453 {}
454};
455
456/* Find which quirks are needed for a particular vendor/ model pair */
457static void find_quirks(void)
458{
459 if (!force_series) {
460 dmi_check_system(acer_quirks);
461 } else if (force_series == 2490) {
462 quirks = &quirk_acer_travelmate_2490;
463 }
464
465 if (quirks == NULL)
466 quirks = &quirk_unknown;
467
468 set_quirks();
469}
470
471/*
472 * General interface convenience methods
473 */
474
475static bool has_cap(u32 cap)
476{
477 if ((interface->capability & cap) != 0)
478 return 1;
479
480 return 0;
481}
482
483/*
484 * AMW0 (V1) interface
485 */
486struct wmab_args {
487 u32 eax;
488 u32 ebx;
489 u32 ecx;
490 u32 edx;
491};
492
493struct wmab_ret {
494 u32 eax;
495 u32 ebx;
496 u32 ecx;
497 u32 edx;
498 u32 eex;
499};
500
501static acpi_status wmab_execute(struct wmab_args *regbuf,
502struct acpi_buffer *result)
503{
504 struct acpi_buffer input;
505 acpi_status status;
506 input.length = sizeof(struct wmab_args);
507 input.pointer = (u8 *)regbuf;
508
509 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
510
511 return status;
512}
513
514static acpi_status AMW0_get_u32(u32 *value, u32 cap,
515struct wmi_interface *iface)
516{
517 int err;
518 u8 result;
519
520 switch (cap) {
521 case ACER_CAP_MAILLED:
522 switch (quirks->mailled) {
523 default:
524 err = ec_read(0xA, &result);
525 if (err)
526 return AE_ERROR;
527 *value = (result >> 7) & 0x1;
528 return AE_OK;
529 }
530 break;
531 case ACER_CAP_WIRELESS:
532 switch (quirks->wireless) {
533 case 1:
534 err = ec_read(0x7B, &result);
535 if (err)
536 return AE_ERROR;
537 *value = result & 0x1;
538 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100539 case 2:
540 err = ec_read(0x71, &result);
541 if (err)
542 return AE_ERROR;
543 *value = result & 0x1;
544 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000545 default:
546 err = ec_read(0xA, &result);
547 if (err)
548 return AE_ERROR;
549 *value = (result >> 2) & 0x1;
550 return AE_OK;
551 }
552 break;
553 case ACER_CAP_BLUETOOTH:
554 switch (quirks->bluetooth) {
555 default:
556 err = ec_read(0xA, &result);
557 if (err)
558 return AE_ERROR;
559 *value = (result >> 4) & 0x1;
560 return AE_OK;
561 }
562 break;
563 case ACER_CAP_BRIGHTNESS:
564 switch (quirks->brightness) {
565 default:
566 err = ec_read(0x83, &result);
567 if (err)
568 return AE_ERROR;
569 *value = result;
570 return AE_OK;
571 }
572 break;
573 default:
Lin Ming08237972008-08-08 11:57:11 +0800574 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000575 }
576 return AE_OK;
577}
578
579static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
580{
581 struct wmab_args args;
582
583 args.eax = ACER_AMW0_WRITE;
584 args.ebx = value ? (1<<8) : 0;
585 args.ecx = args.edx = 0;
586
587 switch (cap) {
588 case ACER_CAP_MAILLED:
589 if (value > 1)
590 return AE_BAD_PARAMETER;
591 args.ebx |= ACER_AMW0_MAILLED_MASK;
592 break;
593 case ACER_CAP_WIRELESS:
594 if (value > 1)
595 return AE_BAD_PARAMETER;
596 args.ebx |= ACER_AMW0_WIRELESS_MASK;
597 break;
598 case ACER_CAP_BLUETOOTH:
599 if (value > 1)
600 return AE_BAD_PARAMETER;
601 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
602 break;
603 case ACER_CAP_BRIGHTNESS:
604 if (value > max_brightness)
605 return AE_BAD_PARAMETER;
606 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000607 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000608 return ec_write(0x83, value);
609 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000610 }
611 default:
Lin Ming08237972008-08-08 11:57:11 +0800612 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000613 }
614
615 /* Actually do the set */
616 return wmab_execute(&args, NULL);
617}
618
619static acpi_status AMW0_find_mailled(void)
620{
621 struct wmab_args args;
622 struct wmab_ret ret;
623 acpi_status status = AE_OK;
624 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
625 union acpi_object *obj;
626
627 args.eax = 0x86;
628 args.ebx = args.ecx = args.edx = 0;
629
630 status = wmab_execute(&args, &out);
631 if (ACPI_FAILURE(status))
632 return status;
633
634 obj = (union acpi_object *) out.pointer;
635 if (obj && obj->type == ACPI_TYPE_BUFFER &&
636 obj->buffer.length == sizeof(struct wmab_ret)) {
637 ret = *((struct wmab_ret *) obj->buffer.pointer);
638 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700639 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000640 return AE_ERROR;
641 }
642
643 if (ret.eex & 0x1)
644 interface->capability |= ACER_CAP_MAILLED;
645
646 kfree(out.pointer);
647
648 return AE_OK;
649}
650
651static acpi_status AMW0_set_capabilities(void)
652{
653 struct wmab_args args;
654 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700655 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000656 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
657 union acpi_object *obj;
658
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100659 /*
660 * On laptops with this strange GUID (non Acer), normal probing doesn't
661 * work.
662 */
663 if (wmi_has_guid(AMW0_GUID2)) {
664 interface->capability |= ACER_CAP_WIRELESS;
665 return AE_OK;
666 }
667
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000668 args.eax = ACER_AMW0_WRITE;
669 args.ecx = args.edx = 0;
670
671 args.ebx = 0xa2 << 8;
672 args.ebx |= ACER_AMW0_WIRELESS_MASK;
673
674 status = wmab_execute(&args, &out);
675 if (ACPI_FAILURE(status))
676 return status;
677
Axel Lin7677fbd2010-07-20 15:19:53 -0700678 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000679 if (obj && obj->type == ACPI_TYPE_BUFFER &&
680 obj->buffer.length == sizeof(struct wmab_ret)) {
681 ret = *((struct wmab_ret *) obj->buffer.pointer);
682 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700683 status = AE_ERROR;
684 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000685 }
686
687 if (ret.eax & 0x1)
688 interface->capability |= ACER_CAP_WIRELESS;
689
690 args.ebx = 2 << 8;
691 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
692
Axel Lin7677fbd2010-07-20 15:19:53 -0700693 /*
694 * It's ok to use existing buffer for next wmab_execute call.
695 * But we need to kfree(out.pointer) if next wmab_execute fail.
696 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000697 status = wmab_execute(&args, &out);
698 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700699 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000700
701 obj = (union acpi_object *) out.pointer;
702 if (obj && obj->type == ACPI_TYPE_BUFFER
703 && obj->buffer.length == sizeof(struct wmab_ret)) {
704 ret = *((struct wmab_ret *) obj->buffer.pointer);
705 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700706 status = AE_ERROR;
707 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000708 }
709
710 if (ret.eax & 0x1)
711 interface->capability |= ACER_CAP_BLUETOOTH;
712
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000713 /*
714 * This appears to be safe to enable, since all Wistron based laptops
715 * appear to use the same EC register for brightness, even if they
716 * differ for wireless, etc
717 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100718 if (quirks->brightness >= 0)
719 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000720
Axel Lin7677fbd2010-07-20 15:19:53 -0700721 status = AE_OK;
722out:
723 kfree(out.pointer);
724 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000725}
726
727static struct wmi_interface AMW0_interface = {
728 .type = ACER_AMW0,
729};
730
731static struct wmi_interface AMW0_V2_interface = {
732 .type = ACER_AMW0_V2,
733};
734
735/*
736 * New interface (The WMID interface)
737 */
738static acpi_status
739WMI_execute_u32(u32 method_id, u32 in, u32 *out)
740{
741 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
742 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
743 union acpi_object *obj;
744 u32 tmp;
745 acpi_status status;
746
747 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
748
749 if (ACPI_FAILURE(status))
750 return status;
751
752 obj = (union acpi_object *) result.pointer;
753 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +0800754 (obj->buffer.length == sizeof(u32) ||
755 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000756 tmp = *((u32 *) obj->buffer.pointer);
757 } else {
758 tmp = 0;
759 }
760
761 if (out)
762 *out = tmp;
763
764 kfree(result.pointer);
765
766 return status;
767}
768
769static acpi_status WMID_get_u32(u32 *value, u32 cap,
770struct wmi_interface *iface)
771{
772 acpi_status status;
773 u8 tmp;
774 u32 result, method_id = 0;
775
776 switch (cap) {
777 case ACER_CAP_WIRELESS:
778 method_id = ACER_WMID_GET_WIRELESS_METHODID;
779 break;
780 case ACER_CAP_BLUETOOTH:
781 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
782 break;
783 case ACER_CAP_BRIGHTNESS:
784 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
785 break;
786 case ACER_CAP_THREEG:
787 method_id = ACER_WMID_GET_THREEG_METHODID;
788 break;
789 case ACER_CAP_MAILLED:
790 if (quirks->mailled == 1) {
791 ec_read(0x9f, &tmp);
792 *value = tmp & 0x1;
793 return 0;
794 }
795 default:
Lin Ming08237972008-08-08 11:57:11 +0800796 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000797 }
798 status = WMI_execute_u32(method_id, 0, &result);
799
800 if (ACPI_SUCCESS(status))
801 *value = (u8)result;
802
803 return status;
804}
805
806static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
807{
808 u32 method_id = 0;
809 char param;
810
811 switch (cap) {
812 case ACER_CAP_BRIGHTNESS:
813 if (value > max_brightness)
814 return AE_BAD_PARAMETER;
815 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
816 break;
817 case ACER_CAP_WIRELESS:
818 if (value > 1)
819 return AE_BAD_PARAMETER;
820 method_id = ACER_WMID_SET_WIRELESS_METHODID;
821 break;
822 case ACER_CAP_BLUETOOTH:
823 if (value > 1)
824 return AE_BAD_PARAMETER;
825 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
826 break;
827 case ACER_CAP_THREEG:
828 if (value > 1)
829 return AE_BAD_PARAMETER;
830 method_id = ACER_WMID_SET_THREEG_METHODID;
831 break;
832 case ACER_CAP_MAILLED:
833 if (value > 1)
834 return AE_BAD_PARAMETER;
835 if (quirks->mailled == 1) {
836 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700837 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000838 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700839 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000840 return 0;
841 }
842 break;
843 default:
Lin Ming08237972008-08-08 11:57:11 +0800844 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000845 }
846 return WMI_execute_u32(method_id, (u32)value, NULL);
847}
848
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800849static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
850{
851 struct hotkey_function_type_aa *type_aa;
852
853 /* We are looking for OEM-specific Type AAh */
854 if (header->type != 0xAA)
855 return;
856
857 has_type_aa = true;
858 type_aa = (struct hotkey_function_type_aa *) header;
859
Lee, Chun-Yicae15702011-03-16 18:52:36 +0800860 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800861 type_aa->commun_func_bitmap);
862
863 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
864 interface->capability |= ACER_CAP_WIRELESS;
865 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
866 interface->capability |= ACER_CAP_THREEG;
867 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
868 interface->capability |= ACER_CAP_BLUETOOTH;
869}
870
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000871static acpi_status WMID_set_capabilities(void)
872{
873 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
874 union acpi_object *obj;
875 acpi_status status;
876 u32 devices;
877
878 status = wmi_query_block(WMID_GUID2, 1, &out);
879 if (ACPI_FAILURE(status))
880 return status;
881
882 obj = (union acpi_object *) out.pointer;
883 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +0800884 (obj->buffer.length == sizeof(u32) ||
885 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000886 devices = *((u32 *) obj->buffer.pointer);
887 } else {
Axel Lin66904862010-07-20 15:19:52 -0700888 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000889 return AE_ERROR;
890 }
891
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800892 dmi_walk(type_aa_dmi_decode, NULL);
893 if (!has_type_aa) {
894 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yia8d1a262011-05-22 07:33:52 +0800895 if (devices & 0x40)
896 interface->capability |= ACER_CAP_THREEG;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800897 if (devices & 0x10)
898 interface->capability |= ACER_CAP_BLUETOOTH;
899 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000900
901 /* WMID always provides brightness methods */
902 interface->capability |= ACER_CAP_BRIGHTNESS;
903
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000904 if (!(devices & 0x20))
905 max_brightness = 0x9;
906
Axel Lin66904862010-07-20 15:19:52 -0700907 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000908 return status;
909}
910
911static struct wmi_interface wmid_interface = {
912 .type = ACER_WMID,
913};
914
915/*
916 * Generic Device (interface-independent)
917 */
918
919static acpi_status get_u32(u32 *value, u32 cap)
920{
Lin Ming08237972008-08-08 11:57:11 +0800921 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000922
923 switch (interface->type) {
924 case ACER_AMW0:
925 status = AMW0_get_u32(value, cap, interface);
926 break;
927 case ACER_AMW0_V2:
928 if (cap == ACER_CAP_MAILLED) {
929 status = AMW0_get_u32(value, cap, interface);
930 break;
931 }
932 case ACER_WMID:
933 status = WMID_get_u32(value, cap, interface);
934 break;
935 }
936
937 return status;
938}
939
940static acpi_status set_u32(u32 value, u32 cap)
941{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100942 acpi_status status;
943
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000944 if (interface->capability & cap) {
945 switch (interface->type) {
946 case ACER_AMW0:
947 return AMW0_set_u32(value, cap, interface);
948 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100949 if (cap == ACER_CAP_MAILLED)
950 return AMW0_set_u32(value, cap, interface);
951
952 /*
953 * On some models, some WMID methods don't toggle
954 * properly. For those cases, we want to run the AMW0
955 * method afterwards to be certain we've really toggled
956 * the device state.
957 */
958 if (cap == ACER_CAP_WIRELESS ||
959 cap == ACER_CAP_BLUETOOTH) {
960 status = WMID_set_u32(value, cap, interface);
961 if (ACPI_FAILURE(status))
962 return status;
963
964 return AMW0_set_u32(value, cap, interface);
965 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000966 case ACER_WMID:
967 return WMID_set_u32(value, cap, interface);
968 default:
969 return AE_BAD_PARAMETER;
970 }
971 }
972 return AE_BAD_PARAMETER;
973}
974
975static void __init acer_commandline_init(void)
976{
977 /*
978 * These will all fail silently if the value given is invalid, or the
979 * capability isn't available on the given interface
980 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +0800981 if (mailled >= 0)
982 set_u32(mailled, ACER_CAP_MAILLED);
983 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800984 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +0800985 if (brightness >= 0)
986 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000987}
988
989/*
990 * LED device (Mail LED only, no other LEDs known yet)
991 */
992static void mail_led_set(struct led_classdev *led_cdev,
993enum led_brightness value)
994{
995 set_u32(value, ACER_CAP_MAILLED);
996}
997
998static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000999 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001000 .brightness_set = mail_led_set,
1001};
1002
Sam Ravnborg7560e382008-02-17 13:22:54 +01001003static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001004{
1005 return led_classdev_register(dev, &mail_led);
1006}
1007
1008static void acer_led_exit(void)
1009{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001010 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001011 led_classdev_unregister(&mail_led);
1012}
1013
1014/*
1015 * Backlight device
1016 */
1017static struct backlight_device *acer_backlight_device;
1018
1019static int read_brightness(struct backlight_device *bd)
1020{
1021 u32 value;
1022 get_u32(&value, ACER_CAP_BRIGHTNESS);
1023 return value;
1024}
1025
1026static int update_bl_status(struct backlight_device *bd)
1027{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001028 int intensity = bd->props.brightness;
1029
1030 if (bd->props.power != FB_BLANK_UNBLANK)
1031 intensity = 0;
1032 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1033 intensity = 0;
1034
1035 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1036
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001037 return 0;
1038}
1039
Lionel Debrouxacc24722010-11-16 14:14:02 +01001040static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001041 .get_brightness = read_brightness,
1042 .update_status = update_bl_status,
1043};
1044
Sam Ravnborg7560e382008-02-17 13:22:54 +01001045static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001046{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001047 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001048 struct backlight_device *bd;
1049
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001050 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001051 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001052 props.max_brightness = max_brightness;
1053 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1054 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001055 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001056 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001057 acer_backlight_device = NULL;
1058 return PTR_ERR(bd);
1059 }
1060
1061 acer_backlight_device = bd;
1062
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001063 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001064 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001065 backlight_update_status(bd);
1066 return 0;
1067}
1068
Sam Ravnborg7560e382008-02-17 13:22:54 +01001069static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001070{
1071 backlight_device_unregister(acer_backlight_device);
1072}
1073
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001074static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1075{
1076 struct wmid3_gds_return_value return_value;
1077 acpi_status status;
1078 union acpi_object *obj;
1079 struct wmid3_gds_input_param params = {
1080 .function_num = 0x1,
1081 .hotkey_number = 0x01,
1082 .devices = device,
1083 };
1084 struct acpi_buffer input = {
1085 sizeof(struct wmid3_gds_input_param),
1086 &params
1087 };
1088 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1089
1090 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1091 if (ACPI_FAILURE(status))
1092 return status;
1093
1094 obj = output.pointer;
1095
1096 if (!obj)
1097 return AE_ERROR;
1098 else if (obj->type != ACPI_TYPE_BUFFER) {
1099 kfree(obj);
1100 return AE_ERROR;
1101 }
1102 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001103 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001104 kfree(obj);
1105 return AE_ERROR;
1106 }
1107
1108 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1109 kfree(obj);
1110
1111 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001112 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1113 return_value.error_code,
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001114 return_value.ec_return_value);
1115 else
1116 *value = !!(return_value.devices & device);
1117
1118 return status;
1119}
1120
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001121static acpi_status get_device_status(u32 *value, u32 cap)
1122{
1123 if (wmi_has_guid(WMID_GUID3)) {
1124 u16 device;
1125
1126 switch (cap) {
1127 case ACER_CAP_WIRELESS:
1128 device = ACER_WMID3_GDS_WIRELESS;
1129 break;
1130 case ACER_CAP_BLUETOOTH:
1131 device = ACER_WMID3_GDS_BLUETOOTH;
1132 break;
1133 case ACER_CAP_THREEG:
1134 device = ACER_WMID3_GDS_THREEG;
1135 break;
1136 default:
1137 return AE_ERROR;
1138 }
1139 return wmid3_get_device_status(value, device);
1140
1141 } else {
1142 return get_u32(value, cap);
1143 }
1144}
1145
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +08001146static acpi_status wmid3_set_device_status(u32 value, u16 device)
1147{
1148 struct wmid3_gds_return_value return_value;
1149 acpi_status status;
1150 union acpi_object *obj;
1151 u16 devices;
1152 struct wmid3_gds_input_param params = {
1153 .function_num = 0x1,
1154 .hotkey_number = 0x01,
1155 .devices = ACER_WMID3_GDS_WIRELESS &
1156 ACER_WMID3_GDS_THREEG &
1157 ACER_WMID3_GDS_WIMAX &
1158 ACER_WMID3_GDS_BLUETOOTH,
1159 };
1160 struct acpi_buffer input = {
1161 sizeof(struct wmid3_gds_input_param),
1162 &params
1163 };
1164 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1165 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1166
1167 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1168 if (ACPI_FAILURE(status))
1169 return status;
1170
1171 obj = output.pointer;
1172
1173 if (!obj)
1174 return AE_ERROR;
1175 else if (obj->type != ACPI_TYPE_BUFFER) {
1176 kfree(obj);
1177 return AE_ERROR;
1178 }
1179 if (obj->buffer.length != 8) {
1180 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1181 kfree(obj);
1182 return AE_ERROR;
1183 }
1184
1185 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1186 kfree(obj);
1187
1188 if (return_value.error_code || return_value.ec_return_value) {
1189 pr_warning("Get Current Device Status failed: "
1190 "0x%x - 0x%x\n", return_value.error_code,
1191 return_value.ec_return_value);
1192 return status;
1193 }
1194
1195 devices = return_value.devices;
1196 params.function_num = 0x2;
1197 params.hotkey_number = 0x01;
1198 params.devices = (value) ? (devices | device) : (devices & ~device);
1199
1200 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
1201 if (ACPI_FAILURE(status))
1202 return status;
1203
1204 obj = output2.pointer;
1205
1206 if (!obj)
1207 return AE_ERROR;
1208 else if (obj->type != ACPI_TYPE_BUFFER) {
1209 kfree(obj);
1210 return AE_ERROR;
1211 }
1212 if (obj->buffer.length != 4) {
1213 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1214 kfree(obj);
1215 return AE_ERROR;
1216 }
1217
1218 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1219 kfree(obj);
1220
1221 if (return_value.error_code || return_value.ec_return_value)
1222 pr_warning("Set Device Status failed: "
1223 "0x%x - 0x%x\n", return_value.error_code,
1224 return_value.ec_return_value);
1225
1226 return status;
1227}
1228
1229static acpi_status set_device_status(u32 value, u32 cap)
1230{
1231 if (wmi_has_guid(WMID_GUID3)) {
1232 u16 device;
1233
1234 switch (cap) {
1235 case ACER_CAP_WIRELESS:
1236 device = ACER_WMID3_GDS_WIRELESS;
1237 break;
1238 case ACER_CAP_BLUETOOTH:
1239 device = ACER_WMID3_GDS_BLUETOOTH;
1240 break;
1241 case ACER_CAP_THREEG:
1242 device = ACER_WMID3_GDS_THREEG;
1243 break;
1244 default:
1245 return AE_ERROR;
1246 }
1247 return wmid3_set_device_status(value, device);
1248
1249 } else {
1250 return set_u32(value, cap);
1251 }
1252}
1253
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001254/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001255 * Rfkill devices
1256 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001257static void acer_rfkill_update(struct work_struct *ignored);
1258static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1259static void acer_rfkill_update(struct work_struct *ignored)
1260{
1261 u32 state;
1262 acpi_status status;
1263
1264 status = get_u32(&state, ACER_CAP_WIRELESS);
1265 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001266 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001267
1268 if (has_cap(ACER_CAP_BLUETOOTH)) {
1269 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1270 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001271 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001272 }
1273
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001274 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1275 status = wmid3_get_device_status(&state,
1276 ACER_WMID3_GDS_THREEG);
1277 if (ACPI_SUCCESS(status))
1278 rfkill_set_sw_state(threeg_rfkill, !state);
1279 }
1280
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001281 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001282}
1283
Johannes Berg19d337d2009-06-02 13:01:37 +02001284static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001285{
1286 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001287 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001288
1289 if (rfkill_inited) {
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +08001290 status = set_device_status(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001291 if (ACPI_FAILURE(status))
1292 return -ENODEV;
1293 }
1294
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001295 return 0;
1296}
1297
Johannes Berg19d337d2009-06-02 13:01:37 +02001298static const struct rfkill_ops acer_rfkill_ops = {
1299 .set_block = acer_rfkill_set,
1300};
1301
1302static struct rfkill *acer_rfkill_register(struct device *dev,
1303 enum rfkill_type type,
1304 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001305{
1306 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001307 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001308 u32 state;
1309 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001310
Johannes Berg19d337d2009-06-02 13:01:37 +02001311 rfkill_dev = rfkill_alloc(name, dev, type,
1312 &acer_rfkill_ops,
1313 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001314 if (!rfkill_dev)
1315 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001316
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001317 status = get_device_status(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001318
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001319 err = rfkill_register(rfkill_dev);
1320 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001321 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001322 return ERR_PTR(err);
1323 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001324
1325 if (ACPI_SUCCESS(status))
1326 rfkill_set_sw_state(rfkill_dev, !state);
1327
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001328 return rfkill_dev;
1329}
1330
1331static int acer_rfkill_init(struct device *dev)
1332{
1333 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1334 "acer-wireless", ACER_CAP_WIRELESS);
1335 if (IS_ERR(wireless_rfkill))
1336 return PTR_ERR(wireless_rfkill);
1337
1338 if (has_cap(ACER_CAP_BLUETOOTH)) {
1339 bluetooth_rfkill = acer_rfkill_register(dev,
1340 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1341 ACER_CAP_BLUETOOTH);
1342 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001343 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001344 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001345 return PTR_ERR(bluetooth_rfkill);
1346 }
1347 }
1348
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001349 if (has_cap(ACER_CAP_THREEG)) {
1350 threeg_rfkill = acer_rfkill_register(dev,
1351 RFKILL_TYPE_WWAN, "acer-threeg",
1352 ACER_CAP_THREEG);
1353 if (IS_ERR(threeg_rfkill)) {
1354 rfkill_unregister(wireless_rfkill);
1355 rfkill_destroy(wireless_rfkill);
1356 rfkill_unregister(bluetooth_rfkill);
1357 rfkill_destroy(bluetooth_rfkill);
1358 return PTR_ERR(threeg_rfkill);
1359 }
1360 }
1361
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001362 rfkill_inited = true;
1363
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001364 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1365 schedule_delayed_work(&acer_rfkill_work,
1366 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001367
1368 return 0;
1369}
1370
1371static void acer_rfkill_exit(void)
1372{
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001373 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1374 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001375
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001376 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001377 rfkill_destroy(wireless_rfkill);
1378
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001379 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001380 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001381 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001382 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001383
1384 if (has_cap(ACER_CAP_THREEG)) {
1385 rfkill_unregister(threeg_rfkill);
1386 rfkill_destroy(threeg_rfkill);
1387 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001388 return;
1389}
1390
1391/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001392 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001393 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001394static ssize_t show_bool_threeg(struct device *dev,
1395 struct device_attribute *attr, char *buf)
1396{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001397 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001398 acpi_status status;
1399 if (wmi_has_guid(WMID_GUID3))
1400 status = wmid3_get_device_status(&result,
1401 ACER_WMID3_GDS_THREEG);
1402 else
1403 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001404 if (ACPI_SUCCESS(status))
1405 return sprintf(buf, "%u\n", result);
1406 return sprintf(buf, "Read error\n");
1407}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001408
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001409static ssize_t set_bool_threeg(struct device *dev,
1410 struct device_attribute *attr, const char *buf, size_t count)
1411{
1412 u32 tmp = simple_strtoul(buf, NULL, 10);
1413 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1414 if (ACPI_FAILURE(status))
1415 return -EINVAL;
1416 return count;
1417}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001418static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001419 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001420
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001421static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1422 char *buf)
1423{
1424 switch (interface->type) {
1425 case ACER_AMW0:
1426 return sprintf(buf, "AMW0\n");
1427 case ACER_AMW0_V2:
1428 return sprintf(buf, "AMW0 v2\n");
1429 case ACER_WMID:
1430 return sprintf(buf, "WMID\n");
1431 default:
1432 return sprintf(buf, "Error!\n");
1433 }
1434}
1435
Axel Lin370525d2010-06-30 10:20:23 +08001436static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001437
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001438static void acer_wmi_notify(u32 value, void *context)
1439{
1440 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1441 union acpi_object *obj;
1442 struct event_return_value return_value;
1443 acpi_status status;
1444
1445 status = wmi_get_event_data(value, &response);
1446 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001447 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001448 return;
1449 }
1450
1451 obj = (union acpi_object *)response.pointer;
1452
1453 if (!obj)
1454 return;
1455 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001456 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001457 kfree(obj);
1458 return;
1459 }
1460 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001461 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001462 kfree(obj);
1463 return;
1464 }
1465
1466 return_value = *((struct event_return_value *)obj->buffer.pointer);
1467 kfree(obj);
1468
1469 switch (return_value.function) {
1470 case WMID_HOTKEY_EVENT:
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001471 if (return_value.device_state) {
1472 u16 device_state = return_value.device_state;
Melchior FRANZ8ae68de2011-05-24 10:35:55 +02001473 pr_debug("device state: 0x%x\n", device_state);
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001474 if (has_cap(ACER_CAP_WIRELESS))
1475 rfkill_set_sw_state(wireless_rfkill,
1476 !(device_state & ACER_WMID3_GDS_WIRELESS));
1477 if (has_cap(ACER_CAP_BLUETOOTH))
1478 rfkill_set_sw_state(bluetooth_rfkill,
1479 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1480 if (has_cap(ACER_CAP_THREEG))
1481 rfkill_set_sw_state(threeg_rfkill,
1482 !(device_state & ACER_WMID3_GDS_THREEG));
1483 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001484 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1485 return_value.key_num, 1, true))
Joe Perches249c7202011-03-29 15:21:34 -07001486 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001487 return_value.key_num);
1488 break;
1489 default:
Joe Perches249c7202011-03-29 15:21:34 -07001490 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001491 return_value.function, return_value.key_num);
1492 break;
1493 }
1494}
1495
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001496static acpi_status
1497wmid3_set_lm_mode(struct lm_input_params *params,
1498 struct lm_return_value *return_value)
1499{
1500 acpi_status status;
1501 union acpi_object *obj;
1502
1503 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1504 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1505
1506 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1507 if (ACPI_FAILURE(status))
1508 return status;
1509
1510 obj = output.pointer;
1511
1512 if (!obj)
1513 return AE_ERROR;
1514 else if (obj->type != ACPI_TYPE_BUFFER) {
1515 kfree(obj);
1516 return AE_ERROR;
1517 }
1518 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001519 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001520 kfree(obj);
1521 return AE_ERROR;
1522 }
1523
1524 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1525 kfree(obj);
1526
1527 return status;
1528}
1529
1530static int acer_wmi_enable_ec_raw(void)
1531{
1532 struct lm_return_value return_value;
1533 acpi_status status;
1534 struct lm_input_params params = {
1535 .function_num = 0x1,
1536 .commun_devices = 0xFFFF,
1537 .devices = 0xFFFF,
1538 .lm_status = 0x00, /* Launch Manager Deactive */
1539 };
1540
1541 status = wmid3_set_lm_mode(&params, &return_value);
1542
1543 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001544 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1545 return_value.error_code,
1546 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001547 else
Joe Perches249c7202011-03-29 15:21:34 -07001548 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001549
1550 return status;
1551}
1552
1553static int acer_wmi_enable_lm(void)
1554{
1555 struct lm_return_value return_value;
1556 acpi_status status;
1557 struct lm_input_params params = {
1558 .function_num = 0x1,
1559 .commun_devices = 0xFFFF,
1560 .devices = 0xFFFF,
1561 .lm_status = 0x01, /* Launch Manager Active */
1562 };
1563
1564 status = wmid3_set_lm_mode(&params, &return_value);
1565
1566 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001567 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1568 return_value.error_code,
1569 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001570
1571 return status;
1572}
1573
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001574static int __init acer_wmi_input_setup(void)
1575{
1576 acpi_status status;
1577 int err;
1578
1579 acer_wmi_input_dev = input_allocate_device();
1580 if (!acer_wmi_input_dev)
1581 return -ENOMEM;
1582
1583 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1584 acer_wmi_input_dev->phys = "wmi/input0";
1585 acer_wmi_input_dev->id.bustype = BUS_HOST;
1586
1587 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1588 if (err)
1589 goto err_free_dev;
1590
1591 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1592 acer_wmi_notify, NULL);
1593 if (ACPI_FAILURE(status)) {
1594 err = -EIO;
1595 goto err_free_keymap;
1596 }
1597
1598 err = input_register_device(acer_wmi_input_dev);
1599 if (err)
1600 goto err_uninstall_notifier;
1601
1602 return 0;
1603
1604err_uninstall_notifier:
1605 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1606err_free_keymap:
1607 sparse_keymap_free(acer_wmi_input_dev);
1608err_free_dev:
1609 input_free_device(acer_wmi_input_dev);
1610 return err;
1611}
1612
1613static void acer_wmi_input_destroy(void)
1614{
1615 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1616 sparse_keymap_free(acer_wmi_input_dev);
1617 input_unregister_device(acer_wmi_input_dev);
1618}
1619
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001620/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001621 * debugfs functions
1622 */
1623static u32 get_wmid_devices(void)
1624{
1625 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1626 union acpi_object *obj;
1627 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001628 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001629
1630 status = wmi_query_block(WMID_GUID2, 1, &out);
1631 if (ACPI_FAILURE(status))
1632 return 0;
1633
1634 obj = (union acpi_object *) out.pointer;
1635 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a9312011-05-22 07:33:53 +08001636 (obj->buffer.length == sizeof(u32) ||
1637 obj->buffer.length == sizeof(u64))) {
Axel Lin66904862010-07-20 15:19:52 -07001638 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001639 }
Axel Lin66904862010-07-20 15:19:52 -07001640
1641 kfree(out.pointer);
1642 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001643}
1644
1645/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001646 * Platform device
1647 */
1648static int __devinit acer_platform_probe(struct platform_device *device)
1649{
1650 int err;
1651
1652 if (has_cap(ACER_CAP_MAILLED)) {
1653 err = acer_led_init(&device->dev);
1654 if (err)
1655 goto error_mailled;
1656 }
1657
1658 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1659 err = acer_backlight_init(&device->dev);
1660 if (err)
1661 goto error_brightness;
1662 }
1663
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001664 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001665 if (err)
1666 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001667
1668 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001669
Andy Whitcroft350e3292009-04-04 09:33:34 +01001670error_rfkill:
1671 if (has_cap(ACER_CAP_BRIGHTNESS))
1672 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001673error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001674 if (has_cap(ACER_CAP_MAILLED))
1675 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001676error_mailled:
1677 return err;
1678}
1679
1680static int acer_platform_remove(struct platform_device *device)
1681{
1682 if (has_cap(ACER_CAP_MAILLED))
1683 acer_led_exit();
1684 if (has_cap(ACER_CAP_BRIGHTNESS))
1685 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001686
1687 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001688 return 0;
1689}
1690
1691static int acer_platform_suspend(struct platform_device *dev,
1692pm_message_t state)
1693{
1694 u32 value;
1695 struct acer_data *data = &interface->data;
1696
1697 if (!data)
1698 return -ENOMEM;
1699
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001700 if (has_cap(ACER_CAP_MAILLED)) {
1701 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001702 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001703 data->mailled = value;
1704 }
1705
1706 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1707 get_u32(&value, ACER_CAP_BRIGHTNESS);
1708 data->brightness = value;
1709 }
1710
1711 return 0;
1712}
1713
1714static int acer_platform_resume(struct platform_device *device)
1715{
1716 struct acer_data *data = &interface->data;
1717
1718 if (!data)
1719 return -ENOMEM;
1720
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001721 if (has_cap(ACER_CAP_MAILLED))
1722 set_u32(data->mailled, ACER_CAP_MAILLED);
1723
1724 if (has_cap(ACER_CAP_BRIGHTNESS))
1725 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1726
1727 return 0;
1728}
1729
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001730static void acer_platform_shutdown(struct platform_device *device)
1731{
1732 struct acer_data *data = &interface->data;
1733
1734 if (!data)
1735 return;
1736
1737 if (has_cap(ACER_CAP_MAILLED))
1738 set_u32(LED_OFF, ACER_CAP_MAILLED);
1739}
1740
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001741static struct platform_driver acer_platform_driver = {
1742 .driver = {
1743 .name = "acer-wmi",
1744 .owner = THIS_MODULE,
1745 },
1746 .probe = acer_platform_probe,
1747 .remove = acer_platform_remove,
1748 .suspend = acer_platform_suspend,
1749 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001750 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001751};
1752
1753static struct platform_device *acer_platform_device;
1754
1755static int remove_sysfs(struct platform_device *device)
1756{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001757 if (has_cap(ACER_CAP_THREEG))
1758 device_remove_file(&device->dev, &dev_attr_threeg);
1759
1760 device_remove_file(&device->dev, &dev_attr_interface);
1761
1762 return 0;
1763}
1764
1765static int create_sysfs(void)
1766{
1767 int retval = -ENOMEM;
1768
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001769 if (has_cap(ACER_CAP_THREEG)) {
1770 retval = device_create_file(&acer_platform_device->dev,
1771 &dev_attr_threeg);
1772 if (retval)
1773 goto error_sysfs;
1774 }
1775
1776 retval = device_create_file(&acer_platform_device->dev,
1777 &dev_attr_interface);
1778 if (retval)
1779 goto error_sysfs;
1780
1781 return 0;
1782
1783error_sysfs:
1784 remove_sysfs(acer_platform_device);
1785 return retval;
1786}
1787
Carlos Corbacho81143522008-06-21 09:09:53 +01001788static void remove_debugfs(void)
1789{
1790 debugfs_remove(interface->debug.devices);
1791 debugfs_remove(interface->debug.root);
1792}
1793
1794static int create_debugfs(void)
1795{
1796 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1797 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001798 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001799 return -ENOMEM;
1800 }
1801
1802 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1803 interface->debug.root,
1804 &interface->debug.wmid_devices);
1805 if (!interface->debug.devices)
1806 goto error_debugfs;
1807
1808 return 0;
1809
1810error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001811 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001812 return -ENOMEM;
1813}
1814
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001815static int __init acer_wmi_init(void)
1816{
1817 int err;
1818
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001819 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001820
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001821 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001822 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001823 return -ENODEV;
1824 }
1825
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001826 find_quirks();
1827
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001828 /*
1829 * Detect which ACPI-WMI interface we're using.
1830 */
1831 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1832 interface = &AMW0_V2_interface;
1833
1834 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1835 interface = &wmid_interface;
1836
1837 if (wmi_has_guid(WMID_GUID2) && interface) {
1838 if (ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001839 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001840 return -ENODEV;
1841 }
1842 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001843 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001844 return -ENODEV;
1845 }
1846
1847 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1848 interface = &AMW0_interface;
1849
1850 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001851 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001852 return -ENODEV;
1853 }
1854 }
1855
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001856 if (wmi_has_guid(AMW0_GUID1))
1857 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001858
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001859 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001860 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001861 return -ENODEV;
1862 }
1863
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001864 set_quirks();
1865
Michael Spang1ba869e2009-03-12 14:31:34 -07001866 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001867 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001868 pr_info("Brightness must be controlled by "
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001869 "generic video driver\n");
1870 }
1871
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001872 if (wmi_has_guid(WMID_GUID3)) {
1873 if (ec_raw_mode) {
1874 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001875 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001876 return -ENODEV;
1877 }
1878 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001879 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001880 return -ENODEV;
1881 }
1882 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001883 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001884 }
1885
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001886 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1887 err = acer_wmi_input_setup();
1888 if (err)
1889 return err;
1890 }
1891
Axel Lin1c796322010-06-22 16:17:38 +08001892 err = platform_driver_register(&acer_platform_driver);
1893 if (err) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001894 pr_err("Unable to register platform driver.\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001895 goto error_platform_register;
1896 }
Axel Lin1c796322010-06-22 16:17:38 +08001897
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001898 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001899 if (!acer_platform_device) {
1900 err = -ENOMEM;
1901 goto error_device_alloc;
1902 }
1903
1904 err = platform_device_add(acer_platform_device);
1905 if (err)
1906 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001907
1908 err = create_sysfs();
1909 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001910 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001911
Carlos Corbacho81143522008-06-21 09:09:53 +01001912 if (wmi_has_guid(WMID_GUID2)) {
1913 interface->debug.wmid_devices = get_wmid_devices();
1914 err = create_debugfs();
1915 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001916 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001917 }
1918
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001919 /* Override any initial settings with values from the commandline */
1920 acer_commandline_init();
1921
1922 return 0;
1923
Axel Lin1c796322010-06-22 16:17:38 +08001924error_create_debugfs:
1925 remove_sysfs(acer_platform_device);
1926error_create_sys:
1927 platform_device_del(acer_platform_device);
1928error_device_add:
1929 platform_device_put(acer_platform_device);
1930error_device_alloc:
1931 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001932error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001933 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1934 acer_wmi_input_destroy();
1935
Axel Lin1c796322010-06-22 16:17:38 +08001936 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001937}
1938
1939static void __exit acer_wmi_exit(void)
1940{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001941 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1942 acer_wmi_input_destroy();
1943
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001944 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001945 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001946 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001947 platform_driver_unregister(&acer_platform_driver);
1948
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001949 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001950 return;
1951}
1952
1953module_init(acer_wmi_init);
1954module_exit(acer_wmi_exit);