Loading...
1/*
2 * Watchdog driver for Cirrus Logic EP93xx family of devices.
3 *
4 * Copyright (c) 2004 Ray Lehtiniemi
5 * Copyright (c) 2006 Tower Technologies
6 * Based on ep93xx driver, bits from alim7101_wdt.c
7 *
8 * Authors: Ray Lehtiniemi <rayl@mail.com>,
9 * Alessandro Zummo <a.zummo@towertech.it>
10 *
11 * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
12 * Convert to a platform device and use the watchdog framework API
13 *
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 *
18 * This watchdog fires after 250msec, which is a too short interval
19 * for us to rely on the user space daemon alone. So we ping the
20 * wdt each ~200msec and eventually stop doing it if the user space
21 * daemon dies.
22 */
23
24#include <linux/platform_device.h>
25#include <linux/module.h>
26#include <linux/watchdog.h>
27#include <linux/io.h>
28
29/* default timeout (secs) */
30#define WDT_TIMEOUT 30
31
32static bool nowayout = WATCHDOG_NOWAYOUT;
33module_param(nowayout, bool, 0);
34MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
35
36static unsigned int timeout;
37module_param(timeout, uint, 0);
38MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds.");
39
40#define EP93XX_WATCHDOG 0x00
41#define EP93XX_WDSTATUS 0x04
42
43struct ep93xx_wdt_priv {
44 void __iomem *mmio;
45 struct watchdog_device wdd;
46};
47
48static int ep93xx_wdt_start(struct watchdog_device *wdd)
49{
50 struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
51
52 writel(0xaaaa, priv->mmio + EP93XX_WATCHDOG);
53
54 return 0;
55}
56
57static int ep93xx_wdt_stop(struct watchdog_device *wdd)
58{
59 struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
60
61 writel(0xaa55, priv->mmio + EP93XX_WATCHDOG);
62
63 return 0;
64}
65
66static int ep93xx_wdt_ping(struct watchdog_device *wdd)
67{
68 struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
69
70 writel(0x5555, priv->mmio + EP93XX_WATCHDOG);
71
72 return 0;
73}
74
75static const struct watchdog_info ep93xx_wdt_ident = {
76 .options = WDIOF_CARDRESET |
77 WDIOF_SETTIMEOUT |
78 WDIOF_MAGICCLOSE |
79 WDIOF_KEEPALIVEPING,
80 .identity = "EP93xx Watchdog",
81};
82
83static const struct watchdog_ops ep93xx_wdt_ops = {
84 .owner = THIS_MODULE,
85 .start = ep93xx_wdt_start,
86 .stop = ep93xx_wdt_stop,
87 .ping = ep93xx_wdt_ping,
88};
89
90static int ep93xx_wdt_probe(struct platform_device *pdev)
91{
92 struct device *dev = &pdev->dev;
93 struct ep93xx_wdt_priv *priv;
94 struct watchdog_device *wdd;
95 unsigned long val;
96 int ret;
97
98 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
99 if (!priv)
100 return -ENOMEM;
101
102 priv->mmio = devm_platform_ioremap_resource(pdev, 0);
103 if (IS_ERR(priv->mmio))
104 return PTR_ERR(priv->mmio);
105
106 val = readl(priv->mmio + EP93XX_WATCHDOG);
107
108 wdd = &priv->wdd;
109 wdd->bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
110 wdd->info = &ep93xx_wdt_ident;
111 wdd->ops = &ep93xx_wdt_ops;
112 wdd->min_timeout = 1;
113 wdd->max_hw_heartbeat_ms = 200;
114 wdd->parent = dev;
115
116 watchdog_set_nowayout(wdd, nowayout);
117
118 wdd->timeout = WDT_TIMEOUT;
119 watchdog_init_timeout(wdd, timeout, dev);
120
121 watchdog_set_drvdata(wdd, priv);
122
123 ret = devm_watchdog_register_device(dev, wdd);
124 if (ret)
125 return ret;
126
127 dev_info(dev, "EP93XX watchdog driver %s\n",
128 (val & 0x08) ? " (nCS1 disable detected)" : "");
129
130 return 0;
131}
132
133static struct platform_driver ep93xx_wdt_driver = {
134 .driver = {
135 .name = "ep93xx-wdt",
136 },
137 .probe = ep93xx_wdt_probe,
138};
139
140module_platform_driver(ep93xx_wdt_driver);
141
142MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>");
143MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
144MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
145MODULE_DESCRIPTION("EP93xx Watchdog");
146MODULE_LICENSE("GPL");
1/*
2 * Watchdog driver for Cirrus Logic EP93xx family of devices.
3 *
4 * Copyright (c) 2004 Ray Lehtiniemi
5 * Copyright (c) 2006 Tower Technologies
6 * Based on ep93xx driver, bits from alim7101_wdt.c
7 *
8 * Authors: Ray Lehtiniemi <rayl@mail.com>,
9 * Alessandro Zummo <a.zummo@towertech.it>
10 *
11 * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
12 * Convert to a platform device and use the watchdog framework API
13 *
14 * This file is licensed under the terms of the GNU General Public
15 * License version 2. This program is licensed "as is" without any
16 * warranty of any kind, whether express or implied.
17 *
18 * This watchdog fires after 250msec, which is a too short interval
19 * for us to rely on the user space daemon alone. So we ping the
20 * wdt each ~200msec and eventually stop doing it if the user space
21 * daemon dies.
22 *
23 * TODO:
24 *
25 * - Test last reset from watchdog status
26 * - Add a few missing ioctls
27 */
28
29#include <linux/platform_device.h>
30#include <linux/module.h>
31#include <linux/miscdevice.h>
32#include <linux/watchdog.h>
33#include <linux/timer.h>
34#include <linux/io.h>
35
36#define WDT_VERSION "0.4"
37
38/* default timeout (secs) */
39#define WDT_TIMEOUT 30
40
41static bool nowayout = WATCHDOG_NOWAYOUT;
42module_param(nowayout, bool, 0);
43MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
44
45static unsigned int timeout = WDT_TIMEOUT;
46module_param(timeout, uint, 0);
47MODULE_PARM_DESC(timeout,
48 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
49 __MODULE_STRING(WDT_TIMEOUT) ")");
50
51static void __iomem *mmio_base;
52static struct timer_list timer;
53static unsigned long next_heartbeat;
54
55#define EP93XX_WATCHDOG 0x00
56#define EP93XX_WDSTATUS 0x04
57
58/* reset the wdt every ~200ms - the heartbeat of the device is 0.250 seconds*/
59#define WDT_INTERVAL (HZ/5)
60
61static void ep93xx_wdt_timer_ping(unsigned long data)
62{
63 if (time_before(jiffies, next_heartbeat))
64 writel(0x5555, mmio_base + EP93XX_WATCHDOG);
65
66 /* Re-set the timer interval */
67 mod_timer(&timer, jiffies + WDT_INTERVAL);
68}
69
70static int ep93xx_wdt_start(struct watchdog_device *wdd)
71{
72 next_heartbeat = jiffies + (timeout * HZ);
73
74 writel(0xaaaa, mmio_base + EP93XX_WATCHDOG);
75 mod_timer(&timer, jiffies + WDT_INTERVAL);
76
77 return 0;
78}
79
80static int ep93xx_wdt_stop(struct watchdog_device *wdd)
81{
82 del_timer_sync(&timer);
83 writel(0xaa55, mmio_base + EP93XX_WATCHDOG);
84
85 return 0;
86}
87
88static int ep93xx_wdt_keepalive(struct watchdog_device *wdd)
89{
90 /* user land ping */
91 next_heartbeat = jiffies + (timeout * HZ);
92
93 return 0;
94}
95
96static const struct watchdog_info ep93xx_wdt_ident = {
97 .options = WDIOF_CARDRESET |
98 WDIOF_MAGICCLOSE |
99 WDIOF_KEEPALIVEPING,
100 .identity = "EP93xx Watchdog",
101};
102
103static struct watchdog_ops ep93xx_wdt_ops = {
104 .owner = THIS_MODULE,
105 .start = ep93xx_wdt_start,
106 .stop = ep93xx_wdt_stop,
107 .ping = ep93xx_wdt_keepalive,
108};
109
110static struct watchdog_device ep93xx_wdt_wdd = {
111 .info = &ep93xx_wdt_ident,
112 .ops = &ep93xx_wdt_ops,
113};
114
115static int __devinit ep93xx_wdt_probe(struct platform_device *pdev)
116{
117 struct resource *res;
118 unsigned long val;
119 int err;
120
121 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
122 if (!res)
123 return -ENXIO;
124
125 if (!devm_request_mem_region(&pdev->dev, res->start,
126 resource_size(res), pdev->name))
127 return -EBUSY;
128
129 mmio_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
130 if (!mmio_base)
131 return -ENXIO;
132
133 if (timeout < 1 || timeout > 3600) {
134 timeout = WDT_TIMEOUT;
135 dev_warn(&pdev->dev,
136 "timeout value must be 1<=x<=3600, using %d\n",
137 timeout);
138 }
139
140 val = readl(mmio_base + EP93XX_WATCHDOG);
141 ep93xx_wdt_wdd.bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
142 ep93xx_wdt_wdd.timeout = timeout;
143
144 watchdog_set_nowayout(&ep93xx_wdt_wdd, nowayout);
145
146 setup_timer(&timer, ep93xx_wdt_timer_ping, 1);
147
148 err = watchdog_register_device(&ep93xx_wdt_wdd);
149 if (err)
150 return err;
151
152 dev_info(&pdev->dev,
153 "EP93XX watchdog, driver version " WDT_VERSION "%s\n",
154 (val & 0x08) ? " (nCS1 disable detected)" : "");
155
156 return 0;
157}
158
159static int __devexit ep93xx_wdt_remove(struct platform_device *pdev)
160{
161 watchdog_unregister_device(&ep93xx_wdt_wdd);
162 return 0;
163}
164
165static struct platform_driver ep93xx_wdt_driver = {
166 .driver = {
167 .owner = THIS_MODULE,
168 .name = "ep93xx-wdt",
169 },
170 .probe = ep93xx_wdt_probe,
171 .remove = __devexit_p(ep93xx_wdt_remove),
172};
173
174module_platform_driver(ep93xx_wdt_driver);
175
176MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>,"
177 "Alessandro Zummo <a.zummo@towertech.it>,"
178 "H Hartley Sweeten <hsweeten@visionengravers.com>");
179MODULE_DESCRIPTION("EP93xx Watchdog");
180MODULE_LICENSE("GPL");
181MODULE_VERSION(WDT_VERSION);
182MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);