xref: /openbmc/linux/arch/xtensa/include/asm/timex.h (revision f35e839a)
1 /*
2  * include/asm-xtensa/timex.h
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 2001 - 2008 Tensilica Inc.
9  */
10 
11 #ifndef _XTENSA_TIMEX_H
12 #define _XTENSA_TIMEX_H
13 
14 #ifdef __KERNEL__
15 
16 #include <asm/processor.h>
17 #include <linux/stringify.h>
18 
19 #define _INTLEVEL(x)	XCHAL_INT ## x ## _LEVEL
20 #define INTLEVEL(x)	_INTLEVEL(x)
21 
22 #if XCHAL_NUM_TIMERS > 0 && \
23 	INTLEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
24 # define LINUX_TIMER     0
25 # define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
26 #elif XCHAL_NUM_TIMERS > 1 && \
27 	INTLEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
28 # define LINUX_TIMER     1
29 # define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
30 #elif XCHAL_NUM_TIMERS > 2 && \
31 	INTLEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
32 # define LINUX_TIMER     2
33 # define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
34 #else
35 # error "Bad timer number for Linux configurations!"
36 #endif
37 
38 #define LINUX_TIMER_MASK        (1L << LINUX_TIMER_INT)
39 
40 #define CLOCK_TICK_RATE 	1193180	/* (everyone is using this value) */
41 #define CLOCK_TICK_FACTOR       20 /* Factor of both 10^6 and CLOCK_TICK_RATE */
42 
43 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
44 extern unsigned long ccount_per_jiffy;
45 extern unsigned long nsec_per_ccount;
46 #define CCOUNT_PER_JIFFY ccount_per_jiffy
47 #define NSEC_PER_CCOUNT  nsec_per_ccount
48 #else
49 #define CCOUNT_PER_JIFFY (CONFIG_XTENSA_CPU_CLOCK*(1000000UL/HZ))
50 #define NSEC_PER_CCOUNT (1000UL / CONFIG_XTENSA_CPU_CLOCK)
51 #endif
52 
53 
54 typedef unsigned long long cycles_t;
55 
56 /*
57  * Only used for SMP.
58  */
59 
60 extern cycles_t cacheflush_time;
61 
62 #define get_cycles()	(0)
63 
64 
65 /*
66  * Register access.
67  */
68 
69 #define WSR_CCOUNT(r)	  asm volatile ("wsr %0, ccount" :: "a" (r))
70 #define RSR_CCOUNT(r)	  asm volatile ("rsr %0, ccount" : "=a" (r))
71 #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
72 #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
73 
74 static inline unsigned long get_ccount (void)
75 {
76 	unsigned long ccount;
77 	RSR_CCOUNT(ccount);
78 	return ccount;
79 }
80 
81 static inline void set_ccount (unsigned long ccount)
82 {
83 	WSR_CCOUNT(ccount);
84 }
85 
86 static inline unsigned long get_linux_timer (void)
87 {
88 	unsigned ccompare;
89 	RSR_CCOMPARE(LINUX_TIMER, ccompare);
90 	return ccompare;
91 }
92 
93 static inline void set_linux_timer (unsigned long ccompare)
94 {
95 	WSR_CCOMPARE(LINUX_TIMER, ccompare);
96 }
97 
98 #endif	/* __KERNEL__ */
99 #endif	/* _XTENSA_TIMEX_H */
100