[PATCH v5 11/12] powercap: arm_scmi: Add get_power_uw to synthetic node

Philip Radford
2026-04-28T09:10:06Z

Exposes the current power usage from the immediate children of
the synthetic (root) powercap node. Iterates over pr->spzones and
sums per-zone power.

Signed-off-by: Philip Radford <philip.radford@arm.com>
---
drivers/powercap/arm_scmi_powercap.c | 29 ++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c
index d74869af1633..81b5214acda4 100644
--- a/drivers/powercap/arm_scmi_powercap.c
+++ b/drivers/powercap/arm_scmi_powercap.c
@@ -270,9 +270,34 @@ static int instance_root_release(struct powercap_zone *pz)
return 0;
}

-static int instance_root_get_power_uw(struct powercap_zone *pz, u64 *v)
+static int instance_root_get_power_uw(struct powercap_zone *pz, u64 *power_uw)
{
- *v = 0;
+ struct scmi_powercap_zone *root = to_scmi_powercap_zone(pz);
+ struct scmi_powercap_zone *child;
+ struct scmi_powercap_root *pr;
+ u64 acc = 0;
+ u64 p;
+ int ret;
+
+ if (!pz || !power_uw)
+ return -EINVAL;
+
+ pr = container_of(root, struct scmi_powercap_root, instance_root);
+ if (!pr)
+ return -ENODEV;
+
+ list_for_each_entry(child, &pr->registered_zones[0], node) {
+ if (child == &pr->instance_root)
+ continue;
+
+ ret = scmi_powercap_get_power_uw(&child->zone, &p);
+ if (!ret)
+ acc += p;
+ else
+ dev_dbg(child->dev, "Failed to read child power: %u\n", ret);
+ }
+
+ *power_uw = acc;
return 0;
}

--
2.47.3