2 * mpc83xx_wdt.c - MPC83xx watchdog userspace interface
4 * Authors: Dave Updegraff <dave@cray.org>
5 * Kumar Gala <galak@kernel.crashing.org>
6 * Attribution: from 83xx_wst: Florian Schirmer <jolt@tuxbox.org>
9 * Note: it appears that you can only actually ENABLE or DISABLE the thing
10 * once after POR. Once enabled, you cannot disable, and vice versa.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/miscdevice.h>
22 #include <linux/platform_device.h>
23 #include <linux/module.h>
24 #include <linux/watchdog.h>
26 #include <linux/uaccess.h>
30 __be32 swcrr; /* System watchdog control register */
31 #define SWCRR_SWTC 0xFFFF0000 /* Software Watchdog Time Count. */
32 #define SWCRR_SWEN 0x00000004 /* Watchdog Enable bit. */
33 #define SWCRR_SWRI 0x00000002 /* Software Watchdog Reset/Interrupt Select bit.*/
34 #define SWCRR_SWPR 0x00000001 /* Software Watchdog Counter Prescale bit. */
35 __be32 swcnr; /* System watchdog count register */
37 __be16 swsrr; /* System watchdog service register */
41 static struct mpc83xx_wdt __iomem *wd_base;
43 static u16 timeout = 0xffff;
44 module_param(timeout, ushort, 0);
45 MODULE_PARM_DESC(timeout,
46 "Watchdog timeout in ticks. (0<timeout<65536, default=65535");
49 module_param(reset, bool, 0);
50 MODULE_PARM_DESC(reset,
51 "Watchdog Interrupt/Reset Mode. 0 = interrupt, 1 = reset");
54 * We always prescale, but if someone really doesn't want to they can set this
57 static int prescale = 1;
58 static unsigned int timeout_sec;
60 static unsigned long wdt_is_open;
61 static DEFINE_SPINLOCK(wdt_spinlock);
63 static void mpc83xx_wdt_keepalive(void)
66 spin_lock(&wdt_spinlock);
67 out_be16(&wd_base->swsrr, 0x556c);
68 out_be16(&wd_base->swsrr, 0xaa39);
69 spin_unlock(&wdt_spinlock);
72 static ssize_t mpc83xx_wdt_write(struct file *file, const char __user *buf,
73 size_t count, loff_t *ppos)
76 mpc83xx_wdt_keepalive();
80 static int mpc83xx_wdt_open(struct inode *inode, struct file *file)
83 if (test_and_set_bit(0, &wdt_is_open))
86 /* Once we start the watchdog we can't stop it */
87 __module_get(THIS_MODULE);
89 /* Good, fire up the show */
97 out_be32(&wd_base->swcrr, tmp);
99 return nonseekable_open(inode, file);
102 static int mpc83xx_wdt_release(struct inode *inode, struct file *file)
104 printk(KERN_CRIT "Unexpected close, not stopping watchdog!\n");
105 mpc83xx_wdt_keepalive();
106 clear_bit(0, &wdt_is_open);
110 static long mpc83xx_wdt_ioctl(struct file *file, unsigned int cmd,
113 void __user *argp = (void __user *)arg;
114 int __user *p = argp;
115 static struct watchdog_info ident = {
116 .options = WDIOF_KEEPALIVEPING,
117 .firmware_version = 1,
118 .identity = "MPC83xx",
122 case WDIOC_GETSUPPORT:
123 return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
124 case WDIOC_GETSTATUS:
125 case WDIOC_GETBOOTSTATUS:
126 return put_user(0, p);
127 case WDIOC_KEEPALIVE:
128 mpc83xx_wdt_keepalive();
130 case WDIOC_GETTIMEOUT:
131 return put_user(timeout_sec, p);
137 static const struct file_operations mpc83xx_wdt_fops = {
138 .owner = THIS_MODULE,
140 .write = mpc83xx_wdt_write,
141 .unlocked_ioctl = mpc83xx_wdt_ioctl,
142 .open = mpc83xx_wdt_open,
143 .release = mpc83xx_wdt_release,
146 static struct miscdevice mpc83xx_wdt_miscdev = {
147 .minor = WATCHDOG_MINOR,
149 .fops = &mpc83xx_wdt_fops,
152 static int __devinit mpc83xx_wdt_probe(struct platform_device *dev)
156 unsigned int *freq = dev->dev.platform_data;
158 /* get a pointer to the register memory */
159 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
166 wd_base = ioremap(r->start, sizeof(struct mpc83xx_wdt));
167 if (wd_base == NULL) {
172 ret = misc_register(&mpc83xx_wdt_miscdev);
174 printk(KERN_ERR "cannot register miscdev on minor=%d "
176 WATCHDOG_MINOR, ret);
180 /* Calculate the timeout in seconds */
182 timeout_sec = (timeout * 0x10000) / (*freq);
184 timeout_sec = timeout / (*freq);
186 printk(KERN_INFO "WDT driver for MPC83xx initialized. "
187 "mode:%s timeout=%d (%d seconds)\n",
188 reset ? "reset":"interrupt", timeout, timeout_sec);
197 static int __devexit mpc83xx_wdt_remove(struct platform_device *dev)
199 misc_deregister(&mpc83xx_wdt_miscdev);
205 static struct platform_driver mpc83xx_wdt_driver = {
206 .probe = mpc83xx_wdt_probe,
207 .remove = __devexit_p(mpc83xx_wdt_remove),
209 .name = "mpc83xx_wdt",
210 .owner = THIS_MODULE,
214 static int __init mpc83xx_wdt_init(void)
216 return platform_driver_register(&mpc83xx_wdt_driver);
219 static void __exit mpc83xx_wdt_exit(void)
221 platform_driver_unregister(&mpc83xx_wdt_driver);
224 module_init(mpc83xx_wdt_init);
225 module_exit(mpc83xx_wdt_exit);
227 MODULE_AUTHOR("Dave Updegraff, Kumar Gala");
228 MODULE_DESCRIPTION("Driver for watchdog timer in MPC83xx uProcessor");
229 MODULE_LICENSE("GPL");
230 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
231 MODULE_ALIAS("platform:mpc83xx_wdt");