Skip to contentSkip to conversation

pmdomain: imx8mp-blk-ctrl: set awake path for power_dev if attached device needs wakeup

PATCH In review Xu Yang 2 participants 5 messages Feb 2 – Feb 4

Subsystems (2)
lore
Share & tools
lore

Xu Yang

author
#0 lore raw

PATCH 1/2 pmdomain: imx8mp-blk-ctrl: set awake path for power_dev if attached device needs wakeup

Current design will power off all dependent GPC power domains in imx8mp_blk_ctrl_suspend(), even though the user device has enabled wakeup capability. The result is that wakeup function never works for such device.

An example will be USB wakeup on i.MX8MP. PHY device '382f0040.usb-phy' is attached to power domain 'hsioblk-usb-phy2' which is spawned by hsio block control. A virtual power domain device 'genpd:3:32f10000.blk-ctrl' is created to build connection with 'hsioblk-usb-phy2' and it depends on GPC power domain 'usb-otg2'. If device '382f0040.usb-phy' enable wakeup, only power domain 'hsioblk-usb-phy2' keeps on during system suspend, power domain 'usb-otg2' is off all the time. So the wakeup event can't happen.

Let's propagate wakeup path to virtual power domain device so the wakeup event can happen properly.

Fixes 556f5cf9568a ("soc: imx: add i.MX8MP HSIO blk-ctrl")
---
 drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/pmdomain/imx/imx8mp-blk-ctrl.c +8 -0
index 34576be606e3..f3bfd6d22722 100644
@@ -804,12 +804,20 @@ static int imx8mp_blk_ctrl_suspend(struct device *dev)
 
 	for (i = 0; i < bc->onecell_data.num_domains; i++) {
 		struct imx8mp_blk_ctrl_domain *domain = &bc->domains[i];
+		struct pm_domain_data *pdd;
 
 		ret = pm_runtime_get_sync(domain->power_dev);
 		if (ret < 0) {
 			pm_runtime_put_noidle(domain->power_dev);
 			goto out_fail;
 		}
+
+		list_for_each_entry(pdd, &domain->genpd.dev_list, list_node) {
+			if (device_awake_path(pdd->dev)) {
+				device_set_awake_path(domain->power_dev);
+				break;
+			}
+		}
 	}
 
 	return 0;
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/2 pmdomain: imx: gpcv2: keep usb phy power domain on for wakeup

USB remote wakeup need its PHY on, so add USB PHY power domain on active flag.

---
 drivers/pmdomain/imx/gpcv2.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pmdomain/imx/gpcv2.c +2 -0
