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