Blame view
drivers/watchdog/ks8695_wdt.c
7.65 KB
ccb8f430a [WATCHDOG] ks8695... |
1 2 3 4 5 6 7 8 9 |
/* * Watchdog driver for Kendin/Micrel KS8695. * * (C) 2007 Andrew Victor * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ |
27c766aaa watchdog: Use pr_... |
10 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1977f0327 remove asm/bitops... |
11 |
#include <linux/bitops.h> |
ccb8f430a [WATCHDOG] ks8695... |
12 13 14 15 16 17 18 19 20 21 |
#include <linux/errno.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/miscdevice.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/platform_device.h> #include <linux/types.h> #include <linux/watchdog.h> |
f4fabce15 [WATCHDOG 23/57] ... |
22 23 |
#include <linux/io.h> #include <linux/uaccess.h> |
568dba66a watchdog: ks8695_... |
24 |
#include <mach/hardware.h> |
cab463a29 watchdog: ks8695:... |
25 26 27 28 29 30 31 32 33 34 35 36 37 |
#define KS8695_TMR_OFFSET (0xF0000 + 0xE400) #define KS8695_TMR_VA (KS8695_IO_VA + KS8695_TMR_OFFSET) /* * Timer registers */ #define KS8695_TMCON (0x00) /* Timer Control Register */ #define KS8695_T0TC (0x08) /* Timer 0 Timeout Count Register */ #define TMCON_T0EN (1 << 0) /* Timer 0 Enable */ /* Timer0 Timeout Counter Register */ #define T0TC_WATCHDOG (0xff) /* Enable watchdog mode */ |
ccb8f430a [WATCHDOG] ks8695... |
38 |
|
ccb8f430a [WATCHDOG] ks8695... |
39 40 41 42 |
#define WDT_DEFAULT_TIME 5 /* seconds */ #define WDT_MAX_TIME 171 /* seconds */ static int wdt_time = WDT_DEFAULT_TIME; |
86a1e1896 watchdog: nowayou... |
43 |
static bool nowayout = WATCHDOG_NOWAYOUT; |
ccb8f430a [WATCHDOG] ks8695... |
44 45 |
module_param(wdt_time, int, 0); |
f4fabce15 [WATCHDOG 23/57] ... |
46 47 |
MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" __MODULE_STRING(WDT_DEFAULT_TIME) ")"); |
ccb8f430a [WATCHDOG] ks8695... |
48 49 |
#ifdef CONFIG_WATCHDOG_NOWAYOUT |
86a1e1896 watchdog: nowayou... |
50 |
module_param(nowayout, bool, 0); |
f4fabce15 [WATCHDOG 23/57] ... |
51 52 |
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
ccb8f430a [WATCHDOG] ks8695... |
53 54 55 56 |
#endif static unsigned long ks8695wdt_busy; |
1334f3293 watchdog: Use DEF... |
57 |
static DEFINE_SPINLOCK(ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
58 59 60 61 62 63 |
/* ......................................................................... */ /* * Disable the watchdog. */ |
f4fabce15 [WATCHDOG 23/57] ... |
64 |
static inline void ks8695_wdt_stop(void) |
ccb8f430a [WATCHDOG] ks8695... |
65 66 |
{ unsigned long tmcon; |
f4fabce15 [WATCHDOG 23/57] ... |
67 |
spin_lock(&ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
68 69 70 |
/* disable timer0 */ tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); |
f4fabce15 [WATCHDOG 23/57] ... |
71 |
spin_unlock(&ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
72 73 74 75 76 |
} /* * Enable and reset the watchdog. */ |
f4fabce15 [WATCHDOG 23/57] ... |
77 |
static inline void ks8695_wdt_start(void) |
ccb8f430a [WATCHDOG] ks8695... |
78 79 |
{ unsigned long tmcon; |
0a51810aa ARM: 5637/1: [KS8... |
80 |
unsigned long tval = wdt_time * KS8695_CLOCK_RATE; |
ccb8f430a [WATCHDOG] ks8695... |
81 |
|
f4fabce15 [WATCHDOG 23/57] ... |
82 |
spin_lock(&ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
83 84 85 86 87 88 89 90 91 92 |
/* disable timer0 */ tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); /* program timer0 */ __raw_writel(tval | T0TC_WATCHDOG, KS8695_TMR_VA + KS8695_T0TC); /* re-enable timer0 */ tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); |
f4fabce15 [WATCHDOG 23/57] ... |
93 |
spin_unlock(&ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
94 95 96 97 98 |
} /* * Reload the watchdog timer. (ie, pat the watchdog) */ |
f4fabce15 [WATCHDOG 23/57] ... |
99 |
static inline void ks8695_wdt_reload(void) |
ccb8f430a [WATCHDOG] ks8695... |
100 101 |
{ unsigned long tmcon; |
f4fabce15 [WATCHDOG 23/57] ... |
102 |
spin_lock(&ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
103 104 105 106 |
/* disable, then re-enable timer0 */ tmcon = __raw_readl(KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon & ~TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); __raw_writel(tmcon | TMCON_T0EN, KS8695_TMR_VA + KS8695_TMCON); |
f4fabce15 [WATCHDOG 23/57] ... |
107 |
spin_unlock(&ks8695_lock); |
ccb8f430a [WATCHDOG] ks8695... |
108 109 110 111 112 113 114 115 |
} /* * Change the watchdog time interval. */ static int ks8695_wdt_settimeout(int new_time) { /* |
0a51810aa ARM: 5637/1: [KS8... |
116 |
* All counting occurs at KS8695_CLOCK_RATE / 128 = 0.256 Hz |
ccb8f430a [WATCHDOG] ks8695... |
117 118 119 120 121 122 |
* * Since WDV is a 16-bit counter, the maximum period is * 65536 / 0.256 = 256 seconds. */ if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) return -EINVAL; |
f4fabce15 [WATCHDOG 23/57] ... |
123 124 |
/* Set new watchdog time. It will be used when ks8695_wdt_start() is called. */ |
ccb8f430a [WATCHDOG] ks8695... |
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
wdt_time = new_time; return 0; } /* ......................................................................... */ /* * Watchdog device is opened, and watchdog starts running. */ static int ks8695_wdt_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &ks8695wdt_busy)) return -EBUSY; ks8695_wdt_start(); return nonseekable_open(inode, file); } /* * Close the watchdog device. * If CONFIG_WATCHDOG_NOWAYOUT is NOT defined then the watchdog is also * disabled. */ static int ks8695_wdt_close(struct inode *inode, struct file *file) { |
f4fabce15 [WATCHDOG 23/57] ... |
150 |
/* Disable the watchdog when file is closed */ |
ccb8f430a [WATCHDOG] ks8695... |
151 |
if (!nowayout) |
f4fabce15 [WATCHDOG 23/57] ... |
152 |
ks8695_wdt_stop(); |
ccb8f430a [WATCHDOG] ks8695... |
153 154 155 |
clear_bit(0, &ks8695wdt_busy); return 0; } |
42747d712 [WATCHDOG] watchd... |
156 |
static const struct watchdog_info ks8695_wdt_info = { |
ccb8f430a [WATCHDOG] ks8695... |
157 158 159 160 161 162 163 |
.identity = "ks8695 watchdog", .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, }; /* * Handle commands from user-space. */ |
f4fabce15 [WATCHDOG 23/57] ... |
164 165 |
static long ks8695_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
ccb8f430a [WATCHDOG] ks8695... |
166 167 168 169 |
{ void __user *argp = (void __user *)arg; int __user *p = argp; int new_value; |
f4fabce15 [WATCHDOG 23/57] ... |
170 |
switch (cmd) { |
f4fabce15 [WATCHDOG 23/57] ... |
171 172 173 |
case WDIOC_GETSUPPORT: return copy_to_user(argp, &ks8695_wdt_info, sizeof(ks8695_wdt_info)) ? -EFAULT : 0; |
f4fabce15 [WATCHDOG 23/57] ... |
174 175 176 177 178 179 180 181 182 |
case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, p); case WDIOC_SETOPTIONS: if (get_user(new_value, p)) return -EFAULT; if (new_value & WDIOS_DISABLECARD) ks8695_wdt_stop(); if (new_value & WDIOS_ENABLECARD) |
ccb8f430a [WATCHDOG] ks8695... |
183 |
ks8695_wdt_start(); |
f4fabce15 [WATCHDOG 23/57] ... |
184 |
return 0; |
0c06090c9 [WATCHDOG] Coding... |
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
case WDIOC_KEEPALIVE: ks8695_wdt_reload(); /* pat the watchdog */ return 0; case WDIOC_SETTIMEOUT: if (get_user(new_value, p)) return -EFAULT; if (ks8695_wdt_settimeout(new_value)) return -EINVAL; /* Enable new time value */ ks8695_wdt_start(); /* Return current value */ return put_user(wdt_time, p); case WDIOC_GETTIMEOUT: return put_user(wdt_time, p); |
f4fabce15 [WATCHDOG 23/57] ... |
199 200 |
default: return -ENOTTY; |
ccb8f430a [WATCHDOG] ks8695... |
201 202 203 204 205 206 |
} } /* * Pat the watchdog whenever device is written to. */ |
f4fabce15 [WATCHDOG 23/57] ... |
207 208 |
static ssize_t ks8695_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos) |
ccb8f430a [WATCHDOG] ks8695... |
209 210 211 212 213 214 215 216 217 218 |
{ ks8695_wdt_reload(); /* pat the watchdog */ return len; } /* ......................................................................... */ static const struct file_operations ks8695wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, |
f4fabce15 [WATCHDOG 23/57] ... |
219 |
.unlocked_ioctl = ks8695_wdt_ioctl, |
ccb8f430a [WATCHDOG] ks8695... |
220 221 222 223 224 225 226 227 228 229 |
.open = ks8695_wdt_open, .release = ks8695_wdt_close, .write = ks8695_wdt_write, }; static struct miscdevice ks8695wdt_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &ks8695wdt_fops, }; |
2d991a164 watchdog: remove ... |
230 |
static int ks8695wdt_probe(struct platform_device *pdev) |
ccb8f430a [WATCHDOG] ks8695... |
231 232 233 234 235 236 237 238 239 240 |
{ int res; if (ks8695wdt_miscdev.parent) return -EBUSY; ks8695wdt_miscdev.parent = &pdev->dev; res = misc_register(&ks8695wdt_miscdev); if (res) return res; |
27c766aaa watchdog: Use pr_... |
241 242 243 |
pr_info("KS8695 Watchdog Timer enabled (%d seconds%s) ", wdt_time, nowayout ? ", nowayout" : ""); |
ccb8f430a [WATCHDOG] ks8695... |
244 245 |
return 0; } |
4b12b896c watchdog: remove ... |
246 |
static int ks8695wdt_remove(struct platform_device *pdev) |
ccb8f430a [WATCHDOG] ks8695... |
247 |
{ |
f368ed608 char: make misc_d... |
248 249 |
misc_deregister(&ks8695wdt_miscdev); ks8695wdt_miscdev.parent = NULL; |
ccb8f430a [WATCHDOG] ks8695... |
250 |
|
f368ed608 char: make misc_d... |
251 |
return 0; |
ccb8f430a [WATCHDOG] ks8695... |
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
} static void ks8695wdt_shutdown(struct platform_device *pdev) { ks8695_wdt_stop(); } #ifdef CONFIG_PM static int ks8695wdt_suspend(struct platform_device *pdev, pm_message_t message) { ks8695_wdt_stop(); return 0; } static int ks8695wdt_resume(struct platform_device *pdev) { if (ks8695wdt_busy) ks8695_wdt_start(); return 0; } #else #define ks8695wdt_suspend NULL #define ks8695wdt_resume NULL #endif static struct platform_driver ks8695wdt_driver = { .probe = ks8695wdt_probe, |
82268714b watchdog: remove ... |
281 |
.remove = ks8695wdt_remove, |
ccb8f430a [WATCHDOG] ks8695... |
282 283 284 285 286 |
.shutdown = ks8695wdt_shutdown, .suspend = ks8695wdt_suspend, .resume = ks8695wdt_resume, .driver = { .name = "ks8695_wdt", |
ccb8f430a [WATCHDOG] ks8695... |
287 288 289 290 291 |
}, }; static int __init ks8695_wdt_init(void) { |
f4fabce15 [WATCHDOG 23/57] ... |
292 293 |
/* Check that the heartbeat value is within range; if not reset to the default */ |
ccb8f430a [WATCHDOG] ks8695... |
294 295 |
if (ks8695_wdt_settimeout(wdt_time)) { ks8695_wdt_settimeout(WDT_DEFAULT_TIME); |
a77dba7e4 [WATCHDOG] Some m... |
296 297 298 |
pr_info("ks8695_wdt: wdt_time value must be 1 <= wdt_time <= %i" ", using %d ", wdt_time, WDT_MAX_TIME); |
ccb8f430a [WATCHDOG] ks8695... |
299 |
} |
ccb8f430a [WATCHDOG] ks8695... |
300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
return platform_driver_register(&ks8695wdt_driver); } static void __exit ks8695_wdt_exit(void) { platform_driver_unregister(&ks8695wdt_driver); } module_init(ks8695_wdt_init); module_exit(ks8695_wdt_exit); MODULE_AUTHOR("Andrew Victor"); MODULE_DESCRIPTION("Watchdog driver for KS8695"); MODULE_LICENSE("GPL"); |
f37d193c7 watchdog: fix pla... |
314 |
MODULE_ALIAS("platform:ks8695_wdt"); |