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"
48 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
49 #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
50 #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
51 #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
52 #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
53 #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
54 #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
55 #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
56 #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
57 #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
58 #define ACPI_EC_COMMAND_READ 0x80
59 #define ACPI_EC_COMMAND_WRITE 0x81
60 #define ACPI_EC_BURST_ENABLE 0x82
61 #define ACPI_EC_BURST_DISABLE 0x83
62 #define ACPI_EC_COMMAND_QUERY 0x84
63 #define EC_POLLING 0xFF
65 static int acpi_ec_remove(struct acpi_device
*device
, int type
);
66 static int acpi_ec_start(struct acpi_device
*device
);
67 static int acpi_ec_stop(struct acpi_device
*device
, int type
);
68 static int acpi_ec_burst_add(struct acpi_device
*device
);
69 static int acpi_ec_polling_add(struct acpi_device
*device
);
71 static struct acpi_driver acpi_ec_driver
= {
72 .name
= ACPI_EC_DRIVER_NAME
,
73 .class = ACPI_EC_CLASS
,
76 .add
= acpi_ec_polling_add
,
77 .remove
= acpi_ec_remove
,
78 .start
= acpi_ec_start
,
87 unsigned long gpe_bit
;
88 struct acpi_generic_address status_addr
;
89 struct acpi_generic_address command_addr
;
90 struct acpi_generic_address data_addr
;
91 unsigned long global_lock
;
98 unsigned long gpe_bit
;
99 struct acpi_generic_address status_addr
;
100 struct acpi_generic_address command_addr
;
101 struct acpi_generic_address data_addr
;
102 unsigned long global_lock
;
103 unsigned int expect_event
;
104 atomic_t leaving_burst
; /* 0 : No, 1 : Yes, 2: abort */
105 atomic_t pending_gpe
;
106 struct semaphore sem
;
107 wait_queue_head_t wait
;
114 unsigned long gpe_bit
;
115 struct acpi_generic_address status_addr
;
116 struct acpi_generic_address command_addr
;
117 struct acpi_generic_address data_addr
;
118 unsigned long global_lock
;
123 static int acpi_ec_polling_wait(union acpi_ec
*ec
, u8 event
);
124 static int acpi_ec_burst_wait(union acpi_ec
*ec
, unsigned int event
);
125 static int acpi_ec_polling_read(union acpi_ec
*ec
, u8 address
, u32
* data
);
126 static int acpi_ec_burst_read(union acpi_ec
*ec
, u8 address
, u32
* data
);
127 static int acpi_ec_polling_write(union acpi_ec
*ec
, u8 address
, u8 data
);
128 static int acpi_ec_burst_write(union acpi_ec
*ec
, u8 address
, u8 data
);
129 static int acpi_ec_polling_query(union acpi_ec
*ec
, u32
* data
);
130 static int acpi_ec_burst_query(union acpi_ec
*ec
, u32
* data
);
131 static void acpi_ec_gpe_polling_query(void *ec_cxt
);
132 static void acpi_ec_gpe_burst_query(void *ec_cxt
);
133 static u32
acpi_ec_gpe_polling_handler(void *data
);
134 static u32
acpi_ec_gpe_burst_handler(void *data
);
135 static acpi_status __init
136 acpi_fake_ecdt_polling_callback(acpi_handle handle
,
137 u32 Level
, void *context
, void **retval
);
139 static acpi_status __init
140 acpi_fake_ecdt_burst_callback(acpi_handle handle
,
141 u32 Level
, void *context
, void **retval
);
143 static int __init
acpi_ec_polling_get_real_ecdt(void);
144 static int __init
acpi_ec_burst_get_real_ecdt(void);
145 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
146 static union acpi_ec
*ec_ecdt
;
148 /* External interfaces use first EC only, so remember */
149 static struct acpi_device
*first_ec
;
150 static int acpi_ec_polling_mode
= EC_POLLING
;
152 /* --------------------------------------------------------------------------
153 Transaction Management
154 -------------------------------------------------------------------------- */
156 static inline u32
acpi_ec_read_status(union acpi_ec
*ec
)
160 acpi_hw_low_level_read(8, &status
, &ec
->common
.status_addr
);
164 static int acpi_ec_wait(union acpi_ec
*ec
, u8 event
)
166 if (acpi_ec_polling_mode
)
167 return acpi_ec_polling_wait(ec
, event
);
169 return acpi_ec_burst_wait(ec
, event
);
172 static int acpi_ec_polling_wait(union acpi_ec
*ec
, u8 event
)
174 u32 acpi_ec_status
= 0;
175 u32 i
= ACPI_EC_UDELAY_COUNT
;
180 /* Poll the EC status register waiting for the event to occur. */
182 case ACPI_EC_EVENT_OBF
:
184 acpi_hw_low_level_read(8, &acpi_ec_status
,
185 &ec
->common
.status_addr
);
186 if (acpi_ec_status
& ACPI_EC_FLAG_OBF
)
188 udelay(ACPI_EC_UDELAY
);
191 case ACPI_EC_EVENT_IBE
:
193 acpi_hw_low_level_read(8, &acpi_ec_status
,
194 &ec
->common
.status_addr
);
195 if (!(acpi_ec_status
& ACPI_EC_FLAG_IBF
))
197 udelay(ACPI_EC_UDELAY
);
206 static int acpi_ec_burst_wait(union acpi_ec
*ec
, unsigned int event
)
210 ACPI_FUNCTION_TRACE("acpi_ec_wait");
212 ec
->burst
.expect_event
= event
;
215 result
= wait_event_interruptible_timeout(ec
->burst
.wait
,
216 !ec
->burst
.expect_event
,
220 ec
->burst
.expect_event
= 0;
224 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, " result = %d ", result
));
225 return_VALUE(result
);
229 * Verify that the event in question has actually happened by
230 * querying EC status. Do the check even if operation timed-out
231 * to make sure that we did not miss interrupt.
234 case ACPI_EC_EVENT_OBF
:
235 if (acpi_ec_read_status(ec
) & ACPI_EC_FLAG_OBF
)
239 case ACPI_EC_EVENT_IBE
:
240 if (~acpi_ec_read_status(ec
) & ACPI_EC_FLAG_IBF
)
245 return_VALUE(-ETIME
);
248 static int acpi_ec_enter_burst_mode(union acpi_ec
*ec
)
253 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
255 status
= acpi_ec_read_status(ec
);
256 if (status
!= -EINVAL
&& !(status
& ACPI_EC_FLAG_BURST
)) {
257 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE
,
258 &ec
->common
.command_addr
);
259 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
261 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
262 return_VALUE(-EINVAL
);
264 acpi_hw_low_level_read(8, &tmp
, &ec
->common
.data_addr
);
265 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
266 if (tmp
!= 0x90) { /* Burst ACK byte */
267 return_VALUE(-EINVAL
);
271 atomic_set(&ec
->burst
.leaving_burst
, 0);
275 static int acpi_ec_leave_burst_mode(union acpi_ec
*ec
)
279 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
281 atomic_set(&ec
->burst
.leaving_burst
, 1);
282 status
= acpi_ec_read_status(ec
);
283 if (status
!= -EINVAL
&& (status
& ACPI_EC_FLAG_BURST
)) {
284 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE
,
285 &ec
->common
.command_addr
);
286 status
= acpi_ec_wait(ec
, ACPI_EC_FLAG_IBF
);
288 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
289 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
290 "------->wait fail\n"));
291 return_VALUE(-EINVAL
);
293 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
294 status
= acpi_ec_read_status(ec
);
300 static int acpi_ec_read(union acpi_ec
*ec
, u8 address
, u32
* data
)
302 if (acpi_ec_polling_mode
)
303 return acpi_ec_polling_read(ec
, address
, data
);
305 return acpi_ec_burst_read(ec
, address
, data
);
307 static int acpi_ec_write(union acpi_ec
*ec
, u8 address
, u8 data
)
309 if (acpi_ec_polling_mode
)
310 return acpi_ec_polling_write(ec
, address
, data
);
312 return acpi_ec_burst_write(ec
, address
, data
);
314 static int acpi_ec_polling_read(union acpi_ec
*ec
, u8 address
, u32
* data
)
316 acpi_status status
= AE_OK
;
318 unsigned long flags
= 0;
321 ACPI_FUNCTION_TRACE("acpi_ec_read");
324 return_VALUE(-EINVAL
);
328 if (ec
->common
.global_lock
) {
329 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
330 if (ACPI_FAILURE(status
))
331 return_VALUE(-ENODEV
);
334 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
336 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ
,
337 &ec
->common
.command_addr
);
338 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
342 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
343 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
347 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
349 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Read [%02x] from address [%02x]\n",
353 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
355 if (ec
->common
.global_lock
)
356 acpi_release_global_lock(glk
);
358 return_VALUE(result
);
361 static int acpi_ec_polling_write(union acpi_ec
*ec
, u8 address
, u8 data
)
364 acpi_status status
= AE_OK
;
365 unsigned long flags
= 0;
368 ACPI_FUNCTION_TRACE("acpi_ec_write");
371 return_VALUE(-EINVAL
);
373 if (ec
->common
.global_lock
) {
374 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
375 if (ACPI_FAILURE(status
))
376 return_VALUE(-ENODEV
);
379 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
381 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE
,
382 &ec
->common
.command_addr
);
383 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
387 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
388 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
392 acpi_hw_low_level_write(8, data
, &ec
->common
.data_addr
);
393 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
397 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Wrote [%02x] to address [%02x]\n",
401 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
403 if (ec
->common
.global_lock
)
404 acpi_release_global_lock(glk
);
406 return_VALUE(result
);
409 static int acpi_ec_burst_read(union acpi_ec
*ec
, u8 address
, u32
* data
)
414 ACPI_FUNCTION_TRACE("acpi_ec_read");
417 return_VALUE(-EINVAL
);
422 if (ec
->common
.global_lock
) {
423 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
424 if (ACPI_FAILURE(status
))
425 return_VALUE(-ENODEV
);
428 WARN_ON(in_interrupt());
429 down(&ec
->burst
.sem
);
431 if (acpi_ec_enter_burst_mode(ec
))
434 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ
,
435 &ec
->common
.command_addr
);
436 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
437 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
442 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
443 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
445 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
449 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
450 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
452 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Read [%02x] from address [%02x]\n",
456 acpi_ec_leave_burst_mode(ec
);
459 if (ec
->common
.global_lock
)
460 acpi_release_global_lock(glk
);
462 if (atomic_read(&ec
->burst
.leaving_burst
) == 2) {
463 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "aborted, retry ...\n"));
464 while (atomic_read(&ec
->burst
.pending_gpe
)) {
467 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
471 return_VALUE(status
);
474 static int acpi_ec_burst_write(union acpi_ec
*ec
, u8 address
, u8 data
)
480 ACPI_FUNCTION_TRACE("acpi_ec_write");
483 return_VALUE(-EINVAL
);
485 if (ec
->common
.global_lock
) {
486 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
487 if (ACPI_FAILURE(status
))
488 return_VALUE(-ENODEV
);
491 WARN_ON(in_interrupt());
492 down(&ec
->burst
.sem
);
494 if (acpi_ec_enter_burst_mode(ec
))
497 status
= acpi_ec_read_status(ec
);
498 if (status
!= -EINVAL
&& !(status
& ACPI_EC_FLAG_BURST
)) {
499 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE
,
500 &ec
->common
.command_addr
);
501 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
504 acpi_hw_low_level_read(8, &tmp
, &ec
->common
.data_addr
);
505 if (tmp
!= 0x90) /* Burst ACK byte */
508 /*Now we are in burst mode */
510 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE
,
511 &ec
->common
.command_addr
);
512 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
513 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
518 acpi_hw_low_level_write(8, address
, &ec
->common
.data_addr
);
519 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
521 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
525 acpi_hw_low_level_write(8, data
, &ec
->common
.data_addr
);
526 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_IBE
);
527 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
531 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Wrote [%02x] to address [%02x]\n",
535 acpi_ec_leave_burst_mode(ec
);
538 if (ec
->common
.global_lock
)
539 acpi_release_global_lock(glk
);
541 if (atomic_read(&ec
->burst
.leaving_burst
) == 2) {
542 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "aborted, retry ...\n"));
543 while (atomic_read(&ec
->burst
.pending_gpe
)) {
546 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
550 return_VALUE(status
);
554 * Externally callable EC access functions. For now, assume 1 EC only
556 int ec_read(u8 addr
, u8
* val
)
565 ec
= acpi_driver_data(first_ec
);
567 err
= acpi_ec_read(ec
, addr
, &temp_data
);
576 EXPORT_SYMBOL(ec_read
);
578 int ec_write(u8 addr
, u8 val
)
586 ec
= acpi_driver_data(first_ec
);
588 err
= acpi_ec_write(ec
, addr
, val
);
593 EXPORT_SYMBOL(ec_write
);
595 static int acpi_ec_query(union acpi_ec
*ec
, u32
* data
)
597 if (acpi_ec_polling_mode
)
598 return acpi_ec_polling_query(ec
, data
);
600 return acpi_ec_burst_query(ec
, data
);
602 static int acpi_ec_polling_query(union acpi_ec
*ec
, u32
* data
)
605 acpi_status status
= AE_OK
;
606 unsigned long flags
= 0;
609 ACPI_FUNCTION_TRACE("acpi_ec_query");
612 return_VALUE(-EINVAL
);
616 if (ec
->common
.global_lock
) {
617 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
618 if (ACPI_FAILURE(status
))
619 return_VALUE(-ENODEV
);
623 * Query the EC to find out which _Qxx method we need to evaluate.
624 * Note that successful completion of the query causes the ACPI_EC_SCI
625 * bit to be cleared (and thus clearing the interrupt source).
627 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
629 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY
,
630 &ec
->common
.command_addr
);
631 result
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
635 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
640 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
642 if (ec
->common
.global_lock
)
643 acpi_release_global_lock(glk
);
645 return_VALUE(result
);
647 static int acpi_ec_burst_query(union acpi_ec
*ec
, u32
* data
)
652 ACPI_FUNCTION_TRACE("acpi_ec_query");
655 return_VALUE(-EINVAL
);
658 if (ec
->common
.global_lock
) {
659 status
= acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK
, &glk
);
660 if (ACPI_FAILURE(status
))
661 return_VALUE(-ENODEV
);
664 down(&ec
->burst
.sem
);
665 if (acpi_ec_enter_burst_mode(ec
))
668 * Query the EC to find out which _Qxx method we need to evaluate.
669 * Note that successful completion of the query causes the ACPI_EC_SCI
670 * bit to be cleared (and thus clearing the interrupt source).
672 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY
,
673 &ec
->common
.command_addr
);
674 status
= acpi_ec_wait(ec
, ACPI_EC_EVENT_OBF
);
676 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
680 acpi_hw_low_level_read(8, data
, &ec
->common
.data_addr
);
681 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
686 acpi_ec_leave_burst_mode(ec
);
689 if (ec
->common
.global_lock
)
690 acpi_release_global_lock(glk
);
692 if (atomic_read(&ec
->burst
.leaving_burst
) == 2) {
693 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "aborted, retry ...\n"));
694 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
697 return_VALUE(status
);
700 /* --------------------------------------------------------------------------
702 -------------------------------------------------------------------------- */
704 union acpi_ec_query_data
{
709 static void acpi_ec_gpe_query(void *ec_cxt
)
711 if (acpi_ec_polling_mode
)
712 acpi_ec_gpe_polling_query(ec_cxt
);
714 acpi_ec_gpe_burst_query(ec_cxt
);
717 static void acpi_ec_gpe_polling_query(void *ec_cxt
)
719 union acpi_ec
*ec
= (union acpi_ec
*)ec_cxt
;
721 unsigned long flags
= 0;
722 static char object_name
[5] = { '_', 'Q', '0', '0', '\0' };
723 const char hex
[] = { '0', '1', '2', '3', '4', '5', '6', '7',
724 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
727 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
732 spin_lock_irqsave(&ec
->polling
.lock
, flags
);
733 acpi_hw_low_level_read(8, &value
, &ec
->common
.command_addr
);
734 spin_unlock_irqrestore(&ec
->polling
.lock
, flags
);
736 /* TBD: Implement asynch events!
737 * NOTE: All we care about are EC-SCI's. Other EC events are
738 * handled via polling (yuck!). This is because some systems
739 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
740 * a purely interrupt-driven approach (grumble, grumble).
742 if (!(value
& ACPI_EC_FLAG_SCI
))
745 if (acpi_ec_query(ec
, &value
))
748 object_name
[2] = hex
[((value
>> 4) & 0x0F)];
749 object_name
[3] = hex
[(value
& 0x0F)];
751 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Evaluating %s\n", object_name
));
753 acpi_evaluate_object(ec
->common
.handle
, object_name
, NULL
, NULL
);
756 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
758 static void acpi_ec_gpe_burst_query(void *ec_cxt
)
760 union acpi_ec
*ec
= (union acpi_ec
*)ec_cxt
;
762 int result
= -ENODATA
;
763 static char object_name
[5] = { '_', 'Q', '0', '0', '\0' };
764 const char hex
[] = { '0', '1', '2', '3', '4', '5', '6', '7',
765 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
768 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
770 if (acpi_ec_read_status(ec
) & ACPI_EC_FLAG_SCI
)
771 result
= acpi_ec_query(ec
, &value
);
776 object_name
[2] = hex
[((value
>> 4) & 0x0F)];
777 object_name
[3] = hex
[(value
& 0x0F)];
779 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Evaluating %s\n", object_name
));
781 acpi_evaluate_object(ec
->common
.handle
, object_name
, NULL
, NULL
);
783 atomic_dec(&ec
->burst
.pending_gpe
);
787 static u32
acpi_ec_gpe_handler(void *data
)
789 if (acpi_ec_polling_mode
)
790 return acpi_ec_gpe_polling_handler(data
);
792 return acpi_ec_gpe_burst_handler(data
);
794 static u32
acpi_ec_gpe_polling_handler(void *data
)
796 acpi_status status
= AE_OK
;
797 union acpi_ec
*ec
= (union acpi_ec
*)data
;
800 return ACPI_INTERRUPT_NOT_HANDLED
;
802 acpi_disable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_ISR
);
804 status
= acpi_os_queue_for_execution(OSD_PRIORITY_GPE
,
805 acpi_ec_gpe_query
, ec
);
808 return ACPI_INTERRUPT_HANDLED
;
810 return ACPI_INTERRUPT_NOT_HANDLED
;
812 static u32
acpi_ec_gpe_burst_handler(void *data
)
814 acpi_status status
= AE_OK
;
816 union acpi_ec
*ec
= (union acpi_ec
*)data
;
819 return ACPI_INTERRUPT_NOT_HANDLED
;
821 acpi_disable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_ISR
);
823 value
= acpi_ec_read_status(ec
);
825 if ((value
& ACPI_EC_FLAG_IBF
) &&
826 !(value
& ACPI_EC_FLAG_BURST
) &&
827 (atomic_read(&ec
->burst
.leaving_burst
) == 0)) {
829 * the embedded controller disables
830 * burst mode for any reason other
831 * than the burst disable command
832 * to process critical event.
834 atomic_set(&ec
->burst
.leaving_burst
, 2); /* block current pending transaction
836 wake_up(&ec
->burst
.wait
);
838 if ((ec
->burst
.expect_event
== ACPI_EC_EVENT_OBF
&&
839 (value
& ACPI_EC_FLAG_OBF
)) ||
840 (ec
->burst
.expect_event
== ACPI_EC_EVENT_IBE
&&
841 !(value
& ACPI_EC_FLAG_IBF
))) {
842 ec
->burst
.expect_event
= 0;
843 wake_up(&ec
->burst
.wait
);
844 return ACPI_INTERRUPT_HANDLED
;
848 if (value
& ACPI_EC_FLAG_SCI
) {
849 atomic_add(1, &ec
->burst
.pending_gpe
);
850 status
= acpi_os_queue_for_execution(OSD_PRIORITY_GPE
,
851 acpi_ec_gpe_query
, ec
);
852 return status
== AE_OK
?
853 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
855 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_ISR
);
856 return status
== AE_OK
?
857 ACPI_INTERRUPT_HANDLED
: ACPI_INTERRUPT_NOT_HANDLED
;
860 /* --------------------------------------------------------------------------
861 Address Space Management
862 -------------------------------------------------------------------------- */
865 acpi_ec_space_setup(acpi_handle region_handle
,
866 u32 function
, void *handler_context
, void **return_context
)
869 * The EC object is in the handler context and is needed
870 * when calling the acpi_ec_space_handler.
872 *return_context
= (function
!= ACPI_REGION_DEACTIVATE
) ?
873 handler_context
: NULL
;
879 acpi_ec_space_handler(u32 function
,
880 acpi_physical_address address
,
882 acpi_integer
* value
,
883 void *handler_context
, void *region_context
)
886 union acpi_ec
*ec
= NULL
;
888 acpi_integer f_v
= 0;
891 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
893 if ((address
> 0xFF) || !value
|| !handler_context
)
894 return_VALUE(AE_BAD_PARAMETER
);
896 if (bit_width
!= 8 && acpi_strict
) {
897 printk(KERN_WARNING PREFIX
898 "acpi_ec_space_handler: bit_width should be 8\n");
899 return_VALUE(AE_BAD_PARAMETER
);
902 ec
= (union acpi_ec
*)handler_context
;
908 result
= acpi_ec_read(ec
, (u8
) address
, (u32
*) & temp
);
911 result
= acpi_ec_write(ec
, (u8
) address
, (u8
) temp
);
921 if (function
== ACPI_READ
)
922 f_v
|= temp
<< 8 * i
;
923 if (function
== ACPI_WRITE
)
930 if (function
== ACPI_READ
) {
931 f_v
|= temp
<< 8 * i
;
938 return_VALUE(AE_BAD_PARAMETER
);
941 return_VALUE(AE_NOT_FOUND
);
944 return_VALUE(AE_TIME
);
951 /* --------------------------------------------------------------------------
953 -------------------------------------------------------------------------- */
955 static struct proc_dir_entry
*acpi_ec_dir
;
957 static int acpi_ec_read_info(struct seq_file
*seq
, void *offset
)
959 union acpi_ec
*ec
= (union acpi_ec
*)seq
->private;
961 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
966 seq_printf(seq
, "gpe bit: 0x%02x\n",
967 (u32
) ec
->common
.gpe_bit
);
968 seq_printf(seq
, "ports: 0x%02x, 0x%02x\n",
969 (u32
) ec
->common
.status_addr
.address
,
970 (u32
) ec
->common
.data_addr
.address
);
971 seq_printf(seq
, "use global lock: %s\n",
972 ec
->common
.global_lock
? "yes" : "no");
973 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
979 static int acpi_ec_info_open_fs(struct inode
*inode
, struct file
*file
)
981 return single_open(file
, acpi_ec_read_info
, PDE(inode
)->data
);
984 static struct file_operations acpi_ec_info_ops
= {
985 .open
= acpi_ec_info_open_fs
,
988 .release
= single_release
,
989 .owner
= THIS_MODULE
,
992 static int acpi_ec_add_fs(struct acpi_device
*device
)
994 struct proc_dir_entry
*entry
= NULL
;
996 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
998 if (!acpi_device_dir(device
)) {
999 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1001 if (!acpi_device_dir(device
))
1002 return_VALUE(-ENODEV
);
1005 entry
= create_proc_entry(ACPI_EC_FILE_INFO
, S_IRUGO
,
1006 acpi_device_dir(device
));
1008 ACPI_DEBUG_PRINT((ACPI_DB_WARN
,
1009 "Unable to create '%s' fs entry\n",
1010 ACPI_EC_FILE_INFO
));
1012 entry
->proc_fops
= &acpi_ec_info_ops
;
1013 entry
->data
= acpi_driver_data(device
);
1014 entry
->owner
= THIS_MODULE
;
1020 static int acpi_ec_remove_fs(struct acpi_device
*device
)
1022 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
1024 if (acpi_device_dir(device
)) {
1025 remove_proc_entry(ACPI_EC_FILE_INFO
, acpi_device_dir(device
));
1026 remove_proc_entry(acpi_device_bid(device
), acpi_ec_dir
);
1027 acpi_device_dir(device
) = NULL
;
1033 /* --------------------------------------------------------------------------
1035 -------------------------------------------------------------------------- */
1037 static int acpi_ec_polling_add(struct acpi_device
*device
)
1040 acpi_status status
= AE_OK
;
1041 union acpi_ec
*ec
= NULL
;
1044 ACPI_FUNCTION_TRACE("acpi_ec_add");
1047 return_VALUE(-EINVAL
);
1049 ec
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1051 return_VALUE(-ENOMEM
);
1052 memset(ec
, 0, sizeof(union acpi_ec
));
1054 ec
->common
.handle
= device
->handle
;
1055 ec
->common
.uid
= -1;
1056 spin_lock_init(&ec
->polling
.lock
);
1057 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
1058 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
1059 acpi_driver_data(device
) = ec
;
1061 /* Use the global lock for all EC transactions? */
1062 acpi_evaluate_integer(ec
->common
.handle
, "_GLK", NULL
,
1063 &ec
->common
.global_lock
);
1065 /* If our UID matches the UID for the ECDT-enumerated EC,
1066 we now have the *real* EC info, so kill the makeshift one. */
1067 acpi_evaluate_integer(ec
->common
.handle
, "_UID", NULL
, &uid
);
1068 if (ec_ecdt
&& ec_ecdt
->common
.uid
== uid
) {
1069 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
1071 &acpi_ec_space_handler
);
1073 acpi_remove_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
,
1074 &acpi_ec_gpe_handler
);
1079 /* Get GPE bit assignment (EC events). */
1080 /* TODO: Add support for _GPE returning a package */
1082 acpi_evaluate_integer(ec
->common
.handle
, "_GPE", NULL
,
1083 &ec
->common
.gpe_bit
);
1084 if (ACPI_FAILURE(status
)) {
1085 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1086 "Error obtaining GPE bit assignment\n"));
1091 result
= acpi_ec_add_fs(device
);
1095 printk(KERN_INFO PREFIX
"%s [%s] (gpe %d)\n",
1096 acpi_device_name(device
), acpi_device_bid(device
),
1097 (u32
) ec
->common
.gpe_bit
);
1106 return_VALUE(result
);
1108 static int acpi_ec_burst_add(struct acpi_device
*device
)
1111 acpi_status status
= AE_OK
;
1112 union acpi_ec
*ec
= NULL
;
1115 ACPI_FUNCTION_TRACE("acpi_ec_add");
1118 return_VALUE(-EINVAL
);
1120 ec
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1122 return_VALUE(-ENOMEM
);
1123 memset(ec
, 0, sizeof(union acpi_ec
));
1125 ec
->common
.handle
= device
->handle
;
1126 ec
->common
.uid
= -1;
1127 atomic_set(&ec
->burst
.pending_gpe
, 0);
1128 atomic_set(&ec
->burst
.leaving_burst
, 1);
1129 init_MUTEX(&ec
->burst
.sem
);
1130 init_waitqueue_head(&ec
->burst
.wait
);
1131 strcpy(acpi_device_name(device
), ACPI_EC_DEVICE_NAME
);
1132 strcpy(acpi_device_class(device
), ACPI_EC_CLASS
);
1133 acpi_driver_data(device
) = ec
;
1135 /* Use the global lock for all EC transactions? */
1136 acpi_evaluate_integer(ec
->common
.handle
, "_GLK", NULL
,
1137 &ec
->common
.global_lock
);
1139 /* If our UID matches the UID for the ECDT-enumerated EC,
1140 we now have the *real* EC info, so kill the makeshift one. */
1141 acpi_evaluate_integer(ec
->common
.handle
, "_UID", NULL
, &uid
);
1142 if (ec_ecdt
&& ec_ecdt
->common
.uid
== uid
) {
1143 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT
,
1145 &acpi_ec_space_handler
);
1147 acpi_remove_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
,
1148 &acpi_ec_gpe_handler
);
1153 /* Get GPE bit assignment (EC events). */
1154 /* TODO: Add support for _GPE returning a package */
1156 acpi_evaluate_integer(ec
->common
.handle
, "_GPE", NULL
,
1157 &ec
->common
.gpe_bit
);
1158 if (ACPI_FAILURE(status
)) {
1159 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1160 "Error obtaining GPE bit assignment\n"));
1165 result
= acpi_ec_add_fs(device
);
1169 printk(KERN_INFO PREFIX
"%s [%s] (gpe %d)\n",
1170 acpi_device_name(device
), acpi_device_bid(device
),
1171 (u32
) ec
->common
.gpe_bit
);
1180 return_VALUE(result
);
1183 static int acpi_ec_remove(struct acpi_device
*device
, int type
)
1185 union acpi_ec
*ec
= NULL
;
1187 ACPI_FUNCTION_TRACE("acpi_ec_remove");
1190 return_VALUE(-EINVAL
);
1192 ec
= acpi_driver_data(device
);
1194 acpi_ec_remove_fs(device
);
1202 acpi_ec_io_ports(struct acpi_resource
*resource
, void *context
)
1204 union acpi_ec
*ec
= (union acpi_ec
*)context
;
1205 struct acpi_generic_address
*addr
;
1207 if (resource
->id
!= ACPI_RSTYPE_IO
) {
1212 * The first address region returned is the data port, and
1213 * the second address region returned is the status/command
1216 if (ec
->common
.data_addr
.register_bit_width
== 0) {
1217 addr
= &ec
->common
.data_addr
;
1218 } else if (ec
->common
.command_addr
.register_bit_width
== 0) {
1219 addr
= &ec
->common
.command_addr
;
1221 return AE_CTRL_TERMINATE
;
1224 addr
->address_space_id
= ACPI_ADR_SPACE_SYSTEM_IO
;
1225 addr
->register_bit_width
= 8;
1226 addr
->register_bit_offset
= 0;
1227 addr
->address
= resource
->data
.io
.min_base_address
;
1232 static int acpi_ec_start(struct acpi_device
*device
)
1234 acpi_status status
= AE_OK
;
1235 union acpi_ec
*ec
= NULL
;
1237 ACPI_FUNCTION_TRACE("acpi_ec_start");
1240 return_VALUE(-EINVAL
);
1242 ec
= acpi_driver_data(device
);
1245 return_VALUE(-EINVAL
);
1248 * Get I/O port addresses. Convert to GAS format.
1250 status
= acpi_walk_resources(ec
->common
.handle
, METHOD_NAME__CRS
,
1251 acpi_ec_io_ports
, ec
);
1252 if (ACPI_FAILURE(status
)
1253 || ec
->common
.command_addr
.register_bit_width
== 0) {
1254 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1255 "Error getting I/O port addresses"));
1256 return_VALUE(-ENODEV
);
1259 ec
->common
.status_addr
= ec
->common
.command_addr
;
1261 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
1262 (u32
) ec
->common
.gpe_bit
,
1263 (u32
) ec
->common
.command_addr
.address
,
1264 (u32
) ec
->common
.data_addr
.address
));
1267 * Install GPE handler
1269 status
= acpi_install_gpe_handler(NULL
, ec
->common
.gpe_bit
,
1270 ACPI_GPE_EDGE_TRIGGERED
,
1271 &acpi_ec_gpe_handler
, ec
);
1272 if (ACPI_FAILURE(status
)) {
1273 return_VALUE(-ENODEV
);
1275 acpi_set_gpe_type(NULL
, ec
->common
.gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
1276 acpi_enable_gpe(NULL
, ec
->common
.gpe_bit
, ACPI_NOT_ISR
);
1278 status
= acpi_install_address_space_handler(ec
->common
.handle
,
1280 &acpi_ec_space_handler
,
1281 &acpi_ec_space_setup
, ec
);
1282 if (ACPI_FAILURE(status
)) {
1283 acpi_remove_gpe_handler(NULL
, ec
->common
.gpe_bit
,
1284 &acpi_ec_gpe_handler
);
1285 return_VALUE(-ENODEV
);
1288 return_VALUE(AE_OK
);
1291 static int acpi_ec_stop(struct acpi_device
*device
, int type
)
1293 acpi_status status
= AE_OK
;
1294 union acpi_ec
*ec
= NULL
;
1296 ACPI_FUNCTION_TRACE("acpi_ec_stop");
1299 return_VALUE(-EINVAL
);
1301 ec
= acpi_driver_data(device
);
1303 status
= acpi_remove_address_space_handler(ec
->common
.handle
,
1305 &acpi_ec_space_handler
);
1306 if (ACPI_FAILURE(status
))
1307 return_VALUE(-ENODEV
);
1310 acpi_remove_gpe_handler(NULL
, ec
->common
.gpe_bit
,
1311 &acpi_ec_gpe_handler
);
1312 if (ACPI_FAILURE(status
))
1313 return_VALUE(-ENODEV
);
1318 static acpi_status __init
1319 acpi_fake_ecdt_callback(acpi_handle handle
,
1320 u32 Level
, void *context
, void **retval
)
1323 if (acpi_ec_polling_mode
)
1324 return acpi_fake_ecdt_polling_callback(handle
,
1325 Level
, context
, retval
);
1327 return acpi_fake_ecdt_burst_callback(handle
,
1328 Level
, context
, retval
);
1331 static acpi_status __init
1332 acpi_fake_ecdt_polling_callback(acpi_handle handle
,
1333 u32 Level
, void *context
, void **retval
)
1337 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
1338 acpi_ec_io_ports
, ec_ecdt
);
1339 if (ACPI_FAILURE(status
))
1341 ec_ecdt
->common
.status_addr
= ec_ecdt
->common
.command_addr
;
1343 ec_ecdt
->common
.uid
= -1;
1344 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->common
.uid
);
1347 acpi_evaluate_integer(handle
, "_GPE", NULL
,
1348 &ec_ecdt
->common
.gpe_bit
);
1349 if (ACPI_FAILURE(status
))
1351 spin_lock_init(&ec_ecdt
->polling
.lock
);
1352 ec_ecdt
->common
.global_lock
= TRUE
;
1353 ec_ecdt
->common
.handle
= handle
;
1355 printk(KERN_INFO PREFIX
"GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1356 (u32
) ec_ecdt
->common
.gpe_bit
,
1357 (u32
) ec_ecdt
->common
.command_addr
.address
,
1358 (u32
) ec_ecdt
->common
.data_addr
.address
);
1360 return AE_CTRL_TERMINATE
;
1363 static acpi_status __init
1364 acpi_fake_ecdt_burst_callback(acpi_handle handle
,
1365 u32 Level
, void *context
, void **retval
)
1369 init_MUTEX(&ec_ecdt
->burst
.sem
);
1370 init_waitqueue_head(&ec_ecdt
->burst
.wait
);
1371 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
1372 acpi_ec_io_ports
, ec_ecdt
);
1373 if (ACPI_FAILURE(status
))
1375 ec_ecdt
->common
.status_addr
= ec_ecdt
->common
.command_addr
;
1377 ec_ecdt
->common
.uid
= -1;
1378 acpi_evaluate_integer(handle
, "_UID", NULL
, &ec_ecdt
->common
.uid
);
1381 acpi_evaluate_integer(handle
, "_GPE", NULL
,
1382 &ec_ecdt
->common
.gpe_bit
);
1383 if (ACPI_FAILURE(status
))
1385 ec_ecdt
->common
.global_lock
= TRUE
;
1386 ec_ecdt
->common
.handle
= handle
;
1388 printk(KERN_INFO PREFIX
"GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1389 (u32
) ec_ecdt
->common
.gpe_bit
,
1390 (u32
) ec_ecdt
->common
.command_addr
.address
,
1391 (u32
) ec_ecdt
->common
.data_addr
.address
);
1393 return AE_CTRL_TERMINATE
;
1397 * Some BIOS (such as some from Gateway laptops) access EC region very early
1398 * such as in BAT0._INI or EC._INI before an EC device is found and
1399 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
1400 * required, but if EC regison is accessed early, it is required.
1401 * The routine tries to workaround the BIOS bug by pre-scan EC device
1402 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
1403 * op region (since _REG isn't invoked yet). The assumption is true for
1404 * all systems found.
1406 static int __init
acpi_ec_fake_ecdt(void)
1411 printk(KERN_INFO PREFIX
"Try to make an fake ECDT\n");
1413 ec_ecdt
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1418 memset(ec_ecdt
, 0, sizeof(union acpi_ec
));
1420 status
= acpi_get_devices(ACPI_EC_HID
,
1421 acpi_fake_ecdt_callback
, NULL
, NULL
);
1422 if (ACPI_FAILURE(status
)) {
1430 printk(KERN_ERR PREFIX
"Can't make an fake ECDT\n");
1434 static int __init
acpi_ec_get_real_ecdt(void)
1436 if (acpi_ec_polling_mode
)
1437 return acpi_ec_polling_get_real_ecdt();
1439 return acpi_ec_burst_get_real_ecdt();
1442 static int __init
acpi_ec_polling_get_real_ecdt(void)
1445 struct acpi_table_ecdt
*ecdt_ptr
;
1447 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
1448 (struct acpi_table_header
**)
1450 if (ACPI_FAILURE(status
))
1453 printk(KERN_INFO PREFIX
"Found ECDT\n");
1456 * Generate a temporary ec context to use until the namespace is scanned
1458 ec_ecdt
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1461 memset(ec_ecdt
, 0, sizeof(union acpi_ec
));
1463 ec_ecdt
->common
.command_addr
= ecdt_ptr
->ec_control
;
1464 ec_ecdt
->common
.status_addr
= ecdt_ptr
->ec_control
;
1465 ec_ecdt
->common
.data_addr
= ecdt_ptr
->ec_data
;
1466 ec_ecdt
->common
.gpe_bit
= ecdt_ptr
->gpe_bit
;
1467 spin_lock_init(&ec_ecdt
->polling
.lock
);
1468 /* use the GL just to be safe */
1469 ec_ecdt
->common
.global_lock
= TRUE
;
1470 ec_ecdt
->common
.uid
= ecdt_ptr
->uid
;
1473 acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->common
.handle
);
1474 if (ACPI_FAILURE(status
)) {
1480 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
1487 static int __init
acpi_ec_burst_get_real_ecdt(void)
1490 struct acpi_table_ecdt
*ecdt_ptr
;
1492 status
= acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING
,
1493 (struct acpi_table_header
**)
1495 if (ACPI_FAILURE(status
))
1498 printk(KERN_INFO PREFIX
"Found ECDT\n");
1501 * Generate a temporary ec context to use until the namespace is scanned
1503 ec_ecdt
= kmalloc(sizeof(union acpi_ec
), GFP_KERNEL
);
1506 memset(ec_ecdt
, 0, sizeof(union acpi_ec
));
1508 init_MUTEX(&ec_ecdt
->burst
.sem
);
1509 init_waitqueue_head(&ec_ecdt
->burst
.wait
);
1510 ec_ecdt
->common
.command_addr
= ecdt_ptr
->ec_control
;
1511 ec_ecdt
->common
.status_addr
= ecdt_ptr
->ec_control
;
1512 ec_ecdt
->common
.data_addr
= ecdt_ptr
->ec_data
;
1513 ec_ecdt
->common
.gpe_bit
= ecdt_ptr
->gpe_bit
;
1514 /* use the GL just to be safe */
1515 ec_ecdt
->common
.global_lock
= TRUE
;
1516 ec_ecdt
->common
.uid
= ecdt_ptr
->uid
;
1519 acpi_get_handle(NULL
, ecdt_ptr
->ec_id
, &ec_ecdt
->common
.handle
);
1520 if (ACPI_FAILURE(status
)) {
1526 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
1533 static int __initdata acpi_fake_ecdt_enabled
;
1534 int __init
acpi_ec_ecdt_probe(void)
1539 ret
= acpi_ec_get_real_ecdt();
1540 /* Try to make a fake ECDT */
1541 if (ret
&& acpi_fake_ecdt_enabled
) {
1542 ret
= acpi_ec_fake_ecdt();
1549 * Install GPE handler
1551 status
= acpi_install_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
,
1552 ACPI_GPE_EDGE_TRIGGERED
,
1553 &acpi_ec_gpe_handler
, ec_ecdt
);
1554 if (ACPI_FAILURE(status
)) {
1557 acpi_set_gpe_type(NULL
, ec_ecdt
->common
.gpe_bit
, ACPI_GPE_TYPE_RUNTIME
);
1558 acpi_enable_gpe(NULL
, ec_ecdt
->common
.gpe_bit
, ACPI_NOT_ISR
);
1560 status
= acpi_install_address_space_handler(ACPI_ROOT_OBJECT
,
1562 &acpi_ec_space_handler
,
1563 &acpi_ec_space_setup
,
1565 if (ACPI_FAILURE(status
)) {
1566 acpi_remove_gpe_handler(NULL
, ec_ecdt
->common
.gpe_bit
,
1567 &acpi_ec_gpe_handler
);
1574 printk(KERN_ERR PREFIX
"Could not use ECDT\n");
1581 static int __init
acpi_ec_init(void)
1585 ACPI_FUNCTION_TRACE("acpi_ec_init");
1590 acpi_ec_dir
= proc_mkdir(ACPI_EC_CLASS
, acpi_root_dir
);
1592 return_VALUE(-ENODEV
);
1594 /* Now register the driver for the EC */
1595 result
= acpi_bus_register_driver(&acpi_ec_driver
);
1597 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1598 return_VALUE(-ENODEV
);
1601 return_VALUE(result
);
1604 subsys_initcall(acpi_ec_init
);
1606 /* EC driver currently not unloadable */
1608 static void __exit
acpi_ec_exit(void)
1610 ACPI_FUNCTION_TRACE("acpi_ec_exit");
1612 acpi_bus_unregister_driver(&acpi_ec_driver
);
1614 remove_proc_entry(ACPI_EC_CLASS
, acpi_root_dir
);
1620 static int __init
acpi_fake_ecdt_setup(char *str
)
1622 acpi_fake_ecdt_enabled
= 1;
1626 __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup
);
1627 static int __init
acpi_ec_set_polling_mode(char *str
)
1631 if (!get_option(&str
, &burst
))
1635 acpi_ec_polling_mode
= EC_BURST
;
1636 acpi_ec_driver
.ops
.add
= acpi_ec_burst_add
;
1638 acpi_ec_polling_mode
= EC_POLLING
;
1639 acpi_ec_driver
.ops
.add
= acpi_ec_polling_add
;
1641 printk(KERN_INFO PREFIX
"EC %s mode.\n", burst
? "burst" : "polling");
1645 __setup("ec_burst=", acpi_ec_set_polling_mode
);