blob: a91c15ca4e18881ce8e30be48a1111b5ce52fafd [file] [log] [blame]
Suman Annad98e8602022-05-25 13:38:42 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * AM625: SoC specific initialization
4 *
5 * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/
6 * Suman Anna <s-anna@ti.com>
7 */
8
9#include <spl.h>
10#include <asm/io.h>
11#include <asm/arch/hardware.h>
12#include <asm/arch/sysfw-loader.h>
13#include "common.h"
14#include <dm.h>
15#include <dm/uclass-internal.h>
16#include <dm/pinctrl.h>
17
Suman Annad98e8602022-05-25 13:38:42 +053018/*
19 * This uninitialized global variable would normal end up in the .bss section,
20 * but the .bss is cleared between writing and reading this variable, so move
21 * it to the .data section.
22 */
23u32 bootindex __section(".data");
24static struct rom_extended_boot_data bootdata __section(".data");
25
26static void store_boot_info_from_rom(void)
27{
28 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Bryan Brattlof4c710fa2022-11-22 13:28:11 -060029 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
Suman Annad98e8602022-05-25 13:38:42 +053030 sizeof(struct rom_extended_boot_data));
31}
32
33static void ctrl_mmr_unlock(void)
34{
35 /* Unlock all WKUP_CTRL_MMR0 module registers */
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
37 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
40 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
41 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
42 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
44
45 /* Unlock all CTRL_MMR0 module registers */
46 mmr_unlock(CTRL_MMR0_BASE, 0);
47 mmr_unlock(CTRL_MMR0_BASE, 1);
48 mmr_unlock(CTRL_MMR0_BASE, 2);
49 mmr_unlock(CTRL_MMR0_BASE, 4);
50 mmr_unlock(CTRL_MMR0_BASE, 6);
51
52 /* Unlock all MCU_CTRL_MMR0 module registers */
53 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
54 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
55 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
56 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
57 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
58 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
59
60 /* Unlock PADCFG_CTRL_MMR padconf registers */
61 mmr_unlock(PADCFG_MMR0_BASE, 1);
62 mmr_unlock(PADCFG_MMR1_BASE, 1);
63}
64
Julien Panis16958202022-07-01 14:30:11 +020065static __maybe_unused void enable_mcu_esm_reset(void)
66{
67 /* Set CTRLMMR_MCU_RST_CTRL:MCU_ESM_ERROR_RST_EN_Z to '0' (low active) */
68 u32 stat = readl(CTRLMMR_MCU_RST_CTRL);
69
70 stat &= RST_CTRL_ESM_ERROR_RST_EN_Z_MASK;
71 writel(stat, CTRLMMR_MCU_RST_CTRL);
72}
73
Suman Annad98e8602022-05-25 13:38:42 +053074void board_init_f(ulong dummy)
75{
76 struct udevice *dev;
77 int ret;
78
79#if defined(CONFIG_CPU_V7R)
80 setup_k3_mpu_regions();
81#endif
82
83 /*
84 * Cannot delay this further as there is a chance that
85 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
86 */
87 store_boot_info_from_rom();
88
89 ctrl_mmr_unlock();
90
91 /* Init DM early */
92 spl_early_init();
93
94 /*
95 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
96 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
97 * Do this without probing the device, but instead by searching the
98 * device that would request the given sequence number if probed. The
99 * UARTs will be used by the DM firmware and TIFS firmware images
100 * respectively and the firmware depend on SPL to initialize the pin
101 * settings.
102 */
103 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
104 if (!ret)
105 pinctrl_select_state(dev, "default");
106
107 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
108 if (!ret)
109 pinctrl_select_state(dev, "default");
110
111 preloader_console_init();
112
113#ifdef CONFIG_K3_EARLY_CONS
114 /*
115 * Allow establishing an early console as required for example when
116 * doing a UART-based boot. Note that this console may not "survive"
117 * through a SYSFW PM-init step and will need a re-init in some way
118 * due to changing module clock frequencies.
119 */
120 early_console_init();
121#endif
122
123#if defined(CONFIG_K3_LOAD_SYSFW)
124 /*
125 * Configure and start up system controller firmware. Provide
126 * the U-Boot console init function to the SYSFW post-PM configuration
127 * callback hook, effectively switching on (or over) the console
128 * output.
129 */
130 ret = is_rom_loaded_sysfw(&bootdata);
131 if (!ret)
132 panic("ROM has not loaded TIFS firmware\n");
133
134 k3_sysfw_loader(true, NULL, NULL);
135#endif
136
137 /*
138 * Force probe of clk_k3 driver here to ensure basic default clock
139 * configuration is always done.
140 */
141 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
142 ret = uclass_get_device_by_driver(UCLASS_CLK,
143 DM_DRIVER_GET(ti_clk),
144 &dev);
145 if (ret)
146 printf("Failed to initialize clk-k3!\n");
147 }
148
149 /* Output System Firmware version info */
150 k3_sysfw_print_ver();
151
Julien Panis16958202022-07-01 14:30:11 +0200152 if (IS_ENABLED(CONFIG_ESM_K3)) {
153 /* Probe/configure ESM0 */
154 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@420000", &dev);
155 if (ret)
156 printf("esm main init failed: %d\n", ret);
157
158 /* Probe/configure MCUESM */
159 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@4100000", &dev);
160 if (ret)
161 printf("esm mcu init failed: %d\n", ret);
162
163 enable_mcu_esm_reset();
164 }
165
Suman Annad98e8602022-05-25 13:38:42 +0530166#if defined(CONFIG_K3_AM64_DDRSS)
167 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
168 if (ret)
169 panic("DRAM init failed: %d\n", ret);
170#endif
171}
172
173u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
174{
175 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Martyn Welch7c34b712022-12-20 18:38:18 +0000176 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
177 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
Suman Annad98e8602022-05-25 13:38:42 +0530178 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
179 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
180
Suman Annad98e8602022-05-25 13:38:42 +0530181
Martyn Welch7c34b712022-12-20 18:38:18 +0000182 switch (bootmode) {
183 case BOOT_DEVICE_EMMC:
184 return MMCSD_MODE_EMMCBOOT;
185 case BOOT_DEVICE_MMC:
186 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
187 return MMCSD_MODE_RAW;
Suman Annad98e8602022-05-25 13:38:42 +0530188 default:
Martyn Welch7c34b712022-12-20 18:38:18 +0000189 return MMCSD_MODE_FS;
Suman Annad98e8602022-05-25 13:38:42 +0530190 }
191}
192
193static u32 __get_backup_bootmedia(u32 devstat)
194{
195 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
196 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
197 u32 bkup_bootmode_cfg =
198 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
199 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
200
201 switch (bkup_bootmode) {
202 case BACKUP_BOOT_DEVICE_UART:
203 return BOOT_DEVICE_UART;
204
205 case BACKUP_BOOT_DEVICE_USB:
206 return BOOT_DEVICE_USB;
207
208 case BACKUP_BOOT_DEVICE_ETHERNET:
209 return BOOT_DEVICE_ETHERNET;
210
211 case BACKUP_BOOT_DEVICE_MMC:
212 if (bkup_bootmode_cfg)
213 return BOOT_DEVICE_MMC2;
214 return BOOT_DEVICE_MMC1;
215
216 case BACKUP_BOOT_DEVICE_SPI:
217 return BOOT_DEVICE_SPI;
218
219 case BACKUP_BOOT_DEVICE_I2C:
220 return BOOT_DEVICE_I2C;
221
222 case BACKUP_BOOT_DEVICE_DFU:
223 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
224 return BOOT_DEVICE_USB;
225 return BOOT_DEVICE_DFU;
226 };
227
228 return BOOT_DEVICE_RAM;
229}
230
231static u32 __get_primary_bootmedia(u32 devstat)
232{
233 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
234 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
235 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
236 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
237
238 switch (bootmode) {
239 case BOOT_DEVICE_OSPI:
240 fallthrough;
241 case BOOT_DEVICE_QSPI:
242 fallthrough;
243 case BOOT_DEVICE_XSPI:
244 fallthrough;
245 case BOOT_DEVICE_SPI:
246 return BOOT_DEVICE_SPI;
247
248 case BOOT_DEVICE_ETHERNET_RGMII:
249 fallthrough;
250 case BOOT_DEVICE_ETHERNET_RMII:
251 return BOOT_DEVICE_ETHERNET;
252
253 case BOOT_DEVICE_EMMC:
254 return BOOT_DEVICE_MMC1;
255
256 case BOOT_DEVICE_MMC:
257 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
258 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
259 return BOOT_DEVICE_MMC2;
260 return BOOT_DEVICE_MMC1;
261
262 case BOOT_DEVICE_DFU:
263 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
264 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
265 return BOOT_DEVICE_USB;
266 return BOOT_DEVICE_DFU;
267
268 case BOOT_DEVICE_NOBOOT:
269 return BOOT_DEVICE_RAM;
270 }
271
272 return bootmode;
273}
274
275u32 spl_boot_device(void)
276{
277 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
278 u32 bootmedia;
279
280 if (bootindex == K3_PRIMARY_BOOTMODE)
281 bootmedia = __get_primary_bootmedia(devstat);
282 else
283 bootmedia = __get_backup_bootmedia(devstat);
284
285 debug("am625_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
286 __func__, devstat, bootmedia, bootindex);
287
288 return bootmedia;
289}