1 diff -ruN linux-2.4.30-patch006/drivers/char/ar7_wdt.c linux-2.4.30-patch007/drivers/char/ar7_wdt.c
2 --- linux-2.4.30-patch006/drivers/char/ar7_wdt.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.4.30-patch007/drivers/char/ar7_wdt.c 2005-10-27 09:39:40.000000000 +0200
5 +/* linux/drivers/char/ar7_wdt.c
7 + TI AR7 watch dog timer support
9 + Copyright (c) 2005 Enrik Berkhan <Enrik.Berkhan@akk.org>
11 + Som code taken from:
12 + National Semiconductor SCx200 Watchdog support
13 + Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
15 + This program is free software; you can redistribute it and/or
16 + modify it under the terms of the GNU General Public License as
17 + published by the Free Software Foundation; either version 2 of the
18 + License, or (at your option) any later version.
20 + The author(s) of this software shall not be held liable for damages
21 + of any nature resulting due to the use of this software. This
22 + software is provided AS-IS with no warranties. */
24 +#include <linux/config.h>
25 +#include <linux/module.h>
26 +#include <linux/errno.h>
27 +#include <linux/kernel.h>
28 +#include <linux/init.h>
29 +#include <linux/miscdevice.h>
30 +#include <linux/watchdog.h>
31 +#include <linux/notifier.h>
32 +#include <linux/reboot.h>
33 +#include <linux/ioport.h>
35 +#include <asm/uaccess.h>
37 +#include <asm/ar7/avalanche_misc.h>
38 +#include <asm/ar7/sangam.h>
40 +#define NAME "ar7_wdt"
41 +#define LONGNAME "TI AR7 Watchdog Timer"
43 +MODULE_AUTHOR("Enrik Berkhan <Enrik.Berkhan@akk.org>");
44 +MODULE_DESCRIPTION(LONGNAME);
45 +MODULE_LICENSE("GPL");
47 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
48 +#define CONFIG_WATCHDOG_NOWAYOUT 0
51 +static int margin = 60;
52 +MODULE_PARM(margin, "i");
53 +MODULE_PARM_DESC(margin, "Watchdog margin in seconds (1 - ~68)");
55 +static int nowayout = CONFIG_WATCHDOG_NOWAYOUT;
56 +MODULE_PARM(nowayout, "i");
57 +MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
62 + uint32_t change_lock;
64 + uint32_t disable_lock;
66 + uint32_t prescale_lock;
70 +volatile ar7_wdt_t *ar7_wdt = (ar7_wdt_t *)AVALANCHE_WATCHDOG_TIMER_BASE;
72 +static struct semaphore open_semaphore;
73 +static unsigned expect_close;
75 +/* XXX correct? assumed to be sysfreq/2. get this dynamically ... */
76 +#define vbus_freq 62500000
78 +/* XXX currently fixed, allows max margin ~68.72 secs */
79 +#define prescale_value 0xFFFF
81 +static void ar7_wdt_kick(uint32_t value)
83 + ar7_wdt->kick_lock = 0x5555;
84 + if ((ar7_wdt->kick_lock & 3) == 1) {
85 + ar7_wdt->kick_lock = 0xAAAA;
86 + if ((ar7_wdt->kick_lock & 3) == 3) {
87 + ar7_wdt->kick = value;
91 + printk(KERN_ERR NAME "failed to unlock WDT kick reg\n");
94 +static void ar7_wdt_prescale(uint32_t value)
96 + ar7_wdt->prescale_lock = 0x5A5A;
97 + if ((ar7_wdt->prescale_lock & 3) == 1) {
98 + ar7_wdt->prescale_lock = 0xA5A5;
99 + if ((ar7_wdt->prescale_lock & 3) == 3) {
100 + ar7_wdt->prescale = value;
104 + printk(KERN_ERR NAME "failed to unlock WDT prescale reg\n");
107 +static void ar7_wdt_change(uint32_t value)
109 + ar7_wdt->change_lock = 0x6666;
110 + if ((ar7_wdt->change_lock & 3) == 1) {
111 + ar7_wdt->change_lock = 0xBBBB;
112 + if ((ar7_wdt->change_lock & 3) == 3) {
113 + ar7_wdt->change = value;
117 + printk(KERN_ERR NAME "failed to unlock WDT change reg\n");
120 +static void ar7_wdt_disable(uint32_t value)
122 + ar7_wdt->disable_lock = 0x7777;
123 + if ((ar7_wdt->disable_lock & 3) == 1) {
124 + ar7_wdt->disable_lock = 0xCCCC;
125 + if ((ar7_wdt->disable_lock & 3) == 2) {
126 + ar7_wdt->disable_lock = 0xDDDD;
127 + if ((ar7_wdt->disable_lock & 3) == 3) {
128 + ar7_wdt->disable = value;
133 + printk(KERN_ERR NAME "failed to unlock WDT disable reg\n");
137 +static void ar7_wdt_update_margin(int new_margin)
141 + change = new_margin * (vbus_freq / prescale_value);
142 + if (change < 1) change = 1;
143 + if (change > 0xFFFF) change = 0xFFFF;
144 + ar7_wdt_change(change);
145 + margin = change * prescale_value / vbus_freq;
146 + printk(KERN_INFO NAME
147 + ": timer margin %d seconds (prescale %d, change %d, freq %d)\n",
148 + margin, prescale_value, change, vbus_freq);
151 +static void ar7_wdt_enable_wdt(void)
153 + printk(KERN_DEBUG NAME ": enabling watchdog timer\n");
154 + ar7_wdt_disable(1);
158 +static void ar7_wdt_disable_wdt(void)
160 + printk(KERN_DEBUG NAME ": disabling watchdog timer\n");
161 + ar7_wdt_disable(0);
164 +static int ar7_wdt_open(struct inode *inode, struct file *file)
166 + /* only allow one at a time */
167 + if (down_trylock(&open_semaphore))
169 + ar7_wdt_enable_wdt();
175 +static int ar7_wdt_release(struct inode *inode, struct file *file)
177 + if (!expect_close) {
178 + printk(KERN_WARNING NAME ": watchdog device closed unexpectedly, will not disable the watchdog timer\n");
179 + } else if (!nowayout) {
180 + ar7_wdt_disable_wdt();
182 + up(&open_semaphore);
187 +static int ar7_wdt_notify_sys(struct notifier_block *this,
188 + unsigned long code, void *unused)
190 + if (code == SYS_HALT || code == SYS_POWER_OFF)
192 + ar7_wdt_disable_wdt();
194 + return NOTIFY_DONE;
197 +static struct notifier_block ar7_wdt_notifier =
199 + .notifier_call = ar7_wdt_notify_sys
202 +static ssize_t ar7_wdt_write(struct file *file, const char *data,
203 + size_t len, loff_t *ppos)
205 + if (ppos != &file->f_pos)
208 + /* check for a magic close character */
216 + for (i = 0; i < len; ++i) {
218 + if (get_user(c, data+i))
228 +static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
229 + unsigned int cmd, unsigned long arg)
231 + static struct watchdog_info ident = {
232 + .identity = LONGNAME,
233 + .firmware_version = 1,
234 + .options = (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING),
241 + case WDIOC_GETSUPPORT:
242 + if(copy_to_user((struct watchdog_info *)arg, &ident,
246 + case WDIOC_GETSTATUS:
247 + case WDIOC_GETBOOTSTATUS:
248 + if (put_user(0, (int *)arg))
251 + case WDIOC_KEEPALIVE:
254 + case WDIOC_SETTIMEOUT:
255 + if (get_user(new_margin, (int *)arg))
257 + if (new_margin < 1)
260 + ar7_wdt_update_margin(new_margin);
263 + case WDIOC_GETTIMEOUT:
264 + if (put_user(margin, (int *)arg))
270 +static struct file_operations ar7_wdt_fops = {
271 + .owner = THIS_MODULE,
272 + .write = ar7_wdt_write,
273 + .ioctl = ar7_wdt_ioctl,
274 + .open = ar7_wdt_open,
275 + .release = ar7_wdt_release,
278 +static struct miscdevice ar7_wdt_miscdev = {
279 + .minor = WATCHDOG_MINOR,
280 + .name = "watchdog",
281 + .fops = &ar7_wdt_fops,
284 +static __initdata char *last_initiator[] = {
285 + [HARDWARE_RESET] = "hardware reset",
286 + [SOFTWARE_RESET0] = "SW0 software reset",
287 + [SOFTWARE_RESET1] = "SW1 software reset",
288 + [WATCHDOG_RESET] = "watchdog"
291 +static int __init ar7_wdt_init(void)
295 + if (!request_mem_region(AVALANCHE_WATCHDOG_TIMER_BASE,
296 + sizeof(ar7_wdt_t), LONGNAME)) {
297 + printk(KERN_WARNING NAME ": watchdog I/O region busy\n");
301 + printk(KERN_INFO NAME ": last system reset initiated by %s\n",
302 + last_initiator[avalanche_get_sys_last_reset_status()]);
305 + ar7_wdt_disable_wdt();
306 + ar7_wdt_prescale(prescale_value);
307 + ar7_wdt_update_margin(margin);
309 + sema_init(&open_semaphore, 1);
311 + r = misc_register(&ar7_wdt_miscdev);
313 + printk(KERN_ERR NAME ": unable to register misc device\n");
314 + release_mem_region(AVALANCHE_WATCHDOG_TIMER_BASE,
315 + sizeof(ar7_wdt_t));
319 + r = register_reboot_notifier(&ar7_wdt_notifier);
321 + printk(KERN_ERR NAME ": unable to register reboot notifier\n");
322 + misc_deregister(&ar7_wdt_miscdev);
323 + release_mem_region(AVALANCHE_WATCHDOG_TIMER_BASE,
324 + sizeof(ar7_wdt_t));
331 +static void __exit ar7_wdt_cleanup(void)
333 + unregister_reboot_notifier(&ar7_wdt_notifier);
334 + misc_deregister(&ar7_wdt_miscdev);
335 + release_mem_region(AVALANCHE_WATCHDOG_TIMER_BASE, sizeof(ar7_wdt_t));
338 +module_init(ar7_wdt_init);
339 +module_exit(ar7_wdt_cleanup);
340 diff -ruN linux-2.4.30-patch006/drivers/char/Config.in linux-2.4.30-patch007/drivers/char/Config.in
341 --- linux-2.4.30-patch006/drivers/char/Config.in 2005-10-27 11:25:29.000000000 +0200
342 +++ linux-2.4.30-patch007/drivers/char/Config.in 2005-10-27 11:17:32.000000000 +0200
344 bool 'Watchdog Timer Support' CONFIG_WATCHDOG
345 if [ "$CONFIG_WATCHDOG" != "n" ]; then
346 bool ' Disable watchdog shutdown on close' CONFIG_WATCHDOG_NOWAYOUT
347 + if [ "$CONFIG_AR7" = "y" ] ; then
348 + tristate ' TI AR7 Watchdog Timer' CONFIG_AR7_WDT
350 tristate ' Acquire SBC Watchdog Timer' CONFIG_ACQUIRE_WDT
351 tristate ' Advantech SBC Watchdog Timer' CONFIG_ADVANTECH_WDT
352 tristate ' ALi M7101 PMU on ALi 1535D+ Watchdog Timer' CONFIG_ALIM1535_WDT
354 tristate ' SBC-60XX Watchdog Timer' CONFIG_60XX_WDT
355 dep_tristate ' SC1200 Watchdog Timer (EXPERIMENTAL)' CONFIG_SC1200_WDT $CONFIG_EXPERIMENTAL
356 tristate ' NatSemi SCx200 Watchdog' CONFIG_SCx200_WDT
357 - tristate ' Software Watchdog' CONFIG_SOFT_WATCHDOG
358 tristate ' W83877F (EMACS) Watchdog Timer' CONFIG_W83877F_WDT
359 tristate ' WDT Watchdog timer' CONFIG_WDT
360 tristate ' WDT PCI Watchdog timer' CONFIG_WDTPCI
364 tristate ' ZF MachZ Watchdog' CONFIG_MACHZ_WDT
366 + tristate ' Software Watchdog' CONFIG_SOFT_WATCHDOG
367 if [ "$CONFIG_SGI_IP22" = "y" ]; then
368 dep_tristate ' Indy/I2 Hardware Watchdog' CONFIG_INDYDOG $CONFIG_SGI_IP22
370 diff -ruN linux-2.4.30-patch006/drivers/char/Makefile linux-2.4.30-patch007/drivers/char/Makefile
371 --- linux-2.4.30-patch006/drivers/char/Makefile 2005-10-27 11:19:38.000000000 +0200
372 +++ linux-2.4.30-patch007/drivers/char/Makefile 2005-10-27 09:39:40.000000000 +0200
374 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
375 obj-$(CONFIG_INDYDOG) += indydog.o
376 obj-$(CONFIG_8xx_WDT) += mpc8xx_wdt.o
377 +obj-$(CONFIG_AR7_WDT) += ar7_wdt.o
379 subdir-$(CONFIG_MWAVE) += mwave
380 ifeq ($(CONFIG_MWAVE),y)
381 diff -ruN linux-2.4.30-patch006/include/asm-mips/ar7/sangam.h linux-2.4.30-patch007/include/asm-mips/ar7/sangam.h
382 --- linux-2.4.30-patch006/include/asm-mips/ar7/sangam.h 2005-10-27 11:25:51.000000000 +0200
383 +++ linux-2.4.30-patch007/include/asm-mips/ar7/sangam.h 2005-10-27 11:13:37.000000000 +0200
385 #define AVALANCHE_EMIF_SDRAM_CFG (AVALANCHE_EMIF_CONTROL_BASE + 0x8)
386 #define AVALANCHE_RST_CTRL_PRCR (KSEG1ADDR(0x08611600))
387 #define AVALANCHE_RST_CTRL_SWRCR (KSEG1ADDR(0x08611604))
388 -#define AVALANCHE_RST_CTRL_RSR (KSEG1ADDR(0x08611600))
389 +#define AVALANCHE_RST_CTRL_RSR (KSEG1ADDR(0x08611608))
391 #define AVALANCHE_POWER_CTRL_PDCR (KSEG1ADDR(0x08610A00))
392 #define AVALANCHE_WAKEUP_CTRL_WKCR (KSEG1ADDR(0x08610A0C))