blob: c7ec70f8ca852bc9cd490206733eb55314601e02 [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>
30#include <asm/arch/ddr2_defs.h>
31#include <asm/arch/emif_defs.h>
Heiko Schocher34061e82011-11-15 10:00:02 -050032#include <asm/arch/pll_defs.h>
Heiko Schocherfe954e32011-09-14 19:59:38 +000033
Christian Riesch0e5e0c52011-11-08 08:55:07 -050034void da850_waitloop(unsigned long loopcnt)
Heiko Schocherfe954e32011-09-14 19:59:38 +000035{
36 unsigned long i;
37
38 for (i = 0; i < loopcnt; i++)
39 asm(" NOP");
40}
41
Christian Riesch0e5e0c52011-11-08 08:55:07 -050042int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
Heiko Schocherfe954e32011-09-14 19:59:38 +000043{
44 if (reg == davinci_pllc0_regs)
45 /* Unlock PLL registers. */
Heiko Schocher34061e82011-11-15 10:00:02 -050046 clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
Heiko Schocherfe954e32011-09-14 19:59:38 +000047
48 /*
49 * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
50 * through MMR
51 */
Heiko Schocher34061e82011-11-15 10:00:02 -050052 clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000053 /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
Heiko Schocher34061e82011-11-15 10:00:02 -050054 clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000055
56 /* Set PLLEN=0 => PLL BYPASS MODE */
Heiko Schocher34061e82011-11-15 10:00:02 -050057 clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000058
Christian Riesch0e5e0c52011-11-08 08:55:07 -050059 da850_waitloop(150);
Heiko Schocherfe954e32011-09-14 19:59:38 +000060
61 if (reg == davinci_pllc0_regs) {
62 /*
63 * Select the Clock Mode bit 8 as External Clock or On Chip
64 * Oscilator
65 */
Heiko Schocher34061e82011-11-15 10:00:02 -050066 dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
67 setbits_le32(&reg->pllctl,
68 (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
Heiko Schocherfe954e32011-09-14 19:59:38 +000069 }
70
71 /* Clear PLLRST bit to reset the PLL */
Heiko Schocher34061e82011-11-15 10:00:02 -050072 clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +000073
74 /* Disable the PLL output */
Heiko Schocher34061e82011-11-15 10:00:02 -050075 setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000076
77 /* PLL initialization sequence */
78 /*
79 * Power up the PLL- PWRDN bit set to 0 to bring the PLL out of
80 * power down bit
81 */
Heiko Schocher34061e82011-11-15 10:00:02 -050082 clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000083
84 /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
Heiko Schocher34061e82011-11-15 10:00:02 -050085 clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000086
87 /* Program the required multiplier value in PLLM */
88 writel(pllmult, &reg->pllm);
89
90 /* program the postdiv */
91 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -050092 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +000093 &reg->postdiv);
94 else
Heiko Schocher34061e82011-11-15 10:00:02 -050095 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +000096 &reg->postdiv);
97
98 /*
99 * Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
100 * no GO operation is currently in progress
101 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500102 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000103 ;
104
105 if (reg == davinci_pllc0_regs) {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500106 writel(CONFIG_SYS_DA850_PLL0_PLLDIV1, &reg->plldiv1);
107 writel(CONFIG_SYS_DA850_PLL0_PLLDIV2, &reg->plldiv2);
108 writel(CONFIG_SYS_DA850_PLL0_PLLDIV3, &reg->plldiv3);
109 writel(CONFIG_SYS_DA850_PLL0_PLLDIV4, &reg->plldiv4);
110 writel(CONFIG_SYS_DA850_PLL0_PLLDIV5, &reg->plldiv5);
111 writel(CONFIG_SYS_DA850_PLL0_PLLDIV6, &reg->plldiv6);
112 writel(CONFIG_SYS_DA850_PLL0_PLLDIV7, &reg->plldiv7);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000113 } else {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500114 writel(CONFIG_SYS_DA850_PLL1_PLLDIV1, &reg->plldiv1);
115 writel(CONFIG_SYS_DA850_PLL1_PLLDIV2, &reg->plldiv2);
116 writel(CONFIG_SYS_DA850_PLL1_PLLDIV3, &reg->plldiv3);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000117 }
118
119 /*
120 * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
121 * transition.
122 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500123 setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000124
125 /*
126 * Wait for the GOSTAT bit in PLLSTAT to clear to 0
127 * (completion of phase alignment).
128 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500129 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000130 ;
131
132 /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500133 da850_waitloop(200);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000134
135 /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
Heiko Schocher34061e82011-11-15 10:00:02 -0500136 setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000137
138 /* Wait for PLL to lock. See PLL spec for PLL lock time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500139 da850_waitloop(2400);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000140
141 /*
142 * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
143 * mode
144 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500145 setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000146
147
148 /*
149 * clear EMIFA and EMIFB clock source settings, let them
150 * run off SYSCLK
151 */
152 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -0500153 dv_maskbits(&davinci_syscfg_regs->cfgchip3,
154 ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
Heiko Schocherfe954e32011-09-14 19:59:38 +0000155
156 return 0;
157}
158
Heiko Schocher34061e82011-11-15 10:00:02 -0500159int da850_ddr_setup(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000160{
161 unsigned long tmp;
162
163 /* Enable the Clock to DDR2/mDDR */
Christian Riesch99271c82011-11-08 08:55:10 -0500164 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000165
166 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
167 if ((tmp & VTP_POWERDWN) == VTP_POWERDWN) {
168 /* Begin VTP Calibration */
169 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
170 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
171 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
172 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
173 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
174
175 /* Polling READY bit to see when VTP calibration is done */
176 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
177 while ((tmp & VTP_READY) != VTP_READY)
178 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
179
180 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
181 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
182
183 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_IOPWRDWN);
184 }
185
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500186 writel(CONFIG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000187 clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
188 (1 << DDR_SLEW_CMOSEN_BIT));
189
Christian Riesch81ad48e2011-11-08 08:55:13 -0500190 /*
191 * SDRAM Configuration Register (SDCR):
192 * First set the BOOTUNLOCK bit to make configuration bits
193 * writeable.
194 */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000195 setbits_le32(&dv_ddr2_regs_ctrl->sdbcr, DV_DDR_BOOTUNLOCK);
196
Christian Riesch81ad48e2011-11-08 08:55:13 -0500197 /*
198 * Write the new value of these bits and clear BOOTUNLOCK.
199 * At the same time, set the TIMUNLOCK bit to allow changing
200 * the timing registers
201 */
202 tmp = CONFIG_SYS_DA850_DDR2_SDBCR;
Heiko Schocher34061e82011-11-15 10:00:02 -0500203 tmp &= ~DV_DDR_BOOTUNLOCK;
204 tmp |= DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500205 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000206
Christian Riesch81ad48e2011-11-08 08:55:13 -0500207 /* write memory configuration and timing */
208 writel(CONFIG_SYS_DA850_DDR2_SDBCR2, &dv_ddr2_regs_ctrl->sdbcr2);
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500209 writel(CONFIG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
210 writel(CONFIG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000211
Christian Riesch81ad48e2011-11-08 08:55:13 -0500212 /* clear the TIMUNLOCK bit and write the value of the CL field */
Heiko Schocher34061e82011-11-15 10:00:02 -0500213 tmp &= ~DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500214 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000215
216 /*
217 * LPMODEN and MCLKSTOPEN must be set!
218 * Without this bits set, PSC don;t switch states !!
219 */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500220 writel(CONFIG_SYS_DA850_DDR2_SDRCR |
Heiko Schocherfe954e32011-09-14 19:59:38 +0000221 (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
222 (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
223 &dv_ddr2_regs_ctrl->sdrcr);
224
225 /* SyncReset the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500226 lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000227 /* Enable the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500228 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000229
230 /* disable self refresh */
Heiko Schocher34061e82011-11-15 10:00:02 -0500231 clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
232 DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_LPMODEN);
233 writel(CONFIG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000234
235 return 0;
236}
237
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500238void da850_pinmux_ctl(unsigned long offset, unsigned long mask,
Heiko Schocherfe954e32011-09-14 19:59:38 +0000239 unsigned long value)
240{
241 clrbits_le32(&davinci_syscfg_regs->pinmux[offset], mask);
242 setbits_le32(&davinci_syscfg_regs->pinmux[offset], (mask & value));
243}
244
245__attribute__((weak))
246void board_gpio_init(void)
247{
248 return;
249}
250
Heiko Schocherfe954e32011-09-14 19:59:38 +0000251int arch_cpu_init(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000252{
Heiko Schocherfe954e32011-09-14 19:59:38 +0000253 /* Unlock kick registers */
Heiko Schocher34061e82011-11-15 10:00:02 -0500254 writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
255 writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000256
257 dv_maskbits(&davinci_syscfg_regs->suspsrc,
Heiko Schocher34061e82011-11-15 10:00:02 -0500258 CONFIG_SYS_DA850_SYSCFG_SUSPSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000259
Heiko Schocherfe954e32011-09-14 19:59:38 +0000260 /* Setup Pinmux */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500261 da850_pinmux_ctl(0, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX0);
262 da850_pinmux_ctl(1, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX1);
263 da850_pinmux_ctl(2, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX2);
264 da850_pinmux_ctl(3, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX3);
265 da850_pinmux_ctl(4, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX4);
266 da850_pinmux_ctl(5, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX5);
267 da850_pinmux_ctl(6, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX6);
268 da850_pinmux_ctl(7, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX7);
269 da850_pinmux_ctl(8, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX8);
270 da850_pinmux_ctl(9, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX9);
271 da850_pinmux_ctl(10, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX10);
272 da850_pinmux_ctl(11, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX11);
273 da850_pinmux_ctl(12, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX12);
274 da850_pinmux_ctl(13, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX13);
275 da850_pinmux_ctl(14, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX14);
276 da850_pinmux_ctl(15, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX15);
277 da850_pinmux_ctl(16, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX16);
278 da850_pinmux_ctl(17, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX17);
279 da850_pinmux_ctl(18, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX18);
280 da850_pinmux_ctl(19, 0xFFFFFFFF, CONFIG_SYS_DA850_PINMUX19);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000281
282 /* PLL setup */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500283 da850_pll_init(davinci_pllc0_regs, CONFIG_SYS_DA850_PLL0_PLLM);
284 da850_pll_init(davinci_pllc1_regs, CONFIG_SYS_DA850_PLL1_PLLM);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000285
286 /* GPIO setup */
287 board_gpio_init();
288
289 /* setup CSn config */
Heiko Schocher34061e82011-11-15 10:00:02 -0500290#if defined(CONFIG_SYS_DA850_CS2CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500291 writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500292#endif
293#if defined(CONFIG_SYS_DA850_CS3CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500294 writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500295#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000296
Heiko Schocher34061e82011-11-15 10:00:02 -0500297 lpsc_on(CONFIG_SYS_DA850_LPSC_UART);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000298 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
299 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
300
301 /*
302 * Fix Power and Emulation Management Register
303 * see sprufw3a.pdf page 37 Table 24
304 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500305 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
306 DAVINCI_UART_PWREMU_MGMT_UTRST),
307 &davinci_uart2_ctrl_regs->pwremu_mgmt);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000308
Heiko Schocher34061e82011-11-15 10:00:02 -0500309 da850_ddr_setup();
Heiko Schocherfe954e32011-09-14 19:59:38 +0000310 return 0;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000311}