blob: b37c6fe218da48a6ca5b4da478a66f72ca5a9081 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babic17b60372016-06-08 10:50:20 +02002/*
3 * Copyright (C) 2016 Stefano Babic <sbabic@denx.de>
Stefano Babic17b60372016-06-08 10:50:20 +02004 */
5
6/*
7 * Please note: there are two version of the board
8 * one with NAND and the other with eMMC.
9 * Both NAND and eMMC cannot be set because they share the
10 * same pins (SD4)
11 */
12#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Stefano Babic17b60372016-06-08 10:50:20 +020015#include <asm/arch/crm_regs.h>
16#include <asm/arch/mx6-ddr.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/boot_mode.h>
Stefano Babic17b60372016-06-08 10:50:20 +020019#include <asm/arch/sys_proto.h>
Shiji Yangbb112342023-08-03 09:47:16 +080020#include <asm/sections.h>
Niel Fourie8ee19072020-05-19 14:01:43 +020021#include <dm.h>
Stefano Babic17b60372016-06-08 10:50:20 +020022
23DECLARE_GLOBAL_DATA_PTR;
24
Stefano Babic17b60372016-06-08 10:50:20 +020025#define IMX6Q_DRIVE_STRENGTH 0x30
26
27int dram_init(void)
28{
29 gd->ram_size = imx_ddr_size();
30 return 0;
31}
32
Stefano Babic17b60372016-06-08 10:50:20 +020033int board_mmc_get_env_dev(int devno)
34{
35 return devno - 1;
36}
37
Stefano Babic17b60372016-06-08 10:50:20 +020038#ifdef CONFIG_CMD_NAND
39static void setup_gpmi_nand(void)
40{
41 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
42
Stefano Babic17b60372016-06-08 10:50:20 +020043 /* gate ENFC_CLK_ROOT clock first,before clk source switch */
44 clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
45
46 /* config gpmi and bch clock to 100 MHz */
47 clrsetbits_le32(&mxc_ccm->cs2cdr,
48 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
49 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
50 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
51 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
52 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
53 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
54
55 /* enable ENFC_CLK_ROOT clock */
56 setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
57
58 /* enable gpmi and bch clock gating */
59 setbits_le32(&mxc_ccm->CCGR4,
60 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
61 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
62 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
63 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
64 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
65
66 /* enable apbh clock gating */
67 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
68}
69#endif
70
Stefano Babic17b60372016-06-08 10:50:20 +020071int board_init(void)
72{
73 /* address of boot parameters */
74 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
75
Stefano Babic17b60372016-06-08 10:50:20 +020076#ifdef CONFIG_CMD_NAND
77 setup_gpmi_nand();
78#endif
79 return 0;
80}
81
Stefano Babic17b60372016-06-08 10:50:20 +020082#ifdef CONFIG_CMD_BMODE
83/*
84 * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
85 * see Table 8-11 and Table 5-9
86 * BOOT_CFG1[7] = 1 (boot from NAND)
87 * BOOT_CFG1[5] = 0 - raw NAND
88 * BOOT_CFG1[4] = 0 - default pad settings
89 * BOOT_CFG1[3:2] = 00 - devices = 1
90 * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
91 * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
92 * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
93 * BOOT_CFG2[0] = 0 - Reset time 12ms
94 */
95static const struct boot_mode board_boot_modes[] = {
96 /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
97 {"nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00)},
98 {"mmc0", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
99 {NULL, 0},
100};
101#endif
102
103int board_late_init(void)
104{
105#ifdef CONFIG_CMD_BMODE
106 add_board_boot_modes(board_boot_modes);
107#endif
108
109 return 0;
110}
111
112#ifdef CONFIG_SPL_BUILD
113#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900114#include <linux/libfdt.h>
Stefano Babic17b60372016-06-08 10:50:20 +0200115
116static const struct mx6dq_iomux_ddr_regs mx6_ddr_ioregs = {
117 .dram_sdclk_0 = 0x00000030,
118 .dram_sdclk_1 = 0x00000030,
119 .dram_cas = 0x00000030,
120 .dram_ras = 0x00000030,
121 .dram_reset = 0x00000030,
122 .dram_sdcke0 = 0x00000030,
123 .dram_sdcke1 = 0x00000030,
124 .dram_sdba2 = 0x00000000,
125 .dram_sdodt0 = 0x00000030,
126 .dram_sdodt1 = 0x00000030,
127 .dram_sdqs0 = 0x00000030,
128 .dram_sdqs1 = 0x00000030,
129 .dram_sdqs2 = 0x00000030,
130 .dram_sdqs3 = 0x00000030,
131 .dram_sdqs4 = 0x00000030,
132 .dram_sdqs5 = 0x00000030,
133 .dram_sdqs6 = 0x00000030,
134 .dram_sdqs7 = 0x00000030,
135 .dram_dqm0 = 0x00000030,
136 .dram_dqm1 = 0x00000030,
137 .dram_dqm2 = 0x00000030,
138 .dram_dqm3 = 0x00000030,
139 .dram_dqm4 = 0x00000030,
140 .dram_dqm5 = 0x00000030,
141 .dram_dqm6 = 0x00000030,
142 .dram_dqm7 = 0x00000030,
143};
144
145static const struct mx6dq_iomux_grp_regs mx6_grp_ioregs = {
146 .grp_ddr_type = 0x000C0000,
147 .grp_ddrmode_ctl = 0x00020000,
148 .grp_ddrpke = 0x00000000,
149 .grp_addds = IMX6Q_DRIVE_STRENGTH,
150 .grp_ctlds = IMX6Q_DRIVE_STRENGTH,
151 .grp_ddrmode = 0x00020000,
152 .grp_b0ds = IMX6Q_DRIVE_STRENGTH,
153 .grp_b1ds = IMX6Q_DRIVE_STRENGTH,
154 .grp_b2ds = IMX6Q_DRIVE_STRENGTH,
155 .grp_b3ds = IMX6Q_DRIVE_STRENGTH,
156 .grp_b4ds = IMX6Q_DRIVE_STRENGTH,
157 .grp_b5ds = IMX6Q_DRIVE_STRENGTH,
158 .grp_b6ds = IMX6Q_DRIVE_STRENGTH,
159 .grp_b7ds = IMX6Q_DRIVE_STRENGTH,
160};
161
162static const struct mx6_mmdc_calibration mx6_mmcd_calib = {
163 .p0_mpwldectrl0 = 0x00140014,
164 .p0_mpwldectrl1 = 0x000A0015,
165 .p1_mpwldectrl0 = 0x000A001E,
166 .p1_mpwldectrl1 = 0x000A0015,
167 .p0_mpdgctrl0 = 0x43080314,
168 .p0_mpdgctrl1 = 0x02680300,
169 .p1_mpdgctrl0 = 0x430C0318,
170 .p1_mpdgctrl1 = 0x03000254,
171 .p0_mprddlctl = 0x3A323234,
172 .p1_mprddlctl = 0x3E3C3242,
173 .p0_mpwrdlctl = 0x2A2E3632,
174 .p1_mpwrdlctl = 0x3C323E34,
175};
176
177static struct mx6_ddr3_cfg mem_ddr = {
178 .mem_speed = 1600,
179 .density = 2,
180 .width = 16,
181 .banks = 8,
182 .rowaddr = 14,
183 .coladdr = 10,
184 .pagesz = 2,
185 .trcd = 1375,
186 .trcmin = 4875,
187 .trasmin = 3500,
188 .SRT = 1,
189};
190
191static void ccgr_init(void)
192{
193 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
194
195 writel(0x00C03F3F, &ccm->CCGR0);
196 writel(0x0030FC03, &ccm->CCGR1);
197 writel(0x0FFFC000, &ccm->CCGR2);
198 writel(0x3FF00000, &ccm->CCGR3);
199 writel(0x00FFF300, &ccm->CCGR4);
200 writel(0x0F0000C3, &ccm->CCGR5);
201 writel(0x000003FF, &ccm->CCGR6);
202}
203
Stefano Babic17b60372016-06-08 10:50:20 +0200204static void spl_dram_init(void)
205{
206 struct mx6_ddr_sysinfo sysinfo = {
207 /* width of data bus:0=16,1=32,2=64 */
208 .dsize = 2,
209 /* config for full 4GB range so that get_mem_size() works */
210 .cs_density = 32, /* 32Gb per CS */
211 /* single chip select */
212 .ncs = 1,
213 .cs1_mirror = 0,
214 .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */
215 .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */
216 .walat = 1, /* Write additional latency */
217 .ralat = 5, /* Read additional latency */
218 .mif3_mode = 3, /* Command prediction working mode */
219 .bi_on = 1, /* Bank interleaving enabled */
220 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
221 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
222 .ddr_type = DDR_TYPE_DDR3,
Fabio Estevamcb3c1212016-08-29 20:37:15 -0300223 .refsel = 1, /* Refresh cycles at 32KHz */
224 .refr = 7, /* 8 refresh commands per refresh cycle */
Stefano Babic17b60372016-06-08 10:50:20 +0200225 };
226
227 mx6dq_dram_iocfg(64, &mx6_ddr_ioregs, &mx6_grp_ioregs);
228 mx6_dram_cfg(&sysinfo, &mx6_mmcd_calib, &mem_ddr);
229}
230
231void board_boot_order(u32 *spl_boot_list)
232{
233 spl_boot_list[0] = spl_boot_device();
234 printf("Boot device %x\n", spl_boot_list[0]);
235 switch (spl_boot_list[0]) {
236 case BOOT_DEVICE_SPI:
237 spl_boot_list[1] = BOOT_DEVICE_UART;
238 break;
239 case BOOT_DEVICE_MMC1:
240 spl_boot_list[1] = BOOT_DEVICE_SPI;
241 spl_boot_list[2] = BOOT_DEVICE_UART;
242 break;
243 default:
244 printf("Boot device %x\n", spl_boot_list[0]);
245 }
246}
247
248void board_init_f(ulong dummy)
249{
Stefano Babic17b60372016-06-08 10:50:20 +0200250 /* setup clock gating */
251 ccgr_init();
252
253 /* setup AIPS and disable watchdog */
254 arch_cpu_init();
255
256 /* setup AXI */
257 gpr_init();
258
Stefano Babic17b60372016-06-08 10:50:20 +0200259 /* setup GP timer */
260 timer_init();
261
Stefano Babic17b60372016-06-08 10:50:20 +0200262 /* DDR initialization */
263 spl_dram_init();
264
265 /* Clear the BSS. */
266 memset(__bss_start, 0, __bss_end - __bss_start);
267
Niel Fourie8ee19072020-05-19 14:01:43 +0200268 /* Enable device tree and early DM support*/
269 spl_early_init();
270
271 /* UART clocks enabled and gd valid - init serial console */
272 preloader_console_init();
273}
274
275/*
276 * Manually probe the SPI bus devices, as this does not happen when the
277 * SPI Flash is probed, which then fails to find the bus.
278 */
279void spl_board_init(void)
280{
281 struct udevice *udev;
282 int ret = uclass_get_device_by_name(UCLASS_SPI, "spi@2008000", &udev);
283
284 if (ret) {
285 printf("SPI bus probe failed, err = %d\n", ret);
286 };
Stefano Babic17b60372016-06-08 10:50:20 +0200287}
288#endif