blackfin_local.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * U-boot - blackfin_local.h
  3. *
  4. * Copyright (c) 2005-2007 Analog Devices Inc.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #ifndef __BLACKFIN_LOCAL_H__
  25. #define __BLACKFIN_LOCAL_H__
  26. #define LO(con32) ((con32) & 0xFFFF)
  27. #define lo(con32) ((con32) & 0xFFFF)
  28. #define HI(con32) (((con32) >> 16) & 0xFFFF)
  29. #define hi(con32) (((con32) >> 16) & 0xFFFF)
  30. #define OFFSET_(x) (x & 0x0000FFFF)
  31. #define MK_BMSK_(x) (1 << x)
  32. /* Ideally this should be USEC not MSEC, but the USEC multiplication
  33. * likes to overflow 32bit quantities which is all our assembler
  34. * currently supports ;(
  35. */
  36. #define USEC_PER_MSEC 1000
  37. #define MSEC_PER_SEC 1000
  38. #define BFIN_SCLK (100000000)
  39. #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC))
  40. #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC)
  41. #define L1_CACHE_SHIFT 5
  42. #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  43. #include <asm/linkage.h>
  44. #ifndef __ASSEMBLY__
  45. # ifdef SHARED_RESOURCES
  46. # include <asm/shared_resources.h>
  47. # endif
  48. # include <linux/types.h>
  49. extern u_long get_vco(void);
  50. extern u_long get_cclk(void);
  51. extern u_long get_sclk(void);
  52. # define bfin_revid() (*pCHIPID >> 28)
  53. extern void blackfin_icache_flush_range(const void *, const void *);
  54. extern void blackfin_dcache_flush_range(const void *, const void *);
  55. extern void blackfin_icache_dcache_flush_range(const void *, const void *);
  56. extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
  57. /* Use DMA to move data from on chip to external memory. The L1 instruction
  58. * regions can only be accessed via DMA, so if the address in question is in
  59. * that region, make sure we attempt to DMA indirectly.
  60. */
  61. # define addr_bfin_on_chip_mem(addr) (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
  62. # include <asm/system.h>
  63. #if ANOMALY_05000198
  64. # define NOP_PAD_ANOMALY_05000198 "nop;"
  65. #else
  66. # define NOP_PAD_ANOMALY_05000198
  67. #endif
  68. #define bfin_read8(addr) ({ \
  69. uint8_t __v; \
  70. __asm__ __volatile__( \
  71. NOP_PAD_ANOMALY_05000198 \
  72. "%0 = b[%1] (z);" \
  73. : "=d" (__v) \
  74. : "a" (addr) \
  75. ); \
  76. __v; })
  77. #define bfin_read16(addr) ({ \
  78. uint16_t __v; \
  79. __asm__ __volatile__( \
  80. NOP_PAD_ANOMALY_05000198 \
  81. "%0 = w[%1] (z);" \
  82. : "=d" (__v) \
  83. : "a" (addr) \
  84. ); \
  85. __v; })
  86. #define bfin_read32(addr) ({ \
  87. uint32_t __v; \
  88. __asm__ __volatile__( \
  89. NOP_PAD_ANOMALY_05000198 \
  90. "%0 = [%1];" \
  91. : "=d" (__v) \
  92. : "a" (addr) \
  93. ); \
  94. __v; })
  95. #define bfin_readPTR(addr) bfin_read32(addr)
  96. #define bfin_write8(addr, val) \
  97. __asm__ __volatile__( \
  98. NOP_PAD_ANOMALY_05000198 \
  99. "b[%0] = %1;" \
  100. : \
  101. : "a" (addr), "d" (val) \
  102. : "memory" \
  103. )
  104. #define bfin_write16(addr, val) \
  105. __asm__ __volatile__( \
  106. NOP_PAD_ANOMALY_05000198 \
  107. "w[%0] = %1;" \
  108. : \
  109. : "a" (addr), "d" (val) \
  110. : "memory" \
  111. )
  112. #define bfin_write32(addr, val) \
  113. __asm__ __volatile__( \
  114. NOP_PAD_ANOMALY_05000198 \
  115. "[%0] = %1;" \
  116. : \
  117. : "a" (addr), "d" (val) \
  118. : "memory" \
  119. )
  120. #define bfin_writePTR(addr, val) bfin_write32(addr, val)
  121. /* SSYNC implementation for C file */
  122. static inline void SSYNC(void)
  123. {
  124. int _tmp;
  125. if (ANOMALY_05000312)
  126. __asm__ __volatile__(
  127. "cli %0;"
  128. "nop;"
  129. "nop;"
  130. "ssync;"
  131. "sti %0;"
  132. : "=d" (_tmp)
  133. );
  134. else if (ANOMALY_05000244)
  135. __asm__ __volatile__(
  136. "nop;"
  137. "nop;"
  138. "nop;"
  139. "ssync;"
  140. );
  141. else
  142. __asm__ __volatile__("ssync;");
  143. }
  144. /* CSYNC implementation for C file */
  145. static inline void CSYNC(void)
  146. {
  147. int _tmp;
  148. if (ANOMALY_05000312)
  149. __asm__ __volatile__(
  150. "cli %0;"
  151. "nop;"
  152. "nop;"
  153. "csync;"
  154. "sti %0;"
  155. : "=d" (_tmp)
  156. );
  157. else if (ANOMALY_05000244)
  158. __asm__ __volatile__(
  159. "nop;"
  160. "nop;"
  161. "nop;"
  162. "csync;"
  163. );
  164. else
  165. __asm__ __volatile__("csync;");
  166. }
  167. #else /* __ASSEMBLY__ */
  168. /* SSYNC & CSYNC implementations for assembly files */
  169. #define ssync(x) SSYNC(x)
  170. #define csync(x) CSYNC(x)
  171. #if ANOMALY_05000312
  172. #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
  173. #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
  174. #elif ANOMALY_05000244
  175. #define SSYNC(scratch) nop; nop; nop; SSYNC;
  176. #define CSYNC(scratch) nop; nop; nop; CSYNC;
  177. #else
  178. #define SSYNC(scratch) SSYNC;
  179. #define CSYNC(scratch) CSYNC;
  180. #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
  181. #endif /* __ASSEMBLY__ */
  182. #endif