tracing: add sched_set_prio tracepoint
[deliverable/linux.git] / drivers / watchdog / ep93xx_wdt.c
CommitLineData
f52ac8fe
AZ
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 *
e12a679d
HS
11 * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
12 * Convert to a platform device and use the watchdog framework API
13 *
f52ac8fe
AZ
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
3e0113a8 29#include <linux/platform_device.h>
f52ac8fe 30#include <linux/module.h>
f52ac8fe
AZ
31#include <linux/watchdog.h>
32#include <linux/timer.h>
2653d1d7 33#include <linux/io.h>
f52ac8fe 34
e12a679d 35#define WDT_VERSION "0.4"
f52ac8fe
AZ
36
37/* default timeout (secs) */
38#define WDT_TIMEOUT 30
39
86a1e189 40static bool nowayout = WATCHDOG_NOWAYOUT;
e12a679d
HS
41module_param(nowayout, bool, 0);
42MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
43
2ca16063
WVS
44static unsigned int timeout = WDT_TIMEOUT;
45module_param(timeout, uint, 0);
e12a679d
HS
46MODULE_PARM_DESC(timeout,
47 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
48 __MODULE_STRING(WDT_TIMEOUT) ")");
f52ac8fe 49
3e0113a8 50static void __iomem *mmio_base;
f52ac8fe
AZ
51static struct timer_list timer;
52static unsigned long next_heartbeat;
f52ac8fe 53
3e0113a8
HS
54#define EP93XX_WATCHDOG 0x00
55#define EP93XX_WDSTATUS 0x04
f52ac8fe 56
2ca16063 57/* reset the wdt every ~200ms - the heartbeat of the device is 0.250 seconds*/
f52ac8fe
AZ
58#define WDT_INTERVAL (HZ/5)
59
e12a679d 60static void ep93xx_wdt_timer_ping(unsigned long data)
f52ac8fe 61{
e12a679d
HS
62 if (time_before(jiffies, next_heartbeat))
63 writel(0x5555, mmio_base + EP93XX_WATCHDOG);
f52ac8fe 64
e12a679d
HS
65 /* Re-set the timer interval */
66 mod_timer(&timer, jiffies + WDT_INTERVAL);
f52ac8fe
AZ
67}
68
e12a679d 69static int ep93xx_wdt_start(struct watchdog_device *wdd)
f52ac8fe
AZ
70{
71 next_heartbeat = jiffies + (timeout * HZ);
72
e12a679d 73 writel(0xaaaa, mmio_base + EP93XX_WATCHDOG);
f52ac8fe 74 mod_timer(&timer, jiffies + WDT_INTERVAL);
e12a679d
HS
75
76 return 0;
f52ac8fe
AZ
77}
78
e12a679d 79static int ep93xx_wdt_stop(struct watchdog_device *wdd)
f52ac8fe
AZ
80{
81 del_timer_sync(&timer);
e12a679d
HS
82 writel(0xaa55, mmio_base + EP93XX_WATCHDOG);
83
84 return 0;
f52ac8fe
AZ
85}
86
e12a679d 87static int ep93xx_wdt_keepalive(struct watchdog_device *wdd)
f52ac8fe
AZ
88{
89 /* user land ping */
90 next_heartbeat = jiffies + (timeout * HZ);
f52ac8fe 91
e12a679d 92 return 0;
f52ac8fe
AZ
93}
94
e12a679d
HS
95static const struct watchdog_info ep93xx_wdt_ident = {
96 .options = WDIOF_CARDRESET |
97 WDIOF_MAGICCLOSE |
98 WDIOF_KEEPALIVEPING,
99 .identity = "EP93xx Watchdog",
f52ac8fe
AZ
100};
101
e12a679d 102static struct watchdog_ops ep93xx_wdt_ops = {
f52ac8fe 103 .owner = THIS_MODULE,
e12a679d
HS
104 .start = ep93xx_wdt_start,
105 .stop = ep93xx_wdt_stop,
106 .ping = ep93xx_wdt_keepalive,
f52ac8fe
AZ
107};
108
e12a679d
HS
109static struct watchdog_device ep93xx_wdt_wdd = {
110 .info = &ep93xx_wdt_ident,
111 .ops = &ep93xx_wdt_ops,
f52ac8fe
AZ
112};
113
2d991a16 114static int ep93xx_wdt_probe(struct platform_device *pdev)
f52ac8fe 115{
3e0113a8
HS
116 struct resource *res;
117 unsigned long val;
f52ac8fe
AZ
118 int err;
119
3e0113a8 120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4f6120b0
JH
121 mmio_base = devm_ioremap_resource(&pdev->dev, res);
122 if (IS_ERR(mmio_base))
123 return PTR_ERR(mmio_base);
3e0113a8 124
f52ac8fe
AZ
125 if (timeout < 1 || timeout > 3600) {
126 timeout = WDT_TIMEOUT;
e12a679d
HS
127 dev_warn(&pdev->dev,
128 "timeout value must be 1<=x<=3600, using %d\n",
f52ac8fe
AZ
129 timeout);
130 }
131
697b41e4 132 val = readl(mmio_base + EP93XX_WATCHDOG);
e12a679d 133 ep93xx_wdt_wdd.bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
59dcf1eb 134 ep93xx_wdt_wdd.timeout = timeout;
6551881c 135 ep93xx_wdt_wdd.parent = &pdev->dev;
e12a679d
HS
136
137 watchdog_set_nowayout(&ep93xx_wdt_wdd, nowayout);
697b41e4 138
e12a679d 139 setup_timer(&timer, ep93xx_wdt_timer_ping, 1);
697b41e4 140
e12a679d
HS
141 err = watchdog_register_device(&ep93xx_wdt_wdd);
142 if (err)
143 return err;
697b41e4 144
e12a679d
HS
145 dev_info(&pdev->dev,
146 "EP93XX watchdog, driver version " WDT_VERSION "%s\n",
697b41e4 147 (val & 0x08) ? " (nCS1 disable detected)" : "");
e12a679d
HS
148
149 return 0;
f52ac8fe
AZ
150}
151
4b12b896 152static int ep93xx_wdt_remove(struct platform_device *pdev)
f52ac8fe 153{
e12a679d 154 watchdog_unregister_device(&ep93xx_wdt_wdd);
3e0113a8 155 return 0;
f52ac8fe
AZ
156}
157
3e0113a8
HS
158static struct platform_driver ep93xx_wdt_driver = {
159 .driver = {
3e0113a8
HS
160 .name = "ep93xx-wdt",
161 },
162 .probe = ep93xx_wdt_probe,
82268714 163 .remove = ep93xx_wdt_remove,
3e0113a8
HS
164};
165
166module_platform_driver(ep93xx_wdt_driver);
f52ac8fe 167
5f5e1909
JH
168MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>");
169MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
170MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
f52ac8fe
AZ
171MODULE_DESCRIPTION("EP93xx Watchdog");
172MODULE_LICENSE("GPL");
173MODULE_VERSION(WDT_VERSION);
This page took 0.685496 seconds and 5 git commands to generate.