aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/ks8695_wdt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/watchdog/ks8695_wdt.c')
-rw-r--r--drivers/watchdog/ks8695_wdt.c120
1 files changed, 62 insertions, 58 deletions
diff --git a/drivers/watchdog/ks8695_wdt.c b/drivers/watchdog/ks8695_wdt.c
index d21a6407fe21..0b798fdaa378 100644
--- a/drivers/watchdog/ks8695_wdt.c
+++ b/drivers/watchdog/ks8695_wdt.c
@@ -19,11 +19,10 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/watchdog.h> 21#include <linux/watchdog.h>
22#include <asm/io.h> 22#include <linux/io.h>
23#include <asm/uaccess.h> 23#include <linux/uaccess.h>
24#include <mach/regs-timer.h> 24#include <mach/regs-timer.h>
25 25
26
27#define WDT_DEFAULT_TIME 5 /* seconds */ 26#define WDT_DEFAULT_TIME 5 /* seconds */
28#define WDT_MAX_TIME 171 /* seconds */ 27#define WDT_MAX_TIME 171 /* seconds */
29 28
@@ -31,38 +30,44 @@ static int wdt_time = WDT_DEFAULT_TIME;
31static int nowayout = WATCHDOG_NOWAYOUT; 30static int nowayout = WATCHDOG_NOWAYOUT;
32 31
33module_param(wdt_time, int, 0); 32module_param(wdt_time, int, 0);
34MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="__MODULE_STRING(WDT_DEFAULT_TIME) ")"); 33MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
34 __MODULE_STRING(WDT_DEFAULT_TIME) ")");
35 35
36#ifdef CONFIG_WATCHDOG_NOWAYOUT 36#ifdef CONFIG_WATCHDOG_NOWAYOUT
37module_param(nowayout, int, 0); 37module_param(nowayout, int, 0);
38MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 38MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
39 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
39#endif 40#endif
40 41
41 42
42static unsigned long ks8695wdt_busy; 43static unsigned long ks8695wdt_busy;
44static spinlock_t ks8695_lock;
43 45
44/* ......................................................................... */ 46/* ......................................................................... */
45 47
46/* 48/*
47 * Disable the watchdog. 49 * Disable the watchdog.
48 */ 50 */
49static void inline ks8695_wdt_stop(void) 51static inline void ks8695_wdt_stop(void)
50{ 52{
51 unsigned long tmcon; 53 unsigned long tmcon;
52 54
55 spin_lock(&ks8695_lock);
53 /* disable timer0 */ 56 /* disable timer0 */
54 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); 57 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
55 __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); 58 __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
59 spin_unlock(&ks8695_lock);
56} 60}
57 61
58/* 62/*
59 * Enable and reset the watchdog. 63 * Enable and reset the watchdog.
60 */ 64 */
61static void inline ks8695_wdt_start(void) 65static inline void ks8695_wdt_start(void)
62{ 66{
63 unsigned long tmcon; 67 unsigned long tmcon;
64 unsigned long tval = wdt_time * CLOCK_TICK_RATE; 68 unsigned long tval = wdt_time * CLOCK_TICK_RATE;
65 69
70 spin_lock(&ks8695_lock);
66 /* disable timer0 */ 71 /* disable timer0 */
67 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); 72 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
68 __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); 73 __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
@@ -73,19 +78,22 @@ static void inline ks8695_wdt_start(void)
73 /* re-enable timer0 */ 78 /* re-enable timer0 */
74 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); 79 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
75 __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); 80 __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
81 spin_unlock(&ks8695_lock);
76} 82}
77 83
78/* 84/*
79 * Reload the watchdog timer. (ie, pat the watchdog) 85 * Reload the watchdog timer. (ie, pat the watchdog)
80 */ 86 */
81static void inline ks8695_wdt_reload(void) 87static inline void ks8695_wdt_reload(void)
82{ 88{
83 unsigned long tmcon; 89 unsigned long tmcon;
84 90
91 spin_lock(&ks8695_lock);
85 /* disable, then re-enable timer0 */ 92 /* disable, then re-enable timer0 */
86 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); 93 tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON);
87 __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); 94 __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
88 __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); 95 __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON);
96 spin_unlock(&ks8695_lock);
89} 97}
90 98
91/* 99/*
@@ -102,7 +110,8 @@ static int ks8695_wdt_settimeout(int new_time)
102 if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) 110 if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
103 return -EINVAL; 111 return -EINVAL;
104 112
105 /* Set new watchdog time. It will be used when ks8695_wdt_start() is called. */ 113 /* Set new watchdog time. It will be used when
114 ks8695_wdt_start() is called. */
106 wdt_time = new_time; 115 wdt_time = new_time;
107 return 0; 116 return 0;
108} 117}
@@ -128,9 +137,9 @@ static int ks8695_wdt_open(struct inode *inode, struct file *file)
128 */ 137 */
129static int ks8695_wdt_close(struct inode *inode, struct file *file) 138static int ks8695_wdt_close(struct inode *inode, struct file *file)
130{ 139{
140 /* Disable the watchdog when file is closed */
131 if (!nowayout) 141 if (!nowayout)
132 ks8695_wdt_stop(); /* Disable the watchdog when file is closed */ 142 ks8695_wdt_stop();
133
134 clear_bit(0, &ks8695wdt_busy); 143 clear_bit(0, &ks8695wdt_busy);
135 return 0; 144 return 0;
136} 145}
@@ -143,60 +152,52 @@ static struct watchdog_info ks8695_wdt_info = {
143/* 152/*
144 * Handle commands from user-space. 153 * Handle commands from user-space.
145 */ 154 */
146static int ks8695_wdt_ioctl(struct inode *inode, struct file *file, 155static long ks8695_wdt_ioctl(struct file *file, unsigned int cmd,
147 unsigned int cmd, unsigned long arg) 156 unsigned long arg)
148{ 157{
149 void __user *argp = (void __user *)arg; 158 void __user *argp = (void __user *)arg;
150 int __user *p = argp; 159 int __user *p = argp;
151 int new_value; 160 int new_value;
152 161
153 switch(cmd) { 162 switch (cmd) {
154 case WDIOC_KEEPALIVE: 163 case WDIOC_GETSUPPORT:
155 ks8695_wdt_reload(); /* pat the watchdog */ 164 return copy_to_user(argp, &ks8695_wdt_info,
156 return 0; 165 sizeof(ks8695_wdt_info)) ? -EFAULT : 0;
157 166 case WDIOC_GETSTATUS:
158 case WDIOC_GETSUPPORT: 167 case WDIOC_GETBOOTSTATUS:
159 return copy_to_user(argp, &ks8695_wdt_info, sizeof(ks8695_wdt_info)) ? -EFAULT : 0; 168 return put_user(0, p);
160 169 case WDIOC_SETOPTIONS:
161 case WDIOC_SETTIMEOUT: 170 if (get_user(new_value, p))
162 if (get_user(new_value, p)) 171 return -EFAULT;
163 return -EFAULT; 172 if (new_value & WDIOS_DISABLECARD)
164 173 ks8695_wdt_stop();
165 if (ks8695_wdt_settimeout(new_value)) 174 if (new_value & WDIOS_ENABLECARD)
166 return -EINVAL;
167
168 /* Enable new time value */
169 ks8695_wdt_start(); 175 ks8695_wdt_start();
170 176 return 0;
171 /* Return current value */ 177 case WDIOC_KEEPALIVE:
172 return put_user(wdt_time, p); 178 ks8695_wdt_reload(); /* pat the watchdog */
173 179 return 0;
174 case WDIOC_GETTIMEOUT: 180 case WDIOC_SETTIMEOUT:
175 return put_user(wdt_time, p); 181 if (get_user(new_value, p))
176 182 return -EFAULT;
177 case WDIOC_GETSTATUS: 183 if (ks8695_wdt_settimeout(new_value))
178 case WDIOC_GETBOOTSTATUS: 184 return -EINVAL;
179 return put_user(0, p); 185 /* Enable new time value */
180 186 ks8695_wdt_start();
181 case WDIOC_SETOPTIONS: 187 /* Return current value */
182 if (get_user(new_value, p)) 188 return put_user(wdt_time, p);
183 return -EFAULT; 189 case WDIOC_GETTIMEOUT:
184 190 return put_user(wdt_time, p);
185 if (new_value & WDIOS_DISABLECARD) 191 default:
186 ks8695_wdt_stop(); 192 return -ENOTTY;
187 if (new_value & WDIOS_ENABLECARD)
188 ks8695_wdt_start();
189 return 0;
190
191 default:
192 return -ENOTTY;
193 } 193 }
194} 194}
195 195
196/* 196/*
197 * Pat the watchdog whenever device is written to. 197 * Pat the watchdog whenever device is written to.
198 */ 198 */
199static ssize_t ks8695_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos) 199static ssize_t ks8695_wdt_write(struct file *file, const char *data,
200 size_t len, loff_t *ppos)
200{ 201{
201 ks8695_wdt_reload(); /* pat the watchdog */ 202 ks8695_wdt_reload(); /* pat the watchdog */
202 return len; 203 return len;
@@ -207,7 +208,7 @@ static ssize_t ks8695_wdt_write(struct file *file, const char *data, size_t len,
207static const struct file_operations ks8695wdt_fops = { 208static const struct file_operations ks8695wdt_fops = {
208 .owner = THIS_MODULE, 209 .owner = THIS_MODULE,
209 .llseek = no_llseek, 210 .llseek = no_llseek,
210 .ioctl = ks8695_wdt_ioctl, 211 .unlocked_ioctl = ks8695_wdt_ioctl,
211 .open = ks8695_wdt_open, 212 .open = ks8695_wdt_open,
212 .release = ks8695_wdt_close, 213 .release = ks8695_wdt_close,
213 .write = ks8695_wdt_write, 214 .write = ks8695_wdt_write,
@@ -231,7 +232,8 @@ static int __init ks8695wdt_probe(struct platform_device *pdev)
231 if (res) 232 if (res)
232 return res; 233 return res;
233 234
234 printk("KS8695 Watchdog Timer enabled (%d seconds%s)\n", wdt_time, nowayout ? ", nowayout" : ""); 235 printk(KERN_INFO "KS8695 Watchdog Timer enabled (%d seconds%s)\n",
236 wdt_time, nowayout ? ", nowayout" : "");
235 return 0; 237 return 0;
236} 238}
237 239
@@ -285,12 +287,14 @@ static struct platform_driver ks8695wdt_driver = {
285 287
286static int __init ks8695_wdt_init(void) 288static int __init ks8695_wdt_init(void)
287{ 289{
288 /* Check that the heartbeat value is within range; if not reset to the default */ 290 spin_lock_init(&ks8695_lock);
291 /* Check that the heartbeat value is within range;
292 if not reset to the default */
289 if (ks8695_wdt_settimeout(wdt_time)) { 293 if (ks8695_wdt_settimeout(wdt_time)) {
290 ks8695_wdt_settimeout(WDT_DEFAULT_TIME); 294 ks8695_wdt_settimeout(WDT_DEFAULT_TIME);
291 pr_info("ks8695_wdt: wdt_time value must be 1 <= wdt_time <= %i, using %d\n", wdt_time, WDT_MAX_TIME); 295 pr_info("ks8695_wdt: wdt_time value must be 1 <= wdt_time <= %i, using %d\n",
296 wdt_time, WDT_MAX_TIME);
292 } 297 }
293
294 return platform_driver_register(&ks8695wdt_driver); 298 return platform_driver_register(&ks8695wdt_driver);
295} 299}
296 300