blob: 73729a42b458bab93522d8d98211aa71b88237df [file] [log] [blame]
Marcel Ziswiler36a439d2022-02-07 11:54:13 +01001// 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 Cainikovs50e94832022-10-04 13:06:31 +020020#include <dm/device.h>
21#include <dm/uclass.h>
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010022#include <power/pmic.h>
23#include <power/pca9450.h>
Emanuele Ghidoli03d23b82023-04-03 14:01:56 +020024#include "lpddr4_timing.h"
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010025
26DECLARE_GLOBAL_DATA_PTR;
27
28int spl_board_boot_device(enum boot_device boot_dev_spl)
29{
30 return BOOT_DEVICE_BOOTROM;
31}
32
33void spl_dram_init(void)
34{
35 /*
Emanuele Ghidolidbbe19b2023-04-03 14:01:53 +020036 * Try configuring for dual rank memory falling back to single rank
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010037 */
Emanuele Ghidolid3bfc022023-04-03 14:01:57 +020038 if (!ddr_init(&dram_timing)) {
39 puts("DDR configured as dual rank\n");
40 return;
41 }
42
43 lpddr4_single_rank_training_patch();
44 if (!ddr_init(&dram_timing)) {
45 puts("DDR configured as single rank\n");
46 return;
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010047 }
Emanuele Ghidolid3bfc022023-04-03 14:01:57 +020048 puts("DDR configuration failed\n");
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010049}
50
51void spl_board_init(void)
52{
Andrejs Cainikovs50e94832022-10-04 13:06:31 +020053 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
54 struct udevice *dev;
55 int ret;
56
57 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
58 if (ret)
59 printf("Failed to initialize caam_jr: %d\n", ret);
60 }
61
Marcel Ziswiler36a439d2022-02-07 11:54:13 +010062 /*
63 * Set GIC clock to 500Mhz for OD VDD_SOC. Kernel driver does
64 * not allow to change it. Should set the clock after PMIC
65 * setting done. Default is 400Mhz (system_pll1_800m with div = 2)
66 * set by ROM for ND VDD_SOC
67 */
68 clock_enable(CCGR_GIC, 0);
69 clock_set_target_val(GIC_CLK_ROOT, CLK_ROOT_ON | CLK_ROOT_SOURCE_SEL(5));
70 clock_enable(CCGR_GIC, 1);
71
72 puts("Normal Boot\n");
73}
74
75#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PE)
76#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
77struct i2c_pads_info i2c_pad_info1 = {
78 .scl = {
79 .i2c_mode = MX8MP_PAD_I2C1_SCL__I2C1_SCL | PC,
80 .gpio_mode = MX8MP_PAD_I2C1_SCL__GPIO5_IO14 | PC,
81 .gp = IMX_GPIO_NR(5, 14),
82 },
83 .sda = {
84 .i2c_mode = MX8MP_PAD_I2C1_SDA__I2C1_SDA | PC,
85 .gpio_mode = MX8MP_PAD_I2C1_SDA__GPIO5_IO15 | PC,
86 .gp = IMX_GPIO_NR(5, 15),
87 },
88};
89
90#if CONFIG_IS_ENABLED(POWER_LEGACY)
91#define I2C_PMIC 0
92int power_init_board(void)
93{
94 struct pmic *p;
95 int ret;
96
97 ret = power_pca9450_init(I2C_PMIC, 0x25);
98 if (ret)
99 printf("power init failed\n");
100 p = pmic_get("PCA9450");
101 pmic_probe(p);
102
103 /* BUCKxOUT_DVS0/1 control BUCK123 output */
104 pmic_reg_write(p, PCA9450_BUCK123_DVS, 0x29);
105
106 /*
107 * increase VDD_SOC to typical value 0.95V before first
108 * DRAM access, set DVS1 to 0.85v for suspend.
109 * Enable DVS control through PMIC_STBY_REQ and
110 * set B1_ENMODE=1 (ON by PMIC_ON_REQ=H)
111 */
112 if (IS_ENABLED(CONFIG_IMX8M_VDD_SOC_850MV))
113 /* set DVS0 to 0.85v for special case */
114 pmic_reg_write(p, PCA9450_BUCK1OUT_DVS0, 0x14);
115 else
116 pmic_reg_write(p, PCA9450_BUCK1OUT_DVS0, 0x1c);
117 pmic_reg_write(p, PCA9450_BUCK1OUT_DVS1, 0x14);
118 pmic_reg_write(p, PCA9450_BUCK1CTRL, 0x59);
119
120 /* Kernel uses OD/OD freq for SoC */
121 /* To avoid timing risk from SoC to ARM, increase VDD_ARM to OD voltage 0.95v */
122 pmic_reg_write(p, PCA9450_BUCK2OUT_DVS0, 0x1c);
123
Marcel Ziswiler36a439d2022-02-07 11:54:13 +0100124 /* set LDO4 and CONFIG2 to enable the I2C level translator */
125 pmic_reg_write(p, PCA9450_LDO4CTRL, 0x59);
126 pmic_reg_write(p, PCA9450_CONFIG2, 0x1);
127
128 return 0;
129}
130#endif
131
132#if IS_ENABLED(CONFIG_SPL_LOAD_FIT)
133int board_fit_config_name_match(const char *name)
134{
135 /* Just empty function now - can't decide what to choose */
136 debug("%s: %s\n", __func__, name);
137
138 return 0;
139}
140#endif
141
142/* Do not use BSS area in this phase */
143void board_init_f(ulong dummy)
144{
145 int ret;
146
147 arch_cpu_init();
148
149 init_uart_clk(1);
150
151 board_early_init_f();
152
153 ret = spl_early_init();
154 if (ret) {
155 debug("spl_init() failed: %d\n", ret);
156 hang();
157 }
158
159 preloader_console_init();
160
161 enable_tzc380();
162
163 /* Adjust PMIC voltage to 1.0V for 800 MHz */
164 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
165
166 /* PMIC initialization */
167 power_init_board();
168
169 /* DDR initialization */
170 spl_dram_init();
171}