21136c0e3c57312d9935cb346130c0e686e1f4a6
[openwrt/staging/yousong.git] / target / linux / brcm47xx / patches-3.6 / 540-watchdog-bcm47xx_wdt.c-convert-to-watchdog-core-api.patch
1 --- a/drivers/watchdog/Kconfig
2 +++ b/drivers/watchdog/Kconfig
3 @@ -959,6 +959,7 @@ config ATH79_WDT
4 config BCM47XX_WDT
5 tristate "Broadcom BCM47xx Watchdog Timer"
6 depends on BCM47XX
7 + select WATCHDOG_CORE
8 help
9 Hardware driver for the Broadcom BCM47xx Watchdog Timer.
10
11 --- a/drivers/watchdog/bcm47xx_wdt.c
12 +++ b/drivers/watchdog/bcm47xx_wdt.c
13 @@ -14,15 +14,12 @@
14
15 #include <linux/bitops.h>
16 #include <linux/errno.h>
17 -#include <linux/fs.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 -#include <linux/miscdevice.h>
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/reboot.h>
24 #include <linux/types.h>
25 -#include <linux/uaccess.h>
26 #include <linux/watchdog.h>
27 #include <linux/timer.h>
28 #include <linux/jiffies.h>
29 @@ -41,15 +38,11 @@ module_param(wdt_time, int, 0);
30 MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
31 __MODULE_STRING(WDT_DEFAULT_TIME) ")");
32
33 -#ifdef CONFIG_WATCHDOG_NOWAYOUT
34 module_param(nowayout, bool, 0);
35 MODULE_PARM_DESC(nowayout,
36 "Watchdog cannot be stopped once started (default="
37 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
38 -#endif
39
40 -static unsigned long bcm47xx_wdt_busy;
41 -static char expect_release;
42 static struct timer_list wdt_timer;
43 static atomic_t ticks;
44
45 @@ -97,29 +90,31 @@ static void bcm47xx_timer_tick(unsigned
46 }
47 }
48
49 -static inline void bcm47xx_wdt_pet(void)
50 +static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd)
51 {
52 atomic_set(&ticks, wdt_time);
53 +
54 + return 0;
55 }
56
57 -static void bcm47xx_wdt_start(void)
58 +static int bcm47xx_wdt_start(struct watchdog_device *wdd)
59 {
60 bcm47xx_wdt_pet();
61 bcm47xx_timer_tick(0);
62 +
63 + return 0;
64 }
65
66 -static void bcm47xx_wdt_pause(void)
67 +static int bcm47xx_wdt_stop(struct watchdog_device *wdd)
68 {
69 del_timer_sync(&wdt_timer);
70 bcm47xx_wdt_hw_stop();
71 -}
72
73 -static void bcm47xx_wdt_stop(void)
74 -{
75 - bcm47xx_wdt_pause();
76 + return 0;
77 }
78
79 -static int bcm47xx_wdt_settimeout(int new_time)
80 +static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd,
81 + unsigned int new_time)
82 {
83 if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
84 return -EINVAL;
85 @@ -128,51 +123,6 @@ static int bcm47xx_wdt_settimeout(int ne
86 return 0;
87 }
88
89 -static int bcm47xx_wdt_open(struct inode *inode, struct file *file)
90 -{
91 - if (test_and_set_bit(0, &bcm47xx_wdt_busy))
92 - return -EBUSY;
93 -
94 - bcm47xx_wdt_start();
95 - return nonseekable_open(inode, file);
96 -}
97 -
98 -static int bcm47xx_wdt_release(struct inode *inode, struct file *file)
99 -{
100 - if (expect_release == 42) {
101 - bcm47xx_wdt_stop();
102 - } else {
103 - pr_crit("Unexpected close, not stopping watchdog!\n");
104 - bcm47xx_wdt_start();
105 - }
106 -
107 - clear_bit(0, &bcm47xx_wdt_busy);
108 - expect_release = 0;
109 - return 0;
110 -}
111 -
112 -static ssize_t bcm47xx_wdt_write(struct file *file, const char __user *data,
113 - size_t len, loff_t *ppos)
114 -{
115 - if (len) {
116 - if (!nowayout) {
117 - size_t i;
118 -
119 - expect_release = 0;
120 -
121 - for (i = 0; i != len; i++) {
122 - char c;
123 - if (get_user(c, data + i))
124 - return -EFAULT;
125 - if (c == 'V')
126 - expect_release = 42;
127 - }
128 - }
129 - bcm47xx_wdt_pet();
130 - }
131 - return len;
132 -}
133 -
134 static const struct watchdog_info bcm47xx_wdt_info = {
135 .identity = DRV_NAME,
136 .options = WDIOF_SETTIMEOUT |
137 @@ -180,80 +130,25 @@ static const struct watchdog_info bcm47x
138 WDIOF_MAGICCLOSE,
139 };
140
141 -static long bcm47xx_wdt_ioctl(struct file *file,
142 - unsigned int cmd, unsigned long arg)
143 -{
144 - void __user *argp = (void __user *)arg;
145 - int __user *p = argp;
146 - int new_value, retval = -EINVAL;
147 -
148 - switch (cmd) {
149 - case WDIOC_GETSUPPORT:
150 - return copy_to_user(argp, &bcm47xx_wdt_info,
151 - sizeof(bcm47xx_wdt_info)) ? -EFAULT : 0;
152 -
153 - case WDIOC_GETSTATUS:
154 - case WDIOC_GETBOOTSTATUS:
155 - return put_user(0, p);
156 -
157 - case WDIOC_SETOPTIONS:
158 - if (get_user(new_value, p))
159 - return -EFAULT;
160 -
161 - if (new_value & WDIOS_DISABLECARD) {
162 - bcm47xx_wdt_stop();
163 - retval = 0;
164 - }
165 -
166 - if (new_value & WDIOS_ENABLECARD) {
167 - bcm47xx_wdt_start();
168 - retval = 0;
169 - }
170 -
171 - return retval;
172 -
173 - case WDIOC_KEEPALIVE:
174 - bcm47xx_wdt_pet();
175 - return 0;
176 -
177 - case WDIOC_SETTIMEOUT:
178 - if (get_user(new_value, p))
179 - return -EFAULT;
180 -
181 - if (bcm47xx_wdt_settimeout(new_value))
182 - return -EINVAL;
183 -
184 - bcm47xx_wdt_pet();
185 -
186 - case WDIOC_GETTIMEOUT:
187 - return put_user(wdt_time, p);
188 -
189 - default:
190 - return -ENOTTY;
191 - }
192 -}
193 -
194 static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
195 - unsigned long code, void *unused)
196 + unsigned long code, void *unused)
197 {
198 if (code == SYS_DOWN || code == SYS_HALT)
199 bcm47xx_wdt_stop();
200 return NOTIFY_DONE;
201 }
202
203 -static const struct file_operations bcm47xx_wdt_fops = {
204 +static struct watchdog_ops bcm47xx_wdt_ops = {
205 .owner = THIS_MODULE,
206 - .llseek = no_llseek,
207 - .unlocked_ioctl = bcm47xx_wdt_ioctl,
208 - .open = bcm47xx_wdt_open,
209 - .release = bcm47xx_wdt_release,
210 - .write = bcm47xx_wdt_write,
211 + .start = bcm47xx_wdt_start,
212 + .stop = bcm47xx_wdt_stop,
213 + .ping = bcm47xx_wdt_keepalive,
214 + .set_timeout = bcm47xx_wdt_set_timeout,
215 };
216
217 -static struct miscdevice bcm47xx_wdt_miscdev = {
218 - .minor = WATCHDOG_MINOR,
219 - .name = "watchdog",
220 - .fops = &bcm47xx_wdt_fops,
221 +static struct watchdog_device bcm47xx_wdt_wdd = {
222 + .info = &bcm47xx_wdt_info,
223 + .ops = &bcm47xx_wdt_ops,
224 };
225
226 static struct notifier_block bcm47xx_wdt_notifier = {
227 @@ -274,12 +169,13 @@ static int __init bcm47xx_wdt_init(void)
228 pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n",
229 (WDT_MAX_TIME + 1), wdt_time);
230 }
231 + watchdog_set_nowayout(&bcm47xx_wdt_wdd, nowayout);
232
233 ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
234 if (ret)
235 return ret;
236
237 - ret = misc_register(&bcm47xx_wdt_miscdev);
238 + ret = watchdog_register_device(&bcm47xx_wdt_wdd);
239 if (ret) {
240 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
241 return ret;
242 @@ -292,10 +188,8 @@ static int __init bcm47xx_wdt_init(void)
243
244 static void __exit bcm47xx_wdt_exit(void)
245 {
246 - if (!nowayout)
247 - bcm47xx_wdt_stop();
248 -
249 - misc_deregister(&bcm47xx_wdt_miscdev);
250 + watchdog_stop(&bcm47xx_wdt_wdd);
251 + watchdog_unregister_device(&bcm47xx_wdt_wdd);
252
253 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
254 }
255 @@ -306,4 +200,3 @@ module_exit(bcm47xx_wdt_exit);
256 MODULE_AUTHOR("Aleksandar Radovanovic");
257 MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
258 MODULE_LICENSE("GPL");
259 -MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);