blob: 0682ecb30746e3f117747ab0e894b853bd4809b4 [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 */
101 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
102 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
103 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
104 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
105 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
106 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Lee, Chun-Yi89411782011-03-02 01:07:11 +0800107 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800108 {KE_END, 0}
109};
110
111static struct input_dev *acer_wmi_input_dev;
112
113struct event_return_value {
114 u8 function;
115 u8 key_num;
116 u16 device_state;
117 u32 reserved;
118} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000119
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000120/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800121 * GUID3 Get Device Status device flags
122 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800123#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800124#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800125#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800126
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500127struct lm_input_params {
128 u8 function_num; /* Function Number */
129 u16 commun_devices; /* Communication type devices default status */
130 u16 devices; /* Other type devices default status */
131 u8 lm_status; /* Launch Manager Status */
132 u16 reserved;
133} __attribute__((packed));
134
135struct lm_return_value {
136 u8 error_code; /* Error Code */
137 u8 ec_return_value; /* EC Return Value */
138 u16 reserved;
139} __attribute__((packed));
140
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800141struct wmid3_gds_input_param { /* Get Device Status input parameter */
142 u8 function_num; /* Function Number */
143 u8 hotkey_number; /* Hotkey Number */
144 u16 devices; /* Get Device */
145} __attribute__((packed));
146
147struct wmid3_gds_return_value { /* Get Device Status return value*/
148 u8 error_code; /* Error Code */
149 u8 ec_return_value; /* EC Return Value */
150 u16 devices; /* Current Device Status */
151 u32 reserved;
152} __attribute__((packed));
153
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800154struct hotkey_function_type_aa {
155 u8 type;
156 u8 length;
157 u16 handle;
158 u16 commun_func_bitmap;
159} __attribute__((packed));
160
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800161/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000162 * Interface capability flags
163 */
164#define ACER_CAP_MAILLED (1<<0)
165#define ACER_CAP_WIRELESS (1<<1)
166#define ACER_CAP_BLUETOOTH (1<<2)
167#define ACER_CAP_BRIGHTNESS (1<<3)
168#define ACER_CAP_THREEG (1<<4)
169#define ACER_CAP_ANY (0xFFFFFFFF)
170
171/*
172 * Interface type flags
173 */
174enum interface_flags {
175 ACER_AMW0,
176 ACER_AMW0_V2,
177 ACER_WMID,
178};
179
180#define ACER_DEFAULT_WIRELESS 0
181#define ACER_DEFAULT_BLUETOOTH 0
182#define ACER_DEFAULT_MAILLED 0
183#define ACER_DEFAULT_THREEG 0
184
185static int max_brightness = 0xF;
186
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000187static int mailled = -1;
188static int brightness = -1;
189static int threeg = -1;
190static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500191static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800192static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000193
194module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000195module_param(brightness, int, 0444);
196module_param(threeg, int, 0444);
197module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500198module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000199MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
200MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
201MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
202MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500203MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000204
205struct acer_data {
206 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000207 int threeg;
208 int brightness;
209};
210
Carlos Corbacho81143522008-06-21 09:09:53 +0100211struct acer_debug {
212 struct dentry *root;
213 struct dentry *devices;
214 u32 wmid_devices;
215};
216
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100217static struct rfkill *wireless_rfkill;
218static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800219static struct rfkill *threeg_rfkill;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +0800220static bool rfkill_inited;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100221
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000222/* Each low-level interface must define at least some of the following */
223struct wmi_interface {
224 /* The WMI device type */
225 u32 type;
226
227 /* The capabilities this interface provides */
228 u32 capability;
229
230 /* Private data for the current interface */
231 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100232
233 /* debugfs entries associated with this interface */
234 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000235};
236
237/* The static interface pointer, points to the currently detected interface */
238static struct wmi_interface *interface;
239
240/*
241 * Embedded Controller quirks
242 * Some laptops require us to directly access the EC to either enable or query
243 * features that are not available through WMI.
244 */
245
246struct quirk_entry {
247 u8 wireless;
248 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100249 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000250 u8 bluetooth;
251};
252
253static struct quirk_entry *quirks;
254
255static void set_quirks(void)
256{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700257 if (!interface)
258 return;
259
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000260 if (quirks->mailled)
261 interface->capability |= ACER_CAP_MAILLED;
262
263 if (quirks->brightness)
264 interface->capability |= ACER_CAP_BRIGHTNESS;
265}
266
267static int dmi_matched(const struct dmi_system_id *dmi)
268{
269 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800270 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000271}
272
273static struct quirk_entry quirk_unknown = {
274};
275
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100276static struct quirk_entry quirk_acer_aspire_1520 = {
277 .brightness = -1,
278};
279
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000280static struct quirk_entry quirk_acer_travelmate_2490 = {
281 .mailled = 1,
282};
283
284/* This AMW0 laptop has no bluetooth */
285static struct quirk_entry quirk_medion_md_98300 = {
286 .wireless = 1,
287};
288
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100289static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
290 .wireless = 2,
291};
292
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100293/* The Aspire One has a dummy ACPI-WMI interface - disable it */
294static struct dmi_system_id __devinitdata acer_blacklist[] = {
295 {
296 .ident = "Acer Aspire One (SSD)",
297 .matches = {
298 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
299 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
300 },
301 },
302 {
303 .ident = "Acer Aspire One (HDD)",
304 .matches = {
305 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
306 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
307 },
308 },
309 {}
310};
311
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000312static struct dmi_system_id acer_quirks[] = {
313 {
314 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100315 .ident = "Acer Aspire 1360",
316 .matches = {
317 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
318 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
319 },
320 .driver_data = &quirk_acer_aspire_1520,
321 },
322 {
323 .callback = dmi_matched,
324 .ident = "Acer Aspire 1520",
325 .matches = {
326 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
327 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
328 },
329 .driver_data = &quirk_acer_aspire_1520,
330 },
331 {
332 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000333 .ident = "Acer Aspire 3100",
334 .matches = {
335 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
336 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
337 },
338 .driver_data = &quirk_acer_travelmate_2490,
339 },
340 {
341 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000342 .ident = "Acer Aspire 3610",
343 .matches = {
344 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
345 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
346 },
347 .driver_data = &quirk_acer_travelmate_2490,
348 },
349 {
350 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000351 .ident = "Acer Aspire 5100",
352 .matches = {
353 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
354 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
355 },
356 .driver_data = &quirk_acer_travelmate_2490,
357 },
358 {
359 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000360 .ident = "Acer Aspire 5610",
361 .matches = {
362 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
363 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
364 },
365 .driver_data = &quirk_acer_travelmate_2490,
366 },
367 {
368 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000369 .ident = "Acer Aspire 5630",
370 .matches = {
371 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
372 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
373 },
374 .driver_data = &quirk_acer_travelmate_2490,
375 },
376 {
377 .callback = dmi_matched,
378 .ident = "Acer Aspire 5650",
379 .matches = {
380 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
381 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
382 },
383 .driver_data = &quirk_acer_travelmate_2490,
384 },
385 {
386 .callback = dmi_matched,
387 .ident = "Acer Aspire 5680",
388 .matches = {
389 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
390 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
391 },
392 .driver_data = &quirk_acer_travelmate_2490,
393 },
394 {
395 .callback = dmi_matched,
396 .ident = "Acer Aspire 9110",
397 .matches = {
398 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
399 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
400 },
401 .driver_data = &quirk_acer_travelmate_2490,
402 },
403 {
404 .callback = dmi_matched,
405 .ident = "Acer TravelMate 2490",
406 .matches = {
407 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
408 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
409 },
410 .driver_data = &quirk_acer_travelmate_2490,
411 },
412 {
413 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000414 .ident = "Acer TravelMate 4200",
415 .matches = {
416 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
417 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
418 },
419 .driver_data = &quirk_acer_travelmate_2490,
420 },
421 {
422 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100423 .ident = "Fujitsu Siemens Amilo Li 1718",
424 .matches = {
425 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
426 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
427 },
428 .driver_data = &quirk_fujitsu_amilo_li_1718,
429 },
430 {
431 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000432 .ident = "Medion MD 98300",
433 .matches = {
434 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
435 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
436 },
437 .driver_data = &quirk_medion_md_98300,
438 },
439 {}
440};
441
442/* Find which quirks are needed for a particular vendor/ model pair */
443static void find_quirks(void)
444{
445 if (!force_series) {
446 dmi_check_system(acer_quirks);
447 } else if (force_series == 2490) {
448 quirks = &quirk_acer_travelmate_2490;
449 }
450
451 if (quirks == NULL)
452 quirks = &quirk_unknown;
453
454 set_quirks();
455}
456
457/*
458 * General interface convenience methods
459 */
460
461static bool has_cap(u32 cap)
462{
463 if ((interface->capability & cap) != 0)
464 return 1;
465
466 return 0;
467}
468
469/*
470 * AMW0 (V1) interface
471 */
472struct wmab_args {
473 u32 eax;
474 u32 ebx;
475 u32 ecx;
476 u32 edx;
477};
478
479struct wmab_ret {
480 u32 eax;
481 u32 ebx;
482 u32 ecx;
483 u32 edx;
484 u32 eex;
485};
486
487static acpi_status wmab_execute(struct wmab_args *regbuf,
488struct acpi_buffer *result)
489{
490 struct acpi_buffer input;
491 acpi_status status;
492 input.length = sizeof(struct wmab_args);
493 input.pointer = (u8 *)regbuf;
494
495 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
496
497 return status;
498}
499
500static acpi_status AMW0_get_u32(u32 *value, u32 cap,
501struct wmi_interface *iface)
502{
503 int err;
504 u8 result;
505
506 switch (cap) {
507 case ACER_CAP_MAILLED:
508 switch (quirks->mailled) {
509 default:
510 err = ec_read(0xA, &result);
511 if (err)
512 return AE_ERROR;
513 *value = (result >> 7) & 0x1;
514 return AE_OK;
515 }
516 break;
517 case ACER_CAP_WIRELESS:
518 switch (quirks->wireless) {
519 case 1:
520 err = ec_read(0x7B, &result);
521 if (err)
522 return AE_ERROR;
523 *value = result & 0x1;
524 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100525 case 2:
526 err = ec_read(0x71, &result);
527 if (err)
528 return AE_ERROR;
529 *value = result & 0x1;
530 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000531 default:
532 err = ec_read(0xA, &result);
533 if (err)
534 return AE_ERROR;
535 *value = (result >> 2) & 0x1;
536 return AE_OK;
537 }
538 break;
539 case ACER_CAP_BLUETOOTH:
540 switch (quirks->bluetooth) {
541 default:
542 err = ec_read(0xA, &result);
543 if (err)
544 return AE_ERROR;
545 *value = (result >> 4) & 0x1;
546 return AE_OK;
547 }
548 break;
549 case ACER_CAP_BRIGHTNESS:
550 switch (quirks->brightness) {
551 default:
552 err = ec_read(0x83, &result);
553 if (err)
554 return AE_ERROR;
555 *value = result;
556 return AE_OK;
557 }
558 break;
559 default:
Lin Ming08237972008-08-08 11:57:11 +0800560 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000561 }
562 return AE_OK;
563}
564
565static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
566{
567 struct wmab_args args;
568
569 args.eax = ACER_AMW0_WRITE;
570 args.ebx = value ? (1<<8) : 0;
571 args.ecx = args.edx = 0;
572
573 switch (cap) {
574 case ACER_CAP_MAILLED:
575 if (value > 1)
576 return AE_BAD_PARAMETER;
577 args.ebx |= ACER_AMW0_MAILLED_MASK;
578 break;
579 case ACER_CAP_WIRELESS:
580 if (value > 1)
581 return AE_BAD_PARAMETER;
582 args.ebx |= ACER_AMW0_WIRELESS_MASK;
583 break;
584 case ACER_CAP_BLUETOOTH:
585 if (value > 1)
586 return AE_BAD_PARAMETER;
587 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
588 break;
589 case ACER_CAP_BRIGHTNESS:
590 if (value > max_brightness)
591 return AE_BAD_PARAMETER;
592 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000593 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000594 return ec_write(0x83, value);
595 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000596 }
597 default:
Lin Ming08237972008-08-08 11:57:11 +0800598 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000599 }
600
601 /* Actually do the set */
602 return wmab_execute(&args, NULL);
603}
604
605static acpi_status AMW0_find_mailled(void)
606{
607 struct wmab_args args;
608 struct wmab_ret ret;
609 acpi_status status = AE_OK;
610 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
611 union acpi_object *obj;
612
613 args.eax = 0x86;
614 args.ebx = args.ecx = args.edx = 0;
615
616 status = wmab_execute(&args, &out);
617 if (ACPI_FAILURE(status))
618 return status;
619
620 obj = (union acpi_object *) out.pointer;
621 if (obj && obj->type == ACPI_TYPE_BUFFER &&
622 obj->buffer.length == sizeof(struct wmab_ret)) {
623 ret = *((struct wmab_ret *) obj->buffer.pointer);
624 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700625 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000626 return AE_ERROR;
627 }
628
629 if (ret.eex & 0x1)
630 interface->capability |= ACER_CAP_MAILLED;
631
632 kfree(out.pointer);
633
634 return AE_OK;
635}
636
637static acpi_status AMW0_set_capabilities(void)
638{
639 struct wmab_args args;
640 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700641 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000642 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
643 union acpi_object *obj;
644
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100645 /*
646 * On laptops with this strange GUID (non Acer), normal probing doesn't
647 * work.
648 */
649 if (wmi_has_guid(AMW0_GUID2)) {
650 interface->capability |= ACER_CAP_WIRELESS;
651 return AE_OK;
652 }
653
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000654 args.eax = ACER_AMW0_WRITE;
655 args.ecx = args.edx = 0;
656
657 args.ebx = 0xa2 << 8;
658 args.ebx |= ACER_AMW0_WIRELESS_MASK;
659
660 status = wmab_execute(&args, &out);
661 if (ACPI_FAILURE(status))
662 return status;
663
Axel Lin7677fbd2010-07-20 15:19:53 -0700664 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000665 if (obj && obj->type == ACPI_TYPE_BUFFER &&
666 obj->buffer.length == sizeof(struct wmab_ret)) {
667 ret = *((struct wmab_ret *) obj->buffer.pointer);
668 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700669 status = AE_ERROR;
670 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000671 }
672
673 if (ret.eax & 0x1)
674 interface->capability |= ACER_CAP_WIRELESS;
675
676 args.ebx = 2 << 8;
677 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
678
Axel Lin7677fbd2010-07-20 15:19:53 -0700679 /*
680 * It's ok to use existing buffer for next wmab_execute call.
681 * But we need to kfree(out.pointer) if next wmab_execute fail.
682 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000683 status = wmab_execute(&args, &out);
684 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700685 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000686
687 obj = (union acpi_object *) out.pointer;
688 if (obj && obj->type == ACPI_TYPE_BUFFER
689 && obj->buffer.length == sizeof(struct wmab_ret)) {
690 ret = *((struct wmab_ret *) obj->buffer.pointer);
691 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700692 status = AE_ERROR;
693 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000694 }
695
696 if (ret.eax & 0x1)
697 interface->capability |= ACER_CAP_BLUETOOTH;
698
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000699 /*
700 * This appears to be safe to enable, since all Wistron based laptops
701 * appear to use the same EC register for brightness, even if they
702 * differ for wireless, etc
703 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100704 if (quirks->brightness >= 0)
705 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000706
Axel Lin7677fbd2010-07-20 15:19:53 -0700707 status = AE_OK;
708out:
709 kfree(out.pointer);
710 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000711}
712
713static struct wmi_interface AMW0_interface = {
714 .type = ACER_AMW0,
715};
716
717static struct wmi_interface AMW0_V2_interface = {
718 .type = ACER_AMW0_V2,
719};
720
721/*
722 * New interface (The WMID interface)
723 */
724static acpi_status
725WMI_execute_u32(u32 method_id, u32 in, u32 *out)
726{
727 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
728 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
729 union acpi_object *obj;
730 u32 tmp;
731 acpi_status status;
732
733 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
734
735 if (ACPI_FAILURE(status))
736 return status;
737
738 obj = (union acpi_object *) result.pointer;
739 if (obj && obj->type == ACPI_TYPE_BUFFER &&
740 obj->buffer.length == sizeof(u32)) {
741 tmp = *((u32 *) obj->buffer.pointer);
742 } else {
743 tmp = 0;
744 }
745
746 if (out)
747 *out = tmp;
748
749 kfree(result.pointer);
750
751 return status;
752}
753
754static acpi_status WMID_get_u32(u32 *value, u32 cap,
755struct wmi_interface *iface)
756{
757 acpi_status status;
758 u8 tmp;
759 u32 result, method_id = 0;
760
761 switch (cap) {
762 case ACER_CAP_WIRELESS:
763 method_id = ACER_WMID_GET_WIRELESS_METHODID;
764 break;
765 case ACER_CAP_BLUETOOTH:
766 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
767 break;
768 case ACER_CAP_BRIGHTNESS:
769 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
770 break;
771 case ACER_CAP_THREEG:
772 method_id = ACER_WMID_GET_THREEG_METHODID;
773 break;
774 case ACER_CAP_MAILLED:
775 if (quirks->mailled == 1) {
776 ec_read(0x9f, &tmp);
777 *value = tmp & 0x1;
778 return 0;
779 }
780 default:
Lin Ming08237972008-08-08 11:57:11 +0800781 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000782 }
783 status = WMI_execute_u32(method_id, 0, &result);
784
785 if (ACPI_SUCCESS(status))
786 *value = (u8)result;
787
788 return status;
789}
790
791static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
792{
793 u32 method_id = 0;
794 char param;
795
796 switch (cap) {
797 case ACER_CAP_BRIGHTNESS:
798 if (value > max_brightness)
799 return AE_BAD_PARAMETER;
800 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
801 break;
802 case ACER_CAP_WIRELESS:
803 if (value > 1)
804 return AE_BAD_PARAMETER;
805 method_id = ACER_WMID_SET_WIRELESS_METHODID;
806 break;
807 case ACER_CAP_BLUETOOTH:
808 if (value > 1)
809 return AE_BAD_PARAMETER;
810 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
811 break;
812 case ACER_CAP_THREEG:
813 if (value > 1)
814 return AE_BAD_PARAMETER;
815 method_id = ACER_WMID_SET_THREEG_METHODID;
816 break;
817 case ACER_CAP_MAILLED:
818 if (value > 1)
819 return AE_BAD_PARAMETER;
820 if (quirks->mailled == 1) {
821 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700822 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000823 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700824 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000825 return 0;
826 }
827 break;
828 default:
Lin Ming08237972008-08-08 11:57:11 +0800829 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000830 }
831 return WMI_execute_u32(method_id, (u32)value, NULL);
832}
833
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800834static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
835{
836 struct hotkey_function_type_aa *type_aa;
837
838 /* We are looking for OEM-specific Type AAh */
839 if (header->type != 0xAA)
840 return;
841
842 has_type_aa = true;
843 type_aa = (struct hotkey_function_type_aa *) header;
844
Lee, Chun-Yicae15702011-03-16 18:52:36 +0800845 pr_info("Function bitmap for Communication Button: 0x%x\n",
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800846 type_aa->commun_func_bitmap);
847
848 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
849 interface->capability |= ACER_CAP_WIRELESS;
850 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
851 interface->capability |= ACER_CAP_THREEG;
852 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
853 interface->capability |= ACER_CAP_BLUETOOTH;
854}
855
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000856static acpi_status WMID_set_capabilities(void)
857{
858 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
859 union acpi_object *obj;
860 acpi_status status;
861 u32 devices;
862
863 status = wmi_query_block(WMID_GUID2, 1, &out);
864 if (ACPI_FAILURE(status))
865 return status;
866
867 obj = (union acpi_object *) out.pointer;
868 if (obj && obj->type == ACPI_TYPE_BUFFER &&
869 obj->buffer.length == sizeof(u32)) {
870 devices = *((u32 *) obj->buffer.pointer);
871 } else {
Axel Lin66904862010-07-20 15:19:52 -0700872 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000873 return AE_ERROR;
874 }
875
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800876 dmi_walk(type_aa_dmi_decode, NULL);
877 if (!has_type_aa) {
878 interface->capability |= ACER_CAP_WIRELESS;
879 interface->capability |= ACER_CAP_THREEG;
880 if (devices & 0x10)
881 interface->capability |= ACER_CAP_BLUETOOTH;
882 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000883
884 /* WMID always provides brightness methods */
885 interface->capability |= ACER_CAP_BRIGHTNESS;
886
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000887 if (!(devices & 0x20))
888 max_brightness = 0x9;
889
Axel Lin66904862010-07-20 15:19:52 -0700890 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000891 return status;
892}
893
894static struct wmi_interface wmid_interface = {
895 .type = ACER_WMID,
896};
897
898/*
899 * Generic Device (interface-independent)
900 */
901
902static acpi_status get_u32(u32 *value, u32 cap)
903{
Lin Ming08237972008-08-08 11:57:11 +0800904 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000905
906 switch (interface->type) {
907 case ACER_AMW0:
908 status = AMW0_get_u32(value, cap, interface);
909 break;
910 case ACER_AMW0_V2:
911 if (cap == ACER_CAP_MAILLED) {
912 status = AMW0_get_u32(value, cap, interface);
913 break;
914 }
915 case ACER_WMID:
916 status = WMID_get_u32(value, cap, interface);
917 break;
918 }
919
920 return status;
921}
922
923static acpi_status set_u32(u32 value, u32 cap)
924{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100925 acpi_status status;
926
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000927 if (interface->capability & cap) {
928 switch (interface->type) {
929 case ACER_AMW0:
930 return AMW0_set_u32(value, cap, interface);
931 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100932 if (cap == ACER_CAP_MAILLED)
933 return AMW0_set_u32(value, cap, interface);
934
935 /*
936 * On some models, some WMID methods don't toggle
937 * properly. For those cases, we want to run the AMW0
938 * method afterwards to be certain we've really toggled
939 * the device state.
940 */
941 if (cap == ACER_CAP_WIRELESS ||
942 cap == ACER_CAP_BLUETOOTH) {
943 status = WMID_set_u32(value, cap, interface);
944 if (ACPI_FAILURE(status))
945 return status;
946
947 return AMW0_set_u32(value, cap, interface);
948 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000949 case ACER_WMID:
950 return WMID_set_u32(value, cap, interface);
951 default:
952 return AE_BAD_PARAMETER;
953 }
954 }
955 return AE_BAD_PARAMETER;
956}
957
958static void __init acer_commandline_init(void)
959{
960 /*
961 * These will all fail silently if the value given is invalid, or the
962 * capability isn't available on the given interface
963 */
Lee, Chun-Yic2647b52011-04-15 18:42:47 +0800964 if (mailled >= 0)
965 set_u32(mailled, ACER_CAP_MAILLED);
966 if (!has_type_aa && threeg >= 0)
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800967 set_u32(threeg, ACER_CAP_THREEG);
Lee, Chun-Yic2647b52011-04-15 18:42:47 +0800968 if (brightness >= 0)
969 set_u32(brightness, ACER_CAP_BRIGHTNESS);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000970}
971
972/*
973 * LED device (Mail LED only, no other LEDs known yet)
974 */
975static void mail_led_set(struct led_classdev *led_cdev,
976enum led_brightness value)
977{
978 set_u32(value, ACER_CAP_MAILLED);
979}
980
981static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000982 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000983 .brightness_set = mail_led_set,
984};
985
Sam Ravnborg7560e382008-02-17 13:22:54 +0100986static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000987{
988 return led_classdev_register(dev, &mail_led);
989}
990
991static void acer_led_exit(void)
992{
Pali Rohár9a0b74f2011-02-26 21:18:58 +0100993 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000994 led_classdev_unregister(&mail_led);
995}
996
997/*
998 * Backlight device
999 */
1000static struct backlight_device *acer_backlight_device;
1001
1002static int read_brightness(struct backlight_device *bd)
1003{
1004 u32 value;
1005 get_u32(&value, ACER_CAP_BRIGHTNESS);
1006 return value;
1007}
1008
1009static int update_bl_status(struct backlight_device *bd)
1010{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001011 int intensity = bd->props.brightness;
1012
1013 if (bd->props.power != FB_BLANK_UNBLANK)
1014 intensity = 0;
1015 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1016 intensity = 0;
1017
1018 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1019
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001020 return 0;
1021}
1022
Lionel Debrouxacc24722010-11-16 14:14:02 +01001023static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001024 .get_brightness = read_brightness,
1025 .update_status = update_bl_status,
1026};
1027
Sam Ravnborg7560e382008-02-17 13:22:54 +01001028static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001029{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001030 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001031 struct backlight_device *bd;
1032
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001033 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001034 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001035 props.max_brightness = max_brightness;
1036 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1037 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001038 if (IS_ERR(bd)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001039 pr_err("Could not register Acer backlight device\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001040 acer_backlight_device = NULL;
1041 return PTR_ERR(bd);
1042 }
1043
1044 acer_backlight_device = bd;
1045
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001046 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001047 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001048 backlight_update_status(bd);
1049 return 0;
1050}
1051
Sam Ravnborg7560e382008-02-17 13:22:54 +01001052static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001053{
1054 backlight_device_unregister(acer_backlight_device);
1055}
1056
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001057static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1058{
1059 struct wmid3_gds_return_value return_value;
1060 acpi_status status;
1061 union acpi_object *obj;
1062 struct wmid3_gds_input_param params = {
1063 .function_num = 0x1,
1064 .hotkey_number = 0x01,
1065 .devices = device,
1066 };
1067 struct acpi_buffer input = {
1068 sizeof(struct wmid3_gds_input_param),
1069 &params
1070 };
1071 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1072
1073 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1074 if (ACPI_FAILURE(status))
1075 return status;
1076
1077 obj = output.pointer;
1078
1079 if (!obj)
1080 return AE_ERROR;
1081 else if (obj->type != ACPI_TYPE_BUFFER) {
1082 kfree(obj);
1083 return AE_ERROR;
1084 }
1085 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001086 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001087 kfree(obj);
1088 return AE_ERROR;
1089 }
1090
1091 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1092 kfree(obj);
1093
1094 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001095 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1096 return_value.error_code,
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001097 return_value.ec_return_value);
1098 else
1099 *value = !!(return_value.devices & device);
1100
1101 return status;
1102}
1103
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001104static acpi_status get_device_status(u32 *value, u32 cap)
1105{
1106 if (wmi_has_guid(WMID_GUID3)) {
1107 u16 device;
1108
1109 switch (cap) {
1110 case ACER_CAP_WIRELESS:
1111 device = ACER_WMID3_GDS_WIRELESS;
1112 break;
1113 case ACER_CAP_BLUETOOTH:
1114 device = ACER_WMID3_GDS_BLUETOOTH;
1115 break;
1116 case ACER_CAP_THREEG:
1117 device = ACER_WMID3_GDS_THREEG;
1118 break;
1119 default:
1120 return AE_ERROR;
1121 }
1122 return wmid3_get_device_status(value, device);
1123
1124 } else {
1125 return get_u32(value, cap);
1126 }
1127}
1128
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001129/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001130 * Rfkill devices
1131 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001132static void acer_rfkill_update(struct work_struct *ignored);
1133static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1134static void acer_rfkill_update(struct work_struct *ignored)
1135{
1136 u32 state;
1137 acpi_status status;
1138
1139 status = get_u32(&state, ACER_CAP_WIRELESS);
1140 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001141 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001142
1143 if (has_cap(ACER_CAP_BLUETOOTH)) {
1144 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1145 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001146 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001147 }
1148
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001149 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1150 status = wmid3_get_device_status(&state,
1151 ACER_WMID3_GDS_THREEG);
1152 if (ACPI_SUCCESS(status))
1153 rfkill_set_sw_state(threeg_rfkill, !state);
1154 }
1155
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001156 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001157}
1158
Johannes Berg19d337d2009-06-02 13:01:37 +02001159static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001160{
1161 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001162 u32 cap = (unsigned long)data;
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001163
1164 if (rfkill_inited) {
1165 status = set_u32(!blocked, cap);
1166 if (ACPI_FAILURE(status))
1167 return -ENODEV;
1168 }
1169
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001170 return 0;
1171}
1172
Johannes Berg19d337d2009-06-02 13:01:37 +02001173static const struct rfkill_ops acer_rfkill_ops = {
1174 .set_block = acer_rfkill_set,
1175};
1176
1177static struct rfkill *acer_rfkill_register(struct device *dev,
1178 enum rfkill_type type,
1179 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001180{
1181 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001182 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001183 u32 state;
1184 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001185
Johannes Berg19d337d2009-06-02 13:01:37 +02001186 rfkill_dev = rfkill_alloc(name, dev, type,
1187 &acer_rfkill_ops,
1188 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001189 if (!rfkill_dev)
1190 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001191
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001192 status = get_device_status(&state, cap);
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001193
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001194 err = rfkill_register(rfkill_dev);
1195 if (err) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001196 rfkill_destroy(rfkill_dev);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001197 return ERR_PTR(err);
1198 }
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001199
1200 if (ACPI_SUCCESS(status))
1201 rfkill_set_sw_state(rfkill_dev, !state);
1202
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001203 return rfkill_dev;
1204}
1205
1206static int acer_rfkill_init(struct device *dev)
1207{
1208 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1209 "acer-wireless", ACER_CAP_WIRELESS);
1210 if (IS_ERR(wireless_rfkill))
1211 return PTR_ERR(wireless_rfkill);
1212
1213 if (has_cap(ACER_CAP_BLUETOOTH)) {
1214 bluetooth_rfkill = acer_rfkill_register(dev,
1215 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1216 ACER_CAP_BLUETOOTH);
1217 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001218 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001219 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001220 return PTR_ERR(bluetooth_rfkill);
1221 }
1222 }
1223
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001224 if (has_cap(ACER_CAP_THREEG)) {
1225 threeg_rfkill = acer_rfkill_register(dev,
1226 RFKILL_TYPE_WWAN, "acer-threeg",
1227 ACER_CAP_THREEG);
1228 if (IS_ERR(threeg_rfkill)) {
1229 rfkill_unregister(wireless_rfkill);
1230 rfkill_destroy(wireless_rfkill);
1231 rfkill_unregister(bluetooth_rfkill);
1232 rfkill_destroy(bluetooth_rfkill);
1233 return PTR_ERR(threeg_rfkill);
1234 }
1235 }
1236
Lee, Chun-Yi8215af02011-03-28 16:52:02 +08001237 rfkill_inited = true;
1238
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001239 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1240 schedule_delayed_work(&acer_rfkill_work,
1241 round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001242
1243 return 0;
1244}
1245
1246static void acer_rfkill_exit(void)
1247{
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001248 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1249 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001250
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001251 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001252 rfkill_destroy(wireless_rfkill);
1253
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001254 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001255 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001256 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001257 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001258
1259 if (has_cap(ACER_CAP_THREEG)) {
1260 rfkill_unregister(threeg_rfkill);
1261 rfkill_destroy(threeg_rfkill);
1262 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001263 return;
1264}
1265
1266/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001267 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001268 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001269static ssize_t show_bool_threeg(struct device *dev,
1270 struct device_attribute *attr, char *buf)
1271{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001272 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001273 acpi_status status;
1274 if (wmi_has_guid(WMID_GUID3))
1275 status = wmid3_get_device_status(&result,
1276 ACER_WMID3_GDS_THREEG);
1277 else
1278 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001279 if (ACPI_SUCCESS(status))
1280 return sprintf(buf, "%u\n", result);
1281 return sprintf(buf, "Read error\n");
1282}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001283
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001284static ssize_t set_bool_threeg(struct device *dev,
1285 struct device_attribute *attr, const char *buf, size_t count)
1286{
1287 u32 tmp = simple_strtoul(buf, NULL, 10);
1288 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1289 if (ACPI_FAILURE(status))
1290 return -EINVAL;
1291 return count;
1292}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001293static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001294 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001295
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001296static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1297 char *buf)
1298{
1299 switch (interface->type) {
1300 case ACER_AMW0:
1301 return sprintf(buf, "AMW0\n");
1302 case ACER_AMW0_V2:
1303 return sprintf(buf, "AMW0 v2\n");
1304 case ACER_WMID:
1305 return sprintf(buf, "WMID\n");
1306 default:
1307 return sprintf(buf, "Error!\n");
1308 }
1309}
1310
Axel Lin370525d2010-06-30 10:20:23 +08001311static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001312
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001313static void acer_wmi_notify(u32 value, void *context)
1314{
1315 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1316 union acpi_object *obj;
1317 struct event_return_value return_value;
1318 acpi_status status;
1319
1320 status = wmi_get_event_data(value, &response);
1321 if (status != AE_OK) {
Joe Perches249c7202011-03-29 15:21:34 -07001322 pr_warn("bad event status 0x%x\n", status);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001323 return;
1324 }
1325
1326 obj = (union acpi_object *)response.pointer;
1327
1328 if (!obj)
1329 return;
1330 if (obj->type != ACPI_TYPE_BUFFER) {
Joe Perches249c7202011-03-29 15:21:34 -07001331 pr_warn("Unknown response received %d\n", obj->type);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001332 kfree(obj);
1333 return;
1334 }
1335 if (obj->buffer.length != 8) {
Joe Perches249c7202011-03-29 15:21:34 -07001336 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001337 kfree(obj);
1338 return;
1339 }
1340
1341 return_value = *((struct event_return_value *)obj->buffer.pointer);
1342 kfree(obj);
1343
1344 switch (return_value.function) {
1345 case WMID_HOTKEY_EVENT:
Lee, Chun-Yi70a9b902011-03-28 06:34:13 -04001346 if (return_value.device_state) {
1347 u16 device_state = return_value.device_state;
1348 pr_debug("deivces states: 0x%x\n", device_state);
1349 if (has_cap(ACER_CAP_WIRELESS))
1350 rfkill_set_sw_state(wireless_rfkill,
1351 !(device_state & ACER_WMID3_GDS_WIRELESS));
1352 if (has_cap(ACER_CAP_BLUETOOTH))
1353 rfkill_set_sw_state(bluetooth_rfkill,
1354 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1355 if (has_cap(ACER_CAP_THREEG))
1356 rfkill_set_sw_state(threeg_rfkill,
1357 !(device_state & ACER_WMID3_GDS_THREEG));
1358 }
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001359 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1360 return_value.key_num, 1, true))
Joe Perches249c7202011-03-29 15:21:34 -07001361 pr_warn("Unknown key number - 0x%x\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001362 return_value.key_num);
1363 break;
1364 default:
Joe Perches249c7202011-03-29 15:21:34 -07001365 pr_warn("Unknown function number - %d - %d\n",
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001366 return_value.function, return_value.key_num);
1367 break;
1368 }
1369}
1370
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001371static acpi_status
1372wmid3_set_lm_mode(struct lm_input_params *params,
1373 struct lm_return_value *return_value)
1374{
1375 acpi_status status;
1376 union acpi_object *obj;
1377
1378 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1379 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1380
1381 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1382 if (ACPI_FAILURE(status))
1383 return status;
1384
1385 obj = output.pointer;
1386
1387 if (!obj)
1388 return AE_ERROR;
1389 else if (obj->type != ACPI_TYPE_BUFFER) {
1390 kfree(obj);
1391 return AE_ERROR;
1392 }
1393 if (obj->buffer.length != 4) {
Joe Perches249c7202011-03-29 15:21:34 -07001394 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001395 kfree(obj);
1396 return AE_ERROR;
1397 }
1398
1399 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1400 kfree(obj);
1401
1402 return status;
1403}
1404
1405static int acer_wmi_enable_ec_raw(void)
1406{
1407 struct lm_return_value return_value;
1408 acpi_status status;
1409 struct lm_input_params params = {
1410 .function_num = 0x1,
1411 .commun_devices = 0xFFFF,
1412 .devices = 0xFFFF,
1413 .lm_status = 0x00, /* Launch Manager Deactive */
1414 };
1415
1416 status = wmid3_set_lm_mode(&params, &return_value);
1417
1418 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001419 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1420 return_value.error_code,
1421 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001422 else
Joe Perches249c7202011-03-29 15:21:34 -07001423 pr_info("Enabled EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001424
1425 return status;
1426}
1427
1428static int acer_wmi_enable_lm(void)
1429{
1430 struct lm_return_value return_value;
1431 acpi_status status;
1432 struct lm_input_params params = {
1433 .function_num = 0x1,
1434 .commun_devices = 0xFFFF,
1435 .devices = 0xFFFF,
1436 .lm_status = 0x01, /* Launch Manager Active */
1437 };
1438
1439 status = wmid3_set_lm_mode(&params, &return_value);
1440
1441 if (return_value.error_code || return_value.ec_return_value)
Joe Perches249c7202011-03-29 15:21:34 -07001442 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1443 return_value.error_code,
1444 return_value.ec_return_value);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001445
1446 return status;
1447}
1448
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001449static int __init acer_wmi_input_setup(void)
1450{
1451 acpi_status status;
1452 int err;
1453
1454 acer_wmi_input_dev = input_allocate_device();
1455 if (!acer_wmi_input_dev)
1456 return -ENOMEM;
1457
1458 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1459 acer_wmi_input_dev->phys = "wmi/input0";
1460 acer_wmi_input_dev->id.bustype = BUS_HOST;
1461
1462 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1463 if (err)
1464 goto err_free_dev;
1465
1466 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1467 acer_wmi_notify, NULL);
1468 if (ACPI_FAILURE(status)) {
1469 err = -EIO;
1470 goto err_free_keymap;
1471 }
1472
1473 err = input_register_device(acer_wmi_input_dev);
1474 if (err)
1475 goto err_uninstall_notifier;
1476
1477 return 0;
1478
1479err_uninstall_notifier:
1480 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1481err_free_keymap:
1482 sparse_keymap_free(acer_wmi_input_dev);
1483err_free_dev:
1484 input_free_device(acer_wmi_input_dev);
1485 return err;
1486}
1487
1488static void acer_wmi_input_destroy(void)
1489{
1490 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1491 sparse_keymap_free(acer_wmi_input_dev);
1492 input_unregister_device(acer_wmi_input_dev);
1493}
1494
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001495/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001496 * debugfs functions
1497 */
1498static u32 get_wmid_devices(void)
1499{
1500 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1501 union acpi_object *obj;
1502 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001503 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001504
1505 status = wmi_query_block(WMID_GUID2, 1, &out);
1506 if (ACPI_FAILURE(status))
1507 return 0;
1508
1509 obj = (union acpi_object *) out.pointer;
1510 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1511 obj->buffer.length == sizeof(u32)) {
Axel Lin66904862010-07-20 15:19:52 -07001512 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001513 }
Axel Lin66904862010-07-20 15:19:52 -07001514
1515 kfree(out.pointer);
1516 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001517}
1518
1519/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001520 * Platform device
1521 */
1522static int __devinit acer_platform_probe(struct platform_device *device)
1523{
1524 int err;
1525
1526 if (has_cap(ACER_CAP_MAILLED)) {
1527 err = acer_led_init(&device->dev);
1528 if (err)
1529 goto error_mailled;
1530 }
1531
1532 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1533 err = acer_backlight_init(&device->dev);
1534 if (err)
1535 goto error_brightness;
1536 }
1537
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001538 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001539 if (err)
1540 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001541
1542 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001543
Andy Whitcroft350e3292009-04-04 09:33:34 +01001544error_rfkill:
1545 if (has_cap(ACER_CAP_BRIGHTNESS))
1546 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001547error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001548 if (has_cap(ACER_CAP_MAILLED))
1549 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001550error_mailled:
1551 return err;
1552}
1553
1554static int acer_platform_remove(struct platform_device *device)
1555{
1556 if (has_cap(ACER_CAP_MAILLED))
1557 acer_led_exit();
1558 if (has_cap(ACER_CAP_BRIGHTNESS))
1559 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001560
1561 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001562 return 0;
1563}
1564
1565static int acer_platform_suspend(struct platform_device *dev,
1566pm_message_t state)
1567{
1568 u32 value;
1569 struct acer_data *data = &interface->data;
1570
1571 if (!data)
1572 return -ENOMEM;
1573
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001574 if (has_cap(ACER_CAP_MAILLED)) {
1575 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001576 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001577 data->mailled = value;
1578 }
1579
1580 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1581 get_u32(&value, ACER_CAP_BRIGHTNESS);
1582 data->brightness = value;
1583 }
1584
1585 return 0;
1586}
1587
1588static int acer_platform_resume(struct platform_device *device)
1589{
1590 struct acer_data *data = &interface->data;
1591
1592 if (!data)
1593 return -ENOMEM;
1594
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001595 if (has_cap(ACER_CAP_MAILLED))
1596 set_u32(data->mailled, ACER_CAP_MAILLED);
1597
1598 if (has_cap(ACER_CAP_BRIGHTNESS))
1599 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1600
1601 return 0;
1602}
1603
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001604static void acer_platform_shutdown(struct platform_device *device)
1605{
1606 struct acer_data *data = &interface->data;
1607
1608 if (!data)
1609 return;
1610
1611 if (has_cap(ACER_CAP_MAILLED))
1612 set_u32(LED_OFF, ACER_CAP_MAILLED);
1613}
1614
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001615static struct platform_driver acer_platform_driver = {
1616 .driver = {
1617 .name = "acer-wmi",
1618 .owner = THIS_MODULE,
1619 },
1620 .probe = acer_platform_probe,
1621 .remove = acer_platform_remove,
1622 .suspend = acer_platform_suspend,
1623 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001624 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001625};
1626
1627static struct platform_device *acer_platform_device;
1628
1629static int remove_sysfs(struct platform_device *device)
1630{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001631 if (has_cap(ACER_CAP_THREEG))
1632 device_remove_file(&device->dev, &dev_attr_threeg);
1633
1634 device_remove_file(&device->dev, &dev_attr_interface);
1635
1636 return 0;
1637}
1638
1639static int create_sysfs(void)
1640{
1641 int retval = -ENOMEM;
1642
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001643 if (has_cap(ACER_CAP_THREEG)) {
1644 retval = device_create_file(&acer_platform_device->dev,
1645 &dev_attr_threeg);
1646 if (retval)
1647 goto error_sysfs;
1648 }
1649
1650 retval = device_create_file(&acer_platform_device->dev,
1651 &dev_attr_interface);
1652 if (retval)
1653 goto error_sysfs;
1654
1655 return 0;
1656
1657error_sysfs:
1658 remove_sysfs(acer_platform_device);
1659 return retval;
1660}
1661
Carlos Corbacho81143522008-06-21 09:09:53 +01001662static void remove_debugfs(void)
1663{
1664 debugfs_remove(interface->debug.devices);
1665 debugfs_remove(interface->debug.root);
1666}
1667
1668static int create_debugfs(void)
1669{
1670 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1671 if (!interface->debug.root) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001672 pr_err("Failed to create debugfs directory");
Carlos Corbacho81143522008-06-21 09:09:53 +01001673 return -ENOMEM;
1674 }
1675
1676 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1677 interface->debug.root,
1678 &interface->debug.wmid_devices);
1679 if (!interface->debug.devices)
1680 goto error_debugfs;
1681
1682 return 0;
1683
1684error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001685 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001686 return -ENOMEM;
1687}
1688
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001689static int __init acer_wmi_init(void)
1690{
1691 int err;
1692
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001693 pr_info("Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001694
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001695 if (dmi_check_system(acer_blacklist)) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001696 pr_info("Blacklisted hardware detected - not loading\n");
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001697 return -ENODEV;
1698 }
1699
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001700 find_quirks();
1701
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001702 /*
1703 * Detect which ACPI-WMI interface we're using.
1704 */
1705 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1706 interface = &AMW0_V2_interface;
1707
1708 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1709 interface = &wmid_interface;
1710
1711 if (wmi_has_guid(WMID_GUID2) && interface) {
1712 if (ACPI_FAILURE(WMID_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001713 pr_err("Unable to detect available WMID devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001714 return -ENODEV;
1715 }
1716 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001717 pr_err("No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001718 return -ENODEV;
1719 }
1720
1721 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1722 interface = &AMW0_interface;
1723
1724 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001725 pr_err("Unable to detect available AMW0 devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001726 return -ENODEV;
1727 }
1728 }
1729
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001730 if (wmi_has_guid(AMW0_GUID1))
1731 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001732
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001733 if (!interface) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001734 pr_err("No or unsupported WMI interface, unable to load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001735 return -ENODEV;
1736 }
1737
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001738 set_quirks();
1739
Michael Spang1ba869e2009-03-12 14:31:34 -07001740 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001741 interface->capability &= ~ACER_CAP_BRIGHTNESS;
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001742 pr_info("Brightness must be controlled by "
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001743 "generic video driver\n");
1744 }
1745
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001746 if (wmi_has_guid(WMID_GUID3)) {
1747 if (ec_raw_mode) {
1748 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001749 pr_err("Cannot enable EC raw mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001750 return -ENODEV;
1751 }
1752 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001753 pr_err("Cannot enable Launch Manager mode\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001754 return -ENODEV;
1755 }
1756 } else if (ec_raw_mode) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001757 pr_info("No WMID EC raw mode enable method\n");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001758 }
1759
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001760 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1761 err = acer_wmi_input_setup();
1762 if (err)
1763 return err;
1764 }
1765
Axel Lin1c796322010-06-22 16:17:38 +08001766 err = platform_driver_register(&acer_platform_driver);
1767 if (err) {
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001768 pr_err("Unable to register platform driver.\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001769 goto error_platform_register;
1770 }
Axel Lin1c796322010-06-22 16:17:38 +08001771
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001772 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001773 if (!acer_platform_device) {
1774 err = -ENOMEM;
1775 goto error_device_alloc;
1776 }
1777
1778 err = platform_device_add(acer_platform_device);
1779 if (err)
1780 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001781
1782 err = create_sysfs();
1783 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001784 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001785
Carlos Corbacho81143522008-06-21 09:09:53 +01001786 if (wmi_has_guid(WMID_GUID2)) {
1787 interface->debug.wmid_devices = get_wmid_devices();
1788 err = create_debugfs();
1789 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001790 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001791 }
1792
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001793 /* Override any initial settings with values from the commandline */
1794 acer_commandline_init();
1795
1796 return 0;
1797
Axel Lin1c796322010-06-22 16:17:38 +08001798error_create_debugfs:
1799 remove_sysfs(acer_platform_device);
1800error_create_sys:
1801 platform_device_del(acer_platform_device);
1802error_device_add:
1803 platform_device_put(acer_platform_device);
1804error_device_alloc:
1805 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001806error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001807 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1808 acer_wmi_input_destroy();
1809
Axel Lin1c796322010-06-22 16:17:38 +08001810 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001811}
1812
1813static void __exit acer_wmi_exit(void)
1814{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001815 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1816 acer_wmi_input_destroy();
1817
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001818 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001819 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001820 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001821 platform_driver_unregister(&acer_platform_driver);
1822
Lee, Chun-Yicae15702011-03-16 18:52:36 +08001823 pr_info("Acer Laptop WMI Extras unloaded\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001824 return;
1825}
1826
1827module_init(acer_wmi_init);
1828module_exit(acer_wmi_exit);