blob: 68f0b8c011f028460ecb0ae712e29c840c1a0b3f [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 Vutlaed0e6052018-08-27 15:57:09 +053013
14#ifdef CONFIG_SPL_BUILD
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053015static void mmr_unlock(u32 base, u32 partition)
16{
17 /* Translate the base address */
18 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
19
20 /* Unlock the requested partition if locked using two-step sequence */
21 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
22 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
23}
24
25static void ctrl_mmr_unlock(void)
26{
27 /* Unlock all WKUP_CTRL_MMR0 module registers */
28 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
29 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
30 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
31 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
34
35 /* Unlock all MCU_CTRL_MMR0 module registers */
36 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
37 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
38 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
40
41 /* Unlock all CTRL_MMR0 module registers */
42 mmr_unlock(CTRL_MMR0_BASE, 0);
43 mmr_unlock(CTRL_MMR0_BASE, 1);
44 mmr_unlock(CTRL_MMR0_BASE, 2);
45 mmr_unlock(CTRL_MMR0_BASE, 3);
46 mmr_unlock(CTRL_MMR0_BASE, 6);
47 mmr_unlock(CTRL_MMR0_BASE, 7);
48}
49
Lokesh Vutlae0064602018-08-27 15:57:11 +053050static void store_boot_index_from_rom(void)
51{
52 u32 *boot_index = (u32 *)K3_BOOT_PARAM_TABLE_INDEX_VAL;
53
54 *boot_index = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
55}
56
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053057void board_init_f(ulong dummy)
58{
Lokesh Vutlae0064602018-08-27 15:57:11 +053059 /*
60 * Cannot delay this further as there is a chance that
61 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
62 */
63 store_boot_index_from_rom();
64
Andreas Dannenbergc68721d2018-08-27 15:57:12 +053065 /* Make all control module registers accessible */
66 ctrl_mmr_unlock();
67
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053068 /* Init DM early in-order to invoke system controller */
69 spl_early_init();
70
71 /* Prepare console output */
72 preloader_console_init();
73}
74
Andrew F. Davis81089a52018-10-03 10:03:23 -050075u32 spl_boot_mode(const u32 boot_device)
76{
77#if defined(CONFIG_SUPPORT_EMMC_BOOT)
78 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
79 u32 bootindex = readl(K3_BOOT_PARAM_TABLE_INDEX_VAL);
80
81 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
82 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
83
84 /* eMMC boot0 mode is only supported for primary boot */
85 if (bootindex == K3_PRIMARY_BOOTMODE &&
86 bootmode == BOOT_DEVICE_MMC1)
87 return MMCSD_MODE_EMMCBOOT;
88#endif
89
90 /* Everything else use filesystem if available */
91#if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
92 return MMCSD_MODE_FS;
93#else
94 return MMCSD_MODE_RAW;
95#endif
96}
97
Lokesh Vutlae0064602018-08-27 15:57:11 +053098static u32 __get_backup_bootmedia(u32 devstat)
99{
100 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
101 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
102
103 switch (bkup_boot) {
104 case BACKUP_BOOT_DEVICE_USB:
105 return BOOT_DEVICE_USB;
106 case BACKUP_BOOT_DEVICE_UART:
107 return BOOT_DEVICE_UART;
108 case BACKUP_BOOT_DEVICE_ETHERNET:
109 return BOOT_DEVICE_ETHERNET;
110 case BACKUP_BOOT_DEVICE_MMC2:
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500111 {
112 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
113 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
114 if (port == 0x0)
115 return BOOT_DEVICE_MMC1;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530116 return BOOT_DEVICE_MMC2;
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500117 }
Lokesh Vutlae0064602018-08-27 15:57:11 +0530118 case BACKUP_BOOT_DEVICE_SPI:
119 return BOOT_DEVICE_SPI;
120 case BACKUP_BOOT_DEVICE_HYPERFLASH:
121 return BOOT_DEVICE_HYPERFLASH;
122 case BACKUP_BOOT_DEVICE_I2C:
123 return BOOT_DEVICE_I2C;
124 };
125
126 return BOOT_DEVICE_RAM;
127}
128
129static u32 __get_primary_bootmedia(u32 devstat)
130{
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500131 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
132 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
Lokesh Vutlae0064602018-08-27 15:57:11 +0530133
134 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
135 bootmode = BOOT_DEVICE_SPI;
136
Andrew F. Davisb5700ef2018-10-03 10:03:22 -0500137 if (bootmode == BOOT_DEVICE_MMC2) {
138 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
139 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
140 if (port == 0x0)
141 bootmode = BOOT_DEVICE_MMC1;
142 } else if (bootmode == BOOT_DEVICE_MMC1) {
143 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
144 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
145 if (port == 0x1)
146 bootmode = BOOT_DEVICE_MMC2;
147 }
148
Lokesh Vutlae0064602018-08-27 15:57:11 +0530149 return bootmode;
150}
151
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530152u32 spl_boot_device(void)
153{
Lokesh Vutlae0064602018-08-27 15:57:11 +0530154 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
155 u32 bootindex = readl(K3_BOOT_PARAM_TABLE_INDEX_VAL);
156
157 if (bootindex == K3_PRIMARY_BOOTMODE)
158 return __get_primary_bootmedia(devstat);
159 else
160 return __get_backup_bootmedia(devstat);
Lokesh Vutlaed0e6052018-08-27 15:57:09 +0530161}
162#endif
163
164#ifndef CONFIG_SYSRESET
165void reset_cpu(ulong ignored)
166{
167}
168#endif