2 * Acer Laptop ACPI Extras
4 * Copyright (C) 2005-2007 E.M. Smith
5 * Copyright (C) 2007 Carlos Corbacho <cathectic@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * The devolpment page for this driver is located at
23 * http://code.google.com/p/aceracpi
27 * John Belmonte - the Toshiba ACPI driver originally adapted for this module.
28 * Julien Lerouge & Karol Kozimor - ASUS Acpi driver authors.
29 * Olaf Tauber - developer of acerhk, the inspiration to solve the 64-bit
30 * driver problem for my Aspire 5024.
31 * Mathieu Segaud - solved the ACPI problem that needed a double-modprobe
32 * in version 0.2 and below.
33 * Jim Ramsay - Figured out and added support for WMID interface
36 #define ACER_ACPI_VERSION "0.10.0"
39 * Comment the following line out to remove /proc support
44 #define PROC_ACER "acer"
45 #include <linux/proc_fs.h>
48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/init.h>
51 #include <linux/types.h>
52 #include <linux/delay.h>
53 #include <linux/version.h>
55 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,17)
56 #include <asm/uaccess.h>
58 #include <linux/uaccess.h>
62 #include <linux/dmi.h>
63 #include <linux/backlight.h>
64 #include <linux/leds.h>
65 #include <linux/platform_device.h>
67 #include <acpi/acpi_drivers.h>
71 /* Workaround needed for older kernels */
76 MODULE_AUTHOR("Mark Smith, Carlos Corbacho");
77 MODULE_DESCRIPTION("Acer Laptop ACPI Extras Driver");
78 MODULE_LICENSE("GPL");
80 MODULE_ALIAS("dmi:*:*Acer*:*:");
82 #define ACER_LOGPREFIX "acer_acpi: "
83 #define ACER_ERR KERN_ERR ACER_LOGPREFIX
84 #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
85 #define ACER_INFO KERN_INFO ACER_LOGPREFIX
87 #define DEBUG(level, message...) { \
89 printk(KERN_DEBUG ACER_LOGPREFIX message);\
93 * The maximum temperature one can set for fan control override.
94 * Doesn't propably make much sense if over 80 degrees celsius though...
96 #define ACER_MAX_TEMPERATURE_OVERRIDE 150
99 * The following defines quirks to get some specific functions to work
100 * which are known to not be supported over ACPI (such as the mail LED
101 * on WMID based Acer's)
110 * Keyboard controller ports
112 #define ACER_KBD_STATUS_REG 0x64 /* Status register (R) */
113 #define ACER_KBD_CNTL_REG 0x64 /* Controller command register (W) */
114 #define ACER_KBD_DATA_REG 0x60 /* Keyboard data register (R/W) */
118 * Meaning is unknown - this number is required for writing to ACPI for AMW0
119 * (it's also used in acerhk when directly accessing the EC)
121 #define ACER_AMW0_WRITE 0x9610
124 * Bit masks for the old AMW0 interface
126 #define ACER_AMW0_WIRELESS_MASK 0x35
127 #define ACER_AMW0_BLUETOOTH_MASK 0x34
128 #define ACER_AMW0_MAILLED_MASK 0x31
131 * Method IDs for new WMID interface
133 #define ACER_WMID_GET_WIRELESS_METHODID 1
134 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
135 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
136 #define ACER_WMID_SET_WIRELESS_METHODID 4
137 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
138 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
139 #define ACER_WMID_GET_THREEG_METHODID 10
140 #define ACER_WMID_SET_THREEG_METHODID 11
143 * Acer ACPI method GUIDs
145 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
146 #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
147 #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
150 * Interface capability flags
152 #define ACER_CAP_MAILLED (1<<0)
153 #define ACER_CAP_WIRELESS (1<<1)
154 #define ACER_CAP_BLUETOOTH (1<<2)
155 #define ACER_CAP_BRIGHTNESS (1<<3)
156 #define ACER_CAP_THREEG (1<<4)
157 #define ACER_CAP_TOUCHPAD_READ (1<<5)
158 #define ACER_CAP_TEMPERATURE_OVERRIDE (1<<6)
159 #define ACER_CAP_ANY (0xFFFFFFFF)
162 * Interface type flags
164 enum interface_flags
{
171 * Presumed start states -
172 * On some AMW0 laptops, we do not yet know how to get the device status from
173 * the EC, so we must store this ourselves.
175 * Plus, we can't tell which features are enabled or disabled on a specific
176 * model - e.g. The 5020 series can _support_ bluetooth; but the 5021 has no
177 * bluetooth, whilst the 5024 does. However, the BIOS identifies both laptops
178 * as 5020, and you can add bluetooth later.
180 * Basically the code works like this:
181 * - On init, any values specified on the commandline are set.
182 * - For interfaces where the current values cannot be detected and which
183 * have not been set on the commandline, we set them to some sane default
186 * See AMW0_init and acer_commandline_init
189 #define ACER_DEFAULT_WIRELESS 0
190 #define ACER_DEFAULT_BLUETOOTH 0
191 #define ACER_DEFAULT_MAILLED 0
192 #define ACER_DEFAULT_THREEG 0
194 static int max_brightness
= 0xF;
196 static int wireless
= -1;
197 static int bluetooth
= -1;
198 static int mailled
= -1;
199 static int brightness
= -1;
200 static int threeg
= -1;
201 static int fan_temperature_override
= -1;
202 static int debug
= 0;
203 static int force_series
;
205 module_param(mailled
, int, 0444);
206 module_param(wireless
, int, 0444);
207 module_param(bluetooth
, int, 0444);
208 module_param(brightness
, int, 0444);
209 module_param(threeg
, int, 0444);
210 module_param(force_series
, int, 0444);
211 module_param(fan_temperature_override
, int, 0444);
212 module_param(debug
, int, 0664);
213 MODULE_PARM_DESC(wireless
, "Set initial state of Wireless hardware");
214 MODULE_PARM_DESC(bluetooth
, "Set initial state of Bluetooth hardware");
215 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
216 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
217 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
218 MODULE_PARM_DESC(fan_temperature_override
, "Set initial state of the 'FAN temperature-override'");
219 MODULE_PARM_DESC(debug
, "Debugging verbosity level (0=least 2=most)");
220 MODULE_PARM_DESC(force_series
, "Force a different laptop series for extra features (5020, 5720 or 2490)");
225 char *(*read_func
) (char *, u32
);
226 unsigned long (*write_func
) (const char *, unsigned long, u32
);
227 unsigned int capability
;
230 static struct proc_dir_entry
*acer_proc_dir
;
234 * Wait for the keyboard controller to become ready
236 static int wait_kbd_write(void)
239 while ((inb(ACER_KBD_STATUS_REG
) & 0x02) && (i
< 10000)) {
243 return -(i
== 10000);
246 static void send_kbd_cmd(u8 cmd
, u8 val
)
249 if (!wait_kbd_write())
250 outb(cmd
, ACER_KBD_CNTL_REG
);
251 if (!wait_kbd_write())
252 outb(val
, ACER_KBD_DATA_REG
);
253 preempt_enable_no_resched();
256 static void set_keyboard_quirk(void)
258 send_kbd_cmd(0x59, 0x90);
269 /* Each low-level interface must define at least some of the following */
271 u32 type
; /* WMI device type */
272 u32 capability
; /* The capabilities this interface provides */
273 struct acer_data data
; /* Private data for interface */
276 /* The static interface pointer, points to the currently detected interface */
277 static struct Interface
*interface
;
280 * Embedded Controller quirks
281 * Some laptops require us to directly access the EC to either enable or query
282 * features that are not available through ACPI.
290 u8 temperature_override
;
295 static struct quirk_entry
*quirks
;
297 static void set_quirks(void)
299 if (quirks
->mailled
!= 0) {
300 interface
->capability
|= ACER_CAP_MAILLED
;
301 DEBUG(1, "Using EC direct-access quirk for mail LED\n");
304 if (quirks
->touchpad
!= 0) {
305 interface
->capability
|= ACER_CAP_TOUCHPAD_READ
;
306 DEBUG(1, "Using EC direct-access quirk for reading touchpad status\n");
309 if (quirks
->temperature_override
!= 0) {
310 interface
->capability
|= ACER_CAP_TEMPERATURE_OVERRIDE
;
311 DEBUG(1, "Using EC direct-access quirk for temperature override setting (fan)\n");
314 if (quirks
->brightness
!= 0) {
315 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
316 DEBUG(1, "Using EC direct-access quirk for backlight brightness\n");
319 if (quirks
->mmkeys
!= 0) {
320 set_keyboard_quirk();
321 printk(ACER_INFO
"Setting keyboard quirk to enable multimedia keys\n");
324 if (quirks
->bluetooth
!= 0) {
325 interface
->capability
|= ACER_CAP_BLUETOOTH
;
326 DEBUG(1, "Using EC direct-access quirk for bluetooth\n");
329 if (quirks
->wireless
!= 0) {
330 interface
->capability
|= ACER_CAP_WIRELESS
;
331 DEBUG(1, "Using EC direct-access quirk for wireless\n");
335 static int dmi_matched(struct dmi_system_id
*dmi
)
337 quirks
= dmi
->driver_data
;
341 static struct quirk_entry quirk_unknown
= {
344 /* Same Mail LED quirk as TM2490, but does not require keyboard quirk */
345 static struct quirk_entry quirk_acer_aspire_5100
= {
349 static struct quirk_entry quirk_acer_travelmate_2490
= {
352 .temperature_override
= 1,
356 static struct quirk_entry quirk_acer_travelmate_5720
= {
360 static struct dmi_system_id acer_quirks
[] = {
362 .callback
= dmi_matched
,
363 .ident
= "Acer Aspire 3100",
365 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
366 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
368 .driver_data
= &quirk_acer_aspire_5100
,
371 .callback
= dmi_matched
,
372 .ident
= "Acer Aspire 5100",
374 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
375 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
377 .driver_data
= &quirk_acer_aspire_5100
,
380 .callback
= dmi_matched
,
381 .ident
= "Acer Aspire 5630",
383 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
384 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
386 .driver_data
= &quirk_acer_travelmate_2490
,
389 .callback
= dmi_matched
,
390 .ident
= "Acer Aspire 5650",
392 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
393 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
395 .driver_data
= &quirk_acer_travelmate_2490
,
398 .callback
= dmi_matched
,
399 .ident
= "Acer Aspire 5680",
401 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
402 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
404 .driver_data
= &quirk_acer_travelmate_2490
,
407 .callback
= dmi_matched
,
408 .ident
= "Acer Extensa 5220",
410 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
411 DMI_MATCH(DMI_PRODUCT_NAME
, "Extensa 5220"),
413 .driver_data
= &quirk_acer_travelmate_5720
,
416 .callback
= dmi_matched
,
417 .ident
= "Acer TravelMate 2490",
419 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
420 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
422 .driver_data
= &quirk_acer_travelmate_2490
,
425 .callback
= dmi_matched
,
426 .ident
= "Acer TravelMate 5720",
428 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
429 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5720"),
431 .driver_data
= &quirk_acer_travelmate_5720
,
436 /* Find which quirks are needed for a particular vendor/ model pair */
437 static void find_quirks(void)
439 DEBUG (1, "Looking for quirks\n");
441 dmi_check_system(acer_quirks
);
442 } else if (force_series
== 2490) {
443 DEBUG(0, "Forcing Acer TravelMate 2490\n");
444 quirks
= &quirk_acer_travelmate_2490
;
447 if (quirks
== NULL
) {
448 DEBUG(1, "No quirks known for this laptop\n");
449 quirks
= &quirk_unknown
;
455 * General interface convenience methods
458 static bool has_cap(u32 cap
)
460 if ((interface
->capability
& cap
) != 0) {
467 * Old interface (now known as the AMW0 interface)
476 static acpi_status
WMAB_execute(struct WMAB_args
*regbuf
, struct acpi_buffer
*result
)
478 struct acpi_buffer input
;
480 input
.length
= sizeof(struct WMAB_args
);
481 input
.pointer
= (u8
*)regbuf
;
483 status
= wmi_acer_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
484 DEBUG(2, " Args: 0x%08x 0x%08x 0x%08x 0x%08x\n", regbuf
->eax
, regbuf
->ebx
, regbuf
->ecx
, regbuf
->edx
);
489 static acpi_status
AMW0_get_bool(bool *value
, u32 cap
, struct Interface
*iface
)
493 DEBUG(2, " AMW0_get_bool: cap=%d\n", cap
);
495 case ACER_CAP_MAILLED
:
496 switch (quirks
->mailled
) {
498 ec_read(0x0A, &result
);
499 *value
= (result
>> 7) & 0x01;
503 case ACER_CAP_WIRELESS
:
504 switch (quirks
->wireless
) {
506 ec_read(0x0A, &result
);
507 *value
= (result
>> 2) & 0x01;
511 case ACER_CAP_BLUETOOTH
:
512 switch (quirks
->bluetooth
) {
514 ec_read(0x0A, &result
);
515 *value
= (result
>> 4) & 0x01;
520 return AE_BAD_ADDRESS
;
525 static acpi_status
AMW0_set_bool(bool value
, u32 cap
, struct Interface
*iface
)
527 struct WMAB_args args
;
529 args
.eax
= ACER_AMW0_WRITE
;
530 args
.ebx
= value
? (1<<8) : 0;
531 args
.ecx
= args
.edx
= 0;
534 case ACER_CAP_MAILLED
:
535 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
537 case ACER_CAP_WIRELESS
:
538 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
540 case ACER_CAP_BLUETOOTH
:
541 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
544 return AE_BAD_ADDRESS
;
547 /* Actually do the set */
548 return WMAB_execute(&args
, NULL
);
551 static acpi_status
AMW0_get_u8(u8
*value
, u32 cap
, struct Interface
*iface
) {
553 case ACER_CAP_BRIGHTNESS
:
554 switch (quirks
->brightness
) {
556 return ec_read(0x83, value
);
560 return AE_BAD_ADDRESS
;
565 static acpi_status
AMW0_set_u8(u8 value
, u32 cap
, struct Interface
*iface
) {
567 case ACER_CAP_BRIGHTNESS
:
568 switch (quirks
->brightness
) {
570 return ec_write(0x83, value
);
572 return AE_BAD_ADDRESS
;
576 return AE_BAD_ADDRESS
;
581 static struct Interface AMW0_interface
= {
590 static struct Interface AMW0_V2_interface
= {
591 .type
= ACER_AMW0_V2
,
598 * New interface (The WMID interface)
601 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
603 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
604 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
605 union acpi_object
*obj
;
609 DEBUG(2, " WMI_execute_u32:\n");
610 status
= wmi_acer_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
611 DEBUG(2, " In: 0x%08x\n", in
);
613 if (ACPI_FAILURE(status
))
616 obj
= (union acpi_object
*) result
.pointer
;
617 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
618 tmp
= *((u32
*) obj
->buffer
.pointer
);
619 DEBUG(2, " Out: 0x%08x\n", tmp
);
623 DEBUG(2, " Got unexpected result of type %d\n", obj
->type
);
625 DEBUG(2, " Got unexpected null result\n");
632 if (result
.length
> 0 && result
.pointer
)
633 kfree(result
.pointer
);
635 DEBUG(2, " Returning from WMI_execute_u32:\n");
639 static acpi_status
WMID_get_u8(u8
*value
, u32 cap
, struct Interface
*iface
) {
644 DEBUG(2, " WMID_get_u8: cap=%d\n", cap
);
646 case ACER_CAP_WIRELESS
:
647 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
649 case ACER_CAP_BLUETOOTH
:
650 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
652 case ACER_CAP_BRIGHTNESS
:
653 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
655 case ACER_CAP_THREEG
:
656 method_id
= ACER_WMID_GET_THREEG_METHODID
;
658 case ACER_CAP_MAILLED
:
659 if (quirks
->mailled
== 1) {
660 ec_read(0x9f, value
);
664 case ACER_CAP_TOUCHPAD_READ
:
665 switch (quirks
->touchpad
) {
667 ec_read(0x9e, value
);
668 *value
= 1 - ((*value
>> 3) & 0x01);
671 ec_read(0x74, value
);
672 *value
= ((*value
>> 3) & 0x01);
677 case ACER_CAP_TEMPERATURE_OVERRIDE
:
678 if (quirks
->temperature_override
== 1) {
679 ec_read(0xa9, value
);
683 return AE_BAD_ADDRESS
;
685 status
= WMI_execute_u32(method_id
, 0, &result
);
686 DEBUG(2, " WMI_execute_u32 status=%d:\n", status
);
688 if (ACPI_SUCCESS(status
))
691 DEBUG(2, " Returning from WMID_get_u8:\n");
695 static acpi_status
WMID_set_u8(u8 value
, u32 cap
, struct Interface
*iface
) {
699 case ACER_CAP_BRIGHTNESS
:
700 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
702 case ACER_CAP_WIRELESS
:
703 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
705 case ACER_CAP_BLUETOOTH
:
706 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
708 case ACER_CAP_THREEG
:
709 method_id
= ACER_WMID_SET_THREEG_METHODID
;
711 case ACER_CAP_MAILLED
:
712 if (quirks
->mailled
== 1) {
713 send_kbd_cmd(0x59, value
? 0x92 : 0x93);
716 case ACER_CAP_TEMPERATURE_OVERRIDE
:
717 if (quirks
->temperature_override
== 1) {
718 ec_write(0xa9, value
);
722 return AE_BAD_ADDRESS
;
724 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
727 static acpi_status
WMID_set_capabilities(void) {
728 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
729 union acpi_object
*obj
;
733 status
= wmi_acer_query_block(WMID_GUID2
, 1, &out
);
734 if (ACPI_FAILURE(status
))
737 obj
= (union acpi_object
*) out
.pointer
;
738 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
739 devices
= *((u32
*) obj
->buffer
.pointer
);
744 /* Not sure on the meaning of the relevant bits yet */
745 interface
->capability
|= ACER_CAP_WIRELESS
;
746 interface
->capability
|= ACER_CAP_THREEG
;
748 if (devices
& 0x10) {
749 DEBUG(1, "Bluetooth hardware available - enabling\n");
750 interface
->capability
|= ACER_CAP_BLUETOOTH
;
753 if (!(devices
& 0x20)) {
754 DEBUG(1, "Maximum brightness quirk detected - enabling\n");
755 max_brightness
= 0x9;
762 static struct Interface WMID_interface
= {
768 * High-level Procfs file handlers
772 dispatch_read(char *page
, char **start
, off_t off
, int count
, int *eof
,
773 struct ProcItem
*item
)
778 DEBUG(2, " dispatch_read: \n");
780 p
= item
->read_func(p
, item
->capability
);
782 if (len
<= off
+ count
)
794 dispatch_write(struct file
*file
, const char __user
*buffer
,
795 unsigned long count
, struct ProcItem
*item
)
801 * Arg buffer points to userspace memory, which can't be accessed
802 * directly. Since we're making a copy, zero-terminate the
803 * destination so that sscanf can be used on it safely.
805 tmp_buffer
= kmalloc(count
+ 1, GFP_KERNEL
);
806 if (copy_from_user(tmp_buffer
, buffer
, count
)) {
809 tmp_buffer
[count
] = 0;
810 result
= item
->write_func(tmp_buffer
, count
, item
->capability
);
818 * Generic Device (interface-independent)
821 static acpi_status
get_bool(bool *value
, u32 cap
) {
822 acpi_status status
= AE_BAD_ADDRESS
;
825 DEBUG(2, " get_bool: cap=%d, interface type=%d\n",
826 cap
, interface
->type
);
827 switch (interface
->type
) {
829 status
= AMW0_get_bool(value
, cap
, interface
);
832 if (cap
== ACER_CAP_MAILLED
) {
833 status
= AMW0_get_bool(value
, cap
, interface
);
837 status
= WMID_get_u8(&tmp
, cap
, interface
);
838 *value
= (tmp
== 1) ? 1 : 0;
841 DEBUG(2, " Returning from get_bool:\n");
845 static acpi_status
set_bool(int value
, u32 cap
) {
846 acpi_status status
= AE_BAD_PARAMETER
;
848 DEBUG(2, " set_bool: cap=%d, interface type=%d, value=%d\n",
849 cap
, interface
->type
, value
);
850 if ((value
== 0 || value
== 1) && (interface
->capability
& cap
)) {
851 switch (interface
->type
) {
853 status
= AMW0_set_bool(value
== 1, cap
, interface
);
856 if (cap
== ACER_CAP_MAILLED
) {
857 status
= AMW0_set_bool(value
== 1, cap
,
862 status
= WMID_set_u8(value
== 1, cap
, interface
);
869 static acpi_status
get_u8(u8
*value
, u32 cap
) {
870 DEBUG(2, " get_u8: cap=%d\n", cap
);
871 switch (interface
->type
) {
873 return AMW0_get_u8(value
, cap
, interface
);
877 return WMID_get_u8(value
, cap
, interface
);
880 return AE_BAD_ADDRESS
;
884 static acpi_status
set_u8(u8 value
, u8 min
, u8 max
, u32 cap
) {
886 DEBUG(2, " set_u8: cap=%d, interface type=%d, value=%d\n",
887 cap
, interface
->type
, value
);
889 if ((value
>= min
&& value
<= max
) && (interface
->capability
& cap
) ) {
890 switch (interface
->type
) {
892 return AMW0_set_u8(value
, cap
, interface
);
895 return WMID_set_u8(value
, cap
, interface
);
897 return AE_BAD_PARAMETER
;
900 return AE_BAD_PARAMETER
;
903 /* Each _u8 needs a small wrapper that sets the boundary values */
904 static acpi_status
set_brightness(u8 value
)
906 return set_u8(value
, 0, max_brightness
, ACER_CAP_BRIGHTNESS
);
909 static acpi_status
set_temperature_override(u8 value
)
911 return set_u8(value
, 0, ACER_MAX_TEMPERATURE_OVERRIDE
, ACER_CAP_TEMPERATURE_OVERRIDE
);
914 static void __init
acer_commandline_init(void)
916 DEBUG(1, "Commandline args: mailled(%d) wireless(%d) bluetooth(%d) brightness(%d)\n",
917 mailled
, wireless
, bluetooth
, brightness
);
920 * These will all fail silently if the value given is invalid, or the
921 * capability isn't available on the given interface
923 set_bool(mailled
, ACER_CAP_MAILLED
);
924 set_bool(wireless
, ACER_CAP_WIRELESS
);
925 set_bool(bluetooth
, ACER_CAP_BLUETOOTH
);
926 set_bool(threeg
, ACER_CAP_THREEG
);
927 set_temperature_override(fan_temperature_override
);
928 set_brightness((u8
)brightness
);
933 * Procfs interface (deprecated)
935 static char *read_bool(char *p
, u32 cap
)
940 DEBUG(2, " read_bool: cap=%d\n", cap
);
941 status
= get_bool(&result
, cap
);
942 if (ACPI_SUCCESS(status
))
943 p
+= sprintf(p
, "%d\n", result
);
945 p
+= sprintf(p
, "Read error" );
949 static unsigned long write_bool(const char *buffer
, unsigned long count
, u32 cap
)
953 DEBUG(2, " write_bool: cap=%d, interface type=%d\n buffer=%s\n",
954 cap
, interface
->type
, buffer
);
956 if (sscanf(buffer
, "%i", &value
) == 1) {
957 acpi_status status
= set_bool(value
, cap
);
958 if (ACPI_FAILURE(status
))
966 static char *read_u8(char *p
, u32 cap
)
971 DEBUG(2, " read_u8: cap=%d\n", cap
);
972 status
= get_u8(&result
, cap
);
973 if (ACPI_SUCCESS(status
))
974 p
+= sprintf(p
, "%u\n", result
);
976 p
+= sprintf(p
, "Read error" );
980 static unsigned long write_u8(const char *buffer
, unsigned long count
, u32 cap
)
983 acpi_status (*set_method
)(u8
);
985 /* Choose the appropriate set_u8 wrapper here, based on the capability */
987 case ACER_CAP_BRIGHTNESS
:
988 set_method
= set_brightness
;
990 case ACER_CAP_TEMPERATURE_OVERRIDE
:
991 set_method
= set_temperature_override
;
997 if (sscanf(buffer
, "%i", &value
) == 1) {
998 acpi_status status
= (*set_method
)(value
);
999 if (ACPI_FAILURE(status
))
1007 static char *read_version(char *p
, u32 cap
)
1009 p
+= sprintf(p
, "%s\n", ACER_ACPI_VERSION
);
1013 static char *read_interface(char *p
, u32 cap
)
1015 p
+= sprintf(p
, "%s\n", (interface
->type
== ACER_AMW0
) ? "AMW0": "WMID");
1019 static struct ProcItem proc_items
[] = {
1020 {"mailled", read_bool
, write_bool
, ACER_CAP_MAILLED
},
1021 {"bluetooth", read_bool
, write_bool
, ACER_CAP_BLUETOOTH
},
1022 {"wireless", read_bool
, write_bool
, ACER_CAP_WIRELESS
},
1023 {"brightness", read_u8
, write_u8
, ACER_CAP_BRIGHTNESS
},
1024 {"threeg", read_bool
, write_bool
, ACER_CAP_THREEG
},
1025 {"touchpad", read_bool
, NULL
, ACER_CAP_TOUCHPAD_READ
},
1026 {"fan_temperature_override", read_u8
, write_u8
, ACER_CAP_TEMPERATURE_OVERRIDE
},
1027 {"version", read_version
, NULL
, ACER_CAP_ANY
},
1028 {"interface", read_interface
, NULL
, ACER_CAP_ANY
},
1032 static int __init
add_proc_entries(void)
1034 struct proc_dir_entry
*proc
;
1035 struct ProcItem
*item
;
1037 for (item
= proc_items
; item
->name
; ++item
) {
1039 * Only add the proc file if the current interface actually
1042 if (interface
->capability
& item
->capability
) {
1043 proc
= create_proc_read_entry(item
->name
,
1044 S_IFREG
| S_IRUGO
| S_IWUSR
,
1046 (read_proc_t
*) dispatch_read
,
1049 proc
->owner
= THIS_MODULE
;
1050 if (proc
&& item
->write_func
)
1051 proc
->write_proc
= (write_proc_t
*) dispatch_write
;
1058 static int __exit
remove_proc_entries(void)
1060 struct ProcItem
*item
;
1062 for (item
= proc_items
; item
->name
; ++item
)
1063 remove_proc_entry(item
->name
, acer_proc_dir
);
1069 * LED device (Mail LED only, no other LEDs known yet)
1071 static void mail_led_set(struct led_classdev
*led_cdev
, enum led_brightness value
)
1074 set_bool(tmp
, ACER_CAP_MAILLED
);
1077 static struct led_classdev mail_led
= {
1078 .name
= "acer_acpi:mail",
1079 .brightness_set
= mail_led_set
,
1082 static void acer_led_init(struct device
*dev
)
1084 led_classdev_register(dev
, &mail_led
);
1087 static void acer_led_exit(void)
1089 led_classdev_unregister(&mail_led
);
1092 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1096 static struct backlight_device
*acer_backlight_device
;
1098 static int read_brightness(struct backlight_device
*bd
)
1101 get_u8(&value
, ACER_CAP_BRIGHTNESS
);
1105 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,20)
1106 static int update_bl_status(struct backlight_device
*bd
)
1108 set_brightness(bd
->props
->brightness
);
1112 static struct backlight_properties acer_backlight_properties
= {
1113 .get_brightness
= read_brightness
,
1114 .update_status
= update_bl_status
,
1117 static int __init
acer_backlight_init(struct device
*dev
)
1119 struct backlight_device
*bd
;
1121 DEBUG(1, "Loading backlight driver\n");
1122 bd
= backlight_device_register("acer_acpi", dev
, NULL
, &acer_backlight_properties
);
1124 printk(ACER_ERR
"Could not register Acer backlight device\n");
1125 acer_backlight_device
= NULL
;
1129 acer_backlight_device
= bd
;
1131 bd
->props
->max_brightness
= max_brightness
;
1135 static int update_bl_status(struct backlight_device
*bd
)
1137 set_brightness(bd
->props
.brightness
);
1141 static struct backlight_ops acer_backlight_ops
= {
1142 .get_brightness
= read_brightness
,
1143 .update_status
= update_bl_status
,
1146 static int __init
acer_backlight_init(struct device
*dev
)
1148 struct backlight_device
*bd
;
1150 DEBUG(1, "Loading backlight driver\n");
1151 bd
= backlight_device_register("acer_acpi", dev
, NULL
, &acer_backlight_ops
);
1153 printk(ACER_ERR
"Could not register Acer backlight device\n");
1154 acer_backlight_device
= NULL
;
1158 acer_backlight_device
= bd
;
1160 bd
->props
.max_brightness
= max_brightness
;
1161 bd
->props
.brightness
= read_brightness(NULL
);
1162 backlight_update_status(bd
);
1167 static void __exit
acer_backlight_exit(void)
1169 backlight_device_unregister(acer_backlight_device
);
1174 * Read/ write bool sysfs macro
1176 #define show_set_bool(value, cap) \
1178 show_bool_##value(struct device *dev, struct device_attribute *attr, \
1182 acpi_status status = get_bool(&result, cap); \
1183 if (ACPI_SUCCESS(status)) \
1184 return sprintf(buf, "%d\n", result); \
1185 return sprintf(buf, "Read error" ); \
1189 set_bool_##value(struct device *dev, struct device_attribute *attr, \
1190 const char *buf, size_t count) \
1192 bool tmp = simple_strtoul(buf, NULL, 10); \
1193 acpi_status status = set_bool(tmp, cap); \
1194 if (ACPI_FAILURE(status)) \
1198 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
1199 show_bool_##value, set_bool_##value);
1201 show_set_bool(wireless
, ACER_CAP_WIRELESS
);
1202 show_set_bool(bluetooth
, ACER_CAP_BLUETOOTH
);
1203 show_set_bool(threeg
, ACER_CAP_THREEG
);
1204 show_set_bool(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1207 * Read-only bool sysfs macro
1209 #define show_bool(value, cap) \
1211 show_bool_##value(struct device *dev, struct device_attribute *attr, \
1215 acpi_status status = get_bool(&result, cap); \
1216 if (ACPI_SUCCESS(status)) \
1217 return sprintf(buf, "%d\n", result); \
1218 return sprintf(buf, "Read error" ); \
1220 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
1221 show_bool_##value, NULL);
1223 show_bool(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1226 * Read interface sysfs macro
1228 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1231 switch (interface
->type
) {
1233 return sprintf(buf
, "AMW0\n");
1235 return sprintf(buf
, "AMW0 v2\n");
1237 return sprintf(buf
, "WMID\n");
1239 return sprintf(buf
, "Error!\n");
1243 static DEVICE_ATTR(interface
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_interface
, NULL
);
1245 static ssize_t
show_devices(struct device
*dev
, struct device_attribute
*attr
,
1248 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1249 union acpi_object
*obj
;
1253 status
= wmi_acer_query_block(WMID_GUID2
, 1, &out
);
1254 if (ACPI_FAILURE(status
))
1255 return sprintf(buf
, "Error\n");
1257 obj
= (union acpi_object
*) out
.pointer
;
1258 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
1259 tmp
= *((u32
*) obj
->buffer
.pointer
);
1261 return sprintf(buf
, "Error\n");
1264 return sprintf(buf
, "%u\n", tmp
);
1267 static DEVICE_ATTR(devices
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_devices
, NULL
);
1272 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1274 if (has_cap(ACER_CAP_MAILLED
))
1275 acer_led_init(&device
->dev
);
1276 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1277 if (has_cap(ACER_CAP_BRIGHTNESS
))
1278 acer_backlight_init(&device
->dev
);
1283 static int acer_platform_remove(struct platform_device
*device
)
1285 if (has_cap(ACER_CAP_MAILLED
))
1287 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1288 if (has_cap(ACER_CAP_BRIGHTNESS
))
1289 acer_backlight_exit();
1294 static int acer_platform_suspend(struct platform_device
*device
, pm_message_t state
)
1297 * WMID fix for suspend-to-disk - save all current states now so we can
1298 * restore them on resume
1302 struct acer_data
*data
= &interface
->data
;
1304 #define save_bool_device(device, cap) \
1305 if (has_cap(cap)) {\
1306 get_bool(&value, cap);\
1307 data->device = value;\
1310 #define save_u8_device(device, cap) \
1311 if (has_cap(cap)) {\
1312 get_u8(&u8value, cap);\
1313 data->device = u8value;\
1316 save_bool_device(wireless
, ACER_CAP_WIRELESS
);
1317 save_bool_device(bluetooth
, ACER_CAP_BLUETOOTH
);
1318 save_bool_device(threeg
, ACER_CAP_THREEG
);
1319 save_bool_device(mailled
, ACER_CAP_MAILLED
);
1320 save_u8_device(brightness
, ACER_CAP_BRIGHTNESS
);
1325 static int acer_platform_resume(struct platform_device
*device
)
1327 struct acer_data
*data
= &interface
->data
;
1329 #define restore_bool_device(device, cap) \
1331 set_bool(data->device, cap);\
1333 restore_bool_device(wireless, ACER_CAP_WIRELESS);
1334 restore_bool_device(bluetooth
, ACER_CAP_BLUETOOTH
);
1335 restore_bool_device(threeg
, ACER_CAP_THREEG
);
1336 restore_bool_device(mailled
, ACER_CAP_MAILLED
);
1338 if (has_cap(ACER_CAP_BRIGHTNESS
))
1339 set_brightness((u8
)data
->brightness
);
1341 /* Check if this laptop requires the keyboard quirk */
1342 if (quirks
->mmkeys
!= 0) {
1343 set_keyboard_quirk();
1344 printk(ACER_INFO
"Setting keyboard quirk to enable multimedia keys\n");
1350 static struct platform_driver acer_platform_driver
= {
1352 .name
= "acer_acpi",
1353 .owner
= THIS_MODULE
,
1355 .probe
= acer_platform_probe
,
1356 .remove
= acer_platform_remove
,
1357 .suspend
= acer_platform_suspend
,
1358 .resume
= acer_platform_resume
,
1361 static struct platform_device
*acer_platform_device
;
1363 static int remove_sysfs(struct platform_device
*device
)
1365 #define remove_device_file(value, cap) \
1367 device_remove_file(&device->dev, &dev_attr_##value);
1369 if (wmi_acer_has_guid(WMID_GUID2
)) {
1370 device_remove_file(&device
->dev
, &dev_attr_devices
);
1373 remove_device_file(wireless
, ACER_CAP_WIRELESS
);
1374 remove_device_file(bluetooth
, ACER_CAP_BLUETOOTH
);
1375 remove_device_file(threeg
, ACER_CAP_THREEG
);
1376 remove_device_file(interface
, ACER_CAP_ANY
);
1377 remove_device_file(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1378 remove_device_file(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1382 static int create_sysfs(void)
1384 int retval
= -ENOMEM
;
1386 #define add_device_file(value, cap) \
1387 if (has_cap(cap)) {\
1388 retval = device_create_file(&acer_platform_device->dev, &dev_attr_##value);\
1393 if (wmi_acer_has_guid(WMID_GUID2
)) {
1394 retval
= device_create_file(&acer_platform_device
->dev
, &dev_attr_devices
);
1399 add_device_file(wireless
, ACER_CAP_WIRELESS
);
1400 add_device_file(bluetooth
, ACER_CAP_BLUETOOTH
);
1401 add_device_file(threeg
, ACER_CAP_THREEG
);
1402 add_device_file(interface
, ACER_CAP_ANY
);
1403 add_device_file(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1404 add_device_file(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1409 remove_sysfs(acer_platform_device
);
1413 static int __init
acer_acpi_init(void)
1415 printk(ACER_INFO
"Acer Laptop ACPI Extras version %s\n",
1418 /* Find if this laptop requires any quirks */
1419 DEBUG(1, "Finding quirks\n");
1423 * Detect which WMI interface we're using.
1425 if (wmi_acer_has_guid(AMW0_GUID1
)) {
1426 interface
= &AMW0_interface
;
1428 if (wmi_acer_has_guid(WMID_GUID1
)) {
1429 DEBUG(0, "Detected Acer AMW0 version 2 interface\n");
1430 interface
= &AMW0_V2_interface
;
1432 DEBUG(0, "Detected Acer AMW0 version 1 interface\n");
1433 if (!quirks
->brightness
) {
1434 quirks
->brightness
= 1;
1435 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
1438 } else if (wmi_acer_has_guid(WMID_GUID1
)) {
1439 DEBUG(0, "Detected Acer WMID interface\n");
1440 interface
= &WMID_interface
;
1442 printk(ACER_ERR
"No or unsupported WMI interface, unable to load.\n");
1446 if (wmi_acer_has_guid(WMID_GUID2
)) {
1447 if (ACPI_FAILURE(WMID_set_capabilities())) {
1448 printk(ACER_ERR
"Unable to detect available devices\n");
1454 /* Create the proc entries */
1455 acer_proc_dir
= proc_mkdir(PROC_ACER
, acpi_root_dir
);
1456 if (!acer_proc_dir
) {
1457 printk(ACER_ERR
"Unable to create /proc entries, aborting.\n");
1458 goto error_proc_mkdir
;
1461 acer_proc_dir
->owner
= THIS_MODULE
;
1462 if (add_proc_entries()) {
1463 printk(ACER_ERR
"Unable to create /proc entries, aborting.\n");
1464 goto error_proc_add
;
1469 * Register the driver
1471 if (platform_driver_register(&acer_platform_driver
)) {
1472 printk(ACER_ERR
"Unable to register platform driver, aborting.\n");
1473 goto error_platform_register
;
1475 acer_platform_device
= platform_device_alloc("acer_acpi", -1);
1476 platform_device_add(acer_platform_device
);
1480 DEBUG(1, "Driver registered\n");
1482 /* Override any initial settings with values from the commandline */
1483 acer_commandline_init();
1487 error_platform_register
:
1489 remove_proc_entries();
1492 remove_proc_entry(PROC_ACER
, acpi_root_dir
);
1498 static void __exit
acer_acpi_exit(void)
1500 remove_sysfs(acer_platform_device
);
1501 platform_device_del(acer_platform_device
);
1502 platform_driver_unregister(&acer_platform_driver
);
1505 remove_proc_entries();
1508 remove_proc_entry(PROC_ACER
, acpi_root_dir
);
1510 printk(ACER_INFO
"Acer Laptop ACPI Extras unloaded\n");
1514 module_init(acer_acpi_init
);
1515 module_exit(acer_acpi_exit
);