aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/watchdog/ixp4xx_wdt.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/char/watchdog/ixp4xx_wdt.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/char/watchdog/ixp4xx_wdt.c')
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c230
1 files changed, 230 insertions, 0 deletions
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
new file mode 100644
index 000000000000..82396e06c8a8
--- /dev/null
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -0,0 +1,230 @@
1/*
2 * drivers/watchdog/ixp4xx_wdt.c
3 *
4 * Watchdog driver for Intel IXP4xx network processors
5 *
6 * Author: Deepak Saxena <dsaxena@plexity.net>
7 *
8 * Copyright 2004 (c) MontaVista, Software, Inc.
9 * Based on sa1100 driver, Copyright (C) 2000 Oleg Drokin <green@crimea.edu>
10 *
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.
14 */
15
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>
21#include <linux/fs.h>
22#include <linux/miscdevice.h>
23#include <linux/watchdog.h>
24#include <linux/init.h>
25#include <linux/bitops.h>
26
27#include <asm/hardware.h>
28#include <asm/uaccess.h>
29
30#ifdef CONFIG_WATCHDOG_NOWAYOUT
31static int nowayout = 1;
32#else
33static int nowayout = 0;
34#endif
35static int heartbeat = 60; /* (secs) Default is 1 minute */
36static unsigned long wdt_status;
37static unsigned long boot_status;
38
39#define WDT_TICK_RATE (IXP4XX_PERIPHERAL_BUS_CLOCK * 1000000UL)
40
41#define WDT_IN_USE 0
42#define WDT_OK_TO_CLOSE 1
43
44static void
45wdt_enable(void)
46{
47 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
48 *IXP4XX_OSWE = 0;
49 *IXP4XX_OSWT = WDT_TICK_RATE * heartbeat;
50 *IXP4XX_OSWE = IXP4XX_WDT_COUNT_ENABLE | IXP4XX_WDT_RESET_ENABLE;
51 *IXP4XX_OSWK = 0;
52}
53
54static void
55wdt_disable(void)
56{
57 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
58 *IXP4XX_OSWE = 0;
59 *IXP4XX_OSWK = 0;
60}
61
62static int
63ixp4xx_wdt_open(struct inode *inode, struct file *file)
64{
65 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
66 return -EBUSY;
67
68 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
69
70 wdt_enable();
71
72 return nonseekable_open(inode, file);
73}
74
75static ssize_t
76ixp4xx_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
77{
78 if (len) {
79 if (!nowayout) {
80 size_t i;
81
82 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
83
84 for (i = 0; i != len; i++) {
85 char c;
86
87 if (get_user(c, data + i))
88 return -EFAULT;
89 if (c == 'V')
90 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
91 }
92 }
93 wdt_enable();
94 }
95
96 return len;
97}
98
99static struct watchdog_info ident = {
100 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
101 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
102 .identity = "IXP4xx Watchdog",
103};
104
105
106static int
107ixp4xx_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
108 unsigned long arg)
109{
110 int ret = -ENOIOCTLCMD;
111 int time;
112
113 switch (cmd) {
114 case WDIOC_GETSUPPORT:
115 ret = copy_to_user((struct watchdog_info *)arg, &ident,
116 sizeof(ident)) ? -EFAULT : 0;
117 break;
118
119 case WDIOC_GETSTATUS:
120 ret = put_user(0, (int *)arg);
121 break;
122
123 case WDIOC_GETBOOTSTATUS:
124 ret = put_user(boot_status, (int *)arg);
125 break;
126
127 case WDIOC_SETTIMEOUT:
128 ret = get_user(time, (int *)arg);
129 if (ret)
130 break;
131
132 if (time <= 0 || time > 60) {
133 ret = -EINVAL;
134 break;
135 }
136
137 heartbeat = time;
138 wdt_enable();
139 /* Fall through */
140
141 case WDIOC_GETTIMEOUT:
142 ret = put_user(heartbeat, (int *)arg);
143 break;
144
145 case WDIOC_KEEPALIVE:
146 wdt_enable();
147 ret = 0;
148 break;
149 }
150 return ret;
151}
152
153static int
154ixp4xx_wdt_release(struct inode *inode, struct file *file)
155{
156 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
157 wdt_disable();
158 } else {
159 printk(KERN_CRIT "WATCHDOG: Device closed unexpectdly - "
160 "timer will not stop\n");
161 }
162
163 clear_bit(WDT_IN_USE, &wdt_status);
164 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
165
166 return 0;
167}
168
169
170static struct file_operations ixp4xx_wdt_fops =
171{
172 .owner = THIS_MODULE,
173 .llseek = no_llseek,
174 .write = ixp4xx_wdt_write,
175 .ioctl = ixp4xx_wdt_ioctl,
176 .open = ixp4xx_wdt_open,
177 .release = ixp4xx_wdt_release,
178};
179
180static struct miscdevice ixp4xx_wdt_miscdev =
181{
182 .minor = WATCHDOG_MINOR,
183 .name = "IXP4xx Watchdog",
184 .fops = &ixp4xx_wdt_fops,
185};
186
187static int __init ixp4xx_wdt_init(void)
188{
189 int ret;
190 unsigned long processor_id;
191
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");
196
197 return -ENODEV;
198 }
199
200 ret = misc_register(&ixp4xx_wdt_miscdev);
201 if (ret == 0)
202 printk("IXP4xx Watchdog Timer: heartbeat %d sec\n", heartbeat);
203
204 boot_status = (*IXP4XX_OSST & IXP4XX_OSST_TIMER_WARM_RESET) ?
205 WDIOF_CARDRESET : 0;
206
207 return ret;
208}
209
210static void __exit ixp4xx_wdt_exit(void)
211{
212 misc_deregister(&ixp4xx_wdt_miscdev);
213}
214
215
216module_init(ixp4xx_wdt_init);
217module_exit(ixp4xx_wdt_exit);
218
219MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
220MODULE_DESCRIPTION("IXP4xx Network Processor Watchdog");
221
222module_param(heartbeat, int, 0);
223MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 60s)");
224
225module_param(nowayout, int, 0);
226MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
227
228MODULE_LICENSE("GPL");
229MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
230