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) // 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)  *	Advantech Single Board Computer WDT driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	(c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Based on acquirewdt.c which is based on wdt.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	Original copyright messages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	(c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *						All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *	Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *	warranty for any of this software. This material is provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *	"AS-IS" and at no charge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	(c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *	14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *	    Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *	16-Oct-2002 Rob Radez <rob@osinvestor.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *	    Clean up ioctls, clean up init + exit, add expect close support,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *	    add wdt_start and wdt_stop as parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define DRV_NAME "advantechwdt"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define WATCHDOG_NAME "Advantech WDT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define WATCHDOG_TIMEOUT 60		/* 60 sec default timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* the watchdog platform device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct platform_device *advwdt_platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static unsigned long advwdt_is_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static char adv_expect_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *	You must set these - there is no sane way to probe for this board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *	To enable or restart, write the timeout value in seconds (1 to 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *	to I/O port wdt_start.  To disable, read I/O port wdt_stop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *	Both are 0x443 for most boards (tested on a PCA-6276VE-00B1), but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *	check your manual (at least the PCA-6159 seems to be different -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *	the manual says wdt_stop is 0x43, not 0x443).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *	(0x43 is also a write-only control register for the 8254 timer!)
^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 int wdt_stop = 0x443;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) module_param(wdt_stop, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) MODULE_PARM_DESC(wdt_stop, "Advantech WDT 'stop' io port (default 0x443)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int wdt_start = 0x443;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) module_param(wdt_start, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) MODULE_PARM_DESC(wdt_start, "Advantech WDT 'start' io port (default 0x443)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int timeout = WATCHDOG_TIMEOUT;	/* in seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) module_param(timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) MODULE_PARM_DESC(timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	"Watchdog timeout in seconds. 1<= timeout <=63, default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		__MODULE_STRING(WATCHDOG_TIMEOUT) ".");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) MODULE_PARM_DESC(nowayout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	"Watchdog cannot be stopped once started (default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *	Watchdog Operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static void advwdt_ping(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* Write a watchdog value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	outb_p(timeout, wdt_start);
^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) static void advwdt_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	inb_p(wdt_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static int advwdt_set_heartbeat(int t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (t < 1 || t > 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	timeout = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^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)  *	/dev/watchdog handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static ssize_t advwdt_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 						size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (!nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			adv_expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			for (i = 0; i != count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				if (get_user(c, buf + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				if (c == 'V')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					adv_expect_close = 42;
^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) 		advwdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static long advwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int new_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int __user *p = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.options = WDIOF_KEEPALIVEPING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			   WDIOF_SETTIMEOUT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			   WDIOF_MAGICCLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		.firmware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		.identity = WATCHDOG_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (copy_to_user(argp, &ident, sizeof(ident)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			return -EFAULT;
^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) 	case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return put_user(0, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		int options, retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (get_user(options, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (options & WDIOS_DISABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			advwdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		if (options & WDIOS_ENABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			advwdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		advwdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		if (get_user(new_timeout, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		if (advwdt_set_heartbeat(new_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		advwdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return put_user(timeout, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int advwdt_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (test_and_set_bit(0, &advwdt_is_open))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 *	Activate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	advwdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return stream_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int advwdt_close(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (adv_expect_close == 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		advwdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		pr_crit("Unexpected close, not stopping watchdog!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		advwdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	clear_bit(0, &advwdt_is_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	adv_expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return 0;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  *	Kernel Interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static const struct file_operations advwdt_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	.llseek		= no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.write		= advwdt_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.unlocked_ioctl	= advwdt_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.compat_ioctl	= compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.open		= advwdt_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.release	= advwdt_close,
^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 struct miscdevice advwdt_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	.minor	= WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	.name	= "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	.fops	= &advwdt_fops,
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *	Init & exit routines
^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 int __init advwdt_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (wdt_stop != wdt_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			pr_err("I/O address 0x%04x already in use\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			       wdt_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (!request_region(wdt_start, 1, WATCHDOG_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		pr_err("I/O address 0x%04x already in use\n", wdt_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		goto unreg_stop;
^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) 	/* Check that the heartbeat value is within it's range ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 * if not reset to the default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (advwdt_set_heartbeat(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		advwdt_set_heartbeat(WATCHDOG_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		pr_info("timeout value must be 1<=x<=63, using %d\n", timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	ret = misc_register(&advwdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		pr_err("cannot register miscdev on minor=%d (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		       WATCHDOG_MINOR, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		goto unreg_regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	pr_info("initialized. timeout=%d sec (nowayout=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		timeout, nowayout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) unreg_regions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	release_region(wdt_start, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) unreg_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (wdt_stop != wdt_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		release_region(wdt_stop, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	goto out;
^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) static int advwdt_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	misc_deregister(&advwdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	release_region(wdt_start, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (wdt_stop != wdt_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		release_region(wdt_stop, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^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) static void advwdt_shutdown(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* Turn the WDT off if we have a soft shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	advwdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static struct platform_driver advwdt_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.remove		= advwdt_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	.shutdown	= advwdt_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		.name	= DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int __init advwdt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	pr_info("WDT driver for Advantech single board computer initialising\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	advwdt_platform_device = platform_device_register_simple(DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 								-1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (IS_ERR(advwdt_platform_device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return PTR_ERR(advwdt_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	err = platform_driver_probe(&advwdt_driver, advwdt_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		goto unreg_platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) unreg_platform_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	platform_device_unregister(advwdt_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static void __exit advwdt_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	platform_device_unregister(advwdt_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	platform_driver_unregister(&advwdt_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	pr_info("Watchdog Module Unloaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) module_init(advwdt_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) module_exit(advwdt_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_AUTHOR("Marek Michalkiewicz <marekm@linux.org.pl>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_DESCRIPTION("Advantech Single Board Computer WDT driver");