|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
|
/*-
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2009 Clemens Zeidler
|
|
|
|
|
* Copyright (c) 2003-2007 Nate Lawson
|
|
|
|
|
* Copyright (c) 2000 Michael Smith
|
|
|
|
@@ -27,6 +27,7 @@
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "acpi_embedded_controller.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
@@ -40,6 +41,7 @@
|
|
|
|
|
|
|
|
|
|
#include "SmallResourceData.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define ACPI_EC_DRIVER_NAME "drivers/power/acpi_embedded_controller/driver_v1"
|
|
|
|
|
|
|
|
|
|
#define ACPI_EC_DEVICE_NAME "drivers/power/acpi_embedded_controller/device_v1"
|
|
|
|
@@ -59,9 +61,9 @@ bus_space_read_1(int address)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bus_space_write_1(int address, uint8 v)
|
|
|
|
|
bus_space_write_1(int address, uint8 value)
|
|
|
|
|
{
|
|
|
|
|
gPCIManager->write_io_8(address, v);
|
|
|
|
|
gPCIManager->write_io_8(address, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -74,12 +76,9 @@ acpi_GetInteger(acpi_device_module_info* acpi, acpi_device& acpiCookie,
|
|
|
|
|
buf.pointer = &object;
|
|
|
|
|
buf.length = sizeof(acpi_object_type);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Assume that what we've been pointed at is an Integer object, or
|
|
|
|
|
* a method that will return an Integer.
|
|
|
|
|
*/
|
|
|
|
|
// Assume that what we've been pointed at is an Integer object, or
|
|
|
|
|
// a method that will return an Integer.
|
|
|
|
|
status_t status = acpi->evaluate_method(acpiCookie, path, NULL, &buf);
|
|
|
|
|
|
|
|
|
|
if (status == B_OK) {
|
|
|
|
|
if (object.object_type == ACPI_TYPE_INTEGER)
|
|
|
|
|
*number = object.data.integer;
|
|
|
|
@@ -98,20 +97,15 @@ acpi_GetReference(acpi_module_info* acpi, acpi_handle scope,
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
switch (obj->object_type) {
|
|
|
|
|
|
|
|
|
|
case ACPI_TYPE_LOCAL_REFERENCE:
|
|
|
|
|
case ACPI_TYPE_ANY:
|
|
|
|
|
return obj->data.reference.handle;
|
|
|
|
|
|
|
|
|
|
case ACPI_TYPE_STRING:
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The String object usually contains a fully-qualified path, so
|
|
|
|
|
* scope can be NULL.
|
|
|
|
|
*
|
|
|
|
|
* XXX This may not always be the case.
|
|
|
|
|
*/
|
|
|
|
|
// The String object usually contains a fully-qualified path, so
|
|
|
|
|
// scope can be NULL.
|
|
|
|
|
// TODO: This may not always be the case.
|
|
|
|
|
acpi_handle handle;
|
|
|
|
|
if (acpi->get_handle(scope, obj->data.string.string, &handle)
|
|
|
|
|
== B_OK)
|
|
|
|
@@ -148,6 +142,9 @@ acpi_PkgInt32(acpi_object_type* res, int idx, uint32* dst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static status_t
|
|
|
|
|
embedded_controller_open(void* initCookie, const char* path, int flags,
|
|
|
|
|
void** cookie)
|
|
|
|
@@ -198,6 +195,7 @@ embedded_controller_free(void* cookie)
|
|
|
|
|
|
|
|
|
|
// #pragma mark - driver module API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32
|
|
|
|
|
acpi_get_type(device_node* dev)
|
|
|
|
|
{
|
|
|
|
@@ -220,22 +218,31 @@ acpi_get_type(device_node* dev)
|
|
|
|
|
static float
|
|
|
|
|
embedded_controller_support(device_node* dev)
|
|
|
|
|
{
|
|
|
|
|
static const char* ec_ids[] = { "PNP0C09", NULL };
|
|
|
|
|
TRACE("embedded_controller_support()\n");
|
|
|
|
|
|
|
|
|
|
/* Check that this is a device. */
|
|
|
|
|
TRACE("before acpi_get_type...");
|
|
|
|
|
// Check that this is a device
|
|
|
|
|
if (acpi_get_type(dev) != ACPI_TYPE_DEVICE)
|
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
|
|
const char* name;
|
|
|
|
|
|
|
|
|
|
if (gDeviceManager->get_attr_string(dev, ACPI_DEVICE_HID_ITEM, &name, false)
|
|
|
|
|
!= B_OK || strcmp(name, ec_ids[0]))
|
|
|
|
|
!= B_OK)
|
|
|
|
|
return 0.0;
|
|
|
|
|
TRACE("after\n");
|
|
|
|
|
|
|
|
|
|
// Test all known IDs
|
|
|
|
|
|
|
|
|
|
static const char* kEmbeddedControllerIDs[] = { "PNP0C09" };
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(kEmbeddedControllerIDs)
|
|
|
|
|
/ sizeof(kEmbeddedControllerIDs[0]); i++) {
|
|
|
|
|
if (!strcmp(name, kEmbeddedControllerIDs[i])) {
|
|
|
|
|
TRACE("supported device found %s\n", name);
|
|
|
|
|
return 0.6;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static status_t
|
|
|
|
@@ -259,6 +266,9 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
|
|
|
|
|
acpi_ec_cookie* sc;
|
|
|
|
|
sc = (acpi_ec_cookie*)malloc(sizeof(acpi_ec_cookie));
|
|
|
|
|
if (sc == NULL)
|
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
|
|
memset(sc, 0, sizeof(acpi_ec_cookie));
|
|
|
|
|
|
|
|
|
|
*_driverCookie = sc;
|
|
|
|
@@ -286,12 +296,9 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
buf.pointer = NULL;
|
|
|
|
|
buf.length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read the unit ID to check for duplicate attach and the
|
|
|
|
|
* global lock value to see if we should acquire it when
|
|
|
|
|
* accessing the EC.
|
|
|
|
|
*/
|
|
|
|
|
// Read the unit ID to check for duplicate attach and the
|
|
|
|
|
// global lock value to see if we should acquire it when
|
|
|
|
|
// accessing the EC.
|
|
|
|
|
status_t status = acpi_GetInteger(sc->ec_acpi, sc->ec_handle, "_UID",
|
|
|
|
|
&sc->ec_uid);
|
|
|
|
|
if (status != B_OK)
|
|
|
|
@@ -300,11 +307,9 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
if (status != B_OK)
|
|
|
|
|
sc->ec_glk = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Evaluate the _GPE method to find the GPE bit used by the EC to
|
|
|
|
|
* signal status (SCI). If it's a package, it contains a reference
|
|
|
|
|
* and GPE bit, similar to _PRW.
|
|
|
|
|
*/
|
|
|
|
|
// Evaluate the _GPE method to find the GPE bit used by the EC to
|
|
|
|
|
// signal status (SCI). If it's a package, it contains a reference
|
|
|
|
|
// and GPE bit, similar to _PRW.
|
|
|
|
|
status = sc->ec_acpi->evaluate_method(sc->ec_handle, "_GPE", NULL, &buf);
|
|
|
|
|
if (status != B_OK) {
|
|
|
|
|
TRACE("can't evaluate _GPE\n");
|
|
|
|
@@ -337,7 +342,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
|
|
|
|
|
sc->ec_suspending = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Attach bus resources for data and command/status ports. */
|
|
|
|
|
// Attach bus resources for data and command/status ports.
|
|
|
|
|
if (resourceData.ReadIOPort(&portData) != B_OK)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
@@ -348,10 +353,8 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
|
|
|
|
|
sc->ec_csr_pci_address = portData.minimumBase;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Install a handler for this EC's GPE bit. We want edge-triggered
|
|
|
|
|
* behavior.
|
|
|
|
|
*/
|
|
|
|
|
// Install a handler for this EC's GPE bit. We want edge-triggered
|
|
|
|
|
// behavior.
|
|
|
|
|
TRACE("attaching GPE handler\n");
|
|
|
|
|
status = sc->ec_acpi_module->install_gpe_handler(sc->ec_gpehandle,
|
|
|
|
|
sc->ec_gpebit, ACPI_GPE_EDGE_TRIGGERED, &EcGpeHandler, sc);
|
|
|
|
@@ -360,7 +363,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Install address space handler */
|
|
|
|
|
// Install address space handler
|
|
|
|
|
TRACE("attaching address space handler\n");
|
|
|
|
|
status = sc->ec_acpi->install_address_space_handler(sc->ec_handle,
|
|
|
|
|
ACPI_ADR_SPACE_EC, &EcSpaceHandler, &EcSpaceSetup, sc);
|
|
|
|
@@ -369,7 +372,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Enable runtime GPEs for the handler. */
|
|
|
|
|
// Enable runtime GPEs for the handler.
|
|
|
|
|
status = sc->ec_acpi_module->set_gpe_type(sc->ec_gpehandle, sc->ec_gpebit,
|
|
|
|
|
ACPI_GPE_TYPE_RUNTIME);
|
|
|
|
|
if (status != B_OK) {
|
|
|
|
@@ -386,7 +389,6 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (buf.pointer)
|
|
|
|
|
free(buf.pointer);
|
|
|
|
|
|
|
|
|
|
sc->ec_acpi_module->remove_gpe_handler(sc->ec_gpehandle, sc->ec_gpebit,
|
|
|
|
@@ -482,6 +484,9 @@ struct device_module_info embedded_controller_device_module = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
EcGpeQueryHandler(void* context)
|
|
|
|
|
{
|
|
|
|
@@ -489,20 +494,18 @@ EcGpeQueryHandler(void* context)
|
|
|
|
|
|
|
|
|
|
ASSERT(context != NULL);//, ("EcGpeQueryHandler called with NULL"));
|
|
|
|
|
|
|
|
|
|
/* Serialize user access with EcSpaceHandler(). */
|
|
|
|
|
// Serialize user access with EcSpaceHandler().
|
|
|
|
|
status_t status = EcLock(sc);
|
|
|
|
|
if (status != B_OK) {
|
|
|
|
|
TRACE("GpeQuery lock error.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Send a query command to the EC to find out which _Qxx call it
|
|
|
|
|
* wants to make. This command clears the SCI bit and also the
|
|
|
|
|
* interrupt source since we are edge-triggered. To prevent the GPE
|
|
|
|
|
* that may arise from running the query from causing another query
|
|
|
|
|
* to be queued, we clear the pending flag only after running it.
|
|
|
|
|
*/
|
|
|
|
|
// Send a query command to the EC to find out which _Qxx call it
|
|
|
|
|
// wants to make. This command clears the SCI bit and also the
|
|
|
|
|
// interrupt source since we are edge-triggered. To prevent the GPE
|
|
|
|
|
// that may arise from running the query from causing another query
|
|
|
|
|
// to be queued, we clear the pending flag only after running it.
|
|
|
|
|
status = EcCommand(sc, EC_COMMAND_QUERY);
|
|
|
|
|
sc->ec_sci_pending = FALSE;
|
|
|
|
|
if (status != B_OK) {
|
|
|
|
@@ -512,19 +515,17 @@ EcGpeQueryHandler(void* context)
|
|
|
|
|
}
|
|
|
|
|
uint8 data = EC_GET_DATA(sc);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We have to unlock before running the _Qxx method below since that
|
|
|
|
|
* method may attempt to read/write from EC address space, causing
|
|
|
|
|
* recursive acquisition of the lock.
|
|
|
|
|
*/
|
|
|
|
|
// We have to unlock before running the _Qxx method below since that
|
|
|
|
|
// method may attempt to read/write from EC address space, causing
|
|
|
|
|
// recursive acquisition of the lock.
|
|
|
|
|
EcUnlock(sc);
|
|
|
|
|
|
|
|
|
|
/* Ignore the value for "no outstanding event". (13.3.5) */
|
|
|
|
|
// Ignore the value for "no outstanding event". (13.3.5)
|
|
|
|
|
TRACE("query ok,%s running _Q%02X\n", data ? "" : " not", data);
|
|
|
|
|
if (data == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Evaluate _Qxx to respond to the controller. */
|
|
|
|
|
// Evaluate _Qxx to respond to the controller.
|
|
|
|
|
char qxx[5];
|
|
|
|
|
snprintf(qxx, sizeof(qxx), "_Q%02X", data);
|
|
|
|
|
AcpiUtStrupr(qxx);
|
|
|
|
@@ -535,9 +536,8 @@ EcGpeQueryHandler(void* context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The GPE handler is called when IBE/OBF or SCI events occur. We are
|
|
|
|
|
* called from an unknown lock context.
|
|
|
|
|
/*! The GPE handler is called when IBE/OBF or SCI events occur. We are
|
|
|
|
|
called from an unknown lock context.
|
|
|
|
|
*/
|
|
|
|
|
static uint32
|
|
|
|
|
EcGpeHandler(void* context)
|
|
|
|
@@ -547,25 +547,21 @@ EcGpeHandler(void* context)
|
|
|
|
|
ASSERT(context != NULL);//, ("EcGpeHandler called with NULL"));
|
|
|
|
|
TRACE("gpe handler start\n");
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Notify EcWaitEvent() that the status register is now fresh. If we
|
|
|
|
|
* didn't do this, it wouldn't be possible to distinguish an old IBE
|
|
|
|
|
* from a new one, for example when doing a write transaction (writing
|
|
|
|
|
* address and then data values.)
|
|
|
|
|
*/
|
|
|
|
|
// Notify EcWaitEvent() that the status register is now fresh. If we
|
|
|
|
|
// didn't do this, it wouldn't be possible to distinguish an old IBE
|
|
|
|
|
// from a new one, for example when doing a write transaction (writing
|
|
|
|
|
// address and then data values.)
|
|
|
|
|
atomic_add(&sc->ec_gencount, 1);
|
|
|
|
|
sc->ec_condition_var.NotifyAll();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the EC_SCI bit of the status register is set, queue a query handler.
|
|
|
|
|
* It will run the query and _Qxx method later, under the lock.
|
|
|
|
|
*/
|
|
|
|
|
// If the EC_SCI bit of the status register is set, queue a query handler.
|
|
|
|
|
// It will run the query and _Qxx method later, under the lock.
|
|
|
|
|
EC_STATUS EcStatus = EC_GET_CSR(sc);
|
|
|
|
|
if ((EcStatus & EC_EVENT_SCI) && !sc->ec_sci_pending) {
|
|
|
|
|
TRACE("gpe queueing query handler\n");
|
|
|
|
|
ACPI_STATUS s = AcpiOsExecute(OSL_GPE_HANDLER, EcGpeQueryHandler,
|
|
|
|
|
ACPI_STATUS status = AcpiOsExecute(OSL_GPE_HANDLER, EcGpeQueryHandler,
|
|
|
|
|
context);
|
|
|
|
|
if (s == AE_OK)
|
|
|
|
|
if (status == AE_OK)
|
|
|
|
|
sc->ec_sci_pending = TRUE;
|
|
|
|
|
else
|
|
|
|
|
dprintf("EcGpeHandler: queuing GPE query handler failed\n");
|
|
|
|
@@ -578,10 +574,8 @@ static acpi_status
|
|
|
|
|
EcSpaceSetup(acpi_handle region, uint32 function, void* context,
|
|
|
|
|
void** regionContext)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* If deactivating a region, always set the output to NULL. Otherwise,
|
|
|
|
|
* just pass the context through.
|
|
|
|
|
*/
|
|
|
|
|
// If deactivating a region, always set the output to NULL. Otherwise,
|
|
|
|
|
// just pass the context through.
|
|
|
|
|
if (function == ACPI_REGION_DEACTIVATE)
|
|
|
|
|
*regionContext = NULL;
|
|
|
|
|
else
|
|
|
|
@@ -599,7 +593,6 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
|
|
|
|
|
struct acpi_ec_cookie* sc = (struct acpi_ec_cookie*)context;
|
|
|
|
|
uint8 ecData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (width % 8 != 0 || value == NULL || context == NULL)
|
|
|
|
|
return AE_BAD_PARAMETER;
|
|
|
|
|
if (address + (width / 8) - 1 > 0xFF)
|
|
|
|
@@ -622,12 +615,12 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
|
|
|
|
|
}
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
/* Serialize with EcGpeQueryHandler() at transaction granularity. */
|
|
|
|
|
// Serialize with EcGpeQueryHandler() at transaction granularity.
|
|
|
|
|
status = EcLock(sc);
|
|
|
|
|
if (status != B_OK)
|
|
|
|
|
return AE_NOT_ACQUIRED;
|
|
|
|
|
|
|
|
|
|
/* Perform the transaction(s), based on width. */
|
|
|
|
|
// Perform the transaction(s), based on width.
|
|
|
|
|
for (uint32 i = 0; i < width; i += 8, ecAddr++) {
|
|
|
|
|
switch (function) {
|
|
|
|
|
case ACPI_READ:
|
|
|
|
@@ -644,10 +637,9 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
|
|
|
|
|
status = AE_BAD_PARAMETER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (status != AE_OK) {
|
|
|
|
|
if (status != AE_OK)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EcUnlock(sc);
|
|
|
|
|
return status;
|
|
|
|
@@ -673,27 +665,25 @@ EcCheckStatus(struct acpi_ec_cookie* sc, const char* msg, EC_EVENT event)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static acpi_status
|
|
|
|
|
EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
|
|
|
|
|
EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 generationCount)
|
|
|
|
|
{
|
|
|
|
|
acpi_status status = AE_NO_HARDWARE_RESPONSE;
|
|
|
|
|
int32 count, i;
|
|
|
|
|
|
|
|
|
|
// int need_poll = cold || rebooting || ec_polled_mode || sc->ec_suspending;
|
|
|
|
|
int need_poll = ec_polled_mode || sc->ec_suspending;
|
|
|
|
|
int needPoll = ec_polled_mode || sc->ec_suspending;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The main CPU should be much faster than the EC. So the status should
|
|
|
|
|
* be "not ready" when we start waiting. But if the main CPU is really
|
|
|
|
|
* slow, it's possible we see the current "ready" response. Since that
|
|
|
|
|
* can't be distinguished from the previous response in polled mode,
|
|
|
|
|
* this is a potential issue. We really should have interrupts enabled
|
|
|
|
|
* during boot so there is no ambiguity in polled mode.
|
|
|
|
|
*
|
|
|
|
|
* If this occurs, we add an additional delay before actually entering
|
|
|
|
|
* the status checking loop, hopefully to allow the EC to go to work
|
|
|
|
|
* and produce a non-stale status.
|
|
|
|
|
*/
|
|
|
|
|
if (need_poll) {
|
|
|
|
|
// The main CPU should be much faster than the EC. So the status should
|
|
|
|
|
// be "not ready" when we start waiting. But if the main CPU is really
|
|
|
|
|
// slow, it's possible we see the current "ready" response. Since that
|
|
|
|
|
// can't be distinguished from the previous response in polled mode,
|
|
|
|
|
// this is a potential issue. We really should have interrupts enabled
|
|
|
|
|
// during boot so there is no ambiguity in polled mode.
|
|
|
|
|
//
|
|
|
|
|
// If this occurs, we add an additional delay before actually entering
|
|
|
|
|
// the status checking loop, hopefully to allow the EC to go to work
|
|
|
|
|
// and produce a non-stale status.
|
|
|
|
|
if (needPoll) {
|
|
|
|
|
static int once;
|
|
|
|
|
|
|
|
|
|
if (EcCheckStatus(sc, "pre-check", event) == B_OK) {
|
|
|
|
@@ -705,11 +695,12 @@ EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait for event by polling or GPE (interrupt). */
|
|
|
|
|
if (need_poll) {
|
|
|
|
|
// Wait for event by polling or GPE (interrupt).
|
|
|
|
|
if (needPoll) {
|
|
|
|
|
count = (ec_timeout * 1000) / EC_POLL_DELAY;
|
|
|
|
|
if (count == 0)
|
|
|
|
|
count = 1;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
|
status = EcCheckStatus(sc, "poll", event);
|
|
|
|
|
if (status == AE_OK)
|
|
|
|
@@ -717,38 +708,32 @@ EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
|
|
|
|
|
spin(EC_POLL_DELAY);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
bigtime_t slp_ival = system_time() + ec_timeout * 1000;
|
|
|
|
|
bigtime_t sleepInterval = system_time() + ec_timeout * 1000;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Wait for the GPE to signal the status changed, checking the
|
|
|
|
|
* status register each time we get one. It's possible to get a
|
|
|
|
|
* GPE for an event we're not interested in here (i.e., SCI for
|
|
|
|
|
* EC query).
|
|
|
|
|
*/
|
|
|
|
|
// Wait for the GPE to signal the status changed, checking the
|
|
|
|
|
// status register each time we get one. It's possible to get a
|
|
|
|
|
// GPE for an event we're not interested in here (i.e., SCI for
|
|
|
|
|
// EC query).
|
|
|
|
|
status_t waitStatus = B_NO_ERROR;
|
|
|
|
|
while (waitStatus != B_TIMED_OUT) {
|
|
|
|
|
if (gen_count != sc->ec_gencount) {
|
|
|
|
|
/*
|
|
|
|
|
* Record new generation count. It's possible the GPE was
|
|
|
|
|
* just to notify us that a query is needed and we need to
|
|
|
|
|
* wait for a second GPE to signal the completion of the
|
|
|
|
|
* event we are actually waiting for.
|
|
|
|
|
*/
|
|
|
|
|
gen_count = sc->ec_gencount;
|
|
|
|
|
if (generationCount != sc->ec_gencount) {
|
|
|
|
|
// Record new generation count. It's possible the GPE was
|
|
|
|
|
// just to notify us that a query is needed and we need to
|
|
|
|
|
// wait for a second GPE to signal the completion of the
|
|
|
|
|
// event we are actually waiting for.
|
|
|
|
|
generationCount = sc->ec_gencount;
|
|
|
|
|
status = EcCheckStatus(sc, "sleep", event);
|
|
|
|
|
if (status == AE_OK)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
waitStatus = sc->ec_condition_var.Wait(B_ABSOLUTE_TIMEOUT,
|
|
|
|
|
slp_ival);
|
|
|
|
|
sleepInterval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We finished waiting for the GPE and it never arrived. Try to
|
|
|
|
|
* read the register once and trust whatever value we got. This is
|
|
|
|
|
* the best we can do at this point. Then, force polled mode on
|
|
|
|
|
* since this system doesn't appear to generate GPEs.
|
|
|
|
|
*/
|
|
|
|
|
// We finished waiting for the GPE and it never arrived. Try to
|
|
|
|
|
// read the register once and trust whatever value we got. This is
|
|
|
|
|
// the best we can do at this point. Then, force polled mode on
|
|
|
|
|
// since this system doesn't appear to generate GPEs.
|
|
|
|
|
if (status != AE_OK) {
|
|
|
|
|
status = EcCheckStatus(sc, "sleep_end", event);
|
|
|
|
|
TRACE("wait timed out (%sresponse), forcing polled mode\n",
|
|
|
|
@@ -766,11 +751,11 @@ EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
|
|
|
|
|
static acpi_status
|
|
|
|
|
EcCommand(struct acpi_ec_cookie* sc, EC_COMMAND cmd)
|
|
|
|
|
{
|
|
|
|
|
/* Don't use burst mode if user disabled it. */
|
|
|
|
|
// Don't use burst mode if user disabled it.
|
|
|
|
|
if (!ec_burst_mode && cmd == EC_COMMAND_BURST_ENABLE)
|
|
|
|
|
return AE_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Decide what to wait for based on command type. */
|
|
|
|
|
// Decide what to wait for based on command type.
|
|
|
|
|
EC_EVENT event;
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
case EC_COMMAND_READ:
|
|
|
|
@@ -787,13 +772,13 @@ EcCommand(struct acpi_ec_cookie* sc, EC_COMMAND cmd)
|
|
|
|
|
return AE_BAD_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Run the command and wait for the chosen event. */
|
|
|
|
|
// Run the command and wait for the chosen event.
|
|
|
|
|
TRACE("running command %#x\n", cmd);
|
|
|
|
|
u_int gen_count = sc->ec_gencount;
|
|
|
|
|
EC_SET_CSR(sc, cmd);
|
|
|
|
|
acpi_status status = EcWaitEvent(sc, event, gen_count);
|
|
|
|
|
if (status == AE_OK) {
|
|
|
|
|
/* If we succeeded, burst flag should now be present. */
|
|
|
|
|
// If we succeeded, burst flag should now be present.
|
|
|
|
|
if (cmd == EC_COMMAND_BURST_ENABLE) {
|
|
|
|
|
EC_STATUS ec_status = EC_GET_CSR(sc);
|
|
|
|
|
if ((ec_status & EC_FLAG_BURST_MODE) == 0)
|
|
|
|
@@ -811,7 +796,7 @@ EcRead(struct acpi_ec_cookie* sc, uint8 address, uint8* readData)
|
|
|
|
|
{
|
|
|
|
|
TRACE("read from %#x\n", address);
|
|
|
|
|
|
|
|
|
|
/* If we can't start burst mode, continue anyway. */
|
|
|
|
|
// If we can't start burst mode, continue anyway.
|
|
|
|
|
acpi_status status = EcCommand(sc, EC_COMMAND_BURST_ENABLE);
|
|
|
|
|
if (status == AE_OK) {
|
|
|
|
|
uint8 data = EC_GET_DATA(sc);
|
|
|
|
@@ -825,10 +810,10 @@ EcRead(struct acpi_ec_cookie* sc, uint8 address, uint8* readData)
|
|
|
|
|
if (status != AE_OK)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
u_int gen_count = sc->ec_gencount;
|
|
|
|
|
u_int generationCount = sc->ec_gencount;
|
|
|
|
|
|
|
|
|
|
EC_SET_DATA(sc, address);
|
|
|
|
|
status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL, gen_count);
|
|
|
|
|
status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL, generationCount);
|
|
|
|
|
if (status != AE_OK) {
|
|
|
|
|
TRACE("EcRead: failed waiting to get data\n");
|
|
|
|
|
return status;
|
|
|
|
@@ -864,17 +849,17 @@ EcWrite(struct acpi_ec_cookie* sc, uint8 address, uint8* writeData)
|
|
|
|
|
if (status != AE_OK)
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
u_int gen_count = sc->ec_gencount;
|
|
|
|
|
u_int generationCount = sc->ec_gencount;
|
|
|
|
|
EC_SET_DATA(sc, address);
|
|
|
|
|
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, gen_count);
|
|
|
|
|
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, generationCount);
|
|
|
|
|
if (status != AE_OK) {
|
|
|
|
|
TRACE("EcRead: failed waiting for sent address\n");
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gen_count = sc->ec_gencount;
|
|
|
|
|
generationCount = sc->ec_gencount;
|
|
|
|
|
EC_SET_DATA(sc, *writeData);
|
|
|
|
|
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, gen_count);
|
|
|
|
|
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, generationCount);
|
|
|
|
|
if (status != AE_OK) {
|
|
|
|
|
TRACE("EcWrite: failed waiting for sent data\n");
|
|
|
|
|
return status;
|
|
|
|
|