blob: 07b5d7d7504f664fa591456e6b2d637d42b2a2db [file] [log] [blame]
Apurva Nandan67ebc302024-02-24 01:51:41 +05301// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * J784S4: SoC specific initialization
4 *
5 * Copyright (C) 2023-2024 Texas Instruments Incorporated - https://www.ti.com/
6 * Hari Nagalla <hnagalla@ti.com>
7 */
8
9#include <init.h>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm/armv7_mpu.h>
13#include <asm/arch/hardware.h>
Apurva Nandan67ebc302024-02-24 01:51:41 +053014#include <linux/soc/ti/ti_sci_protocol.h>
15#include <dm.h>
16#include <dm/uclass-internal.h>
17#include <dm/pinctrl.h>
18#include <mmc.h>
19#include <remoteproc.h>
20
Andrew Davis336b0792024-05-10 15:21:24 -050021#include "../sysfw-loader.h"
22#include "../common.h"
23
Apurva Nandan67ebc302024-02-24 01:51:41 +053024#define J784S4_MAX_DDR_CONTROLLERS 4
25
Jayesh Choudharyb9bbedc2024-06-14 18:14:39 +053026/* NAVSS North Bridge (NB) */
27#define NAVSS0_NBSS_NB0_CFG_MMRS 0x03702000
28#define NAVSS0_NBSS_NB1_CFG_MMRS 0x03703000
29#define NAVSS0_NBSS_NB0_CFG_NB_THREADMAP (NAVSS0_NBSS_NB0_CFG_MMRS + 0x10)
30#define NAVSS0_NBSS_NB1_CFG_NB_THREADMAP (NAVSS0_NBSS_NB1_CFG_MMRS + 0x10)
31/*
32 * Thread Map for North Bridge Configuration
33 * Each bit is for each VBUSM source.
34 * Bit[0] maps orderID 0-3 to VBUSM.C thread number
35 * Bit[1] maps orderID 4-9 to VBUSM.C thread number
36 * Bit[2] maps orderID 10-15 to VBUSM.C thread number
37 * When bit has value 0: VBUSM.C thread 0 (non-real time traffic)
38 * When bit has value 1: VBUSM.C thread 2 (real time traffic)
39 */
40#define NB_THREADMAP_BIT0 BIT(0)
41#define NB_THREADMAP_BIT1 BIT(1)
42#define NB_THREADMAP_BIT2 BIT(2)
43
Apurva Nandan67ebc302024-02-24 01:51:41 +053044struct fwl_data infra_cbass0_fwls[] = {
45 { "PSC0", 5, 1 },
46 { "PLL_CTRL0", 6, 1 },
47 { "PLL_MMR0", 8, 26 },
48 { "CTRL_MMR0", 9, 16 },
49 { "GPIO0", 16, 1 },
50}, wkup_cbass0_fwls[] = {
51 { "WKUP_PSC0", 129, 1 },
52 { "WKUP_PLL_CTRL0", 130, 1 },
53 { "WKUP_CTRL_MMR0", 131, 16 },
54 { "WKUP_GPIO0", 132, 1 },
55 { "WKUP_I2C0", 144, 1 },
56 { "WKUP_USART0", 160, 1 },
57}, mcu_cbass0_fwls[] = {
58 { "MCU_R5FSS0_CORE0", 1024, 4 },
59 { "MCU_R5FSS0_CORE0_CFG", 1025, 3 },
60 { "MCU_R5FSS0_CORE1", 1028, 4 },
61 { "MCU_R5FSS0_CORE1_CFG", 1029, 1 },
62 { "MCU_FSS0_CFG", 1032, 12 },
63 { "MCU_FSS0_S1", 1033, 8 },
64 { "MCU_FSS0_S0", 1036, 8 },
65 { "MCU_PSROM49152X32", 1048, 1 },
66 { "MCU_MSRAM128KX64", 1050, 8 },
67 { "MCU_MSRAM128KX64_CFG", 1051, 1 },
68 { "MCU_TIMER0", 1056, 1 },
69 { "MCU_TIMER9", 1065, 1 },
70 { "MCU_USART0", 1120, 1 },
71 { "MCU_I2C0", 1152, 1 },
72 { "MCU_CTRL_MMR0", 1200, 8 },
73 { "MCU_PLL_MMR0", 1201, 3 },
74 { "MCU_CPSW0", 1220, 2 },
75}, cbass_rc_cfg0_fwls[] = {
76 { "EMMCSD4SS0_CFG", 2400, 4 },
77}, cbass_hc2_fwls[] = {
78 { "PCIE0", 2547, 24 },
79}, cbass_hc_cfg0_fwls[] = {
80 { "PCIE0_CFG", 2577, 7 },
81 { "EMMC8SS0_CFG", 2579, 4 },
82 { "USB3SS0_CORE", 2580, 4 },
83 { "USB3SS1_CORE", 2581, 1 },
84}, navss_cbass0_fwls[] = {
85 { "NACSS_VIRT0", 6253, 1 },
86};
87
88static void ctrl_mmr_unlock(void)
89{
90 /* Unlock all WKUP_CTRL_MMR0 module registers */
91 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
92 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
93 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
94 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
95 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
96 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
97 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
98
99 /* Unlock all MCU_CTRL_MMR0 module registers */
100 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
101 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
102 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
103 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
104 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
105
106 /* Unlock all CTRL_MMR0 module registers */
107 mmr_unlock(CTRL_MMR0_BASE, 0);
108 mmr_unlock(CTRL_MMR0_BASE, 1);
109 mmr_unlock(CTRL_MMR0_BASE, 2);
110 mmr_unlock(CTRL_MMR0_BASE, 3);
111 mmr_unlock(CTRL_MMR0_BASE, 5);
112 mmr_unlock(CTRL_MMR0_BASE, 7);
113}
114
Jayesh Choudharyb9bbedc2024-06-14 18:14:39 +0530115/* Setup North Bridge registers to map ORDERID 10-15 to RT traffic */
116static void setup_navss_nb(void)
117{
118 writel(NB_THREADMAP_BIT1, (uintptr_t)NAVSS0_NBSS_NB0_CFG_NB_THREADMAP);
119 writel(NB_THREADMAP_BIT2, (uintptr_t)NAVSS0_NBSS_NB1_CFG_NB_THREADMAP);
120}
121
Apurva Nandan67ebc302024-02-24 01:51:41 +0530122/*
123 * This uninitialized global variable would normal end up in the .bss section,
124 * but the .bss is cleared between writing and reading this variable, so move
125 * it to the .data section.
126 */
127u32 bootindex __section(".data");
128static struct rom_extended_boot_data bootdata __section(".data");
129
130static void store_boot_info_from_rom(void)
131{
132 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
133 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
134 sizeof(struct rom_extended_boot_data));
135}
136
137void k3_spl_init(void)
138{
139 struct udevice *dev;
140 int ret;
141
142 /*
143 * Cannot delay this further as there is a chance that
144 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
145 */
146 store_boot_info_from_rom();
147
148 /* Make all control module registers accessible */
149 ctrl_mmr_unlock();
150
151 if (IS_ENABLED(CONFIG_CPU_V7R)) {
152 disable_linefill_optimization();
153 setup_k3_mpu_regions();
154 }
155
156 /* Init DM early */
157 ret = spl_early_init();
158
159 /* Prepare console output */
160 preloader_console_init();
161
162 if (IS_ENABLED(CONFIG_CPU_V7R)) {
163 /*
164 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
165 * regardless of the result of pinctrl. Do this without probing the
166 * device, but instead by searching the device that would request the
167 * given sequence number if probed. The UART will be used by the system
168 * firmware (TIFS) image for various purposes and TIFS depends on us
169 * to initialize its pin settings.
170 */
171 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
172 if (!ret)
173 pinctrl_select_state(dev, "default");
174
175 /*
176 * Load, start up, and configure system controller firmware. Provide
177 * the U-Boot console init function to the TIFS post-PM configuration
178 * callback hook, effectively switching on (or over) the console
179 * output.
180 */
181 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata), NULL, NULL);
182
183 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
184 /*
185 * Force probe of clk_k3 driver here to ensure basic default clock
186 * configuration is always done for enabling PM services.
187 */
188 ret = uclass_get_device_by_driver(UCLASS_CLK,
189 DM_DRIVER_GET(ti_clk),
190 &dev);
191 if (ret)
192 panic("Failed to initialize clk-k3!\n");
193 }
194
195 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
196 remove_fwl_configs(cbass_hc2_fwls, ARRAY_SIZE(cbass_hc2_fwls));
197 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
198 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
199 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
200 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
201 remove_fwl_configs(navss_cbass0_fwls, ARRAY_SIZE(navss_cbass0_fwls));
202 }
203
204 /* Output System Firmware version info */
205 k3_sysfw_print_ver();
206}
207
208void k3_mem_init(void)
209{
210 struct udevice *dev;
211 int ret, ctrl = 0;
212
213 if (IS_ENABLED(CONFIG_K3_J721E_DDRSS)) {
214 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
215 if (ret)
216 panic("DRAM 0 init failed: %d\n", ret);
217 ctrl++;
218
219 while (ctrl < J784S4_MAX_DDR_CONTROLLERS) {
220 ret = uclass_next_device_err(&dev);
221 if (ret == -ENODEV)
222 break;
223
224 if (ret)
225 panic("DRAM %d init failed: %d\n", ctrl, ret);
226 ctrl++;
227 }
228 printf("Initialized %d DRAM controllers\n", ctrl);
229 }
230
231 spl_enable_cache();
232}
233
234void board_init_f(ulong dummy)
235{
236 k3_spl_init();
237 k3_mem_init();
Jayesh Choudharyb9bbedc2024-06-14 18:14:39 +0530238
239 if (IS_ENABLED(CONFIG_CPU_V7R))
240 setup_navss_nb();
241
242 setup_qos();
Apurva Nandan67ebc302024-02-24 01:51:41 +0530243}
244
245u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
246{
247 switch (boot_device) {
248 case BOOT_DEVICE_MMC1:
249 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
250 return MMCSD_MODE_EMMCBOOT;
251 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
252 return MMCSD_MODE_FS;
253 return MMCSD_MODE_EMMCBOOT;
254 case BOOT_DEVICE_MMC2:
255 return MMCSD_MODE_FS;
256 default:
257 return MMCSD_MODE_RAW;
258 }
259}
260
261static u32 __get_backup_bootmedia(u32 main_devstat)
262{
263 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
264 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
265
266 switch (bkup_boot) {
267 case BACKUP_BOOT_DEVICE_USB:
268 return BOOT_DEVICE_DFU;
269 case BACKUP_BOOT_DEVICE_UART:
270 return BOOT_DEVICE_UART;
271 case BACKUP_BOOT_DEVICE_ETHERNET:
272 return BOOT_DEVICE_ETHERNET;
273 case BACKUP_BOOT_DEVICE_MMC2:
274 {
275 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
276 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
277 if (port == 0x0)
278 return BOOT_DEVICE_MMC1;
279 return BOOT_DEVICE_MMC2;
280 }
281 case BACKUP_BOOT_DEVICE_SPI:
282 return BOOT_DEVICE_SPI;
283 case BACKUP_BOOT_DEVICE_I2C:
284 return BOOT_DEVICE_I2C;
285 }
286
287 return BOOT_DEVICE_RAM;
288}
289
290static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
291{
292 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
293 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
294
295 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
296 BOOT_MODE_B_SHIFT;
297
298 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
299 bootmode == BOOT_DEVICE_XSPI)
300 bootmode = BOOT_DEVICE_SPI;
301
302 if (bootmode == BOOT_DEVICE_MMC2) {
303 u32 port = (main_devstat &
304 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
305 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
306 if (port == 0x0)
307 bootmode = BOOT_DEVICE_MMC1;
308 }
309
310 return bootmode;
311}
312
313u32 spl_spi_boot_bus(void)
314{
315 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
316 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
317 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
318 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
319 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
320
321 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
322}
323
324u32 spl_boot_device(void)
325{
326 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
327 u32 main_devstat;
328
329 if (wkup_devstat & WKUP_DEVSTAT_MCU_ONLY_MASK) {
330 printf("ERROR: MCU only boot is not yet supported\n");
331 return BOOT_DEVICE_RAM;
332 }
333
334 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
335 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
336
337 if (bootindex == K3_PRIMARY_BOOTMODE)
338 return __get_primary_bootmedia(main_devstat, wkup_devstat);
339 else
340 return __get_backup_bootmedia(main_devstat);
341}