^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) * W83977F Watchdog Timer Driver for Winbond W83977F I/O Chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) Copyright 2005 Jose Goncalves <jose.goncalves@inov.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on w83877f_wdt.c by Scott Jennings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * and wdt977.c by Woody Suwalski
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * -----------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define WATCHDOG_VERSION "1.00"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define WATCHDOG_NAME "W83977F WDT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define IO_INDEX_PORT 0x3F0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define IO_DATA_PORT (IO_INDEX_PORT+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define UNLOCK_DATA 0x87
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define LOCK_DATA 0xAA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define DEVICE_REGISTER 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DEFAULT_TIMEOUT 45 /* default timeout in seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int timeout = DEFAULT_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int timeoutW; /* timeout in watchdog counter units */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static unsigned long timer_alive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int testmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static char expect_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static DEFINE_SPINLOCK(spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) module_param(timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_PARM_DESC(timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "Watchdog timeout in seconds (15..7635), default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __MODULE_STRING(DEFAULT_TIMEOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) module_param(testmode, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) MODULE_PARM_DESC(testmode, "Watchdog testmode (1 = no reboot), default=0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) MODULE_PARM_DESC(nowayout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) "Watchdog cannot be stopped once started (default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Start the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int wdt_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Select device Aux2 (device=8) to set watchdog regs F2, F3 and F4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * F2 has the timeout in watchdog counter units.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * F3 is set to enable watchdog LED blink at timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * F4 is used to just clear the TIMEOUT'ed state (bit 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) outb_p(timeoutW, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) outb_p(0xF3, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) outb_p(0xF4, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Set device Aux2 active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) outb_p(0x30, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) outb_p(0x01, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * Select device Aux1 (dev=7) to set GP16 as the watchdog output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * (in reg E6) and GP13 as the watchdog LED output (in reg E3).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Map GP16 at pin 119.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * In test mode watch the bit 0 on F4 to indicate "triggered" or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * check watchdog LED on SBC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) outb_p(0x07, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (!testmode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned pin_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) outb_p(0xE6, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) outb_p(0x0A, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) outb_p(0x2C, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pin_map = inb_p(IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) pin_map |= 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) pin_map &= ~(0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) outb_p(0x2C, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) outb_p(pin_map, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) outb_p(0xE3, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Set device Aux1 active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) outb_p(0x30, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) outb_p(0x01, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) pr_info("activated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Stop the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int wdt_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* Unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Select device Aux2 (device=8) to set watchdog regs F2, F3 and F4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * F2 is reset to its default value (watchdog timer disabled).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * F3 is reset to its default state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * F4 clears the TIMEOUT'ed state (bit 0) - back to default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^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(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) outb_p(0xFF, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) outb_p(0xF3, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) outb_p(0xF4, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) outb_p(0x00, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Select device Aux1 (dev=7) to set GP16 (in reg E6) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * Gp13 (in reg E3) as inputs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) outb_p(0x07, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!testmode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) outb_p(0xE6, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) outb_p(0x01, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) outb_p(0xE3, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) outb_p(0x01, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pr_info("shutdown\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Send a keepalive ping to the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * This is done by simply re-writing the timeout to reg. 0xF2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int wdt_keepalive(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Select device Aux2 (device=8) to kick watchdog reg F2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) outb_p(0xF2, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) outb_p(timeoutW, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Set the watchdog timeout value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int wdt_set_timeout(int t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) unsigned int tmrval;
^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) * Convert seconds to watchdog counter time units, rounding up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * On PCM-5335 watchdog units are 30 seconds/step with 15 sec startup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * value. This information is supplied in the PCM-5335 manual and was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * checked by me on a real board. This is a bit strange because W83977f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * datasheet says counter unit is in minutes!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (t < 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) tmrval = ((t + 15) + 29) / 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (tmrval > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * timeout is the timeout in seconds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * timeoutW is the timeout in watchdog counter units.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) timeoutW = tmrval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) timeout = (timeoutW * 30) - 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * Get the watchdog status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int wdt_get_status(int *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int new_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) spin_lock_irqsave(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* Unlock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) outb_p(UNLOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* Select device Aux2 (device=8) to read watchdog reg F4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) outb_p(DEVICE_REGISTER, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) outb_p(0x08, IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) outb_p(0xF4, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) new_status = inb_p(IO_DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* Lock the SuperIO chip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) outb_p(LOCK_DATA, IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) spin_unlock_irqrestore(&spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (new_status & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *status |= WDIOF_CARDRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * /dev/watchdog handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static int wdt_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* If the watchdog is alive we don't need to start it again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (test_and_set_bit(0, &timer_alive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (nowayout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) __module_get(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) wdt_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return stream_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int wdt_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Shut off the timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * Lock it in if it's a module and we set nowayout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (expect_close == 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) wdt_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) clear_bit(0, &timer_alive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) pr_crit("unexpected close, not stopping watchdog!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * wdt_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * @file: file handle to the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * @buf: buffer to write (unused as data does not matter here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * @count: count of bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * @ppos: pointer to the position to write. No seeks allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * A write to a watchdog device is defined as a keepalive signal. Any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * write of data will do, as we we don't define content meaning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static ssize_t wdt_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* See if we got the magic character 'V' and reload the timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) size_t ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* note: just in case someone wrote the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) magic character long ago */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /* scan to see whether or not we got the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) magic character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) for (ofs = 0; ofs != count; ofs++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (get_user(c, buf + ofs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (c == 'V')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) expect_close = 42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* someone wrote to us, we should restart timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * wdt_ioctl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * @inode: inode of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * @file: file handle to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * @cmd: watchdog command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * @arg: argument pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * The watchdog API defines a common set of functions for all watchdogs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * according to their available features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .firmware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) .identity = WATCHDOG_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int new_options, retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int new_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct watchdog_info __user *ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) int __user *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) } uarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) uarg.i = (int __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return copy_to_user(uarg.ident, &ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) sizeof(ident)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) wdt_get_status(&status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return put_user(status, uarg.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return put_user(0, uarg.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (get_user(new_options, uarg.i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (new_options & WDIOS_DISABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) wdt_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (new_options & WDIOS_ENABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) wdt_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) retval = 0;
^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) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (get_user(new_timeout, uarg.i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (wdt_set_timeout(new_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return put_user(timeout, uarg.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^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 int wdt_notify_sys(struct notifier_block *this, unsigned long code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (code == SYS_DOWN || code == SYS_HALT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) wdt_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static const struct file_operations wdt_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) .write = wdt_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) .unlocked_ioctl = wdt_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) .compat_ioctl = compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) .open = wdt_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) .release = wdt_release,
^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) static struct miscdevice wdt_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) .minor = WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .name = "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) .fops = &wdt_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static struct notifier_block wdt_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) .notifier_call = wdt_notify_sys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static int __init w83977f_wdt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) pr_info("driver v%s\n", WATCHDOG_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Check that the timeout value is within it's range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * if not reset to the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (wdt_set_timeout(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) wdt_set_timeout(DEFAULT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) pr_info("timeout value must be 15 <= timeout <= 7635, using %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) DEFAULT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!request_region(IO_INDEX_PORT, 2, WATCHDOG_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) pr_err("I/O address 0x%04x already in use\n", IO_INDEX_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) rc = register_reboot_notifier(&wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) pr_err("cannot register reboot notifier (err=%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) goto err_out_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) rc = misc_register(&wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) pr_err("cannot register miscdev on minor=%d (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) wdt_miscdev.minor, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) goto err_out_reboot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) pr_info("initialized. timeout=%d sec (nowayout=%d testmode=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) timeout, nowayout, testmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) err_out_reboot:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) unregister_reboot_notifier(&wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) err_out_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) release_region(IO_INDEX_PORT, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static void __exit w83977f_wdt_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) wdt_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) misc_deregister(&wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) unregister_reboot_notifier(&wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) release_region(IO_INDEX_PORT, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) module_init(w83977f_wdt_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) module_exit(w83977f_wdt_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) MODULE_AUTHOR("Jose Goncalves <jose.goncalves@inov.pt>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) MODULE_DESCRIPTION("Driver for watchdog timer in W83977F I/O chip");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) MODULE_LICENSE("GPL");