head.S 11 KB

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