[PATCH v7 03/16] power: sequencing: Add pwrseq_get_state()
Chen-Yu Tsai
wenst at chromium.org
Fri Jul 24 01:43:12 PDT 2026
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 <bartosz.golaszewski at oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst at chromium.org>
---
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 02f42da91598..701728e60a26 100644
--- a/drivers/power/sequencing/core.c
+++ b/drivers/power/sequencing/core.c
@@ -968,6 +968,25 @@ int pwrseq_power_off(struct pwrseq_desc *desc)
}
EXPORT_SYMBOL_GPL(pwrseq_power_off);
+/**
+ * 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 3c907c9e1885..af949e756bbd 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_power_on(struct pwrseq_desc *desc);
int pwrseq_power_off(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_power_off(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.229.g6434b31f56-goog
More information about the Linux-mediatek
mailing list