📄 wdt3210.c
字号:
/***file name: wtd3210.c*developed for DC16B3210 driver*created on july 1,2008***/#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/fs.h>#include <linux/mm.h>#include <linux/miscdevice.h>#include <linux/watchdog.h>#include <linux/reboot.h>#include <linux/init.h> /* define watchdog TIMER register */#define WD_TIMER (*(volatile unsigned int *) (0xBF003230)) /* define watchdog CONTROL register */#define WD_CTRL (*(volatile unsigned int *) (0xBF003234)) #define WD_SIG 0x0100 /* a signal for reseting */#define WD_ENABLE 0x0001 /* enable the watchdog */#define WD_DISABLE 0x0000 /* forbin the watchdog */#define SECONDS 100000000static unsigned int soft_margin = 20*SECONDS; /* 20 seconds *//*** reset the watchdog timer and count again*/static int watchdog_reset(){ WD_TIMER = soft_margin; return 0 ;}/*** enable watchdog and begin to count*/static int watchdog_enable(){ WD_CTRL = WD_ENABLE ; return 0 ;}/*** forbid watchdog and stop counting*/static int watchdog_disable(){ WD_CTRL = WD_DISABLE ; return 0 ;}/* * set the watchdog and keep program going */static int watchdog_keepalive(){ WD_CTRL |= WD_SIG ; return 0;}/* * Allow only one person to hold it open */static int watchdog_open(struct inode *inode, struct file *file){ watchdog_reset(); watchdog_enable(); return nonseekable_open(inode, file);}static struct watchdog_info ident = { .options = WDIOF_SETTIMEOUT, .identity = "Granchips Watchdog",};/* *define 4 ways for processing the command from ioctl function * * * WDIOC_KEEPALIVE: Ping the keepalive to keep us alive for another timeout. * * WDIOC_SETTIMEOUT: Set the timeout for the watchdog. The parameter is generally * an integer number of milliseconds, the watchdog times will * be set to the first value larger than the given time. It will * return EINVAL if the timeout is beyond the capability of the * watchdog timer. For some boards. it is a custom timeout that * is board dependent. Note that this function will automatically * does the keepalive for the watchdog. * * WDIOC_GETTIMEOUT: Get the timeout for programmer. * * WDIOS_DISABLECARD: Turn off the watchdog timer. * */static int watchdog_ioctl(struct inode *inode, struct file *file, unsigned int cmd,unsigned long arg){ int ret = -1; switch(cmd) { case WDIOC_KEEPALIVE: ret = watchdog_keepalive(); break; case WDIOC_SETTIMEOUT: ret = get_user(soft_margin, (int *)arg ); watchdog_reset(); break; case WDIOC_GETTIMEOUT: ret = put_user(soft_margin, (int *)arg ); break; case WDIOS_DISABLECARD: ret = watchdog_disable(); break; } return ret;}static const struct file_operations watchdog_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .ioctl = watchdog_ioctl, .open = watchdog_open,};static struct miscdevice watchdog_miscdev = { .minor = WATCHDOG_MINOR, .name = "watchdog", .fops = &watchdog_fops,};static int __init footbridge_watchdog_init(void){ int retval; retval = misc_register(&watchdog_miscdev); if (retval < 0) return retval; else {// succeeding about register printk("\nwatchdog register is successful\n"); printk("Footbridge Watchdog Timer: 0.01, timer margin: %d sec\n", soft_margin); } return 0;}static void __exit footbridge_watchdog_exit(void){ if(misc_deregister(&watchdog_miscdev) < 0) { printk("\nwatchdog deregister error\n"); } else { printk("\nwatchdog deregister successfully\n"); }}MODULE_AUTHOR("Miles zhang");MODULE_DESCRIPTION("DC16B3210 watchdog driver");MODULE_LICENSE("GPL");MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);module_param(soft_margin, int, 0);MODULE_PARM_DESC(soft_margin,"Watchdog timeout in seconds");module_init(footbridge_watchdog_init);module_exit(footbridge_watchdog_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -