2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/acpica/acpi_ec.c,v 1.38.2.1 2003/08/22 20:49:20 jhb Exp $
28 * $DragonFly: src/sys/dev/acpica/Attic/acpi_ec.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $
30 /******************************************************************************
34 * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights
39 * 2.1. This is your license from Intel Corp. under its intellectual property
40 * rights. You may have additional license terms from the party that provided
41 * you this software, covering your right to use that party's intellectual
44 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
45 * copy of the source code appearing in this file ("Covered Code") an
46 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
47 * base code distributed originally by Intel ("Original Intel Code") to copy,
48 * make derivatives, distribute, use and display any portion of the Covered
49 * Code in any form, with the right to sublicense such rights; and
51 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
52 * license (with the right to sublicense), under only those claims of Intel
53 * patents that are infringed by the Original Intel Code, to make, use, sell,
54 * offer to sell, and import the Covered Code and derivative works thereof
55 * solely to the minimum extent necessary to exercise the above copyright
56 * license, and in no event shall the patent license extend to any additions
57 * to or modifications of the Original Intel Code. No other license or right
58 * is granted directly or by implication, estoppel or otherwise;
60 * The above copyright and patent license is granted only if the following
65 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
66 * Redistribution of source code of any substantial portion of the Covered
67 * Code or modification with rights to further distribute source must include
68 * the above Copyright Notice, the above License, this list of Conditions,
69 * and the following Disclaimer and Export Compliance provision. In addition,
70 * Licensee must cause all Covered Code to which Licensee contributes to
71 * contain a file documenting the changes Licensee made to create that Covered
72 * Code and the date of any change. Licensee must include in that file the
73 * documentation of any changes made by any predecessor Licensee. Licensee
74 * must include a prominent statement that the modification is derived,
75 * directly or indirectly, from Original Intel Code.
77 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
78 * Redistribution of source code of any substantial portion of the Covered
79 * Code or modification without rights to further distribute source must
80 * include the following Disclaimer and Export Compliance provision in the
81 * documentation and/or other materials provided with distribution. In
82 * addition, Licensee may not authorize further sublicense of source of any
83 * portion of the Covered Code, and must include terms to the effect that the
84 * license from Licensee to its licensee is limited to the intellectual
85 * property embodied in the software Licensee provides to its licensee, and
86 * not to intellectual property embodied in modifications its licensee may
89 * 3.3. Redistribution of Executable. Redistribution in executable form of any
90 * substantial portion of the Covered Code or modification must reproduce the
91 * above Copyright Notice, and the following Disclaimer and Export Compliance
92 * provision in the documentation and/or other materials provided with the
95 * 3.4. Intel retains all right, title, and interest in and to the Original
98 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
99 * Intel shall be used in advertising or otherwise to promote the sale, use or
100 * other dealings in products derived from or relating to the Covered Code
101 * without prior written authorization from Intel.
103 * 4. Disclaimer and Export Compliance
105 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
106 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
107 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
108 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
109 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
110 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
111 * PARTICULAR PURPOSE.
113 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
114 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
115 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
116 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
117 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
118 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
119 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
122 * 4.3. Licensee shall not export, either directly or indirectly, any of this
123 * software or system incorporating such software without first obtaining any
124 * required license or other approval from the U. S. Department of Commerce or
125 * any other agency or department of the United States Government. In the
126 * event Licensee exports any such software from the United States or
127 * re-exports any such software from a foreign destination, Licensee shall
128 * ensure that the distribution and export/re-export of the software is in
129 * compliance with all laws, regulations, orders, or other restrictions of the
130 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
131 * any of its subsidiaries will export/re-export any technical data, process,
132 * software, or service, directly or indirectly, to any country for which the
133 * United States government or any agency thereof requires an export license,
134 * other governmental approval, or letter of assurance, without first obtaining
135 * such license, approval or letter.
137 *****************************************************************************/
139 #include "opt_acpi.h"
140 #include <sys/param.h>
141 #include <sys/kernel.h>
144 #include <machine/bus.h>
145 #include <machine/resource.h>
146 #include <sys/rman.h>
150 #include <dev/acpica/acpivar.h>
153 * Hooks for the ACPI CA debugging infrastructure
155 #define _COMPONENT ACPI_EC
156 ACPI_MODULE_NAME("EC")
162 typedef UINT8 EC_COMMAND;
164 #define EC_COMMAND_UNKNOWN ((EC_COMMAND) 0x00)
165 #define EC_COMMAND_READ ((EC_COMMAND) 0x80)
166 #define EC_COMMAND_WRITE ((EC_COMMAND) 0x81)
167 #define EC_COMMAND_BURST_ENABLE ((EC_COMMAND) 0x82)
168 #define EC_COMMAND_BURST_DISABLE ((EC_COMMAND) 0x83)
169 #define EC_COMMAND_QUERY ((EC_COMMAND) 0x84)
174 * The encoding of the EC status register is illustrated below.
175 * Note that a set bit (1) indicates the property is TRUE
176 * (e.g. if bit 0 is set then the output buffer is full).
181 * | | | | | | | +- Output Buffer Full?
182 * | | | | | | +--- Input Buffer Full?
183 * | | | | | +----- <reserved>
184 * | | | | +------- Data Register is Command Byte?
185 * | | | +--------- Burst Mode Enabled?
186 * | | +----------- SCI Event?
187 * | +------------- SMI Event?
188 * +--------------- <Reserved>
191 typedef UINT8 EC_STATUS;
193 #define EC_FLAG_OUTPUT_BUFFER ((EC_STATUS) 0x01)
194 #define EC_FLAG_INPUT_BUFFER ((EC_STATUS) 0x02)
195 #define EC_FLAG_BURST_MODE ((EC_STATUS) 0x10)
196 #define EC_FLAG_SCI ((EC_STATUS) 0x20)
202 typedef UINT8 EC_EVENT;
204 #define EC_EVENT_UNKNOWN ((EC_EVENT) 0x00)
205 #define EC_EVENT_OUTPUT_BUFFER_FULL ((EC_EVENT) 0x01)
206 #define EC_EVENT_INPUT_BUFFER_EMPTY ((EC_EVENT) 0x02)
207 #define EC_EVENT_SCI ((EC_EVENT) 0x20)
210 * Register access primitives
212 #define EC_GET_DATA(sc) \
213 bus_space_read_1((sc)->ec_data_tag, (sc)->ec_data_handle, 0)
215 #define EC_SET_DATA(sc, v) \
216 bus_space_write_1((sc)->ec_data_tag, (sc)->ec_data_handle, 0, (v))
218 #define EC_GET_CSR(sc) \
219 bus_space_read_1((sc)->ec_csr_tag, (sc)->ec_csr_handle, 0)
221 #define EC_SET_CSR(sc, v) \
222 bus_space_write_1((sc)->ec_csr_tag, (sc)->ec_csr_handle, 0, (v))
227 struct acpi_ec_softc {
229 ACPI_HANDLE ec_handle;
233 struct resource *ec_data_res;
234 bus_space_tag_t ec_data_tag;
235 bus_space_handle_t ec_data_handle;
238 struct resource *ec_csr_res;
239 bus_space_tag_t ec_csr_tag;
240 bus_space_handle_t ec_csr_handle;
248 static int acpi_ec_event_driven = 0;
249 TUNABLE_INT("hw.acpi.ec.event_driven", &acpi_ec_event_driven);
251 #define EC_LOCK_TIMEOUT 1000 /* 1ms */
253 static __inline ACPI_STATUS
254 EcLock(struct acpi_ec_softc *sc)
258 /* XXX ACPI_WAIT_FOREVER is probably a bad idea, what is a better time? */
259 status = AcpiAcquireGlobalLock(ACPI_WAIT_FOREVER, &sc->ec_lockhandle);
260 if (ACPI_SUCCESS(status))
267 EcUnlock(struct acpi_ec_softc *sc)
270 AcpiReleaseGlobalLock(sc->ec_lockhandle);
274 EcIsLocked(struct acpi_ec_softc *sc)
276 return (sc->ec_locked != 0);
286 static void EcGpeHandler(void *Context);
287 static ACPI_STATUS EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function,
288 void *Context, void **return_Context);
289 static ACPI_STATUS EcSpaceHandler(UINT32 Function,
290 ACPI_PHYSICAL_ADDRESS Address,
291 UINT32 width, ACPI_INTEGER *Value,
292 void *Context, void *RegionContext);
293 static ACPI_STATUS EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event);
294 static ACPI_STATUS EcQuery(struct acpi_ec_softc *sc, UINT8 *Data);
295 static ACPI_STATUS EcTransaction(struct acpi_ec_softc *sc,
296 EC_REQUEST *EcRequest);
297 static ACPI_STATUS EcRead(struct acpi_ec_softc *sc, UINT8 Address,
299 static ACPI_STATUS EcWrite(struct acpi_ec_softc *sc, UINT8 Address,
301 static void acpi_ec_identify(driver_t driver, device_t bus);
302 static int acpi_ec_probe(device_t dev);
303 static int acpi_ec_attach(device_t dev);
305 static device_method_t acpi_ec_methods[] = {
306 /* Device interface */
307 DEVMETHOD(device_identify, acpi_ec_identify),
308 DEVMETHOD(device_probe, acpi_ec_probe),
309 DEVMETHOD(device_attach, acpi_ec_attach),
314 static driver_t acpi_ec_driver = {
317 sizeof(struct acpi_ec_softc),
320 static devclass_t acpi_ec_devclass;
321 DRIVER_MODULE(acpi_ec, acpi, acpi_ec_driver, acpi_ec_devclass, 0, 0);
324 * Look for an ECDT table and if we find one, set up a default EC
325 * space handler to catch possible attempts to access EC space before
326 * we have a real driver instance in place.
327 * We're not really an identify routine, but because we get called
328 * before most other things, this works out OK.
331 acpi_ec_identify(driver_t driver, device_t bus)
333 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
335 /* XXX implement - need an ACPI 2.0 system to test this */
339 * We could setup resources in the probe routine in order to have them printed
340 * when the device is attached.
343 acpi_ec_probe(device_t dev)
346 if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("ec") &&
347 acpi_MatchHid(dev, "PNP0C09")) {
350 * Set device description
352 device_set_desc(dev, "embedded controller");
359 acpi_ec_attach(device_t dev)
361 struct acpi_ec_softc *sc;
365 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
368 * Fetch/initialise softc
370 sc = device_get_softc(dev);
371 bzero(sc, sizeof(*sc));
373 sc->ec_handle = acpi_get_handle(dev);
376 * Attach bus resources
379 sc->ec_data_res = bus_alloc_resource(sc->ec_dev, SYS_RES_IOPORT,
380 &sc->ec_data_rid, 0, ~0, 1, RF_ACTIVE);
381 if (sc->ec_data_res == NULL) {
382 device_printf(dev, "can't allocate data port\n");
386 sc->ec_data_tag = rman_get_bustag(sc->ec_data_res);
387 sc->ec_data_handle = rman_get_bushandle(sc->ec_data_res);
390 sc->ec_csr_res = bus_alloc_resource(sc->ec_dev, SYS_RES_IOPORT,
391 &sc->ec_csr_rid, 0, ~0, 1, RF_ACTIVE);
392 if (sc->ec_csr_res == NULL) {
393 device_printf(dev, "can't allocate command/status port\n");
397 sc->ec_csr_tag = rman_get_bustag(sc->ec_csr_res);
398 sc->ec_csr_handle = rman_get_bushandle(sc->ec_csr_res);
401 * Install GPE handler
403 * Evaluate the _GPE method to find the GPE bit used by the EC to signal
406 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching GPE\n"));
407 Status = acpi_EvaluateInteger(sc->ec_handle, "_GPE", &sc->ec_gpebit);
408 if (ACPI_FAILURE(Status)) {
409 device_printf(dev, "can't evaluate _GPE - %s\n",
410 AcpiFormatException(Status));
416 * Install a handler for this EC's GPE bit. Note that EC SCIs are
417 * treated as both edge- and level-triggered interrupts; in other words
418 * we clear the status bit immediately after getting an EC-SCI, then
419 * again after we're done processing the event. This guarantees that
420 * events we cause while performing a transaction (e.g. IBE/OBF) get
421 * cleared before re-enabling the GPE.
423 Status = AcpiInstallGpeHandler(sc->ec_gpebit,
424 ACPI_EVENT_LEVEL_TRIGGERED | ACPI_EVENT_EDGE_TRIGGERED,
426 if (ACPI_FAILURE(Status)) {
427 device_printf(dev, "can't install GPE handler for %s - %s\n",
428 acpi_name(sc->ec_handle), AcpiFormatException(Status));
434 * Install address space handler
436 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching address space handler\n"));
437 Status = AcpiInstallAddressSpaceHandler(sc->ec_handle, ACPI_ADR_SPACE_EC,
438 EcSpaceHandler, EcSpaceSetup, sc);
439 if (ACPI_FAILURE(Status)) {
440 device_printf(dev, "can't install address space handler for %s - %s\n",
441 acpi_name(sc->ec_handle), AcpiFormatException(Status));
446 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attach complete\n"));
451 bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_csr_rid,
454 bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_data_rid,
456 return_VALUE (errval);
460 EcGpeQueryHandler(void *Context)
462 struct acpi_ec_softc *sc = (struct acpi_ec_softc *)Context;
467 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
474 * Bail out if the EC_SCI bit of the status register is not set.
475 * Note that this function should only be called when
476 * this bit is set (polling is used to detect IBE/OBF events).
478 * It is safe to do this without locking the controller, as it's
479 * OK to call EcQuery when there's no data ready; in the worst
480 * case we should just find nothing waiting for us and bail.
482 if ((EC_GET_CSR(sc) & EC_EVENT_SCI) == 0)
486 * Find out why the EC is signalling us
488 Status = EcQuery(sc, &Data);
491 * If we failed to get anything from the EC, give up
493 if (ACPI_FAILURE(Status)) {
494 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
495 "GPE query failed - %s\n", AcpiFormatException(Status));
500 * Evaluate _Qxx to respond to the controller.
502 sprintf(qxx, "_Q%02x", Data);
504 Status = AcpiEvaluateObject(sc->ec_handle, qxx, NULL, NULL);
506 * Ignore spurious query requests.
508 if (ACPI_FAILURE(Status) && (Data != 0 || Status != AE_NOT_FOUND)) {
509 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
510 "evaluation of GPE query method %s failed - %s\n",
511 qxx, AcpiFormatException(Status));
514 /* I know I request Level trigger cleanup */
515 if (ACPI_FAILURE(AcpiClearEvent(sc->ec_gpebit, ACPI_EVENT_GPE)))
516 printf("EcGpeQueryHandler:ClearEvent Failed\n");
517 if (ACPI_FAILURE(AcpiEnableEvent(sc->ec_gpebit, ACPI_EVENT_GPE, 0)))
518 printf("EcGpeQueryHandler:EnableEvent Failed\n");
522 * Handle a GPE sent to us.
525 EcGpeHandler(void *Context)
527 struct acpi_ec_softc *sc = Context;
531 * If EC is locked, the intr must process EcRead/Write wait only.
532 * Query request must be pending.
534 if (EcIsLocked(sc)) {
535 csrvalue = EC_GET_CSR(sc);
536 if (csrvalue & EC_EVENT_SCI)
537 sc->ec_pendquery = 1;
538 if ((csrvalue & EC_FLAG_OUTPUT_BUFFER) != 0 ||
539 (csrvalue & EC_FLAG_INPUT_BUFFER) == 0) {
540 sc->ec_csrvalue = csrvalue;
541 wakeup(&sc->ec_csrvalue);
544 /* Queue GpeQuery Handler */
545 if (ACPI_FAILURE(AcpiOsQueueForExecution(OSD_PRIORITY_HIGH,
546 EcGpeQueryHandler,Context))) {
547 printf("QueryHandler Queuing Failed\n");
553 EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function, void *Context,
554 void **RegionContext)
557 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
560 * Just pass the context through, there's nothing to do here.
562 *RegionContext = Context;
564 return_ACPI_STATUS (AE_OK);
568 EcSpaceHandler(UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 width,
569 ACPI_INTEGER *Value, void *Context, void *RegionContext)
571 struct acpi_ec_softc *sc = (struct acpi_ec_softc *)Context;
572 ACPI_STATUS Status = AE_OK;
573 EC_REQUEST EcRequest;
576 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, (UINT32)Address);
578 if (Address > 0xFF || width % 8 != 0 || Value == NULL || Context == NULL)
579 return_ACPI_STATUS (AE_BAD_PARAMETER);
583 EcRequest.Command = EC_COMMAND_READ;
584 EcRequest.Address = Address;
588 EcRequest.Command = EC_COMMAND_WRITE;
589 EcRequest.Address = Address;
592 device_printf(sc->ec_dev, "invalid Address Space function %d\n",
594 return_ACPI_STATUS (AE_BAD_PARAMETER);
598 * Perform the transaction.
600 for (i = 0; i < width; i += 8) {
601 if (Function == ACPI_READ)
604 EcRequest.Data = (UINT8)((*Value) >> i);
605 Status = EcTransaction(sc, &EcRequest);
606 if (ACPI_FAILURE(Status))
608 *Value |= (ACPI_INTEGER)EcRequest.Data << i;
609 if (++EcRequest.Address == 0)
610 return_ACPI_STATUS (AE_BAD_PARAMETER);
612 return_ACPI_STATUS (Status);
616 * Wait for an event interrupt for a specific condition.
619 EcWaitEventIntr(struct acpi_ec_softc *sc, EC_EVENT Event)
624 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, (UINT32)Event);
626 /* XXX this should test whether interrupts are available some other way */
627 if (cold || acpi_ec_event_driven)
628 return_ACPI_STATUS (EcWaitEvent(sc, Event));
630 if (!EcIsLocked(sc)) {
631 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
632 "EcWaitEventIntr called without EC lock!\n");
635 EcStatus = EC_GET_CSR(sc);
637 /* XXX waiting too long? */
638 for (i = 0; i < 10; i++) {
640 * Check EC status against the desired event.
642 if ((Event == EC_EVENT_OUTPUT_BUFFER_FULL) &&
643 (EcStatus & EC_FLAG_OUTPUT_BUFFER) != 0)
644 return_ACPI_STATUS (AE_OK);
646 if ((Event == EC_EVENT_INPUT_BUFFER_EMPTY) &&
647 (EcStatus & EC_FLAG_INPUT_BUFFER) == 0)
648 return_ACPI_STATUS (AE_OK);
651 /* XXX sleeping with Acpi Global Lock held */
652 if (tsleep(&sc->ec_csrvalue, 0, "EcWait", 1) != EWOULDBLOCK) {
653 EcStatus = sc->ec_csrvalue;
655 EcStatus = EC_GET_CSR(sc);
658 return_ACPI_STATUS (AE_ERROR);
662 EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event)
667 if (!EcIsLocked(sc)) {
668 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
669 "EcWaitEvent called without EC lock!\n");
675 * Stall for 1 microsecond before reading the status register
676 * for the first time. This allows the EC to set the IBF/OBF
677 * bit to its proper state.
679 * XXX it is not clear why we read the CSR twice.
682 EcStatus = EC_GET_CSR(sc);
687 * Poll the EC status register to detect completion of the last
688 * command. Wait up to 10ms (in 10us chunks) for this to occur.
690 for (i = 0; i < 1000; i++) {
691 EcStatus = EC_GET_CSR(sc);
693 if (Event == EC_EVENT_OUTPUT_BUFFER_FULL &&
694 (EcStatus & EC_FLAG_OUTPUT_BUFFER) != 0)
697 if (Event == EC_EVENT_INPUT_BUFFER_EMPTY &&
698 (EcStatus & EC_FLAG_INPUT_BUFFER) == 0)
708 EcQuery(struct acpi_ec_softc *sc, UINT8 *Data)
713 if (ACPI_FAILURE(Status))
716 EC_SET_CSR(sc, EC_COMMAND_QUERY);
717 Status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL);
718 if (ACPI_SUCCESS(Status))
719 *Data = EC_GET_DATA(sc);
723 if (ACPI_FAILURE(Status)) {
724 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
725 "timeout waiting for EC to respond to EC_COMMAND_QUERY\n");
731 EcTransaction(struct acpi_ec_softc *sc, EC_REQUEST *EcRequest)
736 if (ACPI_FAILURE(Status))
740 * Perform the transaction.
742 switch (EcRequest->Command) {
743 case EC_COMMAND_READ:
744 Status = EcRead(sc, EcRequest->Address, &EcRequest->Data);
746 case EC_COMMAND_WRITE:
747 Status = EcWrite(sc, EcRequest->Address, &EcRequest->Data);
757 * Clear & Re-Enable the EC GPE:
758 * -----------------------------
759 * 'Consume' any EC GPE events that we generated while performing
760 * the transaction (e.g. IBF/OBF). Clearing the GPE here shouldn't
761 * have an adverse affect on outstanding EC-SCI's, as the source
762 * (EC-SCI) will still be high and thus should trigger the GPE
763 * immediately after we re-enabling it.
765 if (sc->ec_pendquery) {
766 if (ACPI_FAILURE(AcpiOsQueueForExecution(OSD_PRIORITY_HIGH,
767 EcGpeQueryHandler, sc)))
768 printf("Pend Query Queuing Failed\n");
769 sc->ec_pendquery = 0;
772 if (ACPI_FAILURE(AcpiClearEvent(sc->ec_gpebit, ACPI_EVENT_GPE))) {
773 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
774 "EcRequest: Unable to clear the EC GPE.\n");
776 if (ACPI_FAILURE(AcpiEnableEvent(sc->ec_gpebit, ACPI_EVENT_GPE, 0))) {
777 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
778 "EcRequest: Unable to re-enable the EC GPE.\n");
786 EcRead(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data)
790 if (!EcIsLocked(sc)) {
791 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
792 "EcRead called without EC lock!\n");
795 /*EcBurstEnable(EmbeddedController);*/
797 EC_SET_CSR(sc, EC_COMMAND_READ);
798 Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY);
799 if (ACPI_FAILURE(Status)) {
800 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
801 "EcRead: Failed waiting for EC to process read command.\n");
805 EC_SET_DATA(sc, Address);
806 Status = EcWaitEventIntr(sc, EC_EVENT_OUTPUT_BUFFER_FULL);
807 if (ACPI_FAILURE(Status)) {
808 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
809 "EcRead: Failed waiting for EC to send data.\n");
813 *Data = EC_GET_DATA(sc);
815 /*EcBurstDisable(EmbeddedController);*/
821 EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data)
825 if (!EcIsLocked(sc)) {
826 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
827 "EcWrite called without EC lock!\n");
830 /*EcBurstEnable(EmbeddedController);*/
832 EC_SET_CSR(sc, EC_COMMAND_WRITE);
833 Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY);
834 if (ACPI_FAILURE(Status)) {
835 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
836 "EcWrite: Failed waiting for EC to process write command.\n");
840 EC_SET_DATA(sc, Address);
841 Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY);
842 if (ACPI_FAILURE(Status)) {
843 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
844 "EcRead: Failed waiting for EC to process address.\n");
848 EC_SET_DATA(sc, *Data);
849 Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY);
850 if (ACPI_FAILURE(Status)) {
851 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
852 "EcWrite: Failed waiting for EC to process data.\n");
856 /*EcBurstDisable(EmbeddedController);*/