blob: 5514dc963edc066291e7bba7461dc7d7052ce738 [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>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm/armv7_mpu.h>
Lokesh Vutla0a704922019-06-13 10:29:43 +053013#include <asm/arch/hardware.h>
Lokesh Vutlac2562d72019-06-13 10:29:42 +053014#include "common.h"
Lokesh Vutla9c0ff862019-06-13 10:29:46 +053015#include <asm/arch/sys_proto.h>
16#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutlac2562d72019-06-13 10:29:42 +053017
18#ifdef CONFIG_SPL_BUILD
Andreas Dannenbergb73fcbc2019-06-13 10:29:44 +053019static void mmr_unlock(u32 base, u32 partition)
20{
21 /* Translate the base address */
22 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
23
24 /* Unlock the requested partition if locked using two-step sequence */
25 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
26 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
27}
28
29static void ctrl_mmr_unlock(void)
30{
31 /* Unlock all WKUP_CTRL_MMR0 module registers */
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
37 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
39
40 /* Unlock all MCU_CTRL_MMR0 module registers */
41 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
42 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
43 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
44 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
45 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
46
47 /* Unlock all CTRL_MMR0 module registers */
48 mmr_unlock(CTRL_MMR0_BASE, 0);
49 mmr_unlock(CTRL_MMR0_BASE, 1);
50 mmr_unlock(CTRL_MMR0_BASE, 2);
51 mmr_unlock(CTRL_MMR0_BASE, 3);
52 mmr_unlock(CTRL_MMR0_BASE, 4);
53 mmr_unlock(CTRL_MMR0_BASE, 5);
54 mmr_unlock(CTRL_MMR0_BASE, 6);
55 mmr_unlock(CTRL_MMR0_BASE, 7);
56}
57
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +053058/*
59 * This uninitialized global variable would normal end up in the .bss section,
60 * but the .bss is cleared between writing and reading this variable, so move
61 * it to the .data section.
62 */
63u32 bootindex __attribute__((section(".data")));
64
65static void store_boot_index_from_rom(void)
66{
67 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
68}
69
Lokesh Vutlac2562d72019-06-13 10:29:42 +053070void board_init_f(ulong dummy)
71{
72 /*
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +053073 * Cannot delay this further as there is a chance that
74 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlac2562d72019-06-13 10:29:42 +053075 */
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +053076 store_boot_index_from_rom();
Lokesh Vutlac2562d72019-06-13 10:29:42 +053077
Andreas Dannenbergb73fcbc2019-06-13 10:29:44 +053078 /* Make all control module registers accessible */
79 ctrl_mmr_unlock();
80
Lokesh Vutlac2562d72019-06-13 10:29:42 +053081#ifdef CONFIG_CPU_V7R
82 setup_k3_mpu_regions();
83#endif
84
85 /* Init DM early */
86 spl_early_init();
87
88 /* Prepare console output */
89 preloader_console_init();
90}
Lokesh Vutla0a704922019-06-13 10:29:43 +053091
92u32 spl_boot_mode(const u32 boot_device)
93{
94 switch (boot_device) {
95 case BOOT_DEVICE_MMC1:
96 return MMCSD_MODE_EMMCBOOT;
97 case BOOT_DEVICE_MMC2:
98 return MMCSD_MODE_FS;
99 default:
100 return MMCSD_MODE_RAW;
101 }
102}
103
104static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
105{
106
107 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
108 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
109
110 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
111 BOOT_MODE_B_SHIFT;
112
113 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
114 bootmode = BOOT_DEVICE_SPI;
115
116 if (bootmode == BOOT_DEVICE_MMC2) {
117 u32 port = (main_devstat &
118 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
119 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
120 if (port == 0x0)
121 bootmode = BOOT_DEVICE_MMC1;
122 }
123
124 return bootmode;
125}
126
127u32 spl_boot_device(void)
128{
129 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
130 u32 main_devstat;
131
132 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
133 printf("ERROR: MCU only boot is not yet supported\n");
134 return BOOT_DEVICE_RAM;
135 }
136
137 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
138 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
139
140 /* ToDo: Add support for backup boot media */
141 return __get_primary_bootmedia(main_devstat, wkup_devstat);
142}
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530143#endif
Lokesh Vutla9c0ff862019-06-13 10:29:46 +0530144
145#ifdef CONFIG_SYS_K3_SPL_ATF
146
147#define J721E_DEV_MCU_RTI0 262
148#define J721E_DEV_MCU_RTI1 263
149#define J721E_DEV_MCU_ARMSS0_CPU0 250
150#define J721E_DEV_MCU_ARMSS0_CPU1 251
151
152void release_resources_for_core_shutdown(void)
153{
154 struct ti_sci_handle *ti_sci;
155 struct ti_sci_dev_ops *dev_ops;
156 struct ti_sci_proc_ops *proc_ops;
157 int ret;
158 u32 i;
159
160 const u32 put_device_ids[] = {
161 J721E_DEV_MCU_RTI0,
162 J721E_DEV_MCU_RTI1,
163 };
164
165 ti_sci = get_ti_sci_handle();
166 dev_ops = &ti_sci->ops.dev_ops;
167 proc_ops = &ti_sci->ops.proc_ops;
168
169 /* Iterate through list of devices to put (shutdown) */
170 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
171 u32 id = put_device_ids[i];
172
173 ret = dev_ops->put_device(ti_sci, id);
174 if (ret)
175 panic("Failed to put device %u (%d)\n", id, ret);
176 }
177
178 const u32 put_core_ids[] = {
179 J721E_DEV_MCU_ARMSS0_CPU1,
180 J721E_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
181 };
182
183 /* Iterate through list of cores to put (shutdown) */
184 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
185 u32 id = put_core_ids[i];
186
187 /*
188 * Queue up the core shutdown request. Note that this call
189 * needs to be followed up by an actual invocation of an WFE
190 * or WFI CPU instruction.
191 */
192 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
193 if (ret)
194 panic("Failed sending core %u shutdown message (%d)\n",
195 id, ret);
196 }
197}
198#endif