1b7e04f8cSWim Van Sebroeck /* 2b7e04f8cSWim Van Sebroeck * SBC8360 Watchdog driver 3b7e04f8cSWim Van Sebroeck * 4b7e04f8cSWim Van Sebroeck * (c) Copyright 2005 Webcon, Inc. 5b7e04f8cSWim Van Sebroeck * 6b7e04f8cSWim Van Sebroeck * Based on ib700wdt.c, which is based on advantechwdt.c which is based 7b7e04f8cSWim Van Sebroeck * on acquirewdt.c which is based on wdt.c. 8b7e04f8cSWim Van Sebroeck * 9b7e04f8cSWim Van Sebroeck * (c) Copyright 2001 Charles Howes <chowes@vsol.net> 10b7e04f8cSWim Van Sebroeck * 11b7e04f8cSWim Van Sebroeck * Based on advantechwdt.c which is based on acquirewdt.c which 12b7e04f8cSWim Van Sebroeck * is based on wdt.c. 13b7e04f8cSWim Van Sebroeck * 14b7e04f8cSWim Van Sebroeck * (c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl> 15b7e04f8cSWim Van Sebroeck * 16b7e04f8cSWim Van Sebroeck * Based on acquirewdt.c which is based on wdt.c. 17b7e04f8cSWim Van Sebroeck * Original copyright messages: 18b7e04f8cSWim Van Sebroeck * 1929fa0586SAlan Cox * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>, 2029fa0586SAlan Cox * All Rights Reserved. 21b7e04f8cSWim Van Sebroeck * 22b7e04f8cSWim Van Sebroeck * This program is free software; you can redistribute it and/or 23b7e04f8cSWim Van Sebroeck * modify it under the terms of the GNU General Public License 24b7e04f8cSWim Van Sebroeck * as published by the Free Software Foundation; either version 25b7e04f8cSWim Van Sebroeck * 2 of the License, or (at your option) any later version. 26b7e04f8cSWim Van Sebroeck * 27b7e04f8cSWim Van Sebroeck * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide 28b7e04f8cSWim Van Sebroeck * warranty for any of this software. This material is provided 29b7e04f8cSWim Van Sebroeck * "AS-IS" and at no charge. 30b7e04f8cSWim Van Sebroeck * 3129fa0586SAlan Cox * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk> 32b7e04f8cSWim Van Sebroeck * 33b7e04f8cSWim Van Sebroeck * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com> 34b7e04f8cSWim Van Sebroeck * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT 35b7e04f8cSWim Van Sebroeck * Added timeout module option to override default 36b7e04f8cSWim Van Sebroeck * 37b7e04f8cSWim Van Sebroeck */ 38b7e04f8cSWim Van Sebroeck 3927c766aaSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 4027c766aaSJoe Perches 41b7e04f8cSWim Van Sebroeck #include <linux/module.h> 42b7e04f8cSWim Van Sebroeck #include <linux/types.h> 43b7e04f8cSWim Van Sebroeck #include <linux/miscdevice.h> 44b7e04f8cSWim Van Sebroeck #include <linux/watchdog.h> 45b7e04f8cSWim Van Sebroeck #include <linux/ioport.h> 46b7e04f8cSWim Van Sebroeck #include <linux/delay.h> 47b7e04f8cSWim Van Sebroeck #include <linux/notifier.h> 48b7e04f8cSWim Van Sebroeck #include <linux/fs.h> 49b7e04f8cSWim Van Sebroeck #include <linux/reboot.h> 50b7e04f8cSWim Van Sebroeck #include <linux/init.h> 51b7e04f8cSWim Van Sebroeck #include <linux/spinlock.h> 52b7e04f8cSWim Van Sebroeck #include <linux/moduleparam.h> 539f53c8deSAlan Cox #include <linux/io.h> 549f53c8deSAlan Cox #include <linux/uaccess.h> 55b7e04f8cSWim Van Sebroeck 56b7e04f8cSWim Van Sebroeck 57b7e04f8cSWim Van Sebroeck static unsigned long sbc8360_is_open; 58b7e04f8cSWim Van Sebroeck static char expect_close; 59b7e04f8cSWim Van Sebroeck 60b7e04f8cSWim Van Sebroeck /* 61b7e04f8cSWim Van Sebroeck * 62b7e04f8cSWim Van Sebroeck * Watchdog Timer Configuration 63b7e04f8cSWim Van Sebroeck * 64b7e04f8cSWim Van Sebroeck * The function of the watchdog timer is to reset the system automatically 65b7e04f8cSWim Van Sebroeck * and is defined at I/O port 0120H and 0121H. To enable the watchdog timer 66b7e04f8cSWim Van Sebroeck * and allow the system to reset, write appropriate values from the table 67b7e04f8cSWim Van Sebroeck * below to I/O port 0120H and 0121H. To disable the timer, write a zero 68b7e04f8cSWim Van Sebroeck * value to I/O port 0121H for the system to stop the watchdog function. 69b7e04f8cSWim Van Sebroeck * 70b7e04f8cSWim Van Sebroeck * The following describes how the timer should be programmed (according to 71b7e04f8cSWim Van Sebroeck * the vendor documentation) 72b7e04f8cSWim Van Sebroeck * 73b7e04f8cSWim Van Sebroeck * Enabling Watchdog: 74b7e04f8cSWim Van Sebroeck * MOV AX,000AH (enable, phase I) 75b7e04f8cSWim Van Sebroeck * MOV DX,0120H 76b7e04f8cSWim Van Sebroeck * OUT DX,AX 77b7e04f8cSWim Van Sebroeck * MOV AX,000BH (enable, phase II) 78b7e04f8cSWim Van Sebroeck * MOV DX,0120H 79b7e04f8cSWim Van Sebroeck * OUT DX,AX 80b7e04f8cSWim Van Sebroeck * MOV AX,000nH (set multiplier n, from 1-4) 81b7e04f8cSWim Van Sebroeck * MOV DX,0120H 82b7e04f8cSWim Van Sebroeck * OUT DX,AX 83b7e04f8cSWim Van Sebroeck * MOV AX,000mH (set base timer m, from 0-F) 84b7e04f8cSWim Van Sebroeck * MOV DX,0121H 85b7e04f8cSWim Van Sebroeck * OUT DX,AX 86b7e04f8cSWim Van Sebroeck * 87b7e04f8cSWim Van Sebroeck * Reset timer: 88b7e04f8cSWim Van Sebroeck * MOV AX,000mH (same as set base timer, above) 89b7e04f8cSWim Van Sebroeck * MOV DX,0121H 90b7e04f8cSWim Van Sebroeck * OUT DX,AX 91b7e04f8cSWim Van Sebroeck * 92b7e04f8cSWim Van Sebroeck * Disabling Watchdog: 93b7e04f8cSWim Van Sebroeck * MOV AX,0000H (a zero value) 94b7e04f8cSWim Van Sebroeck * MOV DX,0120H 95b7e04f8cSWim Van Sebroeck * OUT DX,AX 96b7e04f8cSWim Van Sebroeck * 97b7e04f8cSWim Van Sebroeck * Watchdog timeout configuration values: 98b7e04f8cSWim Van Sebroeck * N 99b7e04f8cSWim Van Sebroeck * M | 1 2 3 4 100b7e04f8cSWim Van Sebroeck * --|---------------------------------- 101b7e04f8cSWim Van Sebroeck * 0 | 0.5s 5s 50s 100s 102b7e04f8cSWim Van Sebroeck * 1 | 1s 10s 100s 200s 103b7e04f8cSWim Van Sebroeck * 2 | 1.5s 15s 150s 300s 104b7e04f8cSWim Van Sebroeck * 3 | 2s 20s 200s 400s 105b7e04f8cSWim Van Sebroeck * 4 | 2.5s 25s 250s 500s 106b7e04f8cSWim Van Sebroeck * 5 | 3s 30s 300s 600s 107b7e04f8cSWim Van Sebroeck * 6 | 3.5s 35s 350s 700s 108b7e04f8cSWim Van Sebroeck * 7 | 4s 40s 400s 800s 109b7e04f8cSWim Van Sebroeck * 8 | 4.5s 45s 450s 900s 110b7e04f8cSWim Van Sebroeck * 9 | 5s 50s 500s 1000s 111b7e04f8cSWim Van Sebroeck * A | 5.5s 55s 550s 1100s 112b7e04f8cSWim Van Sebroeck * B | 6s 60s 600s 1200s 113b7e04f8cSWim Van Sebroeck * C | 6.5s 65s 650s 1300s 114b7e04f8cSWim Van Sebroeck * D | 7s 70s 700s 1400s 115b7e04f8cSWim Van Sebroeck * E | 7.5s 75s 750s 1500s 116b7e04f8cSWim Van Sebroeck * F | 8s 80s 800s 1600s 117b7e04f8cSWim Van Sebroeck * 118b7e04f8cSWim Van Sebroeck * Another way to say the same things is: 119b7e04f8cSWim Van Sebroeck * For N=1, Timeout = (M+1) * 0.5s 120b7e04f8cSWim Van Sebroeck * For N=2, Timeout = (M+1) * 5s 121b7e04f8cSWim Van Sebroeck * For N=3, Timeout = (M+1) * 50s 122b7e04f8cSWim Van Sebroeck * For N=4, Timeout = (M+1) * 100s 123b7e04f8cSWim Van Sebroeck * 124b7e04f8cSWim Van Sebroeck */ 125b7e04f8cSWim Van Sebroeck 126b7e04f8cSWim Van Sebroeck static int wd_times[64][2] = { 127b7e04f8cSWim Van Sebroeck {0, 1}, /* 0 = 0.5s */ 128b7e04f8cSWim Van Sebroeck {1, 1}, /* 1 = 1s */ 129b7e04f8cSWim Van Sebroeck {2, 1}, /* 2 = 1.5s */ 130b7e04f8cSWim Van Sebroeck {3, 1}, /* 3 = 2s */ 131b7e04f8cSWim Van Sebroeck {4, 1}, /* 4 = 2.5s */ 132b7e04f8cSWim Van Sebroeck {5, 1}, /* 5 = 3s */ 133b7e04f8cSWim Van Sebroeck {6, 1}, /* 6 = 3.5s */ 134b7e04f8cSWim Van Sebroeck {7, 1}, /* 7 = 4s */ 135b7e04f8cSWim Van Sebroeck {8, 1}, /* 8 = 4.5s */ 136b7e04f8cSWim Van Sebroeck {9, 1}, /* 9 = 5s */ 137b7e04f8cSWim Van Sebroeck {0xA, 1}, /* 10 = 5.5s */ 138b7e04f8cSWim Van Sebroeck {0xB, 1}, /* 11 = 6s */ 139b7e04f8cSWim Van Sebroeck {0xC, 1}, /* 12 = 6.5s */ 140b7e04f8cSWim Van Sebroeck {0xD, 1}, /* 13 = 7s */ 141b7e04f8cSWim Van Sebroeck {0xE, 1}, /* 14 = 7.5s */ 142b7e04f8cSWim Van Sebroeck {0xF, 1}, /* 15 = 8s */ 143b7e04f8cSWim Van Sebroeck {0, 2}, /* 16 = 5s */ 144b7e04f8cSWim Van Sebroeck {1, 2}, /* 17 = 10s */ 145b7e04f8cSWim Van Sebroeck {2, 2}, /* 18 = 15s */ 146b7e04f8cSWim Van Sebroeck {3, 2}, /* 19 = 20s */ 147b7e04f8cSWim Van Sebroeck {4, 2}, /* 20 = 25s */ 148b7e04f8cSWim Van Sebroeck {5, 2}, /* 21 = 30s */ 149b7e04f8cSWim Van Sebroeck {6, 2}, /* 22 = 35s */ 150b7e04f8cSWim Van Sebroeck {7, 2}, /* 23 = 40s */ 151b7e04f8cSWim Van Sebroeck {8, 2}, /* 24 = 45s */ 152b7e04f8cSWim Van Sebroeck {9, 2}, /* 25 = 50s */ 153b7e04f8cSWim Van Sebroeck {0xA, 2}, /* 26 = 55s */ 154b7e04f8cSWim Van Sebroeck {0xB, 2}, /* 27 = 60s */ 155b7e04f8cSWim Van Sebroeck {0xC, 2}, /* 28 = 65s */ 156b7e04f8cSWim Van Sebroeck {0xD, 2}, /* 29 = 70s */ 157b7e04f8cSWim Van Sebroeck {0xE, 2}, /* 30 = 75s */ 158b7e04f8cSWim Van Sebroeck {0xF, 2}, /* 31 = 80s */ 159b7e04f8cSWim Van Sebroeck {0, 3}, /* 32 = 50s */ 160b7e04f8cSWim Van Sebroeck {1, 3}, /* 33 = 100s */ 161b7e04f8cSWim Van Sebroeck {2, 3}, /* 34 = 150s */ 162b7e04f8cSWim Van Sebroeck {3, 3}, /* 35 = 200s */ 163b7e04f8cSWim Van Sebroeck {4, 3}, /* 36 = 250s */ 164b7e04f8cSWim Van Sebroeck {5, 3}, /* 37 = 300s */ 165b7e04f8cSWim Van Sebroeck {6, 3}, /* 38 = 350s */ 166b7e04f8cSWim Van Sebroeck {7, 3}, /* 39 = 400s */ 167b7e04f8cSWim Van Sebroeck {8, 3}, /* 40 = 450s */ 168b7e04f8cSWim Van Sebroeck {9, 3}, /* 41 = 500s */ 169b7e04f8cSWim Van Sebroeck {0xA, 3}, /* 42 = 550s */ 170b7e04f8cSWim Van Sebroeck {0xB, 3}, /* 43 = 600s */ 171b7e04f8cSWim Van Sebroeck {0xC, 3}, /* 44 = 650s */ 172b7e04f8cSWim Van Sebroeck {0xD, 3}, /* 45 = 700s */ 173b7e04f8cSWim Van Sebroeck {0xE, 3}, /* 46 = 750s */ 174b7e04f8cSWim Van Sebroeck {0xF, 3}, /* 47 = 800s */ 175b7e04f8cSWim Van Sebroeck {0, 4}, /* 48 = 100s */ 176b7e04f8cSWim Van Sebroeck {1, 4}, /* 49 = 200s */ 177b7e04f8cSWim Van Sebroeck {2, 4}, /* 50 = 300s */ 178b7e04f8cSWim Van Sebroeck {3, 4}, /* 51 = 400s */ 179b7e04f8cSWim Van Sebroeck {4, 4}, /* 52 = 500s */ 180b7e04f8cSWim Van Sebroeck {5, 4}, /* 53 = 600s */ 181b7e04f8cSWim Van Sebroeck {6, 4}, /* 54 = 700s */ 182b7e04f8cSWim Van Sebroeck {7, 4}, /* 55 = 800s */ 183b7e04f8cSWim Van Sebroeck {8, 4}, /* 56 = 900s */ 184b7e04f8cSWim Van Sebroeck {9, 4}, /* 57 = 1000s */ 185b7e04f8cSWim Van Sebroeck {0xA, 4}, /* 58 = 1100s */ 186b7e04f8cSWim Van Sebroeck {0xB, 4}, /* 59 = 1200s */ 187b7e04f8cSWim Van Sebroeck {0xC, 4}, /* 60 = 1300s */ 188b7e04f8cSWim Van Sebroeck {0xD, 4}, /* 61 = 1400s */ 189b7e04f8cSWim Van Sebroeck {0xE, 4}, /* 62 = 1500s */ 190b7e04f8cSWim Van Sebroeck {0xF, 4} /* 63 = 1600s */ 191b7e04f8cSWim Van Sebroeck }; 192b7e04f8cSWim Van Sebroeck 193b7e04f8cSWim Van Sebroeck #define SBC8360_ENABLE 0x120 194b7e04f8cSWim Van Sebroeck #define SBC8360_BASETIME 0x121 195b7e04f8cSWim Van Sebroeck 196b7e04f8cSWim Van Sebroeck static int timeout = 27; 197b7e04f8cSWim Van Sebroeck static int wd_margin = 0xB; 198b7e04f8cSWim Van Sebroeck static int wd_multiplier = 2; 19986a1e189SWim Van Sebroeck static bool nowayout = WATCHDOG_NOWAYOUT; 200b7e04f8cSWim Van Sebroeck 201b7e04f8cSWim Van Sebroeck module_param(timeout, int, 0); 202b7e04f8cSWim Van Sebroeck MODULE_PARM_DESC(timeout, "Index into timeout table (0-63) (default=27 (60s))"); 20386a1e189SWim Van Sebroeck module_param(nowayout, bool, 0); 204b7e04f8cSWim Van Sebroeck MODULE_PARM_DESC(nowayout, 2059f53c8deSAlan Cox "Watchdog cannot be stopped once started (default=" 2069f53c8deSAlan Cox __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 207b7e04f8cSWim Van Sebroeck 208b7e04f8cSWim Van Sebroeck /* 209b7e04f8cSWim Van Sebroeck * Kernel methods. 210b7e04f8cSWim Van Sebroeck */ 211b7e04f8cSWim Van Sebroeck 212b7e04f8cSWim Van Sebroeck /* Activate and pre-configure watchdog */ 213b7e04f8cSWim Van Sebroeck static void sbc8360_activate(void) 214b7e04f8cSWim Van Sebroeck { 215b7e04f8cSWim Van Sebroeck /* Enable the watchdog */ 216b7e04f8cSWim Van Sebroeck outb(0x0A, SBC8360_ENABLE); 217b7e04f8cSWim Van Sebroeck msleep_interruptible(100); 218b7e04f8cSWim Van Sebroeck outb(0x0B, SBC8360_ENABLE); 219b7e04f8cSWim Van Sebroeck msleep_interruptible(100); 220b7e04f8cSWim Van Sebroeck /* Set timeout multiplier */ 221b7e04f8cSWim Van Sebroeck outb(wd_multiplier, SBC8360_ENABLE); 222b7e04f8cSWim Van Sebroeck msleep_interruptible(100); 223b7e04f8cSWim Van Sebroeck /* Nothing happens until first sbc8360_ping() */ 224b7e04f8cSWim Van Sebroeck } 225b7e04f8cSWim Van Sebroeck 226b7e04f8cSWim Van Sebroeck /* Kernel pings watchdog */ 227b7e04f8cSWim Van Sebroeck static void sbc8360_ping(void) 228b7e04f8cSWim Van Sebroeck { 229b7e04f8cSWim Van Sebroeck /* Write the base timer register */ 230b7e04f8cSWim Van Sebroeck outb(wd_margin, SBC8360_BASETIME); 231b7e04f8cSWim Van Sebroeck } 232b7e04f8cSWim Van Sebroeck 23312b7a152SWim Van Sebroeck /* stop watchdog */ 23412b7a152SWim Van Sebroeck static void sbc8360_stop(void) 23512b7a152SWim Van Sebroeck { 23612b7a152SWim Van Sebroeck /* De-activate the watchdog */ 23712b7a152SWim Van Sebroeck outb(0, SBC8360_ENABLE); 23812b7a152SWim Van Sebroeck } 23912b7a152SWim Van Sebroeck 240b7e04f8cSWim Van Sebroeck /* Userspace pings kernel driver, or requests clean close */ 241b7e04f8cSWim Van Sebroeck static ssize_t sbc8360_write(struct file *file, const char __user *buf, 242b7e04f8cSWim Van Sebroeck size_t count, loff_t *ppos) 243b7e04f8cSWim Van Sebroeck { 244b7e04f8cSWim Van Sebroeck if (count) { 245b7e04f8cSWim Van Sebroeck if (!nowayout) { 246b7e04f8cSWim Van Sebroeck size_t i; 247b7e04f8cSWim Van Sebroeck 248b7e04f8cSWim Van Sebroeck /* In case it was set long ago */ 249b7e04f8cSWim Van Sebroeck expect_close = 0; 250b7e04f8cSWim Van Sebroeck 251b7e04f8cSWim Van Sebroeck for (i = 0; i != count; i++) { 252b7e04f8cSWim Van Sebroeck char c; 253b7e04f8cSWim Van Sebroeck if (get_user(c, buf + i)) 254b7e04f8cSWim Van Sebroeck return -EFAULT; 255b7e04f8cSWim Van Sebroeck if (c == 'V') 256b7e04f8cSWim Van Sebroeck expect_close = 42; 257b7e04f8cSWim Van Sebroeck } 258b7e04f8cSWim Van Sebroeck } 259b7e04f8cSWim Van Sebroeck sbc8360_ping(); 260b7e04f8cSWim Van Sebroeck } 261b7e04f8cSWim Van Sebroeck return count; 262b7e04f8cSWim Van Sebroeck } 263b7e04f8cSWim Van Sebroeck 264b7e04f8cSWim Van Sebroeck static int sbc8360_open(struct inode *inode, struct file *file) 265b7e04f8cSWim Van Sebroeck { 2669f53c8deSAlan Cox if (test_and_set_bit(0, &sbc8360_is_open)) 267b7e04f8cSWim Van Sebroeck return -EBUSY; 268b7e04f8cSWim Van Sebroeck if (nowayout) 269b7e04f8cSWim Van Sebroeck __module_get(THIS_MODULE); 270b7e04f8cSWim Van Sebroeck 271b7e04f8cSWim Van Sebroeck /* Activate and ping once to start the countdown */ 272b7e04f8cSWim Van Sebroeck sbc8360_activate(); 273b7e04f8cSWim Van Sebroeck sbc8360_ping(); 274*c5bf68feSKirill Smelkov return stream_open(inode, file); 275b7e04f8cSWim Van Sebroeck } 276b7e04f8cSWim Van Sebroeck 277b7e04f8cSWim Van Sebroeck static int sbc8360_close(struct inode *inode, struct file *file) 278b7e04f8cSWim Van Sebroeck { 279b7e04f8cSWim Van Sebroeck if (expect_close == 42) 28012b7a152SWim Van Sebroeck sbc8360_stop(); 281b7e04f8cSWim Van Sebroeck else 28227c766aaSJoe Perches pr_crit("SBC8360 device closed unexpectedly. SBC8360 will not stop!\n"); 283b7e04f8cSWim Van Sebroeck 284b7e04f8cSWim Van Sebroeck clear_bit(0, &sbc8360_is_open); 285b7e04f8cSWim Van Sebroeck expect_close = 0; 286b7e04f8cSWim Van Sebroeck return 0; 287b7e04f8cSWim Van Sebroeck } 288b7e04f8cSWim Van Sebroeck 289b7e04f8cSWim Van Sebroeck /* 290b7e04f8cSWim Van Sebroeck * Notifier for system down 291b7e04f8cSWim Van Sebroeck */ 292b7e04f8cSWim Van Sebroeck 293b7e04f8cSWim Van Sebroeck static int sbc8360_notify_sys(struct notifier_block *this, unsigned long code, 294b7e04f8cSWim Van Sebroeck void *unused) 295b7e04f8cSWim Van Sebroeck { 29612b7a152SWim Van Sebroeck if (code == SYS_DOWN || code == SYS_HALT) 29712b7a152SWim Van Sebroeck sbc8360_stop(); /* Disable the SBC8360 Watchdog */ 29812b7a152SWim Van Sebroeck 299b7e04f8cSWim Van Sebroeck return NOTIFY_DONE; 300b7e04f8cSWim Van Sebroeck } 301b7e04f8cSWim Van Sebroeck 302b7e04f8cSWim Van Sebroeck /* 303b7e04f8cSWim Van Sebroeck * Kernel Interfaces 304b7e04f8cSWim Van Sebroeck */ 305b7e04f8cSWim Van Sebroeck 306b7e04f8cSWim Van Sebroeck static const struct file_operations sbc8360_fops = { 307b7e04f8cSWim Van Sebroeck .owner = THIS_MODULE, 308b7e04f8cSWim Van Sebroeck .llseek = no_llseek, 309b7e04f8cSWim Van Sebroeck .write = sbc8360_write, 310b7e04f8cSWim Van Sebroeck .open = sbc8360_open, 311b7e04f8cSWim Van Sebroeck .release = sbc8360_close, 312b7e04f8cSWim Van Sebroeck }; 313b7e04f8cSWim Van Sebroeck 314b7e04f8cSWim Van Sebroeck static struct miscdevice sbc8360_miscdev = { 315b7e04f8cSWim Van Sebroeck .minor = WATCHDOG_MINOR, 316b7e04f8cSWim Van Sebroeck .name = "watchdog", 317b7e04f8cSWim Van Sebroeck .fops = &sbc8360_fops, 318b7e04f8cSWim Van Sebroeck }; 319b7e04f8cSWim Van Sebroeck 320b7e04f8cSWim Van Sebroeck /* 321b7e04f8cSWim Van Sebroeck * The SBC8360 needs to learn about soft shutdowns in order to 322b7e04f8cSWim Van Sebroeck * turn the timebomb registers off. 323b7e04f8cSWim Van Sebroeck */ 324b7e04f8cSWim Van Sebroeck 325b7e04f8cSWim Van Sebroeck static struct notifier_block sbc8360_notifier = { 326b7e04f8cSWim Van Sebroeck .notifier_call = sbc8360_notify_sys, 327b7e04f8cSWim Van Sebroeck }; 328b7e04f8cSWim Van Sebroeck 329b7e04f8cSWim Van Sebroeck static int __init sbc8360_init(void) 330b7e04f8cSWim Van Sebroeck { 331b7e04f8cSWim Van Sebroeck int res; 332b7e04f8cSWim Van Sebroeck unsigned long int mseconds = 60000; 333b7e04f8cSWim Van Sebroeck 334b7e04f8cSWim Van Sebroeck if (timeout < 0 || timeout > 63) { 33527c766aaSJoe Perches pr_err("Invalid timeout index (must be 0-63)\n"); 336b7e04f8cSWim Van Sebroeck res = -EINVAL; 337b7e04f8cSWim Van Sebroeck goto out; 338b7e04f8cSWim Van Sebroeck } 339b7e04f8cSWim Van Sebroeck 340b7e04f8cSWim Van Sebroeck if (!request_region(SBC8360_ENABLE, 1, "SBC8360")) { 34127c766aaSJoe Perches pr_err("ENABLE method I/O %X is not available\n", 342b7e04f8cSWim Van Sebroeck SBC8360_ENABLE); 343b7e04f8cSWim Van Sebroeck res = -EIO; 344b7e04f8cSWim Van Sebroeck goto out; 345b7e04f8cSWim Van Sebroeck } 346b7e04f8cSWim Van Sebroeck if (!request_region(SBC8360_BASETIME, 1, "SBC8360")) { 34727c766aaSJoe Perches pr_err("BASETIME method I/O %X is not available\n", 348b7e04f8cSWim Van Sebroeck SBC8360_BASETIME); 349b7e04f8cSWim Van Sebroeck res = -EIO; 350b7e04f8cSWim Van Sebroeck goto out_nobasetimereg; 351b7e04f8cSWim Van Sebroeck } 352b7e04f8cSWim Van Sebroeck 353b7e04f8cSWim Van Sebroeck res = register_reboot_notifier(&sbc8360_notifier); 354b7e04f8cSWim Van Sebroeck if (res) { 35527c766aaSJoe Perches pr_err("Failed to register reboot notifier\n"); 356b7e04f8cSWim Van Sebroeck goto out_noreboot; 357b7e04f8cSWim Van Sebroeck } 358b7e04f8cSWim Van Sebroeck 359b7e04f8cSWim Van Sebroeck res = misc_register(&sbc8360_miscdev); 360b7e04f8cSWim Van Sebroeck if (res) { 36127c766aaSJoe Perches pr_err("failed to register misc device\n"); 362b7e04f8cSWim Van Sebroeck goto out_nomisc; 363b7e04f8cSWim Van Sebroeck } 364b7e04f8cSWim Van Sebroeck 365b7e04f8cSWim Van Sebroeck wd_margin = wd_times[timeout][0]; 366b7e04f8cSWim Van Sebroeck wd_multiplier = wd_times[timeout][1]; 367b7e04f8cSWim Van Sebroeck 368b7e04f8cSWim Van Sebroeck if (wd_multiplier == 1) 369b7e04f8cSWim Van Sebroeck mseconds = (wd_margin + 1) * 500; 370b7e04f8cSWim Van Sebroeck else if (wd_multiplier == 2) 371b7e04f8cSWim Van Sebroeck mseconds = (wd_margin + 1) * 5000; 372b7e04f8cSWim Van Sebroeck else if (wd_multiplier == 3) 373b7e04f8cSWim Van Sebroeck mseconds = (wd_margin + 1) * 50000; 374b7e04f8cSWim Van Sebroeck else if (wd_multiplier == 4) 375b7e04f8cSWim Van Sebroeck mseconds = (wd_margin + 1) * 100000; 376b7e04f8cSWim Van Sebroeck 377b7e04f8cSWim Van Sebroeck /* My kingdom for the ability to print "0.5 seconds" in the kernel! */ 37827c766aaSJoe Perches pr_info("Timeout set at %ld ms\n", mseconds); 379b7e04f8cSWim Van Sebroeck 380b7e04f8cSWim Van Sebroeck return 0; 381b7e04f8cSWim Van Sebroeck 382b7e04f8cSWim Van Sebroeck out_nomisc: 383b7e04f8cSWim Van Sebroeck unregister_reboot_notifier(&sbc8360_notifier); 384b7e04f8cSWim Van Sebroeck out_noreboot: 385b7e04f8cSWim Van Sebroeck release_region(SBC8360_BASETIME, 1); 386b7e04f8cSWim Van Sebroeck out_nobasetimereg: 387b7e04f8cSWim Van Sebroeck release_region(SBC8360_ENABLE, 1); 388b7e04f8cSWim Van Sebroeck out: 389b7e04f8cSWim Van Sebroeck return res; 390b7e04f8cSWim Van Sebroeck } 391b7e04f8cSWim Van Sebroeck 392b7e04f8cSWim Van Sebroeck static void __exit sbc8360_exit(void) 393b7e04f8cSWim Van Sebroeck { 394b7e04f8cSWim Van Sebroeck misc_deregister(&sbc8360_miscdev); 395b7e04f8cSWim Van Sebroeck unregister_reboot_notifier(&sbc8360_notifier); 396b7e04f8cSWim Van Sebroeck release_region(SBC8360_ENABLE, 1); 397b7e04f8cSWim Van Sebroeck release_region(SBC8360_BASETIME, 1); 398b7e04f8cSWim Van Sebroeck } 399b7e04f8cSWim Van Sebroeck 400b7e04f8cSWim Van Sebroeck module_init(sbc8360_init); 401b7e04f8cSWim Van Sebroeck module_exit(sbc8360_exit); 402b7e04f8cSWim Van Sebroeck 403b7e04f8cSWim Van Sebroeck MODULE_AUTHOR("Ian E. Morgan <imorgan@webcon.ca>"); 404b7e04f8cSWim Van Sebroeck MODULE_DESCRIPTION("SBC8360 watchdog driver"); 405b7e04f8cSWim Van Sebroeck MODULE_LICENSE("GPL"); 406b7e04f8cSWim Van Sebroeck MODULE_VERSION("1.01"); 407b7e04f8cSWim Van Sebroeck 408b7e04f8cSWim Van Sebroeck /* end of sbc8360.c */ 409