^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NANO7240 SBC Watchdog device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Based on w83877f.c by Scott Jennings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (c) Copyright 2007 Gilles GIGAN <gilles.gigan@jcu.edu.au>
^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) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define SBC7240_ENABLE_PORT 0x443
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SBC7240_DISABLE_PORT 0x043
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SBC7240_SET_TIMEOUT_PORT SBC7240_ENABLE_PORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SBC7240_MAGIC_CHAR 'V'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define SBC7240_TIMEOUT 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define SBC7240_MAX_TIMEOUT 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static int timeout = SBC7240_TIMEOUT; /* in seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) module_param(timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) __MODULE_STRING(SBC7240_MAX_TIMEOUT) ", default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __MODULE_STRING(SBC7240_TIMEOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_PARM_DESC(nowayout, "Disable watchdog when closing device file");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define SBC7240_OPEN_STATUS_BIT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define SBC7240_ENABLED_STATUS_BIT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define SBC7240_EXPECT_CLOSE_STATUS_BIT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static unsigned long wdt_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Utility routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void wdt_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* disable the watchdog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (test_and_clear_bit(SBC7240_ENABLED_STATUS_BIT, &wdt_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) inb_p(SBC7240_DISABLE_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) pr_info("Watchdog timer is now disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void wdt_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* enable the watchdog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (!test_and_set_bit(SBC7240_ENABLED_STATUS_BIT, &wdt_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) inb_p(SBC7240_ENABLE_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pr_info("Watchdog timer is now enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static int wdt_set_timeout(int t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (t < 1 || t > SBC7240_MAX_TIMEOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) pr_err("timeout value must be 1<=x<=%d\n", SBC7240_MAX_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* set the timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) outb_p((unsigned)t, SBC7240_SET_TIMEOUT_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) timeout = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) pr_info("timeout set to %d seconds\n", t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Whack the dog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static inline void wdt_keepalive(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (test_bit(SBC7240_ENABLED_STATUS_BIT, &wdt_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) inb_p(SBC7240_ENABLE_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * /dev/watchdog handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static ssize_t fop_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (!nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) clear_bit(SBC7240_EXPECT_CLOSE_STATUS_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* is there a magic char ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) for (i = 0; i != count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (get_user(c, buf + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (c == SBC7240_MAGIC_CHAR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) set_bit(SBC7240_EXPECT_CLOSE_STATUS_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return count;
^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) static int fop_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (test_and_set_bit(SBC7240_OPEN_STATUS_BIT, &wdt_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return stream_open(inode, file);
^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) static int fop_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (test_and_clear_bit(SBC7240_EXPECT_CLOSE_STATUS_BIT, &wdt_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) || !nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) wdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) pr_crit("Unexpected close, not stopping watchdog!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) clear_bit(SBC7240_OPEN_STATUS_BIT, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .options = WDIOF_KEEPALIVEPING|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) WDIOF_SETTIMEOUT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) WDIOF_MAGICCLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .firmware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .identity = "SBC7240",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static long fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return copy_to_user((void __user *)arg, &ident, sizeof(ident))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return put_user(0, (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (get_user(options, (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (options & WDIOS_DISABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) wdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (options & WDIOS_ENABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) wdt_keepalive();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int new_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (get_user(new_timeout, (int __user *)arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (wdt_set_timeout(new_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return put_user(timeout, (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static const struct file_operations wdt_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .write = fop_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .open = fop_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) .release = fop_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .unlocked_ioctl = fop_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .compat_ioctl = compat_ptr_ioctl,
^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) static struct miscdevice wdt_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .minor = WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .name = "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .fops = &wdt_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Notifier for system down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (code == SYS_DOWN || code == SYS_HALT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) wdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static struct notifier_block wdt_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .notifier_call = wdt_notify_sys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static void __exit sbc7240_wdt_unload(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) pr_info("Removing watchdog\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) misc_deregister(&wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unregister_reboot_notifier(&wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) release_region(SBC7240_ENABLE_PORT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int __init sbc7240_wdt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (!request_region(SBC7240_ENABLE_PORT, 1, "SBC7240 WDT")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pr_err("I/O address 0x%04x already in use\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) SBC7240_ENABLE_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) goto err_out;
^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) /* The IO port 0x043 used to disable the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * is already claimed by the system timer, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * can't request_region() it ...*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (timeout < 1 || timeout > SBC7240_MAX_TIMEOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) timeout = SBC7240_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) pr_info("timeout value must be 1<=x<=%d, using %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) SBC7240_MAX_TIMEOUT, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) wdt_set_timeout(timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) wdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) rc = register_reboot_notifier(&wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) pr_err("cannot register reboot notifier (err=%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) goto err_out_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) rc = misc_register(&wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) pr_err("cannot register miscdev on minor=%d (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) wdt_miscdev.minor, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) goto err_out_reboot_notifier;
^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) pr_info("Watchdog driver for SBC7240 initialised (nowayout=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) nowayout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) err_out_reboot_notifier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unregister_reboot_notifier(&wdt_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) err_out_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) release_region(SBC7240_ENABLE_PORT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) module_init(sbc7240_wdt_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) module_exit(sbc7240_wdt_unload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MODULE_AUTHOR("Gilles Gigan");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MODULE_DESCRIPTION("Watchdog device driver for single board"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) " computers EPIC Nano 7240 from iEi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) MODULE_LICENSE("GPL");