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
,
593 ACER_CAP_BRIGHTNESS
|
599 * New interface (The WMID interface)
602 WMI_execute_u32(u32 method_id
, u32 in
, u32
*out
)
604 struct acpi_buffer input
= { (acpi_size
) sizeof(u32
), (void *)(&in
) };
605 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
606 union acpi_object
*obj
;
610 DEBUG(2, " WMI_execute_u32:\n");
611 status
= wmi_acer_evaluate_method(WMID_GUID1
, 1, method_id
, &input
, &result
);
612 DEBUG(2, " In: 0x%08x\n", in
);
614 if (ACPI_FAILURE(status
))
617 obj
= (union acpi_object
*) result
.pointer
;
618 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
619 tmp
= *((u32
*) obj
->buffer
.pointer
);
620 DEBUG(2, " Out: 0x%08x\n", tmp
);
624 DEBUG(2, " Got unexpected result of type %d\n", obj
->type
);
626 DEBUG(2, " Got unexpected null result\n");
633 if (result
.length
> 0 && result
.pointer
)
634 kfree(result
.pointer
);
636 DEBUG(2, " Returning from WMI_execute_u32:\n");
640 static acpi_status
WMID_get_u8(u8
*value
, u32 cap
, struct Interface
*iface
) {
645 DEBUG(2, " WMID_get_u8: cap=%d\n", cap
);
647 case ACER_CAP_WIRELESS
:
648 method_id
= ACER_WMID_GET_WIRELESS_METHODID
;
650 case ACER_CAP_BLUETOOTH
:
651 method_id
= ACER_WMID_GET_BLUETOOTH_METHODID
;
653 case ACER_CAP_BRIGHTNESS
:
654 method_id
= ACER_WMID_GET_BRIGHTNESS_METHODID
;
656 case ACER_CAP_THREEG
:
657 method_id
= ACER_WMID_GET_THREEG_METHODID
;
659 case ACER_CAP_MAILLED
:
660 if (quirks
->mailled
== 1) {
661 ec_read(0x9f, value
);
665 case ACER_CAP_TOUCHPAD_READ
:
666 switch (quirks
->touchpad
) {
668 ec_read(0x9e, value
);
669 *value
= 1 - ((*value
>> 3) & 0x01);
672 ec_read(0x74, value
);
673 *value
= ((*value
>> 3) & 0x01);
678 case ACER_CAP_TEMPERATURE_OVERRIDE
:
679 if (quirks
->temperature_override
== 1) {
680 ec_read(0xa9, value
);
684 return AE_BAD_ADDRESS
;
686 status
= WMI_execute_u32(method_id
, 0, &result
);
687 DEBUG(2, " WMI_execute_u32 status=%d:\n", status
);
689 if (ACPI_SUCCESS(status
))
692 DEBUG(2, " Returning from WMID_get_u8:\n");
696 static acpi_status
WMID_set_u8(u8 value
, u32 cap
, struct Interface
*iface
) {
700 case ACER_CAP_BRIGHTNESS
:
701 method_id
= ACER_WMID_SET_BRIGHTNESS_METHODID
;
703 case ACER_CAP_WIRELESS
:
704 method_id
= ACER_WMID_SET_WIRELESS_METHODID
;
706 case ACER_CAP_BLUETOOTH
:
707 method_id
= ACER_WMID_SET_BLUETOOTH_METHODID
;
709 case ACER_CAP_THREEG
:
710 method_id
= ACER_WMID_SET_THREEG_METHODID
;
712 case ACER_CAP_MAILLED
:
713 if (quirks
->mailled
== 1) {
714 send_kbd_cmd(0x59, value
? 0x92 : 0x93);
717 case ACER_CAP_TEMPERATURE_OVERRIDE
:
718 if (quirks
->temperature_override
== 1) {
719 ec_write(0xa9, value
);
723 return AE_BAD_ADDRESS
;
725 return WMI_execute_u32(method_id
, (u32
)value
, NULL
);
728 static acpi_status
WMID_set_capabilities(void) {
729 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
730 union acpi_object
*obj
;
734 status
= wmi_acer_query_block(WMID_GUID2
, 1, &out
);
735 if (ACPI_FAILURE(status
))
738 obj
= (union acpi_object
*) out
.pointer
;
739 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
740 devices
= *((u32
*) obj
->buffer
.pointer
);
745 /* Not sure on the meaning of the relevant bits yet */
746 interface
->capability
|= ACER_CAP_WIRELESS
;
747 interface
->capability
|= ACER_CAP_THREEG
;
749 if (devices
& 0x10) {
750 DEBUG(1, "Bluetooth hardware available - enabling\n");
751 interface
->capability
|= ACER_CAP_BLUETOOTH
;
754 if (!(devices
& 0x20)) {
755 DEBUG(1, "Maximum brightness quirk detected - enabling\n");
756 max_brightness
= 0x9;
763 static struct Interface WMID_interface
= {
765 .capability
= ACER_CAP_BRIGHTNESS
,
770 * High-level Procfs file handlers
774 dispatch_read(char *page
, char **start
, off_t off
, int count
, int *eof
,
775 struct ProcItem
*item
)
780 DEBUG(2, " dispatch_read: \n");
782 p
= item
->read_func(p
, item
->capability
);
784 if (len
<= off
+ count
)
796 dispatch_write(struct file
*file
, const char __user
*buffer
,
797 unsigned long count
, struct ProcItem
*item
)
803 * Arg buffer points to userspace memory, which can't be accessed
804 * directly. Since we're making a copy, zero-terminate the
805 * destination so that sscanf can be used on it safely.
807 tmp_buffer
= kmalloc(count
+ 1, GFP_KERNEL
);
808 if (copy_from_user(tmp_buffer
, buffer
, count
)) {
811 tmp_buffer
[count
] = 0;
812 result
= item
->write_func(tmp_buffer
, count
, item
->capability
);
820 * Generic Device (interface-independent)
823 static acpi_status
get_bool(bool *value
, u32 cap
) {
824 acpi_status status
= AE_BAD_ADDRESS
;
827 DEBUG(2, " get_bool: cap=%d, interface type=%d\n",
828 cap
, interface
->type
);
829 switch (interface
->type
) {
831 status
= AMW0_get_bool(value
, cap
, interface
);
834 if (cap
== ACER_CAP_MAILLED
) {
835 status
= AMW0_get_bool(value
, cap
, interface
);
839 status
= WMID_get_u8(&tmp
, cap
, interface
);
840 *value
= (tmp
== 1) ? 1 : 0;
843 DEBUG(2, " Returning from get_bool:\n");
847 static acpi_status
set_bool(int value
, u32 cap
) {
848 acpi_status status
= AE_BAD_PARAMETER
;
850 DEBUG(2, " set_bool: cap=%d, interface type=%d, value=%d\n",
851 cap
, interface
->type
, value
);
852 if ((value
== 0 || value
== 1) && (interface
->capability
& cap
)) {
853 switch (interface
->type
) {
855 status
= AMW0_set_bool(value
== 1, cap
, interface
);
858 if (cap
== ACER_CAP_MAILLED
) {
859 status
= AMW0_set_bool(value
== 1, cap
,
864 status
= WMID_set_u8(value
== 1, cap
, interface
);
871 static acpi_status
get_u8(u8
*value
, u32 cap
) {
872 DEBUG(2, " get_u8: cap=%d\n", cap
);
873 switch (interface
->type
) {
875 return AMW0_get_u8(value
, cap
, interface
);
879 return WMID_get_u8(value
, cap
, interface
);
882 return AE_BAD_ADDRESS
;
886 static acpi_status
set_u8(u8 value
, u8 min
, u8 max
, u32 cap
) {
888 DEBUG(2, " set_u8: cap=%d, interface type=%d, value=%d\n",
889 cap
, interface
->type
, value
);
891 if ((value
>= min
&& value
<= max
) && (interface
->capability
& cap
) ) {
892 switch (interface
->type
) {
894 return AMW0_set_u8(value
, cap
, interface
);
897 return WMID_set_u8(value
, cap
, interface
);
899 return AE_BAD_PARAMETER
;
902 return AE_BAD_PARAMETER
;
905 /* Each _u8 needs a small wrapper that sets the boundary values */
906 static acpi_status
set_brightness(u8 value
)
908 return set_u8(value
, 0, max_brightness
, ACER_CAP_BRIGHTNESS
);
911 static acpi_status
set_temperature_override(u8 value
)
913 return set_u8(value
, 0, ACER_MAX_TEMPERATURE_OVERRIDE
, ACER_CAP_TEMPERATURE_OVERRIDE
);
916 static void __init
acer_commandline_init(void)
918 DEBUG(1, "Commandline args: mailled(%d) wireless(%d) bluetooth(%d) brightness(%d)\n",
919 mailled
, wireless
, bluetooth
, brightness
);
922 * These will all fail silently if the value given is invalid, or the
923 * capability isn't available on the given interface
925 set_bool(mailled
, ACER_CAP_MAILLED
);
926 set_bool(wireless
, ACER_CAP_WIRELESS
);
927 set_bool(bluetooth
, ACER_CAP_BLUETOOTH
);
928 set_bool(threeg
, ACER_CAP_THREEG
);
929 set_temperature_override(fan_temperature_override
);
930 set_brightness((u8
)brightness
);
935 * Procfs interface (deprecated)
937 static char *read_bool(char *p
, u32 cap
)
942 DEBUG(2, " read_bool: cap=%d\n", cap
);
943 status
= get_bool(&result
, cap
);
944 if (ACPI_SUCCESS(status
))
945 p
+= sprintf(p
, "%d\n", result
);
947 p
+= sprintf(p
, "Read error" );
951 static unsigned long write_bool(const char *buffer
, unsigned long count
, u32 cap
)
955 DEBUG(2, " write_bool: cap=%d, interface type=%d\n buffer=%s\n",
956 cap
, interface
->type
, buffer
);
958 if (sscanf(buffer
, "%i", &value
) == 1) {
959 acpi_status status
= set_bool(value
, cap
);
960 if (ACPI_FAILURE(status
))
968 static char *read_u8(char *p
, u32 cap
)
973 DEBUG(2, " read_u8: cap=%d\n", cap
);
974 status
= get_u8(&result
, cap
);
975 if (ACPI_SUCCESS(status
))
976 p
+= sprintf(p
, "%u\n", result
);
978 p
+= sprintf(p
, "Read error" );
982 static unsigned long write_u8(const char *buffer
, unsigned long count
, u32 cap
)
985 acpi_status (*set_method
)(u8
);
987 /* Choose the appropriate set_u8 wrapper here, based on the capability */
989 case ACER_CAP_BRIGHTNESS
:
990 set_method
= set_brightness
;
992 case ACER_CAP_TEMPERATURE_OVERRIDE
:
993 set_method
= set_temperature_override
;
999 if (sscanf(buffer
, "%i", &value
) == 1) {
1000 acpi_status status
= (*set_method
)(value
);
1001 if (ACPI_FAILURE(status
))
1009 static char *read_version(char *p
, u32 cap
)
1011 p
+= sprintf(p
, "%s\n", ACER_ACPI_VERSION
);
1015 static char *read_interface(char *p
, u32 cap
)
1017 p
+= sprintf(p
, "%s\n", (interface
->type
== ACER_AMW0
) ? "AMW0": "WMID");
1021 static struct ProcItem proc_items
[] = {
1022 {"mailled", read_bool
, write_bool
, ACER_CAP_MAILLED
},
1023 {"bluetooth", read_bool
, write_bool
, ACER_CAP_BLUETOOTH
},
1024 {"wireless", read_bool
, write_bool
, ACER_CAP_WIRELESS
},
1025 {"brightness", read_u8
, write_u8
, ACER_CAP_BRIGHTNESS
},
1026 {"threeg", read_bool
, write_bool
, ACER_CAP_THREEG
},
1027 {"touchpad", read_bool
, NULL
, ACER_CAP_TOUCHPAD_READ
},
1028 {"fan_temperature_override", read_u8
, write_u8
, ACER_CAP_TEMPERATURE_OVERRIDE
},
1029 {"version", read_version
, NULL
, ACER_CAP_ANY
},
1030 {"interface", read_interface
, NULL
, ACER_CAP_ANY
},
1034 static int __init
add_proc_entries(void)
1036 struct proc_dir_entry
*proc
;
1037 struct ProcItem
*item
;
1039 for (item
= proc_items
; item
->name
; ++item
) {
1041 * Only add the proc file if the current interface actually
1044 if (interface
->capability
& item
->capability
) {
1045 proc
= create_proc_read_entry(item
->name
,
1046 S_IFREG
| S_IRUGO
| S_IWUSR
,
1048 (read_proc_t
*) dispatch_read
,
1051 proc
->owner
= THIS_MODULE
;
1052 if (proc
&& item
->write_func
)
1053 proc
->write_proc
= (write_proc_t
*) dispatch_write
;
1060 static int __exit
remove_proc_entries(void)
1062 struct ProcItem
*item
;
1064 for (item
= proc_items
; item
->name
; ++item
)
1065 remove_proc_entry(item
->name
, acer_proc_dir
);
1071 * LED device (Mail LED only, no other LEDs known yet)
1073 static void mail_led_set(struct led_classdev
*led_cdev
, enum led_brightness value
)
1076 set_bool(tmp
, ACER_CAP_MAILLED
);
1079 static struct led_classdev mail_led
= {
1080 .name
= "acer_acpi:mail",
1081 .brightness_set
= mail_led_set
,
1084 static void acer_led_init(struct device
*dev
)
1086 led_classdev_register(dev
, &mail_led
);
1089 static void acer_led_exit(void)
1091 led_classdev_unregister(&mail_led
);
1094 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1098 static struct backlight_device
*acer_backlight_device
;
1100 static int read_brightness(struct backlight_device
*bd
)
1103 get_u8(&value
, ACER_CAP_BRIGHTNESS
);
1107 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,20)
1108 static int update_bl_status(struct backlight_device
*bd
)
1110 set_brightness(bd
->props
->brightness
);
1114 static struct backlight_properties acer_backlight_properties
= {
1115 .get_brightness
= read_brightness
,
1116 .update_status
= update_bl_status
,
1119 static int __init
acer_backlight_init(struct device
*dev
)
1121 struct backlight_device
*bd
;
1123 DEBUG(1, "Loading backlight driver\n");
1124 bd
= backlight_device_register("acer_acpi", dev
, NULL
, &acer_backlight_properties
);
1126 printk(ACER_ERR
"Could not register Acer backlight device\n");
1127 acer_backlight_device
= NULL
;
1131 acer_backlight_device
= bd
;
1133 bd
->props
->max_brightness
= max_brightness
;
1137 static int update_bl_status(struct backlight_device
*bd
)
1139 set_brightness(bd
->props
.brightness
);
1143 static struct backlight_ops acer_backlight_ops
= {
1144 .get_brightness
= read_brightness
,
1145 .update_status
= update_bl_status
,
1148 static int __init
acer_backlight_init(struct device
*dev
)
1150 struct backlight_device
*bd
;
1152 DEBUG(1, "Loading backlight driver\n");
1153 bd
= backlight_device_register("acer_acpi", dev
, NULL
, &acer_backlight_ops
);
1155 printk(ACER_ERR
"Could not register Acer backlight device\n");
1156 acer_backlight_device
= NULL
;
1160 acer_backlight_device
= bd
;
1162 bd
->props
.max_brightness
= max_brightness
;
1163 bd
->props
.brightness
= read_brightness(NULL
);
1164 backlight_update_status(bd
);
1169 static void __exit
acer_backlight_exit(void)
1171 backlight_device_unregister(acer_backlight_device
);
1176 * Read/ write bool sysfs macro
1178 #define show_set_bool(value, cap) \
1180 show_bool_##value(struct device *dev, struct device_attribute *attr, \
1184 acpi_status status = get_bool(&result, cap); \
1185 if (ACPI_SUCCESS(status)) \
1186 return sprintf(buf, "%d\n", result); \
1187 return sprintf(buf, "Read error" ); \
1191 set_bool_##value(struct device *dev, struct device_attribute *attr, \
1192 const char *buf, size_t count) \
1194 bool tmp = simple_strtoul(buf, NULL, 10); \
1195 acpi_status status = set_bool(tmp, cap); \
1196 if (ACPI_FAILURE(status)) \
1200 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
1201 show_bool_##value, set_bool_##value);
1203 show_set_bool(wireless
, ACER_CAP_WIRELESS
);
1204 show_set_bool(bluetooth
, ACER_CAP_BLUETOOTH
);
1205 show_set_bool(threeg
, ACER_CAP_THREEG
);
1206 show_set_bool(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1209 * Read-only bool sysfs macro
1211 #define show_bool(value, cap) \
1213 show_bool_##value(struct device *dev, struct device_attribute *attr, \
1217 acpi_status status = get_bool(&result, cap); \
1218 if (ACPI_SUCCESS(status)) \
1219 return sprintf(buf, "%d\n", result); \
1220 return sprintf(buf, "Read error" ); \
1222 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
1223 show_bool_##value, NULL);
1225 show_bool(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1228 * Read interface sysfs macro
1230 static ssize_t
show_interface(struct device
*dev
, struct device_attribute
*attr
,
1233 switch (interface
->type
) {
1235 return sprintf(buf
, "AMW0\n");
1237 return sprintf(buf
, "AMW0 v2\n");
1239 return sprintf(buf
, "WMID\n");
1241 return sprintf(buf
, "Error!\n");
1245 static DEVICE_ATTR(interface
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_interface
, NULL
);
1247 static ssize_t
show_devices(struct device
*dev
, struct device_attribute
*attr
,
1250 struct acpi_buffer out
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1251 union acpi_object
*obj
;
1255 status
= wmi_acer_query_block(WMID_GUID2
, 1, &out
);
1256 if (ACPI_FAILURE(status
))
1257 return sprintf(buf
, "Error\n");
1259 obj
= (union acpi_object
*) out
.pointer
;
1260 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
&& obj
->buffer
.length
== sizeof(u32
)) {
1261 tmp
= *((u32
*) obj
->buffer
.pointer
);
1263 return sprintf(buf
, "Error\n");
1266 return sprintf(buf
, "%u\n", tmp
);
1269 static DEVICE_ATTR(devices
, S_IWUGO
| S_IRUGO
| S_IWUSR
, show_devices
, NULL
);
1274 static int __devinit
acer_platform_probe(struct platform_device
*device
)
1276 if (has_cap(ACER_CAP_MAILLED
))
1277 acer_led_init(&device
->dev
);
1278 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1279 if (has_cap(ACER_CAP_BRIGHTNESS
))
1280 acer_backlight_init(&device
->dev
);
1285 static int acer_platform_remove(struct platform_device
*device
)
1287 if (has_cap(ACER_CAP_MAILLED
))
1289 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
1290 if (has_cap(ACER_CAP_BRIGHTNESS
))
1291 acer_backlight_exit();
1296 static int acer_platform_suspend(struct platform_device
*device
, pm_message_t state
)
1299 * WMID fix for suspend-to-disk - save all current states now so we can
1300 * restore them on resume
1304 struct acer_data
*data
= &interface
->data
;
1306 #define save_bool_device(device, cap) \
1307 if (has_cap(cap)) {\
1308 get_bool(&value, cap);\
1309 data->device = value;\
1312 #define save_u8_device(device, cap) \
1313 if (has_cap(cap)) {\
1314 get_u8(&u8value, cap);\
1315 data->device = u8value;\
1318 save_bool_device(wireless
, ACER_CAP_WIRELESS
);
1319 save_bool_device(bluetooth
, ACER_CAP_BLUETOOTH
);
1320 save_bool_device(threeg
, ACER_CAP_THREEG
);
1321 save_bool_device(mailled
, ACER_CAP_MAILLED
);
1322 save_u8_device(brightness
, ACER_CAP_BRIGHTNESS
);
1327 static int acer_platform_resume(struct platform_device
*device
)
1329 struct acer_data
*data
= &interface
->data
;
1331 #define restore_bool_device(device, cap) \
1333 set_bool(data->device, cap);\
1335 restore_bool_device(wireless, ACER_CAP_WIRELESS);
1336 restore_bool_device(bluetooth
, ACER_CAP_BLUETOOTH
);
1337 restore_bool_device(threeg
, ACER_CAP_THREEG
);
1338 restore_bool_device(mailled
, ACER_CAP_MAILLED
);
1340 if (has_cap(ACER_CAP_BRIGHTNESS
))
1341 set_brightness((u8
)data
->brightness
);
1343 /* Check if this laptop requires the keyboard quirk */
1344 if (quirks
->mmkeys
!= 0) {
1345 set_keyboard_quirk();
1346 printk(ACER_INFO
"Setting keyboard quirk to enable multimedia keys\n");
1352 static struct platform_driver acer_platform_driver
= {
1354 .name
= "acer_acpi",
1355 .owner
= THIS_MODULE
,
1357 .probe
= acer_platform_probe
,
1358 .remove
= acer_platform_remove
,
1359 .suspend
= acer_platform_suspend
,
1360 .resume
= acer_platform_resume
,
1363 static struct platform_device
*acer_platform_device
;
1365 static int remove_sysfs(struct platform_device
*device
)
1367 #define remove_device_file(value, cap) \
1369 device_remove_file(&device->dev, &dev_attr_##value);
1371 if (wmi_acer_has_guid(WMID_GUID2
)) {
1372 device_remove_file(&device
->dev
, &dev_attr_devices
);
1375 remove_device_file(wireless
, ACER_CAP_WIRELESS
);
1376 remove_device_file(bluetooth
, ACER_CAP_BLUETOOTH
);
1377 remove_device_file(threeg
, ACER_CAP_THREEG
);
1378 remove_device_file(interface
, ACER_CAP_ANY
);
1379 remove_device_file(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1380 remove_device_file(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1384 static int create_sysfs(void)
1386 int retval
= -ENOMEM
;
1388 #define add_device_file(value, cap) \
1389 if (has_cap(cap)) {\
1390 retval = device_create_file(&acer_platform_device->dev, &dev_attr_##value);\
1395 if (wmi_acer_has_guid(WMID_GUID2
)) {
1396 retval
= device_create_file(&acer_platform_device
->dev
, &dev_attr_devices
);
1401 add_device_file(wireless
, ACER_CAP_WIRELESS
);
1402 add_device_file(bluetooth
, ACER_CAP_BLUETOOTH
);
1403 add_device_file(threeg
, ACER_CAP_THREEG
);
1404 add_device_file(interface
, ACER_CAP_ANY
);
1405 add_device_file(fan_temperature_override
, ACER_CAP_TEMPERATURE_OVERRIDE
);
1406 add_device_file(touchpad
, ACER_CAP_TOUCHPAD_READ
);
1411 remove_sysfs(acer_platform_device
);
1415 static int __init
acer_acpi_init(void)
1417 printk(ACER_INFO
"Acer Laptop ACPI Extras version %s\n",
1420 /* Find if this laptop requires any quirks */
1421 DEBUG(1, "Finding quirks\n");
1425 * Detect which WMI interface we're using.
1427 if (wmi_acer_has_guid(AMW0_GUID1
)) {
1428 interface
= &AMW0_interface
;
1430 if (wmi_acer_has_guid(WMID_GUID1
)) {
1431 DEBUG(0, "Detected Acer AMW0 version 2 interface\n");
1432 interface
= &AMW0_V2_interface
;
1434 DEBUG(0, "Detected Acer AMW0 version 1 interface\n");
1435 if (!quirks
->brightness
) {
1436 quirks
->brightness
= 1;
1437 interface
->capability
|= ACER_CAP_BRIGHTNESS
;
1440 } else if (wmi_acer_has_guid(WMID_GUID1
)) {
1441 DEBUG(0, "Detected Acer WMID interface\n");
1442 interface
= &WMID_interface
;
1444 printk(ACER_ERR
"No or unsupported WMI interface, unable to load.\n");
1448 if (wmi_acer_has_guid(WMID_GUID2
)) {
1449 if (ACPI_FAILURE(WMID_set_capabilities())) {
1450 printk(ACER_ERR
"Unable to detect available devices\n");
1456 /* Create the proc entries */
1457 acer_proc_dir
= proc_mkdir(PROC_ACER
, acpi_root_dir
);
1458 if (!acer_proc_dir
) {
1459 printk(ACER_ERR
"Unable to create /proc entries, aborting.\n");
1460 goto error_proc_mkdir
;
1463 acer_proc_dir
->owner
= THIS_MODULE
;
1464 if (add_proc_entries()) {
1465 printk(ACER_ERR
"Unable to create /proc entries, aborting.\n");
1466 goto error_proc_add
;
1471 * Register the driver
1473 if (platform_driver_register(&acer_platform_driver
)) {
1474 printk(ACER_ERR
"Unable to register platform driver, aborting.\n");
1475 goto error_platform_register
;
1477 acer_platform_device
= platform_device_alloc("acer_acpi", -1);
1478 platform_device_add(acer_platform_device
);
1482 DEBUG(1, "Driver registered\n");
1484 /* Override any initial settings with values from the commandline */
1485 acer_commandline_init();
1489 error_platform_register
:
1491 remove_proc_entries();
1494 remove_proc_entry(PROC_ACER
, acpi_root_dir
);
1500 static void __exit
acer_acpi_exit(void)
1502 remove_sysfs(acer_platform_device
);
1503 platform_device_del(acer_platform_device
);
1504 platform_driver_unregister(&acer_platform_driver
);
1507 remove_proc_entries();
1510 remove_proc_entry(PROC_ACER
, acpi_root_dir
);
1512 printk(ACER_INFO
"Acer Laptop ACPI Extras unloaded\n");
1516 module_init(acer_acpi_init
);
1517 module_exit(acer_acpi_exit
);