Updated documentation for 0.7 release
[acer_acpi.git] / acer_acpi.c
blobdc5afd67f500bfe511ce74deed6639d7d85e24d1
1 /*
2 * acer_acpi.c - Acer Laptop ACPI Extras
5 * Copyright (C) 2005 E.M. Smith
6 * Copyright (C) 2007 Carlos Corbacho <cathectic@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * The devolpment page for this driver is located at
24 * http://code.google.com/p/aceracpi
26 * Credits:
28 * John Belmonte - the Toshiba ACPI driver I've adapted for this module.
29 * Julien Lerouge & Karol Kozimor - ASUS Acpi driver authors.
30 * Olaf Tauber - developer of acerhk, the inspiration to solve the 64-bit
31 * driver problem for my Aspire 5024.
32 * Mathieu Segaud - solved the ACPI problem that needed a double-modprobe
33 * in version 0.2 and below.
34 * Carlos Corbacho - added initial status support for wireless/ mail/
35 * bluetooth, added module parameter support to turn
36 * hardware/ LEDs on and off at module loading (thanks
37 * again to acerhk for the inspiration)
38 * Jim Ramsay - Figured out and added support for WMID interface
42 #define ACER_ACPI_VERSION "0.6"
43 #define PROC_INTERFACE_VERSION 1
44 #define PROC_ACER "acer"
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/init.h>
49 #include <linux/types.h>
50 #include <linux/proc_fs.h>
51 #include <linux/delay.h>
52 #include <linux/suspend.h>
53 #include <asm/uaccess.h>
55 #include <acpi/acpi_drivers.h>
57 MODULE_AUTHOR("Mark Smith");
58 MODULE_DESCRIPTION("Acer Laptop ACPI Extras Driver");
59 MODULE_LICENSE("GPL");
62 * Defining this enables the 3g interface on the new WMID interface.
64 * However, there are many reports of this not working (and no reports of it
65 * working), so this is for experienced users only.
67 #undef EXPERIMENTAL_INTERFACES
69 #define MY_LOGPREFIX "acer_acpi: "
70 #define MY_ERR KERN_ERR MY_LOGPREFIX
71 #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
72 #define MY_INFO KERN_INFO MY_LOGPREFIX
74 #define DEBUG(level, message...) { \
75 if (debug >= level) \
76 printk(KERN_DEBUG MY_LOGPREFIX message);\
80 * On the 5580, brightness values range from 0x0 to 0xf, inclusive.
81 * This may vary on other machines or other interfaces.
83 #define ACER_MAX_BRIGHTNESS 0xf
86 * Magic Number -
87 * Meaning is unknown - this number is required for writing to ACPI
88 * (it's also used in acerhk when directly accessing the EC)
90 #define ACER_WRITE 0x9610
93 * Bit masks for the old AMW0 interface
94 * These could vary between the particular interface
96 #define ACER_AMW0_WIRELESS_MASK 0x35
97 #define ACER_AMW0_BLUETOOTH_MASK 0x34
98 #define ACER_AMW0_MAILLED_MASK 0x31
101 * Method IDs for new WMID interface
102 * These could be different for other untested machines
104 #define ACER_WMID_GET_WIRELESS_METHODID 1
105 #define ACER_WMID_GET_BLUETOOTH_METHODID 2
106 #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
107 #define ACER_WMID_SET_WIRELESS_METHODID 4
108 #define ACER_WMID_SET_BLUETOOTH_METHODID 5
109 #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
110 #define ACER_WMID_GET_THREEG_METHODID 10
111 #define ACER_WMID_SET_THREEG_METHODID 11
114 * Acer ACPI method paths
116 * TODO: It may be possbile to autodetect these, since these are all at HID PNP0C14
118 #define AMW0_METHOD "\\_SB_.AMW0.WMAB"
119 #define AMW0_GETDATA "\\_SB_.AMW0._WED"
121 #define WMID_METHOD "\\_SB.WMID.WMBA"
122 #define WMID_GETDATA "\\_SB.WMID._WED"
125 * Interface capability flags
127 #define ACER_CAP_MAILLED (1<<0)
128 #define ACER_CAP_WIRELESS (1<<1)
129 #define ACER_CAP_BLUETOOTH (1<<2)
130 #define ACER_CAP_BRIGHTNESS (1<<3)
131 #define ACER_CAP_THREEG (1<<4)
132 #define ACER_CAP_ANY (0xffffffff)
135 * Presumed start states -
136 * For the old-style interfaces, there is no way to know for certain what the start state
137 * is for any of the parameters (ACPI does not provide any methods or store this
138 * anywhere). We therefore start with an unknown state (this is also how acerhk
139 * does it); we then change the status so that we are in a known state (I
140 * suspect LaunchManager on Windows does something similar, since the wireless
141 * appears to turn off as soon as it launches).
143 * Plus, we can't tell which features are enabled or disabled on a specific
144 * model, just ranges - e.g. The 5020 series can _support_ bluetooth; but the
145 * 5021 has no bluetooth, whilst the 5024 does. However, the BIOS identifies
146 * both laptops as 5020 - we can't tell them apart!
148 * Basically the code works like this:
149 * - On init, any values specified on the commandline are set.
150 * - For interfaces where the current values cannot be detected and which
151 * have not been set on the commandline, we set them to some sane default
152 * (disabled)
154 * See AMW0_init and acer_commandline_init
157 #define ACER_DEFAULT_WIRELESS 0
158 #define ACER_DEFAULT_BLUETOOTH 0
159 #define ACER_DEFAULT_MAILLED 0
160 #define ACER_DEFAULT_THREEG 0
161 #define ACER_DEFAULT_BRIGHTNESS ACER_MAX_BRIGHTNESS
163 static int wireless = -1;
164 static int bluetooth = -1;
165 static int mailled = -1;
166 static int brightness = -1;
167 static int threeg = -1;
168 static int debug = 0;
170 module_param(mailled, int, 0444);
171 module_param(wireless, int, 0444);
172 module_param(bluetooth, int, 0444);
173 module_param(brightness, int, 0444);
174 module_param(threeg, int, 0444);
175 module_param(debug, int, 0664);
176 MODULE_PARM_DESC(wireless, "Set initial state of Wireless hardware");
177 MODULE_PARM_DESC(bluetooth, "Set initial state of Bluetooth hardware");
178 MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
179 MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
180 MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
181 MODULE_PARM_DESC(debug, "Debugging verbosity level (0=least 2=most)");
183 typedef struct _ProcItem {
184 const char *name;
185 char *(*read_func) (char *, uint32_t);
186 unsigned long (*write_func) (const char *, unsigned long, uint32_t);
187 unsigned int capability;
188 } ProcItem;
190 struct acer_hotk {
191 struct acpi_device *device;
192 acpi_handle handle;
195 static struct proc_dir_entry *acer_proc_dir;
197 static int is_valid_acpi_path(const char *methodName)
199 acpi_handle handle;
200 acpi_status status;
202 status = acpi_get_handle(NULL, (char *)methodName, &handle);
203 return ACPI_SUCCESS(status);
206 /* Each low-level interface must define at least some of the following */
207 typedef struct _Interface {
209 * The capabilities this interface provides
210 * In the future, these can be removed/added at runtime when we have a
211 * way of detecting what capabilities are /actually/ present on an
212 * interface
214 uint32_t capability;
217 * Initializes an interface, should allocate the interface-specific
218 * data
220 acpi_status (*init) (struct _Interface*);
223 * Frees an interface, should free the interface-specific data
225 void (*free) (struct _Interface*);
228 * Gets and sets various data types.
229 * First paramater: Value to set, or pointer to place got value into
230 * Second parameter: Specific capability being requested
231 * Third paramater: Pointer to this interface
233 acpi_status (*get_bool) (bool*, uint32_t, struct _Interface*);
234 acpi_status (*set_bool) (bool, uint32_t, struct _Interface*);
235 acpi_status (*get_u8) (uint8_t*, uint32_t, struct _Interface*);
236 acpi_status (*set_u8) (uint8_t, uint32_t, struct _Interface*);
239 * Interface-specific private data member. Must *not* be touched by
240 * anyone outside of this struct
242 void *data;
243 } Interface;
245 /* The static interface pointer, points to the currently detected interface */
246 static Interface *interface;
249 * General interface convenience methods
252 /* These *_via_u8 use the interface's *_u8 methods to emulate other gets/sets */
253 static acpi_status get_bool_via_u8(bool *value, uint32_t cap, Interface *iface) {
254 acpi_status status;
255 uint8_t result;
257 status = iface->get_u8(&result, cap, iface);
259 if (ACPI_SUCCESS(status))
260 *value = (result != 0);
262 return status;
265 static acpi_status set_bool_via_u8(bool value, uint32_t cap, Interface *iface) {
266 uint8_t v = value ? 1 : 0;
268 return iface->set_u8(v, cap, iface);
271 /* General wrapper around the ACPI call */
272 static acpi_status
273 WMI_execute(char *methodPath, uint32_t methodId, const struct acpi_buffer *in, struct acpi_buffer *out) {
274 struct acpi_object_list input;
275 union acpi_object params[3];
276 acpi_status status = AE_OK;
278 /* WMI calling convention:
279 * methodPath( instance, methodId, input_buffer )
280 * - instance is always 1, since there's only this module
281 * - methodId is the method number within the current method group.
282 * - Input buffer is ignored for read-only commands
283 * - May return a buffer of results (optional)
285 input.count = 3;
286 input.pointer = params;
287 params[0].type = ACPI_TYPE_INTEGER;
288 params[0].integer.value = 0x01;
289 params[1].type = ACPI_TYPE_INTEGER;
290 params[1].integer.value = methodId;
291 params[2].type = ACPI_TYPE_BUFFER;
292 params[2].buffer.length = in->length;
293 params[2].buffer.pointer = in->pointer;
295 DEBUG(2, "Doing %s( 1, %u, [%llu-byte buffer] )\n", methodPath, methodId, (uint64_t)in->length);
297 status = acpi_evaluate_object(NULL, methodPath, &input, out);
299 DEBUG(2, " Execution status: %d\n", status);
300 DEBUG(2, " Result: %llu bytes\n", (uint64_t)(out ? out->length : 0) );
302 return status;
307 * Old interface (now known as the AMW0 interface)
309 typedef struct _WMAB_args {
310 u32 eax;
311 u32 ebx;
312 u32 ecx;
313 u32 edx;
314 } WMAB_args;
316 typedef struct _AMW0_Data {
317 int mailled;
318 int wireless;
319 int bluetooth;
320 } AMW0_Data;
322 static acpi_status WMAB_execute(WMAB_args * regbuf, struct acpi_buffer *result)
324 struct acpi_buffer input;
325 acpi_status status;
326 input.length = sizeof(WMAB_args);
327 input.pointer = (u8*)regbuf;
329 status = WMI_execute( AMW0_METHOD, 1, &input, result);
330 DEBUG(2, " Args: 0x%08x 0x%08x 0x%08x 0x%08x\n", regbuf->eax, regbuf->ebx, regbuf->ecx, regbuf->edx );
332 return status;
335 static acpi_status AMW0_init(Interface *iface) {
336 WMAB_args args;
337 acpi_status status;
338 AMW0_Data *data;
340 /* Allocate our private data structure */
341 iface->data = kmalloc(sizeof(AMW0_Data), GFP_KERNEL);
342 data = (AMW0_Data*)iface->data;
345 * Call the interface once so the BIOS knows it's to notify us of
346 * events via PNP0C14
348 memset(&args, 0, sizeof(WMAB_args));
349 args.eax = ACER_WRITE;
350 args.ebx = 0;
351 status = WMAB_execute(&args, NULL);
354 * If the commandline doesn't specify these, we need to force them to
355 * the default values
357 if (mailled == -1)
358 mailled = ACER_DEFAULT_MAILLED;
359 if (wireless == -1)
360 wireless = ACER_DEFAULT_WIRELESS;
361 if (bluetooth == -1)
362 bluetooth = ACER_DEFAULT_BLUETOOTH;
365 * Set the cached "current" values to impossible ones so that
366 * acer_commandline_init will definitely set them.
368 data->wireless = data->mailled = data->bluetooth = -1;
370 return status;
373 static void AMW0_free(Interface *iface) {
374 /* Free our private data structure */
375 kfree(iface->data);
378 static acpi_status AMW0_get_bool(bool *value, uint32_t cap, Interface *iface)
380 AMW0_Data *data = iface->data;
382 /* Currently no way to query the state, so just return the cached value */
383 switch (cap) {
384 case ACER_CAP_MAILLED:
385 *value = data->mailled;
386 break;
387 case ACER_CAP_WIRELESS:
388 *value = data->wireless;
389 break;
390 case ACER_CAP_BLUETOOTH:
391 *value = data->bluetooth;
392 break;
393 default:
394 return AE_BAD_ADDRESS;
396 return AE_OK;
399 static acpi_status AMW0_set_bool(bool value, uint32_t cap, Interface *iface)
401 WMAB_args args;
402 acpi_status status;
404 args.eax = ACER_WRITE;
405 args.ebx = value ? (1<<8) : 0;
407 switch (cap) {
408 case ACER_CAP_MAILLED:
409 args.ebx |= ACER_AMW0_MAILLED_MASK;
410 break;
411 case ACER_CAP_WIRELESS:
412 args.ebx |= ACER_AMW0_WIRELESS_MASK;
413 break;
414 case ACER_CAP_BLUETOOTH:
415 args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
416 break;
417 default:
418 return AE_BAD_ADDRESS;
421 /* Actually do the set */
422 status = WMAB_execute(&args, NULL);
425 * Currently no way to query the state, so cache the new value on
426 * success
428 if (ACPI_SUCCESS(status)) {
429 AMW0_Data *data = iface->data;
430 switch (cap) {
431 case ACER_CAP_MAILLED:
432 data->mailled = value;
433 break;
434 case ACER_CAP_WIRELESS:
435 data->wireless = value;
436 break;
437 case ACER_CAP_BLUETOOTH:
438 data->bluetooth = value;
439 break;
443 return status;
446 static Interface AMW0_interface = {
447 .capability = (
448 ACER_CAP_MAILLED |
449 ACER_CAP_WIRELESS |
450 ACER_CAP_BLUETOOTH
452 .init = AMW0_init,
453 .free = AMW0_free,
454 .get_bool = AMW0_get_bool,
455 .set_bool = AMW0_set_bool,
459 * New interface (The WMID interface)
462 static acpi_status
463 WMI_execute_uint32(uint32_t methodId, uint32_t in, uint32_t *out)
465 struct acpi_buffer input = { (acpi_size)sizeof(uint32_t), (void*)(&in) };
466 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
467 union acpi_object *obj;
468 uint32_t tmp;
469 acpi_status status;
471 status = WMI_execute(WMID_METHOD, methodId, &input, &result);
472 DEBUG(2, " In: 0x%08x\n", in);
474 if (ACPI_FAILURE(status))
475 return status;
477 obj = (union acpi_object *)result.pointer;
478 if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == sizeof(uint32_t)) {
479 tmp = *((uint32_t*)obj->buffer.pointer);
480 DEBUG(2, " Out: 0x%08x\n", tmp);
481 } else {
482 tmp = 0;
483 if (obj) {
484 DEBUG(2, " Got unexpected result of type %d\n", obj->type);
485 } else {
486 DEBUG(2, " Got unexpected null result\n");
490 if (out)
491 *out = tmp;
493 if (result.length > 0 && result.pointer)
494 kfree(result.pointer);
496 return status;
499 static acpi_status WMID_get_u8(uint8_t *value, uint32_t cap, Interface *iface) {
500 acpi_status status;
501 uint32_t result;
502 uint32_t methodId = 0;
504 switch (cap) {
505 case ACER_CAP_WIRELESS:
506 methodId = ACER_WMID_GET_WIRELESS_METHODID;
507 break;
508 case ACER_CAP_BLUETOOTH:
509 methodId = ACER_WMID_GET_BLUETOOTH_METHODID;
510 break;
511 case ACER_CAP_BRIGHTNESS:
512 methodId = ACER_WMID_GET_BRIGHTNESS_METHODID;
513 break;
514 case ACER_CAP_THREEG:
515 methodId = ACER_WMID_GET_THREEG_METHODID;
516 break;
517 default:
518 return AE_BAD_ADDRESS;
520 status = WMI_execute_uint32(methodId, 0, &result);
522 if (ACPI_SUCCESS(status))
523 *value = (uint8_t)result;
525 return status;
528 static acpi_status WMID_set_u8(uint8_t value, uint32_t cap, Interface *iface) {
529 uint32_t methodId = 0;
531 switch (cap) {
532 case ACER_CAP_BRIGHTNESS:
533 methodId = ACER_WMID_SET_BRIGHTNESS_METHODID;
534 break;
535 case ACER_CAP_WIRELESS:
536 methodId = ACER_WMID_SET_WIRELESS_METHODID;
537 break;
538 case ACER_CAP_BLUETOOTH:
539 methodId = ACER_WMID_SET_BLUETOOTH_METHODID;
540 break;
541 case ACER_CAP_THREEG:
542 methodId = ACER_WMID_SET_THREEG_METHODID;
543 break;
544 default:
545 return AE_BAD_ADDRESS;
547 return WMI_execute_uint32(methodId, (uint32_t)value, NULL);
551 static Interface WMID_interface = {
552 .capability = (
553 ACER_CAP_WIRELESS
554 | ACER_CAP_BRIGHTNESS
555 | ACER_CAP_BLUETOOTH
556 #ifdef EXPERIMENTAL_INTERFACES
557 | ACER_CAP_THREEG
558 #endif
560 .get_bool = get_bool_via_u8,
561 .set_bool = set_bool_via_u8,
562 .get_u8 = WMID_get_u8,
563 .set_u8 = WMID_set_u8,
564 .data = NULL,
568 * High-level Procfs file handlers
571 static int
572 dispatch_read(char *page, char **start, off_t off, int count, int *eof,
573 ProcItem * item)
575 char *p = page;
576 int len;
578 if (off == 0)
579 p = item->read_func(p, item->capability);
582 * ISSUE: I don't understand this code
584 len = (p - page);
585 if (len <= off + count)
586 *eof = 1;
587 *start = page + off;
588 len -= off;
589 if (len > count)
590 len = count;
591 if (len < 0)
592 len = 0;
593 return len;
596 static int
597 dispatch_write(struct file *file, const char __user * buffer,
598 unsigned long count, ProcItem * item)
600 int result;
601 char *tmp_buffer;
604 * Arg buffer points to userspace memory, which can't be accessed
605 * directly. Since we're making a copy, zero-terminate the
606 * destination so that sscanf can be used on it safely.
608 tmp_buffer = kmalloc(count + 1, GFP_KERNEL);
609 if (copy_from_user(tmp_buffer, buffer, count)) {
610 result = -EFAULT;
611 } else {
612 tmp_buffer[count] = 0;
613 result = item->write_func(tmp_buffer, count, item->capability);
615 kfree(tmp_buffer);
616 return result;
620 * Generic Device (interface-independent)
623 static acpi_status get_bool(bool *value, uint32_t cap) {
624 acpi_status status = AE_BAD_ADDRESS;
625 if (interface->get_bool)
626 status = interface->get_bool(value, cap, interface);
627 return status;
630 static acpi_status set_bool(int value, uint32_t cap) {
631 acpi_status status = AE_BAD_PARAMETER;
632 if ((value == 0 || value == 1) &&
633 (interface->capability & cap)) {
634 if (interface->get_bool) {
635 /* If possible, only set if the value has changed */
636 bool actual;
637 status = interface->get_bool(&actual, cap, interface);
638 if (ACPI_SUCCESS(status) && actual == (bool)value)
639 return status;
641 if (interface->set_bool)
642 status = interface->set_bool(value == 1, cap, interface);
644 return status;
648 static acpi_status get_u8(uint8_t *value, uint32_t cap) {
649 acpi_status status = AE_BAD_ADDRESS;
650 if (interface->get_u8)
651 status = interface->get_u8(value, cap, interface);
652 return status;
655 static acpi_status set_u8(uint8_t value, uint8_t min, uint8_t max, uint32_t cap) {
656 acpi_status status = AE_BAD_PARAMETER;
657 if ((value >= min && value <= max) &&
658 (interface->capability & cap) ) {
659 if (interface->get_u8) {
660 /* If possible, only set if the value has changed */
661 uint8_t actual;
662 status = interface->get_u8(&actual, cap, interface);
663 if (ACPI_SUCCESS(status) && actual == value)
664 return status;
666 if (interface->set_u8)
667 status = interface->set_u8(value, cap, interface);
669 return status;
672 /* Each _u8 needs a small wrapper that sets the boundary values */
673 static acpi_status set_brightness(uint8_t value)
675 return set_u8(value, 0, ACER_MAX_BRIGHTNESS, ACER_CAP_BRIGHTNESS);
678 static void acpi_commandline_init(void)
680 DEBUG(1, "Commandline args: mailled(%d) wireless(%d) bluetooth(%d) brightness(%d)\n",
681 mailled, wireless, bluetooth, brightness);
684 * These will all fail silently if the value given is invalid, or the
685 * capability isn't available on the given interface
687 set_bool(mailled, ACER_CAP_MAILLED);
688 set_bool(wireless, ACER_CAP_WIRELESS);
689 set_bool(bluetooth, ACER_CAP_BLUETOOTH);
690 set_bool(threeg, ACER_CAP_THREEG);
691 set_brightness((uint8_t)brightness);
695 * Procfs interface
697 static char *read_bool(char *p, uint32_t cap)
699 bool result;
700 acpi_status status = get_bool(&result, cap);
701 if (ACPI_SUCCESS(status))
702 p += sprintf(p, "%d\n", result);
703 else
704 p += sprintf(p, "Read error" );
705 return p;
708 static unsigned long write_bool(const char *buffer, unsigned long count, uint32_t cap)
710 int value;
713 * For now, we are still supporting the "enabled: %i" - this _will_ be deprecated in 0.7
715 if ((sscanf(buffer, " enabled : %i", &value) == 1
716 || sscanf(buffer, "%i", &value) == 1)) {
717 acpi_status status = set_bool(value, cap);
718 if (ACPI_FAILURE(status))
719 return -EINVAL;
720 } else {
721 return -EINVAL;
723 return count;
726 static char *read_u8(char *p, uint32_t cap)
728 uint8_t result;
729 acpi_status status = get_u8(&result, cap);
730 if (ACPI_SUCCESS(status))
731 p += sprintf(p, "%u\n", result);
732 else
733 p += sprintf(p, "Read error" );
734 return p;
737 static unsigned long write_u8(const char *buffer, unsigned long count, uint32_t cap)
739 int value;
740 acpi_status (*set_method)(uint8_t);
742 /* Choose the appropriate set_u8 wrapper here, based on the capability */
743 switch (cap) {
744 case ACER_CAP_BRIGHTNESS:
745 set_method = set_brightness;
746 break;
747 default:
748 return -EINVAL;
751 if (sscanf(buffer, "%i", &value) == 1) {
752 acpi_status status = (*set_method)(value);
753 if (ACPI_FAILURE(status))
754 return -EINVAL;
755 } else {
756 return -EINVAL;
758 return count;
761 static char *read_version(char *p, uint32_t cap)
763 p += sprintf(p, "driver: %s\n", ACER_ACPI_VERSION);
764 p += sprintf(p, "proc_interface: %d\n",
765 PROC_INTERFACE_VERSION);
766 return p;
769 ProcItem proc_items[] = {
770 {"mailled", read_bool, write_bool, ACER_CAP_MAILLED},
771 {"bluetooth", read_bool, write_bool, ACER_CAP_BLUETOOTH},
772 {"wireless", read_bool, write_bool, ACER_CAP_WIRELESS},
773 {"brightness", read_u8, write_u8, ACER_CAP_BRIGHTNESS},
774 {"threeg", read_bool, write_bool, ACER_CAP_THREEG},
775 {"version", read_version, NULL, ACER_CAP_ANY},
776 {NULL}
779 static acpi_status __init add_proc_entries(void)
781 struct proc_dir_entry *proc;
782 ProcItem *item;
784 for (item = proc_items; item->name; ++item) {
786 * Only add the proc file if the current interface actually
787 * supports it
789 if (interface->capability & item->capability) {
790 proc = create_proc_read_entry(item->name,
791 S_IFREG | S_IRUGO | S_IWUSR,
792 acer_proc_dir,
793 (read_proc_t *) dispatch_read,
794 item);
795 if (proc)
796 proc->owner = THIS_MODULE;
797 if (proc && item->write_func)
798 proc->write_proc = (write_proc_t *) dispatch_write;
802 return AE_OK;
805 static acpi_status __exit remove_proc_entries(void)
807 ProcItem *item;
809 for (item = proc_items; item->name; ++item)
810 remove_proc_entry(item->name, acer_proc_dir);
811 return AE_OK;
815 * TODO: make this actually do useful stuff, if we ever see events
817 static void acer_acerkeys_notify(acpi_handle handle, u32 event, void *data)
819 struct acer_hotk *hotk = (struct acer_hotk *)data;
821 if (!hotk)
822 return;
823 printk(MY_ERR "Got an event!! %X", event);
825 return;
828 static int acpi_acerkeys_add(struct acpi_device *device)
830 struct acer_hotk *hotk = NULL;
831 acpi_status status = AE_OK;
833 if (!device)
834 return -EINVAL;
836 hotk =
837 (struct acer_hotk *)kmalloc(sizeof(struct acer_hotk), GFP_KERNEL);
838 if (!hotk)
839 return -ENOMEM;
840 memset(hotk, 0, sizeof(struct acer_hotk));
841 hotk->handle = device->handle;
842 strcpy(acpi_device_name(device), "Acer Laptop ACPI Extras");
843 strcpy(acpi_device_class(device), "hkey");
844 acpi_driver_data(device) = hotk;
845 hotk->device = device;
847 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
848 acer_acerkeys_notify, hotk);
849 if (ACPI_FAILURE(status))
850 printk(MY_ERR "Error installing notify handler.\n");
851 return 0;
854 static int acpi_acerkeys_remove(struct acpi_device *device, int type)
856 acpi_status status = 0;
857 struct acer_hotk *hotk = NULL;
859 if (!device || !acpi_driver_data(device))
860 return -EINVAL;
861 hotk = (struct acer_hotk *)acpi_driver_data(device);
863 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
864 acer_acerkeys_notify);
865 if (ACPI_FAILURE(status))
866 printk(MY_ERR "Error removing notify handler.\n");
867 kfree(hotk);
869 return 0;
872 static struct acpi_driver acpi_acerkeys = {
873 .name = "acer_acpi",
874 .class = "hotkey",
875 .ids = "PNP0C14",
876 .ops = {
877 .add = acpi_acerkeys_add,
878 .remove = acpi_acerkeys_remove,
882 static int __init acer_acpi_init(void)
884 acpi_status status = AE_OK;
886 printk(MY_INFO "Acer Laptop ACPI Extras version %s\n",
887 ACER_ACPI_VERSION);
888 if (acpi_disabled) {
889 printk(MY_ERR "ACPI Disabled, unable to load.\n");
890 return -ENODEV;
894 * Detect which WMI interface we're using.
896 * TODO: This could be more dynamic, and perhaps done in part by the
897 * acpi_bus driver?
899 if (is_valid_acpi_path(AMW0_METHOD)) {
900 DEBUG(0, "Detected ACER AMW0 interface\n");
901 interface = &AMW0_interface;
902 } else if (is_valid_acpi_path(WMID_METHOD)) {
903 DEBUG(0, "Detected ACER WMID interface\n");
904 interface = &WMID_interface;
905 } else {
906 printk(MY_ERR "No or unsupported WMI interface, unable to load.\n");
907 goto error_no_interface;
910 /* Now that we have a known interface, initialize it */
911 if (interface->init) {
912 status = interface->init(interface);
913 if (ACPI_FAILURE(status)) {
914 printk(MY_ERR "Interface initialization failed.\n");
915 goto error_interface_init;
919 /* Create the proc entries */
920 acer_proc_dir = proc_mkdir(PROC_ACER, acpi_root_dir);
921 if (!acer_proc_dir) {
922 printk(MY_ERR "Unable to create /proc entries, aborting.\n");
923 goto error_proc_mkdir;
926 acer_proc_dir->owner = THIS_MODULE;
927 status = add_proc_entries();
928 if (ACPI_FAILURE(status)) {
929 printk(MY_ERR "Unable to create /proc entries, aborting.\n");
930 goto error_proc_add;
934 * Register the hotkeys driver
936 * TODO: Does this do anything? Can we use the bus detection code to
937 * check for the interface or all or part of the method ID path?
939 status = acpi_bus_register_driver(&acpi_acerkeys);
940 if (ACPI_FAILURE(status)) {
941 printk(MY_ERR "Unable to register driver, aborting.\n");
942 goto error_acpi_bus_register;
945 /* Finally, override any initial settings with values from the commandline */
946 acpi_commandline_init();
948 return 0;
950 error_acpi_bus_register:
951 remove_proc_entries();
952 error_proc_add:
953 if (acer_proc_dir)
954 remove_proc_entry(PROC_ACER, acpi_root_dir);
955 error_proc_mkdir:
956 if (interface->free)
957 interface->free(interface);
958 error_interface_init:
959 error_no_interface:
960 return -ENODEV;
963 static void __exit acer_acpi_exit(void)
965 acpi_bus_unregister_driver(&acpi_acerkeys);
967 remove_proc_entries();
969 if (acer_proc_dir)
970 remove_proc_entry(PROC_ACER, acpi_root_dir);
972 if (interface->free)
973 interface->free(interface);
975 printk(MY_INFO "Acer Laptop ACPI Extras unloaded\n");
976 return;
979 module_init(acer_acpi_init);
980 module_exit(acer_acpi_exit);