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+
15 #include <linux/sizes.h>
17 #include <asm/arch/clock.h>
18 #include <asm/arch/crm_regs.h>
19 #include <asm/arch/iomux.h>
20 #include <asm/arch/mx6-pins.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/imx-common/iomux-v3.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 #define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
27 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
28 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
30 #define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
31 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
32 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
34 static iomux_v3_cfg_t const uart4_pads[] = {
35 IOMUX_PADS(PAD_KEY_COL0__UART4_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
36 IOMUX_PADS(PAD_KEY_ROW0__UART4_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
39 static iomux_v3_cfg_t const enet_pads[] = {
40 IOMUX_PADS(PAD_ENET_CRS_DV__ENET_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL)),
41 IOMUX_PADS(PAD_GPIO_16__ENET_REF_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL | PAD_CTL_SRE_FAST)),
42 IOMUX_PADS(PAD_ENET_TX_EN__ENET_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL)),
43 IOMUX_PADS(PAD_ENET_RXD1__ENET_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
44 IOMUX_PADS(PAD_ENET_RXD0__ENET_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
45 IOMUX_PADS(PAD_ENET_TXD1__ENET_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
46 IOMUX_PADS(PAD_ENET_TXD0__ENET_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
47 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
48 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
49 IOMUX_PADS(PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(NO_PAD_CTRL)),
53 #define ENET_PHY_RST IMX_GPIO_NR(7, 12)
54 static int setup_fec(void)
56 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
57 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
62 /* Enable fec clock */
63 setbits_le32(&ccm->CCGR1, MXC_CCM_CCGR1_ENET_MASK);
66 ret = enable_fec_anatop_clock(0, ENET_50MHZ);
71 reg = readl(&anatop->pll_enet);
72 reg &= ~BM_ANADIG_PLL_SYS_POWERDOWN;
73 writel(reg, &anatop->pll_enet);
74 reg = readl(&anatop->pll_enet);
75 reg |= BM_ANADIG_PLL_SYS_ENABLE;
77 if (readl(&anatop->pll_enet) & BM_ANADIG_PLL_SYS_LOCK)
82 reg &= ~BM_ANADIG_PLL_SYS_BYPASS;
83 writel(reg, &anatop->pll_enet);
86 gpio_direction_output(ENET_PHY_RST, 0);
88 gpio_set_value(ENET_PHY_RST, 1);
93 int board_eth_init(bd_t *bis)
97 SETUP_IOMUX_PADS(enet_pads);
100 return ret = cpu_eth_init(bis);
104 int board_early_init_f(void)
106 SETUP_IOMUX_PADS(uart4_pads);
113 /* Address of boot parameters */
114 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
121 gd->ram_size = imx_ddr_size();
126 #ifdef CONFIG_SPL_BUILD
130 #include <asm/arch/crm_regs.h>
131 #include <asm/arch/mx6-ddr.h>
133 /* MMC board initialization is needed till adding DM support in SPL */
134 #if defined(CONFIG_FSL_ESDHC) && !defined(CONFIG_DM_MMC)
136 #include <fsl_esdhc.h>
138 #define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
139 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
140 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
142 static iomux_v3_cfg_t const usdhc1_pads[] = {
143 IOMUX_PADS(PAD_SD1_CLK__SD1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
144 IOMUX_PADS(PAD_SD1_CMD__SD1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
145 IOMUX_PADS(PAD_SD1_DAT0__SD1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
146 IOMUX_PADS(PAD_SD1_DAT1__SD1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
147 IOMUX_PADS(PAD_SD1_DAT2__SD1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
148 IOMUX_PADS(PAD_SD1_DAT3__SD1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
149 IOMUX_PADS(PAD_GPIO_1__GPIO1_IO01 | MUX_PAD_CTRL(NO_PAD_CTRL)),/* CD */
152 #define USDHC1_CD_GPIO IMX_GPIO_NR(1, 1)
154 struct fsl_esdhc_cfg usdhc_cfg[1] = {
155 {USDHC1_BASE_ADDR, 0, 4},
158 int board_mmc_getcd(struct mmc *mmc)
160 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
163 switch (cfg->esdhc_base) {
164 case USDHC1_BASE_ADDR:
165 ret = !gpio_get_value(USDHC1_CD_GPIO);
172 int board_mmc_init(bd_t *bis)
177 * According to the board_mmc_init() the following map is done:
178 * (U-boot device node) (Physical Port)
181 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
184 SETUP_IOMUX_PADS(usdhc1_pads);
185 gpio_direction_input(USDHC1_CD_GPIO);
186 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
189 printf("Warning - USDHC%d controller not supporting\n",
194 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
196 printf("Warning: failed to initialize mmc dev %d\n", i);
211 #define IMX6DQ_DRIVE_STRENGTH 0x30
212 #define IMX6SDL_DRIVE_STRENGTH 0x28
214 /* configure MX6Q/DUAL mmdc DDR io registers */
215 static struct mx6dq_iomux_ddr_regs mx6dq_ddr_ioregs = {
234 .dram_sdclk_0 = 0x30,
235 .dram_sdclk_1 = 0x30,
237 .dram_sdcke0 = 0x3000,
238 .dram_sdcke1 = 0x3000,
239 .dram_sdba2 = 0x00000000,
244 /* configure MX6Q/DUAL mmdc GRP io registers */
245 static struct mx6dq_iomux_grp_regs mx6dq_grp_ioregs = {
255 .grp_ddrmode_ctl = 0x00020000,
256 .grp_ddrpke = 0x00000000,
257 .grp_ddrmode = 0x00020000,
259 .grp_ddr_type = 0x000c0000,
262 /* configure MX6SOLO/DUALLITE mmdc DDR io registers */
263 struct mx6sdl_iomux_ddr_regs mx6sdl_ddr_ioregs = {
264 .dram_sdclk_0 = 0x30,
265 .dram_sdclk_1 = 0x30,
271 .dram_sdba2 = 0x00000000,
292 /* configure MX6SOLO/DUALLITE mmdc GRP io registers */
293 struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
294 .grp_ddr_type = 0x000c0000,
295 .grp_ddrmode_ctl = 0x00020000,
296 .grp_ddrpke = 0x00000000,
299 .grp_ddrmode = 0x00020000,
311 static struct mx6_ddr3_cfg mt41j256 = {
325 static struct mx6_mmdc_calibration mx6dq_mmdc_calib = {
326 .p0_mpwldectrl0 = 0x000E0009,
327 .p0_mpwldectrl1 = 0x0018000E,
328 .p1_mpwldectrl0 = 0x00000007,
329 .p1_mpwldectrl1 = 0x00000000,
330 .p0_mpdgctrl0 = 0x43280334,
331 .p0_mpdgctrl1 = 0x031C0314,
332 .p1_mpdgctrl0 = 0x4318031C,
333 .p1_mpdgctrl1 = 0x030C0258,
334 .p0_mprddlctl = 0x3E343A40,
335 .p1_mprddlctl = 0x383C3844,
336 .p0_mpwrdlctl = 0x40404440,
337 .p1_mpwrdlctl = 0x4C3E4446,
341 static struct mx6_ddr_sysinfo mem_q = {
342 .ddr_type = DDR_TYPE_DDR3,
345 /* config for full 4GB range so that get_mem_size() works */
358 static struct mx6_mmdc_calibration mx6dl_mmdc_calib = {
359 .p0_mpwldectrl0 = 0x001F0024,
360 .p0_mpwldectrl1 = 0x00110018,
361 .p1_mpwldectrl0 = 0x001F0024,
362 .p1_mpwldectrl1 = 0x00110018,
363 .p0_mpdgctrl0 = 0x4230022C,
364 .p0_mpdgctrl1 = 0x02180220,
365 .p1_mpdgctrl0 = 0x42440248,
366 .p1_mpdgctrl1 = 0x02300238,
367 .p0_mprddlctl = 0x44444A48,
368 .p1_mprddlctl = 0x46484A42,
369 .p0_mpwrdlctl = 0x38383234,
370 .p1_mpwrdlctl = 0x3C34362E,
374 static struct mx6_ddr_sysinfo mem_dl = {
377 /* config for full 4GB range so that get_mem_size() works */
390 /* DDR 32bit 512MB */
391 static struct mx6_ddr_sysinfo mem_s = {
394 /* config for full 4GB range so that get_mem_size() works */
407 static void ccgr_init(void)
409 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
411 writel(0x00003F3F, &ccm->CCGR0);
412 writel(0x0030FC00, &ccm->CCGR1);
413 writel(0x000FC000, &ccm->CCGR2);
414 writel(0x3F300000, &ccm->CCGR3);
415 writel(0xFF00F300, &ccm->CCGR4);
416 writel(0x0F0000C3, &ccm->CCGR5);
417 writel(0x000003CC, &ccm->CCGR6);
420 static void gpr_init(void)
422 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
424 /* enable AXI cache for VDOA/VPU/IPU */
425 writel(0xF00000CF, &iomux->gpr[4]);
426 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
427 writel(0x007F007F, &iomux->gpr[6]);
428 writel(0x007F007F, &iomux->gpr[7]);
431 static void spl_dram_init(void)
434 mx6sdl_dram_iocfg(32, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
435 mx6_dram_cfg(&mem_s, &mx6dl_mmdc_calib, &mt41j256);
436 } else if (is_mx6dl()) {
437 mx6sdl_dram_iocfg(64, &mx6sdl_ddr_ioregs, &mx6sdl_grp_ioregs);
438 mx6_dram_cfg(&mem_dl, &mx6dl_mmdc_calib, &mt41j256);
439 } else if (is_mx6dq()) {
440 mx6dq_dram_iocfg(64, &mx6dq_ddr_ioregs, &mx6dq_grp_ioregs);
441 mx6_dram_cfg(&mem_q, &mx6dq_mmdc_calib, &mt41j256);
447 void board_init_f(ulong dummy)
451 /* setup AIPS and disable watchdog */
457 board_early_init_f();
462 /* UART clocks enabled and gd valid - init serial console */
463 preloader_console_init();
465 /* DDR initialization */
469 memset(__bss_start, 0, __bss_end - __bss_start);
471 /* load/boot image from boot device */
472 board_init_r(NULL, 0);