Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Watchdog driver for SBC-FITPC2 board
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Author: Denis Turischev <denis@compulab.co.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Adapted from the IXP2000 watchdog driver by Deepak Saxena.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file is licensed under  the terms of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * License version 2. This program is licensed "as is" without any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * warranty of any kind, whether express or implied.
^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 " WATCHDOG: " 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/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/io.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static unsigned int margin = 60;	/* (secs) Default is 1 minute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned long wdt_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static DEFINE_MUTEX(wdt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define WDT_IN_USE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define WDT_OK_TO_CLOSE		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define COMMAND_PORT		0x4c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define DATA_PORT		0x48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define IFACE_ON_COMMAND	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define REBOOT_COMMAND		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define WATCHDOG_NAME		"SBC-FITPC2 Watchdog"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static void wdt_send_data(unsigned char command, unsigned char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	outb(data, DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	msleep(200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	outb(command, COMMAND_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	msleep(100);
^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_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	mutex_lock(&wdt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	wdt_send_data(IFACE_ON_COMMAND, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	wdt_send_data(REBOOT_COMMAND, margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	mutex_unlock(&wdt_lock);
^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) static void wdt_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	mutex_lock(&wdt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	wdt_send_data(IFACE_ON_COMMAND, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	wdt_send_data(REBOOT_COMMAND, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	mutex_unlock(&wdt_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static int fitpc2_wdt_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (test_and_set_bit(WDT_IN_USE, &wdt_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return stream_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static ssize_t fitpc2_wdt_write(struct file *file, const char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 						size_t len, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	for (i = 0; i != len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		if (get_user(c, data + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (c == 'V')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			set_bit(WDT_OK_TO_CLOSE, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^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) static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	.options	= WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				WDIOF_KEEPALIVEPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.identity	= WATCHDOG_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^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) static long fitpc2_wdt_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 							unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int ret = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		ret = copy_to_user((struct watchdog_info *)arg, &ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				   sizeof(ident)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		ret = put_user(0, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		ret = put_user(0, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		ret = get_user(time, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (time < 31 || time > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			break;
^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) 		margin = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		ret = put_user(margin, (int *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return ret;
^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) static int fitpc2_wdt_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		wdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		pr_info("Device disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		pr_warn("Device closed unexpectedly - timer will not stop\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		wdt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	clear_bit(WDT_IN_USE, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	return 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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static const struct file_operations fitpc2_wdt_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	.llseek		= no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	.write		= fitpc2_wdt_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.unlocked_ioctl	= fitpc2_wdt_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.compat_ioctl	= compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.open		= fitpc2_wdt_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.release	= fitpc2_wdt_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static struct miscdevice fitpc2_wdt_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	.minor		= WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	.name		= "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.fops		= &fitpc2_wdt_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int __init fitpc2_wdt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	const char *brd_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	brd_name = dmi_get_system_info(DMI_BOARD_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (!brd_name || !strstr(brd_name, "SBC-FITPC2"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	pr_info("%s found\n", brd_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (!request_region(COMMAND_PORT, 1, WATCHDOG_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		pr_err("I/O address 0x%04x already in use\n", COMMAND_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		return -EIO;
^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) 	if (!request_region(DATA_PORT, 1, WATCHDOG_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		pr_err("I/O address 0x%04x already in use\n", DATA_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		goto err_data_port;
^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) 	if (margin < 31 || margin > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		pr_err("margin must be in range 31 - 255 seconds, you tried to set %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		       margin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		goto err_margin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	err = misc_register(&fitpc2_wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		pr_err("cannot register miscdev on minor=%d (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		       WATCHDOG_MINOR, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		goto err_margin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) err_margin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	release_region(DATA_PORT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) err_data_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	release_region(COMMAND_PORT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return err;
^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 void __exit fitpc2_wdt_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	misc_deregister(&fitpc2_wdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	release_region(DATA_PORT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	release_region(COMMAND_PORT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) module_init(fitpc2_wdt_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) module_exit(fitpc2_wdt_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) MODULE_DESCRIPTION("SBC-FITPC2 Watchdog");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) module_param(margin, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_LICENSE("GPL");