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> |
| 22 | |
| 23 | #include <dm/uclass.h> |
| 24 | #include <dm/device.h> |
| 25 | #include <dm/uclass-internal.h> |
| 26 | #include <dm/device-internal.h> |
| 27 | |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 28 | #include <power/pmic.h> |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 29 | #include <power/pca9450.h> |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 30 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 34 | { |
| 35 | switch (boot_dev_spl) { |
| 36 | case SD2_BOOT: |
| 37 | case MMC2_BOOT: |
| 38 | return BOOT_DEVICE_MMC1; |
| 39 | case SD3_BOOT: |
| 40 | case MMC3_BOOT: |
| 41 | return BOOT_DEVICE_MMC2; |
| 42 | default: |
| 43 | return BOOT_DEVICE_NONE; |
| 44 | } |
| 45 | } |
| 46 | |
Alifer Moraes | f0119b6 | 2020-01-14 15:55:00 -0300 | [diff] [blame] | 47 | static void spl_dram_init(void) |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 48 | { |
| 49 | ddr_init(&dram_timing); |
| 50 | } |
| 51 | |
| 52 | void spl_board_init(void) |
| 53 | { |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 54 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 55 | struct udevice *dev; |
| 56 | int ret; |
| 57 | |
| 58 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 59 | if (ret) |
| 60 | printf("Failed to initialize %s: %d\n", dev->name, ret); |
| 61 | } |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 62 | puts("Normal Boot\n"); |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | #ifdef CONFIG_SPL_LOAD_FIT |
| 66 | int board_fit_config_name_match(const char *name) |
| 67 | { |
| 68 | /* Just empty function now - can't decide what to choose */ |
| 69 | debug("%s: %s\n", __func__, name); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1) |
| 76 | #define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_ODE | PAD_CTL_PUE | PAD_CTL_PE) |
| 77 | |
| 78 | static iomux_v3_cfg_t const uart_pads[] = { |
| 79 | IMX8MM_PAD_UART2_RXD_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 80 | IMX8MM_PAD_UART2_TXD_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 81 | }; |
| 82 | |
| 83 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 84 | IMX8MM_PAD_GPIO1_IO02_WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL), |
| 85 | }; |
| 86 | |
| 87 | int board_early_init_f(void) |
| 88 | { |
| 89 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
| 90 | |
| 91 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 92 | |
| 93 | set_wdog_reset(wdog); |
| 94 | |
| 95 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Alifer Moraes | f0119b6 | 2020-01-14 15:55:00 -0300 | [diff] [blame] | 100 | static int power_init_board(void) |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 101 | { |
| 102 | struct udevice *dev; |
| 103 | int ret; |
| 104 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 105 | ret = pmic_get("pca9450@25", &dev); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 106 | if (ret == -ENODEV) { |
| 107 | puts("No pmic\n"); |
| 108 | return 0; |
| 109 | } |
| 110 | if (ret != 0) |
| 111 | return ret; |
| 112 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 113 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
| 114 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 115 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 116 | /* Buck 1 DVS control through PMIC_STBY_REQ */ |
| 117 | pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 118 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 119 | /* Set DVS1 to 0.8v for suspend */ |
| 120 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x10); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 121 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 122 | /* increase VDD_DRAM to 0.95v for 3Ghz DDR */ |
| 123 | pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1C); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 124 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 125 | /* VDD_DRAM needs off in suspend, set B1_ENMODE=10 (ON by PMIC_ON_REQ = H && PMIC_STBY_REQ = L) */ |
| 126 | pmic_reg_write(dev, PCA9450_BUCK3CTRL, 0x4a); |
| 127 | |
| 128 | /* set VDD_SNVS_0V8 from default 0.85V */ |
| 129 | pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 130 | |
Ye Li | 79e6970 | 2021-03-19 15:56:55 +0800 | [diff] [blame] | 131 | /* set WDOG_B_CFG to cold reset */ |
| 132 | pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1); |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 137 | void board_init_f(ulong dummy) |
| 138 | { |
Peng Fan | b9b7688 | 2019-10-16 10:24:39 +0000 | [diff] [blame] | 139 | struct udevice *dev; |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 140 | int ret; |
| 141 | |
| 142 | arch_cpu_init(); |
| 143 | |
| 144 | init_uart_clk(1); |
| 145 | |
| 146 | board_early_init_f(); |
| 147 | |
| 148 | timer_init(); |
| 149 | |
| 150 | preloader_console_init(); |
| 151 | |
| 152 | /* Clear the BSS. */ |
| 153 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 154 | |
Peng Fan | b9b7688 | 2019-10-16 10:24:39 +0000 | [diff] [blame] | 155 | ret = spl_early_init(); |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 156 | if (ret) { |
Peng Fan | b9b7688 | 2019-10-16 10:24:39 +0000 | [diff] [blame] | 157 | debug("spl_early_init() failed: %d\n", ret); |
| 158 | hang(); |
| 159 | } |
| 160 | |
| 161 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 162 | "clock-controller@30380000", |
| 163 | &dev); |
| 164 | if (ret < 0) { |
| 165 | printf("Failed to find clock node. Check device tree\n"); |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 166 | hang(); |
| 167 | } |
| 168 | |
| 169 | enable_tzc380(); |
| 170 | |
Peng Fan | a9e0433 | 2019-10-16 10:24:42 +0000 | [diff] [blame] | 171 | power_init_board(); |
| 172 | |
Peng Fan | f922017 | 2019-08-27 06:26:08 +0000 | [diff] [blame] | 173 | /* DDR initialization */ |
| 174 | spl_dram_init(); |
| 175 | |
| 176 | board_init_r(NULL, 0); |
| 177 | } |