[PATCH] aic7xxx_osm build fix
[cris-mirror.git] / drivers / char / watchdog / mpc8xx_wdt.c
blob56d62ba7c6ce37218a6f3fbc3604f30acf24682d
1 /*
2 * mpc8xx_wdt.c - MPC8xx watchdog userspace interface
4 * Author: Florian Schirmer <jolt@tuxbox.org>
6 * 2002 (c) Florian Schirmer <jolt@tuxbox.org> This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
12 #include <linux/config.h>
13 #include <linux/fs.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/miscdevice.h>
17 #include <linux/module.h>
18 #include <linux/watchdog.h>
19 #include <asm/8xx_immap.h>
20 #include <asm/uaccess.h>
21 #include <syslib/m8xx_wdt.h>
23 static unsigned long wdt_opened;
24 static int wdt_status;
26 static void mpc8xx_wdt_handler_disable(void)
28 volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
30 imap->im_sit.sit_piscr &= ~(PISCR_PIE | PISCR_PTE);
32 printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n");
35 static void mpc8xx_wdt_handler_enable(void)
37 volatile immap_t *imap = (volatile immap_t *)IMAP_ADDR;
39 imap->im_sit.sit_piscr |= PISCR_PIE | PISCR_PTE;
41 printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n");
44 static int mpc8xx_wdt_open(struct inode *inode, struct file *file)
46 if (test_and_set_bit(0, &wdt_opened))
47 return -EBUSY;
49 m8xx_wdt_reset();
50 mpc8xx_wdt_handler_disable();
52 return 0;
55 static int mpc8xx_wdt_release(struct inode *inode, struct file *file)
57 m8xx_wdt_reset();
59 #if !defined(CONFIG_WATCHDOG_NOWAYOUT)
60 mpc8xx_wdt_handler_enable();
61 #endif
63 clear_bit(0, &wdt_opened);
65 return 0;
68 static ssize_t mpc8xx_wdt_write(struct file *file, const char *data, size_t len,
69 loff_t * ppos)
71 if (ppos != &file->f_pos)
72 return -ESPIPE;
74 if (len)
75 m8xx_wdt_reset();
77 return len;
80 static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
81 unsigned int cmd, unsigned long arg)
83 int timeout;
84 static struct watchdog_info info = {
85 .options = WDIOF_KEEPALIVEPING,
86 .firmware_version = 0,
87 .identity = "MPC8xx watchdog",
90 switch (cmd) {
91 case WDIOC_GETSUPPORT:
92 if (copy_to_user((void *)arg, &info, sizeof(info)))
93 return -EFAULT;
94 break;
96 case WDIOC_GETSTATUS:
97 case WDIOC_GETBOOTSTATUS:
98 if (put_user(wdt_status, (int *)arg))
99 return -EFAULT;
100 wdt_status &= ~WDIOF_KEEPALIVEPING;
101 break;
103 case WDIOC_GETTEMP:
104 return -EOPNOTSUPP;
106 case WDIOC_SETOPTIONS:
107 return -EOPNOTSUPP;
109 case WDIOC_KEEPALIVE:
110 m8xx_wdt_reset();
111 wdt_status |= WDIOF_KEEPALIVEPING;
112 break;
114 case WDIOC_SETTIMEOUT:
115 return -EOPNOTSUPP;
117 case WDIOC_GETTIMEOUT:
118 timeout = m8xx_wdt_get_timeout();
119 if (put_user(timeout, (int *)arg))
120 return -EFAULT;
121 break;
123 default:
124 return -ENOIOCTLCMD;
127 return 0;
130 static struct file_operations mpc8xx_wdt_fops = {
131 .owner = THIS_MODULE,
132 .llseek = no_llseek,
133 .write = mpc8xx_wdt_write,
134 .ioctl = mpc8xx_wdt_ioctl,
135 .open = mpc8xx_wdt_open,
136 .release = mpc8xx_wdt_release,
139 static struct miscdevice mpc8xx_wdt_miscdev = {
140 .minor = WATCHDOG_MINOR,
141 .name = "watchdog",
142 .fops = &mpc8xx_wdt_fops,
145 static int __init mpc8xx_wdt_init(void)
147 return misc_register(&mpc8xx_wdt_miscdev);
150 static void __exit mpc8xx_wdt_exit(void)
152 misc_deregister(&mpc8xx_wdt_miscdev);
154 m8xx_wdt_reset();
155 mpc8xx_wdt_handler_enable();
158 module_init(mpc8xx_wdt_init);
159 module_exit(mpc8xx_wdt_exit);
161 MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
162 MODULE_DESCRIPTION("MPC8xx watchdog driver");
163 MODULE_LICENSE("GPL");
164 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);