lowlevel_init.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Low-level board setup code for TI DaVinci SoC based boards.
  4. *
  5. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  6. *
  7. * Partially based on TI sources, original copyrights follow:
  8. */
  9. /*
  10. * Board specific setup info
  11. *
  12. * (C) Copyright 2003
  13. * Texas Instruments, <www.ti.com>
  14. * Kshitij Gupta <Kshitij@ti.com>
  15. *
  16. * Modified for OMAP 1610 H2 board by Nishant Kamat, Jan 2004
  17. *
  18. * Modified for OMAP 5912 OSK board by Rishi Bhattacharya, Apr 2004
  19. *
  20. * Modified for DV-EVM board by Rishi Bhattacharya, Apr 2005
  21. *
  22. * Modified for DV-EVM board by Swaminathan S, Nov 2005
  23. */
  24. #include <config.h>
  25. #define MDSTAT_STATE 0x3f
  26. .globl lowlevel_init
  27. lowlevel_init:
  28. #ifdef CONFIG_SOC_DM644X
  29. /*-------------------------------------------------------*
  30. * Mask all IRQs by setting all bits in the EINT default *
  31. *-------------------------------------------------------*/
  32. mov r1, $0
  33. ldr r0, =EINT_ENABLE0
  34. str r1, [r0]
  35. ldr r0, =EINT_ENABLE1
  36. str r1, [r0]
  37. /*------------------------------------------------------*
  38. * Put the GEM in reset *
  39. *------------------------------------------------------*/
  40. /* Put the GEM in reset */
  41. ldr r8, PSC_GEM_FLAG_CLEAR
  42. ldr r6, MDCTL_GEM
  43. ldr r7, [r6]
  44. and r7, r7, r8
  45. str r7, [r6]
  46. /* Enable the Power Domain Transition Command */
  47. ldr r6, PTCMD
  48. ldr r7, [r6]
  49. orr r7, r7, $0x02
  50. str r7, [r6]
  51. /* Check for Transition Complete(PTSTAT) */
  52. checkStatClkStopGem:
  53. ldr r6, PTSTAT
  54. ldr r7, [r6]
  55. ands r7, r7, $0x02
  56. bne checkStatClkStopGem
  57. /* Check for GEM Reset Completion */
  58. checkGemStatClkStop:
  59. ldr r6, MDSTAT_GEM
  60. ldr r7, [r6]
  61. ands r7, r7, $0x100
  62. bne checkGemStatClkStop
  63. /* Do this for enabling a WDT initiated reset this is a workaround
  64. for a chip bug. Not required under normal situations */
  65. ldr r6, P1394
  66. mov r10, $0
  67. str r10, [r6]
  68. /*------------------------------------------------------*
  69. * Enable L1 & L2 Memories in Fast mode *
  70. *------------------------------------------------------*/
  71. ldr r6, DFT_ENABLE
  72. mov r10, $0x01
  73. str r10, [r6]
  74. ldr r6, MMARG_BRF0
  75. ldr r10, MMARG_BRF0_VAL
  76. str r10, [r6]
  77. ldr r6, DFT_ENABLE
  78. mov r10, $0
  79. str r10, [r6]
  80. /*------------------------------------------------------*
  81. * DDR2 PLL Initialization *
  82. *------------------------------------------------------*/
  83. /* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
  84. mov r10, $0
  85. ldr r6, PLL2_CTL
  86. ldr r7, PLL_CLKSRC_MASK
  87. ldr r8, [r6]
  88. and r8, r8, r7
  89. mov r9, r10, lsl $8
  90. orr r8, r8, r9
  91. str r8, [r6]
  92. /* Select the PLLEN source */
  93. ldr r7, PLL_ENSRC_MASK
  94. and r8, r8, r7
  95. str r8, [r6]
  96. /* Bypass the PLL */
  97. ldr r7, PLL_BYPASS_MASK
  98. and r8, r8, r7
  99. str r8, [r6]
  100. /* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
  101. mov r10, $0x20
  102. WaitPPL2Loop:
  103. subs r10, r10, $1
  104. bne WaitPPL2Loop
  105. /* Reset the PLL */
  106. ldr r7, PLL_RESET_MASK
  107. and r8, r8, r7
  108. str r8, [r6]
  109. /* Power up the PLL */
  110. ldr r7, PLL_PWRUP_MASK
  111. and r8, r8, r7
  112. str r8, [r6]
  113. /* Enable the PLL from Disable Mode */
  114. ldr r7, PLL_DISABLE_ENABLE_MASK
  115. and r8, r8, r7
  116. str r8, [r6]
  117. /* Program the PLL Multiplier */
  118. ldr r6, PLL2_PLLM
  119. mov r2, $0x17 /* 162 MHz */
  120. str r2, [r6]
  121. /* Program the PLL2 Divisor Value */
  122. ldr r6, PLL2_DIV2
  123. mov r3, $0x01
  124. str r3, [r6]
  125. /* Program the PLL2 Divisor Value */
  126. ldr r6, PLL2_DIV1
  127. mov r4, $0x0b /* 54 MHz */
  128. str r4, [r6]
  129. /* PLL2 DIV2 MMR */
  130. ldr r8, PLL2_DIV_MASK
  131. ldr r6, PLL2_DIV2
  132. ldr r9, [r6]
  133. and r8, r8, r9
  134. mov r9, $0x01
  135. mov r9, r9, lsl $15
  136. orr r8, r8, r9
  137. str r8, [r6]
  138. /* Program the GOSET bit to take new divider values */
  139. ldr r6, PLL2_PLLCMD
  140. ldr r7, [r6]
  141. orr r7, r7, $0x01
  142. str r7, [r6]
  143. /* Wait for Done */
  144. ldr r6, PLL2_PLLSTAT
  145. doneLoop_0:
  146. ldr r7, [r6]
  147. ands r7, r7, $0x01
  148. bne doneLoop_0
  149. /* PLL2 DIV1 MMR */
  150. ldr r8, PLL2_DIV_MASK
  151. ldr r6, PLL2_DIV1
  152. ldr r9, [r6]
  153. and r8, r8, r9
  154. mov r9, $0x01
  155. mov r9, r9, lsl $15
  156. orr r8, r8, r9
  157. str r8, [r6]
  158. /* Program the GOSET bit to take new divider values */
  159. ldr r6, PLL2_PLLCMD
  160. ldr r7, [r6]
  161. orr r7, r7, $0x01
  162. str r7, [r6]
  163. /* Wait for Done */
  164. ldr r6, PLL2_PLLSTAT
  165. doneLoop:
  166. ldr r7, [r6]
  167. ands r7, r7, $0x01
  168. bne doneLoop
  169. /* Wait for PLL to Reset Properly */
  170. mov r10, $0x218
  171. ResetPPL2Loop:
  172. subs r10, r10, $1
  173. bne ResetPPL2Loop
  174. /* Bring PLL out of Reset */
  175. ldr r6, PLL2_CTL
  176. ldr r8, [r6]
  177. orr r8, r8, $0x08
  178. str r8, [r6]
  179. /* Wait for PLL to Lock */
  180. ldr r10, PLL_LOCK_COUNT
  181. PLL2Lock:
  182. subs r10, r10, $1
  183. bne PLL2Lock
  184. /* Enable the PLL */
  185. ldr r6, PLL2_CTL
  186. ldr r8, [r6]
  187. orr r8, r8, $0x01
  188. str r8, [r6]
  189. /*------------------------------------------------------*
  190. * Issue Soft Reset to DDR Module *
  191. *------------------------------------------------------*/
  192. /* Shut down the DDR2 LPSC Module */
  193. ldr r8, PSC_FLAG_CLEAR
  194. ldr r6, MDCTL_DDR2
  195. ldr r7, [r6]
  196. and r7, r7, r8
  197. orr r7, r7, $0x03
  198. str r7, [r6]
  199. /* Enable the Power Domain Transition Command */
  200. ldr r6, PTCMD
  201. ldr r7, [r6]
  202. orr r7, r7, $0x01
  203. str r7, [r6]
  204. /* Check for Transition Complete(PTSTAT) */
  205. checkStatClkStop:
  206. ldr r6, PTSTAT
  207. ldr r7, [r6]
  208. ands r7, r7, $0x01
  209. bne checkStatClkStop
  210. /* Check for DDR2 Controller Enable Completion */
  211. checkDDRStatClkStop:
  212. ldr r6, MDSTAT_DDR2
  213. ldr r7, [r6]
  214. and r7, r7, $MDSTAT_STATE
  215. cmp r7, $0x03
  216. bne checkDDRStatClkStop
  217. /*------------------------------------------------------*
  218. * Program DDR2 MMRs for 162MHz Setting *
  219. *------------------------------------------------------*/
  220. /* Program PHY Control Register */
  221. ldr r6, DDRCTL
  222. ldr r7, DDRCTL_VAL
  223. str r7, [r6]
  224. /* Program SDRAM Bank Config Register */
  225. ldr r6, SDCFG
  226. ldr r7, SDCFG_VAL
  227. str r7, [r6]
  228. /* Program SDRAM TIM-0 Config Register */
  229. ldr r6, SDTIM0
  230. ldr r7, SDTIM0_VAL_162MHz
  231. str r7, [r6]
  232. /* Program SDRAM TIM-1 Config Register */
  233. ldr r6, SDTIM1
  234. ldr r7, SDTIM1_VAL_162MHz
  235. str r7, [r6]
  236. /* Program the SDRAM Bank Config Control Register */
  237. ldr r10, MASK_VAL
  238. ldr r8, SDCFG
  239. ldr r9, SDCFG_VAL
  240. and r9, r9, r10
  241. str r9, [r8]
  242. /* Program SDRAM SDREF Config Register */
  243. ldr r6, SDREF
  244. ldr r7, SDREF_VAL
  245. str r7, [r6]
  246. /*------------------------------------------------------*
  247. * Issue Soft Reset to DDR Module *
  248. *------------------------------------------------------*/
  249. /* Issue a Dummy DDR2 read/write */
  250. ldr r8, DDR2_START_ADDR
  251. ldr r7, DUMMY_VAL
  252. str r7, [r8]
  253. ldr r7, [r8]
  254. /* Shut down the DDR2 LPSC Module */
  255. ldr r8, PSC_FLAG_CLEAR
  256. ldr r6, MDCTL_DDR2
  257. ldr r7, [r6]
  258. and r7, r7, r8
  259. orr r7, r7, $0x01
  260. str r7, [r6]
  261. /* Enable the Power Domain Transition Command */
  262. ldr r6, PTCMD
  263. ldr r7, [r6]
  264. orr r7, r7, $0x01
  265. str r7, [r6]
  266. /* Check for Transition Complete(PTSTAT) */
  267. checkStatClkStop2:
  268. ldr r6, PTSTAT
  269. ldr r7, [r6]
  270. ands r7, r7, $0x01
  271. bne checkStatClkStop2
  272. /* Check for DDR2 Controller Enable Completion */
  273. checkDDRStatClkStop2:
  274. ldr r6, MDSTAT_DDR2
  275. ldr r7, [r6]
  276. and r7, r7, $MDSTAT_STATE
  277. cmp r7, $0x01
  278. bne checkDDRStatClkStop2
  279. /*------------------------------------------------------*
  280. * Turn DDR2 Controller Clocks On *
  281. *------------------------------------------------------*/
  282. /* Enable the DDR2 LPSC Module */
  283. ldr r6, MDCTL_DDR2
  284. ldr r7, [r6]
  285. orr r7, r7, $0x03
  286. str r7, [r6]
  287. /* Enable the Power Domain Transition Command */
  288. ldr r6, PTCMD
  289. ldr r7, [r6]
  290. orr r7, r7, $0x01
  291. str r7, [r6]
  292. /* Check for Transition Complete(PTSTAT) */
  293. checkStatClkEn2:
  294. ldr r6, PTSTAT
  295. ldr r7, [r6]
  296. ands r7, r7, $0x01
  297. bne checkStatClkEn2
  298. /* Check for DDR2 Controller Enable Completion */
  299. checkDDRStatClkEn2:
  300. ldr r6, MDSTAT_DDR2
  301. ldr r7, [r6]
  302. and r7, r7, $MDSTAT_STATE
  303. cmp r7, $0x03
  304. bne checkDDRStatClkEn2
  305. /* DDR Writes and Reads */
  306. ldr r6, CFGTEST
  307. mov r3, $0x01
  308. str r3, [r6]
  309. /*------------------------------------------------------*
  310. * System PLL Initialization *
  311. *------------------------------------------------------*/
  312. /* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
  313. mov r2, $0
  314. ldr r6, PLL1_CTL
  315. ldr r7, PLL_CLKSRC_MASK
  316. ldr r8, [r6]
  317. and r8, r8, r7
  318. mov r9, r2, lsl $8
  319. orr r8, r8, r9
  320. str r8, [r6]
  321. /* Select the PLLEN source */
  322. ldr r7, PLL_ENSRC_MASK
  323. and r8, r8, r7
  324. str r8, [r6]
  325. /* Bypass the PLL */
  326. ldr r7, PLL_BYPASS_MASK
  327. and r8, r8, r7
  328. str r8, [r6]
  329. /* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
  330. mov r10, $0x20
  331. WaitLoop:
  332. subs r10, r10, $1
  333. bne WaitLoop
  334. /* Reset the PLL */
  335. ldr r7, PLL_RESET_MASK
  336. and r8, r8, r7
  337. str r8, [r6]
  338. /* Disable the PLL */
  339. orr r8, r8, $0x10
  340. str r8, [r6]
  341. /* Power up the PLL */
  342. ldr r7, PLL_PWRUP_MASK
  343. and r8, r8, r7
  344. str r8, [r6]
  345. /* Enable the PLL from Disable Mode */
  346. ldr r7, PLL_DISABLE_ENABLE_MASK
  347. and r8, r8, r7
  348. str r8, [r6]
  349. /* Program the PLL Multiplier */
  350. ldr r6, PLL1_PLLM
  351. mov r3, $0x15 /* For 594MHz */
  352. str r3, [r6]
  353. /* Wait for PLL to Reset Properly */
  354. mov r10, $0xff
  355. ResetLoop:
  356. subs r10, r10, $1
  357. bne ResetLoop
  358. /* Bring PLL out of Reset */
  359. ldr r6, PLL1_CTL
  360. orr r8, r8, $0x08
  361. str r8, [r6]
  362. /* Wait for PLL to Lock */
  363. ldr r10, PLL_LOCK_COUNT
  364. PLL1Lock:
  365. subs r10, r10, $1
  366. bne PLL1Lock
  367. /* Enable the PLL */
  368. orr r8, r8, $0x01
  369. str r8, [r6]
  370. nop
  371. nop
  372. nop
  373. nop
  374. /*------------------------------------------------------*
  375. * AEMIF configuration for NOR Flash (double check) *
  376. *------------------------------------------------------*/
  377. ldr r0, _PINMUX0
  378. ldr r1, _DEV_SETTING
  379. str r1, [r0]
  380. ldr r0, WAITCFG
  381. ldr r1, WAITCFG_VAL
  382. ldr r2, [r0]
  383. orr r2, r2, r1
  384. str r2, [r0]
  385. ldr r0, ACFG3
  386. ldr r1, ACFG3_VAL
  387. ldr r2, [r0]
  388. and r1, r2, r1
  389. str r1, [r0]
  390. ldr r0, ACFG4
  391. ldr r1, ACFG4_VAL
  392. ldr r2, [r0]
  393. and r1, r2, r1
  394. str r1, [r0]
  395. ldr r0, ACFG5
  396. ldr r1, ACFG5_VAL
  397. ldr r2, [r0]
  398. and r1, r2, r1
  399. str r1, [r0]
  400. /*--------------------------------------*
  401. * VTP manual Calibration *
  402. *--------------------------------------*/
  403. ldr r0, VTPIOCR
  404. ldr r1, VTP_MMR0
  405. str r1, [r0]
  406. ldr r0, VTPIOCR
  407. ldr r1, VTP_MMR1
  408. str r1, [r0]
  409. /* Wait for 33 VTP CLK cycles. VRP operates at 27 MHz */
  410. ldr r10, VTP_LOCK_COUNT
  411. VTPLock:
  412. subs r10, r10, $1
  413. bne VTPLock
  414. ldr r6, DFT_ENABLE
  415. mov r10, $0x01
  416. str r10, [r6]
  417. ldr r6, DDRVTPR
  418. ldr r7, [r6]
  419. mov r8, r7, LSL #32-10
  420. mov r8, r8, LSR #32-10 /* grab low 10 bits */
  421. ldr r7, VTP_RECAL
  422. orr r8, r7, r8
  423. ldr r7, VTP_EN
  424. orr r8, r7, r8
  425. str r8, [r0]
  426. /* Wait for 33 VTP CLK cycles. VRP operates at 27 MHz */
  427. ldr r10, VTP_LOCK_COUNT
  428. VTP1Lock:
  429. subs r10, r10, $1
  430. bne VTP1Lock
  431. ldr r1, [r0]
  432. ldr r2, VTP_MASK
  433. and r2, r1, r2
  434. str r2, [r0]
  435. ldr r6, DFT_ENABLE
  436. mov r10, $0
  437. str r10, [r6]
  438. /*
  439. * Call board-specific lowlevel init.
  440. * That MUST be present and THAT returns
  441. * back to arch calling code with "mov pc, lr."
  442. */
  443. b dv_board_init
  444. .ltorg
  445. _PINMUX0:
  446. .word 0x01c40000 /* Device Configuration Registers */
  447. _PINMUX1:
  448. .word 0x01c40004 /* Device Configuration Registers */
  449. _DEV_SETTING:
  450. .word 0x00000c1f
  451. WAITCFG:
  452. .word 0x01e00004
  453. WAITCFG_VAL:
  454. .word 0
  455. ACFG3:
  456. .word 0x01e00014
  457. ACFG3_VAL:
  458. .word 0x3ffffffd
  459. ACFG4:
  460. .word 0x01e00018
  461. ACFG4_VAL:
  462. .word 0x3ffffffd
  463. ACFG5:
  464. .word 0x01e0001c
  465. ACFG5_VAL:
  466. .word 0x3ffffffd
  467. MDCTL_DDR2:
  468. .word 0x01c41a34
  469. MDSTAT_DDR2:
  470. .word 0x01c41834
  471. PTCMD:
  472. .word 0x01c41120
  473. PTSTAT:
  474. .word 0x01c41128
  475. EINT_ENABLE0:
  476. .word 0x01c48018
  477. EINT_ENABLE1:
  478. .word 0x01c4801c
  479. PSC_FLAG_CLEAR:
  480. .word 0xffffffe0
  481. PSC_GEM_FLAG_CLEAR:
  482. .word 0xfffffeff
  483. /* DDR2 MMR & CONFIGURATION VALUES, 162 MHZ clock */
  484. DDRCTL:
  485. .word 0x200000e4
  486. DDRCTL_VAL:
  487. .word 0x50006405
  488. SDREF:
  489. .word 0x2000000c
  490. SDREF_VAL:
  491. .word 0x000005c3
  492. SDCFG:
  493. .word 0x20000008
  494. SDCFG_VAL:
  495. #ifdef DDR_4BANKS
  496. .word 0x00178622
  497. #elif defined DDR_8BANKS
  498. .word 0x00178632
  499. #else
  500. #error "Unknown DDR configuration!!!"
  501. #endif
  502. SDTIM0:
  503. .word 0x20000010
  504. SDTIM0_VAL_162MHz:
  505. .word 0x28923211
  506. SDTIM1:
  507. .word 0x20000014
  508. SDTIM1_VAL_162MHz:
  509. .word 0x0016c722
  510. VTPIOCR:
  511. .word 0x200000f0 /* VTP IO Control register */
  512. DDRVTPR:
  513. .word 0x01c42030 /* DDR VPTR MMR */
  514. VTP_MMR0:
  515. .word 0x201f
  516. VTP_MMR1:
  517. .word 0xa01f
  518. DFT_ENABLE:
  519. .word 0x01c4004c
  520. VTP_LOCK_COUNT:
  521. .word 0x5b0
  522. VTP_MASK:
  523. .word 0xffffdfff
  524. VTP_RECAL:
  525. .word 0x08000
  526. VTP_EN:
  527. .word 0x02000
  528. CFGTEST:
  529. .word 0x80010000
  530. MASK_VAL:
  531. .word 0x00000fff
  532. /* GEM Power Up & LPSC Control Register */
  533. MDCTL_GEM:
  534. .word 0x01c41a9c
  535. MDSTAT_GEM:
  536. .word 0x01c4189c
  537. /* For WDT reset chip bug */
  538. P1394:
  539. .word 0x01c41a20
  540. PLL_CLKSRC_MASK:
  541. .word 0xfffffeff /* Mask the Clock Mode bit */
  542. PLL_ENSRC_MASK:
  543. .word 0xffffffdf /* Select the PLLEN source */
  544. PLL_BYPASS_MASK:
  545. .word 0xfffffffe /* Put the PLL in BYPASS */
  546. PLL_RESET_MASK:
  547. .word 0xfffffff7 /* Put the PLL in Reset Mode */
  548. PLL_PWRUP_MASK:
  549. .word 0xfffffffd /* PLL Power up Mask Bit */
  550. PLL_DISABLE_ENABLE_MASK:
  551. .word 0xffffffef /* Enable the PLL from Disable */
  552. PLL_LOCK_COUNT:
  553. .word 0x2000
  554. /* PLL1-SYSTEM PLL MMRs */
  555. PLL1_CTL:
  556. .word 0x01c40900
  557. PLL1_PLLM:
  558. .word 0x01c40910
  559. /* PLL2-SYSTEM PLL MMRs */
  560. PLL2_CTL:
  561. .word 0x01c40d00
  562. PLL2_PLLM:
  563. .word 0x01c40d10
  564. PLL2_DIV1:
  565. .word 0x01c40d18
  566. PLL2_DIV2:
  567. .word 0x01c40d1c
  568. PLL2_PLLCMD:
  569. .word 0x01c40d38
  570. PLL2_PLLSTAT:
  571. .word 0x01c40d3c
  572. PLL2_DIV_MASK:
  573. .word 0xffff7fff
  574. MMARG_BRF0:
  575. .word 0x01c42010 /* BRF margin mode 0 (R/W)*/
  576. MMARG_BRF0_VAL:
  577. .word 0x00444400
  578. DDR2_START_ADDR:
  579. .word 0x80000000
  580. DUMMY_VAL:
  581. .word 0xa55aa55a
  582. #else /* CONFIG_SOC_DM644X */
  583. mov pc, lr
  584. #endif