blob: 0a4d7cc05d5439346ae0b77633089a08ea0464d6 [file] [log] [blame]
Alessandro Zummof52ac8f2006-03-25 03:06:37 -08001/*
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 *
H Hartley Sweetene12a6792012-03-14 10:31:50 -070011 * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
12 * Convert to a platform device and use the watchdog framework API
13 *
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080014 * 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
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +110029#include <linux/platform_device.h>
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080030#include <linux/module.h>
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080031#include <linux/watchdog.h>
32#include <linux/timer.h>
Ryan Mallon2653d1d2009-07-15 21:33:22 +010033#include <linux/io.h>
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080034
H Hartley Sweetene12a6792012-03-14 10:31:50 -070035#define WDT_VERSION "0.4"
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080036
37/* default timeout (secs) */
38#define WDT_TIMEOUT 30
39
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010040static bool nowayout = WATCHDOG_NOWAYOUT;
H Hartley Sweetene12a6792012-03-14 10:31:50 -070041module_param(nowayout, bool, 0);
42MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
43
Wim Van Sebroeck2ca16062012-03-22 09:37:10 +010044static unsigned int timeout = WDT_TIMEOUT;
45module_param(timeout, uint, 0);
H Hartley Sweetene12a6792012-03-14 10:31:50 -070046MODULE_PARM_DESC(timeout,
47 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
48 __MODULE_STRING(WDT_TIMEOUT) ")");
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080049
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +110050static void __iomem *mmio_base;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080051static struct timer_list timer;
52static unsigned long next_heartbeat;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080053
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +110054#define EP93XX_WATCHDOG 0x00
55#define EP93XX_WDSTATUS 0x04
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080056
Wim Van Sebroeck2ca16062012-03-22 09:37:10 +010057/* reset the wdt every ~200ms - the heartbeat of the device is 0.250 seconds*/
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080058#define WDT_INTERVAL (HZ/5)
59
H Hartley Sweetene12a6792012-03-14 10:31:50 -070060static void ep93xx_wdt_timer_ping(unsigned long data)
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080061{
62 if (time_before(jiffies, next_heartbeat))
H Hartley Sweetene12a6792012-03-14 10:31:50 -070063 writel(0x5555, mmio_base + EP93XX_WATCHDOG);
Alessandro Zummof52ac8f2006-03-25 03:06:37 -080064
65 /* Re-set the timer interval */
66 mod_timer(&timer, jiffies + WDT_INTERVAL);
67}
68
H Hartley Sweetene12a6792012-03-14 10:31:50 -070069static int ep93xx_wdt_start(struct watchdog_device *wdd)
70{
71 next_heartbeat = jiffies + (timeout * HZ);
72
73 writel(0xaaaa, mmio_base + EP93XX_WATCHDOG);
74 mod_timer(&timer, jiffies + WDT_INTERVAL);
75
76 return 0;
77}
78
79static int ep93xx_wdt_stop(struct watchdog_device *wdd)
80{
81 del_timer_sync(&timer);
82 writel(0xaa55, mmio_base + EP93XX_WATCHDOG);
83
84 return 0;
85}
86
87static int ep93xx_wdt_keepalive(struct watchdog_device *wdd)
88{
89 /* user land ping */
90 next_heartbeat = jiffies + (timeout * HZ);
91
92 return 0;
93}
94
95static const struct watchdog_info ep93xx_wdt_ident = {
96 .options = WDIOF_CARDRESET |
97 WDIOF_MAGICCLOSE |
98 WDIOF_KEEPALIVEPING,
99 .identity = "EP93xx Watchdog",
100};
101
102static struct watchdog_ops ep93xx_wdt_ops = {
103 .owner = THIS_MODULE,
104 .start = ep93xx_wdt_start,
105 .stop = ep93xx_wdt_stop,
106 .ping = ep93xx_wdt_keepalive,
107};
108
109static struct watchdog_device ep93xx_wdt_wdd = {
110 .info = &ep93xx_wdt_ident,
111 .ops = &ep93xx_wdt_ops,
112};
113
Bill Pemberton2d991a12012-11-19 13:21:41 -0500114static int ep93xx_wdt_probe(struct platform_device *pdev)
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800115{
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100116 struct resource *res;
117 unsigned long val;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800118 int err;
119
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Jingoo Han4f6120b2014-02-11 21:41:54 +0900121 mmio_base = devm_ioremap_resource(&pdev->dev, res);
122 if (IS_ERR(mmio_base))
123 return PTR_ERR(mmio_base);
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100124
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800125 if (timeout < 1 || timeout > 3600) {
126 timeout = WDT_TIMEOUT;
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700127 dev_warn(&pdev->dev,
128 "timeout value must be 1<=x<=3600, using %d\n",
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800129 timeout);
130 }
131
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100132 val = readl(mmio_base + EP93XX_WATCHDOG);
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700133 ep93xx_wdt_wdd.bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
Mika Westerberg59dcf1e2012-03-18 13:09:52 +0200134 ep93xx_wdt_wdd.timeout = timeout;
Pratyush Anand65518812015-08-20 14:05:01 +0530135 ep93xx_wdt_wdd.parent = &pdev->dev;
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100136
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700137 watchdog_set_nowayout(&ep93xx_wdt_wdd, nowayout);
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100138
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700139 setup_timer(&timer, ep93xx_wdt_timer_ping, 1);
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100140
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700141 err = watchdog_register_device(&ep93xx_wdt_wdd);
142 if (err)
143 return err;
144
145 dev_info(&pdev->dev,
146 "EP93XX watchdog, driver version " WDT_VERSION "%s\n",
Wim Van Sebroeck697b41e2012-03-13 09:06:12 +0100147 (val & 0x08) ? " (nCS1 disable detected)" : "");
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700148
149 return 0;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800150}
151
Bill Pemberton4b12b892012-11-19 13:26:24 -0500152static int ep93xx_wdt_remove(struct platform_device *pdev)
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800153{
H Hartley Sweetene12a6792012-03-14 10:31:50 -0700154 watchdog_unregister_device(&ep93xx_wdt_wdd);
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100155 return 0;
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800156}
157
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100158static struct platform_driver ep93xx_wdt_driver = {
159 .driver = {
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100160 .name = "ep93xx-wdt",
161 },
162 .probe = ep93xx_wdt_probe,
Bill Pemberton82268712012-11-19 13:21:12 -0500163 .remove = ep93xx_wdt_remove,
H Hartley Sweeten3e0113a2012-03-13 09:48:16 +1100164};
165
166module_platform_driver(ep93xx_wdt_driver);
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800167
Jingoo Han5f5e1902014-02-27 14:41:42 +0900168MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>");
169MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
170MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
Alessandro Zummof52ac8f2006-03-25 03:06:37 -0800171MODULE_DESCRIPTION("EP93xx Watchdog");
172MODULE_LICENSE("GPL");
173MODULE_VERSION(WDT_VERSION);