blob: cb96581bfbb5c2df0471e73a37b68328f81973aa [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>
Lokesh Vutla32886442018-08-27 15:57:09 +053019
20#ifdef CONFIG_SPL_BUILD
Andreas Dannenberg1c855c12018-08-27 15:57:12 +053021static void mmr_unlock(u32 base, u32 partition)
22{
23 /* Translate the base address */
24 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
25
26 /* Unlock the requested partition if locked using two-step sequence */
27 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
28 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
29}
30
31static void ctrl_mmr_unlock(void)
32{
33 /* Unlock all WKUP_CTRL_MMR0 module registers */
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
37 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
40
41 /* Unlock all MCU_CTRL_MMR0 module registers */
42 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
43 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
44 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
45 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
46
47 /* Unlock all CTRL_MMR0 module registers */
48 mmr_unlock(CTRL_MMR0_BASE, 0);
49 mmr_unlock(CTRL_MMR0_BASE, 1);
50 mmr_unlock(CTRL_MMR0_BASE, 2);
51 mmr_unlock(CTRL_MMR0_BASE, 3);
52 mmr_unlock(CTRL_MMR0_BASE, 6);
53 mmr_unlock(CTRL_MMR0_BASE, 7);
54}
55
Andrew F. Davis9ffea342019-04-12 12:54:42 -040056/*
57 * This uninitialized global variable would normal end up in the .bss section,
58 * but the .bss is cleared between writing and reading this variable, so move
59 * it to the .data section.
60 */
61u32 bootindex __attribute__((section(".data")));
62
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053063static void store_boot_index_from_rom(void)
64{
Andrew F. Davis9ffea342019-04-12 12:54:42 -040065 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053066}
67
Lokesh Vutla32886442018-08-27 15:57:09 +053068void board_init_f(ulong dummy)
69{
Andreas Dannenbergea91da12019-06-04 17:55:50 -050070#if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +053071 struct udevice *dev;
72 int ret;
73#endif
Lokesh Vutlac7bfb852018-08-27 15:57:11 +053074 /*
75 * Cannot delay this further as there is a chance that
76 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
77 */
78 store_boot_index_from_rom();
79
Andreas Dannenberg1c855c12018-08-27 15:57:12 +053080 /* Make all control module registers accessible */
81 ctrl_mmr_unlock();
82
Lokesh Vutlac1e60e82018-11-02 19:51:03 +053083#ifdef CONFIG_CPU_V7R
84 setup_k3_mpu_regions();
85#endif
86
Lokesh Vutla32886442018-08-27 15:57:09 +053087 /* Init DM early in-order to invoke system controller */
88 spl_early_init();
89
Andreas Dannenbergea91da12019-06-04 17:55:50 -050090#ifdef CONFIG_K3_LOAD_SYSFW
91 /*
92 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
93 * regardless of the result of pinctrl. Do this without probing the
94 * device, but instead by searching the device that would request the
95 * given sequence number if probed. The UART will be used by the system
96 * firmware (SYSFW) image for various purposes and SYSFW depends on us
97 * to initialize its pin settings.
98 */
99 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
100 if (!ret)
101 pinctrl_select_state(dev, "default");
102
103 /*
104 * Load, start up, and configure system controller firmware. Provide
105 * the U-Boot console init function to the SYSFW post-PM configuration
106 * callback hook, effectively switching on (or over) the console
107 * output.
108 */
109 k3_sysfw_loader(preloader_console_init);
110#else
Lokesh Vutla32886442018-08-27 15:57:09 +0530111 /* Prepare console output */
112 preloader_console_init();
Andreas Dannenbergea91da12019-06-04 17:55:50 -0500113#endif
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530114
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500115 /* Perform EEPROM-based board detection */
116 do_board_detect();
117
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530118#ifdef CONFIG_K3_AM654_DDRSS
119 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg7f6b62e2019-03-11 15:15:43 -0500120 if (ret)
121 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla2c69d5c2018-11-02 19:51:06 +0530122#endif
Lokesh Vutla32886442018-08-27 15:57:09 +0530123}
124
Andrew F. Davisc5161462018-10-03 10:03:23 -0500125u32 spl_boot_mode(const u32 boot_device)
126{
127#if defined(CONFIG_SUPPORT_EMMC_BOOT)
128 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davisc5161462018-10-03 10:03:23 -0500129
130 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
131 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
132
133 /* eMMC boot0 mode is only supported for primary boot */
134 if (bootindex == K3_PRIMARY_BOOTMODE &&
135 bootmode == BOOT_DEVICE_MMC1)
136 return MMCSD_MODE_EMMCBOOT;
137#endif
138
139 /* Everything else use filesystem if available */
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800140#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davisc5161462018-10-03 10:03:23 -0500141 return MMCSD_MODE_FS;
142#else
143 return MMCSD_MODE_RAW;
144#endif
145}
146
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530147static u32 __get_backup_bootmedia(u32 devstat)
Lokesh Vutla32886442018-08-27 15:57:09 +0530148{
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530149 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
150 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
151
152 switch (bkup_boot) {
153 case BACKUP_BOOT_DEVICE_USB:
154 return BOOT_DEVICE_USB;
155 case BACKUP_BOOT_DEVICE_UART:
156 return BOOT_DEVICE_UART;
157 case BACKUP_BOOT_DEVICE_ETHERNET:
158 return BOOT_DEVICE_ETHERNET;
159 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500160 {
161 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
162 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
163 if (port == 0x0)
164 return BOOT_DEVICE_MMC1;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530165 return BOOT_DEVICE_MMC2;
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500166 }
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530167 case BACKUP_BOOT_DEVICE_SPI:
168 return BOOT_DEVICE_SPI;
169 case BACKUP_BOOT_DEVICE_HYPERFLASH:
170 return BOOT_DEVICE_HYPERFLASH;
171 case BACKUP_BOOT_DEVICE_I2C:
172 return BOOT_DEVICE_I2C;
173 };
174
Lokesh Vutla32886442018-08-27 15:57:09 +0530175 return BOOT_DEVICE_RAM;
176}
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530177
178static u32 __get_primary_bootmedia(u32 devstat)
179{
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500180 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
181 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530182
183 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
184 bootmode = BOOT_DEVICE_SPI;
185
Andrew F. Davisf515cf02018-10-03 10:03:22 -0500186 if (bootmode == BOOT_DEVICE_MMC2) {
187 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
188 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
189 if (port == 0x0)
190 bootmode = BOOT_DEVICE_MMC1;
191 } else if (bootmode == BOOT_DEVICE_MMC1) {
192 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
193 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
194 if (port == 0x1)
195 bootmode = BOOT_DEVICE_MMC2;
196 }
197
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530198 return bootmode;
199}
200
201u32 spl_boot_device(void)
202{
203 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlac7bfb852018-08-27 15:57:11 +0530204
205 if (bootindex == K3_PRIMARY_BOOTMODE)
206 return __get_primary_bootmedia(devstat);
207 else
208 return __get_backup_bootmedia(devstat);
209}
Lokesh Vutla32886442018-08-27 15:57:09 +0530210#endif
211
212#ifndef CONFIG_SYSRESET
213void reset_cpu(ulong ignored)
214{
215}
216#endif