xref: /openbmc/linux/arch/xtensa/include/asm/timex.h (revision ba61bb17)
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2001 - 2013 Tensilica Inc.
7  */
8 
9 #ifndef _XTENSA_TIMEX_H
10 #define _XTENSA_TIMEX_H
11 
12 #include <asm/processor.h>
13 #include <linux/stringify.h>
14 
15 #if XCHAL_NUM_TIMERS > 0 && \
16 	XTENSA_INT_LEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
17 # define LINUX_TIMER     0
18 # define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
19 #elif XCHAL_NUM_TIMERS > 1 && \
20 	XTENSA_INT_LEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
21 # define LINUX_TIMER     1
22 # define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
23 #elif XCHAL_NUM_TIMERS > 2 && \
24 	XTENSA_INT_LEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
25 # define LINUX_TIMER     2
26 # define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
27 #else
28 # error "Bad timer number for Linux configurations!"
29 #endif
30 
31 extern unsigned long ccount_freq;
32 
33 typedef unsigned long long cycles_t;
34 
35 #define get_cycles()	(0)
36 
37 void local_timer_setup(unsigned cpu);
38 
39 /*
40  * Register access.
41  */
42 
43 #define WSR_CCOUNT(r)	  asm volatile ("wsr %0, ccount" :: "a" (r))
44 #define RSR_CCOUNT(r)	  asm volatile ("rsr %0, ccount" : "=a" (r))
45 #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
46 #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
47 
48 static inline unsigned long get_ccount (void)
49 {
50 	unsigned long ccount;
51 	RSR_CCOUNT(ccount);
52 	return ccount;
53 }
54 
55 static inline void set_ccount (unsigned long ccount)
56 {
57 	WSR_CCOUNT(ccount);
58 }
59 
60 static inline unsigned long get_linux_timer (void)
61 {
62 	unsigned ccompare;
63 	RSR_CCOMPARE(LINUX_TIMER, ccompare);
64 	return ccompare;
65 }
66 
67 static inline void set_linux_timer (unsigned long ccompare)
68 {
69 	WSR_CCOMPARE(LINUX_TIMER, ccompare);
70 }
71 
72 #endif	/* _XTENSA_TIMEX_H */
73