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
29 /******************************************************************************
33 * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights
38 * 2.1. This is your license from Intel Corp. under its intellectual property
39 * rights. You may have additional license terms from the party that provided
40 * you this software, covering your right to use that party's intellectual
43 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
44 * copy of the source code appearing in this file ("Covered Code") an
45 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
46 * base code distributed originally by Intel ("Original Intel Code") to copy,
47 * make derivatives, distribute, use and display any portion of the Covered
48 * Code in any form, with the right to sublicense such rights; and
50 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
51 * license (with the right to sublicense), under only those claims of Intel
52 * patents that are infringed by the Original Intel Code, to make, use, sell,
53 * offer to sell, and import the Covered Code and derivative works thereof
54 * solely to the minimum extent necessary to exercise the above copyright
55 * license, and in no event shall the patent license extend to any additions
56 * to or modifications of the Original Intel Code. No other license or right
57 * is granted directly or by implication, estoppel or otherwise;
59 * The above copyright and patent license is granted only if the following
64 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
65 * Redistribution of source code of any substantial portion of the Covered
66 * Code or modification with rights to further distribute source must include
67 * the above Copyright Notice, the above License, this list of Conditions,
68 * and the following Disclaimer and Export Compliance provision. In addition,
69 * Licensee must cause all Covered Code to which Licensee contributes to
70 * contain a file documenting the changes Licensee made to create that Covered
71 * Code and the date of any change. Licensee must include in that file the
72 * documentation of any changes made by any predecessor Licensee. Licensee
73 * must include a prominent statement that the modification is derived,
74 * directly or indirectly, from Original Intel Code.
76 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
77 * Redistribution of source code of any substantial portion of the Covered
78 * Code or modification without rights to further distribute source must
79 * include the following Disclaimer and Export Compliance provision in the
80 * documentation and/or other materials provided with distribution. In
81 * addition, Licensee may not authorize further sublicense of source of any
82 * portion of the Covered Code, and must include terms to the effect that the
83 * license from Licensee to its licensee is limited to the intellectual
84 * property embodied in the software Licensee provides to its licensee, and
85 * not to intellectual property embodied in modifications its licensee may
88 * 3.3. Redistribution of Executable. Redistribution in executable form of any
89 * substantial portion of the Covered Code or modification must reproduce the
90 * above Copyright Notice, and the following Disclaimer and Export Compliance
91 * provision in the documentation and/or other materials provided with the
94 * 3.4. Intel retains all right, title, and interest in and to the Original
97 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
98 * Intel shall be used in advertising or otherwise to promote the sale, use or
99 * other dealings in products derived from or relating to the Covered Code
100 * without prior written authorization from Intel.
102 * 4. Disclaimer and Export Compliance
104 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
105 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
106 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
107 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
108 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
109 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
110 * PARTICULAR PURPOSE.
112 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
113 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
114 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
115 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
116 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
117 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
118 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
121 * 4.3. Licensee shall not export, either directly or indirectly, any of this
122 * software or system incorporating such software without first obtaining any
123 * required license or other approval from the U. S. Department of Commerce or
124 * any other agency or department of the United States Government. In the
125 * event Licensee exports any such software from the United States or
126 * re-exports any such software from a foreign destination, Licensee shall
127 * ensure that the distribution and export/re-export of the software is in
128 * compliance with all laws, regulations, orders, or other restrictions of the
129 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
130 * any of its subsidiaries will export/re-export any technical data, process,
131 * software, or service, directly or indirectly, to any country for which the
132 * United States government or any agency thereof requires an export license,
133 * other governmental approval, or letter of assurance, without first obtaining
134 * such license, approval or letter.
136 *****************************************************************************/
138 #include "opt_acpi.h"
139 #include <sys/param.h>
140 #include <sys/kernel.h>
143 #include <machine/bus.h>
144 #include <machine/resource.h>
145 #include <sys/rman.h>
149 #include <dev/acpica/acpivar.h>
152 * Hooks for the ACPI CA debugging infrastructure
154 #define _COMPONENT ACPI_EC
155 ACPI_MODULE_NAME("EC")
161 typedef UINT8 EC_COMMAND;
163 #define EC_COMMAND_UNKNOWN ((EC_COMMAND) 0x00)
164 #define EC_COMMAND_READ ((EC_COMMAND) 0x80)
165 #define EC_COMMAND_WRITE ((EC_COMMAND) 0x81)
166 #define EC_COMMAND_BURST_ENABLE ((EC_COMMAND) 0x82)
167 #define EC_COMMAND_BURST_DISABLE ((EC_COMMAND) 0x83)
168 #define EC_COMMAND_QUERY ((EC_COMMAND) 0x84)
173 * The encoding of the EC status register is illustrated below.
174 * Note that a set bit (1) indicates the property is TRUE
175 * (e.g. if bit 0 is set then the output buffer is full).
180 * | | | | | | | +- Output Buffer Full?
181 * | | | | | | +--- Input Buffer Full?
182 * | | | | | +----- <reserved>
183 * | | | | +------- Data Register is Command Byte?
184 * | | | +--------- Burst Mode Enabled?
185 * | | +----------- SCI Event?
186 * | +------------- SMI Event?
187 * +--------------- <Reserved>
190 typedef UINT8 EC_STATUS;
192 #define EC_FLAG_OUTPUT_BUFFER ((EC_STATUS) 0x01)
193 #define EC_FLAG_INPUT_BUFFER ((EC_STATUS) 0x02)
194 #define EC_FLAG_BURST_MODE ((EC_STATUS) 0x10)
195 #define EC_FLAG_SCI ((EC_STATUS) 0x20)
201 typedef UINT8 EC_EVENT;
203 #define EC_EVENT_UNKNOWN ((EC_EVENT) 0x00)
204 #define EC_EVENT_OUTPUT_BUFFER_FULL ((EC_EVENT) 0x01)
205 #define EC_EVENT_INPUT_BUFFER_EMPTY ((EC_EVENT) 0x02)
206 #define EC_EVENT_SCI ((EC_EVENT) 0x20)
209 * Register access primitives
211 #define EC_GET_DATA(sc) \
212 bus_space_read_1((sc)->ec_data_tag, (sc)->ec_data_handle, 0)
214 #define EC_SET_DATA(sc, v) \
215 bus_space_write_1((sc)->ec_data_tag, (sc)->ec_data_handle, 0, (v))
217 #define EC_GET_CSR(sc) \
218 bus_space_read_1((sc)->ec_csr_tag, (sc)->ec_csr_handle, 0)
220 #define EC_SET_CSR(sc, v) \
221 bus_space_write_1((sc)->ec_csr_tag, (sc)->ec_csr_handle, 0, (v))
226 struct acpi_ec_softc {
228 ACPI_HANDLE ec_handle;
232 struct resource *ec_data_res;
233 bus_space_tag_t ec_data_tag;
234 bus_space_handle_t ec_data_handle;
237 struct resource *ec_csr_res;
238 bus_space_tag_t ec_csr_tag;
239 bus_space_handle_t ec_csr_handle;
247 #define EC_LOCK_TIMEOUT 1000 /* 1ms */
249 static __inline ACPI_STATUS
250 EcLock(struct acpi_ec_softc *sc)
254 /* XXX WAIT_FOREVER is probably a bad idea, what is a better time? */
255 if (ACPI_SUCCESS(status = AcpiAcquireGlobalLock(WAIT_FOREVER, &sc->ec_lockhandle)))
262 EcUnlock(struct acpi_ec_softc *sc)
265 AcpiReleaseGlobalLock(sc->ec_lockhandle);
269 EcIsLocked(struct acpi_ec_softc *sc)
271 return((sc)->ec_locked != 0);
281 static void EcGpeHandler(void *Context);
282 static ACPI_STATUS EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function,
283 void *Context, void **return_Context);
284 static ACPI_STATUS EcSpaceHandler(UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 width, ACPI_INTEGER *Value,
285 void *Context, void *RegionContext);
287 static ACPI_STATUS EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event);
288 static ACPI_STATUS EcQuery(struct acpi_ec_softc *sc, UINT8 *Data);
289 static ACPI_STATUS EcTransaction(struct acpi_ec_softc *sc, EC_REQUEST *EcRequest);
290 static ACPI_STATUS EcRead(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data);
291 static ACPI_STATUS EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data);
293 static void acpi_ec_identify(driver_t driver, device_t bus);
294 static int acpi_ec_probe(device_t dev);
295 static int acpi_ec_attach(device_t dev);
297 static device_method_t acpi_ec_methods[] = {
298 /* Device interface */
299 DEVMETHOD(device_identify, acpi_ec_identify),
300 DEVMETHOD(device_probe, acpi_ec_probe),
301 DEVMETHOD(device_attach, acpi_ec_attach),
306 static driver_t acpi_ec_driver = {
309 sizeof(struct acpi_ec_softc),
312 static devclass_t acpi_ec_devclass;
313 DRIVER_MODULE(acpi_ec, acpi, acpi_ec_driver, acpi_ec_devclass, 0, 0);
316 * Look for an ECDT table and if we find one, set up a default EC
317 * space handler to catch possible attempts to access EC space before
318 * we have a real driver instance in place.
319 * We're not really an identify routine, but because we get called
320 * before most other things, this works out OK.
323 acpi_ec_identify(driver_t driver, device_t bus)
325 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
327 /* XXX implement - need an ACPI 2.0 system to test this */
333 * We could setup resources in the probe routine in order to have them printed
334 * when the device is attached.
337 acpi_ec_probe(device_t dev)
340 if ((acpi_get_type(dev) == ACPI_TYPE_DEVICE) &&
341 !acpi_disabled("ec") &&
342 acpi_MatchHid(dev, "PNP0C09")) {
345 * Set device description
347 device_set_desc(dev, "embedded controller");
355 acpi_ec_attach(device_t dev)
357 struct acpi_ec_softc *sc;
361 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
364 * Fetch/initialise softc
366 sc = device_get_softc(dev);
367 bzero(sc, sizeof(*sc));
369 sc->ec_handle = acpi_get_handle(dev);
372 * Attach bus resources
375 if ((sc->ec_data_res = bus_alloc_resource(sc->ec_dev, SYS_RES_IOPORT, &sc->ec_data_rid,
376 0, ~0, 1, RF_ACTIVE)) == NULL) {
377 device_printf(dev, "can't allocate data port\n");
381 sc->ec_data_tag = rman_get_bustag(sc->ec_data_res);
382 sc->ec_data_handle = rman_get_bushandle(sc->ec_data_res);
385 if ((sc->ec_csr_res = bus_alloc_resource(sc->ec_dev, SYS_RES_IOPORT, &sc->ec_csr_rid,
386 0, ~0, 1, RF_ACTIVE)) == NULL) {
387 device_printf(dev, "can't allocate command/status port\n");
391 sc->ec_csr_tag = rman_get_bustag(sc->ec_csr_res);
392 sc->ec_csr_handle = rman_get_bushandle(sc->ec_csr_res);
395 * Install GPE handler
397 * Evaluate the _GPE method to find the GPE bit used by the EC to signal
400 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching GPE\n"));
401 if (ACPI_FAILURE(Status = acpi_EvaluateInteger(sc->ec_handle, "_GPE", &sc->ec_gpebit))) {
402 device_printf(dev, "can't evaluate _GPE - %s\n", AcpiFormatException(Status));
408 * Install a handler for this EC's GPE bit. Note that EC SCIs are
409 * treated as both edge- and level-triggered interrupts; in other words
410 * we clear the status bit immediately after getting an EC-SCI, then
411 * again after we're done processing the event. This guarantees that
412 * events we cause while performing a transaction (e.g. IBE/OBF) get
413 * cleared before re-enabling the GPE.
415 if (ACPI_FAILURE(Status = AcpiInstallGpeHandler(sc->ec_gpebit,
416 ACPI_EVENT_LEVEL_TRIGGERED |
417 ACPI_EVENT_EDGE_TRIGGERED,
418 EcGpeHandler, sc))) {
419 device_printf(dev, "can't install GPE handler for %s - %s\n",
420 acpi_name(sc->ec_handle), AcpiFormatException(Status));
426 * Install address space handler
428 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching address space handler\n"));
429 if (ACPI_FAILURE(Status = AcpiInstallAddressSpaceHandler(sc->ec_handle,
434 device_printf(dev, "can't install address space handler for %s - %s\n",
435 acpi_name(sc->ec_handle), AcpiFormatException(Status));
440 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attach complete\n"));
444 bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_csr_rid,
447 bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_data_rid,
449 return_VALUE(errval);
453 EcGpeQueryHandler(void *Context)
455 struct acpi_ec_softc *sc = (struct acpi_ec_softc *)Context;
460 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
467 * Bail out if the EC_SCI bit of the status register is not set.
468 * Note that this function should only be called when
469 * this bit is set (polling is used to detect IBE/OBF events).
471 * It is safe to do this without locking the controller, as it's
472 * OK to call EcQuery when there's no data ready; in the worst
473 * case we should just find nothing waiting for us and bail.
475 if (!(EC_GET_CSR(sc) & EC_EVENT_SCI))
479 * Find out why the EC is signalling us
481 Status = EcQuery(sc, &Data);
484 * If we failed to get anything from the EC, give up
486 if (ACPI_FAILURE(Status)) {
487 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
488 "GPE query failed - %s\n", AcpiFormatException(Status));
493 * Evaluate _Qxx to respond to the controller.
495 sprintf(qxx, "_Q%02x", Data);
497 Status = AcpiEvaluateObject(sc->ec_handle, qxx, NULL, NULL);
499 * Ignore spurious query requests.
501 if (ACPI_FAILURE(Status) && (Data != 0 || Status != AE_NOT_FOUND)) {
502 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
503 "evaluation of GPE query method %s failed - %s\n",
504 qxx, AcpiFormatException(Status));
507 /* I know I request Level trigger cleanup */
508 if (ACPI_FAILURE(AcpiClearEvent(sc->ec_gpebit, ACPI_EVENT_GPE)))
509 printf("EcGpeQueryHandler:ClearEvent Failed\n");
510 if (ACPI_FAILURE(AcpiEnableEvent(sc->ec_gpebit, ACPI_EVENT_GPE, 0)))
511 printf("EcGpeQueryHandler:EnableEvent Failed\n");
516 * Handle a GPE sent to us.
519 EcGpeHandler(void *Context)
521 struct acpi_ec_softc *sc = Context;
525 * If EC is locked, the intr must process EcRead/Write wait only.
526 * Query request must be pending.
529 csrvalue = EC_GET_CSR(sc);
530 if (csrvalue & EC_EVENT_SCI)
531 sc->ec_pendquery = 1;
532 if ((csrvalue & EC_FLAG_OUTPUT_BUFFER)
533 || !(csrvalue & EC_FLAG_INPUT_BUFFER)) {
534 sc->ec_csrvalue = csrvalue;
535 wakeup((void *)&sc->ec_csrvalue);
538 /* Queue GpeQuery Handler */
539 if (ACPI_FAILURE(AcpiOsQueueForExecution(OSD_PRIORITY_HIGH,
540 EcGpeQueryHandler,Context))) {
541 printf("QueryHandler Queuing Failed\n");
548 EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function, void *Context, void **RegionContext)
551 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
554 * Just pass the context through, there's nothing to do here.
556 *RegionContext = Context;
558 return_ACPI_STATUS(AE_OK);
562 EcSpaceHandler(UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 width, ACPI_INTEGER *Value,
563 void *Context, void *RegionContext)
565 struct acpi_ec_softc *sc = (struct acpi_ec_softc *)Context;
566 ACPI_STATUS Status = AE_OK;
567 EC_REQUEST EcRequest;
570 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, (UINT32)Address);
572 if ((Address > 0xFF) || (width % 8 != 0) || (Value == NULL) || (Context == NULL))
573 return_ACPI_STATUS(AE_BAD_PARAMETER);
577 EcRequest.Command = EC_COMMAND_READ;
578 EcRequest.Address = Address;
583 EcRequest.Command = EC_COMMAND_WRITE;
584 EcRequest.Address = Address;
588 device_printf(sc->ec_dev, "invalid Address Space function %d\n", Function);
589 return_ACPI_STATUS(AE_BAD_PARAMETER);
593 * Perform the transaction.
595 for (i = 0; i < width; i += 8) {
596 if (Function == ACPI_READ)
599 EcRequest.Data = (UINT8)((*Value) >> i);
600 if (ACPI_FAILURE(Status = EcTransaction(sc, &EcRequest)))
602 (*Value) |= (ACPI_INTEGER)EcRequest.Data << i;
603 if (++EcRequest.Address == 0)
604 return_ACPI_STATUS(AE_BAD_PARAMETER);
606 return_ACPI_STATUS(Status);
610 * Wait for an event interrupt for a specific condition.
613 EcWaitEventIntr(struct acpi_ec_softc *sc, EC_EVENT Event)
618 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, (UINT32)Event);
620 /* XXX this should test whether interrupts are available some other way */
621 #ifdef ACPI_EC_EVENT_DRIVEN
624 return_ACPI_STATUS(EcWaitEvent(sc, Event));
627 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
628 "EcWaitEventIntr called without EC lock!\n");
630 EcStatus = EC_GET_CSR(sc);
632 /* XXX waiting too long? */
633 for(i = 0; i < 10; i++){
635 * Check EC status against the desired event.
637 if ((Event == EC_EVENT_OUTPUT_BUFFER_FULL) &&
638 (EcStatus & EC_FLAG_OUTPUT_BUFFER))
639 return_ACPI_STATUS(AE_OK);
641 if ((Event == EC_EVENT_INPUT_BUFFER_EMPTY) &&
642 !(EcStatus & EC_FLAG_INPUT_BUFFER))
643 return_ACPI_STATUS(AE_OK);
646 if (ACPI_MSLEEP(&sc->ec_csrvalue, &acpi_mutex, PZERO, "EcWait", 1) != EWOULDBLOCK){
647 EcStatus = sc->ec_csrvalue;
649 EcStatus = EC_GET_CSR(sc);
652 return_ACPI_STATUS(AE_ERROR);
656 EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event)
662 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
663 "EcWaitEvent called without EC lock!\n");
668 * Stall for 1 microsecond before reading the status register
669 * for the first time. This allows the EC to set the IBF/OBF
670 * bit to its proper state.
672 * XXX it is not clear why we read the CSR twice.
675 EcStatus = EC_GET_CSR(sc);
680 * Poll the EC status register to detect completion of the last
681 * command. Wait up to 10ms (in 10us chunks) for this to occur.
683 for (i = 0; i < 1000; i++) {
684 EcStatus = EC_GET_CSR(sc);
686 if ((Event == EC_EVENT_OUTPUT_BUFFER_FULL) &&
687 (EcStatus & EC_FLAG_OUTPUT_BUFFER))
690 if ((Event == EC_EVENT_INPUT_BUFFER_EMPTY) &&
691 !(EcStatus & EC_FLAG_INPUT_BUFFER))
701 EcQuery(struct acpi_ec_softc *sc, UINT8 *Data)
705 if (ACPI_FAILURE(Status = EcLock(sc)))
708 EC_SET_CSR(sc, EC_COMMAND_QUERY);
709 if (ACPI_SUCCESS(Status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL)))
710 *Data = EC_GET_DATA(sc);
714 if (ACPI_FAILURE(Status))
715 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
716 "timeout waiting for EC to respond to EC_COMMAND_QUERY\n");
721 EcTransaction(struct acpi_ec_softc *sc, EC_REQUEST *EcRequest)
728 if (ACPI_FAILURE(Status = EcLock(sc)))
732 * Perform the transaction.
734 switch (EcRequest->Command) {
735 case EC_COMMAND_READ:
736 Status = EcRead(sc, EcRequest->Address, &(EcRequest->Data));
739 case EC_COMMAND_WRITE:
740 Status = EcWrite(sc, EcRequest->Address, &(EcRequest->Data));
754 * Clear & Re-Enable the EC GPE:
755 * -----------------------------
756 * 'Consume' any EC GPE events that we generated while performing
757 * the transaction (e.g. IBF/OBF). Clearing the GPE here shouldn't
758 * have an adverse affect on outstanding EC-SCI's, as the source
759 * (EC-SCI) will still be high and thus should trigger the GPE
760 * immediately after we re-enabling it.
762 if (sc->ec_pendquery){
763 if (ACPI_FAILURE(AcpiOsQueueForExecution(OSD_PRIORITY_HIGH,
764 EcGpeQueryHandler, sc)))
765 printf("Pend Query Queuing Failed\n");
766 sc->ec_pendquery = 0;
769 if (ACPI_FAILURE(AcpiClearEvent(sc->ec_gpebit, ACPI_EVENT_GPE)))
770 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
771 "EcRequest: Unable to clear the EC GPE.\n");
772 if (ACPI_FAILURE(AcpiEnableEvent(sc->ec_gpebit, ACPI_EVENT_GPE, 0)))
773 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
774 "EcRequest: Unable to re-enable the EC GPE.\n");
781 EcRead(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data)
786 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
787 "EcRead called without EC lock!\n");
789 /*EcBurstEnable(EmbeddedController);*/
791 EC_SET_CSR(sc, EC_COMMAND_READ);
792 if (ACPI_FAILURE(Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY))) {
793 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
794 "EcRead: Failed waiting for EC to process read command.\n");
798 EC_SET_DATA(sc, Address);
799 if (ACPI_FAILURE(Status = EcWaitEventIntr(sc, EC_EVENT_OUTPUT_BUFFER_FULL))) {
800 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
801 "EcRead: Failed waiting for EC to send data.\n");
805 (*Data) = EC_GET_DATA(sc);
807 /*EcBurstDisable(EmbeddedController);*/
813 EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data)
818 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
819 "EcWrite called without EC lock!\n");
821 /*EcBurstEnable(EmbeddedController);*/
823 EC_SET_CSR(sc, EC_COMMAND_WRITE);
824 if (ACPI_FAILURE(Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY))) {
825 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
826 "EcWrite: Failed waiting for EC to process write command.\n");
830 EC_SET_DATA(sc, Address);
831 if (ACPI_FAILURE(Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY))) {
832 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
833 "EcRead: Failed waiting for EC to process address.\n");
837 EC_SET_DATA(sc, *Data);
838 if (ACPI_FAILURE(Status = EcWaitEventIntr(sc, EC_EVENT_INPUT_BUFFER_EMPTY))) {
839 ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev),
840 "EcWrite: Failed waiting for EC to process data.\n");
844 /*EcBurstDisable(EmbeddedController);*/