Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 2 | /* |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 3 | * Copyright 2018-2019, 2021 NXP |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 4 | * |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 11 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Peng Fan | a2608a1 | 2021-03-19 15:57:03 +0800 | [diff] [blame] | 13 | #include <asm/arch/clock.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 14 | #include <asm/arch/imx8mp_pins.h> |
| 15 | #include <asm/arch/sys_proto.h> |
| 16 | #include <asm/mach-imx/boot_mode.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 17 | #include <asm/mach-imx/gpio.h> |
Peng Fan | a2608a1 | 2021-03-19 15:57:03 +0800 | [diff] [blame] | 18 | #include <asm/mach-imx/iomux-v3.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 19 | #include <asm/mach-imx/mxc_i2c.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 20 | #include <asm/arch/ddr.h> |
Peng Fan | a2608a1 | 2021-03-19 15:57:03 +0800 | [diff] [blame] | 21 | #include <power/pmic.h> |
| 22 | #include <power/pca9450.h> |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 23 | #include <dm/uclass.h> |
| 24 | #include <dm/device.h> |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 25 | |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 29 | { |
| 30 | return BOOT_DEVICE_BOOTROM; |
| 31 | } |
| 32 | |
| 33 | void spl_dram_init(void) |
| 34 | { |
| 35 | ddr_init(&dram_timing); |
| 36 | } |
| 37 | |
| 38 | void spl_board_init(void) |
| 39 | { |
Marek Vasut | 085555f | 2022-09-19 21:41:15 +0200 | [diff] [blame] | 40 | arch_misc_init(); |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 41 | |
Peng Fan | cc08e7e | 2021-03-19 15:57:04 +0800 | [diff] [blame] | 42 | /* |
| 43 | * Set GIC clock to 500Mhz for OD VDD_SOC. Kernel driver does |
| 44 | * not allow to change it. Should set the clock after PMIC |
| 45 | * setting done. Default is 400Mhz (system_pll1_800m with div = 2) |
| 46 | * set by ROM for ND VDD_SOC |
| 47 | */ |
| 48 | clock_enable(CCGR_GIC, 0); |
| 49 | clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5)); |
| 50 | clock_enable(CCGR_GIC, 1); |
| 51 | |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 52 | puts("Normal Boot\n"); |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE) |
| 56 | #define PC MUX_PAD_CTRL(I2C_PAD_CTRL) |
| 57 | struct i2c_pads_info i2c_pad_info1 = { |
| 58 | .scl = { |
| 59 | .i2c_mode = MX8MP_PAD_I2C1_SCL__I2C1_SCL | PC, |
| 60 | .gpio_mode = MX8MP_PAD_I2C1_SCL__GPIO5_IO14 | PC, |
| 61 | .gp = IMX_GPIO_NR(5, 14), |
| 62 | }, |
| 63 | .sda = { |
| 64 | .i2c_mode = MX8MP_PAD_I2C1_SDA__I2C1_SDA | PC, |
| 65 | .gpio_mode = MX8MP_PAD_I2C1_SDA__GPIO5_IO15 | PC, |
| 66 | .gp = IMX_GPIO_NR(5, 15), |
| 67 | }, |
| 68 | }; |
| 69 | |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 70 | #if CONFIG_IS_ENABLED(DM_PMIC_PCA9450) |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 71 | int power_init_board(void) |
| 72 | { |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 73 | struct udevice *dev; |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 74 | int ret; |
| 75 | |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 76 | ret = pmic_get("pmic@25", &dev); |
| 77 | if (ret == -ENODEV) { |
| 78 | puts("No pmic@25\n"); |
| 79 | return 0; |
| 80 | } |
| 81 | if (ret < 0) |
| 82 | return ret; |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 83 | |
| 84 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 85 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 86 | |
| 87 | /* |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 88 | * Increase VDD_SOC to typical value 0.95V before first |
| 89 | * DRAM access, set DVS1 to 0.85V for suspend. |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 90 | * Enable DVS control through PMIC_STBY_REQ and |
| 91 | * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H) |
| 92 | */ |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 93 | if (CONFIG_IS_ENABLED(IMX8M_VDD_SOC_850MV)) |
| 94 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x14); |
| 95 | else |
| 96 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C); |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 97 | |
Fabio Estevam | 4671ab4 | 2023-10-18 16:17:41 -0300 | [diff] [blame^] | 98 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14); |
| 99 | pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59); |
| 100 | |
| 101 | /* |
| 102 | * Kernel uses OD/OD freq for SOC. |
| 103 | * To avoid timing risk from SOC to ARM,increase VDD_ARM to OD |
| 104 | * voltage 0.95V. |
| 105 | */ |
| 106 | |
| 107 | pmic_reg_write(dev, PCA9450_BUCK2OUT_DVS0, 0x1C); |
Peng Fan | cc08e7e | 2021-03-19 15:57:04 +0800 | [diff] [blame] | 108 | |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | #endif |
| 112 | |
| 113 | #ifdef CONFIG_SPL_LOAD_FIT |
| 114 | int board_fit_config_name_match(const char *name) |
| 115 | { |
| 116 | /* Just empty function now - can't decide what to choose */ |
| 117 | debug("%s: %s\n", __func__, name); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | #endif |
| 122 | |
Peng Fan | a50c0a3 | 2020-05-26 20:33:49 -0300 | [diff] [blame] | 123 | /* Do not use BSS area in this phase */ |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 124 | void board_init_f(ulong dummy) |
| 125 | { |
| 126 | int ret; |
| 127 | |
| 128 | arch_cpu_init(); |
| 129 | |
| 130 | init_uart_clk(1); |
| 131 | |
Peng Fan | 5d93e1c | 2020-05-26 20:33:48 -0300 | [diff] [blame] | 132 | ret = spl_early_init(); |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 133 | if (ret) { |
| 134 | debug("spl_init() failed: %d\n", ret); |
| 135 | hang(); |
| 136 | } |
| 137 | |
Peng Fan | 5d93e1c | 2020-05-26 20:33:48 -0300 | [diff] [blame] | 138 | preloader_console_init(); |
| 139 | |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 140 | enable_tzc380(); |
| 141 | |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 142 | power_init_board(); |
| 143 | |
| 144 | /* DDR initialization */ |
| 145 | spl_dram_init(); |
Peng Fan | c47e09d | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 146 | } |