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