blob: f645befb2c044c5ace02263d087c3b51166252ea [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>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Stefan Roesee463bf32015-01-19 11:33:42 +010013#include <spl.h>
14#include <asm/io.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/soc.h>
17
Stefan Roese44e7ebd2016-01-07 14:09:09 +010018static u32 get_boot_device(void)
Stefan Roesee463bf32015-01-19 11:33:42 +010019{
Stefan Roese44e7ebd2016-01-07 14:09:09 +010020 u32 val;
21 u32 boot_device;
22
Stefan Roese04ec0d32016-01-07 14:12:04 +010023 /*
24 * First check, if UART boot-mode is active. This can only
25 * be done, via the bootrom error register. Here the
26 * MSB marks if the UART mode is active.
27 */
28 val = readl(CONFIG_BOOTROM_ERR_REG);
29 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
30 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
31 if (boot_device == BOOTROM_ERR_MODE_UART)
32 return BOOT_DEVICE_UART;
33
Chris Packham8e932522018-08-17 20:47:42 +120034#ifdef CONFIG_ARMADA_38X
35 /*
36 * If the bootrom error code contains any other than zeros it's an
37 * error condition and the bootROM has fallen back to UART boot
38 */
39 boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
40 if (boot_device)
41 return BOOT_DEVICE_UART;
42#endif
43
Stefan Roese04ec0d32016-01-07 14:12:04 +010044 /*
45 * Now check the SAR register for the strapped boot-device
46 */
Stefan Roese44e7ebd2016-01-07 14:09:09 +010047 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
48 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
Stefan Roese04ec0d32016-01-07 14:12:04 +010049 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
Stefan Roese44e7ebd2016-01-07 14:09:09 +010050 switch (boot_device) {
Sean Nyekjaer11d44662017-11-24 14:01:47 +010051#if defined(CONFIG_ARMADA_38X)
52 case BOOT_FROM_NAND:
53 return BOOT_DEVICE_NAND;
54#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010055#ifdef CONFIG_SPL_MMC_SUPPORT
56 case BOOT_FROM_MMC:
57 case BOOT_FROM_MMC_ALT:
58 return BOOT_DEVICE_MMC1;
Stefan Roese63962132015-07-20 11:20:36 +020059#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010060 case BOOT_FROM_UART:
Baruch Siache4c0ad62017-09-24 15:50:17 +030061#ifdef BOOT_FROM_UART_ALT
62 case BOOT_FROM_UART_ALT:
63#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010064 return BOOT_DEVICE_UART;
Baruch Siachb936a272019-05-16 13:03:58 +030065#ifdef BOOT_FROM_SATA
66 case BOOT_FROM_SATA:
67 case BOOT_FROM_SATA_ALT:
68 return BOOT_DEVICE_SATA;
69#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010070 case BOOT_FROM_SPI:
71 default:
72 return BOOT_DEVICE_SPI;
73 };
74}
75
76u32 spl_boot_device(void)
77{
78 return get_boot_device();
Stefan Roese63962132015-07-20 11:20:36 +020079}
80
Stefan Roesee463bf32015-01-19 11:33:42 +010081void board_init_f(ulong dummy)
82{
Stefan Roese83097cf2015-11-25 07:37:00 +010083 int ret;
84
Stefan Roesed7f2c122015-04-17 18:13:06 +020085 /*
86 * Pin muxing needs to be done before UART output, since
87 * on A38x the UART pins need some re-muxing for output
88 * to work.
89 */
90 board_early_init_f();
91
Stefan Roese83097cf2015-11-25 07:37:00 +010092 /* Example code showing how to enable the debug UART on MVEBU */
93#ifdef EARLY_UART
94 /*
95 * Debug UART can be used from here if required:
96 *
97 * debug_uart_init();
98 * printch('a');
99 * printhex8(0x1234);
100 * printascii("string");
101 */
102#endif
103
Stefan Roese85bddff2019-04-12 16:42:28 +0200104 /*
105 * Use special translation offset for SPL. This needs to be
106 * configured *before* spl_init() is called as this function
107 * calls dm_init() which calls the bind functions of the
108 * device drivers. Here the base address needs to be configured
109 * (translated) correctly.
110 */
111 gd->translation_offset = 0xd0000000 - 0xf1000000;
112
Stefan Roese83097cf2015-11-25 07:37:00 +0100113 ret = spl_init();
114 if (ret) {
115 debug("spl_init() failed: %d\n", ret);
116 hang();
117 }
118
Stefan Roesee463bf32015-01-19 11:33:42 +0100119 preloader_console_init();
120
Stefan Roesed04fe8b2015-07-15 15:36:52 +0200121 timer_init();
122
Stefan Roese479f9af2016-02-10 07:23:00 +0100123 /* Armada 375 does not support SerDes and DDR3 init yet */
124#if !defined(CONFIG_ARMADA_375)
Stefan Roesee463bf32015-01-19 11:33:42 +0100125 /* First init the serdes PHY's */
126 serdes_phy_config();
127
128 /* Setup DDR */
129 ddr3_init();
Stefan Roese479f9af2016-02-10 07:23:00 +0100130#endif
Stefan Roesee463bf32015-01-19 11:33:42 +0100131
Baruch Siach056e1072019-07-10 18:23:04 +0300132 /* Initialize Auto Voltage Scaling */
133 mv_avs_init();
134
Chris Packham3667bec2020-02-26 19:53:50 +1300135 /* Update read timing control for PCIe */
136 mv_rtc_config();
137
Stefan Roese99b3ea72015-08-25 13:49:41 +0200138 /*
139 * Return to the BootROM to continue the Marvell xmodem
140 * UART boot protocol. As initiated by the kwboot tool.
141 *
142 * This can only be done by the BootROM and not by the
143 * U-Boot SPL infrastructure, since the beginning of the
144 * image is already read and interpreted by the BootROM.
145 * SPL has no chance to receive this information. So we
146 * need to return to the BootROM to enable this xmodem
147 * UART download.
Sean Nyekjaer11d44662017-11-24 14:01:47 +0100148 *
149 * If booting from NAND lets let the BootROM load the
150 * rest of the bootloader.
Stefan Roese99b3ea72015-08-25 13:49:41 +0200151 */
Sean Nyekjaer11d44662017-11-24 14:01:47 +0100152 switch (get_boot_device()) {
153 case BOOT_DEVICE_UART:
154#if defined(CONFIG_ARMADA_38X)
155 case BOOT_DEVICE_NAND:
156#endif
157 return_to_bootrom();
158 }
Stefan Roesee463bf32015-01-19 11:33:42 +0100159}