timex.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef _XTENSA_TIMEX_H
  11. #define _XTENSA_TIMEX_H
  12. #ifdef __KERNEL__
  13. #include <asm/processor.h>
  14. #include <linux/stringify.h>
  15. #define _INTLEVEL(x) XCHAL_INT ## x ## _LEVEL
  16. #define INTLEVEL(x) _INTLEVEL(x)
  17. #if XCHAL_NUM_TIMERS > 0 && \
  18. INTLEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
  19. # define LINUX_TIMER 0
  20. # define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
  21. #elif XCHAL_NUM_TIMERS > 1 && \
  22. INTLEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
  23. # define LINUX_TIMER 1
  24. # define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
  25. #elif XCHAL_NUM_TIMERS > 2 && \
  26. INTLEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
  27. # define LINUX_TIMER 2
  28. # define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
  29. #else
  30. # error "Bad timer number for Linux configurations!"
  31. #endif
  32. #define LINUX_TIMER_MASK (1L << LINUX_TIMER_INT)
  33. #define CLOCK_TICK_RATE 1193180 /* (everyone is using this value) */
  34. #define CLOCK_TICK_FACTOR 20 /* Factor of both 10^6 and CLOCK_TICK_RATE */
  35. #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
  36. extern unsigned long ccount_per_jiffy;
  37. extern unsigned long nsec_per_ccount;
  38. #define CCOUNT_PER_JIFFY ccount_per_jiffy
  39. #define NSEC_PER_CCOUNT nsec_per_ccount
  40. #else
  41. #define CCOUNT_PER_JIFFY (CONFIG_XTENSA_CPU_CLOCK*(1000000UL/HZ))
  42. #define NSEC_PER_CCOUNT (1000UL / CONFIG_XTENSA_CPU_CLOCK)
  43. #endif
  44. typedef unsigned long long cycles_t;
  45. /*
  46. * Only used for SMP.
  47. */
  48. extern cycles_t cacheflush_time;
  49. #define get_cycles() (0)
  50. /*
  51. * Register access.
  52. */
  53. #define WSR_CCOUNT(r) asm volatile ("wsr %0, ccount" :: "a" (r))
  54. #define RSR_CCOUNT(r) asm volatile ("rsr %0, ccount" : "=a" (r))
  55. #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
  56. #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
  57. static inline unsigned long get_ccount (void)
  58. {
  59. unsigned long ccount;
  60. RSR_CCOUNT(ccount);
  61. return ccount;
  62. }
  63. static inline void set_ccount (unsigned long ccount)
  64. {
  65. WSR_CCOUNT(ccount);
  66. }
  67. static inline unsigned long get_linux_timer (void)
  68. {
  69. unsigned ccompare;
  70. RSR_CCOMPARE(LINUX_TIMER, ccompare);
  71. return ccompare;
  72. }
  73. static inline void set_linux_timer (unsigned long ccompare)
  74. {
  75. WSR_CCOMPARE(LINUX_TIMER, ccompare);
  76. }
  77. #endif /* __KERNEL__ */
  78. #endif /* _XTENSA_TIMEX_H */