blob: ca929e6a38b5f70a5e1e2d1492b1cdde5e5f0e2a [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
Chris Zankel9a8fd552005-06-23 22:01:26 -07002 * 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 *
Max Filippovf6151362013-10-17 02:42:26 +04006 * Copyright (C) 2001 - 2013 Tensilica Inc.
Chris Zankel9a8fd552005-06-23 22:01:26 -07007 */
8
9#ifndef _XTENSA_TIMEX_H
10#define _XTENSA_TIMEX_H
11
Chris Zankel9a8fd552005-06-23 22:01:26 -070012#include <asm/processor.h>
13#include <linux/stringify.h>
14
Chris Zankel173d66812006-12-10 02:18:48 -080015#define _INTLEVEL(x) XCHAL_INT ## x ## _LEVEL
16#define INTLEVEL(x) _INTLEVEL(x)
17
Max Filippov0f7f9312013-03-10 12:07:14 +040018#if XCHAL_NUM_TIMERS > 0 && \
19 INTLEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
Chris Zankel9a8fd552005-06-23 22:01:26 -070020# define LINUX_TIMER 0
Chris Zankel173d66812006-12-10 02:18:48 -080021# define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
Max Filippov0f7f9312013-03-10 12:07:14 +040022#elif XCHAL_NUM_TIMERS > 1 && \
23 INTLEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
Chris Zankel9a8fd552005-06-23 22:01:26 -070024# define LINUX_TIMER 1
Chris Zankel173d66812006-12-10 02:18:48 -080025# define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
Max Filippov0f7f9312013-03-10 12:07:14 +040026#elif XCHAL_NUM_TIMERS > 2 && \
27 INTLEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
Chris Zankel9a8fd552005-06-23 22:01:26 -070028# define LINUX_TIMER 2
Chris Zankel173d66812006-12-10 02:18:48 -080029# define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
Chris Zankel9a8fd552005-06-23 22:01:26 -070030#else
31# error "Bad timer number for Linux configurations!"
32#endif
33
Baruch Siache504c4b2013-06-17 11:29:43 +030034extern unsigned long ccount_freq;
Chris Zankel9a8fd552005-06-23 22:01:26 -070035
36typedef unsigned long long cycles_t;
37
Chris Zankel9a8fd552005-06-23 22:01:26 -070038#define get_cycles() (0)
39
Max Filippovf6151362013-10-17 02:42:26 +040040void local_timer_setup(unsigned cpu);
Chris Zankel9a8fd552005-06-23 22:01:26 -070041
42/*
43 * Register access.
44 */
45
Max Filippovbc5378f2012-10-15 03:55:38 +040046#define WSR_CCOUNT(r) asm volatile ("wsr %0, ccount" :: "a" (r))
47#define RSR_CCOUNT(r) asm volatile ("rsr %0, ccount" : "=a" (r))
48#define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
49#define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
Chris Zankel9a8fd552005-06-23 22:01:26 -070050
51static inline unsigned long get_ccount (void)
52{
53 unsigned long ccount;
54 RSR_CCOUNT(ccount);
55 return ccount;
56}
57
58static inline void set_ccount (unsigned long ccount)
59{
60 WSR_CCOUNT(ccount);
61}
62
63static inline unsigned long get_linux_timer (void)
64{
65 unsigned ccompare;
66 RSR_CCOMPARE(LINUX_TIMER, ccompare);
67 return ccompare;
68}
69
70static inline void set_linux_timer (unsigned long ccompare)
71{
72 WSR_CCOMPARE(LINUX_TIMER, ccompare);
73}
74
Chris Zankel9a8fd552005-06-23 22:01:26 -070075#endif /* _XTENSA_TIMEX_H */