^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Wdt977 0.04: A Watchdog Device for Netwinder W83977AF chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) Copyright 1998 Rebel.com (Woody Suwalski <woody@netwinder.org>)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * -----------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * -----------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * 19-Dec-2001 Woody Suwalski: Netwinder fixes, ioctl interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * 06-Jan-2002 Woody Suwalski: For compatibility, convert all timeouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * from minutes to seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * 07-Jul-2003 Daniele Bellucci: Audit return code of misc_register in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * nwwatchdog_init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * 25-Oct-2005 Woody Suwalski: Convert addresses to #defs, add spinlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * remove limitiation to be used on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Netwinders only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define WATCHDOG_VERSION "0.04"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define WATCHDOG_NAME "Wdt977"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define IO_INDEX_PORT 0x370 /* on some systems it can be 0x3F0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define IO_DATA_PORT (IO_INDEX_PORT + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define UNLOCK_DATA 0x87
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define LOCK_DATA 0xAA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define DEVICE_REGISTER 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define DEFAULT_TIMEOUT 60 /* default timeout in seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static int timeout = DEFAULT_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int timeoutM; /* timeout in minutes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static unsigned long timer_alive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int testmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static char expect_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static DEFINE_SPINLOCK(spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) module_param(timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (60..15300, default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __MODULE_STRING(DEFAULT_TIMEOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) module_param(testmode, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) MODULE_PARM_DESC(nowayout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) "Watchdog cannot be stopped once started (default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Start the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int wdt977_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* select device Aux2 (device=8) and set watchdog regs F2, F3 and F4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * F2 has the timeout in minutes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * F3 could be set to the POWER LED blink (with GP17 set to PowerLed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * at timeout, and to reset timer on kbd/mouse activity (not impl.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * F4 is used to just clear the TIMEOUT'ed state (bit 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) outb_p(timeoutM, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) outb_p(0xF3, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) outb_p(0x00, IO_DATA_PORT); /* another setting is 0E for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) kbd/mouse/LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) outb_p(0xF4, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* At last select device Aux1 (dev=7) and set GP16 as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * watchdog output. In test mode watch the bit 1 on F4 to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * indicate "triggered"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (!testmode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) outb_p(0x07, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) outb_p(0xE6, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) pr_info("activated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * Stop the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int wdt977_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* select device Aux2 (device=8) and set watchdog regs F2,F3 and F4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * F3 is reset to its default state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * F4 can clear the TIMEOUT'ed state (bit 0) - back to default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * We can not use GP17 as a PowerLed, as we use its usage as a RedLed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) outb_p(0xFF, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) outb_p(0xF3, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) outb_p(0xF4, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* at last select device Aux1 (dev=7) and set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) GP16 as a watchdog output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) outb_p(0x07, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) outb_p(0xE6, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pr_info("shutdown\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Send a keepalive ping to the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * This is done by simply re-writing the timeout to reg. 0xF2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int wdt977_keepalive(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* select device Aux2 (device=8) and kicks watchdog reg F2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* F2 has the timeout in minutes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) outb_p(timeoutM, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * Set the watchdog timeout value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int wdt977_set_timeout(int t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int tmrval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /* convert seconds to minutes, rounding up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) tmrval = (t + 59) / 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (machine_is_netwinder()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* we have a hw bug somewhere, so each 977 minute is actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * only 30sec. This limits the max timeout to half of device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * max of 255 minutes...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) tmrval += tmrval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (tmrval < 1 || tmrval > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* timeout is the timeout in seconds, timeoutM is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) the timeout in minutes) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) timeout = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) timeoutM = tmrval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Get the watchdog status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static int wdt977_get_status(int *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int new_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* select device Aux2 (device=8) and read watchdog reg F4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) outb_p(0xF4, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) new_status = inb_p(IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (new_status & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *status |= WDIOF_CARDRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * /dev/watchdog handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int wdt977_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* If the watchdog is alive we don't need to start it again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (test_and_set_bit(0, &timer_alive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (nowayout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) __module_get(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) wdt977_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return stream_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int wdt977_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * Shut off the timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * Lock it in if it's a module and we set nowayout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (expect_close == 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) wdt977_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) clear_bit(0, &timer_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) wdt977_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) pr_crit("Unexpected close, not stopping watchdog!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * wdt977_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * @file: file handle to the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * @buf: buffer to write (unused as data does not matter here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * @count: count of bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * @ppos: pointer to the position to write. No seeks allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * A write to a watchdog device is defined as a keepalive signal. Any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * write of data will do, as we we don't define content meaning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static ssize_t wdt977_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* In case it was set long ago */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) for (i = 0; i != count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (get_user(c, buf + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (c == 'V')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) expect_close = 42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* someone wrote to us, we should restart timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) wdt977_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .options = WDIOF_SETTIMEOUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) WDIOF_MAGICCLOSE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) WDIOF_KEEPALIVEPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .firmware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .identity = WATCHDOG_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * wdt977_ioctl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * @inode: inode of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * @file: file handle to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * @cmd: watchdog command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * @arg: argument pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * The watchdog API defines a common set of functions for all watchdogs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * according to their available features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static long wdt977_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int new_options, retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int new_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct watchdog_info __user *ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int __user *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) } uarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) uarg.i = (int __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return copy_to_user(uarg.ident, &ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) sizeof(ident)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) wdt977_get_status(&status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return put_user(status, uarg.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return put_user(0, uarg.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (get_user(new_options, uarg.i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (new_options & WDIOS_DISABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) wdt977_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (new_options & WDIOS_ENABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) wdt977_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) wdt977_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (get_user(new_timeout, uarg.i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (wdt977_set_timeout(new_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) wdt977_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return put_user(timeout, uarg.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static int wdt977_notify_sys(struct notifier_block *this, unsigned long code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (code == SYS_DOWN || code == SYS_HALT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) wdt977_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static const struct file_operations wdt977_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .write = wdt977_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .unlocked_ioctl = wdt977_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .open = wdt977_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .release = wdt977_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static struct miscdevice wdt977_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) .minor = WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) .name = "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) .fops = &wdt977_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static struct notifier_block wdt977_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .notifier_call = wdt977_notify_sys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static int __init wd977_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) pr_info("driver v%s\n", WATCHDOG_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* Check that the timeout value is within its range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if not reset to the default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (wdt977_set_timeout(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) wdt977_set_timeout(DEFAULT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) pr_info("timeout value must be 60 < timeout < 15300, using %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) DEFAULT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* on Netwinder the IOports are already reserved by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * arch/arm/mach-footbridge/netwinder-hw.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (!machine_is_netwinder()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) pr_err("I/O address 0x%04x already in use\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) rc = register_reboot_notifier(&wdt977_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) pr_err("cannot register reboot notifier (err=%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) goto err_out_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) rc = misc_register(&wdt977_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) pr_err("cannot register miscdev on minor=%d (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) wdt977_miscdev.minor, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) goto err_out_reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) pr_info("initialized. timeout=%d sec (nowayout=%d, testmode=%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) timeout, nowayout, testmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) err_out_reboot:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) unregister_reboot_notifier(&wdt977_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) err_out_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!machine_is_netwinder())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) release_region(IO_INDEX_PORT, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static void __exit wd977_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) wdt977_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) misc_deregister(&wdt977_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) unregister_reboot_notifier(&wdt977_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) release_region(IO_INDEX_PORT, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) module_init(wd977_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) module_exit(wd977_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) MODULE_DESCRIPTION("W83977AF Watchdog driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) MODULE_LICENSE("GPL");