1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
TS-72xx watchdog driver
Signed-off-by: Matthieu Crapet <mcrapet@gmail.com>
Index: linux-2.6.23-rc5/arch/arm/mach-ep93xx/ts72xx.c
===================================================================
--- linux-2.6.23-rc5.orig/arch/arm/mach-ep93xx/ts72xx.c 2007-09-04 02:25:35.000000000 +0200
+++ linux-2.6.23-rc5/arch/arm/mach-ep93xx/ts72xx.c 2007-09-04 02:27:06.000000000 +0200
@@ -183,6 +183,26 @@
.resource = ts72xx_eth_resource,
};
+static struct resource ts72xx_watchdog_resources[] = {
+ [0] = {
+ .start = TS72XX_WATCHDOG_CONTROL_PHYS_BASE,
+ .end = TS72XX_WATCHDOG_CONTROL_PHYS_BASE + 0x0fff,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = TS72XX_WATCHDOG_FEED_PHYS_BASE,
+ .end = TS72XX_WATCHDOG_FEED_PHYS_BASE + 0x0fff,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device ts72xx_watchdog_device = {
+ .name = "ts72xx_wdt",
+ .id = -1,
+ .num_resources = ARRAY_SIZE(ts72xx_watchdog_resources),
+ .resource = ts72xx_watchdog_resources,
+};
+
static void __init ts72xx_init_machine(void)
{
ep93xx_init_devices();
@@ -193,6 +213,7 @@
memcpy(ts72xx_eth_data.dev_addr,
(void *)(EP93XX_ETHERNET_BASE + 0x50), 6);
platform_device_register(&ts72xx_eth_device);
+ platform_device_register(&ts72xx_watchdog_device);
}
MACHINE_START(TS72XX, "Technologic Systems TS-72xx SBC")
Index: linux-2.6.23-rc5/drivers/char/watchdog/Kconfig
===================================================================
--- linux-2.6.23-rc5.orig/drivers/char/watchdog/Kconfig 2007-09-04 02:25:35.000000000 +0200
+++ linux-2.6.23-rc5/drivers/char/watchdog/Kconfig 2007-09-04 02:27:06.000000000 +0200
@@ -247,6 +247,18 @@
# H8300 Architecture
+config TS72XX_WATCHDOG
+ tristate "TS-72xx Watchdog"
+ depends on WATCHDOG && ARCH_EP93XX && MACH_TS72XX
+ help
+ Say Y here if to include support for the CPLD watchdog
+ included on Technologic Systems SBC.
+
+ NOTE: timeout value is given in milliseconds, not in seconds.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ts72xx_wdt.
+
# X86 (i386 + ia64 + x86_64) Architecture
config ACQUIRE_WDT
Index: linux-2.6.23-rc5/drivers/char/watchdog/Makefile
===================================================================
--- linux-2.6.23-rc5.orig/drivers/char/watchdog/Makefile 2007-09-04 02:25:35.000000000 +0200
+++ linux-2.6.23-rc5/drivers/char/watchdog/Makefile 2007-09-04 02:27:06.000000000 +0200
@@ -36,6 +36,7 @@
obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o
obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o
obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
+obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o
obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o
obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
Index: linux-2.6.23-rc5/drivers/char/watchdog/ts72xx_wdt.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.23-rc5/drivers/char/watchdog/ts72xx_wdt.c 2007-09-04 02:27:06.000000000 +0200
@@ -0,0 +1,332 @@
+/*
+ * TS-72xx Watchdog Driver for Technologic Systems boards.
+ *
+ * Based on ep93xx_wdt.c by Lehtiniemi <rayl@mail.com> &
+ * Alessandro Zummo <a.zummo@towertech.it>
+ * and ib700wdt.c by Charles Howes <chowes@vsol.net>
+ * and mpc83xx_wdt.c by Dave Updegraff <dave@cray.org> &
+ * Kumar Gala <galak@kernel.crashing.org>
+ *
+ * (c) Copyright 2006 Matthieu Crapet <mcrapet@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * This driver only deals with native timeout provided by CPLD :
+ * 1/4s, 1/2s, 1s, 2s, 4s and 8s. No external timer is used.
+ * Notice that we must ping before modifying the control register.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/watchdog.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <asm/mach-types.h>
+
+#define WATCHDOG_VERSION "0.2"
+#define PFX "ts72xx_wdt: "
+
+#define WATCHDOG_TIMEOUT 8000 /* 8 seconds */
+#define WDT_IN_USE 0
+#define WDT_OK_TO_CLOSE 1
+
+static unsigned long ts72xx_wdt_status;
+static unsigned char ts72xx_wdt_cpld_value = 0x7;
+static int nowayout = WATCHDOG_NOWAYOUT;
+static int timeout = WATCHDOG_TIMEOUT;
+
+static int ts72xx_wdt_times[12] = {
+ 6000, 3000, 1500, 750, 275, 0,
+ 8000, 4000, 2000, 1000, 500, 250
+};
+
+static void __iomem *control_register;
+static void __iomem *feed_register;
+
+
+/*
+ * Kernel methods.
+ */
+
+static inline void ts72xx_wdt_ping(void)
+{
+ __raw_writew(0x05, feed_register);
+}
+
+static inline void ts72xx_wdt_enable(void)
+{
+ __raw_writew(0x05, feed_register);
+ __raw_writew(ts72xx_wdt_cpld_value, control_register);
+}
+
+static inline void ts72xx_wdt_disable(void)
+{
+ __raw_writew(0x05, feed_register);
+ __raw_writew(0, control_register);
+}
+
+static inline void ts72xx_parse_timeout(int value)
+{
+ unsigned char cpld_value = 0x7;
+ int i;
+
+ if ((value > 8000) || (value < 250)) {
+ timeout = WATCHDOG_TIMEOUT;
+ printk(KERN_INFO PFX "Timeout value out of range, set to %d\n", timeout);
+ } else {
+ for (i = 0; i < 6; i++) {
+ if (value >= ts72xx_wdt_times[i]) {
+ timeout = ts72xx_wdt_times[i+6];
+
+ if (value != timeout)
+ printk(KERN_INFO PFX "Timeout value rounded to %d\n", timeout);
+
+ if (i >= 3) /* cpld_value can't be 4 */
+ i++;
+
+ cpld_value = 7 - i;
+ break;
+ }
+ }
+ }
+
+ ts72xx_wdt_cpld_value = cpld_value;
+}
+
+static ssize_t ts72xx_wdt_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ /* Can't seek (pwrite) on this device */
+ if (*ppos != file->f_pos)
+ return -ESPIPE;
+
+ if (count) {
+ if (!nowayout) {
+ size_t i;
+
+ clear_bit(WDT_OK_TO_CLOSE, &ts72xx_wdt_status);
+
+ for (i = 0; i != count; i++) {
+ char c;
+
+ if (get_user(c, buf + i))
+ return -EFAULT;
+
+ if (c == 'V')
+ set_bit(WDT_OK_TO_CLOSE, &ts72xx_wdt_status);
+ else
+ clear_bit(WDT_OK_TO_CLOSE, &ts72xx_wdt_status);
+ }
+ }
+ ts72xx_wdt_ping();
+ }
+
+ return count;
+}
+
+static int ts72xx_wdt_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ int new_margin;
+ int ret = -ENOIOCTLCMD;
+
+ static struct watchdog_info ident = {
+ .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+ .firmware_version = 1,
+ .identity = "TS-72xx Watchdog",
+ };
+
+ switch (cmd) {
+ case WDIOC_GETSUPPORT:
+ ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
+ sizeof(ident)) ? -EFAULT : 0;
+ break;
+
+ case WDIOC_GETSTATUS:
+ case WDIOC_GETBOOTSTATUS:
+ ret = put_user(0, (int __user *)arg);
+ break;
+
+ case WDIOC_KEEPALIVE:
+ ts72xx_wdt_ping();
+ ret = 0;
+ break;
+
+ case WDIOC_SETTIMEOUT:
+ if (get_user(new_margin, (int __user *)arg))
+ return -EFAULT;
+
+ ts72xx_parse_timeout(new_margin);
+ ts72xx_wdt_enable();
+ /* Fall */
+
+ case WDIOC_GETTIMEOUT:
+ ret = put_user(timeout, (int __user *)arg);
+ break;
+ }
+
+ return ret;
+}
+
+static int ts72xx_wdt_open(struct inode *inode, struct file *file)
+{
+ if (test_and_set_bit(WDT_IN_USE, &ts72xx_wdt_status))
+ return -EBUSY;
+
+ if (nowayout) {
+ __module_get(THIS_MODULE);
+ }
+
+ ts72xx_wdt_enable();
+ ts72xx_wdt_ping();
+
+ return nonseekable_open(inode, file);
+}
+
+static int ts72xx_wdt_close(struct inode *inode, struct file *file)
+{
+ if (test_bit(WDT_OK_TO_CLOSE, &ts72xx_wdt_status))
+ ts72xx_wdt_disable();
+ else
+ printk(KERN_CRIT PFX "Device file closed unexpectedly. "
+ "Will not stop the WDT!\n");
+
+ clear_bit(WDT_IN_USE, &ts72xx_wdt_status);
+
+ return 0;
+}
+
+/*
+ * Kernel Interfaces
+ */
+
+static struct file_operations ts72xx_wdt_fops = {
+ .owner = THIS_MODULE,
+ .llseek = no_llseek,
+ .write = ts72xx_wdt_write,
+ .ioctl = ts72xx_wdt_ioctl,
+ .open = ts72xx_wdt_open,
+ .release = ts72xx_wdt_close,
+};
+
+static struct miscdevice ts72xx_wdt_miscdev = {
+ .minor = WATCHDOG_MINOR,
+ .name = "watchdog",
+ .fops = &ts72xx_wdt_fops,
+};
+
+static void ts72xx_wdt_shutdown(struct platform_device *dev)
+{
+ ts72xx_wdt_disable();
+}
+
+static int __devinit ts72xx_wdt_probe(struct platform_device *dev)
+{
+ struct resource *r;
+ int ret;
+
+ if (!machine_is_ts72xx())
+ return -ENODEV;
+
+ r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+
+ if (!r) {
+ ret = -ENODEV;
+ goto err_out;
+ }
+
+ control_register = ioremap(r->start, r->end - r->start + 1);
+
+ if (control_register == NULL) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
+
+ r = platform_get_resource(dev, IORESOURCE_MEM, 1);
+
+ if (!r) {
+ ret = -ENODEV;
+ goto err_unmap1;
+ }
+
+ feed_register = ioremap(r->start, r->end - r->start + 1);
+
+ if (feed_register == NULL) {
+ ret = -ENOMEM;
+ goto err_unmap1;
+ }
+
+ ret = misc_register(&ts72xx_wdt_miscdev);
+ if (ret) {
+ printk(KERN_ERR PFX "cannot register miscdev on minor=%d "
+ "(err=%d), ep93xx_watchdog already loaded?!\n", WATCHDOG_MINOR, ret);
+ goto err_unmap2;
+ }
+
+ printk(KERN_INFO PFX "TS-72xx watchdog driver, v%s\n", WATCHDOG_VERSION);
+ ts72xx_parse_timeout(timeout);
+
+ return 0;
+
+err_unmap2:
+ iounmap(feed_register);
+err_unmap1:
+ iounmap(control_register);
+err_out:
+ return ret;
+}
+
+static int __devexit ts72xx_wdt_remove(struct platform_device *dev)
+{
+ misc_deregister(&ts72xx_wdt_miscdev);
+ iounmap(feed_register);
+ iounmap(control_register);
+
+ return 0;
+}
+
+static struct platform_driver ts72xx_wdt_driver = {
+ .probe = ts72xx_wdt_probe,
+ .remove = __devexit_p(ts72xx_wdt_remove),
+ .shutdown = ts72xx_wdt_shutdown,
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "ts72xx_wdt",
+ },
+};
+
+static int __init ts72xx_wdt_init(void)
+{
+ return platform_driver_register(&ts72xx_wdt_driver);
+}
+
+static void __exit ts72xx_wdt_exit(void)
+{
+ platform_driver_unregister(&ts72xx_wdt_driver);
+}
+
+module_init(ts72xx_wdt_init);
+module_exit(ts72xx_wdt_exit);
+
+#ifdef CONFIG_WATCHDOG_NOWAYOUT
+module_param(nowayout, int, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
+#endif
+
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout,"Watchdog timeout in milliseconds (250..8000, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
+
+MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>");
+MODULE_DESCRIPTION("TS-72xx watchdog driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Index: linux-2.6.23-rc5/include/asm-arm/arch-ep93xx/ts72xx.h
===================================================================
--- linux-2.6.23-rc5.orig/include/asm-arm/arch-ep93xx/ts72xx.h 2007-09-04 02:25:35.000000000 +0200
+++ linux-2.6.23-rc5/include/asm-arm/arch-ep93xx/ts72xx.h 2007-09-04 02:27:06.000000000 +0200
@@ -69,6 +69,9 @@
#define TS72XX_RTC_DATA_SIZE 0x00001000
+#define TS72XX_WATCHDOG_CONTROL_PHYS_BASE 0x23800000
+#define TS72XX_WATCHDOG_FEED_PHYS_BASE 0x23c00000
+
#ifndef __ASSEMBLY__
#include <asm/io.h>
|