Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 3 | * Copyright 2019, 2021 NXP |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 9 | #include <hang.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 10 | #include <image.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/mach-imx/iomux-v3.h> |
| 17 | #include <asm/arch/clock.h> |
| 18 | #include <asm/arch/imx8mm_pins.h> |
| 19 | #include <asm/arch/sys_proto.h> |
| 20 | #include <asm/mach-imx/boot_mode.h> |
| 21 | #include <asm/arch/ddr.h> |
Shiji Yang | bb11234 | 2023-08-03 09:47:16 +0800 | [diff] [blame] | 22 | #include <asm/sections.h> |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 23 | |
| 24 | #include <dm/uclass.h> |
| 25 | #include <dm/device.h> |
| 26 | #include <dm/uclass-internal.h> |
| 27 | #include <dm/device-internal.h> |
| 28 | |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 29 | #include <power/pmic.h> |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 30 | #include <power/pca9450.h> |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 31 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 35 | { |
| 36 | switch (boot_dev_spl) { |
Fabio Estevam | e2b3a7b | 2022-09-19 21:20:13 -0300 | [diff] [blame] | 37 | case USB_BOOT: |
| 38 | return BOOT_DEVICE_BOARD; |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 39 | case SD2_BOOT: |
| 40 | case MMC2_BOOT: |
| 41 | return BOOT_DEVICE_MMC1; |
| 42 | case SD3_BOOT: |
| 43 | case MMC3_BOOT: |
| 44 | return BOOT_DEVICE_MMC2; |
Mamta Shukla | 3482429 | 2022-07-12 14:36:20 +0000 | [diff] [blame] | 45 | case QSPI_BOOT: |
| 46 | return BOOT_DEVICE_NOR; |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 47 | default: |
| 48 | return BOOT_DEVICE_NONE; |
| 49 | } |
| 50 | } |
| 51 | |
Alifer Moraes | f0119b6 | 2020-01-14 15:55:00 -0300 | [diff] [blame] | 52 | static void spl_dram_init(void) |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 53 | { |
| 54 | ddr_init(&dram_timing); |
| 55 | } |
| 56 | |
| 57 | void spl_board_init(void) |
| 58 | { |
Marek Vasut | 085555f | 2022-09-19 21:41:15 +0200 | [diff] [blame] | 59 | arch_misc_init(); |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | #ifdef CONFIG_SPL_LOAD_FIT |
| 63 | int board_fit_config_name_match(const char *name) |
| 64 | { |
| 65 | /* Just empty function now - can't decide what to choose */ |
| 66 | debug("%s: %s\n", __func__, name); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | #endif |
| 71 | |
Alifer Moraes | f0119b6 | 2020-01-14 15:55:00 -0300 | [diff] [blame] | 72 | static int power_init_board(void) |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 73 | { |
| 74 | struct udevice *dev; |
| 75 | int ret; |
| 76 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 77 | ret = pmic_get("pca9450@25", &dev); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 78 | if (ret == -ENODEV) { |
| 79 | puts("No pmic\n"); |
| 80 | return 0; |
| 81 | } |
| 82 | if (ret != 0) |
| 83 | return ret; |
| 84 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 85 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
| 86 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 87 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 88 | /* Buck 1 DVS control through PMIC_STBY_REQ */ |
| 89 | pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 90 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 91 | /* Set DVS1 to 0.8v for suspend */ |
| 92 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 93 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 94 | /* increase VDD_DRAM to 0.95v for 3Ghz DDR */ |
| 95 | pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 96 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 97 | /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */ |
| 98 | pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a); |
| 99 | |
| 100 | /* set VDD_SNVS_0V8 from default 0.85V */ |
| 101 | pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 102 | |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 106 | void board_init_f(ulong dummy) |
| 107 | { |
Peng Fan | b9b7688 | 2019-10-16 10:24:39 +0000 | [diff] [blame] | 108 | struct udevice *dev; |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 109 | int ret; |
| 110 | |
| 111 | arch_cpu_init(); |
| 112 | |
| 113 | init_uart_clk(1); |
| 114 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 115 | timer_init(); |
| 116 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 117 | /* Clear the BSS. */ |
| 118 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 119 | |
Peng Fan | b9b7688 | 2019-10-16 10:24:39 +0000 | [diff] [blame] | 120 | ret = spl_early_init(); |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 121 | if (ret) { |
Peng Fan | b9b7688 | 2019-10-16 10:24:39 +0000 | [diff] [blame] | 122 | debug("spl_early_init() failed: %d\n", ret); |
| 123 | hang(); |
| 124 | } |
| 125 | |
| 126 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 127 | "clock-controller@30380000", |
| 128 | &dev); |
| 129 | if (ret < 0) { |
| 130 | printf("Failed to find clock node. Check device tree\n"); |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 131 | hang(); |
| 132 | } |
| 133 | |
Peng Fan | 4ee5ade | 2022-04-15 12:35:34 +0800 | [diff] [blame] | 134 | preloader_console_init(); |
| 135 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 136 | enable_tzc380(); |
| 137 | |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 138 | power_init_board(); |
| 139 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 140 | /* DDR initialization */ |
| 141 | spl_dram_init(); |
| 142 | |
| 143 | board_init_r(NULL, 0); |
| 144 | } |