2 * Acer WMI Laptop Extras
4 * Copyright (C) 2007-2009 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 /* The Aspire One has a dummy ACPI-WMI interface - disable it */
229 static struct dmi_system_id __devinitdata acer_blacklist
[] = {
231 .ident
= "Acer Aspire One (SSD)",
233 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
234 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA110"),
238 .ident
= "Acer Aspire One (HDD)",
240 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
241 DMI_MATCH(DMI_PRODUCT_NAME
, "AOA150"),
247 static struct dmi_system_id acer_quirks
[] = {
249 .callback
= dmi_matched
,
250 .ident
= "Acer Aspire 1360",
252 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
253 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1360"),
255 .driver_data
= &quirk_acer_aspire_1520
,
258 .callback
= dmi_matched
,
259 .ident
= "Acer Aspire 1520",
261 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
262 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 1520"),
264 .driver_data
= &quirk_acer_aspire_1520
,
267 .callback
= dmi_matched
,
268 .ident
= "Acer Aspire 3100",
270 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
271 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
273 .driver_data
= &quirk_acer_travelmate_2490
,
276 .callback
= dmi_matched
,
277 .ident
= "Acer Aspire 3610",
279 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
280 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3610"),
282 .driver_data
= &quirk_acer_travelmate_2490
,
285 .callback
= dmi_matched
,
286 .ident
= "Acer Aspire 5100",
288 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
289 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
291 .driver_data
= &quirk_acer_travelmate_2490
,
294 .callback
= dmi_matched
,
295 .ident
= "Acer Aspire 5610",
297 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
298 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5610"),
300 .driver_data
= &quirk_acer_travelmate_2490
,
303 .callback
= dmi_matched
,
304 .ident
= "Acer Aspire 5630",
306 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
307 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
309 .driver_data
= &quirk_acer_travelmate_2490
,
312 .callback
= dmi_matched
,
313 .ident
= "Acer Aspire 5650",
315 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
316 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
318 .driver_data
= &quirk_acer_travelmate_2490
,
321 .callback
= dmi_matched
,
322 .ident
= "Acer Aspire 5680",
324 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
325 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
327 .driver_data
= &quirk_acer_travelmate_2490
,
330 .callback
= dmi_matched
,
331 .ident
= "Acer Aspire 9110",
333 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
334 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9110"),
336 .driver_data
= &quirk_acer_travelmate_2490
,
339 .callback
= dmi_matched
,
340 .ident
= "Acer TravelMate 2490",
342 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
343 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
345 .driver_data
= &quirk_acer_travelmate_2490
,
348 .callback
= dmi_matched
,
349 .ident
= "Acer TravelMate 4200",
351 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
352 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 4200"),
354 .driver_data
= &quirk_acer_travelmate_2490
,
357 .callback
= dmi_matched
,
358 .ident
= "Fujitsu Siemens Amilo Li 1718",
360 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
361 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Li 1718"),
363 .driver_data
= &quirk_fujitsu_amilo_li_1718
,
366 .callback
= dmi_matched
,
367 .ident
= "Medion MD 98300",
369 DMI_MATCH(DMI_SYS_VENDOR
, "MEDION"),
370 DMI_MATCH(DMI_PRODUCT_NAME
, "WAM2030"),
372 .driver_data
= &quirk_medion_md_98300
,
377 /* Find which quirks are needed for a particular vendor/ model pair */
378 static void find_quirks(void)
381 dmi_check_system(acer_quirks
);
382 } else if (force_series
== 2490) {
383 quirks
= &quirk_acer_travelmate_2490
;
387 quirks
= &quirk_unknown
;
393 * General interface convenience methods
396 static bool has_cap(u32 cap
)
398 if ((interface
->capability
& cap
) != 0)
405 * AMW0 (V1) interface
422 static acpi_status
wmab_execute(struct wmab_args
*regbuf
,
423 struct acpi_buffer
*result
)
425 struct acpi_buffer input
;
427 input
.length
= sizeof(struct wmab_args
);
428 input
.pointer
= (u8
*)regbuf
;
430 status
= wmi_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
435 static acpi_status
AMW0_get_u32(u32
*value
, u32 cap
,
436 struct wmi_interface
*iface
)
442 case ACER_CAP_MAILLED
:
443 switch (quirks
->mailled
) {
445 err
= ec_read(0xA, &result
);
448 *value
= (result
>> 7) & 0x1;
452 case ACER_CAP_WIRELESS
:
453 switch (quirks
->wireless
) {
455 err
= ec_read(0x7B, &result
);
458 *value
= result
& 0x1;
461 err
= ec_read(0x71, &result
);
464 *value
= result
& 0x1;
467 err
= ec_read(0xA, &result
);
470 *value
= (result
>> 2) & 0x1;
474 case ACER_CAP_BLUETOOTH
:
475 switch (quirks
->bluetooth
) {
477 err
= ec_read(0xA, &result
);
480 *value
= (result
>> 4) & 0x1;
484 case ACER_CAP_BRIGHTNESS
:
485 switch (quirks
->brightness
) {
487 err
= ec_read(0x83, &result
);
500 static acpi_status
AMW0_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
502 struct wmab_args args
;
504 args
.eax
= ACER_AMW0_WRITE
;
505 args
.ebx
= value
? (1<<8) : 0;
506 args
.ecx
= args
.edx
= 0;
509 case ACER_CAP_MAILLED
:
511 return AE_BAD_PARAMETER
;
512 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
514 case ACER_CAP_WIRELESS
:
516 return AE_BAD_PARAMETER
;
517 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
519 case ACER_CAP_BLUETOOTH
:
521 return AE_BAD_PARAMETER
;
522 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
524 case ACER_CAP_BRIGHTNESS
:
525 if (value
> max_brightness
)
526 return AE_BAD_PARAMETER
;
527 switch (quirks
->brightness
) {
529 return ec_write(0x83, value
);
536 /* Actually do the set */
537 return wmab_execute(&args
, NULL
);
540 static acpi_status
AMW0_find_mailled(void)
542 struct wmab_args args
;
544 acpi_status status
= AE_OK
;
545 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
546 union acpi_object
*obj
;
549 args
.ebx
= args
.ecx
= args
.edx
= 0;
551 status
= wmab_execute(&args
, &out
);
552 if (ACPI_FAILURE(status
))
555 obj
= (union acpi_object
*) out
.pointer
;
556 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
557 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
558 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
564 interface
->capability
|= ACER_CAP_MAILLED
;
571 static acpi_status
AMW0_set_capabilities(void)
573 struct wmab_args args
;
575 acpi_status status
= AE_OK
;
576 struct acpi_buffer out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
577 union acpi_object
*obj
;
580 * On laptops with this strange GUID (non Acer), normal probing doesn't
583 if (wmi_has_guid(AMW0_GUID2
)) {
584 interface
->capability
|= ACER_CAP_WIRELESS
;
588 args
.eax
= ACER_AMW0_WRITE
;
589 args
.ecx
= args
.edx
= 0;
591 args
.ebx
= 0xa2 << 8;
592 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
594 status
= wmab_execute(&args
, &out
);
595 if (ACPI_FAILURE(status
))
598 obj
= (union acpi_object
*) out
.pointer
;
599 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
600 obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
601 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
607 interface
->capability
|= ACER_CAP_WIRELESS
;
610 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
612 status
= wmab_execute(&args
, &out
);
613 if (ACPI_FAILURE(status
))
616 obj
= (union acpi_object
*) out
.pointer
;
617 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
618 && obj
->buffer
.length
== sizeof(struct wmab_ret
)) {
619 ret
= *((struct wmab_ret
*) obj
->buffer
.pointer
);
625 interface
->capability
|= ACER_CAP_BLUETOOTH
;
630 * This appears to be safe to enable, since all Wistron based laptops
631 * appear to use the same EC register for brightness, even if they
632 * differ for wireless, etc
634 if (quirks
->brightness
>= 0)
635 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
640 static struct wmi_interface AMW0_interface
= {
644 static struct wmi_interface AMW0_V2_interface
= {
645 .type
= ACER_AMW0_V2
,
649 * New interface (The WMID interface)
652 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
654 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
655 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
656 union acpi_object
*obj
;
660 status
= wmi_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
662 if (ACPI_FAILURE(status
))
665 obj
= (union acpi_object
*) result
.pointer
;
666 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
667 obj
->buffer
.length
== sizeof(u32
)) {
668 tmp
= *((u32
*) obj
->buffer
.pointer
);
676 kfree(result
.pointer
);
681 static acpi_status
WMID_get_u32(u32
*value
, u32 cap
,
682 struct wmi_interface
*iface
)
686 u32 result
, method_id
= 0;
689 case ACER_CAP_WIRELESS
:
690 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
692 case ACER_CAP_BLUETOOTH
:
693 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
695 case ACER_CAP_BRIGHTNESS
:
696 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
698 case ACER_CAP_THREEG
:
699 method_id
= ACER_WMID_GET_THREEG_METHODID
;
701 case ACER_CAP_MAILLED
:
702 if (quirks
->mailled
== 1) {
710 status
= WMI_execute_u32(method_id
, 0, &result
);
712 if (ACPI_SUCCESS(status
))
718 static acpi_status
WMID_set_u32(u32 value
, u32 cap
, struct wmi_interface
*iface
)
724 case ACER_CAP_BRIGHTNESS
:
725 if (value
> max_brightness
)
726 return AE_BAD_PARAMETER
;
727 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
729 case ACER_CAP_WIRELESS
:
731 return AE_BAD_PARAMETER
;
732 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
734 case ACER_CAP_BLUETOOTH
:
736 return AE_BAD_PARAMETER
;
737 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
739 case ACER_CAP_THREEG
:
741 return AE_BAD_PARAMETER
;
742 method_id
= ACER_WMID_SET_THREEG_METHODID
;
744 case ACER_CAP_MAILLED
:
746 return AE_BAD_PARAMETER
;
747 if (quirks
->mailled
== 1) {
748 param
= value
? 0x92 : 0x93;
749 i8042_command(¶m
, 0x1059);
756 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
759 static acpi_status
WMID_set_capabilities(void)
761 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
762 union acpi_object
*obj
;
766 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
767 if (ACPI_FAILURE(status
))
770 obj
= (union acpi_object
*) out
.pointer
;
771 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
772 obj
->buffer
.length
== sizeof(u32
)) {
773 devices
= *((u32
*) obj
->buffer
.pointer
);
778 /* Not sure on the meaning of the relevant bits yet to detect these */
779 interface
->capability
|= ACER_CAP_WIRELESS
;
780 interface
->capability
|= ACER_CAP_THREEG
;
782 /* WMID always provides brightness methods */
783 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
786 interface
->capability
|= ACER_CAP_BLUETOOTH
;
788 if (!(devices
& 0x20))
789 max_brightness
= 0x9;
794 static struct wmi_interface wmid_interface
= {
799 * Generic Device (interface-independent)
802 static acpi_status
get_u32(u32
*value
, u32 cap
)
804 acpi_status status
= AE_ERROR
;
806 switch (interface
->type
) {
808 status
= AMW0_get_u32(value
, cap
, interface
);
811 if (cap
== ACER_CAP_MAILLED
) {
812 status
= AMW0_get_u32(value
, cap
, interface
);
816 status
= WMID_get_u32(value
, cap
, interface
);
823 static acpi_status
set_u32(u32 value
, u32 cap
)
827 if (interface
->capability
& cap
) {
828 switch (interface
->type
) {
830 return AMW0_set_u32(value
, cap
, interface
);
832 if (cap
== ACER_CAP_MAILLED
)
833 return AMW0_set_u32(value
, cap
, interface
);
836 * On some models, some WMID methods don't toggle
837 * properly. For those cases, we want to run the AMW0
838 * method afterwards to be certain we've really toggled
841 if (cap
== ACER_CAP_WIRELESS
||
842 cap
== ACER_CAP_BLUETOOTH
) {
843 status
= WMID_set_u32(value
, cap
, interface
);
844 if (ACPI_FAILURE(status
))
847 return AMW0_set_u32(value
, cap
, interface
);
850 return WMID_set_u32(value
, cap
, interface
);
852 return AE_BAD_PARAMETER
;
855 return AE_BAD_PARAMETER
;
858 static void __init
acer_commandline_init(void)
861 * These will all fail silently if the value given is invalid, or the
862 * capability isn't available on the given interface
864 set_u32(mailled
, ACER_CAP_MAILLED
);
865 set_u32(threeg
, ACER_CAP_THREEG
);
866 set_u32(brightness
, ACER_CAP_BRIGHTNESS
);
870 * LED device (Mail LED only, no other LEDs known yet)
872 static void mail_led_set(struct led_classdev
*led_cdev
,
873 enum led_brightness value
)
875 set_u32(value
, ACER_CAP_MAILLED
);
878 static struct led_classdev mail_led
= {
879 .name
= "acer-wmi::mail",
880 .brightness_set
= mail_led_set
,
883 static int __devinit
acer_led_init(struct device
*dev
)
885 return led_classdev_register(dev
, &mail_led
);
888 static void acer_led_exit(void)
890 led_classdev_unregister(&mail_led
);
896 static struct backlight_device
*acer_backlight_device
;
898 static int read_brightness(struct backlight_device
*bd
)
901 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
905 static int update_bl_status(struct backlight_device
*bd
)
907 int intensity
= bd
->props
.brightness
;
909 if (bd
->props
.power
!= FB_BLANK_UNBLANK
)
911 if (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)
914 set_u32(intensity
, ACER_CAP_BRIGHTNESS
);
919 static struct backlight_ops acer_bl_ops
= {
920 .get_brightness
= read_brightness
,
921 .update_status
= update_bl_status
,
924 static int __devinit
acer_backlight_init(struct device
*dev
)
926 struct backlight_device
*bd
;
928 bd
= backlight_device_register("acer-wmi", dev
, NULL
, &acer_bl_ops
);
930 printk(ACER_ERR
"Could not register Acer backlight device\n");
931 acer_backlight_device
= NULL
;
935 acer_backlight_device
= bd
;
937 bd
->props
.power
= FB_BLANK_UNBLANK
;
938 bd
->props
.brightness
= max_brightness
;
939 bd
->props
.max_brightness
= max_brightness
;
940 backlight_update_status(bd
);
944 static void acer_backlight_exit(void)
946 backlight_device_unregister(acer_backlight_device
);
952 static void acer_rfkill_update(struct work_struct
*ignored
);
953 static DECLARE_DELAYED_WORK(acer_rfkill_work
, acer_rfkill_update
);
954 static void acer_rfkill_update(struct work_struct
*ignored
)
959 status
= get_u32(&state
, ACER_CAP_WIRELESS
);
960 if (ACPI_SUCCESS(status
))
961 rfkill_set_sw_state(wireless_rfkill
, !state
);
963 if (has_cap(ACER_CAP_BLUETOOTH
)) {
964 status
= get_u32(&state
, ACER_CAP_BLUETOOTH
);
965 if (ACPI_SUCCESS(status
))
966 rfkill_set_sw_state(bluetooth_rfkill
, !state
);
969 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
972 static int acer_rfkill_set(void *data
, bool blocked
)
975 u32 cap
= (unsigned long)data
;
976 status
= set_u32(!!blocked
, cap
);
977 if (ACPI_FAILURE(status
))
982 static const struct rfkill_ops acer_rfkill_ops
= {
983 .set_block
= acer_rfkill_set
,
986 static struct rfkill
*acer_rfkill_register(struct device
*dev
,
987 enum rfkill_type type
,
991 struct rfkill
*rfkill_dev
;
993 rfkill_dev
= rfkill_alloc(name
, dev
, type
,
995 (void *)(unsigned long)cap
);
997 return ERR_PTR(-ENOMEM
);
999 err
= rfkill_register(rfkill_dev
);
1001 rfkill_destroy(rfkill_dev
);
1002 return ERR_PTR(err
);
1007 static int acer_rfkill_init(struct device
*dev
)
1009 wireless_rfkill
= acer_rfkill_register(dev
, RFKILL_TYPE_WLAN
,
1010 "acer-wireless", ACER_CAP_WIRELESS
);
1011 if (IS_ERR(wireless_rfkill
))
1012 return PTR_ERR(wireless_rfkill
);
1014 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1015 bluetooth_rfkill
= acer_rfkill_register(dev
,
1016 RFKILL_TYPE_BLUETOOTH
, "acer-bluetooth",
1017 ACER_CAP_BLUETOOTH
);
1018 if (IS_ERR(bluetooth_rfkill
)) {
1019 rfkill_unregister(wireless_rfkill
);
1020 rfkill_destroy(wireless_rfkill
);
1021 return PTR_ERR(bluetooth_rfkill
);
1025 schedule_delayed_work(&acer_rfkill_work
, round_jiffies_relative(HZ
));
1030 static void acer_rfkill_exit(void)
1032 cancel_delayed_work_sync(&acer_rfkill_work
);
1034 rfkill_unregister(wireless_rfkill
);
1035 rfkill_destroy(wireless_rfkill
);
1037 if (has_cap(ACER_CAP_BLUETOOTH
)) {
1038 rfkill_unregister(bluetooth_rfkill
);
1039 rfkill_destroy(bluetooth_rfkill
);
1047 static ssize_t
show_bool_threeg(struct device
*dev
,
1048 struct device_attribute
*attr
, char *buf
)
1051 acpi_status status
= get_u32(&result
, ACER_CAP_THREEG
);
1052 if (ACPI_SUCCESS(status
))
1053 return sprintf(buf
, "%u\n", result
);
1054 return sprintf(buf
, "Read error\n");
1057 static ssize_t
set_bool_threeg(struct device
*dev
,
1058 struct device_attribute
*attr
, const char *buf
, size_t count
)
1060 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
1061 acpi_status status
= set_u32(tmp
, ACER_CAP_THREEG
);
1062 if (ACPI_FAILURE(status
))
1066 static DEVICE_ATTR(threeg
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_bool_threeg
,
1069 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1072 switch (interface
->type
) {
1074 return sprintf(buf
, "AMW0\n");
1076 return sprintf(buf
, "AMW0 v2\n");
1078 return sprintf(buf
, "WMID\n");
1080 return sprintf(buf
, "Error!\n");
1084 static DEVICE_ATTR(interface
, S_IWUGO
| S_IRUGO
| S_IWUSR
,
1085 show_interface
, NULL
);
1090 static u32
get_wmid_devices(void)
1092 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1093 union acpi_object
*obj
;
1096 status
= wmi_query_block(WMID_GUID2
, 1, &out
);
1097 if (ACPI_FAILURE(status
))
1100 obj
= (union acpi_object
*) out
.pointer
;
1101 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&&
1102 obj
->buffer
.length
== sizeof(u32
)) {
1103 return *((u32
*) obj
->buffer
.pointer
);
1112 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1116 if (has_cap(ACER_CAP_MAILLED
)) {
1117 err
= acer_led_init(&device
->dev
);
1122 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1123 err
= acer_backlight_init(&device
->dev
);
1125 goto error_brightness
;
1128 err
= acer_rfkill_init(&device
->dev
);
1135 if (has_cap(ACER_CAP_BRIGHTNESS
))
1136 acer_backlight_exit();
1138 if (has_cap(ACER_CAP_MAILLED
))
1144 static int acer_platform_remove(struct platform_device
*device
)
1146 if (has_cap(ACER_CAP_MAILLED
))
1148 if (has_cap(ACER_CAP_BRIGHTNESS
))
1149 acer_backlight_exit();
1155 static int acer_platform_suspend(struct platform_device
*dev
,
1159 struct acer_data
*data
= &interface
->data
;
1164 if (has_cap(ACER_CAP_MAILLED
)) {
1165 get_u32(&value
, ACER_CAP_MAILLED
);
1166 data
->mailled
= value
;
1169 if (has_cap(ACER_CAP_BRIGHTNESS
)) {
1170 get_u32(&value
, ACER_CAP_BRIGHTNESS
);
1171 data
->brightness
= value
;
1177 static int acer_platform_resume(struct platform_device
*device
)
1179 struct acer_data
*data
= &interface
->data
;
1184 if (has_cap(ACER_CAP_MAILLED
))
1185 set_u32(data
->mailled
, ACER_CAP_MAILLED
);
1187 if (has_cap(ACER_CAP_BRIGHTNESS
))
1188 set_u32(data
->brightness
, ACER_CAP_BRIGHTNESS
);
1193 static struct platform_driver acer_platform_driver
= {
1196 .owner
= THIS_MODULE
,
1198 .probe
= acer_platform_probe
,
1199 .remove
= acer_platform_remove
,
1200 .suspend
= acer_platform_suspend
,
1201 .resume
= acer_platform_resume
,
1204 static struct platform_device
*acer_platform_device
;
1206 static int remove_sysfs(struct platform_device
*device
)
1208 if (has_cap(ACER_CAP_THREEG
))
1209 device_remove_file(&device
->dev
, &dev_attr_threeg
);
1211 device_remove_file(&device
->dev
, &dev_attr_interface
);
1216 static int create_sysfs(void)
1218 int retval
= -ENOMEM
;
1220 if (has_cap(ACER_CAP_THREEG
)) {
1221 retval
= device_create_file(&acer_platform_device
->dev
,
1227 retval
= device_create_file(&acer_platform_device
->dev
,
1228 &dev_attr_interface
);
1235 remove_sysfs(acer_platform_device
);
1239 static void remove_debugfs(void)
1241 debugfs_remove(interface
->debug
.devices
);
1242 debugfs_remove(interface
->debug
.root
);
1245 static int create_debugfs(void)
1247 interface
->debug
.root
= debugfs_create_dir("acer-wmi", NULL
);
1248 if (!interface
->debug
.root
) {
1249 printk(ACER_ERR
"Failed to create debugfs directory");
1253 interface
->debug
.devices
= debugfs_create_u32("devices", S_IRUGO
,
1254 interface
->debug
.root
,
1255 &interface
->debug
.wmid_devices
);
1256 if (!interface
->debug
.devices
)
1266 static int __init
acer_wmi_init(void)
1270 printk(ACER_INFO
"Acer Laptop ACPI-WMI Extras\n");
1272 if (dmi_check_system(acer_blacklist
)) {
1273 printk(ACER_INFO
"Blacklisted hardware detected - "
1281 * Detect which ACPI-WMI interface we're using.
1283 if (wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1284 interface
= &AMW0_V2_interface
;
1286 if (!wmi_has_guid(AMW0_GUID1
) && wmi_has_guid(WMID_GUID1
))
1287 interface
= &wmid_interface
;
1289 if (wmi_has_guid(WMID_GUID2
) && interface
) {
1290 if (ACPI_FAILURE(WMID_set_capabilities())) {
1291 printk(ACER_ERR
"Unable to detect available WMID "
1295 } else if (!wmi_has_guid(WMID_GUID2
) && interface
) {
1296 printk(ACER_ERR
"No WMID device detection method found\n");
1300 if (wmi_has_guid(AMW0_GUID1
) && !wmi_has_guid(WMID_GUID1
)) {
1301 interface
= &AMW0_interface
;
1303 if (ACPI_FAILURE(AMW0_set_capabilities())) {
1304 printk(ACER_ERR
"Unable to detect available AMW0 "
1310 if (wmi_has_guid(AMW0_GUID1
))
1311 AMW0_find_mailled();
1314 printk(ACER_ERR
"No or unsupported WMI interface, unable to "
1321 if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS
)) {
1322 interface
->capability
&= ~ACER_CAP_BRIGHTNESS
;
1323 printk(ACER_INFO
"Brightness must be controlled by "
1324 "generic video driver\n");
1327 if (platform_driver_register(&acer_platform_driver
)) {
1328 printk(ACER_ERR
"Unable to register platform driver.\n");
1329 goto error_platform_register
;
1331 acer_platform_device
= platform_device_alloc("acer-wmi", -1);
1332 platform_device_add(acer_platform_device
);
1334 err
= create_sysfs();
1338 if (wmi_has_guid(WMID_GUID2
)) {
1339 interface
->debug
.wmid_devices
= get_wmid_devices();
1340 err
= create_debugfs();
1345 /* Override any initial settings with values from the commandline */
1346 acer_commandline_init();
1350 error_platform_register
:
1354 static void __exit
acer_wmi_exit(void)
1356 remove_sysfs(acer_platform_device
);
1358 platform_device_del(acer_platform_device
);
1359 platform_driver_unregister(&acer_platform_driver
);
1361 printk(ACER_INFO
"Acer Laptop WMI Extras unloaded\n");
1365 module_init(acer_wmi_init
);
1366 module_exit(acer_wmi_exit
);