head.S 9.1 KB

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