blackfin_local.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #include <asm/mem_map.h>
  27. #define LO(con32) ((con32) & 0xFFFF)
  28. #define lo(con32) ((con32) & 0xFFFF)
  29. #define HI(con32) (((con32) >> 16) & 0xFFFF)
  30. #define hi(con32) (((con32) >> 16) & 0xFFFF)
  31. #define OFFSET_(x) (x & 0x0000FFFF)
  32. #define MK_BMSK_(x) (1 << x)
  33. /* Ideally this should be USEC not MSEC, but the USEC multiplication
  34. * likes to overflow 32bit quantities which is all our assembler
  35. * currently supports ;(
  36. */
  37. #define USEC_PER_MSEC 1000
  38. #define MSEC_PER_SEC 1000
  39. #define BFIN_SCLK (100000000)
  40. #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC))
  41. #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC)
  42. #define L1_CACHE_SHIFT 5
  43. #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  44. #include <asm/linkage.h>
  45. #ifndef __ASSEMBLY__
  46. # ifdef SHARED_RESOURCES
  47. # include <asm/shared_resources.h>
  48. # endif
  49. # include <linux/types.h>
  50. extern u_long get_vco(void);
  51. extern u_long get_cclk(void);
  52. extern u_long get_sclk(void);
  53. # define bfin_revid() (bfin_read_CHIPID() >> 28)
  54. extern bool bfin_os_log_check(void);
  55. extern void bfin_os_log_dump(void);
  56. extern void blackfin_icache_flush_range(const void *, const void *);
  57. extern void blackfin_dcache_flush_range(const void *, const void *);
  58. extern void blackfin_icache_dcache_flush_range(const void *, const void *);
  59. extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
  60. /* Use DMA to move data from on chip to external memory. The L1 instruction
  61. * regions can only be accessed via DMA, so if the address in question is in
  62. * that region, make sure we attempt to DMA indirectly.
  63. */
  64. # ifdef __ADSPBF561__
  65. /* Core B regions all need dma from Core A */
  66. # define addr_bfin_on_chip_mem(addr) \
  67. ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \
  68. (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000))
  69. # else
  70. # define addr_bfin_on_chip_mem(addr) \
  71. (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
  72. # endif
  73. # include <asm/system.h>
  74. #if ANOMALY_05000198
  75. # define NOP_PAD_ANOMALY_05000198 "nop;"
  76. #else
  77. # define NOP_PAD_ANOMALY_05000198
  78. #endif
  79. #define bfin_read8(addr) ({ \
  80. uint8_t __v; \
  81. __asm__ __volatile__( \
  82. NOP_PAD_ANOMALY_05000198 \
  83. "%0 = b[%1] (z);" \
  84. : "=d" (__v) \
  85. : "a" (addr) \
  86. ); \
  87. __v; })
  88. #define bfin_read16(addr) ({ \
  89. uint16_t __v; \
  90. __asm__ __volatile__( \
  91. NOP_PAD_ANOMALY_05000198 \
  92. "%0 = w[%1] (z);" \
  93. : "=d" (__v) \
  94. : "a" (addr) \
  95. ); \
  96. __v; })
  97. #define bfin_read32(addr) ({ \
  98. uint32_t __v; \
  99. __asm__ __volatile__( \
  100. NOP_PAD_ANOMALY_05000198 \
  101. "%0 = [%1];" \
  102. : "=d" (__v) \
  103. : "a" (addr) \
  104. ); \
  105. __v; })
  106. #define bfin_readPTR(addr) bfin_read32(addr)
  107. #define bfin_write8(addr, val) \
  108. __asm__ __volatile__( \
  109. NOP_PAD_ANOMALY_05000198 \
  110. "b[%0] = %1;" \
  111. : \
  112. : "a" (addr), "d" (val) \
  113. : "memory" \
  114. )
  115. #define bfin_write16(addr, val) \
  116. __asm__ __volatile__( \
  117. NOP_PAD_ANOMALY_05000198 \
  118. "w[%0] = %1;" \
  119. : \
  120. : "a" (addr), "d" (val) \
  121. : "memory" \
  122. )
  123. #define bfin_write32(addr, val) \
  124. __asm__ __volatile__( \
  125. NOP_PAD_ANOMALY_05000198 \
  126. "[%0] = %1;" \
  127. : \
  128. : "a" (addr), "d" (val) \
  129. : "memory" \
  130. )
  131. #define bfin_writePTR(addr, val) bfin_write32(addr, val)
  132. /* SSYNC implementation for C file */
  133. static inline void SSYNC(void)
  134. {
  135. int _tmp;
  136. if (ANOMALY_05000312)
  137. __asm__ __volatile__(
  138. "cli %0;"
  139. "nop;"
  140. "nop;"
  141. "ssync;"
  142. "sti %0;"
  143. : "=d" (_tmp)
  144. );
  145. else if (ANOMALY_05000244)
  146. __asm__ __volatile__(
  147. "nop;"
  148. "nop;"
  149. "nop;"
  150. "ssync;"
  151. );
  152. else
  153. __asm__ __volatile__("ssync;");
  154. }
  155. /* CSYNC implementation for C file */
  156. static inline void CSYNC(void)
  157. {
  158. int _tmp;
  159. if (ANOMALY_05000312)
  160. __asm__ __volatile__(
  161. "cli %0;"
  162. "nop;"
  163. "nop;"
  164. "csync;"
  165. "sti %0;"
  166. : "=d" (_tmp)
  167. );
  168. else if (ANOMALY_05000244)
  169. __asm__ __volatile__(
  170. "nop;"
  171. "nop;"
  172. "nop;"
  173. "csync;"
  174. );
  175. else
  176. __asm__ __volatile__("csync;");
  177. }
  178. #else /* __ASSEMBLY__ */
  179. /* SSYNC & CSYNC implementations for assembly files */
  180. #define ssync(x) SSYNC(x)
  181. #define csync(x) CSYNC(x)
  182. #if ANOMALY_05000312
  183. #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
  184. #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
  185. #elif ANOMALY_05000244
  186. #define SSYNC(scratch) nop; nop; nop; SSYNC;
  187. #define CSYNC(scratch) nop; nop; nop; CSYNC;
  188. #else
  189. #define SSYNC(scratch) SSYNC;
  190. #define CSYNC(scratch) CSYNC;
  191. #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
  192. #endif /* __ASSEMBLY__ */
  193. #endif