| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | *  IDT Interprise 79RC32434 watchdog driver | 
|  | 3 | * | 
|  | 4 | *  Copyright (C) 2006, Ondrej Zajicek <santiago@crfreenet.org> | 
|  | 5 | *  Copyright (C) 2008, Florian Fainelli <florian@openwrt.org> | 
|  | 6 | * | 
|  | 7 | *  based on | 
|  | 8 | *  SoftDog 0.05:	A Software Watchdog Device | 
|  | 9 | * | 
| Alan Cox | 29fa058 | 2008-10-27 15:17:56 +0000 | [diff] [blame] | 10 | *  (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>, | 
|  | 11 | *					All Rights Reserved. | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 12 | * | 
|  | 13 | *  This program is free software; you can redistribute it and/or | 
|  | 14 | *  modify it under the terms of the GNU General Public License | 
|  | 15 | *  as published by the Free Software Foundation; either version | 
|  | 16 | *  2 of the License, or (at your option) any later version. | 
|  | 17 | * | 
|  | 18 | */ | 
|  | 19 |  | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 20 | #include <linux/module.h>		/* For module specific items */ | 
|  | 21 | #include <linux/moduleparam.h>		/* For new moduleparam's */ | 
|  | 22 | #include <linux/types.h>		/* For standard types (like size_t) */ | 
|  | 23 | #include <linux/errno.h>		/* For the -ENODEV/... values */ | 
|  | 24 | #include <linux/kernel.h>		/* For printk/panic/... */ | 
|  | 25 | #include <linux/fs.h>			/* For file operations */ | 
|  | 26 | #include <linux/miscdevice.h>		/* For MODULE_ALIAS_MISCDEV | 
|  | 27 | (WATCHDOG_MINOR) */ | 
|  | 28 | #include <linux/watchdog.h>		/* For the watchdog specific items */ | 
|  | 29 | #include <linux/init.h>			/* For __init/__exit/... */ | 
|  | 30 | #include <linux/platform_device.h>	/* For platform_driver framework */ | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 31 | #include <linux/spinlock.h>		/* For spin_lock/spin_unlock/... */ | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 32 | #include <linux/uaccess.h>		/* For copy_to_user/put_user/... */ | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 33 |  | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 34 | #include <asm/mach-rc32434/integ.h>	/* For the Watchdog registers */ | 
|  | 35 |  | 
|  | 36 | #define PFX KBUILD_MODNAME ": " | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 37 |  | 
| Wim Van Sebroeck | f296b14 | 2009-02-23 13:08:37 +0000 | [diff] [blame] | 38 | #define VERSION "1.0" | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 39 |  | 
|  | 40 | static struct { | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 41 | unsigned long inuse; | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 42 | spinlock_t io_lock; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 43 | } rc32434_wdt_device; | 
|  | 44 |  | 
|  | 45 | static struct integ __iomem *wdt_reg; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 46 |  | 
|  | 47 | static int expect_close; | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 48 |  | 
|  | 49 | /* Board internal clock speed in Hz, | 
|  | 50 | * the watchdog timer ticks at. */ | 
|  | 51 | extern unsigned int idt_cpu_freq; | 
|  | 52 |  | 
|  | 53 | /* translate wtcompare value to seconds and vice versa */ | 
|  | 54 | #define WTCOMP2SEC(x)	(x / idt_cpu_freq) | 
|  | 55 | #define SEC2WTCOMP(x)	(x * idt_cpu_freq) | 
|  | 56 |  | 
|  | 57 | /* Use a default timeout of 20s. This should be | 
|  | 58 | * safe for CPU clock speeds up to 400MHz, as | 
|  | 59 | * ((2 ^ 32) - 1) / (400MHz / 2) = 21s.  */ | 
|  | 60 | #define WATCHDOG_TIMEOUT 20 | 
|  | 61 |  | 
|  | 62 | static int timeout = WATCHDOG_TIMEOUT; | 
| Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 63 | module_param(timeout, int, 0); | 
|  | 64 | MODULE_PARM_DESC(timeout, "Watchdog timeout value, in seconds (default=" | 
| Florian Fainelli | 810a90a | 2009-12-02 13:21:23 +0100 | [diff] [blame] | 65 | __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 66 |  | 
|  | 67 | static int nowayout = WATCHDOG_NOWAYOUT; | 
|  | 68 | module_param(nowayout, int, 0); | 
|  | 69 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" | 
|  | 70 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 
|  | 71 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 72 | /* apply or and nand masks to data read from addr and write back */ | 
|  | 73 | #define SET_BITS(addr, or, nand) \ | 
|  | 74 | writel((readl(&addr) | or) & ~nand, &addr) | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 75 |  | 
| Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 76 | static int rc32434_wdt_set(int new_timeout) | 
|  | 77 | { | 
|  | 78 | int max_to = WTCOMP2SEC((u32)-1); | 
|  | 79 |  | 
|  | 80 | if (new_timeout < 0 || new_timeout > max_to) { | 
|  | 81 | printk(KERN_ERR PFX "timeout value must be between 0 and %d", | 
|  | 82 | max_to); | 
|  | 83 | return -EINVAL; | 
|  | 84 | } | 
|  | 85 | timeout = new_timeout; | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 86 | spin_lock(&rc32434_wdt_device.io_lock); | 
| Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 87 | writel(SEC2WTCOMP(timeout), &wdt_reg->wtcompare); | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 88 | spin_unlock(&rc32434_wdt_device.io_lock); | 
| Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 89 |  | 
|  | 90 | return 0; | 
|  | 91 | } | 
|  | 92 |  | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 93 | static void rc32434_wdt_start(void) | 
|  | 94 | { | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 95 | u32 or, nand; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 96 |  | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 97 | spin_lock(&rc32434_wdt_device.io_lock); | 
|  | 98 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 99 | /* zero the counter before enabling */ | 
|  | 100 | writel(0, &wdt_reg->wtcount); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 101 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 102 | /* don't generate a non-maskable interrupt, | 
|  | 103 | * do a warm reset instead */ | 
|  | 104 | nand = 1 << RC32434_ERR_WNE; | 
|  | 105 | or = 1 << RC32434_ERR_WRE; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 106 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 107 | /* reset the ERRCS timeout bit in case it's set */ | 
|  | 108 | nand |= 1 << RC32434_ERR_WTO; | 
|  | 109 |  | 
|  | 110 | SET_BITS(wdt_reg->errcs, or, nand); | 
|  | 111 |  | 
| Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 112 | /* set the timeout (either default or based on module param) */ | 
|  | 113 | rc32434_wdt_set(timeout); | 
|  | 114 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 115 | /* reset WTC timeout bit and enable WDT */ | 
|  | 116 | nand = 1 << RC32434_WTC_TO; | 
|  | 117 | or = 1 << RC32434_WTC_EN; | 
|  | 118 |  | 
|  | 119 | SET_BITS(wdt_reg->wtc, or, nand); | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 120 |  | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 121 | spin_unlock(&rc32434_wdt_device.io_lock); | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 122 | printk(KERN_INFO PFX "Started watchdog timer.\n"); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 123 | } | 
|  | 124 |  | 
|  | 125 | static void rc32434_wdt_stop(void) | 
|  | 126 | { | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 127 | spin_lock(&rc32434_wdt_device.io_lock); | 
|  | 128 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 129 | /* Disable WDT */ | 
|  | 130 | SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN); | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 131 |  | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 132 | spin_unlock(&rc32434_wdt_device.io_lock); | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 133 | printk(KERN_INFO PFX "Stopped watchdog timer.\n"); | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 134 | } | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 135 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 136 | static void rc32434_wdt_ping(void) | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 137 | { | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 138 | spin_lock(&rc32434_wdt_device.io_lock); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 139 | writel(0, &wdt_reg->wtcount); | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 140 | spin_unlock(&rc32434_wdt_device.io_lock); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
|  | 143 | static int rc32434_wdt_open(struct inode *inode, struct file *file) | 
|  | 144 | { | 
|  | 145 | if (test_and_set_bit(0, &rc32434_wdt_device.inuse)) | 
|  | 146 | return -EBUSY; | 
|  | 147 |  | 
|  | 148 | if (nowayout) | 
|  | 149 | __module_get(THIS_MODULE); | 
|  | 150 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 151 | rc32434_wdt_start(); | 
|  | 152 | rc32434_wdt_ping(); | 
|  | 153 |  | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 154 | return nonseekable_open(inode, file); | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | static int rc32434_wdt_release(struct inode *inode, struct file *file) | 
|  | 158 | { | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 159 | if (expect_close == 42) { | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 160 | rc32434_wdt_stop(); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 161 | module_put(THIS_MODULE); | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 162 | } else { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 163 | printk(KERN_CRIT PFX | 
|  | 164 | "device closed unexpectedly. WDT will not stop!\n"); | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 165 | rc32434_wdt_ping(); | 
|  | 166 | } | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 167 | clear_bit(0, &rc32434_wdt_device.inuse); | 
|  | 168 | return 0; | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | static ssize_t rc32434_wdt_write(struct file *file, const char *data, | 
|  | 172 | size_t len, loff_t *ppos) | 
|  | 173 | { | 
|  | 174 | if (len) { | 
|  | 175 | if (!nowayout) { | 
|  | 176 | size_t i; | 
|  | 177 |  | 
|  | 178 | /* In case it was set long ago */ | 
|  | 179 | expect_close = 0; | 
|  | 180 |  | 
|  | 181 | for (i = 0; i != len; i++) { | 
|  | 182 | char c; | 
|  | 183 | if (get_user(c, data + i)) | 
|  | 184 | return -EFAULT; | 
|  | 185 | if (c == 'V') | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 186 | expect_close = 42; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 187 | } | 
|  | 188 | } | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 189 | rc32434_wdt_ping(); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 190 | return len; | 
|  | 191 | } | 
|  | 192 | return 0; | 
|  | 193 | } | 
|  | 194 |  | 
| Wim Van Sebroeck | 7275fc8 | 2008-09-18 12:26:15 +0000 | [diff] [blame] | 195 | static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd, | 
|  | 196 | unsigned long arg) | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 197 | { | 
|  | 198 | void __user *argp = (void __user *)arg; | 
|  | 199 | int new_timeout; | 
|  | 200 | unsigned int value; | 
| Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 201 | static const struct watchdog_info ident = { | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 202 | .options =		WDIOF_SETTIMEOUT | | 
|  | 203 | WDIOF_KEEPALIVEPING | | 
|  | 204 | WDIOF_MAGICCLOSE, | 
|  | 205 | .identity =		"RC32434_WDT Watchdog", | 
|  | 206 | }; | 
|  | 207 | switch (cmd) { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 208 | case WDIOC_GETSUPPORT: | 
|  | 209 | if (copy_to_user(argp, &ident, sizeof(ident))) | 
|  | 210 | return -EFAULT; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 211 | break; | 
|  | 212 | case WDIOC_GETSTATUS: | 
|  | 213 | case WDIOC_GETBOOTSTATUS: | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 214 | value = 0; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 215 | if (copy_to_user(argp, &value, sizeof(int))) | 
|  | 216 | return -EFAULT; | 
|  | 217 | break; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 218 | case WDIOC_SETOPTIONS: | 
|  | 219 | if (copy_from_user(&value, argp, sizeof(int))) | 
|  | 220 | return -EFAULT; | 
|  | 221 | switch (value) { | 
|  | 222 | case WDIOS_ENABLECARD: | 
|  | 223 | rc32434_wdt_start(); | 
|  | 224 | break; | 
|  | 225 | case WDIOS_DISABLECARD: | 
|  | 226 | rc32434_wdt_stop(); | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 227 | break; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 228 | default: | 
|  | 229 | return -EINVAL; | 
|  | 230 | } | 
|  | 231 | break; | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 232 | case WDIOC_KEEPALIVE: | 
|  | 233 | rc32434_wdt_ping(); | 
|  | 234 | break; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 235 | case WDIOC_SETTIMEOUT: | 
|  | 236 | if (copy_from_user(&new_timeout, argp, sizeof(int))) | 
|  | 237 | return -EFAULT; | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 238 | if (rc32434_wdt_set(new_timeout)) | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 239 | return -EINVAL; | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 240 | /* Fall through */ | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 241 | case WDIOC_GETTIMEOUT: | 
|  | 242 | return copy_to_user(argp, &timeout, sizeof(int)); | 
|  | 243 | default: | 
|  | 244 | return -ENOTTY; | 
|  | 245 | } | 
|  | 246 |  | 
|  | 247 | return 0; | 
|  | 248 | } | 
|  | 249 |  | 
| Wim Van Sebroeck | d5c26a5 | 2009-03-18 08:18:43 +0000 | [diff] [blame] | 250 | static const struct file_operations rc32434_wdt_fops = { | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 251 | .owner		= THIS_MODULE, | 
|  | 252 | .llseek		= no_llseek, | 
|  | 253 | .write		= rc32434_wdt_write, | 
| Wim Van Sebroeck | 7275fc8 | 2008-09-18 12:26:15 +0000 | [diff] [blame] | 254 | .unlocked_ioctl	= rc32434_wdt_ioctl, | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 255 | .open		= rc32434_wdt_open, | 
|  | 256 | .release	= rc32434_wdt_release, | 
|  | 257 | }; | 
|  | 258 |  | 
|  | 259 | static struct miscdevice rc32434_wdt_miscdev = { | 
|  | 260 | .minor	= WATCHDOG_MINOR, | 
|  | 261 | .name	= "watchdog", | 
|  | 262 | .fops	= &rc32434_wdt_fops, | 
|  | 263 | }; | 
|  | 264 |  | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 265 | static char banner[] __devinitdata = KERN_INFO PFX | 
|  | 266 | "Watchdog Timer version " VERSION ", timer margin: %d sec\n"; | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 267 |  | 
| Phil Sutter | d9a8798 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 268 | static int __devinit rc32434_wdt_probe(struct platform_device *pdev) | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 269 | { | 
|  | 270 | int ret; | 
|  | 271 | struct resource *r; | 
|  | 272 |  | 
| Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 273 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rb532_wdt_res"); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 274 | if (!r) { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 275 | printk(KERN_ERR PFX "failed to retrieve resources\n"); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 276 | return -ENODEV; | 
|  | 277 | } | 
|  | 278 |  | 
| H Hartley Sweeten | be088b1 | 2009-11-24 21:06:26 -0500 | [diff] [blame] | 279 | wdt_reg = ioremap_nocache(r->start, resource_size(r)); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 280 | if (!wdt_reg) { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 281 | printk(KERN_ERR PFX "failed to remap I/O resources\n"); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 282 | return -ENXIO; | 
|  | 283 | } | 
|  | 284 |  | 
| Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 285 | spin_lock_init(&rc32434_wdt_device.io_lock); | 
|  | 286 |  | 
| Wim Van Sebroeck | f296b14 | 2009-02-23 13:08:37 +0000 | [diff] [blame] | 287 | /* Make sure the watchdog is not running */ | 
|  | 288 | rc32434_wdt_stop(); | 
|  | 289 |  | 
| Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 290 | /* Check that the heartbeat value is within it's range; | 
|  | 291 | * if not reset to the default */ | 
|  | 292 | if (rc32434_wdt_set(timeout)) { | 
|  | 293 | rc32434_wdt_set(WATCHDOG_TIMEOUT); | 
|  | 294 | printk(KERN_INFO PFX | 
|  | 295 | "timeout value must be between 0 and %d\n", | 
|  | 296 | WTCOMP2SEC((u32)-1)); | 
|  | 297 | } | 
|  | 298 |  | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 299 | ret = misc_register(&rc32434_wdt_miscdev); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 300 | if (ret < 0) { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 301 | printk(KERN_ERR PFX "failed to register watchdog device\n"); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 302 | goto unmap; | 
|  | 303 | } | 
|  | 304 |  | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 305 | printk(banner, timeout); | 
|  | 306 |  | 
|  | 307 | return 0; | 
|  | 308 |  | 
|  | 309 | unmap: | 
|  | 310 | iounmap(wdt_reg); | 
|  | 311 | return ret; | 
|  | 312 | } | 
|  | 313 |  | 
| Phil Sutter | d9a8798 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 314 | static int __devexit rc32434_wdt_remove(struct platform_device *pdev) | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 315 | { | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 316 | misc_deregister(&rc32434_wdt_miscdev); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 317 | iounmap(wdt_reg); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 318 | return 0; | 
|  | 319 | } | 
|  | 320 |  | 
| Wim Van Sebroeck | 0aaae66 | 2009-02-23 13:08:35 +0000 | [diff] [blame] | 321 | static void rc32434_wdt_shutdown(struct platform_device *pdev) | 
|  | 322 | { | 
|  | 323 | rc32434_wdt_stop(); | 
|  | 324 | } | 
|  | 325 |  | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 326 | static struct platform_driver rc32434_wdt_driver = { | 
| Wim Van Sebroeck | 0aaae66 | 2009-02-23 13:08:35 +0000 | [diff] [blame] | 327 | .probe		= rc32434_wdt_probe, | 
|  | 328 | .remove		= __devexit_p(rc32434_wdt_remove), | 
|  | 329 | .shutdown	= rc32434_wdt_shutdown, | 
|  | 330 | .driver		= { | 
|  | 331 | .name = "rc32434_wdt", | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 332 | } | 
|  | 333 | }; | 
|  | 334 |  | 
|  | 335 | static int __init rc32434_wdt_init(void) | 
|  | 336 | { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 337 | return platform_driver_register(&rc32434_wdt_driver); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 338 | } | 
|  | 339 |  | 
|  | 340 | static void __exit rc32434_wdt_exit(void) | 
|  | 341 | { | 
| Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 342 | platform_driver_unregister(&rc32434_wdt_driver); | 
| Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 343 | } | 
|  | 344 |  | 
|  | 345 | module_init(rc32434_wdt_init); | 
|  | 346 | module_exit(rc32434_wdt_exit); | 
|  | 347 |  | 
|  | 348 | MODULE_AUTHOR("Ondrej Zajicek <santiago@crfreenet.org>," | 
|  | 349 | "Florian Fainelli <florian@openwrt.org>"); | 
|  | 350 | MODULE_DESCRIPTION("Driver for the IDT RC32434 SoC watchdog"); | 
|  | 351 | MODULE_LICENSE("GPL"); | 
|  | 352 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |