[rb532] add support for 2.6.32
[openwrt.git] / target / linux / ifxmips / patches-2.6.30 / 150-wdt.patch
1 Index: linux-2.6.30.8/drivers/watchdog/Makefile
2 ===================================================================
3 --- linux-2.6.30.8.orig/drivers/watchdog/Makefile 2009-09-24 17:28:02.000000000 +0200
4 +++ linux-2.6.30.8/drivers/watchdog/Makefile 2009-10-19 21:31:32.000000000 +0200
5 @@ -105,6 +105,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_IFXMIPS_WDT) += ifxmips_wdt.o
10
11 # PARISC Architecture
12
13 Index: linux-2.6.30.8/drivers/watchdog/Kconfig
14 ===================================================================
15 --- linux-2.6.30.8.orig/drivers/watchdog/Kconfig 2009-09-24 17:28:02.000000000 +0200
16 +++ linux-2.6.30.8/drivers/watchdog/Kconfig 2009-10-19 21:31:32.000000000 +0200
17 @@ -764,6 +764,12 @@
18 help
19 Hardware driver for the built-in watchdog timer on TXx9 MIPS SoCs.
20
21 +config IFXMIPS_WDT
22 + bool "IFXMips watchdog"
23 + depends on IFXMIPS
24 + help
25 + Hardware driver for the IFXMIPS Watchdog Timer.
26 +
27 # PARISC Architecture
28
29 # POWERPC Architecture
30 Index: linux-2.6.30.8/drivers/watchdog/ifxmips_wdt.c
31 ===================================================================
32 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
33 +++ linux-2.6.30.8/drivers/watchdog/ifxmips_wdt.c 2009-10-19 21:40:17.000000000 +0200
34 @@ -0,0 +1,195 @@
35 +/*
36 + * This program is free software; you can redistribute it and/or modify
37 + * it under the terms of the GNU General Public License as published by
38 + * the Free Software Foundation; either version 2 of the License, or
39 + * (at your option) any later version.
40 + *
41 + * This program is distributed in the hope that it will be useful,
42 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 + * GNU General Public License for more details.
45 + *
46 + * You should have received a copy of the GNU General Public License
47 + * along with this program; if not, write to the Free Software
48 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
49 + *
50 + * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
51 + * Based on EP93xx wdt driver
52 + */
53 +
54 +#include <linux/module.h>
55 +#include <linux/fs.h>
56 +#include <linux/miscdevice.h>
57 +#include <linux/miscdevice.h>
58 +#include <linux/watchdog.h>
59 +#include <linux/platform_device.h>
60 +#include <linux/uaccess.h>
61 +
62 +#include <ifxmips.h>
63 +#include <ifxmips_cgu.h>
64 +
65 +#define IFXMIPS_WDT_PW1 0x00BE0000
66 +#define IFXMIPS_WDT_PW2 0x00DC0000
67 +
68 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
69 +static int wdt_ok_to_close;
70 +#endif
71 +
72 +static int wdt_timeout = 30;
73 +
74 +int ifxmips_wdt_enable(unsigned int timeout)
75 +{
76 + u32 fpi;
77 + fpi = cgu_get_io_region_clock();
78 + ifxmips_w32(IFXMIPS_WDT_PW1, IFXMIPS_BIU_WDT_CR);
79 + ifxmips_w32(IFXMIPS_WDT_PW2 |
80 + (0x3 << 26) | /* PWL */
81 + (0x3 << 24) | /* CLKDIV */
82 + (0x1 << 31) | /* enable */
83 + ((timeout * (fpi / 0x40000)) + 0x1000), /* reload */
84 + IFXMIPS_BIU_WDT_CR);
85 + return 0;
86 +}
87 +
88 +void ifxmips_wdt_disable(void)
89 +{
90 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
91 + wdt_ok_to_close = 0;
92 +#endif
93 + ifxmips_w32(IFXMIPS_WDT_PW1, IFXMIPS_BIU_WDT_CR);
94 + ifxmips_w32(IFXMIPS_WDT_PW2, IFXMIPS_BIU_WDT_CR);
95 +}
96 +
97 +static ssize_t ifxmips_wdt_write(struct file *file, const char __user *data,
98 + size_t len, loff_t *ppos)
99 +{
100 + size_t i;
101 +
102 + if (!len)
103 + return 0;
104 +
105 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
106 + for (i = 0; i != len; i++) {
107 + char c;
108 + if (get_user(c, data + i))
109 + return -EFAULT;
110 + if (c == 'V')
111 + wdt_ok_to_close = 1;
112 + }
113 +#endif
114 + ifxmips_wdt_enable(wdt_timeout);
115 + return len;
116 +}
117 +
118 +static struct watchdog_info ident = {
119 + .options = WDIOF_MAGICCLOSE,
120 + .identity = "ifxmips Watchdog",
121 +};
122 +
123 +static int ifxmips_wdt_ioctl(struct inode *inode, struct file *file,
124 + unsigned int cmd, unsigned long arg)
125 +{
126 + int ret = -ENOTTY;
127 +
128 + switch (cmd) {
129 + case WDIOC_GETSUPPORT:
130 + ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
131 + sizeof(ident)) ? -EFAULT : 0;
132 + break;
133 +
134 + case WDIOC_GETTIMEOUT:
135 + ret = put_user(wdt_timeout, (int __user *)arg);
136 + break;
137 +
138 + case WDIOC_SETTIMEOUT:
139 + ret = get_user(wdt_timeout, (int __user *)arg);
140 + break;
141 +
142 + case WDIOC_KEEPALIVE:
143 + ifxmips_wdt_enable(wdt_timeout);
144 + ret = 0;
145 + break;
146 + }
147 + return ret;
148 +}
149 +
150 +static int ifxmips_wdt_open(struct inode *inode, struct file *file)
151 +{
152 + ifxmips_wdt_enable(wdt_timeout);
153 + return nonseekable_open(inode, file);
154 +}
155 +
156 +static int ifxmips_wdt_release(struct inode *inode, struct file *file)
157 +{
158 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
159 + if (wdt_ok_to_close)
160 + ifxmips_wdt_disable();
161 + else
162 +#endif
163 + printk(KERN_ERR "ifxmips_wdt: watchdog closed without warning,"
164 + " rebooting system\n");
165 + return 0;
166 +}
167 +
168 +static const struct file_operations ifxmips_wdt_fops = {
169 + .owner = THIS_MODULE,
170 + .write = ifxmips_wdt_write,
171 + .ioctl = ifxmips_wdt_ioctl,
172 + .open = ifxmips_wdt_open,
173 + .release = ifxmips_wdt_release,
174 +};
175 +
176 +static struct miscdevice ifxmips_wdt_miscdev = {
177 + .minor = WATCHDOG_MINOR,
178 + .name = "watchdog",
179 + .fops = &ifxmips_wdt_fops,
180 +};
181 +
182 +static int ifxmips_wdt_probe(struct platform_device *dev)
183 +{
184 + int err;
185 + err = misc_register(&ifxmips_wdt_miscdev);
186 + if (err)
187 + printk(KERN_INFO "ifxmips_wdt: error creating device\n");
188 + else
189 + printk(KERN_INFO "ifxmips_wdt: loaded\n");
190 + return err;
191 +}
192 +
193 +static int ifxmips_wdt_remove(struct platform_device *dev)
194 +{
195 + ifxmips_wdt_disable();
196 + misc_deregister(&ifxmips_wdt_miscdev);
197 + return 0;
198 +}
199 +
200 +
201 +static struct platform_driver ifxmips_wdt_driver = {
202 + .probe = ifxmips_wdt_probe,
203 + .remove = ifxmips_wdt_remove,
204 + .driver = {
205 + .name = "ifxmips_wdt",
206 + .owner = THIS_MODULE,
207 + },
208 +};
209 +
210 +static int __init init_ifxmips_wdt(void)
211 +{
212 + int ret = platform_driver_register(&ifxmips_wdt_driver);
213 + if (ret)
214 + printk(KERN_INFO "ifxmips_wdt: error registering platfom driver!");
215 + return ret;
216 +}
217 +
218 +static void __exit exit_ifxmips_wdt(void)
219 +{
220 + platform_driver_unregister(&ifxmips_wdt_driver);
221 +}
222 +
223 +module_init(init_ifxmips_wdt);
224 +module_exit(exit_ifxmips_wdt);
225 +
226 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
227 +MODULE_DESCRIPTION("ifxmips Watchdog");
228 +MODULE_LICENSE("GPL");
229 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
This page took 0.050595 seconds and 5 git commands to generate.