blob: 1dff69c82771f5d0e69cd257a8c6ca2f596c4207 [file] [log] [blame]
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2015-2019 Variscite Ltd.
4 * Copyright (C) 2019 Parthiban Nallathambi <parthitce@gmail.com>
5 */
6
7#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +02009#include <spl.h>
10#include <asm/arch/clock.h>
11#include <asm/io.h>
12#include <asm/arch/mx6-ddr.h>
13#include <asm/arch/mx6-pins.h>
14#include <asm/arch/crm_regs.h>
Shiji Yangbb112342023-08-03 09:47:16 +080015#include <asm/sections.h>
Yangbo Lu73340382019-06-21 11:42:28 +080016#include <fsl_esdhc_imx.h>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +020017
18#define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
19 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
20 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
21
22static iomux_v3_cfg_t const uart1_pads[] = {
23 MX6_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
24 MX6_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
25};
26
27static void setup_iomux_uart(void)
28{
29 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
30}
31
32static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
33 .grp_addds = 0x00000030,
34 .grp_ddrmode_ctl = 0x00020000,
35 .grp_b0ds = 0x00000030,
36 .grp_ctlds = 0x00000030,
37 .grp_b1ds = 0x00000030,
38 .grp_ddrpke = 0x00000000,
39 .grp_ddrmode = 0x00020000,
40 .grp_ddr_type = 0x000c0000,
41};
42
43static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
44 .dram_dqm0 = 0x00000030,
45 .dram_dqm1 = 0x00000030,
46 .dram_ras = 0x00000030,
47 .dram_cas = 0x00000030,
48 .dram_odt0 = 0x00000030,
49 .dram_odt1 = 0x00000030,
50 .dram_sdba2 = 0x00000000,
51 .dram_sdclk_0 = 0x00000008,
52 .dram_sdqs0 = 0x00000038,
53 .dram_sdqs1 = 0x00000030,
54 .dram_reset = 0x00000030,
55};
56
57static struct mx6_mmdc_calibration mx6_mmcd_calib = {
58 .p0_mpwldectrl0 = 0x00000000,
59 .p0_mpdgctrl0 = 0x414C0158,
60 .p0_mprddlctl = 0x40403A3A,
61 .p0_mpwrdlctl = 0x40405A56,
62};
63
64struct mx6_ddr_sysinfo ddr_sysinfo = {
65 .dsize = 0,
66 .cs_density = 20,
67 .ncs = 1,
68 .cs1_mirror = 0,
69 .rtt_wr = 2,
70 .rtt_nom = 1, /* RTT_Nom = RZQ/2 */
71 .walat = 1, /* Write additional latency */
72 .ralat = 5, /* Read additional latency */
73 .mif3_mode = 3, /* Command prediction working mode */
74 .bi_on = 1, /* Bank interleaving enabled */
75 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
76 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
77};
78
79static struct mx6_ddr3_cfg mem_ddr = {
80 .mem_speed = 800,
81 .density = 4,
82 .width = 16,
83 .banks = 8,
84 .rowaddr = 15,
85 .coladdr = 10,
86 .pagesz = 2,
87 .trcd = 1375,
88 .trcmin = 4875,
89 .trasmin = 3500,
90};
91
92static void ccgr_init(void)
93{
94 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
95
96 writel(0xFFFFFFFF, &ccm->CCGR0);
97 writel(0xFFFFFFFF, &ccm->CCGR1);
98 writel(0xFFFFFFFF, &ccm->CCGR2);
99 writel(0xFFFFFFFF, &ccm->CCGR3);
100 writel(0xFFFFFFFF, &ccm->CCGR4);
101 writel(0xFFFFFFFF, &ccm->CCGR5);
102 writel(0xFFFFFFFF, &ccm->CCGR6);
103 writel(0xFFFFFFFF, &ccm->CCGR7);
104 /* Enable Audio Clock for SOM codec */
105 writel(0x01130100, (long *)CCM_CCOSR);
106}
107
108static void spl_dram_init(void)
109{
110 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
111 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
112}
113
114#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
115 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
116 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
117static iomux_v3_cfg_t const usdhc1_pads[] = {
118 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
119 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
120 MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
121 MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
122 MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
123 MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
124};
125
126#ifndef CONFIG_NAND_MXS
127static iomux_v3_cfg_t const usdhc2_pads[] = {
128 MX6_PAD_NAND_RE_B__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
129 MX6_PAD_NAND_WE_B__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
130 MX6_PAD_NAND_DATA00__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
131 MX6_PAD_NAND_DATA01__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
132 MX6_PAD_NAND_DATA02__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
133 MX6_PAD_NAND_DATA03__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
134 MX6_PAD_NAND_DATA04__USDHC2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
135 MX6_PAD_NAND_DATA05__USDHC2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
136 MX6_PAD_NAND_DATA06__USDHC2_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
137 MX6_PAD_NAND_DATA07__USDHC2_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
138};
139#endif
140
141static struct fsl_esdhc_cfg usdhc_cfg[] = {
142 {
143 .esdhc_base = USDHC1_BASE_ADDR,
144 .max_bus_width = 4,
145 },
146#ifndef CONFIG_NAND_MXS
147 {
148 .esdhc_base = USDHC2_BASE_ADDR,
149 .max_bus_width = 8,
150 },
151#endif
152};
153
154int board_mmc_getcd(struct mmc *mmc)
155{
156 return 1;
157}
158
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900159int board_mmc_init(struct bd_info *bis)
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +0200160{
161 int i, ret;
162
Tom Rini376b88a2022-10-28 20:27:13 -0400163 for (i = 0; i < CFG_SYS_FSL_USDHC_NUM; i++) {
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +0200164 switch (i) {
165 case 0:
166 SETUP_IOMUX_PADS(usdhc1_pads);
167 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
168 break;
169#ifndef CONFIG_NAND_MXS
170 case 1:
171 SETUP_IOMUX_PADS(usdhc2_pads);
172 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
173 break;
174#endif
175 default:
176 printf("Warning - USDHC%d controller not supporting\n",
177 i + 1);
178 return 0;
179 }
180
181 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
182 if (ret) {
183 printf("Warning: failed to initialize mmc dev %d\n", i);
184 return ret;
185 }
186 }
187
188 return 0;
189}
190
191void board_init_f(ulong dummy)
192{
193 /* setup AIPS and disable watchdog */
194 arch_cpu_init();
195
196 ccgr_init();
197
198 /* setup GP timer */
199 timer_init();
200
201 setup_iomux_uart();
202
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +0200203 /* UART clocks enabled and gd valid - init serial console */
204 preloader_console_init();
205
206 /* DDR initialization */
207 spl_dram_init();
208
209 /* Clear the BSS. */
210 memset(__bss_start, 0, __bss_end - __bss_start);
211
212 /* load/boot image from boot device */
213 board_init_r(NULL, 0);
214}