Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Watchdog implementation for GPI h/w found on PMC-Sierra RM9xxx |
| 3 | * chips. |
| 4 | * |
| 5 | * Copyright (C) 2004 by Basler Vision Technologies AG |
| 6 | * Author: Thomas Koeller <thomas.koeller@baslerweb.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/moduleparam.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/fs.h> |
| 28 | #include <linux/reboot.h> |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 29 | #include <linux/notifier.h> |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 30 | #include <linux/miscdevice.h> |
| 31 | #include <linux/watchdog.h> |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 32 | #include <linux/io.h> |
| 33 | #include <linux/uaccess.h> |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 34 | #include <asm/atomic.h> |
| 35 | #include <asm/processor.h> |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 36 | #include <asm/system.h> |
| 37 | #include <asm/rm9k-ocd.h> |
| 38 | |
| 39 | #include <rm9k_wdt.h> |
| 40 | |
| 41 | |
| 42 | #define CLOCK 125000000 |
| 43 | #define MAX_TIMEOUT_SECONDS 32 |
| 44 | #define CPCCR 0x0080 |
| 45 | #define CPGIG1SR 0x0044 |
| 46 | #define CPGIG1ER 0x0054 |
| 47 | |
| 48 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 49 | /* Function prototypes */ |
Thomas Koeller | 74e86ab | 2006-12-06 01:45:39 +0100 | [diff] [blame] | 50 | static irqreturn_t wdt_gpi_irqhdl(int, void *); |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 51 | static void wdt_gpi_start(void); |
| 52 | static void wdt_gpi_stop(void); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 53 | static void wdt_gpi_set_timeout(unsigned int); |
| 54 | static int wdt_gpi_open(struct inode *, struct file *); |
| 55 | static int wdt_gpi_release(struct inode *, struct file *); |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 56 | static ssize_t wdt_gpi_write(struct file *, const char __user *, size_t, |
| 57 | loff_t *); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 58 | static long wdt_gpi_ioctl(struct file *, unsigned int, unsigned long); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 59 | static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *); |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 60 | static const struct resource *wdt_gpi_get_resource(struct platform_device *, |
| 61 | const char *, unsigned int); |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 62 | static int __init wdt_gpi_probe(struct platform_device *); |
| 63 | static int __exit wdt_gpi_remove(struct platform_device *); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 64 | |
| 65 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 66 | static const char wdt_gpi_name[] = "wdt_gpi"; |
| 67 | static atomic_t opencnt; |
| 68 | static int expect_close; |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 69 | static int locked; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 70 | |
| 71 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 72 | /* These are set from device resources */ |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 73 | static void __iomem *wd_regs; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 74 | static unsigned int wd_irq, wd_ctr; |
| 75 | |
| 76 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 77 | /* Module arguments */ |
| 78 | static int timeout = MAX_TIMEOUT_SECONDS; |
| 79 | module_param(timeout, int, 0444); |
Wim Van Sebroeck | cd57eea | 2006-11-17 21:51:35 +0100 | [diff] [blame] | 80 | MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds"); |
| 81 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 82 | static unsigned long resetaddr = 0xbffdc200; |
| 83 | module_param(resetaddr, ulong, 0444); |
Wim Van Sebroeck | cd57eea | 2006-11-17 21:51:35 +0100 | [diff] [blame] | 84 | MODULE_PARM_DESC(resetaddr, "Address to write to to force a reset"); |
| 85 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 86 | static unsigned long flagaddr = 0xbffdc104; |
| 87 | module_param(flagaddr, ulong, 0444); |
Wim Van Sebroeck | cd57eea | 2006-11-17 21:51:35 +0100 | [diff] [blame] | 88 | MODULE_PARM_DESC(flagaddr, "Address to write to boot flags to"); |
| 89 | |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 90 | static int powercycle; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 91 | module_param(powercycle, bool, 0444); |
Wim Van Sebroeck | cd57eea | 2006-11-17 21:51:35 +0100 | [diff] [blame] | 92 | MODULE_PARM_DESC(powercycle, "Cycle power if watchdog expires"); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 93 | |
| 94 | static int nowayout = WATCHDOG_NOWAYOUT; |
| 95 | module_param(nowayout, bool, 0444); |
Wim Van Sebroeck | cd57eea | 2006-11-17 21:51:35 +0100 | [diff] [blame] | 96 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started"); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 97 | |
| 98 | |
Thomas Koeller | bec4f74 | 2006-12-06 01:45:26 +0100 | [diff] [blame] | 99 | /* Kernel interfaces */ |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 100 | static const struct file_operations fops = { |
Thomas Koeller | bec4f74 | 2006-12-06 01:45:26 +0100 | [diff] [blame] | 101 | .owner = THIS_MODULE, |
| 102 | .open = wdt_gpi_open, |
| 103 | .release = wdt_gpi_release, |
| 104 | .write = wdt_gpi_write, |
| 105 | .unlocked_ioctl = wdt_gpi_ioctl, |
| 106 | }; |
| 107 | |
| 108 | static struct miscdevice miscdev = { |
| 109 | .minor = WATCHDOG_MINOR, |
| 110 | .name = wdt_gpi_name, |
| 111 | .fops = &fops, |
| 112 | }; |
| 113 | |
| 114 | static struct notifier_block wdt_gpi_shutdown = { |
| 115 | .notifier_call = wdt_gpi_notify, |
| 116 | }; |
| 117 | |
| 118 | |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 119 | /* Interrupt handler */ |
Thomas Koeller | 74e86ab | 2006-12-06 01:45:39 +0100 | [diff] [blame] | 120 | static irqreturn_t wdt_gpi_irqhdl(int irq, void *ctxt) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 121 | { |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 122 | if (!unlikely(__raw_readl(wd_regs + 0x0008) & 0x1)) |
| 123 | return IRQ_NONE; |
| 124 | __raw_writel(0x1, wd_regs + 0x0008); |
| 125 | |
| 126 | |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 127 | printk(KERN_CRIT "%s: watchdog expired - resetting system\n", |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 128 | wdt_gpi_name); |
| 129 | |
| 130 | *(volatile char *) flagaddr |= 0x01; |
| 131 | *(volatile char *) resetaddr = powercycle ? 0x01 : 0x2; |
| 132 | iob(); |
| 133 | while (1) |
| 134 | cpu_relax(); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 138 | /* Watchdog functions */ |
Wim Van Sebroeck | 414a6759 | 2006-11-17 23:36:08 +0100 | [diff] [blame] | 139 | static void wdt_gpi_start(void) |
| 140 | { |
| 141 | u32 reg; |
| 142 | |
| 143 | lock_titan_regs(); |
| 144 | reg = titan_readl(CPGIG1ER); |
| 145 | titan_writel(reg | (0x100 << wd_ctr), CPGIG1ER); |
| 146 | iob(); |
| 147 | unlock_titan_regs(); |
| 148 | } |
| 149 | |
| 150 | static void wdt_gpi_stop(void) |
| 151 | { |
| 152 | u32 reg; |
| 153 | |
| 154 | lock_titan_regs(); |
| 155 | reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); |
| 156 | titan_writel(reg, CPCCR); |
| 157 | reg = titan_readl(CPGIG1ER); |
| 158 | titan_writel(reg & ~(0x100 << wd_ctr), CPGIG1ER); |
| 159 | iob(); |
| 160 | unlock_titan_regs(); |
| 161 | } |
| 162 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 163 | static void wdt_gpi_set_timeout(unsigned int to) |
| 164 | { |
| 165 | u32 reg; |
| 166 | const u32 wdval = (to * CLOCK) & ~0x0000000f; |
| 167 | |
| 168 | lock_titan_regs(); |
| 169 | reg = titan_readl(CPCCR) & ~(0xf << (wd_ctr * 4)); |
| 170 | titan_writel(reg, CPCCR); |
| 171 | wmb(); |
| 172 | __raw_writel(wdval, wd_regs + 0x0000); |
| 173 | wmb(); |
| 174 | titan_writel(reg | (0x2 << (wd_ctr * 4)), CPCCR); |
| 175 | wmb(); |
| 176 | titan_writel(reg | (0x5 << (wd_ctr * 4)), CPCCR); |
| 177 | iob(); |
| 178 | unlock_titan_regs(); |
| 179 | } |
| 180 | |
| 181 | |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 182 | /* /dev/watchdog operations */ |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 183 | static int wdt_gpi_open(struct inode *inode, struct file *file) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 184 | { |
| 185 | int res; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 186 | |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 187 | if (unlikely(atomic_dec_if_positive(&opencnt) < 0)) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 188 | return -EBUSY; |
| 189 | |
| 190 | expect_close = 0; |
| 191 | if (locked) { |
| 192 | module_put(THIS_MODULE); |
| 193 | free_irq(wd_irq, &miscdev); |
| 194 | locked = 0; |
| 195 | } |
| 196 | |
Thomas Gleixner | 38515e9 | 2007-02-14 00:33:16 -0800 | [diff] [blame] | 197 | res = request_irq(wd_irq, wdt_gpi_irqhdl, IRQF_SHARED | IRQF_DISABLED, |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 198 | wdt_gpi_name, &miscdev); |
| 199 | if (unlikely(res)) |
| 200 | return res; |
| 201 | |
| 202 | wdt_gpi_set_timeout(timeout); |
Wim Van Sebroeck | 414a6759 | 2006-11-17 23:36:08 +0100 | [diff] [blame] | 203 | wdt_gpi_start(); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 204 | |
| 205 | printk(KERN_INFO "%s: watchdog started, timeout = %u seconds\n", |
| 206 | wdt_gpi_name, timeout); |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 207 | return nonseekable_open(inode, file); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 210 | static int wdt_gpi_release(struct inode *inode, struct file *file) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 211 | { |
| 212 | if (nowayout) { |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 213 | printk(KERN_INFO "%s: no way out - watchdog left running\n", |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 214 | wdt_gpi_name); |
| 215 | __module_get(THIS_MODULE); |
| 216 | locked = 1; |
| 217 | } else { |
| 218 | if (expect_close) { |
Wim Van Sebroeck | 414a6759 | 2006-11-17 23:36:08 +0100 | [diff] [blame] | 219 | wdt_gpi_stop(); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 220 | free_irq(wd_irq, &miscdev); |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 221 | printk(KERN_INFO "%s: watchdog stopped\n", |
| 222 | wdt_gpi_name); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 223 | } else { |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 224 | printk(KERN_CRIT "%s: unexpected close() -" |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 225 | " watchdog left running\n", |
| 226 | wdt_gpi_name); |
| 227 | wdt_gpi_set_timeout(timeout); |
| 228 | __module_get(THIS_MODULE); |
| 229 | locked = 1; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | atomic_inc(&opencnt); |
| 234 | return 0; |
| 235 | } |
| 236 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 237 | static ssize_t wdt_gpi_write(struct file *f, const char __user *d, size_t s, |
| 238 | loff_t *o) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 239 | { |
| 240 | char val; |
| 241 | |
| 242 | wdt_gpi_set_timeout(timeout); |
| 243 | expect_close = (s > 0) && !get_user(val, d) && (val == 'V'); |
| 244 | return s ? 1 : 0; |
| 245 | } |
| 246 | |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 247 | static long wdt_gpi_ioctl(struct file *f, unsigned int cmd, unsigned long arg) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 248 | { |
| 249 | long res = -ENOTTY; |
| 250 | const long size = _IOC_SIZE(cmd); |
| 251 | int stat; |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 252 | void __user *argp = (void __user *)arg; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 253 | static struct watchdog_info wdinfo = { |
| 254 | .identity = "RM9xxx/GPI watchdog", |
| 255 | .firmware_version = 0, |
| 256 | .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
| 257 | }; |
| 258 | |
| 259 | if (unlikely(_IOC_TYPE(cmd) != WATCHDOG_IOCTL_BASE)) |
| 260 | return -ENOTTY; |
| 261 | |
| 262 | if ((_IOC_DIR(cmd) & _IOC_READ) |
| 263 | && !access_ok(VERIFY_WRITE, arg, size)) |
| 264 | return -EFAULT; |
| 265 | |
| 266 | if ((_IOC_DIR(cmd) & _IOC_WRITE) |
| 267 | && !access_ok(VERIFY_READ, arg, size)) |
| 268 | return -EFAULT; |
| 269 | |
| 270 | expect_close = 0; |
| 271 | |
| 272 | switch (cmd) { |
| 273 | case WDIOC_GETSUPPORT: |
| 274 | wdinfo.options = nowayout ? |
| 275 | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING : |
Alan Cox | 72d5c05 | 2008-05-19 14:07:54 +0100 | [diff] [blame] | 276 | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | |
| 277 | WDIOF_MAGICCLOSE; |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 278 | res = __copy_to_user(argp, &wdinfo, size) ? -EFAULT : size; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 279 | break; |
| 280 | |
| 281 | case WDIOC_GETSTATUS: |
| 282 | break; |
| 283 | |
| 284 | case WDIOC_GETBOOTSTATUS: |
| 285 | stat = (*(volatile char *) flagaddr & 0x01) |
| 286 | ? WDIOF_CARDRESET : 0; |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 287 | res = __copy_to_user(argp, &stat, size) ? |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 288 | -EFAULT : size; |
| 289 | break; |
| 290 | |
| 291 | case WDIOC_SETOPTIONS: |
| 292 | break; |
| 293 | |
| 294 | case WDIOC_KEEPALIVE: |
| 295 | wdt_gpi_set_timeout(timeout); |
| 296 | res = size; |
| 297 | break; |
| 298 | |
| 299 | case WDIOC_SETTIMEOUT: |
| 300 | { |
| 301 | int val; |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 302 | if (unlikely(__copy_from_user(&val, argp, size))) { |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 303 | res = -EFAULT; |
| 304 | break; |
| 305 | } |
| 306 | |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 307 | if (val > MAX_TIMEOUT_SECONDS) |
| 308 | val = MAX_TIMEOUT_SECONDS; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 309 | timeout = val; |
| 310 | wdt_gpi_set_timeout(val); |
| 311 | res = size; |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 312 | printk(KERN_INFO "%s: timeout set to %u seconds\n", |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 313 | wdt_gpi_name, timeout); |
| 314 | } |
| 315 | break; |
| 316 | |
| 317 | case WDIOC_GETTIMEOUT: |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 318 | res = __copy_to_user(argp, &timeout, size) ? |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 319 | -EFAULT : size; |
| 320 | break; |
| 321 | } |
| 322 | |
| 323 | return res; |
| 324 | } |
| 325 | |
| 326 | |
Wim Van Sebroeck | d5d06ff | 2006-11-17 23:50:06 +0100 | [diff] [blame] | 327 | /* Shutdown notifier */ |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 328 | static int wdt_gpi_notify(struct notifier_block *this, unsigned long code, |
| 329 | void *unused) |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 330 | { |
Wim Van Sebroeck | 414a6759 | 2006-11-17 23:36:08 +0100 | [diff] [blame] | 331 | if (code == SYS_DOWN || code == SYS_HALT) |
| 332 | wdt_gpi_stop(); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 333 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 334 | return NOTIFY_DONE; |
| 335 | } |
| 336 | |
| 337 | |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 338 | /* Init & exit procedures */ |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 339 | static const struct resource *wdt_gpi_get_resource(struct platform_device *pdv, |
| 340 | const char *name, unsigned int type) |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 341 | { |
| 342 | char buf[80]; |
| 343 | if (snprintf(buf, sizeof buf, "%s_0", name) >= sizeof buf) |
| 344 | return NULL; |
| 345 | return platform_get_resource_byname(pdv, type, buf); |
| 346 | } |
| 347 | |
Wim Van Sebroeck | b6bf291 | 2009-04-14 20:30:55 +0000 | [diff] [blame] | 348 | /* No hotplugging on the platform bus - use __devinit */ |
| 349 | static int __devinit wdt_gpi_probe(struct platform_device *pdv) |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 350 | { |
| 351 | int res; |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 352 | const struct resource |
| 353 | * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS, |
| 354 | IORESOURCE_MEM), |
| 355 | * const ri = wdt_gpi_get_resource(pdv, WDT_RESOURCE_IRQ, |
| 356 | IORESOURCE_IRQ), |
| 357 | * const rc = wdt_gpi_get_resource(pdv, WDT_RESOURCE_COUNTER, |
| 358 | 0); |
| 359 | |
| 360 | if (unlikely(!rr || !ri || !rc)) |
| 361 | return -ENXIO; |
| 362 | |
| 363 | wd_regs = ioremap_nocache(rr->start, rr->end + 1 - rr->start); |
| 364 | if (unlikely(!wd_regs)) |
| 365 | return -ENOMEM; |
| 366 | wd_irq = ri->start; |
| 367 | wd_ctr = rc->start; |
| 368 | res = misc_register(&miscdev); |
| 369 | if (res) |
| 370 | iounmap(wd_regs); |
| 371 | else |
| 372 | register_reboot_notifier(&wdt_gpi_shutdown); |
| 373 | return res; |
| 374 | } |
| 375 | |
Wim Van Sebroeck | b6bf291 | 2009-04-14 20:30:55 +0000 | [diff] [blame] | 376 | static int __devexit wdt_gpi_remove(struct platform_device *dev) |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 377 | { |
| 378 | int res; |
| 379 | |
| 380 | unregister_reboot_notifier(&wdt_gpi_shutdown); |
| 381 | res = misc_deregister(&miscdev); |
| 382 | iounmap(wd_regs); |
| 383 | wd_regs = NULL; |
| 384 | return res; |
| 385 | } |
| 386 | |
| 387 | |
| 388 | /* Device driver init & exit */ |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 389 | static struct platform_driver wgt_gpi_driver = { |
| 390 | .driver = { |
| 391 | .name = wdt_gpi_name, |
| 392 | .owner = THIS_MODULE, |
| 393 | }, |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 394 | .probe = wdt_gpi_probe, |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 395 | .remove = __devexit_p(wdt_gpi_remove), |
Wim Van Sebroeck | 97846e3 | 2006-11-17 23:15:48 +0100 | [diff] [blame] | 396 | }; |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 397 | |
| 398 | static int __init wdt_gpi_init_module(void) |
| 399 | { |
| 400 | atomic_set(&opencnt, 1); |
| 401 | if (timeout > MAX_TIMEOUT_SECONDS) |
| 402 | timeout = MAX_TIMEOUT_SECONDS; |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 403 | return platform_driver_register(&wdt_gpi_driver); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 406 | static void __exit wdt_gpi_cleanup_module(void) |
| 407 | { |
Ming Lei | 7a192ec | 2009-02-06 23:40:12 +0800 | [diff] [blame] | 408 | platform_driver_unregister(&wdt_gpi_driver); |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | module_init(wdt_gpi_init_module); |
| 412 | module_exit(wdt_gpi_cleanup_module); |
| 413 | |
Thomas Koeller | 825d374 | 2006-08-14 21:55:29 +0200 | [diff] [blame] | 414 | MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>"); |
| 415 | MODULE_DESCRIPTION("Basler eXcite watchdog driver for gpi devices"); |
| 416 | MODULE_VERSION("0.1"); |
| 417 | MODULE_LICENSE("GPL"); |
| 418 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); |
Wim Van Sebroeck | cd57eea | 2006-11-17 21:51:35 +0100 | [diff] [blame] | 419 | |