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