2 * ec.c - ACPI Embedded Controller Driver (v2.0)
4 * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
5 * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
6 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
7 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
8 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/types.h>
33 #include <linux/delay.h>
34 #include <linux/proc_fs.h>
35 #include <linux/seq_file.h>
36 #include <linux/interrupt.h>
37 #include <linux/list.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/acpi_drivers.h>
41 #include <acpi/actypes.h>
43 #define ACPI_EC_CLASS "embedded_controller"
44 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
45 #define ACPI_EC_FILE_INFO "info"
48 #define PREFIX "ACPI: EC: "
50 /* EC status register */
51 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
52 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
53 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
54 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
58 ACPI_EC_COMMAND_READ = 0x80,
59 ACPI_EC_COMMAND_WRITE = 0x81,
60 ACPI_EC_BURST_ENABLE = 0x82,
61 ACPI_EC_BURST_DISABLE = 0x83,
62 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 */
75 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
76 EC_FLAGS_QUERY_PENDING, /* Query is pending */
77 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
78 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */
79 EC_FLAGS_ADDRESS, /* Address is being written */
82 static int acpi_ec_remove(struct acpi_device *device, int type);
83 static int acpi_ec_start(struct acpi_device *device);
84 static int acpi_ec_stop(struct acpi_device *device, int type);
85 static int acpi_ec_add(struct acpi_device *device);
87 static const struct acpi_device_id ec_device_ids[] = {
92 static struct acpi_driver acpi_ec_driver = {
94 .class = ACPI_EC_CLASS,
98 .remove = acpi_ec_remove,
99 .start = acpi_ec_start,
100 .stop = acpi_ec_stop,
104 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
105 /* External interfaces use first EC only, so remember */
106 typedef int (*acpi_ec_query_func) (void *data);
108 struct acpi_ec_query_handler {
109 struct list_head node;
110 acpi_ec_query_func func;
116 static struct acpi_ec {
119 unsigned long command_addr;
120 unsigned long data_addr;
121 unsigned long global_lock;
124 wait_queue_head_t wait;
125 struct list_head list;
126 u8 handlers_installed;
127 } *boot_ec, *first_ec;
129 /* --------------------------------------------------------------------------
130 Transaction Management
131 -------------------------------------------------------------------------- */
133 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
135 return inb(ec->command_addr);
138 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
140 return inb(ec->data_addr);
143 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
145 outb(command, ec->command_addr);
148 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
150 outb(data, ec->data_addr);
153 static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
155 if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags))
157 if (event == ACPI_EC_EVENT_OBF_1) {
158 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
160 } else if (event == ACPI_EC_EVENT_IBF_0) {
161 if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
168 static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
171 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
172 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
174 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
175 likely(!force_poll)) {
176 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
177 msecs_to_jiffies(ACPI_EC_DELAY)))
179 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
180 if (acpi_ec_check_status(ec, event)) {
181 if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
182 /* miss address GPE, don't expect it anymore */
183 printk(KERN_INFO PREFIX "missing address confirmation,"
184 "don't expect it any longer.\n");
185 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
187 /* missing GPEs, switch back to poll mode */
188 printk(KERN_INFO PREFIX "missing confirmations,"
189 "switch off interrupt mode.\n");
190 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
195 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
196 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
197 while (time_before(jiffies, delay)) {
198 if (acpi_ec_check_status(ec, event))
202 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
203 " status = %d, expect_event = %d\n",
204 acpi_ec_read_status(ec), event);
207 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
211 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
212 const u8 * wdata, unsigned wdata_len,
213 u8 * rdata, unsigned rdata_len,
217 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
218 acpi_ec_write_cmd(ec, command);
220 for (; wdata_len > 0; --wdata_len) {
221 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
223 printk(KERN_ERR PREFIX
224 "write_cmd timeout, command = %d\n", command);
227 /* mark the address byte written to EC */
228 if (rdata_len + wdata_len > 1)
229 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
230 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
231 acpi_ec_write_data(ec, *(wdata++));
235 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
237 printk(KERN_ERR PREFIX
238 "finish-write timeout, command = %d\n", command);
241 } else if (command == ACPI_EC_COMMAND_QUERY)
242 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
244 for (; rdata_len > 0; --rdata_len) {
245 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
247 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
251 /* Don't expect GPE after last read */
253 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
254 *(rdata++) = acpi_ec_read_data(ec);
260 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
261 const u8 * wdata, unsigned wdata_len,
262 u8 * rdata, unsigned rdata_len,
268 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
272 memset(rdata, 0, rdata_len);
274 mutex_lock(&ec->lock);
275 if (ec->global_lock) {
276 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
277 if (ACPI_FAILURE(status)) {
278 mutex_unlock(&ec->lock);
283 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
285 printk(KERN_ERR PREFIX
286 "input buffer is not empty, aborting transaction\n");
290 status = acpi_ec_transaction_unlocked(ec, command,
298 acpi_release_global_lock(glk);
299 mutex_unlock(&ec->lock);
305 * Note: samsung nv5000 doesn't work with ec burst mode.
306 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
308 int acpi_ec_burst_enable(struct acpi_ec *ec)
311 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
314 int acpi_ec_burst_disable(struct acpi_ec *ec)
316 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
319 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
324 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
325 &address, 1, &d, 1, 0);
330 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
332 u8 wdata[2] = { address, data };
333 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
334 wdata, 2, NULL, 0, 0);
338 * Externally callable EC access functions. For now, assume 1 EC only
340 int ec_burst_enable(void)
344 return acpi_ec_burst_enable(first_ec);
347 EXPORT_SYMBOL(ec_burst_enable);
349 int ec_burst_disable(void)
353 return acpi_ec_burst_disable(first_ec);
356 EXPORT_SYMBOL(ec_burst_disable);
358 int ec_read(u8 addr, u8 * val)
366 err = acpi_ec_read(first_ec, addr, &temp_data);
375 EXPORT_SYMBOL(ec_read);
377 int ec_write(u8 addr, u8 val)
384 err = acpi_ec_write(first_ec, addr, val);
389 EXPORT_SYMBOL(ec_write);
391 int ec_transaction(u8 command,
392 const u8 * wdata, unsigned wdata_len,
393 u8 * rdata, unsigned rdata_len,
399 return acpi_ec_transaction(first_ec, command, wdata,
400 wdata_len, rdata, rdata_len,
404 EXPORT_SYMBOL(ec_transaction);
406 static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
415 * Query the EC to find out which _Qxx method we need to evaluate.
416 * Note that successful completion of the query causes the ACPI_EC_SCI
417 * bit to be cleared (and thus clearing the interrupt source).
420 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
431 /* --------------------------------------------------------------------------
433 -------------------------------------------------------------------------- */
434 int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
435 acpi_handle handle, acpi_ec_query_func func,
438 struct acpi_ec_query_handler *handler =
439 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
443 handler->query_bit = query_bit;
444 handler->handle = handle;
445 handler->func = func;
446 handler->data = data;
447 mutex_lock(&ec->lock);
448 list_add(&handler->node, &ec->list);
449 mutex_unlock(&ec->lock);
453 EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
455 void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
457 struct acpi_ec_query_handler *handler, *tmp;
458 mutex_lock(&ec->lock);
459 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
460 if (query_bit == handler->query_bit) {
461 list_del(&handler->node);
465 mutex_unlock(&ec->lock);
468 EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
470 static void acpi_ec_gpe_query(void *ec_cxt)
472 struct acpi_ec *ec = ec_cxt;
474 struct acpi_ec_query_handler *handler, copy;
476 if (!ec || acpi_ec_query(ec, &value))
478 mutex_lock(&ec->lock);
479 list_for_each_entry(handler, &ec->list, node) {
480 if (value == handler->query_bit) {
481 /* have custom handler for this bit */
482 memcpy(©, handler, sizeof(copy));
483 mutex_unlock(&ec->lock);
485 copy.func(copy.data);
486 } else if (copy.handle) {
487 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
492 mutex_unlock(&ec->lock);
495 static u32 acpi_ec_gpe_handler(void *data)
497 acpi_status status = AE_OK;
498 struct acpi_ec *ec = data;
500 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
501 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
504 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) {
505 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
506 status = acpi_os_execute(OSL_EC_BURST_HANDLER,
507 acpi_ec_gpe_query, ec);
508 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
509 /* this is non-query, must be confirmation */
510 printk(KERN_INFO PREFIX "non-query interrupt received,"
511 " switching to interrupt mode\n");
512 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
515 return ACPI_SUCCESS(status) ?
516 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
519 /* --------------------------------------------------------------------------
520 Address Space Management
521 -------------------------------------------------------------------------- */
524 acpi_ec_space_setup(acpi_handle region_handle,
525 u32 function, void *handler_context, void **return_context)
528 * The EC object is in the handler context and is needed
529 * when calling the acpi_ec_space_handler.
531 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
532 handler_context : NULL;
538 acpi_ec_space_handler(u32 function, acpi_physical_address address,
539 u32 bits, acpi_integer *value,
540 void *handler_context, void *region_context)
542 struct acpi_ec *ec = handler_context;
543 int result = 0, i = 0;
546 if ((address > 0xFF) || !value || !handler_context)
547 return AE_BAD_PARAMETER;
549 if (function != ACPI_READ && function != ACPI_WRITE)
550 return AE_BAD_PARAMETER;
552 if (bits != 8 && acpi_strict)
553 return AE_BAD_PARAMETER;
555 while (bits - i > 0) {
556 if (function == ACPI_READ) {
557 result = acpi_ec_read(ec, address, &temp);
558 (*value) |= ((acpi_integer)temp) << i;
560 temp = 0xff & ((*value) >> i);
561 result = acpi_ec_write(ec, address, temp);
569 return AE_BAD_PARAMETER;
582 /* --------------------------------------------------------------------------
584 -------------------------------------------------------------------------- */
586 static struct proc_dir_entry *acpi_ec_dir;
588 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
590 struct acpi_ec *ec = seq->private;
595 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
596 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
597 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
598 seq_printf(seq, "use global lock:\t%s\n",
599 ec->global_lock ? "yes" : "no");
604 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
606 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
609 static struct file_operations acpi_ec_info_ops = {
610 .open = acpi_ec_info_open_fs,
613 .release = single_release,
614 .owner = THIS_MODULE,
617 static int acpi_ec_add_fs(struct acpi_device *device)
619 struct proc_dir_entry *entry = NULL;
621 if (!acpi_device_dir(device)) {
622 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
624 if (!acpi_device_dir(device))
628 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
629 acpi_device_dir(device));
633 entry->proc_fops = &acpi_ec_info_ops;
634 entry->data = acpi_driver_data(device);
635 entry->owner = THIS_MODULE;
641 static int acpi_ec_remove_fs(struct acpi_device *device)
644 if (acpi_device_dir(device)) {
645 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
646 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
647 acpi_device_dir(device) = NULL;
653 /* --------------------------------------------------------------------------
655 -------------------------------------------------------------------------- */
657 ec_parse_io_ports(struct acpi_resource *resource, void *context);
659 static struct acpi_ec *make_acpi_ec(void)
661 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
664 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
665 mutex_init(&ec->lock);
666 init_waitqueue_head(&ec->wait);
667 INIT_LIST_HEAD(&ec->list);
672 acpi_ec_register_query_methods(acpi_handle handle, u32 level,
673 void *context, void **return_value)
675 struct acpi_namespace_node *node = handle;
676 struct acpi_ec *ec = context;
678 if (sscanf(node->name.ascii, "_Q%x", &value) == 1) {
679 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
685 ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
689 struct acpi_ec *ec = context;
690 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
691 ec_parse_io_ports, ec);
692 if (ACPI_FAILURE(status))
695 /* Get GPE bit assignment (EC events). */
696 /* TODO: Add support for _GPE returning a package */
697 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
698 if (ACPI_FAILURE(status))
700 /* Find and register all query methods */
701 acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1,
702 acpi_ec_register_query_methods, ec, NULL);
703 /* Use the global lock for all EC transactions? */
704 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
706 return AE_CTRL_TERMINATE;
709 static void ec_remove_handlers(struct acpi_ec *ec)
711 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
712 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
713 printk(KERN_ERR PREFIX "failed to remove space handler\n");
714 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
715 &acpi_ec_gpe_handler)))
716 printk(KERN_ERR PREFIX "failed to remove gpe handler\n");
717 ec->handlers_installed = 0;
720 static int acpi_ec_add(struct acpi_device *device)
722 struct acpi_ec *ec = NULL;
726 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
727 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
729 /* Check for boot EC */
731 if (boot_ec->handle == device->handle) {
732 /* Pre-loaded EC from DSDT, just move pointer */
736 } else if (boot_ec->handle == ACPI_ROOT_OBJECT) {
737 /* ECDT-based EC, time to shut it down */
738 ec_remove_handlers(boot_ec);
740 first_ec = boot_ec = NULL;
748 if (ec_parse_device(device->handle, 0, ec, NULL) !=
753 ec->handle = device->handle;
757 acpi_driver_data(device) = ec;
758 acpi_ec_add_fs(device);
759 printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
760 ec->gpe, ec->command_addr, ec->data_addr);
761 printk(KERN_INFO PREFIX "driver started in %s mode\n",
762 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
766 static int acpi_ec_remove(struct acpi_device *device, int type)
769 struct acpi_ec_query_handler *handler, *tmp;
774 ec = acpi_driver_data(device);
775 mutex_lock(&ec->lock);
776 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
777 list_del(&handler->node);
780 mutex_unlock(&ec->lock);
781 acpi_ec_remove_fs(device);
782 acpi_driver_data(device) = NULL;
790 ec_parse_io_ports(struct acpi_resource *resource, void *context)
792 struct acpi_ec *ec = context;
794 if (resource->type != ACPI_RESOURCE_TYPE_IO)
798 * The first address region returned is the data port, and
799 * the second address region returned is the status/command
802 if (ec->data_addr == 0)
803 ec->data_addr = resource->data.io.minimum;
804 else if (ec->command_addr == 0)
805 ec->command_addr = resource->data.io.minimum;
807 return AE_CTRL_TERMINATE;
812 static int ec_install_handlers(struct acpi_ec *ec)
815 if (ec->handlers_installed)
817 status = acpi_install_gpe_handler(NULL, ec->gpe,
818 ACPI_GPE_EDGE_TRIGGERED,
819 &acpi_ec_gpe_handler, ec);
820 if (ACPI_FAILURE(status))
823 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
824 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
826 status = acpi_install_address_space_handler(ec->handle,
828 &acpi_ec_space_handler,
829 &acpi_ec_space_setup, ec);
830 if (ACPI_FAILURE(status)) {
831 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
835 ec->handlers_installed = 1;
839 static int acpi_ec_start(struct acpi_device *device)
847 ec = acpi_driver_data(device);
852 ret = ec_install_handlers(ec);
854 /* EC is fully operational, allow queries */
855 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
859 static int acpi_ec_stop(struct acpi_device *device, int type)
864 ec = acpi_driver_data(device);
867 ec_remove_handlers(ec);
872 int __init acpi_ec_ecdt_probe(void)
876 struct acpi_table_ecdt *ecdt_ptr;
878 boot_ec = make_acpi_ec();
882 * Generate a boot ec context
884 status = acpi_get_table(ACPI_SIG_ECDT, 1,
885 (struct acpi_table_header **)&ecdt_ptr);
886 if (ACPI_SUCCESS(status)) {
887 printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n");
888 boot_ec->command_addr = ecdt_ptr->control.address;
889 boot_ec->data_addr = ecdt_ptr->data.address;
890 boot_ec->gpe = ecdt_ptr->gpe;
891 boot_ec->handle = ACPI_ROOT_OBJECT;
893 /* This workaround is needed only on some broken machines,
894 * which require early EC, but fail to provide ECDT */
896 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
897 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
899 /* Check that acpi_get_devices actually find something */
900 if (ACPI_FAILURE(status) || !boot_ec->handle)
902 /* We really need to limit this workaround, the only ASUS,
903 * which needs it, has fake EC._INI method, so use it as flag.
905 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
909 ret = ec_install_handlers(boot_ec);
920 static int __init acpi_ec_init(void)
927 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
931 /* Now register the driver for the EC */
932 result = acpi_bus_register_driver(&acpi_ec_driver);
934 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
941 subsys_initcall(acpi_ec_init);
943 /* EC driver currently not unloadable */
945 static void __exit acpi_ec_exit(void)
948 acpi_bus_unregister_driver(&acpi_ec_driver);
950 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);