Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 3 | #include <cpu_func.h> |
| 4 | #include <hang.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 5 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 6 | #include <log.h> |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 7 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/mach-imx/iomux-v3.h> |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/imx8mm_pins.h> |
| 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/mach-imx/boot_mode.h> |
| 15 | #include <asm/arch/ddr.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 16 | #include <asm/sections.h> |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 17 | |
| 18 | #include <dm/uclass.h> |
| 19 | #include <dm/device.h> |
| 20 | #include <dm/uclass-internal.h> |
| 21 | #include <dm/device-internal.h> |
| 22 | |
| 23 | #include <power/pmic.h> |
| 24 | #include <power/bd71837.h> |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 29 | { |
| 30 | switch (boot_dev_spl) { |
| 31 | case SD2_BOOT: |
| 32 | case MMC2_BOOT: |
| 33 | return BOOT_DEVICE_MMC1; |
| 34 | case SD3_BOOT: |
| 35 | case MMC3_BOOT: |
| 36 | return BOOT_DEVICE_MMC2; |
Adam Ford | 2cc246a | 2022-10-22 09:28:23 -0500 | [diff] [blame] | 37 | case USB_BOOT: |
| 38 | return BOOT_DEVICE_BOARD; |
Adam Ford | 25f43c6 | 2023-02-01 19:58:41 -0600 | [diff] [blame] | 39 | case QSPI_BOOT: |
| 40 | return BOOT_DEVICE_NOR; |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 41 | default: |
| 42 | return BOOT_DEVICE_NONE; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | static void spl_dram_init(void) |
| 47 | { |
| 48 | ddr_init(&dram_timing); |
| 49 | } |
| 50 | |
Adam Ford | 25f43c6 | 2023-02-01 19:58:41 -0600 | [diff] [blame] | 51 | void spl_board_init(void) |
| 52 | { |
| 53 | arch_misc_init(); |
| 54 | } |
| 55 | |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_LOAD_FIT |
| 57 | int board_fit_config_name_match(const char *name) |
| 58 | { |
| 59 | /* Just empty function now - can't decide what to choose */ |
| 60 | debug("%s: %s\n", __func__, name); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | #endif |
| 65 | |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 66 | static int power_init_board(void) |
| 67 | { |
| 68 | struct udevice *dev; |
| 69 | int ret; |
| 70 | |
| 71 | ret = pmic_get("pmic@4b", &dev); |
| 72 | if (ret == -ENODEV) { |
| 73 | puts("No pmic\n"); |
| 74 | return 0; |
| 75 | } |
| 76 | if (ret != 0) |
| 77 | return ret; |
| 78 | |
| 79 | /* decrease RESET key long push time from the default 10s to 10ms */ |
| 80 | pmic_reg_write(dev, BD718XX_PWRONCONFIG1, 0x0); |
| 81 | |
| 82 | /* unlock the PMIC regs */ |
| 83 | pmic_reg_write(dev, BD718XX_REGLOCK, 0x1); |
| 84 | |
| 85 | /* increase VDD_SOC to typical value 0.85v before first DRAM access */ |
| 86 | pmic_reg_write(dev, BD718XX_BUCK1_VOLT_RUN, 0x0f); |
| 87 | |
| 88 | /* increase VDD_DRAM to 0.975v for 3Ghz DDR */ |
| 89 | pmic_reg_write(dev, BD718XX_1ST_NODVS_BUCK_VOLT, 0x83); |
| 90 | |
| 91 | /* lock the PMIC regs */ |
| 92 | pmic_reg_write(dev, BD718XX_REGLOCK, 0x11); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | void board_init_f(ulong dummy) |
| 98 | { |
| 99 | struct udevice *dev; |
| 100 | int ret; |
| 101 | |
| 102 | arch_cpu_init(); |
| 103 | |
| 104 | init_uart_clk(1); |
| 105 | |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 106 | timer_init(); |
| 107 | |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 108 | /* Clear the BSS. */ |
| 109 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 110 | |
| 111 | ret = spl_early_init(); |
| 112 | if (ret) { |
| 113 | debug("spl_early_init() failed: %d\n", ret); |
| 114 | hang(); |
| 115 | } |
| 116 | |
Peng Fan | a9ed59c | 2022-06-11 20:20:55 +0800 | [diff] [blame] | 117 | preloader_console_init(); |
| 118 | |
Adam Ford | 1487903 | 2020-05-03 08:11:33 -0500 | [diff] [blame] | 119 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 120 | "clock-controller@30380000", |
| 121 | &dev); |
| 122 | if (ret < 0) { |
| 123 | printf("Failed to find clock node. Check device tree\n"); |
| 124 | hang(); |
| 125 | } |
| 126 | |
| 127 | enable_tzc380(); |
| 128 | |
| 129 | power_init_board(); |
| 130 | |
| 131 | /* DDR initialization */ |
| 132 | spl_dram_init(); |
| 133 | |
| 134 | board_init_r(NULL, 0); |
| 135 | } |