]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'ec' into test
authorLen Brown <len.brown@intel.com>
Thu, 23 Oct 2008 03:27:59 +0000 (23:27 -0400)
committerLen Brown <len.brown@intel.com>
Thu, 23 Oct 2008 03:27:59 +0000 (23:27 -0400)
1  2 
drivers/acpi/bus.c
drivers/acpi/ec.c
drivers/acpi/scan.c
include/acpi/acpi_drivers.h

diff --combined drivers/acpi/bus.c
index e6311f432edf7f24d2c42fbaf73a23e65a035369,0e0bbc6209e5a3e08c2b133fafe33c91cd5a1fb0..b11400e2f856e28f787ba23160b18a894a93c285
@@@ -48,23 -48,6 +48,23 @@@ EXPORT_SYMBOL(acpi_root_dir)
  
  #define STRUCT_TO_INT(s)      (*((int*)&s))
  
 +static int set_power_nocheck(const struct dmi_system_id *id)
 +{
 +      printk(KERN_NOTICE PREFIX "%s detected - "
 +              "disable power check in power transistion\n", id->ident);
 +      acpi_power_nocheck = 1;
 +      return 0;
 +}
 +static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
 +      {
 +      set_power_nocheck, "HP Pavilion 05", {
 +      DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
 +      DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
 +      DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
 +      {},
 +};
 +
 +
  /* --------------------------------------------------------------------------
                                  Device Management
     -------------------------------------------------------------------------- */
@@@ -112,21 -95,21 +112,21 @@@ int acpi_bus_get_status(struct acpi_dev
        }
  
        /*
 -       * Otherwise we assume the status of our parent (unless we don't
 -       * have one, in which case status is implied).
 +       * According to ACPI spec some device can be present and functional
 +       * even if the parent is not present but functional.
 +       * In such conditions the child device should not inherit the status
 +       * from the parent.
         */
 -      else if (device->parent)
 -              device->status = device->parent->status;
        else
                STRUCT_TO_INT(device->status) =
                    ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
                    ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
  
        if (device->status.functional && !device->status.present) {
 -              printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
 -                     "functional but not present; setting present\n",
 -                     device->pnp.bus_id, (u32) STRUCT_TO_INT(device->status));
 -              device->status.present = 1;
 +              ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
 +                     "functional but not present;\n",
 +                      device->pnp.bus_id,
 +                      (u32) STRUCT_TO_INT(device->status)));
        }
  
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
@@@ -240,19 -223,7 +240,19 @@@ int acpi_bus_set_power(acpi_handle hand
        /*
         * Get device's current power state
         */
 -      acpi_bus_get_power(device->handle, &device->power.state);
 +      if (!acpi_power_nocheck) {
 +              /*
 +               * Maybe the incorrect power state is returned on the bogus
 +               * bios, which is different with the real power state.
 +               * For example: the bios returns D0 state and the real power
 +               * state is D3. OS expects to set the device to D0 state. In
 +               * such case if OS uses the power state returned by the BIOS,
 +               * the device can't be transisted to the correct power state.
 +               * So if the acpi_power_nocheck is set, it is unnecessary to
 +               * get the power state by calling acpi_bus_get_power.
 +               */
 +              acpi_bus_get_power(device->handle, &device->power.state);
 +      }
        if ((state == device->power.state) && !device->flags.force_power_state) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
                                  state));
@@@ -525,19 -496,6 +525,19 @@@ static int acpi_bus_check_scope(struct 
        return 0;
  }
  
 +static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
 +int register_acpi_bus_notifier(struct notifier_block *nb)
 +{
 +      return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
 +}
 +EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
 +
 +void unregister_acpi_bus_notifier(struct notifier_block *nb)
 +{
 +      blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
 +}
 +EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
 +
  /**
   * acpi_bus_notify
   * ---------------
@@@ -548,8 -506,6 +548,8 @@@ static void acpi_bus_notify(acpi_handl
        int result = 0;
        struct acpi_device *device = NULL;
  
 +      blocking_notifier_call_chain(&acpi_bus_notify_list,
 +              type, (void *)handle);
  
        if (acpi_bus_get_device(handle, &device))
                return;
@@@ -793,6 -749,12 +793,12 @@@ static int __init acpi_bus_init(void
                goto error1;
        }
  
+       /*
+        * Maybe EC region is required at bus_scan/acpi_get_devices. So it
+        * is necessary to enable it as early as possible.
+        */
+       acpi_boot_ec_enable();
        printk(KERN_INFO PREFIX "Interpreter enabled\n");
  
        /* Initialize sleep structures */
