2 * drivers/char/watchdog/ixp4xx_wdt.c
4 * Watchdog driver for Intel IXP4xx network processors
8 * Copyright 2004 (c) MontaVista, Software, Inc.
11 * This file is licensed under the terms of the GNU General Public
12 * License version 2. This program is licensed "as is" without any
13 * warranty of any kind, whether express or implied.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
23 #include <linux/miscdevice.h>
25 #include <linux/watchdog.h>
26 #include <linux/init.h>
27 #include <linux/bitops.h>
28 #include <linux/uaccess.h>
29 #include <mach/hardware.h>
31 static bool nowayout = WATCHDOG_NOWAYOUT;
32 static int heartbeat = 60; /* (secs) Default is 1 minute */
33 static unsigned long wdt_status;
34 static unsigned long boot_status;
35 static DEFINE_SPINLOCK(wdt_lock);
37 #define WDT_TICK_RATE (IXP4XX_PERIPHERAL_BUS_CLOCK * 1000000UL)
40 #define WDT_OK_TO_CLOSE 1
42 static void wdt_enable(void)
45 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
47 *IXP4XX_OSWT = WDT_TICK_RATE * heartbeat;
48 *IXP4XX_OSWE = IXP4XX_WDT_COUNT_ENABLE | IXP4XX_WDT_RESET_ENABLE;
50 spin_unlock(&wdt_lock);
53 static void wdt_disable(void)
56 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
59 spin_unlock(&wdt_lock);
62 static int ixp4xx_wdt_open(struct inode *inode, struct file *file)
64 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
67 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
69 return stream_open(inode, file);
73 ixp4xx_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
79 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
81 for (i = 0; i != len; i++) {
84 if (get_user(c, data + i))
87 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
95 static const struct watchdog_info ident = {
96 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
97 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
98 .identity = "IXP4xx Watchdog",
102 static long ixp4xx_wdt_ioctl(struct file *file, unsigned int cmd,
109 case WDIOC_GETSUPPORT:
110 ret = copy_to_user((struct watchdog_info *)arg, &ident,
111 sizeof(ident)) ? -EFAULT : 0;
114 case WDIOC_GETSTATUS:
115 ret = put_user(0, (int *)arg);
118 case WDIOC_GETBOOTSTATUS:
119 ret = put_user(boot_status, (int *)arg);
122 case WDIOC_KEEPALIVE:
127 case WDIOC_SETTIMEOUT:
128 ret = get_user(time, (int *)arg);
132 if (time <= 0 || time > 60) {
141 case WDIOC_GETTIMEOUT:
142 ret = put_user(heartbeat, (int *)arg);
148 static int ixp4xx_wdt_release(struct inode *inode, struct file *file)
150 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))
153 pr_crit("Device closed unexpectedly - timer will not stop\n");
154 clear_bit(WDT_IN_USE, &wdt_status);
155 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
161 static const struct file_operations ixp4xx_wdt_fops = {
162 .owner = THIS_MODULE,
164 .write = ixp4xx_wdt_write,
165 .unlocked_ioctl = ixp4xx_wdt_ioctl,
166 .compat_ioctl = compat_ptr_ioctl,
167 .open = ixp4xx_wdt_open,
168 .release = ixp4xx_wdt_release,
171 static struct miscdevice ixp4xx_wdt_miscdev = {
172 .minor = WATCHDOG_MINOR,
174 .fops = &ixp4xx_wdt_fops,
177 static int __init ixp4xx_wdt_init(void)
182 * FIXME: we bail out on device tree boot but this really needs
183 * to be fixed in a nicer way: this registers the MDIO bus before
184 * even matching the driver infrastructure, we should only probe
187 if (of_have_populated_dt())
189 if (!(read_cpuid_id() & 0xf) && !cpu_is_ixp46x()) {
190 pr_err("Rev. A0 IXP42x CPU detected - watchdog disabled\n");
194 boot_status = (*IXP4XX_OSST & IXP4XX_OSST_TIMER_WARM_RESET) ?
196 ret = misc_register(&ixp4xx_wdt_miscdev);
198 pr_info("timer heartbeat %d sec\n", heartbeat);
202 static void __exit ixp4xx_wdt_exit(void)
204 misc_deregister(&ixp4xx_wdt_miscdev);
208 module_init(ixp4xx_wdt_init);
209 module_exit(ixp4xx_wdt_exit);
212 MODULE_DESCRIPTION("IXP4xx Network Processor Watchdog");
214 module_param(heartbeat, int, 0);
215 MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 60s)");
217 module_param(nowayout, bool, 0);
218 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
220 MODULE_LICENSE("GPL");