blob: c7b705e66655746a2efce6fdeefbd76f128d0acd [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
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 - 2005 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#if XCHAL_INT_LEVEL(XCHAL_TIMER0_INTERRUPT) == 1
20# define LINUX_TIMER 0
21#elif XCHAL_INT_LEVEL(XCHAL_TIMER1_INTERRUPT) == 1
22# define LINUX_TIMER 1
23#elif XCHAL_INT_LEVEL(XCHAL_TIMER2_INTERRUPT) == 1
24# define LINUX_TIMER 2
25#else
26# error "Bad timer number for Linux configurations!"
27#endif
28
29#define LINUX_TIMER_INT XCHAL_TIMER_INTERRUPT(LINUX_TIMER)
30#define LINUX_TIMER_MASK (1L << LINUX_TIMER_INT)
31
32#define CLOCK_TICK_RATE 1193180 /* (everyone is using this value) */
33#define CLOCK_TICK_FACTOR 20 /* Factor of both 10^6 and CLOCK_TICK_RATE */
Chris Zankel9a8fd552005-06-23 22:01:26 -070034
35#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
36extern unsigned long ccount_per_jiffy;
37extern unsigned long ccount_nsec;
38#define CCOUNT_PER_JIFFY ccount_per_jiffy
39#define CCOUNT_NSEC ccount_nsec
40#else
41#define CCOUNT_PER_JIFFY (CONFIG_XTENSA_CPU_CLOCK*(1000000UL/HZ))
42#define CCOUNT_NSEC (1000000000UL / CONFIG_XTENSA_CPU_CLOCK)
43#endif
44
45
46typedef unsigned long long cycles_t;
47
48/*
49 * Only used for SMP.
50 */
51
52extern cycles_t cacheflush_time;
53
54#define get_cycles() (0)
55
56
57/*
58 * Register access.
59 */
60
61#define WSR_CCOUNT(r) __asm__("wsr %0,"__stringify(CCOUNT) :: "a" (r))
62#define RSR_CCOUNT(r) __asm__("rsr %0,"__stringify(CCOUNT) : "=a" (r))
63#define WSR_CCOMPARE(x,r) __asm__("wsr %0,"__stringify(CCOMPARE_0)"+"__stringify(x) :: "a"(r))
64#define RSR_CCOMPARE(x,r) __asm__("rsr %0,"__stringify(CCOMPARE_0)"+"__stringify(x) : "=a"(r))
65
66static inline unsigned long get_ccount (void)
67{
68 unsigned long ccount;
69 RSR_CCOUNT(ccount);
70 return ccount;
71}
72
73static inline void set_ccount (unsigned long ccount)
74{
75 WSR_CCOUNT(ccount);
76}
77
78static inline unsigned long get_linux_timer (void)
79{
80 unsigned ccompare;
81 RSR_CCOMPARE(LINUX_TIMER, ccompare);
82 return ccompare;
83}
84
85static inline void set_linux_timer (unsigned long ccompare)
86{
87 WSR_CCOMPARE(LINUX_TIMER, ccompare);
88}
89
90#endif /* __KERNEL__ */
91#endif /* _XTENSA_TIMEX_H */