timex.h 2.4 KB

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