// SPDX-License-Identifier: GPL-2.0-or-later /* * Watchdog for the 7101 PMU version found in the ALi M1535 chipsets */ #define pr_fmt(fmt) … #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/types.h> #include <linux/miscdevice.h> #include <linux/watchdog.h> #include <linux/ioport.h> #include <linux/notifier.h> #include <linux/reboot.h> #include <linux/init.h> #include <linux/fs.h> #include <linux/pci.h> #include <linux/uaccess.h> #include <linux/io.h> #define WATCHDOG_NAME … #define WATCHDOG_TIMEOUT … /* internal variables */ static unsigned long ali_is_open; static char ali_expect_release; static struct pci_dev *ali_pci; static u32 ali_timeout_bits; /* stores the computed timeout */ static DEFINE_SPINLOCK(ali_lock); /* Guards the hardware */ /* module parameters */ static int timeout = …; module_param(timeout, int, 0); MODULE_PARM_DESC(…) …; static bool nowayout = … WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0); MODULE_PARM_DESC(…) …; /* * ali_start - start watchdog countdown * * Starts the timer running providing the timer has a counter * configuration set. */ static void ali_start(void) { … } /* * ali_stop - stop the timer countdown * * Stop the ALi watchdog countdown */ static void ali_stop(void) { … } /* * ali_keepalive - send a keepalive to the watchdog * * Send a keepalive to the timer (actually we restart the timer). */ static void ali_keepalive(void) { … } /* * ali_settimer - compute the timer reload value * @t: time in seconds * * Computes the timeout values needed */ static int ali_settimer(int t) { … } /* * /dev/watchdog handling */ /* * ali_write - writes to ALi watchdog * @file: file from VFS * @data: user address of data * @len: length of data * @ppos: pointer to the file offset * * Handle a write to the ALi watchdog. Writing to the file pings * the watchdog and resets it. Writing the magic 'V' sequence allows * the next close to turn off the watchdog. */ static ssize_t ali_write(struct file *file, const char __user *data, size_t len, loff_t *ppos) { … } /* * ali_ioctl - handle watchdog ioctls * @file: VFS file pointer * @cmd: ioctl number * @arg: arguments to the ioctl * * Handle the watchdog ioctls supported by the ALi driver. Really * we want an extension to enable irq ack monitoring and the like */ static long ali_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { … } /* * ali_open - handle open of ali watchdog * @inode: inode from VFS * @file: file from VFS * * Open the ALi watchdog device. Ensure only one person opens it * at a time. Also start the watchdog running. */ static int ali_open(struct inode *inode, struct file *file) { … } /* * ali_release - close an ALi watchdog * @inode: inode from VFS * @file: file from VFS * * Close the ALi watchdog device. Actual shutdown of the timer * only occurs if the magic sequence has been set. */ static int ali_release(struct inode *inode, struct file *file) { … } /* * ali_notify_sys - System down notifier * * Notifier for system down */ static int ali_notify_sys(struct notifier_block *this, unsigned long code, void *unused) { … } /* * Data for PCI driver interface * * This data only exists for exporting the supported * PCI ids via MODULE_DEVICE_TABLE. We do not actually * register a pci_driver, because someone else might one day * want to register another driver on the same PCI id. */ static const struct pci_device_id ali_pci_tbl[] __used = …; MODULE_DEVICE_TABLE(pci, ali_pci_tbl); /* * ali_find_watchdog - find a 1535 and 7101 * * Scans the PCI hardware for a 1535 series bridge and matching 7101 * watchdog device. This may be overtight but it is better to be safe */ static int __init ali_find_watchdog(void) { … } /* * Kernel Interfaces */ static const struct file_operations ali_fops = …; static struct miscdevice ali_miscdev = …; static struct notifier_block ali_notifier = …; /* * watchdog_init - module initialiser * * Scan for a suitable watchdog and if so initialize it. Return an error * if we cannot, the error causes the module to unload */ static int __init watchdog_init(void) { … } /* * watchdog_exit - module de-initialiser * * Called while unloading a successfully installed watchdog module. */ static void __exit watchdog_exit(void) { … } module_init(…) …; module_exit(watchdog_exit); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;