interrupts.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * U-boot - interrupts.c Interrupt related routines
  3. *
  4. * Copyright (c) 2005-2007 Analog Devices Inc.
  5. *
  6. * This file is based on interrupts.c
  7. * Copyright 1996 Roman Zippel
  8. * Copyright 1999 D. Jeff Dionne <jeff@uclinux.org>
  9. * Copyright 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
  10. * Copyright 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
  11. * Copyright 2003 Metrowerks/Motorola
  12. * Copyright 2003 Bas Vermeulen <bas@buyways.nl>,
  13. * BuyWays B.V. (www.buyways.nl)
  14. *
  15. * (C) Copyright 2000-2004
  16. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  33. * MA 02110-1301 USA
  34. */
  35. #include <common.h>
  36. #include <config.h>
  37. #include <asm/blackfin.h>
  38. #include "cpu.h"
  39. static ulong timestamp;
  40. static ulong last_time;
  41. static int int_flag;
  42. int irq_flags; /* needed by asm-blackfin/system.h */
  43. /* Functions just to satisfy the linker */
  44. /*
  45. * This function is derived from PowerPC code (read timebase as long long).
  46. * On BF533 it just returns the timer value.
  47. */
  48. unsigned long long get_ticks(void)
  49. {
  50. return get_timer(0);
  51. }
  52. /*
  53. * This function is derived from PowerPC code (timebase clock frequency).
  54. * On BF533 it returns the number of timer ticks per second.
  55. */
  56. ulong get_tbclk(void)
  57. {
  58. ulong tbclk;
  59. tbclk = CFG_HZ;
  60. return tbclk;
  61. }
  62. void enable_interrupts(void)
  63. {
  64. }
  65. int disable_interrupts(void)
  66. {
  67. return 1;
  68. }
  69. int interrupt_init(void)
  70. {
  71. return (0);
  72. }
  73. void udelay(unsigned long usec)
  74. {
  75. unsigned long delay, start, stop;
  76. unsigned long cclk;
  77. cclk = (CONFIG_CCLK_HZ);
  78. while (usec > 1) {
  79. /*
  80. * how many clock ticks to delay?
  81. * - request(in useconds) * clock_ticks(Hz) / useconds/second
  82. */
  83. if (usec < 1000) {
  84. delay = (usec * (cclk / 244)) >> 12;
  85. usec = 0;
  86. } else {
  87. delay = (1000 * (cclk / 244)) >> 12;
  88. usec -= 1000;
  89. }
  90. asm volatile (" %0 = CYCLES;":"=r" (start));
  91. do {
  92. asm volatile (" %0 = CYCLES; ":"=r" (stop));
  93. } while (stop - start < delay);
  94. }
  95. return;
  96. }
  97. void timer_init(void)
  98. {
  99. *pTCNTL = 0x1;
  100. *pTSCALE = 0x0;
  101. *pTCOUNT = MAX_TIM_LOAD;
  102. *pTPERIOD = MAX_TIM_LOAD;
  103. *pTCNTL = 0x7;
  104. asm("CSYNC;");
  105. timestamp = 0;
  106. last_time = 0;
  107. }
  108. /* Any network command or flash
  109. * command is started get_timer shall
  110. * be called before TCOUNT gets reset,
  111. * to implement the accurate timeouts.
  112. *
  113. * How ever milliconds doesn't return
  114. * the number that has been elapsed from
  115. * the last reset.
  116. *
  117. * As get_timer is used in the u-boot
  118. * only for timeouts this should be
  119. * sufficient
  120. */
  121. ulong get_timer(ulong base)
  122. {
  123. ulong milisec;
  124. /* Number of clocks elapsed */
  125. ulong clocks = (MAX_TIM_LOAD - (*pTCOUNT));
  126. /**
  127. * Find if the TCOUNT is reset
  128. * timestamp gives the number of times
  129. * TCOUNT got reset
  130. */
  131. if (clocks < last_time)
  132. timestamp++;
  133. last_time = clocks;
  134. /* Get the number of milliseconds */
  135. milisec = clocks / (CONFIG_CCLK_HZ / 1000);
  136. /**
  137. * Find the number of millisonds
  138. * that got elapsed before this TCOUNT cycle
  139. */
  140. milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
  141. return (milisec - base);
  142. }