1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2022 Josua Mayer <josua@solid-run.com>
5 * Copyright (C) 2015 Freescale Semiconductor, Inc.
7 * Author: Fabio Estevam <fabio.estevam@freescale.com>
9 * Copyright (C) 2013 Jon Nettleton <jon.nettleton@gmail.com>
11 * Based on SPL code from Solidrun tree, which is:
12 * Author: Tungyi Lin <tungyilin1127@gmail.com>
14 * Derived from EDM_CF_IMX6 code by TechNexion,Inc
15 * Ported to SolidRun microSOM by Rabeeh Khoury <rabeeh@solid-run.com>
22 #include <asm/arch/clock.h>
23 #include <asm/arch/imx-regs.h>
24 #include <asm/arch/iomux.h>
25 #include <asm/arch/mx6-pins.h>
26 #include <asm/arch/mxc_hdmi.h>
28 #include <asm/global_data.h>
29 #include <linux/delay.h>
30 #include <linux/errno.h>
32 #include <asm/mach-imx/iomux-v3.h>
33 #include <asm/mach-imx/sata.h>
34 #include <asm/mach-imx/video.h>
35 #include <asm/sections.h>
37 #include <fsl_esdhc_imx.h>
39 #include <asm/arch/crm_regs.h>
41 #include <asm/arch/sys_proto.h>
44 #include <usb/ehci-ci.h>
48 DECLARE_GLOBAL_DATA_PTR;
50 #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
51 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
52 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
54 #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
55 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
56 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
58 #define USB_H1_VBUS IMX_GPIO_NR(1, 0)
67 static struct gpio_desc board_detect_desc[5];
69 #define MEM_STRIDE 0x4000000
70 static u32 get_ram_size_stride_test(u32 *base, u32 maxsize)
78 /* First save the data */
79 for (cnt = 0; cnt < maxsize; cnt += MEM_STRIDE) {
80 addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */
86 /* First write a signature */
87 * (volatile u32 *)base = 0x12345678;
88 for (size = MEM_STRIDE; size < maxsize; size += MEM_STRIDE) {
89 * (volatile u32 *)((u32)base + size) = size;
91 if (* (volatile u32 *)((u32)base) == size) { /* We reached the overlapping address */
96 /* Restore the data */
97 for (cnt = (maxsize - MEM_STRIDE); i > 0; cnt -= MEM_STRIDE) {
98 addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */
109 u32 max_size = imx_ddr_size();
111 gd->ram_size = get_ram_size_stride_test((u32 *) CFG_SYS_SDRAM_BASE,
117 static iomux_v3_cfg_t const uart1_pads[] = {
118 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
119 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
122 static iomux_v3_cfg_t const usdhc2_pads[] = {
123 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
124 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
125 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
126 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
127 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
128 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
131 static iomux_v3_cfg_t const usdhc3_pads[] = {
132 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
133 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
134 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
135 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
136 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
137 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
138 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
139 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
140 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
141 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
142 IOMUX_PADS(PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
145 static iomux_v3_cfg_t const board_detect[] = {
146 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
147 IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(UART_PAD_CTRL)),
148 IOMUX_PADS(PAD_EIM_DA4__GPIO3_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
149 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(UART_PAD_CTRL)),
152 static iomux_v3_cfg_t const som_rev_detect[] = {
153 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
154 IOMUX_PADS(PAD_CSI0_DAT14__GPIO6_IO00 | MUX_PAD_CTRL(UART_PAD_CTRL)),
155 IOMUX_PADS(PAD_CSI0_DAT18__GPIO6_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
158 static void setup_iomux_uart(void)
160 SETUP_IOMUX_PADS(uart1_pads);
163 int board_mmc_get_env_dev(int devno)
168 #ifdef CONFIG_VIDEO_IPUV3
169 static void do_enable_hdmi(struct display_info_t const *dev)
171 imx_enable_hdmi_phy();
174 struct display_info_t const displays[] = {
178 .pixfmt = IPU_PIX_FMT_RGB24,
179 .detect = detect_hdmi,
180 .enable = do_enable_hdmi,
183 /* 1024x768@60Hz (VESA)*/
195 .vmode = FB_VMODE_NONINTERLACED
200 size_t display_count = ARRAY_SIZE(displays);
202 static int setup_display(void)
204 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
206 int timeout = 100000;
211 /* set video pll to 455MHz (24MHz * (37+11/12) / 2) */
212 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
214 reg = readl(&ccm->analog_pll_video);
215 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
216 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(37);
217 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
218 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1);
219 writel(reg, &ccm->analog_pll_video);
221 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
222 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
224 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
225 writel(reg, &ccm->analog_pll_video);
228 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
231 printf("Warning: video pll lock timeout!\n");
235 reg = readl(&ccm->analog_pll_video);
236 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
237 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
238 writel(reg, &ccm->analog_pll_video);
240 /* gate ipu1_di0_clk */
241 clrbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
243 /* select video_pll clock / 7 for ipu1_di0_clk -> 65MHz pixclock */
244 reg = readl(&ccm->chsccdr);
245 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK |
246 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK |
247 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
248 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET) |
249 (6 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
250 (0 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
251 writel(reg, &ccm->chsccdr);
253 /* enable ipu1_di0_clk */
254 setbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
258 #endif /* CONFIG_VIDEO_IPUV3 */
260 static int setup_fec(void)
262 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
265 ret = enable_fec_anatop_clock(0, ENET_25MHZ);
269 /* set gpr1[ENET_CLK_SEL] */
270 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK);
275 int board_early_init_f(void)
279 if (CONFIG_IS_ENABLED(SATA))
290 /* address of boot parameters */
291 gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
293 #ifdef CONFIG_VIDEO_IPUV3
294 ret = setup_display();
300 static int request_detect_gpios(void)
305 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
306 "solidrun,hummingboard-detect");
310 ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node),
311 "detect-gpios", board_detect_desc,
312 ARRAY_SIZE(board_detect_desc), GPIOD_IS_IN);
317 static int free_detect_gpios(void)
319 return gpio_free_list_nodev(board_detect_desc,
320 ARRAY_SIZE(board_detect_desc));
323 static enum board_type board_type(void)
325 int val1, val2, val3;
327 SETUP_IOMUX_PADS(board_detect);
330 * Machine selection -
331 * Machine val1, val2, val3
332 * ----------------------------
339 val3 = !!dm_gpio_get_value(&board_detect_desc[0]);
342 return HUMMINGBOARD2;
344 val2 = !!dm_gpio_get_value(&board_detect_desc[1]);
349 val1 = !!dm_gpio_get_value(&board_detect_desc[2]);
358 static bool is_rev_15_som(void)
361 SETUP_IOMUX_PADS(som_rev_detect);
363 val1 = !!dm_gpio_get_value(&board_detect_desc[3]);
364 val2 = !!dm_gpio_get_value(&board_detect_desc[4]);
366 if (val1 == 1 && val2 == 0)
372 static bool has_emmc(void)
375 mmc = find_mmc_device(2);
378 return (mmc_get_op_cond(mmc, true) < 0) ? 0 : 1;
381 static int find_ethernet_phy(void)
383 struct mii_dev *bus = NULL;
384 struct phy_device *phydev = NULL;
385 int phy_addr = -ENOENT;
387 #ifdef CONFIG_FEC_MXC
388 bus = fec_get_miibus(ENET_BASE_ADDR, -1);
392 // scan address 0, 1, 4
393 phydev = phy_find_by_mask(bus, 0b00010011);
398 pr_debug("%s: detected ethernet phy at address %d\n", __func__, phydev->addr);
399 phy_addr = phydev->addr;
407 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
409 * Configure the correct ethernet PHYs nodes in device-tree:
410 * - AR8035 at addresses 0 or 4: Cubox
411 * - AR8035 at address 0: HummingBoard, HummingBoard 2
412 * - ADIN1300 at address 1: since SoM rev 1.9
414 int ft_board_setup(void *fdt, struct bd_info *bd)
416 int node_phy0, node_phy1, node_phy4;
418 bool enable_phy0 = false, enable_phy1 = false, enable_phy4 = false;
419 enum board_type board;
422 request_detect_gpios();
423 board = board_type();
427 phy = find_ethernet_phy();
428 if (phy == 0 || phy == 4) {
433 /* atheros phy may appear only at address 0 */
438 /* atheros phy may appear at either address 0 or 4 */
441 } else if (phy == 1) {
444 pr_err("%s: couldn't detect ethernet phy, not patching dtb!\n", __func__);
448 // update all phy nodes status
449 node_phy0 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@0");
450 ret = fdt_setprop_string(fdt, node_phy0, "status", enable_phy0 ? "okay" : "disabled");
451 if (ret < 0 && enable_phy0)
452 pr_err("%s: failed to enable ethernet phy at address 0 in dtb!\n", __func__);
453 node_phy1 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@1");
454 ret = fdt_setprop_string(fdt, node_phy1, "status", enable_phy1 ? "okay" : "disabled");
455 if (ret < 0 && enable_phy1)
456 pr_err("%s: failed to enable ethernet phy at address 1 in dtb!\n", __func__);
457 node_phy4 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@4");
458 ret = fdt_setprop_string(fdt, node_phy4, "status", enable_phy4 ? "okay" : "disabled");
459 if (ret < 0 && enable_phy4)
460 pr_err("%s: failed to enable ethernet phy at address 4 in dtb!\n", __func__);
466 int board_late_init(void)
468 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
469 request_detect_gpios();
471 switch (board_type()) {
473 env_set("board_name", "CUBOXI");
474 puts("Board: MX6 Cubox-i");
477 env_set("board_name", "HUMMINGBOARD");
478 puts("Board: MX6 HummingBoard");
481 env_set("board_name", "HUMMINGBOARD2");
482 puts("Board: MX6 HummingBoard2");
486 env_set("board_name", "CUBOXI");
490 env_set("board_rev", "MX6Q");
492 env_set("board_rev", "MX6DL");
494 if (is_rev_15_som()) {
495 env_set("som_rev", "V15");
496 puts(" (som rev 1.5)\n");
502 env_set("has_emmc", "yes");
511 * This is not a perfect match. Avoid dependency on the DM GPIO driver needed
512 * for accurate board detection. Hummingboard2 DT is good enough for U-Boot on
513 * all Hummingboard/Cubox-i platforms.
515 int board_fit_config_name_match(const char *name)
519 snprintf(tmp_name, sizeof(tmp_name), "%s-hummingboard2-emmc-som-v15",
520 is_mx6dq() ? "imx6q" : "imx6dl");
522 return strcmp(name, tmp_name);
525 void board_boot_order(u32 *spl_boot_list)
527 struct src *psrc = (struct src *)SRC_BASE_ADDR;
528 unsigned int reg = readl(&psrc->sbmr1) >> 11;
529 u32 boot_mode = imx6_src_get_boot_mode() & IMX6_BMODE_MASK;
530 unsigned int bmode = readl(&src_base->sbmr2);
532 /* If bmode is serial or USB phy is active, return serial */
533 if (((bmode >> 24) & 0x03) == 0x01 || is_usbotg_phy_active()) {
534 spl_boot_list[0] = BOOT_DEVICE_BOARD;
538 switch (boot_mode >> IMX6_BMODE_SHIFT) {
542 case IMX6_BMODE_EMMC:
544 * Upon reading BOOT_CFG register the following map is done:
545 * Bit 11 and 12 of BOOT_CFG register can determine the current
551 reg &= 0x3; /* Only care about bottom 2 bits */
554 SETUP_IOMUX_PADS(usdhc2_pads);
555 spl_boot_list[0] = BOOT_DEVICE_MMC1;
558 SETUP_IOMUX_PADS(usdhc3_pads);
559 spl_boot_list[0] = BOOT_DEVICE_MMC2;
564 /* By default use USB downloader */
565 spl_boot_list[0] = BOOT_DEVICE_BOARD;
569 /* As a last resort, use serial downloader */
570 spl_boot_list[1] = BOOT_DEVICE_BOARD;
573 #ifdef CONFIG_SPL_BUILD
574 #include <asm/arch/mx6-ddr.h>
575 static const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = {
576 .dram_sdclk_0 = 0x00020030,
577 .dram_sdclk_1 = 0x00020030,
578 .dram_cas = 0x00020030,
579 .dram_ras = 0x00020030,
580 .dram_reset = 0x000c0030,
581 .dram_sdcke0 = 0x00003000,
582 .dram_sdcke1 = 0x00003000,
583 .dram_sdba2 = 0x00000000,
584 .dram_sdodt0 = 0x00003030,
585 .dram_sdodt1 = 0x00003030,
586 .dram_sdqs0 = 0x00000030,
587 .dram_sdqs1 = 0x00000030,
588 .dram_sdqs2 = 0x00000030,
589 .dram_sdqs3 = 0x00000030,
590 .dram_sdqs4 = 0x00000030,
591 .dram_sdqs5 = 0x00000030,
592 .dram_sdqs6 = 0x00000030,
593 .dram_sdqs7 = 0x00000030,
594 .dram_dqm0 = 0x00020030,
595 .dram_dqm1 = 0x00020030,
596 .dram_dqm2 = 0x00020030,
597 .dram_dqm3 = 0x00020030,
598 .dram_dqm4 = 0x00020030,
599 .dram_dqm5 = 0x00020030,
600 .dram_dqm6 = 0x00020030,
601 .dram_dqm7 = 0x00020030,
604 static const struct mx6sdl_iomux_ddr_regs mx6dl_ddr_ioregs = {
605 .dram_sdclk_0 = 0x00000028,
606 .dram_sdclk_1 = 0x00000028,
607 .dram_cas = 0x00000028,
608 .dram_ras = 0x00000028,
609 .dram_reset = 0x000c0028,
610 .dram_sdcke0 = 0x00003000,
611 .dram_sdcke1 = 0x00003000,
612 .dram_sdba2 = 0x00000000,
613 .dram_sdodt0 = 0x00003030,
614 .dram_sdodt1 = 0x00003030,
615 .dram_sdqs0 = 0x00000028,
616 .dram_sdqs1 = 0x00000028,
617 .dram_sdqs2 = 0x00000028,
618 .dram_sdqs3 = 0x00000028,
619 .dram_sdqs4 = 0x00000028,
620 .dram_sdqs5 = 0x00000028,
621 .dram_sdqs6 = 0x00000028,
622 .dram_sdqs7 = 0x00000028,
623 .dram_dqm0 = 0x00000028,
624 .dram_dqm1 = 0x00000028,
625 .dram_dqm2 = 0x00000028,
626 .dram_dqm3 = 0x00000028,
627 .dram_dqm4 = 0x00000028,
628 .dram_dqm5 = 0x00000028,
629 .dram_dqm6 = 0x00000028,
630 .dram_dqm7 = 0x00000028,
633 static const struct mx6dq_iomux_grp_regs mx6q_grp_ioregs = {
634 .grp_ddr_type = 0x000C0000,
635 .grp_ddrmode_ctl = 0x00020000,
636 .grp_ddrpke = 0x00000000,
637 .grp_addds = 0x00000030,
638 .grp_ctlds = 0x00000030,
639 .grp_ddrmode = 0x00020000,
640 .grp_b0ds = 0x00000030,
641 .grp_b1ds = 0x00000030,
642 .grp_b2ds = 0x00000030,
643 .grp_b3ds = 0x00000030,
644 .grp_b4ds = 0x00000030,
645 .grp_b5ds = 0x00000030,
646 .grp_b6ds = 0x00000030,
647 .grp_b7ds = 0x00000030,
650 static const struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
651 .grp_ddr_type = 0x000c0000,
652 .grp_ddrmode_ctl = 0x00020000,
653 .grp_ddrpke = 0x00000000,
654 .grp_addds = 0x00000028,
655 .grp_ctlds = 0x00000028,
656 .grp_ddrmode = 0x00020000,
657 .grp_b0ds = 0x00000028,
658 .grp_b1ds = 0x00000028,
659 .grp_b2ds = 0x00000028,
660 .grp_b3ds = 0x00000028,
661 .grp_b4ds = 0x00000028,
662 .grp_b5ds = 0x00000028,
663 .grp_b6ds = 0x00000028,
664 .grp_b7ds = 0x00000028,
667 /* microSOM with Dual processor and 1GB memory */
668 static const struct mx6_mmdc_calibration mx6q_1g_mmcd_calib = {
669 .p0_mpwldectrl0 = 0x00000000,
670 .p0_mpwldectrl1 = 0x00000000,
671 .p1_mpwldectrl0 = 0x00000000,
672 .p1_mpwldectrl1 = 0x00000000,
673 .p0_mpdgctrl0 = 0x0314031c,
674 .p0_mpdgctrl1 = 0x023e0304,
675 .p1_mpdgctrl0 = 0x03240330,
676 .p1_mpdgctrl1 = 0x03180260,
677 .p0_mprddlctl = 0x3630323c,
678 .p1_mprddlctl = 0x3436283a,
679 .p0_mpwrdlctl = 0x36344038,
680 .p1_mpwrdlctl = 0x422a423c,
683 /* microSOM with Quad processor and 2GB memory */
684 static const struct mx6_mmdc_calibration mx6q_2g_mmcd_calib = {
685 .p0_mpwldectrl0 = 0x00000000,
686 .p0_mpwldectrl1 = 0x00000000,
687 .p1_mpwldectrl0 = 0x00000000,
688 .p1_mpwldectrl1 = 0x00000000,
689 .p0_mpdgctrl0 = 0x0314031c,
690 .p0_mpdgctrl1 = 0x023e0304,
691 .p1_mpdgctrl0 = 0x03240330,
692 .p1_mpdgctrl1 = 0x03180260,
693 .p0_mprddlctl = 0x3630323c,
694 .p1_mprddlctl = 0x3436283a,
695 .p0_mpwrdlctl = 0x36344038,
696 .p1_mpwrdlctl = 0x422a423c,
699 /* microSOM with Solo processor and 512MB memory */
700 static const struct mx6_mmdc_calibration mx6dl_512m_mmcd_calib = {
701 .p0_mpwldectrl0 = 0x0045004D,
702 .p0_mpwldectrl1 = 0x003A0047,
703 .p0_mpdgctrl0 = 0x023C0224,
704 .p0_mpdgctrl1 = 0x02000220,
705 .p0_mprddlctl = 0x44444846,
706 .p0_mpwrdlctl = 0x32343032,
709 /* microSOM with Dual lite processor and 1GB memory */
710 static const struct mx6_mmdc_calibration mx6dl_1g_mmcd_calib = {
711 .p0_mpwldectrl0 = 0x0045004D,
712 .p0_mpwldectrl1 = 0x003A0047,
713 .p1_mpwldectrl0 = 0x001F001F,
714 .p1_mpwldectrl1 = 0x00210035,
715 .p0_mpdgctrl0 = 0x023C0224,
716 .p0_mpdgctrl1 = 0x02000220,
717 .p1_mpdgctrl0 = 0x02200220,
718 .p1_mpdgctrl1 = 0x02040208,
719 .p0_mprddlctl = 0x44444846,
720 .p1_mprddlctl = 0x4042463C,
721 .p0_mpwrdlctl = 0x32343032,
722 .p1_mpwrdlctl = 0x36363430,
725 static struct mx6_ddr3_cfg mem_ddr_2g = {
738 static struct mx6_ddr3_cfg mem_ddr_4g = {
751 static void ccgr_init(void)
753 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
755 writel(0x00C03F3F, &ccm->CCGR0);
756 writel(0x0030FC03, &ccm->CCGR1);
757 writel(0x0FFFC000, &ccm->CCGR2);
758 writel(0x3FF00000, &ccm->CCGR3);
759 writel(0x00FFF300, &ccm->CCGR4);
760 writel(0x0F0000C3, &ccm->CCGR5);
761 writel(0x000003FF, &ccm->CCGR6);
764 static void spl_dram_init(int width)
766 struct mx6_ddr_sysinfo sysinfo = {
767 /* width of data bus: 0=16, 1=32, 2=64 */
769 /* config for full 4GB range so that get_mem_size() works */
770 .cs_density = 32, /* 32Gb per CS */
771 .ncs = 1, /* single chip select */
773 .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */
774 .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */
775 .walat = 1, /* Write additional latency */
776 .ralat = 5, /* Read additional latency */
777 .mif3_mode = 3, /* Command prediction working mode */
778 .bi_on = 1, /* Bank interleaving enabled */
779 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
780 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
781 .ddr_type = DDR_TYPE_DDR3,
782 .refsel = 1, /* Refresh cycles at 32KHz */
783 .refr = 7, /* 8 refresh commands per refresh cycle */
787 mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs);
789 mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs);
791 if (is_cpu_type(MXC_CPU_MX6D))
792 mx6_dram_cfg(&sysinfo, &mx6q_1g_mmcd_calib, &mem_ddr_2g);
793 else if (is_cpu_type(MXC_CPU_MX6Q))
794 mx6_dram_cfg(&sysinfo, &mx6q_2g_mmcd_calib, &mem_ddr_4g);
795 else if (is_cpu_type(MXC_CPU_MX6DL))
796 mx6_dram_cfg(&sysinfo, &mx6dl_1g_mmcd_calib, &mem_ddr_2g);
797 else if (is_cpu_type(MXC_CPU_MX6SOLO))
798 mx6_dram_cfg(&sysinfo, &mx6dl_512m_mmcd_calib, &mem_ddr_2g);
801 void board_init_f(ulong dummy)
803 /* setup AIPS and disable watchdog */
809 /* iomux and setup of i2c */
810 board_early_init_f();
815 /* Enable device tree and early DM support*/
818 /* UART clocks enabled and gd valid - init serial console */
819 preloader_console_init();
821 /* DDR initialization */
822 if (is_cpu_type(MXC_CPU_MX6SOLO))
828 memset(__bss_start, 0, __bss_end - __bss_start);
830 /* load/boot image from boot device */
831 board_init_r(NULL, 0);