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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Watchdog timer for machines with the CS5535/CS5536 companion chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2006-2007, Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009  Andres Salomon <dilinger@collabora.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/cs5535.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define GEODEWDT_HZ 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define GEODEWDT_SCALE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define GEODEWDT_MAX_SECONDS 131
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define WDT_FLAGS_OPEN 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define WDT_FLAGS_ORPHAN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define DRV_NAME "geodewdt"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define WATCHDOG_NAME "Geode GX/LX WDT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define WATCHDOG_TIMEOUT 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int timeout = WATCHDOG_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) module_param(timeout, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) MODULE_PARM_DESC(timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	"Watchdog timeout in seconds. 1<= timeout <=131, default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				__MODULE_STRING(WATCHDOG_TIMEOUT) ".");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) module_param(nowayout, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) MODULE_PARM_DESC(nowayout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	"Watchdog cannot be stopped once started (default="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static struct platform_device *geodewdt_platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static unsigned long wdt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct cs5535_mfgpt_timer *wdt_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int safe_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static void geodewdt_ping(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* Stop the counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_SETUP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/* Reset the counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_COUNTER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/* Enable the counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_SETUP, MFGPT_SETUP_CNTEN);
^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 geodewdt_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_SETUP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_COUNTER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static int geodewdt_set_heartbeat(int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (val < 1 || val > GEODEWDT_MAX_SECONDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_SETUP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_CMP2, val * GEODEWDT_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_COUNTER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_SETUP, MFGPT_SETUP_CNTEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	timeout = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int geodewdt_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (test_and_set_bit(WDT_FLAGS_OPEN, &wdt_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!test_and_clear_bit(WDT_FLAGS_ORPHAN, &wdt_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		__module_get(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	geodewdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return stream_open(inode, file);
^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) static int geodewdt_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (safe_close) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		geodewdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		pr_crit("Unexpected close - watchdog is not stopping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		geodewdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		set_bit(WDT_FLAGS_ORPHAN, &wdt_flags);
^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) 	clear_bit(WDT_FLAGS_OPEN, &wdt_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	safe_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static ssize_t geodewdt_write(struct file *file, const char __user *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				size_t len, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if (!nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			safe_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			for (i = 0; i != len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				if (get_user(c, data + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				if (c == 'V')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 					safe_close = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		geodewdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static long geodewdt_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 				unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int __user *p = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	static const struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		| WDIOF_MAGICCLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		.firmware_version =     1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		.identity =             WATCHDOG_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return copy_to_user(argp, &ident,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				    sizeof(ident)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	case WDIOC_GETBOOTSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return put_user(0, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		int options, ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (get_user(options, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (options & WDIOS_DISABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			geodewdt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		if (options & WDIOS_ENABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			geodewdt_ping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		geodewdt_ping();
^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) 	case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		if (get_user(interval, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (geodewdt_set_heartbeat(interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		return put_user(timeout, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static const struct file_operations geodewdt_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.owner          = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.llseek         = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.write          = geodewdt_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	.unlocked_ioctl = geodewdt_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	.compat_ioctl	= compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	.open           = geodewdt_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	.release        = geodewdt_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static struct miscdevice geodewdt_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	.minor = WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.name = "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	.fops = &geodewdt_fops,
^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) static int __init geodewdt_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	wdt_timer = cs5535_mfgpt_alloc_timer(MFGPT_TIMER_ANY, MFGPT_DOMAIN_WORKING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (!wdt_timer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		pr_err("No timers were available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return -ENODEV;
^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) 	/* Set up the timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_SETUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			  GEODEWDT_SCALE | (3 << 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* Set up comparator 2 to reset when the event fires */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	cs5535_mfgpt_toggle_event(wdt_timer, MFGPT_CMP2, MFGPT_EVENT_RESET, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* Set up the initial timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	cs5535_mfgpt_write(wdt_timer, MFGPT_REG_CMP2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		timeout * GEODEWDT_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	ret = misc_register(&geodewdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int geodewdt_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	misc_deregister(&geodewdt_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return 0;
^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) static void geodewdt_shutdown(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	geodewdt_disable();
^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) static struct platform_driver geodewdt_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	.remove		= geodewdt_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	.shutdown	= geodewdt_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		.name	= DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int __init geodewdt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	geodewdt_platform_device = platform_device_register_simple(DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 								-1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (IS_ERR(geodewdt_platform_device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return PTR_ERR(geodewdt_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ret = platform_driver_probe(&geodewdt_driver, geodewdt_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	platform_device_unregister(geodewdt_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return ret;
^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) static void __exit geodewdt_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	platform_device_unregister(geodewdt_platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	platform_driver_unregister(&geodewdt_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) module_init(geodewdt_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) module_exit(geodewdt_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) MODULE_AUTHOR("Advanced Micro Devices, Inc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) MODULE_DESCRIPTION("Geode GX/LX Watchdog Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MODULE_LICENSE("GPL");