blob: 54944af25872e343008bb0d9af64d6750df5f14b [file] [log] [blame]
Dave Gerlach96571ec2021-04-23 11:27:32 -05001// SPDX-License-Identifier: GPL-2.0
2/*
3 * AM642: SoC specific initialization
4 *
5 * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
6 * Keerthy <j-keerthy@ti.com>
7 * Dave Gerlach <d-gerlach@ti.com>
8 */
9
10#include <common.h>
11#include <spl.h>
12#include <asm/io.h>
Keerthy05d670e2021-04-23 11:27:33 -050013#include <asm/arch/hardware.h>
Dave Gerlach96571ec2021-04-23 11:27:32 -050014#include "common.h"
15
16#if defined(CONFIG_SPL_BUILD)
17
18void board_init_f(ulong dummy)
19{
20#if defined(CONFIG_CPU_V7R)
21 setup_k3_mpu_regions();
22#endif
23
24 /* Init DM early */
25 spl_early_init();
26
27 preloader_console_init();
28}
Keerthy05d670e2021-04-23 11:27:33 -050029
30u32 spl_boot_mode(const u32 boot_device)
31{
32 switch (boot_device) {
33 case BOOT_DEVICE_MMC1:
34 return MMCSD_MODE_EMMCBOOT;
35
36 case BOOT_DEVICE_MMC2:
37 return MMCSD_MODE_FS;
38
39 default:
40 return MMCSD_MODE_RAW;
41 }
42}
43
44static u32 __get_backup_bootmedia(u32 main_devstat)
45{
46 u32 bkup_bootmode =
47 (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
48 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
49 u32 bkup_bootmode_cfg =
50 (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
51 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
52
53 switch (bkup_bootmode) {
54 case BACKUP_BOOT_DEVICE_UART:
55 return BOOT_DEVICE_UART;
56
57 case BACKUP_BOOT_DEVICE_USB:
58 return BOOT_DEVICE_USB;
59
60 case BACKUP_BOOT_DEVICE_ETHERNET:
61 return BOOT_DEVICE_ETHERNET;
62
63 case BACKUP_BOOT_DEVICE_MMC:
64 if (bkup_bootmode_cfg)
65 return BOOT_DEVICE_MMC2;
66 return BOOT_DEVICE_MMC1;
67
68 case BACKUP_BOOT_DEVICE_SPI:
69 return BOOT_DEVICE_SPI;
70
71 case BACKUP_BOOT_DEVICE_I2C:
72 return BOOT_DEVICE_I2C;
73 };
74
75 return BOOT_DEVICE_RAM;
76}
77
78static u32 __get_primary_bootmedia(u32 main_devstat)
79{
80 u32 bootmode = (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
81 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
82 u32 bootmode_cfg =
83 (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
84 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
85
86 switch (bootmode) {
87 case BOOT_DEVICE_OSPI:
88 fallthrough;
89 case BOOT_DEVICE_QSPI:
90 fallthrough;
91 case BOOT_DEVICE_XSPI:
92 fallthrough;
93 case BOOT_DEVICE_SPI:
94 return BOOT_DEVICE_SPI;
95
96 case BOOT_DEVICE_ETHERNET_RGMII:
97 fallthrough;
98 case BOOT_DEVICE_ETHERNET_RMII:
99 return BOOT_DEVICE_ETHERNET;
100
101 case BOOT_DEVICE_EMMC:
102 return BOOT_DEVICE_MMC1;
103
104 case BOOT_DEVICE_MMC:
105 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
106 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
107 return BOOT_DEVICE_MMC2;
108 return BOOT_DEVICE_MMC1;
109
110 case BOOT_DEVICE_NOBOOT:
111 return BOOT_DEVICE_RAM;
112 }
113
114 return bootmode;
115}
116
117u32 spl_boot_device(void)
118{
119 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
120
121 if (bootindex == K3_PRIMARY_BOOTMODE)
122 return __get_primary_bootmedia(devstat);
123 else
124 return __get_backup_bootmedia(devstat);
125}
Dave Gerlach96571ec2021-04-23 11:27:32 -0500126#endif