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"
49 /* EC status register */
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_BURST 0x10 /* burst mode */
53 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
56 #define ACPI_EC_COMMAND_READ 0x80
57 #define ACPI_EC_COMMAND_WRITE 0x81
58 #define ACPI_EC_BURST_ENABLE 0x82
59 #define ACPI_EC_BURST_DISABLE 0x83
60 #define ACPI_EC_COMMAND_QUERY 0x84
64 ACPI_EC_EVENT_OBF_1
= 1, /* Output buffer full */
65 ACPI_EC_EVENT_IBF_0
, /* Input buffer empty */
68 #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
69 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
70 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
71 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
74 EC_INTR
= 1, /* Output buffer full */
75 EC_POLL
, /* Input buffer empty */
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
= ACPI_EC_DRIVER_NAME
,
85 .class = ACPI_EC_CLASS
,
89 .remove
= acpi_ec_remove
,
90 .start
= acpi_ec_start
,
97 unsigned long gpe_bit
;
98 struct acpi_generic_address status_addr
;
99 struct acpi_generic_address command_addr
;
100 struct acpi_generic_address data_addr
;
101 unsigned long global_lock
;
102 struct semaphore sem
;
103 unsigned int expect_event
;
104 atomic_t leaving_burst
; /* 0 : No, 1 : Yes, 2: abort */
105 wait_queue_head_t wait
;
108 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
109 static struct acpi_ec
*ec_ecdt
;
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 u32
acpi_ec_read_status(struct acpi_ec
*ec
)
123 acpi_hw_low_level_read(8, &status
, &ec
->status_addr
);
127 static u32
acpi_ec_read_data(struct acpi_ec
*ec
)
131 acpi_hw_low_level_read(8, &data
, &ec
->data_addr
);
135 static void acpi_ec_write_cmd(struct acpi_ec
*ec
, u32 command
)
137 acpi_hw_low_level_write(8, command
, &ec
->command_addr
);
140 static void acpi_ec_write_data(struct acpi_ec
*ec
, u32 data
)
142 acpi_hw_low_level_write(8, data
, &ec
->data_addr
);
145 static int acpi_ec_check_status(u32 status
, u8 event
) {
148 case ACPI_EC_EVENT_OBF_1
:
149 if (status
& ACPI_EC_FLAG_OBF
)
152 case ACPI_EC_EVENT_IBF_0
:
153 if (!(status
& ACPI_EC_FLAG_IBF
))
163 static int acpi_ec_wait(struct acpi_ec
*ec
, u8 event
)
165 int i
= (acpi_ec_mode
== EC_POLL
) ? ACPI_EC_UDELAY_COUNT
: 0;
168 ec
->expect_event
= event
;
169 if (acpi_ec_check_status(acpi_ec_read_status(ec
), event
)) {
170 ec
->expect_event
= 0;
175 if (acpi_ec_mode
== EC_POLL
) {
176 udelay(ACPI_EC_UDELAY
);
178 time_left
= wait_event_timeout(ec
->wait
,
180 msecs_to_jiffies(ACPI_EC_DELAY
));
182 ec
->expect_event
= 0;
186 if (acpi_ec_check_status(acpi_ec_read_status(ec
), event
)) {
187 ec
->expect_event
= 0;
192 ec
->expect_event
= 0;
197 #ifdef ACPI_FUTURE_USAGE
199 * Note: samsung nv5000 doesn't work with ec burst mode.
200 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
202 int acpi_ec_enter_burst_mode(struct acpi_ec
*ec
)
208 status
= acpi_ec_read_status(ec
);
209 if (status
!= -EINVAL
&& !(status
& ACPI_EC_FLAG_BURST
)) {
210 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
213 acpi_ec_write_cmd(ec
, ACPI_EC_BURST_ENABLE
);
214 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF_1
);
215 tmp
= acpi_ec_read_data(ec
);
216 if (tmp
!= 0x90) { /* Burst ACK byte */
221 atomic_set(&ec
->leaving_burst
, 0);
224 ACPI_EXCEPTION((AE_INFO
, status
, "EC wait, burst mode"));
228 int acpi_ec_leave_burst_mode(struct acpi_ec
*ec
)
233 status
= acpi_ec_read_status(ec
);
234 if (status
!= -EINVAL
&& (status
& ACPI_EC_FLAG_BURST
)){
235 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
238 acpi_ec_write_cmd(ec
, ACPI_EC_BURST_DISABLE
);
239 acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
241 atomic_set(&ec
->leaving_burst
, 1);
244 ACPI_EXCEPTION((AE_INFO
, status
, "EC leave burst mode"));
247 #endif /* ACPI_FUTURE_USAGE */
249 static int acpi_ec_transaction_unlocked(struct acpi_ec
*ec
, u8 command
,
250 const u8
*wdata
, unsigned wdata_len
,
251 u8
*rdata
, unsigned rdata_len
)
255 acpi_ec_write_cmd(ec
, command
);
257 for (; wdata_len
> 0; wdata_len
--) {
258 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
261 acpi_ec_write_data(ec
, *(wdata
++));
264 if (command
== ACPI_EC_COMMAND_WRITE
) {
265 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
270 for (; rdata_len
> 0; rdata_len
--) {
273 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF_1
);
277 d
= acpi_ec_read_data(ec
);
284 static int acpi_ec_transaction(struct acpi_ec
*ec
, u8 command
,
285 const u8
*wdata
, unsigned wdata_len
,
286 u8
*rdata
, unsigned rdata_len
)
291 if (!ec
|| (wdata_len
&& !wdata
) || (rdata_len
&& !rdata
))
295 memset(rdata
, 0, rdata_len
);
297 if (ec
->global_lock
) {
298 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
299 if (ACPI_FAILURE(status
))
304 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBF_0
);
306 printk(KERN_DEBUG PREFIX
"read EC, IB not empty\n");
310 status
= acpi_ec_transaction_unlocked(ec
, command
,
318 acpi_release_global_lock(glk
);
323 static int acpi_ec_read(struct acpi_ec
*ec
, u8 address
, u32
* data
)
328 result
= acpi_ec_transaction(ec
, ACPI_EC_COMMAND_READ
,
333 static int acpi_ec_write(struct acpi_ec
*ec
, u8 address
, u8 data
)
335 u8 wdata
[2] = { address
, data
};
336 return acpi_ec_transaction(ec
, ACPI_EC_COMMAND_WRITE
,
341 * Externally callable EC access functions. For now, assume 1 EC only
343 int ec_read(u8 addr
, u8
* val
)
352 ec
= acpi_driver_data(first_ec
);
354 err
= acpi_ec_read(ec
, addr
, &temp_data
);
363 EXPORT_SYMBOL(ec_read
);
365 int ec_write(u8 addr
, u8 val
)
373 ec
= acpi_driver_data(first_ec
);
375 err
= acpi_ec_write(ec
, addr
, val
);
380 EXPORT_SYMBOL(ec_write
);
382 extern int ec_transaction(u8 command
,
383 const u8
*wdata
, unsigned wdata_len
,
384 u8
*rdata
, unsigned rdata_len
)
391 ec
= acpi_driver_data(first_ec
);
393 return acpi_ec_transaction(ec
, command
, wdata
,
394 wdata_len
, rdata
, rdata_len
);
397 static int acpi_ec_query(struct acpi_ec
*ec
, u32
* data
)
406 * Query the EC to find out which _Qxx method we need to evaluate.
407 * Note that successful completion of the query causes the ACPI_EC_SCI
408 * bit to be cleared (and thus clearing the interrupt source).
411 result
= acpi_ec_transaction(ec
, ACPI_EC_COMMAND_QUERY
, NULL
, 0, &d
, 1);
422 /* --------------------------------------------------------------------------
424 -------------------------------------------------------------------------- */
426 struct acpi_ec_query_data
{
431 static void acpi_ec_gpe_query(void *ec_cxt
)
433 struct acpi_ec
*ec
= (struct acpi_ec
*)ec_cxt
;
435 static char object_name
[5] = { '_', 'Q', '0', '0', '\0' };
436 const char hex
[] = { '0', '1', '2', '3', '4', '5', '6', '7',
437 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
444 value
= acpi_ec_read_status(ec
);
446 if (!(value
& ACPI_EC_FLAG_SCI
))
449 if (acpi_ec_query(ec
, &value
))
452 object_name
[2] = hex
[((value
>> 4) & 0x0F)];
453 object_name
[3] = hex
[(value
& 0x0F)];
455 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Evaluating %s", object_name
));
457 acpi_evaluate_object(ec
->handle
, object_name
, NULL
, NULL
);
460 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
463 static u32
acpi_ec_gpe_handler(void *data
)
465 acpi_status status
= AE_OK
;
468 struct acpi_ec
*ec
= (struct acpi_ec
*)data
;
470 acpi_clear_gpe(NULL
, ec
->gpe_bit
, ACPI_ISR
);
471 value
= acpi_ec_read_status(ec
);
473 if (acpi_ec_mode
== EC_INTR
) {
474 if (acpi_ec_check_status(value
, ec
->expect_event
)) {
475 ec
->expect_event
= 0;
478 exec_mode
= OSL_EC_BURST_HANDLER
;
480 exec_mode
= OSL_EC_POLL_HANDLER
;
483 if (value
& ACPI_EC_FLAG_SCI
) {
484 status
= acpi_os_execute(exec_mode
, acpi_ec_gpe_query
, ec
);
485 return status
== AE_OK
?
486 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
488 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_ISR
);
489 return status
== AE_OK
?
490 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
493 /* --------------------------------------------------------------------------
494 Address Space Management
495 -------------------------------------------------------------------------- */
498 acpi_ec_space_setup(acpi_handle region_handle
,
499 u32 function
, void *handler_context
, void **return_context
)
502 * The EC object is in the handler context and is needed
503 * when calling the acpi_ec_space_handler.
505 *return_context
= (function
!= ACPI_REGION_DEACTIVATE
) ?
506 handler_context
: NULL
;
512 acpi_ec_space_handler(u32 function
,
513 acpi_physical_address address
,
515 acpi_integer
* value
,
516 void *handler_context
, void *region_context
)
519 struct acpi_ec
*ec
= NULL
;
521 acpi_integer f_v
= 0;
525 if ((address
> 0xFF) || !value
|| !handler_context
)
526 return AE_BAD_PARAMETER
;
528 if (bit_width
!= 8 && acpi_strict
) {
529 return AE_BAD_PARAMETER
;
532 ec
= (struct acpi_ec
*)handler_context
;
538 result
= acpi_ec_read(ec
, (u8
) address
, (u32
*) & temp
);
541 result
= acpi_ec_write(ec
, (u8
) address
, (u8
) temp
);
551 if (function
== ACPI_READ
)
552 f_v
|= temp
<< 8 * i
;
553 if (function
== ACPI_WRITE
)
560 if (function
== ACPI_READ
) {
561 f_v
|= temp
<< 8 * i
;
568 return AE_BAD_PARAMETER
;
581 /* --------------------------------------------------------------------------
583 -------------------------------------------------------------------------- */
585 static struct proc_dir_entry
*acpi_ec_dir
;
587 static int acpi_ec_read_info(struct seq_file
*seq
, void *offset
)
589 struct acpi_ec
*ec
= (struct acpi_ec
*)seq
->private;
595 seq_printf(seq
, "gpe bit: 0x%02x\n",
597 seq_printf(seq
, "ports: 0x%02x, 0x%02x\n",
598 (u32
) ec
->status_addr
.address
,
599 (u32
) ec
->data_addr
.address
);
600 seq_printf(seq
, "use global lock: %s\n",
601 ec
->global_lock
? "yes" : "no");
602 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
608 static int acpi_ec_info_open_fs(struct inode
*inode
, struct file
*file
)
610 return single_open(file
, acpi_ec_read_info
, PDE(inode
)->data
);
613 static struct file_operations acpi_ec_info_ops
= {
614 .open
= acpi_ec_info_open_fs
,
617 .release
= single_release
,
618 .owner
= THIS_MODULE
,
621 static int acpi_ec_add_fs(struct acpi_device
*device
)
623 struct proc_dir_entry
*entry
= NULL
;
626 if (!acpi_device_dir(device
)) {
627 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
629 if (!acpi_device_dir(device
))
633 entry
= create_proc_entry(ACPI_EC_FILE_INFO
, S_IRUGO
,
634 acpi_device_dir(device
));
638 entry
->proc_fops
= &acpi_ec_info_ops
;
639 entry
->data
= acpi_driver_data(device
);
640 entry
->owner
= THIS_MODULE
;
646 static int acpi_ec_remove_fs(struct acpi_device
*device
)
649 if (acpi_device_dir(device
)) {
650 remove_proc_entry(ACPI_EC_FILE_INFO
, acpi_device_dir(device
));
651 remove_proc_entry(acpi_device_bid(device
), acpi_ec_dir
);
652 acpi_device_dir(device
) = NULL
;
658 /* --------------------------------------------------------------------------
660 -------------------------------------------------------------------------- */
662 static int acpi_ec_add(struct acpi_device
*device
)
665 acpi_status status
= AE_OK
;
666 struct acpi_ec
*ec
= NULL
;
672 ec
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
675 memset(ec
, 0, sizeof(struct acpi_ec
));
677 ec
->handle
= device
->handle
;
679 init_MUTEX(&ec
->sem
);
680 if (acpi_ec_mode
== EC_INTR
) {
681 atomic_set(&ec
->leaving_burst
, 1);
682 init_waitqueue_head(&ec
->wait
);
684 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
685 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
686 acpi_driver_data(device
) = ec
;
688 /* Use the global lock for all EC transactions? */
689 acpi_evaluate_integer(ec
->handle
, "_GLK", NULL
,
692 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
693 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
695 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
697 &acpi_ec_space_handler
);
699 acpi_remove_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
700 &acpi_ec_gpe_handler
);
705 /* Get GPE bit assignment (EC events). */
706 /* TODO: Add support for _GPE returning a package */
708 acpi_evaluate_integer(ec
->handle
, "_GPE", NULL
,
710 if (ACPI_FAILURE(status
)) {
711 ACPI_EXCEPTION((AE_INFO
, status
, "Obtaining GPE bit assignment"));
716 result
= acpi_ec_add_fs(device
);
720 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "%s [%s] (gpe %d) interrupt mode.",
721 acpi_device_name(device
), acpi_device_bid(device
),
734 static int acpi_ec_remove(struct acpi_device
*device
, int type
)
736 struct acpi_ec
*ec
= NULL
;
742 ec
= acpi_driver_data(device
);
744 acpi_ec_remove_fs(device
);
752 acpi_ec_io_ports(struct acpi_resource
*resource
, void *context
)
754 struct acpi_ec
*ec
= (struct acpi_ec
*)context
;
755 struct acpi_generic_address
*addr
;
757 if (resource
->type
!= ACPI_RESOURCE_TYPE_IO
) {
762 * The first address region returned is the data port, and
763 * the second address region returned is the status/command
766 if (ec
->data_addr
.register_bit_width
== 0) {
767 addr
= &ec
->data_addr
;
768 } else if (ec
->command_addr
.register_bit_width
== 0) {
769 addr
= &ec
->command_addr
;
771 return AE_CTRL_TERMINATE
;
774 addr
->address_space_id
= ACPI_ADR_SPACE_SYSTEM_IO
;
775 addr
->register_bit_width
= 8;
776 addr
->register_bit_offset
= 0;
777 addr
->address
= resource
->data
.io
.minimum
;
782 static int acpi_ec_start(struct acpi_device
*device
)
784 acpi_status status
= AE_OK
;
785 struct acpi_ec
*ec
= NULL
;
791 ec
= acpi_driver_data(device
);
797 * Get I/O port addresses. Convert to GAS format.
799 status
= acpi_walk_resources(ec
->handle
, METHOD_NAME__CRS
,
800 acpi_ec_io_ports
, ec
);
801 if (ACPI_FAILURE(status
)
802 || ec
->command_addr
.register_bit_width
== 0) {
803 ACPI_EXCEPTION((AE_INFO
, status
,
804 "Error getting I/O port addresses"));
808 ec
->status_addr
= ec
->command_addr
;
810 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "gpe=0x%02x, ports=0x%2x,0x%2x",
812 (u32
) ec
->command_addr
.address
,
813 (u32
) ec
->data_addr
.address
));
816 * Install GPE handler
818 status
= acpi_install_gpe_handler(NULL
, ec
->gpe_bit
,
819 ACPI_GPE_EDGE_TRIGGERED
,
820 &acpi_ec_gpe_handler
, ec
);
821 if (ACPI_FAILURE(status
)) {
824 acpi_set_gpe_type(NULL
, ec
->gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
825 acpi_enable_gpe(NULL
, ec
->gpe_bit
, ACPI_NOT_ISR
);
827 status
= acpi_install_address_space_handler(ec
->handle
,
829 &acpi_ec_space_handler
,
830 &acpi_ec_space_setup
, ec
);
831 if (ACPI_FAILURE(status
)) {
832 acpi_remove_gpe_handler(NULL
, ec
->gpe_bit
,
833 &acpi_ec_gpe_handler
);
840 static int acpi_ec_stop(struct acpi_device
*device
, int type
)
842 acpi_status status
= AE_OK
;
843 struct acpi_ec
*ec
= NULL
;
849 ec
= acpi_driver_data(device
);
851 status
= acpi_remove_address_space_handler(ec
->handle
,
853 &acpi_ec_space_handler
);
854 if (ACPI_FAILURE(status
))
858 acpi_remove_gpe_handler(NULL
, ec
->gpe_bit
,
859 &acpi_ec_gpe_handler
);
860 if (ACPI_FAILURE(status
))
866 static acpi_status __init
867 acpi_fake_ecdt_callback(acpi_handle handle
,
868 u32 Level
, void *context
, void **retval
)
872 init_MUTEX(&ec_ecdt
->sem
);
873 if (acpi_ec_mode
== EC_INTR
) {
874 init_waitqueue_head(&ec_ecdt
->wait
);
876 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
877 acpi_ec_io_ports
, ec_ecdt
);
878 if (ACPI_FAILURE(status
))
880 ec_ecdt
->status_addr
= ec_ecdt
->command_addr
;
883 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->uid
);
886 acpi_evaluate_integer(handle
, "_GPE", NULL
,
888 if (ACPI_FAILURE(status
))
890 ec_ecdt
->global_lock
= TRUE
;
891 ec_ecdt
->handle
= handle
;
893 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "GPE=0x%02x, ports=0x%2x, 0x%2x",
894 (u32
) ec_ecdt
->gpe_bit
,
895 (u32
) ec_ecdt
->command_addr
.address
,
896 (u32
) ec_ecdt
->data_addr
.address
));
898 return AE_CTRL_TERMINATE
;
902 * Some BIOS (such as some from Gateway laptops) access EC region very early
903 * such as in BAT0._INI or EC._INI before an EC device is found and
904 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
905 * required, but if EC regison is accessed early, it is required.
906 * The routine tries to workaround the BIOS bug by pre-scan EC device
907 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
908 * op region (since _REG isn't invoked yet). The assumption is true for
911 static int __init
acpi_ec_fake_ecdt(void)
916 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Try to make an fake ECDT"));
918 ec_ecdt
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
923 memset(ec_ecdt
, 0, sizeof(struct acpi_ec
));
925 status
= acpi_get_devices(ACPI_EC_HID
,
926 acpi_fake_ecdt_callback
, NULL
, NULL
);
927 if (ACPI_FAILURE(status
)) {
931 ACPI_EXCEPTION((AE_INFO
, status
, "Can't make an fake ECDT"));
939 static int __init
acpi_ec_get_real_ecdt(void)
942 struct acpi_table_ecdt
*ecdt_ptr
;
944 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
945 (struct acpi_table_header
**)
947 if (ACPI_FAILURE(status
))
950 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found ECDT"));
953 * Generate a temporary ec context to use until the namespace is scanned
955 ec_ecdt
= kmalloc(sizeof(struct acpi_ec
), GFP_KERNEL
);
958 memset(ec_ecdt
, 0, sizeof(struct acpi_ec
));
960 init_MUTEX(&ec_ecdt
->sem
);
961 if (acpi_ec_mode
== EC_INTR
) {
962 init_waitqueue_head(&ec_ecdt
->wait
);
964 ec_ecdt
->command_addr
= ecdt_ptr
->ec_control
;
965 ec_ecdt
->status_addr
= ecdt_ptr
->ec_control
;
966 ec_ecdt
->data_addr
= ecdt_ptr
->ec_data
;
967 ec_ecdt
->gpe_bit
= ecdt_ptr
->gpe_bit
;
968 /* use the GL just to be safe */
969 ec_ecdt
->global_lock
= TRUE
;
970 ec_ecdt
->uid
= ecdt_ptr
->uid
;
973 acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->handle
);
974 if (ACPI_FAILURE(status
)) {
980 ACPI_EXCEPTION((AE_INFO
, status
, "Could not use ECDT"));
987 static int __initdata acpi_fake_ecdt_enabled
;
988 int __init
acpi_ec_ecdt_probe(void)
993 ret
= acpi_ec_get_real_ecdt();
994 /* Try to make a fake ECDT */
995 if (ret
&& acpi_fake_ecdt_enabled
) {
996 ret
= acpi_ec_fake_ecdt();
1003 * Install GPE handler
1005 status
= acpi_install_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
1006 ACPI_GPE_EDGE_TRIGGERED
,
1007 &acpi_ec_gpe_handler
, ec_ecdt
);
1008 if (ACPI_FAILURE(status
)) {
1011 acpi_set_gpe_type(NULL
, ec_ecdt
->gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
1012 acpi_enable_gpe(NULL
, ec_ecdt
->gpe_bit
, ACPI_NOT_ISR
);
1014 status
= acpi_install_address_space_handler(ACPI_ROOT_OBJECT
,
1016 &acpi_ec_space_handler
,
1017 &acpi_ec_space_setup
,
1019 if (ACPI_FAILURE(status
)) {
1020 acpi_remove_gpe_handler(NULL
, ec_ecdt
->gpe_bit
,
1021 &acpi_ec_gpe_handler
);
1028 ACPI_EXCEPTION((AE_INFO
, status
, "Could not use ECDT"));
1035 static int __init
acpi_ec_init(void)
1043 acpi_ec_dir
= proc_mkdir(ACPI_EC_CLASS
, acpi_root_dir
);
1047 /* Now register the driver for the EC */
1048 result
= acpi_bus_register_driver(&acpi_ec_driver
);
1050 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1057 subsys_initcall(acpi_ec_init
);
1059 /* EC driver currently not unloadable */
1061 static void __exit
acpi_ec_exit(void)
1064 acpi_bus_unregister_driver(&acpi_ec_driver
);
1066 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1072 static int __init
acpi_fake_ecdt_setup(char *str
)
1074 acpi_fake_ecdt_enabled
= 1;
1078 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup
);
1079 static int __init
acpi_ec_set_intr_mode(char *str
)
1083 if (!get_option(&str
, &intr
))
1087 acpi_ec_mode
= EC_INTR
;
1089 acpi_ec_mode
= EC_POLL
;
1091 acpi_ec_driver
.ops
.add
= acpi_ec_add
;
1092 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "EC %s mode.\n", intr
? "interrupt" : "polling"));
1097 __setup("ec_intr=", acpi_ec_set_intr_mode
);