@@@ -862,11 -824,7 +868,11 @@@ static int __init acpi_init(void
                }
        } else
                disable_acpi();
 -
 +      /*
 +       * If the laptop falls into the DMI check table, the power state check
 +       * will be disabled in the course of device power transistion.
 +       */
 +      dmi_check_system(power_nocheck_dmi_table);
        return result;
  }
  
diff --combined drivers/acpi/ec.c
index 4c004286b3d9f230f23a0a52ec49105ed0ef0a1b,444cd9ed12c79a772a9012b178d6f7545cffb24a..4178d17aa0edc2bc8576d44ee6d4bae184c6dcfb
@@@ -1,7 -1,7 +1,7 @@@
  /*
-  *  ec.c - ACPI Embedded Controller Driver (v2.0)
+  *  ec.c - ACPI Embedded Controller Driver (v2.1)
   *
-  *  Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
+  *  Copyright (C) 2006-2008 Alexey Starikovskiy <astarikovskiy@suse.de>
   *  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>
@@@ -26,7 -26,7 +26,7 @@@
   * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   */
  
- /* Uncomment next line to get verbose print outs*/
+ /* Uncomment next line to get verbose printout */
  /* #define DEBUG */
  
  #include <linux/kernel.h>
@@@ -38,6 -38,7 +38,7 @@@
  #include <linux/seq_file.h>
  #include <linux/interrupt.h>
  #include <linux/list.h>
+ #include <linux/spinlock.h>
  #include <asm/io.h>
  #include <acpi/acpi_bus.h>
  #include <acpi/acpi_drivers.h>
@@@ -65,22 -66,21 +66,21 @@@ enum ec_command 
        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         500     /* Wait 500ms max. during EC ops */
  #define ACPI_EC_UDELAY_GLK    1000    /* Wait 1ms max. to get global lock */
  #define ACPI_EC_UDELAY                100     /* Wait 100us before polling EC again */
  
+ #define ACPI_EC_STORM_THRESHOLD 20    /* number of false interrupts
+                                          per one transaction */
  enum {
-       EC_FLAGS_WAIT_GPE = 0,          /* Don't check status until GPE arrives */
        EC_FLAGS_QUERY_PENDING,         /* Query is pending */
-       EC_FLAGS_GPE_MODE,              /* Expect GPE to be sent for status change */
+       EC_FLAGS_GPE_MODE,              /* Expect GPE to be sent
+                                        * for status change */
        EC_FLAGS_NO_GPE,                /* Don't use GPE mode */
-       EC_FLAGS_RESCHEDULE_POLL        /* Re-schedule poll */
+       EC_FLAGS_GPE_STORM,             /* GPE storm detected */
+       EC_FLAGS_HANDLERS_INSTALLED     /* Handlers for GPE and
+                                        * OpReg are installed */
  };
  
  /* If we find an EC via the ECDT, we need to keep a ptr to its context */
@@@ -95,6 -95,15 +95,15 @@@ struct acpi_ec_query_handler 
        u8 query_bit;
  };
  
