Loading...
1/*
2 * Acer WMI Laptop Extras
3 *
4 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
5 *
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
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/dmi.h>
32#include <linux/fb.h>
33#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>
38#include <linux/rfkill.h>
39#include <linux/workqueue.h>
40#include <linux/debugfs.h>
41#include <linux/slab.h>
42#include <linux/input.h>
43#include <linux/input/sparse-keymap.h>
44
45#include <acpi/acpi_drivers.h>
46
47MODULE_AUTHOR("Carlos Corbacho");
48MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
49MODULE_LICENSE("GPL");
50
51/*
52 * 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"
81#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
82#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
83#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
84#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
85
86/*
87 * Acer ACPI event GUIDs
88 */
89#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
90
91MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
92MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
93MODULE_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, 0x03, {KEY_WLAN} }, /* WiFi */
102 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
103 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
104 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
105 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
106 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
107 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
108 {KE_IGNORE, 0x41, {KEY_MUTE} },
109 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
110 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
111 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
112 {KE_IGNORE, 0x45, {KEY_STOP} },
113 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
114 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
115 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
116 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
117 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
118 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
119 {KE_IGNORE, 0x81, {KEY_SLEEP} },
120 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad On/Off */
121 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
122 {KE_END, 0}
123};
124
125static struct input_dev *acer_wmi_input_dev;
126
127struct event_return_value {
128 u8 function;
129 u8 key_num;
130 u16 device_state;
131 u32 reserved;
132} __attribute__((packed));
133
134/*
135 * GUID3 Get Device Status device flags
136 */
137#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
138#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
139#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
140#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
141
142struct lm_input_params {
143 u8 function_num; /* Function Number */
144 u16 commun_devices; /* Communication type devices default status */
145 u16 devices; /* Other type devices default status */
146 u8 lm_status; /* Launch Manager Status */
147 u16 reserved;
148} __attribute__((packed));
149
150struct lm_return_value {
151 u8 error_code; /* Error Code */
152 u8 ec_return_value; /* EC Return Value */
153 u16 reserved;
154} __attribute__((packed));
155
156struct wmid3_gds_input_param { /* Get Device Status input parameter */
157 u8 function_num; /* Function Number */
158 u8 hotkey_number; /* Hotkey Number */
159 u16 devices; /* Get Device */
160} __attribute__((packed));
161
162struct wmid3_gds_return_value { /* Get Device Status return value*/
163 u8 error_code; /* Error Code */
164 u8 ec_return_value; /* EC Return Value */
165 u16 devices; /* Current Device Status */
166 u32 reserved;
167} __attribute__((packed));
168
169struct hotkey_function_type_aa {
170 u8 type;
171 u8 length;
172 u16 handle;
173 u16 commun_func_bitmap;
174} __attribute__((packed));
175
176/*
177 * Interface capability flags
178 */
179#define ACER_CAP_MAILLED (1<<0)
180#define ACER_CAP_WIRELESS (1<<1)
181#define ACER_CAP_BLUETOOTH (1<<2)
182#define ACER_CAP_BRIGHTNESS (1<<3)
183#define ACER_CAP_THREEG (1<<4)
184#define ACER_CAP_ANY (0xFFFFFFFF)
185
186/*
187 * Interface type flags
188 */
189enum interface_flags {
190 ACER_AMW0,
191 ACER_AMW0_V2,
192 ACER_WMID,
193};
194
195#define ACER_DEFAULT_WIRELESS 0
196#define ACER_DEFAULT_BLUETOOTH 0
197#define ACER_DEFAULT_MAILLED 0
198#define ACER_DEFAULT_THREEG 0
199
200static int max_brightness = 0xF;
201
202static int mailled = -1;
203static int brightness = -1;
204static int threeg = -1;
205static int force_series;
206static bool ec_raw_mode;
207static bool has_type_aa;
208
209module_param(mailled, int, 0444);
210module_param(brightness, int, 0444);
211module_param(threeg, int, 0444);
212module_param(force_series, int, 0444);
213module_param(ec_raw_mode, bool, 0444);
214MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
215MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
216MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
217MODULE_PARM_DESC(force_series, "Force a different laptop series");
218MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
219
220struct acer_data {
221 int mailled;
222 int threeg;
223 int brightness;
224};
225
226struct acer_debug {
227 struct dentry *root;
228 struct dentry *devices;
229 u32 wmid_devices;
230};
231
232static struct rfkill *wireless_rfkill;
233static struct rfkill *bluetooth_rfkill;
234static struct rfkill *threeg_rfkill;
235static bool rfkill_inited;
236
237/* Each low-level interface must define at least some of the following */
238struct wmi_interface {
239 /* The WMI device type */
240 u32 type;
241
242 /* The capabilities this interface provides */
243 u32 capability;
244
245 /* Private data for the current interface */
246 struct acer_data data;
247
248 /* debugfs entries associated with this interface */
249 struct acer_debug debug;
250};
251
252/* The static interface pointer, points to the currently detected interface */
253static struct wmi_interface *interface;
254
255/*
256 * Embedded Controller quirks
257 * Some laptops require us to directly access the EC to either enable or query
258 * features that are not available through WMI.
259 */
260
261struct quirk_entry {
262 u8 wireless;
263 u8 mailled;
264 s8 brightness;
265 u8 bluetooth;
266};
267
268static struct quirk_entry *quirks;
269
270static void set_quirks(void)
271{
272 if (!interface)
273 return;
274
275 if (quirks->mailled)
276 interface->capability |= ACER_CAP_MAILLED;
277
278 if (quirks->brightness)
279 interface->capability |= ACER_CAP_BRIGHTNESS;
280}
281
282static int dmi_matched(const struct dmi_system_id *dmi)
283{
284 quirks = dmi->driver_data;
285 return 1;
286}
287
288static struct quirk_entry quirk_unknown = {
289};
290
291static struct quirk_entry quirk_acer_aspire_1520 = {
292 .brightness = -1,
293};
294
295static struct quirk_entry quirk_acer_travelmate_2490 = {
296 .mailled = 1,
297};
298
299/* This AMW0 laptop has no bluetooth */
300static struct quirk_entry quirk_medion_md_98300 = {
301 .wireless = 1,
302};
303
304static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
305 .wireless = 2,
306};
307
308static struct quirk_entry quirk_lenovo_ideapad_s205 = {
309 .wireless = 3,
310};
311
312/* The Aspire One has a dummy ACPI-WMI interface - disable it */
313static struct dmi_system_id __devinitdata acer_blacklist[] = {
314 {
315 .ident = "Acer Aspire One (SSD)",
316 .matches = {
317 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
318 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
319 },
320 },
321 {
322 .ident = "Acer Aspire One (HDD)",
323 .matches = {
324 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
325 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
326 },
327 },
328 {}
329};
330
331static struct dmi_system_id acer_quirks[] = {
332 {
333 .callback = dmi_matched,
334 .ident = "Acer Aspire 1360",
335 .matches = {
336 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
337 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
338 },
339 .driver_data = &quirk_acer_aspire_1520,
340 },
341 {
342 .callback = dmi_matched,
343 .ident = "Acer Aspire 1520",
344 .matches = {
345 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
346 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
347 },
348 .driver_data = &quirk_acer_aspire_1520,
349 },
350 {
351 .callback = dmi_matched,
352 .ident = "Acer Aspire 3100",
353 .matches = {
354 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
355 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
356 },
357 .driver_data = &quirk_acer_travelmate_2490,
358 },
359 {
360 .callback = dmi_matched,
361 .ident = "Acer Aspire 3610",
362 .matches = {
363 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
364 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
365 },
366 .driver_data = &quirk_acer_travelmate_2490,
367 },
368 {
369 .callback = dmi_matched,
370 .ident = "Acer Aspire 5100",
371 .matches = {
372 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
373 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
374 },
375 .driver_data = &quirk_acer_travelmate_2490,
376 },
377 {
378 .callback = dmi_matched,
379 .ident = "Acer Aspire 5610",
380 .matches = {
381 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
382 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
383 },
384 .driver_data = &quirk_acer_travelmate_2490,
385 },
386 {
387 .callback = dmi_matched,
388 .ident = "Acer Aspire 5630",
389 .matches = {
390 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
391 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
392 },
393 .driver_data = &quirk_acer_travelmate_2490,
394 },
395 {
396 .callback = dmi_matched,
397 .ident = "Acer Aspire 5650",
398 .matches = {
399 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
400 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
401 },
402 .driver_data = &quirk_acer_travelmate_2490,
403 },
404 {
405 .callback = dmi_matched,
406 .ident = "Acer Aspire 5680",
407 .matches = {
408 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
409 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
410 },
411 .driver_data = &quirk_acer_travelmate_2490,
412 },
413 {
414 .callback = dmi_matched,
415 .ident = "Acer Aspire 9110",
416 .matches = {
417 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
419 },
420 .driver_data = &quirk_acer_travelmate_2490,
421 },
422 {
423 .callback = dmi_matched,
424 .ident = "Acer TravelMate 2490",
425 .matches = {
426 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
427 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
428 },
429 .driver_data = &quirk_acer_travelmate_2490,
430 },
431 {
432 .callback = dmi_matched,
433 .ident = "Acer TravelMate 4200",
434 .matches = {
435 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
436 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
437 },
438 .driver_data = &quirk_acer_travelmate_2490,
439 },
440 {
441 .callback = dmi_matched,
442 .ident = "Fujitsu Siemens Amilo Li 1718",
443 .matches = {
444 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
445 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
446 },
447 .driver_data = &quirk_fujitsu_amilo_li_1718,
448 },
449 {
450 .callback = dmi_matched,
451 .ident = "Medion MD 98300",
452 .matches = {
453 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
454 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
455 },
456 .driver_data = &quirk_medion_md_98300,
457 },
458 {
459 .callback = dmi_matched,
460 .ident = "Lenovo Ideapad S205",
461 .matches = {
462 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
463 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
464 },
465 .driver_data = &quirk_lenovo_ideapad_s205,
466 },
467 {}
468};
469
470/* Find which quirks are needed for a particular vendor/ model pair */
471static void find_quirks(void)
472{
473 if (!force_series) {
474 dmi_check_system(acer_quirks);
475 } else if (force_series == 2490) {
476 quirks = &quirk_acer_travelmate_2490;
477 }
478
479 if (quirks == NULL)
480 quirks = &quirk_unknown;
481
482 set_quirks();
483}
484
485/*
486 * General interface convenience methods
487 */
488
489static bool has_cap(u32 cap)
490{
491 if ((interface->capability & cap) != 0)
492 return 1;
493
494 return 0;
495}
496
497/*
498 * AMW0 (V1) interface
499 */
500struct wmab_args {
501 u32 eax;
502 u32 ebx;
503 u32 ecx;
504 u32 edx;
505};
506
507struct wmab_ret {
508 u32 eax;
509 u32 ebx;
510 u32 ecx;
511 u32 edx;
512 u32 eex;
513};
514
515static acpi_status wmab_execute(struct wmab_args *regbuf,
516struct acpi_buffer *result)
517{
518 struct acpi_buffer input;
519 acpi_status status;
520 input.length = sizeof(struct wmab_args);
521 input.pointer = (u8 *)regbuf;
522
523 status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
524
525 return status;
526}
527
528static acpi_status AMW0_get_u32(u32 *value, u32 cap,
529struct wmi_interface *iface)
530{
531 int err;
532 u8 result;
533
534 switch (cap) {
535 case ACER_CAP_MAILLED:
536 switch (quirks->mailled) {
537 default:
538 err = ec_read(0xA, &result);
539 if (err)
540 return AE_ERROR;
541 *value = (result >> 7) & 0x1;
542 return AE_OK;
543 }
544 break;
545 case ACER_CAP_WIRELESS:
546 switch (quirks->wireless) {
547 case 1:
548 err = ec_read(0x7B, &result);
549 if (err)
550 return AE_ERROR;
551 *value = result & 0x1;
552 return AE_OK;
553 case 2:
554 err = ec_read(0x71, &result);
555 if (err)
556 return AE_ERROR;
557 *value = result & 0x1;
558 return AE_OK;
559 case 3:
560 err = ec_read(0x78, &result);
561 if (err)
562 return AE_ERROR;
563 *value = result & 0x1;
564 return AE_OK;
565 default:
566 err = ec_read(0xA, &result);
567 if (err)
568 return AE_ERROR;
569 *value = (result >> 2) & 0x1;
570 return AE_OK;
571 }
572 break;
573 case ACER_CAP_BLUETOOTH:
574 switch (quirks->bluetooth) {
575 default:
576 err = ec_read(0xA, &result);
577 if (err)
578 return AE_ERROR;
579 *value = (result >> 4) & 0x1;
580 return AE_OK;
581 }
582 break;
583 case ACER_CAP_BRIGHTNESS:
584 switch (quirks->brightness) {
585 default:
586 err = ec_read(0x83, &result);
587 if (err)
588 return AE_ERROR;
589 *value = result;
590 return AE_OK;
591 }
592 break;
593 default:
594 return AE_ERROR;
595 }
596 return AE_OK;
597}
598
599static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
600{
601 struct wmab_args args;
602
603 args.eax = ACER_AMW0_WRITE;
604 args.ebx = value ? (1<<8) : 0;
605 args.ecx = args.edx = 0;
606
607 switch (cap) {
608 case ACER_CAP_MAILLED:
609 if (value > 1)
610 return AE_BAD_PARAMETER;
611 args.ebx |= ACER_AMW0_MAILLED_MASK;
612 break;
613 case ACER_CAP_WIRELESS:
614 if (value > 1)
615 return AE_BAD_PARAMETER;
616 args.ebx |= ACER_AMW0_WIRELESS_MASK;
617 break;
618 case ACER_CAP_BLUETOOTH:
619 if (value > 1)
620 return AE_BAD_PARAMETER;
621 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
622 break;
623 case ACER_CAP_BRIGHTNESS:
624 if (value > max_brightness)
625 return AE_BAD_PARAMETER;
626 switch (quirks->brightness) {
627 default:
628 return ec_write(0x83, value);
629 break;
630 }
631 default:
632 return AE_ERROR;
633 }
634
635 /* Actually do the set */
636 return wmab_execute(&args, NULL);
637}
638
639static acpi_status AMW0_find_mailled(void)
640{
641 struct wmab_args args;
642 struct wmab_ret ret;
643 acpi_status status = AE_OK;
644 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
645 union acpi_object *obj;
646
647 args.eax = 0x86;
648 args.ebx = args.ecx = args.edx = 0;
649
650 status = wmab_execute(&args, &out);
651 if (ACPI_FAILURE(status))
652 return status;
653
654 obj = (union acpi_object *) out.pointer;
655 if (obj && obj->type == ACPI_TYPE_BUFFER &&
656 obj->buffer.length == sizeof(struct wmab_ret)) {
657 ret = *((struct wmab_ret *) obj->buffer.pointer);
658 } else {
659 kfree(out.pointer);
660 return AE_ERROR;
661 }
662
663 if (ret.eex & 0x1)
664 interface->capability |= ACER_CAP_MAILLED;
665
666 kfree(out.pointer);
667
668 return AE_OK;
669}
670
671static acpi_status AMW0_set_capabilities(void)
672{
673 struct wmab_args args;
674 struct wmab_ret ret;
675 acpi_status status;
676 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
677 union acpi_object *obj;
678
679 /*
680 * On laptops with this strange GUID (non Acer), normal probing doesn't
681 * work.
682 */
683 if (wmi_has_guid(AMW0_GUID2)) {
684 interface->capability |= ACER_CAP_WIRELESS;
685 return AE_OK;
686 }
687
688 args.eax = ACER_AMW0_WRITE;
689 args.ecx = args.edx = 0;
690
691 args.ebx = 0xa2 << 8;
692 args.ebx |= ACER_AMW0_WIRELESS_MASK;
693
694 status = wmab_execute(&args, &out);
695 if (ACPI_FAILURE(status))
696 return status;
697
698 obj = out.pointer;
699 if (obj && obj->type == ACPI_TYPE_BUFFER &&
700 obj->buffer.length == sizeof(struct wmab_ret)) {
701 ret = *((struct wmab_ret *) obj->buffer.pointer);
702 } else {
703 status = AE_ERROR;
704 goto out;
705 }
706
707 if (ret.eax & 0x1)
708 interface->capability |= ACER_CAP_WIRELESS;
709
710 args.ebx = 2 << 8;
711 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
712
713 /*
714 * It's ok to use existing buffer for next wmab_execute call.
715 * But we need to kfree(out.pointer) if next wmab_execute fail.
716 */
717 status = wmab_execute(&args, &out);
718 if (ACPI_FAILURE(status))
719 goto out;
720
721 obj = (union acpi_object *) out.pointer;
722 if (obj && obj->type == ACPI_TYPE_BUFFER
723 && obj->buffer.length == sizeof(struct wmab_ret)) {
724 ret = *((struct wmab_ret *) obj->buffer.pointer);
725 } else {
726 status = AE_ERROR;
727 goto out;
728 }
729
730 if (ret.eax & 0x1)
731 interface->capability |= ACER_CAP_BLUETOOTH;
732
733 /*
734 * This appears to be safe to enable, since all Wistron based laptops
735 * appear to use the same EC register for brightness, even if they
736 * differ for wireless, etc
737 */
738 if (quirks->brightness >= 0)
739 interface->capability |= ACER_CAP_BRIGHTNESS;
740
741 status = AE_OK;
742out:
743 kfree(out.pointer);
744 return status;
745}
746
747static struct wmi_interface AMW0_interface = {
748 .type = ACER_AMW0,
749};
750
751static struct wmi_interface AMW0_V2_interface = {
752 .type = ACER_AMW0_V2,
753};
754
755/*
756 * New interface (The WMID interface)
757 */
758static acpi_status
759WMI_execute_u32(u32 method_id, u32 in, u32 *out)
760{
761 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
762 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
763 union acpi_object *obj;
764 u32 tmp;
765 acpi_status status;
766
767 status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
768
769 if (ACPI_FAILURE(status))
770 return status;
771
772 obj = (union acpi_object *) result.pointer;
773 if (obj && obj->type == ACPI_TYPE_BUFFER &&
774 (obj->buffer.length == sizeof(u32) ||
775 obj->buffer.length == sizeof(u64))) {
776 tmp = *((u32 *) obj->buffer.pointer);
777 } else if (obj->type == ACPI_TYPE_INTEGER) {
778 tmp = (u32) obj->integer.value;
779 } else {
780 tmp = 0;
781 }
782
783 if (out)
784 *out = tmp;
785
786 kfree(result.pointer);
787
788 return status;
789}
790
791static acpi_status WMID_get_u32(u32 *value, u32 cap,
792struct wmi_interface *iface)
793{
794 acpi_status status;
795 u8 tmp;
796 u32 result, method_id = 0;
797
798 switch (cap) {
799 case ACER_CAP_WIRELESS:
800 method_id = ACER_WMID_GET_WIRELESS_METHODID;
801 break;
802 case ACER_CAP_BLUETOOTH:
803 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
804 break;
805 case ACER_CAP_BRIGHTNESS:
806 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
807 break;
808 case ACER_CAP_THREEG:
809 method_id = ACER_WMID_GET_THREEG_METHODID;
810 break;
811 case ACER_CAP_MAILLED:
812 if (quirks->mailled == 1) {
813 ec_read(0x9f, &tmp);
814 *value = tmp & 0x1;
815 return 0;
816 }
817 default:
818 return AE_ERROR;
819 }
820 status = WMI_execute_u32(method_id, 0, &result);
821
822 if (ACPI_SUCCESS(status))
823 *value = (u8)result;
824
825 return status;
826}
827
828static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
829{
830 u32 method_id = 0;
831 char param;
832
833 switch (cap) {
834 case ACER_CAP_BRIGHTNESS:
835 if (value > max_brightness)
836 return AE_BAD_PARAMETER;
837 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
838 break;
839 case ACER_CAP_WIRELESS:
840 if (value > 1)
841 return AE_BAD_PARAMETER;
842 method_id = ACER_WMID_SET_WIRELESS_METHODID;
843 break;
844 case ACER_CAP_BLUETOOTH:
845 if (value > 1)
846 return AE_BAD_PARAMETER;
847 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
848 break;
849 case ACER_CAP_THREEG:
850 if (value > 1)
851 return AE_BAD_PARAMETER;
852 method_id = ACER_WMID_SET_THREEG_METHODID;
853 break;
854 case ACER_CAP_MAILLED:
855 if (value > 1)
856 return AE_BAD_PARAMETER;
857 if (quirks->mailled == 1) {
858 param = value ? 0x92 : 0x93;
859 i8042_lock_chip();
860 i8042_command(¶m, 0x1059);
861 i8042_unlock_chip();
862 return 0;
863 }
864 break;
865 default:
866 return AE_ERROR;
867 }
868 return WMI_execute_u32(method_id, (u32)value, NULL);
869}
870
871static void type_aa_dmi_decode(const struct dmi_header *header, void *dummy)
872{
873 struct hotkey_function_type_aa *type_aa;
874
875 /* We are looking for OEM-specific Type AAh */
876 if (header->type != 0xAA)
877 return;
878
879 has_type_aa = true;
880 type_aa = (struct hotkey_function_type_aa *) header;
881
882 pr_info("Function bitmap for Communication Button: 0x%x\n",
883 type_aa->commun_func_bitmap);
884
885 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
886 interface->capability |= ACER_CAP_WIRELESS;
887 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
888 interface->capability |= ACER_CAP_THREEG;
889 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
890 interface->capability |= ACER_CAP_BLUETOOTH;
891}
892
893static acpi_status WMID_set_capabilities(void)
894{
895 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
896 union acpi_object *obj;
897 acpi_status status;
898 u32 devices;
899
900 status = wmi_query_block(WMID_GUID2, 1, &out);
901 if (ACPI_FAILURE(status))
902 return status;
903
904 obj = (union acpi_object *) out.pointer;
905 if (obj && obj->type == ACPI_TYPE_BUFFER &&
906 (obj->buffer.length == sizeof(u32) ||
907 obj->buffer.length == sizeof(u64))) {
908 devices = *((u32 *) obj->buffer.pointer);
909 } else if (obj->type == ACPI_TYPE_INTEGER) {
910 devices = (u32) obj->integer.value;
911 } else {
912 kfree(out.pointer);
913 return AE_ERROR;
914 }
915
916 dmi_walk(type_aa_dmi_decode, NULL);
917 if (!has_type_aa) {
918 interface->capability |= ACER_CAP_WIRELESS;
919 if (devices & 0x40)
920 interface->capability |= ACER_CAP_THREEG;
921 if (devices & 0x10)
922 interface->capability |= ACER_CAP_BLUETOOTH;
923 }
924
925 /* WMID always provides brightness methods */
926 interface->capability |= ACER_CAP_BRIGHTNESS;
927
928 if (!(devices & 0x20))
929 max_brightness = 0x9;
930
931 kfree(out.pointer);
932 return status;
933}
934
935static struct wmi_interface wmid_interface = {
936 .type = ACER_WMID,
937};
938
939/*
940 * Generic Device (interface-independent)
941 */
942
943static acpi_status get_u32(u32 *value, u32 cap)
944{
945 acpi_status status = AE_ERROR;
946
947 switch (interface->type) {
948 case ACER_AMW0:
949 status = AMW0_get_u32(value, cap, interface);
950 break;
951 case ACER_AMW0_V2:
952 if (cap == ACER_CAP_MAILLED) {
953 status = AMW0_get_u32(value, cap, interface);
954 break;
955 }
956 case ACER_WMID:
957 status = WMID_get_u32(value, cap, interface);
958 break;
959 }
960
961 return status;
962}
963
964static acpi_status set_u32(u32 value, u32 cap)
965{
966 acpi_status status;
967
968 if (interface->capability & cap) {
969 switch (interface->type) {
970 case ACER_AMW0:
971 return AMW0_set_u32(value, cap, interface);
972 case ACER_AMW0_V2:
973 if (cap == ACER_CAP_MAILLED)
974 return AMW0_set_u32(value, cap, interface);
975
976 /*
977 * On some models, some WMID methods don't toggle
978 * properly. For those cases, we want to run the AMW0
979 * method afterwards to be certain we've really toggled
980 * the device state.
981 */
982 if (cap == ACER_CAP_WIRELESS ||
983 cap == ACER_CAP_BLUETOOTH) {
984 status = WMID_set_u32(value, cap, interface);
985 if (ACPI_FAILURE(status))
986 return status;
987
988 return AMW0_set_u32(value, cap, interface);
989 }
990 case ACER_WMID:
991 return WMID_set_u32(value, cap, interface);
992 default:
993 return AE_BAD_PARAMETER;
994 }
995 }
996 return AE_BAD_PARAMETER;
997}
998
999static void __init acer_commandline_init(void)
1000{
1001 /*
1002 * These will all fail silently if the value given is invalid, or the
1003 * capability isn't available on the given interface
1004 */
1005 if (mailled >= 0)
1006 set_u32(mailled, ACER_CAP_MAILLED);
1007 if (!has_type_aa && threeg >= 0)
1008 set_u32(threeg, ACER_CAP_THREEG);
1009 if (brightness >= 0)
1010 set_u32(brightness, ACER_CAP_BRIGHTNESS);
1011}
1012
1013/*
1014 * LED device (Mail LED only, no other LEDs known yet)
1015 */
1016static void mail_led_set(struct led_classdev *led_cdev,
1017enum led_brightness value)
1018{
1019 set_u32(value, ACER_CAP_MAILLED);
1020}
1021
1022static struct led_classdev mail_led = {
1023 .name = "acer-wmi::mail",
1024 .brightness_set = mail_led_set,
1025};
1026
1027static int __devinit acer_led_init(struct device *dev)
1028{
1029 return led_classdev_register(dev, &mail_led);
1030}
1031
1032static void acer_led_exit(void)
1033{
1034 set_u32(LED_OFF, ACER_CAP_MAILLED);
1035 led_classdev_unregister(&mail_led);
1036}
1037
1038/*
1039 * Backlight device
1040 */
1041static struct backlight_device *acer_backlight_device;
1042
1043static int read_brightness(struct backlight_device *bd)
1044{
1045 u32 value;
1046 get_u32(&value, ACER_CAP_BRIGHTNESS);
1047 return value;
1048}
1049
1050static int update_bl_status(struct backlight_device *bd)
1051{
1052 int intensity = bd->props.brightness;
1053
1054 if (bd->props.power != FB_BLANK_UNBLANK)
1055 intensity = 0;
1056 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1057 intensity = 0;
1058
1059 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1060
1061 return 0;
1062}
1063
1064static const struct backlight_ops acer_bl_ops = {
1065 .get_brightness = read_brightness,
1066 .update_status = update_bl_status,
1067};
1068
1069static int __devinit acer_backlight_init(struct device *dev)
1070{
1071 struct backlight_properties props;
1072 struct backlight_device *bd;
1073
1074 memset(&props, 0, sizeof(struct backlight_properties));
1075 props.type = BACKLIGHT_PLATFORM;
1076 props.max_brightness = max_brightness;
1077 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1078 &props);
1079 if (IS_ERR(bd)) {
1080 pr_err("Could not register Acer backlight device\n");
1081 acer_backlight_device = NULL;
1082 return PTR_ERR(bd);
1083 }
1084
1085 acer_backlight_device = bd;
1086
1087 bd->props.power = FB_BLANK_UNBLANK;
1088 bd->props.brightness = read_brightness(bd);
1089 backlight_update_status(bd);
1090 return 0;
1091}
1092
1093static void acer_backlight_exit(void)
1094{
1095 backlight_device_unregister(acer_backlight_device);
1096}
1097
1098static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1099{
1100 struct wmid3_gds_return_value return_value;
1101 acpi_status status;
1102 union acpi_object *obj;
1103 struct wmid3_gds_input_param params = {
1104 .function_num = 0x1,
1105 .hotkey_number = 0x01,
1106 .devices = device,
1107 };
1108 struct acpi_buffer input = {
1109 sizeof(struct wmid3_gds_input_param),
1110 ¶ms
1111 };
1112 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1113
1114 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1115 if (ACPI_FAILURE(status))
1116 return status;
1117
1118 obj = output.pointer;
1119
1120 if (!obj)
1121 return AE_ERROR;
1122 else if (obj->type != ACPI_TYPE_BUFFER) {
1123 kfree(obj);
1124 return AE_ERROR;
1125 }
1126 if (obj->buffer.length != 8) {
1127 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1128 kfree(obj);
1129 return AE_ERROR;
1130 }
1131
1132 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1133 kfree(obj);
1134
1135 if (return_value.error_code || return_value.ec_return_value)
1136 pr_warn("Get Device Status failed: 0x%x - 0x%x\n",
1137 return_value.error_code,
1138 return_value.ec_return_value);
1139 else
1140 *value = !!(return_value.devices & device);
1141
1142 return status;
1143}
1144
1145static acpi_status get_device_status(u32 *value, u32 cap)
1146{
1147 if (wmi_has_guid(WMID_GUID3)) {
1148 u16 device;
1149
1150 switch (cap) {
1151 case ACER_CAP_WIRELESS:
1152 device = ACER_WMID3_GDS_WIRELESS;
1153 break;
1154 case ACER_CAP_BLUETOOTH:
1155 device = ACER_WMID3_GDS_BLUETOOTH;
1156 break;
1157 case ACER_CAP_THREEG:
1158 device = ACER_WMID3_GDS_THREEG;
1159 break;
1160 default:
1161 return AE_ERROR;
1162 }
1163 return wmid3_get_device_status(value, device);
1164
1165 } else {
1166 return get_u32(value, cap);
1167 }
1168}
1169
1170static acpi_status wmid3_set_device_status(u32 value, u16 device)
1171{
1172 struct wmid3_gds_return_value return_value;
1173 acpi_status status;
1174 union acpi_object *obj;
1175 u16 devices;
1176 struct wmid3_gds_input_param params = {
1177 .function_num = 0x1,
1178 .hotkey_number = 0x01,
1179 .devices = ACER_WMID3_GDS_WIRELESS |
1180 ACER_WMID3_GDS_THREEG |
1181 ACER_WMID3_GDS_WIMAX |
1182 ACER_WMID3_GDS_BLUETOOTH,
1183 };
1184 struct acpi_buffer input = {
1185 sizeof(struct wmid3_gds_input_param),
1186 ¶ms
1187 };
1188 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1189 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1190
1191 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1192 if (ACPI_FAILURE(status))
1193 return status;
1194
1195 obj = output.pointer;
1196
1197 if (!obj)
1198 return AE_ERROR;
1199 else if (obj->type != ACPI_TYPE_BUFFER) {
1200 kfree(obj);
1201 return AE_ERROR;
1202 }
1203 if (obj->buffer.length != 8) {
1204 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1205 kfree(obj);
1206 return AE_ERROR;
1207 }
1208
1209 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1210 kfree(obj);
1211
1212 if (return_value.error_code || return_value.ec_return_value) {
1213 pr_warning("Get Current Device Status failed: "
1214 "0x%x - 0x%x\n", return_value.error_code,
1215 return_value.ec_return_value);
1216 return status;
1217 }
1218
1219 devices = return_value.devices;
1220 params.function_num = 0x2;
1221 params.hotkey_number = 0x01;
1222 params.devices = (value) ? (devices | device) : (devices & ~device);
1223
1224 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output2);
1225 if (ACPI_FAILURE(status))
1226 return status;
1227
1228 obj = output2.pointer;
1229
1230 if (!obj)
1231 return AE_ERROR;
1232 else if (obj->type != ACPI_TYPE_BUFFER) {
1233 kfree(obj);
1234 return AE_ERROR;
1235 }
1236 if (obj->buffer.length != 4) {
1237 pr_warning("Unknown buffer length %d\n", obj->buffer.length);
1238 kfree(obj);
1239 return AE_ERROR;
1240 }
1241
1242 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1243 kfree(obj);
1244
1245 if (return_value.error_code || return_value.ec_return_value)
1246 pr_warning("Set Device Status failed: "
1247 "0x%x - 0x%x\n", return_value.error_code,
1248 return_value.ec_return_value);
1249
1250 return status;
1251}
1252
1253static acpi_status set_device_status(u32 value, u32 cap)
1254{
1255 if (wmi_has_guid(WMID_GUID3)) {
1256 u16 device;
1257
1258 switch (cap) {
1259 case ACER_CAP_WIRELESS:
1260 device = ACER_WMID3_GDS_WIRELESS;
1261 break;
1262 case ACER_CAP_BLUETOOTH:
1263 device = ACER_WMID3_GDS_BLUETOOTH;
1264 break;
1265 case ACER_CAP_THREEG:
1266 device = ACER_WMID3_GDS_THREEG;
1267 break;
1268 default:
1269 return AE_ERROR;
1270 }
1271 return wmid3_set_device_status(value, device);
1272
1273 } else {
1274 return set_u32(value, cap);
1275 }
1276}
1277
1278/*
1279 * Rfkill devices
1280 */
1281static void acer_rfkill_update(struct work_struct *ignored);
1282static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1283static void acer_rfkill_update(struct work_struct *ignored)
1284{
1285 u32 state;
1286 acpi_status status;
1287
1288 status = get_u32(&state, ACER_CAP_WIRELESS);
1289 if (ACPI_SUCCESS(status)) {
1290 if (quirks->wireless == 3) {
1291 rfkill_set_hw_state(wireless_rfkill, !state);
1292 } else {
1293 rfkill_set_sw_state(wireless_rfkill, !state);
1294 }
1295 }
1296
1297 if (has_cap(ACER_CAP_BLUETOOTH)) {
1298 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1299 if (ACPI_SUCCESS(status))
1300 rfkill_set_sw_state(bluetooth_rfkill, !state);
1301 }
1302
1303 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1304 status = wmid3_get_device_status(&state,
1305 ACER_WMID3_GDS_THREEG);
1306 if (ACPI_SUCCESS(status))
1307 rfkill_set_sw_state(threeg_rfkill, !state);
1308 }
1309
1310 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1311}
1312
1313static int acer_rfkill_set(void *data, bool blocked)
1314{
1315 acpi_status status;
1316 u32 cap = (unsigned long)data;
1317
1318 if (rfkill_inited) {
1319 status = set_device_status(!blocked, cap);
1320 if (ACPI_FAILURE(status))
1321 return -ENODEV;
1322 }
1323
1324 return 0;
1325}
1326
1327static const struct rfkill_ops acer_rfkill_ops = {
1328 .set_block = acer_rfkill_set,
1329};
1330
1331static struct rfkill *acer_rfkill_register(struct device *dev,
1332 enum rfkill_type type,
1333 char *name, u32 cap)
1334{
1335 int err;
1336 struct rfkill *rfkill_dev;
1337 u32 state;
1338 acpi_status status;
1339
1340 rfkill_dev = rfkill_alloc(name, dev, type,
1341 &acer_rfkill_ops,
1342 (void *)(unsigned long)cap);
1343 if (!rfkill_dev)
1344 return ERR_PTR(-ENOMEM);
1345
1346 status = get_device_status(&state, cap);
1347
1348 err = rfkill_register(rfkill_dev);
1349 if (err) {
1350 rfkill_destroy(rfkill_dev);
1351 return ERR_PTR(err);
1352 }
1353
1354 if (ACPI_SUCCESS(status))
1355 rfkill_set_sw_state(rfkill_dev, !state);
1356
1357 return rfkill_dev;
1358}
1359
1360static int acer_rfkill_init(struct device *dev)
1361{
1362 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1363 "acer-wireless", ACER_CAP_WIRELESS);
1364 if (IS_ERR(wireless_rfkill))
1365 return PTR_ERR(wireless_rfkill);
1366
1367 if (has_cap(ACER_CAP_BLUETOOTH)) {
1368 bluetooth_rfkill = acer_rfkill_register(dev,
1369 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1370 ACER_CAP_BLUETOOTH);
1371 if (IS_ERR(bluetooth_rfkill)) {
1372 rfkill_unregister(wireless_rfkill);
1373 rfkill_destroy(wireless_rfkill);
1374 return PTR_ERR(bluetooth_rfkill);
1375 }
1376 }
1377
1378 if (has_cap(ACER_CAP_THREEG)) {
1379 threeg_rfkill = acer_rfkill_register(dev,
1380 RFKILL_TYPE_WWAN, "acer-threeg",
1381 ACER_CAP_THREEG);
1382 if (IS_ERR(threeg_rfkill)) {
1383 rfkill_unregister(wireless_rfkill);
1384 rfkill_destroy(wireless_rfkill);
1385 rfkill_unregister(bluetooth_rfkill);
1386 rfkill_destroy(bluetooth_rfkill);
1387 return PTR_ERR(threeg_rfkill);
1388 }
1389 }
1390
1391 rfkill_inited = true;
1392
1393 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1394 schedule_delayed_work(&acer_rfkill_work,
1395 round_jiffies_relative(HZ));
1396
1397 return 0;
1398}
1399
1400static void acer_rfkill_exit(void)
1401{
1402 if (ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID))
1403 cancel_delayed_work_sync(&acer_rfkill_work);
1404
1405 rfkill_unregister(wireless_rfkill);
1406 rfkill_destroy(wireless_rfkill);
1407
1408 if (has_cap(ACER_CAP_BLUETOOTH)) {
1409 rfkill_unregister(bluetooth_rfkill);
1410 rfkill_destroy(bluetooth_rfkill);
1411 }
1412
1413 if (has_cap(ACER_CAP_THREEG)) {
1414 rfkill_unregister(threeg_rfkill);
1415 rfkill_destroy(threeg_rfkill);
1416 }
1417 return;
1418}
1419
1420/*
1421 * sysfs interface
1422 */
1423static ssize_t show_bool_threeg(struct device *dev,
1424 struct device_attribute *attr, char *buf)
1425{
1426 u32 result; \
1427 acpi_status status;
1428
1429 pr_info("This threeg sysfs will be removed in 2012"
1430 " - used by: %s\n", current->comm);
1431 if (wmi_has_guid(WMID_GUID3))
1432 status = wmid3_get_device_status(&result,
1433 ACER_WMID3_GDS_THREEG);
1434 else
1435 status = get_u32(&result, ACER_CAP_THREEG);
1436 if (ACPI_SUCCESS(status))
1437 return sprintf(buf, "%u\n", result);
1438 return sprintf(buf, "Read error\n");
1439}
1440
1441static ssize_t set_bool_threeg(struct device *dev,
1442 struct device_attribute *attr, const char *buf, size_t count)
1443{
1444 u32 tmp = simple_strtoul(buf, NULL, 10);
1445 acpi_status status = set_u32(tmp, ACER_CAP_THREEG);
1446 pr_info("This threeg sysfs will be removed in 2012"
1447 " - used by: %s\n", current->comm);
1448 if (ACPI_FAILURE(status))
1449 return -EINVAL;
1450 return count;
1451}
1452static DEVICE_ATTR(threeg, S_IRUGO | S_IWUSR, show_bool_threeg,
1453 set_bool_threeg);
1454
1455static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
1456 char *buf)
1457{
1458 pr_info("This interface sysfs will be removed in 2012"
1459 " - used by: %s\n", current->comm);
1460 switch (interface->type) {
1461 case ACER_AMW0:
1462 return sprintf(buf, "AMW0\n");
1463 case ACER_AMW0_V2:
1464 return sprintf(buf, "AMW0 v2\n");
1465 case ACER_WMID:
1466 return sprintf(buf, "WMID\n");
1467 default:
1468 return sprintf(buf, "Error!\n");
1469 }
1470}
1471
1472static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL);
1473
1474static void acer_wmi_notify(u32 value, void *context)
1475{
1476 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1477 union acpi_object *obj;
1478 struct event_return_value return_value;
1479 acpi_status status;
1480 u16 device_state;
1481 const struct key_entry *key;
1482
1483 status = wmi_get_event_data(value, &response);
1484 if (status != AE_OK) {
1485 pr_warn("bad event status 0x%x\n", status);
1486 return;
1487 }
1488
1489 obj = (union acpi_object *)response.pointer;
1490
1491 if (!obj)
1492 return;
1493 if (obj->type != ACPI_TYPE_BUFFER) {
1494 pr_warn("Unknown response received %d\n", obj->type);
1495 kfree(obj);
1496 return;
1497 }
1498 if (obj->buffer.length != 8) {
1499 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1500 kfree(obj);
1501 return;
1502 }
1503
1504 return_value = *((struct event_return_value *)obj->buffer.pointer);
1505 kfree(obj);
1506
1507 switch (return_value.function) {
1508 case WMID_HOTKEY_EVENT:
1509 device_state = return_value.device_state;
1510 pr_debug("device state: 0x%x\n", device_state);
1511
1512 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1513 return_value.key_num);
1514 if (!key) {
1515 pr_warn("Unknown key number - 0x%x\n",
1516 return_value.key_num);
1517 } else {
1518 switch (key->keycode) {
1519 case KEY_WLAN:
1520 case KEY_BLUETOOTH:
1521 if (has_cap(ACER_CAP_WIRELESS))
1522 rfkill_set_sw_state(wireless_rfkill,
1523 !(device_state & ACER_WMID3_GDS_WIRELESS));
1524 if (has_cap(ACER_CAP_THREEG))
1525 rfkill_set_sw_state(threeg_rfkill,
1526 !(device_state & ACER_WMID3_GDS_THREEG));
1527 if (has_cap(ACER_CAP_BLUETOOTH))
1528 rfkill_set_sw_state(bluetooth_rfkill,
1529 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1530 break;
1531 }
1532 sparse_keymap_report_entry(acer_wmi_input_dev, key,
1533 1, true);
1534 }
1535 break;
1536 default:
1537 pr_warn("Unknown function number - %d - %d\n",
1538 return_value.function, return_value.key_num);
1539 break;
1540 }
1541}
1542
1543static acpi_status
1544wmid3_set_lm_mode(struct lm_input_params *params,
1545 struct lm_return_value *return_value)
1546{
1547 acpi_status status;
1548 union acpi_object *obj;
1549
1550 struct acpi_buffer input = { sizeof(struct lm_input_params), params };
1551 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1552
1553 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1554 if (ACPI_FAILURE(status))
1555 return status;
1556
1557 obj = output.pointer;
1558
1559 if (!obj)
1560 return AE_ERROR;
1561 else if (obj->type != ACPI_TYPE_BUFFER) {
1562 kfree(obj);
1563 return AE_ERROR;
1564 }
1565 if (obj->buffer.length != 4) {
1566 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1567 kfree(obj);
1568 return AE_ERROR;
1569 }
1570
1571 *return_value = *((struct lm_return_value *)obj->buffer.pointer);
1572 kfree(obj);
1573
1574 return status;
1575}
1576
1577static int acer_wmi_enable_ec_raw(void)
1578{
1579 struct lm_return_value return_value;
1580 acpi_status status;
1581 struct lm_input_params params = {
1582 .function_num = 0x1,
1583 .commun_devices = 0xFFFF,
1584 .devices = 0xFFFF,
1585 .lm_status = 0x00, /* Launch Manager Deactive */
1586 };
1587
1588 status = wmid3_set_lm_mode(¶ms, &return_value);
1589
1590 if (return_value.error_code || return_value.ec_return_value)
1591 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1592 return_value.error_code,
1593 return_value.ec_return_value);
1594 else
1595 pr_info("Enabled EC raw mode\n");
1596
1597 return status;
1598}
1599
1600static int acer_wmi_enable_lm(void)
1601{
1602 struct lm_return_value return_value;
1603 acpi_status status;
1604 struct lm_input_params params = {
1605 .function_num = 0x1,
1606 .commun_devices = 0xFFFF,
1607 .devices = 0xFFFF,
1608 .lm_status = 0x01, /* Launch Manager Active */
1609 };
1610
1611 status = wmid3_set_lm_mode(¶ms, &return_value);
1612
1613 if (return_value.error_code || return_value.ec_return_value)
1614 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1615 return_value.error_code,
1616 return_value.ec_return_value);
1617
1618 return status;
1619}
1620
1621static int __init acer_wmi_input_setup(void)
1622{
1623 acpi_status status;
1624 int err;
1625
1626 acer_wmi_input_dev = input_allocate_device();
1627 if (!acer_wmi_input_dev)
1628 return -ENOMEM;
1629
1630 acer_wmi_input_dev->name = "Acer WMI hotkeys";
1631 acer_wmi_input_dev->phys = "wmi/input0";
1632 acer_wmi_input_dev->id.bustype = BUS_HOST;
1633
1634 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
1635 if (err)
1636 goto err_free_dev;
1637
1638 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
1639 acer_wmi_notify, NULL);
1640 if (ACPI_FAILURE(status)) {
1641 err = -EIO;
1642 goto err_free_keymap;
1643 }
1644
1645 err = input_register_device(acer_wmi_input_dev);
1646 if (err)
1647 goto err_uninstall_notifier;
1648
1649 return 0;
1650
1651err_uninstall_notifier:
1652 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1653err_free_keymap:
1654 sparse_keymap_free(acer_wmi_input_dev);
1655err_free_dev:
1656 input_free_device(acer_wmi_input_dev);
1657 return err;
1658}
1659
1660static void acer_wmi_input_destroy(void)
1661{
1662 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
1663 sparse_keymap_free(acer_wmi_input_dev);
1664 input_unregister_device(acer_wmi_input_dev);
1665}
1666
1667/*
1668 * debugfs functions
1669 */
1670static u32 get_wmid_devices(void)
1671{
1672 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1673 union acpi_object *obj;
1674 acpi_status status;
1675 u32 devices = 0;
1676
1677 status = wmi_query_block(WMID_GUID2, 1, &out);
1678 if (ACPI_FAILURE(status))
1679 return 0;
1680
1681 obj = (union acpi_object *) out.pointer;
1682 if (obj && obj->type == ACPI_TYPE_BUFFER &&
1683 (obj->buffer.length == sizeof(u32) ||
1684 obj->buffer.length == sizeof(u64))) {
1685 devices = *((u32 *) obj->buffer.pointer);
1686 } else if (obj->type == ACPI_TYPE_INTEGER) {
1687 devices = (u32) obj->integer.value;
1688 }
1689
1690 kfree(out.pointer);
1691 return devices;
1692}
1693
1694/*
1695 * Platform device
1696 */
1697static int __devinit acer_platform_probe(struct platform_device *device)
1698{
1699 int err;
1700
1701 if (has_cap(ACER_CAP_MAILLED)) {
1702 err = acer_led_init(&device->dev);
1703 if (err)
1704 goto error_mailled;
1705 }
1706
1707 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1708 err = acer_backlight_init(&device->dev);
1709 if (err)
1710 goto error_brightness;
1711 }
1712
1713 err = acer_rfkill_init(&device->dev);
1714 if (err)
1715 goto error_rfkill;
1716
1717 return err;
1718
1719error_rfkill:
1720 if (has_cap(ACER_CAP_BRIGHTNESS))
1721 acer_backlight_exit();
1722error_brightness:
1723 if (has_cap(ACER_CAP_MAILLED))
1724 acer_led_exit();
1725error_mailled:
1726 return err;
1727}
1728
1729static int acer_platform_remove(struct platform_device *device)
1730{
1731 if (has_cap(ACER_CAP_MAILLED))
1732 acer_led_exit();
1733 if (has_cap(ACER_CAP_BRIGHTNESS))
1734 acer_backlight_exit();
1735
1736 acer_rfkill_exit();
1737 return 0;
1738}
1739
1740static int acer_platform_suspend(struct platform_device *dev,
1741pm_message_t state)
1742{
1743 u32 value;
1744 struct acer_data *data = &interface->data;
1745
1746 if (!data)
1747 return -ENOMEM;
1748
1749 if (has_cap(ACER_CAP_MAILLED)) {
1750 get_u32(&value, ACER_CAP_MAILLED);
1751 set_u32(LED_OFF, ACER_CAP_MAILLED);
1752 data->mailled = value;
1753 }
1754
1755 if (has_cap(ACER_CAP_BRIGHTNESS)) {
1756 get_u32(&value, ACER_CAP_BRIGHTNESS);
1757 data->brightness = value;
1758 }
1759
1760 return 0;
1761}
1762
1763static int acer_platform_resume(struct platform_device *device)
1764{
1765 struct acer_data *data = &interface->data;
1766
1767 if (!data)
1768 return -ENOMEM;
1769
1770 if (has_cap(ACER_CAP_MAILLED))
1771 set_u32(data->mailled, ACER_CAP_MAILLED);
1772
1773 if (has_cap(ACER_CAP_BRIGHTNESS))
1774 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
1775
1776 return 0;
1777}
1778
1779static void acer_platform_shutdown(struct platform_device *device)
1780{
1781 struct acer_data *data = &interface->data;
1782
1783 if (!data)
1784 return;
1785
1786 if (has_cap(ACER_CAP_MAILLED))
1787 set_u32(LED_OFF, ACER_CAP_MAILLED);
1788}
1789
1790static struct platform_driver acer_platform_driver = {
1791 .driver = {
1792 .name = "acer-wmi",
1793 .owner = THIS_MODULE,
1794 },
1795 .probe = acer_platform_probe,
1796 .remove = acer_platform_remove,
1797 .suspend = acer_platform_suspend,
1798 .resume = acer_platform_resume,
1799 .shutdown = acer_platform_shutdown,
1800};
1801
1802static struct platform_device *acer_platform_device;
1803
1804static int remove_sysfs(struct platform_device *device)
1805{
1806 if (has_cap(ACER_CAP_THREEG))
1807 device_remove_file(&device->dev, &dev_attr_threeg);
1808
1809 device_remove_file(&device->dev, &dev_attr_interface);
1810
1811 return 0;
1812}
1813
1814static int create_sysfs(void)
1815{
1816 int retval = -ENOMEM;
1817
1818 if (has_cap(ACER_CAP_THREEG)) {
1819 retval = device_create_file(&acer_platform_device->dev,
1820 &dev_attr_threeg);
1821 if (retval)
1822 goto error_sysfs;
1823 }
1824
1825 retval = device_create_file(&acer_platform_device->dev,
1826 &dev_attr_interface);
1827 if (retval)
1828 goto error_sysfs;
1829
1830 return 0;
1831
1832error_sysfs:
1833 remove_sysfs(acer_platform_device);
1834 return retval;
1835}
1836
1837static void remove_debugfs(void)
1838{
1839 debugfs_remove(interface->debug.devices);
1840 debugfs_remove(interface->debug.root);
1841}
1842
1843static int create_debugfs(void)
1844{
1845 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
1846 if (!interface->debug.root) {
1847 pr_err("Failed to create debugfs directory");
1848 return -ENOMEM;
1849 }
1850
1851 interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
1852 interface->debug.root,
1853 &interface->debug.wmid_devices);
1854 if (!interface->debug.devices)
1855 goto error_debugfs;
1856
1857 return 0;
1858
1859error_debugfs:
1860 remove_debugfs();
1861 return -ENOMEM;
1862}
1863
1864static int __init acer_wmi_init(void)
1865{
1866 int err;
1867
1868 pr_info("Acer Laptop ACPI-WMI Extras\n");
1869
1870 if (dmi_check_system(acer_blacklist)) {
1871 pr_info("Blacklisted hardware detected - not loading\n");
1872 return -ENODEV;
1873 }
1874
1875 find_quirks();
1876
1877 /*
1878 * Detect which ACPI-WMI interface we're using.
1879 */
1880 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1881 interface = &AMW0_V2_interface;
1882
1883 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
1884 interface = &wmid_interface;
1885
1886 if (wmi_has_guid(WMID_GUID2) && interface) {
1887 if (ACPI_FAILURE(WMID_set_capabilities())) {
1888 pr_err("Unable to detect available WMID devices\n");
1889 return -ENODEV;
1890 }
1891 } else if (!wmi_has_guid(WMID_GUID2) && interface) {
1892 pr_err("No WMID device detection method found\n");
1893 return -ENODEV;
1894 }
1895
1896 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
1897 interface = &AMW0_interface;
1898
1899 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1900 pr_err("Unable to detect available AMW0 devices\n");
1901 return -ENODEV;
1902 }
1903 }
1904
1905 if (wmi_has_guid(AMW0_GUID1))
1906 AMW0_find_mailled();
1907
1908 if (!interface) {
1909 pr_err("No or unsupported WMI interface, unable to load\n");
1910 return -ENODEV;
1911 }
1912
1913 set_quirks();
1914
1915 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) {
1916 interface->capability &= ~ACER_CAP_BRIGHTNESS;
1917 pr_info("Brightness must be controlled by "
1918 "generic video driver\n");
1919 }
1920
1921 if (wmi_has_guid(WMID_GUID3)) {
1922 if (ec_raw_mode) {
1923 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
1924 pr_err("Cannot enable EC raw mode\n");
1925 return -ENODEV;
1926 }
1927 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
1928 pr_err("Cannot enable Launch Manager mode\n");
1929 return -ENODEV;
1930 }
1931 } else if (ec_raw_mode) {
1932 pr_info("No WMID EC raw mode enable method\n");
1933 }
1934
1935 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
1936 err = acer_wmi_input_setup();
1937 if (err)
1938 return err;
1939 }
1940
1941 err = platform_driver_register(&acer_platform_driver);
1942 if (err) {
1943 pr_err("Unable to register platform driver.\n");
1944 goto error_platform_register;
1945 }
1946
1947 acer_platform_device = platform_device_alloc("acer-wmi", -1);
1948 if (!acer_platform_device) {
1949 err = -ENOMEM;
1950 goto error_device_alloc;
1951 }
1952
1953 err = platform_device_add(acer_platform_device);
1954 if (err)
1955 goto error_device_add;
1956
1957 err = create_sysfs();
1958 if (err)
1959 goto error_create_sys;
1960
1961 if (wmi_has_guid(WMID_GUID2)) {
1962 interface->debug.wmid_devices = get_wmid_devices();
1963 err = create_debugfs();
1964 if (err)
1965 goto error_create_debugfs;
1966 }
1967
1968 /* Override any initial settings with values from the commandline */
1969 acer_commandline_init();
1970
1971 return 0;
1972
1973error_create_debugfs:
1974 remove_sysfs(acer_platform_device);
1975error_create_sys:
1976 platform_device_del(acer_platform_device);
1977error_device_add:
1978 platform_device_put(acer_platform_device);
1979error_device_alloc:
1980 platform_driver_unregister(&acer_platform_driver);
1981error_platform_register:
1982 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1983 acer_wmi_input_destroy();
1984
1985 return err;
1986}
1987
1988static void __exit acer_wmi_exit(void)
1989{
1990 if (wmi_has_guid(ACERWMID_EVENT_GUID))
1991 acer_wmi_input_destroy();
1992
1993 remove_sysfs(acer_platform_device);
1994 remove_debugfs();
1995 platform_device_unregister(acer_platform_device);
1996 platform_driver_unregister(&acer_platform_driver);
1997
1998 pr_info("Acer Laptop WMI Extras unloaded\n");
1999 return;
2000}
2001
2002module_init(acer_wmi_init);
2003module_exit(acer_wmi_exit);
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Acer WMI Laptop Extras
4 *
5 * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk>
6 *
7 * Based on acer_acpi:
8 * Copyright (C) 2005-2007 E.M. Smith
9 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/types.h>
18#include <linux/dmi.h>
19#include <linux/fb.h>
20#include <linux/backlight.h>
21#include <linux/leds.h>
22#include <linux/platform_device.h>
23#include <linux/acpi.h>
24#include <linux/i8042.h>
25#include <linux/rfkill.h>
26#include <linux/workqueue.h>
27#include <linux/debugfs.h>
28#include <linux/slab.h>
29#include <linux/input.h>
30#include <linux/input/sparse-keymap.h>
31#include <acpi/video.h>
32
33MODULE_AUTHOR("Carlos Corbacho");
34MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
35MODULE_LICENSE("GPL");
36
37/*
38 * Magic Number
39 * Meaning is unknown - this number is required for writing to ACPI for AMW0
40 * (it's also used in acerhk when directly accessing the BIOS)
41 */
42#define ACER_AMW0_WRITE 0x9610
43
44/*
45 * Bit masks for the AMW0 interface
46 */
47#define ACER_AMW0_WIRELESS_MASK 0x35
48#define ACER_AMW0_BLUETOOTH_MASK 0x34
49#define ACER_AMW0_MAILLED_MASK 0x31
50
51/*
52 * Method IDs for WMID interface
53 */
54#define ACER_WMID_GET_WIRELESS_METHODID 1
55#define ACER_WMID_GET_BLUETOOTH_METHODID 2
56#define ACER_WMID_GET_BRIGHTNESS_METHODID 3
57#define ACER_WMID_SET_WIRELESS_METHODID 4
58#define ACER_WMID_SET_BLUETOOTH_METHODID 5
59#define ACER_WMID_SET_BRIGHTNESS_METHODID 6
60#define ACER_WMID_GET_THREEG_METHODID 10
61#define ACER_WMID_SET_THREEG_METHODID 11
62
63/*
64 * Acer ACPI method GUIDs
65 */
66#define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
67#define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
68#define WMID_GUID1 "6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"
69#define WMID_GUID2 "95764E09-FB56-4E83-B31A-37761F60994A"
70#define WMID_GUID3 "61EF69EA-865C-4BC3-A502-A0DEBA0CB531"
71
72/*
73 * Acer ACPI event GUIDs
74 */
75#define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026"
76
77MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
78MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3");
79MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026");
80
81enum acer_wmi_event_ids {
82 WMID_HOTKEY_EVENT = 0x1,
83 WMID_ACCEL_OR_KBD_DOCK_EVENT = 0x5,
84};
85
86static const struct key_entry acer_wmi_keymap[] __initconst = {
87 {KE_KEY, 0x01, {KEY_WLAN} }, /* WiFi */
88 {KE_KEY, 0x03, {KEY_WLAN} }, /* WiFi */
89 {KE_KEY, 0x04, {KEY_WLAN} }, /* WiFi */
90 {KE_KEY, 0x12, {KEY_BLUETOOTH} }, /* BT */
91 {KE_KEY, 0x21, {KEY_PROG1} }, /* Backup */
92 {KE_KEY, 0x22, {KEY_PROG2} }, /* Arcade */
93 {KE_KEY, 0x23, {KEY_PROG3} }, /* P_Key */
94 {KE_KEY, 0x24, {KEY_PROG4} }, /* Social networking_Key */
95 {KE_KEY, 0x29, {KEY_PROG3} }, /* P_Key for TM8372 */
96 {KE_IGNORE, 0x41, {KEY_MUTE} },
97 {KE_IGNORE, 0x42, {KEY_PREVIOUSSONG} },
98 {KE_IGNORE, 0x4d, {KEY_PREVIOUSSONG} },
99 {KE_IGNORE, 0x43, {KEY_NEXTSONG} },
100 {KE_IGNORE, 0x4e, {KEY_NEXTSONG} },
101 {KE_IGNORE, 0x44, {KEY_PLAYPAUSE} },
102 {KE_IGNORE, 0x4f, {KEY_PLAYPAUSE} },
103 {KE_IGNORE, 0x45, {KEY_STOP} },
104 {KE_IGNORE, 0x50, {KEY_STOP} },
105 {KE_IGNORE, 0x48, {KEY_VOLUMEUP} },
106 {KE_IGNORE, 0x49, {KEY_VOLUMEDOWN} },
107 {KE_IGNORE, 0x4a, {KEY_VOLUMEDOWN} },
108 {KE_IGNORE, 0x61, {KEY_SWITCHVIDEOMODE} },
109 {KE_IGNORE, 0x62, {KEY_BRIGHTNESSUP} },
110 {KE_IGNORE, 0x63, {KEY_BRIGHTNESSDOWN} },
111 {KE_KEY, 0x64, {KEY_SWITCHVIDEOMODE} }, /* Display Switch */
112 {KE_IGNORE, 0x81, {KEY_SLEEP} },
113 {KE_KEY, 0x82, {KEY_TOUCHPAD_TOGGLE} }, /* Touch Pad Toggle */
114 {KE_IGNORE, 0x84, {KEY_KBDILLUMTOGGLE} }, /* Automatic Keyboard background light toggle */
115 {KE_KEY, KEY_TOUCHPAD_ON, {KEY_TOUCHPAD_ON} },
116 {KE_KEY, KEY_TOUCHPAD_OFF, {KEY_TOUCHPAD_OFF} },
117 {KE_IGNORE, 0x83, {KEY_TOUCHPAD_TOGGLE} },
118 {KE_KEY, 0x85, {KEY_TOUCHPAD_TOGGLE} },
119 {KE_KEY, 0x86, {KEY_WLAN} },
120 {KE_KEY, 0x87, {KEY_POWER} },
121 {KE_END, 0}
122};
123
124static struct input_dev *acer_wmi_input_dev;
125static struct input_dev *acer_wmi_accel_dev;
126
127struct event_return_value {
128 u8 function;
129 u8 key_num;
130 u16 device_state;
131 u16 reserved1;
132 u8 kbd_dock_state;
133 u8 reserved2;
134} __attribute__((packed));
135
136/*
137 * GUID3 Get Device Status device flags
138 */
139#define ACER_WMID3_GDS_WIRELESS (1<<0) /* WiFi */
140#define ACER_WMID3_GDS_THREEG (1<<6) /* 3G */
141#define ACER_WMID3_GDS_WIMAX (1<<7) /* WiMAX */
142#define ACER_WMID3_GDS_BLUETOOTH (1<<11) /* BT */
143#define ACER_WMID3_GDS_RFBTN (1<<14) /* RF Button */
144
145#define ACER_WMID3_GDS_TOUCHPAD (1<<1) /* Touchpad */
146
147/* Hotkey Customized Setting and Acer Application Status.
148 * Set Device Default Value and Report Acer Application Status.
149 * When Acer Application starts, it will run this method to inform
150 * BIOS/EC that Acer Application is on.
151 * App Status
152 * Bit[0]: Launch Manager Status
153 * Bit[1]: ePM Status
154 * Bit[2]: Device Control Status
155 * Bit[3]: Acer Power Button Utility Status
156 * Bit[4]: RF Button Status
157 * Bit[5]: ODD PM Status
158 * Bit[6]: Device Default Value Control
159 * Bit[7]: Hall Sensor Application Status
160 */
161struct func_input_params {
162 u8 function_num; /* Function Number */
163 u16 commun_devices; /* Communication type devices default status */
164 u16 devices; /* Other type devices default status */
165 u8 app_status; /* Acer Device Status. LM, ePM, RF Button... */
166 u8 app_mask; /* Bit mask to app_status */
167 u8 reserved;
168} __attribute__((packed));
169
170struct func_return_value {
171 u8 error_code; /* Error Code */
172 u8 ec_return_value; /* EC Return Value */
173 u16 reserved;
174} __attribute__((packed));
175
176struct wmid3_gds_set_input_param { /* Set Device Status input parameter */
177 u8 function_num; /* Function Number */
178 u8 hotkey_number; /* Hotkey Number */
179 u16 devices; /* Set Device */
180 u8 volume_value; /* Volume Value */
181} __attribute__((packed));
182
183struct wmid3_gds_get_input_param { /* Get Device Status input parameter */
184 u8 function_num; /* Function Number */
185 u8 hotkey_number; /* Hotkey Number */
186 u16 devices; /* Get Device */
187} __attribute__((packed));
188
189struct wmid3_gds_return_value { /* Get Device Status return value*/
190 u8 error_code; /* Error Code */
191 u8 ec_return_value; /* EC Return Value */
192 u16 devices; /* Current Device Status */
193 u32 reserved;
194} __attribute__((packed));
195
196struct hotkey_function_type_aa {
197 u8 type;
198 u8 length;
199 u16 handle;
200 u16 commun_func_bitmap;
201 u16 application_func_bitmap;
202 u16 media_func_bitmap;
203 u16 display_func_bitmap;
204 u16 others_func_bitmap;
205 u8 commun_fn_key_number;
206} __attribute__((packed));
207
208/*
209 * Interface capability flags
210 */
211#define ACER_CAP_MAILLED BIT(0)
212#define ACER_CAP_WIRELESS BIT(1)
213#define ACER_CAP_BLUETOOTH BIT(2)
214#define ACER_CAP_BRIGHTNESS BIT(3)
215#define ACER_CAP_THREEG BIT(4)
216#define ACER_CAP_SET_FUNCTION_MODE BIT(5)
217#define ACER_CAP_KBD_DOCK BIT(6)
218
219/*
220 * Interface type flags
221 */
222enum interface_flags {
223 ACER_AMW0,
224 ACER_AMW0_V2,
225 ACER_WMID,
226 ACER_WMID_v2,
227};
228
229#define ACER_DEFAULT_WIRELESS 0
230#define ACER_DEFAULT_BLUETOOTH 0
231#define ACER_DEFAULT_MAILLED 0
232#define ACER_DEFAULT_THREEG 0
233
234static int max_brightness = 0xF;
235
236static int mailled = -1;
237static int brightness = -1;
238static int threeg = -1;
239static int force_series;
240static int force_caps = -1;
241static bool ec_raw_mode;
242static bool has_type_aa;
243static u16 commun_func_bitmap;
244static u8 commun_fn_key_number;
245
246module_param(mailled, int, 0444);
247module_param(brightness, int, 0444);
248module_param(threeg, int, 0444);
249module_param(force_series, int, 0444);
250module_param(force_caps, int, 0444);
251module_param(ec_raw_mode, bool, 0444);
252MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
253MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
254MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
255MODULE_PARM_DESC(force_series, "Force a different laptop series");
256MODULE_PARM_DESC(force_caps, "Force the capability bitmask to this value");
257MODULE_PARM_DESC(ec_raw_mode, "Enable EC raw mode");
258
259struct acer_data {
260 int mailled;
261 int threeg;
262 int brightness;
263};
264
265struct acer_debug {
266 struct dentry *root;
267 u32 wmid_devices;
268};
269
270static struct rfkill *wireless_rfkill;
271static struct rfkill *bluetooth_rfkill;
272static struct rfkill *threeg_rfkill;
273static bool rfkill_inited;
274
275/* Each low-level interface must define at least some of the following */
276struct wmi_interface {
277 /* The WMI device type */
278 u32 type;
279
280 /* The capabilities this interface provides */
281 u32 capability;
282
283 /* Private data for the current interface */
284 struct acer_data data;
285
286 /* debugfs entries associated with this interface */
287 struct acer_debug debug;
288};
289
290/* The static interface pointer, points to the currently detected interface */
291static struct wmi_interface *interface;
292
293/*
294 * Embedded Controller quirks
295 * Some laptops require us to directly access the EC to either enable or query
296 * features that are not available through WMI.
297 */
298
299struct quirk_entry {
300 u8 wireless;
301 u8 mailled;
302 s8 brightness;
303 u8 bluetooth;
304};
305
306static struct quirk_entry *quirks;
307
308static void __init set_quirks(void)
309{
310 if (quirks->mailled)
311 interface->capability |= ACER_CAP_MAILLED;
312
313 if (quirks->brightness)
314 interface->capability |= ACER_CAP_BRIGHTNESS;
315}
316
317static int __init dmi_matched(const struct dmi_system_id *dmi)
318{
319 quirks = dmi->driver_data;
320 return 1;
321}
322
323static int __init set_force_caps(const struct dmi_system_id *dmi)
324{
325 if (force_caps == -1) {
326 force_caps = (uintptr_t)dmi->driver_data;
327 pr_info("Found %s, set force_caps to 0x%x\n", dmi->ident, force_caps);
328 }
329 return 1;
330}
331
332static struct quirk_entry quirk_unknown = {
333};
334
335static struct quirk_entry quirk_acer_aspire_1520 = {
336 .brightness = -1,
337};
338
339static struct quirk_entry quirk_acer_travelmate_2490 = {
340 .mailled = 1,
341};
342
343/* This AMW0 laptop has no bluetooth */
344static struct quirk_entry quirk_medion_md_98300 = {
345 .wireless = 1,
346};
347
348static struct quirk_entry quirk_fujitsu_amilo_li_1718 = {
349 .wireless = 2,
350};
351
352static struct quirk_entry quirk_lenovo_ideapad_s205 = {
353 .wireless = 3,
354};
355
356/* The Aspire One has a dummy ACPI-WMI interface - disable it */
357static const struct dmi_system_id acer_blacklist[] __initconst = {
358 {
359 .ident = "Acer Aspire One (SSD)",
360 .matches = {
361 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
362 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
363 },
364 },
365 {
366 .ident = "Acer Aspire One (HDD)",
367 .matches = {
368 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
369 DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"),
370 },
371 },
372 {}
373};
374
375static const struct dmi_system_id amw0_whitelist[] __initconst = {
376 {
377 .ident = "Acer",
378 .matches = {
379 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
380 },
381 },
382 {
383 .ident = "Gateway",
384 .matches = {
385 DMI_MATCH(DMI_SYS_VENDOR, "Gateway"),
386 },
387 },
388 {
389 .ident = "Packard Bell",
390 .matches = {
391 DMI_MATCH(DMI_SYS_VENDOR, "Packard Bell"),
392 },
393 },
394 {}
395};
396
397/*
398 * This quirk table is only for Acer/Gateway/Packard Bell family
399 * that those machines are supported by acer-wmi driver.
400 */
401static const struct dmi_system_id acer_quirks[] __initconst = {
402 {
403 .callback = dmi_matched,
404 .ident = "Acer Aspire 1360",
405 .matches = {
406 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
407 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
408 },
409 .driver_data = &quirk_acer_aspire_1520,
410 },
411 {
412 .callback = dmi_matched,
413 .ident = "Acer Aspire 1520",
414 .matches = {
415 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
416 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
417 },
418 .driver_data = &quirk_acer_aspire_1520,
419 },
420 {
421 .callback = dmi_matched,
422 .ident = "Acer Aspire 3100",
423 .matches = {
424 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
425 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
426 },
427 .driver_data = &quirk_acer_travelmate_2490,
428 },
429 {
430 .callback = dmi_matched,
431 .ident = "Acer Aspire 3610",
432 .matches = {
433 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
434 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
435 },
436 .driver_data = &quirk_acer_travelmate_2490,
437 },
438 {
439 .callback = dmi_matched,
440 .ident = "Acer Aspire 5100",
441 .matches = {
442 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
443 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
444 },
445 .driver_data = &quirk_acer_travelmate_2490,
446 },
447 {
448 .callback = dmi_matched,
449 .ident = "Acer Aspire 5610",
450 .matches = {
451 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
452 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
453 },
454 .driver_data = &quirk_acer_travelmate_2490,
455 },
456 {
457 .callback = dmi_matched,
458 .ident = "Acer Aspire 5630",
459 .matches = {
460 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
461 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
462 },
463 .driver_data = &quirk_acer_travelmate_2490,
464 },
465 {
466 .callback = dmi_matched,
467 .ident = "Acer Aspire 5650",
468 .matches = {
469 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
470 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
471 },
472 .driver_data = &quirk_acer_travelmate_2490,
473 },
474 {
475 .callback = dmi_matched,
476 .ident = "Acer Aspire 5680",
477 .matches = {
478 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
479 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
480 },
481 .driver_data = &quirk_acer_travelmate_2490,
482 },
483 {
484 .callback = dmi_matched,
485 .ident = "Acer Aspire 9110",
486 .matches = {
487 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
488 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
489 },
490 .driver_data = &quirk_acer_travelmate_2490,
491 },
492 {
493 .callback = dmi_matched,
494 .ident = "Acer TravelMate 2490",
495 .matches = {
496 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
497 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
498 },
499 .driver_data = &quirk_acer_travelmate_2490,
500 },
501 {
502 .callback = dmi_matched,
503 .ident = "Acer TravelMate 4200",
504 .matches = {
505 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
506 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
507 },
508 .driver_data = &quirk_acer_travelmate_2490,
509 },
510 {
511 .callback = set_force_caps,
512 .ident = "Acer Aspire Switch 10E SW3-016",
513 .matches = {
514 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
515 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW3-016"),
516 },
517 .driver_data = (void *)ACER_CAP_KBD_DOCK,
518 },
519 {
520 .callback = set_force_caps,
521 .ident = "Acer Aspire Switch 10 SW5-012",
522 .matches = {
523 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
524 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
525 },
526 .driver_data = (void *)ACER_CAP_KBD_DOCK,
527 },
528 {
529 .callback = set_force_caps,
530 .ident = "Acer One 10 (S1003)",
531 .matches = {
532 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
533 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "One S1003"),
534 },
535 .driver_data = (void *)ACER_CAP_KBD_DOCK,
536 },
537 {}
538};
539
540/*
541 * This quirk list is for those non-acer machines that have AMW0_GUID1
542 * but supported by acer-wmi in past days. Keeping this quirk list here
543 * is only for backward compatible. Please do not add new machine to
544 * here anymore. Those non-acer machines should be supported by
545 * appropriate wmi drivers.
546 */
547static const struct dmi_system_id non_acer_quirks[] __initconst = {
548 {
549 .callback = dmi_matched,
550 .ident = "Fujitsu Siemens Amilo Li 1718",
551 .matches = {
552 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
553 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"),
554 },
555 .driver_data = &quirk_fujitsu_amilo_li_1718,
556 },
557 {
558 .callback = dmi_matched,
559 .ident = "Medion MD 98300",
560 .matches = {
561 DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
562 DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
563 },
564 .driver_data = &quirk_medion_md_98300,
565 },
566 {
567 .callback = dmi_matched,
568 .ident = "Lenovo Ideapad S205",
569 .matches = {
570 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
571 DMI_MATCH(DMI_PRODUCT_NAME, "10382LG"),
572 },
573 .driver_data = &quirk_lenovo_ideapad_s205,
574 },
575 {
576 .callback = dmi_matched,
577 .ident = "Lenovo Ideapad S205 (Brazos)",
578 .matches = {
579 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
580 DMI_MATCH(DMI_PRODUCT_NAME, "Brazos"),
581 },
582 .driver_data = &quirk_lenovo_ideapad_s205,
583 },
584 {
585 .callback = dmi_matched,
586 .ident = "Lenovo 3000 N200",
587 .matches = {
588 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
589 DMI_MATCH(DMI_PRODUCT_NAME, "0687A31"),
590 },
591 .driver_data = &quirk_fujitsu_amilo_li_1718,
592 },
593 {
594 .callback = dmi_matched,
595 .ident = "Lenovo Ideapad S205-10382JG",
596 .matches = {
597 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
598 DMI_MATCH(DMI_PRODUCT_NAME, "10382JG"),
599 },
600 .driver_data = &quirk_lenovo_ideapad_s205,
601 },
602 {
603 .callback = dmi_matched,
604 .ident = "Lenovo Ideapad S205-1038DPG",
605 .matches = {
606 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
607 DMI_MATCH(DMI_PRODUCT_NAME, "1038DPG"),
608 },
609 .driver_data = &quirk_lenovo_ideapad_s205,
610 },
611 {}
612};
613
614static int __init
615video_set_backlight_video_vendor(const struct dmi_system_id *d)
616{
617 interface->capability &= ~ACER_CAP_BRIGHTNESS;
618 pr_info("Brightness must be controlled by generic video driver\n");
619 return 0;
620}
621
622static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
623 {
624 .callback = video_set_backlight_video_vendor,
625 .ident = "Acer TravelMate 4750",
626 .matches = {
627 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
628 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
629 },
630 },
631 {
632 .callback = video_set_backlight_video_vendor,
633 .ident = "Acer Extensa 5235",
634 .matches = {
635 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
636 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
637 },
638 },
639 {
640 .callback = video_set_backlight_video_vendor,
641 .ident = "Acer TravelMate 5760",
642 .matches = {
643 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
644 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
645 },
646 },
647 {
648 .callback = video_set_backlight_video_vendor,
649 .ident = "Acer Aspire 5750",
650 .matches = {
651 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
652 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
653 },
654 },
655 {
656 .callback = video_set_backlight_video_vendor,
657 .ident = "Acer Aspire 5741",
658 .matches = {
659 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
660 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
661 },
662 },
663 {
664 /*
665 * Note no video_set_backlight_video_vendor, we must use the
666 * acer interface, as there is no native backlight interface.
667 */
668 .ident = "Acer KAV80",
669 .matches = {
670 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
671 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
672 },
673 },
674 {}
675};
676
677/* Find which quirks are needed for a particular vendor/ model pair */
678static void __init find_quirks(void)
679{
680 if (!force_series) {
681 dmi_check_system(acer_quirks);
682 dmi_check_system(non_acer_quirks);
683 } else if (force_series == 2490) {
684 quirks = &quirk_acer_travelmate_2490;
685 }
686
687 if (quirks == NULL)
688 quirks = &quirk_unknown;
689}
690
691/*
692 * General interface convenience methods
693 */
694
695static bool has_cap(u32 cap)
696{
697 return interface->capability & cap;
698}
699
700/*
701 * AMW0 (V1) interface
702 */
703struct wmab_args {
704 u32 eax;
705 u32 ebx;
706 u32 ecx;
707 u32 edx;
708};
709
710struct wmab_ret {
711 u32 eax;
712 u32 ebx;
713 u32 ecx;
714 u32 edx;
715 u32 eex;
716};
717
718static acpi_status wmab_execute(struct wmab_args *regbuf,
719struct acpi_buffer *result)
720{
721 struct acpi_buffer input;
722 acpi_status status;
723 input.length = sizeof(struct wmab_args);
724 input.pointer = (u8 *)regbuf;
725
726 status = wmi_evaluate_method(AMW0_GUID1, 0, 1, &input, result);
727
728 return status;
729}
730
731static acpi_status AMW0_get_u32(u32 *value, u32 cap)
732{
733 int err;
734 u8 result;
735
736 switch (cap) {
737 case ACER_CAP_MAILLED:
738 switch (quirks->mailled) {
739 default:
740 err = ec_read(0xA, &result);
741 if (err)
742 return AE_ERROR;
743 *value = (result >> 7) & 0x1;
744 return AE_OK;
745 }
746 break;
747 case ACER_CAP_WIRELESS:
748 switch (quirks->wireless) {
749 case 1:
750 err = ec_read(0x7B, &result);
751 if (err)
752 return AE_ERROR;
753 *value = result & 0x1;
754 return AE_OK;
755 case 2:
756 err = ec_read(0x71, &result);
757 if (err)
758 return AE_ERROR;
759 *value = result & 0x1;
760 return AE_OK;
761 case 3:
762 err = ec_read(0x78, &result);
763 if (err)
764 return AE_ERROR;
765 *value = result & 0x1;
766 return AE_OK;
767 default:
768 err = ec_read(0xA, &result);
769 if (err)
770 return AE_ERROR;
771 *value = (result >> 2) & 0x1;
772 return AE_OK;
773 }
774 break;
775 case ACER_CAP_BLUETOOTH:
776 switch (quirks->bluetooth) {
777 default:
778 err = ec_read(0xA, &result);
779 if (err)
780 return AE_ERROR;
781 *value = (result >> 4) & 0x1;
782 return AE_OK;
783 }
784 break;
785 case ACER_CAP_BRIGHTNESS:
786 switch (quirks->brightness) {
787 default:
788 err = ec_read(0x83, &result);
789 if (err)
790 return AE_ERROR;
791 *value = result;
792 return AE_OK;
793 }
794 break;
795 default:
796 return AE_ERROR;
797 }
798 return AE_OK;
799}
800
801static acpi_status AMW0_set_u32(u32 value, u32 cap)
802{
803 struct wmab_args args;
804
805 args.eax = ACER_AMW0_WRITE;
806 args.ebx = value ? (1<<8) : 0;
807 args.ecx = args.edx = 0;
808
809 switch (cap) {
810 case ACER_CAP_MAILLED:
811 if (value > 1)
812 return AE_BAD_PARAMETER;
813 args.ebx |= ACER_AMW0_MAILLED_MASK;
814 break;
815 case ACER_CAP_WIRELESS:
816 if (value > 1)
817 return AE_BAD_PARAMETER;
818 args.ebx |= ACER_AMW0_WIRELESS_MASK;
819 break;
820 case ACER_CAP_BLUETOOTH:
821 if (value > 1)
822 return AE_BAD_PARAMETER;
823 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
824 break;
825 case ACER_CAP_BRIGHTNESS:
826 if (value > max_brightness)
827 return AE_BAD_PARAMETER;
828 switch (quirks->brightness) {
829 default:
830 return ec_write(0x83, value);
831 }
832 default:
833 return AE_ERROR;
834 }
835
836 /* Actually do the set */
837 return wmab_execute(&args, NULL);
838}
839
840static acpi_status __init AMW0_find_mailled(void)
841{
842 struct wmab_args args;
843 struct wmab_ret ret;
844 acpi_status status = AE_OK;
845 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
846 union acpi_object *obj;
847
848 args.eax = 0x86;
849 args.ebx = args.ecx = args.edx = 0;
850
851 status = wmab_execute(&args, &out);
852 if (ACPI_FAILURE(status))
853 return status;
854
855 obj = (union acpi_object *) out.pointer;
856 if (obj && obj->type == ACPI_TYPE_BUFFER &&
857 obj->buffer.length == sizeof(struct wmab_ret)) {
858 ret = *((struct wmab_ret *) obj->buffer.pointer);
859 } else {
860 kfree(out.pointer);
861 return AE_ERROR;
862 }
863
864 if (ret.eex & 0x1)
865 interface->capability |= ACER_CAP_MAILLED;
866
867 kfree(out.pointer);
868
869 return AE_OK;
870}
871
872static const struct acpi_device_id norfkill_ids[] __initconst = {
873 { "VPC2004", 0},
874 { "IBM0068", 0},
875 { "LEN0068", 0},
876 { "SNY5001", 0}, /* sony-laptop in charge */
877 { "HPQ6601", 0},
878 { "", 0},
879};
880
881static int __init AMW0_set_cap_acpi_check_device(void)
882{
883 const struct acpi_device_id *id;
884
885 for (id = norfkill_ids; id->id[0]; id++)
886 if (acpi_dev_found(id->id))
887 return true;
888
889 return false;
890}
891
892static acpi_status __init AMW0_set_capabilities(void)
893{
894 struct wmab_args args;
895 struct wmab_ret ret;
896 acpi_status status;
897 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
898 union acpi_object *obj;
899
900 /*
901 * On laptops with this strange GUID (non Acer), normal probing doesn't
902 * work.
903 */
904 if (wmi_has_guid(AMW0_GUID2)) {
905 if ((quirks != &quirk_unknown) ||
906 !AMW0_set_cap_acpi_check_device())
907 interface->capability |= ACER_CAP_WIRELESS;
908 return AE_OK;
909 }
910
911 args.eax = ACER_AMW0_WRITE;
912 args.ecx = args.edx = 0;
913
914 args.ebx = 0xa2 << 8;
915 args.ebx |= ACER_AMW0_WIRELESS_MASK;
916
917 status = wmab_execute(&args, &out);
918 if (ACPI_FAILURE(status))
919 return status;
920
921 obj = out.pointer;
922 if (obj && obj->type == ACPI_TYPE_BUFFER &&
923 obj->buffer.length == sizeof(struct wmab_ret)) {
924 ret = *((struct wmab_ret *) obj->buffer.pointer);
925 } else {
926 status = AE_ERROR;
927 goto out;
928 }
929
930 if (ret.eax & 0x1)
931 interface->capability |= ACER_CAP_WIRELESS;
932
933 args.ebx = 2 << 8;
934 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
935
936 /*
937 * It's ok to use existing buffer for next wmab_execute call.
938 * But we need to kfree(out.pointer) if next wmab_execute fail.
939 */
940 status = wmab_execute(&args, &out);
941 if (ACPI_FAILURE(status))
942 goto out;
943
944 obj = (union acpi_object *) out.pointer;
945 if (obj && obj->type == ACPI_TYPE_BUFFER
946 && obj->buffer.length == sizeof(struct wmab_ret)) {
947 ret = *((struct wmab_ret *) obj->buffer.pointer);
948 } else {
949 status = AE_ERROR;
950 goto out;
951 }
952
953 if (ret.eax & 0x1)
954 interface->capability |= ACER_CAP_BLUETOOTH;
955
956 /*
957 * This appears to be safe to enable, since all Wistron based laptops
958 * appear to use the same EC register for brightness, even if they
959 * differ for wireless, etc
960 */
961 if (quirks->brightness >= 0)
962 interface->capability |= ACER_CAP_BRIGHTNESS;
963
964 status = AE_OK;
965out:
966 kfree(out.pointer);
967 return status;
968}
969
970static struct wmi_interface AMW0_interface = {
971 .type = ACER_AMW0,
972};
973
974static struct wmi_interface AMW0_V2_interface = {
975 .type = ACER_AMW0_V2,
976};
977
978/*
979 * New interface (The WMID interface)
980 */
981static acpi_status
982WMI_execute_u32(u32 method_id, u32 in, u32 *out)
983{
984 struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
985 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
986 union acpi_object *obj;
987 u32 tmp = 0;
988 acpi_status status;
989
990 status = wmi_evaluate_method(WMID_GUID1, 0, method_id, &input, &result);
991
992 if (ACPI_FAILURE(status))
993 return status;
994
995 obj = (union acpi_object *) result.pointer;
996 if (obj) {
997 if (obj->type == ACPI_TYPE_BUFFER &&
998 (obj->buffer.length == sizeof(u32) ||
999 obj->buffer.length == sizeof(u64))) {
1000 tmp = *((u32 *) obj->buffer.pointer);
1001 } else if (obj->type == ACPI_TYPE_INTEGER) {
1002 tmp = (u32) obj->integer.value;
1003 }
1004 }
1005
1006 if (out)
1007 *out = tmp;
1008
1009 kfree(result.pointer);
1010
1011 return status;
1012}
1013
1014static acpi_status WMID_get_u32(u32 *value, u32 cap)
1015{
1016 acpi_status status;
1017 u8 tmp;
1018 u32 result, method_id = 0;
1019
1020 switch (cap) {
1021 case ACER_CAP_WIRELESS:
1022 method_id = ACER_WMID_GET_WIRELESS_METHODID;
1023 break;
1024 case ACER_CAP_BLUETOOTH:
1025 method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
1026 break;
1027 case ACER_CAP_BRIGHTNESS:
1028 method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
1029 break;
1030 case ACER_CAP_THREEG:
1031 method_id = ACER_WMID_GET_THREEG_METHODID;
1032 break;
1033 case ACER_CAP_MAILLED:
1034 if (quirks->mailled == 1) {
1035 ec_read(0x9f, &tmp);
1036 *value = tmp & 0x1;
1037 return 0;
1038 }
1039 fallthrough;
1040 default:
1041 return AE_ERROR;
1042 }
1043 status = WMI_execute_u32(method_id, 0, &result);
1044
1045 if (ACPI_SUCCESS(status))
1046 *value = (u8)result;
1047
1048 return status;
1049}
1050
1051static acpi_status WMID_set_u32(u32 value, u32 cap)
1052{
1053 u32 method_id = 0;
1054 char param;
1055
1056 switch (cap) {
1057 case ACER_CAP_BRIGHTNESS:
1058 if (value > max_brightness)
1059 return AE_BAD_PARAMETER;
1060 method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
1061 break;
1062 case ACER_CAP_WIRELESS:
1063 if (value > 1)
1064 return AE_BAD_PARAMETER;
1065 method_id = ACER_WMID_SET_WIRELESS_METHODID;
1066 break;
1067 case ACER_CAP_BLUETOOTH:
1068 if (value > 1)
1069 return AE_BAD_PARAMETER;
1070 method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
1071 break;
1072 case ACER_CAP_THREEG:
1073 if (value > 1)
1074 return AE_BAD_PARAMETER;
1075 method_id = ACER_WMID_SET_THREEG_METHODID;
1076 break;
1077 case ACER_CAP_MAILLED:
1078 if (value > 1)
1079 return AE_BAD_PARAMETER;
1080 if (quirks->mailled == 1) {
1081 param = value ? 0x92 : 0x93;
1082 i8042_lock_chip();
1083 i8042_command(¶m, 0x1059);
1084 i8042_unlock_chip();
1085 return 0;
1086 }
1087 break;
1088 default:
1089 return AE_ERROR;
1090 }
1091 return WMI_execute_u32(method_id, (u32)value, NULL);
1092}
1093
1094static acpi_status wmid3_get_device_status(u32 *value, u16 device)
1095{
1096 struct wmid3_gds_return_value return_value;
1097 acpi_status status;
1098 union acpi_object *obj;
1099 struct wmid3_gds_get_input_param params = {
1100 .function_num = 0x1,
1101 .hotkey_number = commun_fn_key_number,
1102 .devices = device,
1103 };
1104 struct acpi_buffer input = {
1105 sizeof(struct wmid3_gds_get_input_param),
1106 ¶ms
1107 };
1108 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1109
1110 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input, &output);
1111 if (ACPI_FAILURE(status))
1112 return status;
1113
1114 obj = output.pointer;
1115
1116 if (!obj)
1117 return AE_ERROR;
1118 else if (obj->type != ACPI_TYPE_BUFFER) {
1119 kfree(obj);
1120 return AE_ERROR;
1121 }
1122 if (obj->buffer.length != 8) {
1123 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1124 kfree(obj);
1125 return AE_ERROR;
1126 }
1127
1128 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1129 kfree(obj);
1130
1131 if (return_value.error_code || return_value.ec_return_value)
1132 pr_warn("Get 0x%x Device Status failed: 0x%x - 0x%x\n",
1133 device,
1134 return_value.error_code,
1135 return_value.ec_return_value);
1136 else
1137 *value = !!(return_value.devices & device);
1138
1139 return status;
1140}
1141
1142static acpi_status wmid_v2_get_u32(u32 *value, u32 cap)
1143{
1144 u16 device;
1145
1146 switch (cap) {
1147 case ACER_CAP_WIRELESS:
1148 device = ACER_WMID3_GDS_WIRELESS;
1149 break;
1150 case ACER_CAP_BLUETOOTH:
1151 device = ACER_WMID3_GDS_BLUETOOTH;
1152 break;
1153 case ACER_CAP_THREEG:
1154 device = ACER_WMID3_GDS_THREEG;
1155 break;
1156 default:
1157 return AE_ERROR;
1158 }
1159 return wmid3_get_device_status(value, device);
1160}
1161
1162static acpi_status wmid3_set_device_status(u32 value, u16 device)
1163{
1164 struct wmid3_gds_return_value return_value;
1165 acpi_status status;
1166 union acpi_object *obj;
1167 u16 devices;
1168 struct wmid3_gds_get_input_param get_params = {
1169 .function_num = 0x1,
1170 .hotkey_number = commun_fn_key_number,
1171 .devices = commun_func_bitmap,
1172 };
1173 struct acpi_buffer get_input = {
1174 sizeof(struct wmid3_gds_get_input_param),
1175 &get_params
1176 };
1177 struct wmid3_gds_set_input_param set_params = {
1178 .function_num = 0x2,
1179 .hotkey_number = commun_fn_key_number,
1180 .devices = commun_func_bitmap,
1181 };
1182 struct acpi_buffer set_input = {
1183 sizeof(struct wmid3_gds_set_input_param),
1184 &set_params
1185 };
1186 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1187 struct acpi_buffer output2 = { ACPI_ALLOCATE_BUFFER, NULL };
1188
1189 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &get_input, &output);
1190 if (ACPI_FAILURE(status))
1191 return status;
1192
1193 obj = output.pointer;
1194
1195 if (!obj)
1196 return AE_ERROR;
1197 else if (obj->type != ACPI_TYPE_BUFFER) {
1198 kfree(obj);
1199 return AE_ERROR;
1200 }
1201 if (obj->buffer.length != 8) {
1202 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1203 kfree(obj);
1204 return AE_ERROR;
1205 }
1206
1207 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1208 kfree(obj);
1209
1210 if (return_value.error_code || return_value.ec_return_value) {
1211 pr_warn("Get Current Device Status failed: 0x%x - 0x%x\n",
1212 return_value.error_code,
1213 return_value.ec_return_value);
1214 return status;
1215 }
1216
1217 devices = return_value.devices;
1218 set_params.devices = (value) ? (devices | device) : (devices & ~device);
1219
1220 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &set_input, &output2);
1221 if (ACPI_FAILURE(status))
1222 return status;
1223
1224 obj = output2.pointer;
1225
1226 if (!obj)
1227 return AE_ERROR;
1228 else if (obj->type != ACPI_TYPE_BUFFER) {
1229 kfree(obj);
1230 return AE_ERROR;
1231 }
1232 if (obj->buffer.length != 4) {
1233 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1234 kfree(obj);
1235 return AE_ERROR;
1236 }
1237
1238 return_value = *((struct wmid3_gds_return_value *)obj->buffer.pointer);
1239 kfree(obj);
1240
1241 if (return_value.error_code || return_value.ec_return_value)
1242 pr_warn("Set Device Status failed: 0x%x - 0x%x\n",
1243 return_value.error_code,
1244 return_value.ec_return_value);
1245
1246 return status;
1247}
1248
1249static acpi_status wmid_v2_set_u32(u32 value, u32 cap)
1250{
1251 u16 device;
1252
1253 switch (cap) {
1254 case ACER_CAP_WIRELESS:
1255 device = ACER_WMID3_GDS_WIRELESS;
1256 break;
1257 case ACER_CAP_BLUETOOTH:
1258 device = ACER_WMID3_GDS_BLUETOOTH;
1259 break;
1260 case ACER_CAP_THREEG:
1261 device = ACER_WMID3_GDS_THREEG;
1262 break;
1263 default:
1264 return AE_ERROR;
1265 }
1266 return wmid3_set_device_status(value, device);
1267}
1268
1269static void __init type_aa_dmi_decode(const struct dmi_header *header, void *d)
1270{
1271 struct hotkey_function_type_aa *type_aa;
1272
1273 /* We are looking for OEM-specific Type AAh */
1274 if (header->type != 0xAA)
1275 return;
1276
1277 has_type_aa = true;
1278 type_aa = (struct hotkey_function_type_aa *) header;
1279
1280 pr_info("Function bitmap for Communication Button: 0x%x\n",
1281 type_aa->commun_func_bitmap);
1282 commun_func_bitmap = type_aa->commun_func_bitmap;
1283
1284 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_WIRELESS)
1285 interface->capability |= ACER_CAP_WIRELESS;
1286 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_THREEG)
1287 interface->capability |= ACER_CAP_THREEG;
1288 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_BLUETOOTH)
1289 interface->capability |= ACER_CAP_BLUETOOTH;
1290 if (type_aa->commun_func_bitmap & ACER_WMID3_GDS_RFBTN)
1291 commun_func_bitmap &= ~ACER_WMID3_GDS_RFBTN;
1292
1293 commun_fn_key_number = type_aa->commun_fn_key_number;
1294}
1295
1296static acpi_status __init WMID_set_capabilities(void)
1297{
1298 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1299 union acpi_object *obj;
1300 acpi_status status;
1301 u32 devices;
1302
1303 status = wmi_query_block(WMID_GUID2, 0, &out);
1304 if (ACPI_FAILURE(status))
1305 return status;
1306
1307 obj = (union acpi_object *) out.pointer;
1308 if (obj) {
1309 if (obj->type == ACPI_TYPE_BUFFER &&
1310 (obj->buffer.length == sizeof(u32) ||
1311 obj->buffer.length == sizeof(u64))) {
1312 devices = *((u32 *) obj->buffer.pointer);
1313 } else if (obj->type == ACPI_TYPE_INTEGER) {
1314 devices = (u32) obj->integer.value;
1315 } else {
1316 kfree(out.pointer);
1317 return AE_ERROR;
1318 }
1319 } else {
1320 kfree(out.pointer);
1321 return AE_ERROR;
1322 }
1323
1324 pr_info("Function bitmap for Communication Device: 0x%x\n", devices);
1325 if (devices & 0x07)
1326 interface->capability |= ACER_CAP_WIRELESS;
1327 if (devices & 0x40)
1328 interface->capability |= ACER_CAP_THREEG;
1329 if (devices & 0x10)
1330 interface->capability |= ACER_CAP_BLUETOOTH;
1331
1332 if (!(devices & 0x20))
1333 max_brightness = 0x9;
1334
1335 kfree(out.pointer);
1336 return status;
1337}
1338
1339static struct wmi_interface wmid_interface = {
1340 .type = ACER_WMID,
1341};
1342
1343static struct wmi_interface wmid_v2_interface = {
1344 .type = ACER_WMID_v2,
1345};
1346
1347/*
1348 * Generic Device (interface-independent)
1349 */
1350
1351static acpi_status get_u32(u32 *value, u32 cap)
1352{
1353 acpi_status status = AE_ERROR;
1354
1355 switch (interface->type) {
1356 case ACER_AMW0:
1357 status = AMW0_get_u32(value, cap);
1358 break;
1359 case ACER_AMW0_V2:
1360 if (cap == ACER_CAP_MAILLED) {
1361 status = AMW0_get_u32(value, cap);
1362 break;
1363 }
1364 fallthrough;
1365 case ACER_WMID:
1366 status = WMID_get_u32(value, cap);
1367 break;
1368 case ACER_WMID_v2:
1369 if (cap & (ACER_CAP_WIRELESS |
1370 ACER_CAP_BLUETOOTH |
1371 ACER_CAP_THREEG))
1372 status = wmid_v2_get_u32(value, cap);
1373 else if (wmi_has_guid(WMID_GUID2))
1374 status = WMID_get_u32(value, cap);
1375 break;
1376 }
1377
1378 return status;
1379}
1380
1381static acpi_status set_u32(u32 value, u32 cap)
1382{
1383 acpi_status status;
1384
1385 if (interface->capability & cap) {
1386 switch (interface->type) {
1387 case ACER_AMW0:
1388 return AMW0_set_u32(value, cap);
1389 case ACER_AMW0_V2:
1390 if (cap == ACER_CAP_MAILLED)
1391 return AMW0_set_u32(value, cap);
1392
1393 /*
1394 * On some models, some WMID methods don't toggle
1395 * properly. For those cases, we want to run the AMW0
1396 * method afterwards to be certain we've really toggled
1397 * the device state.
1398 */
1399 if (cap == ACER_CAP_WIRELESS ||
1400 cap == ACER_CAP_BLUETOOTH) {
1401 status = WMID_set_u32(value, cap);
1402 if (ACPI_FAILURE(status))
1403 return status;
1404
1405 return AMW0_set_u32(value, cap);
1406 }
1407 fallthrough;
1408 case ACER_WMID:
1409 return WMID_set_u32(value, cap);
1410 case ACER_WMID_v2:
1411 if (cap & (ACER_CAP_WIRELESS |
1412 ACER_CAP_BLUETOOTH |
1413 ACER_CAP_THREEG))
1414 return wmid_v2_set_u32(value, cap);
1415 else if (wmi_has_guid(WMID_GUID2))
1416 return WMID_set_u32(value, cap);
1417 fallthrough;
1418 default:
1419 return AE_BAD_PARAMETER;
1420 }
1421 }
1422 return AE_BAD_PARAMETER;
1423}
1424
1425static void __init acer_commandline_init(void)
1426{
1427 /*
1428 * These will all fail silently if the value given is invalid, or the
1429 * capability isn't available on the given interface
1430 */
1431 if (mailled >= 0)
1432 set_u32(mailled, ACER_CAP_MAILLED);
1433 if (!has_type_aa && threeg >= 0)
1434 set_u32(threeg, ACER_CAP_THREEG);
1435 if (brightness >= 0)
1436 set_u32(brightness, ACER_CAP_BRIGHTNESS);
1437}
1438
1439/*
1440 * LED device (Mail LED only, no other LEDs known yet)
1441 */
1442static void mail_led_set(struct led_classdev *led_cdev,
1443enum led_brightness value)
1444{
1445 set_u32(value, ACER_CAP_MAILLED);
1446}
1447
1448static struct led_classdev mail_led = {
1449 .name = "acer-wmi::mail",
1450 .brightness_set = mail_led_set,
1451};
1452
1453static int acer_led_init(struct device *dev)
1454{
1455 return led_classdev_register(dev, &mail_led);
1456}
1457
1458static void acer_led_exit(void)
1459{
1460 set_u32(LED_OFF, ACER_CAP_MAILLED);
1461 led_classdev_unregister(&mail_led);
1462}
1463
1464/*
1465 * Backlight device
1466 */
1467static struct backlight_device *acer_backlight_device;
1468
1469static int read_brightness(struct backlight_device *bd)
1470{
1471 u32 value;
1472 get_u32(&value, ACER_CAP_BRIGHTNESS);
1473 return value;
1474}
1475
1476static int update_bl_status(struct backlight_device *bd)
1477{
1478 int intensity = bd->props.brightness;
1479
1480 if (bd->props.power != FB_BLANK_UNBLANK)
1481 intensity = 0;
1482 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
1483 intensity = 0;
1484
1485 set_u32(intensity, ACER_CAP_BRIGHTNESS);
1486
1487 return 0;
1488}
1489
1490static const struct backlight_ops acer_bl_ops = {
1491 .get_brightness = read_brightness,
1492 .update_status = update_bl_status,
1493};
1494
1495static int acer_backlight_init(struct device *dev)
1496{
1497 struct backlight_properties props;
1498 struct backlight_device *bd;
1499
1500 memset(&props, 0, sizeof(struct backlight_properties));
1501 props.type = BACKLIGHT_PLATFORM;
1502 props.max_brightness = max_brightness;
1503 bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops,
1504 &props);
1505 if (IS_ERR(bd)) {
1506 pr_err("Could not register Acer backlight device\n");
1507 acer_backlight_device = NULL;
1508 return PTR_ERR(bd);
1509 }
1510
1511 acer_backlight_device = bd;
1512
1513 bd->props.power = FB_BLANK_UNBLANK;
1514 bd->props.brightness = read_brightness(bd);
1515 backlight_update_status(bd);
1516 return 0;
1517}
1518
1519static void acer_backlight_exit(void)
1520{
1521 backlight_device_unregister(acer_backlight_device);
1522}
1523
1524/*
1525 * Accelerometer device
1526 */
1527static acpi_handle gsensor_handle;
1528
1529static int acer_gsensor_init(void)
1530{
1531 acpi_status status;
1532 struct acpi_buffer output;
1533 union acpi_object out_obj;
1534
1535 output.length = sizeof(out_obj);
1536 output.pointer = &out_obj;
1537 status = acpi_evaluate_object(gsensor_handle, "_INI", NULL, &output);
1538 if (ACPI_FAILURE(status))
1539 return -1;
1540
1541 return 0;
1542}
1543
1544static int acer_gsensor_open(struct input_dev *input)
1545{
1546 return acer_gsensor_init();
1547}
1548
1549static int acer_gsensor_event(void)
1550{
1551 acpi_status status;
1552 struct acpi_buffer output;
1553 union acpi_object out_obj[5];
1554
1555 if (!acer_wmi_accel_dev)
1556 return -1;
1557
1558 output.length = sizeof(out_obj);
1559 output.pointer = out_obj;
1560
1561 status = acpi_evaluate_object(gsensor_handle, "RDVL", NULL, &output);
1562 if (ACPI_FAILURE(status))
1563 return -1;
1564
1565 if (out_obj->package.count != 4)
1566 return -1;
1567
1568 input_report_abs(acer_wmi_accel_dev, ABS_X,
1569 (s16)out_obj->package.elements[0].integer.value);
1570 input_report_abs(acer_wmi_accel_dev, ABS_Y,
1571 (s16)out_obj->package.elements[1].integer.value);
1572 input_report_abs(acer_wmi_accel_dev, ABS_Z,
1573 (s16)out_obj->package.elements[2].integer.value);
1574 input_sync(acer_wmi_accel_dev);
1575 return 0;
1576}
1577
1578/*
1579 * Switch series keyboard dock status
1580 */
1581static int acer_kbd_dock_state_to_sw_tablet_mode(u8 kbd_dock_state)
1582{
1583 switch (kbd_dock_state) {
1584 case 0x01: /* Docked, traditional clamshell laptop mode */
1585 return 0;
1586 case 0x04: /* Stand-alone tablet */
1587 case 0x40: /* Docked, tent mode, keyboard not usable */
1588 return 1;
1589 default:
1590 pr_warn("Unknown kbd_dock_state 0x%02x\n", kbd_dock_state);
1591 }
1592
1593 return 0;
1594}
1595
1596static void acer_kbd_dock_get_initial_state(void)
1597{
1598 u8 *output, input[8] = { 0x05, 0x00, };
1599 struct acpi_buffer input_buf = { sizeof(input), input };
1600 struct acpi_buffer output_buf = { ACPI_ALLOCATE_BUFFER, NULL };
1601 union acpi_object *obj;
1602 acpi_status status;
1603 int sw_tablet_mode;
1604
1605 status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input_buf, &output_buf);
1606 if (ACPI_FAILURE(status)) {
1607 pr_err("Error getting keyboard-dock initial status: %s\n",
1608 acpi_format_exception(status));
1609 return;
1610 }
1611
1612 obj = output_buf.pointer;
1613 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
1614 pr_err("Unexpected output format getting keyboard-dock initial status\n");
1615 goto out_free_obj;
1616 }
1617
1618 output = obj->buffer.pointer;
1619 if (output[0] != 0x00 || (output[3] != 0x05 && output[3] != 0x45)) {
1620 pr_err("Unexpected output [0]=0x%02x [3]=0x%02x getting keyboard-dock initial status\n",
1621 output[0], output[3]);
1622 goto out_free_obj;
1623 }
1624
1625 sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(output[4]);
1626 input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode);
1627
1628out_free_obj:
1629 kfree(obj);
1630}
1631
1632static void acer_kbd_dock_event(const struct event_return_value *event)
1633{
1634 int sw_tablet_mode;
1635
1636 if (!has_cap(ACER_CAP_KBD_DOCK))
1637 return;
1638
1639 sw_tablet_mode = acer_kbd_dock_state_to_sw_tablet_mode(event->kbd_dock_state);
1640 input_report_switch(acer_wmi_input_dev, SW_TABLET_MODE, sw_tablet_mode);
1641 input_sync(acer_wmi_input_dev);
1642}
1643
1644/*
1645 * Rfkill devices
1646 */
1647static void acer_rfkill_update(struct work_struct *ignored);
1648static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update);
1649static void acer_rfkill_update(struct work_struct *ignored)
1650{
1651 u32 state;
1652 acpi_status status;
1653
1654 if (has_cap(ACER_CAP_WIRELESS)) {
1655 status = get_u32(&state, ACER_CAP_WIRELESS);
1656 if (ACPI_SUCCESS(status)) {
1657 if (quirks->wireless == 3)
1658 rfkill_set_hw_state(wireless_rfkill, !state);
1659 else
1660 rfkill_set_sw_state(wireless_rfkill, !state);
1661 }
1662 }
1663
1664 if (has_cap(ACER_CAP_BLUETOOTH)) {
1665 status = get_u32(&state, ACER_CAP_BLUETOOTH);
1666 if (ACPI_SUCCESS(status))
1667 rfkill_set_sw_state(bluetooth_rfkill, !state);
1668 }
1669
1670 if (has_cap(ACER_CAP_THREEG) && wmi_has_guid(WMID_GUID3)) {
1671 status = get_u32(&state, ACER_WMID3_GDS_THREEG);
1672 if (ACPI_SUCCESS(status))
1673 rfkill_set_sw_state(threeg_rfkill, !state);
1674 }
1675
1676 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ));
1677}
1678
1679static int acer_rfkill_set(void *data, bool blocked)
1680{
1681 acpi_status status;
1682 u32 cap = (unsigned long)data;
1683
1684 if (rfkill_inited) {
1685 status = set_u32(!blocked, cap);
1686 if (ACPI_FAILURE(status))
1687 return -ENODEV;
1688 }
1689
1690 return 0;
1691}
1692
1693static const struct rfkill_ops acer_rfkill_ops = {
1694 .set_block = acer_rfkill_set,
1695};
1696
1697static struct rfkill *acer_rfkill_register(struct device *dev,
1698 enum rfkill_type type,
1699 char *name, u32 cap)
1700{
1701 int err;
1702 struct rfkill *rfkill_dev;
1703 u32 state;
1704 acpi_status status;
1705
1706 rfkill_dev = rfkill_alloc(name, dev, type,
1707 &acer_rfkill_ops,
1708 (void *)(unsigned long)cap);
1709 if (!rfkill_dev)
1710 return ERR_PTR(-ENOMEM);
1711
1712 status = get_u32(&state, cap);
1713
1714 err = rfkill_register(rfkill_dev);
1715 if (err) {
1716 rfkill_destroy(rfkill_dev);
1717 return ERR_PTR(err);
1718 }
1719
1720 if (ACPI_SUCCESS(status))
1721 rfkill_set_sw_state(rfkill_dev, !state);
1722
1723 return rfkill_dev;
1724}
1725
1726static int acer_rfkill_init(struct device *dev)
1727{
1728 int err;
1729
1730 if (has_cap(ACER_CAP_WIRELESS)) {
1731 wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN,
1732 "acer-wireless", ACER_CAP_WIRELESS);
1733 if (IS_ERR(wireless_rfkill)) {
1734 err = PTR_ERR(wireless_rfkill);
1735 goto error_wireless;
1736 }
1737 }
1738
1739 if (has_cap(ACER_CAP_BLUETOOTH)) {
1740 bluetooth_rfkill = acer_rfkill_register(dev,
1741 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth",
1742 ACER_CAP_BLUETOOTH);
1743 if (IS_ERR(bluetooth_rfkill)) {
1744 err = PTR_ERR(bluetooth_rfkill);
1745 goto error_bluetooth;
1746 }
1747 }
1748
1749 if (has_cap(ACER_CAP_THREEG)) {
1750 threeg_rfkill = acer_rfkill_register(dev,
1751 RFKILL_TYPE_WWAN, "acer-threeg",
1752 ACER_CAP_THREEG);
1753 if (IS_ERR(threeg_rfkill)) {
1754 err = PTR_ERR(threeg_rfkill);
1755 goto error_threeg;
1756 }
1757 }
1758
1759 rfkill_inited = true;
1760
1761 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1762 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1763 schedule_delayed_work(&acer_rfkill_work,
1764 round_jiffies_relative(HZ));
1765
1766 return 0;
1767
1768error_threeg:
1769 if (has_cap(ACER_CAP_BLUETOOTH)) {
1770 rfkill_unregister(bluetooth_rfkill);
1771 rfkill_destroy(bluetooth_rfkill);
1772 }
1773error_bluetooth:
1774 if (has_cap(ACER_CAP_WIRELESS)) {
1775 rfkill_unregister(wireless_rfkill);
1776 rfkill_destroy(wireless_rfkill);
1777 }
1778error_wireless:
1779 return err;
1780}
1781
1782static void acer_rfkill_exit(void)
1783{
1784 if ((ec_raw_mode || !wmi_has_guid(ACERWMID_EVENT_GUID)) &&
1785 has_cap(ACER_CAP_WIRELESS | ACER_CAP_BLUETOOTH | ACER_CAP_THREEG))
1786 cancel_delayed_work_sync(&acer_rfkill_work);
1787
1788 if (has_cap(ACER_CAP_WIRELESS)) {
1789 rfkill_unregister(wireless_rfkill);
1790 rfkill_destroy(wireless_rfkill);
1791 }
1792
1793 if (has_cap(ACER_CAP_BLUETOOTH)) {
1794 rfkill_unregister(bluetooth_rfkill);
1795 rfkill_destroy(bluetooth_rfkill);
1796 }
1797
1798 if (has_cap(ACER_CAP_THREEG)) {
1799 rfkill_unregister(threeg_rfkill);
1800 rfkill_destroy(threeg_rfkill);
1801 }
1802 return;
1803}
1804
1805static void acer_wmi_notify(u32 value, void *context)
1806{
1807 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
1808 union acpi_object *obj;
1809 struct event_return_value return_value;
1810 acpi_status status;
1811 u16 device_state;
1812 const struct key_entry *key;
1813 u32 scancode;
1814
1815 status = wmi_get_event_data(value, &response);
1816 if (status != AE_OK) {
1817 pr_warn("bad event status 0x%x\n", status);
1818 return;
1819 }
1820
1821 obj = (union acpi_object *)response.pointer;
1822
1823 if (!obj)
1824 return;
1825 if (obj->type != ACPI_TYPE_BUFFER) {
1826 pr_warn("Unknown response received %d\n", obj->type);
1827 kfree(obj);
1828 return;
1829 }
1830 if (obj->buffer.length != 8) {
1831 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1832 kfree(obj);
1833 return;
1834 }
1835
1836 return_value = *((struct event_return_value *)obj->buffer.pointer);
1837 kfree(obj);
1838
1839 switch (return_value.function) {
1840 case WMID_HOTKEY_EVENT:
1841 device_state = return_value.device_state;
1842 pr_debug("device state: 0x%x\n", device_state);
1843
1844 key = sparse_keymap_entry_from_scancode(acer_wmi_input_dev,
1845 return_value.key_num);
1846 if (!key) {
1847 pr_warn("Unknown key number - 0x%x\n",
1848 return_value.key_num);
1849 } else {
1850 scancode = return_value.key_num;
1851 switch (key->keycode) {
1852 case KEY_WLAN:
1853 case KEY_BLUETOOTH:
1854 if (has_cap(ACER_CAP_WIRELESS))
1855 rfkill_set_sw_state(wireless_rfkill,
1856 !(device_state & ACER_WMID3_GDS_WIRELESS));
1857 if (has_cap(ACER_CAP_THREEG))
1858 rfkill_set_sw_state(threeg_rfkill,
1859 !(device_state & ACER_WMID3_GDS_THREEG));
1860 if (has_cap(ACER_CAP_BLUETOOTH))
1861 rfkill_set_sw_state(bluetooth_rfkill,
1862 !(device_state & ACER_WMID3_GDS_BLUETOOTH));
1863 break;
1864 case KEY_TOUCHPAD_TOGGLE:
1865 scancode = (device_state & ACER_WMID3_GDS_TOUCHPAD) ?
1866 KEY_TOUCHPAD_ON : KEY_TOUCHPAD_OFF;
1867 }
1868 sparse_keymap_report_event(acer_wmi_input_dev, scancode, 1, true);
1869 }
1870 break;
1871 case WMID_ACCEL_OR_KBD_DOCK_EVENT:
1872 acer_gsensor_event();
1873 acer_kbd_dock_event(&return_value);
1874 break;
1875 default:
1876 pr_warn("Unknown function number - %d - %d\n",
1877 return_value.function, return_value.key_num);
1878 break;
1879 }
1880}
1881
1882static acpi_status __init
1883wmid3_set_function_mode(struct func_input_params *params,
1884 struct func_return_value *return_value)
1885{
1886 acpi_status status;
1887 union acpi_object *obj;
1888
1889 struct acpi_buffer input = { sizeof(struct func_input_params), params };
1890 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
1891
1892 status = wmi_evaluate_method(WMID_GUID3, 0, 0x1, &input, &output);
1893 if (ACPI_FAILURE(status))
1894 return status;
1895
1896 obj = output.pointer;
1897
1898 if (!obj)
1899 return AE_ERROR;
1900 else if (obj->type != ACPI_TYPE_BUFFER) {
1901 kfree(obj);
1902 return AE_ERROR;
1903 }
1904 if (obj->buffer.length != 4) {
1905 pr_warn("Unknown buffer length %d\n", obj->buffer.length);
1906 kfree(obj);
1907 return AE_ERROR;
1908 }
1909
1910 *return_value = *((struct func_return_value *)obj->buffer.pointer);
1911 kfree(obj);
1912
1913 return status;
1914}
1915
1916static int __init acer_wmi_enable_ec_raw(void)
1917{
1918 struct func_return_value return_value;
1919 acpi_status status;
1920 struct func_input_params params = {
1921 .function_num = 0x1,
1922 .commun_devices = 0xFFFF,
1923 .devices = 0xFFFF,
1924 .app_status = 0x00, /* Launch Manager Deactive */
1925 .app_mask = 0x01,
1926 };
1927
1928 status = wmid3_set_function_mode(¶ms, &return_value);
1929
1930 if (return_value.error_code || return_value.ec_return_value)
1931 pr_warn("Enabling EC raw mode failed: 0x%x - 0x%x\n",
1932 return_value.error_code,
1933 return_value.ec_return_value);
1934 else
1935 pr_info("Enabled EC raw mode\n");
1936
1937 return status;
1938}
1939
1940static int __init acer_wmi_enable_lm(void)
1941{
1942 struct func_return_value return_value;
1943 acpi_status status;
1944 struct func_input_params params = {
1945 .function_num = 0x1,
1946 .commun_devices = 0xFFFF,
1947 .devices = 0xFFFF,
1948 .app_status = 0x01, /* Launch Manager Active */
1949 .app_mask = 0x01,
1950 };
1951
1952 status = wmid3_set_function_mode(¶ms, &return_value);
1953
1954 if (return_value.error_code || return_value.ec_return_value)
1955 pr_warn("Enabling Launch Manager failed: 0x%x - 0x%x\n",
1956 return_value.error_code,
1957 return_value.ec_return_value);
1958
1959 return status;
1960}
1961
1962static int __init acer_wmi_enable_rf_button(void)
1963{
1964 struct func_return_value return_value;
1965 acpi_status status;
1966 struct func_input_params params = {
1967 .function_num = 0x1,
1968 .commun_devices = 0xFFFF,
1969 .devices = 0xFFFF,
1970 .app_status = 0x10, /* RF Button Active */
1971 .app_mask = 0x10,
1972 };
1973
1974 status = wmid3_set_function_mode(¶ms, &return_value);
1975
1976 if (return_value.error_code || return_value.ec_return_value)
1977 pr_warn("Enabling RF Button failed: 0x%x - 0x%x\n",
1978 return_value.error_code,
1979 return_value.ec_return_value);
1980
1981 return status;
1982}
1983
1984static int __init acer_wmi_accel_setup(void)
1985{
1986 struct acpi_device *adev;
1987 int err;
1988
1989 adev = acpi_dev_get_first_match_dev("BST0001", NULL, -1);
1990 if (!adev)
1991 return -ENODEV;
1992
1993 gsensor_handle = acpi_device_handle(adev);
1994 acpi_dev_put(adev);
1995
1996 acer_wmi_accel_dev = input_allocate_device();
1997 if (!acer_wmi_accel_dev)
1998 return -ENOMEM;
1999
2000 acer_wmi_accel_dev->open = acer_gsensor_open;
2001
2002 acer_wmi_accel_dev->name = "Acer BMA150 accelerometer";
2003 acer_wmi_accel_dev->phys = "wmi/input1";
2004 acer_wmi_accel_dev->id.bustype = BUS_HOST;
2005 acer_wmi_accel_dev->evbit[0] = BIT_MASK(EV_ABS);
2006 input_set_abs_params(acer_wmi_accel_dev, ABS_X, -16384, 16384, 0, 0);
2007 input_set_abs_params(acer_wmi_accel_dev, ABS_Y, -16384, 16384, 0, 0);
2008 input_set_abs_params(acer_wmi_accel_dev, ABS_Z, -16384, 16384, 0, 0);
2009
2010 err = input_register_device(acer_wmi_accel_dev);
2011 if (err)
2012 goto err_free_dev;
2013
2014 return 0;
2015
2016err_free_dev:
2017 input_free_device(acer_wmi_accel_dev);
2018 return err;
2019}
2020
2021static int __init acer_wmi_input_setup(void)
2022{
2023 acpi_status status;
2024 int err;
2025
2026 acer_wmi_input_dev = input_allocate_device();
2027 if (!acer_wmi_input_dev)
2028 return -ENOMEM;
2029
2030 acer_wmi_input_dev->name = "Acer WMI hotkeys";
2031 acer_wmi_input_dev->phys = "wmi/input0";
2032 acer_wmi_input_dev->id.bustype = BUS_HOST;
2033
2034 err = sparse_keymap_setup(acer_wmi_input_dev, acer_wmi_keymap, NULL);
2035 if (err)
2036 goto err_free_dev;
2037
2038 if (has_cap(ACER_CAP_KBD_DOCK))
2039 input_set_capability(acer_wmi_input_dev, EV_SW, SW_TABLET_MODE);
2040
2041 status = wmi_install_notify_handler(ACERWMID_EVENT_GUID,
2042 acer_wmi_notify, NULL);
2043 if (ACPI_FAILURE(status)) {
2044 err = -EIO;
2045 goto err_free_dev;
2046 }
2047
2048 if (has_cap(ACER_CAP_KBD_DOCK))
2049 acer_kbd_dock_get_initial_state();
2050
2051 err = input_register_device(acer_wmi_input_dev);
2052 if (err)
2053 goto err_uninstall_notifier;
2054
2055 return 0;
2056
2057err_uninstall_notifier:
2058 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
2059err_free_dev:
2060 input_free_device(acer_wmi_input_dev);
2061 return err;
2062}
2063
2064static void acer_wmi_input_destroy(void)
2065{
2066 wmi_remove_notify_handler(ACERWMID_EVENT_GUID);
2067 input_unregister_device(acer_wmi_input_dev);
2068}
2069
2070/*
2071 * debugfs functions
2072 */
2073static u32 get_wmid_devices(void)
2074{
2075 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
2076 union acpi_object *obj;
2077 acpi_status status;
2078 u32 devices = 0;
2079
2080 status = wmi_query_block(WMID_GUID2, 0, &out);
2081 if (ACPI_FAILURE(status))
2082 return 0;
2083
2084 obj = (union acpi_object *) out.pointer;
2085 if (obj) {
2086 if (obj->type == ACPI_TYPE_BUFFER &&
2087 (obj->buffer.length == sizeof(u32) ||
2088 obj->buffer.length == sizeof(u64))) {
2089 devices = *((u32 *) obj->buffer.pointer);
2090 } else if (obj->type == ACPI_TYPE_INTEGER) {
2091 devices = (u32) obj->integer.value;
2092 }
2093 }
2094
2095 kfree(out.pointer);
2096 return devices;
2097}
2098
2099/*
2100 * Platform device
2101 */
2102static int acer_platform_probe(struct platform_device *device)
2103{
2104 int err;
2105
2106 if (has_cap(ACER_CAP_MAILLED)) {
2107 err = acer_led_init(&device->dev);
2108 if (err)
2109 goto error_mailled;
2110 }
2111
2112 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2113 err = acer_backlight_init(&device->dev);
2114 if (err)
2115 goto error_brightness;
2116 }
2117
2118 err = acer_rfkill_init(&device->dev);
2119 if (err)
2120 goto error_rfkill;
2121
2122 return err;
2123
2124error_rfkill:
2125 if (has_cap(ACER_CAP_BRIGHTNESS))
2126 acer_backlight_exit();
2127error_brightness:
2128 if (has_cap(ACER_CAP_MAILLED))
2129 acer_led_exit();
2130error_mailled:
2131 return err;
2132}
2133
2134static int acer_platform_remove(struct platform_device *device)
2135{
2136 if (has_cap(ACER_CAP_MAILLED))
2137 acer_led_exit();
2138 if (has_cap(ACER_CAP_BRIGHTNESS))
2139 acer_backlight_exit();
2140
2141 acer_rfkill_exit();
2142 return 0;
2143}
2144
2145#ifdef CONFIG_PM_SLEEP
2146static int acer_suspend(struct device *dev)
2147{
2148 u32 value;
2149 struct acer_data *data = &interface->data;
2150
2151 if (!data)
2152 return -ENOMEM;
2153
2154 if (has_cap(ACER_CAP_MAILLED)) {
2155 get_u32(&value, ACER_CAP_MAILLED);
2156 set_u32(LED_OFF, ACER_CAP_MAILLED);
2157 data->mailled = value;
2158 }
2159
2160 if (has_cap(ACER_CAP_BRIGHTNESS)) {
2161 get_u32(&value, ACER_CAP_BRIGHTNESS);
2162 data->brightness = value;
2163 }
2164
2165 return 0;
2166}
2167
2168static int acer_resume(struct device *dev)
2169{
2170 struct acer_data *data = &interface->data;
2171
2172 if (!data)
2173 return -ENOMEM;
2174
2175 if (has_cap(ACER_CAP_MAILLED))
2176 set_u32(data->mailled, ACER_CAP_MAILLED);
2177
2178 if (has_cap(ACER_CAP_BRIGHTNESS))
2179 set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
2180
2181 if (acer_wmi_accel_dev)
2182 acer_gsensor_init();
2183
2184 return 0;
2185}
2186#else
2187#define acer_suspend NULL
2188#define acer_resume NULL
2189#endif
2190
2191static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
2192
2193static void acer_platform_shutdown(struct platform_device *device)
2194{
2195 struct acer_data *data = &interface->data;
2196
2197 if (!data)
2198 return;
2199
2200 if (has_cap(ACER_CAP_MAILLED))
2201 set_u32(LED_OFF, ACER_CAP_MAILLED);
2202}
2203
2204static struct platform_driver acer_platform_driver = {
2205 .driver = {
2206 .name = "acer-wmi",
2207 .pm = &acer_pm,
2208 },
2209 .probe = acer_platform_probe,
2210 .remove = acer_platform_remove,
2211 .shutdown = acer_platform_shutdown,
2212};
2213
2214static struct platform_device *acer_platform_device;
2215
2216static void remove_debugfs(void)
2217{
2218 debugfs_remove_recursive(interface->debug.root);
2219}
2220
2221static void __init create_debugfs(void)
2222{
2223 interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
2224
2225 debugfs_create_u32("devices", S_IRUGO, interface->debug.root,
2226 &interface->debug.wmid_devices);
2227}
2228
2229static int __init acer_wmi_init(void)
2230{
2231 int err;
2232
2233 pr_info("Acer Laptop ACPI-WMI Extras\n");
2234
2235 if (dmi_check_system(acer_blacklist)) {
2236 pr_info("Blacklisted hardware detected - not loading\n");
2237 return -ENODEV;
2238 }
2239
2240 find_quirks();
2241
2242 /*
2243 * The AMW0_GUID1 wmi is not only found on Acer family but also other
2244 * machines like Lenovo, Fujitsu and Medion. In the past days,
2245 * acer-wmi driver handled those non-Acer machines by quirks list.
2246 * But actually acer-wmi driver was loaded on any machines that have
2247 * AMW0_GUID1. This behavior is strange because those machines should
2248 * be supported by appropriate wmi drivers. e.g. fujitsu-laptop,
2249 * ideapad-laptop. So, here checks the machine that has AMW0_GUID1
2250 * should be in Acer/Gateway/Packard Bell white list, or it's already
2251 * in the past quirk list.
2252 */
2253 if (wmi_has_guid(AMW0_GUID1) &&
2254 !dmi_check_system(amw0_whitelist) &&
2255 quirks == &quirk_unknown) {
2256 pr_debug("Unsupported machine has AMW0_GUID1, unable to load\n");
2257 return -ENODEV;
2258 }
2259
2260 /*
2261 * Detect which ACPI-WMI interface we're using.
2262 */
2263 if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2264 interface = &AMW0_V2_interface;
2265
2266 if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
2267 interface = &wmid_interface;
2268
2269 if (wmi_has_guid(WMID_GUID3))
2270 interface = &wmid_v2_interface;
2271
2272 if (interface)
2273 dmi_walk(type_aa_dmi_decode, NULL);
2274
2275 if (wmi_has_guid(WMID_GUID2) && interface) {
2276 if (!has_type_aa && ACPI_FAILURE(WMID_set_capabilities())) {
2277 pr_err("Unable to detect available WMID devices\n");
2278 return -ENODEV;
2279 }
2280 /* WMID always provides brightness methods */
2281 interface->capability |= ACER_CAP_BRIGHTNESS;
2282 } else if (!wmi_has_guid(WMID_GUID2) && interface && !has_type_aa && force_caps == -1) {
2283 pr_err("No WMID device detection method found\n");
2284 return -ENODEV;
2285 }
2286
2287 if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
2288 interface = &AMW0_interface;
2289
2290 if (ACPI_FAILURE(AMW0_set_capabilities())) {
2291 pr_err("Unable to detect available AMW0 devices\n");
2292 return -ENODEV;
2293 }
2294 }
2295
2296 if (wmi_has_guid(AMW0_GUID1))
2297 AMW0_find_mailled();
2298
2299 if (!interface) {
2300 pr_err("No or unsupported WMI interface, unable to load\n");
2301 return -ENODEV;
2302 }
2303
2304 set_quirks();
2305
2306 if (dmi_check_system(video_vendor_dmi_table))
2307 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2308
2309 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2310 interface->capability &= ~ACER_CAP_BRIGHTNESS;
2311
2312 if (wmi_has_guid(WMID_GUID3))
2313 interface->capability |= ACER_CAP_SET_FUNCTION_MODE;
2314
2315 if (force_caps != -1)
2316 interface->capability = force_caps;
2317
2318 if (wmi_has_guid(WMID_GUID3) &&
2319 (interface->capability & ACER_CAP_SET_FUNCTION_MODE)) {
2320 if (ACPI_FAILURE(acer_wmi_enable_rf_button()))
2321 pr_warn("Cannot enable RF Button Driver\n");
2322
2323 if (ec_raw_mode) {
2324 if (ACPI_FAILURE(acer_wmi_enable_ec_raw())) {
2325 pr_err("Cannot enable EC raw mode\n");
2326 return -ENODEV;
2327 }
2328 } else if (ACPI_FAILURE(acer_wmi_enable_lm())) {
2329 pr_err("Cannot enable Launch Manager mode\n");
2330 return -ENODEV;
2331 }
2332 } else if (ec_raw_mode) {
2333 pr_info("No WMID EC raw mode enable method\n");
2334 }
2335
2336 if (wmi_has_guid(ACERWMID_EVENT_GUID)) {
2337 err = acer_wmi_input_setup();
2338 if (err)
2339 return err;
2340 err = acer_wmi_accel_setup();
2341 if (err && err != -ENODEV)
2342 pr_warn("Cannot enable accelerometer\n");
2343 }
2344
2345 err = platform_driver_register(&acer_platform_driver);
2346 if (err) {
2347 pr_err("Unable to register platform driver\n");
2348 goto error_platform_register;
2349 }
2350
2351 acer_platform_device = platform_device_alloc("acer-wmi", -1);
2352 if (!acer_platform_device) {
2353 err = -ENOMEM;
2354 goto error_device_alloc;
2355 }
2356
2357 err = platform_device_add(acer_platform_device);
2358 if (err)
2359 goto error_device_add;
2360
2361 if (wmi_has_guid(WMID_GUID2)) {
2362 interface->debug.wmid_devices = get_wmid_devices();
2363 create_debugfs();
2364 }
2365
2366 /* Override any initial settings with values from the commandline */
2367 acer_commandline_init();
2368
2369 return 0;
2370
2371error_device_add:
2372 platform_device_put(acer_platform_device);
2373error_device_alloc:
2374 platform_driver_unregister(&acer_platform_driver);
2375error_platform_register:
2376 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2377 acer_wmi_input_destroy();
2378 if (acer_wmi_accel_dev)
2379 input_unregister_device(acer_wmi_accel_dev);
2380
2381 return err;
2382}
2383
2384static void __exit acer_wmi_exit(void)
2385{
2386 if (wmi_has_guid(ACERWMID_EVENT_GUID))
2387 acer_wmi_input_destroy();
2388
2389 if (acer_wmi_accel_dev)
2390 input_unregister_device(acer_wmi_accel_dev);
2391
2392 remove_debugfs();
2393 platform_device_unregister(acer_platform_device);
2394 platform_driver_unregister(&acer_platform_driver);
2395
2396 pr_info("Acer Laptop WMI Extras unloaded\n");
2397 return;
2398}
2399
2400module_init(acer_wmi_init);
2401module_exit(acer_wmi_exit);