Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-2019 NXP |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | 9a3b4ce | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 10 | #include <hang.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame^] | 15 | #include <asm/global_data.h> |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <errno.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/mach-imx/iomux-v3.h> |
| 20 | #include <asm/arch/imx8mp_pins.h> |
| 21 | #include <asm/arch/sys_proto.h> |
| 22 | #include <asm/mach-imx/boot_mode.h> |
| 23 | #include <power/pmic.h> |
| 24 | |
| 25 | #include <power/pca9450.h> |
| 26 | #include <asm/arch/clock.h> |
| 27 | #include <asm/mach-imx/gpio.h> |
| 28 | #include <asm/mach-imx/mxc_i2c.h> |
| 29 | #include <fsl_esdhc.h> |
| 30 | #include <mmc.h> |
| 31 | #include <asm/arch/ddr.h> |
| 32 | |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 36 | { |
| 37 | return BOOT_DEVICE_BOOTROM; |
| 38 | } |
| 39 | |
| 40 | void spl_dram_init(void) |
| 41 | { |
| 42 | ddr_init(&dram_timing); |
| 43 | } |
| 44 | |
| 45 | void spl_board_init(void) |
| 46 | { |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 47 | puts("Normal Boot\n"); |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | #define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE) |
| 51 | #define PC MUX_PAD_CTRL(I2C_PAD_CTRL) |
| 52 | struct i2c_pads_info i2c_pad_info1 = { |
| 53 | .scl = { |
| 54 | .i2c_mode = MX8MP_PAD_I2C1_SCL__I2C1_SCL | PC, |
| 55 | .gpio_mode = MX8MP_PAD_I2C1_SCL__GPIO5_IO14 | PC, |
| 56 | .gp = IMX_GPIO_NR(5, 14), |
| 57 | }, |
| 58 | .sda = { |
| 59 | .i2c_mode = MX8MP_PAD_I2C1_SDA__I2C1_SDA | PC, |
| 60 | .gpio_mode = MX8MP_PAD_I2C1_SDA__GPIO5_IO15 | PC, |
| 61 | .gp = IMX_GPIO_NR(5, 15), |
| 62 | }, |
| 63 | }; |
| 64 | |
| 65 | #ifdef CONFIG_POWER |
| 66 | #define I2C_PMIC 0 |
| 67 | int power_init_board(void) |
| 68 | { |
| 69 | struct pmic *p; |
| 70 | int ret; |
| 71 | |
Sébastien Szymanski | eefd93e | 2020-06-30 15:03:13 +0200 | [diff] [blame] | 72 | ret = power_pca9450_init(I2C_PMIC); |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 73 | if (ret) |
| 74 | printf("power init failed"); |
| 75 | p = pmic_get("PCA9450"); |
| 76 | pmic_probe(p); |
| 77 | |
| 78 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
| 79 | pmic_reg_write(p, PCA9450_BUCK123_DVS, 0x29); |
| 80 | |
| 81 | /* |
| 82 | * increase VDD_SOC to typical value 0.95V before first |
| 83 | * DRAM access, set DVS1 to 0.85v for suspend. |
| 84 | * Enable DVS control through PMIC_STBY_REQ and |
| 85 | * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H) |
| 86 | */ |
| 87 | pmic_reg_write(p, PCA9450_BUCK1OUT_DVS0, 0x1C); |
| 88 | pmic_reg_write(p, PCA9450_BUCK1OUT_DVS1, 0x14); |
| 89 | pmic_reg_write(p, PCA9450_BUCK1CTRL, 0x59); |
| 90 | |
| 91 | /* set WDOG_B_CFG to cold reset */ |
| 92 | pmic_reg_write(p, PCA9450_RESET_CTRL, 0xA1); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | #ifdef CONFIG_SPL_LOAD_FIT |
| 99 | int board_fit_config_name_match(const char *name) |
| 100 | { |
| 101 | /* Just empty function now - can't decide what to choose */ |
| 102 | debug("%s: %s\n", __func__, name); |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | #endif |
| 107 | |
Peng Fan | 0ec9d5b | 2020-05-26 20:33:49 -0300 | [diff] [blame] | 108 | /* Do not use BSS area in this phase */ |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 109 | void board_init_f(ulong dummy) |
| 110 | { |
| 111 | int ret; |
| 112 | |
| 113 | arch_cpu_init(); |
| 114 | |
| 115 | init_uart_clk(1); |
| 116 | |
| 117 | board_early_init_f(); |
| 118 | |
Peng Fan | bdada3b | 2020-05-26 20:33:48 -0300 | [diff] [blame] | 119 | ret = spl_early_init(); |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 120 | if (ret) { |
| 121 | debug("spl_init() failed: %d\n", ret); |
| 122 | hang(); |
| 123 | } |
| 124 | |
Peng Fan | bdada3b | 2020-05-26 20:33:48 -0300 | [diff] [blame] | 125 | preloader_console_init(); |
| 126 | |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 127 | enable_tzc380(); |
| 128 | |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 129 | setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1); |
| 130 | |
| 131 | power_init_board(); |
| 132 | |
| 133 | /* DDR initialization */ |
| 134 | spl_dram_init(); |
Peng Fan | 439321b | 2019-12-30 17:46:21 +0800 | [diff] [blame] | 135 | } |