timex.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* timex.h: MN2WS0038 architecture timer specifications
  2. *
  3. * Copyright (C) 2002, 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 License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_UNIT_TIMEX_H
  12. #define _ASM_UNIT_TIMEX_H
  13. #include <asm/timer-regs.h>
  14. #include <unit/clock.h>
  15. #include <asm/param.h>
  16. /*
  17. * jiffies counter specifications
  18. */
  19. #define TMJCBR_MAX 0xffffff /* 24bit */
  20. #define TMJCIRQ TMTIRQ
  21. #ifndef __ASSEMBLY__
  22. #define MN10300_SRC_IOBCLK MN10300_IOBCLK
  23. #ifndef HZ
  24. # error HZ undeclared.
  25. #endif /* !HZ */
  26. #define MN10300_JCCLK (MN10300_SRC_IOBCLK)
  27. #define MN10300_TSCCLK (MN10300_SRC_IOBCLK)
  28. #define MN10300_JC_PER_HZ ((MN10300_JCCLK + HZ / 2) / HZ)
  29. #define MN10300_TSC_PER_HZ ((MN10300_TSCCLK + HZ / 2) / HZ)
  30. /* Check bit width of MTM interval value that sets base register */
  31. #if (MN10300_JC_PER_HZ - 1) > TMJCBR_MAX
  32. # error MTM tick timer interval value is overflow.
  33. #endif
  34. static inline void stop_jiffies_counter(void)
  35. {
  36. u16 tmp;
  37. TMTMD = 0;
  38. tmp = TMTMD;
  39. }
  40. static inline void reload_jiffies_counter(u32 cnt)
  41. {
  42. u32 tmp;
  43. TMTBR = cnt;
  44. tmp = TMTBR;
  45. TMTMD = TMTMD_TMTLDE;
  46. TMTMD = TMTMD_TMTCNE;
  47. tmp = TMTMD;
  48. }
  49. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_CLOCKEVENTS) && \
  50. !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
  51. /*
  52. * If we aren't using broadcasting, each core needs its own event timer.
  53. * Since CPU0 uses the tick timer which is 24-bits, we use timer 4 & 5
  54. * cascaded to 32-bits for CPU1 (but only really use 24-bits to match
  55. * CPU0).
  56. */
  57. #define TMJC1IRQ TM5IRQ
  58. static inline void stop_jiffies_counter1(void)
  59. {
  60. u8 tmp;
  61. TM4MD = 0;
  62. TM5MD = 0;
  63. tmp = TM4MD;
  64. tmp = TM5MD;
  65. }
  66. static inline void reload_jiffies_counter1(u32 cnt)
  67. {
  68. u32 tmp;
  69. TM45BR = cnt;
  70. tmp = TM45BR;
  71. TM4MD = TM4MD_INIT_COUNTER;
  72. tmp = TM4MD;
  73. TM5MD = TM5MD_SRC_TM4CASCADE | TM5MD_INIT_COUNTER;
  74. TM5MD = TM5MD_SRC_TM4CASCADE | TM5MD_COUNT_ENABLE;
  75. tmp = TM5MD;
  76. TM4MD = TM4MD_COUNT_ENABLE;
  77. tmp = TM4MD;
  78. }
  79. #endif /* CONFIG_SMP&GENERIC_CLOCKEVENTS&!GENERIC_CLOCKEVENTS_BROADCAST */
  80. #endif /* !__ASSEMBLY__ */
  81. /*
  82. * timestamp counter specifications
  83. */
  84. #define TMTSCBR_MAX 0xffffffff
  85. #ifndef __ASSEMBLY__
  86. /* Use 32-bit timestamp counter */
  87. #define TMTSCMD TMSMD
  88. #define TMTSCBR TMSBR
  89. #define TMTSCBC TMSBC
  90. #define TMTSCICR TMSICR
  91. static inline void startup_timestamp_counter(void)
  92. {
  93. u32 sync;
  94. /* set up TMS(Timestamp) 32bit timer register to count real time
  95. * - count down from 4Gig-1 to 0 and wrap at IOBCLK rate
  96. */
  97. TMTSCBR = TMTSCBR_MAX;
  98. sync = TMTSCBR;
  99. TMTSCICR = 0;
  100. sync = TMTSCICR;
  101. TMTSCMD = TMTMD_TMTLDE;
  102. TMTSCMD = TMTMD_TMTCNE;
  103. sync = TMTSCMD;
  104. }
  105. static inline void shutdown_timestamp_counter(void)
  106. {
  107. TMTSCMD = 0;
  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 */