blob: 70fef3b573d9e46c4027bbacccf587d6a71c8071 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roesee463bf32015-01-19 11:33:42 +01002/*
Stefan Roese44e7ebd2016-01-07 14:09:09 +01003 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
Stefan Roesee463bf32015-01-19 11:33:42 +01004 */
5
6#include <common.h>
Stefan Roese83097cf2015-11-25 07:37:00 +01007#include <dm.h>
8#include <debug_uart.h>
9#include <fdtdec.h>
Simon Glassf11478f2019-12-28 10:45:07 -070010#include <hang.h>
Stefan Roesee463bf32015-01-19 11:33:42 +010011#include <spl.h>
12#include <asm/io.h>
13#include <asm/arch/cpu.h>
14#include <asm/arch/soc.h>
15
Stefan Roese44e7ebd2016-01-07 14:09:09 +010016static u32 get_boot_device(void)
Stefan Roesee463bf32015-01-19 11:33:42 +010017{
Stefan Roese44e7ebd2016-01-07 14:09:09 +010018 u32 val;
19 u32 boot_device;
20
Stefan Roese04ec0d32016-01-07 14:12:04 +010021 /*
22 * First check, if UART boot-mode is active. This can only
23 * be done, via the bootrom error register. Here the
24 * MSB marks if the UART mode is active.
25 */
26 val = readl(CONFIG_BOOTROM_ERR_REG);
27 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
28 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
29 if (boot_device == BOOTROM_ERR_MODE_UART)
30 return BOOT_DEVICE_UART;
31
Chris Packham8e932522018-08-17 20:47:42 +120032#ifdef CONFIG_ARMADA_38X
33 /*
34 * If the bootrom error code contains any other than zeros it's an
35 * error condition and the bootROM has fallen back to UART boot
36 */
37 boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
38 if (boot_device)
39 return BOOT_DEVICE_UART;
40#endif
41
Stefan Roese04ec0d32016-01-07 14:12:04 +010042 /*
43 * Now check the SAR register for the strapped boot-device
44 */
Stefan Roese44e7ebd2016-01-07 14:09:09 +010045 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
46 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
Stefan Roese04ec0d32016-01-07 14:12:04 +010047 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
Stefan Roese44e7ebd2016-01-07 14:09:09 +010048 switch (boot_device) {
Sean Nyekjaer11d44662017-11-24 14:01:47 +010049#if defined(CONFIG_ARMADA_38X)
50 case BOOT_FROM_NAND:
51 return BOOT_DEVICE_NAND;
52#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010053#ifdef CONFIG_SPL_MMC_SUPPORT
54 case BOOT_FROM_MMC:
55 case BOOT_FROM_MMC_ALT:
56 return BOOT_DEVICE_MMC1;
Stefan Roese63962132015-07-20 11:20:36 +020057#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010058 case BOOT_FROM_UART:
Baruch Siache4c0ad62017-09-24 15:50:17 +030059#ifdef BOOT_FROM_UART_ALT
60 case BOOT_FROM_UART_ALT:
61#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010062 return BOOT_DEVICE_UART;
Baruch Siachb936a272019-05-16 13:03:58 +030063#ifdef BOOT_FROM_SATA
64 case BOOT_FROM_SATA:
65 case BOOT_FROM_SATA_ALT:
66 return BOOT_DEVICE_SATA;
67#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010068 case BOOT_FROM_SPI:
69 default:
70 return BOOT_DEVICE_SPI;
71 };
72}
73
74u32 spl_boot_device(void)
75{
76 return get_boot_device();
Stefan Roese63962132015-07-20 11:20:36 +020077}
78
Stefan Roesee463bf32015-01-19 11:33:42 +010079void board_init_f(ulong dummy)
80{
Stefan Roese83097cf2015-11-25 07:37:00 +010081 int ret;
82
Stefan Roesed7f2c122015-04-17 18:13:06 +020083 /*
84 * Pin muxing needs to be done before UART output, since
85 * on A38x the UART pins need some re-muxing for output
86 * to work.
87 */
88 board_early_init_f();
89
Stefan Roese83097cf2015-11-25 07:37:00 +010090 /* Example code showing how to enable the debug UART on MVEBU */
91#ifdef EARLY_UART
92 /*
93 * Debug UART can be used from here if required:
94 *
95 * debug_uart_init();
96 * printch('a');
97 * printhex8(0x1234);
98 * printascii("string");
99 */
100#endif
101
Stefan Roese85bddff2019-04-12 16:42:28 +0200102 /*
103 * Use special translation offset for SPL. This needs to be
104 * configured *before* spl_init() is called as this function
105 * calls dm_init() which calls the bind functions of the
106 * device drivers. Here the base address needs to be configured
107 * (translated) correctly.
108 */
109 gd->translation_offset = 0xd0000000 - 0xf1000000;
110
Stefan Roese83097cf2015-11-25 07:37:00 +0100111 ret = spl_init();
112 if (ret) {
113 debug("spl_init() failed: %d\n", ret);
114 hang();
115 }
116
Stefan Roesee463bf32015-01-19 11:33:42 +0100117 preloader_console_init();
118
Stefan Roesed04fe8b2015-07-15 15:36:52 +0200119 timer_init();
120
Stefan Roese479f9af2016-02-10 07:23:00 +0100121 /* Armada 375 does not support SerDes and DDR3 init yet */
122#if !defined(CONFIG_ARMADA_375)
Stefan Roesee463bf32015-01-19 11:33:42 +0100123 /* First init the serdes PHY's */
124 serdes_phy_config();
125
126 /* Setup DDR */
127 ddr3_init();
Stefan Roese479f9af2016-02-10 07:23:00 +0100128#endif
Stefan Roesee463bf32015-01-19 11:33:42 +0100129
Baruch Siach056e1072019-07-10 18:23:04 +0300130 /* Initialize Auto Voltage Scaling */
131 mv_avs_init();
132
Chris Packham3667bec2020-02-26 19:53:50 +1300133 /* Update read timing control for PCIe */
134 mv_rtc_config();
135
Stefan Roese99b3ea72015-08-25 13:49:41 +0200136 /*
137 * Return to the BootROM to continue the Marvell xmodem
138 * UART boot protocol. As initiated by the kwboot tool.
139 *
140 * This can only be done by the BootROM and not by the
141 * U-Boot SPL infrastructure, since the beginning of the
142 * image is already read and interpreted by the BootROM.
143 * SPL has no chance to receive this information. So we
144 * need to return to the BootROM to enable this xmodem
145 * UART download.
Sean Nyekjaer11d44662017-11-24 14:01:47 +0100146 *
147 * If booting from NAND lets let the BootROM load the
148 * rest of the bootloader.
Stefan Roese99b3ea72015-08-25 13:49:41 +0200149 */
Sean Nyekjaer11d44662017-11-24 14:01:47 +0100150 switch (get_boot_device()) {
151 case BOOT_DEVICE_UART:
152#if defined(CONFIG_ARMADA_38X)
153 case BOOT_DEVICE_NAND:
154#endif
155 return_to_bootrom();
156 }
Stefan Roesee463bf32015-01-19 11:33:42 +0100157}