]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/davinci/da850_lowlevel.c
Merge branch 'ext4'
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / davinci / da850_lowlevel.c
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/davinci_misc.h>
31 #include <asm/arch/ddr2_defs.h>
32 #include <asm/arch/emif_defs.h>
33 #include <asm/arch/pll_defs.h>
34
35 #if defined(CONFIG_SYS_DA850_PLL_INIT)
36 void da850_waitloop(unsigned long loopcnt)
37 {
38         unsigned long   i;
39
40         for (i = 0; i < loopcnt; i++)
41                 asm("   NOP");
42 }
43
44 int da850_pll_init(struct davinci_pllc_regs *reg, unsigned long pllmult)
45 {
46         if (reg == davinci_pllc0_regs)
47                 /* Unlock PLL registers. */
48                 clrbits_le32(&davinci_syscfg_regs->cfgchip0, PLL_MASTER_LOCK);
49
50         /*
51          * Set PLLENSRC '0',bit 5, PLL Enable(PLLEN) selection is controlled
52          * through MMR
53          */
54         clrbits_le32(&reg->pllctl, PLLCTL_PLLENSRC);
55         /* PLLCTL.EXTCLKSRC bit 9 should be left at 0 for Freon */
56         clrbits_le32(&reg->pllctl, PLLCTL_EXTCLKSRC);
57
58         /* Set PLLEN=0 => PLL BYPASS MODE */
59         clrbits_le32(&reg->pllctl, PLLCTL_PLLEN);
60
61         da850_waitloop(150);
62
63         if (reg == davinci_pllc0_regs) {
64                 /*
65                  * Select the Clock Mode bit 8 as External Clock or On Chip
66                  * Oscilator
67                  */
68                 dv_maskbits(&reg->pllctl, ~PLLCTL_RES_9);
69                 setbits_le32(&reg->pllctl,
70                         (CONFIG_SYS_DV_CLKMODE << PLLCTL_CLOCK_MODE_SHIFT));
71         }
72
73         /* Clear PLLRST bit to reset the PLL */
74         clrbits_le32(&reg->pllctl, PLLCTL_PLLRST);
75
76         /* Disable the PLL output */
77         setbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
78
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          */
84         clrbits_le32(&reg->pllctl, PLLCTL_PLLPWRDN);
85
86         /* Enable the PLL from Disable Mode PLLDIS bit to 0 */
87         clrbits_le32(&reg->pllctl, PLLCTL_PLLDIS);
88
89 #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
96         /* Program the required multiplier value in PLLM */
97         writel(pllmult, &reg->pllm);
98
99         /* program the postdiv */
100         if (reg == davinci_pllc0_regs)
101                 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL0_POSTDIV),
102                         &reg->postdiv);
103         else
104                 writel((PLL_POSTDEN | CONFIG_SYS_DA850_PLL1_POSTDIV),
105                         &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          */
111         while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
112                 ;
113
114         if (reg == davinci_pllc0_regs) {
115                 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);
122         } else {
123                 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);
126         }
127
128         /*
129          * Set the GOSET bit in PLLCMD to 1 to initiate a new divider
130          * transition.
131          */
132         setbits_le32(&reg->pllcmd, PLLCMD_GOSTAT);
133
134         /*
135          * Wait for the GOSTAT bit in PLLSTAT to clear to 0
136          * (completion of phase alignment).
137          */
138         while ((readl(&reg->pllstat) & PLLCMD_GOSTAT) == PLLCMD_GOSTAT)
139                 ;
140
141         /* Wait for PLL to reset properly. See PLL spec for PLL reset time */
142         da850_waitloop(200);
143
144         /* Set the PLLRST bit in PLLCTL to 1 to bring the PLL out of reset */
145         setbits_le32(&reg->pllctl, PLLCTL_PLLRST);
146
147         /* Wait for PLL to lock. See PLL spec for PLL lock time */
148         da850_waitloop(2400);
149
150         /*
151          * Set the PLLEN bit in PLLCTL to 1 to remove the PLL from bypass
152          * mode
153          */
154         setbits_le32(&reg->pllctl, PLLCTL_PLLEN);
155
156
157         /*
158          * clear EMIFA and EMIFB clock source settings, let them
159          * run off SYSCLK
160          */
161         if (reg == davinci_pllc0_regs)
162                 dv_maskbits(&davinci_syscfg_regs->cfgchip3,
163                         ~(PLL_SCSCFG3_DIV45PENA | PLL_SCSCFG3_EMA_CLKSRC));
164
165         return 0;
166 }
167 #endif /* CONFIG_SYS_DA850_PLL_INIT */
168
169 #if defined(CONFIG_SYS_DA850_DDR_INIT)
170 int da850_ddr_setup(void)
171 {
172         unsigned long   tmp;
173
174         /* Enable the Clock to DDR2/mDDR */
175         lpsc_on(DAVINCI_LPSC_DDR_EMIF);
176
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         writel(CONFIG_SYS_DA850_DDR2_DDRPHYCR, &dv_ddr2_regs_ctrl->ddrphycr);
196
197         if (CONFIG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT)) {
198                 /* DDR2 */
199                 clrbits_le32(&davinci_syscfg1_regs->ddr_slew,
200                         (1 << DDR_SLEW_DDR_PDENA_BIT) |
201                         (1 << DDR_SLEW_CMOSEN_BIT));
202         } else {
203                 /* MOBILE DDR */
204                 setbits_le32(&davinci_syscfg1_regs->ddr_slew,
205                         (1 << DDR_SLEW_DDR_PDENA_BIT) |
206                         (1 << DDR_SLEW_CMOSEN_BIT));
207         }
208
209         /*
210          * SDRAM Configuration Register (SDCR):
211          * First set the BOOTUNLOCK bit to make configuration bits
212          * writeable.
213          */
214         setbits_le32(&dv_ddr2_regs_ctrl->sdbcr, DV_DDR_BOOTUNLOCK);
215
216         /*
217          * Write the new value of these bits and clear BOOTUNLOCK.
218          * At the same time, set the TIMUNLOCK bit to allow changing
219          * the timing registers
220          */
221         tmp = CONFIG_SYS_DA850_DDR2_SDBCR;
222         tmp &= ~DV_DDR_BOOTUNLOCK;
223         tmp |= DV_DDR_TIMUNLOCK;
224         writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
225
226         /* write memory configuration and timing */
227         if (!(CONFIG_SYS_DA850_DDR2_SDBCR & (1 << DV_DDR_SDCR_DDR2EN_SHIFT))) {
228                 /* MOBILE DDR only*/
229                 writel(CONFIG_SYS_DA850_DDR2_SDBCR2,
230                         &dv_ddr2_regs_ctrl->sdbcr2);
231         }
232         writel(CONFIG_SYS_DA850_DDR2_SDTIMR, &dv_ddr2_regs_ctrl->sdtimr);
233         writel(CONFIG_SYS_DA850_DDR2_SDTIMR2, &dv_ddr2_regs_ctrl->sdtimr2);
234
235         /* clear the TIMUNLOCK bit and write the value of the CL field */
236         tmp &= ~DV_DDR_TIMUNLOCK;
237         writel(tmp, &dv_ddr2_regs_ctrl->sdbcr);
238
239         /*
240          * LPMODEN and MCLKSTOPEN must be set!
241          * Without this bits set, PSC don;t switch states !!
242          */
243         writel(CONFIG_SYS_DA850_DDR2_SDRCR |
244                 (1 << DV_DDR_SRCR_LPMODEN_SHIFT) |
245                 (1 << DV_DDR_SRCR_MCLKSTOPEN_SHIFT),
246                 &dv_ddr2_regs_ctrl->sdrcr);
247
248         /* SyncReset the Clock to EMIF3A SDRAM */
249         lpsc_syncreset(DAVINCI_LPSC_DDR_EMIF);
250         /* Enable the Clock to EMIF3A SDRAM */
251         lpsc_on(DAVINCI_LPSC_DDR_EMIF);
252
253         /* disable self refresh */
254         clrbits_le32(&dv_ddr2_regs_ctrl->sdrcr,
255                 DV_DDR_SDRCR_LPMODEN | DV_DDR_SDRCR_MCLKSTOPEN);
256         writel(CONFIG_SYS_DA850_DDR2_PBBPR, &dv_ddr2_regs_ctrl->pbbpr);
257
258         return 0;
259 }
260 #endif /* CONFIG_SYS_DA850_DDR_INIT */
261
262 __attribute__((weak))
263 void board_gpio_init(void)
264 {
265         return;
266 }
267
268 int arch_cpu_init(void)
269 {
270         /* Unlock kick registers */
271         writel(DV_SYSCFG_KICK0_UNLOCK, &davinci_syscfg_regs->kick0);
272         writel(DV_SYSCFG_KICK1_UNLOCK, &davinci_syscfg_regs->kick1);
273
274         dv_maskbits(&davinci_syscfg_regs->suspsrc,
275                 CONFIG_SYS_DA850_SYSCFG_SUSPSRC);
276
277         /* configure pinmux settings */
278         if (davinci_configure_pin_mux_items(pinmuxes, pinmuxes_size))
279                 return 1;
280
281 #if defined(CONFIG_SYS_DA850_PLL_INIT)
282         /* PLL setup */
283         da850_pll_init(davinci_pllc0_regs, CONFIG_SYS_DA850_PLL0_PLLM);
284         da850_pll_init(davinci_pllc1_regs, CONFIG_SYS_DA850_PLL1_PLLM);
285 #endif
286         /* setup CSn config */
287 #if defined(CONFIG_SYS_DA850_CS2CFG)
288         writel(CONFIG_SYS_DA850_CS2CFG, &davinci_emif_regs->ab1cr);
289 #endif
290 #if defined(CONFIG_SYS_DA850_CS3CFG)
291         writel(CONFIG_SYS_DA850_CS3CFG, &davinci_emif_regs->ab2cr);
292 #endif
293
294         da8xx_configure_lpsc_items(lpsc, lpsc_size);
295
296         /* GPIO setup */
297         board_gpio_init();
298
299
300         NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1),
301                         CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
302
303         /*
304          * Fix Power and Emulation Management Register
305          * see sprufw3a.pdf page 37 Table 24
306          */
307         writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
308                 DAVINCI_UART_PWREMU_MGMT_UTRST),
309                &davinci_uart2_ctrl_regs->pwremu_mgmt);
310
311 #if defined(CONFIG_SYS_DA850_DDR_INIT)
312         da850_ddr_setup();
313 #endif
314
315         return 0;
316 }