]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/watchdog/ixp4xx_wdt.c
[WATCHDOG] Coding style - Indentation - part 1
[mirror_ubuntu-zesty-kernel.git] / drivers / watchdog / ixp4xx_wdt.c
CommitLineData
1da177e4 1/*
f30c2269 2 * drivers/char/watchdog/ixp4xx_wdt.c
1da177e4
LT
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
1da177e4
LT
16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/fs.h>
21#include <linux/miscdevice.h>
22#include <linux/watchdog.h>
23#include <linux/init.h>
24#include <linux/bitops.h>
089ab079 25#include <linux/uaccess.h>
1da177e4
LT
26
27#include <asm/hardware.h>
1da177e4 28
4bfdf378 29static int nowayout = WATCHDOG_NOWAYOUT;
1da177e4
LT
30static int heartbeat = 60; /* (secs) Default is 1 minute */
31static unsigned long wdt_status;
32static unsigned long boot_status;
20d35f3e 33static spin_lock_t wdt_lock;
1da177e4
LT
34
35#define WDT_TICK_RATE (IXP4XX_PERIPHERAL_BUS_CLOCK * 1000000UL)
36
37#define WDT_IN_USE 0
38#define WDT_OK_TO_CLOSE 1
39
20d35f3e 40static void wdt_enable(void)
1da177e4 41{
20d35f3e 42 spin_lock(&wdt_lock);
1da177e4
LT
43 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
44 *IXP4XX_OSWE = 0;
45 *IXP4XX_OSWT = WDT_TICK_RATE * heartbeat;
46 *IXP4XX_OSWE = IXP4XX_WDT_COUNT_ENABLE | IXP4XX_WDT_RESET_ENABLE;
47 *IXP4XX_OSWK = 0;
20d35f3e 48 spin_unlock(&wdt_lock);
1da177e4
LT
49}
50
20d35f3e 51static void wdt_disable(void)
1da177e4 52{
20d35f3e 53 spin_lock(&wdt_lock);
1da177e4
LT
54 *IXP4XX_OSWK = IXP4XX_WDT_KEY;
55 *IXP4XX_OSWE = 0;
56 *IXP4XX_OSWK = 0;
20d35f3e 57 spin_unlock(&wdt_lock);
1da177e4
LT
58}
59
20d35f3e 60static int ixp4xx_wdt_open(struct inode *inode, struct file *file)
1da177e4
LT
61{
62 if (test_and_set_bit(WDT_IN_USE, &wdt_status))
63 return -EBUSY;
64
65 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
1da177e4 66 wdt_enable();
1da177e4
LT
67 return nonseekable_open(inode, file);
68}
69
70static ssize_t
71ixp4xx_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
72{
73 if (len) {
74 if (!nowayout) {
75 size_t i;
76
77 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
78
79 for (i = 0; i != len; i++) {
80 char c;
81
82 if (get_user(c, data + i))
83 return -EFAULT;
84 if (c == 'V')
85 set_bit(WDT_OK_TO_CLOSE, &wdt_status);
86 }
87 }
88 wdt_enable();
89 }
1da177e4
LT
90 return len;
91}
92
93static struct watchdog_info ident = {
94 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE |
95 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
96 .identity = "IXP4xx Watchdog",
97};
98
99
20d35f3e
AC
100static long ixp4xx_wdt_ioctl(struct file *file, unsigned int cmd,
101 unsigned long arg)
1da177e4 102{
795b89d2 103 int ret = -ENOTTY;
1da177e4
LT
104 int time;
105
106 switch (cmd) {
107 case WDIOC_GETSUPPORT:
108 ret = copy_to_user((struct watchdog_info *)arg, &ident,
109 sizeof(ident)) ? -EFAULT : 0;
110 break;
111
112 case WDIOC_GETSTATUS:
113 ret = put_user(0, (int *)arg);
114 break;
115
116 case WDIOC_GETBOOTSTATUS:
117 ret = put_user(boot_status, (int *)arg);
118 break;
119
120 case WDIOC_SETTIMEOUT:
121 ret = get_user(time, (int *)arg);
122 if (ret)
123 break;
124
125 if (time <= 0 || time > 60) {
126 ret = -EINVAL;
127 break;
128 }
129
130 heartbeat = time;
131 wdt_enable();
132 /* Fall through */
133
134 case WDIOC_GETTIMEOUT:
135 ret = put_user(heartbeat, (int *)arg);
136 break;
137
138 case WDIOC_KEEPALIVE:
139 wdt_enable();
140 ret = 0;
141 break;
142 }
143 return ret;
144}
145
20d35f3e 146static int ixp4xx_wdt_release(struct inode *inode, struct file *file)
1da177e4 147{
20d35f3e 148 if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))
1da177e4 149 wdt_disable();
20d35f3e 150 else
b36bbb6c 151 printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - "
1da177e4 152 "timer will not stop\n");
1da177e4
LT
153 clear_bit(WDT_IN_USE, &wdt_status);
154 clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
155
156 return 0;
157}
158
159
62322d25 160static const struct file_operations ixp4xx_wdt_fops =
1da177e4
LT
161{
162 .owner = THIS_MODULE,
163 .llseek = no_llseek,
164 .write = ixp4xx_wdt_write,
20d35f3e 165 .unlocked_ioctl = ixp4xx_wdt_ioctl,
1da177e4
LT
166 .open = ixp4xx_wdt_open,
167 .release = ixp4xx_wdt_release,
168};
169
170static struct miscdevice ixp4xx_wdt_miscdev =
171{
172 .minor = WATCHDOG_MINOR,
2dab3cab 173 .name = "watchdog",
1da177e4
LT
174 .fops = &ixp4xx_wdt_fops,
175};
176
177static int __init ixp4xx_wdt_init(void)
178{
179 int ret;
180 unsigned long processor_id;
181
182 asm("mrc p15, 0, %0, cr0, cr0, 0;" : "=r"(processor_id) :);
3adfd4e2
DS
183 if (!(processor_id & 0xf) && !cpu_is_ixp46x()) {
184 printk("IXP4XXX Watchdog: Rev. A0 IXP42x CPU detected - "
1da177e4
LT
185 "watchdog disabled\n");
186
187 return -ENODEV;
188 }
20d35f3e
AC
189 spin_lock_init(&wdt_lock);
190 boot_status = (*IXP4XX_OSST & IXP4XX_OSST_TIMER_WARM_RESET) ?
191 WDIOF_CARDRESET : 0;
1da177e4
LT
192 ret = misc_register(&ixp4xx_wdt_miscdev);
193 if (ret == 0)
194 printk("IXP4xx Watchdog Timer: heartbeat %d sec\n", heartbeat);
1da177e4
LT
195 return ret;
196}
197
198static void __exit ixp4xx_wdt_exit(void)
199{
200 misc_deregister(&ixp4xx_wdt_miscdev);
201}
202
203
204module_init(ixp4xx_wdt_init);
205module_exit(ixp4xx_wdt_exit);
206
207MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
208MODULE_DESCRIPTION("IXP4xx Network Processor Watchdog");
209
210module_param(heartbeat, int, 0);
211MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 60s)");
212
213module_param(nowayout, int, 0);
214MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
215
216MODULE_LICENSE("GPL");
217MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
218