blob: 85b5734403a5dbc5c2d3e8c026100aea79825f60 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * mpc8xx_wdt.c - MPC8xx watchdog userspace interface
3 *
4 * Author: Florian Schirmer <jolt@tuxbox.org>
5 *
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.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/fs.h>
13#include <linux/init.h>
14#include <linux/kernel.h>
15#include <linux/miscdevice.h>
16#include <linux/module.h>
17#include <linux/watchdog.h>
18#include <asm/8xx_immap.h>
19#include <asm/uaccess.h>
Marcelo Tosatti398f6852005-12-05 19:31:36 -020020#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <syslib/m8xx_wdt.h>
22
23static unsigned long wdt_opened;
24static int wdt_status;
25
26static void mpc8xx_wdt_handler_disable(void)
27{
Marcelo Tosatti398f6852005-12-05 19:31:36 -020028 volatile uint __iomem *piscr;
29 piscr = (uint *)&((immap_t*)IMAP_ADDR)->im_sit.sit_piscr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Marcelo Tosattifb64c242005-11-24 11:32:09 -020031 if (!m8xx_has_internal_rtc)
32 m8xx_wdt_stop_timer();
33 else
Marcelo Tosatti398f6852005-12-05 19:31:36 -020034 out_be32(piscr, in_be32(piscr) & ~(PISCR_PIE | PISCR_PTE));
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36 printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler deactivated\n");
37}
38
39static void mpc8xx_wdt_handler_enable(void)
40{
Marcelo Tosatti398f6852005-12-05 19:31:36 -020041 volatile uint __iomem *piscr;
42 piscr = (uint *)&((immap_t*)IMAP_ADDR)->im_sit.sit_piscr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Marcelo Tosattifb64c242005-11-24 11:32:09 -020044 if (!m8xx_has_internal_rtc)
45 m8xx_wdt_install_timer();
46 else
Marcelo Tosatti398f6852005-12-05 19:31:36 -020047 out_be32(piscr, in_be32(piscr) | PISCR_PIE | PISCR_PTE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 printk(KERN_NOTICE "mpc8xx_wdt: keep-alive handler activated\n");
50}
51
52static int mpc8xx_wdt_open(struct inode *inode, struct file *file)
53{
54 if (test_and_set_bit(0, &wdt_opened))
55 return -EBUSY;
56
57 m8xx_wdt_reset();
58 mpc8xx_wdt_handler_disable();
59
Wim Van Sebroeckec9505a2007-07-20 20:41:37 +000060 return nonseekable_open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
63static int mpc8xx_wdt_release(struct inode *inode, struct file *file)
64{
65 m8xx_wdt_reset();
66
67#if !defined(CONFIG_WATCHDOG_NOWAYOUT)
68 mpc8xx_wdt_handler_enable();
69#endif
70
71 clear_bit(0, &wdt_opened);
72
73 return 0;
74}
75
76static ssize_t mpc8xx_wdt_write(struct file *file, const char *data, size_t len,
77 loff_t * ppos)
78{
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 if (len)
80 m8xx_wdt_reset();
81
82 return len;
83}
84
85static int mpc8xx_wdt_ioctl(struct inode *inode, struct file *file,
86 unsigned int cmd, unsigned long arg)
87{
88 int timeout;
89 static struct watchdog_info info = {
90 .options = WDIOF_KEEPALIVEPING,
91 .firmware_version = 0,
92 .identity = "MPC8xx watchdog",
93 };
94
95 switch (cmd) {
96 case WDIOC_GETSUPPORT:
97 if (copy_to_user((void *)arg, &info, sizeof(info)))
98 return -EFAULT;
99 break;
100
101 case WDIOC_GETSTATUS:
102 case WDIOC_GETBOOTSTATUS:
103 if (put_user(wdt_status, (int *)arg))
104 return -EFAULT;
105 wdt_status &= ~WDIOF_KEEPALIVEPING;
106 break;
107
108 case WDIOC_GETTEMP:
109 return -EOPNOTSUPP;
110
111 case WDIOC_SETOPTIONS:
112 return -EOPNOTSUPP;
113
114 case WDIOC_KEEPALIVE:
115 m8xx_wdt_reset();
116 wdt_status |= WDIOF_KEEPALIVEPING;
117 break;
118
119 case WDIOC_SETTIMEOUT:
120 return -EOPNOTSUPP;
121
122 case WDIOC_GETTIMEOUT:
123 timeout = m8xx_wdt_get_timeout();
124 if (put_user(timeout, (int *)arg))
125 return -EFAULT;
126 break;
127
128 default:
Samuel Tardieu795b89d2006-09-09 17:34:31 +0200129 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
132 return 0;
133}
134
Arjan van de Ven62322d22006-07-03 00:24:21 -0700135static const struct file_operations mpc8xx_wdt_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .owner = THIS_MODULE,
137 .llseek = no_llseek,
138 .write = mpc8xx_wdt_write,
139 .ioctl = mpc8xx_wdt_ioctl,
140 .open = mpc8xx_wdt_open,
141 .release = mpc8xx_wdt_release,
142};
143
144static struct miscdevice mpc8xx_wdt_miscdev = {
145 .minor = WATCHDOG_MINOR,
146 .name = "watchdog",
147 .fops = &mpc8xx_wdt_fops,
148};
149
150static int __init mpc8xx_wdt_init(void)
151{
152 return misc_register(&mpc8xx_wdt_miscdev);
153}
154
155static void __exit mpc8xx_wdt_exit(void)
156{
157 misc_deregister(&mpc8xx_wdt_miscdev);
158
159 m8xx_wdt_reset();
160 mpc8xx_wdt_handler_enable();
161}
162
163module_init(mpc8xx_wdt_init);
164module_exit(mpc8xx_wdt_exit);
165
166MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
167MODULE_DESCRIPTION("MPC8xx watchdog driver");
168MODULE_LICENSE("GPL");
169MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);