head.S 9.7 KB

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