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