blob: fef01075056e8baa8fe98c59282d5190dd15184a [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 Vutlaed0e6052018-08-27 15:57:09 +053014
15#ifdef CONFIG_SPL_BUILD
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053016static void mmr_unlock(u32 base, u32 partition)
17{
18 /* Translate the base address */
19 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
20
21 /* Unlock the requested partition if locked using two-step sequence */
22 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
23 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
24}
25
26static void ctrl_mmr_unlock(void)
27{
28 /* Unlock all WKUP_CTRL_MMR0 module registers */
29 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
30 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
31 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
35
36 /* Unlock all MCU_CTRL_MMR0 module registers */
37 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
38 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
40 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
41
42 /* Unlock all CTRL_MMR0 module registers */
43 mmr_unlock(CTRL_MMR0_BASE, 0);
44 mmr_unlock(CTRL_MMR0_BASE, 1);
45 mmr_unlock(CTRL_MMR0_BASE, 2);
46 mmr_unlock(CTRL_MMR0_BASE, 3);
47 mmr_unlock(CTRL_MMR0_BASE, 6);
48 mmr_unlock(CTRL_MMR0_BASE, 7);
49}
50
Lokesh Vutlae0064602018-08-27 15:57:11 +053051static void store_boot_index_from_rom(void)
52{
53 u32 *boot_index = (u32 *)K3_BOOT_PARAM_TABLE_INDEX_VAL;
54
55 *boot_index = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
56}
57
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053058void board_init_f(ulong dummy)
59{
Lokesh Vutlae0064602018-08-27 15:57:11 +053060 /*
61 * Cannot delay this further as there is a chance that
62 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
63 */
64 store_boot_index_from_rom();
65
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053066 /* Make all control module registers accessible */
67 ctrl_mmr_unlock();
68
Lokesh Vutla23f7b1a2018-11-02 19:51:03 +053069#ifdef CONFIG_CPU_V7R
70 setup_k3_mpu_regions();
71#endif
72
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053073 /* Init DM early in-order to invoke system controller */
74 spl_early_init();
75
76 /* Prepare console output */
77 preloader_console_init();
78}
79
Andrew F. Davis81089a52018-10-03 10:03:23 -050080u32 spl_boot_mode(const u32 boot_device)
81{
82#if defined(CONFIG_SUPPORT_EMMC_BOOT)
83 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
84 u32 bootindex = readl(K3_BOOT_PARAM_TABLE_INDEX_VAL);
85
86 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
87 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
88
89 /* eMMC boot0 mode is only supported for primary boot */
90 if (bootindex == K3_PRIMARY_BOOTMODE &&
91 bootmode == BOOT_DEVICE_MMC1)
92 return MMCSD_MODE_EMMCBOOT;
93#endif
94
95 /* Everything else use filesystem if available */
96#if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
97 return MMCSD_MODE_FS;
98#else
99 return MMCSD_MODE_RAW;
100#endif
101}
102
Lokesh Vutlae0064602018-08-27 15:57:11 +0530103static u32 __get_backup_bootmedia(u32 devstat)
104{
105 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
106 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
107
108 switch (bkup_boot) {
109 case BACKUP_BOOT_DEVICE_USB:
110 return BOOT_DEVICE_USB;
111 case BACKUP_BOOT_DEVICE_UART:
112 return BOOT_DEVICE_UART;
113 case BACKUP_BOOT_DEVICE_ETHERNET:
114 return BOOT_DEVICE_ETHERNET;
115 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500116 {
117 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
118 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
119 if (port == 0x0)
120 return BOOT_DEVICE_MMC1;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530121 return BOOT_DEVICE_MMC2;
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500122 }
Lokesh Vutlae0064602018-08-27 15:57:11 +0530123 case BACKUP_BOOT_DEVICE_SPI:
124 return BOOT_DEVICE_SPI;
125 case BACKUP_BOOT_DEVICE_HYPERFLASH:
126 return BOOT_DEVICE_HYPERFLASH;
127 case BACKUP_BOOT_DEVICE_I2C:
128 return BOOT_DEVICE_I2C;
129 };
130
131 return BOOT_DEVICE_RAM;
132}
133
134static u32 __get_primary_bootmedia(u32 devstat)
135{
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500136 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
137 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530138
139 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
140 bootmode = BOOT_DEVICE_SPI;
141
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500142 if (bootmode == BOOT_DEVICE_MMC2) {
143 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
144 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
145 if (port == 0x0)
146 bootmode = BOOT_DEVICE_MMC1;
147 } else if (bootmode == BOOT_DEVICE_MMC1) {
148 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
149 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
150 if (port == 0x1)
151 bootmode = BOOT_DEVICE_MMC2;
152 }
153
Lokesh Vutlae0064602018-08-27 15:57:11 +0530154 return bootmode;
155}
156
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530157u32 spl_boot_device(void)
158{
Lokesh Vutlae0064602018-08-27 15:57:11 +0530159 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
160 u32 bootindex = readl(K3_BOOT_PARAM_TABLE_INDEX_VAL);
161
162 if (bootindex == K3_PRIMARY_BOOTMODE)
163 return __get_primary_bootmedia(devstat);
164 else
165 return __get_backup_bootmedia(devstat);
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530166}
167#endif
168
169#ifndef CONFIG_SYSRESET
170void reset_cpu(ulong ignored)
171{
172}
173#endif