blob: ff56fd88d68ed21fea9382488cd5698b7e47da6a [file] [log] [blame]
Fabio Estevam8f926ff2018-09-04 10:23:08 -03001// SPDX-License-Identifier: GPL-2.0+
2
Simon Glass8e16b1e2019-12-28 10:45:05 -07003#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07004#include <cpu_func.h>
Simon Glassf11478f2019-12-28 10:45:07 -07005#include <hang.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -07006#include <init.h>
Fabio Estevam8f926ff2018-09-04 10:23:08 -03007#include <asm/arch/clock.h>
8#include <asm/arch/iomux.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/crm_regs.h>
11#include <asm/arch/mx6ul_pins.h>
12#include <asm/arch/mx6-pins.h>
13#include <asm/arch/sys_proto.h>
14#include <asm/gpio.h>
15#include <asm/mach-imx/iomux-v3.h>
16#include <asm/mach-imx/boot_mode.h>
Shiji Yangbb112342023-08-03 09:47:16 +080017#include <asm/sections.h>
Yangbo Lu73340382019-06-21 11:42:28 +080018#include <fsl_esdhc_imx.h>
Fabio Estevam8f926ff2018-09-04 10:23:08 -030019#include <linux/libfdt.h>
20#include <spl.h>
21
22#if defined(CONFIG_SPL_BUILD)
Otavio Salvadorecc56402018-09-13 16:57:05 -030023
24#ifdef CONFIG_SPL_OS_BOOT
25int spl_start_uboot(void)
26{
Fabio Estevame2689522019-09-11 14:33:44 -030027 /* Break into full U-Boot on 'c' */
28 if (serial_tstc() && serial_getc() == 'c')
29 return 1;
30
Otavio Salvadorecc56402018-09-13 16:57:05 -030031 return 0;
32}
33#endif
34
Fabio Estevam8f926ff2018-09-04 10:23:08 -030035#include <asm/arch/mx6-ddr.h>
36
37static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
38 .grp_addds = 0x00000030,
39 .grp_ddrmode_ctl = 0x00020000,
40 .grp_b0ds = 0x00000030,
41 .grp_ctlds = 0x00000030,
42 .grp_b1ds = 0x00000030,
43 .grp_ddrpke = 0x00000000,
44 .grp_ddrmode = 0x00020000,
45 .grp_ddr_type = 0x00080000,
46};
47
48static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
49 .dram_dqm0 = 0x00000030,
50 .dram_dqm1 = 0x00000030,
51 .dram_ras = 0x00000030,
52 .dram_cas = 0x00000030,
53 .dram_odt0 = 0x00000030,
54 .dram_odt1 = 0x00000030,
55 .dram_sdba2 = 0x00000000,
56 .dram_sdclk_0 = 0x00000030,
57 .dram_sdqs0 = 0x00000030,
58 .dram_sdqs1 = 0x00000030,
59 .dram_reset = 0x00000030,
60};
61
62static struct mx6_mmdc_calibration mx6_mmcd_calib = {
63 .p0_mpwldectrl0 = 0x00000000,
64 .p0_mpdgctrl0 = 0x01380134,
65 .p0_mprddlctl = 0x40404244,
66 .p0_mpwrdlctl = 0x40405050,
67};
68
69static struct mx6_ddr_sysinfo ddr_sysinfo = {
70 .dsize = 0,
71 .cs1_mirror = 0,
72 .cs_density = 32,
73 .ncs = 1,
74 .bi_on = 1,
75 .rtt_nom = 1,
76 .rtt_wr = 0,
77 .ralat = 5,
78 .walat = 0,
79 .mif3_mode = 3,
80 .rst_to_cke = 0x23,
81 .sde_to_rst = 0x10,
82 .refsel = 1,
83 .refr = 3,
84};
85
86static struct mx6_ddr3_cfg mem_ddr = {
87 .mem_speed = 1333,
88 .density = 2,
89 .width = 16,
90 .banks = 8,
Fabio Estevam8f926ff2018-09-04 10:23:08 -030091 .coladdr = 10,
92 .pagesz = 2,
93 .trcd = 1350,
94 .trcmin = 4950,
95 .trasmin = 3600,
96};
97
98static void ccgr_init(void)
99{
100 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
101
102 writel(0xFFFFFFFF, &ccm->CCGR0);
103 writel(0xFFFFFFFF, &ccm->CCGR1);
104 writel(0xFFFFFFFF, &ccm->CCGR2);
105 writel(0xFFFFFFFF, &ccm->CCGR3);
106 writel(0xFFFFFFFF, &ccm->CCGR4);
107 writel(0xFFFFFFFF, &ccm->CCGR5);
108 writel(0xFFFFFFFF, &ccm->CCGR6);
109}
110
Fabio Estevam36c926c2018-09-04 10:23:11 -0300111static void imx6ul_spl_dram_cfg_size(u32 ram_size)
Fabio Estevam8f926ff2018-09-04 10:23:08 -0300112{
Fabio Estevam36c926c2018-09-04 10:23:11 -0300113 if (ram_size == SZ_256M)
114 mem_ddr.rowaddr = 14;
115 else
116 mem_ddr.rowaddr = 15;
117
Fabio Estevam8f926ff2018-09-04 10:23:08 -0300118 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
119 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
120}
121
Fabio Estevam36c926c2018-09-04 10:23:11 -0300122static void imx6ul_spl_dram_cfg(void)
123{
124 ulong ram_size_test, ram_size = 0;
125
126 for (ram_size = SZ_512M; ram_size >= SZ_256M; ram_size >>= 1) {
127 imx6ul_spl_dram_cfg_size(ram_size);
128 ram_size_test = get_ram_size((long int *)PHYS_SDRAM, ram_size);
129 if (ram_size_test == ram_size)
130 break;
131 }
132
133 if (ram_size < SZ_256M) {
134 puts("ERROR: DRAM size detection failed\n");
135 hang();
136 }
137}
138
Fabio Estevam8f926ff2018-09-04 10:23:08 -0300139void board_init_f(ulong dummy)
140{
141 ccgr_init();
142 arch_cpu_init();
143 board_early_init_f();
144 timer_init();
145 preloader_console_init();
Fabio Estevam36c926c2018-09-04 10:23:11 -0300146 imx6ul_spl_dram_cfg();
Fabio Estevam8f926ff2018-09-04 10:23:08 -0300147 memset(__bss_start, 0, __bss_end - __bss_start);
148 board_init_r(NULL, 0);
149}
150
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100151void reset_cpu(void)
Fabio Estevam8f926ff2018-09-04 10:23:08 -0300152{
153}
Fabio Estevam67fc8fc2019-03-21 10:59:06 -0300154
155#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
156 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
157 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
158
159static iomux_v3_cfg_t const usdhc1_pads[] = {
160 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
161 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
162 MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
163 MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
164 MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
165 MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
166 MX6_PAD_NAND_READY_B__USDHC1_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
167 MX6_PAD_NAND_CE0_B__USDHC1_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
168 MX6_PAD_NAND_CE1_B__USDHC1_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
169 MX6_PAD_NAND_CLE__USDHC1_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
170};
171
172static struct fsl_esdhc_cfg usdhc_cfg[1] = {
173 {USDHC1_BASE_ADDR},
174};
175
176int board_mmc_getcd(struct mmc *mmc)
177{
178 return 1;
179}
180
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900181int board_mmc_init(struct bd_info *bis)
Fabio Estevam67fc8fc2019-03-21 10:59:06 -0300182{
183 imx_iomux_v3_setup_multiple_pads(usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
184 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
185 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
186}
Fabio Estevam8f926ff2018-09-04 10:23:08 -0300187#endif