Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 2 | /* |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 3 | * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <debug_uart.h> |
| 9 | #include <fdtdec.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 10 | #include <hang.h> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 11 | #include <spl.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/cpu.h> |
| 14 | #include <asm/arch/soc.h> |
| 15 | |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 16 | static u32 get_boot_device(void) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 17 | { |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 18 | u32 val; |
| 19 | u32 boot_device; |
| 20 | |
Stefan Roese | 04ec0d3 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 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 | |
Chris Packham | 8e93252 | 2018-08-17 20:47:42 +1200 | [diff] [blame] | 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 | |
Stefan Roese | 04ec0d3 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 42 | /* |
| 43 | * Now check the SAR register for the strapped boot-device |
| 44 | */ |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 45 | val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ |
| 46 | boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; |
Stefan Roese | 04ec0d3 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 47 | debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device); |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 48 | switch (boot_device) { |
Sean Nyekjaer | 11d4466 | 2017-11-24 14:01:47 +0100 | [diff] [blame] | 49 | #if defined(CONFIG_ARMADA_38X) |
| 50 | case BOOT_FROM_NAND: |
| 51 | return BOOT_DEVICE_NAND; |
| 52 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 53 | #ifdef CONFIG_SPL_MMC_SUPPORT |
| 54 | case BOOT_FROM_MMC: |
| 55 | case BOOT_FROM_MMC_ALT: |
| 56 | return BOOT_DEVICE_MMC1; |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 57 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 58 | case BOOT_FROM_UART: |
Baruch Siach | e4c0ad6 | 2017-09-24 15:50:17 +0300 | [diff] [blame] | 59 | #ifdef BOOT_FROM_UART_ALT |
| 60 | case BOOT_FROM_UART_ALT: |
| 61 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 62 | return BOOT_DEVICE_UART; |
Baruch Siach | b936a27 | 2019-05-16 13:03:58 +0300 | [diff] [blame] | 63 | #ifdef BOOT_FROM_SATA |
| 64 | case BOOT_FROM_SATA: |
| 65 | case BOOT_FROM_SATA_ALT: |
| 66 | return BOOT_DEVICE_SATA; |
| 67 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 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(); |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 79 | void board_init_f(ulong dummy) |
| 80 | { |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 81 | int ret; |
| 82 | |
Stefan Roese | d7f2c12 | 2015-04-17 18:13:06 +0200 | [diff] [blame] | 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 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 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 | |
Stefan Roese | 85bddff | 2019-04-12 16:42:28 +0200 | [diff] [blame] | 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 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 111 | ret = spl_init(); |
| 112 | if (ret) { |
| 113 | debug("spl_init() failed: %d\n", ret); |
| 114 | hang(); |
| 115 | } |
| 116 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 117 | preloader_console_init(); |
| 118 | |
Stefan Roese | d04fe8b | 2015-07-15 15:36:52 +0200 | [diff] [blame] | 119 | timer_init(); |
| 120 | |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 121 | /* Armada 375 does not support SerDes and DDR3 init yet */ |
| 122 | #if !defined(CONFIG_ARMADA_375) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 123 | /* First init the serdes PHY's */ |
| 124 | serdes_phy_config(); |
| 125 | |
| 126 | /* Setup DDR */ |
| 127 | ddr3_init(); |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 128 | #endif |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 129 | |
Baruch Siach | 056e107 | 2019-07-10 18:23:04 +0300 | [diff] [blame] | 130 | /* Initialize Auto Voltage Scaling */ |
| 131 | mv_avs_init(); |
| 132 | |
Chris Packham | 3667bec | 2020-02-26 19:53:50 +1300 | [diff] [blame] | 133 | /* Update read timing control for PCIe */ |
| 134 | mv_rtc_config(); |
| 135 | |
Stefan Roese | 99b3ea7 | 2015-08-25 13:49:41 +0200 | [diff] [blame] | 136 | /* |
| 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 Nyekjaer | 11d4466 | 2017-11-24 14:01:47 +0100 | [diff] [blame] | 146 | * |
| 147 | * If booting from NAND lets let the BootROM load the |
| 148 | * rest of the bootloader. |
Stefan Roese | 99b3ea7 | 2015-08-25 13:49:41 +0200 | [diff] [blame] | 149 | */ |
Sean Nyekjaer | 11d4466 | 2017-11-24 14:01:47 +0100 | [diff] [blame] | 150 | 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 Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 157 | } |