timex.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* ASB2303-specific timer specifications
  2. *
  3. * Copyright (C) 2007, 2010 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_UNIT_TIMEX_H
  12. #define _ASM_UNIT_TIMEX_H
  13. #ifndef __ASSEMBLY__
  14. #include <linux/irq.h>
  15. #endif /* __ASSEMBLY__ */
  16. #include <asm/timer-regs.h>
  17. #include <unit/clock.h>
  18. #include <asm/param.h>
  19. /*
  20. * jiffies counter specifications
  21. */
  22. #define TMJCBR_MAX 0xffff
  23. #define TMJCIRQ TM1IRQ
  24. #define TMJCICR TM1ICR
  25. #ifndef __ASSEMBLY__
  26. #define MN10300_SRC_IOCLK MN10300_IOCLK
  27. #ifndef HZ
  28. # error HZ undeclared.
  29. #endif /* !HZ */
  30. /* use as little prescaling as possible to avoid losing accuracy */
  31. #if (MN10300_SRC_IOCLK + HZ / 2) / HZ - 1 <= TMJCBR_MAX
  32. # define IOCLK_PRESCALE 1
  33. # define JC_TIMER_CLKSRC TM0MD_SRC_IOCLK
  34. # define TSC_TIMER_CLKSRC TM4MD_SRC_IOCLK
  35. #elif (MN10300_SRC_IOCLK / 8 + HZ / 2) / HZ - 1 <= TMJCBR_MAX
  36. # define IOCLK_PRESCALE 8
  37. # define JC_TIMER_CLKSRC TM0MD_SRC_IOCLK_8
  38. # define TSC_TIMER_CLKSRC TM4MD_SRC_IOCLK_8
  39. #elif (MN10300_SRC_IOCLK / 32 + HZ / 2) / HZ - 1 <= TMJCBR_MAX
  40. # define IOCLK_PRESCALE 32
  41. # define JC_TIMER_CLKSRC TM0MD_SRC_IOCLK_32
  42. # define TSC_TIMER_CLKSRC TM4MD_SRC_IOCLK_32
  43. #else
  44. # error You lose.
  45. #endif
  46. #define MN10300_JCCLK (MN10300_SRC_IOCLK / IOCLK_PRESCALE)
  47. #define MN10300_TSCCLK (MN10300_SRC_IOCLK / IOCLK_PRESCALE)
  48. #define MN10300_JC_PER_HZ ((MN10300_JCCLK + HZ / 2) / HZ)
  49. #define MN10300_TSC_PER_HZ ((MN10300_TSCCLK + HZ / 2) / HZ)
  50. static inline void stop_jiffies_counter(void)
  51. {
  52. u16 tmp;
  53. TM01MD = JC_TIMER_CLKSRC | TM1MD_SRC_TM0CASCADE << 8;
  54. tmp = TM01MD;
  55. }
  56. static inline void reload_jiffies_counter(u32 cnt)
  57. {
  58. u32 tmp;
  59. TM01BR = cnt;
  60. tmp = TM01BR;
  61. TM01MD = JC_TIMER_CLKSRC | \
  62. TM1MD_SRC_TM0CASCADE << 8 | \
  63. TM0MD_INIT_COUNTER | \
  64. TM1MD_INIT_COUNTER << 8;
  65. TM01MD = JC_TIMER_CLKSRC | \
  66. TM1MD_SRC_TM0CASCADE << 8 | \
  67. TM0MD_COUNT_ENABLE | \
  68. TM1MD_COUNT_ENABLE << 8;
  69. tmp = TM01MD;
  70. }
  71. #endif /* !__ASSEMBLY__ */
  72. /*
  73. * timestamp counter specifications
  74. */
  75. #define TMTSCBR_MAX 0xffffffff
  76. #define TMTSCBC TM45BC
  77. #ifndef __ASSEMBLY__
  78. static inline void startup_timestamp_counter(void)
  79. {
  80. u32 t32;
  81. /* set up timer 4 & 5 cascaded as a 32-bit counter to count real time
  82. * - count down from 4Gig-1 to 0 and wrap at IOCLK rate
  83. */
  84. TM45BR = TMTSCBR_MAX;
  85. t32 = TM45BR;
  86. TM4MD = TSC_TIMER_CLKSRC;
  87. TM4MD |= TM4MD_INIT_COUNTER;
  88. TM4MD &= ~TM4MD_INIT_COUNTER;
  89. TM4ICR = 0;
  90. t32 = TM4ICR;
  91. TM5MD = TM5MD_SRC_TM4CASCADE;
  92. TM5MD |= TM5MD_INIT_COUNTER;
  93. TM5MD &= ~TM5MD_INIT_COUNTER;
  94. TM5ICR = 0;
  95. t32 = TM5ICR;
  96. TM5MD |= TM5MD_COUNT_ENABLE;
  97. TM4MD |= TM4MD_COUNT_ENABLE;
  98. t32 = TM5MD;
  99. t32 = TM4MD;
  100. }
  101. static inline void shutdown_timestamp_counter(void)
  102. {
  103. u8 t8;
  104. TM4MD = 0;
  105. TM5MD = 0;
  106. t8 = TM4MD;
  107. t8 = TM5MD;
  108. }
  109. /*
  110. * we use a cascaded pair of 16-bit down-counting timers to count I/O
  111. * clock cycles for the purposes of time keeping
  112. */
  113. typedef unsigned long cycles_t;
  114. static inline cycles_t read_timestamp_counter(void)
  115. {
  116. return (cycles_t)~TMTSCBC;
  117. }
  118. #endif /* !__ASSEMBLY__ */
  119. #endif /* _ASM_UNIT_TIMEX_H */