common: Move hang() to the same header as panic()
[oweals/u-boot.git] / arch / arm / mach-mvebu / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <debug_uart.h>
9 #include <fdtdec.h>
10 #include <hang.h>
11 #include <spl.h>
12 #include <asm/io.h>
13 #include <asm/arch/cpu.h>
14 #include <asm/arch/soc.h>
15
16 static u32 get_boot_device(void)
17 {
18         u32 val;
19         u32 boot_device;
20
21         /*
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 #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
42         /*
43          * Now check the SAR register for the strapped boot-device
44          */
45         val = readl(CONFIG_SAR_REG);    /* SAR - Sample At Reset */
46         boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
47         debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
48         switch (boot_device) {
49 #if defined(CONFIG_ARMADA_38X)
50         case BOOT_FROM_NAND:
51                 return BOOT_DEVICE_NAND;
52 #endif
53 #ifdef CONFIG_SPL_MMC_SUPPORT
54         case BOOT_FROM_MMC:
55         case BOOT_FROM_MMC_ALT:
56                 return BOOT_DEVICE_MMC1;
57 #endif
58         case BOOT_FROM_UART:
59 #ifdef BOOT_FROM_UART_ALT
60         case BOOT_FROM_UART_ALT:
61 #endif
62                 return BOOT_DEVICE_UART;
63 #ifdef BOOT_FROM_SATA
64         case BOOT_FROM_SATA:
65         case BOOT_FROM_SATA_ALT:
66                 return BOOT_DEVICE_SATA;
67 #endif
68         case BOOT_FROM_SPI:
69         default:
70                 return BOOT_DEVICE_SPI;
71         };
72 }
73
74 u32 spl_boot_device(void)
75 {
76         return get_boot_device();
77 }
78
79 void board_init_f(ulong dummy)
80 {
81         int ret;
82
83         /*
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
90         /* 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
102         /*
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
111         ret = spl_init();
112         if (ret) {
113                 debug("spl_init() failed: %d\n", ret);
114                 hang();
115         }
116
117         preloader_console_init();
118
119         timer_init();
120
121         /* Armada 375 does not support SerDes and DDR3 init yet */
122 #if !defined(CONFIG_ARMADA_375)
123         /* First init the serdes PHY's */
124         serdes_phy_config();
125
126         /* Setup DDR */
127         ddr3_init();
128 #endif
129
130         /* Initialize Auto Voltage Scaling */
131         mv_avs_init();
132
133         /*
134          * Return to the BootROM to continue the Marvell xmodem
135          * UART boot protocol. As initiated by the kwboot tool.
136          *
137          * This can only be done by the BootROM and not by the
138          * U-Boot SPL infrastructure, since the beginning of the
139          * image is already read and interpreted by the BootROM.
140          * SPL has no chance to receive this information. So we
141          * need to return to the BootROM to enable this xmodem
142          * UART download.
143          *
144          * If booting from NAND lets let the BootROM load the
145          * rest of the bootloader.
146          */
147         switch (get_boot_device()) {
148                 case BOOT_DEVICE_UART:
149 #if defined(CONFIG_ARMADA_38X)
150                 case BOOT_DEVICE_NAND:
151 #endif
152                         return_to_bootrom();
153         }
154 }