blackfin_local.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #include <asm/linkage.h>
  42. #ifndef __ASSEMBLY__
  43. # ifdef SHARED_RESOURCES
  44. # include <asm/shared_resources.h>
  45. # endif
  46. # include <linux/types.h>
  47. extern u_long get_vco(void);
  48. extern u_long get_cclk(void);
  49. extern u_long get_sclk(void);
  50. # define bfin_revid() (*pCHIPID >> 28)
  51. extern void blackfin_icache_flush_range(const void *, const void *);
  52. extern void blackfin_dcache_flush_range(const void *, const void *);
  53. extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
  54. /* Use DMA to move data from on chip to external memory. While this is
  55. * required for only L1 instruction (it is not directly readable by the
  56. * core via data loads), it isn't a huge performance issue for other
  57. * regions (it's probably even faster than core load/stores). However,
  58. * the DMA engine does not have access to the L1 scratchpad, and we
  59. * cannot use DMA inside of the MMR space.
  60. */
  61. # define addr_bfin_on_chip_mem(addr) \
  62. (((unsigned long)(addr) >= 0xef000000 && (unsigned long)addr < SYSMMR_BASE) && \
  63. !((unsigned long)(addr) >= L1_SRAM_SCRATCH && \
  64. (unsigned long)(addr) < L1_SRAM_SCRATCH_END))
  65. # include <asm/system.h>
  66. #if ANOMALY_05000198
  67. # define NOP_PAD_ANOMALY_05000198 "nop;"
  68. #else
  69. # define NOP_PAD_ANOMALY_05000198
  70. #endif
  71. #define bfin_read8(addr) ({ \
  72. uint8_t __v; \
  73. __asm__ __volatile__( \
  74. NOP_PAD_ANOMALY_05000198 \
  75. "%0 = b[%1] (z);" \
  76. : "=d" (__v) \
  77. : "a" (addr) \
  78. ); \
  79. __v; })
  80. #define bfin_read16(addr) ({ \
  81. uint16_t __v; \
  82. __asm__ __volatile__( \
  83. NOP_PAD_ANOMALY_05000198 \
  84. "%0 = w[%1] (z);" \
  85. : "=d" (__v) \
  86. : "a" (addr) \
  87. ); \
  88. __v; })
  89. #define bfin_read32(addr) ({ \
  90. uint32_t __v; \
  91. __asm__ __volatile__( \
  92. NOP_PAD_ANOMALY_05000198 \
  93. "%0 = [%1];" \
  94. : "=d" (__v) \
  95. : "a" (addr) \
  96. ); \
  97. __v; })
  98. #define bfin_readPTR(addr) bfin_read32(addr)
  99. #define bfin_write8(addr, val) \
  100. __asm__ __volatile__( \
  101. NOP_PAD_ANOMALY_05000198 \
  102. "b[%0] = %1;" \
  103. : \
  104. : "a" (addr), "d" (val) \
  105. : "memory" \
  106. )
  107. #define bfin_write16(addr, val) \
  108. __asm__ __volatile__( \
  109. NOP_PAD_ANOMALY_05000198 \
  110. "w[%0] = %1;" \
  111. : \
  112. : "a" (addr), "d" (val) \
  113. : "memory" \
  114. )
  115. #define bfin_write32(addr, val) \
  116. __asm__ __volatile__( \
  117. NOP_PAD_ANOMALY_05000198 \
  118. "[%0] = %1;" \
  119. : \
  120. : "a" (addr), "d" (val) \
  121. : "memory" \
  122. )
  123. #define bfin_writePTR(addr, val) bfin_write32(addr, val)
  124. /* SSYNC implementation for C file */
  125. static inline void SSYNC(void)
  126. {
  127. int _tmp;
  128. if (ANOMALY_05000312)
  129. __asm__ __volatile__(
  130. "cli %0;"
  131. "nop;"
  132. "nop;"
  133. "ssync;"
  134. "sti %0;"
  135. : "=d" (_tmp)
  136. );
  137. else if (ANOMALY_05000244)
  138. __asm__ __volatile__(
  139. "nop;"
  140. "nop;"
  141. "nop;"
  142. "ssync;"
  143. );
  144. else
  145. __asm__ __volatile__("ssync;");
  146. }
  147. /* CSYNC implementation for C file */
  148. static inline void CSYNC(void)
  149. {
  150. int _tmp;
  151. if (ANOMALY_05000312)
  152. __asm__ __volatile__(
  153. "cli %0;"
  154. "nop;"
  155. "nop;"
  156. "csync;"
  157. "sti %0;"
  158. : "=d" (_tmp)
  159. );
  160. else if (ANOMALY_05000244)
  161. __asm__ __volatile__(
  162. "nop;"
  163. "nop;"
  164. "nop;"
  165. "csync;"
  166. );
  167. else
  168. __asm__ __volatile__("csync;");
  169. }
  170. #else /* __ASSEMBLY__ */
  171. /* SSYNC & CSYNC implementations for assembly files */
  172. #define ssync(x) SSYNC(x)
  173. #define csync(x) CSYNC(x)
  174. #if ANOMALY_05000312
  175. #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
  176. #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
  177. #elif ANOMALY_05000244
  178. #define SSYNC(scratch) nop; nop; nop; SSYNC;
  179. #define CSYNC(scratch) nop; nop; nop; CSYNC;
  180. #else
  181. #define SSYNC(scratch) SSYNC;
  182. #define CSYNC(scratch) CSYNC;
  183. #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
  184. #endif /* __ASSEMBLY__ */
  185. #endif