[brcm63xx] add support for 2.6.32, dropped the SPI patch for now
[openwrt.git] / target / linux / brcm63xx / patches-2.6.32 / 020-watchdog.patch
1 Index: linux-2.6.32.9/drivers/watchdog/Makefile
2 ===================================================================
3 --- linux-2.6.32.9.orig/drivers/watchdog/Makefile 2010-02-23 16:38:51.000000000 +0100
4 +++ linux-2.6.32.9/drivers/watchdog/Makefile 2010-02-28 18:13:51.000000000 +0100
5 @@ -113,6 +113,7 @@
6 obj-$(CONFIG_SIBYTE_WDOG) += sb_wdog.o
7 obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
8 obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
9 +obj-$(CONFIG_BCM63XX_WDT) += bcm63xx_wdt.o
10
11 # PARISC Architecture
12
13 Index: linux-2.6.32.9/drivers/watchdog/Kconfig
14 ===================================================================
15 --- linux-2.6.32.9.orig/drivers/watchdog/Kconfig 2010-02-23 16:38:51.000000000 +0100
16 +++ linux-2.6.32.9/drivers/watchdog/Kconfig 2010-02-28 18:13:51.000000000 +0100
17 @@ -850,6 +850,16 @@
18 help
19 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
20
21 +config BCM63XX_WDT
22 + tristate "Broadcom BCM63xx hardware watchdog"
23 + depends on BCM63XX
24 + help
25 + Watchdog driver for the built in watchdog hardware in Broadcom
26 + BCM63xx SoC.
27 +
28 + To compile thi driver as a loadable module, choose M here.
29 + The module will be called bcm63xx_wdt.
30 +
31 # PARISC Architecture
32
33 # POWERPC Architecture
34 Index: linux-2.6.32.9/drivers/watchdog/bcm63xx_wdt.c
35 ===================================================================
36 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
37 +++ linux-2.6.32.9/drivers/watchdog/bcm63xx_wdt.c 2010-02-28 18:17:15.000000000 +0100
38 @@ -0,0 +1,334 @@
39 +/*
40 + * Broadcom BCM63xx SoC watchdog driver
41 + *
42 + * Copyright (C) 2007, Miguel Gaio <miguel.gaio@efixo.com>
43 + * Copyright (C) 2008, Florian Fainelli <florian@openwrt.org>
44 + *
45 + * This program is free software; you can redistribute it and/or
46 + * modify it under the terms of the GNU General Public License
47 + * as published by the Free Software Foundation; either version
48 + * 2 of the License, or (at your option) any later version.
49 + */
50 +
51 +#include <linux/bitops.h>
52 +#include <linux/errno.h>
53 +#include <linux/fs.h>
54 +#include <linux/init.h>
55 +#include <linux/kernel.h>
56 +#include <linux/miscdevice.h>
57 +#include <linux/module.h>
58 +#include <linux/moduleparam.h>
59 +#include <linux/reboot.h>
60 +#include <linux/types.h>
61 +#include <linux/uaccess.h>
62 +#include <linux/watchdog.h>
63 +#include <linux/timer.h>
64 +#include <linux/jiffies.h>
65 +#include <linux/resource.h>
66 +#include <linux/platform_device.h>
67 +
68 +#include <bcm63xx_cpu.h>
69 +#include <bcm63xx_io.h>
70 +#include <bcm63xx_regs.h>
71 +
72 +#define PFX KBUILD_MODNAME
73 +
74 +#define WDT_HZ 50000000 /* Fclk */
75 +#define WDT_DEFAULT_TIME 30 /* seconds */
76 +#define WDT_MAX_TIME 256 /* seconds */
77 +
78 +static struct {
79 + void __iomem *regs;
80 + struct timer_list timer;
81 + int default_ticks;
82 + unsigned long inuse;
83 + atomic_t ticks;
84 +} bcm63xx_wdt_device;
85 +
86 +static int expect_close;
87 +static int timeout;
88 +
89 +static int wdt_time = WDT_DEFAULT_TIME;
90 +static int nowayout = WATCHDOG_NOWAYOUT;
91 +module_param(nowayout, int, 0);
92 +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
93 + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
94 +
95 +/* HW functions */
96 +static void bcm63xx_wdt_hw_start(void)
97 +{
98 + bcm_writel(0xfffffffe, bcm63xx_wdt_device.regs + WDT_DEFVAL_REG);
99 + bcm_writel(WDT_START_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
100 + bcm_writel(WDT_START_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
101 +}
102 +
103 +static void bcm63xx_wdt_hw_stop(void)
104 +{
105 + bcm_writel(WDT_STOP_1, bcm63xx_wdt_device.regs + WDT_CTL_REG);
106 + bcm_writel(WDT_STOP_2, bcm63xx_wdt_device.regs + WDT_CTL_REG);
107 +}
108 +
109 +static void bcm63xx_timer_tick(unsigned long unused)
110 +{
111 + if (!atomic_dec_and_test(&bcm63xx_wdt_device.ticks)) {
112 + bcm63xx_wdt_hw_start();
113 + mod_timer(&bcm63xx_wdt_device.timer, jiffies + HZ);
114 + } else
115 + printk(KERN_CRIT PFX ": watchdog will restart system\n");
116 +}
117 +
118 +static void bcm63xx_wdt_pet(void)
119 +{
120 + atomic_set(&bcm63xx_wdt_device.ticks, wdt_time);
121 +}
122 +
123 +static void bcm63xx_wdt_start(void)
124 +{
125 + bcm63xx_wdt_pet();
126 + bcm63xx_timer_tick(0);
127 +}
128 +
129 +static void bcm63xx_wdt_pause(void)
130 +{
131 + del_timer_sync(&bcm63xx_wdt_device.timer);
132 + bcm63xx_wdt_hw_stop();
133 +}
134 +
135 +static int bcm63xx_wdt_settimeout(int new_time)
136 +{
137 + if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
138 + return -EINVAL;
139 +
140 + wdt_time = new_time;
141 +
142 + return 0;
143 +}
144 +
145 +static int bcm63xx_wdt_open(struct inode *inode, struct file *file)
146 +{
147 + if (test_and_set_bit(0, &bcm63xx_wdt_device.inuse))
148 + return -EBUSY;
149 +
150 + bcm63xx_wdt_start();
151 + return nonseekable_open(inode, file);
152 +}
153 +
154 +static int bcm63xx_wdt_release(struct inode *inode, struct file *file)
155 +{
156 + if (expect_close == 42)
157 + bcm63xx_wdt_pause();
158 + else {
159 + printk(KERN_CRIT PFX
160 + ": Unexpected close, not stopping watchdog!\n");
161 + bcm63xx_wdt_start();
162 + }
163 + clear_bit(0, &bcm63xx_wdt_device.inuse);
164 + expect_close = 0;
165 + return 0;
166 +}
167 +
168 +static ssize_t bcm63xx_wdt_write(struct file *file, const char *data,
169 + size_t len, loff_t *ppos)
170 +{
171 + if (len) {
172 + if (!nowayout) {
173 + size_t i;
174 +
175 + /* In case it was set long ago */
176 + expect_close = 0;
177 +
178 + for (i = 0; i != len; i++) {
179 + char c;
180 + if (get_user(c, data + i))
181 + return -EFAULT;
182 + if (c == 'V')
183 + expect_close = 42;
184 + }
185 + }
186 + bcm63xx_wdt_pet();
187 + }
188 + return len;
189 +}
190 +
191 +static struct watchdog_info bcm63xx_wdt_info = {
192 + .identity = PFX,
193 + .options = WDIOF_SETTIMEOUT |
194 + WDIOF_KEEPALIVEPING |
195 + WDIOF_MAGICCLOSE,
196 +};
197 +
198 +
199 +static long bcm63xx_wdt_ioctl(struct file *file, unsigned int cmd,
200 + unsigned long arg)
201 +{
202 + void __user *argp = (void __user *)arg;
203 + int __user *p = argp;
204 + int new_value, retval = -EINVAL;
205 +
206 + switch (cmd) {
207 + case WDIOC_GETSUPPORT:
208 + return copy_to_user(argp, &bcm63xx_wdt_info,
209 + sizeof(bcm63xx_wdt_info)) ? -EFAULT : 0;
210 +
211 + case WDIOC_GETSTATUS:
212 + case WDIOC_GETBOOTSTATUS:
213 + return put_user(0, p);
214 +
215 + case WDIOC_SETOPTIONS:
216 + if (get_user(new_value, p))
217 + return -EFAULT;
218 +
219 + if (new_value & WDIOS_DISABLECARD) {
220 + bcm63xx_wdt_pause();
221 + retval = 0;
222 + }
223 + if (new_value & WDIOS_ENABLECARD) {
224 + bcm63xx_wdt_start();
225 + retval = 0;
226 + }
227 +
228 + return retval;
229 +
230 + case WDIOC_KEEPALIVE:
231 + bcm63xx_wdt_pet();
232 + return 0;
233 +
234 + case WDIOC_SETTIMEOUT:
235 + if (get_user(new_value, p))
236 + return -EFAULT;
237 +
238 + if (bcm63xx_wdt_settimeout(new_value))
239 + return -EINVAL;
240 +
241 + bcm63xx_wdt_pet();
242 +
243 + case WDIOC_GETTIMEOUT:
244 + return put_user(wdt_time, p);
245 +
246 + default:
247 + return -ENOTTY;
248 +
249 + }
250 +}
251 +
252 +static int bcm63xx_wdt_notify_sys(struct notifier_block *this,
253 + unsigned long code, void *unused)
254 +{
255 + if (code == SYS_DOWN || code == SYS_HALT)
256 + bcm63xx_wdt_pause();
257 + return NOTIFY_DONE;
258 +}
259 +
260 +static const struct file_operations bcm63xx_wdt_fops = {
261 + .owner = THIS_MODULE,
262 + .llseek = no_llseek,
263 + .write = bcm63xx_wdt_write,
264 + .unlocked_ioctl = bcm63xx_wdt_ioctl,
265 + .open = bcm63xx_wdt_open,
266 + .release = bcm63xx_wdt_release,
267 +};
268 +
269 +static struct miscdevice bcm63xx_wdt_miscdev = {
270 + .minor = WATCHDOG_MINOR,
271 + .name = "watchdog",
272 + .fops = &bcm63xx_wdt_fops,
273 +};
274 +
275 +static struct notifier_block bcm63xx_wdt_notifier = {
276 + .notifier_call = bcm63xx_wdt_notify_sys,
277 +};
278 +
279 +
280 +static int bcm63xx_wdt_probe(struct platform_device *pdev)
281 +{
282 + int ret;
283 + struct resource *r;
284 +
285 + setup_timer(&bcm63xx_wdt_device.timer, bcm63xx_timer_tick, 0L);
286 +
287 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
288 + if (!r) {
289 + printk(KERN_ERR PFX
290 + "failed to retrieve resources\n");
291 + return -ENODEV;
292 + }
293 +
294 + bcm63xx_wdt_device.regs = ioremap_nocache(r->start, r->end - r->start);
295 + if (!bcm63xx_wdt_device.regs) {
296 + printk(KERN_ERR PFX
297 + "failed to remap I/O resources\n");
298 + return -ENXIO;
299 + }
300 +
301 + if (bcm63xx_wdt_settimeout(wdt_time)) {
302 + bcm63xx_wdt_settimeout(WDT_DEFAULT_TIME);
303 + printk(KERN_INFO PFX
304 + ": wdt_time value must be 1 <= wdt_time <= 256, using %d\n",
305 + wdt_time);
306 + }
307 +
308 + ret = register_reboot_notifier(&bcm63xx_wdt_notifier);
309 + if (ret) {
310 + printk(KERN_ERR PFX
311 + "failed to register reboot_notifier\n");
312 + return ret;
313 + }
314 +
315 + ret = misc_register(&bcm63xx_wdt_miscdev);
316 + if (ret < 0) {
317 + printk(KERN_ERR PFX
318 + "failed to register watchdog device\n");
319 + goto unmap;
320 + }
321 +
322 + printk(KERN_INFO PFX " started, timer margin: %d sec\n", WDT_DEFAULT_TIME);
323 +
324 + return 0;
325 +
326 +unmap:
327 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
328 + iounmap(bcm63xx_wdt_device.regs);
329 + return ret;
330 +}
331 +
332 +static int bcm63xx_wdt_remove(struct platform_device *pdev)
333 +{
334 + if (!nowayout)
335 + bcm63xx_wdt_pause();
336 +
337 + misc_deregister(&bcm63xx_wdt_miscdev);
338 +
339 + iounmap(bcm63xx_wdt_device.regs);
340 +
341 + unregister_reboot_notifier(&bcm63xx_wdt_notifier);
342 +
343 + return 0;
344 +}
345 +
346 +static struct platform_driver bcm63xx_wdt = {
347 + .probe = bcm63xx_wdt_probe,
348 + .remove = bcm63xx_wdt_remove,
349 + .driver = {
350 + .name = "bcm63xx-wdt",
351 + }
352 +};
353 +
354 +static int __init bcm63xx_wdt_init(void)
355 +{
356 + return platform_driver_register(&bcm63xx_wdt);
357 +}
358 +
359 +static void __exit bcm63xx_wdt_exit(void)
360 +{
361 + platform_driver_unregister(&bcm63xx_wdt);
362 +}
363 +
364 +module_init(bcm63xx_wdt_init);
365 +module_exit(bcm63xx_wdt_exit);
366 +
367 +MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
368 +MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
369 +MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog");
370 +MODULE_LICENSE("GPL");
371 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
372 +MODULE_ALIAS("platform:bcm63xx-wdt");
This page took 0.084247 seconds and 5 git commands to generate.