Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright 2022 Toradex |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <hang.h> |
| 8 | #include <init.h> |
| 9 | #include <log.h> |
| 10 | #include <spl.h> |
| 11 | #include <asm/global_data.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/imx8mp_pins.h> |
| 14 | #include <asm/arch/sys_proto.h> |
| 15 | #include <asm/mach-imx/boot_mode.h> |
| 16 | #include <asm/mach-imx/gpio.h> |
| 17 | #include <asm/mach-imx/iomux-v3.h> |
| 18 | #include <asm/mach-imx/mxc_i2c.h> |
| 19 | #include <asm/arch/ddr.h> |
Andrejs Cainikovs | 50e9483 | 2022-10-04 13:06:31 +0200 | [diff] [blame] | 20 | #include <dm/device.h> |
| 21 | #include <dm/uclass.h> |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 22 | #include <power/pmic.h> |
| 23 | #include <power/pca9450.h> |
| 24 | |
| 25 | extern struct dram_timing_info dram_timing2; |
| 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
| 29 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 30 | { |
| 31 | return BOOT_DEVICE_BOOTROM; |
| 32 | } |
| 33 | |
| 34 | void spl_dram_init(void) |
| 35 | { |
| 36 | /* |
| 37 | * try configuring for quad die, dual rank aka 8 GB falling back to |
| 38 | * dual die, single rank aka 1 GB (untested), 2 GB or 4 GB if it fails |
| 39 | */ |
| 40 | if (ddr_init(&dram_timing)) { |
| 41 | printf("Quad die, dual rank failed, attempting dual die, single rank configuration.\n"); |
| 42 | ddr_init(&dram_timing2); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void spl_board_init(void) |
| 47 | { |
Andrejs Cainikovs | 50e9483 | 2022-10-04 13:06:31 +0200 | [diff] [blame] | 48 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 49 | struct udevice *dev; |
| 50 | int ret; |
| 51 | |
| 52 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 53 | if (ret) |
| 54 | printf("Failed to initialize caam_jr: %d\n", ret); |
| 55 | } |
| 56 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 57 | /* |
| 58 | * Set GIC clock to 500Mhz for OD VDD_SOC. Kernel driver does |
| 59 | * not allow to change it. Should set the clock after PMIC |
| 60 | * setting done. Default is 400Mhz (system_pll1_800m with div = 2) |
| 61 | * set by ROM for ND VDD_SOC |
| 62 | */ |
| 63 | clock_enable(CCGR_GIC, 0); |
| 64 | clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5)); |
| 65 | clock_enable(CCGR_GIC, 1); |
| 66 | |
| 67 | puts("Normal Boot\n"); |
| 68 | } |
| 69 | |
| 70 | #define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE) |
| 71 | #define PC MUX_PAD_CTRL(I2C_PAD_CTRL) |
| 72 | struct i2c_pads_info i2c_pad_info1 = { |
| 73 | .scl = { |
| 74 | .i2c_mode = MX8MP_PAD_I2C1_SCL__I2C1_SCL | PC, |
| 75 | .gpio_mode = MX8MP_PAD_I2C1_SCL__GPIO5_IO14 | PC, |
| 76 | .gp = IMX_GPIO_NR(5, 14), |
| 77 | }, |
| 78 | .sda = { |
| 79 | .i2c_mode = MX8MP_PAD_I2C1_SDA__I2C1_SDA | PC, |
| 80 | .gpio_mode = MX8MP_PAD_I2C1_SDA__GPIO5_IO15 | PC, |
| 81 | .gp = IMX_GPIO_NR(5, 15), |
| 82 | }, |
| 83 | }; |
| 84 | |
| 85 | #if CONFIG_IS_ENABLED(POWER_LEGACY) |
| 86 | #define I2C_PMIC 0 |
| 87 | int power_init_board(void) |
| 88 | { |
| 89 | struct pmic *p; |
| 90 | int ret; |
| 91 | |
| 92 | ret = power_pca9450_init(I2C_PMIC, 0x25); |
| 93 | if (ret) |
| 94 | printf("power init failed\n"); |
| 95 | p = pmic_get("PCA9450"); |
| 96 | pmic_probe(p); |
| 97 | |
| 98 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
| 99 | pmic_reg_write(p, PCA9450_BUCK123_DVS, 0x29); |
| 100 | |
| 101 | /* |
| 102 | * increase VDD_SOC to typical value 0.95V before first |
| 103 | * DRAM access, set DVS1 to 0.85v for suspend. |
| 104 | * Enable DVS control through PMIC_STBY_REQ and |
| 105 | * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H) |
| 106 | */ |
| 107 | if (IS_ENABLED(CONFIG_IMX8M_VDD_SOC_850MV)) |
| 108 | /* set DVS0 to 0.85v for special case */ |
| 109 | pmic_reg_write(p, PCA9450_BUCK1OUT_DVS0, 0x14); |
| 110 | else |
| 111 | pmic_reg_write(p, PCA9450_BUCK1OUT_DVS0, 0x1c); |
| 112 | pmic_reg_write(p, PCA9450_BUCK1OUT_DVS1, 0x14); |
| 113 | pmic_reg_write(p, PCA9450_BUCK1CTRL, 0x59); |
| 114 | |
| 115 | /* Kernel uses OD/OD freq for SoC */ |
| 116 | /* To avoid timing risk from SoC to ARM, increase VDD_ARM to OD voltage 0.95v */ |
| 117 | pmic_reg_write(p, PCA9450_BUCK2OUT_DVS0, 0x1c); |
| 118 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 119 | /* set LDO4 and CONFIG2 to enable the I2C level translator */ |
| 120 | pmic_reg_write(p, PCA9450_LDO4CTRL, 0x59); |
| 121 | pmic_reg_write(p, PCA9450_CONFIG2, 0x1); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | #if IS_ENABLED(CONFIG_SPL_LOAD_FIT) |
| 128 | int board_fit_config_name_match(const char *name) |
| 129 | { |
| 130 | /* Just empty function now - can't decide what to choose */ |
| 131 | debug("%s: %s\n", __func__, name); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | #endif |
| 136 | |
| 137 | /* Do not use BSS area in this phase */ |
| 138 | void board_init_f(ulong dummy) |
| 139 | { |
| 140 | int ret; |
| 141 | |
| 142 | arch_cpu_init(); |
| 143 | |
| 144 | init_uart_clk(1); |
| 145 | |
| 146 | board_early_init_f(); |
| 147 | |
| 148 | ret = spl_early_init(); |
| 149 | if (ret) { |
| 150 | debug("spl_init() failed: %d\n", ret); |
| 151 | hang(); |
| 152 | } |
| 153 | |
| 154 | preloader_console_init(); |
| 155 | |
| 156 | enable_tzc380(); |
| 157 | |
| 158 | /* Adjust PMIC voltage to 1.0V for 800 MHz */ |
| 159 | setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1); |
| 160 | |
| 161 | /* PMIC initialization */ |
| 162 | power_init_board(); |
| 163 | |
| 164 | /* DDR initialization */ |
| 165 | spl_dram_init(); |
| 166 | } |