diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index b840db9b803a6..69d1015d1353c 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -1768,11 +1768,12 @@ static const struct dev_pm_ops apple_pmgr_ps_pm_ops = { }; /* - * All of the domain's consumers have probed (fw_devlink). A domain the boot loader left - * clock gated that no consumer has raised since, with no subdomain on and still clock - * gated, has nothing that uses it: power gate it, so the hardware matches what genpd - * holds. A consumer that took over its state raised it first; a domain whose consumer - * never probes stays as the boot loader left it. + * All of the domain's direct consumers have probed (fw_devlink). A leaf domain the boot + * loader left clock gated that no consumer has raised since and that is still clock gated + * has nothing that uses it: power gate it, so the hardware matches what genpd holds. + * Skip domains that have subdomains: fw_devlink calls sync_state on a parent as soon as + * its child apple-pmgr-pwrstate devices probe, before those subdomains' own consumers + * probe and while a child may still be left clock gated in hardware. */ static void apple_pmgr_ps_sync_state(struct device *dev) { @@ -1787,6 +1788,7 @@ static void apple_pmgr_ps_sync_state(struct device *dev) spin_lock_irqsave(&ps->genpd.slock, flags); ps->boot_clkgated = false; if (ps->genpd.status == GENPD_STATE_OFF && !atomic_read(&ps->genpd.sd_count) && + list_empty(&ps->genpd.parent_links) && !regmap_read(ps->regmap, ps->offset, ®) && FIELD_GET(APPLE_PMGR_PS_TARGET, reg) == APPLE_PMGR_PS_CLKGATE && FIELD_GET(APPLE_PMGR_PS_ACTUAL, reg) == APPLE_PMGR_PS_CLKGATE && diff --git a/tools/testing/selftests/drivers/apple/pmgr-inherited.py b/tools/testing/selftests/drivers/apple/pmgr-inherited.py index 77bc6a11afd20..54973a75ed0ca 100755 --- a/tools/testing/selftests/drivers/apple/pmgr-inherited.py +++ b/tools/testing/selftests/drivers/apple/pmgr-inherited.py @@ -79,11 +79,14 @@ def main(): struct platform_device { struct device dev; }; struct dev_pm_ops { int (*runtime_suspend)(struct device *); }; struct dev_pm_domain { struct dev_pm_ops ops; }; +struct list_head { struct list_head *next, *prev; }; +static inline bool list_empty(const struct list_head *h) { return h->next == h; } struct generic_pm_domain { struct dev_pm_domain domain; const char *name; unsigned flags, status, slock; int sd_count; + struct list_head parent_links; int (*power_on)(struct generic_pm_domain *), (*power_off)(struct generic_pm_domain *); }; struct of_phandle_args { struct device_node *np; int args_count, args[8]; }; @@ -166,7 +169,7 @@ def main(): #define regmap_read_poll_timeout_atomic(m,o,v,cond,delay,bound) \ (regmap_read(m,o,&v) ?: ((cond) ? 0 : -ETIMEDOUT)) static int pm_genpd_init(struct generic_pm_domain *g, void *gov, bool off) -{ (void)g; (void)gov; init_count++; initialized_off=off; return 0; } +{ (void)gov; g->parent_links.next=&g->parent_links; g->parent_links.prev=&g->parent_links; init_count++; initialized_off=off; return 0; } static int of_genpd_add_provider_simple(struct device_node *n, struct generic_pm_domain *g) { (void)n; (void)g; provider_count++; return 0; } static void pm_genpd_remove_device(struct device *d) { (void)d; } @@ -275,13 +278,15 @@ def main(): apple_pmgr_ps_sync_state(&pd); assert(genpd_sync_count==1 && map.writes==1 && !ps->boot_clkgated); apple_pmgr_ps_sync_state(&pd); assert(map.writes==1); - /* A consumer raised it, a subdomain is on, or it moved on since probe: left alone. */ - for (int c=0; c<3; c++) { + /* Consumer raised it, subdomain on, subdomain attached (off), or state moved: left alone. */ + for (int c=0; c<4; c++) { + struct list_head child_link; assert(!probe(&plain,0x44,0)); ps=driver_data; assert(ps->boot_clkgated); ps->genpd.status=GENPD_STATE_OFF; if (c==0) ps->genpd.status=1; if (c==1) ps->genpd.sd_count=1; if (c==2) map.value=0x4f; + if (c==3) { ps->genpd.parent_links.next=&child_link; child_link.prev=&ps->genpd.parent_links; } apple_pmgr_ps_sync_state(&pd); assert(!map.writes && !ps->boot_clkgated); }