blob: 768fdd69602f4ddb6cd0a6b176db04d92bdd7766 [file] [log] [blame]
Lokesh Vutla32886442018-08-27 15:57:09 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
Andrew F. Davis2dbe3892020-01-10 14:35:20 -05003 * AM6: SoC specific initialization
Lokesh Vutla32886442018-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>
Faiz Abbas3385a862020-08-03 11:35:09 +053010#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053013#include <asm/io.h>
Lokesh Vutla32886442018-08-27 15:57:09 +053014#include <spl.h>
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053015#include <asm/arch/hardware.h>
Andreas Dannenbergea91da12019-06-04 17:55:50 -050016#include <asm/arch/sysfw-loader.h>
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050017#include <asm/arch/sys_proto.h>
Lokesh Vutlac1e60e82018-11-02 19:51:03 +053018#include "common.h"
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +053019#include <dm.h>
Andreas Dannenbergea91da12019-06-04 17:55:50 -050020#include <dm/uclass-internal.h>
21#include <dm/pinctrl.h>
Andreas Dannenberg31175f82019-06-07 19:24:42 +053022#include <linux/soc/ti/ti_sci_protocol.h>
Faiz Abbasfe1217e2020-08-03 11:35:06 +053023#include <log.h>
Faiz Abbas68393212020-02-26 13:44:36 +053024#include <mmc.h>
Faiz Abbasfe1217e2020-08-03 11:35:06 +053025#include <stdlib.h>
Lokesh Vutla32886442018-08-27 15:57:09 +053026
Faiz Abbas3385a862020-08-03 11:35:09 +053027DECLARE_GLOBAL_DATA_PTR;
28
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050029#ifdef CONFIG_K3_LOAD_SYSFW
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050030struct fwl_data main_cbass_fwls[] = {
31 { "MMCSD1_CFG", 2057, 1 },
32 { "MMCSD0_CFG", 2058, 1 },
33 { "USB3SS0_SLV0", 2176, 2 },
34 { "PCIE0_SLV", 2336, 8 },
35 { "PCIE1_SLV", 2337, 8 },
36 { "PCIE0_CFG", 2688, 1 },
37 { "PCIE1_CFG", 2689, 1 },
38}, mcu_cbass_fwls[] = {
39 { "MCU_ARMSS0_CORE0_SLV", 1024, 1 },
40 { "MCU_ARMSS0_CORE1_SLV", 1028, 1 },
41 { "MCU_FSS0_S1", 1033, 8 },
42 { "MCU_FSS0_S0", 1036, 8 },
43 { "MCU_CPSW0", 1220, 1 },
44};
45#endif
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050046
Andreas Dannenberg1c855c12018-08-27 15:57:12 +053047static void ctrl_mmr_unlock(void)
48{
49 /* Unlock all WKUP_CTRL_MMR0 module registers */
50 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
51 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
52 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
53 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
54 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
55 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
56
57 /* Unlock all MCU_CTRL_MMR0 module registers */
58 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
59 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
60 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
61 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
62
63 /* Unlock all CTRL_MMR0 module registers */
64 mmr_unlock(CTRL_MMR0_BASE, 0);
65 mmr_unlock(CTRL_MMR0_BASE, 1);
66 mmr_unlock(CTRL_MMR0_BASE, 2);
67 mmr_unlock(CTRL_MMR0_BASE, 3);
68 mmr_unlock(CTRL_MMR0_BASE, 6);
69 mmr_unlock(CTRL_MMR0_BASE, 7);
70}
71
Andrew F. Davis9ffea342019-04-12 12:54:42 -040072/*
73 * This uninitialized global variable would normal end up in the .bss section,
74 * but the .bss is cleared between writing and reading this variable, so move
75 * it to the .data section.
76 */
Marek BehĂșn4bebdd32021-05-20 13:23:52 +020077u32 bootindex __section(".data");
Andrew F. Davis9ffea342019-04-12 12:54:42 -040078
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053079static void store_boot_index_from_rom(void)
80{
Andrew F. Davis9ffea342019-04-12 12:54:42 -040081 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053082}
83
Faiz Abbasb4372bf2020-08-03 11:35:08 +053084#if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC)
Faiz Abbas68393212020-02-26 13:44:36 +053085void k3_mmc_stop_clock(void)
86{
87 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
88 struct mmc *mmc = find_mmc_device(0);
89
90 if (!mmc)
91 return;
92
93 mmc->saved_clock = mmc->clock;
94 mmc_set_clock(mmc, 0, true);
95 }
96}
97
98void k3_mmc_restart_clock(void)
99{
100 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
101 struct mmc *mmc = find_mmc_device(0);
102
103 if (!mmc)
104 return;
105
106 mmc_set_clock(mmc, mmc->saved_clock, false);
107 }
108}
Faiz Abbasb4372bf2020-08-03 11:35:08 +0530109#else
110void k3_mmc_stop_clock(void) {}
111void k3_mmc_restart_clock(void) {}
Faiz Abbas68393212020-02-26 13:44:36 +0530112#endif
Faiz Abbas3385a862020-08-03 11:35:09 +0530113#if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE)
114#define CTRLMMR_SERDES0_CTRL 0x00104080
115#define PCIE_LANE0 0x1
116static int fixup_usb_boot(void)
117{
118 int ret;
Faiz Abbas68393212020-02-26 13:44:36 +0530119
Faiz Abbas3385a862020-08-03 11:35:09 +0530120 switch (spl_boot_device()) {
121 case BOOT_DEVICE_USB:
122 /*
123 * If bootmode is Host bootmode, fixup the dr_mode to host
124 * before the dwc3 bind takes place
125 */
126 ret = fdt_find_and_setprop((void *)gd->fdt_blob,
Aswath Govindraju271d76e2022-05-18 16:49:13 +0530127 "/bus@100000/dwc3@4000000/usb@10000",
128 "dr_mode", "host", 5, 0);
Faiz Abbas3385a862020-08-03 11:35:09 +0530129 if (ret)
130 printf("%s: fdt_find_and_setprop() failed:%d\n", __func__,
131 ret);
132 fallthrough;
133 case BOOT_DEVICE_DFU:
134 /*
135 * The serdes mux between PCIe and USB3 needs to be set to PCIe for
136 * accessing the interface at USB 2.0
137 */
138 writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL);
139 default:
140 break;
141 }
142
143 return 0;
144}
145
146int fdtdec_board_setup(const void *fdt_blob)
147{
148 return fixup_usb_boot();
149}
150#endif
Roger Quadros768e6672021-09-08 15:28:59 -0500151
152static void setup_am654_navss_northbridge(void)
153{
154 /*
155 * NB0 is bridge to SRAM and NB1 is bridge to DDR.
156 * To ensure that SRAM transfers are not stalled due to
157 * delays during DDR refreshes, SRAM traffic should be higher
158 * priority (threadmap=2) than DDR traffic (threadmap=0).
159 */
160 writel(0x2, NAVSS0_NBSS_NB0_CFG_BASE + NAVSS_NBSS_THREADMAP);
161 writel(0x0, NAVSS0_NBSS_NB1_CFG_BASE + NAVSS_NBSS_THREADMAP);
162}
163
Lokesh Vutla32886442018-08-27 15:57:09 +0530164void board_init_f(ulong dummy)
165{
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500166#if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530167 struct udevice *dev;
Faiz Abbasfe1217e2020-08-03 11:35:06 +0530168 size_t pool_size;
169 void *pool_addr;
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530170 int ret;
171#endif
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530172 /*
173 * Cannot delay this further as there is a chance that
174 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
175 */
176 store_boot_index_from_rom();
177
Andreas Dannenberg1c855c12018-08-27 15:57:12 +0530178 /* Make all control module registers accessible */
179 ctrl_mmr_unlock();
180
Roger Quadros768e6672021-09-08 15:28:59 -0500181 setup_am654_navss_northbridge();
182
Lokesh Vutlac1e60e82018-11-02 19:51:03 +0530183#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530184 disable_linefill_optimization();
Lokesh Vutlac1e60e82018-11-02 19:51:03 +0530185 setup_k3_mpu_regions();
186#endif
187
Lokesh Vutla32886442018-08-27 15:57:09 +0530188 /* Init DM early in-order to invoke system controller */
189 spl_early_init();
190
Andreas Dannenbergb45d2cd2018-12-04 22:29:47 -0600191#ifdef CONFIG_K3_EARLY_CONS
192 /*
193 * Allow establishing an early console as required for example when
194 * doing a UART-based boot. Note that this console may not "survive"
195 * through a SYSFW PM-init step and will need a re-init in some way
196 * due to changing module clock frequencies.
197 */
198 early_console_init();
199#endif
200
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500201#ifdef CONFIG_K3_LOAD_SYSFW
202 /*
Faiz Abbasfe1217e2020-08-03 11:35:06 +0530203 * Initialize an early full malloc environment. Do so by allocating a
204 * new malloc area inside the currently active pre-relocation "first"
205 * malloc pool of which we use all that's left.
206 */
207 pool_size = CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr;
208 pool_addr = malloc(pool_size);
209 if (!pool_addr)
210 panic("ERROR: Can't allocate full malloc pool!\n");
211
212 mem_malloc_init((ulong)pool_addr, (ulong)pool_size);
213 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
214 debug("%s: initialized an early full malloc pool at 0x%08lx of 0x%lx bytes\n",
215 __func__, (unsigned long)pool_addr, (unsigned long)pool_size);
216 /*
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500217 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
218 * regardless of the result of pinctrl. Do this without probing the
219 * device, but instead by searching the device that would request the
220 * given sequence number if probed. The UART will be used by the system
221 * firmware (SYSFW) image for various purposes and SYSFW depends on us
222 * to initialize its pin settings.
223 */
Simon Glass07e13382020-12-16 21:20:29 -0700224 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500225 if (!ret)
226 pinctrl_select_state(dev, "default");
227
228 /*
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530229 * Load, start up, and configure system controller firmware while
230 * also populating the SYSFW post-PM configuration callback hook.
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500231 */
Lokesh Vutla17951b72020-08-05 22:44:18 +0530232 k3_sysfw_loader(false, k3_mmc_stop_clock, k3_mmc_restart_clock);
Faiz Abbas68393212020-02-26 13:44:36 +0530233
234 /* Prepare console output */
235 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500236
237 /* Disable ROM configured firewalls right after loading sysfw */
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500238 remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls));
239 remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls));
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500240#else
Lokesh Vutla32886442018-08-27 15:57:09 +0530241 /* Prepare console output */
242 preloader_console_init();
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500243#endif
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530244
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530245 /* Output System Firmware version info */
246 k3_sysfw_print_ver();
247
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500248 /* Perform EEPROM-based board detection */
Christian Gmeiner955bc4f2022-02-15 07:47:55 +0100249 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
250 do_board_detect();
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500251
Keerthy2cd50972019-10-24 15:00:52 +0530252#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
Simon Glass65130cd2020-12-28 20:34:56 -0700253 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
Keerthy2cd50972019-10-24 15:00:52 +0530254 &dev);
255 if (ret)
256 printf("AVS init failed: %d\n", ret);
257#endif
258
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530259#ifdef CONFIG_K3_AM654_DDRSS
260 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg7f6b62e2019-03-11 15:15:43 -0500261 if (ret)
262 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530263#endif
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200264 spl_enable_dcache();
Lokesh Vutla32886442018-08-27 15:57:09 +0530265}
266
Andre Przywara3cb12ef2021-07-12 11:06:49 +0100267u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Andrew F. Davisc5161462018-10-03 10:03:23 -0500268{
269#if defined(CONFIG_SUPPORT_EMMC_BOOT)
270 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davisc5161462018-10-03 10:03:23 -0500271
272 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
273 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
274
275 /* eMMC boot0 mode is only supported for primary boot */
276 if (bootindex == K3_PRIMARY_BOOTMODE &&
277 bootmode == BOOT_DEVICE_MMC1)
278 return MMCSD_MODE_EMMCBOOT;
279#endif
280
281 /* Everything else use filesystem if available */
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800282#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davisc5161462018-10-03 10:03:23 -0500283 return MMCSD_MODE_FS;
284#else
285 return MMCSD_MODE_RAW;
286#endif
287}
288
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530289static u32 __get_backup_bootmedia(u32 devstat)
Lokesh Vutla32886442018-08-27 15:57:09 +0530290{
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530291 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
292 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
293
294 switch (bkup_boot) {
295 case BACKUP_BOOT_DEVICE_USB:
296 return BOOT_DEVICE_USB;
297 case BACKUP_BOOT_DEVICE_UART:
298 return BOOT_DEVICE_UART;
299 case BACKUP_BOOT_DEVICE_ETHERNET:
300 return BOOT_DEVICE_ETHERNET;
301 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500302 {
303 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
304 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
305 if (port == 0x0)
306 return BOOT_DEVICE_MMC1;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530307 return BOOT_DEVICE_MMC2;
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500308 }
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530309 case BACKUP_BOOT_DEVICE_SPI:
310 return BOOT_DEVICE_SPI;
311 case BACKUP_BOOT_DEVICE_HYPERFLASH:
312 return BOOT_DEVICE_HYPERFLASH;
313 case BACKUP_BOOT_DEVICE_I2C:
314 return BOOT_DEVICE_I2C;
315 };
316
Lokesh Vutla32886442018-08-27 15:57:09 +0530317 return BOOT_DEVICE_RAM;
318}
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530319
320static u32 __get_primary_bootmedia(u32 devstat)
321{
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500322 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
323 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530324
325 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
326 bootmode = BOOT_DEVICE_SPI;
327
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500328 if (bootmode == BOOT_DEVICE_MMC2) {
329 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
330 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
331 if (port == 0x0)
332 bootmode = BOOT_DEVICE_MMC1;
333 } else if (bootmode == BOOT_DEVICE_MMC1) {
334 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
335 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
336 if (port == 0x1)
337 bootmode = BOOT_DEVICE_MMC2;
Faiz Abbas0ae20ed2020-08-03 11:35:10 +0530338 } else if (bootmode == BOOT_DEVICE_DFU) {
339 u32 mode = (devstat & CTRLMMR_MAIN_DEVSTAT_USB_MODE_MASK) >>
340 CTRLMMR_MAIN_DEVSTAT_USB_MODE_SHIFT;
341 if (mode == 0x2)
342 bootmode = BOOT_DEVICE_USB;
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500343 }
344
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530345 return bootmode;
346}
347
348u32 spl_boot_device(void)
349{
350 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530351
352 if (bootindex == K3_PRIMARY_BOOTMODE)
353 return __get_primary_bootmedia(devstat);
354 else
355 return __get_backup_bootmedia(devstat);
356}
Lokesh Vutla32886442018-08-27 15:57:09 +0530357
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530358#ifdef CONFIG_SYS_K3_SPL_ATF
359
360#define AM6_DEV_MCU_RTI0 134
361#define AM6_DEV_MCU_RTI1 135
362#define AM6_DEV_MCU_ARMSS0_CPU0 159
363#define AM6_DEV_MCU_ARMSS0_CPU1 245
364
365void release_resources_for_core_shutdown(void)
366{
Lokesh Vutlaac9ca952019-09-09 12:47:38 +0530367 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
368 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
369 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530370 int ret;
371 u32 i;
372
373 const u32 put_device_ids[] = {
374 AM6_DEV_MCU_RTI0,
375 AM6_DEV_MCU_RTI1,
376 };
377
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530378 /* Iterate through list of devices to put (shutdown) */
379 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
380 u32 id = put_device_ids[i];
381
382 ret = dev_ops->put_device(ti_sci, id);
383 if (ret)
384 panic("Failed to put device %u (%d)\n", id, ret);
385 }
386
387 const u32 put_core_ids[] = {
388 AM6_DEV_MCU_ARMSS0_CPU1,
389 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
390 };
391
392 /* Iterate through list of cores to put (shutdown) */
393 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
394 u32 id = put_core_ids[i];
395
396 /*
397 * Queue up the core shutdown request. Note that this call
398 * needs to be followed up by an actual invocation of an WFE
399 * or WFI CPU instruction.
400 */
401 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
402 if (ret)
403 panic("Failed sending core %u shutdown message (%d)\n",
404 id, ret);
405 }
406}
407#endif