blob: 50b24f5760b71bbea7ce76d43fed17568a2574ae [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>
Stefan Roesee463bf32015-01-19 11:33:42 +010010#include <spl.h>
11#include <asm/io.h>
12#include <asm/arch/cpu.h>
13#include <asm/arch/soc.h>
14
Stefan Roese44e7ebd2016-01-07 14:09:09 +010015static u32 get_boot_device(void)
Stefan Roesee463bf32015-01-19 11:33:42 +010016{
Stefan Roese44e7ebd2016-01-07 14:09:09 +010017 u32 val;
18 u32 boot_device;
19
Stefan Roese04ec0d32016-01-07 14:12:04 +010020 /*
21 * First check, if UART boot-mode is active. This can only
22 * be done, via the bootrom error register. Here the
23 * MSB marks if the UART mode is active.
24 */
25 val = readl(CONFIG_BOOTROM_ERR_REG);
26 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
27 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
Sean Nyekjaer8e72a4f2017-11-24 14:01:28 +010028#if defined(CONFIG_ARMADA_38X)
29 /*
30 * If the bootrom error register contains any else than zeros
31 * in the first 8 bits it's an error condition. And in that case
32 * try to boot from UART.
33 */
34 if (boot_device)
35#else
Stefan Roese04ec0d32016-01-07 14:12:04 +010036 if (boot_device == BOOTROM_ERR_MODE_UART)
Sean Nyekjaer8e72a4f2017-11-24 14:01:28 +010037#endif
Stefan Roese04ec0d32016-01-07 14:12:04 +010038 return BOOT_DEVICE_UART;
39
40 /*
41 * Now check the SAR register for the strapped boot-device
42 */
Stefan Roese44e7ebd2016-01-07 14:09:09 +010043 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
44 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
Stefan Roese04ec0d32016-01-07 14:12:04 +010045 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
Stefan Roese44e7ebd2016-01-07 14:09:09 +010046 switch (boot_device) {
Sean Nyekjaer11d44662017-11-24 14:01:47 +010047#if defined(CONFIG_ARMADA_38X)
48 case BOOT_FROM_NAND:
49 return BOOT_DEVICE_NAND;
50#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010051#ifdef CONFIG_SPL_MMC_SUPPORT
52 case BOOT_FROM_MMC:
53 case BOOT_FROM_MMC_ALT:
54 return BOOT_DEVICE_MMC1;
Stefan Roese63962132015-07-20 11:20:36 +020055#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010056 case BOOT_FROM_UART:
Baruch Siache4c0ad62017-09-24 15:50:17 +030057#ifdef BOOT_FROM_UART_ALT
58 case BOOT_FROM_UART_ALT:
59#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010060 return BOOT_DEVICE_UART;
61 case BOOT_FROM_SPI:
62 default:
63 return BOOT_DEVICE_SPI;
64 };
65}
66
67u32 spl_boot_device(void)
68{
69 return get_boot_device();
Stefan Roese63962132015-07-20 11:20:36 +020070}
71
Stefan Roesee463bf32015-01-19 11:33:42 +010072void board_init_f(ulong dummy)
73{
Stefan Roese83097cf2015-11-25 07:37:00 +010074 int ret;
75
Stefan Roesed7f2c122015-04-17 18:13:06 +020076 /*
77 * Pin muxing needs to be done before UART output, since
78 * on A38x the UART pins need some re-muxing for output
79 * to work.
80 */
81 board_early_init_f();
82
Stefan Roese83097cf2015-11-25 07:37:00 +010083 /* Example code showing how to enable the debug UART on MVEBU */
84#ifdef EARLY_UART
85 /*
86 * Debug UART can be used from here if required:
87 *
88 * debug_uart_init();
89 * printch('a');
90 * printhex8(0x1234);
91 * printascii("string");
92 */
93#endif
94
95 ret = spl_init();
96 if (ret) {
97 debug("spl_init() failed: %d\n", ret);
98 hang();
99 }
100
101 /* Use special translation offset for SPL */
102 dm_set_translation_offset(0xd0000000 - 0xf1000000);
103
Stefan Roesee463bf32015-01-19 11:33:42 +0100104 preloader_console_init();
105
Stefan Roesed04fe8b2015-07-15 15:36:52 +0200106 timer_init();
107
Stefan Roese479f9af2016-02-10 07:23:00 +0100108 /* Armada 375 does not support SerDes and DDR3 init yet */
109#if !defined(CONFIG_ARMADA_375)
Stefan Roesee463bf32015-01-19 11:33:42 +0100110 /* First init the serdes PHY's */
111 serdes_phy_config();
112
113 /* Setup DDR */
114 ddr3_init();
Stefan Roese479f9af2016-02-10 07:23:00 +0100115#endif
Stefan Roesee463bf32015-01-19 11:33:42 +0100116
Stefan Roese99b3ea72015-08-25 13:49:41 +0200117 /*
118 * Return to the BootROM to continue the Marvell xmodem
119 * UART boot protocol. As initiated by the kwboot tool.
120 *
121 * This can only be done by the BootROM and not by the
122 * U-Boot SPL infrastructure, since the beginning of the
123 * image is already read and interpreted by the BootROM.
124 * SPL has no chance to receive this information. So we
125 * need to return to the BootROM to enable this xmodem
126 * UART download.
Sean Nyekjaer11d44662017-11-24 14:01:47 +0100127 *
128 * If booting from NAND lets let the BootROM load the
129 * rest of the bootloader.
Stefan Roese99b3ea72015-08-25 13:49:41 +0200130 */
Sean Nyekjaer11d44662017-11-24 14:01:47 +0100131 switch (get_boot_device()) {
132 case BOOT_DEVICE_UART:
133#if defined(CONFIG_ARMADA_38X)
134 case BOOT_DEVICE_NAND:
135#endif
136 return_to_bootrom();
137 }
Stefan Roesee463bf32015-01-19 11:33:42 +0100138}