summaryrefslogtreecommitdiff
path: root/drivers/acpi/sleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/sleep.c')
-rw-r--r--drivers/acpi/sleep.c110
1 files changed, 41 insertions, 69 deletions
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 5b7c52e4a00f..cf82989ae756 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -70,10 +70,10 @@ static int acpi_sleep_prepare(u32 acpi_state)
}
ACPI_FLUSH_CPU_CACHE();
- acpi_enable_wakeup_device_prep(acpi_state);
#endif
printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
acpi_state);
+ acpi_enable_wakeup_devices(acpi_state);
acpi_enter_sleep_state_prep(acpi_state);
return 0;
}
@@ -82,6 +82,20 @@ static int acpi_sleep_prepare(u32 acpi_state)
static u32 acpi_target_sleep_state = ACPI_STATE_S0;
/*
+ * The ACPI specification wants us to save NVS memory regions during hibernation
+ * and to restore them during the subsequent resume. Windows does that also for
+ * suspend to RAM. However, it is known that this mechanism does not work on
+ * all machines, so we allow the user to disable it with the help of the
+ * 'acpi_sleep=nonvs' kernel command line option.
+ */
+static bool nvs_nosave;
+
+void __init acpi_nvs_nosave(void)
+{
+ nvs_nosave = 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.
@@ -105,6 +119,16 @@ static int acpi_pm_freeze(void)
}
/**
+ * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
+ */
+static int acpi_pm_pre_suspend(void)
+{
+ acpi_pm_freeze();
+ suspend_nvs_save();
+ return 0;
+}
+
+/**
* __acpi_pm_prepare - Prepare the platform to enter the target state.
*
* If necessary, set the firmware waking vector and do arch-specific
@@ -113,11 +137,9 @@ static int acpi_pm_freeze(void)
static int __acpi_pm_prepare(void)
{
int error = acpi_sleep_prepare(acpi_target_sleep_state);
-
- suspend_nvs_save();
-
if (error)
acpi_target_sleep_state = ACPI_STATE_S0;
+
return error;
}
@@ -128,9 +150,8 @@ static int __acpi_pm_prepare(void)
static int acpi_pm_prepare(void)
{
int error = __acpi_pm_prepare();
-
if (!error)
- acpi_pm_freeze();
+ acpi_pm_pre_suspend();
return error;
}
@@ -145,7 +166,6 @@ static void acpi_pm_finish(void)
{
u32 acpi_state = acpi_target_sleep_state;
- suspend_nvs_free();
acpi_ec_unblock_transactions();
if (acpi_state == ACPI_STATE_S0)
@@ -153,7 +173,7 @@ static void acpi_pm_finish(void)
printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
acpi_state);
- acpi_disable_wakeup_device(acpi_state);
+ acpi_disable_wakeup_devices(acpi_state);
acpi_leave_sleep_state(acpi_state);
/* reset firmware waking vector */
@@ -167,6 +187,7 @@ static void acpi_pm_finish(void)
*/
static void acpi_pm_end(void)
{
+ suspend_nvs_free();
/*
* This is necessary in case acpi_pm_finish() is not called during a
* failing transition to a sleep state.
@@ -197,8 +218,7 @@ static int acpi_suspend_begin(suspend_state_t pm_state)
u32 acpi_state = acpi_suspend_states[pm_state];
int error = 0;
- error = suspend_nvs_alloc();
-
+ error = nvs_nosave ? 0 : suspend_nvs_alloc();
if (error)
return error;
@@ -238,7 +258,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
}
local_irq_save(flags);
- acpi_enable_wakeup_device(acpi_state);
switch (acpi_state) {
case ACPI_STATE_S1:
barrier();
@@ -284,11 +303,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
return ACPI_SUCCESS(status) ? 0 : -EFAULT;
}
-static void acpi_suspend_finish(void)
-{
- acpi_pm_finish();
-}
-
static int acpi_suspend_state_valid(suspend_state_t pm_state)
{
u32 acpi_state;
@@ -310,7 +324,7 @@ static struct platform_suspend_ops acpi_suspend_ops = {
.begin = acpi_suspend_begin,
.prepare_late = acpi_pm_prepare,
.enter = acpi_suspend_enter,
- .wake = acpi_suspend_finish,
+ .wake = acpi_pm_finish,
.end = acpi_pm_end,
};
@@ -323,9 +337,9 @@ static struct platform_suspend_ops acpi_suspend_ops = {
static int acpi_suspend_begin_old(suspend_state_t pm_state)
{
int error = acpi_suspend_begin(pm_state);
-
if (!error)
error = __acpi_pm_prepare();
+
return error;
}
@@ -336,9 +350,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_late = acpi_pm_freeze,
+ .prepare_late = acpi_pm_pre_suspend,
.enter = acpi_suspend_enter,
- .wake = acpi_suspend_finish,
+ .wake = acpi_pm_finish,
.end = acpi_pm_end,
.recover = acpi_pm_finish,
};
@@ -388,20 +402,6 @@ 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;
@@ -415,7 +415,7 @@ static int acpi_hibernation_begin(void)
{
int error;
- error = s4_no_nvs ? 0 : suspend_nvs_alloc();
+ error = nvs_nosave ? 0 : suspend_nvs_alloc();
if (!error) {
acpi_target_sleep_state = ACPI_STATE_S4;
acpi_sleep_tts_switch(acpi_target_sleep_state);
@@ -424,16 +424,6 @@ static int acpi_hibernation_begin(void)
return error;
}
-static int acpi_hibernation_pre_snapshot(void)
-{
- int error = acpi_pm_prepare();
-
- if (!error)
- suspend_nvs_save();
-
- return error;
-}
-
static int acpi_hibernation_enter(void)
{
acpi_status status = AE_OK;
@@ -442,7 +432,6 @@ static int acpi_hibernation_enter(void)
ACPI_FLUSH_CPU_CACHE();
local_irq_save(flags);
- acpi_enable_wakeup_device(ACPI_STATE_S4);
/* This shouldn't return. If it returns, we have a problem */
status = acpi_enter_sleep_state(ACPI_STATE_S4);
/* Reprogram control registers and execute _BFS */
@@ -482,7 +471,7 @@ static void acpi_pm_thaw(void)
static struct platform_hibernation_ops acpi_hibernation_ops = {
.begin = acpi_hibernation_begin,
.end = acpi_pm_end,
- .pre_snapshot = acpi_hibernation_pre_snapshot,
+ .pre_snapshot = acpi_pm_prepare,
.finish = acpi_pm_finish,
.prepare = acpi_pm_prepare,
.enter = acpi_hibernation_enter,
@@ -510,7 +499,7 @@ static int acpi_hibernation_begin_old(void)
error = acpi_sleep_prepare(ACPI_STATE_S4);
if (!error) {
- if (!s4_no_nvs)
+ if (!nvs_nosave)
error = suspend_nvs_alloc();
if (!error)
acpi_target_sleep_state = ACPI_STATE_S4;
@@ -518,13 +507,6 @@ static int acpi_hibernation_begin_old(void)
return error;
}
-static int acpi_hibernation_pre_snapshot_old(void)
-{
- acpi_pm_freeze();
- suspend_nvs_save();
- return 0;
-}
-
/*
* The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
* been requested.
@@ -532,7 +514,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
static struct platform_hibernation_ops acpi_hibernation_ops_old = {
.begin = acpi_hibernation_begin_old,
.end = acpi_pm_end,
- .pre_snapshot = acpi_hibernation_pre_snapshot_old,
+ .pre_snapshot = acpi_pm_pre_suspend,
.prepare = acpi_pm_freeze,
.finish = acpi_pm_finish,
.enter = acpi_hibernation_enter,
@@ -664,18 +646,9 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
return -ENODEV;
}
- 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);
- }
+ error = enable ?
+ acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
+ acpi_disable_wakeup_device_power(adev);
if (!error)
dev_info(dev, "wake-up capability %s by ACPI\n",
enable ? "enabled" : "disabled");
@@ -696,7 +669,6 @@ static void acpi_power_off(void)
/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
printk(KERN_DEBUG "%s called\n", __func__);
local_irq_disable();
- acpi_enable_wakeup_device(ACPI_STATE_S5);
acpi_enter_sleep_state(ACPI_STATE_S5);
}