blob: 80e88dd185df2bfc00e008ebad555b652aab00e8 [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
17void board_init_f(ulong dummy)
18{
19 /*
20 * ToDo:
21 * - Store boot rom index.
22 * - unlock mmr.
23 */
24
25#ifdef CONFIG_CPU_V7R
26 setup_k3_mpu_regions();
27#endif
28
29 /* Init DM early */
30 spl_early_init();
31
32 /* Prepare console output */
33 preloader_console_init();
34}
Lokesh Vutla0a704922019-06-13 10:29:43 +053035
36u32 spl_boot_mode(const u32 boot_device)
37{
38 switch (boot_device) {
39 case BOOT_DEVICE_MMC1:
40 return MMCSD_MODE_EMMCBOOT;
41 case BOOT_DEVICE_MMC2:
42 return MMCSD_MODE_FS;
43 default:
44 return MMCSD_MODE_RAW;
45 }
46}
47
48static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)
49{
50
51 u32 bootmode = (wkup_devstat & WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
52 WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
53
54 bootmode |= (main_devstat & MAIN_DEVSTAT_BOOT_MODE_B_MASK) <<
55 BOOT_MODE_B_SHIFT;
56
57 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
58 bootmode = BOOT_DEVICE_SPI;
59
60 if (bootmode == BOOT_DEVICE_MMC2) {
61 u32 port = (main_devstat &
62 MAIN_DEVSTAT_PRIM_BOOTMODE_MMC_PORT_MASK) >>
63 MAIN_DEVSTAT_PRIM_BOOTMODE_PORT_SHIFT;
64 if (port == 0x0)
65 bootmode = BOOT_DEVICE_MMC1;
66 }
67
68 return bootmode;
69}
70
71u32 spl_boot_device(void)
72{
73 u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
74 u32 main_devstat;
75
76 if (wkup_devstat & WKUP_DEVSTAT_MCU_OMLY_MASK) {
77 printf("ERROR: MCU only boot is not yet supported\n");
78 return BOOT_DEVICE_RAM;
79 }
80
81 /* MAIN CTRL MMR can only be read if MCU ONLY is 0 */
82 main_devstat = readl(CTRLMMR_MAIN_DEVSTAT);
83
84 /* ToDo: Add support for backup boot media */
85 return __get_primary_bootmedia(main_devstat, wkup_devstat);
86}
Lokesh Vutlac2562d72019-06-13 10:29:42 +053087#endif