head.S 9.9 KB

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