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