watchdog: qcom: register a restart notifier
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> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
This commit is contained in:
parent
f286e1335f
commit
05e487d905
1 changed files with 38 additions and 0 deletions
|
@ -11,11 +11,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
|
#include <linux/delay.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
|
#include <linux/reboot.h>
|
||||||
#include <linux/watchdog.h>
|
#include <linux/watchdog.h>
|
||||||
|
|
||||||
#define WDT_RST 0x0
|
#define WDT_RST 0x0
|
||||||
|
@ -26,6 +28,7 @@ struct qcom_wdt {
|
||||||
struct watchdog_device wdd;
|
struct watchdog_device wdd;
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
unsigned long rate;
|
unsigned long rate;
|
||||||
|
struct notifier_block restart_nb;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,6 +87,32 @@ static const struct watchdog_info qcom_wdt_info = {
|
||||||
.identity = KBUILD_MODNAME,
|
.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)
|
static int qcom_wdt_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct qcom_wdt *wdt;
|
struct qcom_wdt *wdt;
|
||||||
|
@ -147,6 +176,14 @@ static int qcom_wdt_probe(struct platform_device *pdev)
|
||||||
goto err_clk_unprepare;
|
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);
|
platform_set_drvdata(pdev, wdt);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -159,6 +196,7 @@ static int qcom_wdt_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct qcom_wdt *wdt = platform_get_drvdata(pdev);
|
struct qcom_wdt *wdt = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
|
unregister_restart_handler(&wdt->restart_nb);
|
||||||
watchdog_unregister_device(&wdt->wdd);
|
watchdog_unregister_device(&wdt->wdd);
|
||||||
clk_disable_unprepare(wdt->clk);
|
clk_disable_unprepare(wdt->clk);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue