[U-Boot] [PATCH 0/4] dm: core: Add support for controlled power domain handling

This series introduces a flag to disable pd control by DM framework. And disbables the power domain during device removal.
Depends on: https://patchwork.ozlabs.org/project/uboot/list/?series=132841
Anatolij Gustschin (1): dm: core: device: switch off power domain after device removal
Lokesh Vutla (3): dm: core: Allow for not controlling the power-domain by DM framework remoteproc: k3_arm64: Enable DM_FLAG_DEFAULT_PD_CTRL_OFF power: domain: Introduce dev_power_domain_off
drivers/core/device-remove.c | 5 ++++ drivers/core/device.c | 3 +- drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + include/dm/device.h | 3 ++ include/power-domain.h | 17 +++++++++++ 6 files changed, 55 insertions(+), 8 deletions(-)

In some remoteproc cases, enabling the power domain of the core will start running the core. In such cases image should be loaded before enabling the power domain. But the current DM framework enables the power-domain by default during probe. This is causing the remotecore to start and crash as there is no valid image loaded.
In order to avoid this introduce a DM flag that doesn't allow for enabling/disabling the power-domain by DM framework.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com --- drivers/core/device.c | 3 ++- include/dm/device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/core/device.c b/drivers/core/device.c index f4d7140698..91f80edc8d 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -388,7 +388,8 @@ int device_probe(struct udevice *dev) pinctrl_select_state(dev, "default");
if (CONFIG_IS_ENABLED(POWER_DOMAIN) && dev->parent && - device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN) { + (device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN) && + !(drv->flags & DM_FLAG_DEFAULT_PD_CTRL_OFF)) { ret = dev_power_domain_on(dev); if (ret) goto fail; diff --git a/include/dm/device.h b/include/dm/device.h index 27a6d7b9fd..f51f9b71da 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -61,6 +61,9 @@ struct driver_info; */ #define DM_FLAG_OS_PREPARE (1 << 10)
+/* DM does not enable/disable the power domains corresponding to this device */ +#define DM_FLAG_DEFAULT_PD_CTRL_OFF (1 << 11) + /* * One or multiple of these flags are passed to device_remove() so that * a selective device removal as specified by the remove-stage and the

Hi Lokesh,
On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
In some remoteproc cases, enabling the power domain of the core will start running the core. In such cases image should be loaded before enabling the power domain. But the current DM framework enables the power-domain by default during probe. This is causing the remotecore to start and crash as there is no valid image loaded.
In order to avoid this introduce a DM flag that doesn't allow for enabling/disabling the power-domain by DM framework.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/core/device.c | 3 ++- include/dm/device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

Hi Lokesh,
On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
In some remoteproc cases, enabling the power domain of the core will start running the core. In such cases image should be loaded before enabling the power domain. But the current DM framework enables the power-domain by default during probe. This is causing the remotecore to start and crash as there is no valid image loaded.
In order to avoid this introduce a DM flag that doesn't allow for enabling/disabling the power-domain by DM framework.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/core/device.c | 3 ++- include/dm/device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!

Enable DM_FLAG_DEFAULT_PD_CTRL_OFF for arm64 remote core so that pd can be enabled after loading the image.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com --- drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/remoteproc/ti_k3_arm64_rproc.c b/drivers/remoteproc/ti_k3_arm64_rproc.c index 9676a96f98..3e35293514 100644 --- a/drivers/remoteproc/ti_k3_arm64_rproc.c +++ b/drivers/remoteproc/ti_k3_arm64_rproc.c @@ -225,4 +225,5 @@ U_BOOT_DRIVER(k3_arm64) = { .ops = &k3_arm64_ops, .probe = k3_arm64_probe, .priv_auto_alloc_size = sizeof(struct k3_arm64_privdata), + .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF, };

On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
Enable DM_FLAG_DEFAULT_PD_CTRL_OFF for arm64 remote core so that pd can be enabled after loading the image.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
Enable DM_FLAG_DEFAULT_PD_CTRL_OFF for arm64 remote core so that pd can be enabled after loading the image.
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!

Add dev_power_domain_off() api to disable all the power-domains corresponding to a device
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com --- drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- include/power-domain.h | 17 +++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/drivers/power/domain/power-domain-uclass.c b/drivers/power/domain/power-domain-uclass.c index 6eb4267de3..80df5aff50 100644 --- a/drivers/power/domain/power-domain-uclass.c +++ b/drivers/power/domain/power-domain-uclass.c @@ -7,6 +7,7 @@ #include <dm.h> #include <power-domain.h> #include <power-domain-uclass.h> +#include <dm/device-internal.h>
static inline struct power_domain_ops *power_domain_dev_ops(struct udevice *dev) { @@ -107,12 +108,11 @@ int power_domain_off(struct power_domain *power_domain) return ops->off(power_domain); }
- #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) -int dev_power_domain_on(struct udevice *dev) +static int dev_power_domain_ctrl(struct udevice *dev, bool on) { struct power_domain pd; - int i, count, ret; + int i, count, ret = 0;
count = dev_count_phandle_with_args(dev, "power-domains", "#power-domain-cells"); @@ -120,12 +120,32 @@ int dev_power_domain_on(struct udevice *dev) ret = power_domain_get_by_index(dev, &pd, i); if (ret) return ret; - ret = power_domain_on(&pd); - if (ret) - return ret; + if (on) + ret = power_domain_on(&pd); + else + ret = power_domain_off(&pd); }
- return 0; + /* + * power_domain_get() bound the device, thus + * we must remove it again to prevent unbinding + * active devices (which would result in unbind + * error). + */ + if (count > 0 && !on) + device_remove(pd.dev, DM_REMOVE_NORMAL); + + return ret; +} + +int dev_power_domain_on(struct udevice *dev) +{ + return dev_power_domain_ctrl(dev, true); +} + +int dev_power_domain_off(struct udevice *dev) +{ + return dev_power_domain_ctrl(dev, false); } #endif
diff --git a/include/power-domain.h b/include/power-domain.h index 490fedbb12..72ff2ff25b 100644 --- a/include/power-domain.h +++ b/include/power-domain.h @@ -172,4 +172,21 @@ static inline int dev_power_domain_on(struct udevice *dev) } #endif
+/** + * dev_power_domain_off - Disable power domains for a device . + * + * @dev: The client device. + * + * @return 0 if OK, or a negative error code. + */ +#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \ + CONFIG_IS_ENABLED(POWER_DOMAIN) +int dev_power_domain_off(struct udevice *dev); +#else +static inline int dev_power_domain_off(struct udevice *dev) +{ + return 0; +} +#endif + #endif

