dm: core: Add support for controlled power domain handling
cover 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(-)
Signature · 1 line
2.23.0
PATCH 1/4 dm: core: Allow for not controlling the power-domain by DM framework
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.
--- drivers/core/device.c | 3 ++- include/dm/device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/core/device.c +2 -1
@@ -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;
include/dm/device.h +3 -0
@@ -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
Signature · 1 line
2.23.0
PATCH 1/4 dm: core: Allow for not controlling the power-domain by DM framework
Hi Lokesh,
Quoted 7 lines · Lokesh Vutla
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.
Quoted 8 lines
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 <[email protected]>--- drivers/core/device.c | 3 ++- include/dm/device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
PATCH 1/4 dm: core: Allow for not controlling the power-domain by DM framework
Hi Lokesh,
Quoted 7 lines · Lokesh Vutla
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.
Quoted 8 lines
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 <[email protected]>--- drivers/core/device.c | 3 ++- include/dm/device.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH 2/4 remoteproc: k3_arm64: Enable DM_FLAG_DEFAULT_PD_CTRL_OFF
In reply to Lokesh VutlaEnable DM_FLAG_DEFAULT_PD_CTRL_OFF for arm64 remote core so that pd can be enabled after loading the image.
--- drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + 1 file changed, 1 insertion(+)
drivers/remoteproc/ti_k3_arm64_rproc.c +1 -0
@@ -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, };
Signature · 1 line
2.23.0
PATCH 2/4 remoteproc: k3_arm64: Enable DM_FLAG_DEFAULT_PD_CTRL_OFF
Quoted 8 lines · Lokesh Vutla
Enable
DM_FLAG_DEFAULT_PD_CTRL_OFFfor arm64 remote core so that pd can be enabled after loading the image.Signed-off-by Lokesh Vutla <[email protected]>--- drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + 1 file changed, 1 insertion(+)
PATCH 2/4 remoteproc: k3_arm64: Enable DM_FLAG_DEFAULT_PD_CTRL_OFF
Quoted 8 lines · Lokesh Vutla
Enable
DM_FLAG_DEFAULT_PD_CTRL_OFFfor arm64 remote core so that pd can be enabled after loading the image.Signed-off-by Lokesh Vutla <[email protected]>--- drivers/remoteproc/ti_k3_arm64_rproc.c | 1 + 1 file changed, 1 insertion(+)
Applied to u-boot-dm, thanks!
PATCH 3/4 power: domain: Introduce dev_power_domain_off
In reply to Lokesh VutlaAdd dev_power_domain_off() api to disable all the power-domains corresponding to a device
--- drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- include/power-domain.h | 17 +++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-)
drivers/power/domain/power-domain-uclass.c +27 -7
@@ -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
include/power-domain.h +17 -0
@@ -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
Signature · 1 line
2.23.0
PATCH 3/4 power: domain: Introduce dev_power_domain_off
Quoted 9 lines · Lokesh Vutla
Add
dev_power_domain_off()api to disable all the power-domains corresponding to a deviceSigned-off-by Lokesh Vutla <[email protected]>--- drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- include/power-domain.h | 17 +++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-)
PATCH 3/4 power: domain: Introduce dev_power_domain_off
Quoted 9 lines · Lokesh Vutla
Add
dev_power_domain_off()api to disable all the power-domains corresponding to a deviceSigned-off-by Lokesh Vutla <[email protected]>--- drivers/power/domain/power-domain-uclass.c | 34 +++++++++++++++++----- include/power-domain.h | 17 +++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 4/4 dm: core: device: switch off power domain after device removal
In reply to Lokesh VutlaFrom: Anatolij Gustschin <[email protected]>
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.
--- drivers/core/device-remove.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/core/device-remove.c +5 -0
@@ -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);
Signature · 1 line
2.23.0
PATCH 4/4 dm: core: device: switch off power domain after device removal
Quoted 16 lines · Lokesh Vutla
From: Anatolij Gustschin <[email protected]>
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 ofdm_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.
Quoted 5 lines
Signed-off-by Anatolij Gustschin <[email protected]>Signed-off-by Lokesh Vutla <[email protected]>--- drivers/core/device-remove.c | 5 +++++ 1 file changed, 5 insertions(+)
PATCH 4/4 dm: core: device: switch off power domain after device removal
Quoted 16 lines · Lokesh Vutla
From: Anatolij Gustschin <[email protected]>
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 ofdm_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.
Quoted 5 lines
Signed-off-by Anatolij Gustschin <[email protected]>Signed-off-by Lokesh Vutla <[email protected]>--- drivers/core/device-remove.c | 5 +++++ 1 file changed, 5 insertions(+)
Applied to u-boot-dm, thanks!