2 * mpc8xx_wdt.c - MPC8xx watchdog userspace interface
4 * Copyright (C) 2002 Florian Schirmer <jolt@tuxbox.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/config.h>
23 #include <linux/init.h>
24 #include <linux/kernel.h>
25 #include <linux/miscdevice.h>
26 #include <linux/module.h>
27 #include <linux/watchdog.h>
28 #include <asm/8xx_immap.h>
29 #include <asm/uaccess.h>
31 extern int m8xx_wdt_get_timeout(void);
32 extern void m8xx_wdt_reset(void);
34 static struct semaphore wdt_sem;
35 static int wdt_status;
37 static struct watchdog_info ident = {
38 .identity = "MPC8xx watchdog",
39 .options = WDIOF_KEEPALIVEPING,
43 mpc8xx_wdt_handler_disable(void)
45 volatile immap_t *imap = (volatile immap_t *) IMAP_ADDR;
47 imap->im_sit.sit_piscr &= ~(PISCR_PIE | PISCR_PTE);
49 printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n");
53 mpc8xx_wdt_handler_enable(void)
55 volatile immap_t *imap = (volatile immap_t *) IMAP_ADDR;
57 imap->im_sit.sit_piscr |= PISCR_PIE | PISCR_PTE;
59 printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n");
63 mpc8xx_wdt_open(struct inode *inode, struct file *file)
65 switch (MINOR(inode->i_rdev)) {
67 if (down_trylock(&wdt_sem))
71 mpc8xx_wdt_handler_disable();
82 mpc8xx_wdt_release(struct inode *inode, struct file *file)
86 #if !defined(CONFIG_WATCHDOG_NOWAYOUT)
87 mpc8xx_wdt_handler_enable();
96 mpc8xx_wdt_write(struct file *file, const char *data, size_t len, loff_t * ppos)
98 /* Can't seek (pwrite) on this device */
99 if (ppos != &file->f_pos)
111 mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
112 unsigned int cmd, unsigned long arg)
115 case WDIOC_GETSUPPORT:
116 if (copy_to_user((void *) arg, &ident, sizeof (ident)))
120 case WDIOC_GETSTATUS:
121 case WDIOC_GETBOOTSTATUS:
122 if (put_user(wdt_status, (int *) arg))
124 wdt_status &= ~WDIOF_KEEPALIVEPING;
127 case WDIOC_KEEPALIVE:
129 wdt_status |= WDIOF_KEEPALIVEPING;
132 case WDIOC_GETTIMEOUT:
134 int timeout = m8xx_wdt_get_timeout();
135 if (put_user(timeout, (int *) arg))
147 static struct file_operations mpc8xx_wdt_fops = {
148 .owner = THIS_MODULE,
149 .write = mpc8xx_wdt_write,
150 .ioctl = mpc8xx_wdt_ioctl,
151 .open = mpc8xx_wdt_open,
152 .release = mpc8xx_wdt_release,
155 static struct miscdevice mpc8xx_wdt_miscdev = {
156 .minor = WATCHDOG_MINOR,
158 .fops = &mpc8xx_wdt_fops,
162 mpc8xx_wdt_init(void)
166 sema_init(&wdt_sem, 1);
168 if ((ret = misc_register(&mpc8xx_wdt_miscdev))) {
170 "mpc8xx_wdt: could not register userspace interface\n");
178 mpc8xx_wdt_exit(void)
180 misc_deregister(&mpc8xx_wdt_miscdev);
183 mpc8xx_wdt_handler_enable();
186 module_init(mpc8xx_wdt_init);
187 module_exit(mpc8xx_wdt_exit);
189 MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
190 MODULE_DESCRIPTION("MPC8xx watchdog driver");
191 MODULE_LICENSE("GPL");