Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 2 | /* |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 3 | * Copyright 2018-2019, 2021 NXP |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 4 | * |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 10 | #include <hang.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/mach-imx/iomux-v3.h> |
| 18 | #include <asm/arch/clock.h> |
| 19 | #include <asm/arch/imx8mn_pins.h> |
| 20 | #include <asm/arch/sys_proto.h> |
| 21 | #include <asm/mach-imx/boot_mode.h> |
| 22 | #include <asm/arch/ddr.h> |
| 23 | |
| 24 | #include <dm/uclass.h> |
| 25 | #include <dm/device.h> |
| 26 | #include <dm/uclass-internal.h> |
| 27 | #include <dm/device-internal.h> |
Peng Fan | 80607bf | 2021-03-19 15:57:08 +0800 | [diff] [blame] | 28 | #include <power/pmic.h> |
| 29 | #include <power/pca9450.h> |
| 30 | #include <asm/mach-imx/gpio.h> |
| 31 | #include <asm/mach-imx/mxc_i2c.h> |
| 32 | #include <fsl_esdhc_imx.h> |
| 33 | #include <mmc.h> |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
| 37 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 38 | { |
| 39 | return BOOT_DEVICE_BOOTROM; |
| 40 | } |
| 41 | |
| 42 | void spl_dram_init(void) |
| 43 | { |
| 44 | ddr_init(&dram_timing); |
| 45 | } |
| 46 | |
| 47 | void spl_board_init(void) |
| 48 | { |
| 49 | struct udevice *dev; |
| 50 | int ret; |
| 51 | |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 52 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 53 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 54 | if (ret) |
Ye Li | ec34689 | 2022-05-11 13:56:20 +0530 | [diff] [blame] | 55 | printf("Failed to initialize caam_jr: %d\n", ret); |
Gaurav Jain | 81113a0 | 2022-03-24 11:50:27 +0530 | [diff] [blame] | 56 | } |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 57 | puts("Normal Boot\n"); |
| 58 | |
| 59 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 60 | "clock-controller@30380000", |
| 61 | &dev); |
| 62 | if (ret < 0) |
| 63 | printf("Failed to find clock node. Check device tree\n"); |
| 64 | } |
| 65 | |
Peng Fan | 80607bf | 2021-03-19 15:57:08 +0800 | [diff] [blame] | 66 | #if CONFIG_IS_ENABLED(DM_PMIC_PCA9450) |
| 67 | int power_init_board(void) |
| 68 | { |
| 69 | struct udevice *dev; |
| 70 | int ret; |
| 71 | |
| 72 | ret = pmic_get("pca9450@25", &dev); |
| 73 | if (ret == -ENODEV) { |
| 74 | puts("No pca9450@25\n"); |
| 75 | return 0; |
| 76 | } |
| 77 | if (ret != 0) |
| 78 | return ret; |
| 79 | |
| 80 | /* BUCKxOUT_DVS0/1 control BUCK123 output */ |
| 81 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
| 82 | |
Ye Li | ee337ce | 2021-03-19 15:57:09 +0800 | [diff] [blame] | 83 | #ifdef CONFIG_IMX8MN_LOW_DRIVE_MODE |
| 84 | /* Set VDD_SOC/VDD_DRAM to 0.8v for low drive mode */ |
| 85 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x10); |
| 86 | #else |
Peng Fan | 80607bf | 2021-03-19 15:57:08 +0800 | [diff] [blame] | 87 | /* increase VDD_SOC/VDD_DRAM to typical value 0.95V before first DRAM access */ |
Ye Li | ee337ce | 2021-03-19 15:57:09 +0800 | [diff] [blame] | 88 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C); |
| 89 | #endif |
Peng Fan | 80607bf | 2021-03-19 15:57:08 +0800 | [diff] [blame] | 90 | /* Set DVS1 to 0.85v for suspend */ |
| 91 | /* Enable DVS control through PMIC_STBY_REQ and set B1_ENMODE=1 (ON by PMIC_ON_REQ=H) */ |
Peng Fan | 80607bf | 2021-03-19 15:57:08 +0800 | [diff] [blame] | 92 | pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14); |
| 93 | pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59); |
| 94 | |
| 95 | /* set VDD_SNVS_0V8 from default 0.85V */ |
| 96 | pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0); |
| 97 | |
| 98 | /* enable LDO4 to 1.2v */ |
| 99 | pmic_reg_write(dev, PCA9450_LDO4CTRL, 0x44); |
| 100 | |
| 101 | /* set WDOG_B_CFG to cold reset */ |
| 102 | pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1); |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | #endif |
| 107 | |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 108 | #ifdef CONFIG_SPL_LOAD_FIT |
| 109 | int board_fit_config_name_match(const char *name) |
| 110 | { |
| 111 | /* Just empty function now - can't decide what to choose */ |
| 112 | debug("%s: %s\n", __func__, name); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | #endif |
| 117 | |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 118 | void board_init_f(ulong dummy) |
| 119 | { |
| 120 | int ret; |
| 121 | |
| 122 | arch_cpu_init(); |
| 123 | |
| 124 | init_uart_clk(1); |
| 125 | |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 126 | timer_init(); |
| 127 | |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 128 | /* Clear the BSS. */ |
| 129 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 130 | |
| 131 | ret = spl_init(); |
| 132 | if (ret) { |
| 133 | debug("spl_init() failed: %d\n", ret); |
| 134 | hang(); |
| 135 | } |
| 136 | |
Peng Fan | bee25f1 | 2022-04-15 12:35:35 +0800 | [diff] [blame] | 137 | preloader_console_init(); |
| 138 | |
Peng Fan | a181afe | 2019-09-16 03:09:55 +0000 | [diff] [blame] | 139 | enable_tzc380(); |
| 140 | |
| 141 | /* DDR initialization */ |
| 142 | spl_dram_init(); |
| 143 | |
| 144 | board_init_r(NULL, 0); |
| 145 | } |