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;
106 struct semaphore sem;
107 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
108 wait_queue_head_t wait;
111 /* External interfaces use first EC only, so remember */
112 static struct acpi_device *first_ec;
113 static int acpi_ec_mode = EC_INTR;
115 /* --------------------------------------------------------------------------
116 Transaction Management
117 -------------------------------------------------------------------------- */
119 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
121 return inb(ec->command_addr);
124 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
126 return inb(ec->data_addr);
129 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
131 outb(command, ec->command_addr);
134 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
136 outb(data, ec->data_addr);
139 static int acpi_ec_check_status(struct acpi_ec *ec, u8 event)
141 u8 status = acpi_ec_read_status(ec);
143 case ACPI_EC_EVENT_OBF_1:
144 if (status & ACPI_EC_FLAG_OBF)
147 case ACPI_EC_EVENT_IBF_0:
148 if (!(status & ACPI_EC_FLAG_IBF))
158 static int acpi_ec_wait(struct acpi_ec *ec, u8 event)
160 if (acpi_ec_mode == EC_POLL) {
162 for (i = 0; i < ACPI_EC_UDELAY_COUNT; ++i) {
163 if (acpi_ec_check_status(ec, event))
165 udelay(ACPI_EC_UDELAY);
168 if (wait_event_timeout(ec->wait,
169 acpi_ec_check_status(ec, event),
170 msecs_to_jiffies(ACPI_EC_DELAY)) ||
171 acpi_ec_check_status(ec, event)) {
174 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
175 " status = %d, expect_event = %d\n",
176 acpi_ec_read_status(ec), event);
183 #ifdef ACPI_FUTURE_USAGE
185 * Note: samsung nv5000 doesn't work with ec burst mode.
186 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
188 int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
194 status = acpi_ec_read_status(ec);
195 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
196 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
199 acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE);
200 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
201 tmp = acpi_ec_read_data(ec);
202 if (tmp != 0x90) { /* Burst ACK byte */
207 atomic_set(&ec->leaving_burst, 0);
210 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
214 int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
219 status = acpi_ec_read_status(ec);
220 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){
221 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
224 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
225 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
227 atomic_set(&ec->leaving_burst, 1);
230 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
233 #endif /* ACPI_FUTURE_USAGE */
235 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
236 const u8 *wdata, unsigned wdata_len,
237 u8 *rdata, unsigned rdata_len)
241 acpi_ec_write_cmd(ec, command);
243 for (; wdata_len > 0; wdata_len --) {
244 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
246 printk(KERN_ERR PREFIX "write_cmd timeout, command = %d\n",
250 acpi_ec_write_data(ec, *(wdata++));
254 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
256 printk(KERN_ERR PREFIX "finish-write timeout, command = %d\n",
262 for (; rdata_len > 0; rdata_len --) {
263 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
265 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
270 *(rdata++) = acpi_ec_read_data(ec);
276 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
277 const u8 *wdata, unsigned wdata_len,
278 u8 *rdata, unsigned rdata_len)
283 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
287 memset(rdata, 0, rdata_len);
289 if (ec->global_lock) {
290 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
291 if (ACPI_FAILURE(status))
296 /* Make sure GPE is enabled before doing transaction */
297 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
299 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
301 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n");
305 status = acpi_ec_transaction_unlocked(ec, command,
313 acpi_release_global_lock(glk);
318 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
323 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
329 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
331 u8 wdata[2] = { address, data };
332 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
337 * Externally callable EC access functions. For now, assume 1 EC only
339 int ec_read(u8 addr, u8 *val)
348 ec = acpi_driver_data(first_ec);
350 err = acpi_ec_read(ec, addr, &temp_data);
359 EXPORT_SYMBOL(ec_read);
361 int ec_write(u8 addr, u8 val)
369 ec = acpi_driver_data(first_ec);
371 err = acpi_ec_write(ec, addr, val);
376 EXPORT_SYMBOL(ec_write);
378 extern int ec_transaction(u8 command,
379 const u8 *wdata, unsigned wdata_len,
380 u8 *rdata, unsigned rdata_len)
387 ec = acpi_driver_data(first_ec);
389 return acpi_ec_transaction(ec, command, wdata,
390 wdata_len, rdata, rdata_len);
393 EXPORT_SYMBOL(ec_transaction);
395 static int acpi_ec_query(struct acpi_ec *ec, u8 *data)
404 * Query the EC to find out which _Qxx method we need to evaluate.
405 * Note that successful completion of the query causes the ACPI_EC_SCI
406 * bit to be cleared (and thus clearing the interrupt source).
409 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
420 /* --------------------------------------------------------------------------
422 -------------------------------------------------------------------------- */
424 static void acpi_ec_gpe_query(void *ec_cxt)
426 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
428 static char object_name[8];
433 value = acpi_ec_read_status(ec);
435 if (!(value & ACPI_EC_FLAG_SCI))
438 if (acpi_ec_query(ec, &value))
441 snprintf(object_name, 8, "_Q%2.2X", value);
443 printk(KERN_INFO PREFIX "evaluating %s\n", object_name);
445 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
448 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
451 static u32 acpi_ec_gpe_handler(void *data)
453 acpi_status status = AE_OK;
455 struct acpi_ec *ec = (struct acpi_ec *)data;
457 acpi_clear_gpe(NULL, ec->gpe_bit, ACPI_ISR);
459 if (acpi_ec_mode == EC_INTR) {
463 value = acpi_ec_read_status(ec);
464 if (value & ACPI_EC_FLAG_SCI) {
465 status = acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
467 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
468 return status == AE_OK ?
469 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
472 /* --------------------------------------------------------------------------
473 Address Space Management
474 -------------------------------------------------------------------------- */
477 acpi_ec_space_setup(acpi_handle region_handle,
478 u32 function, void *handler_context, void **return_context)
481 * The EC object is in the handler context and is needed
482 * when calling the acpi_ec_space_handler.
484 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
485 handler_context : NULL;
491 acpi_ec_space_handler(u32 function,
492 acpi_physical_address address,
494 acpi_integer * value,
495 void *handler_context, void *region_context)
498 struct acpi_ec *ec = NULL;
500 acpi_integer f_v = 0;
504 if ((address > 0xFF) || !value || !handler_context)
505 return AE_BAD_PARAMETER;
507 if (bit_width != 8 && acpi_strict) {
508 return AE_BAD_PARAMETER;
511 ec = (struct acpi_ec *)handler_context;
517 result = acpi_ec_read(ec, (u8) address, (u8 *) &temp);
520 result = acpi_ec_write(ec, (u8) address, (u8) temp);
530 if (function == ACPI_READ)
531 f_v |= temp << 8 * i;
532 if (function == ACPI_WRITE)
539 if (function == ACPI_READ) {
540 f_v |= temp << 8 * i;
547 return AE_BAD_PARAMETER;
560 /* --------------------------------------------------------------------------
562 -------------------------------------------------------------------------- */
564 static struct proc_dir_entry *acpi_ec_dir;
566 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
568 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
574 seq_printf(seq, "gpe bit: 0x%02x\n",
576 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
577 (u32) ec->command_addr,
578 (u32) ec->data_addr);
579 seq_printf(seq, "use global lock: %s\n",
580 ec->global_lock ? "yes" : "no");
581 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
587 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
589 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
592 static struct file_operations acpi_ec_info_ops = {
593 .open = acpi_ec_info_open_fs,
596 .release = single_release,
597 .owner = THIS_MODULE,
600 static int acpi_ec_add_fs(struct acpi_device *device)
602 struct proc_dir_entry *entry = NULL;
605 if (!acpi_device_dir(device)) {
606 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
608 if (!acpi_device_dir(device))
612 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
613 acpi_device_dir(device));
617 entry->proc_fops = &acpi_ec_info_ops;
618 entry->data = acpi_driver_data(device);
619 entry->owner = THIS_MODULE;
625 static int acpi_ec_remove_fs(struct acpi_device *device)
628 if (acpi_device_dir(device)) {
629 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
630 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
631 acpi_device_dir(device) = NULL;
637 /* --------------------------------------------------------------------------
639 -------------------------------------------------------------------------- */
641 static int acpi_ec_add(struct acpi_device *device)
644 acpi_status status = AE_OK;
645 struct acpi_ec *ec = NULL;
651 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
654 memset(ec, 0, sizeof(struct acpi_ec));
656 ec->handle = device->handle;
658 init_MUTEX(&ec->sem);
659 if (acpi_ec_mode == EC_INTR) {
660 atomic_set(&ec->leaving_burst, 1);
661 init_waitqueue_head(&ec->wait);
663 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
664 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
665 acpi_driver_data(device) = ec;
667 /* Use the global lock for all EC transactions? */
668 acpi_evaluate_integer(ec->handle, "_GLK", NULL,
671 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
672 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
674 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
676 &acpi_ec_space_handler);
678 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
679 &acpi_ec_gpe_handler);
684 /* Get GPE bit assignment (EC events). */
685 /* TODO: Add support for _GPE returning a package */
687 acpi_evaluate_integer(ec->handle, "_GPE", NULL,
689 if (ACPI_FAILURE(status)) {
690 ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment"));
695 result = acpi_ec_add_fs(device);
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
700 acpi_device_name(device), acpi_device_bid(device),
713 static int acpi_ec_remove(struct acpi_device *device, int type)
715 struct acpi_ec *ec = NULL;
721 ec = acpi_driver_data(device);
723 acpi_ec_remove_fs(device);
731 acpi_ec_io_ports(struct acpi_resource *resource, void *context)
733 struct acpi_ec *ec = (struct acpi_ec *)context;
735 if (resource->type != ACPI_RESOURCE_TYPE_IO) {
740 * The first address region returned is the data port, and
741 * the second address region returned is the status/command
744 if (ec->data_addr == 0) {
745 ec->data_addr = resource->data.io.minimum;
746 } else if (ec->command_addr == 0) {
747 ec->command_addr = resource->data.io.minimum;
749 return AE_CTRL_TERMINATE;
755 static int acpi_ec_start(struct acpi_device *device)
757 acpi_status status = AE_OK;
758 struct acpi_ec *ec = NULL;
764 ec = acpi_driver_data(device);
770 * Get I/O port addresses. Convert to GAS format.
772 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
773 acpi_ec_io_ports, ec);
774 if (ACPI_FAILURE(status) || ec->command_addr == 0) {
775 ACPI_EXCEPTION((AE_INFO, status,
776 "Error getting I/O port addresses"));
780 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
781 ec->gpe_bit, ec->command_addr, ec->data_addr));
784 * Install GPE handler
786 status = acpi_install_gpe_handler(NULL, ec->gpe_bit,
787 ACPI_GPE_EDGE_TRIGGERED,
788 &acpi_ec_gpe_handler, ec);
789 if (ACPI_FAILURE(status)) {
792 acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
793 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
795 status = acpi_install_address_space_handler(ec->handle,
797 &acpi_ec_space_handler,
798 &acpi_ec_space_setup, ec);
799 if (ACPI_FAILURE(status)) {
800 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
801 &acpi_ec_gpe_handler);
808 static int acpi_ec_stop(struct acpi_device *device, int type)
810 acpi_status status = AE_OK;
811 struct acpi_ec *ec = NULL;
817 ec = acpi_driver_data(device);
819 status = acpi_remove_address_space_handler(ec->handle,
821 &acpi_ec_space_handler);
822 if (ACPI_FAILURE(status))
826 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
827 &acpi_ec_gpe_handler);
828 if (ACPI_FAILURE(status))
834 static acpi_status __init
835 acpi_fake_ecdt_callback(acpi_handle handle,
836 u32 Level, void *context, void **retval)
840 init_MUTEX(&ec_ecdt->sem);
841 if (acpi_ec_mode == EC_INTR) {
842 init_waitqueue_head(&ec_ecdt->wait);
844 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
845 acpi_ec_io_ports, ec_ecdt);
846 if (ACPI_FAILURE(status))
850 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
853 acpi_evaluate_integer(handle, "_GPE", NULL,
855 if (ACPI_FAILURE(status))
857 ec_ecdt->global_lock = TRUE;
858 ec_ecdt->handle = handle;
860 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
861 ec_ecdt->gpe_bit, ec_ecdt->command_addr, ec_ecdt->data_addr));
863 return AE_CTRL_TERMINATE;
867 * Some BIOS (such as some from Gateway laptops) access EC region very early
868 * such as in BAT0._INI or EC._INI before an EC device is found and
869 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
870 * required, but if EC regison is accessed early, it is required.
871 * The routine tries to workaround the BIOS bug by pre-scan EC device
872 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
873 * op region (since _REG isn't invoked yet). The assumption is true for
876 static int __init acpi_ec_fake_ecdt(void)
881 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
883 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
888 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
890 status = acpi_get_devices(ACPI_EC_HID,
891 acpi_fake_ecdt_callback, NULL, NULL);
892 if (ACPI_FAILURE(status)) {
896 ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT"));
904 static int __init acpi_ec_get_real_ecdt(void)
907 struct acpi_table_ecdt *ecdt_ptr;
909 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
910 (struct acpi_table_header **)
912 if (ACPI_FAILURE(status))
915 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
918 * Generate a temporary ec context to use until the namespace is scanned
920 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
923 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
925 init_MUTEX(&ec_ecdt->sem);
926 if (acpi_ec_mode == EC_INTR) {
927 init_waitqueue_head(&ec_ecdt->wait);
929 ec_ecdt->command_addr = ecdt_ptr->ec_control.address;
930 ec_ecdt->data_addr = ecdt_ptr->ec_data.address;
931 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
932 /* use the GL just to be safe */
933 ec_ecdt->global_lock = TRUE;
934 ec_ecdt->uid = ecdt_ptr->uid;
937 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
938 if (ACPI_FAILURE(status)) {
944 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
951 static int __initdata acpi_fake_ecdt_enabled;
952 int __init acpi_ec_ecdt_probe(void)
957 ret = acpi_ec_get_real_ecdt();
958 /* Try to make a fake ECDT */
959 if (ret && acpi_fake_ecdt_enabled) {
960 ret = acpi_ec_fake_ecdt();
967 * Install GPE handler
969 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit,
970 ACPI_GPE_EDGE_TRIGGERED,
971 &acpi_ec_gpe_handler, ec_ecdt);
972 if (ACPI_FAILURE(status)) {
975 acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
976 acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR);
978 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
980 &acpi_ec_space_handler,
981 &acpi_ec_space_setup,
983 if (ACPI_FAILURE(status)) {
984 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
985 &acpi_ec_gpe_handler);
992 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
999 static int __init acpi_ec_init(void)
1007 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1011 /* Now register the driver for the EC */
1012 result = acpi_bus_register_driver(&acpi_ec_driver);
1014 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1021 subsys_initcall(acpi_ec_init);
1023 /* EC driver currently not unloadable */
1025 static void __exit acpi_ec_exit(void)
1028 acpi_bus_unregister_driver(&acpi_ec_driver);
1030 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1036 static int __init acpi_fake_ecdt_setup(char *str)
1038 acpi_fake_ecdt_enabled = 1;
1042 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
1043 static int __init acpi_ec_set_intr_mode(char *str)
1047 if (!get_option(&str, &intr))
1051 acpi_ec_mode = EC_INTR;
1053 acpi_ec_mode = EC_POLL;
1055 acpi_ec_driver.ops.add = acpi_ec_add;
1056 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling"));
1061 __setup("ec_intr=", acpi_ec_set_intr_mode);