head.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * File: arch/blackfin/mach-bf537/head.S
  3. * Based on: arch/blackfin/mach-bf533/head.S
  4. * Author: Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne
  5. *
  6. * Created: 1998
  7. * Description: Startup code for Blackfin BF537
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/linkage.h>
  30. #include <linux/init.h>
  31. #include <asm/blackfin.h>
  32. #include <asm/trace.h>
  33. #ifdef CONFIG_BFIN_KERNEL_CLOCK
  34. #include <asm/mach-common/clocks.h>
  35. #include <asm/mach/mem_init.h>
  36. #endif
  37. .extern ___bss_stop
  38. .extern ___bss_start
  39. .extern _bf53x_relocate_l1_mem
  40. #define INITIAL_STACK 0xFFB01000
  41. __INIT
  42. ENTRY(__start)
  43. /* R0: argument of command line string, passed from uboot, save it */
  44. R7 = R0;
  45. /* Enable Cycle Counter and Nesting Of Interrupts */
  46. #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
  47. R0 = SYSCFG_SNEN;
  48. #else
  49. R0 = SYSCFG_SNEN | SYSCFG_CCEN;
  50. #endif
  51. SYSCFG = R0;
  52. R0 = 0;
  53. /* Clear Out All the data and pointer Registers */
  54. R1 = R0;
  55. R2 = R0;
  56. R3 = R0;
  57. R4 = R0;
  58. R5 = R0;
  59. R6 = R0;
  60. P0 = R0;
  61. P1 = R0;
  62. P2 = R0;
  63. P3 = R0;
  64. P4 = R0;
  65. P5 = R0;
  66. LC0 = r0;
  67. LC1 = r0;
  68. L0 = r0;
  69. L1 = r0;
  70. L2 = r0;
  71. L3 = r0;
  72. /* Clear Out All the DAG Registers */
  73. B0 = r0;
  74. B1 = r0;
  75. B2 = r0;
  76. B3 = r0;
  77. I0 = r0;
  78. I1 = r0;
  79. I2 = r0;
  80. I3 = r0;
  81. M0 = r0;
  82. M1 = r0;
  83. M2 = r0;
  84. M3 = r0;
  85. trace_buffer_init(p0,r0);
  86. P0 = R1;
  87. R0 = R1;
  88. /* Turn off the icache */
  89. p0.l = LO(IMEM_CONTROL);
  90. p0.h = HI(IMEM_CONTROL);
  91. R1 = [p0];
  92. R0 = ~ENICPLB;
  93. R0 = R0 & R1;
  94. [p0] = R0;
  95. SSYNC;
  96. /* Turn off the dcache */
  97. p0.l = LO(DMEM_CONTROL);
  98. p0.h = HI(DMEM_CONTROL);
  99. R1 = [p0];
  100. R0 = ~ENDCPLB;
  101. R0 = R0 & R1;
  102. [p0] = R0;
  103. SSYNC;
  104. /* Initialise General-Purpose I/O Modules on BF537 */
  105. p0.h = hi(BFIN_PORT_MUX);
  106. p0.l = lo(BFIN_PORT_MUX);
  107. R0 = (PGDE_UART | PFTE_UART)(Z);
  108. W[P0] = R0.L; /* Enable both UARTS */
  109. SSYNC;
  110. /* Enable peripheral function of PORTF for UART0 and UART1 */
  111. p0.h = hi(PORTF_FER);
  112. p0.l = lo(PORTF_FER);
  113. R0 = 0x000F(Z);
  114. W[P0] = R0.L;
  115. SSYNC;
  116. #if !defined(CONFIG_BF534)
  117. p0.h = hi(EMAC_SYSTAT);
  118. p0.l = lo(EMAC_SYSTAT);
  119. R0.h = 0xFFFF; /* Clear EMAC Interrupt Status bits */
  120. R0.l = 0xFFFF;
  121. [P0] = R0;
  122. SSYNC;
  123. #endif
  124. /* Initialise UART - when booting from u-boot, the UART is not disabled
  125. * so if we dont initalize here, our serial console gets hosed */
  126. p0.h = hi(BFIN_UART_LCR);
  127. p0.l = lo(BFIN_UART_LCR);
  128. r0 = 0x0(Z);
  129. w[p0] = r0.L; /* To enable DLL writes */
  130. ssync;
  131. p0.h = hi(BFIN_UART_DLL);
  132. p0.l = lo(BFIN_UART_DLL);
  133. r0 = 0x0(Z);
  134. w[p0] = r0.L;
  135. ssync;
  136. p0.h = hi(BFIN_UART_DLH);
  137. p0.l = lo(BFIN_UART_DLH);
  138. r0 = 0x00(Z);
  139. w[p0] = r0.L;
  140. ssync;
  141. p0.h = hi(BFIN_UART_GCTL);
  142. p0.l = lo(BFIN_UART_GCTL);
  143. r0 = 0x0(Z);
  144. w[p0] = r0.L; /* To enable UART clock */
  145. ssync;
  146. /* Initialize stack pointer */
  147. sp.l = lo(INITIAL_STACK);
  148. sp.h = hi(INITIAL_STACK);
  149. fp = sp;
  150. usp = sp;
  151. #ifdef CONFIG_EARLY_PRINTK
  152. SP += -12;
  153. call _init_early_exception_vectors;
  154. SP += 12;
  155. #endif
  156. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  157. call _bf53x_relocate_l1_mem;
  158. #ifdef CONFIG_BFIN_KERNEL_CLOCK
  159. call _start_dma_code;
  160. #endif
  161. /* Code for initializing Async memory banks */
  162. p2.h = hi(EBIU_AMBCTL1);
  163. p2.l = lo(EBIU_AMBCTL1);
  164. r0.h = hi(AMBCTL1VAL);
  165. r0.l = lo(AMBCTL1VAL);
  166. [p2] = r0;
  167. ssync;
  168. p2.h = hi(EBIU_AMBCTL0);
  169. p2.l = lo(EBIU_AMBCTL0);
  170. r0.h = hi(AMBCTL0VAL);
  171. r0.l = lo(AMBCTL0VAL);
  172. [p2] = r0;
  173. ssync;
  174. p2.h = hi(EBIU_AMGCTL);
  175. p2.l = lo(EBIU_AMGCTL);
  176. r0 = AMGCTLVAL;
  177. w[p2] = r0;
  178. ssync;
  179. /* This section keeps the processor in supervisor mode
  180. * during kernel boot. Switches to user mode at end of boot.
  181. * See page 3-9 of Hardware Reference manual for documentation.
  182. */
  183. /* EVT15 = _real_start */
  184. p0.l = lo(EVT15);
  185. p0.h = hi(EVT15);
  186. p1.l = _real_start;
  187. p1.h = _real_start;
  188. [p0] = p1;
  189. csync;
  190. p0.l = lo(IMASK);
  191. p0.h = hi(IMASK);
  192. p1.l = IMASK_IVG15;
  193. p1.h = 0x0;
  194. [p0] = p1;
  195. csync;
  196. raise 15;
  197. p0.l = .LWAIT_HERE;
  198. p0.h = .LWAIT_HERE;
  199. reti = p0;
  200. #if ANOMALY_05000281
  201. nop; nop; nop;
  202. #endif
  203. rti;
  204. .LWAIT_HERE:
  205. jump .LWAIT_HERE;
  206. ENDPROC(__start)
  207. __FINIT
  208. .section .l1.text
  209. #ifdef CONFIG_BFIN_KERNEL_CLOCK
  210. ENTRY(_start_dma_code)
  211. /* Enable PHY CLK buffer output */
  212. p0.h = hi(VR_CTL);
  213. p0.l = lo(VR_CTL);
  214. r0.l = w[p0];
  215. bitset(r0, 14);
  216. w[p0] = r0.l;
  217. ssync;
  218. p0.h = hi(SIC_IWR);
  219. p0.l = lo(SIC_IWR);
  220. r0.l = 0x1;
  221. r0.h = 0x0;
  222. [p0] = r0;
  223. SSYNC;
  224. /*
  225. * Set PLL_CTL
  226. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  227. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  228. * - [7] = output delay (add 200ps of delay to mem signals)
  229. * - [6] = input delay (add 200ps of input delay to mem signals)
  230. * - [5] = PDWN : 1=All Clocks off
  231. * - [3] = STOPCK : 1=Core Clock off
  232. * - [1] = PLL_OFF : 1=Disable Power to PLL
  233. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  234. * all other bits set to zero
  235. */
  236. p0.h = hi(PLL_LOCKCNT);
  237. p0.l = lo(PLL_LOCKCNT);
  238. r0 = 0x300(Z);
  239. w[p0] = r0.l;
  240. ssync;
  241. P2.H = hi(EBIU_SDGCTL);
  242. P2.L = lo(EBIU_SDGCTL);
  243. R0 = [P2];
  244. BITSET (R0, 24);
  245. [P2] = R0;
  246. SSYNC;
  247. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  248. r0 = r0 << 9; /* Shift it over, */
  249. r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  250. r0 = r1 | r0;
  251. r1 = PLL_BYPASS; /* Bypass the PLL? */
  252. r1 = r1 << 8; /* Shift it over */
  253. r0 = r1 | r0; /* add them all together */
  254. p0.h = hi(PLL_CTL);
  255. p0.l = lo(PLL_CTL); /* Load the address */
  256. cli r2; /* Disable interrupts */
  257. ssync;
  258. w[p0] = r0.l; /* Set the value */
  259. idle; /* Wait for the PLL to stablize */
  260. sti r2; /* Enable interrupts */
  261. .Lcheck_again:
  262. p0.h = hi(PLL_STAT);
  263. p0.l = lo(PLL_STAT);
  264. R0 = W[P0](Z);
  265. CC = BITTST(R0,5);
  266. if ! CC jump .Lcheck_again;
  267. /* Configure SCLK & CCLK Dividers */
  268. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  269. p0.h = hi(PLL_DIV);
  270. p0.l = lo(PLL_DIV);
  271. w[p0] = r0.l;
  272. ssync;
  273. p0.l = lo(EBIU_SDRRC);
  274. p0.h = hi(EBIU_SDRRC);
  275. r0 = mem_SDRRC;
  276. w[p0] = r0.l;
  277. ssync;
  278. P2.H = hi(EBIU_SDGCTL);
  279. P2.L = lo(EBIU_SDGCTL);
  280. R0 = [P2];
  281. BITCLR (R0, 24);
  282. p0.h = hi(EBIU_SDSTAT);
  283. p0.l = lo(EBIU_SDSTAT);
  284. r2.l = w[p0];
  285. cc = bittst(r2,3);
  286. if !cc jump .Lskip;
  287. NOP;
  288. BITSET (R0, 23);
  289. .Lskip:
  290. [P2] = R0;
  291. SSYNC;
  292. R0.L = lo(mem_SDGCTL);
  293. R0.H = hi(mem_SDGCTL);
  294. R1 = [p2];
  295. R1 = R1 | R0;
  296. [P2] = R1;
  297. SSYNC;
  298. p0.h = hi(SIC_IWR);
  299. p0.l = lo(SIC_IWR);
  300. r0.l = lo(IWR_ENABLE_ALL);
  301. r0.h = hi(IWR_ENABLE_ALL);
  302. [p0] = r0;
  303. SSYNC;
  304. RTS;
  305. ENDPROC(_start_dma_code)
  306. #endif /* CONFIG_BFIN_KERNEL_CLOCK */