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")
43 #define ACPI_EC_COMPONENT 0x00100000
44 #define ACPI_EC_CLASS "embedded_controller"
45 #define ACPI_EC_HID "PNP0C09"
46 #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
47 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
48 #define ACPI_EC_FILE_INFO "info"
51 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
52 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
53 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
54 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
56 #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
57 #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
59 #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
60 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
62 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
63 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
65 #define ACPI_EC_COMMAND_READ 0x80
66 #define ACPI_EC_COMMAND_WRITE 0x81
67 #define ACPI_EC_BURST_ENABLE 0x82
68 #define ACPI_EC_BURST_DISABLE 0x83
69 #define ACPI_EC_COMMAND_QUERY 0x84
71 #define EC_POLLING 0xFF
75 static int acpi_ec_remove (struct acpi_device
*device
, int type
);
76 static int acpi_ec_start (struct acpi_device
*device
);
77 static int acpi_ec_stop (struct acpi_device
*device
, int type
);
78 static int acpi_ec_burst_add ( struct acpi_device
*device
);
80 static struct acpi_driver acpi_ec_driver
= {
81 .name
= ACPI_EC_DRIVER_NAME
,
82 .class = ACPI_EC_CLASS
,
85 .add
= acpi_ec_burst_add
,
86 .remove
= acpi_ec_remove
,
87 .start
= acpi_ec_start
,
96 unsigned long gpe_bit
;
97 struct acpi_generic_address status_addr
;
98 struct acpi_generic_address command_addr
;
99 struct acpi_generic_address data_addr
;
100 unsigned long global_lock
;
107 unsigned long gpe_bit
;
108 struct acpi_generic_address status_addr
;
109 struct acpi_generic_address command_addr
;
110 struct acpi_generic_address data_addr
;
111 unsigned long global_lock
;
112 unsigned int expect_event
;
113 atomic_t leaving_burst
; /* 0 : No, 1 : Yes, 2: abort*/
114 atomic_t pending_gpe
;
115 struct semaphore sem
;
116 wait_queue_head_t wait
;
123 unsigned long gpe_bit
;
124 struct acpi_generic_address status_addr
;
125 struct acpi_generic_address command_addr
;
126 struct acpi_generic_address data_addr
;
127 unsigned long global_lock
;
132 static int acpi_ec_polling_wait ( union acpi_ec
*ec
, u8 event
);
133 static int acpi_ec_burst_wait(union acpi_ec
*ec
, unsigned int event
);
134 static int acpi_ec_polling_read ( union acpi_ec
*ec
, u8 address
, u32
*data
);
135 static int acpi_ec_burst_read( union acpi_ec
*ec
, u8 address
, u32
*data
);
136 static int acpi_ec_polling_write ( union acpi_ec
*ec
, u8 address
, u8 data
);
137 static int acpi_ec_burst_write ( union acpi_ec
*ec
, u8 address
, u8 data
);
138 static int acpi_ec_polling_query ( union acpi_ec
*ec
, u32
*data
);
139 static int acpi_ec_burst_query ( union acpi_ec
*ec
, u32
*data
);
140 static void acpi_ec_gpe_polling_query ( void *ec_cxt
);
141 static void acpi_ec_gpe_burst_query ( void *ec_cxt
);
142 static u32
acpi_ec_gpe_polling_handler ( void *data
);
143 static u32
acpi_ec_gpe_burst_handler ( void *data
);
144 static acpi_status __init
145 acpi_fake_ecdt_polling_callback (
151 static acpi_status __init
152 acpi_fake_ecdt_burst_callback (
159 acpi_ec_polling_get_real_ecdt(void);
161 acpi_ec_burst_get_real_ecdt(void);
162 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
163 static union acpi_ec
*ec_ecdt
;
165 /* External interfaces use first EC only, so remember */
166 static struct acpi_device
*first_ec
;
167 static int acpi_ec_polling_mode
;
169 /* --------------------------------------------------------------------------
170 Transaction Management
171 -------------------------------------------------------------------------- */
173 static inline u32
acpi_ec_read_status(union acpi_ec
*ec
)
177 acpi_hw_low_level_read(8, &status
, &ec
->common
.status_addr
);
186 if (acpi_ec_polling_mode
)
187 return acpi_ec_polling_wait (ec
, event
);
189 return acpi_ec_burst_wait (ec
, event
);
193 acpi_ec_polling_wait (
197 u32 acpi_ec_status
= 0;
198 u32 i
= ACPI_EC_UDELAY_COUNT
;
203 /* Poll the EC status register waiting for the event to occur. */
205 case ACPI_EC_EVENT_OBF
:
207 acpi_hw_low_level_read(8, &acpi_ec_status
, &ec
->common
.status_addr
);
208 if (acpi_ec_status
& ACPI_EC_FLAG_OBF
)
210 udelay(ACPI_EC_UDELAY
);
213 case ACPI_EC_EVENT_IBE
:
215 acpi_hw_low_level_read(8, &acpi_ec_status
, &ec
->common
.status_addr
);
216 if (!(acpi_ec_status
& ACPI_EC_FLAG_IBF
))
218 udelay(ACPI_EC_UDELAY
);
227 static int acpi_ec_burst_wait(union acpi_ec
*ec
, unsigned int event
)
231 ACPI_FUNCTION_TRACE("acpi_ec_wait");
233 ec
->burst
.expect_event
= event
;
236 result
= wait_event_interruptible_timeout(ec
->burst
.wait
,
237 !ec
->burst
.expect_event
,
238 msecs_to_jiffies(ACPI_EC_DELAY
));
240 ec
->burst
.expect_event
= 0;
244 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
," result = %d ", result
));
245 return_VALUE(result
);
249 * Verify that the event in question has actually happened by
250 * querying EC status. Do the check even if operation timed-out
251 * to make sure that we did not miss interrupt.
254 case ACPI_EC_EVENT_OBF
:
255 if (acpi_ec_read_status(ec
) & ACPI_EC_FLAG_OBF
)
259 case ACPI_EC_EVENT_IBE
:
260 if (~acpi_ec_read_status(ec
) & ACPI_EC_FLAG_IBF
)
265 return_VALUE(-ETIME
);
271 acpi_ec_enter_burst_mode (
277 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
279 status
= acpi_ec_read_status(ec
);
280 if (status
!= -EINVAL
&&
281 !(status
& ACPI_EC_FLAG_BURST
)){
282 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE
, &ec
->common
.command_addr
);
283 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
285 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
286 return_VALUE(-EINVAL
);
288 acpi_hw_low_level_read(8, &tmp
, &ec
->common
.data_addr
);
289 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
290 if(tmp
!= 0x90 ) {/* Burst ACK byte*/
291 return_VALUE(-EINVAL
);
295 atomic_set(&ec
->burst
.leaving_burst
, 0);
300 acpi_ec_leave_burst_mode (
305 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
307 atomic_set(&ec
->burst
.leaving_burst
, 1);
308 status
= acpi_ec_read_status(ec
);
309 if (status
!= -EINVAL
&&
310 (status
& ACPI_EC_FLAG_BURST
)){
311 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE
, &ec
->common
.command_addr
);
312 status
= acpi_ec_wait(ec
, ACPI_EC_FLAG_IBF
);
314 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
315 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,"------->wait fail\n"));
316 return_VALUE(-EINVAL
);
318 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
319 status
= acpi_ec_read_status(ec
);
331 if (acpi_ec_polling_mode
)
332 return acpi_ec_polling_read(ec
, address
, data
);
334 return acpi_ec_burst_read(ec
, address
, data
);
342 if (acpi_ec_polling_mode
)
343 return acpi_ec_polling_write(ec
, address
, data
);
345 return acpi_ec_burst_write(ec
, address
, data
);
348 acpi_ec_polling_read (
353 acpi_status status
= AE_OK
;
355 unsigned long flags
= 0;
358 ACPI_FUNCTION_TRACE("acpi_ec_read");
361 return_VALUE(-EINVAL
);
365 if (ec
->common
.global_lock
) {
366 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
367 if (ACPI_FAILURE(status
))
368 return_VALUE(-ENODEV
);
371 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
373 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ
, &ec
->common
.command_addr
);
374 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
378 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
379 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
383 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
385 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Read [%02x] from address [%02x]\n",
389 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
391 if (ec
->common
.global_lock
)
392 acpi_release_global_lock(glk
);
394 return_VALUE(result
);
399 acpi_ec_polling_write (
405 acpi_status status
= AE_OK
;
406 unsigned long flags
= 0;
409 ACPI_FUNCTION_TRACE("acpi_ec_write");
412 return_VALUE(-EINVAL
);
414 if (ec
->common
.global_lock
) {
415 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
416 if (ACPI_FAILURE(status
))
417 return_VALUE(-ENODEV
);
420 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
422 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE
, &ec
->common
.command_addr
);
423 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
427 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
428 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
432 acpi_hw_low_level_write(8, data
, &ec
->common
.data_addr
);
433 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
437 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Wrote [%02x] to address [%02x]\n",
441 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
443 if (ec
->common
.global_lock
)
444 acpi_release_global_lock(glk
);
446 return_VALUE(result
);
458 ACPI_FUNCTION_TRACE("acpi_ec_read");
461 return_VALUE(-EINVAL
);
466 if (ec
->common
.global_lock
) {
467 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
468 if (ACPI_FAILURE(status
))
469 return_VALUE(-ENODEV
);
472 WARN_ON(in_interrupt());
473 down(&ec
->burst
.sem
);
475 if(acpi_ec_enter_burst_mode(ec
))
478 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ
, &ec
->common
.command_addr
);
479 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
480 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
485 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
486 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
488 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
492 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
493 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
495 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Read [%02x] from address [%02x]\n",
499 acpi_ec_leave_burst_mode(ec
);
502 if (ec
->common
.global_lock
)
503 acpi_release_global_lock(glk
);
505 if(atomic_read(&ec
->burst
.leaving_burst
) == 2){
506 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,"aborted, retry ...\n"));
507 while(atomic_read(&ec
->burst
.pending_gpe
)){
510 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
514 return_VALUE(status
);
519 acpi_ec_burst_write (
528 ACPI_FUNCTION_TRACE("acpi_ec_write");
531 return_VALUE(-EINVAL
);
533 if (ec
->common
.global_lock
) {
534 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
535 if (ACPI_FAILURE(status
))
536 return_VALUE(-ENODEV
);
539 WARN_ON(in_interrupt());
540 down(&ec
->burst
.sem
);
542 if(acpi_ec_enter_burst_mode(ec
))
545 status
= acpi_ec_read_status(ec
);
546 if (status
!= -EINVAL
&&
547 !(status
& ACPI_EC_FLAG_BURST
)){
548 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE
, &ec
->common
.command_addr
);
549 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
552 acpi_hw_low_level_read(8, &tmp
, &ec
->common
.data_addr
);
553 if(tmp
!= 0x90 ) /* Burst ACK byte*/
556 /*Now we are in burst mode*/
558 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE
, &ec
->common
.command_addr
);
559 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
560 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
565 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
566 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
568 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
572 acpi_hw_low_level_write(8, data
, &ec
->common
.data_addr
);
573 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
574 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
578 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Wrote [%02x] to address [%02x]\n",
582 acpi_ec_leave_burst_mode(ec
);
585 if (ec
->common
.global_lock
)
586 acpi_release_global_lock(glk
);
588 if(atomic_read(&ec
->burst
.leaving_burst
) == 2){
589 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,"aborted, retry ...\n"));
590 while(atomic_read(&ec
->burst
.pending_gpe
)){
593 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
597 return_VALUE(status
);
601 * Externally callable EC access functions. For now, assume 1 EC only
604 ec_read(u8 addr
, u8
*val
)
613 ec
= acpi_driver_data(first_ec
);
615 err
= acpi_ec_read(ec
, addr
, &temp_data
);
624 EXPORT_SYMBOL(ec_read
);
627 ec_write(u8 addr
, u8 val
)
635 ec
= acpi_driver_data(first_ec
);
637 err
= acpi_ec_write(ec
, addr
, val
);
641 EXPORT_SYMBOL(ec_write
);
648 if (acpi_ec_polling_mode
)
649 return acpi_ec_polling_query(ec
, data
);
651 return acpi_ec_burst_query(ec
, data
);
654 acpi_ec_polling_query (
659 acpi_status status
= AE_OK
;
660 unsigned long flags
= 0;
663 ACPI_FUNCTION_TRACE("acpi_ec_query");
666 return_VALUE(-EINVAL
);
670 if (ec
->common
.global_lock
) {
671 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
672 if (ACPI_FAILURE(status
))
673 return_VALUE(-ENODEV
);
677 * Query the EC to find out which _Qxx method we need to evaluate.
678 * Note that successful completion of the query causes the ACPI_EC_SCI
679 * bit to be cleared (and thus clearing the interrupt source).
681 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
683 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY
, &ec
->common
.command_addr
);
684 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
688 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
693 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
695 if (ec
->common
.global_lock
)
696 acpi_release_global_lock(glk
);
698 return_VALUE(result
);
701 acpi_ec_burst_query (
708 ACPI_FUNCTION_TRACE("acpi_ec_query");
711 return_VALUE(-EINVAL
);
714 if (ec
->common
.global_lock
) {
715 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
716 if (ACPI_FAILURE(status
))
717 return_VALUE(-ENODEV
);
720 down(&ec
->burst
.sem
);
721 if(acpi_ec_enter_burst_mode(ec
))
724 * Query the EC to find out which _Qxx method we need to evaluate.
725 * Note that successful completion of the query causes the ACPI_EC_SCI
726 * bit to be cleared (and thus clearing the interrupt source).
728 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY
, &ec
->common
.command_addr
);
729 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
731 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
735 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
736 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
741 acpi_ec_leave_burst_mode(ec
);
744 if (ec
->common
.global_lock
)
745 acpi_release_global_lock(glk
);
747 if(atomic_read(&ec
->burst
.leaving_burst
) == 2){
748 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,"aborted, retry ...\n"));
749 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
752 return_VALUE(status
);
756 /* --------------------------------------------------------------------------
758 -------------------------------------------------------------------------- */
760 union acpi_ec_query_data
{
769 if (acpi_ec_polling_mode
)
770 acpi_ec_gpe_polling_query(ec_cxt
);
772 acpi_ec_gpe_burst_query(ec_cxt
);
776 acpi_ec_gpe_polling_query (
779 union acpi_ec
*ec
= (union acpi_ec
*) ec_cxt
;
781 unsigned long flags
= 0;
782 static char object_name
[5] = {'_','Q','0','0','\0'};
783 const char hex
[] = {'0','1','2','3','4','5','6','7',
784 '8','9','A','B','C','D','E','F'};
786 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
791 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
792 acpi_hw_low_level_read(8, &value
, &ec
->common
.command_addr
);
793 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
795 /* TBD: Implement asynch events!
796 * NOTE: All we care about are EC-SCI's. Other EC events are
797 * handled via polling (yuck!). This is because some systems
798 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
799 * a purely interrupt-driven approach (grumble, grumble).
801 if (!(value
& ACPI_EC_FLAG_SCI
))
804 if (acpi_ec_query(ec
, &value
))
807 object_name
[2] = hex
[((value
>> 4) & 0x0F)];
808 object_name
[3] = hex
[(value
& 0x0F)];
810 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Evaluating %s\n", object_name
));
812 acpi_evaluate_object(ec
->common
.handle
, object_name
, NULL
, NULL
);
815 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
818 acpi_ec_gpe_burst_query (
821 union acpi_ec
*ec
= (union acpi_ec
*) ec_cxt
;
823 int result
= -ENODATA
;
824 static char object_name
[5] = {'_','Q','0','0','\0'};
825 const char hex
[] = {'0','1','2','3','4','5','6','7',
826 '8','9','A','B','C','D','E','F'};
828 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
830 if (acpi_ec_read_status(ec
) & ACPI_EC_FLAG_SCI
)
831 result
= acpi_ec_query(ec
, &value
);
836 object_name
[2] = hex
[((value
>> 4) & 0x0F)];
837 object_name
[3] = hex
[(value
& 0x0F)];
839 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Evaluating %s\n", object_name
));
841 acpi_evaluate_object(ec
->common
.handle
, object_name
, NULL
, NULL
);
843 atomic_dec(&ec
->burst
.pending_gpe
);
848 acpi_ec_gpe_handler (
851 if (acpi_ec_polling_mode
)
852 return acpi_ec_gpe_polling_handler(data
);
854 return acpi_ec_gpe_burst_handler(data
);
857 acpi_ec_gpe_polling_handler (
860 acpi_status status
= AE_OK
;
861 union acpi_ec
*ec
= (union acpi_ec
*) data
;
864 return ACPI_INTERRUPT_NOT_HANDLED
;
866 acpi_disable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_ISR
);
868 status
= acpi_os_queue_for_execution(OSD_PRIORITY_GPE
,
869 acpi_ec_gpe_query
, ec
);
872 return ACPI_INTERRUPT_HANDLED
;
874 return ACPI_INTERRUPT_NOT_HANDLED
;
877 acpi_ec_gpe_burst_handler (
880 acpi_status status
= AE_OK
;
882 union acpi_ec
*ec
= (union acpi_ec
*) data
;
885 return ACPI_INTERRUPT_NOT_HANDLED
;
887 acpi_disable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_ISR
);
889 value
= acpi_ec_read_status(ec
);
891 if((value
& ACPI_EC_FLAG_IBF
) &&
892 !(value
& ACPI_EC_FLAG_BURST
) &&
893 (atomic_read(&ec
->burst
.leaving_burst
) == 0)) {
895 * the embedded controller disables
896 * burst mode for any reason other
897 * than the burst disable command
898 * to process critical event.
900 atomic_set(&ec
->burst
.leaving_burst
, 2); /* block current pending transaction
902 wake_up(&ec
->burst
.wait
);
904 if ((ec
->burst
.expect_event
== ACPI_EC_EVENT_OBF
&&
905 (value
& ACPI_EC_FLAG_OBF
)) ||
906 (ec
->burst
.expect_event
== ACPI_EC_EVENT_IBE
&&
907 !(value
& ACPI_EC_FLAG_IBF
))) {
908 ec
->burst
.expect_event
= 0;
909 wake_up(&ec
->burst
.wait
);
910 return ACPI_INTERRUPT_HANDLED
;
914 if (value
& ACPI_EC_FLAG_SCI
){
915 atomic_add(1, &ec
->burst
.pending_gpe
) ;
916 status
= acpi_os_queue_for_execution(OSD_PRIORITY_GPE
,
917 acpi_ec_gpe_query
, ec
);
918 return status
== AE_OK
?
919 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
921 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_ISR
);
922 return status
== AE_OK
?
923 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
926 /* --------------------------------------------------------------------------
927 Address Space Management
928 -------------------------------------------------------------------------- */
931 acpi_ec_space_setup (
932 acpi_handle region_handle
,
934 void *handler_context
,
935 void **return_context
)
938 * The EC object is in the handler context and is needed
939 * when calling the acpi_ec_space_handler.
941 *return_context
= (function
!= ACPI_REGION_DEACTIVATE
) ?
942 handler_context
: NULL
;
949 acpi_ec_space_handler (
951 acpi_physical_address address
,
954 void *handler_context
,
955 void *region_context
)
958 union acpi_ec
*ec
= NULL
;
960 acpi_integer f_v
= 0;
963 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
965 if ((address
> 0xFF) || !value
|| !handler_context
)
966 return_VALUE(AE_BAD_PARAMETER
);
968 if (bit_width
!= 8 && acpi_strict
) {
969 printk(KERN_WARNING PREFIX
"acpi_ec_space_handler: bit_width should be 8\n");
970 return_VALUE(AE_BAD_PARAMETER
);
973 ec
= (union acpi_ec
*) handler_context
;
979 result
= acpi_ec_read(ec
, (u8
) address
, (u32
*)&temp
);
982 result
= acpi_ec_write(ec
, (u8
) address
, (u8
) temp
);
992 if (function
== ACPI_READ
)
993 f_v
|= temp
<< 8 * i
;
994 if (function
== ACPI_WRITE
)
1001 if (function
== ACPI_READ
) {
1002 f_v
|= temp
<< 8 * i
;
1010 return_VALUE(AE_BAD_PARAMETER
);
1013 return_VALUE(AE_NOT_FOUND
);
1016 return_VALUE(AE_TIME
);
1019 return_VALUE(AE_OK
);
1024 /* --------------------------------------------------------------------------
1025 FS Interface (/proc)
1026 -------------------------------------------------------------------------- */
1028 static struct proc_dir_entry
*acpi_ec_dir
;
1032 acpi_ec_read_info (struct seq_file
*seq
, void *offset
)
1034 union acpi_ec
*ec
= (union acpi_ec
*) seq
->private;
1036 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
1041 seq_printf(seq
, "gpe bit: 0x%02x\n",
1042 (u32
) ec
->common
.gpe_bit
);
1043 seq_printf(seq
, "ports: 0x%02x, 0x%02x\n",
1044 (u32
) ec
->common
.status_addr
.address
, (u32
) ec
->common
.data_addr
.address
);
1045 seq_printf(seq
, "use global lock: %s\n",
1046 ec
->common
.global_lock
?"yes":"no");
1047 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
1053 static int acpi_ec_info_open_fs(struct inode
*inode
, struct file
*file
)
1055 return single_open(file
, acpi_ec_read_info
, PDE(inode
)->data
);
1058 static struct file_operations acpi_ec_info_ops
= {
1059 .open
= acpi_ec_info_open_fs
,
1061 .llseek
= seq_lseek
,
1062 .release
= single_release
,
1063 .owner
= THIS_MODULE
,
1068 struct acpi_device
*device
)
1070 struct proc_dir_entry
*entry
= NULL
;
1072 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
1074 if (!acpi_device_dir(device
)) {
1075 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1077 if (!acpi_device_dir(device
))
1078 return_VALUE(-ENODEV
);
1081 entry
= create_proc_entry(ACPI_EC_FILE_INFO
, S_IRUGO
,
1082 acpi_device_dir(device
));
1084 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
1085 "Unable to create '%s' fs entry\n",
1086 ACPI_EC_FILE_INFO
));
1088 entry
->proc_fops
= &acpi_ec_info_ops
;
1089 entry
->data
= acpi_driver_data(device
);
1090 entry
->owner
= THIS_MODULE
;
1099 struct acpi_device
*device
)
1101 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
1103 if (acpi_device_dir(device
)) {
1104 remove_proc_entry(ACPI_EC_FILE_INFO
, acpi_device_dir(device
));
1105 remove_proc_entry(acpi_device_bid(device
), acpi_ec_dir
);
1106 acpi_device_dir(device
) = NULL
;
1113 /* --------------------------------------------------------------------------
1115 -------------------------------------------------------------------------- */
1119 acpi_ec_polling_add (
1120 struct acpi_device
*device
)
1123 acpi_status status
= AE_OK
;
1124 union acpi_ec
*ec
= NULL
;
1127 ACPI_FUNCTION_TRACE("acpi_ec_add");
1130 return_VALUE(-EINVAL
);
1132 ec
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1134 return_VALUE(-ENOMEM
);
1135 memset(ec
, 0, sizeof(union acpi_ec
));
1137 ec
->common
.handle
= device
->handle
;
1138 ec
->common
.uid
= -1;
1139 spin_lock_init(&ec
->polling
.lock
);
1140 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
1141 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
1142 acpi_driver_data(device
) = ec
;
1144 /* Use the global lock for all EC transactions? */
1145 acpi_evaluate_integer(ec
->common
.handle
, "_GLK", NULL
, &ec
->common
.global_lock
);
1147 /* If our UID matches the UID for the ECDT-enumerated EC,
1148 we now have the *real* EC info, so kill the makeshift one.*/
1149 acpi_evaluate_integer(ec
->common
.handle
, "_UID", NULL
, &uid
);
1150 if (ec_ecdt
&& ec_ecdt
->common
.uid
== uid
) {
1151 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
1152 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
);
1154 acpi_remove_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
, &acpi_ec_gpe_handler
);
1159 /* Get GPE bit assignment (EC events). */
1160 /* TODO: Add support for _GPE returning a package */
1161 status
= acpi_evaluate_integer(ec
->common
.handle
, "_GPE", NULL
, &ec
->common
.gpe_bit
);
1162 if (ACPI_FAILURE(status
)) {
1163 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1164 "Error obtaining GPE bit assignment\n"));
1169 result
= acpi_ec_add_fs(device
);
1173 printk(KERN_INFO PREFIX
"%s [%s] (gpe %d)\n",
1174 acpi_device_name(device
), acpi_device_bid(device
),
1175 (u32
) ec
->common
.gpe_bit
);
1184 return_VALUE(result
);
1188 struct acpi_device
*device
)
1191 acpi_status status
= AE_OK
;
1192 union acpi_ec
*ec
= NULL
;
1195 ACPI_FUNCTION_TRACE("acpi_ec_add");
1198 return_VALUE(-EINVAL
);
1200 ec
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1202 return_VALUE(-ENOMEM
);
1203 memset(ec
, 0, sizeof(union acpi_ec
));
1205 ec
->common
.handle
= device
->handle
;
1206 ec
->common
.uid
= -1;
1207 atomic_set(&ec
->burst
.pending_gpe
, 0);
1208 atomic_set(&ec
->burst
.leaving_burst
, 1);
1209 init_MUTEX(&ec
->burst
.sem
);
1210 init_waitqueue_head(&ec
->burst
.wait
);
1211 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
1212 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
1213 acpi_driver_data(device
) = ec
;
1215 /* Use the global lock for all EC transactions? */
1216 acpi_evaluate_integer(ec
->common
.handle
, "_GLK", NULL
, &ec
->common
.global_lock
);
1218 /* If our UID matches the UID for the ECDT-enumerated EC,
1219 we now have the *real* EC info, so kill the makeshift one.*/
1220 acpi_evaluate_integer(ec
->common
.handle
, "_UID", NULL
, &uid
);
1221 if (ec_ecdt
&& ec_ecdt
->common
.uid
== uid
) {
1222 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
1223 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
);
1225 acpi_remove_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
, &acpi_ec_gpe_handler
);
1230 /* Get GPE bit assignment (EC events). */
1231 /* TODO: Add support for _GPE returning a package */
1232 status
= acpi_evaluate_integer(ec
->common
.handle
, "_GPE", NULL
, &ec
->common
.gpe_bit
);
1233 if (ACPI_FAILURE(status
)) {
1234 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1235 "Error obtaining GPE bit assignment\n"));
1240 result
= acpi_ec_add_fs(device
);
1244 printk(KERN_INFO PREFIX
"%s [%s] (gpe %d)\n",
1245 acpi_device_name(device
), acpi_device_bid(device
),
1246 (u32
) ec
->common
.gpe_bit
);
1255 return_VALUE(result
);
1261 struct acpi_device
*device
,
1264 union acpi_ec
*ec
= NULL
;
1266 ACPI_FUNCTION_TRACE("acpi_ec_remove");
1269 return_VALUE(-EINVAL
);
1271 ec
= acpi_driver_data(device
);
1273 acpi_ec_remove_fs(device
);
1283 struct acpi_resource
*resource
,
1286 union acpi_ec
*ec
= (union acpi_ec
*) context
;
1287 struct acpi_generic_address
*addr
;
1289 if (resource
->id
!= ACPI_RSTYPE_IO
) {
1294 * The first address region returned is the data port, and
1295 * the second address region returned is the status/command
1298 if (ec
->common
.data_addr
.register_bit_width
== 0) {
1299 addr
= &ec
->common
.data_addr
;
1300 } else if (ec
->common
.command_addr
.register_bit_width
== 0) {
1301 addr
= &ec
->common
.command_addr
;
1303 return AE_CTRL_TERMINATE
;
1306 addr
->address_space_id
= ACPI_ADR_SPACE_SYSTEM_IO
;
1307 addr
->register_bit_width
= 8;
1308 addr
->register_bit_offset
= 0;
1309 addr
->address
= resource
->data
.io
.min_base_address
;
1317 struct acpi_device
*device
)
1319 acpi_status status
= AE_OK
;
1320 union acpi_ec
*ec
= NULL
;
1322 ACPI_FUNCTION_TRACE("acpi_ec_start");
1325 return_VALUE(-EINVAL
);
1327 ec
= acpi_driver_data(device
);
1330 return_VALUE(-EINVAL
);
1333 * Get I/O port addresses. Convert to GAS format.
1335 status
= acpi_walk_resources(ec
->common
.handle
, METHOD_NAME__CRS
,
1336 acpi_ec_io_ports
, ec
);
1337 if (ACPI_FAILURE(status
) || ec
->common
.command_addr
.register_bit_width
== 0) {
1338 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error getting I/O port addresses"));
1339 return_VALUE(-ENODEV
);
1342 ec
->common
.status_addr
= ec
->common
.command_addr
;
1344 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
1345 (u32
) ec
->common
.gpe_bit
, (u32
) ec
->common
.command_addr
.address
,
1346 (u32
) ec
->common
.data_addr
.address
));
1350 * Install GPE handler
1352 status
= acpi_install_gpe_handler(NULL
, ec
->common
.gpe_bit
,
1353 ACPI_GPE_EDGE_TRIGGERED
, &acpi_ec_gpe_handler
, ec
);
1354 if (ACPI_FAILURE(status
)) {
1355 return_VALUE(-ENODEV
);
1357 acpi_set_gpe_type (NULL
, ec
->common
.gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
1358 acpi_enable_gpe (NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
1360 status
= acpi_install_address_space_handler (ec
->common
.handle
,
1361 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
,
1362 &acpi_ec_space_setup
, ec
);
1363 if (ACPI_FAILURE(status
)) {
1364 acpi_remove_gpe_handler(NULL
, ec
->common
.gpe_bit
, &acpi_ec_gpe_handler
);
1365 return_VALUE(-ENODEV
);
1368 return_VALUE(AE_OK
);
1374 struct acpi_device
*device
,
1377 acpi_status status
= AE_OK
;
1378 union acpi_ec
*ec
= NULL
;
1380 ACPI_FUNCTION_TRACE("acpi_ec_stop");
1383 return_VALUE(-EINVAL
);
1385 ec
= acpi_driver_data(device
);
1387 status
= acpi_remove_address_space_handler(ec
->common
.handle
,
1388 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
);
1389 if (ACPI_FAILURE(status
))
1390 return_VALUE(-ENODEV
);
1392 status
= acpi_remove_gpe_handler(NULL
, ec
->common
.gpe_bit
, &acpi_ec_gpe_handler
);
1393 if (ACPI_FAILURE(status
))
1394 return_VALUE(-ENODEV
);
1399 static acpi_status __init
1400 acpi_fake_ecdt_callback (
1407 if (acpi_ec_polling_mode
)
1408 return acpi_fake_ecdt_polling_callback(handle
,
1409 Level
, context
, retval
);
1411 return acpi_fake_ecdt_burst_callback(handle
,
1412 Level
, context
, retval
);
1415 static acpi_status __init
1416 acpi_fake_ecdt_polling_callback (
1424 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
1425 acpi_ec_io_ports
, ec_ecdt
);
1426 if (ACPI_FAILURE(status
))
1428 ec_ecdt
->common
.status_addr
= ec_ecdt
->common
.command_addr
;
1430 ec_ecdt
->common
.uid
= -1;
1431 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->common
.uid
);
1433 status
= acpi_evaluate_integer(handle
, "_GPE", NULL
, &ec_ecdt
->common
.gpe_bit
);
1434 if (ACPI_FAILURE(status
))
1436 spin_lock_init(&ec_ecdt
->polling
.lock
);
1437 ec_ecdt
->common
.global_lock
= TRUE
;
1438 ec_ecdt
->common
.handle
= handle
;
1440 printk(KERN_INFO PREFIX
"GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1441 (u32
) ec_ecdt
->common
.gpe_bit
, (u32
) ec_ecdt
->common
.command_addr
.address
,
1442 (u32
) ec_ecdt
->common
.data_addr
.address
);
1444 return AE_CTRL_TERMINATE
;
1447 static acpi_status __init
1448 acpi_fake_ecdt_burst_callback (
1456 init_MUTEX(&ec_ecdt
->burst
.sem
);
1457 init_waitqueue_head(&ec_ecdt
->burst
.wait
);
1458 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
1459 acpi_ec_io_ports
, ec_ecdt
);
1460 if (ACPI_FAILURE(status
))
1462 ec_ecdt
->common
.status_addr
= ec_ecdt
->common
.command_addr
;
1464 ec_ecdt
->common
.uid
= -1;
1465 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->common
.uid
);
1467 status
= acpi_evaluate_integer(handle
, "_GPE", NULL
, &ec_ecdt
->common
.gpe_bit
);
1468 if (ACPI_FAILURE(status
))
1470 ec_ecdt
->common
.global_lock
= TRUE
;
1471 ec_ecdt
->common
.handle
= handle
;
1473 printk(KERN_INFO PREFIX
"GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1474 (u32
) ec_ecdt
->common
.gpe_bit
, (u32
) ec_ecdt
->common
.command_addr
.address
,
1475 (u32
) ec_ecdt
->common
.data_addr
.address
);
1477 return AE_CTRL_TERMINATE
;
1481 * Some BIOS (such as some from Gateway laptops) access EC region very early
1482 * such as in BAT0._INI or EC._INI before an EC device is found and
1483 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
1484 * required, but if EC regison is accessed early, it is required.
1485 * The routine tries to workaround the BIOS bug by pre-scan EC device
1486 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
1487 * op region (since _REG isn't invoked yet). The assumption is true for
1488 * all systems found.
1491 acpi_ec_fake_ecdt(void)
1496 printk(KERN_INFO PREFIX
"Try to make an fake ECDT\n");
1498 ec_ecdt
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1503 memset(ec_ecdt
, 0, sizeof(union acpi_ec
));
1505 status
= acpi_get_devices (ACPI_EC_HID
,
1506 acpi_fake_ecdt_callback
,
1509 if (ACPI_FAILURE(status
)) {
1517 printk(KERN_ERR PREFIX
"Can't make an fake ECDT\n");
1522 acpi_ec_get_real_ecdt(void)
1524 if (acpi_ec_polling_mode
)
1525 return acpi_ec_polling_get_real_ecdt();
1527 return acpi_ec_burst_get_real_ecdt();
1531 acpi_ec_polling_get_real_ecdt(void)
1534 struct acpi_table_ecdt
*ecdt_ptr
;
1536 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
1537 (struct acpi_table_header
**) &ecdt_ptr
);
1538 if (ACPI_FAILURE(status
))
1541 printk(KERN_INFO PREFIX
"Found ECDT\n");
1544 * Generate a temporary ec context to use until the namespace is scanned
1546 ec_ecdt
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1549 memset(ec_ecdt
, 0, sizeof(union acpi_ec
));
1551 ec_ecdt
->common
.command_addr
= ecdt_ptr
->ec_control
;
1552 ec_ecdt
->common
.status_addr
= ecdt_ptr
->ec_control
;
1553 ec_ecdt
->common
.data_addr
= ecdt_ptr
->ec_data
;
1554 ec_ecdt
->common
.gpe_bit
= ecdt_ptr
->gpe_bit
;
1555 spin_lock_init(&ec_ecdt
->polling
.lock
);
1556 /* use the GL just to be safe */
1557 ec_ecdt
->common
.global_lock
= TRUE
;
1558 ec_ecdt
->common
.uid
= ecdt_ptr
->uid
;
1560 status
= acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->common
.handle
);
1561 if (ACPI_FAILURE(status
)) {
1567 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
1576 acpi_ec_burst_get_real_ecdt(void)
1579 struct acpi_table_ecdt
*ecdt_ptr
;
1581 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
1582 (struct acpi_table_header
**) &ecdt_ptr
);
1583 if (ACPI_FAILURE(status
))
1586 printk(KERN_INFO PREFIX
"Found ECDT\n");
1589 * Generate a temporary ec context to use until the namespace is scanned
1591 ec_ecdt
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1594 memset(ec_ecdt
, 0, sizeof(union acpi_ec
));
1596 init_MUTEX(&ec_ecdt
->burst
.sem
);
1597 init_waitqueue_head(&ec_ecdt
->burst
.wait
);
1598 ec_ecdt
->common
.command_addr
= ecdt_ptr
->ec_control
;
1599 ec_ecdt
->common
.status_addr
= ecdt_ptr
->ec_control
;
1600 ec_ecdt
->common
.data_addr
= ecdt_ptr
->ec_data
;
1601 ec_ecdt
->common
.gpe_bit
= ecdt_ptr
->gpe_bit
;
1602 /* use the GL just to be safe */
1603 ec_ecdt
->common
.global_lock
= TRUE
;
1604 ec_ecdt
->common
.uid
= ecdt_ptr
->uid
;
1606 status
= acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->common
.handle
);
1607 if (ACPI_FAILURE(status
)) {
1613 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
1620 static int __initdata acpi_fake_ecdt_enabled
;
1622 acpi_ec_ecdt_probe (void)
1627 ret
= acpi_ec_get_real_ecdt();
1628 /* Try to make a fake ECDT */
1629 if (ret
&& acpi_fake_ecdt_enabled
) {
1630 ret
= acpi_ec_fake_ecdt();
1637 * Install GPE handler
1639 status
= acpi_install_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
,
1640 ACPI_GPE_EDGE_TRIGGERED
, &acpi_ec_gpe_handler
,
1642 if (ACPI_FAILURE(status
)) {
1645 acpi_set_gpe_type (NULL
, ec_ecdt
->common
.gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
1646 acpi_enable_gpe (NULL
, ec_ecdt
->common
.gpe_bit
, ACPI_NOT_ISR
);
1648 status
= acpi_install_address_space_handler (ACPI_ROOT_OBJECT
,
1649 ACPI_ADR_SPACE_EC
, &acpi_ec_space_handler
,
1650 &acpi_ec_space_setup
, ec_ecdt
);
1651 if (ACPI_FAILURE(status
)) {
1652 acpi_remove_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
,
1653 &acpi_ec_gpe_handler
);
1660 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
1668 static int __init
acpi_ec_init (void)
1672 ACPI_FUNCTION_TRACE("acpi_ec_init");
1677 acpi_ec_dir
= proc_mkdir(ACPI_EC_CLASS
, acpi_root_dir
);
1679 return_VALUE(-ENODEV
);
1681 /* Now register the driver for the EC */
1682 result
= acpi_bus_register_driver(&acpi_ec_driver
);
1684 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1685 return_VALUE(-ENODEV
);
1688 return_VALUE(result
);
1691 subsys_initcall(acpi_ec_init
);
1693 /* EC driver currently not unloadable */
1698 ACPI_FUNCTION_TRACE("acpi_ec_exit");
1700 acpi_bus_unregister_driver(&acpi_ec_driver
);
1702 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1708 static int __init
acpi_fake_ecdt_setup(char *str
)
1710 acpi_fake_ecdt_enabled
= 1;
1713 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup
);
1714 static int __init
acpi_ec_set_polling_mode(char *str
)
1716 acpi_ec_polling_mode
= EC_POLLING
;
1717 acpi_ec_driver
.ops
.add
= acpi_ec_polling_add
;
1720 __setup("ec_polling", acpi_ec_set_polling_mode
);