timex.h 2.2 KB

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