interrupts.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <asm/machdep.h>
  37. #include <asm/irq.h>
  38. #include <config.h>
  39. #include <asm/blackfin.h>
  40. #include "cpu.h"
  41. static ulong timestamp;
  42. static ulong last_time;
  43. static int int_flag;
  44. int irq_flags; /* needed by asm-blackfin/system.h */
  45. /* Functions just to satisfy the linker */
  46. /*
  47. * This function is derived from PowerPC code (read timebase as long long).
  48. * On BF533 it just returns the timer value.
  49. */
  50. unsigned long long get_ticks(void)
  51. {
  52. return get_timer(0);
  53. }
  54. /*
  55. * This function is derived from PowerPC code (timebase clock frequency).
  56. * On BF533 it returns the number of timer ticks per second.
  57. */
  58. ulong get_tbclk(void)
  59. {
  60. ulong tbclk;
  61. tbclk = CFG_HZ;
  62. return tbclk;
  63. }
  64. void enable_interrupts(void)
  65. {
  66. restore_flags(int_flag);
  67. }
  68. int disable_interrupts(void)
  69. {
  70. save_and_cli(int_flag);
  71. return 1;
  72. }
  73. int interrupt_init(void)
  74. {
  75. return (0);
  76. }
  77. void udelay(unsigned long usec)
  78. {
  79. unsigned long delay, start, stop;
  80. unsigned long cclk;
  81. cclk = (CONFIG_CCLK_HZ);
  82. while (usec > 1) {
  83. /*
  84. * how many clock ticks to delay?
  85. * - request(in useconds) * clock_ticks(Hz) / useconds/second
  86. */
  87. if (usec < 1000) {
  88. delay = (usec * (cclk / 244)) >> 12;
  89. usec = 0;
  90. } else {
  91. delay = (1000 * (cclk / 244)) >> 12;
  92. usec -= 1000;
  93. }
  94. asm volatile (" %0 = CYCLES;":"=r" (start));
  95. do {
  96. asm volatile (" %0 = CYCLES; ":"=r" (stop));
  97. } while (stop - start < delay);
  98. }
  99. return;
  100. }
  101. void timer_init(void)
  102. {
  103. *pTCNTL = 0x1;
  104. *pTSCALE = 0x0;
  105. *pTCOUNT = MAX_TIM_LOAD;
  106. *pTPERIOD = MAX_TIM_LOAD;
  107. *pTCNTL = 0x7;
  108. asm("CSYNC;");
  109. timestamp = 0;
  110. last_time = 0;
  111. }
  112. /* Any network command or flash
  113. * command is started get_timer shall
  114. * be called before TCOUNT gets reset,
  115. * to implement the accurate timeouts.
  116. *
  117. * How ever milliconds doesn't return
  118. * the number that has been elapsed from
  119. * the last reset.
  120. *
  121. * As get_timer is used in the u-boot
  122. * only for timeouts this should be
  123. * sufficient
  124. */
  125. ulong get_timer(ulong base)
  126. {
  127. ulong milisec;
  128. /* Number of clocks elapsed */
  129. ulong clocks = (MAX_TIM_LOAD - (*pTCOUNT));
  130. /**
  131. * Find if the TCOUNT is reset
  132. * timestamp gives the number of times
  133. * TCOUNT got reset
  134. */
  135. if (clocks < last_time)
  136. timestamp++;
  137. last_time = clocks;
  138. /* Get the number of milliseconds */
  139. milisec = clocks / (CONFIG_CCLK_HZ / 1000);
  140. /**
  141. * Find the number of millisonds
  142. * that got elapsed before this TCOUNT cycle
  143. */
  144. milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
  145. return (milisec - base);
  146. }