start.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * U-boot - start.S Startup file of u-boot for BF533
  3. *
  4. * Copyright (c) 2005 blackfin.uclinux.org
  5. *
  6. * This file is based on head.S
  7. * Copyright (c) 2003 Metrowerks/Motorola
  8. * Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
  9. * Kenneth Albanowski <kjahds@kjahds.com>,
  10. * The Silver Hammer Group, Ltd.
  11. * (c) 1995, Dionne & Associates
  12. * (c) 1995, DKG Display Tech.
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. /*
  33. * Note: A change in this file subsequently requires a change in
  34. * board/$(board_name)/config.mk for a valid u-boot.bin
  35. */
  36. #define ASSEMBLY
  37. #include <linux/config.h>
  38. #include <asm/blackfin.h>
  39. #include <config.h>
  40. #include <asm/mem_init.h>
  41. #if (CONFIG_CCLK_DIV == 1)
  42. #define CONFIG_CCLK_ACT_DIV CCLK_DIV1
  43. #endif
  44. #if (CONFIG_CCLK_DIV == 2)
  45. #define CONFIG_CCLK_ACT_DIV CCLK_DIV2
  46. #endif
  47. #if (CONFIG_CCLK_DIV == 4)
  48. #define CONFIG_CCLK_ACT_DIV CCLK_DIV4
  49. #endif
  50. #if (CONFIG_CCLK_DIV == 8)
  51. #define CONFIG_CCLK_ACT_DIV CCLK_DIV8
  52. #endif
  53. #ifndef CONFIG_CCLK_ACT_DIV
  54. #define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
  55. #endif
  56. .global _stext;
  57. .global __bss_start;
  58. .global start;
  59. .global _start;
  60. .global _rambase;
  61. .global _ramstart;
  62. .global _ramend;
  63. .global _bf533_data_dest;
  64. .global _bf533_data_size;
  65. .global edata;
  66. .global _initialize;
  67. .global _exit;
  68. .global flashdataend;
  69. .text
  70. _start:
  71. start:
  72. _stext:
  73. R0 = 0x30;
  74. SYSCFG = R0;
  75. SSYNC;
  76. /* As per HW reference manual DAG registers,
  77. * DATA and Address resgister shall be zero'd
  78. * in initialization, after a reset state
  79. */
  80. r1 = 0; /* Data registers zero'd */
  81. r2 = 0;
  82. r3 = 0;
  83. r4 = 0;
  84. r5 = 0;
  85. r6 = 0;
  86. r7 = 0;
  87. p0 = 0; /* Address registers zero'd */
  88. p1 = 0;
  89. p2 = 0;
  90. p3 = 0;
  91. p4 = 0;
  92. p5 = 0;
  93. i0 = 0; /* DAG Registers zero'd */
  94. i1 = 0;
  95. i2 = 0;
  96. i3 = 0;
  97. m0 = 0;
  98. m1 = 0;
  99. m3 = 0;
  100. m3 = 0;
  101. l0 = 0;
  102. l1 = 0;
  103. l2 = 0;
  104. l3 = 0;
  105. b0 = 0;
  106. b1 = 0;
  107. b2 = 0;
  108. b3 = 0;
  109. /* Set loop counters to zero, to make sure that
  110. * hw loops are disabled.
  111. */
  112. lc0 = 0;
  113. lc1 = 0;
  114. SSYNC;
  115. /* Check soft reset status */
  116. p0.h = SWRST >> 16;
  117. p0.l = SWRST & 0xFFFF;
  118. r0.l = w[p0];
  119. cc = bittst(r0, 15);
  120. if !cc jump no_soft_reset;
  121. /* Clear Soft reset */
  122. r0 = 0x0000;
  123. w[p0] = r0;
  124. ssync;
  125. no_soft_reset:
  126. nop;
  127. /* Clear EVT registers */
  128. p0.h = (EVT_EMULATION_ADDR >> 16);
  129. p0.l = (EVT_EMULATION_ADDR & 0xFFFF);
  130. p0 += 8;
  131. p1 = 14;
  132. r1 = 0;
  133. LSETUP(4,4) lc0 = p1;
  134. [ p0 ++ ] = r1;
  135. /*
  136. * Set PLL_CTL
  137. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  138. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  139. * - [7] = output delay (add 200ps of delay to mem signals)
  140. * - [6] = input delay (add 200ps of input delay to mem signals)
  141. * - [5] = PDWN : 1=All Clocks off
  142. * - [3] = STOPCK : 1=Core Clock off
  143. * - [1] = PLL_OFF : 1=Disable Power to PLL
  144. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  145. * all other bits set to zero
  146. */
  147. r0 = CONFIG_VCO_MULT; /* Load the VCO multiplier */
  148. r0 = r0 << 9; /* Shift it over */
  149. r1 = CONFIG_CLKIN_HALF; /* Do we need to divide CLKIN by 2? */
  150. r0 = r1 | r0;
  151. r1 = CONFIG_PLL_BYPASS; /* Bypass the PLL? */
  152. r1 = r1 << 8; /* Shift it over */
  153. r0 = r1 | r0; /* add them all together */
  154. p0.h = (PLL_CTL >> 16);
  155. p0.l = (PLL_CTL & 0xFFFF); /* Load the address */
  156. cli r2; /* Disable interrupts */
  157. w[p0] = r0; /* Set the value */
  158. idle; /* Wait for the PLL to stablize */
  159. sti r2; /* Enable interrupts */
  160. ssync;
  161. /*
  162. * Turn on the CYCLES COUNTER
  163. */
  164. r2 = SYSCFG;
  165. BITSET (r2,1);
  166. SYSCFG = r2;
  167. /* Configure SCLK & CCLK Dividers */
  168. r0 = CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV;
  169. p0.h = (PLL_DIV >> 16);
  170. p0.l = (PLL_DIV & 0xFFFF);
  171. w[p0] = r0;
  172. ssync;
  173. wait_for_pll_stab:
  174. p0.h = (PLL_STAT >> 16);
  175. p0.l = (PLL_STAT & 0xFFFF);
  176. r0.l = w[p0];
  177. cc = bittst(r0,5);
  178. if !cc jump wait_for_pll_stab;
  179. /* Configure SDRAM if SDRAM is already not enabled */
  180. p0.l = (EBIU_SDSTAT & 0xFFFF);
  181. p0.h = (EBIU_SDSTAT >> 16);
  182. r0.l = w[p0];
  183. cc = bittst(r0, 3);
  184. if !cc jump skip_sdram_enable;
  185. /* SDRAM initialization */
  186. p0.l = (EBIU_SDGCTL & 0xFFFF);
  187. p0.h = (EBIU_SDGCTL >> 16); /* SDRAM Memory Global Control Register */
  188. r0.h = (mem_SDGCTL >> 16);
  189. r0.l = (mem_SDGCTL & 0xFFFF);
  190. [p0] = r0;
  191. ssync;
  192. p0.l = (EBIU_SDBCTL & 0xFFFF);
  193. p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */
  194. r0 = mem_SDBCTL;
  195. w[p0] = r0.l;
  196. ssync;
  197. p0.l = (EBIU_SDRRC & 0xFFFF);
  198. p0.h = (EBIU_SDRRC >> 16); /* SDRAM Refresh Rate Control Register */
  199. r0 = mem_SDRRC;
  200. w[p0] = r0.l;
  201. ssync;
  202. skip_sdram_enable:
  203. nop;
  204. #ifndef CFG_NO_FLASH
  205. /* relocate into to RAM */
  206. p1.l = (CFG_FLASH_BASE & 0xffff);
  207. p1.h = (CFG_FLASH_BASE >> 16);
  208. p2.l = (CFG_MONITOR_BASE & 0xffff);
  209. p2.h = (CFG_MONITOR_BASE >> 16);
  210. r0.l = (CFG_MONITOR_LEN & 0xffff);
  211. r0.h = (CFG_MONITOR_LEN >> 16);
  212. loop1:
  213. r1 = [p1];
  214. [p2] = r1;
  215. p3=0x4;
  216. p1=p1+p3;
  217. p2=p2+p3;
  218. r2=0x4;
  219. r0=r0-r2;
  220. cc=r0==0x0;
  221. if !cc jump loop1;
  222. #endif
  223. /*
  224. * configure STACK
  225. */
  226. r0.h = (CONFIG_STACKBASE >> 16);
  227. r0.l = (CONFIG_STACKBASE & 0xFFFF);
  228. sp = r0;
  229. fp = sp;
  230. /*
  231. * This next section keeps the processor in supervisor mode
  232. * during kernel boot. Switches to user mode at end of boot.
  233. * See page 3-9 of Hardware Reference manual for documentation.
  234. */
  235. /* To keep ourselves in the supervisor mode */
  236. p0.l = (EVT_IVG15_ADDR & 0xFFFF);
  237. p0.h = (EVT_IVG15_ADDR >> 16);
  238. p1.l = _real_start;
  239. p1.h = _real_start;
  240. [p0] = p1;
  241. p0.l = (IMASK & 0xFFFF);
  242. p0.h = (IMASK >> 16);
  243. r0 = IVG15_POS;
  244. [p0] = r0;
  245. raise 15;
  246. p0.l = WAIT_HERE;
  247. p0.h = WAIT_HERE;
  248. reti = p0;
  249. rti;
  250. WAIT_HERE:
  251. jump WAIT_HERE;
  252. .global _real_start;
  253. _real_start:
  254. [ -- sp ] = reti;
  255. #ifdef CONFIG_EZKIT533
  256. p0.l = (WDOG_CTL & 0xFFFF);
  257. p0.h = (WDOG_CTL >> 16);
  258. r0 = WATCHDOG_DISABLE(z);
  259. w[p0] = r0;
  260. #endif
  261. /* Code for initializing Async mem banks */
  262. p2.h = (EBIU_AMBCTL1 >> 16);
  263. p2.l = (EBIU_AMBCTL1 & 0xFFFF);
  264. r0.h = (AMBCTL1VAL >> 16);
  265. r0.l = (AMBCTL1VAL & 0xFFFF);
  266. [p2] = r0;
  267. ssync;
  268. p2.h = (EBIU_AMBCTL0 >> 16);
  269. p2.l = (EBIU_AMBCTL0 & 0xFFFF);
  270. r0.h = (AMBCTL0VAL >> 16);
  271. r0.l = (AMBCTL0VAL & 0xFFFF);
  272. [p2] = r0;
  273. ssync;
  274. p2.h = (EBIU_AMGCTL >> 16);
  275. p2.l = (EBIU_AMGCTL & 0xffff);
  276. r0 = AMGCTLVAL;
  277. w[p2] = r0;
  278. ssync;
  279. /* DMA reset code to Hi of L1 SRAM */
  280. copy:
  281. P1.H = hi(SYSMMR_BASE); /* P1 Points to the beginning of SYSTEM MMR Space */
  282. P1.L = lo(SYSMMR_BASE);
  283. R0.H = reset_start; /* Source Address (high) */
  284. R0.L = reset_start; /* Source Address (low) */
  285. R1.H = reset_end;
  286. R1.L = reset_end;
  287. R2 = R1 - R0; /* Count */
  288. R1.H = hi(L1_ISRAM); /* Destination Address (high) */
  289. R1.L = lo(L1_ISRAM); /* Destination Address (low) */
  290. R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
  291. R4.L = (DI_EN | WNR | DMAEN); /* Destination DMAConfig Value (8-bit words) */
  292. DMA:
  293. R6 = 0x1 (Z);
  294. W[P1+OFFSET_(MDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
  295. W[P1+OFFSET_(MDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
  296. [P1+OFFSET_(MDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
  297. W[P1+OFFSET_(MDMA_S0_X_COUNT)] = R2; /* Set Source Count */
  298. /* Set Source DMAConfig = DMA Enable,
  299. Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
  300. W[P1+OFFSET_(MDMA_S0_CONFIG)] = R3;
  301. [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
  302. W[P1+OFFSET_(MDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
  303. /* Set Destination DMAConfig = DMA Enable,
  304. Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
  305. W[P1+OFFSET_(MDMA_D0_CONFIG)] = R4;
  306. IDLE; /* Wait for DMA to Complete */
  307. R0 = 0x1;
  308. W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0; /* Write 1 to clear DMA interrupt */
  309. /* DMA reset code to DATA BANK A which uses this port
  310. * to avoid following problem
  311. * " Data from a Data Cache fill can be corrupoted after or during
  312. * instruction DMA if certain core stalls exist"
  313. */
  314. copy_as_data:
  315. R0.H = reset_start; /* Source Address (high) */
  316. R0.L = reset_start; /* Source Address (low) */
  317. R1.H = reset_end;
  318. R1.L = reset_end;
  319. R2 = R1 - R0; /* Count */
  320. R1.H = hi(DATA_BANKA_SRAM); /* Destination Address (high) */
  321. R1.L = lo(DATA_BANKA_SRAM); /* Destination Address (low) */
  322. R3.L = DMAEN; /* Source DMAConfig Value (8-bit words) */
  323. R4.L = (DI_EN | WNR | DMAEN); /* Destination DMAConfig Value (8-bit words) */
  324. DMA_DATA:
  325. R6 = 0x1 (Z);
  326. W[P1+OFFSET_(MDMA_S0_X_MODIFY)] = R6; /* Source Modify = 1 */
  327. W[P1+OFFSET_(MDMA_D0_X_MODIFY)] = R6; /* Destination Modify = 1 */
  328. [P1+OFFSET_(MDMA_S0_START_ADDR)] = R0; /* Set Source Base Address */
  329. W[P1+OFFSET_(MDMA_S0_X_COUNT)] = R2; /* Set Source Count */
  330. /* Set Source DMAConfig = DMA Enable,
  331. Memory Read, 8-Bit Transfers, 1-D DMA, Flow - Stop */
  332. W[P1+OFFSET_(MDMA_S0_CONFIG)] = R3;
  333. [P1+OFFSET_(MDMA_D0_START_ADDR)] = R1; /* Set Destination Base Address */
  334. W[P1+OFFSET_(MDMA_D0_X_COUNT)] = R2; /* Set Destination Count */
  335. /* Set Destination DMAConfig = DMA Enable,
  336. Memory Write, 8-Bit Transfers, 1-D DMA, Flow - Stop, IOC */
  337. W[P1+OFFSET_(MDMA_D0_CONFIG)] = R4;
  338. IDLE; /* Wait for DMA to Complete */
  339. R0 = 0x1;
  340. W[P1+OFFSET_(MDMA_D0_IRQ_STATUS)] = R0; /* Write 1 to clear DMA interrupt */
  341. copy_end: nop;
  342. /* Initialize BSS Section with 0 s */
  343. p1.l = __bss_start;
  344. p1.h = __bss_start;
  345. p2.l = _end;
  346. p2.h = _end;
  347. r1 = p1;
  348. r2 = p2;
  349. r3 = r2 - r1;
  350. r3 = r3 >> 2;
  351. p3 = r3;
  352. lsetup (_clear_bss, _clear_bss_end ) lc1 = p3;
  353. CC = p2<=p1;
  354. if CC jump _clear_bss_skip;
  355. r0 = 0;
  356. _clear_bss:
  357. _clear_bss_end:
  358. [p1++] = r0;
  359. _clear_bss_skip:
  360. p0.l = _start1;
  361. p0.h = _start1;
  362. jump (p0);
  363. reset_start:
  364. p0.h = WDOG_CNT >> 16;
  365. p0.l = WDOG_CNT & 0xffff;
  366. r0 = 0x0010;
  367. w[p0] = r0;
  368. p0.h = WDOG_CTL >> 16;
  369. p0.l = WDOG_CTL & 0xffff;
  370. r0 = 0x0000;
  371. w[p0] = r0;
  372. reset_wait:
  373. jump reset_wait;
  374. reset_end: nop;
  375. _exit:
  376. jump.s _exit;