blob: 8a41cd3bb500be57a6e2497f0fd4ca9a6b7fcb4a [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{
Neha Malcom Francis55713862024-11-18 16:27:12 +0530236 struct udevice *dev;
237 int ret;
238
Apurva Nandan67ebc302024-02-24 01:51:41 +0530239 k3_spl_init();
240 k3_mem_init();
Jayesh Choudharyb9bbedc2024-06-14 18:14:39 +0530241
Neha Malcom Francis55713862024-11-18 16:27:12 +0530242 if (IS_ENABLED(CONFIG_CPU_V7R) && IS_ENABLED(CONFIG_K3_AVS0)) {
243 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
244 &dev);
245 if (ret)
246 printf("AVS init failed: %d\n", ret);
247 }
248
Jayesh Choudharyb9bbedc2024-06-14 18:14:39 +0530249 if (IS_ENABLED(CONFIG_CPU_V7R))
250 setup_navss_nb();
251
252 setup_qos();
Apurva Nandan67ebc302024-02-24 01:51:41 +0530253}
254
255u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
256{
257 switch (boot_device) {
258 case BOOT_DEVICE_MMC1:
259 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
260 return MMCSD_MODE_EMMCBOOT;
261 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
262 return MMCSD_MODE_FS;
263 return MMCSD_MODE_EMMCBOOT;
264 case BOOT_DEVICE_MMC2:
265 return MMCSD_MODE_FS;
266 default:
267 return MMCSD_MODE_RAW;
268 }
269}
270
271static u32 __get_backup_bootmedia(u32 main_devstat)
272{
273 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
274 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
275
276 switch (bkup_boot) {
277 case BACKUP_BOOT_DEVICE_USB:
278 return BOOT_DEVICE_DFU;
279 case BACKUP_BOOT_DEVICE_UART:
280 return BOOT_DEVICE_UART;
281 case BACKUP_BOOT_DEVICE_ETHERNET:
282 return BOOT_DEVICE_ETHERNET;
283 case BACKUP_BOOT_DEVICE_MMC2:
284 {
285 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
286 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
287 if (port == 0x0)
288 return BOOT_DEVICE_MMC1;
289 return BOOT_DEVICE_MMC2;
290 }
291 case BACKUP_BOOT_DEVICE_SPI:
292 return BOOT_DEVICE_SPI;
293 case BACKUP_BOOT_DEVICE_I2C:
294 return BOOT_DEVICE_I2C;
295 }
296
297 return BOOT_DEVICE_RAM;
298}
299
300static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
301{
302 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
303 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
304
305 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
306 BOOT_MODE_B_SHIFT;
307
308 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI ||
309 bootmode == BOOT_DEVICE_XSPI)
310 bootmode = BOOT_DEVICE_SPI;
311
312 if (bootmode == BOOT_DEVICE_MMC2) {
313 u32 port = (main_devstat &
314 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
315 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
316 if (port == 0x0)
317 bootmode = BOOT_DEVICE_MMC1;
318 }
319
320 return bootmode;
321}
322
323u32 spl_spi_boot_bus(void)
324{
325 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
326 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
327 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
328 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
329 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
330
331 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
332}
333
334u32 spl_boot_device(void)
335{
336 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
337 u32 main_devstat;
338
339 if (wkup_devstat & WKUP_DEVSTAT_MCU_ONLY_MASK) {
340 printf("ERROR: MCU only boot is not yet supported\n");
341 return BOOT_DEVICE_RAM;
342 }
343
344 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
345 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
346
347 if (bootindex == K3_PRIMARY_BOOTMODE)
348 return __get_primary_bootmedia(main_devstat, wkup_devstat);
349 else
350 return __get_backup_bootmedia(main_devstat);
351}