xref: /openbmc/linux/arch/xtensa/include/asm/timex.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1367b8112SChris Zankel /*
2367b8112SChris Zankel  * This file is subject to the terms and conditions of the GNU General Public
3367b8112SChris Zankel  * License.  See the file "COPYING" in the main directory of this archive
4367b8112SChris Zankel  * for more details.
5367b8112SChris Zankel  *
6f615136cSMax Filippov  * Copyright (C) 2001 - 2013 Tensilica Inc.
7367b8112SChris Zankel  */
8367b8112SChris Zankel 
9367b8112SChris Zankel #ifndef _XTENSA_TIMEX_H
10367b8112SChris Zankel #define _XTENSA_TIMEX_H
11367b8112SChris Zankel 
12367b8112SChris Zankel #include <asm/processor.h>
13367b8112SChris Zankel 
140f7f9310SMax Filippov #if XCHAL_NUM_TIMERS > 0 && \
157d202219SMax Filippov 	XTENSA_INT_LEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
16367b8112SChris Zankel # define LINUX_TIMER     0
17367b8112SChris Zankel # define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
180f7f9310SMax Filippov #elif XCHAL_NUM_TIMERS > 1 && \
197d202219SMax Filippov 	XTENSA_INT_LEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
20367b8112SChris Zankel # define LINUX_TIMER     1
21367b8112SChris Zankel # define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
220f7f9310SMax Filippov #elif XCHAL_NUM_TIMERS > 2 && \
237d202219SMax Filippov 	XTENSA_INT_LEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
24367b8112SChris Zankel # define LINUX_TIMER     2
25367b8112SChris Zankel # define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
26367b8112SChris Zankel #else
27367b8112SChris Zankel # error "Bad timer number for Linux configurations!"
28367b8112SChris Zankel #endif
29367b8112SChris Zankel 
30e504c4b6SBaruch Siach extern unsigned long ccount_freq;
31367b8112SChris Zankel 
32f615136cSMax Filippov void local_timer_setup(unsigned cpu);
33367b8112SChris Zankel 
34367b8112SChris Zankel /*
35367b8112SChris Zankel  * Register access.
36367b8112SChris Zankel  */
37367b8112SChris Zankel 
get_ccount(void)38367b8112SChris Zankel static inline unsigned long get_ccount (void)
39367b8112SChris Zankel {
40cad6fadeSMax Filippov 	return xtensa_get_sr(ccount);
41367b8112SChris Zankel }
42367b8112SChris Zankel 
set_ccount(unsigned long ccount)43367b8112SChris Zankel static inline void set_ccount (unsigned long ccount)
44367b8112SChris Zankel {
45cad6fadeSMax Filippov 	xtensa_set_sr(ccount, ccount);
46367b8112SChris Zankel }
47367b8112SChris Zankel 
get_linux_timer(void)48367b8112SChris Zankel static inline unsigned long get_linux_timer (void)
49367b8112SChris Zankel {
50cad6fadeSMax Filippov 	return xtensa_get_sr(SREG_CCOMPARE + LINUX_TIMER);
51367b8112SChris Zankel }
52367b8112SChris Zankel 
set_linux_timer(unsigned long ccompare)53367b8112SChris Zankel static inline void set_linux_timer (unsigned long ccompare)
54367b8112SChris Zankel {
55cad6fadeSMax Filippov 	xtensa_set_sr(ccompare, SREG_CCOMPARE + LINUX_TIMER);
56367b8112SChris Zankel }
57367b8112SChris Zankel 
58*e10e2f58SJason A. Donenfeld #include <asm-generic/timex.h>
59*e10e2f58SJason A. Donenfeld 
60367b8112SChris Zankel #endif	/* _XTENSA_TIMEX_H */
61