blob: 0d9525992bb09380a4894f1c028879b0af08abce [file] [log] [blame]
Suman Annad98e8602022-05-25 13:38:42 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * AM625: SoC specific initialization
4 *
5 * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/
6 * Suman Anna <s-anna@ti.com>
7 */
8
9#include <spl.h>
10#include <asm/io.h>
11#include <asm/arch/hardware.h>
12#include <asm/arch/sysfw-loader.h>
13#include "common.h"
14#include <dm.h>
15#include <dm/uclass-internal.h>
16#include <dm/pinctrl.h>
17
18#if defined(CONFIG_SPL_BUILD)
19
20/*
21 * This uninitialized global variable would normal end up in the .bss section,
22 * but the .bss is cleared between writing and reading this variable, so move
23 * it to the .data section.
24 */
25u32 bootindex __section(".data");
26static struct rom_extended_boot_data bootdata __section(".data");
27
28static void store_boot_info_from_rom(void)
29{
30 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
31 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
32 sizeof(struct rom_extended_boot_data));
33}
34
35static void ctrl_mmr_unlock(void)
36{
37 /* Unlock all WKUP_CTRL_MMR0 module registers */
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
40 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
41 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
42 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
44 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
45 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
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, 4);
52 mmr_unlock(CTRL_MMR0_BASE, 6);
53
54 /* Unlock all MCU_CTRL_MMR0 module registers */
55 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
56 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
57 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
58 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
59 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
60 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
61
62 /* Unlock PADCFG_CTRL_MMR padconf registers */
63 mmr_unlock(PADCFG_MMR0_BASE, 1);
64 mmr_unlock(PADCFG_MMR1_BASE, 1);
65}
66
67void board_init_f(ulong dummy)
68{
69 struct udevice *dev;
70 int ret;
71
72#if defined(CONFIG_CPU_V7R)
73 setup_k3_mpu_regions();
74#endif
75
76 /*
77 * Cannot delay this further as there is a chance that
78 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
79 */
80 store_boot_info_from_rom();
81
82 ctrl_mmr_unlock();
83
84 /* Init DM early */
85 spl_early_init();
86
87 /*
88 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
89 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
90 * Do this without probing the device, but instead by searching the
91 * device that would request the given sequence number if probed. The
92 * UARTs will be used by the DM firmware and TIFS firmware images
93 * respectively and the firmware depend on SPL to initialize the pin
94 * settings.
95 */
96 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
97 if (!ret)
98 pinctrl_select_state(dev, "default");
99
100 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
101 if (!ret)
102 pinctrl_select_state(dev, "default");
103
104 preloader_console_init();
105
106#ifdef CONFIG_K3_EARLY_CONS
107 /*
108 * Allow establishing an early console as required for example when
109 * doing a UART-based boot. Note that this console may not "survive"
110 * through a SYSFW PM-init step and will need a re-init in some way
111 * due to changing module clock frequencies.
112 */
113 early_console_init();
114#endif
115
116#if defined(CONFIG_K3_LOAD_SYSFW)
117 /*
118 * Configure and start up system controller firmware. Provide
119 * the U-Boot console init function to the SYSFW post-PM configuration
120 * callback hook, effectively switching on (or over) the console
121 * output.
122 */
123 ret = is_rom_loaded_sysfw(&bootdata);
124 if (!ret)
125 panic("ROM has not loaded TIFS firmware\n");
126
127 k3_sysfw_loader(true, NULL, NULL);
128#endif
129
130 /*
131 * Force probe of clk_k3 driver here to ensure basic default clock
132 * configuration is always done.
133 */
134 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
135 ret = uclass_get_device_by_driver(UCLASS_CLK,
136 DM_DRIVER_GET(ti_clk),
137 &dev);
138 if (ret)
139 printf("Failed to initialize clk-k3!\n");
140 }
141
142 /* Output System Firmware version info */
143 k3_sysfw_print_ver();
144
145#if defined(CONFIG_K3_AM64_DDRSS)
146 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
147 if (ret)
148 panic("DRAM init failed: %d\n", ret);
149#endif
150}
151
152u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
153{
154 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
155 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
156 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
157
158 switch (boot_device) {
159 case BOOT_DEVICE_MMC1:
160 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK) >>
161 MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_SHIFT)
162 return MMCSD_MODE_EMMCBOOT;
163 return MMCSD_MODE_FS;
164
165 case BOOT_DEVICE_MMC2:
166 return MMCSD_MODE_FS;
167
168 default:
169 return MMCSD_MODE_RAW;
170 }
171}
172
173static u32 __get_backup_bootmedia(u32 devstat)
174{
175 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
176 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
177 u32 bkup_bootmode_cfg =
178 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
179 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
180
181 switch (bkup_bootmode) {
182 case BACKUP_BOOT_DEVICE_UART:
183 return BOOT_DEVICE_UART;
184
185 case BACKUP_BOOT_DEVICE_USB:
186 return BOOT_DEVICE_USB;
187
188 case BACKUP_BOOT_DEVICE_ETHERNET:
189 return BOOT_DEVICE_ETHERNET;
190
191 case BACKUP_BOOT_DEVICE_MMC:
192 if (bkup_bootmode_cfg)
193 return BOOT_DEVICE_MMC2;
194 return BOOT_DEVICE_MMC1;
195
196 case BACKUP_BOOT_DEVICE_SPI:
197 return BOOT_DEVICE_SPI;
198
199 case BACKUP_BOOT_DEVICE_I2C:
200 return BOOT_DEVICE_I2C;
201
202 case BACKUP_BOOT_DEVICE_DFU:
203 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
204 return BOOT_DEVICE_USB;
205 return BOOT_DEVICE_DFU;
206 };
207
208 return BOOT_DEVICE_RAM;
209}
210
211static u32 __get_primary_bootmedia(u32 devstat)
212{
213 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
214 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
215 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
216 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
217
218 switch (bootmode) {
219 case BOOT_DEVICE_OSPI:
220 fallthrough;
221 case BOOT_DEVICE_QSPI:
222 fallthrough;
223 case BOOT_DEVICE_XSPI:
224 fallthrough;
225 case BOOT_DEVICE_SPI:
226 return BOOT_DEVICE_SPI;
227
228 case BOOT_DEVICE_ETHERNET_RGMII:
229 fallthrough;
230 case BOOT_DEVICE_ETHERNET_RMII:
231 return BOOT_DEVICE_ETHERNET;
232
233 case BOOT_DEVICE_EMMC:
234 return BOOT_DEVICE_MMC1;
235
236 case BOOT_DEVICE_MMC:
237 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
238 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
239 return BOOT_DEVICE_MMC2;
240 return BOOT_DEVICE_MMC1;
241
242 case BOOT_DEVICE_DFU:
243 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
244 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
245 return BOOT_DEVICE_USB;
246 return BOOT_DEVICE_DFU;
247
248 case BOOT_DEVICE_NOBOOT:
249 return BOOT_DEVICE_RAM;
250 }
251
252 return bootmode;
253}
254
255u32 spl_boot_device(void)
256{
257 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
258 u32 bootmedia;
259
260 if (bootindex == K3_PRIMARY_BOOTMODE)
261 bootmedia = __get_primary_bootmedia(devstat);
262 else
263 bootmedia = __get_backup_bootmedia(devstat);
264
265 debug("am625_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
266 __func__, devstat, bootmedia, bootindex);
267
268 return bootmedia;
269}
270
271#endif /* CONFIG_SPL_BUILD */