+ struct transaction {
+       const u8 *wdata;
+       u8 *rdata;
+       unsigned short irq_count;
+       u8 command;
+       u8 wlen;
+       u8 rlen;
+ };
  static struct acpi_ec {
        acpi_handle handle;
        unsigned long gpe;
        struct mutex lock;
        wait_queue_head_t wait;
        struct list_head list;
-       struct delayed_work work;
-       atomic_t irq_count;
-       u8 handlers_installed;
+       struct transaction *curr;
+       spinlock_t curr_lock;
  } *boot_ec, *first_ec;
  
  /* 
@@@ -150,7 -158,7 +158,7 @@@ static inline u8 acpi_ec_read_data(stru
  {
        u8 x = inb(ec->data_addr);
        pr_debug(PREFIX "---> data = 0x%2.2x\n", x);
-       return inb(ec->data_addr);
+       return x;
  }
  
  static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
@@@ -165,158 -173,172 +173,172 @@@ static inline void acpi_ec_write_data(s
        outb(data, ec->data_addr);
  }
  
- static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
+ static int ec_transaction_done(struct acpi_ec *ec)
  {
-       if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags))
-               return 0;
-       if (event == ACPI_EC_EVENT_OBF_1) {
-               if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
-                       return 1;
-       } else if (event == ACPI_EC_EVENT_IBF_0) {
-               if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
-                       return 1;
-       }
-       return 0;
+       unsigned long flags;
+       int ret = 0;
+       spin_lock_irqsave(&ec->curr_lock, flags);
+       if (!ec->curr || (!ec->curr->wlen && !ec->curr->rlen))
+               ret = 1;
+       spin_unlock_irqrestore(&ec->curr_lock, flags);
+       return ret;
  }
  
- static void ec_schedule_ec_poll(struct acpi_ec *ec)
+ static void gpe_transaction(struct acpi_ec *ec, u8 status)
  {
-       if (test_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags))
-               schedule_delayed_work(&ec->work,
-                                     msecs_to_jiffies(ACPI_EC_DELAY));
+       unsigned long flags;
+       spin_lock_irqsave(&ec->curr_lock, flags);
+       if (!ec->curr)
+               goto unlock;
+       if (ec->curr->wlen > 0) {
+               if ((status & ACPI_EC_FLAG_IBF) == 0) {
+                       acpi_ec_write_data(ec, *(ec->curr->wdata++));
+                       --ec->curr->wlen;
+               } else
+                       /* false interrupt, state didn't change */
+                       ++ec->curr->irq_count;
+       } else if (ec->curr->rlen > 0) {
+               if ((status & ACPI_EC_FLAG_OBF) == 1) {
+                       *(ec->curr->rdata++) = acpi_ec_read_data(ec);
+                       --ec->curr->rlen;
+               } else
+                       /* false interrupt, state didn't change */
+                       ++ec->curr->irq_count;
+       }
+ unlock:
+       spin_unlock_irqrestore(&ec->curr_lock, flags);
  }
  
- static void ec_switch_to_poll_mode(struct acpi_ec *ec)
+ static int acpi_ec_wait(struct acpi_ec *ec)
  {
+       if (wait_event_timeout(ec->wait, ec_transaction_done(ec),
+                              msecs_to_jiffies(ACPI_EC_DELAY)))
+               return 0;
+       /* missing GPEs, switch back to poll mode */
+       if (printk_ratelimit())
+               pr_info(PREFIX "missing confirmations, "
+                               "switch off interrupt mode.\n");
        set_bit(EC_FLAGS_NO_GPE, &ec->flags);
        clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
-       acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
-       set_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
+       return 1;
  }
  
- static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
+ static void acpi_ec_gpe_query(void *ec_cxt);
+ static int ec_check_sci(struct acpi_ec *ec, u8 state)
  {
-       atomic_set(&ec->irq_count, 0);
-       if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
-           likely(!force_poll)) {
-               if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
-                                      msecs_to_jiffies(ACPI_EC_DELAY)))
-                       return 0;
-               clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
-               if (acpi_ec_check_status(ec, event)) {
-                       /* missing GPEs, switch back to poll mode */
-                       if (printk_ratelimit())
-                               pr_info(PREFIX "missing confirmations, "
-                                               "switch off interrupt mode.\n");
-                       ec_switch_to_poll_mode(ec);
-                       ec_schedule_ec_poll(ec);
-                       return 0;
-               }
-       } else {
-               unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
-               clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
-               while (time_before(jiffies, delay)) {
-                       if (acpi_ec_check_status(ec, event))
-                               return 0;
-                       msleep(1);
-               }
-               if (acpi_ec_check_status(ec,event))
+       if (state & ACPI_EC_FLAG_SCI) {
+               if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
+                       return acpi_os_execute(OSL_EC_BURST_HANDLER,
+                               acpi_ec_gpe_query, ec);
+       }
+       return 0;
+ }
+ static int ec_poll(struct acpi_ec *ec)
+ {
+       unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
+       msleep(1);
+       while (time_before(jiffies, delay)) {
+               gpe_transaction(ec, acpi_ec_read_status(ec));
+               msleep(1);
+               if (ec_transaction_done(ec))
                        return 0;
        }
-       pr_err(PREFIX "acpi_ec_wait timeout, status = 0x%2.2x, event = %s\n",
-               acpi_ec_read_status(ec),
-               (event == ACPI_EC_EVENT_OBF_1) ? "\"b0=1\"" : "\"b1=0\"");
        return -ETIME;
  }
  
