1 // SPDX-License-Identifier: GPL-2.0-only
3 * Watchdog driver for Technologic Systems TS-72xx based SBCs
4 * (TS-7200, TS-7250 and TS-7260). These boards have external
5 * glue logic CPLD chip, which includes programmable watchdog
8 * Copyright (c) 2009 Mika Westerberg <mika.westerberg@iki.fi>
10 * This driver is based on ep93xx_wdt and wm831x_wdt drivers.
14 #include <linux/platform_device.h>
15 #include <linux/module.h>
16 #include <linux/watchdog.h>
19 #define TS72XX_WDT_DEFAULT_TIMEOUT 30
22 module_param(timeout, int, 0);
23 MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds.");
25 static bool nowayout = WATCHDOG_NOWAYOUT;
26 module_param(nowayout, bool, 0);
27 MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
29 /* priv->control_reg */
30 #define TS72XX_WDT_CTRL_DISABLE 0x00
31 #define TS72XX_WDT_CTRL_250MS 0x01
32 #define TS72XX_WDT_CTRL_500MS 0x02
33 #define TS72XX_WDT_CTRL_1SEC 0x03
34 #define TS72XX_WDT_CTRL_RESERVED 0x04
35 #define TS72XX_WDT_CTRL_2SEC 0x05
36 #define TS72XX_WDT_CTRL_4SEC 0x06
37 #define TS72XX_WDT_CTRL_8SEC 0x07
40 #define TS72XX_WDT_FEED_VAL 0x05
42 struct ts72xx_wdt_priv {
43 void __iomem *control_reg;
44 void __iomem *feed_reg;
45 struct watchdog_device wdd;
49 static int ts72xx_wdt_start(struct watchdog_device *wdd)
51 struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
53 writeb(TS72XX_WDT_FEED_VAL, priv->feed_reg);
54 writeb(priv->regval, priv->control_reg);
59 static int ts72xx_wdt_stop(struct watchdog_device *wdd)
61 struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
63 writeb(TS72XX_WDT_FEED_VAL, priv->feed_reg);
64 writeb(TS72XX_WDT_CTRL_DISABLE, priv->control_reg);
69 static int ts72xx_wdt_ping(struct watchdog_device *wdd)
71 struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
73 writeb(TS72XX_WDT_FEED_VAL, priv->feed_reg);
78 static int ts72xx_wdt_settimeout(struct watchdog_device *wdd, unsigned int to)
80 struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
83 priv->regval = TS72XX_WDT_CTRL_1SEC;
85 priv->regval = TS72XX_WDT_CTRL_2SEC;
87 priv->regval = TS72XX_WDT_CTRL_4SEC;
90 priv->regval = TS72XX_WDT_CTRL_8SEC;
97 if (watchdog_active(wdd)) {
99 ts72xx_wdt_start(wdd);
105 static const struct watchdog_info ts72xx_wdt_ident = {
106 .options = WDIOF_KEEPALIVEPING |
109 .firmware_version = 1,
110 .identity = "TS-72XX WDT",
113 static const struct watchdog_ops ts72xx_wdt_ops = {
114 .owner = THIS_MODULE,
115 .start = ts72xx_wdt_start,
116 .stop = ts72xx_wdt_stop,
117 .ping = ts72xx_wdt_ping,
118 .set_timeout = ts72xx_wdt_settimeout,
121 static int ts72xx_wdt_probe(struct platform_device *pdev)
123 struct device *dev = &pdev->dev;
124 struct ts72xx_wdt_priv *priv;
125 struct watchdog_device *wdd;
128 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
132 priv->control_reg = devm_platform_ioremap_resource(pdev, 0);
133 if (IS_ERR(priv->control_reg))
134 return PTR_ERR(priv->control_reg);
136 priv->feed_reg = devm_platform_ioremap_resource(pdev, 1);
137 if (IS_ERR(priv->feed_reg))
138 return PTR_ERR(priv->feed_reg);
141 wdd->info = &ts72xx_wdt_ident;
142 wdd->ops = &ts72xx_wdt_ops;
143 wdd->min_timeout = 1;
144 wdd->max_hw_heartbeat_ms = 8000;
147 watchdog_set_nowayout(wdd, nowayout);
149 wdd->timeout = TS72XX_WDT_DEFAULT_TIMEOUT;
150 watchdog_init_timeout(wdd, timeout, dev);
152 watchdog_set_drvdata(wdd, priv);
154 ret = devm_watchdog_register_device(dev, wdd);
158 dev_info(dev, "TS-72xx Watchdog driver\n");
163 static struct platform_driver ts72xx_wdt_driver = {
164 .probe = ts72xx_wdt_probe,
166 .name = "ts72xx-wdt",
170 module_platform_driver(ts72xx_wdt_driver);
172 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@iki.fi>");
173 MODULE_DESCRIPTION("TS-72xx SBC Watchdog");
174 MODULE_LICENSE("GPL");
175 MODULE_ALIAS("platform:ts72xx-wdt");