timex.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* ASB2303-specific timer specifcations
  2. *
  3. * Copyright (C) 2007 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 <asm/unit/clock.h>
  18. /*
  19. * jiffies counter specifications
  20. */
  21. #define TMJCBR_MAX 0xffff
  22. #define TMJCBC TM01BC
  23. #define TMJCMD TM01MD
  24. #define TMJCBR TM01BR
  25. #define TMJCIRQ TM1IRQ
  26. #define TMJCICR TM1ICR
  27. #define TMJCICR_LEVEL GxICR_LEVEL_5
  28. #ifndef __ASSEMBLY__
  29. static inline void startup_jiffies_counter(void)
  30. {
  31. unsigned rate;
  32. u16 md, t16;
  33. /* use as little prescaling as possible to avoid losing accuracy */
  34. md = TM0MD_SRC_IOCLK;
  35. rate = MN10300_JCCLK / HZ;
  36. if (rate > TMJCBR_MAX) {
  37. md = TM0MD_SRC_IOCLK_8;
  38. rate = MN10300_JCCLK / 8 / HZ;
  39. if (rate > TMJCBR_MAX) {
  40. md = TM0MD_SRC_IOCLK_32;
  41. rate = MN10300_JCCLK / 32 / HZ;
  42. if (rate > TMJCBR_MAX)
  43. BUG();
  44. }
  45. }
  46. TMJCBR = rate - 1;
  47. t16 = TMJCBR;
  48. TMJCMD =
  49. md |
  50. TM1MD_SRC_TM0CASCADE << 8 |
  51. TM0MD_INIT_COUNTER |
  52. TM1MD_INIT_COUNTER << 8;
  53. TMJCMD =
  54. md |
  55. TM1MD_SRC_TM0CASCADE << 8 |
  56. TM0MD_COUNT_ENABLE |
  57. TM1MD_COUNT_ENABLE << 8;
  58. t16 = TMJCMD;
  59. TMJCICR |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
  60. t16 = TMJCICR;
  61. }
  62. static inline void shutdown_jiffies_counter(void)
  63. {
  64. }
  65. #endif /* !__ASSEMBLY__ */
  66. /*
  67. * timestamp counter specifications
  68. */
  69. #define TMTSCBR_MAX 0xffffffff
  70. #define TMTSCBC TM45BC
  71. #ifndef __ASSEMBLY__
  72. static inline void startup_timestamp_counter(void)
  73. {
  74. /* set up timer 4 & 5 cascaded as a 32-bit counter to count real time
  75. * - count down from 4Gig-1 to 0 and wrap at IOCLK rate
  76. */
  77. TM45BR = TMTSCBR_MAX;
  78. TM4MD = TM4MD_SRC_IOCLK;
  79. TM4MD |= TM4MD_INIT_COUNTER;
  80. TM4MD &= ~TM4MD_INIT_COUNTER;
  81. TM4ICR = 0;
  82. TM5MD = TM5MD_SRC_TM4CASCADE;
  83. TM5MD |= TM5MD_INIT_COUNTER;
  84. TM5MD &= ~TM5MD_INIT_COUNTER;
  85. TM5ICR = 0;
  86. TM5MD |= TM5MD_COUNT_ENABLE;
  87. TM4MD |= TM4MD_COUNT_ENABLE;
  88. }
  89. static inline void shutdown_timestamp_counter(void)
  90. {
  91. TM4MD = 0;
  92. TM5MD = 0;
  93. }
  94. /*
  95. * we use a cascaded pair of 16-bit down-counting timers to count I/O
  96. * clock cycles for the purposes of time keeping
  97. */
  98. typedef unsigned long cycles_t;
  99. static inline cycles_t read_timestamp_counter(void)
  100. {
  101. return (cycles_t)TMTSCBC;
  102. }
  103. #endif /* !__ASSEMBLY__ */
  104. #endif /* _ASM_UNIT_TIMEX_H */