blob: fa7153020ca11a5b2206dbb8548dbbc4cd2ae39a [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,
193};
194
195#define ACER_DEFAULT_WIRELESS 0
196#define ACER_DEFAULT_BLUETOOTH 0
197#define ACER_DEFAULT_MAILLED 0
198#define ACER_DEFAULT_THREEG 0
199
200static int max_brightness = 0xF;
201
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000202static int mailled = -1;
203static int brightness = -1;
204static int threeg = -1;
205static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500206static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800207static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000208
209module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000210module_param(brightness, int, 0444);
211module_param(threeg, int, 0444);
212module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500213module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000214MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
215MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
216MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
217MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500218MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000219
220struct acer_data {
221 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000222 int threeg;
223 int brightness;
224};
225
Carlos Corbacho81143522008-06-21 09:09:53 +0100226struct acer_debug {
227 struct dentry *root;
228 struct dentry *devices;
229 u32 wmid_devices;
230};
231
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100232static struct rfkill *wireless_rfkill;
233static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800234static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800235static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100236
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000237/* Each low-level interface must define at least some of the following */
238struct wmi_interface {
239 /* The WMI device type */
240 u32 type;
241
242 /* The capabilities this interface provides */
243 u32 capability;
244
245 /* Private data for the current interface */
246 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100247
248 /* debugfs entries associated with this interface */
249 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000250};
251
252/* The static interface pointer, points to the currently detected interface */
253static struct wmi_interface *interface;
254
255/*
256 * Embedded Controller quirks
257 * Some laptops require us to directly access the EC to either enable or query
258 * features that are not available through WMI.
259 */
260
261struct quirk_entry {
262 u8 wireless;
263 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100264 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000265 u8 bluetooth;
266};
267
268static struct quirk_entry *quirks;
269
270static void set_quirks(void)
271{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700272 if (!interface)
273 return;
274
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000275 if (quirks->mailled)
276 interface->capability |= ACER_CAP_MAILLED;
277
278 if (quirks->brightness)
279 interface->capability |= ACER_CAP_BRIGHTNESS;
280}
281
282static int dmi_matched(const struct dmi_system_id *dmi)
283{
284 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800285 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000286}
287
288static struct quirk_entry quirk_unknown = {
289};
290
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100291static struct quirk_entry quirk_acer_aspire_1520 = {
292 .brightness = -1,
293};
294
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000295static struct quirk_entry quirk_acer_travelmate_2490 = {
296 .mailled = 1,
297};
298
299/* This AMW0 laptop has no bluetooth */
300static struct quirk_entry quirk_medion_md_98300 = {
301 .wireless = 1,
302};
303
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100304static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
305 .wireless = 2,
306};
307
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100308/* The Aspire One has a dummy ACPI-WMI interface - disable it */
309static struct dmi_system_id __devinitdata acer_blacklist[] = {
310 {
311 .ident = "Acer Aspire One (SSD)",
312 .matches = {
313 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
314 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
315 },
316 },
317 {
318 .ident = "Acer Aspire One (HDD)",
319 .matches = {
320 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
321 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
322 },
323 },
324 {}
325};
326
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000327static struct dmi_system_id acer_quirks[] = {
328 {
329 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100330 .ident = "Acer Aspire 1360",
331 .matches = {
332 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
333 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
334 },
335 .driver_data = &quirk_acer_aspire_1520,
336 },
337 {
338 .callback = dmi_matched,
339 .ident = "Acer Aspire 1520",
340 .matches = {
341 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
342 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
343 },
344 .driver_data = &quirk_acer_aspire_1520,
345 },
346 {
347 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000348 .ident = "Acer Aspire 3100",
349 .matches = {
350 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
351 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
352 },
353 .driver_data = &quirk_acer_travelmate_2490,
354 },
355 {
356 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000357 .ident = "Acer Aspire 3610",
358 .matches = {
359 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
360 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
361 },
362 .driver_data = &quirk_acer_travelmate_2490,
363 },
364 {
365 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000366 .ident = "Acer Aspire 5100",
367 .matches = {
368 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
369 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
370 },
371 .driver_data = &quirk_acer_travelmate_2490,
372 },
373 {
374 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000375 .ident = "Acer Aspire 5610",
376 .matches = {
377 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
378 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
379 },
380 .driver_data = &quirk_acer_travelmate_2490,
381 },
382 {
383 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000384 .ident = "Acer Aspire 5630",
385 .matches = {
386 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
387 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
388 },
389 .driver_data = &quirk_acer_travelmate_2490,
390 },
391 {
392 .callback = dmi_matched,
393 .ident = "Acer Aspire 5650",
394 .matches = {
395 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
396 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
397 },
398 .driver_data = &quirk_acer_travelmate_2490,
399 },
400 {
401 .callback = dmi_matched,
402 .ident = "Acer Aspire 5680",
403 .matches = {
404 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
405 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
406 },
407 .driver_data = &quirk_acer_travelmate_2490,
408 },
409 {
410 .callback = dmi_matched,
411 .ident = "Acer Aspire 9110",
412 .matches = {
413 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
414 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
415 },
416 .driver_data = &quirk_acer_travelmate_2490,
417 },
418 {
419 .callback = dmi_matched,
420 .ident = "Acer TravelMate 2490",
421 .matches = {
422 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
423 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
424 },
425 .driver_data = &quirk_acer_travelmate_2490,
426 },
427 {
428 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000429 .ident = "Acer TravelMate 4200",
430 .matches = {
431 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
432 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
433 },
434 .driver_data = &quirk_acer_travelmate_2490,
435 },
436 {
437 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100438 .ident = "Fujitsu Siemens Amilo Li 1718",
439 .matches = {
440 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
441 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
442 },
443 .driver_data = &quirk_fujitsu_amilo_li_1718,
444 },
445 {
446 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000447 .ident = "Medion MD 98300",
448 .matches = {
449 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
450 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
451 },
452 .driver_data = &quirk_medion_md_98300,
453 },
454 {}
455};
456
457/* Find which quirks are needed for a particular vendor/ model pair */
458static void find_quirks(void)
459{
460 if (!force_series) {
461 dmi_check_system(acer_quirks);
462 } else if (force_series == 2490) {
463 quirks = &quirk_acer_travelmate_2490;
464 }
465
466 if (quirks == NULL)
467 quirks = &quirk_unknown;
468
469 set_quirks();
470}
471
472/*
473 * General interface convenience methods
474 */
475
476static bool has_cap(u32 cap)
477{
478 if ((interface->capability & cap) != 0)
479 return 1;
480
481 return 0;
482}
483
484/*
485 * AMW0 (V1) interface
486 */
487struct wmab_args {
488 u32 eax;
489 u32 ebx;
490 u32 ecx;
491 u32 edx;
492};
493
494struct wmab_ret {
495 u32 eax;
496 u32 ebx;
497 u32 ecx;
498 u32 edx;
499 u32 eex;
500};
501
502static acpi_status wmab_execute(struct wmab_args *regbuf,
503struct acpi_buffer *result)
504{
505 struct acpi_buffer input;
506 acpi_status status;
507 input.length = sizeof(struct wmab_args);
508 input.pointer = (u8 *)regbuf;
509
510 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
511
512 return status;
513}
514
515static acpi_status AMW0_get_u32(u32 *value, u32 cap,
516struct wmi_interface *iface)
517{
518 int err;
519 u8 result;
520
521 switch (cap) {
522 case ACER_CAP_MAILLED:
523 switch (quirks->mailled) {
524 default:
525 err = ec_read(0xA, &result);
526 if (err)
527 return AE_ERROR;
528 *value = (result >> 7) & 0x1;
529 return AE_OK;
530 }
531 break;
532 case ACER_CAP_WIRELESS:
533 switch (quirks->wireless) {
534 case 1:
535 err = ec_read(0x7B, &result);
536 if (err)
537 return AE_ERROR;
538 *value = result & 0x1;
539 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100540 case 2:
541 err = ec_read(0x71, &result);
542 if (err)
543 return AE_ERROR;
544 *value = result & 0x1;
545 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000546 default:
547 err = ec_read(0xA, &result);
548 if (err)
549 return AE_ERROR;
550 *value = (result >> 2) & 0x1;
551 return AE_OK;
552 }
553 break;
554 case ACER_CAP_BLUETOOTH:
555 switch (quirks->bluetooth) {
556 default:
557 err = ec_read(0xA, &result);
558 if (err)
559 return AE_ERROR;
560 *value = (result >> 4) & 0x1;
561 return AE_OK;
562 }
563 break;
564 case ACER_CAP_BRIGHTNESS:
565 switch (quirks->brightness) {
566 default:
567 err = ec_read(0x83, &result);
568 if (err)
569 return AE_ERROR;
570 *value = result;
571 return AE_OK;
572 }
573 break;
574 default:
Lin Ming08237972008-08-08 11:57:11 +0800575 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000576 }
577 return AE_OK;
578}
579
580static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
581{
582 struct wmab_args args;
583
584 args.eax = ACER_AMW0_WRITE;
585 args.ebx = value ? (1<<8) : 0;
586 args.ecx = args.edx = 0;
587
588 switch (cap) {
589 case ACER_CAP_MAILLED:
590 if (value > 1)
591 return AE_BAD_PARAMETER;
592 args.ebx |= ACER_AMW0_MAILLED_MASK;
593 break;
594 case ACER_CAP_WIRELESS:
595 if (value > 1)
596 return AE_BAD_PARAMETER;
597 args.ebx |= ACER_AMW0_WIRELESS_MASK;
598 break;
599 case ACER_CAP_BLUETOOTH:
600 if (value > 1)
601 return AE_BAD_PARAMETER;
602 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
603 break;
604 case ACER_CAP_BRIGHTNESS:
605 if (value > max_brightness)
606 return AE_BAD_PARAMETER;
607 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000608 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000609 return ec_write(0x83, value);
610 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000611 }
612 default:
Lin Ming08237972008-08-08 11:57:11 +0800613 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000614 }
615
616 /* Actually do the set */
617 return wmab_execute(&args, NULL);
618}
619
620static acpi_status AMW0_find_mailled(void)
621{
622 struct wmab_args args;
623 struct wmab_ret ret;
624 acpi_status status = AE_OK;
625 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
626 union acpi_object *obj;
627
628 args.eax = 0x86;
629 args.ebx = args.ecx = args.edx = 0;
630
631 status = wmab_execute(&args, &out);
632 if (ACPI_FAILURE(status))
633 return status;
634
635 obj = (union acpi_object *) out.pointer;
636 if (obj && obj->type == ACPI_TYPE_BUFFER &&
637 obj->buffer.length == sizeof(struct wmab_ret)) {
638 ret = *((struct wmab_ret *) obj->buffer.pointer);
639 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700640 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000641 return AE_ERROR;
642 }
643
644 if (ret.eex & 0x1)
645 interface->capability |= ACER_CAP_MAILLED;
646
647 kfree(out.pointer);
648
649 return AE_OK;
650}
651
652static acpi_status AMW0_set_capabilities(void)
653{
654 struct wmab_args args;
655 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700656 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000657 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
658 union acpi_object *obj;
659
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100660 /*
661 * On laptops with this strange GUID (non Acer), normal probing doesn't
662 * work.
663 */
664 if (wmi_has_guid(AMW0_GUID2)) {
665 interface->capability |= ACER_CAP_WIRELESS;
666 return AE_OK;
667 }
668
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000669 args.eax = ACER_AMW0_WRITE;
670 args.ecx = args.edx = 0;
671
672 args.ebx = 0xa2 << 8;
673 args.ebx |= ACER_AMW0_WIRELESS_MASK;
674
675 status = wmab_execute(&args, &out);
676 if (ACPI_FAILURE(status))
677 return status;
678
Axel Lin7677fbd2010-07-20 15:19:53 -0700679 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000680 if (obj && obj->type == ACPI_TYPE_BUFFER &&
681 obj->buffer.length == sizeof(struct wmab_ret)) {
682 ret = *((struct wmab_ret *) obj->buffer.pointer);
683 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700684 status = AE_ERROR;
685 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000686 }
687
688 if (ret.eax & 0x1)
689 interface->capability |= ACER_CAP_WIRELESS;
690
691 args.ebx = 2 << 8;
692 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
693
Axel Lin7677fbd2010-07-20 15:19:53 -0700694 /*
695 * It's ok to use existing buffer for next wmab_execute call.
696 * But we need to kfree(out.pointer) if next wmab_execute fail.
697 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000698 status = wmab_execute(&args, &out);
699 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700700 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000701
702 obj = (union acpi_object *) out.pointer;
703 if (obj && obj->type == ACPI_TYPE_BUFFER
704 && obj->buffer.length == sizeof(struct wmab_ret)) {
705 ret = *((struct wmab_ret *) obj->buffer.pointer);
706 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700707 status = AE_ERROR;
708 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000709 }
710
711 if (ret.eax & 0x1)
712 interface->capability |= ACER_CAP_BLUETOOTH;
713
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000714 /*
715 * This appears to be safe to enable, since all Wistron based laptops
716 * appear to use the same EC register for brightness, even if they
717 * differ for wireless, etc
718 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100719 if (quirks->brightness >= 0)
720 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000721
Axel Lin7677fbd2010-07-20 15:19:53 -0700722 status = AE_OK;
723out:
724 kfree(out.pointer);
725 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000726}
727
728static struct wmi_interface AMW0_interface = {
729 .type = ACER_AMW0,
730};
731
732static struct wmi_interface AMW0_V2_interface = {
733 .type = ACER_AMW0_V2,
734};
735
736/*
737 * New interface (The WMID interface)
738 */
739static acpi_status
740WMI_execute_u32(u32 method_id, u32 in, u32 *out)
741{
742 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
743 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
744 union acpi_object *obj;
745 u32 tmp;
746 acpi_status status;
747
748 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
749
750 if (ACPI_FAILURE(status))
751 return status;
752
753 obj = (union acpi_object *) result.pointer;
754 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a93162011-05-22 07:33:53 +0800755 (obj->buffer.length == sizeof(u32) ||
756 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000757 tmp = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +0800758 } else if (obj->type == ACPI_TYPE_INTEGER) {
759 tmp = (u32) obj->integer.value;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000760 } else {
761 tmp = 0;
762 }
763
764 if (out)
765 *out = tmp;
766
767 kfree(result.pointer);
768
769 return status;
770}
771
772static acpi_status WMID_get_u32(u32 *value, u32 cap,
773struct wmi_interface *iface)
774{
775 acpi_status status;
776 u8 tmp;
777 u32 result, method_id = 0;
778
779 switch (cap) {
780 case ACER_CAP_WIRELESS:
781 method_id = ACER_WMID_GET_WIRELESS_METHODID;
782 break;
783 case ACER_CAP_BLUETOOTH:
784 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
785 break;
786 case ACER_CAP_BRIGHTNESS:
787 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
788 break;
789 case ACER_CAP_THREEG:
790 method_id = ACER_WMID_GET_THREEG_METHODID;
791 break;
792 case ACER_CAP_MAILLED:
793 if (quirks->mailled == 1) {
794 ec_read(0x9f, &tmp);
795 *value = tmp & 0x1;
796 return 0;
797 }
798 default:
Lin Ming08237972008-08-08 11:57:11 +0800799 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000800 }
801 status = WMI_execute_u32(method_id, 0, &result);
802
803 if (ACPI_SUCCESS(status))
804 *value = (u8)result;
805
806 return status;
807}
808
809static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
810{
811 u32 method_id = 0;
812 char param;
813
814 switch (cap) {
815 case ACER_CAP_BRIGHTNESS:
816 if (value > max_brightness)
817 return AE_BAD_PARAMETER;
818 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
819 break;
820 case ACER_CAP_WIRELESS:
821 if (value > 1)
822 return AE_BAD_PARAMETER;
823 method_id = ACER_WMID_SET_WIRELESS_METHODID;
824 break;
825 case ACER_CAP_BLUETOOTH:
826 if (value > 1)
827 return AE_BAD_PARAMETER;
828 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
829 break;
830 case ACER_CAP_THREEG:
831 if (value > 1)
832 return AE_BAD_PARAMETER;
833 method_id = ACER_WMID_SET_THREEG_METHODID;
834 break;
835 case ACER_CAP_MAILLED:
836 if (value > 1)
837 return AE_BAD_PARAMETER;
838 if (quirks->mailled == 1) {
839 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700840 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000841 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700842 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000843 return 0;
844 }
845 break;
846 default:
Lin Ming08237972008-08-08 11:57:11 +0800847 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000848 }
849 return WMI_execute_u32(method_id, (u32)value, NULL);
850}
851
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800852static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
853{
854 struct hotkey_function_type_aa *type_aa;
855
856 /* We are looking for OEM-specific Type AAh */
857 if (header->type != 0xAA)
858 return;
859
860 has_type_aa = true;
861 type_aa = (struct hotkey_function_type_aa *) header;
862
Lee, Chun-Yicae15702011-03-16 18:52:36 +0800863 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800864 type_aa->commun_func_bitmap);
865
866 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
867 interface->capability |= ACER_CAP_WIRELESS;
868 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
869 interface->capability |= ACER_CAP_THREEG;
870 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
871 interface->capability |= ACER_CAP_BLUETOOTH;
872}
873
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000874static acpi_status WMID_set_capabilities(void)
875{
876 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
877 union acpi_object *obj;
878 acpi_status status;
879 u32 devices;
880
881 status = wmi_query_block(WMID_GUID2, 1, &out);
882 if (ACPI_FAILURE(status))
883 return status;
884
885 obj = (union acpi_object *) out.pointer;
886 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a93162011-05-22 07:33:53 +0800887 (obj->buffer.length == sizeof(u32) ||
888 obj->buffer.length == sizeof(u64))) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000889 devices = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +0800890 } else if (obj->type == ACPI_TYPE_INTEGER) {
891 devices = (u32) obj->integer.value;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000892 } else {
Axel Lin66904862010-07-20 15:19:52 -0700893 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000894 return AE_ERROR;
895 }
896
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800897 dmi_walk(type_aa_dmi_decode, NULL);
898 if (!has_type_aa) {
899 interface->capability |= ACER_CAP_WIRELESS;
Lee, Chun-Yia8d1a262011-05-22 07:33:52 +0800900 if (devices & 0x40)
901 interface->capability |= ACER_CAP_THREEG;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800902 if (devices & 0x10)
903 interface->capability |= ACER_CAP_BLUETOOTH;
904 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000905
906 /* WMID always provides brightness methods */
907 interface->capability |= ACER_CAP_BRIGHTNESS;
908
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000909 if (!(devices & 0x20))
910 max_brightness = 0x9;
911
Axel Lin66904862010-07-20 15:19:52 -0700912 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000913 return status;
914}
915
916static struct wmi_interface wmid_interface = {
917 .type = ACER_WMID,
918};
919
920/*
921 * Generic Device (interface-independent)
922 */
923
924static acpi_status get_u32(u32 *value, u32 cap)
925{
Lin Ming08237972008-08-08 11:57:11 +0800926 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000927
928 switch (interface->type) {
929 case ACER_AMW0:
930 status = AMW0_get_u32(value, cap, interface);
931 break;
932 case ACER_AMW0_V2:
933 if (cap == ACER_CAP_MAILLED) {
934 status = AMW0_get_u32(value, cap, interface);
935 break;
936 }
937 case ACER_WMID:
938 status = WMID_get_u32(value, cap, interface);
939 break;
940 }
941
942 return status;
943}
944
945static acpi_status set_u32(u32 value, u32 cap)
946{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100947 acpi_status status;
948
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000949 if (interface->capability & cap) {
950 switch (interface->type) {
951 case ACER_AMW0:
952 return AMW0_set_u32(value, cap, interface);
953 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100954 if (cap == ACER_CAP_MAILLED)
955 return AMW0_set_u32(value, cap, interface);
956
957 /*
958 * On some models, some WMID methods don't toggle
959 * properly. For those cases, we want to run the AMW0
960 * method afterwards to be certain we've really toggled
961 * the device state.
962 */
963 if (cap == ACER_CAP_WIRELESS ||
964 cap == ACER_CAP_BLUETOOTH) {
965 status = WMID_set_u32(value, cap, interface);
966 if (ACPI_FAILURE(status))
967 return status;
968
969 return AMW0_set_u32(value, cap, interface);
970 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000971 case ACER_WMID:
972 return WMID_set_u32(value, cap, interface);
973 default:
974 return AE_BAD_PARAMETER;
975 }
976 }
977 return AE_BAD_PARAMETER;
978}
979
980static void __init acer_commandline_init(void)
981{
982 /*
983 * These will all fail silently if the value given is invalid, or the
984 * capability isn't available on the given interface
985 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +0800986 if (mailled >= 0)
987 set_u32(mailled, ACER_CAP_MAILLED);
988 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800989 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +0800990 if (brightness >= 0)
991 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000992}
993
994/*
995 * LED device (Mail LED only, no other LEDs known yet)
996 */
997static void mail_led_set(struct led_classdev *led_cdev,
998enum led_brightness value)
999{
1000 set_u32(value, ACER_CAP_MAILLED);
1001}
1002
1003static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +00001004 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001005 .brightness_set = mail_led_set,
1006};
1007
Sam Ravnborg7560e382008-02-17 13:22:54 +01001008static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001009{
1010 return led_classdev_register(dev, &mail_led);
1011}
1012
1013static void acer_led_exit(void)
1014{
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001015 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001016 led_classdev_unregister(&mail_led);
1017}
1018
1019/*
1020 * Backlight device
1021 */
1022static struct backlight_device *acer_backlight_device;
1023
1024static int read_brightness(struct backlight_device *bd)
1025{
1026 u32 value;
1027 get_u32(&value, ACER_CAP_BRIGHTNESS);
1028 return value;
1029}
1030
1031static int update_bl_status(struct backlight_device *bd)
1032{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001033 int intensity = bd->props.brightness;
1034
1035 if (bd->props.power != FB_BLANK_UNBLANK)
1036 intensity = 0;
1037 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1038 intensity = 0;
1039
1040 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1041
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001042 return 0;
1043}
1044
Lionel Debrouxacc24722010-11-16 14:14:02 +01001045static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001046 .get_brightness = read_brightness,
1047 .update_status = update_bl_status,
1048};
1049
Sam Ravnborg7560e382008-02-17 13:22:54 +01001050static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001051{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001052 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001053 struct backlight_device *bd;
1054
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001055 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001056 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001057 props.max_brightness = max_brightness;
1058 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1059 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001060 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001061 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001062 acer_backlight_device = NULL;
1063 return PTR_ERR(bd);
1064 }
1065
1066 acer_backlight_device = bd;
1067
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001068 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001069 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001070 backlight_update_status(bd);
1071 return 0;
1072}
1073
Sam Ravnborg7560e382008-02-17 13:22:54 +01001074static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001075{
1076 backlight_device_unregister(acer_backlight_device);
1077}
1078
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001079static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1080{
1081 struct wmid3_gds_return_value return_value;
1082 acpi_status status;
1083 union acpi_object *obj;
1084 struct wmid3_gds_input_param params = {
1085 .function_num = 0x1,
1086 .hotkey_number = 0x01,
1087 .devices = device,
1088 };
1089 struct acpi_buffer input = {
1090 sizeof(struct wmid3_gds_input_param),
1091 &params
1092 };
1093 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1094
1095 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1096 if (ACPI_FAILURE(status))
1097 return status;
1098
1099 obj = output.pointer;
1100
1101 if (!obj)
1102 return AE_ERROR;
1103 else if (obj->type != ACPI_TYPE_BUFFER) {
1104 kfree(obj);
1105 return AE_ERROR;
1106 }
1107 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001108 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001109 kfree(obj);
1110 return AE_ERROR;
1111 }
1112
1113 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1114 kfree(obj);
1115
1116 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001117 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1118 return_value.error_code,
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001119 return_value.ec_return_value);
1120 else
1121 *value = !!(return_value.devices & device);
1122
1123 return status;
1124}
1125
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001126static acpi_status get_device_status(u32 *value, u32 cap)
1127{
1128 if (wmi_has_guid(WMID_GUID3)) {
1129 u16 device;
1130
1131 switch (cap) {
1132 case ACER_CAP_WIRELESS:
1133 device = ACER_WMID3_GDS_WIRELESS;
1134 break;
1135 case ACER_CAP_BLUETOOTH:
1136 device = ACER_WMID3_GDS_BLUETOOTH;
1137 break;
1138 case ACER_CAP_THREEG:
1139 device = ACER_WMID3_GDS_THREEG;
1140 break;
1141 default:
1142 return AE_ERROR;
1143 }
1144 return wmid3_get_device_status(value, device);
1145
1146 } else {
1147 return get_u32(value, cap);
1148 }
1149}
1150
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +08001151static acpi_status wmid3_set_device_status(u32 value, u16 device)
1152{
1153 struct wmid3_gds_return_value return_value;
1154 acpi_status status;
1155 union acpi_object *obj;
1156 u16 devices;
1157 struct wmid3_gds_input_param params = {
1158 .function_num = 0x1,
1159 .hotkey_number = 0x01,
Lee, Chun-Yiae821c12011-05-31 14:20:11 +08001160 .devices = ACER_WMID3_GDS_WIRELESS |
1161 ACER_WMID3_GDS_THREEG |
1162 ACER_WMID3_GDS_WIMAX |
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +08001163 ACER_WMID3_GDS_BLUETOOTH,
1164 };
1165 struct acpi_buffer input = {
1166 sizeof(struct wmid3_gds_input_param),
1167 &params
1168 };
1169 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1170 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1171
1172 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1173 if (ACPI_FAILURE(status))
1174 return status;
1175
1176 obj = output.pointer;
1177
1178 if (!obj)
1179 return AE_ERROR;
1180 else if (obj->type != ACPI_TYPE_BUFFER) {
1181 kfree(obj);
1182 return AE_ERROR;
1183 }
1184 if (obj->buffer.length != 8) {
1185 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1186 kfree(obj);
1187 return AE_ERROR;
1188 }
1189
1190 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1191 kfree(obj);
1192
1193 if (return_value.error_code || return_value.ec_return_value) {
1194 pr_warning("Get Current Device Status failed: "
1195 "0x%x - 0x%x\n", return_value.error_code,
1196 return_value.ec_return_value);
1197 return status;
1198 }
1199
1200 devices = return_value.devices;
1201 params.function_num = 0x2;
1202 params.hotkey_number = 0x01;
1203 params.devices = (value) ? (devices | device) : (devices & ~device);
1204
1205 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
1206 if (ACPI_FAILURE(status))
1207 return status;
1208
1209 obj = output2.pointer;
1210
1211 if (!obj)
1212 return AE_ERROR;
1213 else if (obj->type != ACPI_TYPE_BUFFER) {
1214 kfree(obj);
1215 return AE_ERROR;
1216 }
1217 if (obj->buffer.length != 4) {
1218 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1219 kfree(obj);
1220 return AE_ERROR;
1221 }
1222
1223 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1224 kfree(obj);
1225
1226 if (return_value.error_code || return_value.ec_return_value)
1227 pr_warning("Set Device Status failed: "
1228 "0x%x - 0x%x\n", return_value.error_code,
1229 return_value.ec_return_value);
1230
1231 return status;
1232}
1233
1234static acpi_status set_device_status(u32 value, u32 cap)
1235{
1236 if (wmi_has_guid(WMID_GUID3)) {
1237 u16 device;
1238
1239 switch (cap) {
1240 case ACER_CAP_WIRELESS:
1241 device = ACER_WMID3_GDS_WIRELESS;
1242 break;
1243 case ACER_CAP_BLUETOOTH:
1244 device = ACER_WMID3_GDS_BLUETOOTH;
1245 break;
1246 case ACER_CAP_THREEG:
1247 device = ACER_WMID3_GDS_THREEG;
1248 break;
1249 default:
1250 return AE_ERROR;
1251 }
1252 return wmid3_set_device_status(value, device);
1253
1254 } else {
1255 return set_u32(value, cap);
1256 }
1257}
1258
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001259/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001260 * Rfkill devices
1261 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001262static void acer_rfkill_update(struct work_struct *ignored);
1263static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1264static void acer_rfkill_update(struct work_struct *ignored)
1265{
1266 u32 state;
1267 acpi_status status;
1268
1269 status = get_u32(&state, ACER_CAP_WIRELESS);
1270 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001271 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001272
1273 if (has_cap(ACER_CAP_BLUETOOTH)) {
1274 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1275 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001276 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001277 }
1278
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001279 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1280 status = wmid3_get_device_status(&state,
1281 ACER_WMID3_GDS_THREEG);
1282 if (ACPI_SUCCESS(status))
1283 rfkill_set_sw_state(threeg_rfkill, !state);
1284 }
1285
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001286 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001287}
1288
Johannes Berg19d337d2009-06-02 13:01:37 +02001289static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001290{
1291 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001292 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001293
1294 if (rfkill_inited) {
Lee, Chun-Yi6d88ff02011-05-22 07:33:54 +08001295 status = set_device_status(!blocked, cap);
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001296 if (ACPI_FAILURE(status))
1297 return -ENODEV;
1298 }
1299
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001300 return 0;
1301}
1302
Johannes Berg19d337d2009-06-02 13:01:37 +02001303static const struct rfkill_ops acer_rfkill_ops = {
1304 .set_block = acer_rfkill_set,
1305};
1306
1307static struct rfkill *acer_rfkill_register(struct device *dev,
1308 enum rfkill_type type,
1309 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001310{
1311 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001312 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001313 u32 state;
1314 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001315
Johannes Berg19d337d2009-06-02 13:01:37 +02001316 rfkill_dev = rfkill_alloc(name, dev, type,
1317 &acer_rfkill_ops,
1318 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001319 if (!rfkill_dev)
1320 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001321
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001322 status = get_device_status(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001323
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001324 err = rfkill_register(rfkill_dev);
1325 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001326 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001327 return ERR_PTR(err);
1328 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001329
1330 if (ACPI_SUCCESS(status))
1331 rfkill_set_sw_state(rfkill_dev, !state);
1332
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001333 return rfkill_dev;
1334}
1335
1336static int acer_rfkill_init(struct device *dev)
1337{
1338 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1339 "acer-wireless", ACER_CAP_WIRELESS);
1340 if (IS_ERR(wireless_rfkill))
1341 return PTR_ERR(wireless_rfkill);
1342
1343 if (has_cap(ACER_CAP_BLUETOOTH)) {
1344 bluetooth_rfkill = acer_rfkill_register(dev,
1345 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1346 ACER_CAP_BLUETOOTH);
1347 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001348 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001349 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001350 return PTR_ERR(bluetooth_rfkill);
1351 }
1352 }
1353
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001354 if (has_cap(ACER_CAP_THREEG)) {
1355 threeg_rfkill = acer_rfkill_register(dev,
1356 RFKILL_TYPE_WWAN, "acer-threeg",
1357 ACER_CAP_THREEG);
1358 if (IS_ERR(threeg_rfkill)) {
1359 rfkill_unregister(wireless_rfkill);
1360 rfkill_destroy(wireless_rfkill);
1361 rfkill_unregister(bluetooth_rfkill);
1362 rfkill_destroy(bluetooth_rfkill);
1363 return PTR_ERR(threeg_rfkill);
1364 }
1365 }
1366
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001367 rfkill_inited = true;
1368
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001369 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1370 schedule_delayed_work(&acer_rfkill_work,
1371 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001372
1373 return 0;
1374}
1375
1376static void acer_rfkill_exit(void)
1377{
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001378 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1379 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001380
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001381 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001382 rfkill_destroy(wireless_rfkill);
1383
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001384 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001385 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001386 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001387 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001388
1389 if (has_cap(ACER_CAP_THREEG)) {
1390 rfkill_unregister(threeg_rfkill);
1391 rfkill_destroy(threeg_rfkill);
1392 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001393 return;
1394}
1395
1396/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001397 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001398 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001399static ssize_t show_bool_threeg(struct device *dev,
1400 struct device_attribute *attr, char *buf)
1401{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001402 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001403 acpi_status status;
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001404
1405 pr_info("This threeg sysfs will be removed in 2012"
1406 " - used by: %s\n", current->comm);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001407 if (wmi_has_guid(WMID_GUID3))
1408 status = wmid3_get_device_status(&result,
1409 ACER_WMID3_GDS_THREEG);
1410 else
1411 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001412 if (ACPI_SUCCESS(status))
1413 return sprintf(buf, "%u\n", result);
1414 return sprintf(buf, "Read error\n");
1415}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001416
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001417static ssize_t set_bool_threeg(struct device *dev,
1418 struct device_attribute *attr, const char *buf, size_t count)
1419{
1420 u32 tmp = simple_strtoul(buf, NULL, 10);
1421 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001422 pr_info("This threeg sysfs will be removed in 2012"
1423 " - used by: %s\n", current->comm);
1424 if (ACPI_FAILURE(status))
1425 return -EINVAL;
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001426 return count;
1427}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001428static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001429 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001430
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001431static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1432 char *buf)
1433{
Lee, Chun-Yi7b8aca62011-05-31 14:52:22 +08001434 pr_info("This interface sysfs will be removed in 2012"
1435 " - used by: %s\n", current->comm);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001436 switch (interface->type) {
1437 case ACER_AMW0:
1438 return sprintf(buf, "AMW0\n");
1439 case ACER_AMW0_V2:
1440 return sprintf(buf, "AMW0 v2\n");
1441 case ACER_WMID:
1442 return sprintf(buf, "WMID\n");
1443 default:
1444 return sprintf(buf, "Error!\n");
1445 }
1446}
1447
Axel Lin370525d2010-06-30 10:20:23 +08001448static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001449
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001450static void acer_wmi_notify(u32 value, void *context)
1451{
1452 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1453 union acpi_object *obj;
1454 struct event_return_value return_value;
1455 acpi_status status;
Seth Forshee92530662011-06-21 12:00:33 -05001456 u16 device_state;
1457 const struct key_entry *key;
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001458
1459 status = wmi_get_event_data(value, &response);
1460 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001461 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001462 return;
1463 }
1464
1465 obj = (union acpi_object *)response.pointer;
1466
1467 if (!obj)
1468 return;
1469 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001470 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001471 kfree(obj);
1472 return;
1473 }
1474 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001475 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001476 kfree(obj);
1477 return;
1478 }
1479
1480 return_value = *((struct event_return_value *)obj->buffer.pointer);
1481 kfree(obj);
1482
1483 switch (return_value.function) {
1484 case WMID_HOTKEY_EVENT:
Seth Forshee92530662011-06-21 12:00:33 -05001485 device_state = return_value.device_state;
1486 pr_debug("device state: 0x%x\n", device_state);
1487
1488 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1489 return_value.key_num);
1490 if (!key) {
Joe Perches249c7202011-03-29 15:21:34 -07001491 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001492 return_value.key_num);
Seth Forshee92530662011-06-21 12:00:33 -05001493 } else {
1494 switch (key->keycode) {
1495 case KEY_WLAN:
1496 case KEY_BLUETOOTH:
1497 if (has_cap(ACER_CAP_WIRELESS))
1498 rfkill_set_sw_state(wireless_rfkill,
1499 !(device_state & ACER_WMID3_GDS_WIRELESS));
1500 if (has_cap(ACER_CAP_THREEG))
1501 rfkill_set_sw_state(threeg_rfkill,
1502 !(device_state & ACER_WMID3_GDS_THREEG));
1503 if (has_cap(ACER_CAP_BLUETOOTH))
1504 rfkill_set_sw_state(bluetooth_rfkill,
1505 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1506 break;
1507 }
1508 sparse_keymap_report_entry(acer_wmi_input_dev, key,
1509 1, true);
1510 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001511 break;
1512 default:
Joe Perches249c7202011-03-29 15:21:34 -07001513 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001514 return_value.function, return_value.key_num);
1515 break;
1516 }
1517}
1518
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001519static acpi_status
1520wmid3_set_lm_mode(struct lm_input_params *params,
1521 struct lm_return_value *return_value)
1522{
1523 acpi_status status;
1524 union acpi_object *obj;
1525
1526 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1527 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1528
1529 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1530 if (ACPI_FAILURE(status))
1531 return status;
1532
1533 obj = output.pointer;
1534
1535 if (!obj)
1536 return AE_ERROR;
1537 else if (obj->type != ACPI_TYPE_BUFFER) {
1538 kfree(obj);
1539 return AE_ERROR;
1540 }
1541 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001542 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001543 kfree(obj);
1544 return AE_ERROR;
1545 }
1546
1547 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1548 kfree(obj);
1549
1550 return status;
1551}
1552
1553static int acer_wmi_enable_ec_raw(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 = 0x00, /* Launch Manager Deactive */
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 EC raw mode 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 else
Joe Perches249c7202011-03-29 15:21:34 -07001571 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001572
1573 return status;
1574}
1575
1576static int acer_wmi_enable_lm(void)
1577{
1578 struct lm_return_value return_value;
1579 acpi_status status;
1580 struct lm_input_params params = {
1581 .function_num = 0x1,
1582 .commun_devices = 0xFFFF,
1583 .devices = 0xFFFF,
1584 .lm_status = 0x01, /* Launch Manager Active */
1585 };
1586
1587 status = wmid3_set_lm_mode(&params, &return_value);
1588
1589 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001590 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1591 return_value.error_code,
1592 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001593
1594 return status;
1595}
1596
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001597static int __init acer_wmi_input_setup(void)
1598{
1599 acpi_status status;
1600 int err;
1601
1602 acer_wmi_input_dev = input_allocate_device();
1603 if (!acer_wmi_input_dev)
1604 return -ENOMEM;
1605
1606 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1607 acer_wmi_input_dev->phys = "wmi/input0";
1608 acer_wmi_input_dev->id.bustype = BUS_HOST;
1609
1610 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1611 if (err)
1612 goto err_free_dev;
1613
1614 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1615 acer_wmi_notify, NULL);
1616 if (ACPI_FAILURE(status)) {
1617 err = -EIO;
1618 goto err_free_keymap;
1619 }
1620
1621 err = input_register_device(acer_wmi_input_dev);
1622 if (err)
1623 goto err_uninstall_notifier;
1624
1625 return 0;
1626
1627err_uninstall_notifier:
1628 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1629err_free_keymap:
1630 sparse_keymap_free(acer_wmi_input_dev);
1631err_free_dev:
1632 input_free_device(acer_wmi_input_dev);
1633 return err;
1634}
1635
1636static void acer_wmi_input_destroy(void)
1637{
1638 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1639 sparse_keymap_free(acer_wmi_input_dev);
1640 input_unregister_device(acer_wmi_input_dev);
1641}
1642
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001643/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001644 * debugfs functions
1645 */
1646static u32 get_wmid_devices(void)
1647{
1648 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1649 union acpi_object *obj;
1650 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001651 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001652
1653 status = wmi_query_block(WMID_GUID2, 1, &out);
1654 if (ACPI_FAILURE(status))
1655 return 0;
1656
1657 obj = (union acpi_object *) out.pointer;
1658 if (obj && obj->type == ACPI_TYPE_BUFFER &&
Lee, Chun-Yiab6a93162011-05-22 07:33:53 +08001659 (obj->buffer.length == sizeof(u32) ||
1660 obj->buffer.length == sizeof(u64))) {
Axel Lin66904862010-07-20 15:19:52 -07001661 devices = *((u32 *) obj->buffer.pointer);
Lee, Chun-Yi987dfba2011-05-27 14:52:14 +08001662 } else if (obj->type == ACPI_TYPE_INTEGER) {
1663 devices = (u32) obj->integer.value;
Carlos Corbacho81143522008-06-21 09:09:53 +01001664 }
Axel Lin66904862010-07-20 15:19:52 -07001665
1666 kfree(out.pointer);
1667 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001668}
1669
1670/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001671 * Platform device
1672 */
1673static int __devinit acer_platform_probe(struct platform_device *device)
1674{
1675 int err;
1676
1677 if (has_cap(ACER_CAP_MAILLED)) {
1678 err = acer_led_init(&device->dev);
1679 if (err)
1680 goto error_mailled;
1681 }
1682
1683 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1684 err = acer_backlight_init(&device->dev);
1685 if (err)
1686 goto error_brightness;
1687 }
1688
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001689 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001690 if (err)
1691 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001692
1693 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001694
Andy Whitcroft350e3292009-04-04 09:33:34 +01001695error_rfkill:
1696 if (has_cap(ACER_CAP_BRIGHTNESS))
1697 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001698error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001699 if (has_cap(ACER_CAP_MAILLED))
1700 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001701error_mailled:
1702 return err;
1703}
1704
1705static int acer_platform_remove(struct platform_device *device)
1706{
1707 if (has_cap(ACER_CAP_MAILLED))
1708 acer_led_exit();
1709 if (has_cap(ACER_CAP_BRIGHTNESS))
1710 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001711
1712 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001713 return 0;
1714}
1715
1716static int acer_platform_suspend(struct platform_device *dev,
1717pm_message_t state)
1718{
1719 u32 value;
1720 struct acer_data *data = &interface->data;
1721
1722 if (!data)
1723 return -ENOMEM;
1724
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001725 if (has_cap(ACER_CAP_MAILLED)) {
1726 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001727 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001728 data->mailled = value;
1729 }
1730
1731 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1732 get_u32(&value, ACER_CAP_BRIGHTNESS);
1733 data->brightness = value;
1734 }
1735
1736 return 0;
1737}
1738
1739static int acer_platform_resume(struct platform_device *device)
1740{
1741 struct acer_data *data = &interface->data;
1742
1743 if (!data)
1744 return -ENOMEM;
1745
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001746 if (has_cap(ACER_CAP_MAILLED))
1747 set_u32(data->mailled, ACER_CAP_MAILLED);
1748
1749 if (has_cap(ACER_CAP_BRIGHTNESS))
1750 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1751
1752 return 0;
1753}
1754
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001755static void acer_platform_shutdown(struct platform_device *device)
1756{
1757 struct acer_data *data = &interface->data;
1758
1759 if (!data)
1760 return;
1761
1762 if (has_cap(ACER_CAP_MAILLED))
1763 set_u32(LED_OFF, ACER_CAP_MAILLED);
1764}
1765
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001766static struct platform_driver acer_platform_driver = {
1767 .driver = {
1768 .name = "acer-wmi",
1769 .owner = THIS_MODULE,
1770 },
1771 .probe = acer_platform_probe,
1772 .remove = acer_platform_remove,
1773 .suspend = acer_platform_suspend,
1774 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001775 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001776};
1777
1778static struct platform_device *acer_platform_device;
1779
1780static int remove_sysfs(struct platform_device *device)
1781{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001782 if (has_cap(ACER_CAP_THREEG))
1783 device_remove_file(&device->dev, &dev_attr_threeg);
1784
1785 device_remove_file(&device->dev, &dev_attr_interface);
1786
1787 return 0;
1788}
1789
1790static int create_sysfs(void)
1791{
1792 int retval = -ENOMEM;
1793
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001794 if (has_cap(ACER_CAP_THREEG)) {
1795 retval = device_create_file(&acer_platform_device->dev,
1796 &dev_attr_threeg);
1797 if (retval)
1798 goto error_sysfs;
1799 }
1800
1801 retval = device_create_file(&acer_platform_device->dev,
1802 &dev_attr_interface);
1803 if (retval)
1804 goto error_sysfs;
1805
1806 return 0;
1807
1808error_sysfs:
1809 remove_sysfs(acer_platform_device);
1810 return retval;
1811}
1812
Carlos Corbacho81143522008-06-21 09:09:53 +01001813static void remove_debugfs(void)
1814{
1815 debugfs_remove(interface->debug.devices);
1816 debugfs_remove(interface->debug.root);
1817}
1818
1819static int create_debugfs(void)
1820{
1821 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1822 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001823 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001824 return -ENOMEM;
1825 }
1826
1827 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1828 interface->debug.root,
1829 &interface->debug.wmid_devices);
1830 if (!interface->debug.devices)
1831 goto error_debugfs;
1832
1833 return 0;
1834
1835error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001836 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001837 return -ENOMEM;
1838}
1839
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001840static int __init acer_wmi_init(void)
1841{
1842 int err;
1843
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001844 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001845
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001846 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001847 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001848 return -ENODEV;
1849 }
1850
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001851 find_quirks();
1852
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001853 /*
1854 * Detect which ACPI-WMI interface we're using.
1855 */
1856 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1857 interface = &AMW0_V2_interface;
1858
1859 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1860 interface = &wmid_interface;
1861
1862 if (wmi_has_guid(WMID_GUID2) && interface) {
1863 if (ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001864 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001865 return -ENODEV;
1866 }
1867 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001868 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001869 return -ENODEV;
1870 }
1871
1872 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1873 interface = &AMW0_interface;
1874
1875 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001876 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001877 return -ENODEV;
1878 }
1879 }
1880
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001881 if (wmi_has_guid(AMW0_GUID1))
1882 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001883
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001884 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001885 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001886 return -ENODEV;
1887 }
1888
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001889 set_quirks();
1890
Michael Spang1ba869e2009-03-12 14:31:34 -07001891 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001892 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001893 pr_info("Brightness must be controlled by "
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001894 "generic video driver\n");
1895 }
1896
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001897 if (wmi_has_guid(WMID_GUID3)) {
1898 if (ec_raw_mode) {
1899 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001900 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001901 return -ENODEV;
1902 }
1903 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001904 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001905 return -ENODEV;
1906 }
1907 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001908 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001909 }
1910
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001911 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1912 err = acer_wmi_input_setup();
1913 if (err)
1914 return err;
1915 }
1916
Axel Lin1c796322010-06-22 16:17:38 +08001917 err = platform_driver_register(&acer_platform_driver);
1918 if (err) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001919 pr_err("Unable to register platform driver.\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001920 goto error_platform_register;
1921 }
Axel Lin1c796322010-06-22 16:17:38 +08001922
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001923 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001924 if (!acer_platform_device) {
1925 err = -ENOMEM;
1926 goto error_device_alloc;
1927 }
1928
1929 err = platform_device_add(acer_platform_device);
1930 if (err)
1931 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001932
1933 err = create_sysfs();
1934 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001935 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001936
Carlos Corbacho81143522008-06-21 09:09:53 +01001937 if (wmi_has_guid(WMID_GUID2)) {
1938 interface->debug.wmid_devices = get_wmid_devices();
1939 err = create_debugfs();
1940 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001941 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001942 }
1943
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001944 /* Override any initial settings with values from the commandline */
1945 acer_commandline_init();
1946
1947 return 0;
1948
Axel Lin1c796322010-06-22 16:17:38 +08001949error_create_debugfs:
1950 remove_sysfs(acer_platform_device);
1951error_create_sys:
1952 platform_device_del(acer_platform_device);
1953error_device_add:
1954 platform_device_put(acer_platform_device);
1955error_device_alloc:
1956 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001957error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001958 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1959 acer_wmi_input_destroy();
1960
Axel Lin1c796322010-06-22 16:17:38 +08001961 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001962}
1963
1964static void __exit acer_wmi_exit(void)
1965{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001966 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1967 acer_wmi_input_destroy();
1968
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001969 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001970 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001971 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001972 platform_driver_unregister(&acer_platform_driver);
1973
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001974 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001975 return;
1976}
1977
1978module_init(acer_wmi_init);
1979module_exit(acer_wmi_exit);