2 * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/delay.h>
32 #include <linux/proc_fs.h>
33 #include <linux/seq_file.h>
34 #include <linux/interrupt.h>
36 #include <acpi/acpi_bus.h>
37 #include <acpi/acpi_drivers.h>
38 #include <acpi/actypes.h>
40 #define _COMPONENT ACPI_EC_COMPONENT
41 ACPI_MODULE_NAME("acpi_ec")
42 #define ACPI_EC_COMPONENT 0x00100000
43 #define ACPI_EC_CLASS "embedded_controller"
44 #define ACPI_EC_HID "PNP0C09"
45 #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
47 #define ACPI_EC_FILE_INFO "info"
49 /* EC status register */
50 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
52 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
53 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
56 #define ACPI_EC_COMMAND_READ 0x80
57 #define ACPI_EC_COMMAND_WRITE 0x81
58 #define ACPI_EC_BURST_ENABLE 0x82
59 #define ACPI_EC_BURST_DISABLE 0x83
60 #define ACPI_EC_COMMAND_QUERY 0x84
64 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
65 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
68 #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
69 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
70 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
71 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 100ms max. during EC ops */
74 EC_INTR = 1, /* Output buffer full */
75 EC_POLL, /* Input buffer empty */
78 static int acpi_ec_remove(struct acpi_device *device, int type);
79 static int acpi_ec_start(struct acpi_device *device);
80 static int acpi_ec_stop(struct acpi_device *device, int type);
81 static int acpi_ec_add(struct acpi_device *device);
83 static struct acpi_driver acpi_ec_driver = {
84 .name = ACPI_EC_DRIVER_NAME,
85 .class = ACPI_EC_CLASS,
89 .remove = acpi_ec_remove,
90 .start = acpi_ec_start,
95 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
99 unsigned long gpe_bit;
100 unsigned long command_addr;
101 unsigned long data_addr;
102 unsigned long global_lock;
103 struct semaphore sem;
104 unsigned int expect_event;
105 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
106 wait_queue_head_t wait;
109 /* External interfaces use first EC only, so remember */
110 static struct acpi_device *first_ec;
111 static int acpi_ec_mode = EC_INTR;
113 /* --------------------------------------------------------------------------
114 Transaction Management
115 -------------------------------------------------------------------------- */
117 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
119 return inb(ec->command_addr);
122 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
124 return inb(ec->data_addr);
127 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
129 outb(command, ec->command_addr);
132 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
134 outb(data, ec->data_addr);
137 static int acpi_ec_check_status(struct acpi_ec *ec, u8 event)
139 u8 status = acpi_ec_read_status(ec);
141 case ACPI_EC_EVENT_OBF_1:
142 if (status & ACPI_EC_FLAG_OBF)
145 case ACPI_EC_EVENT_IBF_0:
146 if (!(status & ACPI_EC_FLAG_IBF))
156 static int acpi_ec_wait(struct acpi_ec *ec, u8 event)
158 int i = (acpi_ec_mode == EC_POLL) ? ACPI_EC_UDELAY_COUNT : 0;
161 ec->expect_event = event;
162 if (acpi_ec_check_status(ec, event)) {
163 ec->expect_event = 0;
168 if (acpi_ec_mode == EC_POLL) {
169 udelay(ACPI_EC_UDELAY);
171 time_left = wait_event_timeout(ec->wait,
173 msecs_to_jiffies(ACPI_EC_DELAY));
175 ec->expect_event = 0;
179 if (acpi_ec_check_status(ec, event)) {
180 ec->expect_event = 0;
185 ec->expect_event = 0;
190 #ifdef ACPI_FUTURE_USAGE
192 * Note: samsung nv5000 doesn't work with ec burst mode.
193 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
195 int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
201 status = acpi_ec_read_status(ec);
202 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
203 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
206 acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE);
207 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
208 tmp = acpi_ec_read_data(ec);
209 if (tmp != 0x90) { /* Burst ACK byte */
214 atomic_set(&ec->leaving_burst, 0);
217 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
221 int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
226 status = acpi_ec_read_status(ec);
227 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){
228 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
231 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
232 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
234 atomic_set(&ec->leaving_burst, 1);
237 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
240 #endif /* ACPI_FUTURE_USAGE */
242 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
243 const u8 *wdata, unsigned wdata_len,
244 u8 *rdata, unsigned rdata_len)
248 acpi_ec_write_cmd(ec, command);
250 for (; wdata_len > 0; wdata_len --) {
251 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
254 acpi_ec_write_data(ec, *(wdata++));
258 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
263 for (; rdata_len > 0; rdata_len --) {
264 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
268 *(rdata++) = acpi_ec_read_data(ec);
274 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
275 const u8 *wdata, unsigned wdata_len,
276 u8 *rdata, unsigned rdata_len)
281 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
285 memset(rdata, 0, rdata_len);
287 if (ec->global_lock) {
288 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
289 if (ACPI_FAILURE(status))
294 /* Make sure GPE is enabled before doing transaction */
295 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
297 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
299 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n");
303 status = acpi_ec_transaction_unlocked(ec, command,
311 acpi_release_global_lock(glk);
316 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
321 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
327 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
329 u8 wdata[2] = { address, data };
330 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
335 * Externally callable EC access functions. For now, assume 1 EC only
337 int ec_read(u8 addr, u8 *val)
346 ec = acpi_driver_data(first_ec);
348 err = acpi_ec_read(ec, addr, &temp_data);
357 EXPORT_SYMBOL(ec_read);
359 int ec_write(u8 addr, u8 val)
367 ec = acpi_driver_data(first_ec);
369 err = acpi_ec_write(ec, addr, val);
374 EXPORT_SYMBOL(ec_write);
376 extern int ec_transaction(u8 command,
377 const u8 *wdata, unsigned wdata_len,
378 u8 *rdata, unsigned rdata_len)
385 ec = acpi_driver_data(first_ec);
387 return acpi_ec_transaction(ec, command, wdata,
388 wdata_len, rdata, rdata_len);
391 EXPORT_SYMBOL(ec_transaction);
393 static int acpi_ec_query(struct acpi_ec *ec, u8 *data)
402 * Query the EC to find out which _Qxx method we need to evaluate.
403 * Note that successful completion of the query causes the ACPI_EC_SCI
404 * bit to be cleared (and thus clearing the interrupt source).
407 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
418 /* --------------------------------------------------------------------------
420 -------------------------------------------------------------------------- */
422 struct acpi_ec_query_data {
427 static void acpi_ec_gpe_query(void *ec_cxt)
429 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
431 static char object_name[8];
436 value = acpi_ec_read_status(ec);
438 if (!(value & ACPI_EC_FLAG_SCI))
441 if (acpi_ec_query(ec, &value))
444 snprintf(object_name, 8, "_Q%2.2X", value);
446 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name));
448 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
451 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
454 static u32 acpi_ec_gpe_handler(void *data)
456 acpi_status status = AE_OK;
458 struct acpi_ec *ec = (struct acpi_ec *)data;
460 acpi_clear_gpe(NULL, ec->gpe_bit, ACPI_ISR);
462 if (acpi_ec_mode == EC_INTR) {
463 if (acpi_ec_check_status(ec, ec->expect_event)) {
464 ec->expect_event = 0;
469 value = acpi_ec_read_status(ec);
470 if (value & ACPI_EC_FLAG_SCI) {
471 status = acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
472 return status == AE_OK ?
473 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
475 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
476 return status == AE_OK ?
477 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
480 /* --------------------------------------------------------------------------
481 Address Space Management
482 -------------------------------------------------------------------------- */
485 acpi_ec_space_setup(acpi_handle region_handle,
486 u32 function, void *handler_context, void **return_context)
489 * The EC object is in the handler context and is needed
490 * when calling the acpi_ec_space_handler.
492 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
493 handler_context : NULL;
499 acpi_ec_space_handler(u32 function,
500 acpi_physical_address address,
502 acpi_integer * value,
503 void *handler_context, void *region_context)
506 struct acpi_ec *ec = NULL;
508 acpi_integer f_v = 0;
512 if ((address > 0xFF) || !value || !handler_context)
513 return AE_BAD_PARAMETER;
515 if (bit_width != 8 && acpi_strict) {
516 return AE_BAD_PARAMETER;
519 ec = (struct acpi_ec *)handler_context;
525 result = acpi_ec_read(ec, (u8) address, (u8 *) &temp);
528 result = acpi_ec_write(ec, (u8) address, (u8) temp);
538 if (function == ACPI_READ)
539 f_v |= temp << 8 * i;
540 if (function == ACPI_WRITE)
547 if (function == ACPI_READ) {
548 f_v |= temp << 8 * i;
555 return AE_BAD_PARAMETER;
568 /* --------------------------------------------------------------------------
570 -------------------------------------------------------------------------- */
572 static struct proc_dir_entry *acpi_ec_dir;
574 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
576 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
582 seq_printf(seq, "gpe bit: 0x%02x\n",
584 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
585 (u32) ec->command_addr,
586 (u32) ec->data_addr);
587 seq_printf(seq, "use global lock: %s\n",
588 ec->global_lock ? "yes" : "no");
589 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
595 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
597 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
600 static struct file_operations acpi_ec_info_ops = {
601 .open = acpi_ec_info_open_fs,
604 .release = single_release,
605 .owner = THIS_MODULE,
608 static int acpi_ec_add_fs(struct acpi_device *device)
610 struct proc_dir_entry *entry = NULL;
613 if (!acpi_device_dir(device)) {
614 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
616 if (!acpi_device_dir(device))
620 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
621 acpi_device_dir(device));
625 entry->proc_fops = &acpi_ec_info_ops;
626 entry->data = acpi_driver_data(device);
627 entry->owner = THIS_MODULE;
633 static int acpi_ec_remove_fs(struct acpi_device *device)
636 if (acpi_device_dir(device)) {
637 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
638 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
639 acpi_device_dir(device) = NULL;
645 /* --------------------------------------------------------------------------
647 -------------------------------------------------------------------------- */
649 static int acpi_ec_add(struct acpi_device *device)
652 acpi_status status = AE_OK;
653 struct acpi_ec *ec = NULL;
659 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
662 memset(ec, 0, sizeof(struct acpi_ec));
664 ec->handle = device->handle;
666 init_MUTEX(&ec->sem);
667 if (acpi_ec_mode == EC_INTR) {
668 atomic_set(&ec->leaving_burst, 1);
669 init_waitqueue_head(&ec->wait);
671 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
672 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
673 acpi_driver_data(device) = ec;
675 /* Use the global lock for all EC transactions? */
676 acpi_evaluate_integer(ec->handle, "_GLK", NULL,
679 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
680 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
682 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
684 &acpi_ec_space_handler);
686 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
687 &acpi_ec_gpe_handler);
692 /* Get GPE bit assignment (EC events). */
693 /* TODO: Add support for _GPE returning a package */
695 acpi_evaluate_integer(ec->handle, "_GPE", NULL,
697 if (ACPI_FAILURE(status)) {
698 ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment"));
703 result = acpi_ec_add_fs(device);
707 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
708 acpi_device_name(device), acpi_device_bid(device),
721 static int acpi_ec_remove(struct acpi_device *device, int type)
723 struct acpi_ec *ec = NULL;
729 ec = acpi_driver_data(device);
731 acpi_ec_remove_fs(device);
739 acpi_ec_io_ports(struct acpi_resource *resource, void *context)
741 struct acpi_ec *ec = (struct acpi_ec *)context;
743 if (resource->type != ACPI_RESOURCE_TYPE_IO) {
748 * The first address region returned is the data port, and
749 * the second address region returned is the status/command
752 if (ec->data_addr == 0) {
753 ec->data_addr = resource->data.io.minimum;
754 } else if (ec->command_addr == 0) {
755 ec->command_addr = resource->data.io.minimum;
757 return AE_CTRL_TERMINATE;
763 static int acpi_ec_start(struct acpi_device *device)
765 acpi_status status = AE_OK;
766 struct acpi_ec *ec = NULL;
772 ec = acpi_driver_data(device);
778 * Get I/O port addresses. Convert to GAS format.
780 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
781 acpi_ec_io_ports, ec);
782 if (ACPI_FAILURE(status) || ec->command_addr == 0) {
783 ACPI_EXCEPTION((AE_INFO, status,
784 "Error getting I/O port addresses"));
788 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
789 ec->gpe_bit, ec->command_addr, ec->data_addr));
792 * Install GPE handler
794 status = acpi_install_gpe_handler(NULL, ec->gpe_bit,
795 ACPI_GPE_EDGE_TRIGGERED,
796 &acpi_ec_gpe_handler, ec);
797 if (ACPI_FAILURE(status)) {
800 acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
801 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
803 status = acpi_install_address_space_handler(ec->handle,
805 &acpi_ec_space_handler,
806 &acpi_ec_space_setup, ec);
807 if (ACPI_FAILURE(status)) {
808 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
809 &acpi_ec_gpe_handler);
816 static int acpi_ec_stop(struct acpi_device *device, int type)
818 acpi_status status = AE_OK;
819 struct acpi_ec *ec = NULL;
825 ec = acpi_driver_data(device);
827 status = acpi_remove_address_space_handler(ec->handle,
829 &acpi_ec_space_handler);
830 if (ACPI_FAILURE(status))
834 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
835 &acpi_ec_gpe_handler);
836 if (ACPI_FAILURE(status))
842 static acpi_status __init
843 acpi_fake_ecdt_callback(acpi_handle handle,
844 u32 Level, void *context, void **retval)
848 init_MUTEX(&ec_ecdt->sem);
849 if (acpi_ec_mode == EC_INTR) {
850 init_waitqueue_head(&ec_ecdt->wait);
852 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
853 acpi_ec_io_ports, ec_ecdt);
854 if (ACPI_FAILURE(status))
858 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
861 acpi_evaluate_integer(handle, "_GPE", NULL,
863 if (ACPI_FAILURE(status))
865 ec_ecdt->global_lock = TRUE;
866 ec_ecdt->handle = handle;
868 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
869 ec_ecdt->gpe_bit, ec_ecdt->command_addr, ec_ecdt->data_addr));
871 return AE_CTRL_TERMINATE;
875 * Some BIOS (such as some from Gateway laptops) access EC region very early
876 * such as in BAT0._INI or EC._INI before an EC device is found and
877 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
878 * required, but if EC regison is accessed early, it is required.
879 * The routine tries to workaround the BIOS bug by pre-scan EC device
880 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
881 * op region (since _REG isn't invoked yet). The assumption is true for
884 static int __init acpi_ec_fake_ecdt(void)
889 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
891 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
896 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
898 status = acpi_get_devices(ACPI_EC_HID,
899 acpi_fake_ecdt_callback, NULL, NULL);
900 if (ACPI_FAILURE(status)) {
904 ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT"));
912 static int __init acpi_ec_get_real_ecdt(void)
915 struct acpi_table_ecdt *ecdt_ptr;
917 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
918 (struct acpi_table_header **)
920 if (ACPI_FAILURE(status))
923 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
926 * Generate a temporary ec context to use until the namespace is scanned
928 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
931 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
933 init_MUTEX(&ec_ecdt->sem);
934 if (acpi_ec_mode == EC_INTR) {
935 init_waitqueue_head(&ec_ecdt->wait);
937 ec_ecdt->command_addr = ecdt_ptr->ec_control.address;
938 ec_ecdt->data_addr = ecdt_ptr->ec_data.address;
939 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
940 /* use the GL just to be safe */
941 ec_ecdt->global_lock = TRUE;
942 ec_ecdt->uid = ecdt_ptr->uid;
945 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
946 if (ACPI_FAILURE(status)) {
952 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
959 static int __initdata acpi_fake_ecdt_enabled;
960 int __init acpi_ec_ecdt_probe(void)
965 ret = acpi_ec_get_real_ecdt();
966 /* Try to make a fake ECDT */
967 if (ret && acpi_fake_ecdt_enabled) {
968 ret = acpi_ec_fake_ecdt();
975 * Install GPE handler
977 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit,
978 ACPI_GPE_EDGE_TRIGGERED,
979 &acpi_ec_gpe_handler, ec_ecdt);
980 if (ACPI_FAILURE(status)) {
983 acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
984 acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR);
986 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
988 &acpi_ec_space_handler,
989 &acpi_ec_space_setup,
991 if (ACPI_FAILURE(status)) {
992 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
993 &acpi_ec_gpe_handler);
1000 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
1007 static int __init acpi_ec_init(void)
1015 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1019 /* Now register the driver for the EC */
1020 result = acpi_bus_register_driver(&acpi_ec_driver);
1022 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1029 subsys_initcall(acpi_ec_init);
1031 /* EC driver currently not unloadable */
1033 static void __exit acpi_ec_exit(void)
1036 acpi_bus_unregister_driver(&acpi_ec_driver);
1038 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1044 static int __init acpi_fake_ecdt_setup(char *str)
1046 acpi_fake_ecdt_enabled = 1;
1050 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
1051 static int __init acpi_ec_set_intr_mode(char *str)
1055 if (!get_option(&str, &intr))
1059 acpi_ec_mode = EC_INTR;
1061 acpi_ec_mode = EC_POLL;
1063 acpi_ec_driver.ops.add = acpi_ec_add;
1064 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling"));
1069 __setup("ec_intr=", acpi_ec_set_intr_mode);