interrupts.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Alex Zuepke <azu@sysgo.de>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <clps7111.h>
  30. #include <asm/proc-armv/ptrace.h>
  31. #include <asm/hardware.h>
  32. #ifndef CONFIG_NETARM
  33. /* we always count down the max. */
  34. #define TIMER_LOAD_VAL 0xffff
  35. /* macro to read the 16 bit timer */
  36. #define READ_TIMER (IO_TC1D & 0xffff)
  37. #else
  38. #define IRQEN (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_INTR_ENABLE))
  39. #define TM2CTRL (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_CONTROL))
  40. #define TM2STAT (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_TIMER2_STATUS))
  41. #define TIMER_LOAD_VAL NETARM_GEN_TSTAT_CTC_MASK
  42. #define READ_TIMER (TM2STAT & NETARM_GEN_TSTAT_CTC_MASK)
  43. #endif
  44. #ifdef CONFIG_USE_IRQ
  45. void do_irq (struct pt_regs *pt_regs)
  46. {
  47. #if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  48. /* No do_irq() for IntegratorAP/CM720T as yet */
  49. #else
  50. #error do_irq() not defined for this CPU type
  51. #endif
  52. }
  53. #endif
  54. #if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  55. /* Use IntegratorAP routines in board/integratorap.c */
  56. #else
  57. static ulong timestamp;
  58. static ulong lastdec;
  59. int timer_init (void)
  60. {
  61. #if defined(CONFIG_NETARM)
  62. /* disable all interrupts */
  63. IRQEN = 0;
  64. /* operate timer 2 in non-prescale mode */
  65. TM2CTRL = ( NETARM_GEN_TIMER_SET_HZ(CONFIG_SYS_HZ) |
  66. NETARM_GEN_TCTL_ENABLE |
  67. NETARM_GEN_TCTL_INIT_COUNT(TIMER_LOAD_VAL));
  68. /* set timer 2 counter */
  69. lastdec = TIMER_LOAD_VAL;
  70. #elif defined(CONFIG_TEGRA)
  71. /* No timer routines for tegra as yet */
  72. lastdec = 0;
  73. #else
  74. #error No timer_init() defined for this CPU type
  75. #endif
  76. timestamp = 0;
  77. return (0);
  78. }
  79. #endif /* ! IntegratorAP */
  80. /*
  81. * timer without interrupts
  82. */
  83. #if defined(CONFIG_NETARM)
  84. ulong get_timer (ulong base)
  85. {
  86. return get_timer_masked () - base;
  87. }
  88. void __udelay (unsigned long usec)
  89. {
  90. ulong tmo;
  91. tmo = usec / 1000;
  92. tmo *= CONFIG_SYS_HZ;
  93. tmo /= 1000;
  94. tmo += get_timer (0);
  95. while (get_timer_masked () < tmo)
  96. }
  97. ulong get_timer_masked (void)
  98. {
  99. ulong now = READ_TIMER;
  100. if (lastdec >= now) {
  101. /* normal mode */
  102. timestamp += lastdec - now;
  103. } else {
  104. /* we have an overflow ... */
  105. timestamp += lastdec + TIMER_LOAD_VAL - now;
  106. }
  107. lastdec = now;
  108. return timestamp;
  109. }
  110. void udelay_masked (unsigned long usec)
  111. {
  112. ulong tmo;
  113. ulong endtime;
  114. signed long diff;
  115. if (usec >= 1000) {
  116. tmo = usec / 1000;
  117. tmo *= CONFIG_SYS_HZ;
  118. tmo /= 1000;
  119. } else {
  120. tmo = usec * CONFIG_SYS_HZ;
  121. tmo /= (1000*1000);
  122. }
  123. endtime = get_timer_masked () + tmo;
  124. do {
  125. ulong now = get_timer_masked ();
  126. diff = endtime - now;
  127. } while (diff >= 0);
  128. }
  129. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  130. /* No timer routines for IntegratorAP/CM720T as yet */
  131. #elif defined(CONFIG_TEGRA)
  132. /* No timer routines for tegra as yet */
  133. #else
  134. #error Timer routines not defined for this CPU type
  135. #endif