blob: c6d4f05a01a77a251a5b32851a340f7a8e1d1a72 [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>
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053012#include <asm/io.h>
Lokesh Vutla32886442018-08-27 15:57:09 +053013#include <spl.h>
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053014#include <asm/arch/hardware.h>
Andreas Dannenbergea91da12019-06-04 17:55:50 -050015#include <asm/arch/sysfw-loader.h>
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050016#include <asm/arch/sys_proto.h>
Lokesh Vutlac1e60e82018-11-02 19:51:03 +053017#include "common.h"
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +053018#include <dm.h>
Andreas Dannenbergea91da12019-06-04 17:55:50 -050019#include <dm/uclass-internal.h>
20#include <dm/pinctrl.h>
Andreas Dannenberg31175f82019-06-07 19:24:42 +053021#include <linux/soc/ti/ti_sci_protocol.h>
Faiz Abbasfe1217e2020-08-03 11:35:06 +053022#include <log.h>
Faiz Abbas68393212020-02-26 13:44:36 +053023#include <mmc.h>
Faiz Abbasfe1217e2020-08-03 11:35:06 +053024#include <stdlib.h>
Lokesh Vutla32886442018-08-27 15:57:09 +053025
Faiz Abbas3385a862020-08-03 11:35:09 +053026DECLARE_GLOBAL_DATA_PTR;
27
Lokesh Vutla32886442018-08-27 15:57:09 +053028#ifdef CONFIG_SPL_BUILD
Andrew F. Davisf0bcb662020-01-10 14:35:21 -050029#ifdef CONFIG_K3_LOAD_SYSFW
30#ifdef CONFIG_TI_SECURE_DEVICE
31struct fwl_data main_cbass_fwls[] = {
32 { "MMCSD1_CFG", 2057, 1 },
33 { "MMCSD0_CFG", 2058, 1 },
34 { "USB3SS0_SLV0", 2176, 2 },
35 { "PCIE0_SLV", 2336, 8 },
36 { "PCIE1_SLV", 2337, 8 },
37 { "PCIE0_CFG", 2688, 1 },
38 { "PCIE1_CFG", 2689, 1 },
39}, mcu_cbass_fwls[] = {
40 { "MCU_ARMSS0_CORE0_SLV", 1024, 1 },
41 { "MCU_ARMSS0_CORE1_SLV", 1028, 1 },
42 { "MCU_FSS0_S1", 1033, 8 },
43 { "MCU_FSS0_S0", 1036, 8 },
44 { "MCU_CPSW0", 1220, 1 },
45};
46#endif
47#endif
48
Andreas Dannenberg1c855c12018-08-27 15:57:12 +053049static void mmr_unlock(u32 base, u32 partition)
50{
51 /* Translate the base address */
52 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
53
54 /* Unlock the requested partition if locked using two-step sequence */
55 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
56 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
57}
58
59static void ctrl_mmr_unlock(void)
60{
61 /* Unlock all WKUP_CTRL_MMR0 module registers */
62 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
63 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
64 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
65 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
66 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
67 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
68
69 /* Unlock all MCU_CTRL_MMR0 module registers */
70 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
71 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
72 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
73 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
74
75 /* Unlock all CTRL_MMR0 module registers */
76 mmr_unlock(CTRL_MMR0_BASE, 0);
77 mmr_unlock(CTRL_MMR0_BASE, 1);
78 mmr_unlock(CTRL_MMR0_BASE, 2);
79 mmr_unlock(CTRL_MMR0_BASE, 3);
80 mmr_unlock(CTRL_MMR0_BASE, 6);
81 mmr_unlock(CTRL_MMR0_BASE, 7);
82}
83
Andrew F. Davis9ffea342019-04-12 12:54:42 -040084/*
85 * This uninitialized global variable would normal end up in the .bss section,
86 * but the .bss is cleared between writing and reading this variable, so move
87 * it to the .data section.
88 */
89u32 bootindex __attribute__((section(".data")));
90
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053091static void store_boot_index_from_rom(void)
92{
Andrew F. Davis9ffea342019-04-12 12:54:42 -040093 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053094}
95
Faiz Abbasb4372bf2020-08-03 11:35:08 +053096#if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC)
Faiz Abbas68393212020-02-26 13:44:36 +053097void k3_mmc_stop_clock(void)
98{
99 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
100 struct mmc *mmc = find_mmc_device(0);
101
102 if (!mmc)
103 return;
104
105 mmc->saved_clock = mmc->clock;
106 mmc_set_clock(mmc, 0, true);
107 }
108}
109
110void k3_mmc_restart_clock(void)
111{
112 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
113 struct mmc *mmc = find_mmc_device(0);
114
115 if (!mmc)
116 return;
117
118 mmc_set_clock(mmc, mmc->saved_clock, false);
119 }
120}
Faiz Abbasb4372bf2020-08-03 11:35:08 +0530121#else
122void k3_mmc_stop_clock(void) {}
123void k3_mmc_restart_clock(void) {}
Faiz Abbas68393212020-02-26 13:44:36 +0530124#endif
Faiz Abbas3385a862020-08-03 11:35:09 +0530125#if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE)
126#define CTRLMMR_SERDES0_CTRL 0x00104080
127#define PCIE_LANE0 0x1
128static int fixup_usb_boot(void)
129{
130 int ret;
Faiz Abbas68393212020-02-26 13:44:36 +0530131
Faiz Abbas3385a862020-08-03 11:35:09 +0530132 switch (spl_boot_device()) {
133 case BOOT_DEVICE_USB:
134 /*
135 * If bootmode is Host bootmode, fixup the dr_mode to host
136 * before the dwc3 bind takes place
137 */
138 ret = fdt_find_and_setprop((void *)gd->fdt_blob,
139 "/interconnect@100000/dwc3@4000000/usb@10000",
140 "dr_mode", "host", 11, 0);
141 if (ret)
142 printf("%s: fdt_find_and_setprop() failed:%d\n", __func__,
143 ret);
144 fallthrough;
145 case BOOT_DEVICE_DFU:
146 /*
147 * The serdes mux between PCIe and USB3 needs to be set to PCIe for
148 * accessing the interface at USB 2.0
149 */
150 writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL);
151 default:
152 break;
153 }
154
155 return 0;
156}
157
158int fdtdec_board_setup(const void *fdt_blob)
159{
160 return fixup_usb_boot();
161}
162#endif
Lokesh Vutla32886442018-08-27 15:57:09 +0530163void board_init_f(ulong dummy)
164{
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500165#if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530166 struct udevice *dev;
Faiz Abbasfe1217e2020-08-03 11:35:06 +0530167 size_t pool_size;
168 void *pool_addr;
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530169 int ret;
170#endif
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530171 /*
172 * Cannot delay this further as there is a chance that
173 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
174 */
175 store_boot_index_from_rom();
176
Andreas Dannenberg1c855c12018-08-27 15:57:12 +0530177 /* Make all control module registers accessible */
178 ctrl_mmr_unlock();
179
Lokesh Vutlac1e60e82018-11-02 19:51:03 +0530180#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +0530181 disable_linefill_optimization();
Lokesh Vutlac1e60e82018-11-02 19:51:03 +0530182 setup_k3_mpu_regions();
183#endif
184
Lokesh Vutla32886442018-08-27 15:57:09 +0530185 /* Init DM early in-order to invoke system controller */
186 spl_early_init();
187
Andreas Dannenbergb45d2cd2018-12-04 22:29:47 -0600188#ifdef CONFIG_K3_EARLY_CONS
189 /*
190 * Allow establishing an early console as required for example when
191 * doing a UART-based boot. Note that this console may not "survive"
192 * through a SYSFW PM-init step and will need a re-init in some way
193 * due to changing module clock frequencies.
194 */
195 early_console_init();
196#endif
197
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500198#ifdef CONFIG_K3_LOAD_SYSFW
199 /*
Faiz Abbasfe1217e2020-08-03 11:35:06 +0530200 * Initialize an early full malloc environment. Do so by allocating a
201 * new malloc area inside the currently active pre-relocation "first"
202 * malloc pool of which we use all that's left.
203 */
204 pool_size = CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr;
205 pool_addr = malloc(pool_size);
206 if (!pool_addr)
207 panic("ERROR: Can't allocate full malloc pool!\n");
208
209 mem_malloc_init((ulong)pool_addr, (ulong)pool_size);
210 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
211 debug("%s: initialized an early full malloc pool at 0x%08lx of 0x%lx bytes\n",
212 __func__, (unsigned long)pool_addr, (unsigned long)pool_size);
213 /*
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500214 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
215 * regardless of the result of pinctrl. Do this without probing the
216 * device, but instead by searching the device that would request the
217 * given sequence number if probed. The UART will be used by the system
218 * firmware (SYSFW) image for various purposes and SYSFW depends on us
219 * to initialize its pin settings.
220 */
221 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
222 if (!ret)
223 pinctrl_select_state(dev, "default");
224
225 /*
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530226 * Load, start up, and configure system controller firmware while
227 * also populating the SYSFW post-PM configuration callback hook.
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500228 */
Faiz Abbas68393212020-02-26 13:44:36 +0530229 k3_sysfw_loader(k3_mmc_stop_clock, k3_mmc_restart_clock);
230
231 /* Prepare console output */
232 preloader_console_init();
Andrew F. Davisf0bcb662020-01-10 14:35:21 -0500233
234 /* Disable ROM configured firewalls right after loading sysfw */
235#ifdef CONFIG_TI_SECURE_DEVICE
236 remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls));
237 remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls));
238#endif
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500239#else
Lokesh Vutla32886442018-08-27 15:57:09 +0530240 /* Prepare console output */
241 preloader_console_init();
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500242#endif
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530243
Lokesh Vutla5fafe442020-03-10 16:50:58 +0530244 /* Output System Firmware version info */
245 k3_sysfw_print_ver();
246
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500247 /* Perform EEPROM-based board detection */
248 do_board_detect();
249
Keerthy2cd50972019-10-24 15:00:52 +0530250#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
251 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
252 &dev);
253 if (ret)
254 printf("AVS init failed: %d\n", ret);
255#endif
256
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530257#ifdef CONFIG_K3_AM654_DDRSS
258 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg7f6b62e2019-03-11 15:15:43 -0500259 if (ret)
260 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530261#endif
Jan Kiszka7ce99f72020-05-18 07:57:22 +0200262 spl_enable_dcache();
Lokesh Vutla32886442018-08-27 15:57:09 +0530263}
264
Harald Seiler0bf7ab12020-04-15 11:33:30 +0200265u32 spl_mmc_boot_mode(const u32 boot_device)
Andrew F. Davisc5161462018-10-03 10:03:23 -0500266{
267#if defined(CONFIG_SUPPORT_EMMC_BOOT)
268 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davisc5161462018-10-03 10:03:23 -0500269
270 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
271 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
272
273 /* eMMC boot0 mode is only supported for primary boot */
274 if (bootindex == K3_PRIMARY_BOOTMODE &&
275 bootmode == BOOT_DEVICE_MMC1)
276 return MMCSD_MODE_EMMCBOOT;
277#endif
278
279 /* Everything else use filesystem if available */
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800280#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davisc5161462018-10-03 10:03:23 -0500281 return MMCSD_MODE_FS;
282#else
283 return MMCSD_MODE_RAW;
284#endif
285}
286
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530287static u32 __get_backup_bootmedia(u32 devstat)
Lokesh Vutla32886442018-08-27 15:57:09 +0530288{
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530289 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
290 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
291
292 switch (bkup_boot) {
293 case BACKUP_BOOT_DEVICE_USB:
294 return BOOT_DEVICE_USB;
295 case BACKUP_BOOT_DEVICE_UART:
296 return BOOT_DEVICE_UART;
297 case BACKUP_BOOT_DEVICE_ETHERNET:
298 return BOOT_DEVICE_ETHERNET;
299 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500300 {
301 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
302 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
303 if (port == 0x0)
304 return BOOT_DEVICE_MMC1;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530305 return BOOT_DEVICE_MMC2;
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500306 }
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530307 case BACKUP_BOOT_DEVICE_SPI:
308 return BOOT_DEVICE_SPI;
309 case BACKUP_BOOT_DEVICE_HYPERFLASH:
310 return BOOT_DEVICE_HYPERFLASH;
311 case BACKUP_BOOT_DEVICE_I2C:
312 return BOOT_DEVICE_I2C;
313 };
314
Lokesh Vutla32886442018-08-27 15:57:09 +0530315 return BOOT_DEVICE_RAM;
316}
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530317
318static u32 __get_primary_bootmedia(u32 devstat)
319{
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500320 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
321 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530322
323 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
324 bootmode = BOOT_DEVICE_SPI;
325
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500326 if (bootmode == BOOT_DEVICE_MMC2) {
327 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
328 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
329 if (port == 0x0)
330 bootmode = BOOT_DEVICE_MMC1;
331 } else if (bootmode == BOOT_DEVICE_MMC1) {
332 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
333 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
334 if (port == 0x1)
335 bootmode = BOOT_DEVICE_MMC2;
336 }
337
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530338 return bootmode;
339}
340
341u32 spl_boot_device(void)
342{
343 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530344
345 if (bootindex == K3_PRIMARY_BOOTMODE)
346 return __get_primary_bootmedia(devstat);
347 else
348 return __get_backup_bootmedia(devstat);
349}
Lokesh Vutla32886442018-08-27 15:57:09 +0530350#endif
351
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530352#ifdef CONFIG_SYS_K3_SPL_ATF
353
354#define AM6_DEV_MCU_RTI0 134
355#define AM6_DEV_MCU_RTI1 135
356#define AM6_DEV_MCU_ARMSS0_CPU0 159
357#define AM6_DEV_MCU_ARMSS0_CPU1 245
358
359void release_resources_for_core_shutdown(void)
360{
Lokesh Vutlaac9ca952019-09-09 12:47:38 +0530361 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
362 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
363 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530364 int ret;
365 u32 i;
366
367 const u32 put_device_ids[] = {
368 AM6_DEV_MCU_RTI0,
369 AM6_DEV_MCU_RTI1,
370 };
371
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530372 /* Iterate through list of devices to put (shutdown) */
373 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
374 u32 id = put_device_ids[i];
375
376 ret = dev_ops->put_device(ti_sci, id);
377 if (ret)
378 panic("Failed to put device %u (%d)\n", id, ret);
379 }
380
381 const u32 put_core_ids[] = {
382 AM6_DEV_MCU_ARMSS0_CPU1,
383 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
384 };
385
386 /* Iterate through list of cores to put (shutdown) */
387 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
388 u32 id = put_core_ids[i];
389
390 /*
391 * Queue up the core shutdown request. Note that this call
392 * needs to be followed up by an actual invocation of an WFE
393 * or WFI CPU instruction.
394 */
395 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
396 if (ret)
397 panic("Failed sending core %u shutdown message (%d)\n",
398 id, ret);
399 }
400}
401#endif