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"
50 #define PREFIX "ACPI: EC: "
52 /* EC status register */
53 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
54 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
55 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
56 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
59 #define ACPI_EC_COMMAND_READ 0x80
60 #define ACPI_EC_COMMAND_WRITE 0x81
61 #define ACPI_EC_BURST_ENABLE 0x82
62 #define ACPI_EC_BURST_DISABLE 0x83
63 #define ACPI_EC_COMMAND_QUERY 0x84
67 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
68 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
71 #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
72 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
73 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
74 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 100ms max. during EC ops */
77 EC_INTR = 1, /* Output buffer full */
78 EC_POLL, /* Input buffer empty */
81 static int acpi_ec_remove(struct acpi_device *device, int type);
82 static int acpi_ec_start(struct acpi_device *device);
83 static int acpi_ec_stop(struct acpi_device *device, int type);
84 static int acpi_ec_add(struct acpi_device *device);
86 static struct acpi_driver acpi_ec_driver = {
87 .name = ACPI_EC_DRIVER_NAME,
88 .class = ACPI_EC_CLASS,
92 .remove = acpi_ec_remove,
93 .start = acpi_ec_start,
98 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
102 unsigned long gpe_bit;
103 unsigned long command_addr;
104 unsigned long data_addr;
105 unsigned long global_lock;
107 atomic_t query_pending;
108 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
109 wait_queue_head_t wait;
112 /* External interfaces use first EC only, so remember */
113 static struct acpi_device *first_ec;
114 static int acpi_ec_mode = EC_INTR;
116 /* --------------------------------------------------------------------------
117 Transaction Management
118 -------------------------------------------------------------------------- */
120 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
122 return inb(ec->command_addr);
125 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
127 return inb(ec->data_addr);
130 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
132 outb(command, ec->command_addr);
135 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
137 outb(data, ec->data_addr);
140 static int acpi_ec_check_status(struct acpi_ec *ec, u8 event)
142 u8 status = acpi_ec_read_status(ec);
144 case ACPI_EC_EVENT_OBF_1:
145 if (status & ACPI_EC_FLAG_OBF)
148 case ACPI_EC_EVENT_IBF_0:
149 if (!(status & ACPI_EC_FLAG_IBF))
159 static int acpi_ec_wait(struct acpi_ec *ec, u8 event)
161 if (acpi_ec_mode == EC_POLL) {
163 for (i = 0; i < ACPI_EC_UDELAY_COUNT; ++i) {
164 if (acpi_ec_check_status(ec, event))
166 udelay(ACPI_EC_UDELAY);
169 if (wait_event_timeout(ec->wait,
170 acpi_ec_check_status(ec, event),
171 msecs_to_jiffies(ACPI_EC_DELAY)) ||
172 acpi_ec_check_status(ec, event)) {
175 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
176 " status = %d, expect_event = %d\n",
177 acpi_ec_read_status(ec), event);
184 #ifdef ACPI_FUTURE_USAGE
186 * Note: samsung nv5000 doesn't work with ec burst mode.
187 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
189 int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
195 status = acpi_ec_read_status(ec);
196 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
197 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
200 acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE);
201 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
202 tmp = acpi_ec_read_data(ec);
203 if (tmp != 0x90) { /* Burst ACK byte */
208 atomic_set(&ec->leaving_burst, 0);
211 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
215 int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
220 status = acpi_ec_read_status(ec);
221 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){
222 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
225 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
226 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
228 atomic_set(&ec->leaving_burst, 1);
231 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
234 #endif /* ACPI_FUTURE_USAGE */
236 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
237 const u8 *wdata, unsigned wdata_len,
238 u8 *rdata, unsigned rdata_len)
242 acpi_ec_write_cmd(ec, command);
244 for (; wdata_len > 0; wdata_len --) {
245 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
247 printk(KERN_ERR PREFIX "write_cmd timeout, command = %d\n",
251 acpi_ec_write_data(ec, *(wdata++));
255 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
257 printk(KERN_ERR PREFIX "finish-write timeout, command = %d\n",
261 } else if (command == ACPI_EC_COMMAND_QUERY) {
262 atomic_set(&ec->query_pending, 0);
265 for (; rdata_len > 0; rdata_len --) {
266 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
268 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
273 *(rdata++) = acpi_ec_read_data(ec);
279 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
280 const u8 *wdata, unsigned wdata_len,
281 u8 *rdata, unsigned rdata_len)
286 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
290 memset(rdata, 0, rdata_len);
292 if (ec->global_lock) {
293 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
294 if (ACPI_FAILURE(status))
297 mutex_lock(&ec->lock);
299 /* Make sure GPE is enabled before doing transaction */
300 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
302 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
304 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n");
308 status = acpi_ec_transaction_unlocked(ec, command,
313 mutex_unlock(&ec->lock);
316 acpi_release_global_lock(glk);
321 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
326 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
332 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
334 u8 wdata[2] = { address, data };
335 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
340 * Externally callable EC access functions. For now, assume 1 EC only
342 int ec_read(u8 addr, u8 *val)
351 ec = acpi_driver_data(first_ec);
353 err = acpi_ec_read(ec, addr, &temp_data);
362 EXPORT_SYMBOL(ec_read);
364 int ec_write(u8 addr, u8 val)
372 ec = acpi_driver_data(first_ec);
374 err = acpi_ec_write(ec, addr, val);
379 EXPORT_SYMBOL(ec_write);
381 extern int ec_transaction(u8 command,
382 const u8 *wdata, unsigned wdata_len,
383 u8 *rdata, unsigned rdata_len)
390 ec = acpi_driver_data(first_ec);
392 return acpi_ec_transaction(ec, command, wdata,
393 wdata_len, rdata, rdata_len);
396 EXPORT_SYMBOL(ec_transaction);
398 static int acpi_ec_query(struct acpi_ec *ec, u8 *data)
407 * Query the EC to find out which _Qxx method we need to evaluate.
408 * Note that successful completion of the query causes the ACPI_EC_SCI
409 * bit to be cleared (and thus clearing the interrupt source).
412 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
423 /* --------------------------------------------------------------------------
425 -------------------------------------------------------------------------- */
427 static void acpi_ec_gpe_query(void *ec_cxt)
429 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
433 if (!ec || acpi_ec_query(ec, &value))
436 snprintf(object_name, 8, "_Q%2.2X", value);
438 printk(KERN_INFO PREFIX "evaluating %s\n", object_name);
440 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
443 static u32 acpi_ec_gpe_handler(void *data)
445 acpi_status status = AE_OK;
447 struct acpi_ec *ec = (struct acpi_ec *)data;
450 if (acpi_ec_mode == EC_INTR) {
454 value = acpi_ec_read_status(ec);
455 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
456 atomic_set(&ec->query_pending, 1);
457 status = acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
460 return status == AE_OK ?
461 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
464 /* --------------------------------------------------------------------------
465 Address Space Management
466 -------------------------------------------------------------------------- */
469 acpi_ec_space_setup(acpi_handle region_handle,
470 u32 function, void *handler_context, void **return_context)
473 * The EC object is in the handler context and is needed
474 * when calling the acpi_ec_space_handler.
476 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
477 handler_context : NULL;
483 acpi_ec_space_handler(u32 function,
484 acpi_physical_address address,
486 acpi_integer * value,
487 void *handler_context, void *region_context)
490 struct acpi_ec *ec = NULL;
492 acpi_integer f_v = 0;
496 if ((address > 0xFF) || !value || !handler_context)
497 return AE_BAD_PARAMETER;
499 if (bit_width != 8 && acpi_strict) {
500 return AE_BAD_PARAMETER;
503 ec = (struct acpi_ec *)handler_context;
509 result = acpi_ec_read(ec, (u8) address, (u8 *) &temp);
512 result = acpi_ec_write(ec, (u8) address, (u8) temp);
522 if (function == ACPI_READ)
523 f_v |= temp << 8 * i;
524 if (function == ACPI_WRITE)
531 if (function == ACPI_READ) {
532 f_v |= temp << 8 * i;
539 return AE_BAD_PARAMETER;
552 /* --------------------------------------------------------------------------
554 -------------------------------------------------------------------------- */
556 static struct proc_dir_entry *acpi_ec_dir;
558 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
560 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
566 seq_printf(seq, "gpe bit: 0x%02x\n",
568 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
569 (u32) ec->command_addr,
570 (u32) ec->data_addr);
571 seq_printf(seq, "use global lock: %s\n",
572 ec->global_lock ? "yes" : "no");
573 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
579 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
581 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
584 static struct file_operations acpi_ec_info_ops = {
585 .open = acpi_ec_info_open_fs,
588 .release = single_release,
589 .owner = THIS_MODULE,
592 static int acpi_ec_add_fs(struct acpi_device *device)
594 struct proc_dir_entry *entry = NULL;
597 if (!acpi_device_dir(device)) {
598 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
600 if (!acpi_device_dir(device))
604 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
605 acpi_device_dir(device));
609 entry->proc_fops = &acpi_ec_info_ops;
610 entry->data = acpi_driver_data(device);
611 entry->owner = THIS_MODULE;
617 static int acpi_ec_remove_fs(struct acpi_device *device)
620 if (acpi_device_dir(device)) {
621 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
622 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
623 acpi_device_dir(device) = NULL;
629 /* --------------------------------------------------------------------------
631 -------------------------------------------------------------------------- */
633 static int acpi_ec_add(struct acpi_device *device)
636 acpi_status status = AE_OK;
637 struct acpi_ec *ec = NULL;
643 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
646 memset(ec, 0, sizeof(struct acpi_ec));
648 ec->handle = device->handle;
650 mutex_init(&ec->lock);
651 atomic_set(&ec->query_pending, 0);
652 if (acpi_ec_mode == EC_INTR) {
653 atomic_set(&ec->leaving_burst, 1);
654 init_waitqueue_head(&ec->wait);
656 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
657 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
658 acpi_driver_data(device) = ec;
660 /* Use the global lock for all EC transactions? */
661 acpi_evaluate_integer(ec->handle, "_GLK", NULL,
664 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
665 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
667 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
669 &acpi_ec_space_handler);
671 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
672 &acpi_ec_gpe_handler);
677 /* Get GPE bit assignment (EC events). */
678 /* TODO: Add support for _GPE returning a package */
680 acpi_evaluate_integer(ec->handle, "_GPE", NULL,
682 if (ACPI_FAILURE(status)) {
683 ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment"));
688 result = acpi_ec_add_fs(device);
692 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
693 acpi_device_name(device), acpi_device_bid(device),
706 static int acpi_ec_remove(struct acpi_device *device, int type)
708 struct acpi_ec *ec = NULL;
714 ec = acpi_driver_data(device);
716 acpi_ec_remove_fs(device);
724 acpi_ec_io_ports(struct acpi_resource *resource, void *context)
726 struct acpi_ec *ec = (struct acpi_ec *)context;
728 if (resource->type != ACPI_RESOURCE_TYPE_IO) {
733 * The first address region returned is the data port, and
734 * the second address region returned is the status/command
737 if (ec->data_addr == 0) {
738 ec->data_addr = resource->data.io.minimum;
739 } else if (ec->command_addr == 0) {
740 ec->command_addr = resource->data.io.minimum;
742 return AE_CTRL_TERMINATE;
748 static int acpi_ec_start(struct acpi_device *device)
750 acpi_status status = AE_OK;
751 struct acpi_ec *ec = NULL;
757 ec = acpi_driver_data(device);
763 * Get I/O port addresses. Convert to GAS format.
765 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
766 acpi_ec_io_ports, ec);
767 if (ACPI_FAILURE(status) || ec->command_addr == 0) {
768 ACPI_EXCEPTION((AE_INFO, status,
769 "Error getting I/O port addresses"));
773 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
774 ec->gpe_bit, ec->command_addr, ec->data_addr));
777 * Install GPE handler
779 status = acpi_install_gpe_handler(NULL, ec->gpe_bit,
780 ACPI_GPE_EDGE_TRIGGERED,
781 &acpi_ec_gpe_handler, ec);
782 if (ACPI_FAILURE(status)) {
785 acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
786 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
788 status = acpi_install_address_space_handler(ec->handle,
790 &acpi_ec_space_handler,
791 &acpi_ec_space_setup, ec);
792 if (ACPI_FAILURE(status)) {
793 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
794 &acpi_ec_gpe_handler);
801 static int acpi_ec_stop(struct acpi_device *device, int type)
803 acpi_status status = AE_OK;
804 struct acpi_ec *ec = NULL;
810 ec = acpi_driver_data(device);
812 status = acpi_remove_address_space_handler(ec->handle,
814 &acpi_ec_space_handler);
815 if (ACPI_FAILURE(status))
819 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
820 &acpi_ec_gpe_handler);
821 if (ACPI_FAILURE(status))
827 static acpi_status __init
828 acpi_fake_ecdt_callback(acpi_handle handle,
829 u32 Level, void *context, void **retval)
833 mutex_init(&ec_ecdt->lock);
834 if (acpi_ec_mode == EC_INTR) {
835 init_waitqueue_head(&ec_ecdt->wait);
837 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
838 acpi_ec_io_ports, ec_ecdt);
839 if (ACPI_FAILURE(status))
843 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
846 acpi_evaluate_integer(handle, "_GPE", NULL,
848 if (ACPI_FAILURE(status))
850 ec_ecdt->global_lock = TRUE;
851 ec_ecdt->handle = handle;
853 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
854 ec_ecdt->gpe_bit, ec_ecdt->command_addr, ec_ecdt->data_addr));
856 return AE_CTRL_TERMINATE;
860 * Some BIOS (such as some from Gateway laptops) access EC region very early
861 * such as in BAT0._INI or EC._INI before an EC device is found and
862 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
863 * required, but if EC regison is accessed early, it is required.
864 * The routine tries to workaround the BIOS bug by pre-scan EC device
865 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
866 * op region (since _REG isn't invoked yet). The assumption is true for
869 static int __init acpi_ec_fake_ecdt(void)
874 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
876 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
881 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
883 status = acpi_get_devices(ACPI_EC_HID,
884 acpi_fake_ecdt_callback, NULL, NULL);
885 if (ACPI_FAILURE(status)) {
889 ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT"));
897 static int __init acpi_ec_get_real_ecdt(void)
900 struct acpi_table_ecdt *ecdt_ptr;
902 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
903 (struct acpi_table_header **)
905 if (ACPI_FAILURE(status))
908 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
911 * Generate a temporary ec context to use until the namespace is scanned
913 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
916 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
918 mutex_init(&ec_ecdt->lock);
919 if (acpi_ec_mode == EC_INTR) {
920 init_waitqueue_head(&ec_ecdt->wait);
922 ec_ecdt->command_addr = ecdt_ptr->ec_control.address;
923 ec_ecdt->data_addr = ecdt_ptr->ec_data.address;
924 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
925 /* use the GL just to be safe */
926 ec_ecdt->global_lock = TRUE;
927 ec_ecdt->uid = ecdt_ptr->uid;
930 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
931 if (ACPI_FAILURE(status)) {
937 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
944 static int __initdata acpi_fake_ecdt_enabled;
945 int __init acpi_ec_ecdt_probe(void)
950 ret = acpi_ec_get_real_ecdt();
951 /* Try to make a fake ECDT */
952 if (ret && acpi_fake_ecdt_enabled) {
953 ret = acpi_ec_fake_ecdt();
960 * Install GPE handler
962 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit,
963 ACPI_GPE_EDGE_TRIGGERED,
964 &acpi_ec_gpe_handler, ec_ecdt);
965 if (ACPI_FAILURE(status)) {
968 acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
969 acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR);
971 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
973 &acpi_ec_space_handler,
974 &acpi_ec_space_setup,
976 if (ACPI_FAILURE(status)) {
977 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
978 &acpi_ec_gpe_handler);
985 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
992 static int __init acpi_ec_init(void)
1000 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1004 /* Now register the driver for the EC */
1005 result = acpi_bus_register_driver(&acpi_ec_driver);
1007 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1014 subsys_initcall(acpi_ec_init);
1016 /* EC driver currently not unloadable */
1018 static void __exit acpi_ec_exit(void)
1021 acpi_bus_unregister_driver(&acpi_ec_driver);
1023 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1029 static int __init acpi_fake_ecdt_setup(char *str)
1031 acpi_fake_ecdt_enabled = 1;
1035 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
1036 static int __init acpi_ec_set_intr_mode(char *str)
1040 if (!get_option(&str, &intr))
1044 acpi_ec_mode = EC_INTR;
1046 acpi_ec_mode = EC_POLL;
1048 acpi_ec_driver.ops.add = acpi_ec_add;
1049 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling"));
1054 __setup("ec_intr=", acpi_ec_set_intr_mode);