blob: cb9f7eebec1a38deafd294479296e821683a1829 [file] [log] [blame]
Lokesh Vutlaa2285322019-06-13 10:29:42 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * J721E: SoC specific initialization
4 *
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
9#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053011#include <spl.h>
12#include <asm/io.h>
13#include <asm/armv7_mpu.h>
Lokesh Vutla6edde292019-06-13 10:29:43 +053014#include <asm/arch/hardware.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053015#include <asm/arch/sysfw-loader.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053016#include "common.h"
Lokesh Vutla96c11f42019-06-13 10:29:46 +053017#include <asm/arch/sys_proto.h>
18#include <linux/soc/ti/ti_sci_protocol.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053019#include <dm.h>
20#include <dm/uclass-internal.h>
21#include <dm/pinctrl.h>
Sinthu Rajaa79cbe32022-02-09 15:06:53 +053022#include <dm/root.h>
23#include <fdtdec.h>
Faiz Abbas68393212020-02-26 13:44:36 +053024#include <mmc.h>
Keerthy7007adc2020-02-12 13:55:04 +053025#include <remoteproc.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053026
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050027#ifdef CONFIG_K3_LOAD_SYSFW
28#ifdef CONFIG_TI_SECURE_DEVICE
29struct fwl_data cbass_hc_cfg0_fwls[] = {
30 { "PCIE0_CFG", 2560, 8 },
31 { "PCIE1_CFG", 2561, 8 },
32 { "USB3SS0_CORE", 2568, 4 },
33 { "USB3SS1_CORE", 2570, 4 },
34 { "EMMC8SS0_CFG", 2576, 4 },
35 { "UFS_HCI0_CFG", 2580, 4 },
36 { "SERDES0", 2584, 1 },
37 { "SERDES1", 2585, 1 },
38}, cbass_hc0_fwls[] = {
39 { "PCIE0_HP", 2528, 24 },
40 { "PCIE0_LP", 2529, 24 },
41 { "PCIE1_HP", 2530, 24 },
42 { "PCIE1_LP", 2531, 24 },
43}, cbass_rc_cfg0_fwls[] = {
44 { "EMMCSD4SS0_CFG", 2380, 4 },
45}, cbass_rc0_fwls[] = {
46 { "GPMC0", 2310, 8 },
47}, infra_cbass0_fwls[] = {
48 { "PLL_MMR0", 8, 26 },
49 { "CTRL_MMR0", 9, 16 },
50}, mcu_cbass0_fwls[] = {
51 { "MCU_R5FSS0_CORE0", 1024, 4 },
52 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
53 { "MCU_R5FSS0_CORE1", 1028, 4 },
54 { "MCU_FSS0_CFG", 1032, 12 },
55 { "MCU_FSS0_S1", 1033, 8 },
56 { "MCU_FSS0_S0", 1036, 8 },
57 { "MCU_PSROM49152X32", 1048, 1 },
58 { "MCU_MSRAM128KX64", 1050, 8 },
59 { "MCU_CTRL_MMR0", 1200, 8 },
60 { "MCU_PLL_MMR0", 1201, 3 },
61 { "MCU_CPSW0", 1220, 2 },
62}, wkup_cbass0_fwls[] = {
63 { "WKUP_CTRL_MMR0", 131, 16 },
64};
65#endif
66#endif
67
Andreas Dannenberg660aa462019-06-13 10:29:44 +053068static void ctrl_mmr_unlock(void)
69{
70 /* Unlock all WKUP_CTRL_MMR0 module registers */
71 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
72 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
73 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
74 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
75 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
76 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
77 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
78
79 /* Unlock all MCU_CTRL_MMR0 module registers */
80 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
81 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
82 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
83 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
84 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
85
86 /* Unlock all CTRL_MMR0 module registers */
87 mmr_unlock(CTRL_MMR0_BASE, 0);
88 mmr_unlock(CTRL_MMR0_BASE, 1);
89 mmr_unlock(CTRL_MMR0_BASE, 2);
90 mmr_unlock(CTRL_MMR0_BASE, 3);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053091 mmr_unlock(CTRL_MMR0_BASE, 5);
Lokesh Vutlad5bc6862020-08-05 22:44:20 +053092 if (soc_is_j721e())
93 mmr_unlock(CTRL_MMR0_BASE, 6);
Andreas Dannenberg660aa462019-06-13 10:29:44 +053094 mmr_unlock(CTRL_MMR0_BASE, 7);
95}
96
Faiz Abbas68393212020-02-26 13:44:36 +053097#if defined(CONFIG_K3_LOAD_SYSFW)
98void k3_mmc_stop_clock(void)
99{
100 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
101 struct mmc *mmc = find_mmc_device(0);
102
103 if (!mmc)
104 return;
105
106 mmc->saved_clock = mmc->clock;
107 mmc_set_clock(mmc, 0, true);
108 }
109}
110
111void k3_mmc_restart_clock(void)
112{
113 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
114 struct mmc *mmc = find_mmc_device(0);
115
116 if (!mmc)
117 return;
118
119 mmc_set_clock(mmc, mmc->saved_clock, false);
120 }
121}
122#endif
123
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530124/*
125 * This uninitialized global variable would normal end up in the .bss section,
126 * but the .bss is cleared between writing and reading this variable, so move
127 * it to the .data section.
128 */
Marek BehĂșn4bebdd32021-05-20 13:23:52 +0200129u32 bootindex __section(".data");
130static struct rom_extended_boot_data bootdata __section(".data");
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530131
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530132static void store_boot_info_from_rom(void)
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530133{
134 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530135 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
136 sizeof(struct rom_extended_boot_data));
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530137}
138
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530139#ifdef CONFIG_SPL_OF_LIST
140void do_dt_magic(void)
141{
142 int ret, rescan, mmc_dev = -1;
143 static struct mmc *mmc;
144
145 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
146 do_board_detect();
147
148 /*
149 * Board detection has been done.
150 * Let us see if another dtb wouldn't be a better match
151 * for our board
152 */
153 if (IS_ENABLED(CONFIG_CPU_V7R)) {
154 ret = fdtdec_resetup(&rescan);
155 if (!ret && rescan) {
156 dm_uninit();
157 dm_init_and_scan(true);
158 }
159 }
160
161 /*
162 * Because of multi DTB configuration, the MMC device has
163 * to be re-initialized after reconfiguring FDT inorder to
164 * boot from MMC. Do this when boot mode is MMC and ROM has
165 * not loaded SYSFW.
166 */
167 switch (spl_boot_device()) {
168 case BOOT_DEVICE_MMC1:
169 mmc_dev = 0;
170 break;
171 case BOOT_DEVICE_MMC2:
172 case BOOT_DEVICE_MMC2_2:
173 mmc_dev = 1;
174 break;
175 }
176
177 if (mmc_dev > 0 && !is_rom_loaded_sysfw(&bootdata)) {
178 ret = mmc_init_device(mmc_dev);
179 if (!ret) {
180 mmc = find_mmc_device(mmc_dev);
181 if (mmc) {
182 ret = mmc_init(mmc);
183 if (ret) {
184 printf("mmc init failed with error: %d\n", ret);
185 }
186 }
187 }
188 }
189}
190#endif
191
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530192void board_init_f(ulong dummy)
193{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530194#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530195 struct udevice *dev;
196 int ret;
197#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530198 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530199 * Cannot delay this further as there is a chance that
200 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530201 */
Lokesh Vutla8e7bd012020-08-05 22:44:22 +0530202 store_boot_info_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530203
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530204 /* Make all control module registers accessible */
205 ctrl_mmr_unlock();
206
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530207#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530208 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530209 setup_k3_mpu_regions();
210#endif
211
212 /* Init DM early */
213 spl_early_init();
214
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530215#ifdef CONFIG_K3_LOAD_SYSFW
216 /*
217 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
218 * regardless of the result of pinctrl. Do this without probing the
219 * device, but instead by searching the device that would request the
220 * given sequence number if probed. The UART will be used by the system
221 * firmware (SYSFW) image for various purposes and SYSFW depends on us
222 * to initialize its pin settings.
223 */
Simon Glass07e13382020-12-16 21:20:29 -0700224 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530225 if (!ret)
226 pinctrl_select_state(dev, "default");
227
228 /*
229 * Load, start up, and configure system controller firmware. Provide
230 * the U-Boot console init function to the SYSFW post-PM configuration
231 * callback hook, effectively switching on (or over) the console
232 * output.
233 */
Lokesh Vutla8be6bbf2020-08-05 22:44:23 +0530234 k3_sysfw_loader(is_rom_loaded_sysfw(&bootdata),
235 k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530236
Sinthu Rajaa79cbe32022-02-09 15:06:53 +0530237#ifdef CONFIG_SPL_OF_LIST
238 do_dt_magic();
239#endif
240
Dave Gerlach9cda54d2021-06-11 11:45:23 +0300241 /*
242 * Force probe of clk_k3 driver here to ensure basic default clock
243 * configuration is always done.
244 */
245 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
246 ret = uclass_get_device_by_driver(UCLASS_CLK,
247 DM_DRIVER_GET(ti_clk),
248 &dev);
249 if (ret)
250 panic("Failed to initialize clk-k3!\n");
251 }
252
Faiz Abbas68393212020-02-26 13:44:36 +0530253 /* Prepare console output */
254 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500255
256 /* Disable ROM configured firewalls right after loading sysfw */
257#ifdef CONFIG_TI_SECURE_DEVICE
258 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
259 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
260 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
261 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
262 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
263 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
264 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
265#endif
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530266#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530267 /* Prepare console output */
268 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530269#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530270
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530271 /* Output System Firmware version info */
272 k3_sysfw_print_ver();
273
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530274 /* Perform EEPROM-based board detection */
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530275 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
276 do_board_detect();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530277
Keerthy0b01f662019-10-24 15:00:53 +0530278#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700279 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy0b01f662019-10-24 15:00:53 +0530280 &dev);
281 if (ret)
282 printf("AVS init failed: %d\n", ret);
283#endif
284
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530285#if defined(CONFIG_K3_J721E_DDRSS)
286 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
287 if (ret)
288 panic("DRAM init failed: %d\n", ret);
289#endif
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200290 spl_enable_dcache();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530291}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530292
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100293u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Lokesh Vutla6edde292019-06-13 10:29:43 +0530294{
295 switch (boot_device) {
296 case BOOT_DEVICE_MMC1:
297 return MMCSD_MODE_EMMCBOOT;
298 case BOOT_DEVICE_MMC2:
299 return MMCSD_MODE_FS;
300 default:
301 return MMCSD_MODE_RAW;
302 }
303}
304
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530305static u32 __get_backup_bootmedia(u32 main_devstat)
306{
307 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
308 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
309
310 switch (bkup_boot) {
311 case BACKUP_BOOT_DEVICE_USB:
312 return BOOT_DEVICE_DFU;
313 case BACKUP_BOOT_DEVICE_UART:
314 return BOOT_DEVICE_UART;
315 case BACKUP_BOOT_DEVICE_ETHERNET:
316 return BOOT_DEVICE_ETHERNET;
317 case BACKUP_BOOT_DEVICE_MMC2:
318 {
319 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
320 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
321 if (port == 0x0)
322 return BOOT_DEVICE_MMC1;
323 return BOOT_DEVICE_MMC2;
324 }
325 case BACKUP_BOOT_DEVICE_SPI:
326 return BOOT_DEVICE_SPI;
327 case BACKUP_BOOT_DEVICE_I2C:
328 return BOOT_DEVICE_I2C;
329 }
330
331 return BOOT_DEVICE_RAM;
332}
333
Lokesh Vutla6edde292019-06-13 10:29:43 +0530334static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
335{
336
337 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
338 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
339
340 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
341 BOOT_MODE_B_SHIFT;
342
343 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
344 bootmode = BOOT_DEVICE_SPI;
345
346 if (bootmode == BOOT_DEVICE_MMC2) {
347 u32 port = (main_devstat &
348 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
349 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
350 if (port == 0x0)
351 bootmode = BOOT_DEVICE_MMC1;
352 }
353
354 return bootmode;
355}
356
Vaishnav Achath146b6c12022-06-03 11:32:16 +0530357u32 spl_spi_boot_bus(void)
358{
359 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
360 u32 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
361 u32 bootmode = ((wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
362 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT) |
363 ((main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) << BOOT_MODE_B_SHIFT);
364
365 return (bootmode == BOOT_DEVICE_QSPI) ? 1 : 0;
366}
367
Lokesh Vutla6edde292019-06-13 10:29:43 +0530368u32 spl_boot_device(void)
369{
370 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
371 u32 main_devstat;
372
373 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
374 printf("ERROR: MCU only boot is not yet supported\n");
375 return BOOT_DEVICE_RAM;
376 }
377
378 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
379 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
380
Andreas Dannenbergee0f5e62020-05-16 21:05:01 +0530381 if (bootindex == K3_PRIMARY_BOOTMODE)
382 return __get_primary_bootmedia(main_devstat, wkup_devstat);
383 else
384 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla6edde292019-06-13 10:29:43 +0530385}
Lokesh Vutla96c11f42019-06-13 10:29:46 +0530386
387#ifdef CONFIG_SYS_K3_SPL_ATF
388
389#define J721E_DEV_MCU_RTI0 262
390#define J721E_DEV_MCU_RTI1 263
391#define J721E_DEV_MCU_ARMSS0_CPU0 250
392#define J721E_DEV_MCU_ARMSS0_CPU1 251
393
394void release_resources_for_core_shutdown(void)
395{
396 struct ti_sci_handle *ti_sci;
397 struct ti_sci_dev_ops *dev_ops;
398 struct ti_sci_proc_ops *proc_ops;
399 int ret;
400 u32 i;
401
402 const u32 put_device_ids[] = {
403 J721E_DEV_MCU_RTI0,
404 J721E_DEV_MCU_RTI1,
405 };
406
407 ti_sci = get_ti_sci_handle();
408 dev_ops = &ti_sci->ops.dev_ops;
409 proc_ops = &ti_sci->ops.proc_ops;
410
411 /* Iterate through list of devices to put (shutdown) */
412 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
413 u32 id = put_device_ids[i];
414
415 ret = dev_ops->put_device(ti_sci, id);
416 if (ret)
417 panic("Failed to put device %u (%d)\n", id, ret);
418 }
419
420 const u32 put_core_ids[] = {
421 J721E_DEV_MCU_ARMSS0_CPU1,
422 J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
423 };
424
425 /* Iterate through list of cores to put (shutdown) */
426 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
427 u32 id = put_core_ids[i];
428
429 /*
430 * Queue up the core shutdown request. Note that this call
431 * needs to be followed up by an actual invocation of an WFE
432 * or WFI CPU instruction.
433 */
434 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
435 if (ret)
436 panic("Failed sending core %u shutdown message (%d)\n",
437 id, ret);
438 }
439}
440#endif