| 
									
										
										
										
											2008-01-28 16:40:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  *  linux/arch/cris/kernel/time.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Copyright (C) 1991, 1992, 1995  Linus Torvalds | 
					
						
							|  |  |  |  *  Copyright (C) 1999, 2000, 2001 Axis Communications AB | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1994-07-02    Alan Modra | 
					
						
							|  |  |  |  *	fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime | 
					
						
							|  |  |  |  * 1995-03-26    Markus Kuhn | 
					
						
							|  |  |  |  *      fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887 | 
					
						
							|  |  |  |  *      precision CMOS clock update | 
					
						
							|  |  |  |  * 1996-05-03    Ingo Molnar | 
					
						
							|  |  |  |  *      fixed time warps in do_[slow|fast]_gettimeoffset() | 
					
						
							|  |  |  |  * 1997-09-10	Updated NTP code according to technical memorandum Jan '96 | 
					
						
							|  |  |  |  *		"A Kernel Model for Precision Timekeeping" by Dave Mills | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Linux/CRIS specific code: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors:    Bjorn Wesen | 
					
						
							| 
									
										
										
										
											2008-01-28 16:40:21 +01:00
										 |  |  |  *             Johan Adolfsson | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asm/rtc.h>
 | 
					
						
							|  |  |  | #include <linux/errno.h>
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/param.h>
 | 
					
						
							|  |  |  | #include <linux/jiffies.h>
 | 
					
						
							|  |  |  | #include <linux/bcd.h>
 | 
					
						
							|  |  |  | #include <linux/timex.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							| 
									
										
										
										
											2005-07-27 11:44:40 -07:00
										 |  |  | #include <linux/profile.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-30 15:03:48 -08:00
										 |  |  | #include <linux/sched.h>	/* just for sched_clock() - funny that */
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | int have_rtc;  /* used to remember if we have an RTC or not */; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define TICK_SIZE tick
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern unsigned long loops_per_jiffy; /* init/main.c */ | 
					
						
							|  |  |  | unsigned long loops_per_usec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern unsigned long do_slow_gettimeoffset(void); | 
					
						
							|  |  |  | static unsigned long (*do_gettimeoffset)(void) = do_slow_gettimeoffset; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-05 13:42:31 -08:00
										 |  |  | u32 arch_gettimeoffset(void) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-05 13:42:31 -08:00
										 |  |  | 	return do_gettimeoffset() * 1000; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * BUG: This routine does not handle hour overflow properly; it just | 
					
						
							|  |  |  |  *      sets the minutes. Usually you'll only notice that after reboot! | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int set_rtc_mmss(unsigned long nowtime) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int retval = 0; | 
					
						
							|  |  |  | 	int real_seconds, real_minutes, cmos_minutes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printk(KERN_DEBUG "set_rtc_mmss(%lu)\n", nowtime); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!have_rtc) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmos_minutes = CMOS_READ(RTC_MINUTES); | 
					
						
							| 
									
										
										
										
											2008-10-18 20:28:40 -07:00
										 |  |  | 	cmos_minutes = bcd2bin(cmos_minutes); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * since we're only adjusting minutes and seconds, | 
					
						
							|  |  |  | 	 * don't interfere with hour overflow. This avoids | 
					
						
							|  |  |  | 	 * messing with unknown time zones but requires your | 
					
						
							|  |  |  | 	 * RTC not to be off by more than 15 minutes | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	real_seconds = nowtime % 60; | 
					
						
							|  |  |  | 	real_minutes = nowtime / 60; | 
					
						
							|  |  |  | 	if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) | 
					
						
							|  |  |  | 		real_minutes += 30;		/* correct for half hour time zone */ | 
					
						
							|  |  |  | 	real_minutes %= 60; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (abs(real_minutes - cmos_minutes) < 30) { | 
					
						
							| 
									
										
										
										
											2008-10-18 20:28:40 -07:00
										 |  |  | 		real_seconds = bin2bcd(real_seconds); | 
					
						
							|  |  |  | 		real_minutes = bin2bcd(real_minutes); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		CMOS_WRITE(real_seconds,RTC_SECONDS); | 
					
						
							|  |  |  | 		CMOS_WRITE(real_minutes,RTC_MINUTES); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		printk(KERN_WARNING | 
					
						
							|  |  |  | 		       "set_rtc_mmss: can't update from %d to %d\n", | 
					
						
							|  |  |  | 		       cmos_minutes, real_minutes); | 
					
						
							|  |  |  | 		retval = -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return retval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* grab the time from the RTC chip */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unsigned long | 
					
						
							|  |  |  | get_cmos_time(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int year, mon, day, hour, min, sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sec = CMOS_READ(RTC_SECONDS); | 
					
						
							|  |  |  | 	min = CMOS_READ(RTC_MINUTES); | 
					
						
							|  |  |  | 	hour = CMOS_READ(RTC_HOURS); | 
					
						
							|  |  |  | 	day = CMOS_READ(RTC_DAY_OF_MONTH); | 
					
						
							|  |  |  | 	mon = CMOS_READ(RTC_MONTH); | 
					
						
							|  |  |  | 	year = CMOS_READ(RTC_YEAR); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-18 20:28:40 -07:00
										 |  |  | 	sec = bcd2bin(sec); | 
					
						
							|  |  |  | 	min = bcd2bin(min); | 
					
						
							|  |  |  | 	hour = bcd2bin(hour); | 
					
						
							|  |  |  | 	day = bcd2bin(day); | 
					
						
							|  |  |  | 	mon = bcd2bin(mon); | 
					
						
							|  |  |  | 	year = bcd2bin(year); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((year += 1900) < 1970) | 
					
						
							|  |  |  | 		year += 100; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return mktime(year, mon, day, hour, min, sec); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* update xtime from the CMOS settings. used when /dev/rtc gets a SET_TIME.
 | 
					
						
							|  |  |  |  * TODO: this doesn't reset the fancy NTP phase stuff as do_settimeofday does. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | update_xtime_from_cmos(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(have_rtc) { | 
					
						
							|  |  |  | 		xtime.tv_sec = get_cmos_time(); | 
					
						
							|  |  |  | 		xtime.tv_nsec = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-27 11:44:40 -07:00
										 |  |  | extern void cris_profile_sample(struct pt_regs* regs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | cris_do_profile(struct pt_regs* regs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-14 17:01:00 -08:00
										 |  |  | #ifdef CONFIG_SYSTEM_PROFILER
 | 
					
						
							| 
									
										
										
										
											2005-07-27 11:44:40 -07:00
										 |  |  |         cris_profile_sample(regs); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-14 17:01:00 -08:00
										 |  |  | #ifdef CONFIG_PROFILING
 | 
					
						
							| 
									
										
										
										
											2008-01-31 17:56:24 +01:00
										 |  |  | 	profile_tick(CPU_PROFILING); | 
					
						
							| 
									
										
										
										
											2005-07-27 11:44:40 -07:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-28 16:40:21 +01:00
										 |  |  | unsigned long long sched_clock(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (unsigned long long)jiffies * (1000000000 / HZ) + | 
					
						
							|  |  |  | 		get_ns_in_jiffie(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static int | 
					
						
							|  |  |  | __init init_udelay(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	loops_per_usec = (loops_per_jiffy * HZ) / 1000000; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __initcall(init_udelay); |