blob: a72a769f7c740eeb8c4fabf46964c0ba913f2e3d [file] [log] [blame]
Stefan Roesee463bf32015-01-19 11:33:42 +01001/*
Stefan Roese44e7ebd2016-01-07 14:09:09 +01002 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
Stefan Roesee463bf32015-01-19 11:33:42 +01003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Stefan Roese83097cf2015-11-25 07:37:00 +01008#include <dm.h>
9#include <debug_uart.h>
10#include <fdtdec.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
32 /*
33 * Now check the SAR register for the strapped boot-device
34 */
Stefan Roese44e7ebd2016-01-07 14:09:09 +010035 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
36 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
Stefan Roese04ec0d32016-01-07 14:12:04 +010037 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
Stefan Roese44e7ebd2016-01-07 14:09:09 +010038 switch (boot_device) {
39#ifdef CONFIG_SPL_MMC_SUPPORT
40 case BOOT_FROM_MMC:
41 case BOOT_FROM_MMC_ALT:
42 return BOOT_DEVICE_MMC1;
Stefan Roese63962132015-07-20 11:20:36 +020043#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010044 case BOOT_FROM_UART:
Baruch Siache4c0ad62017-09-24 15:50:17 +030045#ifdef BOOT_FROM_UART_ALT
46 case BOOT_FROM_UART_ALT:
47#endif
Stefan Roese44e7ebd2016-01-07 14:09:09 +010048 return BOOT_DEVICE_UART;
49 case BOOT_FROM_SPI:
50 default:
51 return BOOT_DEVICE_SPI;
52 };
53}
54
55u32 spl_boot_device(void)
56{
57 return get_boot_device();
Stefan Roese63962132015-07-20 11:20:36 +020058}
59
60#ifdef CONFIG_SPL_MMC_SUPPORT
Marek Vasut64d64bb2016-05-14 23:42:07 +020061u32 spl_boot_mode(const u32 boot_device)
Stefan Roese63962132015-07-20 11:20:36 +020062{
63 return MMCSD_MODE_RAW;
Stefan Roesee463bf32015-01-19 11:33:42 +010064}
Stefan Roese63962132015-07-20 11:20:36 +020065#endif
Stefan Roesee463bf32015-01-19 11:33:42 +010066
67void board_init_f(ulong dummy)
68{
Stefan Roese83097cf2015-11-25 07:37:00 +010069 int ret;
70
Stefan Roesed7f2c122015-04-17 18:13:06 +020071 /*
72 * Pin muxing needs to be done before UART output, since
73 * on A38x the UART pins need some re-muxing for output
74 * to work.
75 */
76 board_early_init_f();
77
Stefan Roese83097cf2015-11-25 07:37:00 +010078 /* Example code showing how to enable the debug UART on MVEBU */
79#ifdef EARLY_UART
80 /*
81 * Debug UART can be used from here if required:
82 *
83 * debug_uart_init();
84 * printch('a');
85 * printhex8(0x1234);
86 * printascii("string");
87 */
88#endif
89
90 ret = spl_init();
91 if (ret) {
92 debug("spl_init() failed: %d\n", ret);
93 hang();
94 }
95
96 /* Use special translation offset for SPL */
97 dm_set_translation_offset(0xd0000000 - 0xf1000000);
98
Stefan Roesee463bf32015-01-19 11:33:42 +010099 preloader_console_init();
100
Stefan Roesed04fe8b2015-07-15 15:36:52 +0200101 timer_init();
102
Stefan Roese479f9af2016-02-10 07:23:00 +0100103 /* Armada 375 does not support SerDes and DDR3 init yet */
104#if !defined(CONFIG_ARMADA_375)
Stefan Roesee463bf32015-01-19 11:33:42 +0100105 /* First init the serdes PHY's */
106 serdes_phy_config();
107
108 /* Setup DDR */
109 ddr3_init();
Stefan Roese479f9af2016-02-10 07:23:00 +0100110#endif
Stefan Roesee463bf32015-01-19 11:33:42 +0100111
Stefan Roese99b3ea72015-08-25 13:49:41 +0200112 /*
113 * Return to the BootROM to continue the Marvell xmodem
114 * UART boot protocol. As initiated by the kwboot tool.
115 *
116 * This can only be done by the BootROM and not by the
117 * U-Boot SPL infrastructure, since the beginning of the
118 * image is already read and interpreted by the BootROM.
119 * SPL has no chance to receive this information. So we
120 * need to return to the BootROM to enable this xmodem
121 * UART download.
122 */
Stefan Roese04ec0d32016-01-07 14:12:04 +0100123 if (get_boot_device() == BOOT_DEVICE_UART)
124 return_to_bootrom();
Stefan Roesee463bf32015-01-19 11:33:42 +0100125}