head.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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 - when booting from u-boot, the UART is not disabled
  165. * so if we dont initalize here, our serial console gets hosed */
  166. p0.h = hi(UART_LCR);
  167. p0.l = lo(UART_LCR);
  168. r0 = 0x0(Z);
  169. w[p0] = r0.L; /* To enable DLL writes */
  170. ssync;
  171. p0.h = hi(UART_DLL);
  172. p0.l = lo(UART_DLL);
  173. r0 = 0x00(Z);
  174. w[p0] = r0.L;
  175. ssync;
  176. p0.h = hi(UART_DLH);
  177. p0.l = lo(UART_DLH);
  178. r0 = 0x00(Z);
  179. w[p0] = r0.L;
  180. ssync;
  181. p0.h = hi(UART_GCTL);
  182. p0.l = lo(UART_GCTL);
  183. r0 = 0x0(Z);
  184. w[p0] = r0.L; /* To enable UART clock */
  185. ssync;
  186. /* Initialize stack pointer */
  187. sp.l = lo(INITIAL_STACK);
  188. sp.h = hi(INITIAL_STACK);
  189. fp = sp;
  190. usp = sp;
  191. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  192. call _bf53x_relocate_l1_mem;
  193. #if CONFIG_BFIN_KERNEL_CLOCK
  194. call _start_dma_code;
  195. #endif
  196. /* Code for initializing Async memory banks */
  197. p2.h = hi(EBIU_AMBCTL1);
  198. p2.l = lo(EBIU_AMBCTL1);
  199. r0.h = hi(AMBCTL1VAL);
  200. r0.l = lo(AMBCTL1VAL);
  201. [p2] = r0;
  202. ssync;
  203. p2.h = hi(EBIU_AMBCTL0);
  204. p2.l = lo(EBIU_AMBCTL0);
  205. r0.h = hi(AMBCTL0VAL);
  206. r0.l = lo(AMBCTL0VAL);
  207. [p2] = r0;
  208. ssync;
  209. p2.h = hi(EBIU_AMGCTL);
  210. p2.l = lo(EBIU_AMGCTL);
  211. r0 = AMGCTLVAL;
  212. w[p2] = r0;
  213. ssync;
  214. /* This section keeps the processor in supervisor mode
  215. * during kernel boot. Switches to user mode at end of boot.
  216. * See page 3-9 of Hardware Reference manual for documentation.
  217. */
  218. /* EVT15 = _real_start */
  219. p0.l = lo(EVT15);
  220. p0.h = hi(EVT15);
  221. p1.l = _real_start;
  222. p1.h = _real_start;
  223. [p0] = p1;
  224. csync;
  225. p0.l = lo(IMASK);
  226. p0.h = hi(IMASK);
  227. p1.l = IMASK_IVG15;
  228. p1.h = 0x0;
  229. [p0] = p1;
  230. csync;
  231. raise 15;
  232. p0.l = .LWAIT_HERE;
  233. p0.h = .LWAIT_HERE;
  234. reti = p0;
  235. #if defined(ANOMALY_05000281)
  236. nop; nop; nop;
  237. #endif
  238. rti;
  239. .LWAIT_HERE:
  240. jump .LWAIT_HERE;
  241. ENTRY(_real_start)
  242. [ -- sp ] = reti;
  243. p0.l = lo(WDOG_CTL);
  244. p0.h = hi(WDOG_CTL);
  245. r0 = 0xAD6(z);
  246. w[p0] = r0; /* watchdog off for now */
  247. ssync;
  248. /* Code update for BSS size == 0
  249. * Zero out the bss region.
  250. */
  251. p1.l = ___bss_start;
  252. p1.h = ___bss_start;
  253. p2.l = ___bss_stop;
  254. p2.h = ___bss_stop;
  255. r0 = 0;
  256. p2 -= p1;
  257. lsetup (.L_clear_bss, .L_clear_bss ) lc0 = p2;
  258. .L_clear_bss:
  259. B[p1++] = r0;
  260. /* In case there is a NULL pointer reference
  261. * Zero out region before stext
  262. */
  263. p1.l = 0x0;
  264. p1.h = 0x0;
  265. r0.l = __stext;
  266. r0.h = __stext;
  267. r0 = r0 >> 1;
  268. p2 = r0;
  269. r0 = 0;
  270. lsetup (.L_clear_zero, .L_clear_zero ) lc0 = p2;
  271. .L_clear_zero:
  272. W[p1++] = r0;
  273. /* pass the uboot arguments to the global value command line */
  274. R0 = R7;
  275. call _cmdline_init;
  276. p1.l = __rambase;
  277. p1.h = __rambase;
  278. r0.l = __sdata;
  279. r0.h = __sdata;
  280. [p1] = r0;
  281. p1.l = __ramstart;
  282. p1.h = __ramstart;
  283. p3.l = ___bss_stop;
  284. p3.h = ___bss_stop;
  285. r1 = p3;
  286. [p1] = r1;
  287. /*
  288. * load the current thread pointer and stack
  289. */
  290. r1.l = _init_thread_union;
  291. r1.h = _init_thread_union;
  292. r2.l = 0x2000;
  293. r2.h = 0x0000;
  294. r1 = r1 + r2;
  295. sp = r1;
  296. usp = sp;
  297. fp = sp;
  298. call _start_kernel;
  299. .L_exit:
  300. jump.s .L_exit;
  301. .section .l1.text
  302. #if CONFIG_BFIN_KERNEL_CLOCK
  303. ENTRY(_start_dma_code)
  304. /* Enable PHY CLK buffer output */
  305. p0.h = hi(VR_CTL);
  306. p0.l = lo(VR_CTL);
  307. r0.l = w[p0];
  308. bitset(r0, 14);
  309. w[p0] = r0.l;
  310. ssync;
  311. p0.h = hi(SIC_IWR);
  312. p0.l = lo(SIC_IWR);
  313. r0.l = 0x1;
  314. r0.h = 0x0;
  315. [p0] = r0;
  316. SSYNC;
  317. /*
  318. * Set PLL_CTL
  319. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  320. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  321. * - [7] = output delay (add 200ps of delay to mem signals)
  322. * - [6] = input delay (add 200ps of input delay to mem signals)
  323. * - [5] = PDWN : 1=All Clocks off
  324. * - [3] = STOPCK : 1=Core Clock off
  325. * - [1] = PLL_OFF : 1=Disable Power to PLL
  326. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  327. * all other bits set to zero
  328. */
  329. p0.h = hi(PLL_LOCKCNT);
  330. p0.l = lo(PLL_LOCKCNT);
  331. r0 = 0x300(Z);
  332. w[p0] = r0.l;
  333. ssync;
  334. P2.H = hi(EBIU_SDGCTL);
  335. P2.L = lo(EBIU_SDGCTL);
  336. R0 = [P2];
  337. BITSET (R0, 24);
  338. [P2] = R0;
  339. SSYNC;
  340. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  341. r0 = r0 << 9; /* Shift it over, */
  342. r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  343. r0 = r1 | r0;
  344. r1 = PLL_BYPASS; /* Bypass the PLL? */
  345. r1 = r1 << 8; /* Shift it over */
  346. r0 = r1 | r0; /* add them all together */
  347. p0.h = hi(PLL_CTL);
  348. p0.l = lo(PLL_CTL); /* Load the address */
  349. cli r2; /* Disable interrupts */
  350. ssync;
  351. w[p0] = r0.l; /* Set the value */
  352. idle; /* Wait for the PLL to stablize */
  353. sti r2; /* Enable interrupts */
  354. .Lcheck_again:
  355. p0.h = hi(PLL_STAT);
  356. p0.l = lo(PLL_STAT);
  357. R0 = W[P0](Z);
  358. CC = BITTST(R0,5);
  359. if ! CC jump .Lcheck_again;
  360. /* Configure SCLK & CCLK Dividers */
  361. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  362. p0.h = hi(PLL_DIV);
  363. p0.l = lo(PLL_DIV);
  364. w[p0] = r0.l;
  365. ssync;
  366. p0.l = lo(EBIU_SDRRC);
  367. p0.h = hi(EBIU_SDRRC);
  368. r0 = mem_SDRRC;
  369. w[p0] = r0.l;
  370. ssync;
  371. p0.l = (EBIU_SDBCTL & 0xFFFF);
  372. p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */
  373. r0 = mem_SDBCTL;
  374. w[p0] = r0.l;
  375. ssync;
  376. P2.H = hi(EBIU_SDGCTL);
  377. P2.L = lo(EBIU_SDGCTL);
  378. R0 = [P2];
  379. BITCLR (R0, 24);
  380. p0.h = hi(EBIU_SDSTAT);
  381. p0.l = lo(EBIU_SDSTAT);
  382. r2.l = w[p0];
  383. cc = bittst(r2,3);
  384. if !cc jump .Lskip;
  385. NOP;
  386. BITSET (R0, 23);
  387. .Lskip:
  388. [P2] = R0;
  389. SSYNC;
  390. R0.L = lo(mem_SDGCTL);
  391. R0.H = hi(mem_SDGCTL);
  392. R1 = [p2];
  393. R1 = R1 | R0;
  394. [P2] = R1;
  395. SSYNC;
  396. p0.h = hi(SIC_IWR);
  397. p0.l = lo(SIC_IWR);
  398. r0.l = lo(IWR_ENABLE_ALL);
  399. r0.h = hi(IWR_ENABLE_ALL);
  400. [p0] = r0;
  401. SSYNC;
  402. RTS;
  403. #endif /* CONFIG_BFIN_KERNEL_CLOCK */
  404. ENTRY(_bfin_reset)
  405. /* No more interrupts to be handled*/
  406. CLI R6;
  407. SSYNC;
  408. #if defined(CONFIG_MTD_M25P80)
  409. /*
  410. * The following code fix the SPI flash reboot issue,
  411. * /CS signal of the chip which is using PF10 return to GPIO mode
  412. */
  413. p0.h = hi(PORTF_FER);
  414. p0.l = lo(PORTF_FER);
  415. r0.l = 0x0000;
  416. w[p0] = r0.l;
  417. SSYNC;
  418. /* /CS return to high */
  419. p0.h = hi(PORTFIO);
  420. p0.l = lo(PORTFIO);
  421. r0.l = 0xFFFF;
  422. w[p0] = r0.l;
  423. SSYNC;
  424. /* Delay some time, This is necessary */
  425. r1.h = 0;
  426. r1.l = 0x400;
  427. p1 = r1;
  428. lsetup (.L_delay_lab1, .L_delay_lab1_end) lc1 = p1;
  429. .L_delay_lab1:
  430. r0.h = 0;
  431. r0.l = 0x8000;
  432. p0 = r0;
  433. lsetup (.L_delay_lab0, .L_delay_lab0_end) lc0 = p0;
  434. .L_delay_lab0:
  435. nop;
  436. .L_delay_lab0_end:
  437. nop;
  438. .L_delay_lab1_end:
  439. nop;
  440. #endif
  441. /* Clear the IMASK register */
  442. p0.h = hi(IMASK);
  443. p0.l = lo(IMASK);
  444. r0 = 0x0;
  445. [p0] = r0;
  446. /* Clear the ILAT register */
  447. p0.h = hi(ILAT);
  448. p0.l = lo(ILAT);
  449. r0 = [p0];
  450. [p0] = r0;
  451. SSYNC;
  452. /* make sure SYSCR is set to use BMODE */
  453. P0.h = hi(SYSCR);
  454. P0.l = lo(SYSCR);
  455. R0.l = 0x0;
  456. W[P0] = R0.l;
  457. SSYNC;
  458. /* issue a system soft reset */
  459. P1.h = hi(SWRST);
  460. P1.l = lo(SWRST);
  461. R1.l = 0x0007;
  462. W[P1] = R1;
  463. SSYNC;
  464. /* clear system soft reset */
  465. R0.l = 0x0000;
  466. W[P0] = R0;
  467. SSYNC;
  468. /* issue core reset */
  469. raise 1;
  470. RTS;
  471. ENDPROC(_bfin_reset)
  472. .data
  473. /*
  474. * Set up the usable of RAM stuff. Size of RAM is determined then
  475. * an initial stack set up at the end.
  476. */
  477. .align 4
  478. __rambase:
  479. .long 0
  480. __ramstart:
  481. .long 0
  482. __ramend:
  483. .long 0