- static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
-                                       const u8 * wdata, unsigned wdata_len,
-                                       u8 * rdata, unsigned rdata_len,
+ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
+                                       struct transaction *t,
                                        int force_poll)
  {
-       int result = 0;
-       set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
+       unsigned long tmp;
+       int ret = 0;
        pr_debug(PREFIX "transaction start\n");
-       acpi_ec_write_cmd(ec, command);
-       for (; wdata_len > 0; --wdata_len) {
-               result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
-               if (result) {
-                       pr_err(PREFIX
-                              "write_cmd timeout, command = %d\n", command);
-                       goto end;
-               }
-               set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
-               acpi_ec_write_data(ec, *(wdata++));
+       /* disable GPE during transaction if storm is detected */
+       if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
+               clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
+               acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
        }
-       if (!rdata_len) {
-               result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
-               if (result) {
-                       pr_err(PREFIX
-                              "finish-write timeout, command = %d\n", command);
-                       goto end;
-               }
-       } else if (command == ACPI_EC_COMMAND_QUERY)
+       /* start transaction */
+       spin_lock_irqsave(&ec->curr_lock, tmp);
+       /* following two actions should be kept atomic */
+       t->irq_count = 0;
+       ec->curr = t;
+       acpi_ec_write_cmd(ec, ec->curr->command);
+       if (ec->curr->command == ACPI_EC_COMMAND_QUERY)
                clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
-       for (; rdata_len > 0; --rdata_len) {
-               result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
-               if (result) {
-                       pr_err(PREFIX "read timeout, command = %d\n", command);
-                       goto end;
-               }
-               /* Don't expect GPE after last read */
-               if (rdata_len > 1)
-                       set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
-               *(rdata++) = acpi_ec_read_data(ec);
-       }
-       end:
+       spin_unlock_irqrestore(&ec->curr_lock, tmp);
+       /* if we selected poll mode or failed in GPE-mode do a poll loop */
+       if (force_poll ||
+           !test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ||
+           acpi_ec_wait(ec))
+               ret = ec_poll(ec);
        pr_debug(PREFIX "transaction end\n");
-       return result;
+       spin_lock_irqsave(&ec->curr_lock, tmp);
+       ec->curr = NULL;
+       spin_unlock_irqrestore(&ec->curr_lock, tmp);
+       if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
+               /* check if we received SCI during transaction */
+               ec_check_sci(ec, acpi_ec_read_status(ec));
+               /* it is safe to enable GPE outside of transaction */
+               acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
+       } else if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
+                  t->irq_count > ACPI_EC_STORM_THRESHOLD) {
+               pr_debug(PREFIX "GPE storm detected\n");
+               set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
+       }
+       return ret;
+ }
+ static int ec_check_ibf0(struct acpi_ec *ec)
+ {
+       u8 status = acpi_ec_read_status(ec);
+       return (status & ACPI_EC_FLAG_IBF) == 0;
+ }
+ static int ec_wait_ibf0(struct acpi_ec *ec)
+ {
+       unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
+       /* interrupt wait manually if GPE mode is not active */
+       unsigned long timeout = test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ?
+               msecs_to_jiffies(ACPI_EC_DELAY) : msecs_to_jiffies(1);
+       while (time_before(jiffies, delay))
+               if (wait_event_timeout(ec->wait, ec_check_ibf0(ec), timeout))
+                       return 0;
+       return -ETIME;
  }
  
