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 /* Uncomment next line to get verbose print outs*/
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/delay.h>
37 #include <linux/proc_fs.h>
38 #include <linux/seq_file.h>
39 #include <linux/interrupt.h>
40 #include <linux/list.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
44 #include <acpi/actypes.h>
46 #define ACPI_EC_CLASS "embedded_controller"
47 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
48 #define ACPI_EC_FILE_INFO "info"
51 #define PREFIX "ACPI: EC: "
53 /* EC status register */
54 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
55 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
56 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
57 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
61 ACPI_EC_COMMAND_READ = 0x80,
62 ACPI_EC_COMMAND_WRITE = 0x81,
63 ACPI_EC_BURST_ENABLE = 0x82,
64 ACPI_EC_BURST_DISABLE = 0x83,
65 ACPI_EC_COMMAND_QUERY = 0x84,
70 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
71 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
74 #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
75 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
76 #define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */
79 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
80 EC_FLAGS_QUERY_PENDING, /* Query is pending */
81 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
82 EC_FLAGS_NO_GPE, /* Don't use GPE mode */
83 EC_FLAGS_RESCHEDULE_POLL /* Re-schedule poll */
86 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
87 /* External interfaces use first EC only, so remember */
88 typedef int (*acpi_ec_query_func) (void *data);
90 struct acpi_ec_query_handler {
91 struct list_head node;
92 acpi_ec_query_func func;
98 static struct acpi_ec {
101 unsigned long command_addr;
102 unsigned long data_addr;
103 unsigned long global_lock;
106 wait_queue_head_t wait;
107 struct list_head list;
108 struct delayed_work work;
110 u8 handlers_installed;
111 } *boot_ec, *first_ec;
113 /* --------------------------------------------------------------------------
114 Transaction Management
115 -------------------------------------------------------------------------- */
117 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
119 u8 x = inb(ec->command_addr);
120 pr_debug(PREFIX "---> status = 0x%2.2x\n", x);
124 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
126 u8 x = inb(ec->data_addr);
127 pr_debug(PREFIX "---> data = 0x%2.2x\n", x);
128 return inb(ec->data_addr);
131 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
133 pr_debug(PREFIX "<--- command = 0x%2.2x\n", command);
134 outb(command, ec->command_addr);
137 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
139 pr_debug(PREFIX "<--- data = 0x%2.2x\n", data);
140 outb(data, ec->data_addr);
143 static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
145 if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags))
147 if (event == ACPI_EC_EVENT_OBF_1) {
148 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
150 } else if (event == ACPI_EC_EVENT_IBF_0) {
151 if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
158 static void ec_schedule_ec_poll(struct acpi_ec *ec)
160 if (test_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags))
161 schedule_delayed_work(&ec->work,
162 msecs_to_jiffies(ACPI_EC_DELAY));
165 static void ec_switch_to_poll_mode(struct acpi_ec *ec)
167 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
168 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
169 acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
170 set_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
173 static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
175 atomic_set(&ec->irq_count, 0);
176 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
177 likely(!force_poll)) {
178 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
179 msecs_to_jiffies(ACPI_EC_DELAY)))
181 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
182 if (acpi_ec_check_status(ec, event)) {
183 /* missing GPEs, switch back to poll mode */
184 if (printk_ratelimit())
185 pr_info(PREFIX "missing confirmations, "
186 "switch off interrupt mode.\n");
187 ec_switch_to_poll_mode(ec);
188 ec_schedule_ec_poll(ec);
192 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
193 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
194 while (time_before(jiffies, delay)) {
195 if (acpi_ec_check_status(ec, event))
197 udelay(ACPI_EC_UDELAY);
200 pr_err(PREFIX "acpi_ec_wait timeout, status = 0x%2.2x, event = %s\n",
201 acpi_ec_read_status(ec),
202 (event == ACPI_EC_EVENT_OBF_1) ? "\"b0=1\"" : "\"b1=0\"");
206 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
207 const u8 * wdata, unsigned wdata_len,
208 u8 * rdata, unsigned rdata_len,
212 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
213 pr_debug(PREFIX "transaction start\n");
214 acpi_ec_write_cmd(ec, command);
215 for (; wdata_len > 0; --wdata_len) {
216 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
219 "write_cmd timeout, command = %d\n", command);
222 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
223 acpi_ec_write_data(ec, *(wdata++));
227 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
230 "finish-write timeout, command = %d\n", command);
233 } else if (command == ACPI_EC_COMMAND_QUERY)
234 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
236 for (; rdata_len > 0; --rdata_len) {
237 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
239 pr_err(PREFIX "read timeout, command = %d\n", command);
242 /* Don't expect GPE after last read */
244 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
245 *(rdata++) = acpi_ec_read_data(ec);
248 pr_debug(PREFIX "transaction end\n");
252 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
253 const u8 * wdata, unsigned wdata_len,
254 u8 * rdata, unsigned rdata_len,
260 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
264 memset(rdata, 0, rdata_len);
266 mutex_lock(&ec->lock);
267 if (ec->global_lock) {
268 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
269 if (ACPI_FAILURE(status)) {
270 mutex_unlock(&ec->lock);
275 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
277 pr_err(PREFIX "input buffer is not empty, "
278 "aborting transaction\n");
282 status = acpi_ec_transaction_unlocked(ec, command,
290 acpi_release_global_lock(glk);
291 mutex_unlock(&ec->lock);
297 * Note: samsung nv5000 doesn't work with ec burst mode.
298 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
300 int acpi_ec_burst_enable(struct acpi_ec *ec)
303 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
306 int acpi_ec_burst_disable(struct acpi_ec *ec)
308 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
311 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
316 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
317 &address, 1, &d, 1, 0);
322 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
324 u8 wdata[2] = { address, data };
325 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
326 wdata, 2, NULL, 0, 0);
330 * Externally callable EC access functions. For now, assume 1 EC only
332 int ec_burst_enable(void)
336 return acpi_ec_burst_enable(first_ec);
339 EXPORT_SYMBOL(ec_burst_enable);
341 int ec_burst_disable(void)
345 return acpi_ec_burst_disable(first_ec);
348 EXPORT_SYMBOL(ec_burst_disable);
350 int ec_read(u8 addr, u8 * val)
358 err = acpi_ec_read(first_ec, addr, &temp_data);
367 EXPORT_SYMBOL(ec_read);
369 int ec_write(u8 addr, u8 val)
376 err = acpi_ec_write(first_ec, addr, val);
381 EXPORT_SYMBOL(ec_write);
383 int ec_transaction(u8 command,
384 const u8 * wdata, unsigned wdata_len,
385 u8 * rdata, unsigned rdata_len,
391 return acpi_ec_transaction(first_ec, command, wdata,
392 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, 0);
423 /* --------------------------------------------------------------------------
425 -------------------------------------------------------------------------- */
426 int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
427 acpi_handle handle, acpi_ec_query_func func,
430 struct acpi_ec_query_handler *handler =
431 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
435 handler->query_bit = query_bit;
436 handler->handle = handle;
437 handler->func = func;
438 handler->data = data;
439 mutex_lock(&ec->lock);
440 list_add(&handler->node, &ec->list);
441 mutex_unlock(&ec->lock);
445 EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
447 void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
449 struct acpi_ec_query_handler *handler, *tmp;
450 mutex_lock(&ec->lock);
451 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
452 if (query_bit == handler->query_bit) {
453 list_del(&handler->node);
457 mutex_unlock(&ec->lock);
460 EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
462 static void acpi_ec_gpe_query(void *ec_cxt)
464 struct acpi_ec *ec = ec_cxt;
466 struct acpi_ec_query_handler *handler, copy;
468 if (!ec || acpi_ec_query(ec, &value))
470 mutex_lock(&ec->lock);
471 list_for_each_entry(handler, &ec->list, node) {
472 if (value == handler->query_bit) {
473 /* have custom handler for this bit */
474 memcpy(©, handler, sizeof(copy));
475 mutex_unlock(&ec->lock);
477 copy.func(copy.data);
478 } else if (copy.handle) {
479 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
484 mutex_unlock(&ec->lock);
487 static u32 acpi_ec_gpe_handler(void *data)
489 acpi_status status = AE_OK;
490 struct acpi_ec *ec = data;
491 u8 state = acpi_ec_read_status(ec);
493 pr_debug(PREFIX "~~~> interrupt\n");
494 atomic_inc(&ec->irq_count);
495 if (atomic_read(&ec->irq_count) > 5) {
496 pr_err(PREFIX "GPE storm detected, disabling EC GPE\n");
497 ec_switch_to_poll_mode(ec);
500 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
501 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
504 if (state & 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 (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
509 !test_bit(EC_FLAGS_NO_GPE, &ec->flags) &&
511 /* this is non-query, must be confirmation */
512 if (printk_ratelimit())
513 pr_info(PREFIX "non-query interrupt received,"
514 " switching to interrupt mode\n");
515 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
516 clear_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
519 ec_schedule_ec_poll(ec);
520 return ACPI_SUCCESS(status) ?
521 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
524 static void do_ec_poll(struct work_struct *work)
526 struct acpi_ec *ec = container_of(work, struct acpi_ec, work.work);
527 atomic_set(&ec->irq_count, 0);
528 (void)acpi_ec_gpe_handler(ec);
531 /* --------------------------------------------------------------------------
532 Address Space Management
533 -------------------------------------------------------------------------- */
536 acpi_ec_space_handler(u32 function, acpi_physical_address address,
537 u32 bits, acpi_integer *value,
538 void *handler_context, void *region_context)
540 struct acpi_ec *ec = handler_context;
544 if ((address > 0xFF) || !value || !handler_context)
545 return AE_BAD_PARAMETER;
547 if (function != ACPI_READ && function != ACPI_WRITE)
548 return AE_BAD_PARAMETER;
550 if (bits != 8 && acpi_strict)
551 return AE_BAD_PARAMETER;
553 acpi_ec_burst_enable(ec);
555 if (function == ACPI_READ) {
556 result = acpi_ec_read(ec, address, &temp);
559 temp = 0xff & (*value);
560 result = acpi_ec_write(ec, address, temp);
563 for (i = 8; unlikely(bits - i > 0); i += 8) {
565 if (function == ACPI_READ) {
566 result = acpi_ec_read(ec, address, &temp);
567 (*value) |= ((acpi_integer)temp) << i;
569 temp = 0xff & ((*value) >> i);
570 result = acpi_ec_write(ec, address, temp);
574 acpi_ec_burst_disable(ec);
578 return AE_BAD_PARAMETER;
591 /* --------------------------------------------------------------------------
593 -------------------------------------------------------------------------- */
595 static struct proc_dir_entry *acpi_ec_dir;
597 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
599 struct acpi_ec *ec = seq->private;
604 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
605 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
606 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
607 seq_printf(seq, "use global lock:\t%s\n",
608 ec->global_lock ? "yes" : "no");
613 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
615 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
618 static struct file_operations acpi_ec_info_ops = {
619 .open = acpi_ec_info_open_fs,
622 .release = single_release,
623 .owner = THIS_MODULE,
626 static int acpi_ec_add_fs(struct acpi_device *device)
628 struct proc_dir_entry *entry = NULL;
630 if (!acpi_device_dir(device)) {
631 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
633 if (!acpi_device_dir(device))
637 entry = proc_create_data(ACPI_EC_FILE_INFO, S_IRUGO,
638 acpi_device_dir(device),
639 &acpi_ec_info_ops, acpi_driver_data(device));
645 static int acpi_ec_remove_fs(struct acpi_device *device)
648 if (acpi_device_dir(device)) {
649 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
650 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
651 acpi_device_dir(device) = NULL;
657 /* --------------------------------------------------------------------------
659 -------------------------------------------------------------------------- */
661 ec_parse_io_ports(struct acpi_resource *resource, void *context);
663 static struct acpi_ec *make_acpi_ec(void)
665 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
668 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
669 mutex_init(&ec->lock);
670 init_waitqueue_head(&ec->wait);
671 INIT_LIST_HEAD(&ec->list);
672 INIT_DELAYED_WORK_DEFERRABLE(&ec->work, do_ec_poll);
673 atomic_set(&ec->irq_count, 0);
678 acpi_ec_register_query_methods(acpi_handle handle, u32 level,
679 void *context, void **return_value)
681 struct acpi_namespace_node *node = handle;
682 struct acpi_ec *ec = context;
684 if (sscanf(node->name.ascii, "_Q%x", &value) == 1) {
685 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
691 ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
695 struct acpi_ec *ec = context;
696 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
697 ec_parse_io_ports, ec);
698 if (ACPI_FAILURE(status))
701 /* Get GPE bit assignment (EC events). */
702 /* TODO: Add support for _GPE returning a package */
703 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
704 if (ACPI_FAILURE(status))
706 /* Use the global lock for all EC transactions? */
707 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
709 return AE_CTRL_TERMINATE;
712 static void ec_poll_stop(struct acpi_ec *ec)
714 clear_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
715 cancel_delayed_work(&ec->work);
718 static void ec_remove_handlers(struct acpi_ec *ec)
721 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
722 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
723 pr_err(PREFIX "failed to remove space handler\n");
724 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
725 &acpi_ec_gpe_handler)))
726 pr_err(PREFIX "failed to remove gpe handler\n");
727 ec->handlers_installed = 0;
730 static int acpi_ec_add(struct acpi_device *device)
732 struct acpi_ec *ec = NULL;
736 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
737 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
739 /* Check for boot EC */
741 (boot_ec->handle == device->handle ||
742 boot_ec->handle == ACPI_ROOT_OBJECT)) {
749 if (ec_parse_device(device->handle, 0, ec, NULL) !=
756 ec->handle = device->handle;
758 /* Find and register all query methods */
759 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
760 acpi_ec_register_query_methods, ec, NULL);
764 acpi_driver_data(device) = ec;
765 acpi_ec_add_fs(device);
766 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
767 ec->gpe, ec->command_addr, ec->data_addr);
768 pr_info(PREFIX "driver started in %s mode\n",
769 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
773 static int acpi_ec_remove(struct acpi_device *device, int type)
776 struct acpi_ec_query_handler *handler, *tmp;
781 ec = acpi_driver_data(device);
782 mutex_lock(&ec->lock);
783 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
784 list_del(&handler->node);
787 mutex_unlock(&ec->lock);
788 acpi_ec_remove_fs(device);
789 acpi_driver_data(device) = NULL;
797 ec_parse_io_ports(struct acpi_resource *resource, void *context)
799 struct acpi_ec *ec = context;
801 if (resource->type != ACPI_RESOURCE_TYPE_IO)
805 * The first address region returned is the data port, and
806 * the second address region returned is the status/command
809 if (ec->data_addr == 0)
810 ec->data_addr = resource->data.io.minimum;
811 else if (ec->command_addr == 0)
812 ec->command_addr = resource->data.io.minimum;
814 return AE_CTRL_TERMINATE;
819 static int ec_install_handlers(struct acpi_ec *ec)
822 if (ec->handlers_installed)
824 status = acpi_install_gpe_handler(NULL, ec->gpe,
825 ACPI_GPE_EDGE_TRIGGERED,
826 &acpi_ec_gpe_handler, ec);
827 if (ACPI_FAILURE(status))
830 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
831 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
833 status = acpi_install_address_space_handler(ec->handle,
835 &acpi_ec_space_handler,
837 if (ACPI_FAILURE(status)) {
838 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
842 ec->handlers_installed = 1;
846 static int acpi_ec_start(struct acpi_device *device)
854 ec = acpi_driver_data(device);
859 ret = ec_install_handlers(ec);
861 /* EC is fully operational, allow queries */
862 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
863 ec_schedule_ec_poll(ec);
867 static int acpi_ec_stop(struct acpi_device *device, int type)
872 ec = acpi_driver_data(device);
875 ec_remove_handlers(ec);
880 int __init acpi_boot_ec_enable(void)
882 if (!boot_ec || boot_ec->handlers_installed)
884 if (!ec_install_handlers(boot_ec)) {
891 static const struct acpi_device_id ec_device_ids[] = {
896 int __init acpi_ec_ecdt_probe(void)
900 struct acpi_table_ecdt *ecdt_ptr;
902 boot_ec = make_acpi_ec();
906 * Generate a boot ec context
908 status = acpi_get_table(ACPI_SIG_ECDT, 1,
909 (struct acpi_table_header **)&ecdt_ptr);
910 if (ACPI_SUCCESS(status)) {
911 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
912 boot_ec->command_addr = ecdt_ptr->control.address;
913 boot_ec->data_addr = ecdt_ptr->data.address;
914 boot_ec->gpe = ecdt_ptr->gpe;
915 boot_ec->handle = ACPI_ROOT_OBJECT;
916 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
918 /* This workaround is needed only on some broken machines,
919 * which require early EC, but fail to provide ECDT */
921 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
922 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
924 /* Check that acpi_get_devices actually find something */
925 if (ACPI_FAILURE(status) || !boot_ec->handle)
927 /* We really need to limit this workaround, the only ASUS,
928 * which needs it, has fake EC._INI method, so use it as flag.
929 * Keep boot_ec struct as it will be needed soon.
931 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
935 ret = ec_install_handlers(boot_ec);
946 static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
948 struct acpi_ec *ec = acpi_driver_data(device);
950 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
951 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
952 acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
956 static int acpi_ec_resume(struct acpi_device *device)
958 struct acpi_ec *ec = acpi_driver_data(device);
959 /* Enable use of GPE back */
960 clear_bit(EC_FLAGS_NO_GPE, &ec->flags);
961 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
965 static struct acpi_driver acpi_ec_driver = {
967 .class = ACPI_EC_CLASS,
968 .ids = ec_device_ids,
971 .remove = acpi_ec_remove,
972 .start = acpi_ec_start,
973 .stop = acpi_ec_stop,
974 .suspend = acpi_ec_suspend,
975 .resume = acpi_ec_resume,
979 static int __init acpi_ec_init(void)
986 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
990 /* Now register the driver for the EC */
991 result = acpi_bus_register_driver(&acpi_ec_driver);
993 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1000 subsys_initcall(acpi_ec_init);
1002 /* EC driver currently not unloadable */
1004 static void __exit acpi_ec_exit(void)
1007 acpi_bus_unregister_driver(&acpi_ec_driver);
1009 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);