staging: Add framebuffer driver for XGI chipsets
[safe/jmp/linux-2.6] / drivers / acpi / sleep.c
index 7e3c609..4ab2275 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];
@@ -78,6 +80,7 @@ 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'
@@ -90,31 +93,6 @@ 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
- * 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;
-/*
- * 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;
-}
-
 /**
  *     acpi_pm_disable_gpes - Disable the GPEs.
  */
@@ -259,11 +237,8 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
                break;
        }
 
-       /* 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);
-       else
-               acpi_enable();
+       /* This violates the spec but is required for bug compatibility. */
+       acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
 
        /* Reprogram control registers and execute _BFS */
        acpi_leave_sleep_state_prep(acpi_state);
@@ -311,9 +286,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 +314,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,
 };
@@ -352,12 +327,6 @@ static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
        return 0;
 }
 
-static int __init init_set_sci_en_on_resume(const struct dmi_system_id *d)
-{
-       set_sci_en_on_resume = true;
-       return 0;
-}
-
 static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
        {
        .callback = init_old_suspend_ordering,
@@ -376,19 +345,20 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
                },
        },
        {
-       .callback = init_set_sci_en_on_resume,
-       .ident = "Apple MacBook 1,1",
+       .callback = init_old_suspend_ordering,
+       .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
        .matches = {
-               DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
-               DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"),
+               DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
+               DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
                },
        },
        {
-       .callback = init_set_sci_en_on_resume,
-       .ident = "Apple MacMini 1,1",
+       .callback = init_old_suspend_ordering,
+       .ident = "Panasonic CF51-2L",
        .matches = {
-               DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
-               DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
+               DMI_MATCH(DMI_BOARD_VENDOR,
+                               "Matsushita Electric Industrial Co.,Ltd."),
+               DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
                },
        },
        {},
@@ -396,6 +366,20 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
 #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 +455,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 +477,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 +530,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 +646,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 +687,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 +777,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;
 }