Merge branches 'battery-2.6.34', 'bugzilla-10805', 'bugzilla-14668', 'bugzilla-531916...
[safe/jmp/linux-2.6] / drivers / acpi / sleep.c
index 5f2c379..f74834a 100644 (file)
@@ -81,6 +81,23 @@ static int acpi_sleep_prepare(u32 acpi_state)
 #ifdef CONFIG_ACPI_SLEEP
 static u32 acpi_target_sleep_state = ACPI_STATE_S0;
 /*
+ * According to the ACPI specification the BIOS should make sure that ACPI is
+ * enabled and SCI_EN bit is set on wake-up from S1 - S3 sleep states.  Still,
+ * some BIOSes don't do that and therefore we use acpi_enable() to enable ACPI
+ * on such systems during resume.  Unfortunately that doesn't help in
+ * particularly pathological cases in which SCI_EN has to be set directly on
+ * resume, although the specification states very clearly that this flag is
+ * owned by the hardware.  The set_sci_en_on_resume variable will be set in such
+ * cases.
+ */
+static bool set_sci_en_on_resume;
+
+void __init acpi_set_sci_en_on_resume(void)
+{
+       set_sci_en_on_resume = true;
+}
+
+/*
  * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
  * user to request that behavior by using the 'acpi_old_suspend_ordering'
  * kernel command line option that causes the following variable to be set.
@@ -170,18 +187,6 @@ static void acpi_pm_end(void)
 #endif /* CONFIG_ACPI_SLEEP */
 
 #ifdef CONFIG_SUSPEND
-/*
- * According to the ACPI specification the BIOS should make sure that ACPI is
- * enabled and SCI_EN bit is set on wake-up from S1 - S3 sleep states.  Still,
- * some BIOSes don't do that and therefore we use acpi_enable() to enable ACPI
- * on such systems during resume.  Unfortunately that doesn't help in
- * particularly pathological cases in which SCI_EN has to be set directly on
- * resume, although the specification states very clearly that this flag is
- * owned by the hardware.  The set_sci_en_on_resume variable will be set in such
- * cases.
- */
-static bool set_sci_en_on_resume;
-
 extern void do_suspend_lowlevel(void);
 
 static u32 acpi_suspend_states[] = {
@@ -547,8 +552,17 @@ static void acpi_hibernation_leave(void)
        hibernate_nvs_restore();
 }
 
-static void acpi_pm_enable_gpes(void)
+static int acpi_pm_pre_restore(void)
 {
+       acpi_disable_all_gpes();
+       acpi_os_wait_events_complete(NULL);
+       acpi_ec_suspend_transactions();
+       return 0;
+}
+
+static void acpi_pm_restore_cleanup(void)
+{
+       acpi_ec_resume_transactions();
        acpi_enable_all_runtime_gpes();
 }
 
@@ -560,8 +574,8 @@ static struct platform_hibernation_ops acpi_hibernation_ops = {
        .prepare = acpi_pm_prepare,
        .enter = acpi_hibernation_enter,
        .leave = acpi_hibernation_leave,
-       .pre_restore = acpi_pm_disable_gpes,
-       .restore_cleanup = acpi_pm_enable_gpes,
+       .pre_restore = acpi_pm_pre_restore,
+       .restore_cleanup = acpi_pm_restore_cleanup,
 };
 
 /**
@@ -613,8 +627,8 @@ static struct platform_hibernation_ops acpi_hibernation_ops_old = {
        .prepare = acpi_pm_disable_gpes,
        .enter = acpi_hibernation_enter,
        .leave = acpi_hibernation_leave,
-       .pre_restore = acpi_pm_disable_gpes,
-       .restore_cleanup = acpi_pm_enable_gpes,
+       .pre_restore = acpi_pm_pre_restore,
+       .restore_cleanup = acpi_pm_restore_cleanup,
        .recover = acpi_pm_finish,
 };
 #endif /* CONFIG_HIBERNATION */
@@ -740,9 +754,18 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
                return -ENODEV;
        }
 
-       error = enable ?
-               acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
-               acpi_disable_wakeup_device_power(adev);
+       if (enable) {
+               error = acpi_enable_wakeup_device_power(adev,
+                                               acpi_target_sleep_state);
+               if (!error)
+                       acpi_enable_gpe(adev->wakeup.gpe_device,
+                                       adev->wakeup.gpe_number,
+                                       ACPI_GPE_TYPE_WAKE);
+       } else {
+               acpi_disable_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
+                               ACPI_GPE_TYPE_WAKE);
+               error = acpi_disable_wakeup_device_power(adev);
+       }
        if (!error)
                dev_info(dev, "wake-up capability %s by ACPI\n",
                                enable ? "enabled" : "disabled");