timex.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #define FINETUNE ((((((long)LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \
  29. (1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \
  30. << (SHIFT_SCALE-SHIFT_HZ)) / HZ)
  31. #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
  32. extern unsigned long ccount_per_jiffy;
  33. extern unsigned long ccount_nsec;
  34. #define CCOUNT_PER_JIFFY ccount_per_jiffy
  35. #define CCOUNT_NSEC ccount_nsec
  36. #else
  37. #define CCOUNT_PER_JIFFY (CONFIG_XTENSA_CPU_CLOCK*(1000000UL/HZ))
  38. #define CCOUNT_NSEC (1000000000UL / CONFIG_XTENSA_CPU_CLOCK)
  39. #endif
  40. typedef unsigned long long cycles_t;
  41. /*
  42. * Only used for SMP.
  43. */
  44. extern cycles_t cacheflush_time;
  45. #define get_cycles() (0)
  46. /*
  47. * Register access.
  48. */
  49. #define WSR_CCOUNT(r) __asm__("wsr %0,"__stringify(CCOUNT) :: "a" (r))
  50. #define RSR_CCOUNT(r) __asm__("rsr %0,"__stringify(CCOUNT) : "=a" (r))
  51. #define WSR_CCOMPARE(x,r) __asm__("wsr %0,"__stringify(CCOMPARE_0)"+"__stringify(x) :: "a"(r))
  52. #define RSR_CCOMPARE(x,r) __asm__("rsr %0,"__stringify(CCOMPARE_0)"+"__stringify(x) : "=a"(r))
  53. static inline unsigned long get_ccount (void)
  54. {
  55. unsigned long ccount;
  56. RSR_CCOUNT(ccount);
  57. return ccount;
  58. }
  59. static inline void set_ccount (unsigned long ccount)
  60. {
  61. WSR_CCOUNT(ccount);
  62. }
  63. static inline unsigned long get_linux_timer (void)
  64. {
  65. unsigned ccompare;
  66. RSR_CCOMPARE(LINUX_TIMER, ccompare);
  67. return ccompare;
  68. }
  69. static inline void set_linux_timer (unsigned long ccompare)
  70. {
  71. WSR_CCOMPARE(LINUX_TIMER, ccompare);
  72. }
  73. #endif /* __KERNEL__ */
  74. #endif /* _XTENSA_TIMEX_H */