/* User land timeout */ #define WDT_HEARTBEAT 15 staticint heartbeat = WDT_HEARTBEAT;
module_param(heartbeat, int, 0);
MODULE_PARM_DESC(heartbeat, "Watchdog heartbeats in seconds. " "(default = " __MODULE_STRING(WDT_HEARTBEAT) ")");
staticbool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
staticstruct { void __iomem *fpga; unsignedlong next_heartbeat; /* the next_heartbeat for the timer */ unsignedlong open; char expect_close; int bootstatus; struct timer_list timer; /* The timer that pings the watchdog */
} pikawdt_private;
/* * Reload the watchdog timer. (ie, pat the watchdog)
*/ staticinlinevoid pikawdt_reset(void)
{ /* -- FPGA: Reset Control Register (32bit R/W) (Offset: 0x14) -- * Bit 7, WTCHDG_EN: When set to 1, the watchdog timer is enabled. * Once enabled, it cannot be disabled. The watchdog can be * kicked by performing any write access to the reset * control register (this register). * Bit 8-11, WTCHDG_TIMEOUT_SEC: Sets the watchdog timeout value in * seconds. Valid ranges are 1 to 15 seconds. The value can * be modified dynamically.
*/ unsigned reset = in_be32(pikawdt_private.fpga + 0x14); /* enable with max timeout - 15 seconds */
reset |= (1 << 7) + (WDT_HW_TIMEOUT << 8);
out_be32(pikawdt_private.fpga + 0x14, reset);
}
/* * Watchdog device is opened, and watchdog starts running.
*/ staticint pikawdt_open(struct inode *inode, struct file *file)
{ /* /dev/watchdog can only be opened once */ if (test_and_set_bit(0, &pikawdt_private.open)) return -EBUSY;
pikawdt_start();
return stream_open(inode, file);
}
/* * Close the watchdog device.
*/ staticint pikawdt_release(struct inode *inode, struct file *file)
{ /* stop internal ping */ if (!pikawdt_private.expect_close)
timer_delete(&pikawdt_private.timer);
/* * Pat the watchdog whenever device is written to.
*/ static ssize_t pikawdt_write(struct file *file, constchar __user *data,
size_t len, loff_t *ppos)
{ if (!len) return 0;
/* Scan for magic character */ if (!nowayout) {
size_t i;
pikawdt_private.expect_close = 0;
for (i = 0; i < len; i++) { char c; if (get_user(c, data + i)) return -EFAULT; if (c == 'V') {
pikawdt_private.expect_close = 42; break;
}
}
}
pikawdt_keepalive();
return len;
}
/* * Handle commands from user-space.
*/ staticlong pikawdt_ioctl(struct file *file, unsignedint cmd, unsignedlong arg)
{ void __user *argp = (void __user *)arg; int __user *p = argp; int new_value;
/* POST information is in the sd area. */
np = of_find_compatible_node(NULL, NULL, "pika,fpga-sd"); if (np == NULL) {
pr_err("Unable to find fpga-sd\n");
ret = -ENOENT; goto out;
}
fpga = of_iomap(np, 0);
of_node_put(np); if (fpga == NULL) {
pr_err("Unable to map fpga-sd\n");
ret = -ENOMEM; goto out;
}
/* -- FPGA: POST Test Results Register 1 (32bit R/W) (Offset: 0x4040) -- * Bit 31, WDOG: Set to 1 when the last reset was caused by a watchdog * timeout.
*/
post1 = in_be32(fpga + 0x40); if (post1 & 0x80000000)
pikawdt_private.bootstatus = WDIOF_CARDRESET;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.