xref: /openbmc/u-boot/board/gateworks/gw_ventana/gw_ventana_spl.c (revision a0d12cd2392af52000790739df3fc8ddbd4db460)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
20cc11deaSTim Harvey /*
30cc11deaSTim Harvey  * Copyright (C) 2014 Gateworks Corporation
40cc11deaSTim Harvey  * Author: Tim Harvey <tharvey@gateworks.com>
50cc11deaSTim Harvey  */
60cc11deaSTim Harvey 
70cc11deaSTim Harvey #include <common.h>
80cc11deaSTim Harvey #include <asm/io.h>
9e25fbe3fSFabio Estevam #include <asm/arch/crm_regs.h>
100cc11deaSTim Harvey #include <asm/arch/mx6-ddr.h>
110cc11deaSTim Harvey #include <asm/arch/mx6-pins.h>
120cc11deaSTim Harvey #include <asm/arch/sys_proto.h>
13552a848eSStefano Babic #include <asm/mach-imx/boot_mode.h>
14552a848eSStefano Babic #include <asm/mach-imx/iomux-v3.h>
15552a848eSStefano Babic #include <asm/mach-imx/mxc_i2c.h>
1653940a50STim Harvey #include <environment.h>
173c0fd17fSTim Harvey #include <i2c.h>
180cc11deaSTim Harvey #include <spl.h>
190cc11deaSTim Harvey 
202089b7beSTim Harvey #include "gsc.h"
212089b7beSTim Harvey #include "common.h"
220cc11deaSTim Harvey 
230cc11deaSTim Harvey #define RTT_NOM_120OHM /* use 120ohm Rtt_nom vs 60ohm (lower power) */
240cc11deaSTim Harvey #define GSC_EEPROM_DDR_SIZE	0x2B	/* enum (512,1024,2048) MB */
250cc11deaSTim Harvey #define GSC_EEPROM_DDR_WIDTH	0x2D	/* enum (32,64) bit */
260cc11deaSTim Harvey 
270cc11deaSTim Harvey /* configure MX6Q/DUAL mmdc DDR io registers */
280cc11deaSTim Harvey struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
290cc11deaSTim Harvey 	/* SDCLK[0:1], CAS, RAS, Reset: Differential input, 40ohm */
300cc11deaSTim Harvey 	.dram_sdclk_0 = 0x00020030,
310cc11deaSTim Harvey 	.dram_sdclk_1 = 0x00020030,
320cc11deaSTim Harvey 	.dram_cas = 0x00020030,
330cc11deaSTim Harvey 	.dram_ras = 0x00020030,
340cc11deaSTim Harvey 	.dram_reset = 0x00020030,
350cc11deaSTim Harvey 	/* SDCKE[0:1]: 100k pull-up */
360cc11deaSTim Harvey 	.dram_sdcke0 = 0x00003000,
370cc11deaSTim Harvey 	.dram_sdcke1 = 0x00003000,
380cc11deaSTim Harvey 	/* SDBA2: pull-up disabled */
390cc11deaSTim Harvey 	.dram_sdba2 = 0x00000000,
400cc11deaSTim Harvey 	/* SDODT[0:1]: 100k pull-up, 40 ohm */
410cc11deaSTim Harvey 	.dram_sdodt0 = 0x00003030,
420cc11deaSTim Harvey 	.dram_sdodt1 = 0x00003030,
430cc11deaSTim Harvey 	/* SDQS[0:7]: Differential input, 40 ohm */
440cc11deaSTim Harvey 	.dram_sdqs0 = 0x00000030,
450cc11deaSTim Harvey 	.dram_sdqs1 = 0x00000030,
460cc11deaSTim Harvey 	.dram_sdqs2 = 0x00000030,
470cc11deaSTim Harvey 	.dram_sdqs3 = 0x00000030,
480cc11deaSTim Harvey 	.dram_sdqs4 = 0x00000030,
490cc11deaSTim Harvey 	.dram_sdqs5 = 0x00000030,
500cc11deaSTim Harvey 	.dram_sdqs6 = 0x00000030,
510cc11deaSTim Harvey 	.dram_sdqs7 = 0x00000030,
520cc11deaSTim Harvey 
530cc11deaSTim Harvey 	/* DQM[0:7]: Differential input, 40 ohm */
540cc11deaSTim Harvey 	.dram_dqm0 = 0x00020030,
550cc11deaSTim Harvey 	.dram_dqm1 = 0x00020030,
560cc11deaSTim Harvey 	.dram_dqm2 = 0x00020030,
570cc11deaSTim Harvey 	.dram_dqm3 = 0x00020030,
580cc11deaSTim Harvey 	.dram_dqm4 = 0x00020030,
590cc11deaSTim Harvey 	.dram_dqm5 = 0x00020030,
600cc11deaSTim Harvey 	.dram_dqm6 = 0x00020030,
610cc11deaSTim Harvey 	.dram_dqm7 = 0x00020030,
620cc11deaSTim Harvey };
630cc11deaSTim Harvey 
640cc11deaSTim Harvey /* configure MX6Q/DUAL mmdc GRP io registers */
650cc11deaSTim Harvey struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
660cc11deaSTim Harvey 	/* DDR3 */
670cc11deaSTim Harvey 	.grp_ddr_type = 0x000c0000,
680cc11deaSTim Harvey 	.grp_ddrmode_ctl = 0x00020000,
690cc11deaSTim Harvey 	/* disable DDR pullups */
700cc11deaSTim Harvey 	.grp_ddrpke = 0x00000000,
710cc11deaSTim Harvey 	/* ADDR[00:16], SDBA[0:1]: 40 ohm */
720cc11deaSTim Harvey 	.grp_addds = 0x00000030,
730cc11deaSTim Harvey 	/* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 40 ohm */
740cc11deaSTim Harvey 	.grp_ctlds = 0x00000030,
750cc11deaSTim Harvey 	/* DATA[00:63]: Differential input, 40 ohm */
760cc11deaSTim Harvey 	.grp_ddrmode = 0x00020000,
770cc11deaSTim Harvey 	.grp_b0ds = 0x00000030,
780cc11deaSTim Harvey 	.grp_b1ds = 0x00000030,
790cc11deaSTim Harvey 	.grp_b2ds = 0x00000030,
800cc11deaSTim Harvey 	.grp_b3ds = 0x00000030,
810cc11deaSTim Harvey 	.grp_b4ds = 0x00000030,
820cc11deaSTim Harvey 	.grp_b5ds = 0x00000030,
830cc11deaSTim Harvey 	.grp_b6ds = 0x00000030,
840cc11deaSTim Harvey 	.grp_b7ds = 0x00000030,
850cc11deaSTim Harvey };
860cc11deaSTim Harvey 
870cc11deaSTim Harvey /* configure MX6SOLO/DUALLITE mmdc DDR io registers */
880cc11deaSTim Harvey struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
890cc11deaSTim Harvey 	/* SDCLK[0:1], CAS, RAS, Reset: Differential input, 40ohm */
900cc11deaSTim Harvey 	.dram_sdclk_0 = 0x00020030,
910cc11deaSTim Harvey 	.dram_sdclk_1 = 0x00020030,
920cc11deaSTim Harvey 	.dram_cas = 0x00020030,
930cc11deaSTim Harvey 	.dram_ras = 0x00020030,
940cc11deaSTim Harvey 	.dram_reset = 0x00020030,
950cc11deaSTim Harvey 	/* SDCKE[0:1]: 100k pull-up */
960cc11deaSTim Harvey 	.dram_sdcke0 = 0x00003000,
970cc11deaSTim Harvey 	.dram_sdcke1 = 0x00003000,
980cc11deaSTim Harvey 	/* SDBA2: pull-up disabled */
990cc11deaSTim Harvey 	.dram_sdba2 = 0x00000000,
1000cc11deaSTim Harvey 	/* SDODT[0:1]: 100k pull-up, 40 ohm */
1010cc11deaSTim Harvey 	.dram_sdodt0 = 0x00003030,
1020cc11deaSTim Harvey 	.dram_sdodt1 = 0x00003030,
1030cc11deaSTim Harvey 	/* SDQS[0:7]: Differential input, 40 ohm */
1040cc11deaSTim Harvey 	.dram_sdqs0 = 0x00000030,
1050cc11deaSTim Harvey 	.dram_sdqs1 = 0x00000030,
1060cc11deaSTim Harvey 	.dram_sdqs2 = 0x00000030,
1070cc11deaSTim Harvey 	.dram_sdqs3 = 0x00000030,
1080cc11deaSTim Harvey 	.dram_sdqs4 = 0x00000030,
1090cc11deaSTim Harvey 	.dram_sdqs5 = 0x00000030,
1100cc11deaSTim Harvey 	.dram_sdqs6 = 0x00000030,
1110cc11deaSTim Harvey 	.dram_sdqs7 = 0x00000030,
1120cc11deaSTim Harvey 
1130cc11deaSTim Harvey 	/* DQM[0:7]: Differential input, 40 ohm */
1140cc11deaSTim Harvey 	.dram_dqm0 = 0x00020030,
1150cc11deaSTim Harvey 	.dram_dqm1 = 0x00020030,
1160cc11deaSTim Harvey 	.dram_dqm2 = 0x00020030,
1170cc11deaSTim Harvey 	.dram_dqm3 = 0x00020030,
1180cc11deaSTim Harvey 	.dram_dqm4 = 0x00020030,
1190cc11deaSTim Harvey 	.dram_dqm5 = 0x00020030,
1200cc11deaSTim Harvey 	.dram_dqm6 = 0x00020030,
1210cc11deaSTim Harvey 	.dram_dqm7 = 0x00020030,
1220cc11deaSTim Harvey };
1230cc11deaSTim Harvey 
1240cc11deaSTim Harvey /* configure MX6SOLO/DUALLITE mmdc GRP io registers */
1250cc11deaSTim Harvey struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
1260cc11deaSTim Harvey 	/* DDR3 */
1270cc11deaSTim Harvey 	.grp_ddr_type = 0x000c0000,
1280cc11deaSTim Harvey 	/* SDQS[0:7]: Differential input, 40 ohm */
1290cc11deaSTim Harvey 	.grp_ddrmode_ctl = 0x00020000,
1300cc11deaSTim Harvey 	/* disable DDR pullups */
1310cc11deaSTim Harvey 	.grp_ddrpke = 0x00000000,
1320cc11deaSTim Harvey 	/* ADDR[00:16], SDBA[0:1]: 40 ohm */
1330cc11deaSTim Harvey 	.grp_addds = 0x00000030,
1340cc11deaSTim Harvey 	/* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 40 ohm */
1350cc11deaSTim Harvey 	.grp_ctlds = 0x00000030,
1360cc11deaSTim Harvey 	/* DATA[00:63]: Differential input, 40 ohm */
1370cc11deaSTim Harvey 	.grp_ddrmode = 0x00020000,
1380cc11deaSTim Harvey 	.grp_b0ds = 0x00000030,
1390cc11deaSTim Harvey 	.grp_b1ds = 0x00000030,
1400cc11deaSTim Harvey 	.grp_b2ds = 0x00000030,
1410cc11deaSTim Harvey 	.grp_b3ds = 0x00000030,
1420cc11deaSTim Harvey 	.grp_b4ds = 0x00000030,
1430cc11deaSTim Harvey 	.grp_b5ds = 0x00000030,
1440cc11deaSTim Harvey 	.grp_b6ds = 0x00000030,
1450cc11deaSTim Harvey 	.grp_b7ds = 0x00000030,
1460cc11deaSTim Harvey };
1470cc11deaSTim Harvey 
148767d88b0SPushpal Sidhu /* MT41K64M16JT-125 (1Gb density) */
149767d88b0SPushpal Sidhu static struct mx6_ddr3_cfg mt41k64m16jt_125 = {
150767d88b0SPushpal Sidhu 	.mem_speed = 1600,
151767d88b0SPushpal Sidhu 	.density = 1,
152767d88b0SPushpal Sidhu 	.width = 16,
153767d88b0SPushpal Sidhu 	.banks = 8,
154767d88b0SPushpal Sidhu 	.rowaddr = 13,
155767d88b0SPushpal Sidhu 	.coladdr = 10,
156767d88b0SPushpal Sidhu 	.pagesz = 2,
157767d88b0SPushpal Sidhu 	.trcd = 1375,
158767d88b0SPushpal Sidhu 	.trcmin = 4875,
159767d88b0SPushpal Sidhu 	.trasmin = 3500,
160767d88b0SPushpal Sidhu };
161767d88b0SPushpal Sidhu 
162b0b83347STim Harvey /* MT41K128M16JT-125 (2Gb density) */
1630cc11deaSTim Harvey static struct mx6_ddr3_cfg mt41k128m16jt_125 = {
1640cc11deaSTim Harvey 	.mem_speed = 1600,
1650cc11deaSTim Harvey 	.density = 2,
1660cc11deaSTim Harvey 	.width = 16,
1670cc11deaSTim Harvey 	.banks = 8,
1680cc11deaSTim Harvey 	.rowaddr = 14,
1690cc11deaSTim Harvey 	.coladdr = 10,
1700cc11deaSTim Harvey 	.pagesz = 2,
1710cc11deaSTim Harvey 	.trcd = 1375,
1720cc11deaSTim Harvey 	.trcmin = 4875,
1730cc11deaSTim Harvey 	.trasmin = 3500,
1740cc11deaSTim Harvey };
1750cc11deaSTim Harvey 
176b0b83347STim Harvey /* MT41K256M16HA-125 (4Gb density) */
177c91e4b8bSTim Harvey static struct mx6_ddr3_cfg mt41k256m16ha_125 = {
178c91e4b8bSTim Harvey 	.mem_speed = 1600,
179c91e4b8bSTim Harvey 	.density = 4,
180c91e4b8bSTim Harvey 	.width = 16,
181c91e4b8bSTim Harvey 	.banks = 8,
182c91e4b8bSTim Harvey 	.rowaddr = 15,
183c91e4b8bSTim Harvey 	.coladdr = 10,
184c91e4b8bSTim Harvey 	.pagesz = 2,
185c91e4b8bSTim Harvey 	.trcd = 1375,
186c91e4b8bSTim Harvey 	.trcmin = 4875,
187c91e4b8bSTim Harvey 	.trasmin = 3500,
1880cc11deaSTim Harvey };
1890cc11deaSTim Harvey 
1906052b1c6STim Harvey /* MT41K512M16HA-125 (8Gb density) */
1916052b1c6STim Harvey static struct mx6_ddr3_cfg mt41k512m16ha_125 = {
1926052b1c6STim Harvey 	.mem_speed = 1600,
1936052b1c6STim Harvey 	.density = 8,
1946052b1c6STim Harvey 	.width = 16,
1956052b1c6STim Harvey 	.banks = 8,
1966052b1c6STim Harvey 	.rowaddr = 16,
1976052b1c6STim Harvey 	.coladdr = 10,
1986052b1c6STim Harvey 	.pagesz = 2,
1996052b1c6STim Harvey 	.trcd = 1375,
2006052b1c6STim Harvey 	.trcmin = 4875,
2016052b1c6STim Harvey 	.trasmin = 3500,
2026052b1c6STim Harvey };
2036052b1c6STim Harvey 
204c91e4b8bSTim Harvey /*
205c91e4b8bSTim Harvey  * calibration - these are the various CPU/DDR3 combinations we support
206c91e4b8bSTim Harvey  */
207767d88b0SPushpal Sidhu static struct mx6_mmdc_calibration mx6sdl_64x16_mmdc_calib = {
208767d88b0SPushpal Sidhu 	/* write leveling calibration determine */
209767d88b0SPushpal Sidhu 	.p0_mpwldectrl0 = 0x004C004E,
210767d88b0SPushpal Sidhu 	.p0_mpwldectrl1 = 0x00440044,
211767d88b0SPushpal Sidhu 	/* Read DQS Gating calibration */
212767d88b0SPushpal Sidhu 	.p0_mpdgctrl0 = 0x42440247,
213767d88b0SPushpal Sidhu 	.p0_mpdgctrl1 = 0x02310232,
214767d88b0SPushpal Sidhu 	/* Read Calibration: DQS delay relative to DQ read access */
215767d88b0SPushpal Sidhu 	.p0_mprddlctl = 0x45424746,
216767d88b0SPushpal Sidhu 	/* Write Calibration: DQ/DM delay relative to DQS write access */
217767d88b0SPushpal Sidhu 	.p0_mpwrdlctl = 0x33382C31,
218767d88b0SPushpal Sidhu };
219c91e4b8bSTim Harvey 
220ebe07ef7STim Harvey /* TODO: update with calibrated values */
221ebe07ef7STim Harvey static struct mx6_mmdc_calibration mx6dq_64x64_mmdc_calib = {
222ebe07ef7STim Harvey 	/* write leveling calibration determine */
223ebe07ef7STim Harvey 	.p0_mpwldectrl0 = 0x00190017,
224ebe07ef7STim Harvey 	.p0_mpwldectrl1 = 0x00140026,
225ebe07ef7STim Harvey 	.p1_mpwldectrl0 = 0x0021001C,
226ebe07ef7STim Harvey 	.p1_mpwldectrl1 = 0x0011001D,
227ebe07ef7STim Harvey 	/* Read DQS Gating calibration */
228ebe07ef7STim Harvey 	.p0_mpdgctrl0 = 0x43380347,
229ebe07ef7STim Harvey 	.p0_mpdgctrl1 = 0x433C034D,
230ebe07ef7STim Harvey 	.p1_mpdgctrl0 = 0x032C0324,
231ebe07ef7STim Harvey 	.p1_mpdgctrl1 = 0x03310232,
232ebe07ef7STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
233ebe07ef7STim Harvey 	.p0_mprddlctl = 0x3C313539,
234ebe07ef7STim Harvey 	.p1_mprddlctl = 0x37343141,
235ebe07ef7STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
236ebe07ef7STim Harvey 	.p0_mpwrdlctl = 0x36393C39,
237ebe07ef7STim Harvey 	.p1_mpwrdlctl = 0x42344438,
238ebe07ef7STim Harvey };
239ebe07ef7STim Harvey 
240ebe07ef7STim Harvey /* TODO: update with calibrated values */
241ebe07ef7STim Harvey static struct mx6_mmdc_calibration mx6sdl_64x64_mmdc_calib = {
242ebe07ef7STim Harvey 	/* write leveling calibration determine */
243ebe07ef7STim Harvey 	.p0_mpwldectrl0 = 0x003C003C,
244ebe07ef7STim Harvey 	.p0_mpwldectrl1 = 0x001F002A,
245ebe07ef7STim Harvey 	.p1_mpwldectrl0 = 0x00330038,
246ebe07ef7STim Harvey 	.p1_mpwldectrl1 = 0x0022003F,
247ebe07ef7STim Harvey 	/* Read DQS Gating calibration */
248ebe07ef7STim Harvey 	.p0_mpdgctrl0 = 0x42410244,
249ebe07ef7STim Harvey 	.p0_mpdgctrl1 = 0x4234023A,
250ebe07ef7STim Harvey 	.p1_mpdgctrl0 = 0x022D022D,
251ebe07ef7STim Harvey 	.p1_mpdgctrl1 = 0x021C0228,
252ebe07ef7STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
253ebe07ef7STim Harvey 	.p0_mprddlctl = 0x484A4C4B,
254ebe07ef7STim Harvey 	.p1_mprddlctl = 0x4B4D4E4B,
255ebe07ef7STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
256ebe07ef7STim Harvey 	.p0_mpwrdlctl = 0x33342B32,
257ebe07ef7STim Harvey 	.p1_mpwrdlctl = 0x3933332B,
258ebe07ef7STim Harvey };
259ebe07ef7STim Harvey 
26075f21e31STim Harvey static struct mx6_mmdc_calibration mx6dq_256x16_mmdc_calib = {
26175f21e31STim Harvey 	/* write leveling calibration determine */
26206edcb9dSTim Harvey 	.p0_mpwldectrl0 = 0x001B0016,
26306edcb9dSTim Harvey 	.p0_mpwldectrl1 = 0x000C000E,
26475f21e31STim Harvey 	/* Read DQS Gating calibration */
26506edcb9dSTim Harvey 	.p0_mpdgctrl0 = 0x4324033A,
26606edcb9dSTim Harvey 	.p0_mpdgctrl1 = 0x00000000,
26775f21e31STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
26806edcb9dSTim Harvey 	.p0_mprddlctl = 0x40403438,
26975f21e31STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
27006edcb9dSTim Harvey 	.p0_mpwrdlctl = 0x40403D36,
27175f21e31STim Harvey };
27275f21e31STim Harvey 
27375f21e31STim Harvey static struct mx6_mmdc_calibration mx6sdl_256x16_mmdc_calib = {
27475f21e31STim Harvey 	/* write leveling calibration determine */
27506edcb9dSTim Harvey 	.p0_mpwldectrl0 = 0x00420043,
27606edcb9dSTim Harvey 	.p0_mpwldectrl1 = 0x0016001A,
27775f21e31STim Harvey 	/* Read DQS Gating calibration */
27806edcb9dSTim Harvey 	.p0_mpdgctrl0 = 0x4238023B,
27906edcb9dSTim Harvey 	.p0_mpdgctrl1 = 0x00000000,
28075f21e31STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
28106edcb9dSTim Harvey 	.p0_mprddlctl = 0x40404849,
28275f21e31STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
28306edcb9dSTim Harvey 	.p0_mpwrdlctl = 0x40402E2F,
28475f21e31STim Harvey };
28575f21e31STim Harvey 
286c91e4b8bSTim Harvey static struct mx6_mmdc_calibration mx6dq_128x32_mmdc_calib = {
2870cc11deaSTim Harvey 	/* write leveling calibration determine */
288c91e4b8bSTim Harvey 	.p0_mpwldectrl0 = 0x00190017,
289c91e4b8bSTim Harvey 	.p0_mpwldectrl1 = 0x00140026,
2900cc11deaSTim Harvey 	/* Read DQS Gating calibration */
291c91e4b8bSTim Harvey 	.p0_mpdgctrl0 = 0x43380347,
292c91e4b8bSTim Harvey 	.p0_mpdgctrl1 = 0x433C034D,
2930cc11deaSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
294c91e4b8bSTim Harvey 	.p0_mprddlctl = 0x3C313539,
2950cc11deaSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
296c91e4b8bSTim Harvey 	.p0_mpwrdlctl = 0x36393C39,
2970cc11deaSTim Harvey };
298c91e4b8bSTim Harvey 
299c91e4b8bSTim Harvey static struct mx6_mmdc_calibration mx6sdl_128x32_mmdc_calib = {
3000cc11deaSTim Harvey 	/* write leveling calibration determine */
3010cc11deaSTim Harvey 	.p0_mpwldectrl0 = 0x003C003C,
302c91e4b8bSTim Harvey 	.p0_mpwldectrl1 = 0x001F002A,
303c91e4b8bSTim Harvey 	/* Read DQS Gating calibration */
304c91e4b8bSTim Harvey 	.p0_mpdgctrl0 = 0x42410244,
305c91e4b8bSTim Harvey 	.p0_mpdgctrl1 = 0x4234023A,
306c91e4b8bSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
307c91e4b8bSTim Harvey 	.p0_mprddlctl = 0x484A4C4B,
308c91e4b8bSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
309c91e4b8bSTim Harvey 	.p0_mpwrdlctl = 0x33342B32,
310c91e4b8bSTim Harvey };
311c91e4b8bSTim Harvey 
312c91e4b8bSTim Harvey static struct mx6_mmdc_calibration mx6dq_128x64_mmdc_calib = {
313c91e4b8bSTim Harvey 	/* write leveling calibration determine */
314c91e4b8bSTim Harvey 	.p0_mpwldectrl0 = 0x00190017,
315c91e4b8bSTim Harvey 	.p0_mpwldectrl1 = 0x00140026,
316c91e4b8bSTim Harvey 	.p1_mpwldectrl0 = 0x0021001C,
317c91e4b8bSTim Harvey 	.p1_mpwldectrl1 = 0x0011001D,
318c91e4b8bSTim Harvey 	/* Read DQS Gating calibration */
319c91e4b8bSTim Harvey 	.p0_mpdgctrl0 = 0x43380347,
320c91e4b8bSTim Harvey 	.p0_mpdgctrl1 = 0x433C034D,
321c91e4b8bSTim Harvey 	.p1_mpdgctrl0 = 0x032C0324,
322c91e4b8bSTim Harvey 	.p1_mpdgctrl1 = 0x03310232,
323c91e4b8bSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
324c91e4b8bSTim Harvey 	.p0_mprddlctl = 0x3C313539,
325c91e4b8bSTim Harvey 	.p1_mprddlctl = 0x37343141,
326c91e4b8bSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
327c91e4b8bSTim Harvey 	.p0_mpwrdlctl = 0x36393C39,
328c91e4b8bSTim Harvey 	.p1_mpwrdlctl = 0x42344438,
329c91e4b8bSTim Harvey };
330c91e4b8bSTim Harvey 
331c91e4b8bSTim Harvey static struct mx6_mmdc_calibration mx6sdl_128x64_mmdc_calib = {
332c91e4b8bSTim Harvey 	/* write leveling calibration determine */
333c91e4b8bSTim Harvey 	.p0_mpwldectrl0 = 0x003C003C,
334c91e4b8bSTim Harvey 	.p0_mpwldectrl1 = 0x001F002A,
335c91e4b8bSTim Harvey 	.p1_mpwldectrl0 = 0x00330038,
3360cc11deaSTim Harvey 	.p1_mpwldectrl1 = 0x0022003F,
3370cc11deaSTim Harvey 	/* Read DQS Gating calibration */
3380cc11deaSTim Harvey 	.p0_mpdgctrl0 = 0x42410244,
339c91e4b8bSTim Harvey 	.p0_mpdgctrl1 = 0x4234023A,
340c91e4b8bSTim Harvey 	.p1_mpdgctrl0 = 0x022D022D,
3410cc11deaSTim Harvey 	.p1_mpdgctrl1 = 0x021C0228,
3420cc11deaSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
3430cc11deaSTim Harvey 	.p0_mprddlctl = 0x484A4C4B,
3440cc11deaSTim Harvey 	.p1_mprddlctl = 0x4B4D4E4B,
3450cc11deaSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
3460cc11deaSTim Harvey 	.p0_mpwrdlctl = 0x33342B32,
3470cc11deaSTim Harvey 	.p1_mpwrdlctl = 0x3933332B,
3480cc11deaSTim Harvey };
3490cc11deaSTim Harvey 
350c91e4b8bSTim Harvey static struct mx6_mmdc_calibration mx6dq_256x32_mmdc_calib = {
3510cc11deaSTim Harvey 	/* write leveling calibration determine */
352c91e4b8bSTim Harvey 	.p0_mpwldectrl0 = 0x001E001A,
353c91e4b8bSTim Harvey 	.p0_mpwldectrl1 = 0x0026001F,
3540cc11deaSTim Harvey 	/* Read DQS Gating calibration */
355c91e4b8bSTim Harvey 	.p0_mpdgctrl0 = 0x43370349,
356c91e4b8bSTim Harvey 	.p0_mpdgctrl1 = 0x032D0327,
3570cc11deaSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
358c91e4b8bSTim Harvey 	.p0_mprddlctl = 0x3D303639,
3590cc11deaSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
360c91e4b8bSTim Harvey 	.p0_mpwrdlctl = 0x32363934,
3610cc11deaSTim Harvey };
3620cc11deaSTim Harvey 
363b0b83347STim Harvey static struct mx6_mmdc_calibration mx6sdl_256x32_mmdc_calib = {
364b0b83347STim Harvey 	/* write leveling calibration determine */
365b0b83347STim Harvey 	.p0_mpwldectrl0 = 0X00480047,
366b0b83347STim Harvey 	.p0_mpwldectrl1 = 0X003D003F,
367b0b83347STim Harvey 	/* Read DQS Gating calibration */
368b0b83347STim Harvey 	.p0_mpdgctrl0 = 0X423E0241,
369b0b83347STim Harvey 	.p0_mpdgctrl1 = 0X022B022C,
370b0b83347STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
371b0b83347STim Harvey 	.p0_mprddlctl = 0X49454A4A,
372b0b83347STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
373b0b83347STim Harvey 	.p0_mpwrdlctl = 0X2E372C32,
374b0b83347STim Harvey };
375b0b83347STim Harvey 
376c91e4b8bSTim Harvey static struct mx6_mmdc_calibration mx6dq_256x64_mmdc_calib = {
3770cc11deaSTim Harvey 	/* write leveling calibration determine */
378c91e4b8bSTim Harvey 	.p0_mpwldectrl0 = 0X00220021,
379c91e4b8bSTim Harvey 	.p0_mpwldectrl1 = 0X00200030,
380c91e4b8bSTim Harvey 	.p1_mpwldectrl0 = 0X002D0027,
381c91e4b8bSTim Harvey 	.p1_mpwldectrl1 = 0X00150026,
3820cc11deaSTim Harvey 	/* Read DQS Gating calibration */
383c91e4b8bSTim Harvey 	.p0_mpdgctrl0 = 0x43330342,
384c91e4b8bSTim Harvey 	.p0_mpdgctrl1 = 0x0339034A,
385c91e4b8bSTim Harvey 	.p1_mpdgctrl0 = 0x032F0325,
386c91e4b8bSTim Harvey 	.p1_mpdgctrl1 = 0x032F022E,
3870cc11deaSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
388c91e4b8bSTim Harvey 	.p0_mprddlctl = 0X3A2E3437,
389c91e4b8bSTim Harvey 	.p1_mprddlctl = 0X35312F3F,
3900cc11deaSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
391c91e4b8bSTim Harvey 	.p0_mpwrdlctl = 0X33363B37,
392c91e4b8bSTim Harvey 	.p1_mpwrdlctl = 0X40304239,
3930cc11deaSTim Harvey };
3940cc11deaSTim Harvey 
395ad68d7b8STim Harvey static struct mx6_mmdc_calibration mx6sdl_256x64_mmdc_calib = {
396ad68d7b8STim Harvey 	/* write leveling calibration determine */
397ad68d7b8STim Harvey 	.p0_mpwldectrl0 = 0x0048004A,
398ad68d7b8STim Harvey 	.p0_mpwldectrl1 = 0x003F004A,
399ad68d7b8STim Harvey 	.p1_mpwldectrl0 = 0x001E0028,
400ad68d7b8STim Harvey 	.p1_mpwldectrl1 = 0x002C0043,
401ad68d7b8STim Harvey 	/* Read DQS Gating calibration */
402ad68d7b8STim Harvey 	.p0_mpdgctrl0 = 0x02250219,
403ad68d7b8STim Harvey 	.p0_mpdgctrl1 = 0x01790202,
404ad68d7b8STim Harvey 	.p1_mpdgctrl0 = 0x02080208,
405ad68d7b8STim Harvey 	.p1_mpdgctrl1 = 0x016C0175,
406ad68d7b8STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
407ad68d7b8STim Harvey 	.p0_mprddlctl = 0x4A4C4D4C,
408ad68d7b8STim Harvey 	.p1_mprddlctl = 0x494C4A48,
409ad68d7b8STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
410ad68d7b8STim Harvey 	.p0_mpwrdlctl = 0x403F3437,
411ad68d7b8STim Harvey 	.p1_mpwrdlctl = 0x383A3930,
412ad68d7b8STim Harvey };
413ad68d7b8STim Harvey 
414214fb19bSTim Harvey static struct mx6_mmdc_calibration mx6sdl_256x64x2_mmdc_calib = {
415214fb19bSTim Harvey 	/* write leveling calibration determine */
416214fb19bSTim Harvey 	.p0_mpwldectrl0 = 0x001F003F,
417214fb19bSTim Harvey 	.p0_mpwldectrl1 = 0x001F001F,
418214fb19bSTim Harvey 	.p1_mpwldectrl0 = 0x001F004E,
419214fb19bSTim Harvey 	.p1_mpwldectrl1 = 0x0059001F,
420214fb19bSTim Harvey 	/* Read DQS Gating calibration */
421214fb19bSTim Harvey 	.p0_mpdgctrl0   = 0x42220225,
422214fb19bSTim Harvey 	.p0_mpdgctrl1   = 0x0213021F,
423214fb19bSTim Harvey 	.p1_mpdgctrl0   = 0x022C0242,
424214fb19bSTim Harvey 	.p1_mpdgctrl1   = 0x022C0244,
425214fb19bSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
426214fb19bSTim Harvey 	.p0_mprddlctl   = 0x474A4C4A,
427214fb19bSTim Harvey 	.p1_mprddlctl   = 0x48494C45,
428214fb19bSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
429214fb19bSTim Harvey 	.p0_mpwrdlctl   = 0x3F3F3F36,
430214fb19bSTim Harvey 	.p1_mpwrdlctl   = 0x3F36363F,
431214fb19bSTim Harvey };
432214fb19bSTim Harvey 
433d1c3867aSTim Harvey static struct mx6_mmdc_calibration mx6sdl_128x64x2_mmdc_calib = {
434d1c3867aSTim Harvey 	/* write leveling calibration determine */
435d1c3867aSTim Harvey 	.p0_mpwldectrl0 = 0x001F003F,
436d1c3867aSTim Harvey 	.p0_mpwldectrl1 = 0x001F001F,
437d1c3867aSTim Harvey 	.p1_mpwldectrl0 = 0x001F004E,
438d1c3867aSTim Harvey 	.p1_mpwldectrl1 = 0x0059001F,
439d1c3867aSTim Harvey 	/* Read DQS Gating calibration */
440d1c3867aSTim Harvey 	.p0_mpdgctrl0   = 0x42220225,
441d1c3867aSTim Harvey 	.p0_mpdgctrl1   = 0x0213021F,
442d1c3867aSTim Harvey 	.p1_mpdgctrl0   = 0x022C0242,
443d1c3867aSTim Harvey 	.p1_mpdgctrl1   = 0x022C0244,
444d1c3867aSTim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
445d1c3867aSTim Harvey 	.p0_mprddlctl   = 0x474A4C4A,
446d1c3867aSTim Harvey 	.p1_mprddlctl   = 0x48494C45,
447d1c3867aSTim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
448d1c3867aSTim Harvey 	.p0_mpwrdlctl   = 0x3F3F3F36,
449d1c3867aSTim Harvey 	.p1_mpwrdlctl   = 0x3F36363F,
450d1c3867aSTim Harvey };
451d1c3867aSTim Harvey 
4526052b1c6STim Harvey static struct mx6_mmdc_calibration mx6dq_512x32_mmdc_calib = {
4536052b1c6STim Harvey 	/* write leveling calibration determine */
4546052b1c6STim Harvey 	.p0_mpwldectrl0 = 0x002A0025,
4556052b1c6STim Harvey 	.p0_mpwldectrl1 = 0x003A002A,
4566052b1c6STim Harvey 	/* Read DQS Gating calibration */
4576052b1c6STim Harvey 	.p0_mpdgctrl0 = 0x43430356,
4586052b1c6STim Harvey 	.p0_mpdgctrl1 = 0x033C0335,
4596052b1c6STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
4606052b1c6STim Harvey 	.p0_mprddlctl = 0x4B373F42,
4616052b1c6STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
4626052b1c6STim Harvey 	.p0_mpwrdlctl = 0x303E3C36,
4636052b1c6STim Harvey };
4646052b1c6STim Harvey 
465ad68d7b8STim Harvey static struct mx6_mmdc_calibration mx6dq_512x64_mmdc_calib = {
466ad68d7b8STim Harvey 	/* write leveling calibration determine */
467ad68d7b8STim Harvey 	.p0_mpwldectrl0 = 0x00230020,
468ad68d7b8STim Harvey 	.p0_mpwldectrl1 = 0x002F002A,
469ad68d7b8STim Harvey 	.p1_mpwldectrl0 = 0x001D0027,
470ad68d7b8STim Harvey 	.p1_mpwldectrl1 = 0x00100023,
471ad68d7b8STim Harvey 	/* Read DQS Gating calibration */
472ad68d7b8STim Harvey 	.p0_mpdgctrl0 = 0x03250339,
473ad68d7b8STim Harvey 	.p0_mpdgctrl1 = 0x031C0316,
474ad68d7b8STim Harvey 	.p1_mpdgctrl0 = 0x03210331,
475ad68d7b8STim Harvey 	.p1_mpdgctrl1 = 0x031C025A,
476ad68d7b8STim Harvey 	/* Read Calibration: DQS delay relative to DQ read access */
477ad68d7b8STim Harvey 	.p0_mprddlctl = 0x40373C40,
478ad68d7b8STim Harvey 	.p1_mprddlctl = 0x3A373646,
479ad68d7b8STim Harvey 	/* Write Calibration: DQ/DM delay relative to DQS write access */
480ad68d7b8STim Harvey 	.p0_mpwrdlctl = 0x2E353933,
481ad68d7b8STim Harvey 	.p1_mpwrdlctl = 0x3C2F3F35,
482ad68d7b8STim Harvey };
483ad68d7b8STim Harvey 
spl_dram_init(int width,int size_mb,int board_model)484c91e4b8bSTim Harvey static void spl_dram_init(int width, int size_mb, int board_model)
4850cc11deaSTim Harvey {
486c91e4b8bSTim Harvey 	struct mx6_ddr3_cfg *mem = NULL;
487c91e4b8bSTim Harvey 	struct mx6_mmdc_calibration *calib = NULL;
4880cc11deaSTim Harvey 	struct mx6_ddr_sysinfo sysinfo = {
4890cc11deaSTim Harvey 		/* width of data bus:0=16,1=32,2=64 */
4900cc11deaSTim Harvey 		.dsize = width/32,
4910cc11deaSTim Harvey 		/* config for full 4GB range so that get_mem_size() works */
4920cc11deaSTim Harvey 		.cs_density = 32, /* 32Gb per CS */
4930cc11deaSTim Harvey 		/* single chip select */
4940cc11deaSTim Harvey 		.ncs = 1,
4950cc11deaSTim Harvey 		.cs1_mirror = 0,
4960cc11deaSTim Harvey 		.rtt_wr = 1 /*DDR3_RTT_60_OHM*/,	/* RTT_Wr = RZQ/4 */
4970cc11deaSTim Harvey #ifdef RTT_NOM_120OHM
4980cc11deaSTim Harvey 		.rtt_nom = 2 /*DDR3_RTT_120_OHM*/,	/* RTT_Nom = RZQ/2 */
4990cc11deaSTim Harvey #else
5000cc11deaSTim Harvey 		.rtt_nom = 1 /*DDR3_RTT_60_OHM*/,	/* RTT_Nom = RZQ/4 */
5010cc11deaSTim Harvey #endif
5020cc11deaSTim Harvey 		.walat = 1,	/* Write additional latency */
5030cc11deaSTim Harvey 		.ralat = 5,	/* Read additional latency */
5040cc11deaSTim Harvey 		.mif3_mode = 3,	/* Command prediction working mode */
5050cc11deaSTim Harvey 		.bi_on = 1,	/* Bank interleaving enabled */
5060cc11deaSTim Harvey 		.sde_to_rst = 0x10,	/* 14 cycles, 200us (JEDEC default) */
5070cc11deaSTim Harvey 		.rst_to_cke = 0x23,	/* 33 cycles, 500us (JEDEC default) */
50829f0d6b1STim Harvey 		.pd_fast_exit = 1, /* enable precharge power-down fast exit */
509f2ff8343SPeng Fan 		.ddr_type = DDR_TYPE_DDR3,
510edf00937SFabio Estevam 		.refsel = 1,	/* Refresh cycles at 32KHz */
511edf00937SFabio Estevam 		.refr = 7,	/* 8 refresh commands per refresh cycle */
5120cc11deaSTim Harvey 	};
5130cc11deaSTim Harvey 
5140cc11deaSTim Harvey 	/*
5150cc11deaSTim Harvey 	 * MMDC Calibration requires the following data:
5160cc11deaSTim Harvey 	 *   mx6_mmdc_calibration - board-specific calibration (routing delays)
517c91e4b8bSTim Harvey 	 *      these calibration values depend on board routing, SoC, and DDR
5180cc11deaSTim Harvey 	 *   mx6_ddr_sysinfo - board-specific memory architecture (width/cs/etc)
5190cc11deaSTim Harvey 	 *   mx6_ddr_cfg - chip specific timing/layout details
5200cc11deaSTim Harvey 	 */
521767d88b0SPushpal Sidhu 	if (width == 16 && size_mb == 128) {
522767d88b0SPushpal Sidhu 		mem = &mt41k64m16jt_125;
523767d88b0SPushpal Sidhu 		if (is_cpu_type(MXC_CPU_MX6Q))
524767d88b0SPushpal Sidhu 			;
525767d88b0SPushpal Sidhu 		else
526767d88b0SPushpal Sidhu 			calib = &mx6sdl_64x16_mmdc_calib;
527767d88b0SPushpal Sidhu 		debug("1gB density\n");
528767d88b0SPushpal Sidhu 	} else if (width == 16 && size_mb == 256) {
5297f14c31bSTim Harvey 		/* 1x 2Gb density chip - same calib as 2x 2Gb */
53075f21e31STim Harvey 		mem = &mt41k128m16jt_125;
53175f21e31STim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
5327f14c31bSTim Harvey 			calib = &mx6dq_128x32_mmdc_calib;
53375f21e31STim Harvey 		else
5347f14c31bSTim Harvey 			calib = &mx6sdl_128x32_mmdc_calib;
53575f21e31STim Harvey 		debug("2gB density\n");
53675f21e31STim Harvey 	} else if (width == 16 && size_mb == 512) {
53775f21e31STim Harvey 		mem = &mt41k256m16ha_125;
53875f21e31STim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
53975f21e31STim Harvey 			calib = &mx6dq_256x16_mmdc_calib;
54075f21e31STim Harvey 		else
54175f21e31STim Harvey 			calib = &mx6sdl_256x16_mmdc_calib;
54275f21e31STim Harvey 		debug("4gB density\n");
543*0ab327a7STim Harvey 	} else if (width == 16 && size_mb == 1024) {
544*0ab327a7STim Harvey 		mem = &mt41k512m16ha_125;
545*0ab327a7STim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
546*0ab327a7STim Harvey 			calib = &mx6dq_512x32_mmdc_calib;
547*0ab327a7STim Harvey 		debug("8gB density\n");
548767d88b0SPushpal Sidhu 	} else if (width == 32 && size_mb == 256) {
549767d88b0SPushpal Sidhu 		/* Same calib as width==16, size==128 */
550767d88b0SPushpal Sidhu 		mem = &mt41k64m16jt_125;
551767d88b0SPushpal Sidhu 		if (is_cpu_type(MXC_CPU_MX6Q))
552767d88b0SPushpal Sidhu 			;
553767d88b0SPushpal Sidhu 		else
554767d88b0SPushpal Sidhu 			calib = &mx6sdl_64x16_mmdc_calib;
555767d88b0SPushpal Sidhu 		debug("1gB density\n");
55675f21e31STim Harvey 	} else if (width == 32 && size_mb == 512) {
557c91e4b8bSTim Harvey 		mem = &mt41k128m16jt_125;
5580cc11deaSTim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
559c91e4b8bSTim Harvey 			calib = &mx6dq_128x32_mmdc_calib;
5600cc11deaSTim Harvey 		else
561c91e4b8bSTim Harvey 			calib = &mx6sdl_128x32_mmdc_calib;
562c91e4b8bSTim Harvey 		debug("2gB density\n");
563c91e4b8bSTim Harvey 	}  else if (width == 32 && size_mb == 1024) {
564c91e4b8bSTim Harvey 		mem = &mt41k256m16ha_125;
565c91e4b8bSTim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
566c91e4b8bSTim Harvey 			calib = &mx6dq_256x32_mmdc_calib;
567b0b83347STim Harvey 		else
568b0b83347STim Harvey 			calib = &mx6sdl_256x32_mmdc_calib;
569c91e4b8bSTim Harvey 		debug("4gB density\n");
5706052b1c6STim Harvey 	} else if (width == 32 && size_mb == 2048) {
5716052b1c6STim Harvey 		mem = &mt41k512m16ha_125;
5726052b1c6STim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
5736052b1c6STim Harvey 			calib = &mx6dq_512x32_mmdc_calib;
5746052b1c6STim Harvey 		debug("8gB density\n");
575767d88b0SPushpal Sidhu 	} else if (width == 64 && size_mb == 512) {
576767d88b0SPushpal Sidhu 		mem = &mt41k64m16jt_125;
577767d88b0SPushpal Sidhu 		debug("1gB density\n");
578ebe07ef7STim Harvey 		if (is_cpu_type(MXC_CPU_MX6Q))
579ebe07ef7STim Harvey 			calib = &mx6dq_64x64_mmdc_calib;
580ebe07ef7STim Harvey 		else
581ebe07ef7STim Harvey 			calib = &mx6sdl_64x64_mmdc_calib;
582767d88b0SPushpal Sidhu 	} else if (width == 64 && size_mb == 1024) {
583767d88b0SPushpal Sidhu 		mem = &mt41k128m16jt_125;
584767d88b0SPushpal Sidhu 		if (is_cpu_type(MXC_CPU_MX6Q))
585767d88b0SPushpal Sidhu 			calib = &mx6dq_128x64_mmdc_calib;
586767d88b0SPushpal Sidhu 		else
587767d88b0SPushpal Sidhu 			calib = &mx6sdl_128x64_mmdc_calib;
588767d88b0SPushpal Sidhu 		debug("2gB density\n");
589c91e4b8bSTim Harvey 	} else if (width == 64 && size_mb == 2048) {
590d1c3867aSTim Harvey 		switch(board_model) {
591d1c3867aSTim Harvey 		case GW5905:
592d1c3867aSTim Harvey 			/* 8xMT41K128M16 (2GiB) fly-by mirrored 2-chipsels */
593d1c3867aSTim Harvey 			mem = &mt41k128m16jt_125;
594d1c3867aSTim Harvey 			debug("2gB density - 2 chipsel\n");
595d1c3867aSTim Harvey 			if (!is_cpu_type(MXC_CPU_MX6Q)) {
596d1c3867aSTim Harvey 				calib = &mx6sdl_128x64x2_mmdc_calib;
597d1c3867aSTim Harvey 				sysinfo.ncs = 2;
598d1c3867aSTim Harvey 				sysinfo.cs_density = 10; /* CS0_END=39 */
599d1c3867aSTim Harvey 				sysinfo.cs1_mirror = 1; /* mirror enabled */
600d1c3867aSTim Harvey 			}
601d1c3867aSTim Harvey 			break;
602d1c3867aSTim Harvey 		default:
603c91e4b8bSTim Harvey 			mem = &mt41k256m16ha_125;
604c91e4b8bSTim Harvey 			if (is_cpu_type(MXC_CPU_MX6Q))
605c91e4b8bSTim Harvey 				calib = &mx6dq_256x64_mmdc_calib;
606ad68d7b8STim Harvey 			else
607ad68d7b8STim Harvey 				calib = &mx6sdl_256x64_mmdc_calib;
608c91e4b8bSTim Harvey 			debug("4gB density\n");
609d1c3867aSTim Harvey 			break;
610d1c3867aSTim Harvey 		}
611ad68d7b8STim Harvey 	} else if (width == 64 && size_mb == 4096) {
612214fb19bSTim Harvey 		switch(board_model) {
613214fb19bSTim Harvey 		case GW5903:
614214fb19bSTim Harvey 			/* 8xMT41K256M16 (4GiB) fly-by mirrored 2-chipsels */
615214fb19bSTim Harvey 			mem = &mt41k256m16ha_125;
616d1c3867aSTim Harvey 			debug("4gB density - 2 chipsel\n");
617214fb19bSTim Harvey 			if (!is_cpu_type(MXC_CPU_MX6Q)) {
618214fb19bSTim Harvey 				calib = &mx6sdl_256x64x2_mmdc_calib;
619214fb19bSTim Harvey 				sysinfo.ncs = 2;
620214fb19bSTim Harvey 				sysinfo.cs_density = 18; /* CS0_END=71 */
621214fb19bSTim Harvey 				sysinfo.cs1_mirror = 1; /* mirror enabled */
622214fb19bSTim Harvey 			}
623214fb19bSTim Harvey 			break;
624214fb19bSTim Harvey 		default:
625ad68d7b8STim Harvey 			mem = &mt41k512m16ha_125;
626ad68d7b8STim Harvey 			if (is_cpu_type(MXC_CPU_MX6Q))
627ad68d7b8STim Harvey 				calib = &mx6dq_512x64_mmdc_calib;
628ad68d7b8STim Harvey 			debug("8gB density\n");
629214fb19bSTim Harvey 			break;
630214fb19bSTim Harvey 		}
631c91e4b8bSTim Harvey 	}
632c91e4b8bSTim Harvey 
6339e2b0c2dSPushpal Sidhu 	if (!(mem && calib)) {
6349e2b0c2dSPushpal Sidhu 		puts("Error: Invalid Calibration/Board Configuration\n");
6359e2b0c2dSPushpal Sidhu 		printf("MEM    : %s\n", mem ? "OKAY" : "NULL");
6369e2b0c2dSPushpal Sidhu 		printf("CALIB  : %s\n", calib ? "OKAY" : "NULL");
6379e2b0c2dSPushpal Sidhu 		printf("CPUTYPE: %s\n",
6389e2b0c2dSPushpal Sidhu 		       is_cpu_type(MXC_CPU_MX6Q) ? "IMX6Q" : "IMX6DL");
6399e2b0c2dSPushpal Sidhu 		printf("SIZE_MB: %d\n", size_mb);
6409e2b0c2dSPushpal Sidhu 		printf("WIDTH  : %d\n", width);
641c91e4b8bSTim Harvey 		hang();
6420cc11deaSTim Harvey 	}
6430cc11deaSTim Harvey 
6440cc11deaSTim Harvey 	if (is_cpu_type(MXC_CPU_MX6Q))
6450cc11deaSTim Harvey 		mx6dq_dram_iocfg(width, &mx6dq_ddr_ioregs,
6460cc11deaSTim Harvey 				 &mx6dq_grp_ioregs);
6470cc11deaSTim Harvey 	else
6480cc11deaSTim Harvey 		mx6sdl_dram_iocfg(width, &mx6sdl_ddr_ioregs,
6490cc11deaSTim Harvey 				  &mx6sdl_grp_ioregs);
6500cc11deaSTim Harvey 	mx6_dram_cfg(&sysinfo, calib, mem);
6510cc11deaSTim Harvey }
6520cc11deaSTim Harvey 
ccgr_init(void)653e25fbe3fSFabio Estevam static void ccgr_init(void)
654e25fbe3fSFabio Estevam {
655e25fbe3fSFabio Estevam 	struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
656e25fbe3fSFabio Estevam 
657e25fbe3fSFabio Estevam 	writel(0x00C03F3F, &ccm->CCGR0);
658e25fbe3fSFabio Estevam 	writel(0x0030FC03, &ccm->CCGR1);
659e25fbe3fSFabio Estevam 	writel(0x0FFFC000, &ccm->CCGR2);
660e25fbe3fSFabio Estevam 	writel(0x3FF00000, &ccm->CCGR3);
661576cd6b3SStefan Roese 	writel(0xFFFFF300, &ccm->CCGR4);	/* enable NAND/GPMI/BCH clks */
662e25fbe3fSFabio Estevam 	writel(0x0F0000C3, &ccm->CCGR5);
663e25fbe3fSFabio Estevam 	writel(0x000003FF, &ccm->CCGR6);
664e25fbe3fSFabio Estevam }
665e25fbe3fSFabio Estevam 
6660cc11deaSTim Harvey /*
6670cc11deaSTim Harvey  * called from C runtime startup code (arch/arm/lib/crt0.S:_main)
6680cc11deaSTim Harvey  * - we have a stack and a place to store GD, both in SRAM
6690cc11deaSTim Harvey  * - no variable global data is available
6700cc11deaSTim Harvey  */
board_init_f(ulong dummy)6710cc11deaSTim Harvey void board_init_f(ulong dummy)
6720cc11deaSTim Harvey {
6730cc11deaSTim Harvey 	struct ventana_board_info ventana_info;
6740cc11deaSTim Harvey 	int board_model;
6750cc11deaSTim Harvey 
676d783c274STim Harvey 	/* setup clock gating */
677d783c274STim Harvey 	ccgr_init();
678d783c274STim Harvey 
6790cc11deaSTim Harvey 	/* setup AIPS and disable watchdog */
6800cc11deaSTim Harvey 	arch_cpu_init();
6810cc11deaSTim Harvey 
682d783c274STim Harvey 	/* setup AXI */
683e25fbe3fSFabio Estevam 	gpr_init();
684e25fbe3fSFabio Estevam 
6853f0da874STim Harvey 	/* iomux and setup of uart/i2c */
6862089b7beSTim Harvey 	setup_iomux_uart();
6873f0da874STim Harvey 	setup_ventana_i2c(0);
6883f0da874STim Harvey 	setup_ventana_i2c(1);
6890cc11deaSTim Harvey 
6900cc11deaSTim Harvey 	/* setup GP timer */
6910cc11deaSTim Harvey 	timer_init();
6920cc11deaSTim Harvey 
6930cc11deaSTim Harvey 	/* UART clocks enabled and gd valid - init serial console */
6940cc11deaSTim Harvey 	preloader_console_init();
6950cc11deaSTim Harvey 
6960cc11deaSTim Harvey 	/* read/validate EEPROM info to determine board model and SDRAM cfg */
6972089b7beSTim Harvey 	board_model = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
6980cc11deaSTim Harvey 
699c4b44d76STim Harvey 	/* configure model-specific gpio */
700c4b44d76STim Harvey 	setup_iomux_gpio(board_model, &ventana_info);
701c4b44d76STim Harvey 
7020cc11deaSTim Harvey 	/* provide some some default: 32bit 128MB */
703fdead4beSTim Harvey 	if (GW_UNKNOWN == board_model)
704fdead4beSTim Harvey 		hang();
7050cc11deaSTim Harvey 
7060cc11deaSTim Harvey 	/* configure MMDC for SDRAM width/size and per-model calibration */
7070cc11deaSTim Harvey 	spl_dram_init(8 << ventana_info.sdram_width,
7080cc11deaSTim Harvey 		      16 << ventana_info.sdram_size,
7090cc11deaSTim Harvey 		      board_model);
7100cc11deaSTim Harvey }
7110cc11deaSTim Harvey 
board_boot_order(u32 * spl_boot_list)7128d1a6ff8STim Harvey void board_boot_order(u32 *spl_boot_list)
7138d1a6ff8STim Harvey {
7148d1a6ff8STim Harvey 	spl_boot_list[0] = spl_boot_device();
7158d1a6ff8STim Harvey 	switch (spl_boot_list[0]) {
7168d1a6ff8STim Harvey 	case BOOT_DEVICE_NAND:
7178d1a6ff8STim Harvey 		spl_boot_list[1] = BOOT_DEVICE_MMC1;
7188d1a6ff8STim Harvey 		spl_boot_list[2] = BOOT_DEVICE_UART;
7198d1a6ff8STim Harvey 		break;
7208d1a6ff8STim Harvey 	case BOOT_DEVICE_MMC1:
7218d1a6ff8STim Harvey 		spl_boot_list[1] = BOOT_DEVICE_UART;
7228d1a6ff8STim Harvey 		break;
7238d1a6ff8STim Harvey 	}
7248d1a6ff8STim Harvey }
7258d1a6ff8STim Harvey 
72606c3564dSTim Harvey /* called from board_init_r after gd setup if CONFIG_SPL_BOARD_INIT defined */
72706c3564dSTim Harvey /* its our chance to print info about boot device */
spl_board_init(void)72806c3564dSTim Harvey void spl_board_init(void)
72906c3564dSTim Harvey {
73006c3564dSTim Harvey 	/* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 */
73106c3564dSTim Harvey 	u32 boot_device = spl_boot_device();
73206c3564dSTim Harvey 
73306c3564dSTim Harvey 	switch (boot_device) {
73406c3564dSTim Harvey 	case BOOT_DEVICE_MMC1:
73506c3564dSTim Harvey 		puts("Booting from MMC\n");
73606c3564dSTim Harvey 		break;
73706c3564dSTim Harvey 	case BOOT_DEVICE_NAND:
73806c3564dSTim Harvey 		puts("Booting from NAND\n");
73906c3564dSTim Harvey 		break;
74006c3564dSTim Harvey 	case BOOT_DEVICE_SATA:
74106c3564dSTim Harvey 		puts("Booting from SATA\n");
74206c3564dSTim Harvey 		break;
74306c3564dSTim Harvey 	default:
74406c3564dSTim Harvey 		puts("Unknown boot device\n");
74506c3564dSTim Harvey 	}
746e06a0362STim Harvey 
747e06a0362STim Harvey 	/* PMIC init */
748e06a0362STim Harvey 	setup_pmic();
74906c3564dSTim Harvey }
75006c3564dSTim Harvey 
75153940a50STim Harvey #ifdef CONFIG_SPL_OS_BOOT
75253940a50STim Harvey /* return 1 if we wish to boot to uboot vs os (falcon mode) */
spl_start_uboot(void)75353940a50STim Harvey int spl_start_uboot(void)
75453940a50STim Harvey {
7553c0fd17fSTim Harvey 	unsigned char ret = 1;
75653940a50STim Harvey 
75753940a50STim Harvey 	debug("%s\n", __func__);
75853940a50STim Harvey #ifdef CONFIG_SPL_ENV_SUPPORT
75953940a50STim Harvey 	env_init();
760310fb14bSSimon Glass 	env_load();
76100caae6dSSimon Glass 	debug("boot_os=%s\n", env_get("boot_os"));
762bfebc8c9SSimon Glass 	if (env_get_yesno("boot_os") == 1)
76353940a50STim Harvey 		ret = 0;
7643c0fd17fSTim Harvey #else
7653c0fd17fSTim Harvey 	/* use i2c-0:0x50:0x00 for falcon boot mode (0=linux, else uboot) */
7663c0fd17fSTim Harvey 	i2c_set_bus_num(0);
7673c0fd17fSTim Harvey 	gsc_i2c_read(0x50, 0x0, 1, &ret, 1);
76853940a50STim Harvey #endif
7691b99103fSTim Harvey 	if (!ret)
7701b99103fSTim Harvey 		gsc_boot_wd_disable();
7711b99103fSTim Harvey 
77253940a50STim Harvey 	debug("%s booting %s\n", __func__, ret ? "uboot" : "linux");
77353940a50STim Harvey 	return ret;
77453940a50STim Harvey }
77553940a50STim Harvey #endif
776