blob: 60a580305df01d27e157d5696897fd748a436b92 [file] [log] [blame]
Lokesh Vutlaed0e6052018-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 Vutlae0064602018-08-27 15:57:11 +053010#include <asm/io.h>
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053011#include <spl.h>
Lokesh Vutlae0064602018-08-27 15:57:11 +053012#include <asm/arch/hardware.h>
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +053013#include "common.h"
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +053014#include <dm.h>
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053015
16#ifdef CONFIG_SPL_BUILD
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053017static void mmr_unlock(u32 base, u32 partition)
18{
19 /* Translate the base address */
20 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
21
22 /* Unlock the requested partition if locked using two-step sequence */
23 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
24 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
25}
26
27static void ctrl_mmr_unlock(void)
28{
29 /* Unlock all WKUP_CTRL_MMR0 module registers */
30 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
31 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
36
37 /* Unlock all MCU_CTRL_MMR0 module registers */
38 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
40 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
41 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
42
43 /* Unlock all CTRL_MMR0 module registers */
44 mmr_unlock(CTRL_MMR0_BASE, 0);
45 mmr_unlock(CTRL_MMR0_BASE, 1);
46 mmr_unlock(CTRL_MMR0_BASE, 2);
47 mmr_unlock(CTRL_MMR0_BASE, 3);
48 mmr_unlock(CTRL_MMR0_BASE, 6);
49 mmr_unlock(CTRL_MMR0_BASE, 7);
50}
51
Andrew F. Davis407a2192019-04-12 12:54:42 -040052/*
53 * This uninitialized global variable would normal end up in the .bss section,
54 * but the .bss is cleared between writing and reading this variable, so move
55 * it to the .data section.
56 */
57u32 bootindex __attribute__((section(".data")));
58
Lokesh Vutlae0064602018-08-27 15:57:11 +053059static void store_boot_index_from_rom(void)
60{
Andrew F. Davis407a2192019-04-12 12:54:42 -040061 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
Lokesh Vutlae0064602018-08-27 15:57:11 +053062}
63
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053064void board_init_f(ulong dummy)
65{
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +053066#if defined(CONFIG_K3_AM654_DDRSS)
67 struct udevice *dev;
68 int ret;
69#endif
Lokesh Vutlae0064602018-08-27 15:57:11 +053070 /*
71 * Cannot delay this further as there is a chance that
72 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
73 */
74 store_boot_index_from_rom();
75
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053076 /* Make all control module registers accessible */
77 ctrl_mmr_unlock();
78
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +053079#ifdef CONFIG_CPU_V7R
80 setup_k3_mpu_regions();
81#endif
82
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053083 /* Init DM early in-order to invoke system controller */
84 spl_early_init();
85
86 /* Prepare console output */
87 preloader_console_init();
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +053088
89#ifdef CONFIG_K3_AM654_DDRSS
90 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
Andreas Dannenberg3e9b9c12019-03-11 15:15:43 -050091 if (ret)
92 panic("DRAM init failed: %d\n", ret);
Lokesh Vutla59ebf4a2018-11-02 19:51:06 +053093#endif
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053094}
95
Andrew F. Davis81089a52018-10-03 10:03:23 -050096u32 spl_boot_mode(const u32 boot_device)
97{
98#if defined(CONFIG_SUPPORT_EMMC_BOOT)
99 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Andrew F. Davis81089a52018-10-03 10:03:23 -0500100
101 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
102 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
103
104 /* eMMC boot0 mode is only supported for primary boot */
105 if (bootindex == K3_PRIMARY_BOOTMODE &&
106 bootmode == BOOT_DEVICE_MMC1)
107 return MMCSD_MODE_EMMCBOOT;
108#endif
109
110 /* Everything else use filesystem if available */
Tien Fong Cheef4b40922019-01-23 14:20:05 +0800111#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Andrew F. Davis81089a52018-10-03 10:03:23 -0500112 return MMCSD_MODE_FS;
113#else
114 return MMCSD_MODE_RAW;
115#endif
116}
117
Lokesh Vutlae0064602018-08-27 15:57:11 +0530118static u32 __get_backup_bootmedia(u32 devstat)
119{
120 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
121 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
122
123 switch (bkup_boot) {
124 case BACKUP_BOOT_DEVICE_USB:
125 return BOOT_DEVICE_USB;
126 case BACKUP_BOOT_DEVICE_UART:
127 return BOOT_DEVICE_UART;
128 case BACKUP_BOOT_DEVICE_ETHERNET:
129 return BOOT_DEVICE_ETHERNET;
130 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500131 {
132 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
133 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
134 if (port == 0x0)
135 return BOOT_DEVICE_MMC1;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530136 return BOOT_DEVICE_MMC2;
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500137 }
Lokesh Vutlae0064602018-08-27 15:57:11 +0530138 case BACKUP_BOOT_DEVICE_SPI:
139 return BOOT_DEVICE_SPI;
140 case BACKUP_BOOT_DEVICE_HYPERFLASH:
141 return BOOT_DEVICE_HYPERFLASH;
142 case BACKUP_BOOT_DEVICE_I2C:
143 return BOOT_DEVICE_I2C;
144 };
145
146 return BOOT_DEVICE_RAM;
147}
148
149static u32 __get_primary_bootmedia(u32 devstat)
150{
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500151 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
152 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530153
154 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
155 bootmode = BOOT_DEVICE_SPI;
156
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500157 if (bootmode == BOOT_DEVICE_MMC2) {
158 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
159 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
160 if (port == 0x0)
161 bootmode = BOOT_DEVICE_MMC1;
162 } else if (bootmode == BOOT_DEVICE_MMC1) {
163 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
164 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
165 if (port == 0x1)
166 bootmode = BOOT_DEVICE_MMC2;
167 }
168
Lokesh Vutlae0064602018-08-27 15:57:11 +0530169 return bootmode;
170}
171
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530172u32 spl_boot_device(void)
173{
Lokesh Vutlae0064602018-08-27 15:57:11 +0530174 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
Lokesh Vutlae0064602018-08-27 15:57:11 +0530175
176 if (bootindex == K3_PRIMARY_BOOTMODE)
177 return __get_primary_bootmedia(devstat);
178 else
179 return __get_backup_bootmedia(devstat);
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530180}
181#endif
182
183#ifndef CONFIG_SYSRESET
184void reset_cpu(ulong ignored)
185{
186}
187#endif