blob: 42d13a39f8a8842dbe8c1f0a9950a3cb8ad88e88 [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>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Lokesh Vutlae0064602018-08-27 15:57:11 +053011#include <asm/io.h>
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053012#include <spl.h>
Lokesh Vutlae0064602018-08-27 15:57:11 +053013#include <asm/arch/hardware.h>
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -050014#include <asm/arch/sysfw-loader.h>
Andreas Dannenberg03facc72019-06-04 18:08:26 -050015#include <asm/arch/sys_proto.h>
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +053016#include "common.h"
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +053017#include <dm.h>
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -050018#include <dm/uclass-internal.h>
19#include <dm/pinctrl.h>
Andreas Dannenbergf9380a72019-06-07 19:24:42 +053020#include <linux/soc/ti/ti_sci_protocol.h>
Faiz Abbasf9916b62020-08-03 11:35:06 +053021#include <log.h>
Faiz Abbasd45ffb72020-02-26 13:44:36 +053022#include <mmc.h>
Faiz Abbasf9916b62020-08-03 11:35:06 +053023#include <stdlib.h>
Lokesh Vutlaed0e6052018-08-27 15:57:09 +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 main_cbass_fwls[] = {
29 { "MMCSD1_CFG", 2057, 1 },
30 { "MMCSD0_CFG", 2058, 1 },
31 { "USB3SS0_SLV0", 2176, 2 },
32 { "PCIE0_SLV", 2336, 8 },
33 { "PCIE1_SLV", 2337, 8 },
34 { "PCIE0_CFG", 2688, 1 },
35 { "PCIE1_CFG", 2689, 1 },
36}, mcu_cbass_fwls[] = {
37 { "MCU_ARMSS0_CORE0_SLV", 1024, 1 },
38 { "MCU_ARMSS0_CORE1_SLV", 1028, 1 },
39 { "MCU_FSS0_S1", 1033, 8 },
40 { "MCU_FSS0_S0", 1036, 8 },
41 { "MCU_CPSW0", 1220, 1 },
42};
43#endif
44#endif
45
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053046static void mmr_unlock(u32 base, u32 partition)
47{
48 /* Translate the base address */
49 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
50
51 /* Unlock the requested partition if locked using two-step sequence */
52 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
53 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
54}
55
56static void ctrl_mmr_unlock(void)
57{
58 /* Unlock all WKUP_CTRL_MMR0 module registers */
59 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
60 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
61 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
62 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
63 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
64 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
65
66 /* Unlock all MCU_CTRL_MMR0 module registers */
67 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
68 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
69 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
70 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
71
72 /* Unlock all CTRL_MMR0 module registers */
73 mmr_unlock(CTRL_MMR0_BASE, 0);
74 mmr_unlock(CTRL_MMR0_BASE, 1);
75 mmr_unlock(CTRL_MMR0_BASE, 2);
76 mmr_unlock(CTRL_MMR0_BASE, 3);
77 mmr_unlock(CTRL_MMR0_BASE, 6);
78 mmr_unlock(CTRL_MMR0_BASE, 7);
79}
80
Andrew F. Davis407a2192019-04-12 12:54:42 -040081/*
82 * This uninitialized global variable would normal end up in the .bss section,
83 * but the .bss is cleared between writing and reading this variable, so move
84 * it to the .data section.
85 */
86u32 bootindex __attribute__((section(".data")));
87
Lokesh Vutlae0064602018-08-27 15:57:11 +053088static void store_boot_index_from_rom(void)
89{
Andrew F. Davis407a2192019-04-12 12:54:42 -040090 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlae0064602018-08-27 15:57:11 +053091}
92
Faiz Abbasfebb47a2020-08-03 11:35:08 +053093#if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC)
Faiz Abbasd45ffb72020-02-26 13:44:36 +053094void k3_mmc_stop_clock(void)
95{
96 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
97 struct mmc *mmc = find_mmc_device(0);
98
99 if (!mmc)
100 return;
101
102 mmc->saved_clock = mmc->clock;
103 mmc_set_clock(mmc, 0, true);
104 }
105}
106
107void k3_mmc_restart_clock(void)
108{
109 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
110 struct mmc *mmc = find_mmc_device(0);
111
112 if (!mmc)
113 return;
114
115 mmc_set_clock(mmc, mmc->saved_clock, false);
116 }
117}
Faiz Abbasfebb47a2020-08-03 11:35:08 +0530118#else
119void k3_mmc_stop_clock(void) {}
120void k3_mmc_restart_clock(void) {}
Faiz Abbasd45ffb72020-02-26 13:44:36 +0530121#endif
122
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530123void board_init_f(ulong dummy)
124{
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500125#if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530126 struct udevice *dev;
Faiz Abbasf9916b62020-08-03 11:35:06 +0530127 size_t pool_size;
128 void *pool_addr;
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530129 int ret;
130#endif
Lokesh Vutlae0064602018-08-27 15:57:11 +0530131 /*
132 * Cannot delay this further as there is a chance that
133 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
134 */
135 store_boot_index_from_rom();
136
Andreas Dannenbergc68721d2018-08-27 15:57:12 +0530137 /* Make all control module registers accessible */
138 ctrl_mmr_unlock();
139
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +0530140#ifdef CONFIG_CPU_V7R
Lokesh Vutla40109f42019-12-31 15:49:55 +0530141 disable_linefill_optimization();
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +0530142 setup_k3_mpu_regions();
143#endif
144
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530145 /* Init DM early in-order to invoke system controller */
146 spl_early_init();
147
Andreas Dannenberg96dd2232018-12-04 22:29:47 -0600148#ifdef CONFIG_K3_EARLY_CONS
149 /*
150 * Allow establishing an early console as required for example when
151 * doing a UART-based boot. Note that this console may not "survive"
152 * through a SYSFW PM-init step and will need a re-init in some way
153 * due to changing module clock frequencies.
154 */
155 early_console_init();
156#endif
157
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500158#ifdef CONFIG_K3_LOAD_SYSFW
159 /*
Faiz Abbasf9916b62020-08-03 11:35:06 +0530160 * Initialize an early full malloc environment. Do so by allocating a
161 * new malloc area inside the currently active pre-relocation "first"
162 * malloc pool of which we use all that's left.
163 */
164 pool_size = CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr;
165 pool_addr = malloc(pool_size);
166 if (!pool_addr)
167 panic("ERROR: Can't allocate full malloc pool!\n");
168
169 mem_malloc_init((ulong)pool_addr, (ulong)pool_size);
170 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
171 debug("%s: initialized an early full malloc pool at 0x%08lx of 0x%lx bytes\n",
172 __func__, (unsigned long)pool_addr, (unsigned long)pool_size);
173 /*
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500174 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
175 * regardless of the result of pinctrl. Do this without probing the
176 * device, but instead by searching the device that would request the
177 * given sequence number if probed. The UART will be used by the system
178 * firmware (SYSFW) image for various purposes and SYSFW depends on us
179 * to initialize its pin settings.
180 */
181 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
182 if (!ret)
183 pinctrl_select_state(dev, "default");
184
185 /*
Lokesh Vutla6e44aeb2020-03-10 16:50:58 +0530186 * Load, start up, and configure system controller firmware while
187 * also populating the SYSFW post-PM configuration callback hook.
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500188 */
Faiz Abbasd45ffb72020-02-26 13:44:36 +0530189 k3_sysfw_loader(k3_mmc_stop_clock, k3_mmc_restart_clock);
190
191 /* Prepare console output */
192 preloader_console_init();
Andrew F. Davisea70da12020-01-10 14:35:21 -0500193
194 /* Disable ROM configured firewalls right after loading sysfw */
195#ifdef CONFIG_TI_SECURE_DEVICE
196 remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls));
197 remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls));
198#endif
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500199#else
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530200 /* Prepare console output */
201 preloader_console_init();
Andreas Dannenbergc222e3d2019-06-04 17:55:50 -0500202#endif
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530203
Lokesh Vutla6e44aeb2020-03-10 16:50:58 +0530204 /* Output System Firmware version info */
205 k3_sysfw_print_ver();
206
Andreas Dannenberg03facc72019-06-04 18:08:26 -0500207 /* Perform EEPROM-based board detection */
208 do_board_detect();
209
Keerthy27380cb2019-10-24 15:00:52 +0530210#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
211 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
212 &dev);
213 if (ret)
214 printf("AVS init failed: %d\n", ret);
215#endif
216
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530217#ifdef CONFIG_K3_AM654_DDRSS
218 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg3e9b9c12019-03-11 15:15:43 -0500219 if (ret)
220 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +0530221#endif
Jan Kiszkac02712a2020-05-18 07:57:22 +0200222 spl_enable_dcache();
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530223}
224
Harald Seilere9759062020-04-15 11:33:30 +0200225u32 spl_mmc_boot_mode(const u32 boot_device)
Andrew F. Davis81089a52018-10-03 10:03:23 -0500226{
227#if defined(CONFIG_SUPPORT_EMMC_BOOT)
228 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davis81089a52018-10-03 10:03:23 -0500229
230 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
231 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
232
233 /* eMMC boot0 mode is only supported for primary boot */
234 if (bootindex == K3_PRIMARY_BOOTMODE &&
235 bootmode == BOOT_DEVICE_MMC1)
236 return MMCSD_MODE_EMMCBOOT;
237#endif
238
239 /* Everything else use filesystem if available */
Tien Fong Cheef4b40922019-01-23 14:20:05 +0800240#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davis81089a52018-10-03 10:03:23 -0500241 return MMCSD_MODE_FS;
242#else
243 return MMCSD_MODE_RAW;
244#endif
245}
246
Lokesh Vutlae0064602018-08-27 15:57:11 +0530247static u32 __get_backup_bootmedia(u32 devstat)
248{
249 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
250 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
251
252 switch (bkup_boot) {
253 case BACKUP_BOOT_DEVICE_USB:
254 return BOOT_DEVICE_USB;
255 case BACKUP_BOOT_DEVICE_UART:
256 return BOOT_DEVICE_UART;
257 case BACKUP_BOOT_DEVICE_ETHERNET:
258 return BOOT_DEVICE_ETHERNET;
259 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500260 {
261 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
262 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
263 if (port == 0x0)
264 return BOOT_DEVICE_MMC1;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530265 return BOOT_DEVICE_MMC2;
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500266 }
Lokesh Vutlae0064602018-08-27 15:57:11 +0530267 case BACKUP_BOOT_DEVICE_SPI:
268 return BOOT_DEVICE_SPI;
269 case BACKUP_BOOT_DEVICE_HYPERFLASH:
270 return BOOT_DEVICE_HYPERFLASH;
271 case BACKUP_BOOT_DEVICE_I2C:
272 return BOOT_DEVICE_I2C;
273 };
274
275 return BOOT_DEVICE_RAM;
276}
277
278static u32 __get_primary_bootmedia(u32 devstat)
279{
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500280 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
281 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530282
283 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
284 bootmode = BOOT_DEVICE_SPI;
285
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500286 if (bootmode == BOOT_DEVICE_MMC2) {
287 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
288 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
289 if (port == 0x0)
290 bootmode = BOOT_DEVICE_MMC1;
291 } else if (bootmode == BOOT_DEVICE_MMC1) {
292 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
293 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
294 if (port == 0x1)
295 bootmode = BOOT_DEVICE_MMC2;
296 }
297
Lokesh Vutlae0064602018-08-27 15:57:11 +0530298 return bootmode;
299}
300
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530301u32 spl_boot_device(void)
302{
Lokesh Vutlae0064602018-08-27 15:57:11 +0530303 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlae0064602018-08-27 15:57:11 +0530304
305 if (bootindex == K3_PRIMARY_BOOTMODE)
306 return __get_primary_bootmedia(devstat);
307 else
308 return __get_backup_bootmedia(devstat);
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530309}
310#endif
311
Andreas Dannenbergf9380a72019-06-07 19:24:42 +0530312#ifdef CONFIG_SYS_K3_SPL_ATF
313
314#define AM6_DEV_MCU_RTI0 134
315#define AM6_DEV_MCU_RTI1 135
316#define AM6_DEV_MCU_ARMSS0_CPU0 159
317#define AM6_DEV_MCU_ARMSS0_CPU1 245
318
319void release_resources_for_core_shutdown(void)
320{
Lokesh Vutla78e51212019-09-09 12:47:38 +0530321 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
322 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
323 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andreas Dannenbergf9380a72019-06-07 19:24:42 +0530324 int ret;
325 u32 i;
326
327 const u32 put_device_ids[] = {
328 AM6_DEV_MCU_RTI0,
329 AM6_DEV_MCU_RTI1,
330 };
331
Andreas Dannenbergf9380a72019-06-07 19:24:42 +0530332 /* Iterate through list of devices to put (shutdown) */
333 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
334 u32 id = put_device_ids[i];
335
336 ret = dev_ops->put_device(ti_sci, id);
337 if (ret)
338 panic("Failed to put device %u (%d)\n", id, ret);
339 }
340
341 const u32 put_core_ids[] = {
342 AM6_DEV_MCU_ARMSS0_CPU1,
343 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
344 };
345
346 /* Iterate through list of cores to put (shutdown) */
347 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
348 u32 id = put_core_ids[i];
349
350 /*
351 * Queue up the core shutdown request. Note that this call
352 * needs to be followed up by an actual invocation of an WFE
353 * or WFI CPU instruction.
354 */
355 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
356 if (ret)
357 panic("Failed sending core %u shutdown message (%d)\n",
358 id, ret);
359 }
360}
361#endif