]> err.no Git - linux-2.6/blobdiff - drivers/acpi/ec.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/avi/kvm
[linux-2.6] / drivers / acpi / ec.c
index 125046884b8bd886aa335c60365c225cbcbb1f83..e08cf98f504f12583174d23468a60bf4f9a28c14 100644 (file)
@@ -1,6 +1,8 @@
 /*
- *  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>
@@ -91,9 +93,9 @@ static struct acpi_driver acpi_ec_driver = {
 };
 
 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
+/* External interfaces use first EC only, so remember */
 static struct acpi_ec {
        acpi_handle handle;
-       unsigned long uid;
        unsigned long gpe;
        unsigned long command_addr;
        unsigned long data_addr;
@@ -102,10 +104,7 @@ static struct acpi_ec {
        atomic_t query_pending;
        atomic_t event_count;
        wait_queue_head_t wait;
-} *boot_ec;
-
-/* External interfaces use first EC only, so remember */
-static struct acpi_device *first_ec;
+} *boot_ec, *first_ec;
 
 /* --------------------------------------------------------------------------
                              Transaction Management
@@ -299,38 +298,31 @@ static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
  */
 int ec_burst_enable(void)
 {
-       struct acpi_ec *ec;
        if (!first_ec)
                return -ENODEV;
-       ec = acpi_driver_data(first_ec);
-       return acpi_ec_burst_enable(ec);
+       return acpi_ec_burst_enable(first_ec);
 }
 
 EXPORT_SYMBOL(ec_burst_enable);
 
 int ec_burst_disable(void)
 {
-       struct acpi_ec *ec;
        if (!first_ec)
                return -ENODEV;
-       ec = acpi_driver_data(first_ec);
-       return acpi_ec_burst_disable(ec);
+       return acpi_ec_burst_disable(first_ec);
 }
 
 EXPORT_SYMBOL(ec_burst_disable);
 
 int ec_read(u8 addr, u8 * val)
 {
-       struct acpi_ec *ec;
        int err;
        u8 temp_data;
 
        if (!first_ec)
                return -ENODEV;
 
-       ec = acpi_driver_data(first_ec);
-
-       err = acpi_ec_read(ec, addr, &temp_data);
+       err = acpi_ec_read(first_ec, addr, &temp_data);
 
        if (!err) {
                *val = temp_data;
@@ -343,15 +335,12 @@ EXPORT_SYMBOL(ec_read);
 
 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;
 }
@@ -362,14 +351,10 @@ int ec_transaction(u8 command,
                   const u8 * wdata, unsigned wdata_len,
                   u8 * rdata, unsigned rdata_len)
 {
-       struct acpi_ec *ec;
-
        if (!first_ec)
                return -ENODEV;
 
-       ec = acpi_driver_data(first_ec);
-
-       return acpi_ec_transaction(ec, command, wdata,
+       return acpi_ec_transaction(first_ec, command, wdata,
                                   wdata_len, rdata, rdata_len);
 }
 
@@ -541,13 +526,11 @@ static int acpi_ec_read_info(struct seq_file *seq, void *offset)
        if (!ec)
                goto end;
 
-       seq_printf(seq, "gpe:                 0x%02x\n", (u32) ec->gpe);
-       seq_printf(seq, "ports:                   0x%02x, 0x%02x\n",
-                  (u32) ec->command_addr, (u32) ec->data_addr);
-       seq_printf(seq, "use global lock:         %s\n",
+       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");
-       acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
-
       end:
        return 0;
 }
@@ -616,7 +599,7 @@ static struct acpi_ec *make_acpi_ec(void)
        if (!ec)
                return NULL;
 
-       atomic_set(&ec->query_pending, 0);
+       atomic_set(&ec->query_pending, 1);
        atomic_set(&ec->event_count, 1);
        mutex_init(&ec->lock);
        init_waitqueue_head(&ec->wait);
@@ -655,11 +638,10 @@ static int acpi_ec_add(struct acpi_device *device)
                        kfree(ec);
                        ec = boot_ec;
                }
-       }
+       } else
+               first_ec = ec;
        ec->handle = device->handle;
        acpi_driver_data(device) = ec;
-       if (!first_ec)
-               first_ec = device;
 
        acpi_ec_add_fs(device);
 
@@ -672,23 +654,20 @@ static int acpi_ec_add(struct acpi_device *device)
 
 static int acpi_ec_remove(struct acpi_device *device, int type)
 {
-       struct acpi_ec *ec = NULL;
+       struct acpi_ec *ec;
 
        if (!device)
                return -EINVAL;
 
        ec = acpi_driver_data(device);
-
        acpi_ec_remove_fs(device);
-
        acpi_driver_data(device) = NULL;
-       if (device == first_ec)
+       if (ec == first_ec)
                first_ec = NULL;
 
        /* Don't touch boot EC */
        if (boot_ec != ec)
                kfree(ec);
-
        return 0;
 }
 
@@ -697,22 +676,20 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context)
 {
        struct acpi_ec *ec = context;
 
-       if (resource->type != ACPI_RESOURCE_TYPE_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 == 0) {
+       if (ec->data_addr == 0)
                ec->data_addr = resource->data.io.minimum;
-       } else if (ec->command_addr == 0) {
+       else if (ec->command_addr == 0)
                ec->command_addr = resource->data.io.minimum;
-       } else {
+       else
                return AE_CTRL_TERMINATE;
-       }
 
        return AE_OK;
 }
@@ -725,6 +702,7 @@ static int ec_install_handlers(struct acpi_ec *ec)
                                          &acpi_ec_gpe_handler, ec);
        if (ACPI_FAILURE(status))
                return -ENODEV;
+
        acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
        acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
 
@@ -737,6 +715,9 @@ static int ec_install_handlers(struct acpi_ec *ec)
                return -ENODEV;
        }
 
+       /* EC is fully operational, allow queries */
+       atomic_set(&ec->query_pending, 0);
+
        return 0;
 }
 
@@ -842,12 +823,13 @@ int __init acpi_ec_ecdt_probe(void)
        boot_ec->command_addr = ecdt_ptr->control.address;
        boot_ec->data_addr = ecdt_ptr->data.address;
        boot_ec->gpe = ecdt_ptr->gpe;
-       boot_ec->uid = ecdt_ptr->uid;
        boot_ec->handle = ACPI_ROOT_OBJECT;
 
        ret = ec_install_handlers(boot_ec);
-       if (!ret)
+       if (!ret) {
+               first_ec = boot_ec;
                return 0;
+       }
       error:
        kfree(boot_ec);
        boot_ec = NULL;