head.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * File: arch/blackfin/mach-bf537/head.S
  3. * Based on: arch/blackfin/mach-bf533/head.S
  4. * Author: Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne
  5. *
  6. * Created: 1998
  7. * Description: Startup code for Blackfin BF537
  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. #include <asm/trace.h>
  33. #if CONFIG_BFIN_KERNEL_CLOCK
  34. #include <asm/mach-common/clocks.h>
  35. #include <asm/mach/mem_init.h>
  36. #endif
  37. .global __rambase
  38. .global __ramstart
  39. .global __ramend
  40. .extern ___bss_stop
  41. .extern ___bss_start
  42. .extern _bf53x_relocate_l1_mem
  43. #define INITIAL_STACK 0xFFB01000
  44. __INIT
  45. ENTRY(__start)
  46. /* R0: argument of command line string, passed from uboot, save it */
  47. R7 = R0;
  48. /* Set the SYSCFG register:
  49. * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit)
  50. */
  51. R0 = 0x36;
  52. SYSCFG = R0;
  53. R0 = 0;
  54. /* Clear Out All the data and pointer Registers */
  55. R1 = R0;
  56. R2 = R0;
  57. R3 = R0;
  58. R4 = R0;
  59. R5 = R0;
  60. R6 = R0;
  61. P0 = R0;
  62. P1 = R0;
  63. P2 = R0;
  64. P3 = R0;
  65. P4 = R0;
  66. P5 = R0;
  67. LC0 = r0;
  68. LC1 = r0;
  69. L0 = r0;
  70. L1 = r0;
  71. L2 = r0;
  72. L3 = r0;
  73. /* Clear Out All the DAG Registers */
  74. B0 = r0;
  75. B1 = r0;
  76. B2 = r0;
  77. B3 = r0;
  78. I0 = r0;
  79. I1 = r0;
  80. I2 = r0;
  81. I3 = r0;
  82. M0 = r0;
  83. M1 = r0;
  84. M2 = r0;
  85. M3 = r0;
  86. trace_buffer_start(p0,r0);
  87. P0 = R1;
  88. R0 = R1;
  89. /* Turn off the icache */
  90. p0.l = LO(IMEM_CONTROL);
  91. p0.h = HI(IMEM_CONTROL);
  92. R1 = [p0];
  93. R0 = ~ENICPLB;
  94. R0 = R0 & R1;
  95. /* Anomaly 05000125 */
  96. #if ANOMALY_05000125
  97. CLI R2;
  98. SSYNC;
  99. #endif
  100. [p0] = R0;
  101. SSYNC;
  102. #if ANOMALY_05000125
  103. STI R2;
  104. #endif
  105. /* Turn off the dcache */
  106. p0.l = LO(DMEM_CONTROL);
  107. p0.h = HI(DMEM_CONTROL);
  108. R1 = [p0];
  109. R0 = ~ENDCPLB;
  110. R0 = R0 & R1;
  111. /* Anomaly 05000125 */
  112. #if ANOMALY_05000125
  113. CLI R2;
  114. SSYNC;
  115. #endif
  116. [p0] = R0;
  117. SSYNC;
  118. #if ANOMALY_05000125
  119. STI R2;
  120. #endif
  121. /* Initialise General-Purpose I/O Modules on BF537 */
  122. /* Rev 0.0 Anomaly 05000212 - PORTx_FER,
  123. * PORT_MUX Registers Do Not accept "writes" correctly:
  124. */
  125. p0.h = hi(BFIN_PORT_MUX);
  126. p0.l = lo(BFIN_PORT_MUX);
  127. #if ANOMALY_05000212
  128. R0.L = W[P0]; /* Read */
  129. SSYNC;
  130. #endif
  131. R0 = (PGDE_UART | PFTE_UART)(Z);
  132. #if ANOMALY_05000212
  133. W[P0] = R0.L; /* Write */
  134. SSYNC;
  135. #endif
  136. W[P0] = R0.L; /* Enable both UARTS */
  137. SSYNC;
  138. p0.h = hi(PORTF_FER);
  139. p0.l = lo(PORTF_FER);
  140. #if ANOMALY_05000212
  141. R0.L = W[P0]; /* Read */
  142. SSYNC;
  143. #endif
  144. R0 = 0x000F(Z);
  145. #if ANOMALY_05000212
  146. W[P0] = R0.L; /* Write */
  147. SSYNC;
  148. #endif
  149. /* Enable peripheral function of PORTF for UART0 and UART1 */
  150. W[P0] = R0.L;
  151. SSYNC;
  152. #if !defined(CONFIG_BF534)
  153. p0.h = hi(EMAC_SYSTAT);
  154. p0.l = lo(EMAC_SYSTAT);
  155. R0.h = 0xFFFF; /* Clear EMAC Interrupt Status bits */
  156. R0.l = 0xFFFF;
  157. [P0] = R0;
  158. SSYNC;
  159. #endif
  160. #ifdef CONFIG_BF537_PORT_H
  161. p0.h = hi(PORTH_FER);
  162. p0.l = lo(PORTH_FER);
  163. R0.L = W[P0]; /* Read */
  164. SSYNC;
  165. R0 = 0x0000;
  166. W[P0] = R0.L; /* Write */
  167. SSYNC;
  168. W[P0] = R0.L; /* Disable peripheral function of PORTH */
  169. SSYNC;
  170. #endif
  171. /* Initialise UART - when booting from u-boot, the UART is not disabled
  172. * so if we dont initalize here, our serial console gets hosed */
  173. p0.h = hi(UART_LCR);
  174. p0.l = lo(UART_LCR);
  175. r0 = 0x0(Z);
  176. w[p0] = r0.L; /* To enable DLL writes */
  177. ssync;
  178. p0.h = hi(UART_DLL);
  179. p0.l = lo(UART_DLL);
  180. r0 = 0x0(Z);
  181. w[p0] = r0.L;
  182. ssync;
  183. p0.h = hi(UART_DLH);
  184. p0.l = lo(UART_DLH);
  185. r0 = 0x00(Z);
  186. w[p0] = r0.L;
  187. ssync;
  188. p0.h = hi(UART_GCTL);
  189. p0.l = lo(UART_GCTL);
  190. r0 = 0x0(Z);
  191. w[p0] = r0.L; /* To enable UART clock */
  192. ssync;
  193. /* Initialize stack pointer */
  194. sp.l = lo(INITIAL_STACK);
  195. sp.h = hi(INITIAL_STACK);
  196. fp = sp;
  197. usp = sp;
  198. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  199. call _bf53x_relocate_l1_mem;
  200. #if CONFIG_BFIN_KERNEL_CLOCK
  201. call _start_dma_code;
  202. #endif
  203. /* Code for initializing Async memory banks */
  204. p2.h = hi(EBIU_AMBCTL1);
  205. p2.l = lo(EBIU_AMBCTL1);
  206. r0.h = hi(AMBCTL1VAL);
  207. r0.l = lo(AMBCTL1VAL);
  208. [p2] = r0;
  209. ssync;
  210. p2.h = hi(EBIU_AMBCTL0);
  211. p2.l = lo(EBIU_AMBCTL0);
  212. r0.h = hi(AMBCTL0VAL);
  213. r0.l = lo(AMBCTL0VAL);
  214. [p2] = r0;
  215. ssync;
  216. p2.h = hi(EBIU_AMGCTL);
  217. p2.l = lo(EBIU_AMGCTL);
  218. r0 = AMGCTLVAL;
  219. w[p2] = r0;
  220. ssync;
  221. /* This section keeps the processor in supervisor mode
  222. * during kernel boot. Switches to user mode at end of boot.
  223. * See page 3-9 of Hardware Reference manual for documentation.
  224. */
  225. /* EVT15 = _real_start */
  226. p0.l = lo(EVT15);
  227. p0.h = hi(EVT15);
  228. p1.l = _real_start;
  229. p1.h = _real_start;
  230. [p0] = p1;
  231. csync;
  232. p0.l = lo(IMASK);
  233. p0.h = hi(IMASK);
  234. p1.l = IMASK_IVG15;
  235. p1.h = 0x0;
  236. [p0] = p1;
  237. csync;
  238. raise 15;
  239. p0.l = .LWAIT_HERE;
  240. p0.h = .LWAIT_HERE;
  241. reti = p0;
  242. #if ANOMALY_05000281
  243. nop; nop; nop;
  244. #endif
  245. rti;
  246. .LWAIT_HERE:
  247. jump .LWAIT_HERE;
  248. ENDPROC(__start)
  249. ENTRY(_real_start)
  250. [ -- sp ] = reti;
  251. p0.l = lo(WDOG_CTL);
  252. p0.h = hi(WDOG_CTL);
  253. r0 = 0xAD6(z);
  254. w[p0] = r0; /* watchdog off for now */
  255. ssync;
  256. /* Code update for BSS size == 0
  257. * Zero out the bss region.
  258. */
  259. p1.l = ___bss_start;
  260. p1.h = ___bss_start;
  261. p2.l = ___bss_stop;
  262. p2.h = ___bss_stop;
  263. r0 = 0;
  264. p2 -= p1;
  265. lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
  266. .L_clear_bss:
  267. B[p1++] = r0;
  268. /* In case there is a NULL pointer reference
  269. * Zero out region before stext
  270. */
  271. p1.l = 0x0;
  272. p1.h = 0x0;
  273. r0.l = __stext;
  274. r0.h = __stext;
  275. r0 = r0 >> 1;
  276. p2 = r0;
  277. r0 = 0;
  278. lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
  279. .L_clear_zero:
  280. W[p1++] = r0;
  281. /* pass the uboot arguments to the global value command line */
  282. R0 = R7;
  283. call _cmdline_init;
  284. p1.l = __rambase;
  285. p1.h = __rambase;
  286. r0.l = __sdata;
  287. r0.h = __sdata;
  288. [p1] = r0;
  289. p1.l = __ramstart;
  290. p1.h = __ramstart;
  291. p3.l = ___bss_stop;
  292. p3.h = ___bss_stop;
  293. r1 = p3;
  294. [p1] = r1;
  295. /*
  296. * load the current thread pointer and stack
  297. */
  298. r1.l = _init_thread_union;
  299. r1.h = _init_thread_union;
  300. r2.l = 0x2000;
  301. r2.h = 0x0000;
  302. r1 = r1 + r2;
  303. sp = r1;
  304. usp = sp;
  305. fp = sp;
  306. jump.l _start_kernel;
  307. ENDPROC(_real_start)
  308. __FINIT
  309. .section .l1.text
  310. #if CONFIG_BFIN_KERNEL_CLOCK
  311. ENTRY(_start_dma_code)
  312. /* Enable PHY CLK buffer output */
  313. p0.h = hi(VR_CTL);
  314. p0.l = lo(VR_CTL);
  315. r0.l = w[p0];
  316. bitset(r0, 14);
  317. w[p0] = r0.l;
  318. ssync;
  319. p0.h = hi(SIC_IWR);
  320. p0.l = lo(SIC_IWR);
  321. r0.l = 0x1;
  322. r0.h = 0x0;
  323. [p0] = r0;
  324. SSYNC;
  325. /*
  326. * Set PLL_CTL
  327. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  328. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  329. * - [7] = output delay (add 200ps of delay to mem signals)
  330. * - [6] = input delay (add 200ps of input delay to mem signals)
  331. * - [5] = PDWN : 1=All Clocks off
  332. * - [3] = STOPCK : 1=Core Clock off
  333. * - [1] = PLL_OFF : 1=Disable Power to PLL
  334. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  335. * all other bits set to zero
  336. */
  337. p0.h = hi(PLL_LOCKCNT);
  338. p0.l = lo(PLL_LOCKCNT);
  339. r0 = 0x300(Z);
  340. w[p0] = r0.l;
  341. ssync;
  342. P2.H = hi(EBIU_SDGCTL);
  343. P2.L = lo(EBIU_SDGCTL);
  344. R0 = [P2];
  345. BITSET (R0, 24);
  346. [P2] = R0;
  347. SSYNC;
  348. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  349. r0 = r0 << 9; /* Shift it over, */
  350. r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  351. r0 = r1 | r0;
  352. r1 = PLL_BYPASS; /* Bypass the PLL? */
  353. r1 = r1 << 8; /* Shift it over */
  354. r0 = r1 | r0; /* add them all together */
  355. p0.h = hi(PLL_CTL);
  356. p0.l = lo(PLL_CTL); /* Load the address */
  357. cli r2; /* Disable interrupts */
  358. ssync;
  359. w[p0] = r0.l; /* Set the value */
  360. idle; /* Wait for the PLL to stablize */
  361. sti r2; /* Enable interrupts */
  362. .Lcheck_again:
  363. p0.h = hi(PLL_STAT);
  364. p0.l = lo(PLL_STAT);
  365. R0 = W[P0](Z);
  366. CC = BITTST(R0,5);
  367. if ! CC jump .Lcheck_again;
  368. /* Configure SCLK & CCLK Dividers */
  369. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  370. p0.h = hi(PLL_DIV);
  371. p0.l = lo(PLL_DIV);
  372. w[p0] = r0.l;
  373. ssync;
  374. p0.l = lo(EBIU_SDRRC);
  375. p0.h = hi(EBIU_SDRRC);
  376. r0 = mem_SDRRC;
  377. w[p0] = r0.l;
  378. ssync;
  379. p0.l = LO(EBIU_SDBCTL);
  380. p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
  381. r0 = mem_SDBCTL;
  382. w[p0] = r0.l;
  383. ssync;
  384. P2.H = hi(EBIU_SDGCTL);
  385. P2.L = lo(EBIU_SDGCTL);
  386. R0 = [P2];
  387. BITCLR (R0, 24);
  388. p0.h = hi(EBIU_SDSTAT);
  389. p0.l = lo(EBIU_SDSTAT);
  390. r2.l = w[p0];
  391. cc = bittst(r2,3);
  392. if !cc jump .Lskip;
  393. NOP;
  394. BITSET (R0, 23);
  395. .Lskip:
  396. [P2] = R0;
  397. SSYNC;
  398. R0.L = lo(mem_SDGCTL);
  399. R0.H = hi(mem_SDGCTL);
  400. R1 = [p2];
  401. R1 = R1 | R0;
  402. [P2] = R1;
  403. SSYNC;
  404. p0.h = hi(SIC_IWR);
  405. p0.l = lo(SIC_IWR);
  406. r0.l = lo(IWR_ENABLE_ALL);
  407. r0.h = hi(IWR_ENABLE_ALL);
  408. [p0] = r0;
  409. SSYNC;
  410. RTS;
  411. ENDPROC(_start_dma_code)
  412. #endif /* CONFIG_BFIN_KERNEL_CLOCK */
  413. ENTRY(_bfin_reset)
  414. /* No more interrupts to be handled*/
  415. CLI R6;
  416. SSYNC;
  417. #if defined(CONFIG_MTD_M25P80)
  418. /*
  419. * The following code fix the SPI flash reboot issue,
  420. * /CS signal of the chip which is using PF10 return to GPIO mode
  421. */
  422. p0.h = hi(PORTF_FER);
  423. p0.l = lo(PORTF_FER);
  424. r0.l = 0x0000;
  425. w[p0] = r0.l;
  426. SSYNC;
  427. /* /CS return to high */
  428. p0.h = hi(PORTFIO);
  429. p0.l = lo(PORTFIO);
  430. r0.l = 0xFFFF;
  431. w[p0] = r0.l;
  432. SSYNC;
  433. /* Delay some time, This is necessary */
  434. r1.h = 0;
  435. r1.l = 0x400;
  436. p1 = r1;
  437. lsetup (.L_delay_lab1, .L_delay_lab1_end) lc1 = p1;
  438. .L_delay_lab1:
  439. r0.h = 0;
  440. r0.l = 0x8000;
  441. p0 = r0;
  442. lsetup (.L_delay_lab0, .L_delay_lab0_end) lc0 = p0;
  443. .L_delay_lab0:
  444. nop;
  445. .L_delay_lab0_end:
  446. nop;
  447. .L_delay_lab1_end:
  448. nop;
  449. #endif
  450. /* Clear the IMASK register */
  451. p0.h = hi(IMASK);
  452. p0.l = lo(IMASK);
  453. r0 = 0x0;
  454. [p0] = r0;
  455. /* Clear the ILAT register */
  456. p0.h = hi(ILAT);
  457. p0.l = lo(ILAT);
  458. r0 = [p0];
  459. [p0] = r0;
  460. SSYNC;
  461. /* make sure SYSCR is set to use BMODE */
  462. P0.h = hi(SYSCR);
  463. P0.l = lo(SYSCR);
  464. R0.l = 0x0;
  465. W[P0] = R0.l;
  466. SSYNC;
  467. /* issue a system soft reset */
  468. P1.h = hi(SWRST);
  469. P1.l = lo(SWRST);
  470. R1.l = 0x0007;
  471. W[P1] = R1;
  472. SSYNC;
  473. /* clear system soft reset */
  474. R0.l = 0x0000;
  475. W[P0] = R0;
  476. SSYNC;
  477. /* issue core reset */
  478. raise 1;
  479. RTS;
  480. ENDPROC(_bfin_reset)
  481. .data
  482. /*
  483. * Set up the usable of RAM stuff. Size of RAM is determined then
  484. * an initial stack set up at the end.
  485. */
  486. .align 4
  487. __rambase:
  488. .long 0
  489. __ramstart:
  490. .long 0
  491. __ramend:
  492. .long 0