da850_lowlevel.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * SoC-specific lowlevel code for DA850
  4. *
  5. * Copyright (C) 2011
  6. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  7. */
  8. #include <common.h>
  9. #include <nand.h>
  10. #include <ns16550.h>
  11. #include <post.h>
  12. #include <asm/arch/da850_lowlevel.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/davinci_misc.h>
  15. #include <asm/arch/ddr2_defs.h>
  16. #include <asm/ti-common/davinci_nand.h>
  17. #include <asm/arch/pll_defs.h>
  18. void davinci_enable_uart0(void)
  19. {
  20. lpsc_on(DAVINCI_LPSC_UART0);
  21. /* Bringup UART0 out of reset */
  22. REG(UART0_PWREMU_MGMT) = 0x00006001;
  23. }
  24. #if defined(CONFIG_SYS_DA850_PLL_INIT)
  25. static void da850_waitloop(unsigned long loopcnt)
  26. {
  27. unsigned long i;
  28. for (i = 0; i < loopcnt; i++)
  29. asm(" NOP");
  30. }
  31. static int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
  32. {
  33. if (reg == davinci_pllc0_regs)
  34. /* Unlock PLL registers. */
  35. clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
  36. /*
  37. * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
  38. * through MMR
  39. */
  40. clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
  41. /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
  42. clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
  43. /* Set PLLEN=0 => PLL BYPASS MODE */
  44. clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
  45. da850_waitloop(150);
  46. if (reg == davinci_pllc0_regs) {
  47. /*
  48. * Select the Clock Mode bit 8 as External Clock or On Chip
  49. * Oscilator
  50. */
  51. dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
  52. setbits_le32(&reg->pllctl,
  53. (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
  54. }
  55. /* Clear PLLRST bit to reset the PLL */
  56. clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
  57. /* Disable the PLL output */
  58. setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
  59. /* PLL initialization sequence */
  60. /*
  61. * Power up the PLL- PWRDN bit set to 0 to bring the PLL out of
  62. * power down bit
  63. */
  64. clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
  65. /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
  66. clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
  67. #if defined(CONFIG_SYS_DA850_PLL0_PREDIV)
  68. /* program the prediv */
  69. if (reg == davinci_pllc0_regs && CONFIG_SYS_DA850_PLL0_PREDIV)
  70. writel((PLL_DIVEN | CONFIG_SYS_DA850_PLL0_PREDIV),
  71. &reg->prediv);
  72. #endif
  73. /* Program the required multiplier value in PLLM */
  74. writel(pllmult, &reg->pllm);
  75. /* program the postdiv */
  76. if (reg == davinci_pllc0_regs)
  77. writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
  78. &reg->postdiv);
  79. else
  80. writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
  81. &reg->postdiv);
  82. /*
  83. * Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
  84. * no GO operation is currently in progress
  85. */
  86. while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
  87. ;
  88. if (reg == davinci_pllc0_regs) {
  89. writel(CONFIG_SYS_DA850_PLL0_PLLDIV1, &reg->plldiv1);
  90. writel(CONFIG_SYS_DA850_PLL0_PLLDIV2, &reg->plldiv2);
  91. writel(CONFIG_SYS_DA850_PLL0_PLLDIV3, &reg->plldiv3);
  92. writel(CONFIG_SYS_DA850_PLL0_PLLDIV4, &reg->plldiv4);
  93. writel(CONFIG_SYS_DA850_PLL0_PLLDIV5, &reg->plldiv5);
  94. writel(CONFIG_SYS_DA850_PLL0_PLLDIV6, &reg->plldiv6);
  95. writel(CONFIG_SYS_DA850_PLL0_PLLDIV7, &reg->plldiv7);
  96. } else {
  97. writel(CONFIG_SYS_DA850_PLL1_PLLDIV1, &reg->plldiv1);
  98. writel(CONFIG_SYS_DA850_PLL1_PLLDIV2, &reg->plldiv2);
  99. writel(CONFIG_SYS_DA850_PLL1_PLLDIV3, &reg->plldiv3);
  100. }
  101. /*
  102. * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
  103. * transition.
  104. */
  105. setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
  106. /*
  107. * Wait for the GOSTAT bit in PLLSTAT to clear to 0
  108. * (completion of phase alignment).
  109. */
  110. while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
  111. ;
  112. /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
  113. da850_waitloop(200);
  114. /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
  115. setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
  116. /* Wait for PLL to lock. See PLL spec for PLL lock time */
  117. da850_waitloop(2400);
  118. /*
  119. * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
  120. * mode
  121. */
  122. setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
  123. /*
  124. * clear EMIFA and EMIFB clock source settings, let them
  125. * run off SYSCLK
  126. */
  127. if (reg == davinci_pllc0_regs)
  128. dv_maskbits(&davinci_syscfg_regs->cfgchip3,
  129. ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
  130. return 0;
  131. }
  132. #endif /* CONFIG_SYS_DA850_PLL_INIT */
  133. #if defined(CONFIG_SYS_DA850_DDR_INIT)
  134. static int da850_ddr_setup(void)
  135. {
  136. unsigned long tmp;
  137. /* Enable the Clock to DDR2/mDDR */
  138. lpsc_on(DAVINCI_LPSC_DDR_EMIF);
  139. tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
  140. if ((tmp & VTP_POWERDWN) == VTP_POWERDWN) {
  141. /* Begin VTP Calibration */
  142. clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
  143. clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
  144. setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
  145. clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
  146. setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
  147. /* Polling READY bit to see when VTP calibration is done */
  148. tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
  149. while ((tmp & VTP_READY) != VTP_READY)
  150. tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
  151. setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
  152. setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
  153. }
  154. setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_IOPWRDWN);
  155. writel(CONFIG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
  156. if (CONFIG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT)) {
  157. /* DDR2 */
  158. clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
  159. (1 << DDR_SLEW_DDR_PDENA_BIT) |
  160. (1 << DDR_SLEW_CMOSEN_BIT));
  161. } else {
  162. /* MOBILE DDR */
  163. setbits_le32(&davinci_syscfg1_regs->ddr_slew,
  164. (1 << DDR_SLEW_DDR_PDENA_BIT) |
  165. (1 << DDR_SLEW_CMOSEN_BIT));
  166. }
  167. /*
  168. * SDRAM Configuration Register (SDCR):
  169. * First set the BOOTUNLOCK bit to make configuration bits
  170. * writeable.
  171. */
  172. setbits_le32(&dv_ddr2_regs_ctrl->sdbcr, DV_DDR_BOOTUNLOCK);
  173. /*
  174. * Write the new value of these bits and clear BOOTUNLOCK.
  175. * At the same time, set the TIMUNLOCK bit to allow changing
  176. * the timing registers
  177. */
  178. tmp = CONFIG_SYS_DA850_DDR2_SDBCR;
  179. tmp &= ~DV_DDR_BOOTUNLOCK;
  180. tmp |= DV_DDR_TIMUNLOCK;
  181. writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
  182. /* write memory configuration and timing */
  183. if (!(CONFIG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT))) {
  184. /* MOBILE DDR only*/
  185. writel(CONFIG_SYS_DA850_DDR2_SDBCR2,
  186. &dv_ddr2_regs_ctrl->sdbcr2);
  187. }
  188. writel(CONFIG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
  189. writel(CONFIG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
  190. /* clear the TIMUNLOCK bit and write the value of the CL field */
  191. tmp &= ~DV_DDR_TIMUNLOCK;
  192. writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
  193. /*
  194. * LPMODEN and MCLKSTOPEN must be set!
  195. * Without this bits set, PSC don;t switch states !!
  196. */
  197. writel(CONFIG_SYS_DA850_DDR2_SDRCR |
  198. (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
  199. (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
  200. &dv_ddr2_regs_ctrl->sdrcr);
  201. /* SyncReset the Clock to EMIF3A SDRAM */
  202. lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
  203. /* Enable the Clock to EMIF3A SDRAM */
  204. lpsc_on(DAVINCI_LPSC_DDR_EMIF);
  205. /* disable self refresh */
  206. clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
  207. DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_MCLKSTOPEN);
  208. writel(CONFIG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
  209. return 0;
  210. }
  211. #endif /* CONFIG_SYS_DA850_DDR_INIT */
  212. __attribute__((weak))
  213. void board_gpio_init(void)
  214. {
  215. return;
  216. }
  217. int arch_cpu_init(void)
  218. {
  219. /* Unlock kick registers */
  220. writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
  221. writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
  222. dv_maskbits(&davinci_syscfg_regs->suspsrc,
  223. CONFIG_SYS_DA850_SYSCFG_SUSPSRC);
  224. /* configure pinmux settings */
  225. if (davinci_configure_pin_mux_items(pinmuxes, pinmuxes_size))
  226. return 1;
  227. #if defined(CONFIG_SYS_DA850_PLL_INIT)
  228. /* PLL setup */
  229. da850_pll_init(davinci_pllc0_regs, CONFIG_SYS_DA850_PLL0_PLLM);
  230. da850_pll_init(davinci_pllc1_regs, CONFIG_SYS_DA850_PLL1_PLLM);
  231. #endif
  232. /* setup CSn config */
  233. #if defined(CONFIG_SYS_DA850_CS2CFG)
  234. writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
  235. #endif
  236. #if defined(CONFIG_SYS_DA850_CS3CFG)
  237. writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
  238. #endif
  239. da8xx_configure_lpsc_items(lpsc, lpsc_size);
  240. /* GPIO setup */
  241. board_gpio_init();
  242. #if !CONFIG_IS_ENABLED(DM_SERIAL)
  243. NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
  244. CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
  245. #endif
  246. /*
  247. * Fix Power and Emulation Management Register
  248. * see sprufw3a.pdf page 37 Table 24
  249. */
  250. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  251. DAVINCI_UART_PWREMU_MGMT_UTRST),
  252. #if (CONFIG_SYS_NS16550_COM1 == DAVINCI_UART0_BASE)
  253. &davinci_uart0_ctrl_regs->pwremu_mgmt);
  254. #else
  255. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  256. #endif
  257. #if defined(CONFIG_SYS_DA850_DDR_INIT)
  258. da850_ddr_setup();
  259. #endif
  260. return 0;
  261. }