blob: d0b10e58ad3e176d7f35dcebcb3f5d20ef99b197 [file] [log] [blame]
Lokesh Vutlaed0e6052018-08-27 15:57:09 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
Andrew F. Davis9b322db2020-01-10 14:35:20 -05003 * AM6: SoC specific initialization
Lokesh Vutlaed0e6052018-08-27 15:57:09 +05304 *
5 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
9#include <common.h>
Lokesh Vutlae0064602018-08-27 15:57:11 +053010#include <asm/io.h>
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053011#include <spl.h>
Lokesh Vutlae0064602018-08-27 15:57:11 +053012#include <asm/arch/hardware.h>
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -050013#include <asm/arch/sysfw-loader.h>
Andreas Dannenberg03facc72019-06-04 18:08:26 -050014#include <asm/arch/sys_proto.h>
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +053015#include "common.h"
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +053016#include <dm.h>
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -050017#include <dm/uclass-internal.h>
18#include <dm/pinctrl.h>
Andreas Dannenbergf9380a72019-06-07 19:24:42 +053019#include <linux/soc/ti/ti_sci_protocol.h>
Faiz Abbasd45ffb72020-02-26 13:44:36 +053020#include <mmc.h>
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053021
22#ifdef CONFIG_SPL_BUILD
Andrew F. Davisea70da12020-01-10 14:35:21 -050023#ifdef CONFIG_K3_LOAD_SYSFW
24#ifdef CONFIG_TI_SECURE_DEVICE
25struct fwl_data main_cbass_fwls[] = {
26 { "MMCSD1_CFG", 2057, 1 },
27 { "MMCSD0_CFG", 2058, 1 },
28 { "USB3SS0_SLV0", 2176, 2 },
29 { "PCIE0_SLV", 2336, 8 },
30 { "PCIE1_SLV", 2337, 8 },
31 { "PCIE0_CFG", 2688, 1 },
32 { "PCIE1_CFG", 2689, 1 },
33}, mcu_cbass_fwls[] = {
34 { "MCU_ARMSS0_CORE0_SLV", 1024, 1 },
35 { "MCU_ARMSS0_CORE1_SLV", 1028, 1 },
36 { "MCU_FSS0_S1", 1033, 8 },
37 { "MCU_FSS0_S0", 1036, 8 },
38 { "MCU_CPSW0", 1220, 1 },
39};
40#endif
41#endif
42
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053043static void mmr_unlock(u32 base, u32 partition)
44{
45 /* Translate the base address */
46 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
47
48 /* Unlock the requested partition if locked using two-step sequence */
49 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
50 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
51}
52
53static void ctrl_mmr_unlock(void)
54{
55 /* Unlock all WKUP_CTRL_MMR0 module registers */
56 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
57 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
58 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
59 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
60 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
61 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
62
63 /* Unlock all MCU_CTRL_MMR0 module registers */
64 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
65 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
66 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
67 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
68
69 /* Unlock all CTRL_MMR0 module registers */
70 mmr_unlock(CTRL_MMR0_BASE, 0);
71 mmr_unlock(CTRL_MMR0_BASE, 1);
72 mmr_unlock(CTRL_MMR0_BASE, 2);
73 mmr_unlock(CTRL_MMR0_BASE, 3);
74 mmr_unlock(CTRL_MMR0_BASE, 6);
75 mmr_unlock(CTRL_MMR0_BASE, 7);
76}
77
Andrew F. Davis407a2192019-04-12 12:54:42 -040078/*
79 * This uninitialized global variable would normal end up in the .bss section,
80 * but the .bss is cleared between writing and reading this variable, so move
81 * it to the .data section.
82 */
83u32 bootindex __attribute__((section(".data")));
84
Lokesh Vutlae0064602018-08-27 15:57:11 +053085static void store_boot_index_from_rom(void)
86{
Andrew F. Davis407a2192019-04-12 12:54:42 -040087 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlae0064602018-08-27 15:57:11 +053088}
89
Faiz Abbasd45ffb72020-02-26 13:44:36 +053090#if defined(CONFIG_K3_LOAD_SYSFW)
91void k3_mmc_stop_clock(void)
92{
93 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
94 struct mmc *mmc = find_mmc_device(0);
95
96 if (!mmc)
97 return;
98
99 mmc->saved_clock = mmc->clock;
100 mmc_set_clock(mmc, 0, true);
101 }
102}
103
104void k3_mmc_restart_clock(void)
105{
106 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
107 struct mmc *mmc = find_mmc_device(0);
108
109 if (!mmc)
110 return;
111
112 mmc_set_clock(mmc, mmc->saved_clock, false);
113 }
114}
115#endif
116
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530117void board_init_f(ulong dummy)
118{
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500119#if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530120 struct udevice *dev;
121 int ret;
122#endif
Lokesh Vutlae0064602018-08-27 15:57:11 +0530123 /*
124 * Cannot delay this further as there is a chance that
125 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
126 */
127 store_boot_index_from_rom();
128
Andreas Dannenbergc68721d2018-08-27 15:57:12 +0530129 /* Make all control module registers accessible */
130 ctrl_mmr_unlock();
131
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +0530132#ifdef CONFIG_CPU_V7R
Lokesh Vutla40109f42019-12-31 15:49:55 +0530133 disable_linefill_optimization();
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +0530134 setup_k3_mpu_regions();
135#endif
136
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530137 /* Init DM early in-order to invoke system controller */
138 spl_early_init();
139
Andreas Dannenberg96dd2232018-12-04 22:29:47 -0600140#ifdef CONFIG_K3_EARLY_CONS
141 /*
142 * Allow establishing an early console as required for example when
143 * doing a UART-based boot. Note that this console may not "survive"
144 * through a SYSFW PM-init step and will need a re-init in some way
145 * due to changing module clock frequencies.
146 */
147 early_console_init();
148#endif
149
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500150#ifdef CONFIG_K3_LOAD_SYSFW
151 /*
152 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
153 * regardless of the result of pinctrl. Do this without probing the
154 * device, but instead by searching the device that would request the
155 * given sequence number if probed. The UART will be used by the system
156 * firmware (SYSFW) image for various purposes and SYSFW depends on us
157 * to initialize its pin settings.
158 */
159 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
160 if (!ret)
161 pinctrl_select_state(dev, "default");
162
163 /*
164 * Load, start up, and configure system controller firmware. Provide
165 * the U-Boot console init function to the SYSFW post-PM configuration
166 * callback hook, effectively switching on (or over) the console
167 * output.
168 */
Faiz Abbasd45ffb72020-02-26 13:44:36 +0530169 k3_sysfw_loader(k3_mmc_stop_clock, k3_mmc_restart_clock);
170
171 /* Prepare console output */
172 preloader_console_init();
Andrew F. Davisea70da12020-01-10 14:35:21 -0500173
174 /* Disable ROM configured firewalls right after loading sysfw */
175#ifdef CONFIG_TI_SECURE_DEVICE
176 remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls));
177 remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls));
178#endif
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500179#else
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530180 /* Prepare console output */
181 preloader_console_init();
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500182#endif
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530183
Andreas Dannenberg03facc72019-06-04 18:08:26 -0500184 /* Perform EEPROM-based board detection */
185 do_board_detect();
186
Keerthy27380cb2019-10-24 15:00:52 +0530187#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
188 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
189 &dev);
190 if (ret)
191 printf("AVS init failed: %d\n", ret);
192#endif
193
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530194#ifdef CONFIG_K3_AM654_DDRSS
195 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg3e9b9c12019-03-11 15:15:43 -0500196 if (ret)
197 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530198#endif
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530199}
200
Andrew F. Davis81089a52018-10-03 10:03:23 -0500201u32 spl_boot_mode(const u32 boot_device)
202{
203#if defined(CONFIG_SUPPORT_EMMC_BOOT)
204 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davis81089a52018-10-03 10:03:23 -0500205
206 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
207 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
208
209 /* eMMC boot0 mode is only supported for primary boot */
210 if (bootindex == K3_PRIMARY_BOOTMODE &&
211 bootmode == BOOT_DEVICE_MMC1)
212 return MMCSD_MODE_EMMCBOOT;
213#endif
214
215 /* Everything else use filesystem if available */
Tien Fong Cheef4b40922019-01-23 14:20:05 +0800216#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davis81089a52018-10-03 10:03:23 -0500217 return MMCSD_MODE_FS;
218#else
219 return MMCSD_MODE_RAW;
220#endif
221}
222
Lokesh Vutlae0064602018-08-27 15:57:11 +0530223static u32 __get_backup_bootmedia(u32 devstat)
224{
225 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
226 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
227
228 switch (bkup_boot) {
229 case BACKUP_BOOT_DEVICE_USB:
230 return BOOT_DEVICE_USB;
231 case BACKUP_BOOT_DEVICE_UART:
232 return BOOT_DEVICE_UART;
233 case BACKUP_BOOT_DEVICE_ETHERNET:
234 return BOOT_DEVICE_ETHERNET;
235 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500236 {
237 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
238 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
239 if (port == 0x0)
240 return BOOT_DEVICE_MMC1;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530241 return BOOT_DEVICE_MMC2;
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500242 }
Lokesh Vutlae0064602018-08-27 15:57:11 +0530243 case BACKUP_BOOT_DEVICE_SPI:
244 return BOOT_DEVICE_SPI;
245 case BACKUP_BOOT_DEVICE_HYPERFLASH:
246 return BOOT_DEVICE_HYPERFLASH;
247 case BACKUP_BOOT_DEVICE_I2C:
248 return BOOT_DEVICE_I2C;
249 };
250
251 return BOOT_DEVICE_RAM;
252}
253
254static u32 __get_primary_bootmedia(u32 devstat)
255{
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500256 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
257 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530258
259 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
260 bootmode = BOOT_DEVICE_SPI;
261
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500262 if (bootmode == BOOT_DEVICE_MMC2) {
263 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
264 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
265 if (port == 0x0)
266 bootmode = BOOT_DEVICE_MMC1;
267 } else if (bootmode == BOOT_DEVICE_MMC1) {
268 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
269 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
270 if (port == 0x1)
271 bootmode = BOOT_DEVICE_MMC2;
272 }
273
Lokesh Vutlae0064602018-08-27 15:57:11 +0530274 return bootmode;
275}
276
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530277u32 spl_boot_device(void)
278{
Lokesh Vutlae0064602018-08-27 15:57:11 +0530279 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlae0064602018-08-27 15:57:11 +0530280
281 if (bootindex == K3_PRIMARY_BOOTMODE)
282 return __get_primary_bootmedia(devstat);
283 else
284 return __get_backup_bootmedia(devstat);
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530285}
286#endif
287
Andreas Dannenbergf9380a72019-06-07 19:24:42 +0530288#ifdef CONFIG_SYS_K3_SPL_ATF
289
290#define AM6_DEV_MCU_RTI0 134
291#define AM6_DEV_MCU_RTI1 135
292#define AM6_DEV_MCU_ARMSS0_CPU0 159
293#define AM6_DEV_MCU_ARMSS0_CPU1 245
294
295void release_resources_for_core_shutdown(void)
296{
Lokesh Vutla78e51212019-09-09 12:47:38 +0530297 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
298 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
299 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andreas Dannenbergf9380a72019-06-07 19:24:42 +0530300 int ret;
301 u32 i;
302
303 const u32 put_device_ids[] = {
304 AM6_DEV_MCU_RTI0,
305 AM6_DEV_MCU_RTI1,
306 };
307
Andreas Dannenbergf9380a72019-06-07 19:24:42 +0530308 /* Iterate through list of devices to put (shutdown) */
309 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
310 u32 id = put_device_ids[i];
311
312 ret = dev_ops->put_device(ti_sci, id);
313 if (ret)
314 panic("Failed to put device %u (%d)\n", id, ret);
315 }
316
317 const u32 put_core_ids[] = {
318 AM6_DEV_MCU_ARMSS0_CPU1,
319 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
320 };
321
322 /* Iterate through list of cores to put (shutdown) */
323 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
324 u32 id = put_core_ids[i];
325
326 /*
327 * Queue up the core shutdown request. Note that this call
328 * needs to be followed up by an actual invocation of an WFE
329 * or WFI CPU instruction.
330 */
331 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
332 if (ret)
333 panic("Failed sending core %u shutdown message (%d)\n",
334 id, ret);
335 }
336}
337#endif