2 * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/delay.h>
32 #include <linux/proc_fs.h>
33 #include <linux/seq_file.h>
35 #include <acpi/acpi_bus.h>
36 #include <acpi/acpi_drivers.h>
37 #include <acpi/actypes.h>
39 #define _COMPONENT ACPI_EC_COMPONENT
40 ACPI_MODULE_NAME ("acpi_ec")
42 #define ACPI_EC_COMPONENT 0x00100000
43 #define ACPI_EC_CLASS "embedded_controller"
44 #define ACPI_EC_HID "PNP0C09"
45 #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
47 #define ACPI_EC_FILE_INFO "info"
50 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
52 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
54 #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
55 #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
57 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
58 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
59 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
61 #define ACPI_EC_COMMAND_READ 0x80
62 #define ACPI_EC_COMMAND_WRITE 0x81
63 #define ACPI_EC_COMMAND_QUERY 0x84
65 static int acpi_ec_add (struct acpi_device
*device
);
66 static int acpi_ec_remove (struct acpi_device
*device
, int type
);
67 static int acpi_ec_start (struct acpi_device
*device
);
68 static int acpi_ec_stop (struct acpi_device
*device
, int type
);
70 static struct acpi_driver acpi_ec_driver
= {
71 .name
= ACPI_EC_DRIVER_NAME
,
72 .class = ACPI_EC_CLASS
,
76 .remove
= acpi_ec_remove
,
77 .start
= acpi_ec_start
,
85 unsigned long gpe_bit
;
86 struct acpi_generic_address status_addr
;
87 struct acpi_generic_address command_addr
;
88 struct acpi_generic_address data_addr
;
89 unsigned long global_lock
;
93 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
94 static struct acpi_ec
*ec_ecdt
;
96 /* External interfaces use first EC only, so remember */
97 static struct acpi_device
*first_ec
;
99 /* --------------------------------------------------------------------------
100 Transaction Management
101 -------------------------------------------------------------------------- */
108 u32 acpi_ec_status
= 0;
109 u32 i
= ACPI_EC_UDELAY_COUNT
;
114 /* Poll the EC status register waiting for the event to occur. */
116 case ACPI_EC_EVENT_OBF
:
118 acpi_hw_low_level_read(8, &acpi_ec_status
, &ec
->status_addr
);
119 if (acpi_ec_status
& ACPI_EC_FLAG_OBF
)
121 udelay(ACPI_EC_UDELAY
);
124 case ACPI_EC_EVENT_IBE
:
126 acpi_hw_low_level_read(8, &acpi_ec_status
, &ec
->status_addr
);
127 if (!(acpi_ec_status
& ACPI_EC_FLAG_IBF
))
129 udelay(ACPI_EC_UDELAY
);
146 acpi_status status
= AE_OK
;
148 unsigned long flags
= 0;
151 ACPI_FUNCTION_TRACE("acpi_ec_read");
154 return_VALUE(-EINVAL
);
158 if (ec
->global_lock
) {
159 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
160 if (ACPI_FAILURE(status
))
161 return_VALUE(-ENODEV
);
164 spin_lock_irqsave(&ec
->lock
, flags
);
166 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ
, &ec
->command_addr
);
167 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
171 acpi_hw_low_level_write(8, address
, &ec
->data_addr
);
172 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
177 acpi_hw_low_level_read(8, data
, &ec
->data_addr
);
179 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Read [%02x] from address [%02x]\n",
183 spin_unlock_irqrestore(&ec
->lock
, flags
);
186 acpi_release_global_lock(glk
);
188 return_VALUE(result
);
199 acpi_status status
= AE_OK
;
200 unsigned long flags
= 0;
203 ACPI_FUNCTION_TRACE("acpi_ec_write");
206 return_VALUE(-EINVAL
);
208 if (ec
->global_lock
) {
209 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
210 if (ACPI_FAILURE(status
))
211 return_VALUE(-ENODEV
);
214 spin_lock_irqsave(&ec
->lock
, flags
);
216 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE
, &ec
->command_addr
);
217 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
221 acpi_hw_low_level_write(8, address
, &ec
->data_addr
);
222 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
226 acpi_hw_low_level_write(8, data
, &ec
->data_addr
);
227 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
231 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Wrote [%02x] to address [%02x]\n",
235 spin_unlock_irqrestore(&ec
->lock
, flags
);
238 acpi_release_global_lock(glk
);
240 return_VALUE(result
);
244 * Externally callable EC access functions. For now, assume 1 EC only
247 ec_read(u8 addr
, u8
*val
)
256 ec
= acpi_driver_data(first_ec
);
258 err
= acpi_ec_read(ec
, addr
, &temp_data
);
267 EXPORT_SYMBOL(ec_read
);
270 ec_write(u8 addr
, u8 val
)
278 ec
= acpi_driver_data(first_ec
);
280 err
= acpi_ec_write(ec
, addr
, val
);
284 EXPORT_SYMBOL(ec_write
);
293 acpi_status status
= AE_OK
;
294 unsigned long flags
= 0;
297 ACPI_FUNCTION_TRACE("acpi_ec_query");
300 return_VALUE(-EINVAL
);
304 if (ec
->global_lock
) {
305 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
306 if (ACPI_FAILURE(status
))
307 return_VALUE(-ENODEV
);
311 * Query the EC to find out which _Qxx method we need to evaluate.
312 * Note that successful completion of the query causes the ACPI_EC_SCI
313 * bit to be cleared (and thus clearing the interrupt source).
315 spin_lock_irqsave(&ec
->lock
, flags
);
317 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY
, &ec
->command_addr
);
318 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
322 acpi_hw_low_level_read(8, data
, &ec
->data_addr
);
327 spin_unlock_irqrestore(&ec
->lock
, flags
);
330 acpi_release_global_lock(glk
);
332 return_VALUE(result
);
336 /* --------------------------------------------------------------------------
338 -------------------------------------------------------------------------- */
340 struct acpi_ec_query_data
{
349 struct acpi_ec
*ec
= (struct acpi_ec
*) ec_cxt
;
351 unsigned long flags
= 0;
352 static char object_name
[5] = {'_','Q','0','0','\0'};
353 const char hex
[] = {'0','1','2','3','4','5','6','7',
354 '8','9','A','B','C','D','E','F'};
356 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
361 spin_lock_irqsave(&ec
->lock
, flags
);
362 acpi_hw_low_level_read(8, &value
, &ec
->command_addr
);
363 spin_unlock_irqrestore(&ec
->lock
, flags
);
365 /* TBD: Implement asynch events!
366 * NOTE: All we care about are EC-SCI's. Other EC events are
367 * handled via polling (yuck!). This is because some systems
368 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
369 * a purely interrupt-driven approach (grumble, grumble).
371 if (!(value
& ACPI_EC_FLAG_SCI
))
374 if (acpi_ec_query(ec
, &value
))
377 object_name
[2] = hex
[((value
>> 4) & 0x0F)];
378 object_name
[3] = hex
[(value
& 0x0F)];
380 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Evaluating %s\n", object_name
));
382 acpi_evaluate_object(ec
->handle
, object_name
, NULL
, NULL
);
385 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
389 acpi_ec_gpe_handler (
392 acpi_status status
= AE_OK
;
393 struct acpi_ec
*ec
= (struct acpi_ec
*) data
;
396 return ACPI_INTERRUPT_NOT_HANDLED
;
398 acpi_disable_gpe(NULL
, ec
->gpe_bit
, ACPI_ISR
);
400 status
= acpi_os_queue_for_execution(OSD_PRIORITY_GPE
,
401 acpi_ec_gpe_query
, ec
);
404 return ACPI_INTERRUPT_HANDLED
;
406 return ACPI_INTERRUPT_NOT_HANDLED
;
409 /* --------------------------------------------------------------------------
410 Address Space Management
411 -------------------------------------------------------------------------- */
414 acpi_ec_space_setup (
415 acpi_handle region_handle
,
417 void *handler_context
,
418 void **return_context
)
421 * The EC object is in the handler context and is needed
422 * when calling the acpi_ec_space_handler.
424 if(function
== ACPI_REGION_DEACTIVATE
)
425 *return_context
= NULL
;
427 *return_context
= handler_context
;
434 acpi_ec_space_handler (
436 acpi_physical_address address
,
439 void *handler_context
,
440 void *region_context
)
443 struct acpi_ec
*ec
= NULL
;
445 acpi_integer f_v
= 0;
448 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
450 if ((address
> 0xFF) || !value
|| !handler_context
)
451 return_VALUE(AE_BAD_PARAMETER
);
454 printk(KERN_WARNING PREFIX
"acpi_ec_space_handler: bit_width should be 8\n");
456 return_VALUE(AE_BAD_PARAMETER
);
459 ec
= (struct acpi_ec
*) handler_context
;
464 result
= acpi_ec_read(ec
, (u8
) address
, &temp
);
465 *value
= (acpi_integer
) temp
;
468 result
= acpi_ec_write(ec
, (u8
) address
, (u8
) *value
);
479 if(function
== ACPI_READ
)
480 f_v
|= (acpi_integer
) (*value
) << 8*i
;
481 if(function
== ACPI_WRITE
)
488 if(function
== ACPI_READ
){
489 f_v
|= (acpi_integer
) (*value
) << 8*i
;
497 return_VALUE(AE_BAD_PARAMETER
);
500 return_VALUE(AE_NOT_FOUND
);
503 return_VALUE(AE_TIME
);
513 /* --------------------------------------------------------------------------
515 -------------------------------------------------------------------------- */
517 static struct proc_dir_entry
*acpi_ec_dir
;
521 acpi_ec_read_info (struct seq_file
*seq
, void *offset
)
523 struct acpi_ec
*ec
= (struct acpi_ec
*) seq
->private;
525 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
530 seq_printf(seq
, "gpe bit: 0x%02x\n",
532 seq_printf(seq
, "ports: 0x%02x, 0x%02x\n",
533 (u32
) ec
->status_addr
.address
, (u32
) ec
->data_addr
.address
);
534 seq_printf(seq
, "use global lock: %s\n",
535 ec
->global_lock
?"yes":"no");
541 static int acpi_ec_info_open_fs(struct inode
*inode
, struct file
*file
)
543 return single_open(file
, acpi_ec_read_info
, PDE(inode
)->data
);
546 static struct file_operations acpi_ec_info_ops
= {
547 .open
= acpi_ec_info_open_fs
,
550 .release
= single_release
,
551 .owner
= THIS_MODULE
,
556 struct acpi_device
*device
)
558 struct proc_dir_entry
*entry
= NULL
;
560 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
562 if (!acpi_device_dir(device
)) {
563 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
565 if (!acpi_device_dir(device
))
566 return_VALUE(-ENODEV
);
569 entry
= create_proc_entry(ACPI_EC_FILE_INFO
, S_IRUGO
,
570 acpi_device_dir(device
));
572 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
573 "Unable to create '%s' fs entry\n",
576 entry
->proc_fops
= &acpi_ec_info_ops
;
577 entry
->data
= acpi_driver_data(device
);
578 entry
->owner
= THIS_MODULE
;
587 struct acpi_device
*device
)
589 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
591 if (acpi_device_dir(device
)) {
592 remove_proc_entry(ACPI_EC_FILE_INFO
, acpi_device_dir(device
));
593 remove_proc_entry(acpi_device_bid(device
), acpi_ec_dir
);
594 acpi_device_dir(device
) = NULL
;
601 /* --------------------------------------------------------------------------
603 -------------------------------------------------------------------------- */
607 struct acpi_device
*device
)
610 acpi_status status
= AE_OK
;
611 struct acpi_ec
*ec
= NULL
;
614 ACPI_FUNCTION_TRACE("acpi_ec_add");
617 return_VALUE(-EINVAL
);
619 ec
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
621 return_VALUE(-ENOMEM
);
622 memset(ec
, 0, sizeof(struct acpi_ec
));
624 ec
->handle
= device
->handle
;
626 spin_lock_init(&ec
->lock
);
627 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
628 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
629 acpi_driver_data(device
) = ec
;
631 /* Use the global lock for all EC transactions? */
632 acpi_evaluate_integer(ec
->handle
, "_GLK", NULL
, &ec
->global_lock
);
634 /* If our UID matches the UID for the ECDT-enumerated EC,
635 we now have the *real* EC info, so kill the makeshift one.*/
636 acpi_evaluate_integer(ec
->handle
, "_UID", NULL
, &uid
);
637 if (ec_ecdt
&& ec_ecdt
->uid
== uid
) {
638 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
639 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
);
641 acpi_remove_gpe_handler(NULL
, ec_ecdt
->gpe_bit
, &acpi_ec_gpe_handler
);
646 /* Get GPE bit assignment (EC events). */
647 /* TODO: Add support for _GPE returning a package */
648 status
= acpi_evaluate_integer(ec
->handle
, "_GPE", NULL
, &ec
->gpe_bit
);
649 if (ACPI_FAILURE(status
)) {
650 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
651 "Error obtaining GPE bit assignment\n"));
656 result
= acpi_ec_add_fs(device
);
660 printk(KERN_INFO PREFIX
"%s [%s] (gpe %d)\n",
661 acpi_device_name(device
), acpi_device_bid(device
),
671 return_VALUE(result
);
677 struct acpi_device
*device
,
680 struct acpi_ec
*ec
= NULL
;
682 ACPI_FUNCTION_TRACE("acpi_ec_remove");
685 return_VALUE(-EINVAL
);
687 ec
= acpi_driver_data(device
);
689 acpi_ec_remove_fs(device
);
699 struct acpi_resource
*resource
,
702 struct acpi_ec
*ec
= (struct acpi_ec
*) context
;
703 struct acpi_generic_address
*addr
;
705 if (resource
->id
!= ACPI_RSTYPE_IO
) {
710 * The first address region returned is the data port, and
711 * the second address region returned is the status/command
714 if (ec
->data_addr
.register_bit_width
== 0) {
715 addr
= &ec
->data_addr
;
716 } else if (ec
->command_addr
.register_bit_width
== 0) {
717 addr
= &ec
->command_addr
;
719 return AE_CTRL_TERMINATE
;
722 addr
->address_space_id
= ACPI_ADR_SPACE_SYSTEM_IO
;
723 addr
->register_bit_width
= 8;
724 addr
->register_bit_offset
= 0;
725 addr
->address
= resource
->data
.io
.min_base_address
;
733 struct acpi_device
*device
)
735 acpi_status status
= AE_OK
;
736 struct acpi_ec
*ec
= NULL
;
738 ACPI_FUNCTION_TRACE("acpi_ec_start");
741 return_VALUE(-EINVAL
);
743 ec
= acpi_driver_data(device
);
746 return_VALUE(-EINVAL
);
749 * Get I/O port addresses. Convert to GAS format.
751 status
= acpi_walk_resources(ec
->handle
, METHOD_NAME__CRS
,
752 acpi_ec_io_ports
, ec
);
753 if (ACPI_FAILURE(status
) || ec
->command_addr
.register_bit_width
== 0) {
754 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error getting I/O port addresses"));
755 return_VALUE(-ENODEV
);
758 ec
->status_addr
= ec
->command_addr
;
760 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
761 (u32
) ec
->gpe_bit
, (u32
) ec
->command_addr
.address
,
762 (u32
) ec
->data_addr
.address
));
765 * Install GPE handler
767 status
= acpi_install_gpe_handler(NULL
, ec
->gpe_bit
,
768 ACPI_GPE_EDGE_TRIGGERED
, &acpi_ec_gpe_handler
, ec
);
769 if (ACPI_FAILURE(status
)) {
770 return_VALUE(-ENODEV
);
772 acpi_set_gpe_type (NULL
, ec
->gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
773 acpi_enable_gpe (NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
775 status
= acpi_install_address_space_handler (ec
->handle
,
776 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
,
777 &acpi_ec_space_setup
, ec
);
778 if (ACPI_FAILURE(status
)) {
779 acpi_remove_gpe_handler(NULL
, ec
->gpe_bit
, &acpi_ec_gpe_handler
);
780 return_VALUE(-ENODEV
);
789 struct acpi_device
*device
,
792 acpi_status status
= AE_OK
;
793 struct acpi_ec
*ec
= NULL
;
795 ACPI_FUNCTION_TRACE("acpi_ec_stop");
798 return_VALUE(-EINVAL
);
800 ec
= acpi_driver_data(device
);
802 status
= acpi_remove_address_space_handler(ec
->handle
,
803 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
);
804 if (ACPI_FAILURE(status
))
805 return_VALUE(-ENODEV
);
807 status
= acpi_remove_gpe_handler(NULL
, ec
->gpe_bit
, &acpi_ec_gpe_handler
);
808 if (ACPI_FAILURE(status
))
809 return_VALUE(-ENODEV
);
814 static acpi_status __init
815 acpi_fake_ecdt_callback (
823 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
824 acpi_ec_io_ports
, ec_ecdt
);
825 if (ACPI_FAILURE(status
))
827 ec_ecdt
->status_addr
= ec_ecdt
->command_addr
;
830 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->uid
);
832 status
= acpi_evaluate_integer(handle
, "_GPE", NULL
, &ec_ecdt
->gpe_bit
);
833 if (ACPI_FAILURE(status
))
835 spin_lock_init(&ec_ecdt
->lock
);
836 ec_ecdt
->global_lock
= TRUE
;
837 ec_ecdt
->handle
= handle
;
839 printk(KERN_INFO PREFIX
"GPE=0x%02x, ports=0x%2x, 0x%2x\n",
840 (u32
) ec_ecdt
->gpe_bit
, (u32
) ec_ecdt
->command_addr
.address
,
841 (u32
) ec_ecdt
->data_addr
.address
);
843 return AE_CTRL_TERMINATE
;
847 * Some BIOS (such as some from Gateway laptops) access EC region very early
848 * such as in BAT0._INI or EC._INI before an EC device is found and
849 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
850 * required, but if EC regison is accessed early, it is required.
851 * The routine tries to workaround the BIOS bug by pre-scan EC device
852 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
853 * op region (since _REG isn't invoked yet). The assumption is true for
857 acpi_ec_fake_ecdt(void)
862 printk(KERN_INFO PREFIX
"Try to make an fake ECDT\n");
864 ec_ecdt
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
869 memset(ec_ecdt
, 0, sizeof(struct acpi_ec
));
871 status
= acpi_get_devices (ACPI_EC_HID
,
872 acpi_fake_ecdt_callback
,
875 if (ACPI_FAILURE(status
)) {
883 printk(KERN_ERR PREFIX
"Can't make an fake ECDT\n");
888 acpi_ec_get_real_ecdt(void)
891 struct acpi_table_ecdt
*ecdt_ptr
;
893 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
894 (struct acpi_table_header
**) &ecdt_ptr
);
895 if (ACPI_FAILURE(status
))
898 printk(KERN_INFO PREFIX
"Found ECDT\n");
901 * Generate a temporary ec context to use until the namespace is scanned
903 ec_ecdt
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
906 memset(ec_ecdt
, 0, sizeof(struct acpi_ec
));
908 ec_ecdt
->command_addr
= ecdt_ptr
->ec_control
;
909 ec_ecdt
->status_addr
= ecdt_ptr
->ec_control
;
910 ec_ecdt
->data_addr
= ecdt_ptr
->ec_data
;
911 ec_ecdt
->gpe_bit
= ecdt_ptr
->gpe_bit
;
912 spin_lock_init(&ec_ecdt
->lock
);
913 /* use the GL just to be safe */
914 ec_ecdt
->global_lock
= TRUE
;
915 ec_ecdt
->uid
= ecdt_ptr
->uid
;
917 status
= acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->handle
);
918 if (ACPI_FAILURE(status
)) {
924 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
931 static int __initdata acpi_fake_ecdt_enabled
;
933 acpi_ec_ecdt_probe (void)
938 ret
= acpi_ec_get_real_ecdt();
939 /* Try to make a fake ECDT */
940 if (ret
&& acpi_fake_ecdt_enabled
) {
941 ret
= acpi_ec_fake_ecdt();
948 * Install GPE handler
950 status
= acpi_install_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
951 ACPI_GPE_EDGE_TRIGGERED
, &acpi_ec_gpe_handler
,
953 if (ACPI_FAILURE(status
)) {
956 acpi_set_gpe_type (NULL
, ec_ecdt
->gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
957 acpi_enable_gpe (NULL
, ec_ecdt
->gpe_bit
, ACPI_NOT_ISR
);
959 status
= acpi_install_address_space_handler (ACPI_ROOT_OBJECT
,
960 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
,
961 &acpi_ec_space_setup
, ec_ecdt
);
962 if (ACPI_FAILURE(status
)) {
963 acpi_remove_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
964 &acpi_ec_gpe_handler
);
971 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
979 static int __init
acpi_ec_init (void)
983 ACPI_FUNCTION_TRACE("acpi_ec_init");
988 acpi_ec_dir
= proc_mkdir(ACPI_EC_CLASS
, acpi_root_dir
);
990 return_VALUE(-ENODEV
);
992 /* Now register the driver for the EC */
993 result
= acpi_bus_register_driver(&acpi_ec_driver
);
995 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
996 return_VALUE(-ENODEV
);
999 return_VALUE(result
);
1002 subsys_initcall(acpi_ec_init
);
1004 /* EC driver currently not unloadable */
1009 ACPI_FUNCTION_TRACE("acpi_ec_exit");
1011 acpi_bus_unregister_driver(&acpi_ec_driver
);
1013 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1019 static int __init
acpi_fake_ecdt_setup(char *str
)
1021 acpi_fake_ecdt_enabled
= 1;
1024 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup
);