watchdog: qcom_wdt: set WDOG_HW_RUNNING bit when appropriate
Subsystems (2)
PATCH v2 1/1 watchdog: qcom_wdt: set WDOG_HW_RUNNING bit when appropriate
If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.
Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.
Given the watchdog driver core doesn't know what timeout was originally set by whoever started the watchdog (boot loader), we make sure to update the timeout in the hardware according to what the watchdog core thinks it is.
---
Changes in v2:
* Correct authorship
drivers/watchdog/qcom-wdt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/watchdog/qcom-wdt.c +22 -0
@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action,return 0 ; } +static int qcom_wdt_is_running (struct watchdog_device *wdd) +{ +struct qcom_wdt *wdt =to_qcom_wdt (wdd); + +return (readl (wdt_addr (wdt,WDT_EN )) &1 ); +} +static const struct watchdog_ops qcom_wdt_ops = { .start = qcom_wdt_start, .stop = qcom_wdt_stop,
@@ -294,6 +301,21 @@ static int qcom_wdt_probe(struct platform_device *pdev) wdt->wdd.timeout =min (wdt->wdd.max_timeout,30U );watchdog_init_timeout (&wdt->wdd,0 , dev); +if (qcom_wdt_is_running (&wdt->wdd)) { +/* +* Make sure to apply timeout from watchdog core, taking +* the prescaler of this driver here into account (the +* boot loader might be using a different prescaler). +* +* To avoid spurious resets because of different scaling, +* we first disable the watchdog, set the new prescaler +* and timeout, and then re-enable the watchdog. +*/ +qcom_wdt_stop (&wdt->wdd); +qcom_wdt_start (&wdt->wdd); +set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); + } + ret =devm_watchdog_register_device (dev, &wdt->wdd);if (ret)return ret;
Signature · 1 line
2.28.0
Quoted 28 lines · Robert Marko
If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.
Do so using the
WDOG_HW_RUNNINGflag that exists for exactly that use-case.Given the watchdog driver core doesn't know what timeout was originally set by whoever started the watchdog (boot loader), we make sure to update the timeout in the hardware according to what the watchdog core thinks it is.
Signed-off-by Robert Marko <[email protected]>Cc Luka Perkov <[email protected]>---
Changes in v2:
* Correct authorshipdrivers/watchdog/qcom-wdt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)drivers/watchdog/qcom-wdt.c +0
-0
drivers/watchdog/qcom-wdt.c static int qcom_wdt_restart(struct · line 160
Quoted 9 lines
drivers/watchdog/qcom-wdt.c +5
-0@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, return 0; } +static int qcom_wdt_is_running (struct watchdog_device *wdd) +{ +struct qcom_wdt *wdt =to_qcom_wdt (wdd); + +return (readl (wdt_addr (wdt,WDT_EN )) &1 );
QCOM_WDT_ENABLE macro can be used instead of 1?
Quoted 11 lines
drivers/watchdog/qcom-wdt.c +2
-0+} +static const struct watchdog_ops qcom_wdt_ops = { .start = qcom_wdt_start,drivers/watchdog/qcom-wdt.c +1
-0.stop = qcom_wdt_stop,@@ -294,6 +301,21 @@ static int qcom_wdt_probe(struct platform_device *pdev) wdt->wdd.timeout =min (wdt->wdd.max_timeout,30U );watchdog_init_timeout (&wdt->wdd,0 , dev); +if (qcom_wdt_is_running (&wdt->wdd)) {
drivers/watchdog/qcom-wdt.c static int qcom_wdt_probe(struct platform_device · line 315
Quoted 10 lines
drivers/watchdog/qcom-wdt.c +10
-0+/* +* Make sure to apply timeout from watchdog core, taking +* the prescaler of this driver here into account (the +* boot loader might be using a different prescaler). +* +* To avoid spurious resets because of different scaling, +* we first disable the watchdog, set the new prescaler +* and timeout, and then re-enable the watchdog. +*/ +qcom_wdt_stop (&wdt->wdd);
qcom_wdt_start disables the WDT, configure the timeout values and enables it. Do we still need to call qcom_wdt_stop?
Quoted 7 lines
drivers/watchdog/qcom-wdt.c +4
-0+qcom_wdt_start (&wdt->wdd); +set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); + } + ret =devm_watchdog_register_device (dev, &wdt->wdd);if (ret)return ret;
Quoted 34 lines · On Fri, Oct 30, 2020 at 6:21 AM <[email protected]> wrote:
Quoted 32 lines · Robert Marko
If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.
Do so using the
WDOG_HW_RUNNINGflag that exists for exactly that use-case.Given the watchdog driver core doesn't know what timeout was originally set by whoever started the watchdog (boot loader), we make sure to update the timeout in the hardware according to what the watchdog core thinks it is.
Signed-off-by Robert Marko <[email protected]>Cc Luka Perkov <[email protected]>---
Changes in v2:
* Correct authorshipdrivers/watchdog/qcom-wdt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)drivers/watchdog/qcom-wdt.c +0
-0@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, return 0; }
Quoted 7 lines
drivers/watchdog/qcom-wdt.c static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, · line 159
Quoted 5 lines
drivers/watchdog/qcom-wdt.c +5
-0+static int qcom_wdt_is_running (struct watchdog_device *wdd) +{ +struct qcom_wdt *wdt =to_qcom_wdt (wdd); + +return (readl (wdt_addr (wdt,WDT_EN )) &1 );
QCOM_WDT_ENABLEmacro can be used instead of 1?
Yes, pushed this in v4(Forgot to do it in v3).
Thanks
Quoted 11 lines
Quoted 11 lines
drivers/watchdog/qcom-wdt.c +2
-0+} +static const struct watchdog_ops qcom_wdt_ops = { .start = qcom_wdt_start,.stop =
qcom_wdt_stop,drivers/watchdog/qcom-wdt.c +0
-0@@ -294,6 +301,21 @@ static int qcom_wdt_probe(struct platform_device *pdev) wdt->wdd.timeout =min (wdt->wdd.max_timeout,30U );watchdog_init_timeout (&wdt->wdd,0 , dev);
Quoted 14 lines
drivers/watchdog/qcom-wdt.c static int qcom_wdt_probe(struct platform_device *pdev) · line 314
Quoted 11 lines
drivers/watchdog/qcom-wdt.c +11
-0+if (qcom_wdt_is_running (&wdt->wdd)) { +/* +* Make sure to apply timeout from watchdog core, taking +* the prescaler of this driver here into account (the +* boot loader might be using a different prescaler). +* +* To avoid spurious resets because of different scaling, +* we first disable the watchdog, set the new prescaler +* and timeout, and then re-enable the watchdog. +*/ +qcom_wdt_stop (&wdt->wdd);
qcom_wdt_startdisables the WDT, configure the timeout values and enables it. Do we still need to callqcom_wdt_stop?
No, as the start will actually stop the WDT and then set everything up. Pushed in v3.
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/qcom-wdt.c +4
-0+qcom_wdt_start (&wdt->wdd); +set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); + } + ret =devm_watchdog_register_device (dev, &wdt->wdd);if (ret)return ret;