blob: 12da1b2abfbb7d1a22a2910f7f1d7ebce470bf0a [file] [log] [blame]
Gaurav Jain81113a02022-03-24 11:50:27 +05301// SPDX-License-Identifier: GPL-2.0-or-later
Peng Fanc47e09d2019-12-30 17:46:21 +08002/*
Gaurav Jain81113a02022-03-24 11:50:27 +05303 * Copyright 2018-2019, 2021 NXP
Peng Fanc47e09d2019-12-30 17:46:21 +08004 *
Peng Fanc47e09d2019-12-30 17:46:21 +08005 */
6
Simon Glassf11478f2019-12-28 10:45:07 -07007#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080010#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Peng Fana2608a12021-03-19 15:57:03 +080012#include <asm/arch/clock.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080013#include <asm/arch/imx8mp_pins.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/mach-imx/boot_mode.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080016#include <asm/mach-imx/gpio.h>
Peng Fana2608a12021-03-19 15:57:03 +080017#include <asm/mach-imx/iomux-v3.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080018#include <asm/mach-imx/mxc_i2c.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080019#include <asm/arch/ddr.h>
Peng Fana2608a12021-03-19 15:57:03 +080020#include <power/pmic.h>
21#include <power/pca9450.h>
Gaurav Jain81113a02022-03-24 11:50:27 +053022#include <dm/uclass.h>
23#include <dm/device.h>
Peng Fanc47e09d2019-12-30 17:46:21 +080024
Peng Fanc47e09d2019-12-30 17:46:21 +080025DECLARE_GLOBAL_DATA_PTR;
26
27int spl_board_boot_device(enum boot_device boot_dev_spl)
28{
29 return BOOT_DEVICE_BOOTROM;
30}
31
32void spl_dram_init(void)
33{
34 ddr_init(&dram_timing);
35}
36
37void spl_board_init(void)
38{
Marek Vasut085555f2022-09-19 21:41:15 +020039 arch_misc_init();
Gaurav Jain81113a02022-03-24 11:50:27 +053040
Peng Fancc08e7e2021-03-19 15:57:04 +080041 /*
42 * Set GIC clock to 500Mhz for OD VDD_SOC. Kernel driver does
43 * not allow to change it. Should set the clock after PMIC
44 * setting done. Default is 400Mhz (system_pll1_800m with div = 2)
45 * set by ROM for ND VDD_SOC
46 */
47 clock_enable(CCGR_GIC, 0);
48 clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5));
49 clock_enable(CCGR_GIC, 1);
50
Peng Fanc47e09d2019-12-30 17:46:21 +080051 puts("Normal Boot\n");
Peng Fanc47e09d2019-12-30 17:46:21 +080052}
53
54#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE)
55#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
56struct i2c_pads_info i2c_pad_info1 = {
57 .scl = {
58 .i2c_mode = MX8MP_PAD_I2C1_SCL__I2C1_SCL | PC,
59 .gpio_mode = MX8MP_PAD_I2C1_SCL__GPIO5_IO14 | PC,
60 .gp = IMX_GPIO_NR(5, 14),
61 },
62 .sda = {
63 .i2c_mode = MX8MP_PAD_I2C1_SDA__I2C1_SDA | PC,
64 .gpio_mode = MX8MP_PAD_I2C1_SDA__GPIO5_IO15 | PC,
65 .gp = IMX_GPIO_NR(5, 15),
66 },
67};
68
Fabio Estevam4671ab42023-10-18 16:17:41 -030069#if CONFIG_IS_ENABLED(DM_PMIC_PCA9450)
Peng Fanc47e09d2019-12-30 17:46:21 +080070int power_init_board(void)
71{
Fabio Estevam4671ab42023-10-18 16:17:41 -030072 struct udevice *dev;
Peng Fanc47e09d2019-12-30 17:46:21 +080073 int ret;
74
Fabio Estevam4671ab42023-10-18 16:17:41 -030075 ret = pmic_get("pmic@25", &dev);
76 if (ret == -ENODEV) {
77 puts("No pmic@25\n");
78 return 0;
79 }
80 if (ret < 0)
81 return ret;
Peng Fanc47e09d2019-12-30 17:46:21 +080082
83 /* BUCKxOUT_DVS0/1 control BUCK123 output */
Fabio Estevam4671ab42023-10-18 16:17:41 -030084 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
Peng Fanc47e09d2019-12-30 17:46:21 +080085
86 /*
Fabio Estevam4671ab42023-10-18 16:17:41 -030087 * Increase VDD_SOC to typical value 0.95V before first
88 * DRAM access, set DVS1 to 0.85V for suspend.
Peng Fanc47e09d2019-12-30 17:46:21 +080089 * Enable DVS control through PMIC_STBY_REQ and
90 * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H)
91 */
Fabio Estevam4671ab42023-10-18 16:17:41 -030092 if (CONFIG_IS_ENABLED(IMX8M_VDD_SOC_850MV))
93 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x14);
94 else
95 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS0, 0x1C);
Peng Fanc47e09d2019-12-30 17:46:21 +080096
Fabio Estevam4671ab42023-10-18 16:17:41 -030097 pmic_reg_write(dev, PCA9450_BUCK1OUT_DVS1, 0x14);
98 pmic_reg_write(dev, PCA9450_BUCK1CTRL, 0x59);
99
100 /*
101 * Kernel uses OD/OD freq for SOC.
102 * To avoid timing risk from SOC to ARM,increase VDD_ARM to OD
103 * voltage 0.95V.
104 */
105
106 pmic_reg_write(dev, PCA9450_BUCK2OUT_DVS0, 0x1C);
Peng Fancc08e7e2021-03-19 15:57:04 +0800107
Peng Fanc47e09d2019-12-30 17:46:21 +0800108 return 0;
109}
110#endif
111
112#ifdef CONFIG_SPL_LOAD_FIT
113int board_fit_config_name_match(const char *name)
114{
115 /* Just empty function now - can't decide what to choose */
116 debug("%s: %s\n", __func__, name);
117
118 return 0;
119}
120#endif
121
Peng Fana50c0a32020-05-26 20:33:49 -0300122/* Do not use BSS area in this phase */
Peng Fanc47e09d2019-12-30 17:46:21 +0800123void board_init_f(ulong dummy)
124{
125 int ret;
126
127 arch_cpu_init();
128
129 init_uart_clk(1);
130
Peng Fan5d93e1c2020-05-26 20:33:48 -0300131 ret = spl_early_init();
Peng Fanc47e09d2019-12-30 17:46:21 +0800132 if (ret) {
133 debug("spl_init() failed: %d\n", ret);
134 hang();
135 }
136
Peng Fan5d93e1c2020-05-26 20:33:48 -0300137 preloader_console_init();
138
Peng Fanc47e09d2019-12-30 17:46:21 +0800139 enable_tzc380();
140
Peng Fanc47e09d2019-12-30 17:46:21 +0800141 power_init_board();
142
143 /* DDR initialization */
144 spl_dram_init();
Peng Fanc47e09d2019-12-30 17:46:21 +0800145}