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