blob: 127beb86bc24e65ee438f87c7e5677ee18a93995 [file] [log] [blame]
Heiko Schocherfe954e32011-09-14 19:59:38 +00001/*
Christian Riesch0e5e0c52011-11-08 08:55:07 -05002 * SoC-specific lowlevel code for DA850
Heiko Schocherfe954e32011-09-14 19:59:38 +00003 *
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>
Christian Riesch0e5e0c52011-11-08 08:55:07 -050028#include <asm/arch/da850_lowlevel.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000029#include <asm/arch/hardware.h>
Christian Riesch2eb60502011-11-28 23:46:20 +000030#include <asm/arch/davinci_misc.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000031#include <asm/arch/ddr2_defs.h>
32#include <asm/arch/emif_defs.h>
Heiko Schocher34061e82011-11-15 10:00:02 -050033#include <asm/arch/pll_defs.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000034
Eric Benard3c3dc792013-04-22 05:54:59 +000035void davinci_enable_uart0(void)
36{
37 lpsc_on(DAVINCI_LPSC_UART0);
38
39 /* Bringup UART0 out of reset */
40 REG(UART0_PWREMU_MGMT) = 0x00006001;
41}
42
Sughosh Ganua2616972012-02-02 00:44:41 +000043#if defined(CONFIG_SYS_DA850_PLL_INIT)
Christian Riesch0e5e0c52011-11-08 08:55:07 -050044void da850_waitloop(unsigned long loopcnt)
Heiko Schocherfe954e32011-09-14 19:59:38 +000045{
46 unsigned long i;
47
48 for (i = 0; i < loopcnt; i++)
49 asm(" NOP");
50}
51
Christian Riesch0e5e0c52011-11-08 08:55:07 -050052int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
Heiko Schocherfe954e32011-09-14 19:59:38 +000053{
54 if (reg == davinci_pllc0_regs)
55 /* Unlock PLL registers. */
Heiko Schocher34061e82011-11-15 10:00:02 -050056 clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
Heiko Schocherfe954e32011-09-14 19:59:38 +000057
58 /*
59 * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
60 * through MMR
61 */
Heiko Schocher34061e82011-11-15 10:00:02 -050062 clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000063 /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
Heiko Schocher34061e82011-11-15 10:00:02 -050064 clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000065
66 /* Set PLLEN=0 => PLL BYPASS MODE */
Heiko Schocher34061e82011-11-15 10:00:02 -050067 clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000068
Christian Riesch0e5e0c52011-11-08 08:55:07 -050069 da850_waitloop(150);
Heiko Schocherfe954e32011-09-14 19:59:38 +000070
71 if (reg == davinci_pllc0_regs) {
72 /*
73 * Select the Clock Mode bit 8 as External Clock or On Chip
74 * Oscilator
75 */
Heiko Schocher34061e82011-11-15 10:00:02 -050076 dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
77 setbits_le32(&reg->pllctl,
78 (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
Heiko Schocherfe954e32011-09-14 19:59:38 +000079 }
80
81 /* Clear PLLRST bit to reset the PLL */
Heiko Schocher34061e82011-11-15 10:00:02 -050082 clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +000083
84 /* Disable the PLL output */
Heiko Schocher34061e82011-11-15 10:00:02 -050085 setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000086
87 /* PLL initialization sequence */
88 /*
89 * Power up the PLL- PWRDN bit set to 0 to bring the PLL out of
90 * power down bit
91 */
Heiko Schocher34061e82011-11-15 10:00:02 -050092 clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000093
94 /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
Heiko Schocher34061e82011-11-15 10:00:02 -050095 clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000096
Ben Gardinerb2a47522012-01-16 07:43:15 +000097#if defined(CONFIG_SYS_DA850_PLL0_PREDIV)
98 /* program the prediv */
99 if (reg == davinci_pllc0_regs && CONFIG_SYS_DA850_PLL0_PREDIV)
100 writel((PLL_DIVEN | CONFIG_SYS_DA850_PLL0_PREDIV),
101 &reg->prediv);
102#endif
103
Heiko Schocherfe954e32011-09-14 19:59:38 +0000104 /* Program the required multiplier value in PLLM */
105 writel(pllmult, &reg->pllm);
106
107 /* program the postdiv */
108 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -0500109 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +0000110 &reg->postdiv);
111 else
Heiko Schocher34061e82011-11-15 10:00:02 -0500112 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +0000113 &reg->postdiv);
114
115 /*
116 * Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
117 * no GO operation is currently in progress
118 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500119 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000120 ;
121
122 if (reg == davinci_pllc0_regs) {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500123 writel(CONFIG_SYS_DA850_PLL0_PLLDIV1, &reg->plldiv1);
124 writel(CONFIG_SYS_DA850_PLL0_PLLDIV2, &reg->plldiv2);
125 writel(CONFIG_SYS_DA850_PLL0_PLLDIV3, &reg->plldiv3);
126 writel(CONFIG_SYS_DA850_PLL0_PLLDIV4, &reg->plldiv4);
127 writel(CONFIG_SYS_DA850_PLL0_PLLDIV5, &reg->plldiv5);
128 writel(CONFIG_SYS_DA850_PLL0_PLLDIV6, &reg->plldiv6);
129 writel(CONFIG_SYS_DA850_PLL0_PLLDIV7, &reg->plldiv7);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000130 } else {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500131 writel(CONFIG_SYS_DA850_PLL1_PLLDIV1, &reg->plldiv1);
132 writel(CONFIG_SYS_DA850_PLL1_PLLDIV2, &reg->plldiv2);
133 writel(CONFIG_SYS_DA850_PLL1_PLLDIV3, &reg->plldiv3);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000134 }
135
136 /*
137 * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
138 * transition.
139 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500140 setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000141
142 /*
143 * Wait for the GOSTAT bit in PLLSTAT to clear to 0
144 * (completion of phase alignment).
145 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500146 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000147 ;
148
149 /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500150 da850_waitloop(200);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000151
152 /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
Heiko Schocher34061e82011-11-15 10:00:02 -0500153 setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000154
155 /* Wait for PLL to lock. See PLL spec for PLL lock time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500156 da850_waitloop(2400);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000157
158 /*
159 * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
160 * mode
161 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500162 setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000163
164
165 /*
166 * clear EMIFA and EMIFB clock source settings, let them
167 * run off SYSCLK
168 */
169 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -0500170 dv_maskbits(&davinci_syscfg_regs->cfgchip3,
171 ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
Heiko Schocherfe954e32011-09-14 19:59:38 +0000172
173 return 0;
174}
Sughosh Ganua2616972012-02-02 00:44:41 +0000175#endif /* CONFIG_SYS_DA850_PLL_INIT */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000176
Sughosh Ganua2616972012-02-02 00:44:41 +0000177#if defined(CONFIG_SYS_DA850_DDR_INIT)
Heiko Schocher34061e82011-11-15 10:00:02 -0500178int da850_ddr_setup(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000179{
180 unsigned long tmp;
181
182 /* Enable the Clock to DDR2/mDDR */
Christian Riesch99271c82011-11-08 08:55:10 -0500183 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000184
185 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
186 if ((tmp & VTP_POWERDWN) == VTP_POWERDWN) {
187 /* Begin VTP Calibration */
188 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
189 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
190 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
191 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
192 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
193
194 /* Polling READY bit to see when VTP calibration is done */
195 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
196 while ((tmp & VTP_READY) != VTP_READY)
197 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
198
199 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
200 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000201 }
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000202 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_IOPWRDWN);
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500203 writel(CONFIG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000204
205 if (CONFIG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT)) {
206 /* DDR2 */
207 clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
208 (1 << DDR_SLEW_DDR_PDENA_BIT) |
209 (1 << DDR_SLEW_CMOSEN_BIT));
210 } else {
211 /* MOBILE DDR */
212 setbits_le32(&davinci_syscfg1_regs->ddr_slew,
213 (1 << DDR_SLEW_DDR_PDENA_BIT) |
214 (1 << DDR_SLEW_CMOSEN_BIT));
215 }
Heiko Schocherfe954e32011-09-14 19:59:38 +0000216
Christian Riesch81ad48e2011-11-08 08:55:13 -0500217 /*
218 * SDRAM Configuration Register (SDCR):
219 * First set the BOOTUNLOCK bit to make configuration bits
220 * writeable.
221 */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000222 setbits_le32(&dv_ddr2_regs_ctrl->sdbcr, DV_DDR_BOOTUNLOCK);
223
Christian Riesch81ad48e2011-11-08 08:55:13 -0500224 /*
225 * Write the new value of these bits and clear BOOTUNLOCK.
226 * At the same time, set the TIMUNLOCK bit to allow changing
227 * the timing registers
228 */
229 tmp = CONFIG_SYS_DA850_DDR2_SDBCR;
Heiko Schocher34061e82011-11-15 10:00:02 -0500230 tmp &= ~DV_DDR_BOOTUNLOCK;
231 tmp |= DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500232 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000233
Christian Riesch81ad48e2011-11-08 08:55:13 -0500234 /* write memory configuration and timing */
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000235 if (!(CONFIG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT))) {
236 /* MOBILE DDR only*/
237 writel(CONFIG_SYS_DA850_DDR2_SDBCR2,
238 &dv_ddr2_regs_ctrl->sdbcr2);
239 }
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500240 writel(CONFIG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
241 writel(CONFIG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000242
Christian Riesch81ad48e2011-11-08 08:55:13 -0500243 /* clear the TIMUNLOCK bit and write the value of the CL field */
Heiko Schocher34061e82011-11-15 10:00:02 -0500244 tmp &= ~DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500245 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000246
247 /*
248 * LPMODEN and MCLKSTOPEN must be set!
249 * Without this bits set, PSC don;t switch states !!
250 */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500251 writel(CONFIG_SYS_DA850_DDR2_SDRCR |
Heiko Schocherfe954e32011-09-14 19:59:38 +0000252 (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
253 (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
254 &dv_ddr2_regs_ctrl->sdrcr);
255
256 /* SyncReset the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500257 lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000258 /* Enable the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500259 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000260
261 /* disable self refresh */
Heiko Schocher34061e82011-11-15 10:00:02 -0500262 clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
Mikhail Kshevetskiy4a6d36e2012-07-09 08:52:41 +0000263 DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_MCLKSTOPEN);
Heiko Schocher34061e82011-11-15 10:00:02 -0500264 writel(CONFIG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000265
266 return 0;
267}
Sughosh Ganua2616972012-02-02 00:44:41 +0000268#endif /* CONFIG_SYS_DA850_DDR_INIT */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000269
Heiko Schocherfe954e32011-09-14 19:59:38 +0000270__attribute__((weak))
271void board_gpio_init(void)
272{
273 return;
274}
275
Heiko Schocherfe954e32011-09-14 19:59:38 +0000276int arch_cpu_init(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000277{
Heiko Schocherfe954e32011-09-14 19:59:38 +0000278 /* Unlock kick registers */
Heiko Schocher34061e82011-11-15 10:00:02 -0500279 writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
280 writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000281
282 dv_maskbits(&davinci_syscfg_regs->suspsrc,
Heiko Schocher34061e82011-11-15 10:00:02 -0500283 CONFIG_SYS_DA850_SYSCFG_SUSPSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000284
Christian Riesch2eb60502011-11-28 23:46:20 +0000285 /* configure pinmux settings */
286 if (davinci_configure_pin_mux_items(pinmuxes, pinmuxes_size))
287 return 1;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000288
Sughosh Ganua2616972012-02-02 00:44:41 +0000289#if defined(CONFIG_SYS_DA850_PLL_INIT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000290 /* PLL setup */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500291 da850_pll_init(davinci_pllc0_regs, CONFIG_SYS_DA850_PLL0_PLLM);
292 da850_pll_init(davinci_pllc1_regs, CONFIG_SYS_DA850_PLL1_PLLM);
Sughosh Ganua2616972012-02-02 00:44:41 +0000293#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000294 /* setup CSn config */
Heiko Schocher34061e82011-11-15 10:00:02 -0500295#if defined(CONFIG_SYS_DA850_CS2CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500296 writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500297#endif
298#if defined(CONFIG_SYS_DA850_CS3CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500299 writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500300#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000301
Sughosh Ganua2616972012-02-02 00:44:41 +0000302 da8xx_configure_lpsc_items(lpsc, lpsc_size);
303
304 /* GPIO setup */
305 board_gpio_init();
306
307
Heiko Schocherfe954e32011-09-14 19:59:38 +0000308 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
309 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
310
311 /*
312 * Fix Power and Emulation Management Register
313 * see sprufw3a.pdf page 37 Table 24
314 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500315 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
316 DAVINCI_UART_PWREMU_MGMT_UTRST),
317 &davinci_uart2_ctrl_regs->pwremu_mgmt);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000318
Sughosh Ganua2616972012-02-02 00:44:41 +0000319#if defined(CONFIG_SYS_DA850_DDR_INIT)
Heiko Schocher34061e82011-11-15 10:00:02 -0500320 da850_ddr_setup();
Sughosh Ganua2616972012-02-02 00:44:41 +0000321#endif
322
Heiko Schocherfe954e32011-09-14 19:59:38 +0000323 return 0;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000324}