Skip to content

Commit

Permalink
ACPI / PM: Always enable wakeup GPEs when enabling device wakeup
Browse files Browse the repository at this point in the history
Wakeup GPEs are currently only enabled when setting up devices for
remote wakeup at run time.  During system-wide transitions they are
enabled by ACPICA at the very last stage of suspend (before asking
the BIOS to take over).  Of course, that only works for system
sleep states supported by ACPI, so in particular it doesn't work
for the "freeze" sleep state.

For this reason, modify the ACPI core device PM code to enable wakeup
GPEs for devices when setting them up for wakeup regardless of whether
that is remote wakeup at runtime or system wakeup.  That allows the
same device wakeup setup routine to be used for both runtime PM and
system-wide PM and makes it possible to reduce code size quite a bit.

This make ACPI-based PCI Wake-on-LAN work with the "freeze" sleep
state on my venerable Toshiba Portege R500 and should help other
systems too.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
rafaeljw committed Jul 22, 2014
1 parent c072530 commit f35cec2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
49 changes: 17 additions & 32 deletions drivers/acpi/device_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
}
EXPORT_SYMBOL(acpi_pm_device_sleep_state);

#ifdef CONFIG_PM_RUNTIME
/**
* acpi_pm_notify_work_func - ACPI devices wakeup notification work function.
* @work: Work item to handle.
Expand All @@ -655,8 +654,9 @@ static void acpi_pm_notify_work_func(struct work_struct *work)
}

/**
* __acpi_device_run_wake - Enable/disable runtime remote wakeup for device.
* @adev: ACPI device to enable/disable the remote wakeup for.
* acpi_device_wakeup - Enable/disable wakeup functionality for device.
* @adev: ACPI device to enable/disable wakeup functionality for.
* @target_state: State the system is transitioning into.
* @enable: Whether to enable or disable the wakeup functionality.
*
* Enable/disable the GPE associated with @adev so that it can generate
Expand All @@ -666,15 +666,16 @@ static void acpi_pm_notify_work_func(struct work_struct *work)
* Callers must ensure that @adev is a valid ACPI device node before executing
* this function.
*/
int __acpi_device_run_wake(struct acpi_device *adev, bool enable)
static int acpi_device_wakeup(struct acpi_device *adev, u32 target_state,
bool enable)
{
struct acpi_device_wakeup *wakeup = &adev->wakeup;

if (enable) {
acpi_status res;
int error;

error = acpi_enable_wakeup_device_power(adev, ACPI_STATE_S0);
error = acpi_enable_wakeup_device_power(adev, target_state);
if (error)
return error;

Expand All @@ -690,6 +691,7 @@ int __acpi_device_run_wake(struct acpi_device *adev, bool enable)
return 0;
}

#ifdef CONFIG_PM_RUNTIME
/**
* acpi_pm_device_run_wake - Enable/disable remote wakeup for given device.
* @dev: Device to enable/disable the platform to wake up.
Expand All @@ -710,28 +712,12 @@ int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
return -ENODEV;
}

return __acpi_device_run_wake(adev, enable);
return acpi_device_wakeup(adev, enable, ACPI_STATE_S0);
}
EXPORT_SYMBOL(acpi_pm_device_run_wake);
#else
static inline void acpi_pm_notify_work_func(struct work_struct *work) {}
#endif /* CONFIG_PM_RUNTIME */

#ifdef CONFIG_PM_SLEEP
/**
* __acpi_device_sleep_wake - Enable or disable device to wake up the system.
* @dev: Device to enable/desible to wake up the system.
* @target_state: System state the device is supposed to wake up from.
* @enable: Whether to enable or disable @dev to wake up the system.
*/
int __acpi_device_sleep_wake(struct acpi_device *adev, u32 target_state,
bool enable)
{
return enable ?
acpi_enable_wakeup_device_power(adev, target_state) :
acpi_disable_wakeup_device_power(adev);
}

/**
* acpi_pm_device_sleep_wake - Enable or disable device to wake up the system.
* @dev: Device to enable/desible to wake up the system from sleep states.
Expand All @@ -752,8 +738,7 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
return -ENODEV;
}

error = __acpi_device_sleep_wake(adev, acpi_target_system_state(),
enable);
error = acpi_device_wakeup(adev, acpi_target_system_state(), enable);
if (!error)
dev_info(dev, "System wakeup %s by ACPI\n",
enable ? "enabled" : "disabled");
Expand Down Expand Up @@ -811,13 +796,13 @@ int acpi_dev_runtime_suspend(struct device *dev)

remote_wakeup = dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) >
PM_QOS_FLAGS_NONE;
error = __acpi_device_run_wake(adev, remote_wakeup);
error = acpi_device_wakeup(adev, ACPI_STATE_S0, remote_wakeup);
if (remote_wakeup && error)
return -EAGAIN;

error = acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
if (error)
__acpi_device_run_wake(adev, false);
acpi_device_wakeup(adev, ACPI_STATE_S0, false);

return error;
}
Expand All @@ -840,7 +825,7 @@ int acpi_dev_runtime_resume(struct device *dev)
return 0;

error = acpi_dev_pm_full_power(adev);
__acpi_device_run_wake(adev, false);
acpi_device_wakeup(adev, ACPI_STATE_S0, false);
return error;
}
EXPORT_SYMBOL_GPL(acpi_dev_runtime_resume);
Expand Down Expand Up @@ -896,13 +881,13 @@ int acpi_dev_suspend_late(struct device *dev)

target_state = acpi_target_system_state();
wakeup = device_may_wakeup(dev);
error = __acpi_device_sleep_wake(adev, target_state, wakeup);
error = acpi_device_wakeup(adev, target_state, wakeup);
if (wakeup && error)
return error;

error = acpi_dev_pm_low_power(dev, adev, target_state);
if (error)
__acpi_device_sleep_wake(adev, ACPI_STATE_UNKNOWN, false);
acpi_device_wakeup(adev, ACPI_STATE_UNKNOWN, false);

return error;
}
Expand All @@ -925,7 +910,7 @@ int acpi_dev_resume_early(struct device *dev)
return 0;

error = acpi_dev_pm_full_power(adev);
__acpi_device_sleep_wake(adev, ACPI_STATE_UNKNOWN, false);
acpi_device_wakeup(adev, ACPI_STATE_UNKNOWN, false);
return error;
}
EXPORT_SYMBOL_GPL(acpi_dev_resume_early);
Expand Down Expand Up @@ -1088,7 +1073,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
dev->pm_domain = &acpi_general_pm_domain;
if (power_on) {
acpi_dev_pm_full_power(adev);
__acpi_device_run_wake(adev, false);
acpi_device_wakeup(adev, ACPI_STATE_S0, false);
}
return 0;
}
Expand Down Expand Up @@ -1122,7 +1107,7 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
*/
dev_pm_qos_hide_latency_limit(dev);
dev_pm_qos_hide_flags(dev);
__acpi_device_run_wake(adev, false);
acpi_device_wakeup(adev, ACPI_STATE_S0, false);
acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
}
}
Expand Down
11 changes: 0 additions & 11 deletions include/acpi/acpi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,28 +543,17 @@ static inline int acpi_pm_device_sleep_state(struct device *d, int *p, int m)
#endif

#ifdef CONFIG_PM_RUNTIME
int __acpi_device_run_wake(struct acpi_device *, bool);
int acpi_pm_device_run_wake(struct device *, bool);
#else
static inline int __acpi_device_run_wake(struct acpi_device *adev, bool en)
{
return -ENODEV;
}
static inline int acpi_pm_device_run_wake(struct device *dev, bool enable)
{
return -ENODEV;
}
#endif

#ifdef CONFIG_PM_SLEEP
int __acpi_device_sleep_wake(struct acpi_device *, u32, bool);
int acpi_pm_device_sleep_wake(struct device *, bool);
#else
static inline int __acpi_device_sleep_wake(struct acpi_device *adev,
u32 target_state, bool enable)
{
return -ENODEV;
}
static inline int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
{
return -ENODEV;
Expand Down

0 comments on commit f35cec2

Please sign in to comment.