blob: 3b15da2d7cdf68fd67fb16a63dfb7765d8f8ead4 [file] [log] [blame]
Lokesh Vutlac2562d72019-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 Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Lokesh Vutlac2562d72019-06-13 10:29:42 +053011#include <spl.h>
12#include <asm/io.h>
13#include <asm/armv7_mpu.h>
Lokesh Vutla0a704922019-06-13 10:29:43 +053014#include <asm/arch/hardware.h>
Andreas Dannenberg9d1303b2019-06-13 10:29:47 +053015#include <asm/arch/sysfw-loader.h>
Lokesh Vutlac2562d72019-06-13 10:29:42 +053016#include "common.h"
Lokesh Vutla9c0ff862019-06-13 10:29:46 +053017#include <asm/arch/sys_proto.h>
18#include <linux/soc/ti/ti_sci_protocol.h>
Andreas Dannenberg9d1303b2019-06-13 10:29:47 +053019#include <dm.h>
20#include <dm/uclass-internal.h>
21#include <dm/pinctrl.h>
Faiz Abbasd45ffb72020-02-26 13:44:36 +053022#include <mmc.h>
Keerthy3ab34bc2020-02-12 13:55:04 +053023#include <remoteproc.h>
Lokesh Vutlac2562d72019-06-13 10:29:42 +053024
25#ifdef CONFIG_SPL_BUILD
Andrew F. Davisea70da12020-01-10 14:35:21 -050026#ifdef CONFIG_K3_LOAD_SYSFW
27#ifdef CONFIG_TI_SECURE_DEVICE
28struct fwl_data cbass_hc_cfg0_fwls[] = {
29 { "PCIE0_CFG", 2560, 8 },
30 { "PCIE1_CFG", 2561, 8 },
31 { "USB3SS0_CORE", 2568, 4 },
32 { "USB3SS1_CORE", 2570, 4 },
33 { "EMMC8SS0_CFG", 2576, 4 },
34 { "UFS_HCI0_CFG", 2580, 4 },
35 { "SERDES0", 2584, 1 },
36 { "SERDES1", 2585, 1 },
37}, cbass_hc0_fwls[] = {
38 { "PCIE0_HP", 2528, 24 },
39 { "PCIE0_LP", 2529, 24 },
40 { "PCIE1_HP", 2530, 24 },
41 { "PCIE1_LP", 2531, 24 },
42}, cbass_rc_cfg0_fwls[] = {
43 { "EMMCSD4SS0_CFG", 2380, 4 },
44}, cbass_rc0_fwls[] = {
45 { "GPMC0", 2310, 8 },
46}, infra_cbass0_fwls[] = {
47 { "PLL_MMR0", 8, 26 },
48 { "CTRL_MMR0", 9, 16 },
49}, mcu_cbass0_fwls[] = {
50 { "MCU_R5FSS0_CORE0", 1024, 4 },
51 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
52 { "MCU_R5FSS0_CORE1", 1028, 4 },
53 { "MCU_FSS0_CFG", 1032, 12 },
54 { "MCU_FSS0_S1", 1033, 8 },
55 { "MCU_FSS0_S0", 1036, 8 },
56 { "MCU_PSROM49152X32", 1048, 1 },
57 { "MCU_MSRAM128KX64", 1050, 8 },
58 { "MCU_CTRL_MMR0", 1200, 8 },
59 { "MCU_PLL_MMR0", 1201, 3 },
60 { "MCU_CPSW0", 1220, 2 },
61}, wkup_cbass0_fwls[] = {
62 { "WKUP_CTRL_MMR0", 131, 16 },
63};
64#endif
65#endif
66
Andreas Dannenbergb73fcbc2019-06-13 10:29:44 +053067static void ctrl_mmr_unlock(void)
68{
69 /* Unlock all WKUP_CTRL_MMR0 module registers */
70 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
71 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
72 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
73 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
74 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
75 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
76 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
77
78 /* Unlock all MCU_CTRL_MMR0 module registers */
79 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
80 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
81 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
82 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
83 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
84
85 /* Unlock all CTRL_MMR0 module registers */
86 mmr_unlock(CTRL_MMR0_BASE, 0);
87 mmr_unlock(CTRL_MMR0_BASE, 1);
88 mmr_unlock(CTRL_MMR0_BASE, 2);
89 mmr_unlock(CTRL_MMR0_BASE, 3);
90 mmr_unlock(CTRL_MMR0_BASE, 4);
91 mmr_unlock(CTRL_MMR0_BASE, 5);
92 mmr_unlock(CTRL_MMR0_BASE, 6);
93 mmr_unlock(CTRL_MMR0_BASE, 7);
94}
95
Faiz Abbasd45ffb72020-02-26 13:44:36 +053096#if defined(CONFIG_K3_LOAD_SYSFW)
97void k3_mmc_stop_clock(void)
98{
99 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
100 struct mmc *mmc = find_mmc_device(0);
101
102 if (!mmc)
103 return;
104
105 mmc->saved_clock = mmc->clock;
106 mmc_set_clock(mmc, 0, true);
107 }
108}
109
110void k3_mmc_restart_clock(void)
111{
112 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
113 struct mmc *mmc = find_mmc_device(0);
114
115 if (!mmc)
116 return;
117
118 mmc_set_clock(mmc, mmc->saved_clock, false);
119 }
120}
121#endif
122
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +0530123/*
124 * This uninitialized global variable would normal end up in the .bss section,
125 * but the .bss is cleared between writing and reading this variable, so move
126 * it to the .data section.
127 */
128u32 bootindex __attribute__((section(".data")));
129
130static void store_boot_index_from_rom(void)
131{
132 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
133}
134
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530135void board_init_f(ulong dummy)
136{
Lokesh Vutla22b54802019-10-07 19:26:38 +0530137#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg9d1303b2019-06-13 10:29:47 +0530138 struct udevice *dev;
139 int ret;
140#endif
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530141 /*
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +0530142 * Cannot delay this further as there is a chance that
143 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530144 */
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +0530145 store_boot_index_from_rom();
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530146
Andreas Dannenbergb73fcbc2019-06-13 10:29:44 +0530147 /* Make all control module registers accessible */
148 ctrl_mmr_unlock();
149
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530150#ifdef CONFIG_CPU_V7R
Lokesh Vutla40109f42019-12-31 15:49:55 +0530151 disable_linefill_optimization();
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530152 setup_k3_mpu_regions();
153#endif
154
155 /* Init DM early */
156 spl_early_init();
157
Andreas Dannenberg9d1303b2019-06-13 10:29:47 +0530158#ifdef CONFIG_K3_LOAD_SYSFW
159 /*
160 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
161 * regardless of the result of pinctrl. Do this without probing the
162 * device, but instead by searching the device that would request the
163 * given sequence number if probed. The UART will be used by the system
164 * firmware (SYSFW) image for various purposes and SYSFW depends on us
165 * to initialize its pin settings.
166 */
167 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
168 if (!ret)
169 pinctrl_select_state(dev, "default");
170
171 /*
172 * Load, start up, and configure system controller firmware. Provide
173 * the U-Boot console init function to the SYSFW post-PM configuration
174 * callback hook, effectively switching on (or over) the console
175 * output.
176 */
Lokesh Vutladc57a552020-08-05 22:44:18 +0530177 k3_sysfw_loader(false, k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbasd45ffb72020-02-26 13:44:36 +0530178
179 /* Prepare console output */
180 preloader_console_init();
Andrew F. Davisea70da12020-01-10 14:35:21 -0500181
182 /* Disable ROM configured firewalls right after loading sysfw */
183#ifdef CONFIG_TI_SECURE_DEVICE
184 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
185 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
186 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
187 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
188 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
189 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
190 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
191#endif
Andreas Dannenberg9d1303b2019-06-13 10:29:47 +0530192#else
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530193 /* Prepare console output */
194 preloader_console_init();
Andreas Dannenberg9d1303b2019-06-13 10:29:47 +0530195#endif
Lokesh Vutla22b54802019-10-07 19:26:38 +0530196
Lokesh Vutla6e44aeb2020-03-10 16:50:58 +0530197 /* Output System Firmware version info */
198 k3_sysfw_print_ver();
199
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530200 /* Perform EEPROM-based board detection */
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530201 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
202 do_board_detect();
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530203
Keerthy7b134932019-10-24 15:00:53 +0530204#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
205 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
206 &dev);
207 if (ret)
208 printf("AVS init failed: %d\n", ret);
209#endif
210
Lokesh Vutla22b54802019-10-07 19:26:38 +0530211#if defined(CONFIG_K3_J721E_DDRSS)
212 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
213 if (ret)
214 panic("DRAM init failed: %d\n", ret);
215#endif
Jan Kiszkac02712a2020-05-18 07:57:22 +0200216 spl_enable_dcache();
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530217}
Lokesh Vutla0a704922019-06-13 10:29:43 +0530218
Harald Seilere9759062020-04-15 11:33:30 +0200219u32 spl_mmc_boot_mode(const u32 boot_device)
Lokesh Vutla0a704922019-06-13 10:29:43 +0530220{
221 switch (boot_device) {
222 case BOOT_DEVICE_MMC1:
223 return MMCSD_MODE_EMMCBOOT;
224 case BOOT_DEVICE_MMC2:
225 return MMCSD_MODE_FS;
226 default:
227 return MMCSD_MODE_RAW;
228 }
229}
230
Andreas Dannenberg7bf82cc2020-05-16 21:05:01 +0530231static u32 __get_backup_bootmedia(u32 main_devstat)
232{
233 u32 bkup_boot = (main_devstat & MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
234 MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
235
236 switch (bkup_boot) {
237 case BACKUP_BOOT_DEVICE_USB:
238 return BOOT_DEVICE_DFU;
239 case BACKUP_BOOT_DEVICE_UART:
240 return BOOT_DEVICE_UART;
241 case BACKUP_BOOT_DEVICE_ETHERNET:
242 return BOOT_DEVICE_ETHERNET;
243 case BACKUP_BOOT_DEVICE_MMC2:
244 {
245 u32 port = (main_devstat & MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
246 MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
247 if (port == 0x0)
248 return BOOT_DEVICE_MMC1;
249 return BOOT_DEVICE_MMC2;
250 }
251 case BACKUP_BOOT_DEVICE_SPI:
252 return BOOT_DEVICE_SPI;
253 case BACKUP_BOOT_DEVICE_I2C:
254 return BOOT_DEVICE_I2C;
255 }
256
257 return BOOT_DEVICE_RAM;
258}
259
Lokesh Vutla0a704922019-06-13 10:29:43 +0530260static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
261{
262
263 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
264 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
265
266 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
267 BOOT_MODE_B_SHIFT;
268
269 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
270 bootmode = BOOT_DEVICE_SPI;
271
272 if (bootmode == BOOT_DEVICE_MMC2) {
273 u32 port = (main_devstat &
274 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
275 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
276 if (port == 0x0)
277 bootmode = BOOT_DEVICE_MMC1;
278 }
279
280 return bootmode;
281}
282
283u32 spl_boot_device(void)
284{
285 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
286 u32 main_devstat;
287
288 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
289 printf("ERROR: MCU only boot is not yet supported\n");
290 return BOOT_DEVICE_RAM;
291 }
292
293 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
294 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
295
Andreas Dannenberg7bf82cc2020-05-16 21:05:01 +0530296 if (bootindex == K3_PRIMARY_BOOTMODE)
297 return __get_primary_bootmedia(main_devstat, wkup_devstat);
298 else
299 return __get_backup_bootmedia(main_devstat);
Lokesh Vutla0a704922019-06-13 10:29:43 +0530300}
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530301#endif
Lokesh Vutla9c0ff862019-06-13 10:29:46 +0530302
303#ifdef CONFIG_SYS_K3_SPL_ATF
304
305#define J721E_DEV_MCU_RTI0 262
306#define J721E_DEV_MCU_RTI1 263
307#define J721E_DEV_MCU_ARMSS0_CPU0 250
308#define J721E_DEV_MCU_ARMSS0_CPU1 251
309
310void release_resources_for_core_shutdown(void)
311{
312 struct ti_sci_handle *ti_sci;
313 struct ti_sci_dev_ops *dev_ops;
314 struct ti_sci_proc_ops *proc_ops;
315 int ret;
316 u32 i;
317
318 const u32 put_device_ids[] = {
319 J721E_DEV_MCU_RTI0,
320 J721E_DEV_MCU_RTI1,
321 };
322
323 ti_sci = get_ti_sci_handle();
324 dev_ops = &ti_sci->ops.dev_ops;
325 proc_ops = &ti_sci->ops.proc_ops;
326
327 /* Iterate through list of devices to put (shutdown) */
328 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
329 u32 id = put_device_ids[i];
330
331 ret = dev_ops->put_device(ti_sci, id);
332 if (ret)
333 panic("Failed to put device %u (%d)\n", id, ret);
334 }
335
336 const u32 put_core_ids[] = {
337 J721E_DEV_MCU_ARMSS0_CPU1,
338 J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
339 };
340
341 /* Iterate through list of cores to put (shutdown) */
342 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
343 u32 id = put_core_ids[i];
344
345 /*
346 * Queue up the core shutdown request. Note that this call
347 * needs to be followed up by an actual invocation of an WFE
348 * or WFI CPU instruction.
349 */
350 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
351 if (ret)
352 panic("Failed sending core %u shutdown message (%d)\n",
353 id, ret);
354 }
355}
356#endif
Keerthy3ab34bc2020-02-12 13:55:04 +0530357
358#ifdef CONFIG_SYS_K3_SPL_ATF
359void start_non_linux_remote_cores(void)
360{
361 int size = 0, ret;
362 u32 loadaddr = 0;
363
Lokesh Vutla2a18be72020-08-05 22:44:19 +0530364 if (!soc_is_j721e())
365 return;
366
Keerthy3ab34bc2020-02-12 13:55:04 +0530367 size = load_firmware("name_mainr5f0_0fw", "addr_mainr5f0_0load",
368 &loadaddr);
369 if (size <= 0)
370 goto err_load;
371
372 /* assuming remoteproc 2 is aliased for the needed remotecore */
373 ret = rproc_load(2, loadaddr, size);
374 if (ret) {
375 printf("Firmware failed to start on rproc (%d)\n", ret);
376 goto err_load;
377 }
378
379 ret = rproc_start(2);
380 if (ret) {
381 printf("Firmware init failed on rproc (%d)\n", ret);
382 goto err_load;
383 }
384
385 printf("Remoteproc 2 started successfully\n");
386
387 return;
388
389err_load:
390 rproc_reset(2);
391}
392#endif