34 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36 #include <linux/module.h>
39 #include <linux/watchdog.h>
43 #include <linux/reboot.h>
51 #define SC1200_MODULE_VER "build 20020303"
52 #define SC1200_MODULE_NAME "sc1200wdt"
54 #define MAX_TIMEOUT 255
71 #define UART1_IRQ 0x03
72 #define UART2_IRQ 0x04
77 static int io_len = 2;
78 static unsigned long open_flag;
82 #if defined CONFIG_PNP
83 static int isapnp = 1;
88 "When set to 0 driver ISA PnP support will be disabled");
99 "Watchdog cannot be stopped once started (default="
105 static inline void __sc1200wdt_read_data(
unsigned char index,
112 static void sc1200wdt_read_data(
unsigned char index,
unsigned char *
data)
114 spin_lock(&sc1200wdt_lock);
115 __sc1200wdt_read_data(index, data);
116 spin_unlock(&sc1200wdt_lock);
120 static inline void __sc1200wdt_write_data(
unsigned char index,
127 static inline void sc1200wdt_write_data(
unsigned char index,
130 spin_lock(&sc1200wdt_lock);
131 __sc1200wdt_write_data(index, data);
132 spin_unlock(&sc1200wdt_lock);
136 static void sc1200wdt_start(
void)
139 spin_lock(&sc1200wdt_lock);
141 __sc1200wdt_read_data(
WDCF, ®);
144 __sc1200wdt_write_data(
WDCF, reg);
146 __sc1200wdt_write_data(
WDTO, timeout);
148 spin_unlock(&sc1200wdt_lock);
151 static void sc1200wdt_stop(
void)
153 sc1200wdt_write_data(
WDTO, 0);
157 static inline int sc1200wdt_status(
void)
161 sc1200wdt_read_data(
WDST, &ret);
179 pr_info(
"Watchdog enabled, timeout = %d min(s)", timeout);
185 static long sc1200wdt_ioctl(
struct file *file,
unsigned int cmd,
194 .firmware_version = 0,
195 .identity =
"PC87307/PC97307",
205 return put_user(sc1200wdt_status(), p);
230 sc1200wdt_write_data(
WDTO, timeout);
241 sc1200wdt_write_data(
WDTO, timeout);
253 static int sc1200wdt_release(
struct inode *inode,
struct file *file)
255 if (expect_close == 42) {
257 pr_info(
"Watchdog disabled\n");
259 sc1200wdt_write_data(
WDTO, timeout);
260 pr_crit(
"Unexpected close!, timeout = %d min(s)\n", timeout);
269 static ssize_t sc1200wdt_write(
struct file *file,
const char __user *
data,
270 size_t len, loff_t *ppos)
278 for (i = 0; i != len; i++) {
288 sc1200wdt_write_data(
WDTO, timeout);
307 .notifier_call = sc1200wdt_notify_sys,
313 .write = sc1200wdt_write,
314 .unlocked_ioctl = sc1200wdt_ioctl,
315 .open = sc1200wdt_open,
316 .release = sc1200wdt_release,
319 static struct miscdevice sc1200wdt_miscdev = {
322 .fops = &sc1200wdt_fops,
326 static int __init sc1200wdt_probe(
void)
337 sc1200wdt_read_data(
PMC3, ®);
339 return (reg == 0x0e) ? 0 : -
ENODEV;
343 #if defined CONFIG_PNP
347 {.
id =
"NSC0800", .driver_data = 0},
351 static int scl200wdt_pnp_probe(
struct pnp_dev *
dev,
355 if (wdt_dev || !isapnp)
359 io = pnp_port_start(wdt_dev, 0);
360 io_len = pnp_port_len(wdt_dev, 0);
363 pr_err(
"Unable to register IO port %#x\n",
io);
367 pr_info(
"PnP device found at io port %#x/%d\n",
io, io_len);
371 static void scl200wdt_pnp_remove(
struct pnp_dev *dev)
379 static struct pnp_driver scl200wdt_pnp_driver = {
381 .id_table = scl200wdt_pnp_devices,
382 .probe = scl200wdt_pnp_probe,
383 .remove = scl200wdt_pnp_remove,
389 static int __init sc1200wdt_init(
void)
395 #if defined CONFIG_PNP
404 pr_err(
"io parameter must be specified\n");
409 #if defined CONFIG_PNP
417 pr_err(
"Unable to register IO port %#x\n",
io);
422 ret = sc1200wdt_probe();
428 pr_err(
"Unable to register reboot notifier err = %d\n", ret);
434 pr_err(
"Unable to register miscdev on minor %d\n",
451 #if defined CONFIG_PNP
459 static void __exit sc1200wdt_exit(
void)
464 #if defined CONFIG_PNP
477 "Driver for National Semiconductor PC87307/PC97307 watchdog component");