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