blob: 78d50d4e7191c4fa88daf39d5594407538e6dc0b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherfe954e32011-09-14 19:59:38 +00002/*
Christian Riesch0e5e0c52011-11-08 08:55:07 -05003 * SoC-specific lowlevel code for DA850
Heiko Schocherfe954e32011-09-14 19:59:38 +00004 *
5 * Copyright (C) 2011
6 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
Heiko Schocherfe954e32011-09-14 19:59:38 +00007 */
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <config.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000010#include <nand.h>
11#include <ns16550.h>
12#include <post.h>
Christian Riesch0e5e0c52011-11-08 08:55:07 -050013#include <asm/arch/da850_lowlevel.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000014#include <asm/arch/hardware.h>
Christian Riesch2eb60502011-11-28 23:46:20 +000015#include <asm/arch/davinci_misc.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000016#include <asm/arch/ddr2_defs.h>
Khoronzhuk, Ivan753a00a2014-06-07 04:22:52 +030017#include <asm/ti-common/davinci_nand.h>
Heiko Schocher34061e82011-11-15 10:00:02 -050018#include <asm/arch/pll_defs.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000019
Eric Benard3c3dc792013-04-22 05:54:59 +000020void davinci_enable_uart0(void)
21{
22 lpsc_on(DAVINCI_LPSC_UART0);
23
24 /* Bringup UART0 out of reset */
25 REG(UART0_PWREMU_MGMT) = 0x00006001;
26}
27
Sughosh Ganua2616972012-02-02 00:44:41 +000028#if defined(CONFIG_SYS_DA850_PLL_INIT)
Manish Badarkhed47dffe2014-04-11 08:02:04 +053029static void da850_waitloop(unsigned long loopcnt)
Heiko Schocherfe954e32011-09-14 19:59:38 +000030{
31 unsigned long i;
32
33 for (i = 0; i < loopcnt; i++)
34 asm(" NOP");
35}
36
Manish Badarkhed47dffe2014-04-11 08:02:04 +053037static int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
Heiko Schocherfe954e32011-09-14 19:59:38 +000038{
39 if (reg == davinci_pllc0_regs)
40 /* Unlock PLL registers. */
Heiko Schocher34061e82011-11-15 10:00:02 -050041 clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
Heiko Schocherfe954e32011-09-14 19:59:38 +000042
43 /*
44 * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
45 * through MMR
46 */
Heiko Schocher34061e82011-11-15 10:00:02 -050047 clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000048 /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
Heiko Schocher34061e82011-11-15 10:00:02 -050049 clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000050
51 /* Set PLLEN=0 => PLL BYPASS MODE */
Heiko Schocher34061e82011-11-15 10:00:02 -050052 clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000053
Christian Riesch0e5e0c52011-11-08 08:55:07 -050054 da850_waitloop(150);
Heiko Schocherfe954e32011-09-14 19:59:38 +000055
56 if (reg == davinci_pllc0_regs) {
57 /*
58 * Select the Clock Mode bit 8 as External Clock or On Chip
59 * Oscilator
60 */
Heiko Schocher34061e82011-11-15 10:00:02 -050061 dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
62 setbits_le32(&reg->pllctl,
63 (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
Heiko Schocherfe954e32011-09-14 19:59:38 +000064 }
65
66 /* Clear PLLRST bit to reset the PLL */
Heiko Schocher34061e82011-11-15 10:00:02 -050067 clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +000068
69 /* Disable the PLL output */
Heiko Schocher34061e82011-11-15 10:00:02 -050070 setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000071
72 /* PLL initialization sequence */
73 /*
74 * Power up the PLL- PWRDN bit set to 0 to bring the PLL out of
75 * power down bit
76 */
Heiko Schocher34061e82011-11-15 10:00:02 -050077 clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000078
79 /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
Heiko Schocher34061e82011-11-15 10:00:02 -050080 clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000081
Ben Gardinerb2a47522012-01-16 07:43:15 +000082#if defined(CONFIG_SYS_DA850_PLL0_PREDIV)
83 /* program the prediv */
84 if (reg == davinci_pllc0_regs && CONFIG_SYS_DA850_PLL0_PREDIV)
85 writel((PLL_DIVEN | CONFIG_SYS_DA850_PLL0_PREDIV),
86 &reg->prediv);
87#endif
88
Heiko Schocherfe954e32011-09-14 19:59:38 +000089 /* Program the required multiplier value in PLLM */
90 writel(pllmult, &reg->pllm);
91
92 /* program the postdiv */
93 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -050094 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +000095 &reg->postdiv);
96 else
Heiko Schocher34061e82011-11-15 10:00:02 -050097 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +000098 &reg->postdiv);
99
100 /*
101 * Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
102 * no GO operation is currently in progress
103 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500104 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000105 ;
106
107 if (reg == davinci_pllc0_regs) {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500108 writel(CONFIG_SYS_DA850_PLL0_PLLDIV1, &reg->plldiv1);
109 writel(CONFIG_SYS_DA850_PLL0_PLLDIV2, &reg->plldiv2);
110 writel(CONFIG_SYS_DA850_PLL0_PLLDIV3, &reg->plldiv3);
111 writel(CONFIG_SYS_DA850_PLL0_PLLDIV4, &reg->plldiv4);
112 writel(CONFIG_SYS_DA850_PLL0_PLLDIV5, &reg->plldiv5);
113 writel(CONFIG_SYS_DA850_PLL0_PLLDIV6, &reg->plldiv6);
114 writel(CONFIG_SYS_DA850_PLL0_PLLDIV7, &reg->plldiv7);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000115 } else {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500116 writel(CONFIG_SYS_DA850_PLL1_PLLDIV1, &reg->plldiv1);
117 writel(CONFIG_SYS_DA850_PLL1_PLLDIV2, &reg->plldiv2);
118 writel(CONFIG_SYS_DA850_PLL1_PLLDIV3, &reg->plldiv3);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000119 }
120
121 /*
122 * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
123 * transition.
124 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500125 setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000126
127 /*
128 * Wait for the GOSTAT bit in PLLSTAT to clear to 0
129 * (completion of phase alignment).
130 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500131 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000132 ;
133
134 /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500135 da850_waitloop(200);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000136
137 /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
Heiko Schocher34061e82011-11-15 10:00:02 -0500138 setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000139
140 /* Wait for PLL to lock. See PLL spec for PLL lock time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500141 da850_waitloop(2400);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000142
143 /*
144 * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
145 * mode
146 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500147 setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000148
Heiko Schocherfe954e32011-09-14 19:59:38 +0000149 /*
150 * clear EMIFA and EMIFB clock source settings, let them
151 * run off SYSCLK
152 */
153 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -0500154 dv_maskbits(&davinci_syscfg_regs->cfgchip3,
155 ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
Heiko Schocherfe954e32011-09-14 19:59:38 +0000156
157 return 0;
158}
Sughosh Ganua2616972012-02-02 00:44:41 +0000159#endif /* CONFIG_SYS_DA850_PLL_INIT */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000160
Sughosh Ganua2616972012-02-02 00:44:41 +0000161#if defined(CONFIG_SYS_DA850_DDR_INIT)
Manish Badarkhed47dffe2014-04-11 08:02:04 +0530162static int da850_ddr_setup(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000163{
164 unsigned long tmp;
165
166 /* Enable the Clock to DDR2/mDDR */
Christian Riesch99271c82011-11-08 08:55:10 -0500167 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000168
169 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
170 if ((tmp & VTP_POWERDWN) == VTP_POWERDWN) {
171 /* Begin VTP Calibration */
172 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
173 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
174 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
175 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
176 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
177
178 /* Polling READY bit to see when VTP calibration is done */
179 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
180 while ((tmp & VTP_READY) != VTP_READY)
181 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
182
183 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
184 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000185 }
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000186 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_IOPWRDWN);
Tom Rini6a5dccc2022-11-16 13:10:41 -0500187 writel(CFG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000188
Tom Rini6a5dccc2022-11-16 13:10:41 -0500189 if (CFG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT)) {
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000190 /* DDR2 */
191 clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
192 (1 << DDR_SLEW_DDR_PDENA_BIT) |
193 (1 << DDR_SLEW_CMOSEN_BIT));
194 } else {
195 /* MOBILE DDR */
196 setbits_le32(&davinci_syscfg1_regs->ddr_slew,
197 (1 << DDR_SLEW_DDR_PDENA_BIT) |
198 (1 << DDR_SLEW_CMOSEN_BIT));
199 }
Heiko Schocherfe954e32011-09-14 19:59:38 +0000200
Christian Riesch81ad48e2011-11-08 08:55:13 -0500201 /*
202 * SDRAM Configuration Register (SDCR):
203 * First set the BOOTUNLOCK bit to make configuration bits
204 * writeable.
205 */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000206 setbits_le32(&dv_ddr2_regs_ctrl->sdbcr, DV_DDR_BOOTUNLOCK);
207
Christian Riesch81ad48e2011-11-08 08:55:13 -0500208 /*
209 * Write the new value of these bits and clear BOOTUNLOCK.
210 * At the same time, set the TIMUNLOCK bit to allow changing
211 * the timing registers
212 */
Tom Rini6a5dccc2022-11-16 13:10:41 -0500213 tmp = CFG_SYS_DA850_DDR2_SDBCR;
Heiko Schocher34061e82011-11-15 10:00:02 -0500214 tmp &= ~DV_DDR_BOOTUNLOCK;
215 tmp |= DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500216 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000217
Christian Riesch81ad48e2011-11-08 08:55:13 -0500218 /* write memory configuration and timing */
Tom Rini6a5dccc2022-11-16 13:10:41 -0500219 if (!(CFG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT))) {
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000220 /* MOBILE DDR only*/
Tom Rini6a5dccc2022-11-16 13:10:41 -0500221 writel(CFG_SYS_DA850_DDR2_SDBCR2,
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000222 &dv_ddr2_regs_ctrl->sdbcr2);
223 }
Tom Rini6a5dccc2022-11-16 13:10:41 -0500224 writel(CFG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
225 writel(CFG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000226
Christian Riesch81ad48e2011-11-08 08:55:13 -0500227 /* clear the TIMUNLOCK bit and write the value of the CL field */
Heiko Schocher34061e82011-11-15 10:00:02 -0500228 tmp &= ~DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500229 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000230
231 /*
232 * LPMODEN and MCLKSTOPEN must be set!
233 * Without this bits set, PSC don;t switch states !!
234 */
Tom Rini6a5dccc2022-11-16 13:10:41 -0500235 writel(CFG_SYS_DA850_DDR2_SDRCR |
Heiko Schocherfe954e32011-09-14 19:59:38 +0000236 (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
237 (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
238 &dv_ddr2_regs_ctrl->sdrcr);
239
240 /* SyncReset the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500241 lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000242 /* Enable the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500243 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000244
245 /* disable self refresh */
Heiko Schocher34061e82011-11-15 10:00:02 -0500246 clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000247 DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_MCLKSTOPEN);
Tom Rini6a5dccc2022-11-16 13:10:41 -0500248 writel(CFG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000249
250 return 0;
251}
Sughosh Ganua2616972012-02-02 00:44:41 +0000252#endif /* CONFIG_SYS_DA850_DDR_INIT */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000253
Heiko Schocherfe954e32011-09-14 19:59:38 +0000254__attribute__((weak))
255void board_gpio_init(void)
256{
257 return;
258}
259
Heiko Schocherfe954e32011-09-14 19:59:38 +0000260int arch_cpu_init(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000261{
Heiko Schocherfe954e32011-09-14 19:59:38 +0000262 /* Unlock kick registers */
Heiko Schocher34061e82011-11-15 10:00:02 -0500263 writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
264 writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000265
266 dv_maskbits(&davinci_syscfg_regs->suspsrc,
Tom Rini6a5dccc2022-11-16 13:10:41 -0500267 CFG_SYS_DA850_SYSCFG_SUSPSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000268
Christian Riesch2eb60502011-11-28 23:46:20 +0000269 /* configure pinmux settings */
270 if (davinci_configure_pin_mux_items(pinmuxes, pinmuxes_size))
271 return 1;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000272
Sughosh Ganua2616972012-02-02 00:44:41 +0000273#if defined(CONFIG_SYS_DA850_PLL_INIT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000274 /* PLL setup */
Tom Rini6a5dccc2022-11-16 13:10:41 -0500275 da850_pll_init(davinci_pllc0_regs, CFG_SYS_DA850_PLL0_PLLM);
276 da850_pll_init(davinci_pllc1_regs, CFG_SYS_DA850_PLL1_PLLM);
Sughosh Ganua2616972012-02-02 00:44:41 +0000277#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000278 /* setup CSn config */
Heiko Schocher34061e82011-11-15 10:00:02 -0500279#if defined(CONFIG_SYS_DA850_CS2CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500280 writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500281#endif
282#if defined(CONFIG_SYS_DA850_CS3CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500283 writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500284#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000285
Sughosh Ganua2616972012-02-02 00:44:41 +0000286 da8xx_configure_lpsc_items(lpsc, lpsc_size);
287
288 /* GPIO setup */
289 board_gpio_init();
290
Adam Ford4a60fef2018-09-19 16:06:49 -0500291#if !CONFIG_IS_ENABLED(DM_SERIAL)
Tom Rinidf6a2152022-11-16 13:10:28 -0500292 ns16550_init((struct ns16550 *)(CFG_SYS_NS16550_COM1),
293 CFG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
Adam Ford4a60fef2018-09-19 16:06:49 -0500294#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000295 /*
296 * Fix Power and Emulation Management Register
297 * see sprufw3a.pdf page 37 Table 24
298 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500299 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
300 DAVINCI_UART_PWREMU_MGMT_UTRST),
Tom Rinidf6a2152022-11-16 13:10:28 -0500301#if (CFG_SYS_NS16550_COM1 == DAVINCI_UART0_BASE)
Heiko Schochere999dca2013-08-05 16:00:37 +0200302 &davinci_uart0_ctrl_regs->pwremu_mgmt);
303#else
Heiko Schocher34061e82011-11-15 10:00:02 -0500304 &davinci_uart2_ctrl_regs->pwremu_mgmt);
Heiko Schochere999dca2013-08-05 16:00:37 +0200305#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000306
Sughosh Ganua2616972012-02-02 00:44:41 +0000307#if defined(CONFIG_SYS_DA850_DDR_INIT)
Heiko Schocher34061e82011-11-15 10:00:02 -0500308 da850_ddr_setup();
Sughosh Ganua2616972012-02-02 00:44:41 +0000309#endif
310
Heiko Schocherfe954e32011-09-14 19:59:38 +0000311 return 0;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000312}