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