omap_wdt_core.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 238 行
C
238 行
/* * linux/drivers/char/watchdog/omap_wdt_core.c * * Watchdog driver for the TI OMAP 1610, 1710 & 24xx * * Copyright (C) 2004 Texas Instruments, Inc. * * This package is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//************************ INCLUDES ****************************************/#include <linux/module.h>#include <linux/config.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/smp_lock.h>#include <linux/init.h>#include <asm/uaccess.h>#include <asm/hardware.h>#include <asm/bitops.h>#include <asm/io.h>#include <asm/hardware/clock.h>#include <linux/moduleparam.h>#include <linux/delay.h>#include "omap_wdt_core.h"#include "omap_wdt_hardware.h"/************************ DEFINES *****************************************/#define WATCHDOG_NAME "OMAP Watchdog"/************************ FUNCTION PROTOTYPES *****************************/static int omap_wdt_open(struct inode *inode, struct file *file);static int omap_wdt_release(struct inode *inode, struct file *file);static ssize_t omap_wdt_write(struct file *file, const char *data, size_t len, loff_t * ppos);static int omap_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);/************************ DATA STRUCTURES *********************************//* Current WDT timeout value in second */static int timer_margin;/* Flag to allow only one user acces to driver*/static char omap_wdt_users;/* File Operations Structure */struct file_operations omap_wdt_fops = { .owner = THIS_MODULE, .write = omap_wdt_write, .ioctl = omap_wdt_ioctl, .open = omap_wdt_open, .release = omap_wdt_release,};/* Device Structure */static struct miscdevice omap_wdt_miscdev = { .minor = WATCHDOG_MINOR, .name = "omap_wdt", .fops = &omap_wdt_fops};/************************ FUNCTION DEFINTIONS *****************************//* omap_wdt_open(): Driver open function */static int omap_wdt_open(struct inode *inode, struct file *file){ /* Allow only one person to hold it open at any given time */ if (test_and_set_bit(1, (unsigned long *)&omap_wdt_users)) return -EBUSY; omap_wdt_enable(); return 0;}/* omap_wdt_release(): Driver release function */static int omap_wdt_release(struct inode *inode, struct file *file){ /* * Shut off the timer. * Lock it in if it's a module and we defined ...NOWAYOUT */#ifndef CONFIG_WATCHDOG_NOWAYOUT omap_wdt_disable(); WDT_CK_DISABLE(); /* Disable the clock */#endif /* CONFIG_WATCHDOG_NOWAYOUT */ omap_wdt_users = 0; return 0;}/* omap_wdt_write(): Driver write function * A write with a non zero length data would refresh the watchdog counter */static ssize_tomap_wdt_write(struct file *file, const char *data, size_t len, loff_t * ppos){ /* Can't seek (pwrite) on this device */ if (*ppos != file->f_pos) { printk(KERN_ERR "%s: f_pos!=ppos\n", __FUNCTION__); return -ESPIPE; } /* Refresh the watchdog */ if (len) { omap_wdt_ping(); return 1; } return 0;}/* omap_wdt_ioctl(): Driver ioctl function */static intomap_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int new_margin,min_margin,max_margin; int ret = -ENOIOCTLCMD; static struct watchdog_info ident = { .identity = WATCHDOG_NAME, .options = OPTIONS, .firmware_version = 0, }; switch (cmd) { case WDIOC_GETSUPPORT: ret = copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)); break; case WDIOC_GETSTATUS: ret = put_user(0, (int *)arg); break; case WDIOC_GETBOOTSTATUS: ret = put_user(omap_wdt_boot_status(), (int *)arg); break; case WDIOC_KEEPALIVE: omap_wdt_ping(); ret = 0; break; case WDIOC_SETTIMEOUT: if (get_user(new_margin, (int *)arg)) { printk(KERN_ERR "%s: WDIOC_SETTIMEOUT: Unable to read user space\n", __FUNCTION__); return -EFAULT; } omap_wdt_get_time_margin(&min_margin, &max_margin); if ((new_margin < min_margin) || (new_margin > max_margin)) { /* default timeoout */ timer_margin = max_margin; } else { timer_margin = new_margin; } omap_wdt_disable(); omap_wldr_write(timer_margin); omap_wdt_enable(); omap_wdt_ping(); /* Fall through */ case WDIOC_GETTIMEOUT: ret = put_user(timer_margin, (int *)arg); break; default: break; } return ret;}/* omap_wdt_init: Driver init function */static int __init omap_wdt_init(void){ int ret; ret = misc_register(&omap_wdt_miscdev); if (ret) { printk(KERN_ERR WATCHDOG_NAME ": Failed to register with Misc (%d)\n", ret); return ret; } omap_wdt_start(timer_margin); printk(KERN_INFO "%s: TI OMAP Watchdog Timer: timer margin %d sec\n", omap_wdt_miscdev.name, timer_margin); return 0;}/* omap_wdt_exit: Driver init function */static void __exit omap_wdt_exit(void){ misc_deregister(&omap_wdt_miscdev);}module_init(omap_wdt_init);module_exit(omap_wdt_exit);MODULE_AUTHOR("George G. Davis");MODULE_LICENSE("GPL");module_param(timer_margin, int, 0);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?