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/types.h>
14 #include <linux/rtc.h>
15 #include <linux/threads.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 4xx doesn't even have a decrementer. I tried to use the
34 * generic timer interrupt code, which seems OK, with the 4xx 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 const __USE_RTC(void) {
62 return (mfspr(SPRN_PVR
)>>16) == 1;
68 extern __inline__
unsigned long get_tbl(void) {
70 #if defined(CONFIG_403GCX)
71 asm volatile("mfspr %0, 0x3dd" : "=r" (tbl
));
73 asm volatile("mftb %0" : "=r" (tbl
));
78 extern __inline__
unsigned long get_tbu(void) {
80 #if defined(CONFIG_403GCX)
81 asm volatile("mfspr %0, 0x3dc" : "=r" (tbl
));
83 asm volatile("mftbu %0" : "=r" (tbl
));
88 extern __inline__
void set_tb(unsigned int upper
, unsigned int lower
)
91 mtspr(SPRN_TBWU
, upper
);
92 mtspr(SPRN_TBWL
, lower
);
95 extern __inline__
unsigned long get_rtcl(void) {
97 asm volatile("mfrtcl %0" : "=r" (rtcl
));
101 extern __inline__
unsigned long get_rtcu(void)
104 asm volatile("mfrtcu %0" : "=r" (rtcu
));
108 extern __inline__
unsigned get_native_tbl(void) {
115 /* On machines with RTC, this function can only be used safely
116 * after the timestamp and for 1 second. It is only used by gettimeofday
117 * however so it should not matter.
119 extern __inline__
unsigned tb_ticks_since(unsigned tstamp
) {
121 int delta
= get_rtcl() - tstamp
;
122 return delta
<0 ? delta
+ 1000000000 : delta
;
124 return get_tbl() - tstamp
;
129 extern __inline__
unsigned long get_bin_rtcl(void) {
130 unsigned long rtcl
, rtcu1
, rtcu2
;
137 : "=r" (rtcu1
), "=r" (rtcl
), "=r" (rtcu2
)
139 return rtcu2
*1000000000+rtcl
;
142 extern __inline__
unsigned binary_tbl(void) {
144 return get_bin_rtcl();
150 /* Use mulhwu to scale processor timebase to timeval */
151 /* Specifically, this computes (x * y) / 2^32. -- paulus */
152 #define mulhwu(x,y) \
153 ({unsigned z; asm ("mulhwu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;})
155 unsigned mulhwu_scale_factor(unsigned, unsigned);
156 #endif /* __ASM_TIME_H__ */
157 #endif /* __KERNEL__ */