dm: core: device: switch off power domain after device removal
PATCH 1/2 dm: core: device: switch off power domain after device removal
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 | 8 ++++++++ include/dm/device.h | 6 ++++++ 2 files changed, 14 insertions(+)
drivers/core/device-remove.c +8 -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) {
@@ -154,6 +155,7 @@ static bool flags_remove(uint flags, uint drv_flags)int device_remove (struct udevice *dev,uint flags) { +struct power_domain pd;const struct driver *drv;int ret;
@@ -192,6 +194,12 @@ int device_remove(struct udevice *dev, uint flags) } } +if (dev->parent &&device_get_uclass_id (dev) !=UCLASS_POWER_DOMAIN && + !(dev->flags &DM_FLAG_REMOVE_WITH_PD_ON )) { +if (!power_domain_get (dev, &pd)) +power_domain_off (&pd); + } +if (flags_remove (flags, drv->flags)) {device_free (dev);
include/dm/device.h +6 -0
@@ -61,6 +61,12 @@ struct driver_info;*/ #define DM_FLAG_OS_PREPARE (1 << 10) +/* +* Device is removed without switching off its power domain. This might +* be required, i. e. for serial console (debug) output when booting OS. +*/ +#define DM_FLAG_REMOVE_WITH_PD_ON (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.17.1
PATCH 2/2 serial: lpuart: request dm device removal when booting OS
Extend the driver to allow dm device removal, but always let the console serial device power domain enabled, so that U-Boot doesn't crash when i. e. the serial output is enabled for debugging.
--- drivers/serial/serial_lpuart.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/serial/serial_lpuart.c +9 -0
@@ -488,6 +488,13 @@ static int lpuart_serial_probe(struct udevice *dev)return _lpuart_serial_init (dev); } +static int lpuart_serial_remove (struct udevice *dev) +{ +if (dev == gd->cur_serial_dev) + dev->flags |=DM_FLAG_REMOVE_WITH_PD_ON ; +return 0 ; +} +static int lpuart_serial_ofdata_to_platdata (struct udevice *dev) {struct lpuart_serial_platdata *plat = dev->platdata;
@@ -539,5 +546,7 @@ U_BOOT_DRIVER(serial_lpuart) = { .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata, .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata), .probe = lpuart_serial_probe, + .remove = lpuart_serial_remove, .ops = &lpuart_serial_ops, + .flags = DM_FLAG_OS_PREPARE, };
Signature · 1 line
2.17.1
PATCH 1/2 dm: core: device: switch off power domain after device removal
In reply to Anatolij GustschinHi Anatolij,
Quoted 41 lines · Anatolij Gustschin
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.
Signed-off-by Anatolij Gustschin <[email protected]>--- drivers/core/device-remove.c | 8 ++++++++ include/dm/device.h | 6 ++++++ 2 files changed, 14 insertions(+)drivers/core/device-remove.c +2
-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) {@@ -154,6 +155,7 @@ static bool flags_remove(uint flags, uint drv_flags)int device_remove (struct udevice *dev,uint flags) { +struct power_domain pd;const struct driver *drv;int ret;
drivers/core/device-remove.c int device_remove(struct udevice *dev, uint flags) · line 197
Quoted 4 lines
drivers/core/device-remove.c +1
-0@@ -192,6 +194,12 @@ int device_remove(struct udevice *dev, uint flags) } } + if (dev->parent && device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN &&
Putting my code-size hat on, what do you think about adding an IF_ENABLED(POWER_DOMAIN) as the first arg?
Quoted 26 lines
drivers/core/device-remove.c +5
-0+ !(dev->flags & DM_FLAG_REMOVE_WITH_PD_ON)) { +if (!power_domain_get (dev, &pd)) +power_domain_off (&pd); + } +if (flags_remove (flags, drv->flags)) {device_free (dev);include/dm/device.h +6
-1@@ -61,6 +61,12 @@ struct driver_info;*/ #define DM_FLAG_OS_PREPARE (1 << 10) +/* +* Device is removed without switching off its power domain. This might +* be required, i. e. for serial console (debug) output when booting OS. +*/ +#define DM_FLAG_REMOVE_WITH_PD_ON (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 --
Quoted 2 lines
2.17.1
Regards,
Simon
PATCH 1/2 dm: core: device: switch off power domain after device removal
Hi Simon,
On Fri, 12 Jul 2019 15:05:06 -0600
Simon Glass sjg at chromium.org wrote:
...
Quoted 5 lines
Quoted 2 lines
+ if (
dev->parent&&device_get_uclass_id(dev)!=UCLASS_POWER_DOMAIN&&Putting my code-size hat on, what do you think about adding an
IF_ENABLED(POWER_DOMAIN)as the first arg?
Good point, I'll add it in v2 patch.
Thanks,
Anatolij