From: linux@roeck-us•net (Guenter Roeck)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH v4 3/3] watchdog: qcom: register a restart notifier
Date: Thu, 25 Sep 2014 20:20:23 -0700 [thread overview]
Message-ID: <5424DB77.7000008@roeck-us.net> (raw)
In-Reply-To: <1baf370c79a9bd7d57214c732863375374da2e0a.1411684967.git.joshc@codeaurora.org>
On 09/25/2014 03:51 PM, Josh Cartwright wrote:
> The WDT's BITE_TIME warm-reset behavior can be leveraged as a last
> resort mechanism for triggering chip reset. Usually, other restart
> methods (such as PS_HOLD) are preferrable for issuing a more complete
> reset of the chip. As such, keep the priority of the watchdog notifier
> low.
>
> Signed-off-by: Josh Cartwright <joshc@codeaurora•org>
Reviewed-by: Guenter Roeck <linux@roeck-us•net>
> ---
> drivers/watchdog/qcom-wdt.c | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c
> index 68db322..aa85618 100644
> --- a/drivers/watchdog/qcom-wdt.c
> +++ b/drivers/watchdog/qcom-wdt.c
> @@ -11,11 +11,13 @@
> *
> */
> #include <linux/clk.h>
> +#include <linux/delay.h>
> #include <linux/io.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/platform_device.h>
> +#include <linux/reboot.h>
> #include <linux/watchdog.h>
>
> #define WDT_RST 0x0
> @@ -26,6 +28,7 @@ struct qcom_wdt {
> struct watchdog_device wdd;
> struct clk *clk;
> unsigned long rate;
> + struct notifier_block restart_nb;
> void __iomem *base;
> };
>
> @@ -84,6 +87,32 @@ static const struct watchdog_info qcom_wdt_info = {
> .identity = KBUILD_MODNAME,
> };
>
> +static int qcom_wdt_restart(struct notifier_block *nb, unsigned long action,
> + void *data)
> +{
> + struct qcom_wdt *wdt = container_of(nb, struct qcom_wdt, restart_nb);
> + u32 timeout;
> +
> + /*
> + * Trigger watchdog bite:
> + * Setup BITE_TIME to be 128ms, and enable WDT.
> + */
> + timeout = 128 * wdt->rate / 1000;
> +
> + writel(0, wdt->base + WDT_EN);
> + writel(1, wdt->base + WDT_RST);
> + writel(timeout, wdt->base + WDT_BITE_TIME);
> + writel(1, wdt->base + WDT_EN);
> +
> + /*
> + * Actually make sure the above sequence hits hardware before sleeping.
> + */
> + wmb();
> +
> + msleep(150);
> + return NOTIFY_DONE;
> +}
> +
> static int qcom_wdt_probe(struct platform_device *pdev)
> {
> struct qcom_wdt *wdt;
> @@ -147,6 +176,14 @@ static int qcom_wdt_probe(struct platform_device *pdev)
> goto err_clk_unprepare;
> }
>
> + /*
> + * WDT restart notifier has priority 0 (use as a last resort)
> + */
> + wdt->restart_nb.notifier_call = qcom_wdt_restart;
> + ret = register_restart_handler(&wdt->restart_nb);
> + if (ret)
> + dev_err(&pdev->dev, "failed to setup restart handler\n");
> +
> platform_set_drvdata(pdev, wdt);
> return 0;
>
> @@ -159,6 +196,7 @@ static int qcom_wdt_remove(struct platform_device *pdev)
> {
> struct qcom_wdt *wdt = platform_get_drvdata(pdev);
>
> + unregister_restart_handler(&wdt->restart_nb);
> watchdog_unregister_device(&wdt->wdd);
> clk_disable_unprepare(wdt->clk);
> return 0;
>
prev parent reply other threads:[~2014-09-26 3:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-25 22:51 [PATCH v4 0/3] watchdog: add support for QCOM WDT Josh Cartwright
2014-09-25 22:51 ` [PATCH v4 1/3] watchdog: qcom: add support for KPSS WDT Josh Cartwright
2014-09-26 3:18 ` Guenter Roeck
2014-09-25 22:51 ` [PATCH v4 2/3] watchdog: qcom: document device tree bindings Josh Cartwright
2014-09-26 3:19 ` Guenter Roeck
2014-09-25 22:51 ` [PATCH v4 3/3] watchdog: qcom: register a restart notifier Josh Cartwright
2014-09-26 3:20 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5424DB77.7000008@roeck-us.net \
--to=linux@roeck-us$(echo .)net \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox