[PATCH 2/3] PM / Domains: Choose the deepest state to enter if no devices using it

From: Peng Fan (OSS)
Date: Tue Sep 12 2023 - 22:01:22 EST


From: Dong Aisheng <aisheng.dong@xxxxxxx>

For a domain has no working devices anymore, let's choose the deepest state
to enter to save power. e.g. driver probe failure.

Signed-off-by: Dong Aisheng <aisheng.dong@xxxxxxx>
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
drivers/base/power/domain.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 22cfa3020b18..1887eb1b3130 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -730,6 +730,10 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
if (atomic_read(&genpd->sd_count) > 0)
return -EBUSY;

+ /* Choose the deepest state if no devices using this domain */
+ if (!genpd->device_count)
+ genpd->state_idx = genpd->state_count - 1;
+
ret = _genpd_power_off(genpd, true);
if (ret) {
genpd->states[genpd->state_idx].rejected++;

--
2.37.1