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