tifm: layout fixes, small changes to comments and printfs
[linux-2.6/verdex.git] / drivers / acpi / ec.c
blobe08cf98f504f12583174d23468a60bf4f9a28c14
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, unsigned count)
152 if (acpi_ec_mode == EC_POLL) {
153 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
154 while (time_before(jiffies, delay)) {
155 if (acpi_ec_check_status(ec, event, 0))
156 return 0;
158 } else {
159 if (wait_event_timeout(ec->wait,
160 acpi_ec_check_status(ec, event, count),
161 msecs_to_jiffies(ACPI_EC_DELAY)) ||
162 acpi_ec_check_status(ec, event, 0)) {
163 return 0;
164 } else {
165 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
166 " status = %d, expect_event = %d\n",
167 acpi_ec_read_status(ec), event);
171 return -ETIME;
174 static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
175 const u8 * wdata, unsigned wdata_len,
176 u8 * rdata, unsigned rdata_len)
178 int result = 0;
179 unsigned count = atomic_read(&ec->event_count);
180 acpi_ec_write_cmd(ec, command);
182 for (; wdata_len > 0; --wdata_len) {
183 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count);
184 if (result) {
185 printk(KERN_ERR PREFIX
186 "write_cmd timeout, command = %d\n", command);
187 goto end;
189 count = atomic_read(&ec->event_count);
190 acpi_ec_write_data(ec, *(wdata++));
193 if (!rdata_len) {
194 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count);
195 if (result) {
196 printk(KERN_ERR PREFIX
197 "finish-write timeout, command = %d\n", command);
198 goto end;
200 } else if (command == ACPI_EC_COMMAND_QUERY) {
201 atomic_set(&ec->query_pending, 0);
204 for (; rdata_len > 0; --rdata_len) {
205 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count);
206 if (result) {
207 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
208 command);
209 goto end;
211 count = atomic_read(&ec->event_count);
212 *(rdata++) = acpi_ec_read_data(ec);
214 end:
215 return result;
218 static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
219 const u8 * wdata, unsigned wdata_len,
220 u8 * rdata, unsigned rdata_len)
222 int status;
223 u32 glk;
225 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
226 return -EINVAL;
228 if (rdata)
229 memset(rdata, 0, rdata_len);
231 mutex_lock(&ec->lock);
232 if (ec->global_lock) {
233 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
234 if (ACPI_FAILURE(status)) {
235 mutex_unlock(&ec->lock);
236 return -ENODEV;
240 /* Make sure GPE is enabled before doing transaction */
241 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
243 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
244 if (status) {
245 printk(KERN_DEBUG PREFIX
246 "input buffer is not empty, aborting transaction\n");
247 goto end;
250 status = acpi_ec_transaction_unlocked(ec, command,
251 wdata, wdata_len,
252 rdata, rdata_len);
254 end:
256 if (ec->global_lock)
257 acpi_release_global_lock(glk);
258 mutex_unlock(&ec->lock);
260 return status;
264 * Note: samsung nv5000 doesn't work with ec burst mode.
265 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
267 int acpi_ec_burst_enable(struct acpi_ec *ec)
269 u8 d;
270 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1);
273 int acpi_ec_burst_disable(struct acpi_ec *ec)
275 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0);
278 static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
280 int result;
281 u8 d;
283 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
284 &address, 1, &d, 1);
285 *data = d;
286 return result;
289 static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
291 u8 wdata[2] = { address, data };
292 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
293 wdata, 2, NULL, 0);
297 * Externally callable EC access functions. For now, assume 1 EC only
299 int ec_burst_enable(void)
301 if (!first_ec)
302 return -ENODEV;
303 return acpi_ec_burst_enable(first_ec);
306 EXPORT_SYMBOL(ec_burst_enable);
308 int ec_burst_disable(void)
310 if (!first_ec)
311 return -ENODEV;
312 return acpi_ec_burst_disable(first_ec);
315 EXPORT_SYMBOL(ec_burst_disable);
317 int ec_read(u8 addr, u8 * val)
319 int err;
320 u8 temp_data;
322 if (!first_ec)
323 return -ENODEV;
325 err = acpi_ec_read(first_ec, addr, &temp_data);
327 if (!err) {
328 *val = temp_data;
329 return 0;
330 } else
331 return err;
334 EXPORT_SYMBOL(ec_read);
336 int ec_write(u8 addr, u8 val)
338 int err;
340 if (!first_ec)
341 return -ENODEV;
343 err = acpi_ec_write(first_ec, addr, val);
345 return err;
348 EXPORT_SYMBOL(ec_write);
350 int ec_transaction(u8 command,
351 const u8 * wdata, unsigned wdata_len,
352 u8 * rdata, unsigned rdata_len)
354 if (!first_ec)
355 return -ENODEV;
357 return acpi_ec_transaction(first_ec, command, wdata,
358 wdata_len, rdata, rdata_len);
361 EXPORT_SYMBOL(ec_transaction);
363 static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
365 int result;
366 u8 d;
368 if (!ec || !data)
369 return -EINVAL;
372 * Query the EC to find out which _Qxx method we need to evaluate.
373 * Note that successful completion of the query causes the ACPI_EC_SCI
374 * bit to be cleared (and thus clearing the interrupt source).
377 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
378 if (result)
379 return result;
381 if (!d)
382 return -ENODATA;
384 *data = d;
385 return 0;
388 /* --------------------------------------------------------------------------
389 Event Management
390 -------------------------------------------------------------------------- */
392 static void acpi_ec_gpe_query(void *ec_cxt)
394 struct acpi_ec *ec = ec_cxt;
395 u8 value = 0;
396 char object_name[8];
398 if (!ec || acpi_ec_query(ec, &value))
399 return;
401 snprintf(object_name, 8, "_Q%2.2X", value);
403 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name));
405 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
408 static u32 acpi_ec_gpe_handler(void *data)
410 acpi_status status = AE_OK;
411 u8 value;
412 struct acpi_ec *ec = data;
413 atomic_inc(&ec->event_count);
415 if (acpi_ec_mode == EC_INTR) {
416 wake_up(&ec->wait);
419 value = acpi_ec_read_status(ec);
420 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
421 atomic_set(&ec->query_pending, 1);
422 status =
423 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query,
424 ec);
427 return status == AE_OK ?
428 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
431 /* --------------------------------------------------------------------------
432 Address Space Management
433 -------------------------------------------------------------------------- */
435 static acpi_status
436 acpi_ec_space_setup(acpi_handle region_handle,
437 u32 function, void *handler_context, void **return_context)
440 * The EC object is in the handler context and is needed
441 * when calling the acpi_ec_space_handler.
443 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
444 handler_context : NULL;
446 return AE_OK;
449 static acpi_status
450 acpi_ec_space_handler(u32 function,
451 acpi_physical_address address,
452 u32 bit_width,
453 acpi_integer * value,
454 void *handler_context, void *region_context)
456 int result = 0;
457 struct acpi_ec *ec = handler_context;
458 u64 temp = *value;
459 acpi_integer f_v = 0;
460 int i = 0;
462 if ((address > 0xFF) || !value || !handler_context)
463 return AE_BAD_PARAMETER;
465 if (bit_width != 8 && acpi_strict) {
466 return AE_BAD_PARAMETER;
469 next_byte:
470 switch (function) {
471 case ACPI_READ:
472 temp = 0;
473 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
474 break;
475 case ACPI_WRITE:
476 result = acpi_ec_write(ec, (u8) address, (u8) temp);
477 break;
478 default:
479 result = -EINVAL;
480 goto out;
481 break;
484 bit_width -= 8;
485 if (bit_width) {
486 if (function == ACPI_READ)
487 f_v |= temp << 8 * i;
488 if (function == ACPI_WRITE)
489 temp >>= 8;
490 i++;
491 address++;
492 goto next_byte;
495 if (function == ACPI_READ) {
496 f_v |= temp << 8 * i;
497 *value = f_v;
500 out:
501 switch (result) {
502 case -EINVAL:
503 return AE_BAD_PARAMETER;
504 break;
505 case -ENODEV:
506 return AE_NOT_FOUND;
507 break;
508 case -ETIME:
509 return AE_TIME;
510 break;
511 default:
512 return AE_OK;
516 /* --------------------------------------------------------------------------
517 FS Interface (/proc)
518 -------------------------------------------------------------------------- */
520 static struct proc_dir_entry *acpi_ec_dir;
522 static int acpi_ec_read_info(struct seq_file *seq, void *offset)
524 struct acpi_ec *ec = seq->private;
526 if (!ec)
527 goto end;
529 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
530 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
531 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
532 seq_printf(seq, "use global lock:\t%s\n",
533 ec->global_lock ? "yes" : "no");
534 end:
535 return 0;
538 static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
540 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
543 static struct file_operations acpi_ec_info_ops = {
544 .open = acpi_ec_info_open_fs,
545 .read = seq_read,
546 .llseek = seq_lseek,
547 .release = single_release,
548 .owner = THIS_MODULE,
551 static int acpi_ec_add_fs(struct acpi_device *device)
553 struct proc_dir_entry *entry = NULL;
555 if (!acpi_device_dir(device)) {
556 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
557 acpi_ec_dir);
558 if (!acpi_device_dir(device))
559 return -ENODEV;
562 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
563 acpi_device_dir(device));
564 if (!entry)
565 return -ENODEV;
566 else {
567 entry->proc_fops = &acpi_ec_info_ops;
568 entry->data = acpi_driver_data(device);
569 entry->owner = THIS_MODULE;
572 return 0;
575 static int acpi_ec_remove_fs(struct acpi_device *device)
578 if (acpi_device_dir(device)) {
579 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
580 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
581 acpi_device_dir(device) = NULL;
584 return 0;
587 /* --------------------------------------------------------------------------
588 Driver Interface
589 -------------------------------------------------------------------------- */
590 static acpi_status
591 ec_parse_io_ports(struct acpi_resource *resource, void *context);
593 static acpi_status
594 ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval);
596 static struct acpi_ec *make_acpi_ec(void)
598 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
599 if (!ec)
600 return NULL;
602 atomic_set(&ec->query_pending, 1);
603 atomic_set(&ec->event_count, 1);
604 mutex_init(&ec->lock);
605 init_waitqueue_head(&ec->wait);
607 return ec;
610 static int acpi_ec_add(struct acpi_device *device)
612 acpi_status status = AE_OK;
613 struct acpi_ec *ec = NULL;
615 if (!device)
616 return -EINVAL;
618 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
619 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
621 ec = make_acpi_ec();
622 if (!ec)
623 return -ENOMEM;
625 status = ec_parse_device(device->handle, 0, ec, NULL);
626 if (status != AE_CTRL_TERMINATE) {
627 kfree(ec);
628 return -EINVAL;
631 /* Check if we found the boot EC */
632 if (boot_ec) {
633 if (boot_ec->gpe == ec->gpe) {
634 /* We might have incorrect info for GL at boot time */
635 mutex_lock(&boot_ec->lock);
636 boot_ec->global_lock = ec->global_lock;
637 mutex_unlock(&boot_ec->lock);
638 kfree(ec);
639 ec = boot_ec;
641 } else
642 first_ec = ec;
643 ec->handle = device->handle;
644 acpi_driver_data(device) = ec;
646 acpi_ec_add_fs(device);
648 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
649 acpi_device_name(device), acpi_device_bid(device),
650 (u32) ec->gpe));
652 return 0;
655 static int acpi_ec_remove(struct acpi_device *device, int type)
657 struct acpi_ec *ec;
659 if (!device)
660 return -EINVAL;
662 ec = acpi_driver_data(device);
663 acpi_ec_remove_fs(device);
664 acpi_driver_data(device) = NULL;
665 if (ec == first_ec)
666 first_ec = NULL;
668 /* Don't touch boot EC */
669 if (boot_ec != ec)
670 kfree(ec);
671 return 0;
674 static acpi_status
675 ec_parse_io_ports(struct acpi_resource *resource, void *context)
677 struct acpi_ec *ec = context;
679 if (resource->type != ACPI_RESOURCE_TYPE_IO)
680 return AE_OK;
683 * The first address region returned is the data port, and
684 * the second address region returned is the status/command
685 * port.
687 if (ec->data_addr == 0)
688 ec->data_addr = resource->data.io.minimum;
689 else if (ec->command_addr == 0)
690 ec->command_addr = resource->data.io.minimum;
691 else
692 return AE_CTRL_TERMINATE;
694 return AE_OK;
697 static int ec_install_handlers(struct acpi_ec *ec)
699 acpi_status status;
700 status = acpi_install_gpe_handler(NULL, ec->gpe,
701 ACPI_GPE_EDGE_TRIGGERED,
702 &acpi_ec_gpe_handler, ec);
703 if (ACPI_FAILURE(status))
704 return -ENODEV;
706 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
707 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
709 status = acpi_install_address_space_handler(ec->handle,
710 ACPI_ADR_SPACE_EC,
711 &acpi_ec_space_handler,
712 &acpi_ec_space_setup, ec);
713 if (ACPI_FAILURE(status)) {
714 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
715 return -ENODEV;
718 /* EC is fully operational, allow queries */
719 atomic_set(&ec->query_pending, 0);
721 return 0;
724 static int acpi_ec_start(struct acpi_device *device)
726 struct acpi_ec *ec;
728 if (!device)
729 return -EINVAL;
731 ec = acpi_driver_data(device);
733 if (!ec)
734 return -EINVAL;
736 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
737 ec->gpe, ec->command_addr, ec->data_addr));
739 /* Boot EC is already working */
740 if (ec == boot_ec)
741 return 0;
743 return ec_install_handlers(ec);
746 static int acpi_ec_stop(struct acpi_device *device, int type)
748 acpi_status status;
749 struct acpi_ec *ec;
751 if (!device)
752 return -EINVAL;
754 ec = acpi_driver_data(device);
755 if (!ec)
756 return -EINVAL;
758 /* Don't touch boot EC */
759 if (ec == boot_ec)
760 return 0;
762 status = acpi_remove_address_space_handler(ec->handle,
763 ACPI_ADR_SPACE_EC,
764 &acpi_ec_space_handler);
765 if (ACPI_FAILURE(status))
766 return -ENODEV;
768 status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
769 if (ACPI_FAILURE(status))
770 return -ENODEV;
772 return 0;
775 static acpi_status
776 ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
778 acpi_status status;
780 struct acpi_ec *ec = context;
781 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
782 ec_parse_io_ports, ec);
783 if (ACPI_FAILURE(status))
784 return status;
786 /* Get GPE bit assignment (EC events). */
787 /* TODO: Add support for _GPE returning a package */
788 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
789 if (ACPI_FAILURE(status))
790 return status;
792 /* Use the global lock for all EC transactions? */
793 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
795 ec->handle = handle;
797 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
798 ec->gpe, ec->command_addr, ec->data_addr));
800 return AE_CTRL_TERMINATE;
803 int __init acpi_ec_ecdt_probe(void)
805 int ret;
806 acpi_status status;
807 struct acpi_table_ecdt *ecdt_ptr;
809 boot_ec = make_acpi_ec();
810 if (!boot_ec)
811 return -ENOMEM;
813 * Generate a boot ec context
816 status = acpi_get_table(ACPI_SIG_ECDT, 1,
817 (struct acpi_table_header **)&ecdt_ptr);
818 if (ACPI_FAILURE(status))
819 goto error;
821 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
823 boot_ec->command_addr = ecdt_ptr->control.address;
824 boot_ec->data_addr = ecdt_ptr->data.address;
825 boot_ec->gpe = ecdt_ptr->gpe;
826 boot_ec->handle = ACPI_ROOT_OBJECT;
828 ret = ec_install_handlers(boot_ec);
829 if (!ret) {
830 first_ec = boot_ec;
831 return 0;
833 error:
834 kfree(boot_ec);
835 boot_ec = NULL;
837 return -ENODEV;
840 static int __init acpi_ec_init(void)
842 int result = 0;
844 if (acpi_disabled)
845 return 0;
847 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
848 if (!acpi_ec_dir)
849 return -ENODEV;
851 /* Now register the driver for the EC */
852 result = acpi_bus_register_driver(&acpi_ec_driver);
853 if (result < 0) {
854 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
855 return -ENODEV;
858 return result;
861 subsys_initcall(acpi_ec_init);
863 /* EC driver currently not unloadable */
864 #if 0
865 static void __exit acpi_ec_exit(void)
868 acpi_bus_unregister_driver(&acpi_ec_driver);
870 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
872 return;
874 #endif /* 0 */
876 static int __init acpi_ec_set_intr_mode(char *str)
878 int intr;
880 if (!get_option(&str, &intr))
881 return 0;
883 acpi_ec_mode = (intr) ? EC_INTR : EC_POLL;
885 printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling");
887 return 1;
890 __setup("ec_intr=", acpi_ec_set_intr_mode);