blob: a78ffbb674e37ca68cde812355b8fc578dc7e506 [file] [log] [blame]
Lokesh Vutla32886442018-08-27 15:57:09 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * K3: Architecture initialization
4 *
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 Vutlac7bfb852018-08-27 15:57:11 +053010#include <asm/io.h>
Lokesh Vutla32886442018-08-27 15:57:09 +053011#include <spl.h>
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053012#include <asm/arch/hardware.h>
Andreas Dannenbergea91da12019-06-04 17:55:50 -050013#include <asm/arch/sysfw-loader.h>
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050014#include <asm/arch/sys_proto.h>
Lokesh Vutlac1e60e82018-11-02 19:51:03 +053015#include "common.h"
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +053016#include <dm.h>
Andreas Dannenbergea91da12019-06-04 17:55:50 -050017#include <dm/uclass-internal.h>
18#include <dm/pinctrl.h>
Andreas Dannenberg31175f82019-06-07 19:24:42 +053019#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutla32886442018-08-27 15:57:09 +053020
21#ifdef CONFIG_SPL_BUILD
Andreas Dannenberg1c855c12018-08-27 15:57:12 +053022static void mmr_unlock(u32 base, u32 partition)
23{
24 /* Translate the base address */
25 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
26
27 /* Unlock the requested partition if locked using two-step sequence */
28 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
29 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
30}
31
32static void ctrl_mmr_unlock(void)
33{
34 /* Unlock all WKUP_CTRL_MMR0 module registers */
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
37 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
40 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
41
42 /* Unlock all MCU_CTRL_MMR0 module registers */
43 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
44 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
45 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
46 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
47
48 /* Unlock all CTRL_MMR0 module registers */
49 mmr_unlock(CTRL_MMR0_BASE, 0);
50 mmr_unlock(CTRL_MMR0_BASE, 1);
51 mmr_unlock(CTRL_MMR0_BASE, 2);
52 mmr_unlock(CTRL_MMR0_BASE, 3);
53 mmr_unlock(CTRL_MMR0_BASE, 6);
54 mmr_unlock(CTRL_MMR0_BASE, 7);
55}
56
Andrew F. Davis9ffea342019-04-12 12:54:42 -040057/*
58 * This uninitialized global variable would normal end up in the .bss section,
59 * but the .bss is cleared between writing and reading this variable, so move
60 * it to the .data section.
61 */
62u32 bootindex __attribute__((section(".data")));
63
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053064static void store_boot_index_from_rom(void)
65{
Andrew F. Davis9ffea342019-04-12 12:54:42 -040066 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053067}
68
Lokesh Vutla32886442018-08-27 15:57:09 +053069void board_init_f(ulong dummy)
70{
Andreas Dannenbergea91da12019-06-04 17:55:50 -050071#if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +053072 struct udevice *dev;
73 int ret;
74#endif
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053075 /*
76 * Cannot delay this further as there is a chance that
77 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
78 */
79 store_boot_index_from_rom();
80
Andreas Dannenberg1c855c12018-08-27 15:57:12 +053081 /* Make all control module registers accessible */
82 ctrl_mmr_unlock();
83
Lokesh Vutlac1e60e82018-11-02 19:51:03 +053084#ifdef CONFIG_CPU_V7R
Lokesh Vutla5fbd6fe2019-12-31 15:49:55 +053085 disable_linefill_optimization();
Lokesh Vutlac1e60e82018-11-02 19:51:03 +053086 setup_k3_mpu_regions();
87#endif
88
Lokesh Vutla32886442018-08-27 15:57:09 +053089 /* Init DM early in-order to invoke system controller */
90 spl_early_init();
91
Andreas Dannenbergea91da12019-06-04 17:55:50 -050092#ifdef CONFIG_K3_LOAD_SYSFW
93 /*
94 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
95 * regardless of the result of pinctrl. Do this without probing the
96 * device, but instead by searching the device that would request the
97 * given sequence number if probed. The UART will be used by the system
98 * firmware (SYSFW) image for various purposes and SYSFW depends on us
99 * to initialize its pin settings.
100 */
101 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
102 if (!ret)
103 pinctrl_select_state(dev, "default");
104
105 /*
106 * Load, start up, and configure system controller firmware. Provide
107 * the U-Boot console init function to the SYSFW post-PM configuration
108 * callback hook, effectively switching on (or over) the console
109 * output.
110 */
111 k3_sysfw_loader(preloader_console_init);
112#else
Lokesh Vutla32886442018-08-27 15:57:09 +0530113 /* Prepare console output */
114 preloader_console_init();
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500115#endif
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530116
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500117 /* Perform EEPROM-based board detection */
118 do_board_detect();
119
Keerthy2cd50972019-10-24 15:00:52 +0530120#if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
121 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
122 &dev);
123 if (ret)
124 printf("AVS init failed: %d\n", ret);
125#endif
126
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530127#ifdef CONFIG_K3_AM654_DDRSS
128 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg7f6b62e2019-03-11 15:15:43 -0500129 if (ret)
130 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530131#endif
Lokesh Vutla32886442018-08-27 15:57:09 +0530132}
133
Andrew F. Davisc5161462018-10-03 10:03:23 -0500134u32 spl_boot_mode(const u32 boot_device)
135{
136#if defined(CONFIG_SUPPORT_EMMC_BOOT)
137 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davisc5161462018-10-03 10:03:23 -0500138
139 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
140 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
141
142 /* eMMC boot0 mode is only supported for primary boot */
143 if (bootindex == K3_PRIMARY_BOOTMODE &&
144 bootmode == BOOT_DEVICE_MMC1)
145 return MMCSD_MODE_EMMCBOOT;
146#endif
147
148 /* Everything else use filesystem if available */
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800149#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davisc5161462018-10-03 10:03:23 -0500150 return MMCSD_MODE_FS;
151#else
152 return MMCSD_MODE_RAW;
153#endif
154}
155
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530156static u32 __get_backup_bootmedia(u32 devstat)
Lokesh Vutla32886442018-08-27 15:57:09 +0530157{
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530158 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
159 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
160
161 switch (bkup_boot) {
162 case BACKUP_BOOT_DEVICE_USB:
163 return BOOT_DEVICE_USB;
164 case BACKUP_BOOT_DEVICE_UART:
165 return BOOT_DEVICE_UART;
166 case BACKUP_BOOT_DEVICE_ETHERNET:
167 return BOOT_DEVICE_ETHERNET;
168 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500169 {
170 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
171 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
172 if (port == 0x0)
173 return BOOT_DEVICE_MMC1;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530174 return BOOT_DEVICE_MMC2;
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500175 }
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530176 case BACKUP_BOOT_DEVICE_SPI:
177 return BOOT_DEVICE_SPI;
178 case BACKUP_BOOT_DEVICE_HYPERFLASH:
179 return BOOT_DEVICE_HYPERFLASH;
180 case BACKUP_BOOT_DEVICE_I2C:
181 return BOOT_DEVICE_I2C;
182 };
183
Lokesh Vutla32886442018-08-27 15:57:09 +0530184 return BOOT_DEVICE_RAM;
185}
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530186
187static u32 __get_primary_bootmedia(u32 devstat)
188{
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500189 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
190 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530191
192 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
193 bootmode = BOOT_DEVICE_SPI;
194
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500195 if (bootmode == BOOT_DEVICE_MMC2) {
196 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
197 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
198 if (port == 0x0)
199 bootmode = BOOT_DEVICE_MMC1;
200 } else if (bootmode == BOOT_DEVICE_MMC1) {
201 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
202 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
203 if (port == 0x1)
204 bootmode = BOOT_DEVICE_MMC2;
205 }
206
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530207 return bootmode;
208}
209
210u32 spl_boot_device(void)
211{
212 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530213
214 if (bootindex == K3_PRIMARY_BOOTMODE)
215 return __get_primary_bootmedia(devstat);
216 else
217 return __get_backup_bootmedia(devstat);
218}
Lokesh Vutla32886442018-08-27 15:57:09 +0530219#endif
220
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530221#ifdef CONFIG_SYS_K3_SPL_ATF
222
223#define AM6_DEV_MCU_RTI0 134
224#define AM6_DEV_MCU_RTI1 135
225#define AM6_DEV_MCU_ARMSS0_CPU0 159
226#define AM6_DEV_MCU_ARMSS0_CPU1 245
227
228void release_resources_for_core_shutdown(void)
229{
Lokesh Vutlaac9ca952019-09-09 12:47:38 +0530230 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
231 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
232 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530233 int ret;
234 u32 i;
235
236 const u32 put_device_ids[] = {
237 AM6_DEV_MCU_RTI0,
238 AM6_DEV_MCU_RTI1,
239 };
240
Andreas Dannenberg31175f82019-06-07 19:24:42 +0530241 /* Iterate through list of devices to put (shutdown) */
242 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
243 u32 id = put_device_ids[i];
244
245 ret = dev_ops->put_device(ti_sci, id);
246 if (ret)
247 panic("Failed to put device %u (%d)\n", id, ret);
248 }
249
250 const u32 put_core_ids[] = {
251 AM6_DEV_MCU_ARMSS0_CPU1,
252 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
253 };
254
255 /* Iterate through list of cores to put (shutdown) */
256 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
257 u32 id = put_core_ids[i];
258
259 /*
260 * Queue up the core shutdown request. Note that this call
261 * needs to be followed up by an actual invocation of an WFE
262 * or WFI CPU instruction.
263 */
264 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
265 if (ret)
266 panic("Failed sending core %u shutdown message (%d)\n",
267 id, ret);
268 }
269}
270#endif