- static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
-                              const u8 * wdata, unsigned wdata_len,
-                              u8 * rdata, unsigned rdata_len,
+ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t,
                               int force_poll)
  {
        int status;
        u32 glk;
-       if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
+       if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
                return -EINVAL;
-       if (rdata)
-               memset(rdata, 0, rdata_len);
+       if (t->rdata)
+               memset(t->rdata, 0, t->rlen);
        mutex_lock(&ec->lock);
        if (ec->global_lock) {
                status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
                if (ACPI_FAILURE(status)) {
-                       mutex_unlock(&ec->lock);
-                       return -ENODEV;
+                       status = -ENODEV;
+                       goto unlock;
                }
        }
-       status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
-       if (status) {
+       if (ec_wait_ibf0(ec)) {
                pr_err(PREFIX "input buffer is not empty, "
                                "aborting transaction\n");
+               status = -ETIME;
                goto end;
        }
-       status = acpi_ec_transaction_unlocked(ec, command,
-                                             wdata, wdata_len,
-                                             rdata, rdata_len,
-                                             force_poll);
-       end:
+       status = acpi_ec_transaction_unlocked(ec, t, force_poll);
+ end:
        if (ec->global_lock)
                acpi_release_global_lock(glk);
+ unlock:
        mutex_unlock(&ec->lock);
        return status;
  }
  
  int acpi_ec_burst_enable(struct acpi_ec *ec)
  {
        u8 d;
-       return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
+       struct transaction t = {.command = ACPI_EC_BURST_ENABLE,
+                               .wdata = NULL, .rdata = &d,
+                               .wlen = 0, .rlen = 1};
+       return acpi_ec_transaction(ec, &t, 0);
  }
  
  int acpi_ec_burst_disable(struct acpi_ec *ec)
  {
-       return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
+       struct transaction t = {.command = ACPI_EC_BURST_DISABLE,
+                               .wdata = NULL, .rdata = NULL,
+                               .wlen = 0, .rlen = 0};
+       return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
+                               acpi_ec_transaction(ec, &t, 0) : 0;
  }
  
  static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
  {
        int result;
        u8 d;
+       struct transaction t = {.command = ACPI_EC_COMMAND_READ,
+                               .wdata = &address, .rdata = &d,
+                               .wlen = 1, .rlen = 1};
  
-       result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
-                                    &address, 1, &d, 1, 0);
+       result = acpi_ec_transaction(ec, &t, 0);
        *data = d;
        return result;
  }
  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);
+       struct transaction t = {.command = ACPI_EC_COMMAND_WRITE,
+                               .wdata = wdata, .rdata = NULL,
+                               .wlen = 2, .rlen = 0};
+       return acpi_ec_transaction(ec, &t, 0);
  }
  
  /*
@@@ -412,12 -448,13 +448,13 @@@ int ec_transaction(u8 command
                   u8 * rdata, unsigned rdata_len,
                   int force_poll)
  {
+       struct transaction t = {.command = command,
+                               .wdata = wdata, .rdata = rdata,
+                               .wlen = wdata_len, .rlen = rdata_len};
        if (!first_ec)
                return -ENODEV;
  
-       return acpi_ec_transaction(first_ec, command, wdata,
-                                  wdata_len, rdata, rdata_len,
-                                  force_poll);
+       return acpi_ec_transaction(first_ec, &t, force_poll);
  }
  
  EXPORT_SYMBOL(ec_transaction);
@@@ -426,7 -463,9 +463,9 @@@ static int acpi_ec_query(struct acpi_e
  {
        int result;
        u8 d;
+       struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
+                               .wdata = NULL, .rdata = &d,
+                               .wlen = 0, .rlen = 1};
        if (!ec || !data)
                return -EINVAL;
  
         * bit to be cleared (and thus clearing the interrupt source).
         */
  
-       result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
+       result = acpi_ec_transaction(ec, &t, 0);
        if (result)
                return result;
  
