blob: df7d6a24ba2b2fc68e34ee74c5d5a0ba88d55e42 [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
Sughosh Ganua2616972012-02-02 00:44:41 +000035#if defined(CONFIG_SYS_DA850_PLL_INIT)
Christian Riesch0e5e0c52011-11-08 08:55:07 -050036void da850_waitloop(unsigned long loopcnt)
Heiko Schocherfe954e32011-09-14 19:59:38 +000037{
38 unsigned long i;
39
40 for (i = 0; i < loopcnt; i++)
41 asm(" NOP");
42}
43
Christian Riesch0e5e0c52011-11-08 08:55:07 -050044int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
Heiko Schocherfe954e32011-09-14 19:59:38 +000045{
46 if (reg == davinci_pllc0_regs)
47 /* Unlock PLL registers. */
Heiko Schocher34061e82011-11-15 10:00:02 -050048 clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
Heiko Schocherfe954e32011-09-14 19:59:38 +000049
50 /*
51 * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
52 * through MMR
53 */
Heiko Schocher34061e82011-11-15 10:00:02 -050054 clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000055 /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
Heiko Schocher34061e82011-11-15 10:00:02 -050056 clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +000057
58 /* Set PLLEN=0 => PLL BYPASS MODE */
Heiko Schocher34061e82011-11-15 10:00:02 -050059 clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000060
Christian Riesch0e5e0c52011-11-08 08:55:07 -050061 da850_waitloop(150);
Heiko Schocherfe954e32011-09-14 19:59:38 +000062
63 if (reg == davinci_pllc0_regs) {
64 /*
65 * Select the Clock Mode bit 8 as External Clock or On Chip
66 * Oscilator
67 */
Heiko Schocher34061e82011-11-15 10:00:02 -050068 dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
69 setbits_le32(&reg->pllctl,
70 (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
Heiko Schocherfe954e32011-09-14 19:59:38 +000071 }
72
73 /* Clear PLLRST bit to reset the PLL */
Heiko Schocher34061e82011-11-15 10:00:02 -050074 clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +000075
76 /* Disable the PLL output */
Heiko Schocher34061e82011-11-15 10:00:02 -050077 setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000078
79 /* PLL initialization sequence */
80 /*
81 * Power up the PLL- PWRDN bit set to 0 to bring the PLL out of
82 * power down bit
83 */
Heiko Schocher34061e82011-11-15 10:00:02 -050084 clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
Heiko Schocherfe954e32011-09-14 19:59:38 +000085
86 /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
Heiko Schocher34061e82011-11-15 10:00:02 -050087 clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
Heiko Schocherfe954e32011-09-14 19:59:38 +000088
Ben Gardinerb2a47522012-01-16 07:43:15 +000089#if defined(CONFIG_SYS_DA850_PLL0_PREDIV)
90 /* program the prediv */
91 if (reg == davinci_pllc0_regs && CONFIG_SYS_DA850_PLL0_PREDIV)
92 writel((PLL_DIVEN | CONFIG_SYS_DA850_PLL0_PREDIV),
93 &reg->prediv);
94#endif
95
Heiko Schocherfe954e32011-09-14 19:59:38 +000096 /* Program the required multiplier value in PLLM */
97 writel(pllmult, &reg->pllm);
98
99 /* program the postdiv */
100 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -0500101 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +0000102 &reg->postdiv);
103 else
Heiko Schocher34061e82011-11-15 10:00:02 -0500104 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
Heiko Schocherfe954e32011-09-14 19:59:38 +0000105 &reg->postdiv);
106
107 /*
108 * Check for the GOSTAT bit in PLLSTAT to clear to 0 to indicate that
109 * no GO operation is currently in progress
110 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500111 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000112 ;
113
114 if (reg == davinci_pllc0_regs) {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500115 writel(CONFIG_SYS_DA850_PLL0_PLLDIV1, &reg->plldiv1);
116 writel(CONFIG_SYS_DA850_PLL0_PLLDIV2, &reg->plldiv2);
117 writel(CONFIG_SYS_DA850_PLL0_PLLDIV3, &reg->plldiv3);
118 writel(CONFIG_SYS_DA850_PLL0_PLLDIV4, &reg->plldiv4);
119 writel(CONFIG_SYS_DA850_PLL0_PLLDIV5, &reg->plldiv5);
120 writel(CONFIG_SYS_DA850_PLL0_PLLDIV6, &reg->plldiv6);
121 writel(CONFIG_SYS_DA850_PLL0_PLLDIV7, &reg->plldiv7);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000122 } else {
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500123 writel(CONFIG_SYS_DA850_PLL1_PLLDIV1, &reg->plldiv1);
124 writel(CONFIG_SYS_DA850_PLL1_PLLDIV2, &reg->plldiv2);
125 writel(CONFIG_SYS_DA850_PLL1_PLLDIV3, &reg->plldiv3);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000126 }
127
128 /*
129 * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
130 * transition.
131 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500132 setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000133
134 /*
135 * Wait for the GOSTAT bit in PLLSTAT to clear to 0
136 * (completion of phase alignment).
137 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500138 while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000139 ;
140
141 /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500142 da850_waitloop(200);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000143
144 /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
Heiko Schocher34061e82011-11-15 10:00:02 -0500145 setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000146
147 /* Wait for PLL to lock. See PLL spec for PLL lock time */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500148 da850_waitloop(2400);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000149
150 /*
151 * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
152 * mode
153 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500154 setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000155
156
157 /*
158 * clear EMIFA and EMIFB clock source settings, let them
159 * run off SYSCLK
160 */
161 if (reg == davinci_pllc0_regs)
Heiko Schocher34061e82011-11-15 10:00:02 -0500162 dv_maskbits(&davinci_syscfg_regs->cfgchip3,
163 ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
Heiko Schocherfe954e32011-09-14 19:59:38 +0000164
165 return 0;
166}
Sughosh Ganua2616972012-02-02 00:44:41 +0000167#endif /* CONFIG_SYS_DA850_PLL_INIT */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000168
Sughosh Ganua2616972012-02-02 00:44:41 +0000169#if defined(CONFIG_SYS_DA850_DDR_INIT)
Heiko Schocher34061e82011-11-15 10:00:02 -0500170int da850_ddr_setup(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000171{
172 unsigned long tmp;
173
174 /* Enable the Clock to DDR2/mDDR */
Christian Riesch99271c82011-11-08 08:55:10 -0500175 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000176
177 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
178 if ((tmp & VTP_POWERDWN) == VTP_POWERDWN) {
179 /* Begin VTP Calibration */
180 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
181 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
182 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
183 clrbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
184 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_CLKRZ);
185
186 /* Polling READY bit to see when VTP calibration is done */
187 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
188 while ((tmp & VTP_READY) != VTP_READY)
189 tmp = readl(&davinci_syscfg1_regs->vtpio_ctl);
190
191 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_LOCK);
192 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_POWERDWN);
193
194 setbits_le32(&davinci_syscfg1_regs->vtpio_ctl, VTP_IOPWRDWN);
195 }
196
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500197 writel(CONFIG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000198 clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
199 (1 << DDR_SLEW_CMOSEN_BIT));
200
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 */
213 tmp = CONFIG_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 */
219 writel(CONFIG_SYS_DA850_DDR2_SDBCR2, &dv_ddr2_regs_ctrl->sdbcr2);
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500220 writel(CONFIG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
221 writel(CONFIG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000222
Christian Riesch81ad48e2011-11-08 08:55:13 -0500223 /* clear the TIMUNLOCK bit and write the value of the CL field */
Heiko Schocher34061e82011-11-15 10:00:02 -0500224 tmp &= ~DV_DDR_TIMUNLOCK;
Christian Riesch81ad48e2011-11-08 08:55:13 -0500225 writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000226
227 /*
228 * LPMODEN and MCLKSTOPEN must be set!
229 * Without this bits set, PSC don;t switch states !!
230 */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500231 writel(CONFIG_SYS_DA850_DDR2_SDRCR |
Heiko Schocherfe954e32011-09-14 19:59:38 +0000232 (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
233 (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
234 &dv_ddr2_regs_ctrl->sdrcr);
235
236 /* SyncReset the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500237 lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000238 /* Enable the Clock to EMIF3A SDRAM */
Christian Riesch99271c82011-11-08 08:55:10 -0500239 lpsc_on(DAVINCI_LPSC_DDR_EMIF);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000240
241 /* disable self refresh */
Heiko Schocher34061e82011-11-15 10:00:02 -0500242 clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
243 DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_LPMODEN);
244 writel(CONFIG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000245
246 return 0;
247}
Sughosh Ganua2616972012-02-02 00:44:41 +0000248#endif /* CONFIG_SYS_DA850_DDR_INIT */
Heiko Schocherfe954e32011-09-14 19:59:38 +0000249
Heiko Schocherfe954e32011-09-14 19:59:38 +0000250__attribute__((weak))
251void board_gpio_init(void)
252{
253 return;
254}
255
Heiko Schocherfe954e32011-09-14 19:59:38 +0000256int arch_cpu_init(void)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000257{
Heiko Schocherfe954e32011-09-14 19:59:38 +0000258 /* Unlock kick registers */
Heiko Schocher34061e82011-11-15 10:00:02 -0500259 writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
260 writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000261
262 dv_maskbits(&davinci_syscfg_regs->suspsrc,
Heiko Schocher34061e82011-11-15 10:00:02 -0500263 CONFIG_SYS_DA850_SYSCFG_SUSPSRC);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000264
Christian Riesch2eb60502011-11-28 23:46:20 +0000265 /* configure pinmux settings */
266 if (davinci_configure_pin_mux_items(pinmuxes, pinmuxes_size))
267 return 1;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000268
Sughosh Ganua2616972012-02-02 00:44:41 +0000269#if defined(CONFIG_SYS_DA850_PLL_INIT)
Heiko Schocherfe954e32011-09-14 19:59:38 +0000270 /* PLL setup */
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500271 da850_pll_init(davinci_pllc0_regs, CONFIG_SYS_DA850_PLL0_PLLM);
272 da850_pll_init(davinci_pllc1_regs, CONFIG_SYS_DA850_PLL1_PLLM);
Sughosh Ganua2616972012-02-02 00:44:41 +0000273#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000274 /* setup CSn config */
Heiko Schocher34061e82011-11-15 10:00:02 -0500275#if defined(CONFIG_SYS_DA850_CS2CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500276 writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500277#endif
278#if defined(CONFIG_SYS_DA850_CS3CFG)
Christian Riesch0e5e0c52011-11-08 08:55:07 -0500279 writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
Heiko Schocher34061e82011-11-15 10:00:02 -0500280#endif
Heiko Schocherfe954e32011-09-14 19:59:38 +0000281
Sughosh Ganua2616972012-02-02 00:44:41 +0000282 da8xx_configure_lpsc_items(lpsc, lpsc_size);
283
284 /* GPIO setup */
285 board_gpio_init();
286
287
Heiko Schocherfe954e32011-09-14 19:59:38 +0000288 NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
289 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
290
291 /*
292 * Fix Power and Emulation Management Register
293 * see sprufw3a.pdf page 37 Table 24
294 */
Heiko Schocher34061e82011-11-15 10:00:02 -0500295 writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
296 DAVINCI_UART_PWREMU_MGMT_UTRST),
297 &davinci_uart2_ctrl_regs->pwremu_mgmt);
Heiko Schocherfe954e32011-09-14 19:59:38 +0000298
Sughosh Ganua2616972012-02-02 00:44:41 +0000299#if defined(CONFIG_SYS_DA850_DDR_INIT)
Heiko Schocher34061e82011-11-15 10:00:02 -0500300 da850_ddr_setup();
Sughosh Ganua2616972012-02-02 00:44:41 +0000301#endif
302
Heiko Schocherfe954e32011-09-14 19:59:38 +0000303 return 0;
Heiko Schocherfe954e32011-09-14 19:59:38 +0000304}