timex.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. #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 0xffffff /* 24bit */
  23. #define TMJCIRQ TMTIRQ
  24. #ifndef __ASSEMBLY__
  25. #define MN10300_SRC_IOBCLK MN10300_IOBCLK
  26. #ifndef HZ
  27. # error HZ undeclared.
  28. #endif /* !HZ */
  29. #define MN10300_JCCLK (MN10300_SRC_IOBCLK)
  30. #define MN10300_TSCCLK (MN10300_SRC_IOBCLK)
  31. #define MN10300_JC_PER_HZ ((MN10300_JCCLK + HZ / 2) / HZ)
  32. #define MN10300_TSC_PER_HZ ((MN10300_TSCCLK + HZ / 2) / HZ)
  33. /* Check bit width of MTM interval value that sets base register */
  34. #if (MN10300_JC_PER_HZ - 1) > TMJCBR_MAX
  35. # error MTM tick timer interval value is overflow.
  36. #endif
  37. static inline void stop_jiffies_counter(void)
  38. {
  39. u16 tmp;
  40. TMTMD = 0;
  41. tmp = TMTMD;
  42. }
  43. static inline void reload_jiffies_counter(u32 cnt)
  44. {
  45. u32 tmp;
  46. TMTBR = cnt;
  47. tmp = TMTBR;
  48. TMTMD = TMTMD_TMTLDE;
  49. TMTMD = TMTMD_TMTCNE;
  50. tmp = TMTMD;
  51. }
  52. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_CLOCKEVENTS) && \
  53. !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
  54. /*
  55. * If we aren't using broadcasting, each core needs its own event timer.
  56. * Since CPU0 uses the tick timer which is 24-bits, we use timer 4 & 5
  57. * cascaded to 32-bits for CPU1 (but only really use 24-bits to match
  58. * CPU0).
  59. */
  60. #define TMJC1IRQ TM5IRQ
  61. static inline void stop_jiffies_counter1(void)
  62. {
  63. u8 tmp;
  64. TM4MD = 0;
  65. TM5MD = 0;
  66. tmp = TM4MD;
  67. tmp = TM5MD;
  68. }
  69. static inline void reload_jiffies_counter1(u32 cnt)
  70. {
  71. u32 tmp;
  72. TM45BR = cnt;
  73. tmp = TM45BR;
  74. TM4MD = TM4MD_INIT_COUNTER;
  75. tmp = TM4MD;
  76. TM5MD = TM5MD_SRC_TM4CASCADE | TM5MD_INIT_COUNTER;
  77. TM5MD = TM5MD_SRC_TM4CASCADE | TM5MD_COUNT_ENABLE;
  78. tmp = TM5MD;
  79. TM4MD = TM4MD_COUNT_ENABLE;
  80. tmp = TM4MD;
  81. }
  82. #endif /* CONFIG_SMP&GENERIC_CLOCKEVENTS&!GENERIC_CLOCKEVENTS_BROADCAST */
  83. #endif /* !__ASSEMBLY__ */
  84. /*
  85. * timestamp counter specifications
  86. */
  87. #define TMTSCBR_MAX 0xffffffff
  88. #ifndef __ASSEMBLY__
  89. /* Use 32-bit timestamp counter */
  90. #define TMTSCMD TMSMD
  91. #define TMTSCBR TMSBR
  92. #define TMTSCBC TMSBC
  93. #define TMTSCICR TMSICR
  94. static inline void startup_timestamp_counter(void)
  95. {
  96. u32 sync;
  97. /* set up TMS(Timestamp) 32bit timer register to count real time
  98. * - count down from 4Gig-1 to 0 and wrap at IOBCLK rate
  99. */
  100. TMTSCBR = TMTSCBR_MAX;
  101. sync = TMTSCBR;
  102. TMTSCICR = 0;
  103. sync = TMTSCICR;
  104. TMTSCMD = TMTMD_TMTLDE;
  105. TMTSCMD = TMTMD_TMTCNE;
  106. sync = TMTSCMD;
  107. }
  108. static inline void shutdown_timestamp_counter(void)
  109. {
  110. TMTSCMD = 0;
  111. }
  112. /*
  113. * we use a cascaded pair of 16-bit down-counting timers to count I/O
  114. * clock cycles for the purposes of time keeping
  115. */
  116. typedef unsigned long cycles_t;
  117. static inline cycles_t read_timestamp_counter(void)
  118. {
  119. return (cycles_t)~TMTSCBC;
  120. }
  121. #endif /* !__ASSEMBLY__ */
  122. #endif /* _ASM_UNIT_TIMEX_H */