2 * drivers/char/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/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
21 #include <linux/miscdevice.h>
22 #include <linux/watchdog.h>
23 #include <linux/init.h>
24 #include <linux/bitops.h>
25 #include <linux/uaccess.h>
26 #include <mach/hardware.h>
28 static int nowayout
= WATCHDOG_NOWAYOUT
;
29 static int heartbeat
= 60; /* (secs) Default is 1 minute */
30 static unsigned long wdt_status
;
31 static unsigned long boot_status
;
32 static DEFINE_SPINLOCK(wdt_lock
);
34 #define WDT_TICK_RATE (IXP4XX_PERIPHERAL_BUS_CLOCK * 1000000UL)
37 #define WDT_OK_TO_CLOSE 1
39 static void wdt_enable(void)
42 *IXP4XX_OSWK
= IXP4XX_WDT_KEY
;
44 *IXP4XX_OSWT
= WDT_TICK_RATE
* heartbeat
;
45 *IXP4XX_OSWE
= IXP4XX_WDT_COUNT_ENABLE
| IXP4XX_WDT_RESET_ENABLE
;
47 spin_unlock(&wdt_lock
);
50 static void wdt_disable(void)
53 *IXP4XX_OSWK
= IXP4XX_WDT_KEY
;
56 spin_unlock(&wdt_lock
);
59 static int ixp4xx_wdt_open(struct inode
*inode
, struct file
*file
)
61 if (test_and_set_bit(WDT_IN_USE
, &wdt_status
))
64 clear_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
66 return nonseekable_open(inode
, file
);
70 ixp4xx_wdt_write(struct file
*file
, const char *data
, size_t len
, loff_t
*ppos
)
76 clear_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
78 for (i
= 0; i
!= len
; i
++) {
81 if (get_user(c
, data
+ i
))
84 set_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
92 static const struct watchdog_info ident
= {
93 .options
= WDIOF_CARDRESET
| WDIOF_MAGICCLOSE
|
94 WDIOF_SETTIMEOUT
| WDIOF_KEEPALIVEPING
,
95 .identity
= "IXP4xx Watchdog",
99 static long ixp4xx_wdt_ioctl(struct file
*file
, unsigned int cmd
,
106 case WDIOC_GETSUPPORT
:
107 ret
= copy_to_user((struct watchdog_info
*)arg
, &ident
,
108 sizeof(ident
)) ? -EFAULT
: 0;
111 case WDIOC_GETSTATUS
:
112 ret
= put_user(0, (int *)arg
);
115 case WDIOC_GETBOOTSTATUS
:
116 ret
= put_user(boot_status
, (int *)arg
);
119 case WDIOC_KEEPALIVE
:
124 case WDIOC_SETTIMEOUT
:
125 ret
= get_user(time
, (int *)arg
);
129 if (time
<= 0 || time
> 60) {
138 case WDIOC_GETTIMEOUT
:
139 ret
= put_user(heartbeat
, (int *)arg
);
145 static int ixp4xx_wdt_release(struct inode
*inode
, struct file
*file
)
147 if (test_bit(WDT_OK_TO_CLOSE
, &wdt_status
))
150 printk(KERN_CRIT
"WATCHDOG: Device closed unexpectedly - "
151 "timer will not stop\n");
152 clear_bit(WDT_IN_USE
, &wdt_status
);
153 clear_bit(WDT_OK_TO_CLOSE
, &wdt_status
);
159 static const struct file_operations ixp4xx_wdt_fops
= {
160 .owner
= THIS_MODULE
,
162 .write
= ixp4xx_wdt_write
,
163 .unlocked_ioctl
= ixp4xx_wdt_ioctl
,
164 .open
= ixp4xx_wdt_open
,
165 .release
= ixp4xx_wdt_release
,
168 static struct miscdevice ixp4xx_wdt_miscdev
= {
169 .minor
= WATCHDOG_MINOR
,
171 .fops
= &ixp4xx_wdt_fops
,
174 static int __init
ixp4xx_wdt_init(void)
178 if (!(read_cpuid_id() & 0xf) && !cpu_is_ixp46x()) {
179 printk(KERN_ERR
"IXP4XXX Watchdog: Rev. A0 IXP42x CPU detected"
180 " - watchdog disabled\n");
184 boot_status
= (*IXP4XX_OSST
& IXP4XX_OSST_TIMER_WARM_RESET
) ?
186 ret
= misc_register(&ixp4xx_wdt_miscdev
);
188 printk(KERN_INFO
"IXP4xx Watchdog Timer: heartbeat %d sec\n",
193 static void __exit
ixp4xx_wdt_exit(void)
195 misc_deregister(&ixp4xx_wdt_miscdev
);
199 module_init(ixp4xx_wdt_init
);
200 module_exit(ixp4xx_wdt_exit
);
202 MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
203 MODULE_DESCRIPTION("IXP4xx Network Processor Watchdog");
205 module_param(heartbeat
, int, 0);
206 MODULE_PARM_DESC(heartbeat
, "Watchdog heartbeat in seconds (default 60s)");
208 module_param(nowayout
, int, 0);
209 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started");
211 MODULE_LICENSE("GPL");
212 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);