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