blob: f7f7398081483f2025584198d12a020cb57a97a9 [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>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm/armv7_mpu.h>
Lokesh Vutla6edde292019-06-13 10:29:43 +053013#include <asm/arch/hardware.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053014#include <asm/arch/sysfw-loader.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053015#include "common.h"
Lokesh Vutla96c11f42019-06-13 10:29:46 +053016#include <asm/arch/sys_proto.h>
17#include <linux/soc/ti/ti_sci_protocol.h>
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +053018#include <dm.h>
19#include <dm/uclass-internal.h>
20#include <dm/pinctrl.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053021
22#ifdef CONFIG_SPL_BUILD
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050023#ifdef CONFIG_K3_LOAD_SYSFW
24#ifdef CONFIG_TI_SECURE_DEVICE
25struct fwl_data cbass_hc_cfg0_fwls[] = {
26 { "PCIE0_CFG", 2560, 8 },
27 { "PCIE1_CFG", 2561, 8 },
28 { "USB3SS0_CORE", 2568, 4 },
29 { "USB3SS1_CORE", 2570, 4 },
30 { "EMMC8SS0_CFG", 2576, 4 },
31 { "UFS_HCI0_CFG", 2580, 4 },
32 { "SERDES0", 2584, 1 },
33 { "SERDES1", 2585, 1 },
34}, cbass_hc0_fwls[] = {
35 { "PCIE0_HP", 2528, 24 },
36 { "PCIE0_LP", 2529, 24 },
37 { "PCIE1_HP", 2530, 24 },
38 { "PCIE1_LP", 2531, 24 },
39}, cbass_rc_cfg0_fwls[] = {
40 { "EMMCSD4SS0_CFG", 2380, 4 },
41}, cbass_rc0_fwls[] = {
42 { "GPMC0", 2310, 8 },
43}, infra_cbass0_fwls[] = {
44 { "PLL_MMR0", 8, 26 },
45 { "CTRL_MMR0", 9, 16 },
46}, mcu_cbass0_fwls[] = {
47 { "MCU_R5FSS0_CORE0", 1024, 4 },
48 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
49 { "MCU_R5FSS0_CORE1", 1028, 4 },
50 { "MCU_FSS0_CFG", 1032, 12 },
51 { "MCU_FSS0_S1", 1033, 8 },
52 { "MCU_FSS0_S0", 1036, 8 },
53 { "MCU_PSROM49152X32", 1048, 1 },
54 { "MCU_MSRAM128KX64", 1050, 8 },
55 { "MCU_CTRL_MMR0", 1200, 8 },
56 { "MCU_PLL_MMR0", 1201, 3 },
57 { "MCU_CPSW0", 1220, 2 },
58}, wkup_cbass0_fwls[] = {
59 { "WKUP_CTRL_MMR0", 131, 16 },
60};
61#endif
62#endif
63
Andreas Dannenberg660aa462019-06-13 10:29:44 +053064static void mmr_unlock(u32 base, u32 partition)
65{
66 /* Translate the base address */
67 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
68
69 /* Unlock the requested partition if locked using two-step sequence */
70 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
71 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
72}
73
74static void ctrl_mmr_unlock(void)
75{
76 /* Unlock all WKUP_CTRL_MMR0 module registers */
77 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
78 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
79 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
80 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
81 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
82 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
83 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
84
85 /* Unlock all MCU_CTRL_MMR0 module registers */
86 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
87 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
88 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
89 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
90 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
91
92 /* Unlock all CTRL_MMR0 module registers */
93 mmr_unlock(CTRL_MMR0_BASE, 0);
94 mmr_unlock(CTRL_MMR0_BASE, 1);
95 mmr_unlock(CTRL_MMR0_BASE, 2);
96 mmr_unlock(CTRL_MMR0_BASE, 3);
97 mmr_unlock(CTRL_MMR0_BASE, 4);
98 mmr_unlock(CTRL_MMR0_BASE, 5);
99 mmr_unlock(CTRL_MMR0_BASE, 6);
100 mmr_unlock(CTRL_MMR0_BASE, 7);
101}
102
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530103/*
104 * This uninitialized global variable would normal end up in the .bss section,
105 * but the .bss is cleared between writing and reading this variable, so move
106 * it to the .data section.
107 */
108u32 bootindex __attribute__((section(".data")));
109
110static void store_boot_index_from_rom(void)
111{
112 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
113}
114
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530115void board_init_f(ulong dummy)
116{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530117#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530118 struct udevice *dev;
119 int ret;
120#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530121 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530122 * Cannot delay this further as there is a chance that
123 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530124 */
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530125 store_boot_index_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530126
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530127 /* Make all control module registers accessible */
128 ctrl_mmr_unlock();
129
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530130#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530131 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530132 setup_k3_mpu_regions();
133#endif
134
135 /* Init DM early */
136 spl_early_init();
137
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530138#ifdef CONFIG_K3_LOAD_SYSFW
139 /*
140 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
141 * regardless of the result of pinctrl. Do this without probing the
142 * device, but instead by searching the device that would request the
143 * given sequence number if probed. The UART will be used by the system
144 * firmware (SYSFW) image for various purposes and SYSFW depends on us
145 * to initialize its pin settings.
146 */
147 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
148 if (!ret)
149 pinctrl_select_state(dev, "default");
150
151 /*
152 * Load, start up, and configure system controller firmware. Provide
153 * the U-Boot console init function to the SYSFW post-PM configuration
154 * callback hook, effectively switching on (or over) the console
155 * output.
156 */
157 k3_sysfw_loader(preloader_console_init);
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500158
159 /* Disable ROM configured firewalls right after loading sysfw */
160#ifdef CONFIG_TI_SECURE_DEVICE
161 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
162 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
163 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
164 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
165 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
166 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
167 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
168#endif
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530169#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530170 /* Prepare console output */
171 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530172#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530173
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530174 /* Perform EEPROM-based board detection */
175 do_board_detect();
176
Keerthy0b01f662019-10-24 15:00:53 +0530177#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
178 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
179 &dev);
180 if (ret)
181 printf("AVS init failed: %d\n", ret);
182#endif
183
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530184#if defined(CONFIG_K3_J721E_DDRSS)
185 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
186 if (ret)
187 panic("DRAM init failed: %d\n", ret);
188#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530189}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530190
191u32 spl_boot_mode(const u32 boot_device)
192{
193 switch (boot_device) {
194 case BOOT_DEVICE_MMC1:
195 return MMCSD_MODE_EMMCBOOT;
196 case BOOT_DEVICE_MMC2:
197 return MMCSD_MODE_FS;
198 default:
199 return MMCSD_MODE_RAW;
200 }
201}
202
203static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
204{
205
206 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
207 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
208
209 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
210 BOOT_MODE_B_SHIFT;
211
212 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
213 bootmode = BOOT_DEVICE_SPI;
214
215 if (bootmode == BOOT_DEVICE_MMC2) {
216 u32 port = (main_devstat &
217 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
218 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
219 if (port == 0x0)
220 bootmode = BOOT_DEVICE_MMC1;
221 }
222
223 return bootmode;
224}
225
226u32 spl_boot_device(void)
227{
228 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
229 u32 main_devstat;
230
231 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
232 printf("ERROR: MCU only boot is not yet supported\n");
233 return BOOT_DEVICE_RAM;
234 }
235
236 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
237 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
238
239 /* ToDo: Add support for backup boot media */
240 return __get_primary_bootmedia(main_devstat, wkup_devstat);
241}
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530242#endif
Lokesh Vutla96c11f42019-06-13 10:29:46 +0530243
244#ifdef CONFIG_SYS_K3_SPL_ATF
245
246#define J721E_DEV_MCU_RTI0 262
247#define J721E_DEV_MCU_RTI1 263
248#define J721E_DEV_MCU_ARMSS0_CPU0 250
249#define J721E_DEV_MCU_ARMSS0_CPU1 251
250
251void release_resources_for_core_shutdown(void)
252{
253 struct ti_sci_handle *ti_sci;
254 struct ti_sci_dev_ops *dev_ops;
255 struct ti_sci_proc_ops *proc_ops;
256 int ret;
257 u32 i;
258
259 const u32 put_device_ids[] = {
260 J721E_DEV_MCU_RTI0,
261 J721E_DEV_MCU_RTI1,
262 };
263
264 ti_sci = get_ti_sci_handle();
265 dev_ops = &ti_sci->ops.dev_ops;
266 proc_ops = &ti_sci->ops.proc_ops;
267
268 /* Iterate through list of devices to put (shutdown) */
269 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
270 u32 id = put_device_ids[i];
271
272 ret = dev_ops->put_device(ti_sci, id);
273 if (ret)
274 panic("Failed to put device %u (%d)\n", id, ret);
275 }
276
277 const u32 put_core_ids[] = {
278 J721E_DEV_MCU_ARMSS0_CPU1,
279 J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
280 };
281
282 /* Iterate through list of cores to put (shutdown) */
283 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
284 u32 id = put_core_ids[i];
285
286 /*
287 * Queue up the core shutdown request. Note that this call
288 * needs to be followed up by an actual invocation of an WFE
289 * or WFI CPU instruction.
290 */
291 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
292 if (ret)
293 panic("Failed sending core %u shutdown message (%d)\n",
294 id, ret);
295 }
296}
297#endif