2 * Acer WMI Laptop Extras
4 * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk>
7 * Copyright (C) 2005-2007 E.M. Smith
8 * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/dmi.h>
31 #include <linux/backlight.h>
32 #include <linux/leds.h>
33 #include <linux/platform_device.h>
34 #include <linux/acpi.h>
35 #include <linux/i8042.h>
36 #include <linux/rfkill.h>
37 #include <linux/workqueue.h>
38 #include <linux/debugfs.h>
40 #include <acpi/acpi_drivers.h>
42 MODULE_AUTHOR("Carlos Corbacho");
43 MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
44 MODULE_LICENSE("GPL");
46 #define ACER_LOGPREFIX "acer-wmi: "
47 #define ACER_ERR KERN_ERR ACER_LOGPREFIX
48 #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
49 #define ACER_INFO KERN_INFO ACER_LOGPREFIX
52 * The following defines quirks to get some specific functions to work
53 * which are known to not be supported over ACPI-WMI (such as the mail LED
54 * on WMID based Acer's)
64 * Meaning is unknown - this number is required for writing to ACPI for AMW0
65 * (it's also used in acerhk when directly accessing the BIOS)
67 #define ACER_AMW0_WRITE 0x9610
70 * Bit masks for the AMW0 interface
72 #define ACER_AMW0_WIRELESS_MASK 0x35
73 #define ACER_AMW0_BLUETOOTH_MASK 0x34
74 #define ACER_AMW0_MAILLED_MASK 0x31
77 * Method IDs for WMID interface
79 #define ACER_WMID_GET_WIRELESS_METHODID 1
80 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
81 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
82 #define ACER_WMID_SET_WIRELESS_METHODID 4
83 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
84 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
85 #define ACER_WMID_GET_THREEG_METHODID 10
86 #define ACER_WMID_SET_THREEG_METHODID 11
89 * Acer ACPI method GUIDs
91 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
92 #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C"
93 #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
94 #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
96 MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
97 MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
99 /* Temporary workaround until the WMI sysfs interface goes in */
100 MODULE_ALIAS("dmi:*:*Acer*:*:");
103 * Interface capability flags
105 #define ACER_CAP_MAILLED (1<<0)
106 #define ACER_CAP_WIRELESS (1<<1)
107 #define ACER_CAP_BLUETOOTH (1<<2)
108 #define ACER_CAP_BRIGHTNESS (1<<3)
109 #define ACER_CAP_THREEG (1<<4)
110 #define ACER_CAP_ANY (0xFFFFFFFF)
113 * Interface type flags
115 enum interface_flags
{
121 #define ACER_DEFAULT_WIRELESS 0
122 #define ACER_DEFAULT_BLUETOOTH 0
123 #define ACER_DEFAULT_MAILLED 0
124 #define ACER_DEFAULT_THREEG 0
126 static int max_brightness
= 0xF;
128 static int mailled
= -1;
129 static int brightness
= -1;
130 static int threeg
= -1;
131 static int force_series
;
133 module_param(mailled
, int, 0444);
134 module_param(brightness
, int, 0444);
135 module_param(threeg
, int, 0444);
136 module_param(force_series
, int, 0444);
137 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
138 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
139 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
140 MODULE_PARM_DESC(force_series
, "Force a different laptop series");
150 struct dentry
*devices
;
154 static struct rfkill
*wireless_rfkill
;
155 static struct rfkill
*bluetooth_rfkill
;
157 /* Each low-level interface must define at least some of the following */
158 struct wmi_interface
{
159 /* The WMI device type */
162 /* The capabilities this interface provides */
165 /* Private data for the current interface */
166 struct acer_data data
;
168 /* debugfs entries associated with this interface */
169 struct acer_debug debug
;
172 /* The static interface pointer, points to the currently detected interface */
173 static struct wmi_interface
*interface
;
176 * Embedded Controller quirks
177 * Some laptops require us to directly access the EC to either enable or query
178 * features that are not available through WMI.
188 static struct quirk_entry
*quirks
;
190 static void set_quirks(void)
196 interface
->capability
|= ACER_CAP_MAILLED
;
198 if (quirks
->brightness
)
199 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
202 static int dmi_matched(const struct dmi_system_id
*dmi
)
204 quirks
= dmi
->driver_data
;
208 static struct quirk_entry quirk_unknown
= {
211 static struct quirk_entry quirk_acer_aspire_1520
= {
215 static struct quirk_entry quirk_acer_travelmate_2490
= {
219 /* This AMW0 laptop has no bluetooth */
220 static struct quirk_entry quirk_medion_md_98300
= {
224 static struct quirk_entry quirk_fujitsu_amilo_li_1718
= {
228 static struct dmi_system_id acer_quirks
[] = {
230 .callback
= dmi_matched
,
231 .ident
= "Acer Aspire 1360",
233 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
234 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
236 .driver_data
= &quirk_acer_aspire_1520
,
239 .callback
= dmi_matched
,
240 .ident
= "Acer Aspire 1520",
242 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
243 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
245 .driver_data
= &quirk_acer_aspire_1520
,
248 .callback
= dmi_matched
,
249 .ident
= "Acer Aspire 3100",
251 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
252 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
254 .driver_data
= &quirk_acer_travelmate_2490
,
257 .callback
= dmi_matched
,
258 .ident
= "Acer Aspire 3610",
260 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
261 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
263 .driver_data
= &quirk_acer_travelmate_2490
,
266 .callback
= dmi_matched
,
267 .ident
= "Acer Aspire 5100",
269 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
270 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
272 .driver_data
= &quirk_acer_travelmate_2490
,
275 .callback
= dmi_matched
,
276 .ident
= "Acer Aspire 5610",
278 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
279 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
281 .driver_data
= &quirk_acer_travelmate_2490
,
284 .callback
= dmi_matched
,
285 .ident
= "Acer Aspire 5630",
287 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
288 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
290 .driver_data
= &quirk_acer_travelmate_2490
,
293 .callback
= dmi_matched
,
294 .ident
= "Acer Aspire 5650",
296 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
297 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
299 .driver_data
= &quirk_acer_travelmate_2490
,
302 .callback
= dmi_matched
,
303 .ident
= "Acer Aspire 5680",
305 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
306 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
308 .driver_data
= &quirk_acer_travelmate_2490
,
311 .callback
= dmi_matched
,
312 .ident
= "Acer Aspire 9110",
314 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
315 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
317 .driver_data
= &quirk_acer_travelmate_2490
,
320 .callback
= dmi_matched
,
321 .ident
= "Acer TravelMate 2490",
323 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
324 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
326 .driver_data
= &quirk_acer_travelmate_2490
,
329 .callback
= dmi_matched
,
330 .ident
= "Acer TravelMate 4200",
332 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
333 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
335 .driver_data
= &quirk_acer_travelmate_2490
,
338 .callback
= dmi_matched
,
339 .ident
= "Fujitsu Siemens Amilo Li 1718",
341 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
342 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
344 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
347 .callback
= dmi_matched
,
348 .ident
= "Medion MD 98300",
350 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
351 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
353 .driver_data
= &quirk_medion_md_98300
,
358 /* Find which quirks are needed for a particular vendor/ model pair */
359 static void find_quirks(void)
362 dmi_check_system(acer_quirks
);
363 } else if (force_series
== 2490) {
364 quirks
= &quirk_acer_travelmate_2490
;
368 quirks
= &quirk_unknown
;
374 * General interface convenience methods
377 static bool has_cap(u32 cap
)
379 if ((interface
->capability
& cap
) != 0)
386 * AMW0 (V1) interface
403 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
404 struct acpi_buffer
*result
)
406 struct acpi_buffer input
;
408 input
.length
= sizeof(struct wmab_args
);
409 input
.pointer
= (u8
*)regbuf
;
411 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
416 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
,
417 struct wmi_interface
*iface
)
423 case ACER_CAP_MAILLED
:
424 switch (quirks
->mailled
) {
426 err
= ec_read(0xA, &result
);
429 *value
= (result
>> 7) & 0x1;
433 case ACER_CAP_WIRELESS
:
434 switch (quirks
->wireless
) {
436 err
= ec_read(0x7B, &result
);
439 *value
= result
& 0x1;
442 err
= ec_read(0x71, &result
);
445 *value
= result
& 0x1;
448 err
= ec_read(0xA, &result
);
451 *value
= (result
>> 2) & 0x1;
455 case ACER_CAP_BLUETOOTH
:
456 switch (quirks
->bluetooth
) {
458 err
= ec_read(0xA, &result
);
461 *value
= (result
>> 4) & 0x1;
465 case ACER_CAP_BRIGHTNESS
:
466 switch (quirks
->brightness
) {
468 err
= ec_read(0x83, &result
);
481 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
483 struct wmab_args args
;
485 args
.eax
= ACER_AMW0_WRITE
;
486 args
.ebx
= value
? (1<<8) : 0;
487 args
.ecx
= args
.edx
= 0;
490 case ACER_CAP_MAILLED
:
492 return AE_BAD_PARAMETER
;
493 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
495 case ACER_CAP_WIRELESS
:
497 return AE_BAD_PARAMETER
;
498 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
500 case ACER_CAP_BLUETOOTH
:
502 return AE_BAD_PARAMETER
;
503 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
505 case ACER_CAP_BRIGHTNESS
:
506 if (value
> max_brightness
)
507 return AE_BAD_PARAMETER
;
508 switch (quirks
->brightness
) {
510 return ec_write(0x83, value
);
517 /* Actually do the set */
518 return wmab_execute(&args
, NULL
);
521 static acpi_status
AMW0_find_mailled(void)
523 struct wmab_args args
;
525 acpi_status status
= AE_OK
;
526 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
527 union acpi_object
*obj
;
530 args
.ebx
= args
.ecx
= args
.edx
= 0;
532 status
= wmab_execute(&args
, &out
);
533 if (ACPI_FAILURE(status
))
536 obj
= (union acpi_object
*) out
.pointer
;
537 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
538 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
539 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
545 interface
->capability
|= ACER_CAP_MAILLED
;
552 static acpi_status
AMW0_set_capabilities(void)
554 struct wmab_args args
;
556 acpi_status status
= AE_OK
;
557 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
558 union acpi_object
*obj
;
561 * On laptops with this strange GUID (non Acer), normal probing doesn't
564 if (wmi_has_guid(AMW0_GUID2
)) {
565 interface
->capability
|= ACER_CAP_WIRELESS
;
569 args
.eax
= ACER_AMW0_WRITE
;
570 args
.ecx
= args
.edx
= 0;
572 args
.ebx
= 0xa2 << 8;
573 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
575 status
= wmab_execute(&args
, &out
);
576 if (ACPI_FAILURE(status
))
579 obj
= (union acpi_object
*) out
.pointer
;
580 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
581 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
582 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
588 interface
->capability
|= ACER_CAP_WIRELESS
;
591 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
593 status
= wmab_execute(&args
, &out
);
594 if (ACPI_FAILURE(status
))
597 obj
= (union acpi_object
*) out
.pointer
;
598 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
599 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
600 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
606 interface
->capability
|= ACER_CAP_BLUETOOTH
;
611 * This appears to be safe to enable, since all Wistron based laptops
612 * appear to use the same EC register for brightness, even if they
613 * differ for wireless, etc
615 if (quirks
->brightness
>= 0)
616 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
621 static struct wmi_interface AMW0_interface
= {
625 static struct wmi_interface AMW0_V2_interface
= {
626 .type
= ACER_AMW0_V2
,
630 * New interface (The WMID interface)
633 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
635 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
636 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
637 union acpi_object
*obj
;
641 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
643 if (ACPI_FAILURE(status
))
646 obj
= (union acpi_object
*) result
.pointer
;
647 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
648 obj
->buffer
.length
== sizeof(u32
)) {
649 tmp
= *((u32
*) obj
->buffer
.pointer
);
657 kfree(result
.pointer
);
662 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
,
663 struct wmi_interface
*iface
)
667 u32 result
, method_id
= 0;
670 case ACER_CAP_WIRELESS
:
671 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
673 case ACER_CAP_BLUETOOTH
:
674 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
676 case ACER_CAP_BRIGHTNESS
:
677 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
679 case ACER_CAP_THREEG
:
680 method_id
= ACER_WMID_GET_THREEG_METHODID
;
682 case ACER_CAP_MAILLED
:
683 if (quirks
->mailled
== 1) {
691 status
= WMI_execute_u32(method_id
, 0, &result
);
693 if (ACPI_SUCCESS(status
))
699 static acpi_status
WMID_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
705 case ACER_CAP_BRIGHTNESS
:
706 if (value
> max_brightness
)
707 return AE_BAD_PARAMETER
;
708 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
710 case ACER_CAP_WIRELESS
:
712 return AE_BAD_PARAMETER
;
713 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
715 case ACER_CAP_BLUETOOTH
:
717 return AE_BAD_PARAMETER
;
718 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
720 case ACER_CAP_THREEG
:
722 return AE_BAD_PARAMETER
;
723 method_id
= ACER_WMID_SET_THREEG_METHODID
;
725 case ACER_CAP_MAILLED
:
727 return AE_BAD_PARAMETER
;
728 if (quirks
->mailled
== 1) {
729 param
= value
? 0x92 : 0x93;
730 i8042_command(¶m
, 0x1059);
737 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
740 static acpi_status
WMID_set_capabilities(void)
742 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
743 union acpi_object
*obj
;
747 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
748 if (ACPI_FAILURE(status
))
751 obj
= (union acpi_object
*) out
.pointer
;
752 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
753 obj
->buffer
.length
== sizeof(u32
)) {
754 devices
= *((u32
*) obj
->buffer
.pointer
);
759 /* Not sure on the meaning of the relevant bits yet to detect these */
760 interface
->capability
|= ACER_CAP_WIRELESS
;
761 interface
->capability
|= ACER_CAP_THREEG
;
763 /* WMID always provides brightness methods */
764 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
767 interface
->capability
|= ACER_CAP_BLUETOOTH
;
769 if (!(devices
& 0x20))
770 max_brightness
= 0x9;
775 static struct wmi_interface wmid_interface
= {
780 * Generic Device (interface-independent)
783 static acpi_status
get_u32(u32
*value
, u32 cap
)
785 acpi_status status
= AE_ERROR
;
787 switch (interface
->type
) {
789 status
= AMW0_get_u32(value
, cap
, interface
);
792 if (cap
== ACER_CAP_MAILLED
) {
793 status
= AMW0_get_u32(value
, cap
, interface
);
797 status
= WMID_get_u32(value
, cap
, interface
);
804 static acpi_status
set_u32(u32 value
, u32 cap
)
808 if (interface
->capability
& cap
) {
809 switch (interface
->type
) {
811 return AMW0_set_u32(value
, cap
, interface
);
813 if (cap
== ACER_CAP_MAILLED
)
814 return AMW0_set_u32(value
, cap
, interface
);
817 * On some models, some WMID methods don't toggle
818 * properly. For those cases, we want to run the AMW0
819 * method afterwards to be certain we've really toggled
822 if (cap
== ACER_CAP_WIRELESS
||
823 cap
== ACER_CAP_BLUETOOTH
) {
824 status
= WMID_set_u32(value
, cap
, interface
);
825 if (ACPI_FAILURE(status
))
828 return AMW0_set_u32(value
, cap
, interface
);
831 return WMID_set_u32(value
, cap
, interface
);
833 return AE_BAD_PARAMETER
;
836 return AE_BAD_PARAMETER
;
839 static void __init
acer_commandline_init(void)
842 * These will all fail silently if the value given is invalid, or the
843 * capability isn't available on the given interface
845 set_u32(mailled
, ACER_CAP_MAILLED
);
846 set_u32(threeg
, ACER_CAP_THREEG
);
847 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
851 * LED device (Mail LED only, no other LEDs known yet)
853 static void mail_led_set(struct led_classdev
*led_cdev
,
854 enum led_brightness value
)
856 set_u32(value
, ACER_CAP_MAILLED
);
859 static struct led_classdev mail_led
= {
860 .name
= "acer-wmi::mail",
861 .brightness_set
= mail_led_set
,
864 static int __devinit
acer_led_init(struct device
*dev
)
866 return led_classdev_register(dev
, &mail_led
);
869 static void acer_led_exit(void)
871 led_classdev_unregister(&mail_led
);
877 static struct backlight_device
*acer_backlight_device
;
879 static int read_brightness(struct backlight_device
*bd
)
882 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
886 static int update_bl_status(struct backlight_device
*bd
)
888 int intensity
= bd
->props
.brightness
;
890 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
892 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
895 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
900 static struct backlight_ops acer_bl_ops
= {
901 .get_brightness
= read_brightness
,
902 .update_status
= update_bl_status
,
905 static int __devinit
acer_backlight_init(struct device
*dev
)
907 struct backlight_device
*bd
;
909 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
);
911 printk(ACER_ERR
"Could not register Acer backlight device\n");
912 acer_backlight_device
= NULL
;
916 acer_backlight_device
= bd
;
918 bd
->props
.power
= FB_BLANK_UNBLANK
;
919 bd
->props
.brightness
= max_brightness
;
920 bd
->props
.max_brightness
= max_brightness
;
921 backlight_update_status(bd
);
925 static void acer_backlight_exit(void)
927 backlight_device_unregister(acer_backlight_device
);
933 static void acer_rfkill_update(struct work_struct
*ignored
);
934 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
935 static void acer_rfkill_update(struct work_struct
*ignored
)
940 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
941 if (ACPI_SUCCESS(status
))
942 rfkill_force_state(wireless_rfkill
, state
?
943 RFKILL_STATE_UNBLOCKED
: RFKILL_STATE_SOFT_BLOCKED
);
945 if (has_cap(ACER_CAP_BLUETOOTH
)) {
946 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
947 if (ACPI_SUCCESS(status
))
948 rfkill_force_state(bluetooth_rfkill
, state
?
949 RFKILL_STATE_UNBLOCKED
:
950 RFKILL_STATE_SOFT_BLOCKED
);
953 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
956 static int acer_rfkill_set(void *data
, enum rfkill_state state
)
960 status
= set_u32((u32
) (state
== RFKILL_STATE_UNBLOCKED
), *cap
);
961 if (ACPI_FAILURE(status
))
966 static struct rfkill
* acer_rfkill_register(struct device
*dev
,
967 enum rfkill_type type
, char *name
, u32 cap
)
972 struct rfkill
*rfkill_dev
;
974 rfkill_dev
= rfkill_allocate(dev
, type
);
976 return ERR_PTR(-ENOMEM
);
977 rfkill_dev
->name
= name
;
978 get_u32(&state
, cap
);
979 rfkill_dev
->state
= state
? RFKILL_STATE_UNBLOCKED
:
980 RFKILL_STATE_SOFT_BLOCKED
;
981 data
= kzalloc(sizeof(u32
), GFP_KERNEL
);
983 rfkill_free(rfkill_dev
);
984 return ERR_PTR(-ENOMEM
);
987 rfkill_dev
->data
= data
;
988 rfkill_dev
->toggle_radio
= acer_rfkill_set
;
989 rfkill_dev
->user_claim_unsupported
= 1;
991 err
= rfkill_register(rfkill_dev
);
993 kfree(rfkill_dev
->data
);
994 rfkill_free(rfkill_dev
);
1000 static int acer_rfkill_init(struct device
*dev
)
1002 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1003 "acer-wireless", ACER_CAP_WIRELESS
);
1004 if (IS_ERR(wireless_rfkill
))
1005 return PTR_ERR(wireless_rfkill
);
1007 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1008 bluetooth_rfkill
= acer_rfkill_register(dev
,
1009 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1010 ACER_CAP_BLUETOOTH
);
1011 if (IS_ERR(bluetooth_rfkill
)) {
1012 kfree(wireless_rfkill
->data
);
1013 rfkill_unregister(wireless_rfkill
);
1014 return PTR_ERR(bluetooth_rfkill
);
1018 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1023 static void acer_rfkill_exit(void)
1025 cancel_delayed_work_sync(&acer_rfkill_work
);
1026 kfree(wireless_rfkill
->data
);
1027 rfkill_unregister(wireless_rfkill
);
1028 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1029 kfree(wireless_rfkill
->data
);
1030 rfkill_unregister(bluetooth_rfkill
);
1038 static ssize_t
show_bool_threeg(struct device
*dev
,
1039 struct device_attribute
*attr
, char *buf
)
1042 acpi_status status
= get_u32(&result
, ACER_CAP_THREEG
);
1043 if (ACPI_SUCCESS(status
))
1044 return sprintf(buf
, "%u\n", result
);
1045 return sprintf(buf
, "Read error\n");
1048 static ssize_t
set_bool_threeg(struct device
*dev
,
1049 struct device_attribute
*attr
, const char *buf
, size_t count
)
1051 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
1052 acpi_status status
= set_u32(tmp
, ACER_CAP_THREEG
);
1053 if (ACPI_FAILURE(status
))
1057 static DEVICE_ATTR(threeg
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_bool_threeg
,
1060 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1063 switch (interface
->type
) {
1065 return sprintf(buf
, "AMW0\n");
1067 return sprintf(buf
, "AMW0 v2\n");
1069 return sprintf(buf
, "WMID\n");
1071 return sprintf(buf
, "Error!\n");
1075 static DEVICE_ATTR(interface
, S_IWUGO
| S_IRUGO
| S_IWUSR
,
1076 show_interface
, NULL
);
1081 static u32
get_wmid_devices(void)
1083 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1084 union acpi_object
*obj
;
1087 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1088 if (ACPI_FAILURE(status
))
1091 obj
= (union acpi_object
*) out
.pointer
;
1092 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1093 obj
->buffer
.length
== sizeof(u32
)) {
1094 return *((u32
*) obj
->buffer
.pointer
);
1103 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1107 if (has_cap(ACER_CAP_MAILLED
)) {
1108 err
= acer_led_init(&device
->dev
);
1113 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1114 err
= acer_backlight_init(&device
->dev
);
1116 goto error_brightness
;
1119 err
= acer_rfkill_init(&device
->dev
);
1129 static int acer_platform_remove(struct platform_device
*device
)
1131 if (has_cap(ACER_CAP_MAILLED
))
1133 if (has_cap(ACER_CAP_BRIGHTNESS
))
1134 acer_backlight_exit();
1140 static int acer_platform_suspend(struct platform_device
*dev
,
1144 struct acer_data
*data
= &interface
->data
;
1149 if (has_cap(ACER_CAP_MAILLED
)) {
1150 get_u32(&value
, ACER_CAP_MAILLED
);
1151 data
->mailled
= value
;
1154 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1155 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1156 data
->brightness
= value
;
1162 static int acer_platform_resume(struct platform_device
*device
)
1164 struct acer_data
*data
= &interface
->data
;
1169 if (has_cap(ACER_CAP_MAILLED
))
1170 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
1172 if (has_cap(ACER_CAP_BRIGHTNESS
))
1173 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
1178 static struct platform_driver acer_platform_driver
= {
1181 .owner
= THIS_MODULE
,
1183 .probe
= acer_platform_probe
,
1184 .remove
= acer_platform_remove
,
1185 .suspend
= acer_platform_suspend
,
1186 .resume
= acer_platform_resume
,
1189 static struct platform_device
*acer_platform_device
;
1191 static int remove_sysfs(struct platform_device
*device
)
1193 if (has_cap(ACER_CAP_THREEG
))
1194 device_remove_file(&device
->dev
, &dev_attr_threeg
);
1196 device_remove_file(&device
->dev
, &dev_attr_interface
);
1201 static int create_sysfs(void)
1203 int retval
= -ENOMEM
;
1205 if (has_cap(ACER_CAP_THREEG
)) {
1206 retval
= device_create_file(&acer_platform_device
->dev
,
1212 retval
= device_create_file(&acer_platform_device
->dev
,
1213 &dev_attr_interface
);
1220 remove_sysfs(acer_platform_device
);
1224 static void remove_debugfs(void)
1226 debugfs_remove(interface
->debug
.devices
);
1227 debugfs_remove(interface
->debug
.root
);
1230 static int create_debugfs(void)
1232 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
1233 if (!interface
->debug
.root
) {
1234 printk(ACER_ERR
"Failed to create debugfs directory");
1238 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
1239 interface
->debug
.root
,
1240 &interface
->debug
.wmid_devices
);
1241 if (!interface
->debug
.devices
)
1251 static int __init
acer_wmi_init(void)
1255 printk(ACER_INFO
"Acer Laptop ACPI-WMI Extras\n");
1260 * Detect which ACPI-WMI interface we're using.
1262 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1263 interface
= &AMW0_V2_interface
;
1265 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1266 interface
= &wmid_interface
;
1268 if (wmi_has_guid(WMID_GUID2
) && interface
) {
1269 if (ACPI_FAILURE(WMID_set_capabilities())) {
1270 printk(ACER_ERR
"Unable to detect available WMID "
1274 } else if (!wmi_has_guid(WMID_GUID2
) && interface
) {
1275 printk(ACER_ERR
"No WMID device detection method found\n");
1279 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
1280 interface
= &AMW0_interface
;
1282 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1283 printk(ACER_ERR
"Unable to detect available AMW0 "
1289 if (wmi_has_guid(AMW0_GUID1
))
1290 AMW0_find_mailled();
1293 printk(ACER_ERR
"No or unsupported WMI interface, unable to "
1300 if (platform_driver_register(&acer_platform_driver
)) {
1301 printk(ACER_ERR
"Unable to register platform driver.\n");
1302 goto error_platform_register
;
1304 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
1305 platform_device_add(acer_platform_device
);
1307 err
= create_sysfs();
1311 if (wmi_has_guid(WMID_GUID2
)) {
1312 interface
->debug
.wmid_devices
= get_wmid_devices();
1313 err
= create_debugfs();
1318 /* Override any initial settings with values from the commandline */
1319 acer_commandline_init();
1323 error_platform_register
:
1327 static void __exit
acer_wmi_exit(void)
1329 remove_sysfs(acer_platform_device
);
1331 platform_device_del(acer_platform_device
);
1332 platform_driver_unregister(&acer_platform_driver
);
1334 printk(ACER_INFO
"Acer Laptop WMI Extras unloaded\n");
1338 module_init(acer_wmi_init
);
1339 module_exit(acer_wmi_exit
);