head.S 9.8 KB

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