da850_lowlevel.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * SoC-specific lowlevel code for DA850
  3. *
  4. * Copyright (C) 2011
  5. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <common.h>
  25. #include <nand.h>
  26. #include <ns16550.h>
  27. #include <post.h>
  28. #include <asm/arch/da850_lowlevel.h>
  29. #include <asm/arch/hardware.h>
  30. #include <asm/arch/ddr2_defs.h>
  31. #include <asm/arch/emif_defs.h>
  32. #include <asm/arch/pll_defs.h>
  33. void da850_waitloop(unsigned long loopcnt)
  34. {
  35. unsigned long i;
  36. for (i = 0; i < loopcnt; i++)
  37. asm(" NOP");
  38. }
  39. int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
  40. {
  41. if (reg == davinci_pllc0_regs)
  42. /* Unlock PLL registers. */
  43. clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
  44. /*
  45. * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
  46. * through MMR
  47. */
  48. clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
  49. /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
  50. clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
  51. /* Set PLLEN=0 => PLL BYPASS MODE */
  52. clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
  53. da850_waitloop(150);
  54. if (reg == davinci_pllc0_regs) {
  55. /*
  56. * Select the Clock Mode bit 8 as External Clock or On Chip
  57. * Oscilator
  58. */
  59. dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
  60. setbits_le32(&reg->pllctl,
  61. (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
  62. }
  63. /* Clear PLLRST bit to reset the PLL */
  64. clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
  65. /* Disable the PLL output */
  66. setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
  67. /* PLL initialization sequence */
  68. /*
  69. * Power up the PLL- PWRDN bit set to 0 to bring the PLL out of
  70. * power down bit
  71. */
  72. clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
  73. /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
  74. clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
  75. /* Program the required multiplier value in PLLM */
  76. writel(pllmult, &reg->pllm);
  77. /* program the postdiv */
  78. if (reg == davinci_pllc0_regs)
  79. writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
  80. &reg->postdiv);
  81. else
  82. writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
  83. &reg->postdiv);
  84. /*
  85. * Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
  86. * no GO operation is currently in progress
  87. */
  88. while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
  89. ;
  90. if (reg == davinci_pllc0_regs) {
  91. writel(CONFIG_SYS_DA850_PLL0_PLLDIV1, &reg->plldiv1);
  92. writel(CONFIG_SYS_DA850_PLL0_PLLDIV2, &reg->plldiv2);
  93. writel(CONFIG_SYS_DA850_PLL0_PLLDIV3, &reg->plldiv3);
  94. writel(CONFIG_SYS_DA850_PLL0_PLLDIV4, &reg->plldiv4);
  95. writel(CONFIG_SYS_DA850_PLL0_PLLDIV5, &reg->plldiv5);
  96. writel(CONFIG_SYS_DA850_PLL0_PLLDIV6, &reg->plldiv6);
  97. writel(CONFIG_SYS_DA850_PLL0_PLLDIV7, &reg->plldiv7);
  98. } else {
  99. writel(CONFIG_SYS_DA850_PLL1_PLLDIV1, &reg->plldiv1);
  100. writel(CONFIG_SYS_DA850_PLL1_PLLDIV2, &reg->plldiv2);
  101. writel(CONFIG_SYS_DA850_PLL1_PLLDIV3, &reg->plldiv3);
  102. }
  103. /*
  104. * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
  105. * transition.
  106. */
  107. setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
  108. /*
  109. * Wait for the GOSTAT bit in PLLSTAT to clear to 0
  110. * (completion of phase alignment).
  111. */
  112. while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
  113. ;
  114. /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
  115. da850_waitloop(200);
  116. /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
  117. setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
  118. /* Wait for PLL to lock. See PLL spec for PLL lock time */
  119. da850_waitloop(2400);
  120. /*
  121. * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
  122. * mode
  123. */
  124. setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
  125. /*
  126. * clear EMIFA and EMIFB clock source settings, let them
  127. * run off SYSCLK
  128. */
  129. if (reg == davinci_pllc0_regs)
  130. dv_maskbits(&davinci_syscfg_regs->cfgchip3,
  131. ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
  132. return 0;
  133. }
  134. 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. setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_IOPWRDWN);
  154. }
  155. writel(CONFIG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
  156. clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
  157. (1 << DDR_SLEW_CMOSEN_BIT));
  158. /*
  159. * SDRAM Configuration Register (SDCR):
  160. * First set the BOOTUNLOCK bit to make configuration bits
  161. * writeable.
  162. */
  163. setbits_le32(&dv_ddr2_regs_ctrl->sdbcr, DV_DDR_BOOTUNLOCK);
  164. /*
  165. * Write the new value of these bits and clear BOOTUNLOCK.
  166. * At the same time, set the TIMUNLOCK bit to allow changing
  167. * the timing registers
  168. */
  169. tmp = CONFIG_SYS_DA850_DDR2_SDBCR;
  170. tmp &= ~DV_DDR_BOOTUNLOCK;
  171. tmp |= DV_DDR_TIMUNLOCK;
  172. writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
  173. /* write memory configuration and timing */
  174. writel(CONFIG_SYS_DA850_DDR2_SDBCR2, &dv_ddr2_regs_ctrl->sdbcr2);
  175. writel(CONFIG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
  176. writel(CONFIG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
  177. /* clear the TIMUNLOCK bit and write the value of the CL field */
  178. tmp &= ~DV_DDR_TIMUNLOCK;
  179. writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
  180. /*
  181. * LPMODEN and MCLKSTOPEN must be set!
  182. * Without this bits set, PSC don;t switch states !!
  183. */
  184. writel(CONFIG_SYS_DA850_DDR2_SDRCR |
  185. (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
  186. (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
  187. &dv_ddr2_regs_ctrl->sdrcr);
  188. /* SyncReset the Clock to EMIF3A SDRAM */
  189. lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
  190. /* Enable the Clock to EMIF3A SDRAM */
  191. lpsc_on(DAVINCI_LPSC_DDR_EMIF);
  192. /* disable self refresh */
  193. clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
  194. DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_LPMODEN);
  195. writel(CONFIG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
  196. return 0;
  197. }
  198. void da850_pinmux_ctl(unsigned long offset, unsigned long mask,
  199. unsigned long value)
  200. {
  201. clrbits_le32(&davinci_syscfg_regs->pinmux[offset], mask);
  202. setbits_le32(&davinci_syscfg_regs->pinmux[offset], (mask & value));
  203. }
  204. __attribute__((weak))
  205. void board_gpio_init(void)
  206. {
  207. return;
  208. }
  209. int arch_cpu_init(void)
  210. {
  211. /* Unlock kick registers */
  212. writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
  213. writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
  214. dv_maskbits(&davinci_syscfg_regs->suspsrc,
  215. CONFIG_SYS_DA850_SYSCFG_SUSPSRC);
  216. /* Setup Pinmux */
  217. da850_pinmux_ctl(0, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX0);
  218. da850_pinmux_ctl(1, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX1);
  219. da850_pinmux_ctl(2, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX2);
  220. da850_pinmux_ctl(3, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX3);
  221. da850_pinmux_ctl(4, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX4);
  222. da850_pinmux_ctl(5, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX5);
  223. da850_pinmux_ctl(6, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX6);
  224. da850_pinmux_ctl(7, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX7);
  225. da850_pinmux_ctl(8, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX8);
  226. da850_pinmux_ctl(9, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX9);
  227. da850_pinmux_ctl(10, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX10);
  228. da850_pinmux_ctl(11, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX11);
  229. da850_pinmux_ctl(12, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX12);
  230. da850_pinmux_ctl(13, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX13);
  231. da850_pinmux_ctl(14, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX14);
  232. da850_pinmux_ctl(15, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX15);
  233. da850_pinmux_ctl(16, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX16);
  234. da850_pinmux_ctl(17, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX17);
  235. da850_pinmux_ctl(18, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX18);
  236. da850_pinmux_ctl(19, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX19);
  237. /* PLL setup */
  238. da850_pll_init(davinci_pllc0_regs, CONFIG_SYS_DA850_PLL0_PLLM);
  239. da850_pll_init(davinci_pllc1_regs, CONFIG_SYS_DA850_PLL1_PLLM);
  240. /* GPIO setup */
  241. board_gpio_init();
  242. /* setup CSn config */
  243. #if defined(CONFIG_SYS_DA850_CS2CFG)
  244. writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
  245. #endif
  246. #if defined(CONFIG_SYS_DA850_CS3CFG)
  247. writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
  248. #endif
  249. lpsc_on(CONFIG_SYS_DA850_LPSC_UART);
  250. NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
  251. CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
  252. /*
  253. * Fix Power and Emulation Management Register
  254. * see sprufw3a.pdf page 37 Table 24
  255. */
  256. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  257. DAVINCI_UART_PWREMU_MGMT_UTRST),
  258. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  259. da850_ddr_setup();
  260. return 0;
  261. }