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 #define ACER_LOGPREFIX "acer_acpi: "
81 #define ACER_ERR KERN_ERR ACER_LOGPREFIX
82 #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
83 #define ACER_INFO KERN_INFO ACER_LOGPREFIX
85 #define DEBUG(level, message...) { \
87 printk(KERN_DEBUG ACER_LOGPREFIX message);\
91 * The maximum temperature one can set for fan control override.
92 * Doesn't propably make much sense if over 80 degrees celsius though...
94 #define ACER_MAX_TEMPERATURE_OVERRIDE 150
97 * The following defines quirks to get some specific functions to work
98 * which are known to not be supported over ACPI (such as the mail LED
99 * on WMID based Acer's)
108 * Keyboard controller ports
110 #define ACER_KBD_STATUS_REG 0x64 /* Status register (R) */
111 #define ACER_KBD_CNTL_REG 0x64 /* Controller command register (W) */
112 #define ACER_KBD_DATA_REG 0x60 /* Keyboard data register (R/W) */
116 * Meaning is unknown - this number is required for writing to ACPI for AMW0
117 * (it's also used in acerhk when directly accessing the EC)
119 #define ACER_AMW0_WRITE 0x9610
122 * Bit masks for the old AMW0 interface
124 #define ACER_AMW0_WIRELESS_MASK 0x35
125 #define ACER_AMW0_BLUETOOTH_MASK 0x34
126 #define ACER_AMW0_MAILLED_MASK 0x31
129 * Method IDs for new WMID interface
131 #define ACER_WMID_GET_WIRELESS_METHODID 1
132 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
133 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
134 #define ACER_WMID_SET_WIRELESS_METHODID 4
135 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
136 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
137 #define ACER_WMID_GET_THREEG_METHODID 10
138 #define ACER_WMID_SET_THREEG_METHODID 11
141 * Acer ACPI method GUIDs
143 #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
144 #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
147 * Interface capability flags
149 #define ACER_CAP_MAILLED (1<<0)
150 #define ACER_CAP_WIRELESS (1<<1)
151 #define ACER_CAP_BLUETOOTH (1<<2)
152 #define ACER_CAP_BRIGHTNESS (1<<3)
153 #define ACER_CAP_THREEG (1<<4)
154 #define ACER_CAP_TOUCHPAD_READ (1<<5)
155 #define ACER_CAP_TEMPERATURE_OVERRIDE (1<<6)
156 #define ACER_CAP_ANY (0xFFFFFFFF)
159 * Interface type flags
161 enum interface_flags
{
167 * Presumed start states -
168 * On some AMW0 laptops, we do not yet know how to get the device status from
169 * the EC, so we must store this ourselves.
171 * Plus, we can't tell which features are enabled or disabled on a specific
172 * model - e.g. The 5020 series can _support_ bluetooth; but the 5021 has no
173 * bluetooth, whilst the 5024 does. However, the BIOS identifies both laptops
174 * as 5020, and you can add bluetooth later.
176 * Basically the code works like this:
177 * - On init, any values specified on the commandline are set.
178 * - For interfaces where the current values cannot be detected and which
179 * have not been set on the commandline, we set them to some sane default
182 * See AMW0_init and acer_commandline_init
185 #define ACER_DEFAULT_WIRELESS 0
186 #define ACER_DEFAULT_BLUETOOTH 0
187 #define ACER_DEFAULT_MAILLED 0
188 #define ACER_DEFAULT_THREEG 0
190 static int max_brightness
= 0xF;
192 static int wireless
= -1;
193 static int bluetooth
= -1;
194 static int mailled
= -1;
195 static int brightness
= -1;
196 static int threeg
= -1;
197 static int fan_temperature_override
= -1;
198 static int debug
= 0;
199 static int force_series
;
201 module_param(mailled
, int, 0444);
202 module_param(wireless
, int, 0444);
203 module_param(bluetooth
, int, 0444);
204 module_param(brightness
, int, 0444);
205 module_param(threeg
, int, 0444);
206 module_param(force_series
, int, 0444);
207 module_param(fan_temperature_override
, int, 0444);
208 module_param(debug
, int, 0664);
209 MODULE_PARM_DESC(wireless
, "Set initial state of Wireless hardware");
210 MODULE_PARM_DESC(bluetooth
, "Set initial state of Bluetooth hardware");
211 MODULE_PARM_DESC(mailled
, "Set initial state of Mail LED");
212 MODULE_PARM_DESC(brightness
, "Set initial LCD backlight brightness");
213 MODULE_PARM_DESC(threeg
, "Set initial state of 3G hardware");
214 MODULE_PARM_DESC(fan_temperature_override
, "Set initial state of the 'FAN temperature-override'");
215 MODULE_PARM_DESC(debug
, "Debugging verbosity level (0=least 2=most)");
216 MODULE_PARM_DESC(force_series
, "Force a different laptop series for extra features (5020, 5720 or 2490)");
221 char *(*read_func
) (char *, u32
);
222 unsigned long (*write_func
) (const char *, unsigned long, u32
);
223 unsigned int capability
;
226 static struct proc_dir_entry
*acer_proc_dir
;
230 * Wait for the keyboard controller to become ready
232 static int wait_kbd_write(void)
235 while ((inb(ACER_KBD_STATUS_REG
) & 0x02) && (i
< 10000)) {
239 return -(i
== 10000);
242 static void send_kbd_cmd(u8 cmd
, u8 val
)
245 if (!wait_kbd_write())
246 outb(cmd
, ACER_KBD_CNTL_REG
);
247 if (!wait_kbd_write())
248 outb(val
, ACER_KBD_DATA_REG
);
249 preempt_enable_no_resched();
252 static void set_keyboard_quirk(void)
254 send_kbd_cmd(0x59, 0x90);
265 /* Each low-level interface must define at least some of the following */
268 * The ACPI device type
273 * The capabilities this interface provides
274 * In the future, these can be removed/added at runtime when we have a
275 * way of detecting what capabilities are /actually/ present on an
281 * Initializes an interface, should allocate the interface-specific
284 void (*init
) (struct Interface
*);
287 * Private data for the current interface
289 struct acer_data data
;
292 /* The static interface pointer, points to the currently detected interface */
293 static struct Interface
*interface
;
296 * Embedded Controller quirks
297 * Some laptops require us to directly access the EC to either enable or query
298 * features that are not available through ACPI.
306 u8 temperature_override
;
312 static struct quirk_entry
*quirks
;
314 static void set_quirks(void)
316 if (quirks
->mailled
!= 0) {
317 interface
->capability
|= ACER_CAP_MAILLED
;
318 DEBUG(1, "Using EC direct-access quirk for mail LED\n");
321 if (quirks
->touchpad
!= 0) {
322 interface
->capability
|= ACER_CAP_TOUCHPAD_READ
;
323 DEBUG(1, "Using EC direct-access quirk for reading touchpad status\n");
326 if (quirks
->temperature_override
!= 0) {
327 interface
->capability
|= ACER_CAP_TEMPERATURE_OVERRIDE
;
328 DEBUG(1, "Using EC direct-access quirk for temperature override setting (fan)\n");
331 if (quirks
->brightness
!= 0) {
332 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
333 DEBUG(1, "Using EC direct-access quirk for backlight brightness\n");
336 if (quirks
->mmkeys
!= 0) {
337 set_keyboard_quirk();
338 printk(ACER_INFO
"Setting keyboard quirk to enable multimedia keys\n");
341 if (quirks
->bluetooth
!= 0) {
342 interface
->capability
|= ACER_CAP_BLUETOOTH
;
343 DEBUG(1, "Using EC direct-access quirk for bluetooth\n");
346 if (quirks
->wireless
!= 0) {
347 interface
->capability
|= ACER_CAP_WIRELESS
;
348 DEBUG(1, "Using EC direct-access quirk for wireless\n");
351 if (quirks
->max_brightness
!= 0) {
352 max_brightness
= quirks
->max_brightness
;
353 DEBUG(1, "Changing maximum brightness level\n");
357 static int dmi_matched(struct dmi_system_id
*dmi
)
359 quirks
= dmi
->driver_data
;
363 static struct quirk_entry quirk_unknown
= {
366 static struct quirk_entry quirk_acer_aspire_5020
= {
373 /* Same Mail LED quirk as TM2490, but does not require keyboard quirk */
374 static struct quirk_entry quirk_acer_aspire_5100
= {
378 static struct quirk_entry quirk_acer_aspire_5680
= {
382 static struct quirk_entry quirk_acer_aspire_9300
= {
389 static struct quirk_entry quirk_acer_travelmate_2490
= {
392 .temperature_override
= 1,
397 * This is similar to the Aspire 5020, but with a different wireless quirk
399 static struct quirk_entry quirk_acer_travelmate_5620
= {
406 static struct quirk_entry quirk_acer_travelmate_5720
= {
407 .max_brightness
= 0x9,
414 static struct dmi_system_id acer_quirks
[] = {
416 .callback
= dmi_matched
,
417 .ident
= "Acer Aspire 3020",
419 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
420 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3020"),
422 .driver_data
= &quirk_acer_aspire_5020
,
425 .callback
= dmi_matched
,
426 .ident
= "Acer Aspire 3040",
428 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
429 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3040"),
431 .driver_data
= &quirk_acer_aspire_5020
,
434 .callback
= dmi_matched
,
435 .ident
= "Acer Aspire 3100",
437 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
438 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 3100"),
440 .driver_data
= &quirk_acer_aspire_5100
,
443 .callback
= dmi_matched
,
444 .ident
= "Acer Aspire 5020",
446 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
447 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5020"),
449 .driver_data
= &quirk_acer_aspire_5020
,
452 .callback
= dmi_matched
,
453 .ident
= "Acer Aspire 5040",
455 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
456 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5040"),
458 .driver_data
= &quirk_acer_aspire_5020
,
461 .callback
= dmi_matched
,
462 .ident
= "Acer Aspire 5100",
464 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
465 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5100"),
467 .driver_data
= &quirk_acer_aspire_5100
,
470 .callback
= dmi_matched
,
471 .ident
= "Acer Aspire 5560",
473 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
474 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5560"),
476 .driver_data
= &quirk_acer_travelmate_5620
,
479 .callback
= dmi_matched
,
480 .ident
= "Acer Aspire 5630",
482 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
483 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5630"),
485 .driver_data
= &quirk_acer_travelmate_2490
,
488 .callback
= dmi_matched
,
489 .ident
= "Acer Aspire 5650",
491 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
492 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5650"),
494 .driver_data
= &quirk_acer_travelmate_2490
,
497 .callback
= dmi_matched
,
498 .ident
= "Acer Aspire 5680",
500 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
501 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5680"),
503 .driver_data
= &quirk_acer_aspire_5680
,
506 .callback
= dmi_matched
,
507 .ident
= "Acer Aspire 9300",
509 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
510 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9300"),
512 .driver_data
= &quirk_acer_aspire_9300
,
515 .callback
= dmi_matched
,
516 .ident
= "Acer Aspire 9420",
518 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
519 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 9420"),
521 .driver_data
= &quirk_acer_travelmate_5620
,
524 .callback
= dmi_matched
,
525 .ident
= "Acer TravelMate 2420",
527 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
528 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2420"),
530 .driver_data
= &quirk_acer_aspire_5020
,
533 .callback
= dmi_matched
,
534 .ident
= "Acer TravelMate 2490",
536 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
537 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 2490"),
539 .driver_data
= &quirk_acer_travelmate_2490
,
542 .callback
= dmi_matched
,
543 .ident
= "Acer TravelMate 5620",
545 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
546 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5620"),
548 .driver_data
= &quirk_acer_travelmate_5620
,
551 .callback
= dmi_matched
,
552 .ident
= "Acer TravelMate 5720",
554 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
555 DMI_MATCH(DMI_PRODUCT_NAME
, "TravelMate 5720"),
557 .driver_data
= &quirk_acer_travelmate_5720
,
562 /* Find which quirks are needed for a particular vendor/ model pair */
563 static void find_quirks(void)
565 DEBUG (1, "Looking for quirks\n");
567 dmi_check_system(acer_quirks
);
568 } else if (force_series
== 5020) {
569 DEBUG(0, "Forcing Acer Aspire 5020\n");
570 quirks
= &quirk_acer_aspire_5020
;
571 } else if (force_series
== 2490) {
572 DEBUG(0, "Forcing Acer TravelMate 2490\n");
573 quirks
= &quirk_acer_travelmate_2490
;
574 } else if (force_series
== 5620) {
575 DEBUG(0, "Forcing Acer TravelMate 5620\n");
576 quirks
= &quirk_acer_travelmate_5620
;
577 } else if (force_series
== 5720) {
578 DEBUG(0, "Forcing Acer TravelMate 5720\n");
579 quirks
= &quirk_acer_travelmate_5720
;
582 if (quirks
== NULL
) {
583 DEBUG(1, "No quirks known for this laptop\n");
584 quirks
= &quirk_unknown
;
590 * General interface convenience methods
593 static bool has_cap(u32 cap
)
595 if ((interface
->capability
& cap
) != 0) {
602 * Old interface (now known as the AMW0 interface)
611 static acpi_status
WMAB_execute(struct WMAB_args
*regbuf
, struct acpi_buffer
*result
)
613 struct acpi_buffer input
;
615 input
.length
= sizeof(struct WMAB_args
);
616 input
.pointer
= (u8
*)regbuf
;
618 status
= wmi_acer_evaluate_method(AMW0_GUID1
, 1, 1, &input
, result
);
619 DEBUG(2, " Args: 0x%08x 0x%08x 0x%08x 0x%08x\n", regbuf
->eax
, regbuf
->ebx
, regbuf
->ecx
, regbuf
->edx
);
624 static void AMW0_init(struct Interface
*iface
) {
628 * If the commandline doesn't specify these, we need to force them to
631 if (mailled
== -1 && !quirks
->mailled
)
632 mailled
= ACER_DEFAULT_MAILLED
;
633 if (wireless
== -1 && !quirks
->wireless
)
634 wireless
= ACER_DEFAULT_WIRELESS
;
635 if (bluetooth
== -1 && !quirks
->bluetooth
)
636 bluetooth
= ACER_DEFAULT_BLUETOOTH
;
639 * Set the cached "current" values to impossible ones so that
640 * acer_commandline_init will definitely set them.
642 if (quirks
->bluetooth
== 0) {
644 iface
->data
.bluetooth
= -1;
645 printk(ACER_INFO
"No EC data for reading bluetooth - bluetooth value when read will be a 'best guess'\n");
648 if (quirks
->wireless
== 0) {
650 printk(ACER_INFO
"No EC data for reading wireless - wireless value when read will be a 'best guess'\n");
651 iface
->data
.wireless
= -1;
653 if (quirks
->mailled
== 0) {
655 printk(ACER_INFO
"No EC data for reading mail LED - mail LED value when read will be a 'best guess'\n");
656 iface
->data
.mailled
= -1;
660 printk(ACER_INFO
"We need more data from your laptop's Embedded Controller (EC) to better support it\n");
661 printk(ACER_INFO
"Please see http://code.google.com/p/aceracpi/wiki/EmbeddedController on how to help\n");
665 static acpi_status
AMW0_get_bool(bool *value
, u32 cap
, struct Interface
*iface
)
667 struct acer_data
*data
= &iface
->data
;
670 DEBUG(2, " AMW0_get_bool: cap=%d\n", cap
);
672 * On some models, we can read these values from the EC. On others,
673 * we use a stored value
676 case ACER_CAP_MAILLED
:
677 switch (quirks
->mailled
) {
679 ec_read(0x0A, &result
);
680 *value
= (result
>> 7) & 0x01;
683 *value
= data
->mailled
;
686 case ACER_CAP_WIRELESS
:
687 switch (quirks
->wireless
) {
689 ec_read(0x0A, &result
);
690 *value
= (result
>> 2) & 0x01;
693 ec_read(0x71, &result
);
694 *value
= result
& 0x01;
697 *value
= data
->wireless
;
700 case ACER_CAP_BLUETOOTH
:
701 switch (quirks
->bluetooth
) {
703 ec_read(0x0A, &result
);
704 *value
= (result
>> 4) & 0x01;
707 ec_read(0x71, &result
);
708 *value
= (result
>> 1) & 0x01;
711 *value
= data
->bluetooth
;
714 case ACER_CAP_TOUCHPAD_READ
:
715 switch (quirks
->touchpad
) {
717 ec_read(0x74, &result
);
718 *value
= (result
>> 3) & 0x01;
724 return AE_BAD_ADDRESS
;
729 static acpi_status
AMW0_set_bool(bool value
, u32 cap
, struct Interface
*iface
)
731 struct WMAB_args args
;
732 struct acer_data
*data
= &iface
->data
;
735 args
.eax
= ACER_AMW0_WRITE
;
736 args
.ebx
= value
? (1<<8) : 0;
737 args
.ecx
= args
.edx
= 0;
740 case ACER_CAP_MAILLED
:
741 args
.ebx
|= ACER_AMW0_MAILLED_MASK
;
743 case ACER_CAP_WIRELESS
:
744 args
.ebx
|= ACER_AMW0_WIRELESS_MASK
;
746 case ACER_CAP_BLUETOOTH
:
747 args
.ebx
|= ACER_AMW0_BLUETOOTH_MASK
;
750 return AE_BAD_ADDRESS
;
753 /* Actually do the set */
754 status
= WMAB_execute(&args
, NULL
);
757 * Currently no way to query the state, so cache the new value on
760 if (ACPI_SUCCESS(status
)) {
762 case ACER_CAP_MAILLED
:
763 data
->mailled
= value
;
765 case ACER_CAP_WIRELESS
:
766 data
->wireless
= value
;
768 case ACER_CAP_BLUETOOTH
:
769 data
->bluetooth
= value
;
777 static acpi_status
AMW0_get_u8(u8
*value
, u32 cap
, struct Interface
*iface
) {
779 case ACER_CAP_BRIGHTNESS
:
780 switch (quirks
->brightness
) {
782 return ec_read(0x83, value
);
784 return ec_read(0x85, value
);
786 return AE_BAD_ADDRESS
;
790 return AE_BAD_ADDRESS
;
795 static acpi_status
AMW0_set_u8(u8 value
, u32 cap
, struct Interface
*iface
) {
797 case ACER_CAP_BRIGHTNESS
:
798 switch (quirks
->brightness
) {
800 return ec_write(0x83, value
);
802 return ec_write(0x85, value
);
804 return AE_BAD_ADDRESS
;
808 return AE_BAD_ADDRESS
;
813 static struct Interface AMW0_interface
= {
824 * New interface (The WMID interface)
827 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
829 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
830 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
831 union acpi_object
*obj
;
835 DEBUG(2, " WMI_execute_u32:\n");
836 status
= wmi_acer_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
837 DEBUG(2, " In: 0x%08x\n", in
);
839 if (ACPI_FAILURE(status
))
842 obj
= (union acpi_object
*) result
.pointer
;
843 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
844 tmp
= *((u32
*) obj
->buffer
.pointer
);
845 DEBUG(2, " Out: 0x%08x\n", tmp
);
849 DEBUG(2, " Got unexpected result of type %d\n", obj
->type
);
851 DEBUG(2, " Got unexpected null result\n");
858 if (result
.length
> 0 && result
.pointer
)
859 kfree(result
.pointer
);
861 DEBUG(2, " Returning from WMI_execute_u32:\n");
865 static acpi_status
WMID_get_u8(u8
*value
, u32 cap
, struct Interface
*iface
) {
870 DEBUG(2, " WMID_get_u8: cap=%d\n", cap
);
872 case ACER_CAP_WIRELESS
:
873 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
875 case ACER_CAP_BLUETOOTH
:
876 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
878 case ACER_CAP_BRIGHTNESS
:
879 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
881 case ACER_CAP_THREEG
:
882 method_id
= ACER_WMID_GET_THREEG_METHODID
;
884 case ACER_CAP_MAILLED
:
885 if (quirks
->mailled
== 1) {
886 ec_read(0x9f, value
);
890 case ACER_CAP_TOUCHPAD_READ
:
891 switch (quirks
->touchpad
) {
893 ec_read(0x9e, value
);
894 *value
= 1 - ((*value
>> 3) & 0x01);
899 case ACER_CAP_TEMPERATURE_OVERRIDE
:
900 if (quirks
->temperature_override
== 1) {
901 ec_read(0xa9, value
);
905 return AE_BAD_ADDRESS
;
907 status
= WMI_execute_u32(method_id
, 0, &result
);
908 DEBUG(2, " WMI_execute_u32 status=%d:\n", status
);
910 if (ACPI_SUCCESS(status
))
913 DEBUG(2, " Returning from WMID_get_u8:\n");
917 static acpi_status
WMID_set_u8(u8 value
, u32 cap
, struct Interface
*iface
) {
921 case ACER_CAP_BRIGHTNESS
:
922 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
924 case ACER_CAP_WIRELESS
:
925 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
927 case ACER_CAP_BLUETOOTH
:
928 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
930 case ACER_CAP_THREEG
:
931 method_id
= ACER_WMID_SET_THREEG_METHODID
;
933 case ACER_CAP_MAILLED
:
934 if (quirks
->mailled
== 1) {
935 send_kbd_cmd(0x59, value
? 0x92 : 0x93);
938 case ACER_CAP_TEMPERATURE_OVERRIDE
:
939 if (quirks
->temperature_override
== 1) {
940 ec_write(0xa9, value
);
944 return AE_BAD_ADDRESS
;
946 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
950 static struct Interface WMID_interface
= {
954 | ACER_CAP_BRIGHTNESS
962 * High-level Procfs file handlers
966 dispatch_read(char *page
, char **start
, off_t off
, int count
, int *eof
,
967 struct ProcItem
*item
)
972 DEBUG(2, " dispatch_read: \n");
974 p
= item
->read_func(p
, item
->capability
);
976 if (len
<= off
+ count
)
988 dispatch_write(struct file
*file
, const char __user
*buffer
,
989 unsigned long count
, struct ProcItem
*item
)
995 * Arg buffer points to userspace memory, which can't be accessed
996 * directly. Since we're making a copy, zero-terminate the
997 * destination so that sscanf can be used on it safely.
999 tmp_buffer
= kmalloc(count
+ 1, GFP_KERNEL
);
1000 if (copy_from_user(tmp_buffer
, buffer
, count
)) {
1003 tmp_buffer
[count
] = 0;
1004 result
= item
->write_func(tmp_buffer
, count
, item
->capability
);
1012 * Generic Device (interface-independent)
1015 static acpi_status
get_bool(bool *value
, u32 cap
) {
1016 acpi_status status
= AE_BAD_ADDRESS
;
1019 DEBUG(2, " get_bool: cap=%d, interface type=%d\n",
1020 cap
, interface
->type
);
1021 switch (interface
->type
) {
1023 status
= AMW0_get_bool(value
, cap
, interface
);
1026 status
= WMID_get_u8(&tmp
, cap
, interface
);
1027 *value
= (tmp
== 1) ? 1 : 0;
1030 DEBUG(2, " Returning from get_bool:\n");
1034 static acpi_status
set_bool(int value
, u32 cap
) {
1035 acpi_status status
= AE_BAD_PARAMETER
;
1037 DEBUG(2, " set_bool: cap=%d, interface type=%d, value=%d\n",
1038 cap
, interface
->type
, value
);
1039 if ((value
== 0 || value
== 1) && (interface
->capability
& cap
)) {
1040 switch (interface
->type
) {
1042 status
= AMW0_set_bool(value
== 1, cap
, interface
);
1045 status
= WMID_set_u8(value
== 1, cap
, interface
);
1052 static acpi_status
get_u8(u8
*value
, u32 cap
) {
1053 DEBUG(2, " get_u8: cap=%d\n", cap
);
1054 switch (interface
->type
) {
1056 return AMW0_get_u8(value
, cap
, interface
);
1059 return WMID_get_u8(value
, cap
, interface
);
1062 return AE_BAD_ADDRESS
;
1066 static acpi_status
set_u8(u8 value
, u8 min
, u8 max
, u32 cap
) {
1068 DEBUG(2, " set_u8: cap=%d, interface type=%d, value=%d\n",
1069 cap
, interface
->type
, value
);
1071 if ((value
>= min
&& value
<= max
) && (interface
->capability
& cap
) ) {
1072 switch (interface
->type
) {
1074 return AMW0_set_u8(value
, cap
, interface
);
1076 return WMID_set_u8(value
, cap
, interface
);
1078 return AE_BAD_PARAMETER
;
1081 return AE_BAD_PARAMETER
;
1084 /* Each _u8 needs a small wrapper that sets the boundary values */
1085 static acpi_status
set_brightness(u8 value
)
1087 return set_u8(value
, 0, max_brightness
, ACER_CAP_BRIGHTNESS
);
1090 static acpi_status
set_temperature_override(u8 value
)
1092 return set_u8(value
, 0, ACER_MAX_TEMPERATURE_OVERRIDE
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1095 static void __init
acer_commandline_init(void)
1097 DEBUG(1, "Commandline args: mailled(%d) wireless(%d) bluetooth(%d) brightness(%d)\n",
1098 mailled
, wireless
, bluetooth
, brightness
);
1101 * These will all fail silently if the value given is invalid, or the
1102 * capability isn't available on the given interface
1104 set_bool(mailled
, ACER_CAP_MAILLED
);
1105 set_bool(wireless
, ACER_CAP_WIRELESS
);
1106 set_bool(bluetooth
, ACER_CAP_BLUETOOTH
);
1107 set_bool(threeg
, ACER_CAP_THREEG
);
1108 set_temperature_override(fan_temperature_override
);
1109 set_brightness((u8
)brightness
);
1114 * Procfs interface (deprecated)
1116 static char *read_bool(char *p
, u32 cap
)
1121 DEBUG(2, " read_bool: cap=%d\n", cap
);
1122 status
= get_bool(&result
, cap
);
1123 if (ACPI_SUCCESS(status
))
1124 p
+= sprintf(p
, "%d\n", result
);
1126 p
+= sprintf(p
, "Read error" );
1130 static unsigned long write_bool(const char *buffer
, unsigned long count
, u32 cap
)
1134 DEBUG(2, " write_bool: cap=%d, interface type=%d\n buffer=%s\n",
1135 cap
, interface
->type
, buffer
);
1137 if (sscanf(buffer
, "%i", &value
) == 1) {
1138 acpi_status status
= set_bool(value
, cap
);
1139 if (ACPI_FAILURE(status
))
1147 static char *read_u8(char *p
, u32 cap
)
1152 DEBUG(2, " read_u8: cap=%d\n", cap
);
1153 status
= get_u8(&result
, cap
);
1154 if (ACPI_SUCCESS(status
))
1155 p
+= sprintf(p
, "%u\n", result
);
1157 p
+= sprintf(p
, "Read error" );
1161 static unsigned long write_u8(const char *buffer
, unsigned long count
, u32 cap
)
1164 acpi_status (*set_method
)(u8
);
1166 /* Choose the appropriate set_u8 wrapper here, based on the capability */
1168 case ACER_CAP_BRIGHTNESS
:
1169 set_method
= set_brightness
;
1171 case ACER_CAP_TEMPERATURE_OVERRIDE
:
1172 set_method
= set_temperature_override
;
1178 if (sscanf(buffer
, "%i", &value
) == 1) {
1179 acpi_status status
= (*set_method
)(value
);
1180 if (ACPI_FAILURE(status
))
1188 static char *read_version(char *p
, u32 cap
)
1190 p
+= sprintf(p
, "%s\n", ACER_ACPI_VERSION
);
1194 static char *read_interface(char *p
, u32 cap
)
1196 p
+= sprintf(p
, "%s\n", (interface
->type
== ACER_AMW0
) ? "AMW0": "WMID");
1200 static struct ProcItem proc_items
[] = {
1201 {"mailled", read_bool
, write_bool
, ACER_CAP_MAILLED
},
1202 {"bluetooth", read_bool
, write_bool
, ACER_CAP_BLUETOOTH
},
1203 {"wireless", read_bool
, write_bool
, ACER_CAP_WIRELESS
},
1204 {"brightness", read_u8
, write_u8
, ACER_CAP_BRIGHTNESS
},
1205 {"threeg", read_bool
, write_bool
, ACER_CAP_THREEG
},
1206 {"touchpad", read_bool
, NULL
, ACER_CAP_TOUCHPAD_READ
},
1207 {"fan_temperature_override", read_u8
, write_u8
, ACER_CAP_TEMPERATURE_OVERRIDE
},
1208 {"version", read_version
, NULL
, ACER_CAP_ANY
},
1209 {"interface", read_interface
, NULL
, ACER_CAP_ANY
},
1213 static int __init
add_proc_entries(void)
1215 struct proc_dir_entry
*proc
;
1216 struct ProcItem
*item
;
1218 for (item
= proc_items
; item
->name
; ++item
) {
1220 * Only add the proc file if the current interface actually
1223 if (interface
->capability
& item
->capability
) {
1224 proc
= create_proc_read_entry(item
->name
,
1225 S_IFREG
| S_IRUGO
| S_IWUSR
,
1227 (read_proc_t
*) dispatch_read
,
1230 proc
->owner
= THIS_MODULE
;
1231 if (proc
&& item
->write_func
)
1232 proc
->write_proc
= (write_proc_t
*) dispatch_write
;
1239 static int __exit
remove_proc_entries(void)
1241 struct ProcItem
*item
;
1243 for (item
= proc_items
; item
->name
; ++item
)
1244 remove_proc_entry(item
->name
, acer_proc_dir
);
1250 * LED device (Mail LED only, no other LEDs known yet)
1252 static void mail_led_set(struct led_classdev
*led_cdev
, enum led_brightness value
)
1255 set_bool(tmp
, ACER_CAP_MAILLED
);
1258 static struct led_classdev mail_led
= {
1259 .name
= "acer_acpi:mail",
1260 .brightness_set
= mail_led_set
,
1263 static void acer_led_init(struct device
*dev
)
1265 led_classdev_register(dev
, &mail_led
);
1268 static void acer_led_exit(void)
1270 led_classdev_unregister(&mail_led
);
1273 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1277 static struct backlight_device
*acer_backlight_device
;
1279 static int read_brightness(struct backlight_device
*bd
)
1282 get_u8(&value
, ACER_CAP_BRIGHTNESS
);
1286 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,20)
1287 static int update_bl_status(struct backlight_device
*bd
)
1289 set_brightness(bd
->props
->brightness
);
1293 static struct backlight_properties acer_backlight_properties
= {
1294 .get_brightness
= read_brightness
,
1295 .update_status
= update_bl_status
,
1298 static int __init
acer_backlight_init(struct device
*dev
)
1300 struct backlight_device
*bd
;
1302 DEBUG(1, "Loading backlight driver\n");
1303 bd
= backlight_device_register("acer_acpi", dev
, NULL
, &acer_backlight_properties
);
1305 printk(ACER_ERR
"Could not register Acer backlight device\n");
1306 acer_backlight_device
= NULL
;
1310 acer_backlight_device
= bd
;
1312 bd
->props
->max_brightness
= max_brightness
;
1316 static int update_bl_status(struct backlight_device
*bd
)
1318 set_brightness(bd
->props
.brightness
);
1322 static struct backlight_ops acer_backlight_ops
= {
1323 .get_brightness
= read_brightness
,
1324 .update_status
= update_bl_status
,
1327 static int __init
acer_backlight_init(struct device
*dev
)
1329 struct backlight_device
*bd
;
1331 DEBUG(1, "Loading backlight driver\n");
1332 bd
= backlight_device_register("acer_acpi", dev
, NULL
, &acer_backlight_ops
);
1334 printk(ACER_ERR
"Could not register Acer backlight device\n");
1335 acer_backlight_device
= NULL
;
1339 acer_backlight_device
= bd
;
1341 bd
->props
.max_brightness
= max_brightness
;
1342 bd
->props
.brightness
= read_brightness(NULL
);
1343 backlight_update_status(bd
);
1348 static void __exit
acer_backlight_exit(void)
1350 backlight_device_unregister(acer_backlight_device
);
1355 * Read/ write bool sysfs macro
1357 #define show_set_bool(value, cap) \
1359 show_bool_##value(struct device *dev, struct device_attribute *attr, \
1363 acpi_status status = get_bool(&result, cap); \
1364 if (ACPI_SUCCESS(status)) \
1365 return sprintf(buf, "%d\n", result); \
1366 return sprintf(buf, "Read error" ); \
1370 set_bool_##value(struct device *dev, struct device_attribute *attr, \
1371 const char *buf, size_t count) \
1373 bool tmp = simple_strtoul(buf, NULL, 10); \
1374 acpi_status status = set_bool(tmp, cap); \
1375 if (ACPI_FAILURE(status)) \
1379 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
1380 show_bool_##value, set_bool_##value);
1382 show_set_bool(wireless
, ACER_CAP_WIRELESS
);
1383 show_set_bool(bluetooth
, ACER_CAP_BLUETOOTH
);
1384 show_set_bool(threeg
, ACER_CAP_THREEG
);
1385 show_set_bool(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1388 * Read-only bool sysfs macro
1390 #define show_bool(value, cap) \
1392 show_bool_##value(struct device *dev, struct device_attribute *attr, \
1396 acpi_status status = get_bool(&result, cap); \
1397 if (ACPI_SUCCESS(status)) \
1398 return sprintf(buf, "%d\n", result); \
1399 return sprintf(buf, "Read error" ); \
1401 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
1402 show_bool_##value, NULL);
1404 show_bool(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1407 * Read interface sysfs macro
1409 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1412 return sprintf(buf
, "%s\n", (interface
->type
== ACER_AMW0
) ? "AMW0" : "WMID");
1415 static DEVICE_ATTR(interface
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_interface
, NULL
);
1420 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1422 if (has_cap(ACER_CAP_MAILLED
))
1423 acer_led_init(&device
->dev
);
1424 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1425 if (has_cap(ACER_CAP_BRIGHTNESS
))
1426 acer_backlight_init(&device
->dev
);
1431 static int acer_platform_remove(struct platform_device
*device
)
1433 if (has_cap(ACER_CAP_MAILLED
))
1435 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1436 if (has_cap(ACER_CAP_BRIGHTNESS
))
1437 acer_backlight_exit();
1442 static int acer_platform_suspend(struct platform_device
*device
, pm_message_t state
)
1445 * WMID fix for suspend-to-disk - save all current states now so we can
1446 * restore them on resume
1450 struct acer_data
*data
= &interface
->data
;
1452 #define save_bool_device(device, cap) \
1453 if (has_cap(cap)) {\
1454 get_bool(&value, cap);\
1455 data->device = value;\
1458 #define save_u8_device(device, cap) \
1459 if (has_cap(cap)) {\
1460 get_u8(&u8value, cap);\
1461 data->device = u8value;\
1464 if (interface
->type
== ACER_WMID
) {
1465 save_bool_device(wireless
, ACER_CAP_WIRELESS
);
1466 save_bool_device(bluetooth
, ACER_CAP_BLUETOOTH
);
1467 save_bool_device(threeg
, ACER_CAP_THREEG
);
1468 save_u8_device(brightness
, ACER_CAP_BRIGHTNESS
);
1474 static int acer_platform_resume(struct platform_device
*device
)
1476 struct acer_data
*data
= &interface
->data
;
1478 #define restore_bool_device(device, cap) \
1480 set_bool(data->device, cap);\
1482 restore_bool_device(wireless, ACER_CAP_WIRELESS);
1483 restore_bool_device(bluetooth
, ACER_CAP_BLUETOOTH
);
1484 restore_bool_device(threeg
, ACER_CAP_THREEG
);
1485 restore_bool_device(mailled
, ACER_CAP_MAILLED
);
1487 if (has_cap(ACER_CAP_BRIGHTNESS
))
1488 set_brightness((u8
)data
->brightness
);
1490 /* Check if this laptop requires the keyboard quirk */
1491 if (quirks
->mmkeys
!= 0) {
1492 set_keyboard_quirk();
1493 printk(ACER_INFO
"Setting keyboard quirk to enable multimedia keys\n");
1499 static struct platform_driver acer_platform_driver
= {
1501 .name
= "acer_acpi",
1502 .owner
= THIS_MODULE
,
1504 .probe
= acer_platform_probe
,
1505 .remove
= acer_platform_remove
,
1506 .suspend
= acer_platform_suspend
,
1507 .resume
= acer_platform_resume
,
1510 static struct platform_device
*acer_platform_device
;
1512 static int remove_sysfs(struct platform_device
*device
)
1514 #define remove_device_file(value, cap) \
1516 device_remove_file(&device->dev, &dev_attr_##value);
1518 remove_device_file(wireless
, ACER_CAP_WIRELESS
);
1519 remove_device_file(bluetooth
, ACER_CAP_BLUETOOTH
);
1520 remove_device_file(threeg
, ACER_CAP_THREEG
);
1521 remove_device_file(interface
, ACER_CAP_ANY
);
1522 remove_device_file(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1523 remove_device_file(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1527 static int create_sysfs(void)
1529 int retval
= -ENOMEM
;
1531 #define add_device_file(value, cap) \
1532 if (has_cap(cap)) {\
1533 retval = device_create_file(&acer_platform_device->dev, &dev_attr_##value);\
1538 add_device_file(wireless
, ACER_CAP_WIRELESS
);
1539 add_device_file(bluetooth
, ACER_CAP_BLUETOOTH
);
1540 add_device_file(threeg
, ACER_CAP_THREEG
);
1541 add_device_file(interface
, ACER_CAP_ANY
);
1542 add_device_file(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1543 add_device_file(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1548 remove_sysfs(acer_platform_device
);
1552 static int __init
acer_acpi_init(void)
1554 printk(ACER_INFO
"Acer Laptop ACPI Extras version %s\n",
1558 * Detect which WMI interface we're using.
1559 * Check for AMW0 first, as later AMW0 laptops also have the WMID GUID.
1561 if (wmi_acer_has_guid(AMW0_GUID1
)) {
1562 DEBUG(0, "Detected Acer AMW0 interface\n");
1563 interface
= &AMW0_interface
;
1564 } else if (wmi_acer_has_guid(WMID_GUID1
)) {
1565 DEBUG(0, "Detected Acer WMID interface\n");
1566 interface
= &WMID_interface
;
1568 printk(ACER_ERR
"No or unsupported WMI interface, unable to load.\n");
1572 /* Find if this laptop requires any quirks */
1573 DEBUG(1, "Finding quirks\n");
1576 /* Now that we have a known interface, initialize it */
1577 DEBUG(1, "Initialising interface\n");
1578 if (interface
->init
)
1579 interface
->init(interface
);
1582 /* Create the proc entries */
1583 acer_proc_dir
= proc_mkdir(PROC_ACER
, acpi_root_dir
);
1584 if (!acer_proc_dir
) {
1585 printk(ACER_ERR
"Unable to create /proc entries, aborting.\n");
1586 goto error_proc_mkdir
;
1589 acer_proc_dir
->owner
= THIS_MODULE
;
1590 if (add_proc_entries()) {
1591 printk(ACER_ERR
"Unable to create /proc entries, aborting.\n");
1592 goto error_proc_add
;
1597 * Register the driver
1599 if (platform_driver_register(&acer_platform_driver
)) {
1600 printk(ACER_ERR
"Unable to register platform driver, aborting.\n");
1601 goto error_platform_register
;
1603 acer_platform_device
= platform_device_alloc("acer_acpi", -1);
1604 platform_device_add(acer_platform_device
);
1608 DEBUG(1, "Driver registered\n");
1610 /* Override any initial settings with values from the commandline */
1611 acer_commandline_init();
1615 error_platform_register
:
1617 remove_proc_entries();
1620 remove_proc_entry(PROC_ACER
, acpi_root_dir
);
1626 static void __exit
acer_acpi_exit(void)
1628 remove_sysfs(acer_platform_device
);
1629 platform_device_del(acer_platform_device
);
1630 platform_driver_unregister(&acer_platform_driver
);
1633 remove_proc_entries();
1636 remove_proc_entry(PROC_ACER
, acpi_root_dir
);
1638 printk(ACER_INFO
"Acer Laptop ACPI Extras unloaded\n");
1642 module_init(acer_acpi_init
);
1643 module_exit(acer_acpi_exit
);