[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210210230800.30291-5-sakari.ailus@linux.intel.com>
Date: Thu, 11 Feb 2021 01:07:57 +0200
From: Sakari Ailus <sakari.ailus@...ux.intel.com>
To: linux-i2c@...r.kernel.org
Cc: Wolfram Sang <wsa@...-dreams.de>,
"Rafael J. Wysocki" <rafael@...nel.org>,
linux-acpi@...r.kernel.org, linux-kernel@...r.kernel.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
rajmohan.mani@...el.com, Tomasz Figa <tfiga@...omium.org>,
Bartosz Golaszewski <bgolaszewski@...libre.com>,
Bingbu Cao <bingbu.cao@...el.com>,
Chiranjeevi Rapolu <chiranjeevi.rapolu@...el.com>,
Hyungwoo Yang <hyungwoo.yang@...el.com>,
linux-media@...r.kernel.org
Subject: [PATCH v11 4/7] 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@...ux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@...ux.intel.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
Reviewed-by: Tomasz Figa <tfiga@...omium.org>
---
drivers/acpi/device_pm.c | 27 +++++++++++++++++++++++++++
include/linux/acpi.h | 6 ++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 096153761ebc3..8be6daa9cb7dd 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1336,4 +1336,31 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
return 1;
}
EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
+
+/**
+ * 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 */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index ea296289a94c8..4886692564453 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -992,6 +992,7 @@ int acpi_dev_resume(struct device *dev);
int acpi_subsys_runtime_suspend(struct device *dev);
int acpi_subsys_runtime_resume(struct device *dev);
int acpi_dev_pm_attach(struct device *dev, bool power_on);
+bool acpi_dev_state_d0(struct device *dev);
#else
static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
@@ -999,6 +1000,11 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
{
return 0;
}
+
+static inline bool acpi_dev_state_d0(struct device *dev)
+{
+ return true;
+}
#endif
#if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP)
--
2.20.1
Powered by blists - more mailing lists