blob: 4c8209376985a9861113a06b5e6c7c9ee5d7959e [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
Carlos Corbacho745a5d22008-02-05 02:17:10 +000025#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/types.h>
29#include <linux/dmi.h>
Carlos Corbachof2b585b2008-06-21 09:09:27 +010030#include <linux/fb.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000031#include <linux/backlight.h>
32#include <linux/leds.h>
33#include <linux/platform_device.h>
34#include <linux/acpi.h>
35#include <linux/i8042.h>
Carlos Corbacho0606e1a2008-10-08 21:40:21 +010036#include <linux/rfkill.h>
37#include <linux/workqueue.h>
Carlos Corbacho81143522008-06-21 09:09:53 +010038#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090039#include <linux/slab.h>
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080040#include <linux/input.h>
41#include <linux/input/sparse-keymap.h>
Carlos Corbacho745a5d22008-02-05 02:17:10 +000042
43#include <acpi/acpi_drivers.h>
44
45MODULE_AUTHOR("Carlos Corbacho");
46MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
47MODULE_LICENSE("GPL");
48
49#define ACER_LOGPREFIX "acer-wmi: "
50#define ACER_ERR KERN_ERR ACER_LOGPREFIX
51#define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
52#define ACER_INFO KERN_INFO ACER_LOGPREFIX
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080053#define ACER_WARNING KERN_WARNING ACER_LOGPREFIX
Carlos Corbacho745a5d22008-02-05 02:17:10 +000054
55/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +000056 * Magic Number
57 * Meaning is unknown - this number is required for writing to ACPI for AMW0
58 * (it's also used in acerhk when directly accessing the BIOS)
59 */
60#define ACER_AMW0_WRITE 0x9610
61
62/*
63 * Bit masks for the AMW0 interface
64 */
65#define ACER_AMW0_WIRELESS_MASK 0x35
66#define ACER_AMW0_BLUETOOTH_MASK 0x34
67#define ACER_AMW0_MAILLED_MASK 0x31
68
69/*
70 * Method IDs for WMID interface
71 */
72#define ACER_WMID_GET_WIRELESS_METHODID 1
73#define ACER_WMID_GET_BLUETOOTH_METHODID 2
74#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
75#define ACER_WMID_SET_WIRELESS_METHODID 4
76#define ACER_WMID_SET_BLUETOOTH_METHODID 5
77#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
78#define ACER_WMID_GET_THREEG_METHODID 10
79#define ACER_WMID_SET_THREEG_METHODID 11
80
81/*
82 * Acer ACPI method GUIDs
83 */
84#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
Carlos Corbacho5753dd52008-06-21 09:09:48 +010085#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
Matthew Garrettbbb70602011-02-09 16:39:40 -050086#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000087#define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
Lee, Chun-Yib3c90922010-12-07 10:29:22 +080088#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
Carlos Corbacho745a5d22008-02-05 02:17:10 +000089
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080090/*
91 * Acer ACPI event GUIDs
92 */
93#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
94
Carlos Corbacho745a5d22008-02-05 02:17:10 +000095MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
96MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +080097MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
98
99enum acer_wmi_event_ids {
100 WMID_HOTKEY_EVENT = 0x1,
101};
102
103static const struct key_entry acer_wmi_keymap[] = {
104 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
105 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
106 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
107 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
108 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
109 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
110 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
Lee, Chun-Yi89411782011-03-02 01:07:11 +0800111 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +0800112 {KE_END, 0}
113};
114
115static struct input_dev *acer_wmi_input_dev;
116
117struct event_return_value {
118 u8 function;
119 u8 key_num;
120 u16 device_state;
121 u32 reserved;
122} __attribute__((packed));
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000123
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000124/*
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800125 * GUID3 Get Device Status device flags
126 */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800127#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800128#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800129#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800130
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500131struct lm_input_params {
132 u8 function_num; /* Function Number */
133 u16 commun_devices; /* Communication type devices default status */
134 u16 devices; /* Other type devices default status */
135 u8 lm_status; /* Launch Manager Status */
136 u16 reserved;
137} __attribute__((packed));
138
139struct lm_return_value {
140 u8 error_code; /* Error Code */
141 u8 ec_return_value; /* EC Return Value */
142 u16 reserved;
143} __attribute__((packed));
144
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800145struct wmid3_gds_input_param { /* Get Device Status input parameter */
146 u8 function_num; /* Function Number */
147 u8 hotkey_number; /* Hotkey Number */
148 u16 devices; /* Get Device */
149} __attribute__((packed));
150
151struct wmid3_gds_return_value { /* Get Device Status return value*/
152 u8 error_code; /* Error Code */
153 u8 ec_return_value; /* EC Return Value */
154 u16 devices; /* Current Device Status */
155 u32 reserved;
156} __attribute__((packed));
157
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800158struct hotkey_function_type_aa {
159 u8 type;
160 u8 length;
161 u16 handle;
162 u16 commun_func_bitmap;
163} __attribute__((packed));
164
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800165/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000166 * Interface capability flags
167 */
168#define ACER_CAP_MAILLED (1<<0)
169#define ACER_CAP_WIRELESS (1<<1)
170#define ACER_CAP_BLUETOOTH (1<<2)
171#define ACER_CAP_BRIGHTNESS (1<<3)
172#define ACER_CAP_THREEG (1<<4)
173#define ACER_CAP_ANY (0xFFFFFFFF)
174
175/*
176 * Interface type flags
177 */
178enum interface_flags {
179 ACER_AMW0,
180 ACER_AMW0_V2,
181 ACER_WMID,
182};
183
184#define ACER_DEFAULT_WIRELESS 0
185#define ACER_DEFAULT_BLUETOOTH 0
186#define ACER_DEFAULT_MAILLED 0
187#define ACER_DEFAULT_THREEG 0
188
189static int max_brightness = 0xF;
190
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000191static int mailled = -1;
192static int brightness = -1;
193static int threeg = -1;
194static int force_series;
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500195static bool ec_raw_mode;
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800196static bool has_type_aa;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000197
198module_param(mailled, int, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000199module_param(brightness, int, 0444);
200module_param(threeg, int, 0444);
201module_param(force_series, int, 0444);
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500202module_param(ec_raw_mode, bool, 0444);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000203MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
204MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
205MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
206MODULE_PARM_DESC(force_series, "Force a different laptop series");
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -0500207MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000208
209struct acer_data {
210 int mailled;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000211 int threeg;
212 int brightness;
213};
214
Carlos Corbacho81143522008-06-21 09:09:53 +0100215struct acer_debug {
216 struct dentry *root;
217 struct dentry *devices;
218 u32 wmid_devices;
219};
220
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100221static struct rfkill *wireless_rfkill;
222static struct rfkill *bluetooth_rfkill;
Lee, Chun-Yib3c90922010-12-07 10:29:22 +0800223static struct rfkill *threeg_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +0100224
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000225/* Each low-level interface must define at least some of the following */
226struct wmi_interface {
227 /* The WMI device type */
228 u32 type;
229
230 /* The capabilities this interface provides */
231 u32 capability;
232
233 /* Private data for the current interface */
234 struct acer_data data;
Carlos Corbacho81143522008-06-21 09:09:53 +0100235
236 /* debugfs entries associated with this interface */
237 struct acer_debug debug;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000238};
239
240/* The static interface pointer, points to the currently detected interface */
241static struct wmi_interface *interface;
242
243/*
244 * Embedded Controller quirks
245 * Some laptops require us to directly access the EC to either enable or query
246 * features that are not available through WMI.
247 */
248
249struct quirk_entry {
250 u8 wireless;
251 u8 mailled;
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100252 s8 brightness;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000253 u8 bluetooth;
254};
255
256static struct quirk_entry *quirks;
257
258static void set_quirks(void)
259{
Arjan van de Ven83097ac2008-08-23 21:45:21 -0700260 if (!interface)
261 return;
262
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000263 if (quirks->mailled)
264 interface->capability |= ACER_CAP_MAILLED;
265
266 if (quirks->brightness)
267 interface->capability |= ACER_CAP_BRIGHTNESS;
268}
269
270static int dmi_matched(const struct dmi_system_id *dmi)
271{
272 quirks = dmi->driver_data;
Axel Lind53bf0f2010-06-30 13:32:16 +0800273 return 1;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000274}
275
276static struct quirk_entry quirk_unknown = {
277};
278
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100279static struct quirk_entry quirk_acer_aspire_1520 = {
280 .brightness = -1,
281};
282
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000283static struct quirk_entry quirk_acer_travelmate_2490 = {
284 .mailled = 1,
285};
286
287/* This AMW0 laptop has no bluetooth */
288static struct quirk_entry quirk_medion_md_98300 = {
289 .wireless = 1,
290};
291
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100292static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
293 .wireless = 2,
294};
295
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +0100296/* The Aspire One has a dummy ACPI-WMI interface - disable it */
297static struct dmi_system_id __devinitdata acer_blacklist[] = {
298 {
299 .ident = "Acer Aspire One (SSD)",
300 .matches = {
301 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
302 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
303 },
304 },
305 {
306 .ident = "Acer Aspire One (HDD)",
307 .matches = {
308 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
309 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
310 },
311 },
312 {}
313};
314
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000315static struct dmi_system_id acer_quirks[] = {
316 {
317 .callback = dmi_matched,
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100318 .ident = "Acer Aspire 1360",
319 .matches = {
320 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
321 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
322 },
323 .driver_data = &quirk_acer_aspire_1520,
324 },
325 {
326 .callback = dmi_matched,
327 .ident = "Acer Aspire 1520",
328 .matches = {
329 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
330 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
331 },
332 .driver_data = &quirk_acer_aspire_1520,
333 },
334 {
335 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000336 .ident = "Acer Aspire 3100",
337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
339 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
340 },
341 .driver_data = &quirk_acer_travelmate_2490,
342 },
343 {
344 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000345 .ident = "Acer Aspire 3610",
346 .matches = {
347 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
348 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
349 },
350 .driver_data = &quirk_acer_travelmate_2490,
351 },
352 {
353 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000354 .ident = "Acer Aspire 5100",
355 .matches = {
356 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
357 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
358 },
359 .driver_data = &quirk_acer_travelmate_2490,
360 },
361 {
362 .callback = dmi_matched,
Carlos Corbachoed9cfe92008-03-12 20:13:00 +0000363 .ident = "Acer Aspire 5610",
364 .matches = {
365 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
366 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
367 },
368 .driver_data = &quirk_acer_travelmate_2490,
369 },
370 {
371 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000372 .ident = "Acer Aspire 5630",
373 .matches = {
374 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
375 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
376 },
377 .driver_data = &quirk_acer_travelmate_2490,
378 },
379 {
380 .callback = dmi_matched,
381 .ident = "Acer Aspire 5650",
382 .matches = {
383 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
384 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
385 },
386 .driver_data = &quirk_acer_travelmate_2490,
387 },
388 {
389 .callback = dmi_matched,
390 .ident = "Acer Aspire 5680",
391 .matches = {
392 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
393 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
394 },
395 .driver_data = &quirk_acer_travelmate_2490,
396 },
397 {
398 .callback = dmi_matched,
399 .ident = "Acer Aspire 9110",
400 .matches = {
401 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
402 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
403 },
404 .driver_data = &quirk_acer_travelmate_2490,
405 },
406 {
407 .callback = dmi_matched,
408 .ident = "Acer TravelMate 2490",
409 .matches = {
410 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
411 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
412 },
413 .driver_data = &quirk_acer_travelmate_2490,
414 },
415 {
416 .callback = dmi_matched,
Carlos Corbacho262ee352008-02-16 00:02:56 +0000417 .ident = "Acer TravelMate 4200",
418 .matches = {
419 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
420 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
421 },
422 .driver_data = &quirk_acer_travelmate_2490,
423 },
424 {
425 .callback = dmi_matched,
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100426 .ident = "Fujitsu Siemens Amilo Li 1718",
427 .matches = {
428 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
430 },
431 .driver_data = &quirk_fujitsu_amilo_li_1718,
432 },
433 {
434 .callback = dmi_matched,
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000435 .ident = "Medion MD 98300",
436 .matches = {
437 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
439 },
440 .driver_data = &quirk_medion_md_98300,
441 },
442 {}
443};
444
445/* Find which quirks are needed for a particular vendor/ model pair */
446static void find_quirks(void)
447{
448 if (!force_series) {
449 dmi_check_system(acer_quirks);
450 } else if (force_series == 2490) {
451 quirks = &quirk_acer_travelmate_2490;
452 }
453
454 if (quirks == NULL)
455 quirks = &quirk_unknown;
456
457 set_quirks();
458}
459
460/*
461 * General interface convenience methods
462 */
463
464static bool has_cap(u32 cap)
465{
466 if ((interface->capability & cap) != 0)
467 return 1;
468
469 return 0;
470}
471
472/*
473 * AMW0 (V1) interface
474 */
475struct wmab_args {
476 u32 eax;
477 u32 ebx;
478 u32 ecx;
479 u32 edx;
480};
481
482struct wmab_ret {
483 u32 eax;
484 u32 ebx;
485 u32 ecx;
486 u32 edx;
487 u32 eex;
488};
489
490static acpi_status wmab_execute(struct wmab_args *regbuf,
491struct acpi_buffer *result)
492{
493 struct acpi_buffer input;
494 acpi_status status;
495 input.length = sizeof(struct wmab_args);
496 input.pointer = (u8 *)regbuf;
497
498 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
499
500 return status;
501}
502
503static acpi_status AMW0_get_u32(u32 *value, u32 cap,
504struct wmi_interface *iface)
505{
506 int err;
507 u8 result;
508
509 switch (cap) {
510 case ACER_CAP_MAILLED:
511 switch (quirks->mailled) {
512 default:
513 err = ec_read(0xA, &result);
514 if (err)
515 return AE_ERROR;
516 *value = (result >> 7) & 0x1;
517 return AE_OK;
518 }
519 break;
520 case ACER_CAP_WIRELESS:
521 switch (quirks->wireless) {
522 case 1:
523 err = ec_read(0x7B, &result);
524 if (err)
525 return AE_ERROR;
526 *value = result & 0x1;
527 return AE_OK;
Carlos Corbacho6f061ab2008-06-21 09:09:38 +0100528 case 2:
529 err = ec_read(0x71, &result);
530 if (err)
531 return AE_ERROR;
532 *value = result & 0x1;
533 return AE_OK;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000534 default:
535 err = ec_read(0xA, &result);
536 if (err)
537 return AE_ERROR;
538 *value = (result >> 2) & 0x1;
539 return AE_OK;
540 }
541 break;
542 case ACER_CAP_BLUETOOTH:
543 switch (quirks->bluetooth) {
544 default:
545 err = ec_read(0xA, &result);
546 if (err)
547 return AE_ERROR;
548 *value = (result >> 4) & 0x1;
549 return AE_OK;
550 }
551 break;
552 case ACER_CAP_BRIGHTNESS:
553 switch (quirks->brightness) {
554 default:
555 err = ec_read(0x83, &result);
556 if (err)
557 return AE_ERROR;
558 *value = result;
559 return AE_OK;
560 }
561 break;
562 default:
Lin Ming08237972008-08-08 11:57:11 +0800563 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000564 }
565 return AE_OK;
566}
567
568static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
569{
570 struct wmab_args args;
571
572 args.eax = ACER_AMW0_WRITE;
573 args.ebx = value ? (1<<8) : 0;
574 args.ecx = args.edx = 0;
575
576 switch (cap) {
577 case ACER_CAP_MAILLED:
578 if (value > 1)
579 return AE_BAD_PARAMETER;
580 args.ebx |= ACER_AMW0_MAILLED_MASK;
581 break;
582 case ACER_CAP_WIRELESS:
583 if (value > 1)
584 return AE_BAD_PARAMETER;
585 args.ebx |= ACER_AMW0_WIRELESS_MASK;
586 break;
587 case ACER_CAP_BLUETOOTH:
588 if (value > 1)
589 return AE_BAD_PARAMETER;
590 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
591 break;
592 case ACER_CAP_BRIGHTNESS:
593 if (value > max_brightness)
594 return AE_BAD_PARAMETER;
595 switch (quirks->brightness) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000596 default:
Carlos Corbacho4609d022008-02-08 23:51:49 +0000597 return ec_write(0x83, value);
598 break;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000599 }
600 default:
Lin Ming08237972008-08-08 11:57:11 +0800601 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000602 }
603
604 /* Actually do the set */
605 return wmab_execute(&args, NULL);
606}
607
608static acpi_status AMW0_find_mailled(void)
609{
610 struct wmab_args args;
611 struct wmab_ret ret;
612 acpi_status status = AE_OK;
613 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
614 union acpi_object *obj;
615
616 args.eax = 0x86;
617 args.ebx = args.ecx = args.edx = 0;
618
619 status = wmab_execute(&args, &out);
620 if (ACPI_FAILURE(status))
621 return status;
622
623 obj = (union acpi_object *) out.pointer;
624 if (obj && obj->type == ACPI_TYPE_BUFFER &&
625 obj->buffer.length == sizeof(struct wmab_ret)) {
626 ret = *((struct wmab_ret *) obj->buffer.pointer);
627 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700628 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000629 return AE_ERROR;
630 }
631
632 if (ret.eex & 0x1)
633 interface->capability |= ACER_CAP_MAILLED;
634
635 kfree(out.pointer);
636
637 return AE_OK;
638}
639
640static acpi_status AMW0_set_capabilities(void)
641{
642 struct wmab_args args;
643 struct wmab_ret ret;
Axel Lin7677fbd2010-07-20 15:19:53 -0700644 acpi_status status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000645 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
646 union acpi_object *obj;
647
Carlos Corbacho5753dd52008-06-21 09:09:48 +0100648 /*
649 * On laptops with this strange GUID (non Acer), normal probing doesn't
650 * work.
651 */
652 if (wmi_has_guid(AMW0_GUID2)) {
653 interface->capability |= ACER_CAP_WIRELESS;
654 return AE_OK;
655 }
656
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000657 args.eax = ACER_AMW0_WRITE;
658 args.ecx = args.edx = 0;
659
660 args.ebx = 0xa2 << 8;
661 args.ebx |= ACER_AMW0_WIRELESS_MASK;
662
663 status = wmab_execute(&args, &out);
664 if (ACPI_FAILURE(status))
665 return status;
666
Axel Lin7677fbd2010-07-20 15:19:53 -0700667 obj = out.pointer;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000668 if (obj && obj->type == ACPI_TYPE_BUFFER &&
669 obj->buffer.length == sizeof(struct wmab_ret)) {
670 ret = *((struct wmab_ret *) obj->buffer.pointer);
671 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700672 status = AE_ERROR;
673 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000674 }
675
676 if (ret.eax & 0x1)
677 interface->capability |= ACER_CAP_WIRELESS;
678
679 args.ebx = 2 << 8;
680 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
681
Axel Lin7677fbd2010-07-20 15:19:53 -0700682 /*
683 * It's ok to use existing buffer for next wmab_execute call.
684 * But we need to kfree(out.pointer) if next wmab_execute fail.
685 */
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000686 status = wmab_execute(&args, &out);
687 if (ACPI_FAILURE(status))
Axel Lin7677fbd2010-07-20 15:19:53 -0700688 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000689
690 obj = (union acpi_object *) out.pointer;
691 if (obj && obj->type == ACPI_TYPE_BUFFER
692 && obj->buffer.length == sizeof(struct wmab_ret)) {
693 ret = *((struct wmab_ret *) obj->buffer.pointer);
694 } else {
Axel Lin7677fbd2010-07-20 15:19:53 -0700695 status = AE_ERROR;
696 goto out;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000697 }
698
699 if (ret.eax & 0x1)
700 interface->capability |= ACER_CAP_BLUETOOTH;
701
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000702 /*
703 * This appears to be safe to enable, since all Wistron based laptops
704 * appear to use the same EC register for brightness, even if they
705 * differ for wireless, etc
706 */
Carlos Corbacho9991d9f2008-06-21 09:09:22 +0100707 if (quirks->brightness >= 0)
708 interface->capability |= ACER_CAP_BRIGHTNESS;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000709
Axel Lin7677fbd2010-07-20 15:19:53 -0700710 status = AE_OK;
711out:
712 kfree(out.pointer);
713 return status;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000714}
715
716static struct wmi_interface AMW0_interface = {
717 .type = ACER_AMW0,
718};
719
720static struct wmi_interface AMW0_V2_interface = {
721 .type = ACER_AMW0_V2,
722};
723
724/*
725 * New interface (The WMID interface)
726 */
727static acpi_status
728WMI_execute_u32(u32 method_id, u32 in, u32 *out)
729{
730 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
731 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
732 union acpi_object *obj;
733 u32 tmp;
734 acpi_status status;
735
736 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
737
738 if (ACPI_FAILURE(status))
739 return status;
740
741 obj = (union acpi_object *) result.pointer;
742 if (obj && obj->type == ACPI_TYPE_BUFFER &&
743 obj->buffer.length == sizeof(u32)) {
744 tmp = *((u32 *) obj->buffer.pointer);
745 } else {
746 tmp = 0;
747 }
748
749 if (out)
750 *out = tmp;
751
752 kfree(result.pointer);
753
754 return status;
755}
756
757static acpi_status WMID_get_u32(u32 *value, u32 cap,
758struct wmi_interface *iface)
759{
760 acpi_status status;
761 u8 tmp;
762 u32 result, method_id = 0;
763
764 switch (cap) {
765 case ACER_CAP_WIRELESS:
766 method_id = ACER_WMID_GET_WIRELESS_METHODID;
767 break;
768 case ACER_CAP_BLUETOOTH:
769 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
770 break;
771 case ACER_CAP_BRIGHTNESS:
772 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
773 break;
774 case ACER_CAP_THREEG:
775 method_id = ACER_WMID_GET_THREEG_METHODID;
776 break;
777 case ACER_CAP_MAILLED:
778 if (quirks->mailled == 1) {
779 ec_read(0x9f, &tmp);
780 *value = tmp & 0x1;
781 return 0;
782 }
783 default:
Lin Ming08237972008-08-08 11:57:11 +0800784 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000785 }
786 status = WMI_execute_u32(method_id, 0, &result);
787
788 if (ACPI_SUCCESS(status))
789 *value = (u8)result;
790
791 return status;
792}
793
794static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
795{
796 u32 method_id = 0;
797 char param;
798
799 switch (cap) {
800 case ACER_CAP_BRIGHTNESS:
801 if (value > max_brightness)
802 return AE_BAD_PARAMETER;
803 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
804 break;
805 case ACER_CAP_WIRELESS:
806 if (value > 1)
807 return AE_BAD_PARAMETER;
808 method_id = ACER_WMID_SET_WIRELESS_METHODID;
809 break;
810 case ACER_CAP_BLUETOOTH:
811 if (value > 1)
812 return AE_BAD_PARAMETER;
813 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
814 break;
815 case ACER_CAP_THREEG:
816 if (value > 1)
817 return AE_BAD_PARAMETER;
818 method_id = ACER_WMID_SET_THREEG_METHODID;
819 break;
820 case ACER_CAP_MAILLED:
821 if (value > 1)
822 return AE_BAD_PARAMETER;
823 if (quirks->mailled == 1) {
824 param = value ? 0x92 : 0x93;
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700825 i8042_lock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000826 i8042_command(&param, 0x1059);
Dmitry Torokhov181d6832009-09-16 01:06:43 -0700827 i8042_unlock_chip();
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000828 return 0;
829 }
830 break;
831 default:
Lin Ming08237972008-08-08 11:57:11 +0800832 return AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000833 }
834 return WMI_execute_u32(method_id, (u32)value, NULL);
835}
836
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800837static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
838{
839 struct hotkey_function_type_aa *type_aa;
840
841 /* We are looking for OEM-specific Type AAh */
842 if (header->type != 0xAA)
843 return;
844
845 has_type_aa = true;
846 type_aa = (struct hotkey_function_type_aa *) header;
847
848 printk(ACER_INFO "Function bitmap for Communication Button: 0x%x\n",
849 type_aa->commun_func_bitmap);
850
851 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
852 interface->capability |= ACER_CAP_WIRELESS;
853 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
854 interface->capability |= ACER_CAP_THREEG;
855 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
856 interface->capability |= ACER_CAP_BLUETOOTH;
857}
858
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000859static acpi_status WMID_set_capabilities(void)
860{
861 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
862 union acpi_object *obj;
863 acpi_status status;
864 u32 devices;
865
866 status = wmi_query_block(WMID_GUID2, 1, &out);
867 if (ACPI_FAILURE(status))
868 return status;
869
870 obj = (union acpi_object *) out.pointer;
871 if (obj && obj->type == ACPI_TYPE_BUFFER &&
872 obj->buffer.length == sizeof(u32)) {
873 devices = *((u32 *) obj->buffer.pointer);
874 } else {
Axel Lin66904862010-07-20 15:19:52 -0700875 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000876 return AE_ERROR;
877 }
878
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800879 dmi_walk(type_aa_dmi_decode, NULL);
880 if (!has_type_aa) {
881 interface->capability |= ACER_CAP_WIRELESS;
882 interface->capability |= ACER_CAP_THREEG;
883 if (devices & 0x10)
884 interface->capability |= ACER_CAP_BLUETOOTH;
885 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000886
887 /* WMID always provides brightness methods */
888 interface->capability |= ACER_CAP_BRIGHTNESS;
889
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000890 if (!(devices & 0x20))
891 max_brightness = 0x9;
892
Axel Lin66904862010-07-20 15:19:52 -0700893 kfree(out.pointer);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000894 return status;
895}
896
897static struct wmi_interface wmid_interface = {
898 .type = ACER_WMID,
899};
900
901/*
902 * Generic Device (interface-independent)
903 */
904
905static acpi_status get_u32(u32 *value, u32 cap)
906{
Lin Ming08237972008-08-08 11:57:11 +0800907 acpi_status status = AE_ERROR;
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000908
909 switch (interface->type) {
910 case ACER_AMW0:
911 status = AMW0_get_u32(value, cap, interface);
912 break;
913 case ACER_AMW0_V2:
914 if (cap == ACER_CAP_MAILLED) {
915 status = AMW0_get_u32(value, cap, interface);
916 break;
917 }
918 case ACER_WMID:
919 status = WMID_get_u32(value, cap, interface);
920 break;
921 }
922
923 return status;
924}
925
926static acpi_status set_u32(u32 value, u32 cap)
927{
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100928 acpi_status status;
929
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000930 if (interface->capability & cap) {
931 switch (interface->type) {
932 case ACER_AMW0:
933 return AMW0_set_u32(value, cap, interface);
934 case ACER_AMW0_V2:
Carlos Corbacho5c742b42008-08-06 19:13:56 +0100935 if (cap == ACER_CAP_MAILLED)
936 return AMW0_set_u32(value, cap, interface);
937
938 /*
939 * On some models, some WMID methods don't toggle
940 * properly. For those cases, we want to run the AMW0
941 * method afterwards to be certain we've really toggled
942 * the device state.
943 */
944 if (cap == ACER_CAP_WIRELESS ||
945 cap == ACER_CAP_BLUETOOTH) {
946 status = WMID_set_u32(value, cap, interface);
947 if (ACPI_FAILURE(status))
948 return status;
949
950 return AMW0_set_u32(value, cap, interface);
951 }
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000952 case ACER_WMID:
953 return WMID_set_u32(value, cap, interface);
954 default:
955 return AE_BAD_PARAMETER;
956 }
957 }
958 return AE_BAD_PARAMETER;
959}
960
961static void __init acer_commandline_init(void)
962{
963 /*
964 * These will all fail silently if the value given is invalid, or the
965 * capability isn't available on the given interface
966 */
967 set_u32(mailled, ACER_CAP_MAILLED);
Lee, Chun-Yi6c3df882010-12-07 10:29:23 +0800968 if (!has_type_aa)
969 set_u32(threeg, ACER_CAP_THREEG);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000970 set_u32(brightness, ACER_CAP_BRIGHTNESS);
971}
972
973/*
974 * LED device (Mail LED only, no other LEDs known yet)
975 */
976static void mail_led_set(struct led_classdev *led_cdev,
977enum led_brightness value)
978{
979 set_u32(value, ACER_CAP_MAILLED);
980}
981
982static struct led_classdev mail_led = {
Carlos Corbacho343c0042008-02-24 13:34:18 +0000983 .name = "acer-wmi::mail",
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000984 .brightness_set = mail_led_set,
985};
986
Sam Ravnborg7560e382008-02-17 13:22:54 +0100987static int __devinit acer_led_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000988{
989 return led_classdev_register(dev, &mail_led);
990}
991
992static void acer_led_exit(void)
993{
Pali Rohár9a0b74f2011-02-26 21:18:58 +0100994 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +0000995 led_classdev_unregister(&mail_led);
996}
997
998/*
999 * Backlight device
1000 */
1001static struct backlight_device *acer_backlight_device;
1002
1003static int read_brightness(struct backlight_device *bd)
1004{
1005 u32 value;
1006 get_u32(&value, ACER_CAP_BRIGHTNESS);
1007 return value;
1008}
1009
1010static int update_bl_status(struct backlight_device *bd)
1011{
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001012 int intensity = bd->props.brightness;
1013
1014 if (bd->props.power != FB_BLANK_UNBLANK)
1015 intensity = 0;
1016 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1017 intensity = 0;
1018
1019 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1020
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001021 return 0;
1022}
1023
Lionel Debrouxacc24722010-11-16 14:14:02 +01001024static const struct backlight_ops acer_bl_ops = {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001025 .get_brightness = read_brightness,
1026 .update_status = update_bl_status,
1027};
1028
Sam Ravnborg7560e382008-02-17 13:22:54 +01001029static int __devinit acer_backlight_init(struct device *dev)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001030{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001031 struct backlight_properties props;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001032 struct backlight_device *bd;
1033
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001034 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001035 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001036 props.max_brightness = max_brightness;
1037 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1038 &props);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001039 if (IS_ERR(bd)) {
1040 printk(ACER_ERR "Could not register Acer backlight device\n");
1041 acer_backlight_device = NULL;
1042 return PTR_ERR(bd);
1043 }
1044
1045 acer_backlight_device = bd;
1046
Carlos Corbachof2b585b2008-06-21 09:09:27 +01001047 bd->props.power = FB_BLANK_UNBLANK;
Carlos Corbacho6f6ef822009-12-26 19:24:31 +00001048 bd->props.brightness = read_brightness(bd);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001049 backlight_update_status(bd);
1050 return 0;
1051}
1052
Sam Ravnborg7560e382008-02-17 13:22:54 +01001053static void acer_backlight_exit(void)
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001054{
1055 backlight_device_unregister(acer_backlight_device);
1056}
1057
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001058static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1059{
1060 struct wmid3_gds_return_value return_value;
1061 acpi_status status;
1062 union acpi_object *obj;
1063 struct wmid3_gds_input_param params = {
1064 .function_num = 0x1,
1065 .hotkey_number = 0x01,
1066 .devices = device,
1067 };
1068 struct acpi_buffer input = {
1069 sizeof(struct wmid3_gds_input_param),
1070 &params
1071 };
1072 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1073
1074 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1075 if (ACPI_FAILURE(status))
1076 return status;
1077
1078 obj = output.pointer;
1079
1080 if (!obj)
1081 return AE_ERROR;
1082 else if (obj->type != ACPI_TYPE_BUFFER) {
1083 kfree(obj);
1084 return AE_ERROR;
1085 }
1086 if (obj->buffer.length != 8) {
1087 printk(ACER_WARNING "Unknown buffer length %d\n",
1088 obj->buffer.length);
1089 kfree(obj);
1090 return AE_ERROR;
1091 }
1092
1093 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1094 kfree(obj);
1095
1096 if (return_value.error_code || return_value.ec_return_value)
1097 printk(ACER_WARNING "Get Device Status failed: "
1098 "0x%x - 0x%x\n", return_value.error_code,
1099 return_value.ec_return_value);
1100 else
1101 *value = !!(return_value.devices & device);
1102
1103 return status;
1104}
1105
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001106static acpi_status get_device_status(u32 *value, u32 cap)
1107{
1108 if (wmi_has_guid(WMID_GUID3)) {
1109 u16 device;
1110
1111 switch (cap) {
1112 case ACER_CAP_WIRELESS:
1113 device = ACER_WMID3_GDS_WIRELESS;
1114 break;
1115 case ACER_CAP_BLUETOOTH:
1116 device = ACER_WMID3_GDS_BLUETOOTH;
1117 break;
1118 case ACER_CAP_THREEG:
1119 device = ACER_WMID3_GDS_THREEG;
1120 break;
1121 default:
1122 return AE_ERROR;
1123 }
1124 return wmid3_get_device_status(value, device);
1125
1126 } else {
1127 return get_u32(value, cap);
1128 }
1129}
1130
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001131/*
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001132 * Rfkill devices
1133 */
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001134static void acer_rfkill_update(struct work_struct *ignored);
1135static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1136static void acer_rfkill_update(struct work_struct *ignored)
1137{
1138 u32 state;
1139 acpi_status status;
1140
1141 status = get_u32(&state, ACER_CAP_WIRELESS);
1142 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001143 rfkill_set_sw_state(wireless_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001144
1145 if (has_cap(ACER_CAP_BLUETOOTH)) {
1146 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1147 if (ACPI_SUCCESS(status))
Troy Mourea8784172009-06-17 11:51:56 +01001148 rfkill_set_sw_state(bluetooth_rfkill, !state);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001149 }
1150
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001151 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1152 status = wmid3_get_device_status(&state,
1153 ACER_WMID3_GDS_THREEG);
1154 if (ACPI_SUCCESS(status))
1155 rfkill_set_sw_state(threeg_rfkill, !state);
1156 }
1157
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001158 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001159}
1160
Johannes Berg19d337d2009-06-02 13:01:37 +02001161static int acer_rfkill_set(void *data, bool blocked)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001162{
1163 acpi_status status;
Johannes Berg19d337d2009-06-02 13:01:37 +02001164 u32 cap = (unsigned long)data;
Alan Jenkinsed5c8ef2009-07-19 09:48:28 +01001165 status = set_u32(!blocked, cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001166 if (ACPI_FAILURE(status))
1167 return -ENODEV;
1168 return 0;
1169}
1170
Johannes Berg19d337d2009-06-02 13:01:37 +02001171static const struct rfkill_ops acer_rfkill_ops = {
1172 .set_block = acer_rfkill_set,
1173};
1174
1175static struct rfkill *acer_rfkill_register(struct device *dev,
1176 enum rfkill_type type,
1177 char *name, u32 cap)
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001178{
1179 int err;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001180 struct rfkill *rfkill_dev;
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001181 u32 state;
1182 acpi_status status;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001183
Johannes Berg19d337d2009-06-02 13:01:37 +02001184 rfkill_dev = rfkill_alloc(name, dev, type,
1185 &acer_rfkill_ops,
1186 (void *)(unsigned long)cap);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001187 if (!rfkill_dev)
1188 return ERR_PTR(-ENOMEM);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001189
Lee, Chun-Yi466449c2010-12-13 10:02:41 +08001190 status = get_device_status(&state, cap);
1191 if (ACPI_SUCCESS(status))
1192 rfkill_init_sw_state(rfkill_dev, !state);
1193
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 }
1199 return rfkill_dev;
1200}
1201
1202static int acer_rfkill_init(struct device *dev)
1203{
1204 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1205 "acer-wireless", ACER_CAP_WIRELESS);
1206 if (IS_ERR(wireless_rfkill))
1207 return PTR_ERR(wireless_rfkill);
1208
1209 if (has_cap(ACER_CAP_BLUETOOTH)) {
1210 bluetooth_rfkill = acer_rfkill_register(dev,
1211 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1212 ACER_CAP_BLUETOOTH);
1213 if (IS_ERR(bluetooth_rfkill)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001214 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001215 rfkill_destroy(wireless_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001216 return PTR_ERR(bluetooth_rfkill);
1217 }
1218 }
1219
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001220 if (has_cap(ACER_CAP_THREEG)) {
1221 threeg_rfkill = acer_rfkill_register(dev,
1222 RFKILL_TYPE_WWAN, "acer-threeg",
1223 ACER_CAP_THREEG);
1224 if (IS_ERR(threeg_rfkill)) {
1225 rfkill_unregister(wireless_rfkill);
1226 rfkill_destroy(wireless_rfkill);
1227 rfkill_unregister(bluetooth_rfkill);
1228 rfkill_destroy(bluetooth_rfkill);
1229 return PTR_ERR(threeg_rfkill);
1230 }
1231 }
1232
Carlos Corbachoae3a1b42008-10-10 17:33:35 +01001233 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001234
1235 return 0;
1236}
1237
1238static void acer_rfkill_exit(void)
1239{
1240 cancel_delayed_work_sync(&acer_rfkill_work);
Johannes Berg19d337d2009-06-02 13:01:37 +02001241
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001242 rfkill_unregister(wireless_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001243 rfkill_destroy(wireless_rfkill);
1244
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001245 if (has_cap(ACER_CAP_BLUETOOTH)) {
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001246 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +02001247 rfkill_destroy(bluetooth_rfkill);
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001248 }
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001249
1250 if (has_cap(ACER_CAP_THREEG)) {
1251 rfkill_unregister(threeg_rfkill);
1252 rfkill_destroy(threeg_rfkill);
1253 }
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001254 return;
1255}
1256
1257/*
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001258 * sysfs interface
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001259 */
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001260static ssize_t show_bool_threeg(struct device *dev,
1261 struct device_attribute *attr, char *buf)
1262{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001263 u32 result; \
Lee, Chun-Yib3c90922010-12-07 10:29:22 +08001264 acpi_status status;
1265 if (wmi_has_guid(WMID_GUID3))
1266 status = wmid3_get_device_status(&result,
1267 ACER_WMID3_GDS_THREEG);
1268 else
1269 status = get_u32(&result, ACER_CAP_THREEG);
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001270 if (ACPI_SUCCESS(status))
1271 return sprintf(buf, "%u\n", result);
1272 return sprintf(buf, "Read error\n");
1273}
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001274
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001275static ssize_t set_bool_threeg(struct device *dev,
1276 struct device_attribute *attr, const char *buf, size_t count)
1277{
1278 u32 tmp = simple_strtoul(buf, NULL, 10);
1279 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1280 if (ACPI_FAILURE(status))
1281 return -EINVAL;
1282 return count;
1283}
Vasiliy Kulikovb80b1682011-02-04 15:23:56 +03001284static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
Carlos Corbacho7d9a06d2008-10-08 21:40:26 +01001285 set_bool_threeg);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001286
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001287static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1288 char *buf)
1289{
1290 switch (interface->type) {
1291 case ACER_AMW0:
1292 return sprintf(buf, "AMW0\n");
1293 case ACER_AMW0_V2:
1294 return sprintf(buf, "AMW0 v2\n");
1295 case ACER_WMID:
1296 return sprintf(buf, "WMID\n");
1297 default:
1298 return sprintf(buf, "Error!\n");
1299 }
1300}
1301
Axel Lin370525d2010-06-30 10:20:23 +08001302static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001303
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001304static void acer_wmi_notify(u32 value, void *context)
1305{
1306 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1307 union acpi_object *obj;
1308 struct event_return_value return_value;
1309 acpi_status status;
1310
1311 status = wmi_get_event_data(value, &response);
1312 if (status != AE_OK) {
1313 printk(ACER_WARNING "bad event status 0x%x\n", status);
1314 return;
1315 }
1316
1317 obj = (union acpi_object *)response.pointer;
1318
1319 if (!obj)
1320 return;
1321 if (obj->type != ACPI_TYPE_BUFFER) {
1322 printk(ACER_WARNING "Unknown response received %d\n",
1323 obj->type);
1324 kfree(obj);
1325 return;
1326 }
1327 if (obj->buffer.length != 8) {
1328 printk(ACER_WARNING "Unknown buffer length %d\n",
1329 obj->buffer.length);
1330 kfree(obj);
1331 return;
1332 }
1333
1334 return_value = *((struct event_return_value *)obj->buffer.pointer);
1335 kfree(obj);
1336
1337 switch (return_value.function) {
1338 case WMID_HOTKEY_EVENT:
1339 if (!sparse_keymap_report_event(acer_wmi_input_dev,
1340 return_value.key_num, 1, true))
1341 printk(ACER_WARNING "Unknown key number - 0x%x\n",
1342 return_value.key_num);
1343 break;
1344 default:
1345 printk(ACER_WARNING "Unknown function number - %d - %d\n",
1346 return_value.function, return_value.key_num);
1347 break;
1348 }
1349}
1350
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001351static acpi_status
1352wmid3_set_lm_mode(struct lm_input_params *params,
1353 struct lm_return_value *return_value)
1354{
1355 acpi_status status;
1356 union acpi_object *obj;
1357
1358 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1359 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1360
1361 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1362 if (ACPI_FAILURE(status))
1363 return status;
1364
1365 obj = output.pointer;
1366
1367 if (!obj)
1368 return AE_ERROR;
1369 else if (obj->type != ACPI_TYPE_BUFFER) {
1370 kfree(obj);
1371 return AE_ERROR;
1372 }
1373 if (obj->buffer.length != 4) {
1374 printk(ACER_WARNING "Unknown buffer length %d\n",
1375 obj->buffer.length);
1376 kfree(obj);
1377 return AE_ERROR;
1378 }
1379
1380 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1381 kfree(obj);
1382
1383 return status;
1384}
1385
1386static int acer_wmi_enable_ec_raw(void)
1387{
1388 struct lm_return_value return_value;
1389 acpi_status status;
1390 struct lm_input_params params = {
1391 .function_num = 0x1,
1392 .commun_devices = 0xFFFF,
1393 .devices = 0xFFFF,
1394 .lm_status = 0x00, /* Launch Manager Deactive */
1395 };
1396
1397 status = wmid3_set_lm_mode(&params, &return_value);
1398
1399 if (return_value.error_code || return_value.ec_return_value)
1400 printk(ACER_WARNING "Enabling EC raw mode failed: "
1401 "0x%x - 0x%x\n", return_value.error_code,
1402 return_value.ec_return_value);
1403 else
1404 printk(ACER_INFO "Enabled EC raw mode");
1405
1406 return status;
1407}
1408
1409static int acer_wmi_enable_lm(void)
1410{
1411 struct lm_return_value return_value;
1412 acpi_status status;
1413 struct lm_input_params params = {
1414 .function_num = 0x1,
1415 .commun_devices = 0xFFFF,
1416 .devices = 0xFFFF,
1417 .lm_status = 0x01, /* Launch Manager Active */
1418 };
1419
1420 status = wmid3_set_lm_mode(&params, &return_value);
1421
1422 if (return_value.error_code || return_value.ec_return_value)
1423 printk(ACER_WARNING "Enabling Launch Manager failed: "
1424 "0x%x - 0x%x\n", return_value.error_code,
1425 return_value.ec_return_value);
1426
1427 return status;
1428}
1429
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001430static int __init acer_wmi_input_setup(void)
1431{
1432 acpi_status status;
1433 int err;
1434
1435 acer_wmi_input_dev = input_allocate_device();
1436 if (!acer_wmi_input_dev)
1437 return -ENOMEM;
1438
1439 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1440 acer_wmi_input_dev->phys = "wmi/input0";
1441 acer_wmi_input_dev->id.bustype = BUS_HOST;
1442
1443 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1444 if (err)
1445 goto err_free_dev;
1446
1447 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1448 acer_wmi_notify, NULL);
1449 if (ACPI_FAILURE(status)) {
1450 err = -EIO;
1451 goto err_free_keymap;
1452 }
1453
1454 err = input_register_device(acer_wmi_input_dev);
1455 if (err)
1456 goto err_uninstall_notifier;
1457
1458 return 0;
1459
1460err_uninstall_notifier:
1461 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1462err_free_keymap:
1463 sparse_keymap_free(acer_wmi_input_dev);
1464err_free_dev:
1465 input_free_device(acer_wmi_input_dev);
1466 return err;
1467}
1468
1469static void acer_wmi_input_destroy(void)
1470{
1471 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1472 sparse_keymap_free(acer_wmi_input_dev);
1473 input_unregister_device(acer_wmi_input_dev);
1474}
1475
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001476/*
Carlos Corbacho81143522008-06-21 09:09:53 +01001477 * debugfs functions
1478 */
1479static u32 get_wmid_devices(void)
1480{
1481 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1482 union acpi_object *obj;
1483 acpi_status status;
Axel Lin66904862010-07-20 15:19:52 -07001484 u32 devices = 0;
Carlos Corbacho81143522008-06-21 09:09:53 +01001485
1486 status = wmi_query_block(WMID_GUID2, 1, &out);
1487 if (ACPI_FAILURE(status))
1488 return 0;
1489
1490 obj = (union acpi_object *) out.pointer;
1491 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1492 obj->buffer.length == sizeof(u32)) {
Axel Lin66904862010-07-20 15:19:52 -07001493 devices = *((u32 *) obj->buffer.pointer);
Carlos Corbacho81143522008-06-21 09:09:53 +01001494 }
Axel Lin66904862010-07-20 15:19:52 -07001495
1496 kfree(out.pointer);
1497 return devices;
Carlos Corbacho81143522008-06-21 09:09:53 +01001498}
1499
1500/*
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001501 * Platform device
1502 */
1503static int __devinit acer_platform_probe(struct platform_device *device)
1504{
1505 int err;
1506
1507 if (has_cap(ACER_CAP_MAILLED)) {
1508 err = acer_led_init(&device->dev);
1509 if (err)
1510 goto error_mailled;
1511 }
1512
1513 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1514 err = acer_backlight_init(&device->dev);
1515 if (err)
1516 goto error_brightness;
1517 }
1518
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001519 err = acer_rfkill_init(&device->dev);
Andy Whitcroft350e3292009-04-04 09:33:34 +01001520 if (err)
1521 goto error_rfkill;
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001522
1523 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001524
Andy Whitcroft350e3292009-04-04 09:33:34 +01001525error_rfkill:
1526 if (has_cap(ACER_CAP_BRIGHTNESS))
1527 acer_backlight_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001528error_brightness:
Andy Whitcroft350e3292009-04-04 09:33:34 +01001529 if (has_cap(ACER_CAP_MAILLED))
1530 acer_led_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001531error_mailled:
1532 return err;
1533}
1534
1535static int acer_platform_remove(struct platform_device *device)
1536{
1537 if (has_cap(ACER_CAP_MAILLED))
1538 acer_led_exit();
1539 if (has_cap(ACER_CAP_BRIGHTNESS))
1540 acer_backlight_exit();
Carlos Corbacho0606e1a2008-10-08 21:40:21 +01001541
1542 acer_rfkill_exit();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001543 return 0;
1544}
1545
1546static int acer_platform_suspend(struct platform_device *dev,
1547pm_message_t state)
1548{
1549 u32 value;
1550 struct acer_data *data = &interface->data;
1551
1552 if (!data)
1553 return -ENOMEM;
1554
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001555 if (has_cap(ACER_CAP_MAILLED)) {
1556 get_u32(&value, ACER_CAP_MAILLED);
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001557 set_u32(LED_OFF, ACER_CAP_MAILLED);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001558 data->mailled = value;
1559 }
1560
1561 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1562 get_u32(&value, ACER_CAP_BRIGHTNESS);
1563 data->brightness = value;
1564 }
1565
1566 return 0;
1567}
1568
1569static int acer_platform_resume(struct platform_device *device)
1570{
1571 struct acer_data *data = &interface->data;
1572
1573 if (!data)
1574 return -ENOMEM;
1575
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001576 if (has_cap(ACER_CAP_MAILLED))
1577 set_u32(data->mailled, ACER_CAP_MAILLED);
1578
1579 if (has_cap(ACER_CAP_BRIGHTNESS))
1580 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1581
1582 return 0;
1583}
1584
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001585static void acer_platform_shutdown(struct platform_device *device)
1586{
1587 struct acer_data *data = &interface->data;
1588
1589 if (!data)
1590 return;
1591
1592 if (has_cap(ACER_CAP_MAILLED))
1593 set_u32(LED_OFF, ACER_CAP_MAILLED);
1594}
1595
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001596static struct platform_driver acer_platform_driver = {
1597 .driver = {
1598 .name = "acer-wmi",
1599 .owner = THIS_MODULE,
1600 },
1601 .probe = acer_platform_probe,
1602 .remove = acer_platform_remove,
1603 .suspend = acer_platform_suspend,
1604 .resume = acer_platform_resume,
Pali Rohár9a0b74f2011-02-26 21:18:58 +01001605 .shutdown = acer_platform_shutdown,
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001606};
1607
1608static struct platform_device *acer_platform_device;
1609
1610static int remove_sysfs(struct platform_device *device)
1611{
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001612 if (has_cap(ACER_CAP_THREEG))
1613 device_remove_file(&device->dev, &dev_attr_threeg);
1614
1615 device_remove_file(&device->dev, &dev_attr_interface);
1616
1617 return 0;
1618}
1619
1620static int create_sysfs(void)
1621{
1622 int retval = -ENOMEM;
1623
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001624 if (has_cap(ACER_CAP_THREEG)) {
1625 retval = device_create_file(&acer_platform_device->dev,
1626 &dev_attr_threeg);
1627 if (retval)
1628 goto error_sysfs;
1629 }
1630
1631 retval = device_create_file(&acer_platform_device->dev,
1632 &dev_attr_interface);
1633 if (retval)
1634 goto error_sysfs;
1635
1636 return 0;
1637
1638error_sysfs:
1639 remove_sysfs(acer_platform_device);
1640 return retval;
1641}
1642
Carlos Corbacho81143522008-06-21 09:09:53 +01001643static void remove_debugfs(void)
1644{
1645 debugfs_remove(interface->debug.devices);
1646 debugfs_remove(interface->debug.root);
1647}
1648
1649static int create_debugfs(void)
1650{
1651 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1652 if (!interface->debug.root) {
1653 printk(ACER_ERR "Failed to create debugfs directory");
1654 return -ENOMEM;
1655 }
1656
1657 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1658 interface->debug.root,
1659 &interface->debug.wmid_devices);
1660 if (!interface->debug.devices)
1661 goto error_debugfs;
1662
1663 return 0;
1664
1665error_debugfs:
Russ Dill39dbbb42008-09-02 14:35:40 -07001666 remove_debugfs();
Carlos Corbacho81143522008-06-21 09:09:53 +01001667 return -ENOMEM;
1668}
1669
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001670static int __init acer_wmi_init(void)
1671{
1672 int err;
1673
Carlos Corbacho860f0c62008-06-21 09:09:58 +01001674 printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001675
Carlos Corbachoa74dd5f2009-04-04 09:33:29 +01001676 if (dmi_check_system(acer_blacklist)) {
1677 printk(ACER_INFO "Blacklisted hardware detected - "
1678 "not loading\n");
1679 return -ENODEV;
1680 }
1681
Carlos Corbacho9991d9f2008-06-21 09:09:22 +01001682 find_quirks();
1683
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001684 /*
1685 * Detect which ACPI-WMI interface we're using.
1686 */
1687 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1688 interface = &AMW0_V2_interface;
1689
1690 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1691 interface = &wmid_interface;
1692
1693 if (wmi_has_guid(WMID_GUID2) && interface) {
1694 if (ACPI_FAILURE(WMID_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001695 printk(ACER_ERR "Unable to detect available WMID "
1696 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001697 return -ENODEV;
1698 }
1699 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001700 printk(ACER_ERR "No WMID device detection method found\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001701 return -ENODEV;
1702 }
1703
1704 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1705 interface = &AMW0_interface;
1706
1707 if (ACPI_FAILURE(AMW0_set_capabilities())) {
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001708 printk(ACER_ERR "Unable to detect available AMW0 "
1709 "devices\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001710 return -ENODEV;
1711 }
1712 }
1713
Carlos Corbacho9b963c42008-02-24 13:34:29 +00001714 if (wmi_has_guid(AMW0_GUID1))
1715 AMW0_find_mailled();
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001716
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001717 if (!interface) {
Pascal de Bruijnaf9902e2010-08-30 09:09:53 +02001718 printk(ACER_INFO "No or unsupported WMI interface, unable to "
Carlos Corbacho8d039bc2008-03-12 20:12:50 +00001719 "load\n");
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001720 return -ENODEV;
1721 }
1722
Arjan van de Ven83097ac2008-08-23 21:45:21 -07001723 set_quirks();
1724
Michael Spang1ba869e2009-03-12 14:31:34 -07001725 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
Thomas Renningerfebf2d92008-08-01 17:37:56 +02001726 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1727 printk(ACER_INFO "Brightness must be controlled by "
1728 "generic video driver\n");
1729 }
1730
From: Lee, Chun-Yi59ccf2f2011-01-07 17:25:14 -05001731 if (wmi_has_guid(WMID_GUID3)) {
1732 if (ec_raw_mode) {
1733 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
1734 printk(ACER_ERR "Cannot enable EC raw mode\n");
1735 return -ENODEV;
1736 }
1737 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
1738 printk(ACER_ERR "Cannot enable Launch Manager mode\n");
1739 return -ENODEV;
1740 }
1741 } else if (ec_raw_mode) {
1742 printk(ACER_INFO "No WMID EC raw mode enable method\n");
1743 }
1744
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001745 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1746 err = acer_wmi_input_setup();
1747 if (err)
1748 return err;
1749 }
1750
Axel Lin1c796322010-06-22 16:17:38 +08001751 err = platform_driver_register(&acer_platform_driver);
1752 if (err) {
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001753 printk(ACER_ERR "Unable to register platform driver.\n");
1754 goto error_platform_register;
1755 }
Axel Lin1c796322010-06-22 16:17:38 +08001756
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001757 acer_platform_device = platform_device_alloc("acer-wmi", -1);
Axel Lin1c796322010-06-22 16:17:38 +08001758 if (!acer_platform_device) {
1759 err = -ENOMEM;
1760 goto error_device_alloc;
1761 }
1762
1763 err = platform_device_add(acer_platform_device);
1764 if (err)
1765 goto error_device_add;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001766
1767 err = create_sysfs();
1768 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001769 goto error_create_sys;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001770
Carlos Corbacho81143522008-06-21 09:09:53 +01001771 if (wmi_has_guid(WMID_GUID2)) {
1772 interface->debug.wmid_devices = get_wmid_devices();
1773 err = create_debugfs();
1774 if (err)
Axel Lin1c796322010-06-22 16:17:38 +08001775 goto error_create_debugfs;
Carlos Corbacho81143522008-06-21 09:09:53 +01001776 }
1777
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001778 /* Override any initial settings with values from the commandline */
1779 acer_commandline_init();
1780
1781 return 0;
1782
Axel Lin1c796322010-06-22 16:17:38 +08001783error_create_debugfs:
1784 remove_sysfs(acer_platform_device);
1785error_create_sys:
1786 platform_device_del(acer_platform_device);
1787error_device_add:
1788 platform_device_put(acer_platform_device);
1789error_device_alloc:
1790 platform_driver_unregister(&acer_platform_driver);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001791error_platform_register:
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001792 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1793 acer_wmi_input_destroy();
1794
Axel Lin1c796322010-06-22 16:17:38 +08001795 return err;
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001796}
1797
1798static void __exit acer_wmi_exit(void)
1799{
Lee, Chun-Yi3fdca872010-12-07 10:29:20 +08001800 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1801 acer_wmi_input_destroy();
1802
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001803 remove_sysfs(acer_platform_device);
Russ Dill39dbbb42008-09-02 14:35:40 -07001804 remove_debugfs();
Axel Lin97ba0af2010-06-03 15:18:03 +08001805 platform_device_unregister(acer_platform_device);
Carlos Corbacho745a5d22008-02-05 02:17:10 +00001806 platform_driver_unregister(&acer_platform_driver);
1807
1808 printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
1809 return;
1810}
1811
1812module_init(acer_wmi_init);
1813module_exit(acer_wmi_exit);