Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 Marek Vasut <marex@denx.de> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <hang.h> |
| 8 | #include <image.h> |
| 9 | #include <init.h> |
| 10 | #include <spl.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm-generic/gpio.h> |
| 13 | #include <asm/arch/clock.h> |
| 14 | #include <asm/arch/imx8mp_pins.h> |
| 15 | #include <asm/arch/sys_proto.h> |
| 16 | #include <asm/mach-imx/boot_mode.h> |
| 17 | #include <asm/arch/ddr.h> |
| 18 | |
| 19 | #include <dm/uclass.h> |
| 20 | #include <dm/device.h> |
| 21 | #include <dm/uclass-internal.h> |
| 22 | #include <dm/device-internal.h> |
| 23 | |
| 24 | #include <power/pmic.h> |
| 25 | #include <power/pca9450.h> |
| 26 | |
| 27 | #include "lpddr4_timing.h" |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1) |
| 32 | #define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE) |
| 33 | |
| 34 | static const iomux_v3_cfg_t uart_pads[] = { |
| 35 | MX8MP_PAD_SAI2_RXFS__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 36 | MX8MP_PAD_SAI2_RXC__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 37 | }; |
| 38 | |
| 39 | static const iomux_v3_cfg_t wdog_pads[] = { |
| 40 | MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL), |
| 41 | }; |
| 42 | |
| 43 | static void dh_imx8mp_early_init_f(void) |
| 44 | { |
| 45 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 46 | |
| 47 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 48 | |
| 49 | set_wdog_reset(wdog); |
| 50 | |
| 51 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
| 52 | } |
| 53 | |
| 54 | static int dh_imx8mp_board_power_init(void) |
| 55 | { |
| 56 | struct udevice *dev; |
| 57 | int ret; |
| 58 | |
| 59 | ret = pmic_get("pmic@25", &dev); |
| 60 | if (ret == -ENODEV) { |
| 61 | puts("Failed to get PMIC\n"); |
| 62 | return 0; |
| 63 | } |
| 64 | if (ret != 0) |
| 65 | return ret; |
| 66 | |
| 67 | /* BUCKxOUT_DVS0/1 control BUCK123 output. */ |
| 68 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
| 69 | |
| 70 | /* Increase VDD_SOC to typical value 0.95V before first DRAM access. */ |
| 71 | if (IS_ENABLED(CONFIG_IMX8M_VDD_SOC_850MV)) |
| 72 | /* Set DVS0 to 0.85V for special case. */ |
| 73 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x14); |
| 74 | else |
| 75 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1c); |
| 76 | |
| 77 | /* Set DVS1 to 0.85v for suspend. */ |
| 78 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14); |
| 79 | |
| 80 | /* |
| 81 | * Enable DVS control through PMIC_STBY_REQ and |
| 82 | * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H). |
| 83 | */ |
| 84 | pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59); |
| 85 | |
| 86 | /* Kernel uses OD/OD frequency for SoC. */ |
| 87 | |
| 88 | /* To avoid timing risk from SoC to ARM, increase VDD_ARM to OD voltage 0.95V */ |
| 89 | pmic_reg_write(dev, PCA9450_BUCK2OUT_DVS0, 0x1c); |
| 90 | |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 91 | /* Set LDO4 and CONFIG2 to enable the I2C level translator. */ |
| 92 | pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x59); |
| 93 | pmic_reg_write(dev, PCA9450_CONFIG2, 0x1); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static struct dram_timing_info *dram_timing_info[8] = { |
| 99 | NULL, /* 512 MiB */ |
| 100 | NULL, /* 1024 MiB */ |
| 101 | NULL, /* 1536 MiB */ |
| 102 | NULL, /* 2048 MiB */ |
| 103 | NULL, /* 3072 MiB */ |
| 104 | &dh_imx8mp_dhcom_dram_timing_32g_x32, /* 4096 MiB */ |
| 105 | NULL, /* 6144 MiB */ |
| 106 | NULL, /* 8192 MiB */ |
| 107 | }; |
| 108 | |
| 109 | static void spl_dram_init(void) |
| 110 | { |
| 111 | const u16 size[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 }; |
| 112 | u8 memcfg = dh_get_memcfg(); |
| 113 | int i; |
| 114 | |
| 115 | printf("DDR: %d MiB [0x%x]\n", size[memcfg], memcfg); |
| 116 | |
| 117 | if (!dram_timing_info[memcfg]) { |
| 118 | printf("Unsupported DRAM strapping, trying lowest supported. MEMCFG=0x%x\n", |
| 119 | memcfg); |
| 120 | for (i = 0; i < ARRAY_SIZE(dram_timing_info); i++) |
| 121 | if (dram_timing_info[i]) /* Configuration found */ |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | ddr_init(dram_timing_info[memcfg]); |
| 126 | } |
| 127 | |
| 128 | void spl_board_init(void) |
| 129 | { |
| 130 | /* |
| 131 | * Set GIC clock to 500 MHz for OD VDD_SOC. Kernel driver does not |
| 132 | * allow to change it. Should set the clock after PMIC setting done. |
| 133 | * Default is 400 MHz (system_pll1_800m with div = 2) set by ROM for |
| 134 | * ND VDD_SOC. |
| 135 | */ |
| 136 | clock_enable(CCGR_GIC, 0); |
| 137 | clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5)); |
| 138 | clock_enable(CCGR_GIC, 1); |
| 139 | } |
| 140 | |
| 141 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 142 | { |
| 143 | return BOOT_DEVICE_BOOTROM; |
| 144 | } |
| 145 | |
| 146 | void board_init_f(ulong dummy) |
| 147 | { |
| 148 | struct udevice *dev; |
| 149 | int ret; |
| 150 | |
| 151 | arch_cpu_init(); |
| 152 | |
| 153 | init_uart_clk(0); |
| 154 | |
| 155 | dh_imx8mp_early_init_f(); |
| 156 | |
| 157 | preloader_console_init(); |
| 158 | |
| 159 | /* Clear the BSS. */ |
| 160 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 161 | |
| 162 | ret = spl_early_init(); |
| 163 | if (ret) { |
| 164 | debug("spl_early_init() failed: %d\n", ret); |
| 165 | hang(); |
| 166 | } |
| 167 | |
| 168 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 169 | "clock-controller@30380000", |
| 170 | &dev); |
| 171 | if (ret < 0) { |
| 172 | printf("Failed to find clock node. Check device tree\n"); |
| 173 | hang(); |
| 174 | } |
| 175 | |
| 176 | enable_tzc380(); |
| 177 | |
| 178 | dh_imx8mp_board_power_init(); |
| 179 | |
| 180 | /* DDR initialization */ |
| 181 | spl_dram_init(); |
| 182 | |
| 183 | board_init_r(NULL, 0); |
| 184 | } |