1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2022 Marek Vasut <marex@denx.de>
11 #include <asm-generic/gpio.h>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/ddr.h>
14 #include <asm/arch/imx8mp_pins.h>
15 #include <asm/arch/sys_proto.h>
17 #include <asm/mach-imx/boot_mode.h>
19 #include <dm/uclass.h>
20 #include <dm/device.h>
21 #include <dm/uclass-internal.h>
22 #include <dm/device-internal.h>
24 #include <power/pmic.h>
25 #include <power/pca9450.h>
27 #include "lpddr4_timing.h"
29 #include "../common/common.h"
31 DECLARE_GLOBAL_DATA_PTR;
33 int data_modul_imx_edm_sbc_board_power_init(void)
38 ret = pmic_get("pmic@25", &dev);
40 puts("Failed to get PMIC\n");
46 /* BUCKxOUT_DVS0/1 control BUCK123 output. */
47 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
49 /* Increase VDD_SOC to typical value 0.95V before first DRAM access. */
50 if (IS_ENABLED(CONFIG_IMX8M_VDD_SOC_850MV))
51 /* Set DVS0 to 0.85V for special case. */
52 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x14);
54 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1c);
56 /* Set DVS1 to 0.85v for suspend. */
57 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
60 * Enable DVS control through PMIC_STBY_REQ and
61 * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H).
63 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
65 /* Kernel uses OD/OD frequency for SoC. */
67 /* To avoid timing risk from SoC to ARM, increase VDD_ARM to OD voltage 0.95V */
68 pmic_reg_write(dev, PCA9450_BUCK2OUT_DVS0, 0x1c);
70 /* DRAM Vdd1 always FPWM */
71 pmic_reg_write(dev, PCA9450_BUCK5CTRL, 0x0d);
72 /* DRAM Vdd2/Vddq always FPWM */
73 pmic_reg_write(dev, PCA9450_BUCK6CTRL, 0x0d);
75 /* Set LDO4 and CONFIG2 to enable the I2C level translator. */
76 pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x59);
77 pmic_reg_write(dev, PCA9450_CONFIG2, 0x1);
82 void spl_board_init(void)
85 * Set GIC clock to 500 MHz for OD VDD_SOC. Kernel driver does not
86 * allow to change it. Should set the clock after PMIC setting done.
87 * Default is 400 MHz (system_pll1_800m with div = 2) set by ROM for
90 clock_enable(CCGR_GIC, 0);
91 clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5));
92 clock_enable(CCGR_GIC, 1);
95 int spl_board_boot_device(enum boot_device boot_dev_spl)
97 if (boot_dev_spl == SPI_NOR_BOOT) /* SPI NOR */
98 return BOOT_DEVICE_SPI;
100 if (boot_dev_spl == MMC3_BOOT) /* eMMC */
101 return BOOT_DEVICE_MMC2;
103 return BOOT_DEVICE_MMC1; /* SD */
106 void board_boot_order(u32 *spl_boot_list)
108 int boot_device = spl_boot_device();
110 spl_boot_list[0] = boot_device; /* 1:SD 2:eMMC 8:SPI NOR */
112 if (boot_device == BOOT_DEVICE_SPI) { /* SPI, eMMC, SD */
113 spl_boot_list[1] = BOOT_DEVICE_MMC2; /* eMMC */
114 spl_boot_list[2] = BOOT_DEVICE_MMC1; /* SD */
115 } else if (boot_device == BOOT_DEVICE_MMC1) { /* SD, eMMC, SPI */
116 spl_boot_list[1] = BOOT_DEVICE_MMC2; /* eMMC */
117 spl_boot_list[2] = BOOT_DEVICE_SPI; /* SPI */
118 } else { /* eMMC, SPI, SD */
119 spl_boot_list[1] = BOOT_DEVICE_SPI; /* SPI */
120 spl_boot_list[2] = BOOT_DEVICE_MMC1; /* SD */
123 spl_boot_list[3] = BOOT_DEVICE_UART; /* YModem */
124 spl_boot_list[4] = BOOT_DEVICE_NONE;
127 unsigned long board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc, unsigned long sect)
129 const u32 boot_dev = spl_boot_device();
132 if (boot_dev == BOOT_DEVICE_MMC2) { /* eMMC */
133 part = spl_mmc_emmc_boot_partition(mmc);
134 if (part == 1 || part == 2) /* eMMC BOOT1/BOOT2 HW partitions */
141 static struct dram_timing_info *dram_timing_info[8] = {
142 &dmo_imx8mp_sbc_dram_timing_32_32, /* 32 Gbit x32 */
143 NULL, /* 32 Gbit x16 */
144 NULL, /* 16 Gbit x32 */
145 NULL, /* 16 Gbit x16 */
146 NULL, /* 8 Gbit x32 */
147 NULL, /* 8 Gbit x16 */
152 void board_init_f(ulong dummy)
154 dmo_board_init_f(MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B, dram_timing_info);