blob: b7f0546dd785f646e63ef7c87d05e61b9c5dc4ba [file] [log] [blame]
Lokesh Vutlac2562d72019-06-13 10:29:42 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * J721E: SoC specific initialization
4 *
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 */
8
9#include <common.h>
10#include <spl.h>
11#include <asm/io.h>
12#include <asm/armv7_mpu.h>
Lokesh Vutla0a704922019-06-13 10:29:43 +053013#include <asm/arch/hardware.h>
Lokesh Vutlac2562d72019-06-13 10:29:42 +053014#include "common.h"
15
16#ifdef CONFIG_SPL_BUILD
Andreas Dannenbergb73fcbc2019-06-13 10:29:44 +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, 4);
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
37
38 /* Unlock all MCU_CTRL_MMR0 module registers */
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
40 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
41 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
42 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
43 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
44
45 /* Unlock all CTRL_MMR0 module registers */
46 mmr_unlock(CTRL_MMR0_BASE, 0);
47 mmr_unlock(CTRL_MMR0_BASE, 1);
48 mmr_unlock(CTRL_MMR0_BASE, 2);
49 mmr_unlock(CTRL_MMR0_BASE, 3);
50 mmr_unlock(CTRL_MMR0_BASE, 4);
51 mmr_unlock(CTRL_MMR0_BASE, 5);
52 mmr_unlock(CTRL_MMR0_BASE, 6);
53 mmr_unlock(CTRL_MMR0_BASE, 7);
54}
55
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +053056/*
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
63static void store_boot_index_from_rom(void)
64{
65 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
66}
67
Lokesh Vutlac2562d72019-06-13 10:29:42 +053068void board_init_f(ulong dummy)
69{
70 /*
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +053071 * Cannot delay this further as there is a chance that
72 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
Lokesh Vutlac2562d72019-06-13 10:29:42 +053073 */
Andreas Dannenbergf94a07c2019-06-13 10:29:45 +053074 store_boot_index_from_rom();
Lokesh Vutlac2562d72019-06-13 10:29:42 +053075
Andreas Dannenbergb73fcbc2019-06-13 10:29:44 +053076 /* Make all control module registers accessible */
77 ctrl_mmr_unlock();
78
Lokesh Vutlac2562d72019-06-13 10:29:42 +053079#ifdef CONFIG_CPU_V7R
80 setup_k3_mpu_regions();
81#endif
82
83 /* Init DM early */
84 spl_early_init();
85
86 /* Prepare console output */
87 preloader_console_init();
88}
Lokesh Vutla0a704922019-06-13 10:29:43 +053089
90u32 spl_boot_mode(const u32 boot_device)
91{
92 switch (boot_device) {
93 case BOOT_DEVICE_MMC1:
94 return MMCSD_MODE_EMMCBOOT;
95 case BOOT_DEVICE_MMC2:
96 return MMCSD_MODE_FS;
97 default:
98 return MMCSD_MODE_RAW;
99 }
100}
101
102static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
103{
104
105 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
106 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
107
108 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
109 BOOT_MODE_B_SHIFT;
110
111 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
112 bootmode = BOOT_DEVICE_SPI;
113
114 if (bootmode == BOOT_DEVICE_MMC2) {
115 u32 port = (main_devstat &
116 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
117 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
118 if (port == 0x0)
119 bootmode = BOOT_DEVICE_MMC1;
120 }
121
122 return bootmode;
123}
124
125u32 spl_boot_device(void)
126{
127 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
128 u32 main_devstat;
129
130 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
131 printf("ERROR: MCU only boot is not yet supported\n");
132 return BOOT_DEVICE_RAM;
133 }
134
135 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
136 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
137
138 /* ToDo: Add support for backup boot media */
139 return __get_primary_bootmedia(main_devstat, wkup_devstat);
140}
Lokesh Vutlac2562d72019-06-13 10:29:42 +0530141#endif