summaryrefslogtreecommitdiff
path: root/drivers/watchdog
diff options
context:
space:
mode:
authorRobin Gong <b38343@freescale.com>2015-11-02 16:44:33 +0800
committerNitin Garg <nitin.garg@nxp.com>2016-01-14 11:02:12 -0600
commitecc71ea8693e01372b4766b8a1cea1ce831f162a (patch)
tree0d7784caaf8896a5b1666bd947f07c2a07d8ba56 /drivers/watchdog
parent997ab6d6e2ca214a7d6609ec2a1c0f57f3ff0080 (diff)
MLK-11808-3: watchdog: imx2_wdt: add set_pretimeout
The pre-timeout interrupt will be triggered before watchdog timeout happen. So add interface in imx2_wdt driver. Signed-off-by: Robin Gong <b38343@freescale.com>
Diffstat (limited to 'drivers/watchdog')
-rw-r--r--drivers/watchdog/imx2_wdt.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c
index 7a2975d79d83..5b9f9af4113e 100644
--- a/drivers/watchdog/imx2_wdt.c
+++ b/drivers/watchdog/imx2_wdt.c
@@ -24,7 +24,9 @@
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/init.h>
+#include <linux/interrupt.h>
#include <linux/io.h>
+#include <linux/irq.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -52,12 +54,18 @@
#define IMX2_WDT_WRSR 0x04 /* Reset Status Register */
#define IMX2_WDT_WRSR_TOUT (1 << 1) /* -> Reset due to Timeout */
+#define IMX2_WDT_WICR 0x06 /*Interrupt Control Register*/
+#define IMX2_WDT_WICR_WIE (1 << 15) /* -> Interrupt Enable */
+#define IMX2_WDT_WICR_WTIS (1 << 14) /* -> Interrupt Status */
+#define IMX2_WDT_WICR_WICT (0xFF << 0) /* -> Watchdog Interrupt Timeout Field */
+
#define IMX2_WDT_WMCR 0x08 /* Misc Register */
#define IMX2_WDT_MAX_TIME 128
#define IMX2_WDT_DEFAULT_TIME 60 /* in seconds */
#define WDOG_SEC_TO_COUNT(s) ((s * 2 - 1) << 8)
+#define WDOG_SEC_TO_PRECOUNT(s) (s * 2) /* set WDOG pre timeout count*/
struct imx2_wdt_device {
struct clk *clk;
@@ -81,7 +89,7 @@ MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default="
static const struct watchdog_info imx2_wdt_info = {
.identity = "imx2+ watchdog",
- .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
+ .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_PRETIMEOUT,
};
static int imx2_restart_handler(struct notifier_block *this, unsigned long mode,
@@ -210,12 +218,56 @@ static inline void imx2_wdt_ping_if_active(struct watchdog_device *wdog)
}
}
+static int imx2_wdt_check_pretimeout_set(struct imx2_wdt_device *wdev)
+{
+ u32 val;
+
+ regmap_read(wdev->regmap, IMX2_WDT_WICR, &val);
+ return (val & IMX2_WDT_WICR_WIE) ? 1 : 0;
+}
+
+static int imx2_wdt_set_pretimeout(struct watchdog_device *wdog, unsigned int new_timeout)
+{
+ struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
+ u32 val;
+
+ regmap_read(wdev->regmap, IMX2_WDT_WICR, &val);
+ /* set the new pre-timeout value in the WSR */
+ val &= ~IMX2_WDT_WICR_WICT;
+ val |= WDOG_SEC_TO_PRECOUNT(new_timeout);
+
+ if (!imx2_wdt_check_pretimeout_set(wdev))
+ val |= IMX2_WDT_WICR_WIE; /*enable*/
+
+ regmap_write(wdev->regmap, IMX2_WDT_WICR, val);
+
+ return 0;
+}
+
+static irqreturn_t imx2_wdt_isr(int irq, void *dev_id)
+{
+ struct platform_device *pdev = dev_id;
+ struct watchdog_device *wdog = platform_get_drvdata(pdev);
+ struct imx2_wdt_device *wdev = watchdog_get_drvdata(wdog);
+ u32 val;
+
+ regmap_read(wdev->regmap, IMX2_WDT_WICR, &val);
+ if (val & IMX2_WDT_WICR_WTIS) {
+ /*clear interrupt status bit*/
+ regmap_write(wdev->regmap, IMX2_WDT_WICR, val);
+ dev_warn(&pdev->dev, "watchdog pre-timeout:%d, %d Seconds remained\n", \
+ wdog->pretimeout, wdog->timeout-wdog->pretimeout);
+ }
+ return IRQ_HANDLED;
+}
+
static const struct watchdog_ops imx2_wdt_ops = {
.owner = THIS_MODULE,
.start = imx2_wdt_start,
.stop = imx2_wdt_stop,
.ping = imx2_wdt_ping,
.set_timeout = imx2_wdt_set_timeout,
+ .set_pretimeout = imx2_wdt_set_pretimeout,
};
static const struct regmap_config imx2_wdt_regmap_config = {
@@ -232,6 +284,7 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int ret;
+ int irq;
u32 val;
struct device_node *of_node = pdev->dev.of_node;
@@ -257,6 +310,14 @@ static int __init imx2_wdt_probe(struct platform_device *pdev)
return PTR_ERR(wdev->clk);
}
+ irq = platform_get_irq(pdev, 0);
+ ret = devm_request_irq(&pdev->dev, irq, imx2_wdt_isr, 0,
+ dev_name(&pdev->dev), pdev);
+ if (ret) {
+ dev_err(&pdev->dev, "can't get irq %d\n", irq);
+ return ret;
+ }
+
if (of_get_property(of_node, "fsl,wdog_b", NULL)) {
wdev->wdog_b = true;
dev_info(&pdev->dev, "use WDOG_B to reboot.\n");