blob: 671498a99be1b5dd89868797946f9cb0d5d618c7 [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
Lokesh Vutlae0064602018-08-27 15:57:11 +053015static void store_boot_index_from_rom(void)
16{
17 u32 *boot_index = (u32 *)K3_BOOT_PARAM_TABLE_INDEX_VAL;
18
19 *boot_index = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
20}
21
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053022void board_init_f(ulong dummy)
23{
Lokesh Vutlae0064602018-08-27 15:57:11 +053024 /*
25 * Cannot delay this further as there is a chance that
26 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
27 */
28 store_boot_index_from_rom();
29
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053030 /* Init DM early in-order to invoke system controller */
31 spl_early_init();
32
33 /* Prepare console output */
34 preloader_console_init();
35}
36
Lokesh Vutlae0064602018-08-27 15:57:11 +053037static u32 __get_backup_bootmedia(u32 devstat)
38{
39 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
40 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
41
42 switch (bkup_boot) {
43 case BACKUP_BOOT_DEVICE_USB:
44 return BOOT_DEVICE_USB;
45 case BACKUP_BOOT_DEVICE_UART:
46 return BOOT_DEVICE_UART;
47 case BACKUP_BOOT_DEVICE_ETHERNET:
48 return BOOT_DEVICE_ETHERNET;
49 case BACKUP_BOOT_DEVICE_MMC2:
50 return BOOT_DEVICE_MMC2;
51 case BACKUP_BOOT_DEVICE_SPI:
52 return BOOT_DEVICE_SPI;
53 case BACKUP_BOOT_DEVICE_HYPERFLASH:
54 return BOOT_DEVICE_HYPERFLASH;
55 case BACKUP_BOOT_DEVICE_I2C:
56 return BOOT_DEVICE_I2C;
57 };
58
59 return BOOT_DEVICE_RAM;
60}
61
62static u32 __get_primary_bootmedia(u32 devstat)
63{
64 u32 bootmode = devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK;
65
66 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
67 bootmode = BOOT_DEVICE_SPI;
68
69 return bootmode;
70}
71
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053072u32 spl_boot_device(void)
73{
Lokesh Vutlae0064602018-08-27 15:57:11 +053074 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
75 u32 bootindex = readl(K3_BOOT_PARAM_TABLE_INDEX_VAL);
76
77 if (bootindex == K3_PRIMARY_BOOTMODE)
78 return __get_primary_bootmedia(devstat);
79 else
80 return __get_backup_bootmedia(devstat);
Lokesh Vutlaed0e6052018-08-27 15:57:09 +053081}
82#endif
83
84#ifndef CONFIG_SYSRESET
85void reset_cpu(ulong ignored)
86{
87}
88#endif