head.S 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * File: arch/blackfin/mach-bf561/head.S
  3. * Based on: arch/blackfin/mach-bf533/head.S
  4. * Author:
  5. *
  6. * Created:
  7. * Description: BF561 startup file
  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. #if CONFIG_BFIN_KERNEL_CLOCK
  34. #include <asm/mach-common/clocks.h>
  35. #include <asm/mach/mem_init.h>
  36. #endif
  37. .global __rambase
  38. .global __ramstart
  39. .global __ramend
  40. .extern ___bss_stop
  41. .extern ___bss_start
  42. .extern _bf53x_relocate_l1_mem
  43. #define INITIAL_STACK 0xFFB01000
  44. __INIT
  45. ENTRY(__start)
  46. /* R0: argument of command line string, passed from uboot, save it */
  47. R7 = R0;
  48. /* Enable Cycle Counter and Nesting Of Interrupts */
  49. #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
  50. R0 = SYSCFG_SNEN;
  51. #else
  52. R0 = SYSCFG_SNEN | SYSCFG_CCEN;
  53. #endif
  54. SYSCFG = R0;
  55. R0 = 0;
  56. /* Clear Out All the data and pointer Registers */
  57. R1 = R0;
  58. R2 = R0;
  59. R3 = R0;
  60. R4 = R0;
  61. R5 = R0;
  62. R6 = R0;
  63. P0 = R0;
  64. P1 = R0;
  65. P2 = R0;
  66. P3 = R0;
  67. P4 = R0;
  68. P5 = R0;
  69. LC0 = r0;
  70. LC1 = r0;
  71. L0 = r0;
  72. L1 = r0;
  73. L2 = r0;
  74. L3 = r0;
  75. /* Clear Out All the DAG Registers */
  76. B0 = r0;
  77. B1 = r0;
  78. B2 = r0;
  79. B3 = r0;
  80. I0 = r0;
  81. I1 = r0;
  82. I2 = r0;
  83. I3 = r0;
  84. M0 = r0;
  85. M1 = r0;
  86. M2 = r0;
  87. M3 = r0;
  88. trace_buffer_init(p0,r0);
  89. P0 = R1;
  90. R0 = R1;
  91. /* Turn off the icache */
  92. p0.l = LO(IMEM_CONTROL);
  93. p0.h = HI(IMEM_CONTROL);
  94. R1 = [p0];
  95. R0 = ~ENICPLB;
  96. R0 = R0 & R1;
  97. #if ANOMALY_05000125
  98. CLI R2;
  99. SSYNC;
  100. #endif
  101. [p0] = R0;
  102. SSYNC;
  103. #if ANOMALY_05000125
  104. STI R2;
  105. #endif
  106. /* Turn off the dcache */
  107. p0.l = LO(DMEM_CONTROL);
  108. p0.h = HI(DMEM_CONTROL);
  109. R1 = [p0];
  110. R0 = ~ENDCPLB;
  111. R0 = R0 & R1;
  112. /* Anomaly 05000125 */
  113. #if ANOMALY_05000125
  114. CLI R2;
  115. SSYNC;
  116. #endif
  117. [p0] = R0;
  118. SSYNC;
  119. #if ANOMALY_05000125
  120. STI R2;
  121. #endif
  122. /* Initialise UART - when booting from u-boot, the UART is not disabled
  123. * so if we dont initalize here, our serial console gets hosed */
  124. p0.h = hi(UART_LCR);
  125. p0.l = lo(UART_LCR);
  126. r0 = 0x0(Z);
  127. w[p0] = r0.L; /* To enable DLL writes */
  128. ssync;
  129. p0.h = hi(UART_DLL);
  130. p0.l = lo(UART_DLL);
  131. r0 = 0x0(Z);
  132. w[p0] = r0.L;
  133. ssync;
  134. p0.h = hi(UART_DLH);
  135. p0.l = lo(UART_DLH);
  136. r0 = 0x00(Z);
  137. w[p0] = r0.L;
  138. ssync;
  139. p0.h = hi(UART_GCTL);
  140. p0.l = lo(UART_GCTL);
  141. r0 = 0x0(Z);
  142. w[p0] = r0.L; /* To enable UART clock */
  143. ssync;
  144. /* Initialize stack pointer */
  145. sp.l = lo(INITIAL_STACK);
  146. sp.h = hi(INITIAL_STACK);
  147. fp = sp;
  148. usp = sp;
  149. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  150. call _bf53x_relocate_l1_mem;
  151. #if CONFIG_BFIN_KERNEL_CLOCK
  152. call _start_dma_code;
  153. #endif
  154. /* Code for initializing Async memory banks */
  155. p2.h = hi(EBIU_AMBCTL1);
  156. p2.l = lo(EBIU_AMBCTL1);
  157. r0.h = hi(AMBCTL1VAL);
  158. r0.l = lo(AMBCTL1VAL);
  159. [p2] = r0;
  160. ssync;
  161. p2.h = hi(EBIU_AMBCTL0);
  162. p2.l = lo(EBIU_AMBCTL0);
  163. r0.h = hi(AMBCTL0VAL);
  164. r0.l = lo(AMBCTL0VAL);
  165. [p2] = r0;
  166. ssync;
  167. p2.h = hi(EBIU_AMGCTL);
  168. p2.l = lo(EBIU_AMGCTL);
  169. r0 = AMGCTLVAL;
  170. w[p2] = r0;
  171. ssync;
  172. /* This section keeps the processor in supervisor mode
  173. * during kernel boot. Switches to user mode at end of boot.
  174. * See page 3-9 of Hardware Reference manual for documentation.
  175. */
  176. /* EVT15 = _real_start */
  177. p0.l = lo(EVT15);
  178. p0.h = hi(EVT15);
  179. p1.l = _real_start;
  180. p1.h = _real_start;
  181. [p0] = p1;
  182. csync;
  183. p0.l = lo(IMASK);
  184. p0.h = hi(IMASK);
  185. p1.l = IMASK_IVG15;
  186. p1.h = 0x0;
  187. [p0] = p1;
  188. csync;
  189. raise 15;
  190. p0.l = .LWAIT_HERE;
  191. p0.h = .LWAIT_HERE;
  192. reti = p0;
  193. #if ANOMALY_05000281
  194. nop; nop; nop;
  195. #endif
  196. rti;
  197. .LWAIT_HERE:
  198. jump .LWAIT_HERE;
  199. ENDPROC(__start)
  200. ENTRY(_real_start)
  201. [ -- sp ] = reti;
  202. p0.l = lo(WDOGA_CTL);
  203. p0.h = hi(WDOGA_CTL);
  204. r0 = 0xAD6(z);
  205. w[p0] = r0; /* watchdog off for now */
  206. ssync;
  207. /* Code update for BSS size == 0
  208. * Zero out the bss region.
  209. */
  210. p1.l = ___bss_start;
  211. p1.h = ___bss_start;
  212. p2.l = ___bss_stop;
  213. p2.h = ___bss_stop;
  214. r0 = 0;
  215. p2 -= p1;
  216. lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
  217. .L_clear_bss:
  218. B[p1++] = r0;
  219. /* In case there is a NULL pointer reference
  220. * Zero out region before stext
  221. */
  222. p1.l = 0x0;
  223. p1.h = 0x0;
  224. r0.l = __stext;
  225. r0.h = __stext;
  226. r0 = r0 >> 1;
  227. p2 = r0;
  228. r0 = 0;
  229. lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
  230. .L_clear_zero:
  231. W[p1++] = r0;
  232. /* pass the uboot arguments to the global value command line */
  233. R0 = R7;
  234. call _cmdline_init;
  235. p1.l = __rambase;
  236. p1.h = __rambase;
  237. r0.l = __sdata;
  238. r0.h = __sdata;
  239. [p1] = r0;
  240. p1.l = __ramstart;
  241. p1.h = __ramstart;
  242. p3.l = ___bss_stop;
  243. p3.h = ___bss_stop;
  244. r1 = p3;
  245. [p1] = r1;
  246. /*
  247. * load the current thread pointer and stack
  248. */
  249. r1.l = _init_thread_union;
  250. r1.h = _init_thread_union;
  251. r2.l = 0x2000;
  252. r2.h = 0x0000;
  253. r1 = r1 + r2;
  254. sp = r1;
  255. usp = sp;
  256. fp = sp;
  257. jump.l _start_kernel;
  258. ENDPROC(_real_start)
  259. __FINIT
  260. .section .l1.text
  261. #if CONFIG_BFIN_KERNEL_CLOCK
  262. ENTRY(_start_dma_code)
  263. p0.h = hi(SICA_IWR0);
  264. p0.l = lo(SICA_IWR0);
  265. r0.l = 0x1;
  266. [p0] = r0;
  267. SSYNC;
  268. /*
  269. * Set PLL_CTL
  270. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  271. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  272. * - [7] = output delay (add 200ps of delay to mem signals)
  273. * - [6] = input delay (add 200ps of input delay to mem signals)
  274. * - [5] = PDWN : 1=All Clocks off
  275. * - [3] = STOPCK : 1=Core Clock off
  276. * - [1] = PLL_OFF : 1=Disable Power to PLL
  277. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  278. * all other bits set to zero
  279. */
  280. p0.h = hi(PLL_LOCKCNT);
  281. p0.l = lo(PLL_LOCKCNT);
  282. r0 = 0x300(Z);
  283. w[p0] = r0.l;
  284. ssync;
  285. P2.H = hi(EBIU_SDGCTL);
  286. P2.L = lo(EBIU_SDGCTL);
  287. R0 = [P2];
  288. BITSET (R0, 24);
  289. [P2] = R0;
  290. SSYNC;
  291. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  292. r0 = r0 << 9; /* Shift it over, */
  293. r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  294. r0 = r1 | r0;
  295. r1 = PLL_BYPASS; /* Bypass the PLL? */
  296. r1 = r1 << 8; /* Shift it over */
  297. r0 = r1 | r0; /* add them all together */
  298. p0.h = hi(PLL_CTL);
  299. p0.l = lo(PLL_CTL); /* Load the address */
  300. cli r2; /* Disable interrupts */
  301. ssync;
  302. w[p0] = r0.l; /* Set the value */
  303. idle; /* Wait for the PLL to stablize */
  304. sti r2; /* Enable interrupts */
  305. .Lcheck_again:
  306. p0.h = hi(PLL_STAT);
  307. p0.l = lo(PLL_STAT);
  308. R0 = W[P0](Z);
  309. CC = BITTST(R0,5);
  310. if ! CC jump .Lcheck_again;
  311. /* Configure SCLK & CCLK Dividers */
  312. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  313. p0.h = hi(PLL_DIV);
  314. p0.l = lo(PLL_DIV);
  315. w[p0] = r0.l;
  316. ssync;
  317. p0.l = lo(EBIU_SDRRC);
  318. p0.h = hi(EBIU_SDRRC);
  319. r0 = mem_SDRRC;
  320. w[p0] = r0.l;
  321. ssync;
  322. p0.l = LO(EBIU_SDBCTL);
  323. p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
  324. r0 = mem_SDBCTL;
  325. w[p0] = r0.l;
  326. ssync;
  327. P2.H = hi(EBIU_SDGCTL);
  328. P2.L = lo(EBIU_SDGCTL);
  329. R0 = [P2];
  330. BITCLR (R0, 24);
  331. p0.h = hi(EBIU_SDSTAT);
  332. p0.l = lo(EBIU_SDSTAT);
  333. r2.l = w[p0];
  334. cc = bittst(r2,3);
  335. if !cc jump .Lskip;
  336. NOP;
  337. BITSET (R0, 23);
  338. .Lskip:
  339. [P2] = R0;
  340. SSYNC;
  341. R0.L = lo(mem_SDGCTL);
  342. R0.H = hi(mem_SDGCTL);
  343. R1 = [p2];
  344. R1 = R1 | R0;
  345. [P2] = R1;
  346. SSYNC;
  347. RTS;
  348. ENDPROC(_start_dma_code)
  349. #endif /* CONFIG_BFIN_KERNEL_CLOCK */
  350. .data
  351. /*
  352. * Set up the usable of RAM stuff. Size of RAM is determined then
  353. * an initial stack set up at the end.
  354. */
  355. .align 4
  356. __rambase:
  357. .long 0
  358. __ramstart:
  359. .long 0
  360. __ramend:
  361. .long 0