Improved sysreset/watchdog uclass integration
cover Improved sysreset/watchdog uclass integration
This series hooks up the watchdog uclass to automatically register the first watchdog device for use with sysreset, doing a bit of minor cleanup along the way.
The goal is for this to replace the sunxi board-level non-DM reset_cpu() function. I was surprised to find that the wdt_reboot driver requires its own undocumented device tree node, which references the watchdog device by phandle. This is problematic for us, because sunxi-u-boot.dtsi file covers 20 different SoCs with varying watchdog node phandle names. So it would have required adding a -u-boot.dtsi file for each board.
Hooking things up automatically makes sense to me; this is what Linux does. (In fact, Linux does this for every watchdog device.) However, I put the code behind a new option to avoid surprises for other platforms.
Samuel Holland (4):
sysreset: Add uclass Kconfig dependency to drivers
sysreset: Mark driver probe functions as static
sysreset: watchdog: Move watchdog reference to plat data
watchdog: Automatically register device with sysreset
drivers/sysreset/Kconfig | 11 ++++++-- drivers/sysreset/sysreset_resetctl.c | 2 +- drivers/sysreset/sysreset_syscon.c | 2 +- drivers/sysreset/sysreset_watchdog.c | 40 ++++++++++++++++++++++------ drivers/watchdog/wdt-uclass.c | 5 ++++ include/sysreset.h | 14 ++++++++++ 6 files changed, 62 insertions(+), 12 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/4 sysreset: Add uclass Kconfig dependency to drivers
The drivers enabled by SYSRESET_SYSCON, SYSRESET_WATCHDOG, and SYSRESET_RESETCTL do nothing beyond providing sysreset uclass ops. Therefore, they should depend on the sysreset uclass.
---
drivers/sysreset/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/sysreset/Kconfig +2 -2
@@ -106,8 +106,6 @@ config SYSRESET_TI_SCI This enables the system reset driver support over TI System Control Interface available on some new TI's SoCs. -endif - config SYSRESET_SYSCON bool "Enable support for mfd syscon reboot driver" select REGMAP
@@ -127,6 +125,8 @@ config SYSRESET_RESETCTL help Reboot support using generic reset controller. +endif + config SYSRESET_X86 bool "Enable support for x86 processor reboot driver" depends on X86
Signature · 1 line
2.31.1
Re: [PATCH 1/4] sysreset: Add uclass Kconfig dependency to drivers
Quoted 24 lines · Samuel Holland
The drivers enabled by
SYSRESET_SYSCON,SYSRESET_WATCHDOG, andSYSRESET_RESETCTLdo nothing beyond providing sysreset uclass ops. Therefore, they should depend on the sysreset uclass.Signed-off-by Samuel Holland <[email protected]>---
drivers/sysreset/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/sysreset/Kconfig +0
-2@@ -106,8 +106,6 @@ config SYSRESET_TI_SCI This enables the system reset driver support over TI System Control Interface available on some new TI's SoCs. -endif - config SYSRESET_SYSCON bool "Enable support for mfd syscon reboot driver" select REGMAP
drivers/sysreset/Kconfig config SYSRESET_RESETCTL · line 129
Quoted 5 lines
drivers/sysreset/Kconfig +2
-0@@ -127,6 +125,8 @@ config SYSRESET_RESETCTL help Reboot support using generic reset controller. +endif +
All sysreset drivers in directory drivers/sysreset/ require sysreset-uclass.o. Please, move this endif to the very end of the Kconfig file.
Best regards
Heinrich
Quoted 4 lines
drivers/sysreset/Kconfig +0
-0config SYSRESET_X86 bool "Enable support for x86 processor reboot driver" depends on X86
PATCH 2/4 sysreset: Mark driver probe functions as static
In reply to Samuel HollandThese driver probe functions are not (and should not be) called from outside the respective driver source files. Therefore, the functions should be marked static.
---
drivers/sysreset/sysreset_resetctl.c | 2 +- drivers/sysreset/sysreset_syscon.c | 2 +- drivers/sysreset/sysreset_watchdog.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/sysreset/sysreset_resetctl.c +1 -1
@@ -26,7 +26,7 @@ static struct sysreset_ops resetctl_reboot_ops = { .request = resetctl_reboot_request, }; -int resetctl_reboot_probe (struct udevice *dev) +static int resetctl_reboot_probe (struct udevice *dev) {struct resetctl_reboot_priv *priv =dev_get_priv (dev);
drivers/sysreset/sysreset_syscon.c +1 -1
@@ -39,7 +39,7 @@ static struct sysreset_ops syscon_reboot_ops = { .request = syscon_reboot_request, }; -int syscon_reboot_probe (struct udevice *dev) +static int syscon_reboot_probe (struct udevice *dev) {struct syscon_reboot_priv *priv =dev_get_priv (dev);int err;
drivers/sysreset/sysreset_watchdog.c +1 -1
@@ -29,7 +29,7 @@ static struct sysreset_ops wdt_reboot_ops = { .request = wdt_reboot_request, }; -int wdt_reboot_probe (struct udevice *dev) +static int wdt_reboot_probe (struct udevice *dev) {struct wdt_reboot_priv *priv =dev_get_priv (dev);int err;
Signature · 1 line
2.31.1
Re: [PATCH 2/4] sysreset: Mark driver probe functions as static
Quoted 5 lines · Samuel Holland
These driver probe functions are not (and should not be) called from outside the respective driver source files. Therefore, the functions should be marked static.
Signed-off-by Samuel Holland <[email protected]>
Reviewed by: Heinrich Schuchardt <[email protected]>
PATCH 3/4 sysreset: watchdog: Move watchdog reference to plat data
In reply to Samuel HollandCurrently, the wdt_reboot driver always gets its watchdog device reference from an OF node. This prevents selecting a watchdog at runtime. Move the watchdog device reference to the plat data, so the driver can be bound with the reference pre-provided. The reference will still be acquired from the OF node if it is not already provided.
---
drivers/sysreset/sysreset_watchdog.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/sysreset/sysreset_watchdog.c +8 -8
@@ -9,16 +9,16 @@#include <sysreset.h> #include <wdt.h> -struct wdt_reboot_priv { +struct wdt_reboot_plat {struct udevice *wdt; };static int wdt_reboot_request (struct udevice *dev,enum sysreset_t type) { -struct wdt_reboot_priv *priv =dev_get_priv (dev); +struct wdt_reboot_plat *plat =dev_get_plat (dev);int ret; - ret =wdt_expire_now (priv->wdt,0 ); + ret =wdt_expire_now (plat->wdt,0 );if (ret)return ret;
@@ -29,13 +29,13 @@ static struct sysreset_ops wdt_reboot_ops = { .request = wdt_reboot_request, }; -static int wdt_reboot_probe (struct udevice *dev) +static int wdt_reboot_of_to_plat (struct udevice *dev) { -struct wdt_reboot_priv *priv =dev_get_priv (dev); +struct wdt_reboot_plat *plat =dev_get_plat (dev);int err; err =uclass_get_device_by_phandle (UCLASS_WDT , dev, -"wdt" , &priv->wdt); +"wdt" , &plat->wdt);if (err) {pr_err ("unable to find wdt device\n" );return err;
@@ -53,7 +53,7 @@ U_BOOT_DRIVER(wdt_reboot) = { .name = "wdt_reboot", .id = UCLASS_SYSRESET, .of_match = wdt_reboot_ids, + .of_to_plat = wdt_reboot_of_to_plat, + .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, - .priv_auto = sizeof(struct wdt_reboot_priv), - .probe = wdt_reboot_probe, };
Signature · 1 line
2.31.1
Re: [PATCH 3/4] sysreset: watchdog: Move watchdog reference to plat data
Quoted 8 lines · Samuel Holland
Currently, the
wdt_rebootdriver always gets its watchdog device reference from an OF node. This prevents selecting a watchdog at runtime. Move the watchdog device reference to the plat data, so the driver can be bound with the reference pre-provided. The reference will still be acquired from the OF node if it is not already provided.Signed-off-by Samuel Holland <[email protected]>
Simon Glass
Reviewed-byRe: [PATCH 3/4] sysreset: watchdog: Move watchdog reference to plat data
Quoted 9 lines · Heinrich Schuchardt
Quoted 7 lines · Samuel Holland
Currently, the
wdt_rebootdriver always gets its watchdog device reference from an OF node. This prevents selecting a watchdog at runtime. Move the watchdog device reference to the plat data, so the driver can be bound with the reference pre-provided. The reference will still be acquired from the OF node if it is not already provided.
Quoted 3 lines
Quoted 1 line
Signed-off-by Samuel Holland <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>
PATCH 4/4 watchdog: Automatically register device with sysreset
In reply to Samuel HollandAdd an option to automatically register the first watchdog device with the wdt_reboot driver for use with sysreset. This allows sysreset to be a drop-in replacement for platform-specific watchdog reset code, without needing any device tree changes.
---
drivers/sysreset/Kconfig | 7 +++++++ drivers/sysreset/sysreset_watchdog.c | 24 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 5 +++++ include/sysreset.h | 14 ++++++++++++++ 4 files changed, 50 insertions(+)
drivers/sysreset/Kconfig +7 -0
@@ -119,6 +119,13 @@ config SYSRESET_WATCHDOG help Reboot support for generic watchdog reset. +config SYSRESET_WATCHDOG_AUTO + bool "Automatically register first watchdog with sysreset" + depends on SYSRESET_WATCHDOG + help + If enabled, the first watchdog (as selected by the watchdog uclass) + will automatically be registered with the watchdog reboot driver. + config SYSRESET_RESETCTL bool "Enable support for reset controller reboot driver" select DM_RESET
drivers/sysreset/sysreset_watchdog.c +24 -0
@@ -5,7 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> #include <errno.h> +#include <malloc.h> #include <sysreset.h> #include <wdt.h>
@@ -57,3 +59,25 @@ U_BOOT_DRIVER(wdt_reboot) = { .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, }; + +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev) +{ +struct wdt_reboot_plat *plat =malloc (sizeof (*plat)); +int ret; + +if (!plat) +return -ENOMEM ; + + plat->wdt = dev; + + ret =device_bind (dev,DM_DRIVER_GET (wdt_reboot), + dev->name, plat,ofnode_null (),NULL ); +if (ret) { +free (plat); +return ret; + } + +return 0 ; +} +#endif
drivers/watchdog/wdt-uclass.c +5 -0
@@ -10,6 +10,7 @@#include <errno.h> #include <hang.h> #include <log.h> +#include <sysreset.h> #include <time.h> #include <wdt.h> #include <asm/global_data.h>
@@ -53,6 +54,10 @@ int initr_watchdog(void) 4 * reset_period) / 4; } + ret =sysreset_register_wdt (gd->watchdog_dev); +if (ret) +printf ("WDT: Failed to register sysreset\n" ); +if (!IS_ENABLED (CONFIG_WATCHDOG_AUTOSTART )) {printf ("WDT: Not starting\n" );return 0 ;
include/sysreset.h +14 -0
@@ -118,4 +118,18 @@ void sysreset_walk_halt(enum sysreset_t type);*/ void reset_cpu (void ); +/** +* sysreset_register_wdt() - register a watchdog for use with sysreset +* +* This registers the given watchdog timer to be used to reset the system. +* +* @dev: WDT device +* @return: 0 if OK, -errno if error +*/ +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev); +#else +static inline int sysreset_register_wdt (struct udevice *dev) {return 0 ; } +#endif +#endif
Signature · 1 line
2.31.1
Re: [PATCH 4/4] watchdog: Automatically register device with sysreset
drivers/watchdog/wdt-uclass.c int initr_watchdog(void)
Quoted 85 lines · Samuel Holland
Add an option to automatically register the first watchdog device with the
wdt_rebootdriver for use with sysreset. This allows sysreset to be a drop-in replacement for platform-specific watchdog reset code, without needing any device tree changes.Signed-off-by Samuel Holland <[email protected]>---
drivers/sysreset/Kconfig | 7 +++++++ drivers/sysreset/sysreset_watchdog.c | 24 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 5 +++++ include/sysreset.h | 14 ++++++++++++++ 4 files changed, 50 insertions(+)drivers/sysreset/Kconfig +7
-0@@ -119,6 +119,13 @@ config SYSRESET_WATCHDOG help Reboot support for generic watchdog reset. +config SYSRESET_WATCHDOG_AUTO + bool "Automatically register first watchdog with sysreset" + depends on SYSRESET_WATCHDOG + help + If enabled, the first watchdog (as selected by the watchdog uclass) + will automatically be registered with the watchdog reboot driver. + config SYSRESET_RESETCTL bool "Enable support for reset controller reboot driver" select DM_RESETdrivers/sysreset/sysreset_watchdog.c +24
-0@@ -5,7 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> #include <errno.h> +#include <malloc.h> #include <sysreset.h> #include <wdt.h> @@ -57,3 +59,25 @@ U_BOOT_DRIVER(wdt_reboot) = { .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, }; + +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev) +{ +struct wdt_reboot_plat *plat =malloc (sizeof (*plat)); +int ret; + +if (!plat) +return -ENOMEM ; + + plat->wdt = dev; + + ret =device_bind (dev,DM_DRIVER_GET (wdt_reboot), + dev->name, plat,ofnode_null (),NULL ); +if (ret) { +free (plat); +return ret; + } + +return 0 ; +} +#endif drivers/watchdog/wdt-uclass.c +1
-0@@ -10,6 +10,7 @@#include <errno.h> #include <hang.h> #include <log.h> +#include <sysreset.h> #include <time.h> #include <wdt.h> #include <asm/global_data.h> @@ -53,6 +54,10 @@ int initr_watchdog(void)
This function has been changed in upstream:
@@ -44,6 +45,10 @@ static void init_watchdog_dev(struct udevice *dev)
drivers/watchdog/wdt-uclass.c int initr_watchdog(void) · line 57
Quoted 4 lines
drivers/watchdog/wdt-uclass.c +1
-04 * reset_period) / 4; } + ret =sysreset_register_wdt (gd->watchdog_dev);
ret = sysreset_register_wdt(dev);
I applied the following series to enable testing on the sandbox:
[PATCH 0/2] sandbox: enable testing SYSRESET_WATCHDOG
https://lists.denx.de/pipermail/u-boot/2021-October/465270.html
I found no issues.
Please, resend the rebased series.
Best regards
Heinrich
Quoted 30 lines
drivers/watchdog/wdt-uclass.c +3
-0+if (ret) +printf ("WDT: Failed to register sysreset\n" ); +if (!IS_ENABLED (CONFIG_WATCHDOG_AUTOSTART )) {printf ("WDT: Not starting\n" );return 0 ;include/sysreset.h +14
-0@@ -118,4 +118,18 @@ void sysreset_walk_halt(enum sysreset_t type);*/ void reset_cpu (void ); +/** +* sysreset_register_wdt() - register a watchdog for use with sysreset +* +* This registers the given watchdog timer to be used to reset the system. +* +* @dev: WDT device +* @return: 0 if OK, -errno if error +*/ +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev); +#else +static inline int sysreset_register_wdt (struct udevice *dev) {return 0 ; } +#endif +#endif
Re: [PATCH 4/4] watchdog: Automatically register device with sysreset
In reply to Samuel HollandHi Samuel,
Quoted 6 lines · Samuel Holland
Add an option to automatically register the first watchdog device with the
wdt_rebootdriver for use with sysreset. This allows sysreset to be a drop-in replacement for platform-specific watchdog reset code, without needing any device tree changes.
Quoted 8 lines
Signed-off-by Samuel Holland <[email protected]>---
drivers/sysreset/Kconfig | 7 +++++++ drivers/sysreset/sysreset_watchdog.c | 24 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 5 +++++ include/sysreset.h | 14 ++++++++++++++ 4 files changed, 50 insertions(+)
This is a bit odd, but I suppose it is OK.
Quoted 34 lines
drivers/sysreset/Kconfig +7
-0@@ -119,6 +119,13 @@ config SYSRESET_WATCHDOG help Reboot support for generic watchdog reset. +config SYSRESET_WATCHDOG_AUTO + bool "Automatically register first watchdog with sysreset" + depends on SYSRESET_WATCHDOG + help + If enabled, the first watchdog (as selected by the watchdog uclass) + will automatically be registered with the watchdog reboot driver. + config SYSRESET_RESETCTL bool "Enable support for reset controller reboot driver" select DM_RESETdrivers/sysreset/sysreset_watchdog.c +2
-0@@ -5,7 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> #include <errno.h> +#include <malloc.h> #include <sysreset.h> #include <wdt.h>
drivers/sysreset/sysreset_watchdog.c U_BOOT_DRIVER(wdt_reboot) = { · line 64
Quoted 6 lines
drivers/sysreset/sysreset_watchdog.c +3
-0@@ -57,3 +59,25 @@ U_BOOT_DRIVER(wdt_reboot) = { .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, }; + +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev)
Could you pass in plat here instead of allocating it? You could add it to wdt-uclass.c as some private data for the uclass...
Quoted 66 lines
drivers/sysreset/sysreset_watchdog.c +19
-0+{ +struct wdt_reboot_plat *plat =malloc (sizeof (*plat)); +int ret; + +if (!plat) +return -ENOMEM ; + + plat->wdt = dev; + + ret =device_bind (dev,DM_DRIVER_GET (wdt_reboot), + dev->name, plat,ofnode_null (),NULL ); +if (ret) { +free (plat); +return ret; + } + +return 0 ; +} +#endif drivers/watchdog/wdt-uclass.c +5
-0@@ -10,6 +10,7 @@#include <errno.h> #include <hang.h> #include <log.h> +#include <sysreset.h> #include <time.h> #include <wdt.h> #include <asm/global_data.h> @@ -53,6 +54,10 @@ int initr_watchdog(void) 4 * reset_period) / 4; } + ret =sysreset_register_wdt (gd->watchdog_dev); +if (ret) +printf ("WDT: Failed to register sysreset\n" ); +if (!IS_ENABLED (CONFIG_WATCHDOG_AUTOSTART )) {printf ("WDT: Not starting\n" );return 0 ;include/sysreset.h +14
-1@@ -118,4 +118,18 @@ void sysreset_walk_halt(enum sysreset_t type);*/ void reset_cpu (void ); +/** +* sysreset_register_wdt() - register a watchdog for use with sysreset +* +* This registers the given watchdog timer to be used to reset the system. +* +* @dev: WDT device +* @return: 0 if OK, -errno if error +*/ +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev); +#else +static inline int sysreset_register_wdt (struct udevice *dev) {return 0 ; } +#endif +#endif --
Quoted 2 lines
2.31.1
Regards,
Simon
Re: [PATCH 4/4] watchdog: Automatically register device with sysreset
Quoted 55 lines · Simon Glass
Hi Samuel,
Quoted 6 lines · Samuel Holland
Add an option to automatically register the first watchdog device with the
wdt_rebootdriver for use with sysreset. This allows sysreset to be a drop-in replacement for platform-specific watchdog reset code, without needing any device tree changes.Quoted 8 lines
Signed-off-by Samuel Holland <[email protected]>---
drivers/sysreset/Kconfig | 7 +++++++ drivers/sysreset/sysreset_watchdog.c | 24 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 5 +++++ include/sysreset.h | 14 ++++++++++++++ 4 files changed, 50 insertions(+)This is a bit odd, but I suppose it is OK.
Reviewed-by Simon Glass <[email protected]>Quoted 33 lines
drivers/sysreset/Kconfig +7
-0@@ -119,6 +119,13 @@ config SYSRESET_WATCHDOG help Reboot support for generic watchdog reset. +config SYSRESET_WATCHDOG_AUTO + bool "Automatically register first watchdog with sysreset" + depends on SYSRESET_WATCHDOG + help + If enabled, the first watchdog (as selected by the watchdog uclass) + will automatically be registered with the watchdog reboot driver. + config SYSRESET_RESETCTL bool "Enable support for reset controller reboot driver" select DM_RESETdrivers/sysreset/sysreset_watchdog.c +2
-0@@ -5,7 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> #include <errno.h> +#include <malloc.h> #include <sysreset.h> #include <wdt.h>
Quoted 10 lines
drivers/sysreset/sysreset_watchdog.c U_BOOT_DRIVER(wdt_reboot) = { · line 64
Quoted 7 lines
drivers/sysreset/sysreset_watchdog.c +3
-0@@ -57,3 +59,25 @@ U_BOOT_DRIVER(wdt_reboot) = { .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, }; + +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev)Could you pass in plat here instead of allocating it? You could add it to
wdt-uclass.cas some private data for the uclass...
Yes, that is a good idea, especially now that all watchdogs get initialized during boot (so this code also applies to all watchdogs).
It would be simplest to use the plat pointer directly as the watchdog reference (otherwise the watchdog needs to store a pointer to itself in its uclass priv, which is a bit strange). But that would require using dev_set_plat in the wdt_reboot of_to_plat case. I wonder if that is an appropriate use of this API? Not much else uses dev_set_plat.
So I'd like to do this as a follow-up.
Regards,
Samuel
Quoted 72 lines
Quoted 66 lines
drivers/sysreset/sysreset_watchdog.c +19
-0+{ +struct wdt_reboot_plat *plat =malloc (sizeof (*plat)); +int ret; + +if (!plat) +return -ENOMEM ; + + plat->wdt = dev; + + ret =device_bind (dev,DM_DRIVER_GET (wdt_reboot), + dev->name, plat,ofnode_null (),NULL ); +if (ret) { +free (plat); +return ret; + } + +return 0 ; +} +#endif drivers/watchdog/wdt-uclass.c +5
-0@@ -10,6 +10,7 @@#include <errno.h> #include <hang.h> #include <log.h> +#include <sysreset.h> #include <time.h> #include <wdt.h> #include <asm/global_data.h> @@ -53,6 +54,10 @@ int initr_watchdog(void) 4 * reset_period) / 4; } + ret =sysreset_register_wdt (gd->watchdog_dev); +if (ret) +printf ("WDT: Failed to register sysreset\n" ); +if (!IS_ENABLED (CONFIG_WATCHDOG_AUTOSTART )) {printf ("WDT: Not starting\n" );return 0 ;include/sysreset.h +14
-1@@ -118,4 +118,18 @@ void sysreset_walk_halt(enum sysreset_t type);*/ void reset_cpu (void ); +/** +* sysreset_register_wdt() - register a watchdog for use with sysreset +* +* This registers the given watchdog timer to be used to reset the system. +* +* @dev: WDT device +* @return: 0 if OK, -errno if error +*/ +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev); +#else +static inline int sysreset_register_wdt (struct udevice *dev) {return 0 ; } +#endif +#endif --Quoted 2 lines
2.31.1
Regards,
Simon
Re: [PATCH 4/4] watchdog: Automatically register device with sysreset
Hi Samuel,
Quoted 71 lines · Samuel Holland
Quoted 55 lines · Simon Glass
Hi Samuel,
Quoted 6 lines · Samuel Holland
Add an option to automatically register the first watchdog device with the
wdt_rebootdriver for use with sysreset. This allows sysreset to be a drop-in replacement for platform-specific watchdog reset code, without needing any device tree changes.Quoted 8 lines
Signed-off-by Samuel Holland <[email protected]>---
drivers/sysreset/Kconfig | 7 +++++++ drivers/sysreset/sysreset_watchdog.c | 24 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 5 +++++ include/sysreset.h | 14 ++++++++++++++ 4 files changed, 50 insertions(+)This is a bit odd, but I suppose it is OK.
Reviewed-by Simon Glass <[email protected]>Quoted 33 lines
drivers/sysreset/Kconfig +7
-0@@ -119,6 +119,13 @@ config SYSRESET_WATCHDOG help Reboot support for generic watchdog reset. +config SYSRESET_WATCHDOG_AUTO + bool "Automatically register first watchdog with sysreset" + depends on SYSRESET_WATCHDOG + help + If enabled, the first watchdog (as selected by the watchdog uclass) + will automatically be registered with the watchdog reboot driver. + config SYSRESET_RESETCTL bool "Enable support for reset controller reboot driver" select DM_RESETdrivers/sysreset/sysreset_watchdog.c +2
-0@@ -5,7 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> #include <errno.h> +#include <malloc.h> #include <sysreset.h> #include <wdt.h> Quoted 10 lines
drivers/sysreset/sysreset_watchdog.c U_BOOT_DRIVER(wdt_reboot) = { · line 64
Quoted 7 lines
drivers/sysreset/sysreset_watchdog.c +3
-0@@ -57,3 +59,25 @@ U_BOOT_DRIVER(wdt_reboot) = { .plat_auto = sizeof(struct wdt_reboot_plat), .ops = &wdt_reboot_ops, }; + +#if IS_ENABLED (CONFIG_SYSRESET_WATCHDOG_AUTO ) +int sysreset_register_wdt (struct udevice *dev)Could you pass in plat here instead of allocating it? You could add it to
wdt-uclass.cas some private data for the uclass...Yes, that is a good idea, especially now that all watchdogs get initialized during boot (so this code also applies to all watchdogs).
Quoted 7 lines
It would be simplest to use the plat pointer directly as the watchdog reference (otherwise the watchdog needs to store a pointer to itself in its uclass priv, which is a bit strange). But that would require using
dev_set_platin thewdt_rebootof_to_platcase. I wonder if that is an appropriate use of this API? Not much else usesdev_set_plat.So I'd like to do this as a follow-up.
Yes that's fine, you have the review tag. I was thinking something like:
/* private data for WDT uclass */
struct wdt_priv {
struct wdt_reboot_plat wdt_reboot;
};
/* pass plat to device_bind()device_bind(...&priv->wdt_reboot...)
Needs a little thought of course, as you say. I am not keen on using dev_set_plat() after binding if we can help it.
[..]
Regards,
Simon