MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / acpi / ec.c
blobd1419145ef0f1bd3d9719a7e932a909c9ce67ba9
1 /*
2 * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/delay.h>
31 #include <linux/proc_fs.h>
32 #include <asm/io.h>
33 #include <acpi/acpi_bus.h>
34 #include <acpi/acpi_drivers.h>
35 #include <acpi/actypes.h>
37 #define _COMPONENT ACPI_EC_COMPONENT
38 ACPI_MODULE_NAME ("acpi_ec")
40 #define ACPI_EC_COMPONENT 0x00100000
41 #define ACPI_EC_CLASS "embedded_controller"
42 #define ACPI_EC_HID "PNP0C09"
43 #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
44 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
45 #define ACPI_EC_FILE_INFO "info"
48 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
49 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
50 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
52 #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
53 #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
55 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
56 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
57 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
59 #define ACPI_EC_COMMAND_READ 0x80
60 #define ACPI_EC_COMMAND_WRITE 0x81
61 #define ACPI_EC_COMMAND_QUERY 0x84
63 static int acpi_ec_add (struct acpi_device *device);
64 static int acpi_ec_remove (struct acpi_device *device, int type);
65 static int acpi_ec_start (struct acpi_device *device);
66 static int acpi_ec_stop (struct acpi_device *device, int type);
68 static struct acpi_driver acpi_ec_driver = {
69 .name = ACPI_EC_DRIVER_NAME,
70 .class = ACPI_EC_CLASS,
71 .ids = ACPI_EC_HID,
72 .ops = {
73 .add = acpi_ec_add,
74 .remove = acpi_ec_remove,
75 .start = acpi_ec_start,
76 .stop = acpi_ec_stop,
80 struct acpi_ec {
81 acpi_handle handle;
82 unsigned long uid;
83 unsigned long gpe_bit;
84 struct acpi_generic_address status_addr;
85 struct acpi_generic_address command_addr;
86 struct acpi_generic_address data_addr;
87 unsigned long global_lock;
88 spinlock_t lock;
91 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
92 static struct acpi_ec *ec_ecdt;
94 /* External interfaces use first EC only, so remember */
95 static struct acpi_device *first_ec;
97 /* --------------------------------------------------------------------------
98 Transaction Management
99 -------------------------------------------------------------------------- */
101 static int
102 acpi_ec_wait (
103 struct acpi_ec *ec,
104 u8 event)
106 u32 acpi_ec_status = 0;
107 u32 i = ACPI_EC_UDELAY_COUNT;
109 if (!ec)
110 return -EINVAL;
112 /* Poll the EC status register waiting for the event to occur. */
113 switch (event) {
114 case ACPI_EC_EVENT_OBF:
115 do {
116 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->status_addr);
117 if (acpi_ec_status & ACPI_EC_FLAG_OBF)
118 return 0;
119 udelay(ACPI_EC_UDELAY);
120 } while (--i>0);
121 break;
122 case ACPI_EC_EVENT_IBE:
123 do {
124 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->status_addr);
125 if (!(acpi_ec_status & ACPI_EC_FLAG_IBF))
126 return 0;
127 udelay(ACPI_EC_UDELAY);
128 } while (--i>0);
129 break;
130 default:
131 return -EINVAL;
134 return -ETIME;
138 static int
139 acpi_ec_read (
140 struct acpi_ec *ec,
141 u8 address,
142 u32 *data)
144 acpi_status status = AE_OK;
145 int result = 0;
146 unsigned long flags = 0;
147 u32 glk = 0;
149 ACPI_FUNCTION_TRACE("acpi_ec_read");
151 if (!ec || !data)
152 return_VALUE(-EINVAL);
154 *data = 0;
156 if (ec->global_lock) {
157 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
158 if (ACPI_FAILURE(status))
159 return_VALUE(-ENODEV);
162 spin_lock_irqsave(&ec->lock, flags);
164 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr);
165 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
166 if (result)
167 goto end;
169 acpi_hw_low_level_write(8, address, &ec->data_addr);
170 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
171 if (result)
172 goto end;
175 acpi_hw_low_level_read(8, data, &ec->data_addr);
177 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
178 *data, address));
180 end:
181 spin_unlock_irqrestore(&ec->lock, flags);
183 if (ec->global_lock)
184 acpi_release_global_lock(glk);
186 return_VALUE(result);
190 static int
191 acpi_ec_write (
192 struct acpi_ec *ec,
193 u8 address,
194 u8 data)
196 int result = 0;
197 acpi_status status = AE_OK;
198 unsigned long flags = 0;
199 u32 glk = 0;
201 ACPI_FUNCTION_TRACE("acpi_ec_write");
203 if (!ec)
204 return_VALUE(-EINVAL);
206 if (ec->global_lock) {
207 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
208 if (ACPI_FAILURE(status))
209 return_VALUE(-ENODEV);
212 spin_lock_irqsave(&ec->lock, flags);
214 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr);
215 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
216 if (result)
217 goto end;
219 acpi_hw_low_level_write(8, address, &ec->data_addr);
220 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
221 if (result)
222 goto end;
224 acpi_hw_low_level_write(8, data, &ec->data_addr);
225 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
226 if (result)
227 goto end;
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
230 data, address));
232 end:
233 spin_unlock_irqrestore(&ec->lock, flags);
235 if (ec->global_lock)
236 acpi_release_global_lock(glk);
238 return_VALUE(result);
242 * Externally callable EC access functions. For now, assume 1 EC only
245 ec_read(u8 addr, u8 *val)
247 struct acpi_ec *ec;
248 int err;
249 u32 temp_data;
251 if (!first_ec)
252 return -ENODEV;
254 ec = acpi_driver_data(first_ec);
256 err = acpi_ec_read(ec, addr, &temp_data);
258 if (!err) {
259 *val = temp_data;
260 return 0;
262 else
263 return err;
267 ec_write(u8 addr, u8 val)
269 struct acpi_ec *ec;
270 int err;
272 if (!first_ec)
273 return -ENODEV;
275 ec = acpi_driver_data(first_ec);
277 err = acpi_ec_write(ec, addr, val);
279 return err;
283 static int
284 acpi_ec_query (
285 struct acpi_ec *ec,
286 u32 *data)
288 int result = 0;
289 acpi_status status = AE_OK;
290 unsigned long flags = 0;
291 u32 glk = 0;
293 ACPI_FUNCTION_TRACE("acpi_ec_query");
295 if (!ec || !data)
296 return_VALUE(-EINVAL);
298 *data = 0;
300 if (ec->global_lock) {
301 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
302 if (ACPI_FAILURE(status))
303 return_VALUE(-ENODEV);
307 * Query the EC to find out which _Qxx method we need to evaluate.
308 * Note that successful completion of the query causes the ACPI_EC_SCI
309 * bit to be cleared (and thus clearing the interrupt source).
311 spin_lock_irqsave(&ec->lock, flags);
313 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr);
314 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
315 if (result)
316 goto end;
318 acpi_hw_low_level_read(8, data, &ec->data_addr);
319 if (!*data)
320 result = -ENODATA;
322 end:
323 spin_unlock_irqrestore(&ec->lock, flags);
325 if (ec->global_lock)
326 acpi_release_global_lock(glk);
328 return_VALUE(result);
332 /* --------------------------------------------------------------------------
333 Event Management
334 -------------------------------------------------------------------------- */
336 struct acpi_ec_query_data {
337 acpi_handle handle;
338 u8 data;
341 static void
342 acpi_ec_gpe_query (
343 void *ec_cxt)
345 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt;
346 u32 value = 0;
347 unsigned long flags = 0;
348 static char object_name[5] = {'_','Q','0','0','\0'};
349 const char hex[] = {'0','1','2','3','4','5','6','7',
350 '8','9','A','B','C','D','E','F'};
352 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
354 if (!ec_cxt)
355 goto end;
357 spin_lock_irqsave(&ec->lock, flags);
358 acpi_hw_low_level_read(8, &value, &ec->command_addr);
359 spin_unlock_irqrestore(&ec->lock, flags);
361 /* TBD: Implement asynch events!
362 * NOTE: All we care about are EC-SCI's. Other EC events are
363 * handled via polling (yuck!). This is because some systems
364 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
365 * a purely interrupt-driven approach (grumble, grumble).
367 if (!(value & ACPI_EC_FLAG_SCI))
368 goto end;
370 if (acpi_ec_query(ec, &value))
371 goto end;
373 object_name[2] = hex[((value >> 4) & 0x0F)];
374 object_name[3] = hex[(value & 0x0F)];
376 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
378 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
380 end:
381 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
384 static u32
385 acpi_ec_gpe_handler (
386 void *data)
388 acpi_status status = AE_OK;
389 struct acpi_ec *ec = (struct acpi_ec *) data;
391 if (!ec)
392 return ACPI_INTERRUPT_NOT_HANDLED;
394 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
396 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
397 acpi_ec_gpe_query, ec);
399 if (status == AE_OK)
400 return ACPI_INTERRUPT_HANDLED;
401 else
402 return ACPI_INTERRUPT_NOT_HANDLED;
405 /* --------------------------------------------------------------------------
406 Address Space Management
407 -------------------------------------------------------------------------- */
409 static acpi_status
410 acpi_ec_space_setup (
411 acpi_handle region_handle,
412 u32 function,
413 void *handler_context,
414 void **return_context)
417 * The EC object is in the handler context and is needed
418 * when calling the acpi_ec_space_handler.
420 if(function == ACPI_REGION_DEACTIVATE)
421 *return_context = NULL;
422 else
423 *return_context = handler_context;
425 return AE_OK;
429 static acpi_status
430 acpi_ec_space_handler (
431 u32 function,
432 acpi_physical_address address,
433 u32 bit_width,
434 acpi_integer *value,
435 void *handler_context,
436 void *region_context)
438 int result = 0;
439 struct acpi_ec *ec = NULL;
440 u32 temp = 0;
442 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
444 if ((address > 0xFF) || (bit_width != 8) || !value || !handler_context)
445 return_VALUE(AE_BAD_PARAMETER);
447 ec = (struct acpi_ec *) handler_context;
449 switch (function) {
450 case ACPI_READ:
451 result = acpi_ec_read(ec, (u8) address, &temp);
452 *value = (acpi_integer) temp;
453 break;
454 case ACPI_WRITE:
455 result = acpi_ec_write(ec, (u8) address, (u8) *value);
456 break;
457 default:
458 result = -EINVAL;
459 break;
462 switch (result) {
463 case -EINVAL:
464 return_VALUE(AE_BAD_PARAMETER);
465 break;
466 case -ENODEV:
467 return_VALUE(AE_NOT_FOUND);
468 break;
469 case -ETIME:
470 return_VALUE(AE_TIME);
471 break;
472 default:
473 return_VALUE(AE_OK);
479 /* --------------------------------------------------------------------------
480 FS Interface (/proc)
481 -------------------------------------------------------------------------- */
483 struct proc_dir_entry *acpi_ec_dir;
486 static int
487 acpi_ec_read_info (
488 char *page,
489 char **start,
490 off_t off,
491 int count,
492 int *eof,
493 void *data)
495 struct acpi_ec *ec = (struct acpi_ec *) data;
496 char *p = page;
497 int len = 0;
499 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
501 if (!ec || (off != 0))
502 goto end;
504 p += sprintf(p, "gpe bit: 0x%02x\n",
505 (u32) ec->gpe_bit);
506 p += sprintf(p, "ports: 0x%02x, 0x%02x\n",
507 (u32) ec->status_addr.address, (u32) ec->data_addr.address);
508 p += sprintf(p, "use global lock: %s\n",
509 ec->global_lock?"yes":"no");
511 end:
512 len = (p - page);
513 if (len <= off+count) *eof = 1;
514 *start = page + off;
515 len -= off;
516 if (len>count) len = count;
517 if (len<0) len = 0;
519 return_VALUE(len);
523 static int
524 acpi_ec_add_fs (
525 struct acpi_device *device)
527 struct proc_dir_entry *entry = NULL;
529 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
531 if (!acpi_device_dir(device)) {
532 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
533 acpi_ec_dir);
534 if (!acpi_device_dir(device))
535 return_VALUE(-ENODEV);
538 entry = create_proc_read_entry(ACPI_EC_FILE_INFO, S_IRUGO,
539 acpi_device_dir(device), acpi_ec_read_info,
540 acpi_driver_data(device));
541 if (!entry)
542 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
543 "Unable to create '%s' fs entry\n",
544 ACPI_EC_FILE_INFO));
546 return_VALUE(0);
550 static int
551 acpi_ec_remove_fs (
552 struct acpi_device *device)
554 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
556 if (acpi_device_dir(device)) {
557 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
558 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
559 acpi_device_dir(device) = NULL;
562 return_VALUE(0);
566 /* --------------------------------------------------------------------------
567 Driver Interface
568 -------------------------------------------------------------------------- */
570 static int
571 acpi_ec_add (
572 struct acpi_device *device)
574 int result = 0;
575 acpi_status status = AE_OK;
576 struct acpi_ec *ec = NULL;
577 unsigned long uid;
579 ACPI_FUNCTION_TRACE("acpi_ec_add");
581 if (!device)
582 return_VALUE(-EINVAL);
584 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
585 if (!ec)
586 return_VALUE(-ENOMEM);
587 memset(ec, 0, sizeof(struct acpi_ec));
589 ec->handle = device->handle;
590 ec->uid = -1;
591 ec->lock = SPIN_LOCK_UNLOCKED;
592 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
593 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
594 acpi_driver_data(device) = ec;
596 /* Use the global lock for all EC transactions? */
597 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
599 /* If our UID matches the UID for the ECDT-enumerated EC,
600 we now have the *real* EC info, so kill the makeshift one.*/
601 acpi_evaluate_integer(ec->handle, "_UID", NULL, &uid);
602 if (ec_ecdt && ec_ecdt->uid == uid) {
603 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
604 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
606 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler);
608 kfree(ec_ecdt);
611 /* Get GPE bit assignment (EC events). */
612 /* TODO: Add support for _GPE returning a package */
613 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe_bit);
614 if (ACPI_FAILURE(status)) {
615 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
616 "Error obtaining GPE bit assignment\n"));
617 result = -ENODEV;
618 goto end;
621 result = acpi_ec_add_fs(device);
622 if (result)
623 goto end;
625 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
626 acpi_device_name(device), acpi_device_bid(device),
627 (u32) ec->gpe_bit);
629 if (!first_ec)
630 first_ec = device;
632 end:
633 if (result)
634 kfree(ec);
636 return_VALUE(result);
640 static int
641 acpi_ec_remove (
642 struct acpi_device *device,
643 int type)
645 struct acpi_ec *ec = NULL;
647 ACPI_FUNCTION_TRACE("acpi_ec_remove");
649 if (!device)
650 return_VALUE(-EINVAL);
652 ec = acpi_driver_data(device);
654 acpi_ec_remove_fs(device);
656 kfree(ec);
658 return_VALUE(0);
662 static acpi_status
663 acpi_ec_io_ports (
664 struct acpi_resource *resource,
665 void *context)
667 struct acpi_ec *ec = (struct acpi_ec *) context;
668 struct acpi_generic_address *addr;
670 if (resource->id != ACPI_RSTYPE_IO) {
671 return AE_OK;
675 * The first address region returned is the data port, and
676 * the second address region returned is the status/command
677 * port.
679 if (ec->data_addr.register_bit_width == 0) {
680 addr = &ec->data_addr;
681 } else if (ec->command_addr.register_bit_width == 0) {
682 addr = &ec->command_addr;
683 } else {
684 return AE_CTRL_TERMINATE;
687 addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
688 addr->register_bit_width = 8;
689 addr->register_bit_offset = 0;
690 addr->address = resource->data.io.min_base_address;
692 return AE_OK;
696 static int
697 acpi_ec_start (
698 struct acpi_device *device)
700 acpi_status status = AE_OK;
701 struct acpi_ec *ec = NULL;
703 ACPI_FUNCTION_TRACE("acpi_ec_start");
705 if (!device)
706 return_VALUE(-EINVAL);
708 ec = acpi_driver_data(device);
710 if (!ec)
711 return_VALUE(-EINVAL);
714 * Get I/O port addresses. Convert to GAS format.
716 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
717 acpi_ec_io_ports, ec);
718 if (ACPI_FAILURE(status) || ec->command_addr.register_bit_width == 0) {
719 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses"));
720 return_VALUE(-ENODEV);
723 ec->status_addr = ec->command_addr;
725 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
726 (u32) ec->gpe_bit, (u32) ec->command_addr.address,
727 (u32) ec->data_addr.address));
730 * Install GPE handler
732 status = acpi_install_gpe_handler(NULL, ec->gpe_bit,
733 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec);
734 if (ACPI_FAILURE(status)) {
735 return_VALUE(-ENODEV);
737 acpi_set_gpe_type (NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
738 acpi_enable_gpe (NULL, ec->gpe_bit, ACPI_NOT_ISR);
740 status = acpi_install_address_space_handler (ec->handle,
741 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
742 &acpi_ec_space_setup, ec);
743 if (ACPI_FAILURE(status)) {
744 acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler);
745 return_VALUE(-ENODEV);
748 return_VALUE(AE_OK);
752 static int
753 acpi_ec_stop (
754 struct acpi_device *device,
755 int type)
757 acpi_status status = AE_OK;
758 struct acpi_ec *ec = NULL;
760 ACPI_FUNCTION_TRACE("acpi_ec_stop");
762 if (!device)
763 return_VALUE(-EINVAL);
765 ec = acpi_driver_data(device);
767 status = acpi_remove_address_space_handler(ec->handle,
768 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
769 if (ACPI_FAILURE(status))
770 return_VALUE(-ENODEV);
772 status = acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler);
773 if (ACPI_FAILURE(status))
774 return_VALUE(-ENODEV);
776 return_VALUE(0);
780 int __init
781 acpi_ec_ecdt_probe (void)
783 acpi_status status;
784 struct acpi_table_ecdt *ecdt_ptr;
786 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
787 (struct acpi_table_header **) &ecdt_ptr);
788 if (ACPI_FAILURE(status))
789 return 0;
791 printk(KERN_INFO PREFIX "Found ECDT\n");
794 * Generate a temporary ec context to use until the namespace is scanned
796 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
797 if (!ec_ecdt)
798 return -ENOMEM;
799 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
801 ec_ecdt->command_addr = ecdt_ptr->ec_control;
802 ec_ecdt->status_addr = ecdt_ptr->ec_control;
803 ec_ecdt->data_addr = ecdt_ptr->ec_data;
804 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
805 ec_ecdt->lock = SPIN_LOCK_UNLOCKED;
806 /* use the GL just to be safe */
807 ec_ecdt->global_lock = TRUE;
808 ec_ecdt->uid = ecdt_ptr->uid;
810 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
811 if (ACPI_FAILURE(status)) {
812 goto error;
816 * Install GPE handler
818 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit,
819 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler,
820 ec_ecdt);
821 if (ACPI_FAILURE(status)) {
822 goto error;
824 acpi_set_gpe_type (NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
825 acpi_enable_gpe (NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR);
827 status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT,
828 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
829 &acpi_ec_space_setup, ec_ecdt);
830 if (ACPI_FAILURE(status)) {
831 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
832 &acpi_ec_gpe_handler);
833 goto error;
836 return 0;
838 error:
839 printk(KERN_ERR PREFIX "Could not use ECDT\n");
840 kfree(ec_ecdt);
841 ec_ecdt = NULL;
843 return -ENODEV;
847 static int __init acpi_ec_init (void)
849 int result = 0;
851 ACPI_FUNCTION_TRACE("acpi_ec_init");
853 if (acpi_disabled)
854 return_VALUE(0);
856 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
857 if (!acpi_ec_dir)
858 return_VALUE(-ENODEV);
860 /* Now register the driver for the EC */
861 result = acpi_bus_register_driver(&acpi_ec_driver);
862 if (result < 0) {
863 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
864 return_VALUE(-ENODEV);
867 return_VALUE(result);
870 subsys_initcall(acpi_ec_init);
872 /* EC driver currently not unloadable */
873 #if 0
874 static void __exit
875 acpi_ec_exit (void)
877 ACPI_FUNCTION_TRACE("acpi_ec_exit");
879 acpi_bus_unregister_driver(&acpi_ec_driver);
881 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
883 return_VOID;
885 #endif /* 0 */