[PATCH v8 03/16] power: sequencing: Add pwrseq_get_state()
From: Chen-Yu Tsai <wenst@chromium.org>
Date: 2026-09-04 08:42:27
Also in:
driver-core, linux-acpi, linux-arm-kernel, linux-mediatek, linux-pm, linux-usb, lkml
Subsystem:
power sequencing, the rest · Maintainers:
Bartosz Golaszewski, Linus Torvalds
The power sequencing consumer API already does power on state tracking internally. Expose the state to consumers through pwrseq_get_state() so that they don't have to reimplement it locally. Instead of just on/off and error codes, the function can also return "unknown" state. This is in anticipation for "uncontrollable" power sequencers (such as GPIOs left unconnected). Acked-by: Bartosz Golaszewski <redacted> Reviewed-by: Manivannan Sadhasivam <redacted> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> --- Changes since v7: - Adapted to pwrseq_enable/disable() rename Changes since v6: - Changed to pwrseq_get_state() with enum return value Changes since v5: - Reverted back to returning -EINVAL if descriptor is NULL Changes since v4: - Make pwrseq_power_is_on() return 1 if descriptor is NULL, i.e. if the descriptor is optional, matching the other pwrseq consumer APIs Changes since v3: - Added missing stub function for !POWER_SEQUENCING Changes since v2: - New patch Needs to go in with "usb: hub: Power on connected M.2 E-key connectors" as it is a build time dependency. Bartosz wants the change on an immutable branch to pull into the pwrseq tree. --- drivers/power/sequencing/core.c | 19 +++++++++++++++++++ include/linux/pwrseq/consumer.h | 12 ++++++++++++ 2 files changed, 31 insertions(+)
diff --git a/drivers/power/sequencing/core.c b/drivers/power/sequencing/core.c
index 721e888b658d..dbb2bd2f8864 100644
--- a/drivers/power/sequencing/core.c
+++ b/drivers/power/sequencing/core.c@@ -968,6 +968,25 @@ int pwrseq_disable(struct pwrseq_desc *desc) } EXPORT_SYMBOL_GPL(pwrseq_disable); +/** + * pwrseq_get_state() - Queries the last requested state of the power sequencer. + * @desc: Descriptor referencing the power sequencer. + * + * This returns the last requested state of the power sequencer. + * + * Returns: + * On success, PWRSEQ_STATE_ON for on and PWRSEQ_STATE_OFF for off; + * negative error number on failure. + */ +int pwrseq_get_state(struct pwrseq_desc *desc) +{ + if (!desc) + return -EINVAL; + + return desc->powered_on ? PWRSEQ_STATE_ON : PWRSEQ_STATE_OFF; +} +EXPORT_SYMBOL_GPL(pwrseq_get_state); + /** * pwrseq_to_device() - Get the pwrseq device pointer from a descriptor. * @desc: Descriptor referencing the power sequencer.
diff --git a/include/linux/pwrseq/consumer.h b/include/linux/pwrseq/consumer.h
index 16fad5f3e3ab..e2a2991b20c2 100644
--- a/include/linux/pwrseq/consumer.h
+++ b/include/linux/pwrseq/consumer.h@@ -11,6 +11,12 @@ struct device; struct pwrseq_desc; +enum { + PWRSEQ_STATE_UNKNOWN, + PWRSEQ_STATE_ON, + PWRSEQ_STATE_OFF, +}; + #if IS_ENABLED(CONFIG_POWER_SEQUENCING) struct pwrseq_desc * __must_check
@@ -22,6 +28,7 @@ devm_pwrseq_get(struct device *dev, const char *target); int pwrseq_enable(struct pwrseq_desc *desc); int pwrseq_disable(struct pwrseq_desc *desc); +int pwrseq_get_state(struct pwrseq_desc *desc); struct device *pwrseq_to_device(struct pwrseq_desc *desc);
@@ -53,6 +60,11 @@ static inline int pwrseq_disable(struct pwrseq_desc *desc) return -ENOSYS; } +static inline int pwrseq_get_state(struct pwrseq_desc *desc) +{ + return -ENOSYS; +} + static inline struct device *pwrseq_to_device(struct pwrseq_desc *desc) { return NULL;
--
2.55.0.979.g7e5102b832-goog