2 * Copyright (C) 2016 Amarula Solutions B.V.
3 * Copyright (C) 2016 Engicam S.r.l.
4 * Author: Jagan Teki <jagan@amarulasolutions.com>
6 * SPDX-License-Identifier: GPL-2.0+
13 #include <linux/sizes.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/crm_regs.h>
17 #include <asm/arch/iomux.h>
18 #include <asm/arch/mx6-pins.h>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/imx-common/iomux-v3.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 #define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
25 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
26 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
28 static iomux_v3_cfg_t const uart1_pads[] = {
29 MX6_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
30 MX6_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
33 int board_early_init_f(void)
35 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
40 #ifdef CONFIG_NAND_MXS
42 #define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
43 #define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
45 #define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
47 static iomux_v3_cfg_t const nand_pads[] = {
48 MX6_PAD_NAND_DATA00__RAWNAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
49 MX6_PAD_NAND_DATA01__RAWNAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
50 MX6_PAD_NAND_DATA02__RAWNAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
51 MX6_PAD_NAND_DATA03__RAWNAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
52 MX6_PAD_NAND_DATA04__RAWNAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
53 MX6_PAD_NAND_DATA05__RAWNAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
54 MX6_PAD_NAND_DATA06__RAWNAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
55 MX6_PAD_NAND_DATA07__RAWNAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
56 MX6_PAD_NAND_CLE__RAWNAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
57 MX6_PAD_NAND_ALE__RAWNAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
58 MX6_PAD_NAND_CE0_B__RAWNAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
59 MX6_PAD_NAND_RE_B__RAWNAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
60 MX6_PAD_NAND_WE_B__RAWNAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
61 MX6_PAD_NAND_WP_B__RAWNAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
62 MX6_PAD_NAND_READY_B__RAWNAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
65 static void setup_gpmi_nand(void)
67 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
69 /* config gpmi nand iomux */
70 imx_iomux_v3_setup_multiple_pads(nand_pads, ARRAY_SIZE(nand_pads));
72 clrbits_le32(&mxc_ccm->CCGR4,
73 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
74 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
75 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
76 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
77 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
80 * config gpmi and bch clock to 100 MHz
81 * bch/gpmi select PLL2 PFD2 400M
84 clrbits_le32(&mxc_ccm->cscmr1,
85 MXC_CCM_CSCMR1_BCH_CLK_SEL |
86 MXC_CCM_CSCMR1_GPMI_CLK_SEL);
87 clrsetbits_le32(&mxc_ccm->cscdr1,
88 MXC_CCM_CSCDR1_BCH_PODF_MASK |
89 MXC_CCM_CSCDR1_GPMI_PODF_MASK,
90 (3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
91 (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
93 /* enable gpmi and bch clock gating */
94 setbits_le32(&mxc_ccm->CCGR4,
95 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
96 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
97 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
98 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
99 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
101 /* enable apbh clock gating */
102 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
104 #endif /* CONFIG_NAND_MXS */
106 int board_late_init(void)
108 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
112 setenv("modeboot", "mmcboot");
114 case IMX6_BMODE_NAND:
115 setenv("modeboot", "nandboot");
118 setenv("modeboot", "");
127 /* Address of boot parameters */
128 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
130 #ifdef CONFIG_NAND_MXS
139 gd->ram_size = imx_ddr_size();
144 #ifdef CONFIG_SPL_BUILD
148 #include <asm/arch/crm_regs.h>
149 #include <asm/arch/mx6-ddr.h>
151 /* MMC board initialization is needed till adding DM support in SPL */
152 #if defined(CONFIG_FSL_ESDHC) && !defined(CONFIG_DM_MMC)
154 #include <fsl_esdhc.h>
156 #define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
157 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
158 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
160 static iomux_v3_cfg_t const usdhc1_pads[] = {
161 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
162 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
163 MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
164 MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
165 MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
166 MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
169 MX6_PAD_GPIO1_IO05__USDHC1_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL),
171 MX6_PAD_UART1_RTS_B__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL),
173 MX6_PAD_GPIO1_IO09__GPIO1_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
176 #define USDHC1_CD_GPIO IMX_GPIO_NR(1, 1)
178 struct fsl_esdhc_cfg usdhc_cfg[1] = {
179 {USDHC1_BASE_ADDR, 0, 4},
182 int board_mmc_getcd(struct mmc *mmc)
184 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
187 switch (cfg->esdhc_base) {
188 case USDHC1_BASE_ADDR:
189 ret = !gpio_get_value(USDHC1_CD_GPIO);
196 int board_mmc_init(bd_t *bis)
201 * According to the board_mmc_init() the following map is done:
202 * (U-boot device node) (Physical Port)
205 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
208 imx_iomux_v3_setup_multiple_pads(
209 usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
210 gpio_direction_input(USDHC1_CD_GPIO);
211 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
214 printf("Warning - USDHC%d controller not supporting\n",
219 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
221 printf("Warning: failed to initialize mmc dev %d\n", i);
228 #endif /* CONFIG_FSL_ESDHC */
230 static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
231 .grp_addds = 0x00000030,
232 .grp_ddrmode_ctl = 0x00020000,
233 .grp_b0ds = 0x00000030,
234 .grp_ctlds = 0x00000030,
235 .grp_b1ds = 0x00000030,
236 .grp_ddrpke = 0x00000000,
237 .grp_ddrmode = 0x00020000,
238 .grp_ddr_type = 0x000c0000,
241 static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
242 .dram_dqm0 = 0x00000030,
243 .dram_dqm1 = 0x00000030,
244 .dram_ras = 0x00000030,
245 .dram_cas = 0x00000030,
246 .dram_odt0 = 0x00000030,
247 .dram_odt1 = 0x00000030,
248 .dram_sdba2 = 0x00000000,
249 .dram_sdclk_0 = 0x00000008,
250 .dram_sdqs0 = 0x00000038,
251 .dram_sdqs1 = 0x00000030,
252 .dram_reset = 0x00000030,
255 static struct mx6_mmdc_calibration mx6_mmcd_calib = {
256 .p0_mpwldectrl0 = 0x00070007,
257 .p0_mpdgctrl0 = 0x41490145,
258 .p0_mprddlctl = 0x40404546,
259 .p0_mpwrdlctl = 0x4040524D,
262 struct mx6_ddr_sysinfo ddr_sysinfo = {
268 .rtt_nom = 1, /* RTT_Nom = RZQ/2 */
269 .walat = 1, /* Write additional latency */
270 .ralat = 5, /* Read additional latency */
271 .mif3_mode = 3, /* Command prediction working mode */
272 .bi_on = 1, /* Bank interleaving enabled */
273 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
274 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
275 .ddr_type = DDR_TYPE_DDR3,
278 static struct mx6_ddr3_cfg mem_ddr = {
291 static void ccgr_init(void)
293 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
295 writel(0xFFFFFFFF, &ccm->CCGR0);
296 writel(0xFFFFFFFF, &ccm->CCGR1);
297 writel(0xFFFFFFFF, &ccm->CCGR2);
298 writel(0xFFFFFFFF, &ccm->CCGR3);
299 writel(0xFFFFFFFF, &ccm->CCGR4);
300 writel(0xFFFFFFFF, &ccm->CCGR5);
301 writel(0xFFFFFFFF, &ccm->CCGR6);
302 writel(0xFFFFFFFF, &ccm->CCGR7);
305 static void spl_dram_init(void)
307 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
308 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
311 void board_init_f(ulong dummy)
313 /* setup AIPS and disable watchdog */
318 /* iomux and setup of i2c */
319 board_early_init_f();
324 /* UART clocks enabled and gd valid - init serial console */
325 preloader_console_init();
327 /* DDR initialization */
331 memset(__bss_start, 0, __bss_end - __bss_start);
333 /* load/boot image from boot device */
334 board_init_r(NULL, 0);
336 #endif /* CONFIG_SPL_BUILD */