⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omap-rtc.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 2 页
字号:
		return put_user (epoch, (unsigned long *)arg);	}	case RTC_EPOCH_SET:	/* Set the epoch.	*/	{		/* 		 * There were no RTC clocks before 1900.		 */		if (arg < 1900)			return -EINVAL;		if (!capable(CAP_SYS_TIME))			return -EACCES;		epoch = arg;		return 0;	}	default:#if	!defined(CONFIG_ARCH_OMAP)		return -ENOTTY;#else		return -EINVAL;#endif	}	return copy_to_user((void *)arg, &wtime, sizeof wtime) ? -EFAULT : 0;}/* *	We enforce only one user at a time here with the open/close. *	Also clear the previous interrupt data on an open, and clean *	up things on a close. *//* We use rtc_lock to protect against concurrent opens. So the BKL is not * needed here. Or anywhere else in this driver. */static int rtc_open(struct inode *inode, struct file *file){	spin_lock_irq (&rtc_lock);	if(rtc_status & RTC_IS_OPEN)		goto out_busy;	rtc_status |= RTC_IS_OPEN;	rtc_irq_data = 0;	spin_unlock_irq (&rtc_lock);	return 0;out_busy:	spin_unlock_irq (&rtc_lock);	return -EBUSY;}static int rtc_fasync (int fd, struct file *filp, int on){	return fasync_helper (fd, filp, on, &rtc_async_queue);}static int rtc_release(struct inode *inode, struct file *file){	unsigned char tmp;	/*	 * Turn off all interrupts once the device is no longer	 * in use, and clear the data.	 */	spin_lock_irq(&rtc_lock);	tmp = CMOS_READ(OMAP_RTC_INTERRUPTS_REG);	tmp &=  ~OMAP_RTC_INTERRUPTS_IT_ALARM;	tmp &=  ~OMAP_RTC_INTERRUPTS_IT_TIMER;	CMOS_WRITE(tmp, OMAP_RTC_INTERRUPTS_REG);	spin_unlock_irq(&rtc_lock);	if (file->f_flags & FASYNC) {		rtc_fasync (-1, file, 0);	}	spin_lock_irq (&rtc_lock);	rtc_irq_data = 0;	spin_unlock_irq (&rtc_lock);	/* No need for locking -- nobody else can do anything until this rmw	 * is committed, and we don't implement timer support in omap-rtc.	 */	rtc_status &= ~RTC_IS_OPEN;	return 0;}/* Called without the kernel lock - fine */static unsigned int rtc_poll(struct file *file, poll_table *wait){	unsigned long l;	poll_wait(file, &rtc_wait, wait);	spin_lock_irq (&rtc_lock);	l = rtc_irq_data;	spin_unlock_irq (&rtc_lock);	if (l != 0)		return POLLIN | POLLRDNORM;	return 0;}/* *	The various file operations we support. */static struct file_operations rtc_fops = {	owner:		THIS_MODULE,	llseek:		no_llseek,	read:		rtc_read,	poll:		rtc_poll,	ioctl:		rtc_ioctl,	open:		rtc_open,	release:	rtc_release,	fasync:		rtc_fasync,};static struct miscdevice rtc_dev={	RTC_MINOR,	"omap-rtc",	&rtc_fops};static int __init rtc_init(void){	if (!request_region(OMAP_RTC_VIRT_BASE, OMAP_RTC_SIZE,			    rtc_dev.name)) {		printk(KERN_ERR "%s: RTC I/O port %d is not free.\n",		       rtc_dev.name, OMAP_RTC_VIRT_BASE);		return -EIO;	}	if (CMOS_READ(OMAP_RTC_STATUS_REG) & OMAP_RTC_STATUS_POWER_UP) {		printk(KERN_WARNING "%s: RTC power up reset detected.\n",		       rtc_dev.name);		/* Clear OMAP_RTC_STATUS_POWER_UP */		CMOS_WRITE(OMAP_RTC_STATUS_POWER_UP, OMAP_RTC_STATUS_REG);	}	if (CMOS_READ(OMAP_RTC_STATUS_REG) & OMAP_RTC_STATUS_ALARM) {		printk(KERN_WARNING "%s: Clearing RTC ALARM interrupt.\n",		       rtc_dev.name);		/* Clear OMAP_RTC_STATUS_ALARM */		CMOS_WRITE(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);	}	if (!(CMOS_READ(OMAP_RTC_CTRL_REG) & OMAP_RTC_CTRL_STOP)) {		printk(KERN_INFO "%s: Enabling RTC.\n", rtc_dev.name);		CMOS_WRITE(OMAP_RTC_CTRL_STOP, OMAP_RTC_CTRL_REG);	}	if (request_irq(INT_RTC_TIMER, rtc_interrupt, SA_INTERRUPT,			rtc_dev.name, NULL)) {		printk(KERN_ERR "%s: RTC timer interrupt IRQ%d is not free.\n",		       rtc_dev.name, INT_RTC_TIMER);		release_region(OMAP_RTC_VIRT_BASE, OMAP_RTC_SIZE);		return -EIO;	}	if (request_irq(INT_RTC_ALARM, rtc_interrupt, SA_INTERRUPT,	                "omap-rtc alarm", NULL)) {		printk(KERN_ERR "%s: RTC alarm interrupt IRQ%d is not free.\n",		       rtc_dev.name, INT_RTC_ALARM);		release_region(OMAP_RTC_VIRT_BASE, OMAP_RTC_SIZE);		return -EIO;	}	misc_register(&rtc_dev);	create_proc_read_entry ("driver/rtc", 0, 0, rtc_read_proc, NULL);	printk(KERN_INFO "Real Time Clock Driver v" RTC_VERSION "\n");	return 0;}static void __exit rtc_exit (void){	free_irq (INT_RTC_TIMER, NULL);	free_irq (INT_RTC_ALARM, NULL);	remove_proc_entry ("driver/rtc", NULL);	misc_deregister(&rtc_dev);	release_region (OMAP_RTC_VIRT_BASE, OMAP_RTC_SIZE);}/* *	Info exported via "/proc/driver/rtc". */static int rtc_proc_output (char *buf){#define YN(value) ((value) ? "yes" : "no")#define NY(value) ((value) ? "no" : "yes")	char *p;	struct rtc_time tm;	p = buf;	get_rtc_time(&tm);	/*	 * There is no way to tell if the luser has the RTC set for local	 * time or for Universal Standard Time (GMT). Probably local though.	 */	p += sprintf(p,		     "rtc_time\t: %02d:%02d:%02d\n"		     "rtc_date\t: %04d-%02d-%02d\n"	 	     "rtc_epoch\t: %04lu\n",		     tm.tm_hour, tm.tm_min, tm.tm_sec,		     tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, epoch);	get_rtc_alm_time(&tm);	/*	 * We implicitly assume 24hr mode here. Alarm values >= 0xc0 will	 * match any value for that particular field. Values that are	 * greater than a valid time, but less than 0xc0 shouldn't appear.	 */	p += sprintf(p,		     "alarm_time\t: %02d:%02d:%02d\n"		     "alarm_date\t: %04d-%02d-%02d\n",		     tm.tm_hour, tm.tm_min, tm.tm_sec,		     tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);	p += sprintf(p,		     "BCD\t\t: %s\n"		     "24hr\t\t: %s\n"		     "alarm_IRQ\t: %s\n"		     "update_IRQ\t: %s\n"		     "update_rate\t: %ud\n",		     YN(1),		     YN(1),		     YN(CMOS_READ(OMAP_RTC_INTERRUPTS_REG) &			OMAP_RTC_INTERRUPTS_IT_ALARM),		     YN(CMOS_READ(OMAP_RTC_INTERRUPTS_REG) &			OMAP_RTC_INTERRUPTS_IT_TIMER),		     CMOS_READ(OMAP_RTC_INTERRUPTS_REG) & 3 /* REVISIT */);	return  p - buf;#undef YN#undef NY}static int rtc_read_proc(char *page, char **start, off_t off,                         int count, int *eof, void *data){        int len = rtc_proc_output (page);        if (len <= off+count) *eof = 1;        *start = page + off;        len -= off;        if (len>count) len = count;        if (len<0) len = 0;        return len;}/* * Returns true if a clock update is in progress *//* FIXME shouldn't this be above rtc_init to make it fully inlined? */static inline unsigned char rtc_is_updating(void){	unsigned char uip;	spin_lock_irq(&rtc_lock);	uip = (CMOS_READ(OMAP_RTC_STATUS_REG) & OMAP_RTC_STATUS_BUSY);	spin_unlock_irq(&rtc_lock);	return uip;}static void get_rtc_time(struct rtc_time *rtc_tm){	unsigned char ctrl;	/* REVISIT: Fix this comment!!!	 * read RTC once any update in progress is done. The update	 * can take just over 2ms. We wait 10 to 20ms. There is no need to	 * to poll-wait (up to 1s - eeccch) for the falling edge of OMAP_RTC_STATUS_BUSY.	 * If you need to know *exactly* when a second has started, enable	 * periodic update complete interrupts, (via ioctl) and then 	 * immediately read /dev/rtc which will block until you get the IRQ.	 * Once the read clears, read the RTC time (again via ioctl). Easy.	 */#if	0 /* REVISIT: This need to do as the TRM says. */	unsigned long uip_watchdog = jiffies;	if (rtc_is_updating() != 0)		while (jiffies - uip_watchdog < 2*HZ/100) {			barrier();			cpu_relax();		}#endif	/*	 * Only the values that we read from the RTC are set. We leave	 * tm_wday, tm_yday and tm_isdst untouched. Even though the	 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated	 * by the RTC when initially set to a non-zero value.	 */	spin_lock_irq(&rtc_lock);	rtc_tm->tm_sec = CMOS_READ(OMAP_RTC_SECONDS_REG);	rtc_tm->tm_min = CMOS_READ(OMAP_RTC_MINUTES_REG);	rtc_tm->tm_hour = CMOS_READ(OMAP_RTC_HOURS_REG);	rtc_tm->tm_mday = CMOS_READ(OMAP_RTC_DAYS_REG);	rtc_tm->tm_mon = CMOS_READ(OMAP_RTC_MONTHS_REG);	rtc_tm->tm_year = CMOS_READ(OMAP_RTC_YEARS_REG);	ctrl = CMOS_READ(OMAP_RTC_CTRL_REG);	spin_unlock_irq(&rtc_lock);	BCD_TO_BIN(rtc_tm->tm_sec);	BCD_TO_BIN(rtc_tm->tm_min);	BCD_TO_BIN(rtc_tm->tm_hour);	BCD_TO_BIN(rtc_tm->tm_mday);	BCD_TO_BIN(rtc_tm->tm_mon);	BCD_TO_BIN(rtc_tm->tm_year);	/*	 * Account for differences between how the RTC uses the values	 * and how they are defined in a struct rtc_time;	 */	if ((rtc_tm->tm_year += (epoch - 1900)) <= 69)		rtc_tm->tm_year += 100;	rtc_tm->tm_mon--;}static void get_rtc_alm_time(struct rtc_time *alm_tm){	unsigned char ctrl;	spin_lock_irq(&rtc_lock);	alm_tm->tm_sec = CMOS_READ(OMAP_RTC_ALARM_SECONDS_REG);	alm_tm->tm_min = CMOS_READ(OMAP_RTC_ALARM_MINUTES_REG);	alm_tm->tm_hour = CMOS_READ(OMAP_RTC_ALARM_HOURS_REG);	alm_tm->tm_mday = CMOS_READ(OMAP_RTC_ALARM_DAYS_REG);	alm_tm->tm_mon = CMOS_READ(OMAP_RTC_ALARM_MONTHS_REG);	alm_tm->tm_year = CMOS_READ(OMAP_RTC_ALARM_YEARS_REG);	ctrl = CMOS_READ(OMAP_RTC_CTRL_REG);	spin_unlock_irq(&rtc_lock);	BCD_TO_BIN(alm_tm->tm_sec);	BCD_TO_BIN(alm_tm->tm_min);	BCD_TO_BIN(alm_tm->tm_hour);	BCD_TO_BIN(alm_tm->tm_mday);	BCD_TO_BIN(alm_tm->tm_mon);	BCD_TO_BIN(alm_tm->tm_year);	/*	 * Account for differences between how the RTC uses the values	 * and how they are defined in a struct rtc_time;	 */	if ((alm_tm->tm_year += (epoch - 1900)) <= 69)		alm_tm->tm_year += 100;	alm_tm->tm_mon--;}/* * Used to disable/enable UIE and AIE interrupts. */static void mask_rtc_irq_bit(unsigned char bit){	unsigned char val;	spin_lock_irq(&rtc_lock);	val = CMOS_READ(OMAP_RTC_INTERRUPTS_REG);	val &=  ~bit;	CMOS_WRITE(val, OMAP_RTC_INTERRUPTS_REG);	rtc_irq_data = 0;	spin_unlock_irq(&rtc_lock);}static void set_rtc_irq_bit(unsigned char bit){	unsigned char val;	spin_lock_irq(&rtc_lock);	val = CMOS_READ(OMAP_RTC_INTERRUPTS_REG);	val |= bit;	CMOS_WRITE(val, OMAP_RTC_INTERRUPTS_REG);	rtc_irq_data = 0;	spin_unlock_irq(&rtc_lock);}MODULE_AUTHOR("George G. Davis");MODULE_LICENSE("GPL");module_init(rtc_init);module_exit(rtc_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -