xref: /OK3568_Linux_fs/u-boot/board/barco/platinum/spl_titanium.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2014 Stefan Roese <sr@denx.de>
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Based on: gw_ventana_spl.c which is:
5*4882a593Smuzhiyun  * Copyright (C) 2014 Gateworks Corporation
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * SPDX-License-Identifier:     GPL-2.0+
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <common.h>
11*4882a593Smuzhiyun #include <i2c.h>
12*4882a593Smuzhiyun #include <asm/io.h>
13*4882a593Smuzhiyun #include <asm/arch/iomux.h>
14*4882a593Smuzhiyun #include <asm/arch/mx6-ddr.h>
15*4882a593Smuzhiyun #include <asm/arch/mx6-pins.h>
16*4882a593Smuzhiyun #include <asm/arch/sys_proto.h>
17*4882a593Smuzhiyun #include <asm/mach-imx/boot_mode.h>
18*4882a593Smuzhiyun #include <asm/mach-imx/iomux-v3.h>
19*4882a593Smuzhiyun #include <asm/mach-imx/mxc_i2c.h>
20*4882a593Smuzhiyun #include <spl.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include "platinum.h"
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #undef RTT_NOM_120OHM	/* use 120ohm Rtt_nom vs 60ohm (lower power) */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /* Configure MX6Q/DUAL mmdc DDR io registers */
29*4882a593Smuzhiyun struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
30*4882a593Smuzhiyun 	/* SDCLK[0:1], CAS, RAS, Reset: Differential input, 40ohm */
31*4882a593Smuzhiyun 	.dram_sdclk_0 = 0x00020030,
32*4882a593Smuzhiyun 	.dram_sdclk_1 = 0x00020030,
33*4882a593Smuzhiyun 	.dram_cas = 0x00020030,
34*4882a593Smuzhiyun 	.dram_ras = 0x00020030,
35*4882a593Smuzhiyun 	.dram_reset = 0x00020030,
36*4882a593Smuzhiyun 	/* SDCKE[0:1]: 100k pull-up */
37*4882a593Smuzhiyun 	.dram_sdcke0 = 0x00003000,
38*4882a593Smuzhiyun 	.dram_sdcke1 = 0x00003000,
39*4882a593Smuzhiyun 	/* SDBA2: pull-up disabled */
40*4882a593Smuzhiyun 	.dram_sdba2 = 0x00000000,
41*4882a593Smuzhiyun 	/* SDODT[0:1]: 100k pull-up, 40 ohm */
42*4882a593Smuzhiyun 	.dram_sdodt0 = 0x00003030,
43*4882a593Smuzhiyun 	.dram_sdodt1 = 0x00003030,
44*4882a593Smuzhiyun 	/* SDQS[0:7]: Differential input, 40 ohm */
45*4882a593Smuzhiyun 	.dram_sdqs0 = 0x00000030,
46*4882a593Smuzhiyun 	.dram_sdqs1 = 0x00000030,
47*4882a593Smuzhiyun 	.dram_sdqs2 = 0x00000030,
48*4882a593Smuzhiyun 	.dram_sdqs3 = 0x00000030,
49*4882a593Smuzhiyun 	.dram_sdqs4 = 0x00000030,
50*4882a593Smuzhiyun 	.dram_sdqs5 = 0x00000030,
51*4882a593Smuzhiyun 	.dram_sdqs6 = 0x00000030,
52*4882a593Smuzhiyun 	.dram_sdqs7 = 0x00000030,
53*4882a593Smuzhiyun 	/* DQM[0:7]: Differential input, 40 ohm */
54*4882a593Smuzhiyun 	.dram_dqm0 = 0x00020030,
55*4882a593Smuzhiyun 	.dram_dqm1 = 0x00020030,
56*4882a593Smuzhiyun 	.dram_dqm2 = 0x00020030,
57*4882a593Smuzhiyun 	.dram_dqm3 = 0x00020030,
58*4882a593Smuzhiyun 	.dram_dqm4 = 0x00020030,
59*4882a593Smuzhiyun 	.dram_dqm5 = 0x00020030,
60*4882a593Smuzhiyun 	.dram_dqm6 = 0x00020030,
61*4882a593Smuzhiyun 	.dram_dqm7 = 0x00020030,
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun /* Configure MX6Q/DUAL mmdc GRP io registers */
65*4882a593Smuzhiyun struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
66*4882a593Smuzhiyun 	/* DDR3 */
67*4882a593Smuzhiyun 	.grp_ddr_type = 0x000c0000,
68*4882a593Smuzhiyun 	.grp_ddrmode_ctl = 0x00020000,
69*4882a593Smuzhiyun 	/* disable DDR pullups */
70*4882a593Smuzhiyun 	.grp_ddrpke = 0x00000000,
71*4882a593Smuzhiyun 	/* ADDR[00:16], SDBA[0:1]: 40 ohm */
72*4882a593Smuzhiyun 	.grp_addds = 0x00000030,
73*4882a593Smuzhiyun 	/* CS0/CS1/SDBA2/CKE0/CKE1/SDWE: 40 ohm */
74*4882a593Smuzhiyun 	.grp_ctlds = 0x00000030,
75*4882a593Smuzhiyun 	/* DATA[00:63]: Differential input, 40 ohm */
76*4882a593Smuzhiyun 	.grp_ddrmode = 0x00020000,
77*4882a593Smuzhiyun 	.grp_b0ds = 0x00000030,
78*4882a593Smuzhiyun 	.grp_b1ds = 0x00000030,
79*4882a593Smuzhiyun 	.grp_b2ds = 0x00000030,
80*4882a593Smuzhiyun 	.grp_b3ds = 0x00000030,
81*4882a593Smuzhiyun 	.grp_b4ds = 0x00000030,
82*4882a593Smuzhiyun 	.grp_b5ds = 0x00000030,
83*4882a593Smuzhiyun 	.grp_b6ds = 0x00000030,
84*4882a593Smuzhiyun 	.grp_b7ds = 0x00000030,
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /* MT41J128M16JT-125 */
88*4882a593Smuzhiyun static struct mx6_ddr3_cfg mt41j128m16jt_125 = {
89*4882a593Smuzhiyun 	.mem_speed = 1600,
90*4882a593Smuzhiyun 	.density = 2,
91*4882a593Smuzhiyun 	.width = 16,
92*4882a593Smuzhiyun 	.banks = 8,
93*4882a593Smuzhiyun 	.rowaddr = 14,
94*4882a593Smuzhiyun 	.coladdr = 10,
95*4882a593Smuzhiyun 	.pagesz = 2,
96*4882a593Smuzhiyun 	.trcd = 1375,
97*4882a593Smuzhiyun 	.trcmin = 4875,
98*4882a593Smuzhiyun 	.trasmin = 3500,
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun static struct mx6_mmdc_calibration mx6dq_mmdc_calib = {
102*4882a593Smuzhiyun 	/* Write leveling calibration determine */
103*4882a593Smuzhiyun 	.p0_mpwldectrl0 = 0x001f001f,
104*4882a593Smuzhiyun 	.p0_mpwldectrl1 = 0x001f001f,
105*4882a593Smuzhiyun 	.p1_mpwldectrl0 = 0x00440044,
106*4882a593Smuzhiyun 	.p1_mpwldectrl1 = 0x00440044,
107*4882a593Smuzhiyun 	/* Read DQS Gating calibration */
108*4882a593Smuzhiyun 	.p0_mpdgctrl0 = 0x434b0350,
109*4882a593Smuzhiyun 	.p0_mpdgctrl1 = 0x034c0359,
110*4882a593Smuzhiyun 	.p1_mpdgctrl0 = 0x434b0350,
111*4882a593Smuzhiyun 	.p1_mpdgctrl1 = 0x03650348,
112*4882a593Smuzhiyun 	/* Read Calibration: DQS delay relative to DQ read access */
113*4882a593Smuzhiyun 	.p0_mprddlctl = 0x4436383b,
114*4882a593Smuzhiyun 	.p1_mprddlctl = 0x39393341,
115*4882a593Smuzhiyun 	/* Write Calibration: DQ/DM delay relative to DQS write access */
116*4882a593Smuzhiyun 	.p0_mpwrdlctl = 0x35373933,
117*4882a593Smuzhiyun 	.p1_mpwrdlctl = 0x48254a36,
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun 
spl_dram_init(int width)120*4882a593Smuzhiyun static void spl_dram_init(int width)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun 	struct mx6_ddr3_cfg *mem = &mt41j128m16jt_125;
123*4882a593Smuzhiyun 	struct mx6_ddr_sysinfo sysinfo = {
124*4882a593Smuzhiyun 		/* width of data bus:0=16,1=32,2=64 */
125*4882a593Smuzhiyun 		.dsize = width / 32,
126*4882a593Smuzhiyun 		/* config for full 4GB range so that get_mem_size() works */
127*4882a593Smuzhiyun 		.cs_density = 32, /* 32Gb per CS */
128*4882a593Smuzhiyun 		/* single chip select */
129*4882a593Smuzhiyun 		.ncs = 1,
130*4882a593Smuzhiyun 		.cs1_mirror = 1,
131*4882a593Smuzhiyun 		.rtt_wr = 1 /*DDR3_RTT_60_OHM*/,	/* RTT_Wr = RZQ/4 */
132*4882a593Smuzhiyun #ifdef RTT_NOM_120OHM
133*4882a593Smuzhiyun 		.rtt_nom = 2 /*DDR3_RTT_120_OHM*/,	/* RTT_Nom = RZQ/2 */
134*4882a593Smuzhiyun #else
135*4882a593Smuzhiyun 		.rtt_nom = 1 /*DDR3_RTT_60_OHM*/,	/* RTT_Nom = RZQ/4 */
136*4882a593Smuzhiyun #endif
137*4882a593Smuzhiyun 		.walat = 0,	/* Write additional latency */
138*4882a593Smuzhiyun 		.ralat = 5,	/* Read additional latency */
139*4882a593Smuzhiyun 		.mif3_mode = 3,	/* Command prediction working mode */
140*4882a593Smuzhiyun 		.bi_on = 1,	/* Bank interleaving enabled */
141*4882a593Smuzhiyun 		.sde_to_rst = 0x10,	/* 14 cycles, 200us (JEDEC default) */
142*4882a593Smuzhiyun 		.rst_to_cke = 0x23,	/* 33 cycles, 500us (JEDEC default) */
143*4882a593Smuzhiyun 		.ddr_type = DDR_TYPE_DDR3,
144*4882a593Smuzhiyun 		.refsel = 1,		/* Refresh cycles at 32KHz */
145*4882a593Smuzhiyun 		.refr = 7,		/* 8 refresh commands per refresh cycle */
146*4882a593Smuzhiyun 	};
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	mx6dq_dram_iocfg(width, &mx6dq_ddr_ioregs, &mx6dq_grp_ioregs);
149*4882a593Smuzhiyun 	mx6_dram_cfg(&sysinfo, &mx6dq_mmdc_calib, mem);
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun /*
153*4882a593Smuzhiyun  * Called from C runtime startup code (arch/arm/lib/crt0.S:_main)
154*4882a593Smuzhiyun  * - we have a stack and a place to store GD, both in SRAM
155*4882a593Smuzhiyun  * - no variable global data is available
156*4882a593Smuzhiyun  */
board_init_f(ulong dummy)157*4882a593Smuzhiyun void board_init_f(ulong dummy)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun 	/* Setup AIPS and disable watchdog */
160*4882a593Smuzhiyun 	arch_cpu_init();
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	ccgr_init();
163*4882a593Smuzhiyun 	gpr_init();
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	/* UART iomux */
166*4882a593Smuzhiyun 	board_early_init_f();
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	/* Setup GP timer */
169*4882a593Smuzhiyun 	timer_init();
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/* UART clocks enabled and gd valid - init serial console */
172*4882a593Smuzhiyun 	preloader_console_init();
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun 	/* Init DDR with 32bit width */
175*4882a593Smuzhiyun 	spl_dram_init(32);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	/* Clear the BSS */
178*4882a593Smuzhiyun 	memset(__bss_start, 0, __bss_end - __bss_start);
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	/*
181*4882a593Smuzhiyun 	 * Setup enet related MUXing early to give the PHY
182*4882a593Smuzhiyun 	 * some time to wake-up from reset
183*4882a593Smuzhiyun 	 */
184*4882a593Smuzhiyun 	platinum_setup_enet();
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	/* load/boot image from boot device */
187*4882a593Smuzhiyun 	board_init_r(NULL, 0);
188*4882a593Smuzhiyun }
189