/*
- * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $)
+ * ec.c - ACPI Embedded Controller Driver (v2.0)
*
+ * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
+ * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
* Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/interrupt.h>
+#include <linux/list.h>
#include <asm/io.h>
#include <acpi/acpi_bus.h>
#include <acpi/acpi_drivers.h>
#include <acpi/actypes.h>
-#define _COMPONENT ACPI_EC_COMPONENT
-ACPI_MODULE_NAME ("acpi_ec")
-
-#define ACPI_EC_COMPONENT 0x00100000
#define ACPI_EC_CLASS "embedded_controller"
-#define ACPI_EC_HID "PNP0C09"
-#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
#define ACPI_EC_DEVICE_NAME "Embedded Controller"
#define ACPI_EC_FILE_INFO "info"
+#undef PREFIX
+#define PREFIX "ACPI: EC: "
+/* EC status register */
#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
-#define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
-#define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
+/* EC commands */
+enum ec_command {
+ ACPI_EC_COMMAND_READ = 0x80,
+ ACPI_EC_COMMAND_WRITE = 0x81,
+ ACPI_EC_BURST_ENABLE = 0x82,
+ ACPI_EC_BURST_DISABLE = 0x83,
+ ACPI_EC_COMMAND_QUERY = 0x84,
+};
+
+/* EC events */
+enum ec_event {
+ ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
+ ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
+};
-#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
+#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
-#define ACPI_EC_COMMAND_READ 0x80
-#define ACPI_EC_COMMAND_WRITE 0x81
-#define ACPI_EC_BURST_ENABLE 0x82
-#define ACPI_EC_BURST_DISABLE 0x83
-#define ACPI_EC_COMMAND_QUERY 0x84
+static enum ec_mode {
+ EC_INTR = 1, /* Output buffer full */
+ EC_POLL, /* Input buffer empty */
+} acpi_ec_mode = EC_INTR;
-static int acpi_ec_add (struct acpi_device *device);
-static int acpi_ec_remove (struct acpi_device *device, int type);
-static int acpi_ec_start (struct acpi_device *device);
-static int acpi_ec_stop (struct acpi_device *device, int type);
+static int acpi_ec_remove(struct acpi_device *device, int type);
+static int acpi_ec_start(struct acpi_device *device);
+static int acpi_ec_stop(struct acpi_device *device, int type);
+static int acpi_ec_add(struct acpi_device *device);
-static struct acpi_driver acpi_ec_driver = {
- .name = ACPI_EC_DRIVER_NAME,
- .class = ACPI_EC_CLASS,
- .ids = ACPI_EC_HID,
- .ops = {
- .add = acpi_ec_add,
- .remove = acpi_ec_remove,
- .start = acpi_ec_start,
- .stop = acpi_ec_stop,
- },
+static const struct acpi_device_id ec_device_ids[] = {
+ {"PNP0C09", 0},
+ {"", 0},
};
-struct acpi_ec {
- acpi_handle handle;
- unsigned long uid;
- unsigned long gpe_bit;
- struct acpi_generic_address status_addr;
- struct acpi_generic_address command_addr;
- struct acpi_generic_address data_addr;
- unsigned long global_lock;
- unsigned int expect_event;
- atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/
- atomic_t pending_gpe;
- struct semaphore sem;
- wait_queue_head_t wait;
+static struct acpi_driver acpi_ec_driver = {
+ .name = "ec",
+ .class = ACPI_EC_CLASS,
+ .ids = ec_device_ids,
+ .ops = {
+ .add = acpi_ec_add,
+ .remove = acpi_ec_remove,
+ .start = acpi_ec_start,
+ .stop = acpi_ec_stop,
+ },
};
/* If we find an EC via the ECDT, we need to keep a ptr to its context */
-static struct acpi_ec *ec_ecdt;
-
/* External interfaces use first EC only, so remember */
-static struct acpi_device *first_ec;
+typedef int (*acpi_ec_query_func) (void *data);
+
+struct acpi_ec_query_handler {
+ struct list_head node;
+ acpi_ec_query_func func;
+ acpi_handle handle;
+ void *data;
+ u8 query_bit;
+};
+
+static struct acpi_ec {
+ acpi_handle handle;
+ unsigned long gpe;
+ unsigned long command_addr;
+ unsigned long data_addr;
+ unsigned long global_lock;
+ struct mutex lock;
+ atomic_t query_pending;
+ atomic_t event_count;
+ wait_queue_head_t wait;
+ struct list_head list;
+} *boot_ec, *first_ec;
/* --------------------------------------------------------------------------
Transaction Management
-------------------------------------------------------------------------- */
-static inline u32 acpi_ec_read_status(struct acpi_ec *ec)
+static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
{
- u32 status = 0;
-
- acpi_hw_low_level_read(8, &status, &ec->status_addr);
- return status;
+ return inb(ec->command_addr);
}
-static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event)
+static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
{
- int result = 0;
-
- ACPI_FUNCTION_TRACE("acpi_ec_wait");
-
- ec->expect_event = event;
- smp_mb();
-
- result = wait_event_interruptible_timeout(ec->wait,
- !ec->expect_event,
- msecs_to_jiffies(ACPI_EC_DELAY));
-
- ec->expect_event = 0;
- smp_mb();
+ return inb(ec->data_addr);
+}
- if (result < 0){
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR," result = %d ", result));
- return_VALUE(result);
- }
+static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
+{
+ outb(command, ec->command_addr);
+}
- /*
- * Verify that the event in question has actually happened by
- * querying EC status. Do the check even if operation timed-out
- * to make sure that we did not miss interrupt.
- */
- switch (event) {
- case ACPI_EC_EVENT_OBF:
- if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
- return_VALUE(0);
- break;
+static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
+{
+ outb(data, ec->data_addr);
+}
- case ACPI_EC_EVENT_IBE:
- if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
- return_VALUE(0);
- break;
+static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event,
+ unsigned old_count)
+{
+ u8 status = acpi_ec_read_status(ec);
+ if (old_count == atomic_read(&ec->event_count))
+ return 0;
+ if (event == ACPI_EC_EVENT_OBF_1) {
+ if (status & ACPI_EC_FLAG_OBF)
+ return 1;
+ } else if (event == ACPI_EC_EVENT_IBF_0) {
+ if (!(status & ACPI_EC_FLAG_IBF))
+ return 1;
}
- return_VALUE(-ETIME);
+ return 0;
}
-
-
-static int
-acpi_ec_enter_burst_mode (
- struct acpi_ec *ec)
+static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event,
+ unsigned count, int force_poll)
{
- u32 tmp = 0;
- int status = 0;
-
- ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
-
- status = acpi_ec_read_status(ec);
- if (status != -EINVAL &&
- !(status & ACPI_EC_FLAG_BURST)){
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"entering burst mode \n"));
- acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
- if (status){
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR," status = %d\n", status));
- return_VALUE(-EINVAL);
+ if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) {
+ unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
+ while (time_before(jiffies, delay)) {
+ if (acpi_ec_check_status(ec, event, 0))
+ return 0;
}
- acpi_hw_low_level_read(8, &tmp, &ec->data_addr);
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- if(tmp != 0x90 ) {/* Burst ACK byte*/
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"Ack failed \n"));
- return_VALUE(-EINVAL);
+ } else {
+ if (wait_event_timeout(ec->wait,
+ acpi_ec_check_status(ec, event, count),
+ msecs_to_jiffies(ACPI_EC_DELAY)) ||
+ acpi_ec_check_status(ec, event, 0)) {
+ return 0;
+ } else {
+ printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
+ " status = %d, expect_event = %d\n",
+ acpi_ec_read_status(ec), event);
}
- } else
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"already be in burst mode \n"));
- atomic_set(&ec->leaving_burst , 0);
- return_VALUE(0);
+ }
+
+ return -ETIME;
}
-static int
-acpi_ec_leave_burst_mode (
- struct acpi_ec *ec)
+static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
+ const u8 * wdata, unsigned wdata_len,
+ u8 * rdata, unsigned rdata_len,
+ int force_poll)
{
- int status =0;
-
- ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
-
- atomic_set(&ec->leaving_burst , 1);
- status = acpi_ec_read_status(ec);
- if (status != -EINVAL &&
- (status & ACPI_EC_FLAG_BURST)){
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"leaving burst mode\n"));
- acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr);
- status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
- if (status){
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n"));
- return_VALUE(-EINVAL);
+ int result = 0;
+ unsigned count = atomic_read(&ec->event_count);
+ acpi_ec_write_cmd(ec, command);
+
+ for (; wdata_len > 0; --wdata_len) {
+ result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
+ if (result) {
+ printk(KERN_ERR PREFIX
+ "write_cmd timeout, command = %d\n", command);
+ goto end;
}
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- status = acpi_ec_read_status(ec);
- if (status != -EINVAL &&
- (status & ACPI_EC_FLAG_BURST)) {
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->status fail\n"));
- return_VALUE(-EINVAL);
+ count = atomic_read(&ec->event_count);
+ acpi_ec_write_data(ec, *(wdata++));
+ }
+
+ if (!rdata_len) {
+ result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
+ if (result) {
+ printk(KERN_ERR PREFIX
+ "finish-write timeout, command = %d\n", command);
+ goto end;
}
- }else
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"already be in Non-burst mode \n"));
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"leaving burst mode\n"));
+ } else if (command == ACPI_EC_COMMAND_QUERY) {
+ atomic_set(&ec->query_pending, 0);
+ }
- return_VALUE(0);
+ for (; rdata_len > 0; --rdata_len) {
+ result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll);
+ if (result) {
+ printk(KERN_ERR PREFIX "read timeout, command = %d\n",
+ command);
+ goto end;
+ }
+ count = atomic_read(&ec->event_count);
+ *(rdata++) = acpi_ec_read_data(ec);
+ }
+ end:
+ return result;
}
-static int
-acpi_ec_read (
- struct acpi_ec *ec,
- u8 address,
- u32 *data)
+static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
+ const u8 * wdata, unsigned wdata_len,
+ u8 * rdata, unsigned rdata_len,
+ int force_poll)
{
- int status = 0;
- u32 glk;
+ int status;
+ u32 glk;
- ACPI_FUNCTION_TRACE("acpi_ec_read");
-
- if (!ec || !data)
- return_VALUE(-EINVAL);
+ if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
+ return -EINVAL;
-retry:
- *data = 0;
+ if (rdata)
+ memset(rdata, 0, rdata_len);
+ mutex_lock(&ec->lock);
if (ec->global_lock) {
status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
- if (ACPI_FAILURE(status))
- return_VALUE(-ENODEV);
+ if (ACPI_FAILURE(status)) {
+ mutex_unlock(&ec->lock);
+ return -ENODEV;
+ }
}
- WARN_ON(in_interrupt());
- down(&ec->sem);
-
- if(acpi_ec_enter_burst_mode(ec))
- goto end;
+ /* Make sure GPE is enabled before doing transaction */
+ acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
- acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
+ status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0);
if (status) {
+ printk(KERN_ERR PREFIX
+ "input buffer is not empty, aborting transaction\n");
goto end;
}
- acpi_hw_low_level_write(8, address, &ec->data_addr);
- status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
- if (status){
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- goto end;
- }
-
- acpi_hw_low_level_read(8, data, &ec->data_addr);
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
+ status = acpi_ec_transaction_unlocked(ec, command,
+ wdata, wdata_len,
+ rdata, rdata_len,
+ force_poll);
- ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
- *data, address));
-
-end:
- acpi_ec_leave_burst_mode(ec);
- up(&ec->sem);
+ end:
if (ec->global_lock)
acpi_release_global_lock(glk);
+ mutex_unlock(&ec->lock);
- if(atomic_read(&ec->leaving_burst) == 2){
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
- while(!atomic_read(&ec->pending_gpe)){
- msleep(1);
- }
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- goto retry;
- }
-
- return_VALUE(status);
+ return status;
}
-
-static int
-acpi_ec_write (
- struct acpi_ec *ec,
- u8 address,
- u8 data)
+/*
+ * Note: samsung nv5000 doesn't work with ec burst mode.
+ * http://bugzilla.kernel.org/show_bug.cgi?id=4980
+ */
+int acpi_ec_burst_enable(struct acpi_ec *ec)
{
- int status = 0;
- u32 glk;
- u32 tmp;
-
- ACPI_FUNCTION_TRACE("acpi_ec_write");
-
- if (!ec)
- return_VALUE(-EINVAL);
-retry:
- if (ec->global_lock) {
- status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
- if (ACPI_FAILURE(status))
- return_VALUE(-ENODEV);
- }
-
- WARN_ON(in_interrupt());
- down(&ec->sem);
-
- if(acpi_ec_enter_burst_mode(ec))
- goto end;
-
- status = acpi_ec_read_status(ec);
- if (status != -EINVAL &&
- !(status & ACPI_EC_FLAG_BURST)){
- acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
- if (status)
- goto end;
- acpi_hw_low_level_read(8, &tmp, &ec->data_addr);
- if(tmp != 0x90 ) /* Burst ACK byte*/
- goto end;
- }
- /*Now we are in burst mode*/
-
- acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- if (status){
- goto end;
- }
-
- acpi_hw_low_level_write(8, address, &ec->data_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
- if (status){
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- goto end;
- }
-
- acpi_hw_low_level_write(8, data, &ec->data_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- if (status)
- goto end;
-
- ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
- data, address));
+ u8 d;
+ return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
+}
-end:
- acpi_ec_leave_burst_mode(ec);
- up(&ec->sem);
+int acpi_ec_burst_disable(struct acpi_ec *ec)
+{
+ return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
+}
- if (ec->global_lock)
- acpi_release_global_lock(glk);
+static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
+{
+ int result;
+ u8 d;
- if(atomic_read(&ec->leaving_burst) == 2){
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
- while(!atomic_read(&ec->pending_gpe)){
- msleep(1);
- }
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- goto retry;
- }
+ result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
+ &address, 1, &d, 1, 0);
+ *data = d;
+ return result;
+}
- return_VALUE(status);
+static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
+{
+ u8 wdata[2] = { address, data };
+ return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
+ wdata, 2, NULL, 0, 0);
}
/*
* Externally callable EC access functions. For now, assume 1 EC only
*/
-int
-ec_read(u8 addr, u8 *val)
+int ec_burst_enable(void)
{
- struct acpi_ec *ec;
- int err;
- u32 temp_data;
+ if (!first_ec)
+ return -ENODEV;
+ return acpi_ec_burst_enable(first_ec);
+}
+
+EXPORT_SYMBOL(ec_burst_enable);
+int ec_burst_disable(void)
+{
if (!first_ec)
return -ENODEV;
+ return acpi_ec_burst_disable(first_ec);
+}
+
+EXPORT_SYMBOL(ec_burst_disable);
- ec = acpi_driver_data(first_ec);
+int ec_read(u8 addr, u8 * val)
+{
+ int err;
+ u8 temp_data;
+
+ if (!first_ec)
+ return -ENODEV;
- err = acpi_ec_read(ec, addr, &temp_data);
+ err = acpi_ec_read(first_ec, addr, &temp_data);
if (!err) {
*val = temp_data;
return 0;
- }
- else
+ } else
return err;
}
+
EXPORT_SYMBOL(ec_read);
-int
-ec_write(u8 addr, u8 val)
+int ec_write(u8 addr, u8 val)
{
- struct acpi_ec *ec;
int err;
if (!first_ec)
return -ENODEV;
- ec = acpi_driver_data(first_ec);
-
- err = acpi_ec_write(ec, addr, val);
+ err = acpi_ec_write(first_ec, addr, val);
return err;
}
-EXPORT_SYMBOL(ec_write);
+EXPORT_SYMBOL(ec_write);
-static int
-acpi_ec_query (
- struct acpi_ec *ec,
- u32 *data)
+int ec_transaction(u8 command,
+ const u8 * wdata, unsigned wdata_len,
+ u8 * rdata, unsigned rdata_len,
+ int force_poll)
{
- int status = 0;
- u32 glk;
+ if (!first_ec)
+ return -ENODEV;
- ACPI_FUNCTION_TRACE("acpi_ec_query");
+ return acpi_ec_transaction(first_ec, command, wdata,
+ wdata_len, rdata, rdata_len,
+ force_poll);
+}
- if (!ec || !data)
- return_VALUE(-EINVAL);
-retry:
- *data = 0;
+EXPORT_SYMBOL(ec_transaction);
- if (ec->global_lock) {
- status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
- if (ACPI_FAILURE(status))
- return_VALUE(-ENODEV);
- }
+static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
+{
+ int result;
+ u8 d;
+
+ if (!ec || !data)
+ return -EINVAL;
- down(&ec->sem);
- if(acpi_ec_enter_burst_mode(ec))
- goto end;
/*
* Query the EC to find out which _Qxx method we need to evaluate.
* Note that successful completion of the query causes the ACPI_EC_SCI
* bit to be cleared (and thus clearing the interrupt source).
*/
- acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr);
- status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
- if (status){
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- goto end;
- }
-
- acpi_hw_low_level_read(8, data, &ec->data_addr);
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- if (!*data)
- status = -ENODATA;
-end:
- acpi_ec_leave_burst_mode(ec);
- up(&ec->sem);
+ result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
+ if (result)
+ return result;
- if (ec->global_lock)
- acpi_release_global_lock(glk);
+ if (!d)
+ return -ENODATA;
- if(atomic_read(&ec->leaving_burst) == 2){
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
- while(!atomic_read(&ec->pending_gpe)){
- msleep(1);
- }
- acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
- goto retry;
- }
-
- return_VALUE(status);
+ *data = d;
+ return 0;
}
-
/* --------------------------------------------------------------------------
Event Management
-------------------------------------------------------------------------- */
-
-struct acpi_ec_query_data {
- acpi_handle handle;
- u8 data;
-};
-
-static void
-acpi_ec_gpe_query (
- void *ec_cxt)
+int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
+ acpi_handle handle, acpi_ec_query_func func,
+ void *data)
{
- struct acpi_ec *ec = (struct acpi_ec *) ec_cxt;
- u32 value;
- int result = -ENODATA;
- static char object_name[5] = {'_','Q','0','0','\0'};
- const char hex[] = {'0','1','2','3','4','5','6','7',
- '8','9','A','B','C','D','E','F'};
+ struct acpi_ec_query_handler *handler =
+ kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
+ if (!handler)
+ return -ENOMEM;
- ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
+ handler->query_bit = query_bit;
+ handler->handle = handle;
+ handler->func = func;
+ handler->data = data;
+ mutex_lock(&ec->lock);
+ list_add_tail(&handler->node, &ec->list);
+ mutex_unlock(&ec->lock);
+ return 0;
+}
- if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI)
- result = acpi_ec_query(ec, &value);
+EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
- if (result)
- goto end;
-
- object_name[2] = hex[((value >> 4) & 0x0F)];
- object_name[3] = hex[(value & 0x0F)];
+void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
+{
+ struct acpi_ec_query_handler *handler;
+ mutex_lock(&ec->lock);
+ list_for_each_entry(handler, &ec->list, node) {
+ if (query_bit == handler->query_bit) {
+ list_del(&handler->node);
+ kfree(handler);
+ break;
+ }
+ }
+ mutex_unlock(&ec->lock);
+}
- ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
+EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
- acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
- atomic_dec(&ec->pending_gpe);
-end:
- return;
+static void acpi_ec_gpe_query(void *ec_cxt)
+{
+ struct acpi_ec *ec = ec_cxt;
+ u8 value = 0;
+ struct acpi_ec_query_handler *handler, copy;
+
+ if (!ec || acpi_ec_query(ec, &value))
+ return;
+ mutex_lock(&ec->lock);
+ list_for_each_entry(handler, &ec->list, node) {
+ if (value == handler->query_bit) {
+ /* have custom handler for this bit */
+ memcpy(©, handler, sizeof(copy));
+ mutex_unlock(&ec->lock);
+ if (copy.func) {
+ copy.func(copy.data);
+ } else if (copy.handle) {
+ acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
+ }
+ return;
+ }
+ }
+ mutex_unlock(&ec->lock);
}
-static u32
-acpi_ec_gpe_handler (
- void *data)
+static u32 acpi_ec_gpe_handler(void *data)
{
- acpi_status status = AE_OK;
- u32 value;
- struct acpi_ec *ec = (struct acpi_ec *) data;
-
- if (!ec)
- return ACPI_INTERRUPT_NOT_HANDLED;
-
- acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR);
+ acpi_status status = AE_OK;
+ u8 value;
+ struct acpi_ec *ec = data;
- value = acpi_ec_read_status(ec);
+ atomic_inc(&ec->event_count);
- if((value & ACPI_EC_FLAG_IBF) &&
- !(value & ACPI_EC_FLAG_BURST) &&
- (atomic_read(&ec->leaving_burst) == 0)) {
- /*
- * the embedded controller disables
- * burst mode for any reason other
- * than the burst disable command
- * to process critical event.
- */
- atomic_set(&ec->leaving_burst , 2); /* block current pending transaction
- and retry */
+ if (acpi_ec_mode == EC_INTR) {
wake_up(&ec->wait);
- }else {
- if ((ec->expect_event == ACPI_EC_EVENT_OBF &&
- (value & ACPI_EC_FLAG_OBF)) ||
- (ec->expect_event == ACPI_EC_EVENT_IBE &&
- !(value & ACPI_EC_FLAG_IBF))) {
- ec->expect_event = 0;
- wake_up(&ec->wait);
-
- }
}
- if (value & ACPI_EC_FLAG_SCI){
- atomic_add(1, &ec->pending_gpe) ;
- status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
- acpi_ec_gpe_query, ec);
- }
+ value = acpi_ec_read_status(ec);
+ if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
+ atomic_set(&ec->query_pending, 1);
+ status =
+ acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
+ }
return status == AE_OK ?
- ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
+ ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
}
/* --------------------------------------------------------------------------
-------------------------------------------------------------------------- */
static acpi_status
-acpi_ec_space_setup (
- acpi_handle region_handle,
- u32 function,
- void *handler_context,
- void **return_context)
+acpi_ec_space_setup(acpi_handle region_handle,
+ u32 function, void *handler_context, void **return_context)
{
/*
* The EC object is in the handler context and is needed
* when calling the acpi_ec_space_handler.
*/
- *return_context = (function != ACPI_REGION_DEACTIVATE) ?
- handler_context : NULL;
+ *return_context = (function != ACPI_REGION_DEACTIVATE) ?
+ handler_context : NULL;
return AE_OK;
}
-
static acpi_status
-acpi_ec_space_handler (
- u32 function,
- acpi_physical_address address,
- u32 bit_width,
- acpi_integer *value,
- void *handler_context,
- void *region_context)
+acpi_ec_space_handler(u32 function, acpi_physical_address address,
+ u32 bits, acpi_integer *value,
+ void *handler_context, void *region_context)
{
- int result = 0;
- struct acpi_ec *ec = NULL;
- u32 temp = 0;
- acpi_integer f_v = 0;
- int i = 0;
-
- ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
+ struct acpi_ec *ec = handler_context;
+ int result = 0, i = 0;
+ u8 temp = 0;
if ((address > 0xFF) || !value || !handler_context)
- return_VALUE(AE_BAD_PARAMETER);
+ return AE_BAD_PARAMETER;
- if(bit_width != 8) {
- printk(KERN_WARNING PREFIX "acpi_ec_space_handler: bit_width should be 8\n");
- if (acpi_strict)
- return_VALUE(AE_BAD_PARAMETER);
- }
-
- ec = (struct acpi_ec *) handler_context;
-
-next_byte:
- switch (function) {
- case ACPI_READ:
- result = acpi_ec_read(ec, (u8) address, &temp);
- *value = (acpi_integer) temp;
- break;
- case ACPI_WRITE:
- result = acpi_ec_write(ec, (u8) address, (u8) *value);
- break;
- default:
- result = -EINVAL;
- goto out;
- break;
- }
-
- bit_width -= 8;
- if(bit_width){
-
- if(function == ACPI_READ)
- f_v |= (acpi_integer) (*value) << 8*i;
- if(function == ACPI_WRITE)
- (*value) >>=8;
- i++;
- goto next_byte;
- }
+ if (function != ACPI_READ && function != ACPI_WRITE)
+ return AE_BAD_PARAMETER;
+ if (bits != 8 && acpi_strict)
+ return AE_BAD_PARAMETER;
- if(function == ACPI_READ){
- f_v |= (acpi_integer) (*value) << 8*i;
- *value = f_v;
+ while (bits - i > 0) {
+ if (function == ACPI_READ) {
+ result = acpi_ec_read(ec, address, &temp);
+ (*value) |= ((acpi_integer)temp) << i;
+ } else {
+ temp = 0xff & ((*value) >> i);
+ result = acpi_ec_write(ec, address, temp);
+ }
+ i += 8;
+ ++address;
}
-
-out:
switch (result) {
case -EINVAL:
- return_VALUE(AE_BAD_PARAMETER);
+ return AE_BAD_PARAMETER;
break;
case -ENODEV:
- return_VALUE(AE_NOT_FOUND);
+ return AE_NOT_FOUND;
break;
case -ETIME:
- return_VALUE(AE_TIME);
+ return AE_TIME;
break;
default:
- return_VALUE(AE_OK);
+ return AE_OK;
}
-
-
}
-
/* --------------------------------------------------------------------------
FS Interface (/proc)
-------------------------------------------------------------------------- */
-static struct proc_dir_entry *acpi_ec_dir;
-
+static struct proc_dir_entry *acpi_ec_dir;
-static int
-acpi_ec_read_info (struct seq_file *seq, void *offset)
+static int acpi_ec_read_info(struct seq_file *seq, void *offset)
{
- struct acpi_ec *ec = (struct acpi_ec *) seq->private;
-
- ACPI_FUNCTION_TRACE("acpi_ec_read_info");
+ struct acpi_ec *ec = seq->private;
if (!ec)
goto end;
- seq_printf(seq, "gpe bit: 0x%02x\n",
- (u32) ec->gpe_bit);
- seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
- (u32) ec->status_addr.address, (u32) ec->data_addr.address);
- seq_printf(seq, "use global lock: %s\n",
- ec->global_lock?"yes":"no");
-
-end:
- return_VALUE(0);
+ seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
+ seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
+ (unsigned)ec->command_addr, (unsigned)ec->data_addr);
+ seq_printf(seq, "use global lock:\t%s\n",
+ ec->global_lock ? "yes" : "no");
+ end:
+ return 0;
}
static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
}
static struct file_operations acpi_ec_info_ops = {
- .open = acpi_ec_info_open_fs,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
+ .open = acpi_ec_info_open_fs,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
.owner = THIS_MODULE,
};
-static int
-acpi_ec_add_fs (
- struct acpi_device *device)
+static int acpi_ec_add_fs(struct acpi_device *device)
{
- struct proc_dir_entry *entry;
-
- ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
+ struct proc_dir_entry *entry = NULL;
if (!acpi_device_dir(device)) {
acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
- acpi_ec_dir);
+ acpi_ec_dir);
if (!acpi_device_dir(device))
- return_VALUE(-ENODEV);
+ return -ENODEV;
}
entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
- acpi_device_dir(device));
+ acpi_device_dir(device));
if (!entry)
- ACPI_DEBUG_PRINT((ACPI_DB_WARN,
- "Unable to create '%s' fs entry\n",
- ACPI_EC_FILE_INFO));
+ return -ENODEV;
else {
entry->proc_fops = &acpi_ec_info_ops;
entry->data = acpi_driver_data(device);
entry->owner = THIS_MODULE;
}
- return_VALUE(0);
+ return 0;
}
-
-static int
-acpi_ec_remove_fs (
- struct acpi_device *device)
+static int acpi_ec_remove_fs(struct acpi_device *device)
{
- ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
if (acpi_device_dir(device)) {
remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
acpi_device_dir(device) = NULL;
}
- return_VALUE(0);
+ return 0;
}
-
/* --------------------------------------------------------------------------
Driver Interface
-------------------------------------------------------------------------- */
+static acpi_status
+ec_parse_io_ports(struct acpi_resource *resource, void *context);
-static int
-acpi_ec_add (
- struct acpi_device *device)
+static struct acpi_ec *make_acpi_ec(void)
{
- int result;
- acpi_status status;
- struct acpi_ec *ec;
- unsigned long uid;
+ struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
+ if (!ec)
+ return NULL;
- ACPI_FUNCTION_TRACE("acpi_ec_add");
+ atomic_set(&ec->query_pending, 1);
+ atomic_set(&ec->event_count, 1);
+ mutex_init(&ec->lock);
+ init_waitqueue_head(&ec->wait);
+ INIT_LIST_HEAD(&ec->list);
- if (!device)
- return_VALUE(-EINVAL);
+ return ec;
+}
- ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
- if (!ec)
- return_VALUE(-ENOMEM);
- memset(ec, 0, sizeof(struct acpi_ec));
+static acpi_status
+acpi_ec_register_query_methods(acpi_handle handle, u32 level,
+ void *context, void **return_value)
+{
+ struct acpi_namespace_node *node = handle;
+ struct acpi_ec *ec = context;
+ int value = 0;
+ if (sscanf(node->name.ascii, "_Q%x", &value) == 1) {
+ acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
+ }
+ return AE_OK;
+}
- ec->handle = device->handle;
- ec->uid = -1;
- atomic_set(&ec->pending_gpe, 0);
- atomic_set(&ec->leaving_burst , 1);
- init_MUTEX(&ec->sem);
- init_waitqueue_head(&ec->wait);
- strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
- strcpy(acpi_device_class(device), ACPI_EC_CLASS);
- acpi_driver_data(device) = ec;
+static acpi_status
+ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
+{
+ acpi_status status;
+
+ struct acpi_ec *ec = context;
+ status = acpi_walk_resources(handle, METHOD_NAME__CRS,
+ ec_parse_io_ports, ec);
+ if (ACPI_FAILURE(status))
+ return status;
+
+ /* Get GPE bit assignment (EC events). */
+ /* TODO: Add support for _GPE returning a package */
+ status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
+ if (ACPI_FAILURE(status))
+ return status;
+
+ /* Find and register all query methods */
+ acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1,
+ acpi_ec_register_query_methods, ec, NULL);
/* Use the global lock for all EC transactions? */
- acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
+ acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
- /* If our UID matches the UID for the ECDT-enumerated EC,
- we now have the *real* EC info, so kill the makeshift one.*/
- acpi_evaluate_integer(ec->handle, "_UID", NULL, &uid);
- if (ec_ecdt && ec_ecdt->uid == uid) {
- acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
- ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
+ ec->handle = handle;
- acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler);
+ printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
+ ec->gpe, ec->command_addr, ec->data_addr);
- kfree(ec_ecdt);
- }
+ return AE_CTRL_TERMINATE;
+}
- /* Get GPE bit assignment (EC events). */
- /* TODO: Add support for _GPE returning a package */
- status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe_bit);
- if (ACPI_FAILURE(status)) {
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
- "Error obtaining GPE bit assignment\n"));
- result = -ENODEV;
- goto end;
- }
+static int acpi_ec_add(struct acpi_device *device)
+{
+ struct acpi_ec *ec = NULL;
- result = acpi_ec_add_fs(device);
- if (result)
- goto end;
+ if (!device)
+ return -EINVAL;
- printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
- acpi_device_name(device), acpi_device_bid(device),
- (u32) ec->gpe_bit);
+ strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
+ strcpy(acpi_device_class(device), ACPI_EC_CLASS);
- if (!first_ec)
- first_ec = device;
+ ec = make_acpi_ec();
+ if (!ec)
+ return -ENOMEM;
-end:
- if (result)
+ if (ec_parse_device(device->handle, 0, ec, NULL) !=
+ AE_CTRL_TERMINATE) {
kfree(ec);
+ return -EINVAL;
+ }
+
+ /* Check if we found the boot EC */
+ if (boot_ec) {
+ if (boot_ec->gpe == ec->gpe) {
+ /* We might have incorrect info for GL at boot time */
+ mutex_lock(&boot_ec->lock);
+ boot_ec->global_lock = ec->global_lock;
+ /* Copy handlers from new ec into boot ec */
+ list_splice(&ec->list, &boot_ec->list);
+ mutex_unlock(&boot_ec->lock);
+ kfree(ec);
+ ec = boot_ec;
+ }
+ } else
+ first_ec = ec;
+ ec->handle = device->handle;
+ acpi_driver_data(device) = ec;
- return_VALUE(result);
+ acpi_ec_add_fs(device);
+ return 0;
}
-
-static int
-acpi_ec_remove (
- struct acpi_device *device,
- int type)
+static int acpi_ec_remove(struct acpi_device *device, int type)
{
- struct acpi_ec *ec;
-
- ACPI_FUNCTION_TRACE("acpi_ec_remove");
+ struct acpi_ec *ec;
+ struct acpi_ec_query_handler *handler, *tmp;
if (!device)
- return_VALUE(-EINVAL);
+ return -EINVAL;
ec = acpi_driver_data(device);
-
+ mutex_lock(&ec->lock);
+ list_for_each_entry_safe(handler, tmp, &ec->list, node) {
+ list_del(&handler->node);
+ kfree(handler);
+ }
+ mutex_unlock(&ec->lock);
acpi_ec_remove_fs(device);
+ acpi_driver_data(device) = NULL;
+ if (ec == first_ec)
+ first_ec = NULL;
- kfree(ec);
-
- return_VALUE(0);
+ /* Don't touch boot EC */
+ if (boot_ec != ec)
+ kfree(ec);
+ return 0;
}
-
static acpi_status
-acpi_ec_io_ports (
- struct acpi_resource *resource,
- void *context)
+ec_parse_io_ports(struct acpi_resource *resource, void *context)
{
- struct acpi_ec *ec = (struct acpi_ec *) context;
- struct acpi_generic_address *addr;
+ struct acpi_ec *ec = context;
- if (resource->id != ACPI_RSTYPE_IO) {
+ if (resource->type != ACPI_RESOURCE_TYPE_IO)
return AE_OK;
- }
/*
* The first address region returned is the data port, and
* the second address region returned is the status/command
* port.
*/
- if (ec->data_addr.register_bit_width == 0) {
- addr = &ec->data_addr;
- } else if (ec->command_addr.register_bit_width == 0) {
- addr = &ec->command_addr;
- } else {
+ if (ec->data_addr == 0)
+ ec->data_addr = resource->data.io.minimum;
+ else if (ec->command_addr == 0)
+ ec->command_addr = resource->data.io.minimum;
+ else
return AE_CTRL_TERMINATE;
- }
-
- addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
- addr->register_bit_width = 8;
- addr->register_bit_offset = 0;
- addr->address = resource->data.io.min_base_address;
return AE_OK;
}
-
-static int
-acpi_ec_start (
- struct acpi_device *device)
+static int ec_install_handlers(struct acpi_ec *ec)
{
- acpi_status status;
- struct acpi_ec *ec;
-
- ACPI_FUNCTION_TRACE("acpi_ec_start");
-
- if (!device)
- return_VALUE(-EINVAL);
-
- ec = acpi_driver_data(device);
-
- if (!ec)
- return_VALUE(-EINVAL);
-
- /*
- * Get I/O port addresses. Convert to GAS format.
- */
- status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
- acpi_ec_io_ports, ec);
- if (ACPI_FAILURE(status) || ec->command_addr.register_bit_width == 0) {
- ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses"));
- return_VALUE(-ENODEV);
- }
-
- ec->status_addr = ec->command_addr;
-
- ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
- (u32) ec->gpe_bit, (u32) ec->command_addr.address,
- (u32) ec->data_addr.address));
+ acpi_status status;
+ status = acpi_install_gpe_handler(NULL, ec->gpe,
+ ACPI_GPE_EDGE_TRIGGERED,
+ &acpi_ec_gpe_handler, ec);
+ if (ACPI_FAILURE(status))
+ return -ENODEV;
- /*
- * Install GPE handler
- */
- status = acpi_install_gpe_handler(NULL, ec->gpe_bit,
- ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec);
- if (ACPI_FAILURE(status)) {
- return_VALUE(-ENODEV);
- }
- acpi_set_gpe_type (NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
- acpi_enable_gpe (NULL, ec->gpe_bit, ACPI_NOT_ISR);
+ acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
+ acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
- status = acpi_install_address_space_handler (ec->handle,
- ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
- &acpi_ec_space_setup, ec);
+ status = acpi_install_address_space_handler(ec->handle,
+ ACPI_ADR_SPACE_EC,
+ &acpi_ec_space_handler,
+ &acpi_ec_space_setup, ec);
if (ACPI_FAILURE(status)) {
- acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler);
- return_VALUE(-ENODEV);
+ acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
+ return -ENODEV;
}
- return_VALUE(AE_OK);
+ return 0;
}
-
-static int
-acpi_ec_stop (
- struct acpi_device *device,
- int type)
+static int acpi_ec_start(struct acpi_device *device)
{
- acpi_status status;
- struct acpi_ec *ec;
-
- ACPI_FUNCTION_TRACE("acpi_ec_stop");
+ struct acpi_ec *ec;
+ int ret = 0;
if (!device)
- return_VALUE(-EINVAL);
+ return -EINVAL;
ec = acpi_driver_data(device);
- status = acpi_remove_address_space_handler(ec->handle,
- ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
- if (ACPI_FAILURE(status))
- return_VALUE(-ENODEV);
-
- status = acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler);
- if (ACPI_FAILURE(status))
- return_VALUE(-ENODEV);
-
- return_VALUE(0);
-}
-
-static acpi_status __init
-acpi_fake_ecdt_callback (
- acpi_handle handle,
- u32 Level,
- void *context,
- void **retval)
-{
- acpi_status status;
-
- status = acpi_walk_resources(handle, METHOD_NAME__CRS,
- acpi_ec_io_ports, ec_ecdt);
- if (ACPI_FAILURE(status))
- return status;
- ec_ecdt->status_addr = ec_ecdt->command_addr;
+ if (!ec)
+ return -EINVAL;
- ec_ecdt->uid = -1;
- acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
+ /* Boot EC is already working */
+ if (ec != boot_ec)
+ ret = ec_install_handlers(ec);
- status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit);
- if (ACPI_FAILURE(status))
- return status;
- ec_ecdt->global_lock = TRUE;
- ec_ecdt->handle = handle;
+ /* EC is fully operational, allow queries */
+ atomic_set(&ec->query_pending, 0);
- printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
- (u32) ec_ecdt->gpe_bit, (u32) ec_ecdt->command_addr.address,
- (u32) ec_ecdt->data_addr.address);
-
- return AE_CTRL_TERMINATE;
+ return ret;
}
-/*
- * Some BIOS (such as some from Gateway laptops) access EC region very early
- * such as in BAT0._INI or EC._INI before an EC device is found and
- * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
- * required, but if EC regison is accessed early, it is required.
- * The routine tries to workaround the BIOS bug by pre-scan EC device
- * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
- * op region (since _REG isn't invoked yet). The assumption is true for
- * all systems found.
- */
-static int __init
-acpi_ec_fake_ecdt(void)
+static int acpi_ec_stop(struct acpi_device *device, int type)
{
- acpi_status status;
- int ret = 0;
-
- printk(KERN_INFO PREFIX "Try to make an fake ECDT\n");
+ acpi_status status;
+ struct acpi_ec *ec;
- ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
- if (!ec_ecdt) {
- ret = -ENOMEM;
- goto error;
- }
- memset(ec_ecdt, 0, sizeof(struct acpi_ec));
+ if (!device)
+ return -EINVAL;
- status = acpi_get_devices (ACPI_EC_HID,
- acpi_fake_ecdt_callback,
- NULL,
- NULL);
- if (ACPI_FAILURE(status)) {
- kfree(ec_ecdt);
- ec_ecdt = NULL;
- ret = -ENODEV;
- goto error;
- }
- return 0;
-error:
- printk(KERN_ERR PREFIX "Can't make an fake ECDT\n");
- return ret;
-}
+ ec = acpi_driver_data(device);
+ if (!ec)
+ return -EINVAL;
-static int __init
-acpi_ec_get_real_ecdt(void)
-{
- acpi_status status;
- struct acpi_table_ecdt *ecdt_ptr;
+ /* Don't touch boot EC */
+ if (ec == boot_ec)
+ return 0;
- status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
- (struct acpi_table_header **) &ecdt_ptr);
+ status = acpi_remove_address_space_handler(ec->handle,
+ ACPI_ADR_SPACE_EC,
+ &acpi_ec_space_handler);
if (ACPI_FAILURE(status))
return -ENODEV;
- printk(KERN_INFO PREFIX "Found ECDT\n");
-
- /*
- * Generate a temporary ec context to use until the namespace is scanned
- */
- ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
- if (!ec_ecdt)
- return -ENOMEM;
- memset(ec_ecdt, 0, sizeof(struct acpi_ec));
-
- init_MUTEX(&ec_ecdt->sem);
- init_waitqueue_head(&ec_ecdt->wait);
- ec_ecdt->command_addr = ecdt_ptr->ec_control;
- ec_ecdt->status_addr = ecdt_ptr->ec_control;
- ec_ecdt->data_addr = ecdt_ptr->ec_data;
- ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit;
- /* use the GL just to be safe */
- ec_ecdt->global_lock = TRUE;
- ec_ecdt->uid = ecdt_ptr->uid;
-
- status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
- if (ACPI_FAILURE(status)) {
- goto error;
- }
+ status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
+ if (ACPI_FAILURE(status))
+ return -ENODEV;
return 0;
-error:
- printk(KERN_ERR PREFIX "Could not use ECDT\n");
- kfree(ec_ecdt);
- ec_ecdt = NULL;
-
- return -ENODEV;
}
-static int __initdata acpi_fake_ecdt_enabled;
-int __init
-acpi_ec_ecdt_probe (void)
+int __init acpi_ec_ecdt_probe(void)
{
- acpi_status status;
- int ret;
-
- ret = acpi_ec_get_real_ecdt();
- /* Try to make a fake ECDT */
- if (ret && acpi_fake_ecdt_enabled) {
- ret = acpi_ec_fake_ecdt();
- }
-
- if (ret)
- return 0;
+ int ret;
+ acpi_status status;
+ struct acpi_table_ecdt *ecdt_ptr;
+ boot_ec = make_acpi_ec();
+ if (!boot_ec)
+ return -ENOMEM;
/*
- * Install GPE handler
+ * Generate a boot ec context
*/
- status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit,
- ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler,
- ec_ecdt);
- if (ACPI_FAILURE(status)) {
- goto error;
+ status = acpi_get_table(ACPI_SIG_ECDT, 1,
+ (struct acpi_table_header **)&ecdt_ptr);
+ if (ACPI_SUCCESS(status)) {
+ printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n\n");
+ boot_ec->command_addr = ecdt_ptr->control.address;
+ boot_ec->data_addr = ecdt_ptr->data.address;
+ boot_ec->gpe = ecdt_ptr->gpe;
+ boot_ec->handle = ACPI_ROOT_OBJECT;
+ } else {
+ printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
+ status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
+ boot_ec, NULL);
+ /* Check that acpi_get_devices actually find something */
+ if (ACPI_FAILURE(status) || !boot_ec->handle)
+ goto error;
}
- acpi_set_gpe_type (NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME);
- acpi_enable_gpe (NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR);
- status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT,
- ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
- &acpi_ec_space_setup, ec_ecdt);
- if (ACPI_FAILURE(status)) {
- acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit,
- &acpi_ec_gpe_handler);
- goto error;
+ ret = ec_install_handlers(boot_ec);
+ if (!ret) {
+ first_ec = boot_ec;
+ return 0;
}
-
- return 0;
-
-error:
- printk(KERN_ERR PREFIX "Could not use ECDT\n");
- kfree(ec_ecdt);
- ec_ecdt = NULL;
+ error:
+ kfree(boot_ec);
+ boot_ec = NULL;
return -ENODEV;
}
-
-static int __init acpi_ec_init (void)
+static int __init acpi_ec_init(void)
{
- int result;
-
- ACPI_FUNCTION_TRACE("acpi_ec_init");
+ int result = 0;
if (acpi_disabled)
- return_VALUE(0);
+ return 0;
acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
if (!acpi_ec_dir)
- return_VALUE(-ENODEV);
+ return -ENODEV;
/* Now register the driver for the EC */
result = acpi_bus_register_driver(&acpi_ec_driver);
if (result < 0) {
remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
- return_VALUE(-ENODEV);
+ return -ENODEV;
}
- return_VALUE(result);
+ return result;
}
subsys_initcall(acpi_ec_init);
/* EC driver currently not unloadable */
#if 0
-static void __exit
-acpi_ec_exit (void)
+static void __exit acpi_ec_exit(void)
{
- ACPI_FUNCTION_TRACE("acpi_ec_exit");
acpi_bus_unregister_driver(&acpi_ec_driver);
remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
- return_VOID;
+ return;
}
-#endif /* 0 */
+#endif /* 0 */
-static int __init acpi_fake_ecdt_setup(char *str)
+static int __init acpi_ec_set_intr_mode(char *str)
{
- acpi_fake_ecdt_enabled = 1;
- return 0;
+ int intr;
+
+ if (!get_option(&str, &intr))
+ return 0;
+
+ acpi_ec_mode = (intr) ? EC_INTR : EC_POLL;
+
+ printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling");
+
+ return 1;
}
-__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
+
+__setup("ec_intr=", acpi_ec_set_intr_mode);