blob: bafe9ba6b7aa1145047ec4e184f6fba83ce87531 [file] [log] [blame]
Fabio Estevam8a271ce2019-06-10 22:24:12 -03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2015 Technexion Ltd.
4 *
5 * Author: Richard Hu <richard.hu@technexion.com>
6 * Fabio Estevam <festevam@gmail.com>
7 */
8
Simon Glass1e268642020-05-10 11:39:55 -06009#include <common.h>
Fabio Estevam8a271ce2019-06-10 22:24:12 -030010#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
13#include <asm/arch/mx6-pins.h>
14#include <linux/errno.h>
15#include <asm/gpio.h>
16#include <asm/mach-imx/iomux-v3.h>
17#include <asm/mach-imx/video.h>
18#include <mmc.h>
19#include <fsl_esdhc_imx.h>
20#include <asm/arch/crm_regs.h>
21#include <asm/io.h>
22#include <asm/arch/sys_proto.h>
23#include <spl.h>
24
25#if defined(CONFIG_SPL_BUILD)
26#include <asm/arch/mx6-ddr.h>
27
28#define IMX6DQ_DRIVE_STRENGTH 0x30
29#define IMX6SDL_DRIVE_STRENGTH 0x28
30
Fabio Estevam431adf72019-09-17 22:04:57 -030031#ifdef CONFIG_SPL_OS_BOOT
32int spl_start_uboot(void)
33{
34 /* Break into full U-Boot on 'c' */
35 if (serial_tstc() && serial_getc() == 'c')
36 return 1;
37
38 return 0;
39}
40#endif
41
Fabio Estevam8a271ce2019-06-10 22:24:12 -030042/* configure MX6Q/DUAL mmdc DDR io registers */
43static struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
44 .dram_sdclk_0 = IMX6DQ_DRIVE_STRENGTH,
45 .dram_sdclk_1 = IMX6DQ_DRIVE_STRENGTH,
46 .dram_cas = IMX6DQ_DRIVE_STRENGTH,
47 .dram_ras = IMX6DQ_DRIVE_STRENGTH,
48 .dram_reset = IMX6DQ_DRIVE_STRENGTH,
49 .dram_sdcke0 = IMX6DQ_DRIVE_STRENGTH,
50 .dram_sdcke1 = IMX6DQ_DRIVE_STRENGTH,
51 .dram_sdba2 = 0x00000000,
52 .dram_sdodt0 = IMX6DQ_DRIVE_STRENGTH,
53 .dram_sdodt1 = IMX6DQ_DRIVE_STRENGTH,
54 .dram_sdqs0 = IMX6DQ_DRIVE_STRENGTH,
55 .dram_sdqs1 = IMX6DQ_DRIVE_STRENGTH,
56 .dram_sdqs2 = IMX6DQ_DRIVE_STRENGTH,
57 .dram_sdqs3 = IMX6DQ_DRIVE_STRENGTH,
58 .dram_sdqs4 = IMX6DQ_DRIVE_STRENGTH,
59 .dram_sdqs5 = IMX6DQ_DRIVE_STRENGTH,
60 .dram_sdqs6 = IMX6DQ_DRIVE_STRENGTH,
61 .dram_sdqs7 = IMX6DQ_DRIVE_STRENGTH,
62 .dram_dqm0 = IMX6DQ_DRIVE_STRENGTH,
63 .dram_dqm1 = IMX6DQ_DRIVE_STRENGTH,
64 .dram_dqm2 = IMX6DQ_DRIVE_STRENGTH,
65 .dram_dqm3 = IMX6DQ_DRIVE_STRENGTH,
66 .dram_dqm4 = IMX6DQ_DRIVE_STRENGTH,
67 .dram_dqm5 = IMX6DQ_DRIVE_STRENGTH,
68 .dram_dqm6 = IMX6DQ_DRIVE_STRENGTH,
69 .dram_dqm7 = IMX6DQ_DRIVE_STRENGTH,
70};
71
72/* configure MX6Q/DUAL mmdc GRP io registers */
73static struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
74 .grp_ddr_type = 0x000c0000,
75 .grp_ddrmode_ctl = 0x00020000,
76 .grp_ddrpke = 0x00000000,
77 .grp_addds = IMX6DQ_DRIVE_STRENGTH,
78 .grp_ctlds = IMX6DQ_DRIVE_STRENGTH,
79 .grp_ddrmode = 0x00020000,
80 .grp_b0ds = IMX6DQ_DRIVE_STRENGTH,
81 .grp_b1ds = IMX6DQ_DRIVE_STRENGTH,
82 .grp_b2ds = IMX6DQ_DRIVE_STRENGTH,
83 .grp_b3ds = IMX6DQ_DRIVE_STRENGTH,
84 .grp_b4ds = IMX6DQ_DRIVE_STRENGTH,
85 .grp_b5ds = IMX6DQ_DRIVE_STRENGTH,
86 .grp_b6ds = IMX6DQ_DRIVE_STRENGTH,
87 .grp_b7ds = IMX6DQ_DRIVE_STRENGTH,
88};
89
90/* configure MX6SOLO/DUALLITE mmdc DDR io registers */
91struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
92 .dram_sdclk_0 = IMX6SDL_DRIVE_STRENGTH,
93 .dram_sdclk_1 = IMX6SDL_DRIVE_STRENGTH,
94 .dram_cas = IMX6SDL_DRIVE_STRENGTH,
95 .dram_ras = IMX6SDL_DRIVE_STRENGTH,
96 .dram_reset = IMX6SDL_DRIVE_STRENGTH,
97 .dram_sdcke0 = IMX6SDL_DRIVE_STRENGTH,
98 .dram_sdcke1 = IMX6SDL_DRIVE_STRENGTH,
99 .dram_sdba2 = 0x00000000,
100 .dram_sdodt0 = IMX6SDL_DRIVE_STRENGTH,
101 .dram_sdodt1 = IMX6SDL_DRIVE_STRENGTH,
102 .dram_sdqs0 = IMX6SDL_DRIVE_STRENGTH,
103 .dram_sdqs1 = IMX6SDL_DRIVE_STRENGTH,
104 .dram_sdqs2 = IMX6SDL_DRIVE_STRENGTH,
105 .dram_sdqs3 = IMX6SDL_DRIVE_STRENGTH,
106 .dram_sdqs4 = IMX6SDL_DRIVE_STRENGTH,
107 .dram_sdqs5 = IMX6SDL_DRIVE_STRENGTH,
108 .dram_sdqs6 = IMX6SDL_DRIVE_STRENGTH,
109 .dram_sdqs7 = IMX6SDL_DRIVE_STRENGTH,
110 .dram_dqm0 = IMX6SDL_DRIVE_STRENGTH,
111 .dram_dqm1 = IMX6SDL_DRIVE_STRENGTH,
112 .dram_dqm2 = IMX6SDL_DRIVE_STRENGTH,
113 .dram_dqm3 = IMX6SDL_DRIVE_STRENGTH,
114 .dram_dqm4 = IMX6SDL_DRIVE_STRENGTH,
115 .dram_dqm5 = IMX6SDL_DRIVE_STRENGTH,
116 .dram_dqm6 = IMX6SDL_DRIVE_STRENGTH,
117 .dram_dqm7 = IMX6SDL_DRIVE_STRENGTH,
118};
119
120/* configure MX6SOLO/DUALLITE mmdc GRP io registers */
121struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
122 .grp_ddr_type = 0x000c0000,
123 .grp_ddrmode_ctl = 0x00020000,
124 .grp_ddrpke = 0x00000000,
125 .grp_addds = IMX6SDL_DRIVE_STRENGTH,
126 .grp_ctlds = IMX6SDL_DRIVE_STRENGTH,
127 .grp_ddrmode = 0x00020000,
128 .grp_b0ds = IMX6SDL_DRIVE_STRENGTH,
129 .grp_b1ds = IMX6SDL_DRIVE_STRENGTH,
130 .grp_b2ds = IMX6SDL_DRIVE_STRENGTH,
131 .grp_b3ds = IMX6SDL_DRIVE_STRENGTH,
132 .grp_b4ds = IMX6SDL_DRIVE_STRENGTH,
133 .grp_b5ds = IMX6SDL_DRIVE_STRENGTH,
134 .grp_b6ds = IMX6SDL_DRIVE_STRENGTH,
135 .grp_b7ds = IMX6SDL_DRIVE_STRENGTH,
136};
137
138/* H5T04G63AFR-PB for i.mx6Solo/DL operating DDR at 400MHz */
139static struct mx6_ddr3_cfg h5t04g63afr = {
140 .mem_speed = 800,
141 .density = 4,
142 .width = 16,
143 .banks = 8,
144 .rowaddr = 15,
145 .coladdr = 10,
146 .pagesz = 2,
147 .trcd = 1500,
148 .trcmin = 5250,
149 .trasmin = 3750,
150};
151
152/* H5TQ2G63FFR-H9 for i.mx6Solo/DL operating DDR at 400MHz */
153static struct mx6_ddr3_cfg h5tq2g63ffr = {
154 .mem_speed = 800,
155 .density = 2,
156 .width = 16,
157 .banks = 8,
158 .rowaddr = 14,
159 .coladdr = 10,
160 .pagesz = 2,
161 .trcd = 1500,
162 .trcmin = 5250,
163 .trasmin = 3750,
164};
165
166static struct mx6_mmdc_calibration mx6q_1g_mmdc_calib = {
167 .p0_mpwldectrl0 = 0x00000000,
168 .p0_mpwldectrl1 = 0x00000000,
169 .p1_mpwldectrl0 = 0x00000000,
170 .p1_mpwldectrl1 = 0x00000000,
171 .p0_mpdgctrl0 = 0x032C0340,
172 .p0_mpdgctrl1 = 0x03300324,
173 .p1_mpdgctrl0 = 0x032C0338,
174 .p1_mpdgctrl1 = 0x03300274,
175 .p0_mprddlctl = 0x423A383E,
176 .p1_mprddlctl = 0x3638323E,
177 .p0_mpwrdlctl = 0x363C4640,
178 .p1_mpwrdlctl = 0x4034423C,
179};
180
181/* DDR 32bit */
182static struct mx6_ddr_sysinfo mem_s = {
183 .dsize = 1,
184 .cs1_mirror = 0,
185 /* config for full 4GB range so that get_mem_size() works */
186 .cs_density = 32,
187 .ncs = 1,
188 .bi_on = 1,
189 .rtt_nom = 1,
190 .rtt_wr = 0,
191 .ralat = 5,
192 .walat = 0,
193 .mif3_mode = 3,
194 .rst_to_cke = 0x23,
195 .sde_to_rst = 0x10,
196};
197
198static struct mx6_mmdc_calibration mx6dl_1g_mmdc_calib = {
199 .p0_mpwldectrl0 = 0x001f001f,
200 .p0_mpwldectrl1 = 0x001f001f,
201 .p1_mpwldectrl0 = 0x001f001f,
202 .p1_mpwldectrl1 = 0x001f001f,
203 .p0_mpdgctrl0 = 0x420e020e,
204 .p0_mpdgctrl1 = 0x02000200,
205 .p1_mpdgctrl0 = 0x42020202,
206 .p1_mpdgctrl1 = 0x01720172,
207 .p0_mprddlctl = 0x494c4f4c,
208 .p1_mprddlctl = 0x4a4c4c49,
209 .p0_mpwrdlctl = 0x3f3f3133,
210 .p1_mpwrdlctl = 0x39373f2e,
211};
212
213static struct mx6_mmdc_calibration mx6s_512m_mmdc_calib = {
214 .p0_mpwldectrl0 = 0x0040003c,
215 .p0_mpwldectrl1 = 0x0032003e,
216 .p0_mpdgctrl0 = 0x42350231,
217 .p0_mpdgctrl1 = 0x021a0218,
218 .p0_mprddlctl = 0x4b4b4e49,
219 .p0_mpwrdlctl = 0x3f3f3035,
220};
221
222static void ccgr_init(void)
223{
224 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
225
226 writel(0x00C03F3F, &ccm->CCGR0);
227 writel(0x0030FC03, &ccm->CCGR1);
228 writel(0x0FFFC000, &ccm->CCGR2);
229 writel(0x3FF03000, &ccm->CCGR3);
230 writel(0x00FFF300, &ccm->CCGR4);
231 writel(0x0F0000C3, &ccm->CCGR5);
232 writel(0x000003FF, &ccm->CCGR6);
233}
234
235static void spl_dram_init(void)
236{
237 if (is_mx6solo()) {
238 mx6sdl_dram_iocfg(32, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
239 mx6_dram_cfg(&mem_s, &mx6s_512m_mmdc_calib, &h5tq2g63ffr);
240 } else if (is_mx6dl()) {
241 mx6sdl_dram_iocfg(32, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
242 mx6_dram_cfg(&mem_s, &mx6dl_1g_mmdc_calib, &h5t04g63afr);
243 } else if (is_mx6dq()) {
244 mx6dq_dram_iocfg(32, &mx6dq_ddr_ioregs, &mx6dq_grp_ioregs);
245 mx6_dram_cfg(&mem_s, &mx6q_1g_mmdc_calib, &h5t04g63afr);
246 }
247
248 udelay(100);
249}
250
251void board_init_f(ulong dummy)
252{
253 ccgr_init();
254
255 /* setup AIPS and disable watchdog */
256 arch_cpu_init();
257
258 gpr_init();
259
260 /* iomux */
261 board_early_init_f();
262
263 /* setup GP timer */
264 timer_init();
265
266 /* UART clocks enabled and gd valid - init serial console */
267 preloader_console_init();
268
269 /* DDR initialization */
270 spl_dram_init();
271}
272
273#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
274 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
275 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
276
277static struct fsl_esdhc_cfg usdhc_cfg[1] = {
278 {USDHC3_BASE_ADDR},
279};
280
281static iomux_v3_cfg_t const usdhc3_pads[] = {
282 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
283 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
284 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
285 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
286 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
287 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
288 /* SOM MicroSD Card Detect */
289 IOMUX_PADS(PAD_EIM_DA9__GPIO3_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL)),
290};
291
292int board_mmc_getcd(struct mmc *mmc)
293{
294 return 1;
295}
296
297int board_mmc_init(bd_t *bis)
298{
299 SETUP_IOMUX_PADS(usdhc3_pads);
300 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
301 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
302}
303#endif
304
305#ifdef CONFIG_SPL_LOAD_FIT
306int board_fit_config_name_match(const char *name)
307{
308 if (is_mx6dq() && !strcmp(name, "imx6q-pico"))
309 return 0;
310 else if ((is_mx6dl() || is_mx6solo()) && !strcmp(name, "imx6dl-pico"))
311 return 0;
312
313 return -EINVAL;
314}
315#endif