@@@ -513,46 -552,26 +552,26 @@@ static void acpi_ec_gpe_query(void *ec_
  
  static u32 acpi_ec_gpe_handler(void *data)
  {
-       acpi_status status = AE_OK;
        struct acpi_ec *ec = data;
-       u8 state = acpi_ec_read_status(ec);
+       u8 status;
  
        pr_debug(PREFIX "~~~> interrupt\n");
-       atomic_inc(&ec->irq_count);
-       if (atomic_read(&ec->irq_count) > 5) {
-               pr_err(PREFIX "GPE storm detected, disabling EC GPE\n");
-               ec_switch_to_poll_mode(ec);
-               goto end;
-       }
-       clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
-       if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
+       status = acpi_ec_read_status(ec);
+       gpe_transaction(ec, status);
+       if (ec_transaction_done(ec) && (status & ACPI_EC_FLAG_IBF) == 0)
                wake_up(&ec->wait);
  
-       if (state & ACPI_EC_FLAG_SCI) {
-               if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
-                       status = acpi_os_execute(OSL_EC_BURST_HANDLER,
-                               acpi_ec_gpe_query, ec);
-       } else if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
-                  !test_bit(EC_FLAGS_NO_GPE, &ec->flags) &&
-                  in_interrupt()) {
+       ec_check_sci(ec, status);
+       if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
+           !test_bit(EC_FLAGS_NO_GPE, &ec->flags)) {
                /* this is non-query, must be confirmation */
                if (printk_ratelimit())
                        pr_info(PREFIX "non-query interrupt received,"
                                " switching to interrupt mode\n");
                set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
-               clear_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
        }
- end:
-       ec_schedule_ec_poll(ec);
-       return ACPI_SUCCESS(status) ?
-           ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
- }
- static void do_ec_poll(struct work_struct *work)
- {
-       struct acpi_ec *ec = container_of(work, struct acpi_ec, work.work);
-       atomic_set(&ec->irq_count, 0);
-       (void)acpi_ec_gpe_handler(ec);
+       return ACPI_INTERRUPT_HANDLED;
  }
  
  /* --------------------------------------------------------------------------
@@@ -696,8 -715,7 +715,7 @@@ static struct acpi_ec *make_acpi_ec(voi
        mutex_init(&ec->lock);
        init_waitqueue_head(&ec->wait);
        INIT_LIST_HEAD(&ec->list);
-       INIT_DELAYED_WORK_DEFERRABLE(&ec->work, do_ec_poll);
-       atomic_set(&ec->irq_count, 0);
+       spin_lock_init(&ec->curr_lock);
        return ec;
  }
  
@@@ -736,22 -754,15 +754,15 @@@ ec_parse_device(acpi_handle handle, u3
        return AE_CTRL_TERMINATE;
  }
  
- static void ec_poll_stop(struct acpi_ec *ec)
- {
-       clear_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
-       cancel_delayed_work(&ec->work);
- }
  static void ec_remove_handlers(struct acpi_ec *ec)
  {
-       ec_poll_stop(ec);
        if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
                                ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
                pr_err(PREFIX "failed to remove space handler\n");
        if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
                                &acpi_ec_gpe_handler)))
                pr_err(PREFIX "failed to remove gpe handler\n");
-       ec->handlers_installed = 0;
+       clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
  }
  
  static int acpi_ec_add(struct acpi_device *device)
@@@ -846,38 -857,25 +857,36 @@@ ec_parse_io_ports(struct acpi_resource 
  static int ec_install_handlers(struct acpi_ec *ec)
  {
        acpi_status status;
-       if (ec->handlers_installed)
+       if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
                return 0;
        status = acpi_install_gpe_handler(NULL, ec->gpe,
-                                         ACPI_GPE_EDGE_TRIGGERED,
-                                         &acpi_ec_gpe_handler, ec);
+                                 ACPI_GPE_EDGE_TRIGGERED,
+                                 &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);
        status = acpi_install_address_space_handler(ec->handle,
                                                    ACPI_ADR_SPACE_EC,
                                                    &acpi_ec_space_handler,
                                                    NULL, ec);
        if (ACPI_FAILURE(status)) {
 -              acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
 -              return -ENODEV;
 +              if (status == AE_NOT_FOUND) {
 +                      /*
 +                       * Maybe OS fails in evaluating the _REG object.
 +                       * The AE_NOT_FOUND error will be ignored and OS
 +                       * continue to initialize EC.
 +                       */
 +                      printk(KERN_ERR "Fail in evaluating the _REG object"
 +                              " of EC device. Broken bios is suspected.\n");
 +              } else {
 +                      acpi_remove_gpe_handler(NULL, ec->gpe,
 +                              &acpi_ec_gpe_handler);
 +                      return -ENODEV;
 +              }
        }
  
-       ec->handlers_installed = 1;
+       set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
        return 0;
  }
  
@@@ -898,7 -896,6 +907,6 @@@ static int acpi_ec_start(struct acpi_de
  
        /* EC is fully operational, allow queries */
        clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
-       ec_schedule_ec_poll(ec);
        return ret;
  }
  
