2 * Common time prototypes and such for all ppc machines.
4 * Written by Cort Dougan (cort@fsmlabs.com) to merge
5 * Paul Mackerras' version and mine for PReP and Pmac.
10 #define __ASM_TIME_H__
12 #include <linux/config.h>
13 #include <linux/mc146818rtc.h>
14 #include <linux/threads.h>
15 #include <linux/compiler.h>
17 #include <asm/processor.h>
20 extern unsigned tb_ticks_per_jiffy;
21 extern unsigned tb_to_us;
22 extern unsigned tb_last_stamp;
23 extern unsigned long disarm_decr[NR_CPUS];
25 extern void to_tm(int tim, struct rtc_time * tm);
26 extern time_t last_rtc_update;
28 extern void set_dec_cpu6(unsigned int val);
30 int via_calibrate_decr(void);
32 /* Accessor functions for the decrementer register.
33 * The 40x doesn't even have a decrementer. I tried to use the
34 * generic timer interrupt code, which seems OK, with the 40x PIT
35 * in auto-reload mode. The problem is PIT stops counting when it
36 * hits zero. If it would wrap, we could use it just like a decrementer.
38 static __inline__ unsigned int get_dec(void)
40 #if defined(CONFIG_40x)
41 return (mfspr(SPRN_PIT));
43 return (mfspr(SPRN_DEC));
47 static __inline__ void set_dec(unsigned int val)
49 #if defined(CONFIG_40x)
50 return; /* Have to let it auto-reload */
51 #elif defined(CONFIG_8xx_CPU6)
58 /* Accessor functions for the timebase (RTC on 601) registers. */
59 /* If one day CONFIG_POWER is added just define __USE_RTC as 1 */
61 extern __inline__ int __attribute_const__ __USE_RTC(void) {
62 return (mfspr(SPRN_PVR)>>16) == 1;
68 extern __inline__ unsigned long get_tbl(void) {
70 asm volatile("mftb %0" : "=r" (tbl));
74 extern __inline__ unsigned long get_tbu(void) {
76 asm volatile("mftbu %0" : "=r" (tbl));
80 extern __inline__ void set_tb(unsigned int upper, unsigned int lower)
83 mtspr(SPRN_TBWU, upper);
84 mtspr(SPRN_TBWL, lower);
87 extern __inline__ unsigned long get_rtcl(void) {
89 asm volatile("mfrtcl %0" : "=r" (rtcl));
93 extern __inline__ unsigned get_native_tbl(void) {
100 /* On machines with RTC, this function can only be used safely
101 * after the timestamp and for 1 second. It is only used by gettimeofday
102 * however so it should not matter.
104 extern __inline__ unsigned tb_ticks_since(unsigned tstamp) {
106 int delta = get_rtcl() - tstamp;
107 return delta<0 ? delta + 1000000000 : delta;
109 return get_tbl() - tstamp;
114 extern __inline__ unsigned long get_bin_rtcl(void) {
115 unsigned long rtcl, rtcu1, rtcu2;
122 : "=r" (rtcu1), "=r" (rtcl), "=r" (rtcu2)
124 return rtcu2*1000000000+rtcl;
127 extern __inline__ unsigned binary_tbl(void) {
129 return get_bin_rtcl();
135 /* Use mulhwu to scale processor timebase to timeval */
136 #define mulhwu(x,y) \
137 ({unsigned z; asm ("mulhwu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;})
139 unsigned mulhwu_scale_factor(unsigned, unsigned);
140 #endif /* __ASM_TIME_H__ */
141 #endif /* __KERNEL__ */