head.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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/mem_init.h>
  35. #endif
  36. .global __rambase
  37. .global __ramstart
  38. .global __ramend
  39. .extern ___bss_stop
  40. .extern ___bss_start
  41. .extern _bf53x_relocate_l1_mem
  42. #define INITIAL_STACK 0xFFB01000
  43. __INIT
  44. ENTRY(__start)
  45. /* R0: argument of command line string, passed from uboot, save it */
  46. R7 = R0;
  47. /* Set the SYSCFG register:
  48. * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
  49. */
  50. R0 = 0x36;
  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_start(p0,r0);
  86. P0 = R1;
  87. R0 = R1;
  88. /* Turn off the icache */
  89. p0.l = (IMEM_CONTROL & 0xFFFF);
  90. p0.h = (IMEM_CONTROL >> 16);
  91. R1 = [p0];
  92. R0 = ~ENICPLB;
  93. R0 = R0 & R1;
  94. /* Anomaly 05000125 */
  95. #ifdef ANOMALY_05000125
  96. CLI R2;
  97. SSYNC;
  98. #endif
  99. [p0] = R0;
  100. SSYNC;
  101. #ifdef ANOMALY_05000125
  102. STI R2;
  103. #endif
  104. /* Turn off the dcache */
  105. p0.l = (DMEM_CONTROL & 0xFFFF);
  106. p0.h = (DMEM_CONTROL >> 16);
  107. R1 = [p0];
  108. R0 = ~ENDCPLB;
  109. R0 = R0 & R1;
  110. /* Anomaly 05000125 */
  111. #ifdef ANOMALY_05000125
  112. CLI R2;
  113. SSYNC;
  114. #endif
  115. [p0] = R0;
  116. SSYNC;
  117. #ifdef ANOMALY_05000125
  118. STI R2;
  119. #endif
  120. /* Initialise UART - when booting from u-boot, the UART is not disabled
  121. * so if we dont initalize here, our serial console gets hosed */
  122. p0.h = hi(UART_LCR);
  123. p0.l = lo(UART_LCR);
  124. r0 = 0x0(Z);
  125. w[p0] = r0.L; /* To enable DLL writes */
  126. ssync;
  127. p0.h = hi(UART_DLL);
  128. p0.l = lo(UART_DLL);
  129. r0 = 0x0(Z);
  130. w[p0] = r0.L;
  131. ssync;
  132. p0.h = hi(UART_DLH);
  133. p0.l = lo(UART_DLH);
  134. r0 = 0x00(Z);
  135. w[p0] = r0.L;
  136. ssync;
  137. p0.h = hi(UART_GCTL);
  138. p0.l = lo(UART_GCTL);
  139. r0 = 0x0(Z);
  140. w[p0] = r0.L; /* To enable UART clock */
  141. ssync;
  142. /* Initialize stack pointer */
  143. sp.l = lo(INITIAL_STACK);
  144. sp.h = hi(INITIAL_STACK);
  145. fp = sp;
  146. usp = sp;
  147. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  148. call _bf53x_relocate_l1_mem;
  149. #if CONFIG_BFIN_KERNEL_CLOCK
  150. call _start_dma_code;
  151. #endif
  152. /* Code for initializing Async memory banks */
  153. p2.h = hi(EBIU_AMBCTL1);
  154. p2.l = lo(EBIU_AMBCTL1);
  155. r0.h = hi(AMBCTL1VAL);
  156. r0.l = lo(AMBCTL1VAL);
  157. [p2] = r0;
  158. ssync;
  159. p2.h = hi(EBIU_AMBCTL0);
  160. p2.l = lo(EBIU_AMBCTL0);
  161. r0.h = hi(AMBCTL0VAL);
  162. r0.l = lo(AMBCTL0VAL);
  163. [p2] = r0;
  164. ssync;
  165. p2.h = hi(EBIU_AMGCTL);
  166. p2.l = lo(EBIU_AMGCTL);
  167. r0 = AMGCTLVAL;
  168. w[p2] = r0;
  169. ssync;
  170. /* This section keeps the processor in supervisor mode
  171. * during kernel boot. Switches to user mode at end of boot.
  172. * See page 3-9 of Hardware Reference manual for documentation.
  173. */
  174. /* EVT15 = _real_start */
  175. p0.l = lo(EVT15);
  176. p0.h = hi(EVT15);
  177. p1.l = _real_start;
  178. p1.h = _real_start;
  179. [p0] = p1;
  180. csync;
  181. p0.l = lo(IMASK);
  182. p0.h = hi(IMASK);
  183. p1.l = IMASK_IVG15;
  184. p1.h = 0x0;
  185. [p0] = p1;
  186. csync;
  187. raise 15;
  188. p0.l = .LWAIT_HERE;
  189. p0.h = .LWAIT_HERE;
  190. reti = p0;
  191. #if defined(ANOMALY_05000281)
  192. nop; nop; nop;
  193. #endif
  194. rti;
  195. .LWAIT_HERE:
  196. jump .LWAIT_HERE;
  197. ENDPROC(__start)
  198. ENTRY(_real_start)
  199. [ -- sp ] = reti;
  200. p0.l = lo(WDOGA_CTL);
  201. p0.h = hi(WDOGA_CTL);
  202. r0 = 0xAD6(z);
  203. w[p0] = r0; /* watchdog off for now */
  204. ssync;
  205. /* Code update for BSS size == 0
  206. * Zero out the bss region.
  207. */
  208. p1.l = ___bss_start;
  209. p1.h = ___bss_start;
  210. p2.l = ___bss_stop;
  211. p2.h = ___bss_stop;
  212. r0 = 0;
  213. p2 -= p1;
  214. lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
  215. .L_clear_bss:
  216. B[p1++] = r0;
  217. /* In case there is a NULL pointer reference
  218. * Zero out region before stext
  219. */
  220. p1.l = 0x0;
  221. p1.h = 0x0;
  222. r0.l = __stext;
  223. r0.h = __stext;
  224. r0 = r0 >> 1;
  225. p2 = r0;
  226. r0 = 0;
  227. lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
  228. .L_clear_zero:
  229. W[p1++] = r0;
  230. /* pass the uboot arguments to the global value command line */
  231. R0 = R7;
  232. call _cmdline_init;
  233. p1.l = __rambase;
  234. p1.h = __rambase;
  235. r0.l = __sdata;
  236. r0.h = __sdata;
  237. [p1] = r0;
  238. p1.l = __ramstart;
  239. p1.h = __ramstart;
  240. p3.l = ___bss_stop;
  241. p3.h = ___bss_stop;
  242. r1 = p3;
  243. [p1] = r1;
  244. /*
  245. * load the current thread pointer and stack
  246. */
  247. r1.l = _init_thread_union;
  248. r1.h = _init_thread_union;
  249. r2.l = 0x2000;
  250. r2.h = 0x0000;
  251. r1 = r1 + r2;
  252. sp = r1;
  253. usp = sp;
  254. fp = sp;
  255. jump.l _start_kernel;
  256. ENDPROC(_real_start)
  257. __FINIT
  258. .section .l1.text
  259. #if CONFIG_BFIN_KERNEL_CLOCK
  260. ENTRY(_start_dma_code)
  261. p0.h = hi(SICA_IWR0);
  262. p0.l = lo(SICA_IWR0);
  263. r0.l = 0x1;
  264. [p0] = r0;
  265. SSYNC;
  266. /*
  267. * Set PLL_CTL
  268. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  269. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  270. * - [7] = output delay (add 200ps of delay to mem signals)
  271. * - [6] = input delay (add 200ps of input delay to mem signals)
  272. * - [5] = PDWN : 1=All Clocks off
  273. * - [3] = STOPCK : 1=Core Clock off
  274. * - [1] = PLL_OFF : 1=Disable Power to PLL
  275. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  276. * all other bits set to zero
  277. */
  278. p0.h = hi(PLL_LOCKCNT);
  279. p0.l = lo(PLL_LOCKCNT);
  280. r0 = 0x300(Z);
  281. w[p0] = r0.l;
  282. ssync;
  283. P2.H = hi(EBIU_SDGCTL);
  284. P2.L = lo(EBIU_SDGCTL);
  285. R0 = [P2];
  286. BITSET (R0, 24);
  287. [P2] = R0;
  288. SSYNC;
  289. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  290. r0 = r0 << 9; /* Shift it over, */
  291. r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  292. r0 = r1 | r0;
  293. r1 = PLL_BYPASS; /* Bypass the PLL? */
  294. r1 = r1 << 8; /* Shift it over */
  295. r0 = r1 | r0; /* add them all together */
  296. p0.h = hi(PLL_CTL);
  297. p0.l = lo(PLL_CTL); /* Load the address */
  298. cli r2; /* Disable interrupts */
  299. ssync;
  300. w[p0] = r0.l; /* Set the value */
  301. idle; /* Wait for the PLL to stablize */
  302. sti r2; /* Enable interrupts */
  303. .Lcheck_again:
  304. p0.h = hi(PLL_STAT);
  305. p0.l = lo(PLL_STAT);
  306. R0 = W[P0](Z);
  307. CC = BITTST(R0,5);
  308. if ! CC jump .Lcheck_again;
  309. /* Configure SCLK & CCLK Dividers */
  310. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  311. p0.h = hi(PLL_DIV);
  312. p0.l = lo(PLL_DIV);
  313. w[p0] = r0.l;
  314. ssync;
  315. p0.l = lo(EBIU_SDRRC);
  316. p0.h = hi(EBIU_SDRRC);
  317. r0 = mem_SDRRC;
  318. w[p0] = r0.l;
  319. ssync;
  320. p0.l = (EBIU_SDBCTL & 0xFFFF);
  321. p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */
  322. r0 = mem_SDBCTL;
  323. w[p0] = r0.l;
  324. ssync;
  325. P2.H = hi(EBIU_SDGCTL);
  326. P2.L = lo(EBIU_SDGCTL);
  327. R0 = [P2];
  328. BITCLR (R0, 24);
  329. p0.h = hi(EBIU_SDSTAT);
  330. p0.l = lo(EBIU_SDSTAT);
  331. r2.l = w[p0];
  332. cc = bittst(r2,3);
  333. if !cc jump .Lskip;
  334. NOP;
  335. BITSET (R0, 23);
  336. .Lskip:
  337. [P2] = R0;
  338. SSYNC;
  339. R0.L = lo(mem_SDGCTL);
  340. R0.H = hi(mem_SDGCTL);
  341. R1 = [p2];
  342. R1 = R1 | R0;
  343. [P2] = R1;
  344. SSYNC;
  345. RTS;
  346. ENDPROC(_start_dma_code)
  347. #endif /* CONFIG_BFIN_KERNEL_CLOCK */
  348. ENTRY(_bfin_reset)
  349. /* No more interrupts to be handled*/
  350. CLI R6;
  351. SSYNC;
  352. #if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
  353. p0.h = hi(FIO_INEN);
  354. p0.l = lo(FIO_INEN);
  355. r0.l = ~(PF1 | PF0);
  356. w[p0] = r0.l;
  357. p0.h = hi(FIO_DIR);
  358. p0.l = lo(FIO_DIR);
  359. r0.l = (PF1 | PF0);
  360. w[p0] = r0.l;
  361. p0.h = hi(FIO_FLAG_C);
  362. p0.l = lo(FIO_FLAG_C);
  363. r0.l = (PF1 | PF0);
  364. w[p0] = r0.l;
  365. #endif
  366. /* Clear the IMASK register */
  367. p0.h = hi(IMASK);
  368. p0.l = lo(IMASK);
  369. r0 = 0x0;
  370. [p0] = r0;
  371. /* Clear the ILAT register */
  372. p0.h = hi(ILAT);
  373. p0.l = lo(ILAT);
  374. r0 = [p0];
  375. [p0] = r0;
  376. SSYNC;
  377. /* make sure SYSCR is set to use BMODE */
  378. P0.h = hi(SYSCR);
  379. P0.l = lo(SYSCR);
  380. R0.l = 0x20; /* on BF561, disable core b */
  381. W[P0] = R0.l;
  382. SSYNC;
  383. /* issue a system soft reset */
  384. P1.h = hi(SWRST);
  385. P1.l = lo(SWRST);
  386. R1.l = 0x0007;
  387. W[P1] = R1;
  388. SSYNC;
  389. /* clear system soft reset */
  390. R0.l = 0x0000;
  391. W[P0] = R0;
  392. SSYNC;
  393. /* issue core reset */
  394. raise 1;
  395. RTS;
  396. ENDPROC(_bfin_reset)
  397. .data
  398. /*
  399. * Set up the usable of RAM stuff. Size of RAM is determined then
  400. * an initial stack set up at the end.
  401. */
  402. .align 4
  403. __rambase:
  404. .long 0
  405. __ramstart:
  406. .long 0
  407. __ramend:
  408. .long 0