[PATCH RFC 06/16] pmdomain: core: Support indexed power-domain attachment lists
From: Konrad Dybcio
Date: Wed Oct 14 2026 - 08:26:09 EST
From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
dev_pm_domain_attach_list() can attach domains selected by name or attach
all domains listed for a device. Allow callers to select an explicit list
of power-domain indices as well, retaining the original DT indices for
the virtual attachments.
Assisted-by: LLM
Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
---
drivers/base/power/common.c | 24 +++++++++++++++++-------
include/linux/pm_domain.h | 8 +++++---
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 8beedde6dba7..6a2d8ee473cd 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -179,9 +179,9 @@ EXPORT_SYMBOL_GPL(dev_pm_domain_attach_by_name);
*
* This function helps to attach a device to its multiple PM domains. The
* caller, which is typically a driver's probe function, may provide a list of
- * names for the PM domains that we should try to attach the device to, but it
- * may also provide an empty list, in case the attach should be done for all of
- * the available PM domains.
+ * names or indices for the PM domains that we should try to attach the device
+ * to, but it may also provide an empty list, in case the attach should be done
+ * for all of the available PM domains.
*
* Callers must ensure proper synchronization of this function with power
* management callbacks.
@@ -211,9 +211,14 @@ int dev_pm_domain_attach_list(struct device *dev,
if (!np)
return 0;
+ if (data && data->pd_names && data->pd_indices)
+ return -EINVAL;
+
if (data && data->pd_names) {
num_pds = data->num_pd_names;
by_id = false;
+ } else if (data && data->pd_indices) {
+ num_pds = data->num_pd_indices;
} else {
num_pds = of_count_phandle_with_args(np, "power-domains",
"#power-domain-cells");
@@ -240,13 +245,18 @@ int dev_pm_domain_attach_list(struct device *dev,
link_flags |= DL_FLAG_RPM_ACTIVE;
for (i = 0; i < num_pds; i++) {
- if (by_id)
+ if (by_id) {
+ unsigned int pd_index = data && data->pd_indices ?
+ data->pd_indices[i] : i;
+
pd_dev = data && data->pd_suffix ?
- genpd_dev_pm_attach_by_id_suffix(dev, i, data->pd_suffix) :
- dev_pm_domain_attach_by_id(dev, i);
- else
+ genpd_dev_pm_attach_by_id_suffix(dev, pd_index,
+ data->pd_suffix) :
+ dev_pm_domain_attach_by_id(dev, pd_index);
+ } else {
pd_dev = dev_pm_domain_attach_by_name(dev,
data->pd_names[i]);
+ }
if (IS_ERR_OR_NULL(pd_dev)) {
ret = pd_dev ? PTR_ERR(pd_dev) : -ENODEV;
goto err_attach;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 322453da7fae..f5e340e32f48 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -32,9 +32,9 @@
*
* PD_FLAG_REQUIRED_OPP: Assign required_devs for the required OPPs. The
* index of the required OPP must correspond to the
- * index in the array of the pd_names. If pd_names
- * isn't specified, the index just follows the
- * index for the attached PM domain.
+ * index in the pd_names or pd_indices array. If neither
+ * is specified, the index just follows the index for the
+ * attached PM domain.
*
* PD_FLAG_ATTACH_POWER_ON: Power on the domain during attach.
*
@@ -50,6 +50,8 @@
struct dev_pm_domain_attach_data {
const char * const *pd_names;
u32 num_pd_names;
+ const unsigned int *pd_indices;
+ u32 num_pd_indices;
const char *pd_suffix;
u32 pd_flags;
};
--
2.56.0