head.S 11 KB

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