ACPI: Make _OSI(Linux) a special case
[pv_ops_mirror.git] / drivers / acpi / ec.c
blob82f496c07675c66e3cf76020cfbf81fc3dc4139f
1 /*
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 <asm/io.h>
38 #include <acpi/acpi_bus.h>
39 #include <acpi/acpi_drivers.h>
40 #include <acpi/actypes.h>
42 #define _COMPONENT ACPI_EC_COMPONENT
43 ACPI_MODULE_NAME("ec");
44 #define ACPI_EC_COMPONENT 0x00100000
45 #define ACPI_EC_CLASS "embedded_controller"
46 #define ACPI_EC_HID "PNP0C09"
47 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
48 #define ACPI_EC_FILE_INFO "info"
49 #undef PREFIX
50 #define PREFIX "ACPI: EC: "
51 /* EC status register */
52 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
53 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
54 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
55 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
56 /* EC commands */
57 enum ec_command {
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,
64 /* EC events */
65 enum ec_event {
66 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
67 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
70 #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
71 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
73 static enum ec_mode {
74 EC_INTR = 1, /* Output buffer full */
75 EC_POLL, /* Input buffer empty */
76 } acpi_ec_mode = EC_INTR;
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 = "ec",
85 .class = ACPI_EC_CLASS,
86 .ids = ACPI_EC_HID,
87 .ops = {
88 .add = acpi_ec_add,
89 .remove = acpi_ec_remove,
90 .start = acpi_ec_start,
91 .stop = acpi_ec_stop,
95 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
96 /* External interfaces use first EC only, so remember */
97 static struct acpi_ec {
98 acpi_handle handle;
99 unsigned long gpe;
100 unsigned long command_addr;
101 unsigned long data_addr;
102 unsigned long global_lock;
103 struct mutex lock;
104 atomic_t query_pending;
105 atomic_t event_count;
106 wait_queue_head_t wait;
107 } *boot_ec, *first_ec;
109 /* --------------------------------------------------------------------------
110 Transaction Management
111 -------------------------------------------------------------------------- */
113 static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
115 return inb(ec->command_addr);
118 static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
120 return inb(ec->data_addr);
123 static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
125 outb(command, ec->command_addr);
128 static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
130 outb(data, ec->data_addr);
133 static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event,
134 unsigned old_count)
136 u8 status = acpi_ec_read_status(ec);
137 if (old_count == atomic_read(&ec->event_count))
138 return 0;
139 if (event == ACPI_EC_EVENT_OBF_1) {
140 if (status & ACPI_EC_FLAG_OBF)
141 return 1;
142 } else if (event == ACPI_EC_EVENT_IBF_0) {
143 if (!(status & ACPI_EC_FLAG_IBF))
144 return 1;
147 return 0;
150 static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event,
151 unsigned count, int force_poll)
153 if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) {
154 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
155 while (time_before(jiffies, delay)) {
156 if (acpi_ec_check_status(ec, event, 0))
157 return 0;
159 } else {
160 if (wait_event_timeout(ec->wait,
161 acpi_ec_check_status(ec, event, count),
162 msecs_to_jiffies(ACPI_EC_DELAY)) ||
163 acpi_ec_check_status(ec, event, 0)) {
164 return 0;
165 } else {
166 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
167 " status = %d, expect_event = %d\n",
168 acpi_ec_read_status(ec), event);
172 return -ETIME;
175 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
176 const u8 * wdata, unsigned wdata_len,
177 u8 * rdata, unsigned rdata_len,
178 int force_poll)
180 int result = 0;
181 unsigned count = atomic_read(&ec->event_count);
182 acpi_ec_write_cmd(ec, command);
184 for (; wdata_len > 0; --wdata_len) {
185 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
186 if (result) {
187 printk(KERN_ERR PREFIX
188 "write_cmd timeout, command = %d\n", command);
189 goto end;
191 count = atomic_read(&ec->event_count);
192 acpi_ec_write_data(ec, *(wdata++));
195 if (!rdata_len) {
196 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
197 if (result) {
198 printk(KERN_ERR PREFIX
199 "finish-write timeout, command = %d\n", command);
200 goto end;
202 } else if (command == ACPI_EC_COMMAND_QUERY) {
203 atomic_set(&ec->query_pending, 0);
206 for (; rdata_len > 0; --rdata_len) {
207 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll);
208 if (result) {
209 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
210 command);
211 goto end;
213 count = atomic_read(&ec->event_count);
214 *(rdata++) = acpi_ec_read_data(ec);
216 end:
217 return result;
220 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
221 const u8 * wdata, unsigned wdata_len,
222 u8 * rdata, unsigned rdata_len,
223 int force_poll)
225 int status;
226 u32 glk;
228 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
229 return -EINVAL;
231 if (rdata)
232 memset(rdata, 0, rdata_len);
234 mutex_lock(&ec->lock);
235 if (ec->global_lock) {
236 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
237 if (ACPI_FAILURE(status)) {
238 mutex_unlock(&ec->lock);
239 return -ENODEV;
243 /* Make sure GPE is enabled before doing transaction */
244 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
246 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0);
247 if (status) {
248 printk(KERN_DEBUG PREFIX
249 "input buffer is not empty, aborting transaction\n");
250 goto end;
253 status = acpi_ec_transaction_unlocked(ec, command,
254 wdata, wdata_len,
255 rdata, rdata_len,
256 force_poll);
258 end:
260 if (ec->global_lock)
261 acpi_release_global_lock(glk);
262 mutex_unlock(&ec->lock);
264 return status;
268 * Note: samsung nv5000 doesn't work with ec burst mode.
269 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
271 int acpi_ec_burst_enable(struct acpi_ec *ec)
273 u8 d;
274 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
277 int acpi_ec_burst_disable(struct acpi_ec *ec)
279 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
282 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
284 int result;
285 u8 d;
287 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
288 &address, 1, &d, 1, 0);
289 *data = d;
290 return result;
293 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
295 u8 wdata[2] = { address, data };
296 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
297 wdata, 2, NULL, 0, 0);
301 * Externally callable EC access functions. For now, assume 1 EC only
303 int ec_burst_enable(void)
305 if (!first_ec)
306 return -ENODEV;
307 return acpi_ec_burst_enable(first_ec);
310 EXPORT_SYMBOL(ec_burst_enable);
312 int ec_burst_disable(void)
314 if (!first_ec)
315 return -ENODEV;
316 return acpi_ec_burst_disable(first_ec);
319 EXPORT_SYMBOL(ec_burst_disable);
321 int ec_read(u8 addr, u8 * val)
323 int err;
324 u8 temp_data;
326 if (!first_ec)
327 return -ENODEV;
329 err = acpi_ec_read(first_ec, addr, &temp_data);
331 if (!err) {
332 *val = temp_data;
333 return 0;
334 } else
335 return err;
338 EXPORT_SYMBOL(ec_read);
340 int ec_write(u8 addr, u8 val)
342 int err;
344 if (!first_ec)
345 return -ENODEV;
347 err = acpi_ec_write(first_ec, addr, val);
349 return err;
352 EXPORT_SYMBOL(ec_write);
354 int ec_transaction(u8 command,
355 const u8 * wdata, unsigned wdata_len,
356 u8 * rdata, unsigned rdata_len,
357 int force_poll)
359 if (!first_ec)
360 return -ENODEV;
362 return acpi_ec_transaction(first_ec, command, wdata,
363 wdata_len, rdata, rdata_len,
364 force_poll);
367 EXPORT_SYMBOL(ec_transaction);
369 static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
371 int result;
372 u8 d;
374 if (!ec || !data)
375 return -EINVAL;
378 * Query the EC to find out which _Qxx method we need to evaluate.
379 * Note that successful completion of the query causes the ACPI_EC_SCI
380 * bit to be cleared (and thus clearing the interrupt source).
383 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
384 if (result)
385 return result;
387 if (!d)
388 return -ENODATA;
390 *data = d;
391 return 0;
394 /* --------------------------------------------------------------------------
395 Event Management
396 -------------------------------------------------------------------------- */
398 static void acpi_ec_gpe_query(void *ec_cxt)
400 struct acpi_ec *ec = ec_cxt;
401 u8 value = 0;
402 char object_name[8];
404 if (!ec || acpi_ec_query(ec, &value))
405 return;
407 snprintf(object_name, 8, "_Q%2.2X", value);
409 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name));
411 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
414 static u32 acpi_ec_gpe_handler(void *data)
416 acpi_status status = AE_OK;
417 u8 value;
418 struct acpi_ec *ec = data;
420 atomic_inc(&ec->event_count);
422 if (acpi_ec_mode == EC_INTR) {
423 wake_up(&ec->wait);
426 value = acpi_ec_read_status(ec);
427 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
428 atomic_set(&ec->query_pending, 1);
429 status =
430 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query,
431 ec);
434 return status == AE_OK ?
435 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
438 /* --------------------------------------------------------------------------
439 Address Space Management
440 -------------------------------------------------------------------------- */
442 static acpi_status
443 acpi_ec_space_setup(acpi_handle region_handle,
444 u32 function, void *handler_context, void **return_context)
447 * The EC object is in the handler context and is needed
448 * when calling the acpi_ec_space_handler.
450 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
451 handler_context : NULL;
453 return AE_OK;
456 static acpi_status
457 acpi_ec_space_handler(u32 function,
458 acpi_physical_address address,
459 u32 bit_width,
460 acpi_integer * value,
461 void *handler_context, void *region_context)
463 int result = 0;
464 struct acpi_ec *ec = handler_context;
465 u64 temp = *value;
466 acpi_integer f_v = 0;
467 int i = 0;
469 if ((address > 0xFF) || !value || !handler_context)
470 return AE_BAD_PARAMETER;
472 if (bit_width != 8 && acpi_strict) {
473 return AE_BAD_PARAMETER;
476 next_byte:
477 switch (function) {
478 case ACPI_READ:
479 temp = 0;
480 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
481 break;
482 case ACPI_WRITE:
483 result = acpi_ec_write(ec, (u8) address, (u8) temp);
484 break;
485 default:
486 result = -EINVAL;
487 goto out;
488 break;
491 bit_width -= 8;
492 if (bit_width) {
493 if (function == ACPI_READ)
494 f_v |= temp << 8 * i;
495 if (function == ACPI_WRITE)
496 temp >>= 8;
497 i++;
498 address++;
499 goto next_byte;
502 if (function == ACPI_READ) {
503 f_v |= temp << 8 * i;
504 *value = f_v;
507 out:
508 switch (result) {
509 case -EINVAL:
510 return AE_BAD_PARAMETER;
511 break;
512 case -ENODEV:
513 return AE_NOT_FOUND;
514 break;
515 case -ETIME:
516 return AE_TIME;
517 break;
518 default:
519 return AE_OK;
523 /* --------------------------------------------------------------------------
524 FS Interface (/proc)
525 -------------------------------------------------------------------------- */
527 static struct proc_dir_entry *acpi_ec_dir;
529 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
531 struct acpi_ec *ec = seq->private;
533 if (!ec)
534 goto end;
536 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
537 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
538 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
539 seq_printf(seq, "use global lock:\t%s\n",
540 ec->global_lock ? "yes" : "no");
541 end:
542 return 0;
545 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
547 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
550 static struct file_operations acpi_ec_info_ops = {
551 .open = acpi_ec_info_open_fs,
552 .read = seq_read,
553 .llseek = seq_lseek,
554 .release = single_release,
555 .owner = THIS_MODULE,
558 static int acpi_ec_add_fs(struct acpi_device *device)
560 struct proc_dir_entry *entry = NULL;
562 if (!acpi_device_dir(device)) {
563 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
564 acpi_ec_dir);
565 if (!acpi_device_dir(device))
566 return -ENODEV;
569 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
570 acpi_device_dir(device));
571 if (!entry)
572 return -ENODEV;
573 else {
574 entry->proc_fops = &acpi_ec_info_ops;
575 entry->data = acpi_driver_data(device);
576 entry->owner = THIS_MODULE;
579 return 0;
582 static int acpi_ec_remove_fs(struct acpi_device *device)
585 if (acpi_device_dir(device)) {
586 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
587 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
588 acpi_device_dir(device) = NULL;
591 return 0;
594 /* --------------------------------------------------------------------------
595 Driver Interface
596 -------------------------------------------------------------------------- */
597 static acpi_status
598 ec_parse_io_ports(struct acpi_resource *resource, void *context);
600 static acpi_status
601 ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval);
603 static struct acpi_ec *make_acpi_ec(void)
605 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
606 if (!ec)
607 return NULL;
609 atomic_set(&ec->query_pending, 1);
610 atomic_set(&ec->event_count, 1);
611 mutex_init(&ec->lock);
612 init_waitqueue_head(&ec->wait);
614 return ec;
617 static int acpi_ec_add(struct acpi_device *device)
619 acpi_status status = AE_OK;
620 struct acpi_ec *ec = NULL;
622 if (!device)
623 return -EINVAL;
625 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
626 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
628 ec = make_acpi_ec();
629 if (!ec)
630 return -ENOMEM;
632 status = ec_parse_device(device->handle, 0, ec, NULL);
633 if (status != AE_CTRL_TERMINATE) {
634 kfree(ec);
635 return -EINVAL;
638 /* Check if we found the boot EC */
639 if (boot_ec) {
640 if (boot_ec->gpe == ec->gpe) {
641 /* We might have incorrect info for GL at boot time */
642 mutex_lock(&boot_ec->lock);
643 boot_ec->global_lock = ec->global_lock;
644 mutex_unlock(&boot_ec->lock);
645 kfree(ec);
646 ec = boot_ec;
648 } else
649 first_ec = ec;
650 ec->handle = device->handle;
651 acpi_driver_data(device) = ec;
653 acpi_ec_add_fs(device);
655 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
656 acpi_device_name(device), acpi_device_bid(device),
657 (u32) ec->gpe));
659 return 0;
662 static int acpi_ec_remove(struct acpi_device *device, int type)
664 struct acpi_ec *ec;
666 if (!device)
667 return -EINVAL;
669 ec = acpi_driver_data(device);
670 acpi_ec_remove_fs(device);
671 acpi_driver_data(device) = NULL;
672 if (ec == first_ec)
673 first_ec = NULL;
675 /* Don't touch boot EC */
676 if (boot_ec != ec)
677 kfree(ec);
678 return 0;
681 static acpi_status
682 ec_parse_io_ports(struct acpi_resource *resource, void *context)
684 struct acpi_ec *ec = context;
686 if (resource->type != ACPI_RESOURCE_TYPE_IO)
687 return AE_OK;
690 * The first address region returned is the data port, and
691 * the second address region returned is the status/command
692 * port.
694 if (ec->data_addr == 0)
695 ec->data_addr = resource->data.io.minimum;
696 else if (ec->command_addr == 0)
697 ec->command_addr = resource->data.io.minimum;
698 else
699 return AE_CTRL_TERMINATE;
701 return AE_OK;
704 static int ec_install_handlers(struct acpi_ec *ec)
706 acpi_status status;
707 status = acpi_install_gpe_handler(NULL, ec->gpe,
708 ACPI_GPE_EDGE_TRIGGERED,
709 &acpi_ec_gpe_handler, ec);
710 if (ACPI_FAILURE(status))
711 return -ENODEV;
713 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
714 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
716 status = acpi_install_address_space_handler(ec->handle,
717 ACPI_ADR_SPACE_EC,
718 &acpi_ec_space_handler,
719 &acpi_ec_space_setup, ec);
720 if (ACPI_FAILURE(status)) {
721 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
722 return -ENODEV;
725 /* EC is fully operational, allow queries */
726 atomic_set(&ec->query_pending, 0);
728 return 0;
731 static int acpi_ec_start(struct acpi_device *device)
733 struct acpi_ec *ec;
735 if (!device)
736 return -EINVAL;
738 ec = acpi_driver_data(device);
740 if (!ec)
741 return -EINVAL;
743 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
744 ec->gpe, ec->command_addr, ec->data_addr));
746 /* Boot EC is already working */
747 if (ec == boot_ec)
748 return 0;
750 return ec_install_handlers(ec);
753 static int acpi_ec_stop(struct acpi_device *device, int type)
755 acpi_status status;
756 struct acpi_ec *ec;
758 if (!device)
759 return -EINVAL;
761 ec = acpi_driver_data(device);
762 if (!ec)
763 return -EINVAL;
765 /* Don't touch boot EC */
766 if (ec == boot_ec)
767 return 0;
769 status = acpi_remove_address_space_handler(ec->handle,
770 ACPI_ADR_SPACE_EC,
771 &acpi_ec_space_handler);
772 if (ACPI_FAILURE(status))
773 return -ENODEV;
775 status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
776 if (ACPI_FAILURE(status))
777 return -ENODEV;
779 return 0;
782 static acpi_status
783 ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
785 acpi_status status;
787 struct acpi_ec *ec = context;
788 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
789 ec_parse_io_ports, ec);
790 if (ACPI_FAILURE(status))
791 return status;
793 /* Get GPE bit assignment (EC events). */
794 /* TODO: Add support for _GPE returning a package */
795 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
796 if (ACPI_FAILURE(status))
797 return status;
799 /* Use the global lock for all EC transactions? */
800 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
802 ec->handle = handle;
804 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
805 ec->gpe, ec->command_addr, ec->data_addr));
807 return AE_CTRL_TERMINATE;
810 int __init acpi_ec_ecdt_probe(void)
812 int ret;
813 acpi_status status;
814 struct acpi_table_ecdt *ecdt_ptr;
816 boot_ec = make_acpi_ec();
817 if (!boot_ec)
818 return -ENOMEM;
820 * Generate a boot ec context
823 status = acpi_get_table(ACPI_SIG_ECDT, 1,
824 (struct acpi_table_header **)&ecdt_ptr);
825 if (ACPI_FAILURE(status))
826 goto error;
828 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
830 boot_ec->command_addr = ecdt_ptr->control.address;
831 boot_ec->data_addr = ecdt_ptr->data.address;
832 boot_ec->gpe = ecdt_ptr->gpe;
833 boot_ec->handle = ACPI_ROOT_OBJECT;
835 ret = ec_install_handlers(boot_ec);
836 if (!ret) {
837 first_ec = boot_ec;
838 return 0;
840 error:
841 kfree(boot_ec);
842 boot_ec = NULL;
844 return -ENODEV;
847 static int __init acpi_ec_init(void)
849 int result = 0;
851 if (acpi_disabled)
852 return 0;
854 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
855 if (!acpi_ec_dir)
856 return -ENODEV;
858 /* Now register the driver for the EC */
859 result = acpi_bus_register_driver(&acpi_ec_driver);
860 if (result < 0) {
861 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
862 return -ENODEV;
865 return result;
868 subsys_initcall(acpi_ec_init);
870 /* EC driver currently not unloadable */
871 #if 0
872 static void __exit acpi_ec_exit(void)
875 acpi_bus_unregister_driver(&acpi_ec_driver);
877 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
879 return;
881 #endif /* 0 */
883 static int __init acpi_ec_set_intr_mode(char *str)
885 int intr;
887 if (!get_option(&str, &intr))
888 return 0;
890 acpi_ec_mode = (intr) ? EC_INTR : EC_POLL;
892 printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling");
894 return 1;
897 __setup("ec_intr=", acpi_ec_set_intr_mode);