46 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
48 #include <linux/module.h>
50 #include <linux/types.h>
52 #include <linux/watchdog.h>
57 #include <linux/reboot.h>
66 #define SMSC_SUPPORT_MINUTES
67 #undef SMSC_SUPPORT_MINUTES
69 #define MAX_TIMEOUT 255
82 static unsigned long timer_enabled;
94 static inline void open_io_config(
void)
102 static inline void close_io_config(
void)
108 static inline void select_io_device(
unsigned char devno)
115 static inline void write_io_cr(
unsigned char reg,
unsigned char data)
122 static inline char read_io_cr(
unsigned char reg)
130 static inline void gpio_bit12(
unsigned char reg)
141 write_io_cr(0xE2, reg);
144 static inline void gpio_bit13(
unsigned char reg)
154 write_io_cr(0xE3, reg);
157 static inline void wdt_timer_units(
unsigned char new_units)
164 write_io_cr(0xF1, new_units);
167 static inline void wdt_timeout_value(
unsigned char new_timeout)
172 write_io_cr(0xF2, new_timeout);
175 static inline void wdt_timer_conf(
unsigned char conf)
188 write_io_cr(0xF3, conf);
191 static inline void wdt_timer_ctrl(
unsigned char reg)
210 write_io_cr(0xF4, reg);
217 static void wb_smsc_wdt_initialize(
void)
230 wdt_timeout_value(0);
233 wdt_timer_ctrl(0x00);
236 wdt_timer_conf(0x00);
239 old = read_io_cr(0xF1) & 0x7F;
244 wdt_timer_units(old);
252 static void wb_smsc_wdt_shutdown(
void)
263 wdt_timer_conf(0x00);
266 wdt_timer_ctrl(0x00);
269 wdt_timeout_value(0x00);
277 static void wb_smsc_wdt_set_timeout(
unsigned char new_timeout)
284 wdt_timer_ctrl((new_timeout == 0) ? 0x00 : 0x02);
287 wdt_timeout_value(new_timeout);
295 static unsigned char wb_smsc_wdt_get_timeout(
void)
297 unsigned char set_timeout;
302 set_timeout = read_io_cr(0xF2);
311 static void wb_smsc_wdt_disable(
void)
314 wb_smsc_wdt_set_timeout(0);
319 static void wb_smsc_wdt_enable(
void)
322 wb_smsc_wdt_set_timeout(timeout);
327 static void wb_smsc_wdt_reset_timer(
void)
334 wdt_timeout_value(timeout);
335 wdt_timer_conf(0x08);
343 static int wb_smsc_wdt_status(
void)
364 wb_smsc_wdt_enable();
366 pr_info(
"Watchdog enabled. Timeout set to %d %s\n",
374 static int wb_smsc_wdt_release(
struct inode *inode,
struct file *file)
378 if (expect_close == 42) {
379 wb_smsc_wdt_disable();
380 pr_info(
"Watchdog disabled, sleeping again...\n");
382 pr_crit(
"Unexpected close, not stopping watchdog!\n");
383 wb_smsc_wdt_reset_timer();
393 static ssize_t wb_smsc_wdt_write(
struct file *file,
const char __user *
data,
394 size_t len, loff_t *ppos)
406 for (i = 0; i != len; i++) {
416 wb_smsc_wdt_reset_timer();
423 static long wb_smsc_wdt_ioctl(
struct file *file,
424 unsigned int cmd,
unsigned long arg)
437 .firmware_version = 0,
438 .identity =
"SMsC 37B787 Watchdog",
441 uarg.i = (
int __user *)arg;
448 return put_user(wb_smsc_wdt_status(), uarg.i);
459 wb_smsc_wdt_disable();
463 wb_smsc_wdt_enable();
469 wb_smsc_wdt_reset_timer();
480 wb_smsc_wdt_set_timeout(timeout);
486 return put_user(new_timeout, uarg.i);
500 wb_smsc_wdt_disable();
510 .write = wb_smsc_wdt_write,
511 .unlocked_ioctl = wb_smsc_wdt_ioctl,
512 .open = wb_smsc_wdt_open,
513 .release = wb_smsc_wdt_release,
517 .notifier_call = wb_smsc_wdt_notify_sys,
520 static struct miscdevice wb_smsc_wdt_miscdev = {
523 .fops = &wb_smsc_wdt_fops,
530 static int __init wb_smsc_wdt_init(
void)
534 pr_info(
"SMsC 37B787 watchdog component driver "
548 wb_smsc_wdt_initialize();
552 pr_err(
"Unable to register reboot notifier err = %d\n", ret);
558 pr_err(
"Unable to register miscdev on minor %d\n",
564 pr_info(
"Timeout set to %d %s\n",
566 pr_info(
"Watchdog initialized and sleeping (nowayout=%d)...\n",
583 static void __exit wb_smsc_wdt_exit(
void)
587 wb_smsc_wdt_shutdown();
588 pr_info(
"Watchdog disabled\n");
595 pr_info(
"SMsC 37B787 watchdog component driver removed\n");
608 #ifdef SMSC_SUPPORT_MINUTES
611 "set unit to use, 0=seconds or 1=minutes, default is 0");
619 "Watchdog cannot be stopped once started (default="