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