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>
34 #include <linux/interrupt.h>
36 #include <acpi/acpi_bus.h>
37 #include <acpi/acpi_drivers.h>
38 #include <acpi/actypes.h>
40 #define _COMPONENT ACPI_EC_COMPONENT
41 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 PREFIX "ACPI: EC: "
52 /* EC status register */
53 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
54 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
55 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
56 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
59 #define ACPI_EC_COMMAND_READ 0x80
60 #define ACPI_EC_COMMAND_WRITE 0x81
61 #define ACPI_EC_BURST_ENABLE 0x82
62 #define ACPI_EC_BURST_DISABLE 0x83
63 #define ACPI_EC_COMMAND_QUERY 0x84
67 ACPI_EC_EVENT_OBF_1
= 1, /* Output buffer full */
68 ACPI_EC_EVENT_IBF_0
, /* Input buffer empty */
71 #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
72 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
73 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
74 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 100ms max. during EC ops */
77 EC_INTR
= 1, /* Output buffer full */
78 EC_POLL
, /* Input buffer empty */
81 static int acpi_ec_remove(struct acpi_device
*device
, int type
);
82 static int acpi_ec_start(struct acpi_device
*device
);
83 static int acpi_ec_stop(struct acpi_device
*device
, int type
);
84 static int acpi_ec_add(struct acpi_device
*device
);
86 static struct acpi_driver acpi_ec_driver
= {
87 .name
= ACPI_EC_DRIVER_NAME
,
88 .class = ACPI_EC_CLASS
,
92 .remove
= acpi_ec_remove
,
93 .start
= acpi_ec_start
,
98 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
102 unsigned long gpe_bit
;
103 unsigned long command_addr
;
104 unsigned long data_addr
;
105 unsigned long global_lock
;
106 struct semaphore sem
;
107 atomic_t leaving_burst
; /* 0 : No, 1 : Yes, 2: abort */
108 wait_queue_head_t wait
;
111 /* External interfaces use first EC only, so remember */
112 static struct acpi_device
*first_ec
;
113 static int acpi_ec_mode
= EC_INTR
;
115 /* --------------------------------------------------------------------------
116 Transaction Management
117 -------------------------------------------------------------------------- */
119 static inline u8
acpi_ec_read_status(struct acpi_ec
*ec
)
121 return inb(ec
->command_addr
);
124 static inline u8
acpi_ec_read_data(struct acpi_ec
*ec
)
126 return inb(ec
->data_addr
);
129 static inline void acpi_ec_write_cmd(struct acpi_ec
*ec
, u8 command
)
131 outb(command
, ec
->command_addr
);
134 static inline void acpi_ec_write_data(struct acpi_ec
*ec
, u8 data
)
136 outb(data
, ec
->data_addr
);
139 static int acpi_ec_check_status(struct acpi_ec
*ec
, u8 event
)
141 u8 status
= acpi_ec_read_status(ec
);
143 case ACPI_EC_EVENT_OBF_1
:
144 if (status
& ACPI_EC_FLAG_OBF
)
147 case ACPI_EC_EVENT_IBF_0
:
148 if (!(status
& ACPI_EC_FLAG_IBF
))
158 static int acpi_ec_wait(struct acpi_ec
*ec
, u8 event
)
160 if (acpi_ec_mode
== EC_POLL
) {
162 for (i
= 0; i
< ACPI_EC_UDELAY_COUNT
; ++i
) {
163 if (acpi_ec_check_status(ec
, event
))
165 udelay(ACPI_EC_UDELAY
);
168 if (wait_event_timeout(ec
->wait
,
169 acpi_ec_check_status(ec
, event
),
170 msecs_to_jiffies(ACPI_EC_DELAY
)) ||
171 acpi_ec_check_status(ec
, event
)) {
174 printk(KERN_ERR PREFIX
"acpi_ec_wait timeout,"
175 " status = %d, expect_event = %d\n",
176 acpi_ec_read_status(ec
), event
);
183 #ifdef ACPI_FUTURE_USAGE
185 * Note: samsung nv5000 doesn't work with ec burst mode.
186 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
188 int acpi_ec_enter_burst_mode(struct acpi_ec
*ec
)
194 status
= acpi_ec_read_status(ec
);
195 if (status
!= -EINVAL
&& !(status
& ACPI_EC_FLAG_BURST
)) {
196 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
199 acpi_ec_write_cmd(ec
, ACPI_EC_BURST_ENABLE
);
200 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF_1
);
201 tmp
= acpi_ec_read_data(ec
);
202 if (tmp
!= 0x90) { /* Burst ACK byte */
207 atomic_set(&ec
->leaving_burst
, 0);
210 ACPI_EXCEPTION((AE_INFO
, status
, "EC wait, burst mode"));
214 int acpi_ec_leave_burst_mode(struct acpi_ec
*ec
)
219 status
= acpi_ec_read_status(ec
);
220 if (status
!= -EINVAL
&& (status
& ACPI_EC_FLAG_BURST
)){
221 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
224 acpi_ec_write_cmd(ec
, ACPI_EC_BURST_DISABLE
);
225 acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
227 atomic_set(&ec
->leaving_burst
, 1);
230 ACPI_EXCEPTION((AE_INFO
, status
, "EC leave burst mode"));
233 #endif /* ACPI_FUTURE_USAGE */
235 static int acpi_ec_transaction_unlocked(struct acpi_ec
*ec
, u8 command
,
236 const u8
*wdata
, unsigned wdata_len
,
237 u8
*rdata
, unsigned rdata_len
)
241 acpi_ec_write_cmd(ec
, command
);
243 for (; wdata_len
> 0; wdata_len
--) {
244 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
246 printk(KERN_ERR PREFIX
"write_cmd timeout, command = %d\n",
250 acpi_ec_write_data(ec
, *(wdata
++));
254 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
256 printk(KERN_ERR PREFIX
"finish-write timeout, command = %d\n",
262 for (; rdata_len
> 0; rdata_len
--) {
263 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF_1
);
265 printk(KERN_ERR PREFIX
"read timeout, command = %d\n",
270 *(rdata
++) = acpi_ec_read_data(ec
);
276 static int acpi_ec_transaction(struct acpi_ec
*ec
, u8 command
,
277 const u8
*wdata
, unsigned wdata_len
,
278 u8
*rdata
, unsigned rdata_len
)
283 if (!ec
|| (wdata_len
&& !wdata
) || (rdata_len
&& !rdata
))
287 memset(rdata
, 0, rdata_len
);
289 if (ec
->global_lock
) {
290 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
291 if (ACPI_FAILURE(status
))
296 /* Make sure GPE is enabled before doing transaction */
297 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
299 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
301 printk(KERN_DEBUG PREFIX
"read EC, IB not empty\n");
305 status
= acpi_ec_transaction_unlocked(ec
, command
,
313 acpi_release_global_lock(glk
);
318 static int acpi_ec_read(struct acpi_ec
*ec
, u8 address
, u8
*data
)
323 result
= acpi_ec_transaction(ec
, ACPI_EC_COMMAND_READ
,
329 static int acpi_ec_write(struct acpi_ec
*ec
, u8 address
, u8 data
)
331 u8 wdata
[2] = { address
, data
};
332 return acpi_ec_transaction(ec
, ACPI_EC_COMMAND_WRITE
,
337 * Externally callable EC access functions. For now, assume 1 EC only
339 int ec_read(u8 addr
, u8
*val
)
348 ec
= acpi_driver_data(first_ec
);
350 err
= acpi_ec_read(ec
, addr
, &temp_data
);
359 EXPORT_SYMBOL(ec_read
);
361 int ec_write(u8 addr
, u8 val
)
369 ec
= acpi_driver_data(first_ec
);
371 err
= acpi_ec_write(ec
, addr
, val
);
376 EXPORT_SYMBOL(ec_write
);
378 extern int ec_transaction(u8 command
,
379 const u8
*wdata
, unsigned wdata_len
,
380 u8
*rdata
, unsigned rdata_len
)
387 ec
= acpi_driver_data(first_ec
);
389 return acpi_ec_transaction(ec
, command
, wdata
,
390 wdata_len
, rdata
, rdata_len
);
393 EXPORT_SYMBOL(ec_transaction
);
395 static int acpi_ec_query(struct acpi_ec
*ec
, u8
*data
)
404 * Query the EC to find out which _Qxx method we need to evaluate.
405 * Note that successful completion of the query causes the ACPI_EC_SCI
406 * bit to be cleared (and thus clearing the interrupt source).
409 result
= acpi_ec_transaction(ec
, ACPI_EC_COMMAND_QUERY
, NULL
, 0, &d
, 1);
420 /* --------------------------------------------------------------------------
422 -------------------------------------------------------------------------- */
424 static void acpi_ec_gpe_query(void *ec_cxt
)
426 struct acpi_ec
*ec
= (struct acpi_ec
*)ec_cxt
;
428 static char object_name
[8];
433 value
= acpi_ec_read_status(ec
);
435 if (!(value
& ACPI_EC_FLAG_SCI
))
438 if (acpi_ec_query(ec
, &value
))
441 snprintf(object_name
, 8, "_Q%2.2X", value
);
443 printk(KERN_INFO PREFIX
"evaluating %s\n", object_name
);
445 acpi_evaluate_object(ec
->handle
, object_name
, NULL
, NULL
);
448 static u32
acpi_ec_gpe_handler(void *data
)
450 acpi_status status
= AE_OK
;
452 struct acpi_ec
*ec
= (struct acpi_ec
*)data
;
455 if (acpi_ec_mode
== EC_INTR
) {
459 value
= acpi_ec_read_status(ec
);
460 if (value
& ACPI_EC_FLAG_SCI
) {
461 status
= acpi_os_execute(OSL_EC_BURST_HANDLER
, acpi_ec_gpe_query
, ec
);
464 return status
== AE_OK
?
465 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
468 /* --------------------------------------------------------------------------
469 Address Space Management
470 -------------------------------------------------------------------------- */
473 acpi_ec_space_setup(acpi_handle region_handle
,
474 u32 function
, void *handler_context
, void **return_context
)
477 * The EC object is in the handler context and is needed
478 * when calling the acpi_ec_space_handler.
480 *return_context
= (function
!= ACPI_REGION_DEACTIVATE
) ?
481 handler_context
: NULL
;
487 acpi_ec_space_handler(u32 function
,
488 acpi_physical_address address
,
490 acpi_integer
* value
,
491 void *handler_context
, void *region_context
)
494 struct acpi_ec
*ec
= NULL
;
496 acpi_integer f_v
= 0;
500 if ((address
> 0xFF) || !value
|| !handler_context
)
501 return AE_BAD_PARAMETER
;
503 if (bit_width
!= 8 && acpi_strict
) {
504 return AE_BAD_PARAMETER
;
507 ec
= (struct acpi_ec
*)handler_context
;
513 result
= acpi_ec_read(ec
, (u8
) address
, (u8
*) &temp
);
516 result
= acpi_ec_write(ec
, (u8
) address
, (u8
) temp
);
526 if (function
== ACPI_READ
)
527 f_v
|= temp
<< 8 * i
;
528 if (function
== ACPI_WRITE
)
535 if (function
== ACPI_READ
) {
536 f_v
|= temp
<< 8 * i
;
543 return AE_BAD_PARAMETER
;
556 /* --------------------------------------------------------------------------
558 -------------------------------------------------------------------------- */
560 static struct proc_dir_entry
*acpi_ec_dir
;
562 static int acpi_ec_read_info(struct seq_file
*seq
, void *offset
)
564 struct acpi_ec
*ec
= (struct acpi_ec
*)seq
->private;
570 seq_printf(seq
, "gpe bit: 0x%02x\n",
572 seq_printf(seq
, "ports: 0x%02x, 0x%02x\n",
573 (u32
) ec
->command_addr
,
574 (u32
) ec
->data_addr
);
575 seq_printf(seq
, "use global lock: %s\n",
576 ec
->global_lock
? "yes" : "no");
577 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
583 static int acpi_ec_info_open_fs(struct inode
*inode
, struct file
*file
)
585 return single_open(file
, acpi_ec_read_info
, PDE(inode
)->data
);
588 static struct file_operations acpi_ec_info_ops
= {
589 .open
= acpi_ec_info_open_fs
,
592 .release
= single_release
,
593 .owner
= THIS_MODULE
,
596 static int acpi_ec_add_fs(struct acpi_device
*device
)
598 struct proc_dir_entry
*entry
= NULL
;
601 if (!acpi_device_dir(device
)) {
602 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
604 if (!acpi_device_dir(device
))
608 entry
= create_proc_entry(ACPI_EC_FILE_INFO
, S_IRUGO
,
609 acpi_device_dir(device
));
613 entry
->proc_fops
= &acpi_ec_info_ops
;
614 entry
->data
= acpi_driver_data(device
);
615 entry
->owner
= THIS_MODULE
;
621 static int acpi_ec_remove_fs(struct acpi_device
*device
)
624 if (acpi_device_dir(device
)) {
625 remove_proc_entry(ACPI_EC_FILE_INFO
, acpi_device_dir(device
));
626 remove_proc_entry(acpi_device_bid(device
), acpi_ec_dir
);
627 acpi_device_dir(device
) = NULL
;
633 /* --------------------------------------------------------------------------
635 -------------------------------------------------------------------------- */
637 static int acpi_ec_add(struct acpi_device
*device
)
640 acpi_status status
= AE_OK
;
641 struct acpi_ec
*ec
= NULL
;
647 ec
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
650 memset(ec
, 0, sizeof(struct acpi_ec
));
652 ec
->handle
= device
->handle
;
654 init_MUTEX(&ec
->sem
);
655 if (acpi_ec_mode
== EC_INTR
) {
656 atomic_set(&ec
->leaving_burst
, 1);
657 init_waitqueue_head(&ec
->wait
);
659 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
660 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
661 acpi_driver_data(device
) = ec
;
663 /* Use the global lock for all EC transactions? */
664 acpi_evaluate_integer(ec
->handle
, "_GLK", NULL
,
667 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
668 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
670 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
672 &acpi_ec_space_handler
);
674 acpi_remove_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
675 &acpi_ec_gpe_handler
);
680 /* Get GPE bit assignment (EC events). */
681 /* TODO: Add support for _GPE returning a package */
683 acpi_evaluate_integer(ec
->handle
, "_GPE", NULL
,
685 if (ACPI_FAILURE(status
)) {
686 ACPI_EXCEPTION((AE_INFO
, status
, "Obtaining GPE bit assignment"));
691 result
= acpi_ec_add_fs(device
);
695 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s [%s] (gpe %d) interrupt mode.",
696 acpi_device_name(device
), acpi_device_bid(device
),
709 static int acpi_ec_remove(struct acpi_device
*device
, int type
)
711 struct acpi_ec
*ec
= NULL
;
717 ec
= acpi_driver_data(device
);
719 acpi_ec_remove_fs(device
);
727 acpi_ec_io_ports(struct acpi_resource
*resource
, void *context
)
729 struct acpi_ec
*ec
= (struct acpi_ec
*)context
;
731 if (resource
->type
!= ACPI_RESOURCE_TYPE_IO
) {
736 * The first address region returned is the data port, and
737 * the second address region returned is the status/command
740 if (ec
->data_addr
== 0) {
741 ec
->data_addr
= resource
->data
.io
.minimum
;
742 } else if (ec
->command_addr
== 0) {
743 ec
->command_addr
= resource
->data
.io
.minimum
;
745 return AE_CTRL_TERMINATE
;
751 static int acpi_ec_start(struct acpi_device
*device
)
753 acpi_status status
= AE_OK
;
754 struct acpi_ec
*ec
= NULL
;
760 ec
= acpi_driver_data(device
);
766 * Get I/O port addresses. Convert to GAS format.
768 status
= acpi_walk_resources(ec
->handle
, METHOD_NAME__CRS
,
769 acpi_ec_io_ports
, ec
);
770 if (ACPI_FAILURE(status
) || ec
->command_addr
== 0) {
771 ACPI_EXCEPTION((AE_INFO
, status
,
772 "Error getting I/O port addresses"));
776 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
777 ec
->gpe_bit
, ec
->command_addr
, ec
->data_addr
));
780 * Install GPE handler
782 status
= acpi_install_gpe_handler(NULL
, ec
->gpe_bit
,
783 ACPI_GPE_EDGE_TRIGGERED
,
784 &acpi_ec_gpe_handler
, ec
);
785 if (ACPI_FAILURE(status
)) {
788 acpi_set_gpe_type(NULL
, ec
->gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
789 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
791 status
= acpi_install_address_space_handler(ec
->handle
,
793 &acpi_ec_space_handler
,
794 &acpi_ec_space_setup
, ec
);
795 if (ACPI_FAILURE(status
)) {
796 acpi_remove_gpe_handler(NULL
, ec
->gpe_bit
,
797 &acpi_ec_gpe_handler
);
804 static int acpi_ec_stop(struct acpi_device
*device
, int type
)
806 acpi_status status
= AE_OK
;
807 struct acpi_ec
*ec
= NULL
;
813 ec
= acpi_driver_data(device
);
815 status
= acpi_remove_address_space_handler(ec
->handle
,
817 &acpi_ec_space_handler
);
818 if (ACPI_FAILURE(status
))
822 acpi_remove_gpe_handler(NULL
, ec
->gpe_bit
,
823 &acpi_ec_gpe_handler
);
824 if (ACPI_FAILURE(status
))
830 static acpi_status __init
831 acpi_fake_ecdt_callback(acpi_handle handle
,
832 u32 Level
, void *context
, void **retval
)
836 init_MUTEX(&ec_ecdt
->sem
);
837 if (acpi_ec_mode
== EC_INTR
) {
838 init_waitqueue_head(&ec_ecdt
->wait
);
840 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
841 acpi_ec_io_ports
, ec_ecdt
);
842 if (ACPI_FAILURE(status
))
846 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->uid
);
849 acpi_evaluate_integer(handle
, "_GPE", NULL
,
851 if (ACPI_FAILURE(status
))
853 ec_ecdt
->global_lock
= TRUE
;
854 ec_ecdt
->handle
= handle
;
856 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
857 ec_ecdt
->gpe_bit
, ec_ecdt
->command_addr
, ec_ecdt
->data_addr
));
859 return AE_CTRL_TERMINATE
;
863 * Some BIOS (such as some from Gateway laptops) access EC region very early
864 * such as in BAT0._INI or EC._INI before an EC device is found and
865 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
866 * required, but if EC regison is accessed early, it is required.
867 * The routine tries to workaround the BIOS bug by pre-scan EC device
868 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
869 * op region (since _REG isn't invoked yet). The assumption is true for
872 static int __init
acpi_ec_fake_ecdt(void)
877 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Try to make an fake ECDT"));
879 ec_ecdt
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
884 memset(ec_ecdt
, 0, sizeof(struct acpi_ec
));
886 status
= acpi_get_devices(ACPI_EC_HID
,
887 acpi_fake_ecdt_callback
, NULL
, NULL
);
888 if (ACPI_FAILURE(status
)) {
892 ACPI_EXCEPTION((AE_INFO
, status
, "Can't make an fake ECDT"));
900 static int __init
acpi_ec_get_real_ecdt(void)
903 struct acpi_table_ecdt
*ecdt_ptr
;
905 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
906 (struct acpi_table_header
**)
908 if (ACPI_FAILURE(status
))
911 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found ECDT"));
914 * Generate a temporary ec context to use until the namespace is scanned
916 ec_ecdt
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
919 memset(ec_ecdt
, 0, sizeof(struct acpi_ec
));
921 init_MUTEX(&ec_ecdt
->sem
);
922 if (acpi_ec_mode
== EC_INTR
) {
923 init_waitqueue_head(&ec_ecdt
->wait
);
925 ec_ecdt
->command_addr
= ecdt_ptr
->ec_control
.address
;
926 ec_ecdt
->data_addr
= ecdt_ptr
->ec_data
.address
;
927 ec_ecdt
->gpe_bit
= ecdt_ptr
->gpe_bit
;
928 /* use the GL just to be safe */
929 ec_ecdt
->global_lock
= TRUE
;
930 ec_ecdt
->uid
= ecdt_ptr
->uid
;
933 acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->handle
);
934 if (ACPI_FAILURE(status
)) {
940 ACPI_EXCEPTION((AE_INFO
, status
, "Could not use ECDT"));
947 static int __initdata acpi_fake_ecdt_enabled
;
948 int __init
acpi_ec_ecdt_probe(void)
953 ret
= acpi_ec_get_real_ecdt();
954 /* Try to make a fake ECDT */
955 if (ret
&& acpi_fake_ecdt_enabled
) {
956 ret
= acpi_ec_fake_ecdt();
963 * Install GPE handler
965 status
= acpi_install_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
966 ACPI_GPE_EDGE_TRIGGERED
,
967 &acpi_ec_gpe_handler
, ec_ecdt
);
968 if (ACPI_FAILURE(status
)) {
971 acpi_set_gpe_type(NULL
, ec_ecdt
->gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
972 acpi_enable_gpe(NULL
, ec_ecdt
->gpe_bit
, ACPI_NOT_ISR
);
974 status
= acpi_install_address_space_handler(ACPI_ROOT_OBJECT
,
976 &acpi_ec_space_handler
,
977 &acpi_ec_space_setup
,
979 if (ACPI_FAILURE(status
)) {
980 acpi_remove_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
981 &acpi_ec_gpe_handler
);
988 ACPI_EXCEPTION((AE_INFO
, status
, "Could not use ECDT"));
995 static int __init
acpi_ec_init(void)
1003 acpi_ec_dir
= proc_mkdir(ACPI_EC_CLASS
, acpi_root_dir
);
1007 /* Now register the driver for the EC */
1008 result
= acpi_bus_register_driver(&acpi_ec_driver
);
1010 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1017 subsys_initcall(acpi_ec_init
);
1019 /* EC driver currently not unloadable */
1021 static void __exit
acpi_ec_exit(void)
1024 acpi_bus_unregister_driver(&acpi_ec_driver
);
1026 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1032 static int __init
acpi_fake_ecdt_setup(char *str
)
1034 acpi_fake_ecdt_enabled
= 1;
1038 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup
);
1039 static int __init
acpi_ec_set_intr_mode(char *str
)
1043 if (!get_option(&str
, &intr
))
1047 acpi_ec_mode
= EC_INTR
;
1049 acpi_ec_mode
= EC_POLL
;
1051 acpi_ec_driver
.ops
.add
= acpi_ec_add
;
1052 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "EC %s mode.\n", intr
? "interrupt" : "polling"));
1057 __setup("ec_intr=", acpi_ec_set_intr_mode
);