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