?? at91_watchdog.c
字號:
/* * Timer Counter interface for Linux on Atmel AT91RM9200 * * Copyright (c) 2002 Rick Bronson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *Watchdog driver. This enables you to open a Watchdog and change thetime for the watchdog to expire. */#include <linux/module.h>#include <linux/fs.h>#include <linux/miscdevice.h>#include <linux/string.h>#include <linux/init.h>#include <linux/poll.h>#include <linux/proc_fs.h>#include <asm/bitops.h>#include <asm/hardware.h>#include <asm/irq.h>#include <asm/arch/watchdog.h> /* get ioctl stuff for watchdog */extern struct watchdog_private watchdog_priv; /* watchdog private stuff */#define DRIVER_VERSION "1.00"static int at91_watchdog_open(struct inode *inode, struct file *file){ file->private_data = &watchdog_priv; spin_lock_init(&priv->lock1); MOD_INC_USE_COUNT; return 0;}static int at91_watchdog_release(struct inode *inode, struct file *file){ MOD_DEC_USE_COUNT; return 0;}ssize_t at91_watchdog_write(struct file * file, const char *buf, size_t count, loff_t * ppos) {#if 0 /* not sure if they want to use it this way */ AT91PS_ST pSt; /* pointer to the ST peripheral */ struct at91_watchdog_ioctl_set watchdog_set; if (verify_area(VERIFY_READ, buf, count)) return -EFAULT; if (__get_user(watchdog_set, buf)) return -EFAULT; pSt = AT91C_BASE_ST; pSt->ST_WDMR = watchdog_set.watchdog_wdmr | AT91C_ST_RSTEN; /* (ST) Reset Enable */ pSt->ST_CR = AT91C_ST_WDRST; /* (ST) Watchdog Timer Restart */#endif return count; }/* * Handle commands from user-space */static int at91_watchdog_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { AT91PS_ST pSt; /* pointer to the ST peripheral */ unsigned long flags; struct watchdog_private *priv = (struct watchdog_private *)file->private_data; struct at91_watchdog_ioctl_set watchdog_set; struct at91_watchdog_ioctl_timer watchdog_timer; long long all_64bits; /* upper 44 bits to make 64 bit timer */ AT91_REG crtr, crtr_save; /* saved value from AT91C_ST_CRTR (20 bits) */ int ret = 0; pSt = AT91C_BASE_ST; switch (cmd) { case AT91_WATCHDOG_SET_WATCHDOG: /* set and enable the watchdog */ if (copy_from_user (&watchdog_set, (void *)arg, sizeof (watchdog_set))) return -EFAULT; pSt->ST_WDMR = watchdog_set.watchdog_wdmr | AT91C_ST_RSTEN; /* (ST) Reset Enable */ pSt->ST_CR = AT91C_ST_WDRST; /* (ST) Watchdog Timer Restart */ break; case AT91_WATCHDOG_GET_32768_TIMER: /* get the timer */ spin_lock_irqsave(&priv->lock1, flags); /* stop int's while we read values that could be changed in the interrupt */ crtr = pSt->ST_CRTR; /* 20 ls bits of 32768 Hz clock */ crtr_save = priv->crtr_save; all_64bits = priv->upper_44bits; /* get temp copy */ spin_unlock_irqrestore(&priv->lock1, flags); if (crtr < crtr_save) /* if wrapped, add one to upper bits */ all_64bits += AT91C_ST_CRTV + 1; all_64bits |= crtr; ret = copy_to_user ((void *)arg, &all_64bits, sizeof (watchdog_timer)) ? -EFAULT : 0; break; default: ret = -EINVAL; break; } return ret; }static struct file_operations at91_watchdog_fops = { owner:THIS_MODULE, write:at91_watchdog_write, ioctl:at91_watchdog_ioctl, open:at91_watchdog_open, release:at91_watchdog_release,};static struct miscdevice watchdog_miscdev ={ WATCHDOG_MINOR, "at91 watchdog", &at91_watchdog_fops};#/* * Initialize and install WATCHDOG driver */static int __init at91_watchdog_init(void) { int res; res = misc_register (&watchdog_miscdev); if (res < 0) { printk(KERN_ERR "at91_watchdog: couldn't get a major number.\n"); return res; } printk(KERN_INFO "AT91 Watchdog driver v" DRIVER_VERSION "\n"); return 0; }module_init(at91_watchdog_init);MODULE_AUTHOR("Rick Bronson");MODULE_DESCRIPTION("AT91 Timer Counter Driver (AT91_WATCHDOG)");EXPORT_NO_SYMBOLS;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -