Skip to content

Commit b82a7df

Browse files
Sakari Ailusrafaeljw
authored andcommitted
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 <[email protected]> Signed-off-by: Sakari Ailus <[email protected]> Reviewed-by: Tomasz Figa <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ed66f12 commit b82a7df

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

drivers/acpi/device_pm.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,4 +1400,30 @@ bool acpi_storage_d3(struct device *dev)
14001400
}
14011401
EXPORT_SYMBOL_GPL(acpi_storage_d3);
14021402

1403+
/**
1404+
* acpi_dev_state_d0 - Tell if the device is in D0 power state
1405+
* @dev: Physical device the ACPI power state of which to check
1406+
*
1407+
* On a system without ACPI, return true. On a system with ACPI, return true if
1408+
* the current ACPI power state of the device is D0, or false otherwise.
1409+
*
1410+
* Note that the power state of a device is not well-defined after it has been
1411+
* passed to acpi_device_set_power() and before that function returns, so it is
1412+
* not valid to ask for the ACPI power state of the device in that time frame.
1413+
*
1414+
* This function is intended to be used in a driver's probe or remove
1415+
* function. See Documentation/firmware-guide/acpi/low-power-probe.rst for
1416+
* more information.
1417+
*/
1418+
bool acpi_dev_state_d0(struct device *dev)
1419+
{
1420+
struct acpi_device *adev = ACPI_COMPANION(dev);
1421+
1422+
if (!adev)
1423+
return true;
1424+
1425+
return adev->power.state == ACPI_STATE_D0;
1426+
}
1427+
EXPORT_SYMBOL_GPL(acpi_dev_state_d0);
1428+
14031429
#endif /* CONFIG_PM */

include/linux/acpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ int acpi_subsys_runtime_suspend(struct device *dev);
10161016
int acpi_subsys_runtime_resume(struct device *dev);
10171017
int acpi_dev_pm_attach(struct device *dev, bool power_on);
10181018
bool acpi_storage_d3(struct device *dev);
1019+
bool acpi_dev_state_d0(struct device *dev);
10191020
#else
10201021
static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
10211022
static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
@@ -1027,6 +1028,10 @@ static inline bool acpi_storage_d3(struct device *dev)
10271028
{
10281029
return false;
10291030
}
1031+
static inline bool acpi_dev_state_d0(struct device *dev)
1032+
{
1033+
return true;
1034+
}
10301035
#endif
10311036

10321037
#if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP)

0 commit comments

Comments
 (0)