static int wdt_open(struct inode *inode, struct file *file) { /* Allow only one person to hold it open */ if (access) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); /* Activate timer */ wdt_reset_counter(); wdt_set_timeout(); printk(KERN_INFO NAME ": enabling watchdog timer\n"); access = 1; return 0; }
void wdt_test(unsigned int seconds, unsigned int reset_int) { // wdt 13Mhz *(VUINT_T *)0xD4050200 = 0x7; udelay(10); *(VUINT_T *)0xD4050200 = 0x3; udelay(100); *(VUINT_T *)0xD4051020 |= 0x10; wdt_reset_counter(); // the wdt timer seems only use 256hz // see the emei register TimersCP section for details wdt_set_match(seconds * 256); wdt_enable(reset_int); printf("-------- wdt rest --------------\n"); while (1); }
static ssize_t wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos) { /* Refresh the timer. */ if (len) { if (!nowayout) { size_t i; /* In case it was set long ago */ expect_close = 0; for (i = 0; i != len; i++) { char c; if (get_user(c, data + i)) return -EFAULT; if (c == 'V') expect_close = 1; } } wdt_reset_counter(); return len; } return 0; }
static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int new_timeout; static struct watchdog_info ident = { .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, .firmware_version = 0, .identity = "ADM5120_WDT Watchdog", }; switch (cmd) { default: return -ENOTTY; case WDIOC_GETSUPPORT: if (copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident))) return -EFAULT; return 0; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, (int *)arg); case WDIOC_KEEPALIVE: wdt_reset_counter(); return 0; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, (int *)arg)) return -EFAULT; if (new_timeout < 1) return -EINVAL; if (new_timeout > MAX_TIMEOUT) return -EINVAL; timeout = new_timeout; wdt_set_timeout(); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(timeout, (int *)arg); } } static const struct file_operations wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .write = wdt_write, .unlocked_ioctl = wdt_ioctl, .open = wdt_open, .release = wdt_release, }; static struct miscdevice wdt_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &wdt_fops, }; static char banner[] __initdata = KERN_INFO NAME ": Watchdog Timer version " VERSION "\n"; static int __init watchdog_init(void) { int ret; ret = misc_register(&wdt_miscdev); if (ret) return ret; wdt_disable(); printk(banner); return 0; } static void __exit watchdog_exit(void) { misc_deregister(&wdt_miscdev); }