86aca77339f207636bc9f562f765b5ccd580b967
[firefly-linux-kernel-4.4.55.git] / arch / xtensa / include / asm / timex.h
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 extern unsigned long ccount_freq;
39 #define CCOUNT_PER_JIFFY (ccount_freq / HZ)
40
41 typedef unsigned long long cycles_t;
42
43 /*
44  * Only used for SMP.
45  */
46
47 extern cycles_t cacheflush_time;
48
49 #define get_cycles()    (0)
50
51
52 /*
53  * Register access.
54  */
55
56 #define WSR_CCOUNT(r)     asm volatile ("wsr %0, ccount" :: "a" (r))
57 #define RSR_CCOUNT(r)     asm volatile ("rsr %0, ccount" : "=a" (r))
58 #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
59 #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
60
61 static inline unsigned long get_ccount (void)
62 {
63         unsigned long ccount;
64         RSR_CCOUNT(ccount);
65         return ccount;
66 }
67
68 static inline void set_ccount (unsigned long ccount)
69 {
70         WSR_CCOUNT(ccount);
71 }
72
73 static inline unsigned long get_linux_timer (void)
74 {
75         unsigned ccompare;
76         RSR_CCOMPARE(LINUX_TIMER, ccompare);
77         return ccompare;
78 }
79
80 static inline void set_linux_timer (unsigned long ccompare)
81 {
82         WSR_CCOMPARE(LINUX_TIMER, ccompare);
83 }
84
85 #endif  /* __KERNEL__ */
86 #endif  /* _XTENSA_TIMEX_H */