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 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 22 | #include <linux/module.h> /* For module specific items */ |
| 23 | #include <linux/moduleparam.h> /* For new moduleparam's */ |
| 24 | #include <linux/types.h> /* For standard types (like size_t) */ |
| 25 | #include <linux/errno.h> /* For the -ENODEV/... values */ |
| 26 | #include <linux/kernel.h> /* For printk/panic/... */ |
| 27 | #include <linux/fs.h> /* For file operations */ |
| 28 | #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV |
| 29 | (WATCHDOG_MINOR) */ |
| 30 | #include <linux/watchdog.h> /* For the watchdog specific items */ |
| 31 | #include <linux/init.h> /* For __init/__exit/... */ |
| 32 | #include <linux/platform_device.h> /* For platform_driver framework */ |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 33 | #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */ |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 34 | #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 35 | |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 36 | #include <asm/mach-rc32434/integ.h> /* For the Watchdog registers */ |
| 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 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 67 | static bool nowayout = WATCHDOG_NOWAYOUT; |
| 68 | module_param(nowayout, bool, 0); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 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) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 81 | pr_err("timeout value must be between 0 and %d\n", max_to); |
Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 82 | return -EINVAL; |
| 83 | } |
| 84 | timeout = new_timeout; |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 85 | spin_lock(&rc32434_wdt_device.io_lock); |
Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 86 | writel(SEC2WTCOMP(timeout), &wdt_reg->wtcompare); |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 87 | spin_unlock(&rc32434_wdt_device.io_lock); |
Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 92 | static void rc32434_wdt_start(void) |
| 93 | { |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 94 | u32 or, nand; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 95 | |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 96 | spin_lock(&rc32434_wdt_device.io_lock); |
| 97 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 98 | /* zero the counter before enabling */ |
| 99 | writel(0, &wdt_reg->wtcount); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 100 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 101 | /* don't generate a non-maskable interrupt, |
| 102 | * do a warm reset instead */ |
| 103 | nand = 1 << RC32434_ERR_WNE; |
| 104 | or = 1 << RC32434_ERR_WRE; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 105 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 106 | /* reset the ERRCS timeout bit in case it's set */ |
| 107 | nand |= 1 << RC32434_ERR_WTO; |
| 108 | |
| 109 | SET_BITS(wdt_reg->errcs, or, nand); |
| 110 | |
Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 111 | /* set the timeout (either default or based on module param) */ |
| 112 | rc32434_wdt_set(timeout); |
| 113 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 114 | /* reset WTC timeout bit and enable WDT */ |
| 115 | nand = 1 << RC32434_WTC_TO; |
| 116 | or = 1 << RC32434_WTC_EN; |
| 117 | |
| 118 | SET_BITS(wdt_reg->wtc, or, nand); |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 119 | |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 120 | spin_unlock(&rc32434_wdt_device.io_lock); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 121 | pr_info("Started watchdog timer\n"); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static void rc32434_wdt_stop(void) |
| 125 | { |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 126 | spin_lock(&rc32434_wdt_device.io_lock); |
| 127 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 128 | /* Disable WDT */ |
| 129 | SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN); |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 130 | |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 131 | spin_unlock(&rc32434_wdt_device.io_lock); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 132 | pr_info("Stopped watchdog timer\n"); |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 133 | } |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 134 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 135 | static void rc32434_wdt_ping(void) |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 136 | { |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 137 | spin_lock(&rc32434_wdt_device.io_lock); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 138 | writel(0, &wdt_reg->wtcount); |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 139 | spin_unlock(&rc32434_wdt_device.io_lock); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static int rc32434_wdt_open(struct inode *inode, struct file *file) |
| 143 | { |
| 144 | if (test_and_set_bit(0, &rc32434_wdt_device.inuse)) |
| 145 | return -EBUSY; |
| 146 | |
| 147 | if (nowayout) |
| 148 | __module_get(THIS_MODULE); |
| 149 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 150 | rc32434_wdt_start(); |
| 151 | rc32434_wdt_ping(); |
| 152 | |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 153 | return nonseekable_open(inode, file); |
| 154 | } |
| 155 | |
| 156 | static int rc32434_wdt_release(struct inode *inode, struct file *file) |
| 157 | { |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 158 | if (expect_close == 42) { |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 159 | rc32434_wdt_stop(); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 160 | module_put(THIS_MODULE); |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 161 | } else { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 162 | pr_crit("device closed unexpectedly. WDT will not stop!\n"); |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 163 | rc32434_wdt_ping(); |
| 164 | } |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 165 | clear_bit(0, &rc32434_wdt_device.inuse); |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static ssize_t rc32434_wdt_write(struct file *file, const char *data, |
| 170 | size_t len, loff_t *ppos) |
| 171 | { |
| 172 | if (len) { |
| 173 | if (!nowayout) { |
| 174 | size_t i; |
| 175 | |
| 176 | /* In case it was set long ago */ |
| 177 | expect_close = 0; |
| 178 | |
| 179 | for (i = 0; i != len; i++) { |
| 180 | char c; |
| 181 | if (get_user(c, data + i)) |
| 182 | return -EFAULT; |
| 183 | if (c == 'V') |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 184 | expect_close = 42; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 185 | } |
| 186 | } |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 187 | rc32434_wdt_ping(); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 188 | return len; |
| 189 | } |
| 190 | return 0; |
| 191 | } |
| 192 | |
Wim Van Sebroeck | 7275fc8 | 2008-09-18 12:26:15 +0000 | [diff] [blame] | 193 | static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd, |
| 194 | unsigned long arg) |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 195 | { |
| 196 | void __user *argp = (void __user *)arg; |
| 197 | int new_timeout; |
| 198 | unsigned int value; |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 199 | static const struct watchdog_info ident = { |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 200 | .options = WDIOF_SETTIMEOUT | |
| 201 | WDIOF_KEEPALIVEPING | |
| 202 | WDIOF_MAGICCLOSE, |
| 203 | .identity = "RC32434_WDT Watchdog", |
| 204 | }; |
| 205 | switch (cmd) { |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 206 | case WDIOC_GETSUPPORT: |
| 207 | if (copy_to_user(argp, &ident, sizeof(ident))) |
| 208 | return -EFAULT; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 209 | break; |
| 210 | case WDIOC_GETSTATUS: |
| 211 | case WDIOC_GETBOOTSTATUS: |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 212 | value = 0; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 213 | if (copy_to_user(argp, &value, sizeof(int))) |
| 214 | return -EFAULT; |
| 215 | break; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 216 | case WDIOC_SETOPTIONS: |
| 217 | if (copy_from_user(&value, argp, sizeof(int))) |
| 218 | return -EFAULT; |
| 219 | switch (value) { |
| 220 | case WDIOS_ENABLECARD: |
| 221 | rc32434_wdt_start(); |
| 222 | break; |
| 223 | case WDIOS_DISABLECARD: |
| 224 | rc32434_wdt_stop(); |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 225 | break; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 226 | default: |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | break; |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 230 | case WDIOC_KEEPALIVE: |
| 231 | rc32434_wdt_ping(); |
| 232 | break; |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 233 | case WDIOC_SETTIMEOUT: |
| 234 | if (copy_from_user(&new_timeout, argp, sizeof(int))) |
| 235 | return -EFAULT; |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 236 | if (rc32434_wdt_set(new_timeout)) |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 237 | return -EINVAL; |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 238 | /* Fall through */ |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 239 | case WDIOC_GETTIMEOUT: |
| 240 | return copy_to_user(argp, &timeout, sizeof(int)); |
| 241 | default: |
| 242 | return -ENOTTY; |
| 243 | } |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Wim Van Sebroeck | d5c26a5 | 2009-03-18 08:18:43 +0000 | [diff] [blame] | 248 | static const struct file_operations rc32434_wdt_fops = { |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 249 | .owner = THIS_MODULE, |
| 250 | .llseek = no_llseek, |
| 251 | .write = rc32434_wdt_write, |
Wim Van Sebroeck | 7275fc8 | 2008-09-18 12:26:15 +0000 | [diff] [blame] | 252 | .unlocked_ioctl = rc32434_wdt_ioctl, |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 253 | .open = rc32434_wdt_open, |
| 254 | .release = rc32434_wdt_release, |
| 255 | }; |
| 256 | |
| 257 | static struct miscdevice rc32434_wdt_miscdev = { |
| 258 | .minor = WATCHDOG_MINOR, |
| 259 | .name = "watchdog", |
| 260 | .fops = &rc32434_wdt_fops, |
| 261 | }; |
| 262 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 263 | static int rc32434_wdt_probe(struct platform_device *pdev) |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 264 | { |
| 265 | int ret; |
| 266 | struct resource *r; |
| 267 | |
Phil Sutter | 0af98d3 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 268 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rb532_wdt_res"); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 269 | if (!r) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 270 | pr_err("failed to retrieve resources\n"); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 271 | return -ENODEV; |
| 272 | } |
| 273 | |
H Hartley Sweeten | be088b1 | 2009-11-24 21:06:26 -0500 | [diff] [blame] | 274 | wdt_reg = ioremap_nocache(r->start, resource_size(r)); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 275 | if (!wdt_reg) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 276 | pr_err("failed to remap I/O resources\n"); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 277 | return -ENXIO; |
| 278 | } |
| 279 | |
Wim Van Sebroeck | e455b6b | 2009-02-23 13:08:36 +0000 | [diff] [blame] | 280 | spin_lock_init(&rc32434_wdt_device.io_lock); |
| 281 | |
Wim Van Sebroeck | f296b14 | 2009-02-23 13:08:37 +0000 | [diff] [blame] | 282 | /* Make sure the watchdog is not running */ |
| 283 | rc32434_wdt_stop(); |
| 284 | |
Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 285 | /* Check that the heartbeat value is within it's range; |
| 286 | * if not reset to the default */ |
| 287 | if (rc32434_wdt_set(timeout)) { |
| 288 | rc32434_wdt_set(WATCHDOG_TIMEOUT); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 289 | pr_info("timeout value must be between 0 and %d\n", |
Phil Sutter | 08eb2e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 290 | WTCOMP2SEC((u32)-1)); |
| 291 | } |
| 292 | |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 293 | ret = misc_register(&rc32434_wdt_miscdev); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 294 | if (ret < 0) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 295 | pr_err("failed to register watchdog device\n"); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 296 | goto unmap; |
| 297 | } |
| 298 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 299 | pr_info("Watchdog Timer version " VERSION ", timer margin: %d sec\n", |
| 300 | timeout); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 301 | |
| 302 | return 0; |
| 303 | |
| 304 | unmap: |
| 305 | iounmap(wdt_reg); |
| 306 | return ret; |
| 307 | } |
| 308 | |
Bill Pemberton | 4b12b89 | 2012-11-19 13:26:24 -0500 | [diff] [blame] | 309 | static int rc32434_wdt_remove(struct platform_device *pdev) |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 310 | { |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 311 | misc_deregister(&rc32434_wdt_miscdev); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 312 | iounmap(wdt_reg); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
Wim Van Sebroeck | 0aaae66 | 2009-02-23 13:08:35 +0000 | [diff] [blame] | 316 | static void rc32434_wdt_shutdown(struct platform_device *pdev) |
| 317 | { |
| 318 | rc32434_wdt_stop(); |
| 319 | } |
| 320 | |
Phil Sutter | 9b655e0 | 2009-02-08 16:44:42 +0100 | [diff] [blame] | 321 | static struct platform_driver rc32434_wdt_driver = { |
Wim Van Sebroeck | 0aaae66 | 2009-02-23 13:08:35 +0000 | [diff] [blame] | 322 | .probe = rc32434_wdt_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 323 | .remove = rc32434_wdt_remove, |
Wim Van Sebroeck | 0aaae66 | 2009-02-23 13:08:35 +0000 | [diff] [blame] | 324 | .shutdown = rc32434_wdt_shutdown, |
| 325 | .driver = { |
| 326 | .name = "rc32434_wdt", |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 327 | } |
| 328 | }; |
| 329 | |
Axel Lin | b8ec611 | 2011-11-29 13:56:27 +0800 | [diff] [blame] | 330 | module_platform_driver(rc32434_wdt_driver); |
Florian Fainelli | 03ec585 | 2008-02-25 13:11:31 +0100 | [diff] [blame] | 331 | |
| 332 | MODULE_AUTHOR("Ondrej Zajicek <santiago@crfreenet.org>," |
| 333 | "Florian Fainelli <florian@openwrt.org>"); |
| 334 | MODULE_DESCRIPTION("Driver for the IDT RC32434 SoC watchdog"); |
| 335 | MODULE_LICENSE("GPL"); |
| 336 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |