Re: [PATCH v3 04/12] watchdog: s3c2410: Let kernel kick watchdog

From: Guenter Roeck
Date: Wed Nov 17 2021 - 08:35:25 EST


On Sun, Nov 07, 2021 at 10:29:35PM +0200, Sam Protsenko wrote:
> When "tmr_atboot" module param is set, the watchdog is started in
> driver's probe. In that case, also set WDOG_HW_RUNNING bit to let
> watchdog core driver know it's running. This way watchdog core can kick
> the watchdog for us (if CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED option is
> enabled), until user space takes control.
>
> WDOG_HW_RUNNING bit must be set before registering the watchdog. So the
> "tmr_atboot" handling code is moved before watchdog registration, to
> avoid performing the same check twice. This is also logical because
> WDOG_HW_RUNNING bit makes WDT core expect actually running watchdog.
>
> Signed-off-by: Sam Protsenko <semen.protsenko@xxxxxxxxxx>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxx>

Reviewed-by: Guenter Roeck <linux@xxxxxxxxxxxx>

> ---
> Changes in v3:
> - Added R-b tag by Krzysztof Kozlowski
>
> Changes in v2:
> - Added explanation on moving the code block to commit message
> - [PATCH 03/12] handles the case when tmr_atboot is present but valid
> timeout wasn't found
>
> drivers/watchdog/s3c2410_wdt.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> index 00421cf22556..0845c05034a1 100644
> --- a/drivers/watchdog/s3c2410_wdt.c
> +++ b/drivers/watchdog/s3c2410_wdt.c
> @@ -604,6 +604,21 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
> wdt->wdt_device.bootstatus = s3c2410wdt_get_bootstatus(wdt);
> wdt->wdt_device.parent = dev;
>
> + /*
> + * If "tmr_atboot" param is non-zero, start the watchdog right now. Also
> + * set WDOG_HW_RUNNING bit, so that watchdog core can kick the watchdog.
> + *
> + * If we're not enabling the watchdog, then ensure it is disabled if it
> + * has been left running from the bootloader or other source.
> + */
> + if (tmr_atboot) {
> + dev_info(dev, "starting watchdog timer\n");
> + s3c2410wdt_start(&wdt->wdt_device);
> + set_bit(WDOG_HW_RUNNING, &wdt->wdt_device.status);
> + } else {
> + s3c2410wdt_stop(&wdt->wdt_device);
> + }
> +
> ret = watchdog_register_device(&wdt->wdt_device);
> if (ret)
> goto err_cpufreq;
> @@ -612,17 +627,6 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
> if (ret < 0)
> goto err_unregister;
>
> - if (tmr_atboot) {
> - dev_info(dev, "starting watchdog timer\n");
> - s3c2410wdt_start(&wdt->wdt_device);
> - } else {
> - /* if we're not enabling the watchdog, then ensure it is
> - * disabled if it has been left running from the bootloader
> - * or other source */
> -
> - s3c2410wdt_stop(&wdt->wdt_device);
> - }
> -
> platform_set_drvdata(pdev, wdt);
>
> /* print out a statement of readiness */
> --
> 2.30.2
>