On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
Add dev_power_domain_off() api to disable all the power-domains corresponding to a device
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- include/power-domain.h | 17 +++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
Add dev_power_domain_off() api to disable all the power-domains corresponding to a device
Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- include/power-domain.h | 17 +++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!

From: Anatolij Gustschin agust@denx.de
The power domain associated with a device is enabled when probing, but currently the domain remains enabled when the device is removed. Some boards started to disable power domains for selected devices via custom board_quiesce_devices(), but it doesn't work in many cases, i. e. because devices still can be accessed later in .remove() callback on behalf of dm_remove_devices_flags().
Utilize the DM core to power off the device power domain, but add a device flag to be able to selectively let the power domain enabled after device removal. This might be required for devices that must remain enabled when booting OS, i. e. serial console for debug output, etc.
Signed-off-by: Anatolij Gustschin agust@denx.de Signed-off-by: Lokesh Vutla lokeshvutla@ti.com --- drivers/core/device-remove.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 586fadee0a..5c8dc4ad70 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -16,6 +16,7 @@ #include <dm/uclass.h> #include <dm/uclass-internal.h> #include <dm/util.h> +#include <power-domain.h>
int device_chld_unbind(struct udevice *dev, struct driver *drv) { @@ -192,6 +193,10 @@ int device_remove(struct udevice *dev, uint flags) } }
+ if (!(drv->flags & DM_FLAG_DEFAULT_PD_CTRL_OFF) && + (dev != gd->cur_serial_dev)) + dev_power_domain_off(dev); + if (flags_remove(flags, drv->flags)) { device_free(dev);

On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
From: Anatolij Gustschin agust@denx.de
The power domain associated with a device is enabled when probing, but currently the domain remains enabled when the device is removed. Some boards started to disable power domains for selected devices via custom board_quiesce_devices(), but it doesn't work in many cases, i. e. because devices still can be accessed later in .remove() callback on behalf of dm_remove_devices_flags().
Utilize the DM core to power off the device power domain, but add a device flag to be able to selectively let the power domain enabled after device removal. This might be required for devices that must remain enabled when booting OS, i. e. serial console for debug output, etc.
Signed-off-by: Anatolij Gustschin agust@denx.de Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/core/device-remove.c | 5 +++++ 1 file changed, 5 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, 27 Sep 2019 at 02:19, Lokesh Vutla lokeshvutla@ti.com wrote:
From: Anatolij Gustschin agust@denx.de
The power domain associated with a device is enabled when probing, but currently the domain remains enabled when the device is removed. Some boards started to disable power domains for selected devices via custom board_quiesce_devices(), but it doesn't work in many cases, i. e. because devices still can be accessed later in .remove() callback on behalf of dm_remove_devices_flags().
Utilize the DM core to power off the device power domain, but add a device flag to be able to selectively let the power domain enabled after device removal. This might be required for devices that must remain enabled when booting OS, i. e. serial console for debug output, etc.
Signed-off-by: Anatolij Gustschin agust@denx.de Signed-off-by: Lokesh Vutla lokeshvutla@ti.com
drivers/core/device-remove.c | 5 +++++ 1 file changed, 5 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!
participants (3)
-
Lokesh Vutla
-
Simon Glass
-
sjg@google.com