mmc-omap: add support for 16-bit and 32-bit registers
[safe/jmp/linux-2.6] / drivers / acpi / sleep.c
index 7e3c609..baa76bb 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
+
+#include "internal.h"
 #include "sleep.h"
 
 u8 sleep_states[ACPI_S_STATE_COUNT];
@@ -79,18 +81,6 @@ static int acpi_sleep_prepare(u32 acpi_state)
 #ifdef CONFIG_ACPI_SLEEP
 static u32 acpi_target_sleep_state = ACPI_STATE_S0;
 /*
- * 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.
- */
-static bool old_suspend_ordering;
-
-void __init acpi_old_suspend_ordering(void)
-{
-       old_suspend_ordering = true;
-}
-
-/*
  * 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
@@ -101,18 +91,22 @@ void __init acpi_old_suspend_ordering(void)
  * cases.
  */
 static bool set_sci_en_on_resume;
+
+void __init acpi_set_sci_en_on_resume(void)
+{
+       set_sci_en_on_resume = true;
+}
+
 /*
- * The ACPI specification wants us to save NVS memory regions during hibernation
- * and to restore them during the subsequent resume.  However, it is not certain
- * if this mechanism is going to work on all machines, so we allow the user to
- * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
- * option.
+ * 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.
  */
-static bool s4_no_nvs;
+static bool old_suspend_ordering;
 
-void __init acpi_s4_no_nvs(void)
+void __init acpi_old_suspend_ordering(void)
 {
-       s4_no_nvs = true;
+       old_suspend_ordering = true;
 }
 
 /**
@@ -261,7 +255,7 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
 
        /* If ACPI is not enabled by the BIOS, we need to enable it here. */
        if (set_sci_en_on_resume)
-               acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1);
+               acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
        else
                acpi_enable();
 
@@ -311,9 +305,9 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
 static struct platform_suspend_ops acpi_suspend_ops = {
        .valid = acpi_suspend_state_valid,
        .begin = acpi_suspend_begin,
-       .prepare = acpi_pm_prepare,
+       .prepare_late = acpi_pm_prepare,
        .enter = acpi_suspend_enter,
-       .finish = acpi_pm_finish,
+       .wake = acpi_pm_finish,
        .end = acpi_pm_end,
 };
 
@@ -339,9 +333,9 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
 static struct platform_suspend_ops acpi_suspend_ops_old = {
        .valid = acpi_suspend_state_valid,
        .begin = acpi_suspend_begin_old,
-       .prepare = acpi_pm_disable_gpes,
+       .prepare_late = acpi_pm_disable_gpes,
        .enter = acpi_suspend_enter,
-       .finish = acpi_pm_finish,
+       .wake = acpi_pm_finish,
        .end = acpi_pm_end,
        .recover = acpi_pm_finish,
 };
@@ -391,11 +385,154 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
                DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
                },
        },
+       {
+       .callback = init_old_suspend_ordering,
+       .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
+       .matches = {
+               DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
+               DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Toshiba Satellite L300",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L300"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Hewlett-Packard HP G7000 Notebook PC",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "HP G7000 Notebook PC"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Hewlett-Packard HP Pavilion dv3 Notebook PC",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv3 Notebook PC"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Hewlett-Packard Pavilion dv4",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv4"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Hewlett-Packard Pavilion dv7",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv7"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Hewlett-Packard Compaq Presario C700 Notebook PC",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Compaq Presario C700 Notebook PC"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Hewlett-Packard Compaq Presario CQ40 Notebook PC",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Compaq Presario CQ40 Notebook PC"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Lenovo ThinkPad T410",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T410"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Lenovo ThinkPad T510",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T510"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Lenovo ThinkPad W510",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad W510"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Lenovo ThinkPad X201[s]",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+               DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201"),
+               },
+       },
+       {
+       .callback = init_old_suspend_ordering,
+       .ident = "Panasonic CF51-2L",
+       .matches = {
+               DMI_MATCH(DMI_BOARD_VENDOR,
+                               "Matsushita Electric Industrial Co.,Ltd."),
+               DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Dell Studio 1558",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1558"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Dell Studio 1557",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
+               },
+       },
+       {
+       .callback = init_set_sci_en_on_resume,
+       .ident = "Dell Studio 1555",
+       .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1555"),
+               },
+       },
        {},
 };
 #endif /* CONFIG_SUSPEND */
 
 #ifdef CONFIG_HIBERNATION
+/*
+ * The ACPI specification wants us to save NVS memory regions during hibernation
+ * and to restore them during the subsequent resume.  However, it is not certain
+ * if this mechanism is going to work on all machines, so we allow the user to
+ * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
+ * option.
+ */
+static bool s4_no_nvs;
+
+void __init acpi_s4_no_nvs(void)
+{
+       s4_no_nvs = true;
+}
+
 static unsigned long s4_hardware_signature;
 static struct acpi_table_facs *facs;
 static bool nosigcheck;
@@ -471,8 +608,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();
 }
 
@@ -484,8 +630,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,
 };
 
 /**
@@ -537,8 +683,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 */
@@ -653,19 +799,34 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
 {
        acpi_handle handle;
        struct acpi_device *adev;
+       int error;
 
-       if (!device_may_wakeup(dev))
+       if (!device_can_wakeup(dev))
                return -EINVAL;
 
        handle = DEVICE_ACPI_HANDLE(dev);
        if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
-               printk(KERN_DEBUG "ACPI handle has no context!\n");
+               dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
                return -ENODEV;
        }
 
-       return 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");
+
+       return error;
 }
 #endif
 
@@ -679,12 +840,38 @@ static void acpi_power_off_prepare(void)
 static void acpi_power_off(void)
 {
        /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
-       printk("%s called\n", __func__);
+       printk(KERN_DEBUG "%s called\n", __func__);
        local_irq_disable();
        acpi_enable_wakeup_device(ACPI_STATE_S5);
        acpi_enter_sleep_state(ACPI_STATE_S5);
 }
 
+/*
+ * ACPI 2.0 created the optional _GTS and _BFS,
+ * but industry adoption has been neither rapid nor broad.
+ *
+ * Linux gets into trouble when it executes poorly validated
+ * paths through the BIOS, so disable _GTS and _BFS by default,
+ * but do speak up and offer the option to enable them.
+ */
+void __init acpi_gts_bfs_check(void)
+{
+       acpi_handle dummy;
+
+       if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
+       {
+               printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
+               printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
+                       "please notify linux-acpi@vger.kernel.org\n");
+       }
+       if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
+       {
+               printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
+               printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
+                       "please notify linux-acpi@vger.kernel.org\n");
+       }
+}
+
 int __init acpi_sleep_init(void)
 {
        acpi_status status;
@@ -743,5 +930,6 @@ int __init acpi_sleep_init(void)
         * object can also be evaluated when the system enters S5.
         */
        register_reboot_notifier(&tts_notifier);
+       acpi_gts_bfs_check();
        return 0;
 }