head.S 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. /* 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. /* Anomaly 05000125 */
  98. #if ANOMALY_05000125
  99. CLI R2;
  100. SSYNC;
  101. #endif
  102. [p0] = R0;
  103. SSYNC;
  104. #if ANOMALY_05000125
  105. STI R2;
  106. #endif
  107. /* Turn off the dcache */
  108. p0.l = LO(DMEM_CONTROL);
  109. p0.h = HI(DMEM_CONTROL);
  110. R1 = [p0];
  111. R0 = ~ENDCPLB;
  112. R0 = R0 & R1;
  113. /* Anomaly 05000125 */
  114. #if ANOMALY_05000125
  115. CLI R2;
  116. SSYNC;
  117. #endif
  118. [p0] = R0;
  119. SSYNC;
  120. #if ANOMALY_05000125
  121. STI R2;
  122. #endif
  123. /* Initialise General-Purpose I/O Modules on BF537 */
  124. /* Rev 0.0 Anomaly 05000212 - PORTx_FER,
  125. * PORT_MUX Registers Do Not accept "writes" correctly:
  126. */
  127. p0.h = hi(BFIN_PORT_MUX);
  128. p0.l = lo(BFIN_PORT_MUX);
  129. #if ANOMALY_05000212
  130. R0.L = W[P0]; /* Read */
  131. SSYNC;
  132. #endif
  133. R0 = (PGDE_UART | PFTE_UART)(Z);
  134. #if ANOMALY_05000212
  135. W[P0] = R0.L; /* Write */
  136. SSYNC;
  137. #endif
  138. W[P0] = R0.L; /* Enable both UARTS */
  139. SSYNC;
  140. p0.h = hi(PORTF_FER);
  141. p0.l = lo(PORTF_FER);
  142. #if ANOMALY_05000212
  143. R0.L = W[P0]; /* Read */
  144. SSYNC;
  145. #endif
  146. R0 = 0x000F(Z);
  147. #if ANOMALY_05000212
  148. W[P0] = R0.L; /* Write */
  149. SSYNC;
  150. #endif
  151. /* Enable peripheral function of PORTF for UART0 and UART1 */
  152. W[P0] = R0.L;
  153. SSYNC;
  154. #if !defined(CONFIG_BF534)
  155. p0.h = hi(EMAC_SYSTAT);
  156. p0.l = lo(EMAC_SYSTAT);
  157. R0.h = 0xFFFF; /* Clear EMAC Interrupt Status bits */
  158. R0.l = 0xFFFF;
  159. [P0] = R0;
  160. SSYNC;
  161. #endif
  162. #ifdef CONFIG_BF537_PORT_H
  163. p0.h = hi(PORTH_FER);
  164. p0.l = lo(PORTH_FER);
  165. R0.L = W[P0]; /* Read */
  166. SSYNC;
  167. R0 = 0x0000;
  168. W[P0] = R0.L; /* Write */
  169. SSYNC;
  170. W[P0] = R0.L; /* Disable peripheral function of PORTH */
  171. SSYNC;
  172. #endif
  173. /* Initialise UART - when booting from u-boot, the UART is not disabled
  174. * so if we dont initalize here, our serial console gets hosed */
  175. p0.h = hi(UART_LCR);
  176. p0.l = lo(UART_LCR);
  177. r0 = 0x0(Z);
  178. w[p0] = r0.L; /* To enable DLL writes */
  179. ssync;
  180. p0.h = hi(UART_DLL);
  181. p0.l = lo(UART_DLL);
  182. r0 = 0x0(Z);
  183. w[p0] = r0.L;
  184. ssync;
  185. p0.h = hi(UART_DLH);
  186. p0.l = lo(UART_DLH);
  187. r0 = 0x00(Z);
  188. w[p0] = r0.L;
  189. ssync;
  190. p0.h = hi(UART_GCTL);
  191. p0.l = lo(UART_GCTL);
  192. r0 = 0x0(Z);
  193. w[p0] = r0.L; /* To enable UART clock */
  194. ssync;
  195. /* Initialize stack pointer */
  196. sp.l = lo(INITIAL_STACK);
  197. sp.h = hi(INITIAL_STACK);
  198. fp = sp;
  199. usp = sp;
  200. #ifdef CONFIG_EARLY_PRINTK
  201. SP += -12;
  202. call _init_early_exception_vectors;
  203. SP += 12;
  204. #endif
  205. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  206. call _bf53x_relocate_l1_mem;
  207. #if CONFIG_BFIN_KERNEL_CLOCK
  208. call _start_dma_code;
  209. #endif
  210. /* Code for initializing Async memory banks */
  211. p2.h = hi(EBIU_AMBCTL1);
  212. p2.l = lo(EBIU_AMBCTL1);
  213. r0.h = hi(AMBCTL1VAL);
  214. r0.l = lo(AMBCTL1VAL);
  215. [p2] = r0;
  216. ssync;
  217. p2.h = hi(EBIU_AMBCTL0);
  218. p2.l = lo(EBIU_AMBCTL0);
  219. r0.h = hi(AMBCTL0VAL);
  220. r0.l = lo(AMBCTL0VAL);
  221. [p2] = r0;
  222. ssync;
  223. p2.h = hi(EBIU_AMGCTL);
  224. p2.l = lo(EBIU_AMGCTL);
  225. r0 = AMGCTLVAL;
  226. w[p2] = r0;
  227. ssync;
  228. /* This section keeps the processor in supervisor mode
  229. * during kernel boot. Switches to user mode at end of boot.
  230. * See page 3-9 of Hardware Reference manual for documentation.
  231. */
  232. /* EVT15 = _real_start */
  233. p0.l = lo(EVT15);
  234. p0.h = hi(EVT15);
  235. p1.l = _real_start;
  236. p1.h = _real_start;
  237. [p0] = p1;
  238. csync;
  239. p0.l = lo(IMASK);
  240. p0.h = hi(IMASK);
  241. p1.l = IMASK_IVG15;
  242. p1.h = 0x0;
  243. [p0] = p1;
  244. csync;
  245. raise 15;
  246. p0.l = .LWAIT_HERE;
  247. p0.h = .LWAIT_HERE;
  248. reti = p0;
  249. #if ANOMALY_05000281
  250. nop; nop; nop;
  251. #endif
  252. rti;
  253. .LWAIT_HERE:
  254. jump .LWAIT_HERE;
  255. ENDPROC(__start)
  256. ENTRY(_real_start)
  257. [ -- sp ] = reti;
  258. p0.l = lo(WDOG_CTL);
  259. p0.h = hi(WDOG_CTL);
  260. r0 = 0xAD6(z);
  261. w[p0] = r0; /* watchdog off for now */
  262. ssync;
  263. /* Code update for BSS size == 0
  264. * Zero out the bss region.
  265. */
  266. p1.l = ___bss_start;
  267. p1.h = ___bss_start;
  268. p2.l = ___bss_stop;
  269. p2.h = ___bss_stop;
  270. r0 = 0;
  271. p2 -= p1;
  272. lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2;
  273. .L_clear_bss:
  274. B[p1++] = r0;
  275. /* In case there is a NULL pointer reference
  276. * Zero out region before stext
  277. */
  278. p1.l = 0x0;
  279. p1.h = 0x0;
  280. r0.l = __stext;
  281. r0.h = __stext;
  282. r0 = r0 >> 1;
  283. p2 = r0;
  284. r0 = 0;
  285. lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2;
  286. .L_clear_zero:
  287. W[p1++] = r0;
  288. /* pass the uboot arguments to the global value command line */
  289. R0 = R7;
  290. call _cmdline_init;
  291. p1.l = __rambase;
  292. p1.h = __rambase;
  293. r0.l = __sdata;
  294. r0.h = __sdata;
  295. [p1] = r0;
  296. p1.l = __ramstart;
  297. p1.h = __ramstart;
  298. p3.l = ___bss_stop;
  299. p3.h = ___bss_stop;
  300. r1 = p3;
  301. [p1] = r1;
  302. /*
  303. * load the current thread pointer and stack
  304. */
  305. r1.l = _init_thread_union;
  306. r1.h = _init_thread_union;
  307. r2.l = 0x2000;
  308. r2.h = 0x0000;
  309. r1 = r1 + r2;
  310. sp = r1;
  311. usp = sp;
  312. fp = sp;
  313. jump.l _start_kernel;
  314. ENDPROC(_real_start)
  315. __FINIT
  316. .section .l1.text
  317. #if CONFIG_BFIN_KERNEL_CLOCK
  318. ENTRY(_start_dma_code)
  319. /* Enable PHY CLK buffer output */
  320. p0.h = hi(VR_CTL);
  321. p0.l = lo(VR_CTL);
  322. r0.l = w[p0];
  323. bitset(r0, 14);
  324. w[p0] = r0.l;
  325. ssync;
  326. p0.h = hi(SIC_IWR);
  327. p0.l = lo(SIC_IWR);
  328. r0.l = 0x1;
  329. r0.h = 0x0;
  330. [p0] = r0;
  331. SSYNC;
  332. /*
  333. * Set PLL_CTL
  334. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  335. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  336. * - [7] = output delay (add 200ps of delay to mem signals)
  337. * - [6] = input delay (add 200ps of input delay to mem signals)
  338. * - [5] = PDWN : 1=All Clocks off
  339. * - [3] = STOPCK : 1=Core Clock off
  340. * - [1] = PLL_OFF : 1=Disable Power to PLL
  341. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  342. * all other bits set to zero
  343. */
  344. p0.h = hi(PLL_LOCKCNT);
  345. p0.l = lo(PLL_LOCKCNT);
  346. r0 = 0x300(Z);
  347. w[p0] = r0.l;
  348. ssync;
  349. P2.H = hi(EBIU_SDGCTL);
  350. P2.L = lo(EBIU_SDGCTL);
  351. R0 = [P2];
  352. BITSET (R0, 24);
  353. [P2] = R0;
  354. SSYNC;
  355. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  356. r0 = r0 << 9; /* Shift it over, */
  357. r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  358. r0 = r1 | r0;
  359. r1 = PLL_BYPASS; /* Bypass the PLL? */
  360. r1 = r1 << 8; /* Shift it over */
  361. r0 = r1 | r0; /* add them all together */
  362. p0.h = hi(PLL_CTL);
  363. p0.l = lo(PLL_CTL); /* Load the address */
  364. cli r2; /* Disable interrupts */
  365. ssync;
  366. w[p0] = r0.l; /* Set the value */
  367. idle; /* Wait for the PLL to stablize */
  368. sti r2; /* Enable interrupts */
  369. .Lcheck_again:
  370. p0.h = hi(PLL_STAT);
  371. p0.l = lo(PLL_STAT);
  372. R0 = W[P0](Z);
  373. CC = BITTST(R0,5);
  374. if ! CC jump .Lcheck_again;
  375. /* Configure SCLK & CCLK Dividers */
  376. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  377. p0.h = hi(PLL_DIV);
  378. p0.l = lo(PLL_DIV);
  379. w[p0] = r0.l;
  380. ssync;
  381. p0.l = lo(EBIU_SDRRC);
  382. p0.h = hi(EBIU_SDRRC);
  383. r0 = mem_SDRRC;
  384. w[p0] = r0.l;
  385. ssync;
  386. p0.l = LO(EBIU_SDBCTL);
  387. p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
  388. r0 = mem_SDBCTL;
  389. w[p0] = r0.l;
  390. ssync;
  391. P2.H = hi(EBIU_SDGCTL);
  392. P2.L = lo(EBIU_SDGCTL);
  393. R0 = [P2];
  394. BITCLR (R0, 24);
  395. p0.h = hi(EBIU_SDSTAT);
  396. p0.l = lo(EBIU_SDSTAT);
  397. r2.l = w[p0];
  398. cc = bittst(r2,3);
  399. if !cc jump .Lskip;
  400. NOP;
  401. BITSET (R0, 23);
  402. .Lskip:
  403. [P2] = R0;
  404. SSYNC;
  405. R0.L = lo(mem_SDGCTL);
  406. R0.H = hi(mem_SDGCTL);
  407. R1 = [p2];
  408. R1 = R1 | R0;
  409. [P2] = R1;
  410. SSYNC;
  411. p0.h = hi(SIC_IWR);
  412. p0.l = lo(SIC_IWR);
  413. r0.l = lo(IWR_ENABLE_ALL);
  414. r0.h = hi(IWR_ENABLE_ALL);
  415. [p0] = r0;
  416. SSYNC;
  417. RTS;
  418. ENDPROC(_start_dma_code)
  419. #endif /* CONFIG_BFIN_KERNEL_CLOCK */
  420. .data
  421. /*
  422. * Set up the usable of RAM stuff. Size of RAM is determined then
  423. * an initial stack set up at the end.
  424. */
  425. .align 4
  426. __rambase:
  427. .long 0
  428. __ramstart:
  429. .long 0
  430. __ramend:
  431. .long 0