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