@@@ -917,7 -914,7 +925,7 @@@ static int acpi_ec_stop(struct acpi_dev
  
  int __init acpi_boot_ec_enable(void)
  {
-       if (!boot_ec || boot_ec->handlers_installed)
+       if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
                return 0;
        if (!ec_install_handlers(boot_ec)) {
                first_ec = boot_ec;
diff --combined drivers/acpi/scan.c
index 3196749398eae552de75ffb51a03da9452114644,2ae218f5ea5971a7a7616c9b218427300fefa66f..eae6c801536d80158aabccaa8ad6bccdf2e7b9e9
@@@ -113,16 -113,16 +113,16 @@@ static int acpi_bus_hot_remove_device(v
  
  
        if (acpi_bus_trim(device, 1)) {
 -              ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
 -                              "Removing device failed\n"));
 +              printk(KERN_ERR PREFIX
 +                              "Removing device failed\n");
                return -1;
        }
  
        /* power off device */
        status = acpi_evaluate_object(handle, "_PS3", NULL, NULL);
        if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
 -              ACPI_DEBUG_PRINT((ACPI_DB_WARN,
 -                              "Power-off device failed\n"));
 +              printk(KERN_WARNING PREFIX
 +                              "Power-off device failed\n");
  
        if (device->flags.lockable) {
                arg_list.count = 1;
@@@ -276,13 -276,6 +276,13 @@@ int acpi_match_device_ids(struct acpi_d
  {
        const struct acpi_device_id *id;
  
 +      /*
 +       * If the device is not present, it is unnecessary to load device
 +       * driver for it.
 +       */
 +      if (!device->status.present)
 +              return -ENODEV;
 +
        if (device->flags.hardware_id) {
                for (id = ids; id->id[0]; id++) {
                        if (!strcmp((char*)id->id, device->pnp.hardware_id))
@@@ -484,7 -477,7 +484,7 @@@ static int acpi_device_register(struct 
  
        result = acpi_device_setup_files(device);
        if(result)
 -              ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id));
 +              printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n", device->dev.bus_id);
  
        device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
        return 0;
@@@ -751,16 -744,6 +751,16 @@@ static int acpi_bus_get_wakeup_device_f
        if (!acpi_match_device_ids(device, button_device_ids))
                device->wakeup.flags.run_wake = 1;
  
 +      /*
 +       * Don't set Power button GPE as run_wake
 +       * if Fixed Power button is used
 +       */
 +      if (!strcmp(device->pnp.hardware_id, "PNP0C0C") &&
 +              !(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
 +              device->wakeup.flags.run_wake = 0;
 +              device->wakeup.flags.valid = 0;
 +      }
 +
        end:
        if (ACPI_FAILURE(status))
                device->flags.wake_capable = 0;
@@@ -824,7 -807,6 +824,7 @@@ static int acpi_bus_get_power_flags(str
        /* TBD: System wake support and resource requirements. */
  
        device->power.state = ACPI_STATE_UNKNOWN;
 +      acpi_bus_get_power(device->handle, &(device->power.state));
  
        return 0;
  }
@@@ -1170,6 -1152,20 +1170,6 @@@ static int acpi_bus_remove(struct acpi_
        return 0;
  }
  
 -static int
 -acpi_is_child_device(struct acpi_device *device,
 -                      int (*matcher)(struct acpi_device *))
 -{
 -      int result = -ENODEV;
 -
 -      do {
 -              if (ACPI_SUCCESS(matcher(device)))
 -                      return AE_OK;
 -      } while ((device = device->parent));
 -
 -      return result;
 -}
 -
  static int
  acpi_add_single_object(struct acpi_device **child,
                       struct acpi_device *parent, acpi_handle handle, int type,
                        result = -ENODEV;
                        goto end;
                }
 -              if (!device->status.present) {
 -                      /* Bay and dock should be handled even if absent */
 -                      if (!ACPI_SUCCESS(
 -                           acpi_is_child_device(device, acpi_bay_match)) &&
 -                          !ACPI_SUCCESS(
 -                           acpi_is_child_device(device, acpi_dock_match))) {
 -                                      result = -ENODEV;
 -                                      goto end;
 -                      }
 +              /*
 +               * When the device is neither present nor functional, the
 +               * device should not be added to Linux ACPI device tree.
 +               * When the status of the device is not present but functinal,
 +               * it should be added to Linux ACPI tree. For example : bay
 +               * device , dock device.
 +               * In such conditions it is unncessary to check whether it is
 +               * bay device or dock device.
 +               */
 +              if (!device->status.present && !device->status.functional) {
 +                      result = -ENODEV;
 +                      goto end;
                }
                break;
        default:
         */
        acpi_device_set_id(device, parent, handle, type);
  
 +      /*
 +       * The ACPI device is attached to acpi handle before getting
 +       * the power/wakeup/peformance flags. Otherwise OS can't get
 +       * the corresponding ACPI device by the acpi handle in the course
 +       * of getting the power/wakeup/performance flags.
 +       */
 +      result = acpi_device_set_context(device, type);
 +      if (result)
 +              goto end;
 +
        /*
         * Power Management
         * ----------------
                        goto end;
        }
  
 -      if ((result = acpi_device_set_context(device, type)))
 -              goto end;
  
        result = acpi_device_register(device, parent);
  
@@@ -1417,12 -1402,7 +1417,12 @@@ static int acpi_bus_scan(struct acpi_de
                 * TBD: Need notifications and other detection mechanisms
                 *      in place before we can fully implement this.
                 */
 -              if (child->status.present) {
 +               /*
 +               * When the device is not present but functional, it is also
 +               * necessary to scan the children of this device.
 +               */
 +              if (child->status.present || (!child->status.present &&
 +                                      child->status.functional)) {
                        status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
                                                      NULL, NULL);
                        if (ACPI_SUCCESS(status)) {
@@@ -1565,7 -1545,6 +1565,6 @@@ static int acpi_bus_scan_fixed(struct a
        return result;
  }
  
- int __init acpi_boot_ec_enable(void);
  
  static int __init acpi_scan_init(void)
  {
         */
        result = acpi_bus_scan_fixed(acpi_root);
  
-       /* EC region might be needed at bus_scan, so enable it now */
-       acpi_boot_ec_enable();
        if (!result)
                result = acpi_bus_scan(acpi_root, &ops);
  
index a35c9597d5b136d76a3e417a26bf1da279da6022,ab926a70b39fe3cb382620bf3ceb9eeba0ef5fb7..cf04c6011c2acadf4624a7a39f06fd66668383f4
@@@ -93,7 -93,6 +93,7 @@@ int acpi_enable_wakeup_device_power(str
  int acpi_disable_wakeup_device_power(struct acpi_device *dev);
  int acpi_power_get_inferred_state(struct acpi_device *device);
  int acpi_power_transition(struct acpi_device *device, int state);
 +extern int acpi_power_nocheck;
  #endif
  
  /* --------------------------------------------------------------------------
     -------------------------------------------------------------------------- */
  #ifdef CONFIG_ACPI_EC
  int acpi_ec_ecdt_probe(void);
+ int acpi_boot_ec_enable(void);
  #endif
  
  /* --------------------------------------------------------------------------
@@@ -116,17 -116,12 +117,17 @@@ int acpi_processor_set_thermal_limit(ac
  /*--------------------------------------------------------------------------
                                    Dock Station
    -------------------------------------------------------------------------- */
 +struct acpi_dock_ops {
 +      acpi_notify_handler handler;
 +      acpi_notify_handler uevent;
 +};
 +
  #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
  extern int is_dock_device(acpi_handle handle);
  extern int register_dock_notifier(struct notifier_block *nb);
  extern void unregister_dock_notifier(struct notifier_block *nb);
  extern int register_hotplug_dock_device(acpi_handle handle,
 -                                      acpi_notify_handler handler,
 +                                      struct acpi_dock_ops *ops,
                                        void *context);
  extern void unregister_hotplug_dock_device(acpi_handle handle);
  #else
@@@ -142,7 -137,7 +143,7 @@@ static inline void unregister_dock_noti
  {
  }
  static inline int register_hotplug_dock_device(acpi_handle handle,
 -                                             acpi_notify_handler handler,
 +                                             struct acpi_dock_ops *ops,
                                               void *context)
  {
        return -ENODEV;