pmdomain: imx8mp-blk-ctrl: set awake path for power_dev if attached device needs wakeup
Subsystems (2)
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.
--- drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/pmdomain/imx/imx8mp-blk-ctrl.c +8 -0
@@ -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
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
@@ -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
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")Signed-off-by Xu Yang <[email protected]>--- drivers/pmdomain/imx/imx8mp-blk-ctrl.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/pmdomain/imx/imx8mp-blk-ctrl.c +1
-0@@ -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
-0pm_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
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_devis 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 returnNOTIFY_BADto prevent the "parent domain" that corresponds topower_devfrom 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
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_devis 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 returnNOTIFY_BADto prevent the "parent domain" that corresponds topower_devfrom 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 0Thanks,
Xu Yang
Kind regards
Uffe