index a829f8da5be7..5c66ee0a3731 100644
@@ -953,6 +953,7 @@ static const struct imx_pgc_domain imx8mp_pgc_domains[] = {
 	[IMX8MP_POWER_DOMAIN_USB1_PHY] = {
 		.genpd = {
 			.name = "usb-otg1",
+			.flags = GENPD_FLAG_ACTIVE_WAKEUP,
 		},
 		.bits = {
 			.pxx = IMX8MP_USB1_PHY_Pxx_REQ,
@@ -964,6 +965,7 @@ static const struct imx_pgc_domain imx8mp_pgc_domains[] = {
 	[IMX8MP_POWER_DOMAIN_USB2_PHY] = {
 		.genpd = {
 			.name = "usb-otg2",
+			.flags = GENPD_FLAG_ACTIVE_WAKEUP,
 		},
 		.bits = {
 			.pxx = IMX8MP_USB2_PHY_Pxx_REQ,
Signature · 1 line
2.34.1
#2 lore raw
In reply to Xu Yang
Quoted 37 lines · Xu Yang

Current design will power off all dependent GPC power domains in imx8mp_blk_ctrl_suspend(), even though the user device has enabled wakeup capability. The result is that wakeup function never works for such device.

An example will be USB wakeup on i.MX8MP. PHY device '382f0040.usb-phy' is attached to power domain 'hsioblk-usb-phy2' which is spawned by hsio block control. A virtual power domain device 'genpd:3:32f10000.blk-ctrl' is created to build connection with 'hsioblk-usb-phy2' and it depends on GPC power domain 'usb-otg2'. If device '382f0040.usb-phy' enable wakeup, only power domain 'hsioblk-usb-phy2' keeps on during system suspend, power domain 'usb-otg2' is off all the time. So the wakeup event can't happen.

Let's propagate wakeup path to virtual power domain device so the wakeup event can happen properly.

Fixes 556f5cf9568a ("soc: imx: add i.MX8MP HSIO blk-ctrl")
---
 drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/pmdomain/imx/imx8mp-blk-ctrl.c +1 -0
index 34576be606e3..f3bfd6d22722 100644
@@ -804,12 +804,20 @@ static int imx8mp_blk_ctrl_suspend(struct device *dev)
 
        for (i = 0; i < bc->onecell_data.num_domains; i++) {
                struct imx8mp_blk_ctrl_domain *domain = &bc->domains[i];
+               struct pm_domain_data *pdd;
 
                ret = pm_runtime_get_sync(domain->power_dev);
                if (ret < 0) {

drivers/pmdomain/imx/imx8mp-blk-ctrl.c static int imx8mp_blk_ctrl_suspend(struct device *dev) · line 820

Quoted 10 lines
drivers/pmdomain/imx/imx8mp-blk-ctrl.c +7 -0
                        pm_runtime_put_noidle(domain->power_dev);
                        goto out_fail;
                }
+
+               list_for_each_entry(pdd, &domain->genpd.dev_list, list_node) {
+                       if (device_awake_path(pdd->dev)) {
+                               device_set_awake_path(domain->power_dev);
+                               break;
+                       }
+               }

This is really messy in my opinion. Ideally the above should not be used by a genpd provider as it's internal data structures are managed by genpd itself.

If I understand correctly, this problem boils down to the fact that we should have tried harder to model child/parent domains, rather than using runtime PM to manage the parent domains. I understand there are problems with that, due to specific power on/off sequences we have for imx power-domains, but I wonder if those could be managed better by using genpd on/off notifiers?

Anyway, that said. Rather than walking through the list of devices as above, I suggest that you use the ->power_off() callback for the corresponding genpd(s) to dev in combination with a genpd power on/off notifier for the corresponding genpd that the power_dev is attached to.

More precisely, if the "child domain(s)" that corresponds to "dev" has not been powered-off (because device_awake_path() is set for some device) during system suspend, the power-off notifier should return NOTIFY_BAD to prevent the "parent domain" that corresponds to power_dev from being powered-off.

Would that work, you think?

Kind regards
Uffe

author
#3 lore raw
Quoted 13 lines · Ulf Hansson

drivers/pmdomain/imx/imx8mp-blk-ctrl.c static int imx8mp_blk_ctrl_suspend(struct device *dev) · line 820

Quoted 7 lines · Xu Yang
drivers/pmdomain/imx/imx8mp-blk-ctrl.c +7 -0
+
+               list_for_each_entry(pdd, &domain->genpd.dev_list, list_node) {
+                       if (device_awake_path(pdd->dev)) {
+                               device_set_awake_path(domain->power_dev);
+                               break;
+                       }
+               }

This is really messy in my opinion. Ideally the above should not be used by a genpd provider as it's internal data structures are managed by genpd itself.

Quoted 6 lines

If I understand correctly, this problem boils down to the fact that we should have tried harder to model child/parent domains, rather than using runtime PM to manage the parent domains. I understand there are problems with that, due to specific power on/off sequences we have for imx power-domains, but I wonder if those could be managed better by using genpd on/off notifiers?

Indeed. I have tried using subdomain will resolve the wakeup issue because the parent domain will manage the child domain. But I shouldn't use subdomain and runtime PM way together to avoid any unexpected behaviors according to my understanding.

Quoted 7 lines

Anyway, that said. Rather than walking through the list of devices as above, I suggest that you use the ->power_off() callback for the corresponding genpd(s) to dev in combination with a genpd power on/off notifier for the corresponding genpd that the power_dev is attached to.

Quoted 7 lines

More precisely, if the "child domain(s)" that corresponds to "dev" has not been powered-off (because device_awake_path() is set for some device) during system suspend, the power-off notifier should return NOTIFY_BAD to prevent the "parent domain" that corresponds to power_dev from being powered-off.

Would that work, you think?

Thank you for the suggestion. It works for me.

With this way the rejected count is increasing. Does this have any impact? The count is just used for statistics, right?

# cat /sys/kernel/debug/pm_genpd/usb-otg2/idle_states
State          Time Spent(ms) Usage      Rejected   Above      Below
S0             1203           0          1          0          0

Thanks,
Xu Yang

#4 lore raw
Quoted 22 lines · Xu Yang
Quoted 13 lines · Ulf Hansson

drivers/pmdomain/imx/imx8mp-blk-ctrl.c static int imx8mp_blk_ctrl_suspend(struct device *dev) · line 820

Quoted 7 lines · Xu Yang
drivers/pmdomain/imx/imx8mp-blk-ctrl.c +7 -0
+
+               list_for_each_entry(pdd, &domain->genpd.dev_list, list_node) {
+                       if (device_awake_path(pdd->dev)) {
+                               device_set_awake_path(domain->power_dev);
+                               break;
+                       }
+               }

This is really messy in my opinion. Ideally the above should not be used by a genpd provider as it's internal data structures are managed by genpd itself.

Quoted 6 lines

If I understand correctly, this problem boils down to the fact that we should have tried harder to model child/parent domains, rather than using runtime PM to manage the parent domains. I understand there are problems with that, due to specific power on/off sequences we have for imx power-domains, but I wonder if those could be managed better by using genpd on/off notifiers?

Quoted 4 lines

Indeed. I have tried using subdomain will resolve the wakeup issue because the parent domain will manage the child domain. But I shouldn't use subdomain and runtime PM way together to avoid any unexpected behaviors according to my understanding.

Well, there is nothing wrong with using child/parent domain in combination with runtime PM.

Although in general using runtime PM to manage parents domains from child domains, should be better managed by genpd itself.

Quoted 14 lines
Quoted 14 lines

Anyway, that said. Rather than walking through the list of devices as above, I suggest that you use the ->power_off() callback for the corresponding genpd(s) to dev in combination with a genpd power on/off notifier for the corresponding genpd that the power_dev is attached to.

More precisely, if the "child domain(s)" that corresponds to "dev" has not been powered-off (because device_awake_path() is set for some device) during system suspend, the power-off notifier should return NOTIFY_BAD to prevent the "parent domain" that corresponds to power_dev from being powered-off.

Quoted 3 lines
Quoted 1 line

Would that work, you think?

Thank you for the suggestion. It works for me.

Great!

Quoted 3 lines

With this way the rejected count is increasing. Does this have any impact? The count is just used for statistics, right?

Yes, it's used for statistics.

Quoted 7 lines
# cat /sys/kernel/debug/pm_genpd/usb-otg2/idle_states
State          Time Spent(ms) Usage      Rejected   Above      Below
S0             1203           0          1          0          0

Thanks,
Xu Yang

Kind regards
Uffe