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