30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/module.h>
33 #include <linux/types.h>
34 #include <linux/kernel.h>
38 #include <linux/watchdog.h>
40 #include <linux/pci.h>
46 #define ESB_VERSION "0.05"
47 #define ESB_MODULE_NAME "i6300ESB timer"
48 #define ESB_DRIVER_NAME ESB_MODULE_NAME ", v" ESB_VERSION
51 #define ESB_CONFIG_REG 0x60
52 #define ESB_LOCK_REG 0x68
55 #define ESB_TIMER1_REG (BASEADDR + 0x00)
56 #define ESB_TIMER2_REG (BASEADDR + 0x04)
57 #define ESB_GINTSR_REG (BASEADDR + 0x08)
58 #define ESB_RELOAD_REG (BASEADDR + 0x0c)
61 #define ESB_WDT_FUNC (0x01 << 2)
62 #define ESB_WDT_ENABLE (0x01 << 1)
63 #define ESB_WDT_LOCK (0x01 << 0)
66 #define ESB_WDT_REBOOT (0x01 << 5)
67 #define ESB_WDT_FREQ (0x01 << 2)
68 #define ESB_WDT_INTTYPE (0x03 << 0)
71 #define ESB_WDT_TIMEOUT (0x01 << 9)
72 #define ESB_WDT_RELOAD (0x01 << 8)
75 #define ESB_UNLOCK1 0x80
76 #define ESB_UNLOCK2 0x86
81 static unsigned long timer_alive;
83 static unsigned short triggered;
84 static char esb_expect_close;
87 static int cards_found;
91 #define WATCHDOG_HEARTBEAT 30
95 "Watchdog heartbeat in seconds. (1<heartbeat<2046, default="
101 "Watchdog cannot be stopped once started (default="
114 static inline void esb_unlock_registers(
void)
120 static int esb_timer_start(
void)
124 spin_lock(&esb_lock);
125 esb_unlock_registers();
130 spin_unlock(&esb_lock);
134 static int esb_timer_stop(
void)
138 spin_lock(&esb_lock);
140 esb_unlock_registers();
145 spin_unlock(&esb_lock);
151 static void esb_timer_keepalive(
void)
153 spin_lock(&esb_lock);
154 esb_unlock_registers();
157 spin_unlock(&esb_lock);
160 static int esb_timer_set_heartbeat(
int time)
164 if (time < 0x1 || time > (2 * 0x03ff))
167 spin_lock(&esb_lock);
176 esb_unlock_registers();
180 esb_unlock_registers();
184 esb_unlock_registers();
191 spin_unlock(&esb_lock);
211 static int esb_release(
struct inode *inode,
struct file *file)
214 if (esb_expect_close == 42)
217 pr_crit(
"Unexpected close, not stopping watchdog!\n");
218 esb_timer_keepalive();
221 esb_expect_close = 0;
225 static ssize_t esb_write(
struct file *file,
const char __user *
data,
226 size_t len, loff_t *ppos)
235 esb_expect_close = 0;
239 for (i = 0; i != len; i++) {
244 esb_expect_close = 42;
249 esb_timer_keepalive();
254 static long esb_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
264 .firmware_version = 0,
271 sizeof(ident)) ? -
EFAULT : 0;
296 esb_timer_keepalive();
303 if (esb_timer_set_heartbeat(new_heartbeat))
305 esb_timer_keepalive();
323 .unlocked_ioctl = esb_ioctl,
325 .release = esb_release,
350 pr_err(
"failed to enable device\n");
355 pr_err(
"failed to request region\n");
360 if (BASEADDR ==
NULL) {
362 pr_err(
"failed to get BASEADDR\n");
378 static void __devinit esb_initdevice(
void)
400 pr_warn(
"nowayout already set\n");
406 esb_unlock_registers();
412 esb_unlock_registers();
425 if (cards_found == 1)
426 pr_info(
"Intel 6300ESB WatchDog Timer Driver v%s\n",
429 if (cards_found > 1) {
430 pr_err(
"This driver only supports 1 device\n");
435 if (!esb_getdevice(pdev) || esb_pci ==
NULL)
440 if (heartbeat < 0x1 || heartbeat > 2 * 0x03ff) {
442 pr_info(
"heartbeat value must be 1<heartbeat<2046, using %d\n",
452 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
456 pr_info(
"initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n",
482 static void esb_shutdown(
struct pci_dev *pdev)
489 .id_table = esb_pci_tbl,
492 .shutdown = esb_shutdown,