// SPDX-License-Identifier: GPL-2.0+ /* * Eurotech CPU-1220/1410/1420 on board WDT driver * * (c) Copyright 2001 Ascensit <[email protected]> * (c) Copyright 2001 Rodolfo Giometti <[email protected]> * (c) Copyright 2002 Rob Radez <[email protected]> * * Based on wdt.c. * Original copyright messages: * * (c) Copyright 1996-1997 Alan Cox <[email protected]>, * All Rights Reserved. * * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide * warranty for any of this software. This material is provided * "AS-IS" and at no charge. * * (c) Copyright 1995 Alan Cox <[email protected]>* */ /* Changelog: * * 2001 - Rodolfo Giometti * Initial release * * 2002/04/25 - Rob Radez * clean up #includes * clean up locking * make __setup param unique * proper options in watchdog_info * add WDIOC_GETSTATUS and WDIOC_SETOPTIONS ioctls * add expect_close support * * 2002.05.30 - Joel Becker <[email protected]> * Added Matt Domsch's nowayout module option. */ /* * The eurotech CPU-1220/1410/1420's watchdog is a part * of the on-board SUPER I/O device SMSC FDC 37B782. */ #define pr_fmt(fmt) … #include <linux/interrupt.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/types.h> #include <linux/miscdevice.h> #include <linux/watchdog.h> #include <linux/fs.h> #include <linux/ioport.h> #include <linux/notifier.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/io.h> #include <linux/uaccess.h> static unsigned long eurwdt_is_open; static int eurwdt_timeout; static char eur_expect_close; static DEFINE_SPINLOCK(eurwdt_lock); /* * You must set these - there is no sane way to probe for this board. */ static int io = …; static int irq = …; static char *ev = …; #define WDT_TIMEOUT … static bool nowayout = … WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0); MODULE_PARM_DESC(…) …; /* * Some symbolic names */ #define WDT_CTRL_REG … #define WDT_OUTPIN_CFG … #define WDT_EVENT_INT … #define WDT_EVENT_REBOOT … #define WDT_UNIT_SEL … #define WDT_UNIT_SECS … #define WDT_TIMEOUT_VAL … #define WDT_TIMER_CFG … module_param_hw(io, int, ioport, 0); MODULE_PARM_DESC(…) …; module_param_hw(irq, int, irq, 0); MODULE_PARM_DESC(…) …; module_param(ev, charp, 0); MODULE_PARM_DESC(…) …; /* * Programming support */ static inline void eurwdt_write_reg(u8 index, u8 data) { … } static inline void eurwdt_lock_chip(void) { … } static inline void eurwdt_unlock_chip(void) { … } static inline void eurwdt_set_timeout(int timeout) { … } static inline void eurwdt_disable_timer(void) { … } static void eurwdt_activate_timer(void) { … } /* * Kernel methods. */ static irqreturn_t eurwdt_interrupt(int irq, void *dev_id) { … } /** * eurwdt_ping: * * Reload counter one with the watchdog timeout. */ static void eurwdt_ping(void) { … } /** * eurwdt_write: * @file: file handle to the watchdog * @buf: buffer to write (unused as data does not matter here * @count: count of bytes * @ppos: pointer to the position to write. No seeks allowed * * A write to a watchdog device is defined as a keepalive signal. Any * write of data will do, as we don't define content meaning. */ static ssize_t eurwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { … } /** * eurwdt_ioctl: * @file: file handle to the device * @cmd: watchdog command * @arg: argument pointer * * The watchdog API defines a common set of functions for all watchdogs * according to their available features. */ static long eurwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { … } /** * eurwdt_open: * @inode: inode of device * @file: file handle to device * * The misc device has been opened. The watchdog device is single * open and on opening we load the counter. */ static int eurwdt_open(struct inode *inode, struct file *file) { … } /** * eurwdt_release: * @inode: inode to board * @file: file handle to board * * The watchdog has a configurable API. There is a religious dispute * between people who want their watchdog to be able to shut down and * those who want to be sure if the watchdog manager dies the machine * reboots. In the former case we disable the counters, in the latter * case you have to open it again very soon. */ static int eurwdt_release(struct inode *inode, struct file *file) { … } /** * eurwdt_notify_sys: * @this: our notifier block * @code: the event being reported * @unused: unused * * Our notifier is called on system shutdowns. We want to turn the card * off at reboot otherwise the machine will reboot again during memory * test or worse yet during the following fsck. This would suck, in fact * trust me - if it happens it does suck. */ static int eurwdt_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { … } /* * Kernel Interfaces */ static const struct file_operations eurwdt_fops = …; static struct miscdevice eurwdt_miscdev = …; /* * The WDT card needs to learn about soft shutdowns in order to * turn the timebomb registers off. */ static struct notifier_block eurwdt_notifier = …; /** * eurwdt_exit: * * Unload the watchdog. You cannot do this with any file handles open. * If your watchdog is set to continue ticking on close and you unload * it, well it keeps ticking. We won't get the interrupt but the board * will not touch PC memory so all is fine. You just have to load a new * module in 60 seconds or reboot. */ static void __exit eurwdt_exit(void) { … } /** * eurwdt_init: * * Set up the WDT watchdog board. After grabbing the resources * we require we need also to unlock the device. * The open() function will actually kick the board off. */ static int __init eurwdt_init(void) { … } module_init(…) …; module_exit(eurwdt_exit); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;