Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 Gateworks Corporation |
| 4 | */ |
| 5 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 7 | #include <cpu_func.h> |
| 8 | #include <hang.h> |
| 9 | #include <i2c.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 10 | #include <init.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 11 | #include <spl.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 12 | #include <asm/mach-imx/gpio.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 13 | #include <asm/arch/clock.h> |
| 14 | #include <asm/arch/imx8mm_pins.h> |
Tim Harvey | 1a50e74 | 2022-02-11 10:48:56 -0800 | [diff] [blame] | 15 | #include <asm/arch/imx8mn_pins.h> |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 16 | #include <asm/arch/imx8mp_pins.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/mach-imx/boot_mode.h> |
Tim Harvey | 2ccf28d | 2022-11-11 08:03:07 -0800 | [diff] [blame] | 19 | #include <asm/mach-imx/mxc_i2c.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 20 | #include <asm/arch/ddr.h> |
| 21 | #include <asm-generic/gpio.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 22 | #include <asm/sections.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 23 | #include <dm/uclass.h> |
| 24 | #include <dm/device.h> |
Tim Harvey | 2ccf28d | 2022-11-11 08:03:07 -0800 | [diff] [blame] | 25 | #include <dm/pinctrl.h> |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
Tim Harvey | 1b7fbf6 | 2021-06-30 16:50:02 -0700 | [diff] [blame] | 27 | #include <power/bd71837.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 28 | #include <power/mp5416.h> |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 29 | #include <power/pca9450.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 30 | |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 31 | #include "eeprom.h" |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 32 | #include "lpddr4_timing.h" |
| 33 | |
| 34 | #define PCIE_RSTN IMX_GPIO_NR(4, 6) |
| 35 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 36 | static void spl_dram_init(int size) |
| 37 | { |
| 38 | struct dram_timing_info *dram_timing; |
| 39 | |
| 40 | switch (size) { |
Tim Harvey | 1a50e74 | 2022-02-11 10:48:56 -0800 | [diff] [blame] | 41 | #ifdef CONFIG_IMX8MM |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 42 | case 512: |
| 43 | dram_timing = &dram_timing_512mb; |
| 44 | break; |
| 45 | case 1024: |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 46 | dram_timing = &dram_timing_1gb; |
| 47 | break; |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 48 | case 2048: |
Tim Harvey | 6603b5e | 2021-07-27 15:19:41 -0700 | [diff] [blame] | 49 | dram_timing = &dram_timing_2gb; |
| 50 | break; |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 51 | case 4096: |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 52 | dram_timing = &dram_timing_4gb; |
| 53 | break; |
| 54 | default: |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 55 | printf("Unknown DDR configuration: %d MiB\n", size); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 56 | dram_timing = &dram_timing_1gb; |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 57 | size = 1024; |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 58 | #elif CONFIG_IMX8MN |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 59 | case 1024: |
Tim Harvey | 1a50e74 | 2022-02-11 10:48:56 -0800 | [diff] [blame] | 60 | dram_timing = &dram_timing_1gb_single_die; |
| 61 | break; |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 62 | case 2048: |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 63 | if (!strcmp(eeprom_get_model(), "GW7902-SP466-A") || |
| 64 | !strcmp(eeprom_get_model(), "GW7902-SP466-B")) { |
Tim Harvey | 1a50e74 | 2022-02-11 10:48:56 -0800 | [diff] [blame] | 65 | dram_timing = &dram_timing_2gb_dual_die; |
| 66 | } else { |
| 67 | dram_timing = &dram_timing_2gb_single_die; |
| 68 | } |
| 69 | break; |
| 70 | default: |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 71 | printf("Unknown DDR configuration: %d MiB\n", size); |
Tim Harvey | 1a50e74 | 2022-02-11 10:48:56 -0800 | [diff] [blame] | 72 | dram_timing = &dram_timing_2gb_dual_die; |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 73 | size = 2048; |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 74 | #elif CONFIG_IMX8MP |
Tim Harvey | 08ac93c | 2023-06-09 09:54:51 -0700 | [diff] [blame] | 75 | case 1024: |
| 76 | dram_timing = &dram_timing_1gb_single_die; |
| 77 | break; |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 78 | case 4096: |
| 79 | dram_timing = &dram_timing_4gb_dual_die; |
| 80 | break; |
| 81 | default: |
| 82 | printf("Unknown DDR configuration: %d GiB\n", size); |
| 83 | dram_timing = &dram_timing_4gb_dual_die; |
| 84 | size = 4096; |
Tim Harvey | 1a50e74 | 2022-02-11 10:48:56 -0800 | [diff] [blame] | 85 | #endif |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 88 | printf("DRAM : LPDDR4 "); |
| 89 | if (size > 512) |
Tim Harvey | 03280f3 | 2023-06-09 09:54:01 -0700 | [diff] [blame] | 90 | printf("%d GiB", size / 1024); |
Tim Harvey | 5cc5e19 | 2022-02-18 15:19:33 -0800 | [diff] [blame] | 91 | else |
Tim Harvey | 03280f3 | 2023-06-09 09:54:01 -0700 | [diff] [blame] | 92 | printf("%d MiB", size); |
| 93 | printf(" %dMT/s %dMHz\n", |
| 94 | dram_timing->fsp_msg[0].drate, |
| 95 | dram_timing->fsp_msg[0].drate / 2); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 96 | ddr_init(dram_timing); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 99 | /* |
| 100 | * Model specific PMIC adjustments necessary prior to DRAM init |
| 101 | * |
| 102 | * Note that we can not use pmic dm drivers here as we have a generic |
| 103 | * venice dt that does not have board-specific pmic's defined. |
| 104 | * |
Tim Harvey | 1b7fbf6 | 2021-06-30 16:50:02 -0700 | [diff] [blame] | 105 | * Instead we must use dm_i2c so we a helpers to give us |
| 106 | * clrsetbit functions we would otherwise have if we could use PMIC dm |
| 107 | * drivers. |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 108 | */ |
Tim Harvey | 1b7fbf6 | 2021-06-30 16:50:02 -0700 | [diff] [blame] | 109 | static int dm_i2c_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set) |
| 110 | { |
| 111 | int ret; |
| 112 | u8 val; |
| 113 | |
| 114 | ret = dm_i2c_read(dev, reg, &val, 1); |
| 115 | if (ret) |
| 116 | return ret; |
| 117 | val = (val & ~clr) | set; |
| 118 | |
| 119 | return dm_i2c_write(dev, reg, &val, 1); |
| 120 | } |
| 121 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 122 | static int power_init_board(void) |
| 123 | { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 124 | const char *model = eeprom_get_model(); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 125 | struct udevice *bus; |
| 126 | struct udevice *dev; |
| 127 | int ret; |
| 128 | |
| 129 | if ((!strncmp(model, "GW71", 4)) || |
| 130 | (!strncmp(model, "GW72", 4)) || |
Tim Harvey | 08ac93c | 2023-06-09 09:54:51 -0700 | [diff] [blame] | 131 | (!strncmp(model, "GW73", 4)) || |
| 132 | (!strncmp(model, "GW7905", 6))) { |
Tim Harvey | d541927 | 2021-07-27 15:19:38 -0700 | [diff] [blame] | 133 | ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 134 | if (ret) { |
| 135 | printf("PMIC : failed I2C1 probe: %d\n", ret); |
| 136 | return ret; |
| 137 | } |
| 138 | ret = dm_i2c_probe(bus, 0x69, 0, &dev); |
| 139 | if (ret) { |
| 140 | printf("PMIC : failed probe: %d\n", ret); |
| 141 | return ret; |
| 142 | } |
Tim Harvey | 08ac93c | 2023-06-09 09:54:51 -0700 | [diff] [blame] | 143 | #ifdef CONFIG_IMX8MM |
| 144 | puts("PMIC : MP5416 (IMX8MM)\n"); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 145 | |
| 146 | /* set VDD_ARM SW3 to 0.92V for 1.6GHz */ |
| 147 | dm_i2c_reg_write(dev, MP5416_VSET_SW3, |
| 148 | BIT(7) | MP5416_VSET_SW3_SVAL(920000)); |
Tim Harvey | 08ac93c | 2023-06-09 09:54:51 -0700 | [diff] [blame] | 149 | #elif CONFIG_IMX8MP |
| 150 | puts("PMIC : MP5416 (IMX8MP)\n"); |
| 151 | |
| 152 | /* set VDD_ARM SW3 to 0.95V for 1.6GHz */ |
| 153 | dm_i2c_reg_write(dev, MP5416_VSET_SW3, |
| 154 | BIT(7) | MP5416_VSET_SW3_SVAL(950000)); |
| 155 | /* set VDD_SOC SW1 to 0.95V for 1.6GHz */ |
| 156 | dm_i2c_reg_write(dev, MP5416_VSET_SW1, |
| 157 | BIT(7) | MP5416_VSET_SW1_SVAL(950000)); |
| 158 | #endif |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 161 | else if (!strncmp(model, "GW74", 4)) { |
Tim Harvey | ffe9e3c | 2023-08-15 15:01:15 -0700 | [diff] [blame] | 162 | ret = uclass_get_device_by_seq(UCLASS_I2C, 2, &bus); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 163 | if (ret) { |
Tim Harvey | ffe9e3c | 2023-08-15 15:01:15 -0700 | [diff] [blame] | 164 | printf("PMIC : failed I2C3 probe: %d\n", ret); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 165 | return ret; |
| 166 | } |
| 167 | ret = dm_i2c_probe(bus, 0x25, 0, &dev); |
| 168 | if (ret) { |
| 169 | printf("PMIC : failed probe: %d\n", ret); |
| 170 | return ret; |
| 171 | } |
| 172 | puts("PMIC : PCA9450\n"); |
| 173 | |
| 174 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
| 175 | dm_i2c_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
| 176 | |
| 177 | /* Buck 1 DVS control through PMIC_STBY_REQ */ |
| 178 | dm_i2c_reg_write(dev, PCA9450_BUCK1CTRL, 0x59); |
| 179 | |
Tim Harvey | 4897fc2 | 2022-09-08 14:41:09 -0700 | [diff] [blame] | 180 | /* Set DVS1 to 0.85v for suspend */ |
| 181 | dm_i2c_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 182 | |
Tim Harvey | 4897fc2 | 2022-09-08 14:41:09 -0700 | [diff] [blame] | 183 | /* increase VDD_SOC to 0.95V before first DRAM access */ |
| 184 | dm_i2c_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 185 | |
Tim Harvey | 4897fc2 | 2022-09-08 14:41:09 -0700 | [diff] [blame] | 186 | /* Kernel uses OD/OD freq for SOC */ |
| 187 | /* To avoid timing risk from SOC to ARM, increase VDD_ARM to OD voltage 0.95v */ |
| 188 | dm_i2c_reg_write(dev, PCA9450_BUCK2OUT_DVS0, 0x1C); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Tim Harvey | 6603b5e | 2021-07-27 15:19:41 -0700 | [diff] [blame] | 191 | else if ((!strncmp(model, "GW7901", 6)) || |
Tim Harvey | 83ffc47 | 2022-08-11 11:57:04 -0700 | [diff] [blame] | 192 | (!strncmp(model, "GW7902", 6)) || |
Tim Harvey | b453157 | 2022-09-14 09:02:19 -0700 | [diff] [blame] | 193 | (!strncmp(model, "GW7903", 6)) || |
| 194 | (!strncmp(model, "GW7904", 6))) { |
Tim Harvey | 83ffc47 | 2022-08-11 11:57:04 -0700 | [diff] [blame] | 195 | if (!strncmp(model, "GW7902", 6)) |
Tim Harvey | 6603b5e | 2021-07-27 15:19:41 -0700 | [diff] [blame] | 196 | ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus); |
Tim Harvey | 83ffc47 | 2022-08-11 11:57:04 -0700 | [diff] [blame] | 197 | else |
| 198 | ret = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus); |
Tim Harvey | 1b7fbf6 | 2021-06-30 16:50:02 -0700 | [diff] [blame] | 199 | if (ret) { |
| 200 | printf("PMIC : failed I2C2 probe: %d\n", ret); |
| 201 | return ret; |
| 202 | } |
| 203 | ret = dm_i2c_probe(bus, 0x4b, 0, &dev); |
| 204 | if (ret) { |
| 205 | printf("PMIC : failed probe: %d\n", ret); |
| 206 | return ret; |
| 207 | } |
| 208 | puts("PMIC : BD71847\n"); |
| 209 | |
| 210 | /* unlock the PMIC regs */ |
| 211 | dm_i2c_reg_write(dev, BD718XX_REGLOCK, 0x1); |
| 212 | |
| 213 | /* set switchers to forced PWM mode */ |
| 214 | dm_i2c_clrsetbits(dev, BD718XX_BUCK1_CTRL, 0, 0x8); |
| 215 | dm_i2c_clrsetbits(dev, BD718XX_BUCK2_CTRL, 0, 0x8); |
| 216 | dm_i2c_clrsetbits(dev, BD718XX_1ST_NODVS_BUCK_CTRL, 0, 0x8); |
| 217 | dm_i2c_clrsetbits(dev, BD718XX_2ND_NODVS_BUCK_CTRL, 0, 0x8); |
| 218 | dm_i2c_clrsetbits(dev, BD718XX_3RD_NODVS_BUCK_CTRL, 0, 0x8); |
| 219 | dm_i2c_clrsetbits(dev, BD718XX_4TH_NODVS_BUCK_CTRL, 0, 0x8); |
| 220 | |
| 221 | /* increase VDD_0P95 (VDD_GPU/VPU/DRAM) to 0.975v for 1.5Ghz DDR */ |
| 222 | dm_i2c_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83); |
| 223 | |
| 224 | /* increase VDD_SOC to 0.85v before first DRAM access */ |
| 225 | dm_i2c_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f); |
| 226 | |
| 227 | /* increase VDD_ARM to 0.92v for 800 and 1600Mhz */ |
| 228 | dm_i2c_reg_write(dev, BD718XX_BUCK2_VOLT_RUN, 0x16); |
| 229 | |
| 230 | /* Lock the PMIC regs */ |
| 231 | dm_i2c_reg_write(dev, BD718XX_REGLOCK, 0x11); |
| 232 | } |
| 233 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | void board_init_f(ulong dummy) |
| 238 | { |
Tim Harvey | 2ccf28d | 2022-11-11 08:03:07 -0800 | [diff] [blame] | 239 | struct udevice *bus, *dev; |
| 240 | int i, ret; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 241 | int dram_sz; |
| 242 | |
| 243 | arch_cpu_init(); |
| 244 | |
| 245 | init_uart_clk(1); |
| 246 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 247 | timer_init(); |
| 248 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 249 | /* Clear the BSS. */ |
| 250 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 251 | |
| 252 | ret = spl_early_init(); |
| 253 | if (ret) { |
| 254 | debug("spl_early_init() failed: %d\n", ret); |
| 255 | hang(); |
| 256 | } |
| 257 | |
Tim Harvey | 91db793 | 2022-04-29 12:36:25 -0700 | [diff] [blame] | 258 | preloader_console_init(); |
| 259 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 260 | enable_tzc380(); |
| 261 | |
| 262 | /* need to hold PCIe switch in reset otherwise it can lock i2c bus EEPROM is on */ |
| 263 | gpio_request(PCIE_RSTN, "perst#"); |
| 264 | gpio_direction_output(PCIE_RSTN, 0); |
| 265 | |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 266 | /* |
| 267 | * probe GSC device |
| 268 | * |
| 269 | * On a board with a missing/depleted backup battery for GSC, the |
| 270 | * board may be ready to probe the GSC before its firmware is |
Tim Harvey | 2ccf28d | 2022-11-11 08:03:07 -0800 | [diff] [blame] | 271 | * running. Wait here for 50ms for the GSC firmware to let go of |
| 272 | * the SCL/SDA lines to avoid the i2c driver spamming |
| 273 | * 'Arbitration lost' I2C errors |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 274 | */ |
Tim Harvey | 2ccf28d | 2022-11-11 08:03:07 -0800 | [diff] [blame] | 275 | if (!uclass_get_device_by_seq(UCLASS_I2C, 0, &bus)) { |
| 276 | if (!pinctrl_select_state(bus, "gpio")) { |
| 277 | struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus); |
| 278 | struct gpio_desc *scl_gpio = &i2c_bus->scl_gpio; |
| 279 | struct gpio_desc *sda_gpio = &i2c_bus->sda_gpio; |
| 280 | |
| 281 | dm_gpio_set_dir_flags(scl_gpio, GPIOD_IS_IN); |
| 282 | dm_gpio_set_dir_flags(sda_gpio, GPIOD_IS_IN); |
| 283 | for (i = 0; i < 5; i++) { |
| 284 | if (dm_gpio_get_value(scl_gpio) && |
| 285 | dm_gpio_get_value(sda_gpio)) |
| 286 | break; |
| 287 | mdelay(10); |
| 288 | } |
| 289 | pinctrl_select_state(bus, "default"); |
| 290 | } |
| 291 | } |
| 292 | /* Wait indefiniately until the GSC probes */ |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 293 | while (1) { |
| 294 | if (!uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(gsc), &dev)) |
| 295 | break; |
| 296 | mdelay(1); |
| 297 | } |
Tim Harvey | 1fec182 | 2022-08-11 12:04:01 -0700 | [diff] [blame] | 298 | dram_sz = venice_eeprom_init(0); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 299 | |
| 300 | /* PMIC */ |
| 301 | power_init_board(); |
| 302 | |
| 303 | /* DDR initialization */ |
| 304 | spl_dram_init(dram_sz); |
| 305 | |
| 306 | board_init_r(NULL, 0); |
| 307 | } |
| 308 | |
| 309 | /* determine prioritized order of boot devices to load U-Boot from */ |
| 310 | void board_boot_order(u32 *spl_boot_list) |
| 311 | { |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 312 | int i = 0; |
| 313 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 314 | /* |
| 315 | * If the SPL was loaded via serial loader, we try to get |
| 316 | * U-Boot proper via USB SDP. |
| 317 | */ |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 318 | if (spl_boot_device() == BOOT_DEVICE_BOARD) { |
| 319 | #ifdef CONFIG_IMX8MM |
| 320 | spl_boot_list[i++] = BOOT_DEVICE_BOARD; |
| 321 | #else |
| 322 | spl_boot_list[i++] = BOOT_DEVICE_BOOTROM; |
| 323 | #endif |
| 324 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 325 | |
| 326 | /* we have only eMMC in default venice dt */ |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 327 | spl_boot_list[i++] = BOOT_DEVICE_MMC1; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /* return boot device based on where the SPL was loaded from */ |
| 331 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 332 | { |
| 333 | switch (boot_dev_spl) { |
| 334 | case USB_BOOT: |
| 335 | return BOOT_DEVICE_BOARD; |
| 336 | /* SDHC2 */ |
| 337 | case SD2_BOOT: |
| 338 | case MMC2_BOOT: |
| 339 | return BOOT_DEVICE_MMC1; |
| 340 | /* SDHC3 */ |
| 341 | case SD3_BOOT: |
| 342 | case MMC3_BOOT: |
| 343 | return BOOT_DEVICE_MMC2; |
| 344 | default: |
| 345 | return BOOT_DEVICE_NONE; |
| 346 | } |
| 347 | } |
Tim Harvey | 724d10a | 2022-03-08 10:45:39 -0800 | [diff] [blame] | 348 | |
Marek Vasut | f9a921e | 2023-10-16 18:16:12 +0200 | [diff] [blame] | 349 | unsigned long board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc, unsigned long raw_sect) |
Tim Harvey | a42793c | 2023-05-02 17:05:53 -0700 | [diff] [blame] | 350 | { |
| 351 | if (!IS_SD(mmc)) { |
| 352 | switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) { |
| 353 | case 1: |
| 354 | case 2: |
| 355 | if (IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP)) |
| 356 | raw_sect -= 32 * 2; |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return raw_sect; |
| 362 | } |
| 363 | |
Tim Harvey | 724d10a | 2022-03-08 10:45:39 -0800 | [diff] [blame] | 364 | const char *spl_board_loader_name(u32 boot_device) |
| 365 | { |
| 366 | switch (boot_device) { |
| 367 | /* SDHC2 */ |
| 368 | case BOOT_DEVICE_MMC1: |
| 369 | return "eMMC"; |
| 370 | /* SDHC3 */ |
| 371 | case BOOT_DEVICE_MMC2: |
| 372 | return "SD card"; |
| 373 | default: |
| 374 | return NULL; |
| 375 | } |
| 376 | } |
Tim Harvey | 7ba1e9d | 2023-06-23 09:44:59 -0700 | [diff] [blame] | 377 | |
| 378 | void spl_board_init(void) |
| 379 | { |
| 380 | arch_misc_init(); |
| 381 | } |