2 * drivers/watchdog/ixp4xx_wdt.c
4 * Watchdog driver for Intel IXP4xx network processors
6 * Author: Deepak Saxena <dsaxena@plexity.net>
8 * Copyright 2004 (c) MontaVista, Software, Inc.
9 * Based on sa1100 driver, Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
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 #include <linux/config.h>
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
22 #include <linux/miscdevice.h>
23 #include <linux/watchdog.h>
24 #include <linux/init.h>
25 #include <linux/bitops.h>
27 #include <asm/hardware.h>
28 #include <asm/uaccess.h>
30 #ifdef CONFIG_WATCHDOG_NOWAYOUT
31 static int nowayout = 1;
33 static int nowayout = 0;
35 static int heartbeat = 60; /* (secs) Default is 1 minute */
36 static unsigned long wdt_status;
37 static unsigned long boot_status;
39 #define WDT_TICK_RATE (IXP4XX_PERIPHERAL_BUS_CLOCK * 1000000UL)
42 #define WDT_OK_TO_CLOSE 1
47 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
49 *IXP4XX_OSWT = WDT_TICK_RATE * heartbeat;
50 *IXP4XX_OSWE = IXP4XX_WDT_COUNT_ENABLE | IXP4XX_WDT_RESET_ENABLE;
57 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
63 ixp4xx_wdt_open(struct inode *inode, struct file *file)
65 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
68 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
72 return nonseekable_open(inode, file);
76 ixp4xx_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
82 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
84 for (i = 0; i != len; i++) {
87 if (get_user(c, data + i))
90 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
99 static struct watchdog_info ident = {
100 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
101 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
102 .identity = "IXP4xx Watchdog",
107 ixp4xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
110 int ret = -ENOIOCTLCMD;
114 case WDIOC_GETSUPPORT:
115 ret = copy_to_user((struct watchdog_info *)arg, &ident,
116 sizeof(ident)) ? -EFAULT : 0;
119 case WDIOC_GETSTATUS:
120 ret = put_user(0, (int *)arg);
123 case WDIOC_GETBOOTSTATUS:
124 ret = put_user(boot_status, (int *)arg);
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);
145 case WDIOC_KEEPALIVE:
154 ixp4xx_wdt_release(struct inode *inode, struct file *file)
156 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
159 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
160 "timer will not stop\n");
163 clear_bit(WDT_IN_USE, &wdt_status);
164 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
170 static struct file_operations ixp4xx_wdt_fops =
172 .owner = THIS_MODULE,
174 .write = ixp4xx_wdt_write,
175 .ioctl = ixp4xx_wdt_ioctl,
176 .open = ixp4xx_wdt_open,
177 .release = ixp4xx_wdt_release,
180 static struct miscdevice ixp4xx_wdt_miscdev =
182 .minor = WATCHDOG_MINOR,
183 .name = "IXP4xx Watchdog",
184 .fops = &ixp4xx_wdt_fops,
187 static int __init ixp4xx_wdt_init(void)
190 unsigned long processor_id;
192 asm("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(processor_id) :);
193 if (!(processor_id & 0xf)) {
194 printk("IXP4XXX Watchdog: Rev. A0 CPU detected - "
195 "watchdog disabled\n");
200 ret = misc_register(&ixp4xx_wdt_miscdev);
202 printk("IXP4xx Watchdog Timer: heartbeat %d sec\n", heartbeat);
204 boot_status = (*IXP4XX_OSST & IXP4XX_OSST_TIMER_WARM_RESET) ?
210 static void __exit ixp4xx_wdt_exit(void)
212 misc_deregister(&ixp4xx_wdt_miscdev);
216 module_init(ixp4xx_wdt_init);
217 module_exit(ixp4xx_wdt_exit);
219 MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
220 MODULE_DESCRIPTION("IXP4xx Network Processor Watchdog");
222 module_param(heartbeat, int, 0);
223 MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 60s)");
225 module_param(nowayout, int, 0);
226 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
228 MODULE_LICENSE("GPL");
229 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);