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
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>
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 uint __iomem
*piscr
;
29 piscr
= (uint
*)&((immap_t
*)IMAP_ADDR
)->im_sit
.sit_piscr
;
31 if (!m8xx_has_internal_rtc
)
32 m8xx_wdt_stop_timer();
34 out_be32(piscr
, in_be32(piscr
) & ~(PISCR_PIE
| PISCR_PTE
));
36 printk(KERN_NOTICE
"mpc8xx_wdt: keep-alive handler deactivated\n");
39 static void mpc8xx_wdt_handler_enable(void)
41 volatile uint __iomem
*piscr
;
42 piscr
= (uint
*)&((immap_t
*)IMAP_ADDR
)->im_sit
.sit_piscr
;
44 if (!m8xx_has_internal_rtc
)
45 m8xx_wdt_install_timer();
47 out_be32(piscr
, in_be32(piscr
) | PISCR_PIE
| PISCR_PTE
);
49 printk(KERN_NOTICE
"mpc8xx_wdt: keep-alive handler activated\n");
52 static int mpc8xx_wdt_open(struct inode
*inode
, struct file
*file
)
54 if (test_and_set_bit(0, &wdt_opened
))
58 mpc8xx_wdt_handler_disable();
60 return nonseekable_open(inode
, file
);
63 static int mpc8xx_wdt_release(struct inode
*inode
, struct file
*file
)
67 #if !defined(CONFIG_WATCHDOG_NOWAYOUT)
68 mpc8xx_wdt_handler_enable();
71 clear_bit(0, &wdt_opened
);
76 static ssize_t
mpc8xx_wdt_write(struct file
*file
, const char *data
, size_t len
,
85 static int mpc8xx_wdt_ioctl(struct inode
*inode
, struct file
*file
,
86 unsigned int cmd
, unsigned long arg
)
89 static struct watchdog_info info
= {
90 .options
= WDIOF_KEEPALIVEPING
,
91 .firmware_version
= 0,
92 .identity
= "MPC8xx watchdog",
96 case WDIOC_GETSUPPORT
:
97 if (copy_to_user((void *)arg
, &info
, sizeof(info
)))
101 case WDIOC_GETSTATUS
:
102 case WDIOC_GETBOOTSTATUS
:
103 if (put_user(wdt_status
, (int *)arg
))
105 wdt_status
&= ~WDIOF_KEEPALIVEPING
;
111 case WDIOC_SETOPTIONS
:
114 case WDIOC_KEEPALIVE
:
116 wdt_status
|= WDIOF_KEEPALIVEPING
;
119 case WDIOC_SETTIMEOUT
:
122 case WDIOC_GETTIMEOUT
:
123 timeout
= m8xx_wdt_get_timeout();
124 if (put_user(timeout
, (int *)arg
))
135 static const struct file_operations mpc8xx_wdt_fops
= {
136 .owner
= THIS_MODULE
,
138 .write
= mpc8xx_wdt_write
,
139 .ioctl
= mpc8xx_wdt_ioctl
,
140 .open
= mpc8xx_wdt_open
,
141 .release
= mpc8xx_wdt_release
,
144 static struct miscdevice mpc8xx_wdt_miscdev
= {
145 .minor
= WATCHDOG_MINOR
,
147 .fops
= &mpc8xx_wdt_fops
,
150 static int __init
mpc8xx_wdt_init(void)
152 return misc_register(&mpc8xx_wdt_miscdev
);
155 static void __exit
mpc8xx_wdt_exit(void)
157 misc_deregister(&mpc8xx_wdt_miscdev
);
160 mpc8xx_wdt_handler_enable();
163 module_init(mpc8xx_wdt_init
);
164 module_exit(mpc8xx_wdt_exit
);
166 MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>");
167 MODULE_DESCRIPTION("MPC8xx watchdog driver");
168 MODULE_LICENSE("GPL");
169 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);