blob: 0994522f6c30ceed1e2bf345d32409081be8f1a8 [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>
Faiz Abbas68393212020-02-26 13:44:36 +053021#include <mmc.h>
Lokesh Vutlaa2285322019-06-13 10:29:42 +053022
23#ifdef CONFIG_SPL_BUILD
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050024#ifdef CONFIG_K3_LOAD_SYSFW
25#ifdef CONFIG_TI_SECURE_DEVICE
26struct fwl_data cbass_hc_cfg0_fwls[] = {
27 { "PCIE0_CFG", 2560, 8 },
28 { "PCIE1_CFG", 2561, 8 },
29 { "USB3SS0_CORE", 2568, 4 },
30 { "USB3SS1_CORE", 2570, 4 },
31 { "EMMC8SS0_CFG", 2576, 4 },
32 { "UFS_HCI0_CFG", 2580, 4 },
33 { "SERDES0", 2584, 1 },
34 { "SERDES1", 2585, 1 },
35}, cbass_hc0_fwls[] = {
36 { "PCIE0_HP", 2528, 24 },
37 { "PCIE0_LP", 2529, 24 },
38 { "PCIE1_HP", 2530, 24 },
39 { "PCIE1_LP", 2531, 24 },
40}, cbass_rc_cfg0_fwls[] = {
41 { "EMMCSD4SS0_CFG", 2380, 4 },
42}, cbass_rc0_fwls[] = {
43 { "GPMC0", 2310, 8 },
44}, infra_cbass0_fwls[] = {
45 { "PLL_MMR0", 8, 26 },
46 { "CTRL_MMR0", 9, 16 },
47}, mcu_cbass0_fwls[] = {
48 { "MCU_R5FSS0_CORE0", 1024, 4 },
49 { "MCU_R5FSS0_CORE0_CFG", 1025, 2 },
50 { "MCU_R5FSS0_CORE1", 1028, 4 },
51 { "MCU_FSS0_CFG", 1032, 12 },
52 { "MCU_FSS0_S1", 1033, 8 },
53 { "MCU_FSS0_S0", 1036, 8 },
54 { "MCU_PSROM49152X32", 1048, 1 },
55 { "MCU_MSRAM128KX64", 1050, 8 },
56 { "MCU_CTRL_MMR0", 1200, 8 },
57 { "MCU_PLL_MMR0", 1201, 3 },
58 { "MCU_CPSW0", 1220, 2 },
59}, wkup_cbass0_fwls[] = {
60 { "WKUP_CTRL_MMR0", 131, 16 },
61};
62#endif
63#endif
64
Andreas Dannenberg660aa462019-06-13 10:29:44 +053065static void mmr_unlock(u32 base, u32 partition)
66{
67 /* Translate the base address */
68 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
69
70 /* Unlock the requested partition if locked using two-step sequence */
71 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
72 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
73}
74
75static void ctrl_mmr_unlock(void)
76{
77 /* Unlock all WKUP_CTRL_MMR0 module registers */
78 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
79 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
80 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
81 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
82 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
83 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
84 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
85
86 /* Unlock all MCU_CTRL_MMR0 module registers */
87 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
88 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
89 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
90 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
91 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
92
93 /* Unlock all CTRL_MMR0 module registers */
94 mmr_unlock(CTRL_MMR0_BASE, 0);
95 mmr_unlock(CTRL_MMR0_BASE, 1);
96 mmr_unlock(CTRL_MMR0_BASE, 2);
97 mmr_unlock(CTRL_MMR0_BASE, 3);
98 mmr_unlock(CTRL_MMR0_BASE, 4);
99 mmr_unlock(CTRL_MMR0_BASE, 5);
100 mmr_unlock(CTRL_MMR0_BASE, 6);
101 mmr_unlock(CTRL_MMR0_BASE, 7);
102}
103
Faiz Abbas68393212020-02-26 13:44:36 +0530104#if defined(CONFIG_K3_LOAD_SYSFW)
105void k3_mmc_stop_clock(void)
106{
107 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
108 struct mmc *mmc = find_mmc_device(0);
109
110 if (!mmc)
111 return;
112
113 mmc->saved_clock = mmc->clock;
114 mmc_set_clock(mmc, 0, true);
115 }
116}
117
118void k3_mmc_restart_clock(void)
119{
120 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
121 struct mmc *mmc = find_mmc_device(0);
122
123 if (!mmc)
124 return;
125
126 mmc_set_clock(mmc, mmc->saved_clock, false);
127 }
128}
129#endif
130
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530131/*
132 * This uninitialized global variable would normal end up in the .bss section,
133 * but the .bss is cleared between writing and reading this variable, so move
134 * it to the .data section.
135 */
136u32 bootindex __attribute__((section(".data")));
137
138static void store_boot_index_from_rom(void)
139{
140 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
141}
142
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530143void board_init_f(ulong dummy)
144{
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530145#if defined(CONFIG_K3_J721E_DDRSS) || defined(CONFIG_K3_LOAD_SYSFW)
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530146 struct udevice *dev;
147 int ret;
148#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530149 /*
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530150 * Cannot delay this further as there is a chance that
151 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530152 */
Andreas Dannenbergb8267412019-06-13 10:29:45 +0530153 store_boot_index_from_rom();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530154
Andreas Dannenberg660aa462019-06-13 10:29:44 +0530155 /* Make all control module registers accessible */
156 ctrl_mmr_unlock();
157
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530158#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530159 disable_linefill_optimization();
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530160 setup_k3_mpu_regions();
161#endif
162
163 /* Init DM early */
164 spl_early_init();
165
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530166#ifdef CONFIG_K3_LOAD_SYSFW
167 /*
168 * Process pinctrl for the serial0 a.k.a. MCU_UART0 module and continue
169 * regardless of the result of pinctrl. Do this without probing the
170 * device, but instead by searching the device that would request the
171 * given sequence number if probed. The UART will be used by the system
172 * firmware (SYSFW) image for various purposes and SYSFW depends on us
173 * to initialize its pin settings.
174 */
175 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
176 if (!ret)
177 pinctrl_select_state(dev, "default");
178
179 /*
180 * Load, start up, and configure system controller firmware. Provide
181 * the U-Boot console init function to the SYSFW post-PM configuration
182 * callback hook, effectively switching on (or over) the console
183 * output.
184 */
Faiz Abbas68393212020-02-26 13:44:36 +0530185 k3_sysfw_loader(k3_mmc_stop_clock, k3_mmc_restart_clock);
186
187 /* Prepare console output */
188 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500189
190 /* Disable ROM configured firewalls right after loading sysfw */
191#ifdef CONFIG_TI_SECURE_DEVICE
192 remove_fwl_configs(cbass_hc_cfg0_fwls, ARRAY_SIZE(cbass_hc_cfg0_fwls));
193 remove_fwl_configs(cbass_hc0_fwls, ARRAY_SIZE(cbass_hc0_fwls));
194 remove_fwl_configs(cbass_rc_cfg0_fwls, ARRAY_SIZE(cbass_rc_cfg0_fwls));
195 remove_fwl_configs(cbass_rc0_fwls, ARRAY_SIZE(cbass_rc0_fwls));
196 remove_fwl_configs(infra_cbass0_fwls, ARRAY_SIZE(infra_cbass0_fwls));
197 remove_fwl_configs(mcu_cbass0_fwls, ARRAY_SIZE(mcu_cbass0_fwls));
198 remove_fwl_configs(wkup_cbass0_fwls, ARRAY_SIZE(wkup_cbass0_fwls));
199#endif
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530200#else
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530201 /* Prepare console output */
202 preloader_console_init();
Andreas Dannenberg5e1782c2019-06-13 10:29:47 +0530203#endif
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530204
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530205 /* Perform EEPROM-based board detection */
206 do_board_detect();
207
Keerthy0b01f662019-10-24 15:00:53 +0530208#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
209 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
210 &dev);
211 if (ret)
212 printf("AVS init failed: %d\n", ret);
213#endif
214
Lokesh Vutlaedfb5de2019-10-07 19:26:38 +0530215#if defined(CONFIG_K3_J721E_DDRSS)
216 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
217 if (ret)
218 panic("DRAM init failed: %d\n", ret);
219#endif
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530220}
Lokesh Vutla6edde292019-06-13 10:29:43 +0530221
222u32 spl_boot_mode(const u32 boot_device)
223{
224 switch (boot_device) {
225 case BOOT_DEVICE_MMC1:
226 return MMCSD_MODE_EMMCBOOT;
227 case BOOT_DEVICE_MMC2:
228 return MMCSD_MODE_FS;
229 default:
230 return MMCSD_MODE_RAW;
231 }
232}
233
234static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
235{
236
237 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
238 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
239
240 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
241 BOOT_MODE_B_SHIFT;
242
243 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
244 bootmode = BOOT_DEVICE_SPI;
245
246 if (bootmode == BOOT_DEVICE_MMC2) {
247 u32 port = (main_devstat &
248 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
249 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
250 if (port == 0x0)
251 bootmode = BOOT_DEVICE_MMC1;
252 }
253
254 return bootmode;
255}
256
257u32 spl_boot_device(void)
258{
259 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
260 u32 main_devstat;
261
262 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
263 printf("ERROR: MCU only boot is not yet supported\n");
264 return BOOT_DEVICE_RAM;
265 }
266
267 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
268 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
269
270 /* ToDo: Add support for backup boot media */
271 return __get_primary_bootmedia(main_devstat, wkup_devstat);
272}
Lokesh Vutlaa2285322019-06-13 10:29:42 +0530273#endif
Lokesh Vutla96c11f42019-06-13 10:29:46 +0530274
275#ifdef CONFIG_SYS_K3_SPL_ATF
276
277#define J721E_DEV_MCU_RTI0 262
278#define J721E_DEV_MCU_RTI1 263
279#define J721E_DEV_MCU_ARMSS0_CPU0 250
280#define J721E_DEV_MCU_ARMSS0_CPU1 251
281
282void release_resources_for_core_shutdown(void)
283{
284 struct ti_sci_handle *ti_sci;
285 struct ti_sci_dev_ops *dev_ops;
286 struct ti_sci_proc_ops *proc_ops;
287 int ret;
288 u32 i;
289
290 const u32 put_device_ids[] = {
291 J721E_DEV_MCU_RTI0,
292 J721E_DEV_MCU_RTI1,
293 };
294
295 ti_sci = get_ti_sci_handle();
296 dev_ops = &ti_sci->ops.dev_ops;
297 proc_ops = &ti_sci->ops.proc_ops;
298
299 /* Iterate through list of devices to put (shutdown) */
300 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
301 u32 id = put_device_ids[i];
302
303 ret = dev_ops->put_device(ti_sci, id);
304 if (ret)
305 panic("Failed to put device %u (%d)\n", id, ret);
306 }
307
308 const u32 put_core_ids[] = {
309 J721E_DEV_MCU_ARMSS0_CPU1,
310 J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
311 };
312
313 /* Iterate through list of cores to put (shutdown) */
314 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
315 u32 id = put_core_ids[i];
316
317 /*
318 * Queue up the core shutdown request. Note that this call
319 * needs to be followed up by an actual invocation of an WFE
320 * or WFI CPU instruction.
321 */
322 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
323 if (ret)
324 panic("Failed sending core %u shutdown message (%d)\n",
325 id, ret);
326 }
327}
328#endif