diff options
author | Sakari Ailus <sakari.ailus@linux.intel.com> | 2021-10-18 15:17:27 +0300 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2021-11-03 19:03:55 +0100 |
commit | b82a7df4a7f3841896aaec1ad81e654bc87b5989 (patch) | |
tree | 048f0cc1053c1ad58b1ef73836427e4b7f7c6825 /drivers/acpi/device_pm.c | |
parent | ed66f12ba4b17c66b4c59df76d3b1bb2cb3a75d1 (diff) | |
download | linux-b82a7df4a7f3841896aaec1ad81e654bc87b5989.tar.gz linux-b82a7df4a7f3841896aaec1ad81e654bc87b5989.tar.bz2 linux-b82a7df4a7f3841896aaec1ad81e654bc87b5989.zip |
ACPI: Add a convenience function to tell a device is in D0 state
Add a convenience function to tell whether a device is in D0 state,
primarily for use in drivers' probe or remove functions on busses where
the custom is to power on the device for the duration of both.
Returns false on non-ACPI systems.
Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/device_pm.c')
-rw-r--r-- | drivers/acpi/device_pm.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 0028b6b51c87..19b33c028f35 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1400,4 +1400,30 @@ bool acpi_storage_d3(struct device *dev) } EXPORT_SYMBOL_GPL(acpi_storage_d3); +/** + * acpi_dev_state_d0 - Tell if the device is in D0 power state + * @dev: Physical device the ACPI power state of which to check + * + * On a system without ACPI, return true. On a system with ACPI, return true if + * the current ACPI power state of the device is D0, or false otherwise. + * + * Note that the power state of a device is not well-defined after it has been + * passed to acpi_device_set_power() and before that function returns, so it is + * not valid to ask for the ACPI power state of the device in that time frame. + * + * This function is intended to be used in a driver's probe or remove + * function. See Documentation/firmware-guide/acpi/low-power-probe.rst for + * more information. + */ +bool acpi_dev_state_d0(struct device *dev) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + + if (!adev) + return true; + + return adev->power.state == ACPI_STATE_D0; +} +EXPORT_SYMBOL_GPL(acpi_dev_state_d0); + #endif /* CONFIG_PM */ |