pmdomain:rockchip: Fix init genpd as GENPD_STATE_ON before regulator ready
Subsystems (2)
PATCH 1/1 pmdomain:rockchip: Fix init genpd as GENPD_STATE_ON before regulator ready
RK3588_PD_NPU initialize as GENPD_STATE_ON before regulator ready. rknn_iommu initlized success and suspend RK3588_PD_NPU. When rocket driver register, it will resume rknn_iommu.
If regulator is still not ready at this point, rknn_iommu resume fail, pm runtime status will be error: -EPROBE_DEFER.
This patch check regulator when pmdomain init, if regulator is not ready or not enabled, power off pmdomain. Consumer device can power on it's pmdomain after regulator ready
--- drivers/pmdomain/rockchip/pm-domains.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/pmdomain/rockchip/pm-domains.c +14 -0
@@ -659,6 +659,11 @@ static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on)return ret; } +static bool rockchip_pd_regulator_is_enabled (struct rockchip_pm_domain *pd) +{ +return IS_ERR_OR_NULL (pd->supply) ? false :regulator_is_enabled (pd->supply); +} +static int rockchip_pd_regulator_disable (struct rockchip_pm_domain *pd) {return IS_ERR_OR_NULL (pd->supply) ?0 :regulator_disable (pd->supply);
@@ -861,6 +866,15 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->genpd.name = pd->info->name; else pd->genpd.name = kbasename(node->full_name); + +if (pd->info->need_regulator) { +if (IS_ERR_OR_NULL (pd->supply)) + pd->supply =devm_of_regulator_get (pmu->dev, pd->node,"domain" ); + +if (!rockchip_pd_regulator_is_enabled (pd)) +rockchip_pd_power (pd, false); + } + pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev;
Quoted 39 lines · Frank Zhang
RK3588_PD_NPUinitialize asGENPD_STATE_ONbefore regulator ready.rknn_iommuinitlized success and suspendRK3588_PD_NPU. When rocket driver register, it will resumerknn_iommu.If regulator is still not ready at this point,
rknn_iommuresume fail, pm runtime status will be error: -EPROBE_DEFER.This patch check regulator when pmdomain init, if regulator is not ready or not enabled, power off pmdomain. Consumer device can power on it's pmdomain after regulator ready
Signed-off-by Frank Zhang <[email protected]>--- drivers/pmdomain/rockchip/pm-domains.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/pmdomain/rockchip/pm-domains.c +7
-0@@ -659,6 +659,11 @@ static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on)return ret; } +static bool rockchip_pd_regulator_is_enabled (struct rockchip_pm_domain *pd) +{ +return IS_ERR_OR_NULL (pd->supply) ? false :regulator_is_enabled (pd->supply); +} +static int rockchip_pd_regulator_disable (struct rockchip_pm_domain *pd) {return IS_ERR_OR_NULL (pd->supply) ?0 :regulator_disable (pd->supply);@@ -861,6 +866,15 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->genpd.name = pd->info->name; else pd->genpd.name = kbasename(node->full_name); + +if (pd->info->need_regulator) {
drivers/pmdomain/rockchip/pm-domains.c static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, · line 880
Quoted 10 lines
drivers/pmdomain/rockchip/pm-domains.c +7
-0+if (IS_ERR_OR_NULL (pd->supply)) + pd->supply =devm_of_regulator_get (pmu->dev, pd->node,"domain" ); + +if (!rockchip_pd_regulator_is_enabled (pd)) +rockchip_pd_power (pd, false); + } + pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev;
@Quentin, Could you please try this patch? This should resolve the problem you're currently facing where the NPU fails to work in built-in module.
Signature · 2 lines
Best, Chaoyi
Quentin Schulz
Tested-byHi Chaoyi, Frank,
Quoted 46 lines · Chaoyi Chen
Quoted 45 lines · Frank Zhang
RK3588_PD_NPUinitialize asGENPD_STATE_ONbefore regulator ready.rknn_iommuinitlized success and suspendRK3588_PD_NPU. When rocket driver register, it will resumerknn_iommu.If regulator is still not ready at this point,
rknn_iommuresume fail, pm runtime status will be error: -EPROBE_DEFER.This patch check regulator when pmdomain init, if regulator is not ready or not enabled, power off pmdomain. Consumer device can power on it's pmdomain after regulator ready
Signed-off-by Frank Zhang <[email protected]>--- drivers/pmdomain/rockchip/pm-domains.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/pmdomain/rockchip/pm-domains.c +14
-0@@ -659,6 +659,11 @@ static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on)return ret; } +static bool rockchip_pd_regulator_is_enabled (struct rockchip_pm_domain *pd) +{ +return IS_ERR_OR_NULL (pd->supply) ? false :regulator_is_enabled (pd->supply); +} +static int rockchip_pd_regulator_disable (struct rockchip_pm_domain *pd) {return IS_ERR_OR_NULL (pd->supply) ?0 :regulator_disable (pd->supply);@@ -861,6 +866,15 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->genpd.name = pd->info->name; else pd->genpd.name = kbasename(node->full_name); + +if (pd->info->need_regulator) { +if (IS_ERR_OR_NULL (pd->supply)) + pd->supply =devm_of_regulator_get (pmu->dev, pd->node,"domain" ); + +if (!rockchip_pd_regulator_is_enabled (pd)) +rockchip_pd_power (pd, false); + } +
Quoted 9 lines
drivers/pmdomain/rockchip/pm-domains.c static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, · line 880
Quoted 4 lines
drivers/pmdomain/rockchip/pm-domains.c +0
-0pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev;@Quentin, Could you please try this patch? This should resolve the problem you're currently facing where the NPU fails to work in built-in module.
Thanks for the heads up, Chaoyi!
I tested that for a few hours with a bootloop script (700+) and seems like I couldn't reproduce the issue 4 reported in https://lore.kernel.org/linux-rockchip/[email protected]/ when building wih DRM_ACCEL_ROCKET=y.
So:
@Frank, please add me in Cc if there's a v2 so I can recheck if you want.
Thanks for having a look!
Cheers,
Quentin
Hi,
Quoted 34 lines · Frank Zhang
RK3588_PD_NPUinitialize asGENPD_STATE_ONbefore regulator ready.rknn_iommuinitlized success and suspendRK3588_PD_NPU. When rocket driver register, it will resumerknn_iommu.If regulator is still not ready at this point,
rknn_iommuresume fail, pm runtime status will be error: -EPROBE_DEFER.This patch check regulator when pmdomain init, if regulator is not ready or not enabled, power off pmdomain. Consumer device can power on it's pmdomain after regulator ready
Signed-off-by Frank Zhang <[email protected]>--- drivers/pmdomain/rockchip/pm-domains.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/pmdomain/rockchip/pm-domains.c +5
-0@@ -659,6 +659,11 @@ static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on)return ret; } +static bool rockchip_pd_regulator_is_enabled (struct rockchip_pm_domain *pd) +{ +return IS_ERR_OR_NULL (pd->supply) ? false :regulator_is_enabled (pd->supply); +} +static int rockchip_pd_regulator_disable (struct rockchip_pm_domain *pd) {return IS_ERR_OR_NULL (pd->supply) ?0 :regulator_disable (pd->supply);@@ -861,6 +866,15 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->genpd.name = pd->info->name;
drivers/pmdomain/rockchip/pm-domains.c static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, · line 876
Quoted 10 lines
drivers/pmdomain/rockchip/pm-domains.c +8
-0else pd->genpd.name =kbasename (node->full_name); + +if (pd->info->need_regulator) { +if (IS_ERR_OR_NULL (pd->supply)) + pd->supply =devm_of_regulator_get (pmu->dev, pd->node,"domain" ); + +if (!rockchip_pd_regulator_is_enabled (pd)) +rockchip_pd_power (pd, false); + }
It is extremly unlikely, that you will be able to get the regulator at driver probe time. The typical regulator for NPU or GPU is connected via SPI or I2C, which will only be available after the power domain driver has been probed. So I suppose this could be simplified as:
--------------------------------------------
/*
* power domain's needing a regulator should default to off, since
* the regulator state is unknown at probe time. Also the regulator
* state cannot be checked, since that usually requires IP needing
* (a different) power domain.
*/
if (pd->info->need_regulator)
rockchip_pd_power(pd, false);
--------------------------------------------
I think the proper fix would be to add support for registering the regulator needing power-domain's delayed and then enforce requesting the regulator at probe time. That's not trivial to implement, though.
Greetings,
-- Sebastian
Quoted 4 lines
drivers/pmdomain/rockchip/pm-domains.c +1
-0+ pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev;
Quoted 64 lines
Hi,
Quoted 35 lines · Frank Zhang
RK3588_PD_NPUinitialize asGENPD_STATE_ONbefore regulator ready.rknn_iommuinitlized success and suspendRK3588_PD_NPU. When rocket driver register, it will resumerknn_iommu.If regulator is still not ready at this point,
rknn_iommuresume fail, pm runtime status will be error: -EPROBE_DEFER.This patch check regulator when pmdomain init, if regulator is not ready or not enabled, power off pmdomain. Consumer device can power on it's pmdomain after regulator ready
Signed-off-by Frank Zhang <[email protected]>--- drivers/pmdomain/rockchip/pm-domains.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/pmdomain/rockchip/pm-domains.c +5
-0@@ -659,6 +659,11 @@ static int rockchip_pd_power(struct rockchip_pm_domain *pd, bool power_on)return ret; } +static bool rockchip_pd_regulator_is_enabled (struct rockchip_pm_domain *pd) +{ +return IS_ERR_OR_NULL (pd->supply) ? false :regulator_is_enabled (pd->supply); +} +static int rockchip_pd_regulator_disable (struct rockchip_pm_domain *pd) {return IS_ERR_OR_NULL (pd->supply) ?0 :regulator_disable (pd->supply);@@ -861,6 +866,15 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->genpd.name = pd->info->name;drivers/pmdomain/rockchip/pm-domains.c static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, · line 876
Quoted 10 lines
drivers/pmdomain/rockchip/pm-domains.c +8
-0else pd->genpd.name =kbasename (node->full_name); + +if (pd->info->need_regulator) { +if (IS_ERR_OR_NULL (pd->supply)) + pd->supply =devm_of_regulator_get (pmu->dev, pd->node,"domain" ); + +if (!rockchip_pd_regulator_is_enabled (pd)) +rockchip_pd_power (pd, false); + }It is extremly unlikely, that you will be able to get the regulator at driver probe time. The typical regulator for NPU or GPU is connected via SPI or I2C, which will only be available after the power domain driver has been probed. So I suppose this could be simplified as:
--------------------------------------------
/*
* power domain's needing a regulator should default to off, since
* the regulator state is unknown at probe time. Also the regulator
* state cannot be checked, since that usually requires IP needing
* (a different) power domain.
*/
if (pd->info->need_regulator)
rockchip_pd_power(pd, false);
--------------------------------------------
Quoted 12 lines
I think the proper fix would be to add support for registering the regulator needing power-domain's delayed and then enforce requesting the regulator at probe time. That's not trivial to implement, though.
Greetings,
-- Sebastian
Quoted 4 lines
drivers/pmdomain/rockchip/pm-domains.c +1
-0+ pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev;
Thanks for your comment. This simplification is OK for me. I will test and send new patch.