2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * Copyright (C) 2008 John Crispin <blogic@openwrt.org>
17 * Based on EP93xx and ifxmips wdt driver
20 #include <linux/interrupt.h>
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/types.h>
24 #include <linux/miscdevice.h>
25 #include <linux/watchdog.h>
27 #include <linux/ioport.h>
28 #include <linux/notifier.h>
29 #include <linux/reboot.h>
30 #include <linux/init.h>
31 #include <linux/platform_device.h>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/addrspace.h>
39 #define CLOCK_RATE 40000000
40 #define HEARTBEAT(x) (x < 1 || x > 90)?(20):(x)
42 static int wdt_timeout
= 20;
43 static int started
= 0;
44 static int in_use
= 0;
47 ar2315_wdt_enable(void)
49 sysRegWrite(AR5315_WD
, wdt_timeout
* CLOCK_RATE
);
50 sysRegWrite(AR5315_ISR
, 0x80);
54 ar2315_wdt_write(struct file
*file
, const char __user
*data
, size_t len
, loff_t
*ppos
)
62 ar2315_wdt_open(struct inode
*inode
, struct file
*file
)
68 return nonseekable_open(inode
, file
);
72 ar2315_wdt_release(struct inode
*inode
, struct file
*file
)
79 ar2315_wdt_interrupt(int irq
, void *dev_id
)
83 printk(KERN_CRIT
"watchdog expired, rebooting system\n");
86 sysRegWrite(AR5315_WDC
, 0);
87 sysRegWrite(AR5315_WD
, 0);
88 sysRegWrite(AR5315_ISR
, 0x80);
93 static struct watchdog_info ident
= {
94 .options
= WDIOF_SETTIMEOUT
| WDIOF_KEEPALIVEPING
,
95 .identity
= "ar2315 Watchdog",
99 ar2315_wdt_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
102 int ret
= -ENOIOCTLCMD
;
106 case WDIOC_GETSUPPORT
:
107 ret
= copy_to_user((struct watchdog_info __user
*)arg
, &ident
, sizeof(ident
)) ? -EFAULT
: 0;
110 case WDIOC_KEEPALIVE
:
115 case WDIOC_SETTIMEOUT
:
116 if((ret
= get_user(new_wdt_timeout
, (int __user
*)arg
)))
118 wdt_timeout
= HEARTBEAT(new_wdt_timeout
);
122 case WDIOC_GETTIMEOUT
:
123 ret
= put_user(wdt_timeout
, (int __user
*)arg
);
129 static struct file_operations ar2315_wdt_fops
= {
130 .owner
= THIS_MODULE
,
132 .write
= ar2315_wdt_write
,
133 .ioctl
= ar2315_wdt_ioctl
,
134 .open
= ar2315_wdt_open
,
135 .release
= ar2315_wdt_release
,
138 static struct miscdevice ar2315_wdt_miscdev
= {
139 .minor
= WATCHDOG_MINOR
,
141 .fops
= &ar2315_wdt_fops
,
145 ar2315_wdt_probe(struct platform_device
*dev
)
150 ret
= request_irq(AR531X_MISC_IRQ_WATCHDOG
, ar2315_wdt_interrupt
, IRQF_DISABLED
, "ar2315_wdt", NULL
);
153 printk(KERN_ERR
"ar2315wdt: failed to register inetrrupt\n");
157 ret
= misc_register(&ar2315_wdt_miscdev
);
159 printk(KERN_ERR
"ar2315wdt: failed to register miscdev\n");
166 ar2315_wdt_remove(struct platform_device
*dev
)
168 misc_deregister(&ar2315_wdt_miscdev
);
169 free_irq(AR531X_MISC_IRQ_WATCHDOG
, NULL
);
173 static struct platform_driver ar2315_wdt_driver
= {
174 .probe
= ar2315_wdt_probe
,
175 .remove
= ar2315_wdt_remove
,
177 .name
= "ar2315_wdt",
178 .owner
= THIS_MODULE
,
183 init_ar2315_wdt(void)
185 int ret
= platform_driver_register(&ar2315_wdt_driver
);
187 printk(KERN_INFO
"ar2315_wdt: error registering platfom driver!");
192 exit_ar2315_wdt(void)
194 platform_driver_unregister(&ar2315_wdt_driver
);
197 module_init(init_ar2315_wdt
);
198 module_exit(exit_ar2315_wdt
);