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> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/soc.h> |
| 18 | |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 19 | static u32 get_boot_device(void) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 20 | { |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 21 | u32 val; |
| 22 | u32 boot_device; |
| 23 | |
Stefan Roese | 04ec0d3 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 24 | /* |
| 25 | * First check, if UART boot-mode is active. This can only |
| 26 | * be done, via the bootrom error register. Here the |
| 27 | * MSB marks if the UART mode is active. |
| 28 | */ |
| 29 | val = readl(CONFIG_BOOTROM_ERR_REG); |
| 30 | boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS; |
| 31 | debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device); |
| 32 | if (boot_device == BOOTROM_ERR_MODE_UART) |
| 33 | return BOOT_DEVICE_UART; |
| 34 | |
Chris Packham | 8e93252 | 2018-08-17 20:47:42 +1200 | [diff] [blame] | 35 | #ifdef CONFIG_ARMADA_38X |
| 36 | /* |
| 37 | * If the bootrom error code contains any other than zeros it's an |
| 38 | * error condition and the bootROM has fallen back to UART boot |
| 39 | */ |
| 40 | boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS; |
| 41 | if (boot_device) |
| 42 | return BOOT_DEVICE_UART; |
| 43 | #endif |
| 44 | |
Stefan Roese | 04ec0d3 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 45 | /* |
| 46 | * Now check the SAR register for the strapped boot-device |
| 47 | */ |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 48 | val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ |
| 49 | boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; |
Stefan Roese | 04ec0d3 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 50 | 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] | 51 | switch (boot_device) { |
Sean Nyekjaer | 11d4466 | 2017-11-24 14:01:47 +0100 | [diff] [blame] | 52 | #if defined(CONFIG_ARMADA_38X) |
| 53 | case BOOT_FROM_NAND: |
| 54 | return BOOT_DEVICE_NAND; |
| 55 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_MMC_SUPPORT |
| 57 | case BOOT_FROM_MMC: |
| 58 | case BOOT_FROM_MMC_ALT: |
| 59 | return BOOT_DEVICE_MMC1; |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 60 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 61 | case BOOT_FROM_UART: |
Baruch Siach | e4c0ad6 | 2017-09-24 15:50:17 +0300 | [diff] [blame] | 62 | #ifdef BOOT_FROM_UART_ALT |
| 63 | case BOOT_FROM_UART_ALT: |
| 64 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 65 | return BOOT_DEVICE_UART; |
Baruch Siach | b936a27 | 2019-05-16 13:03:58 +0300 | [diff] [blame] | 66 | #ifdef BOOT_FROM_SATA |
| 67 | case BOOT_FROM_SATA: |
| 68 | case BOOT_FROM_SATA_ALT: |
| 69 | return BOOT_DEVICE_SATA; |
| 70 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 71 | case BOOT_FROM_SPI: |
| 72 | default: |
| 73 | return BOOT_DEVICE_SPI; |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | u32 spl_boot_device(void) |
| 78 | { |
| 79 | return get_boot_device(); |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 80 | } |
| 81 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 82 | void board_init_f(ulong dummy) |
| 83 | { |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 84 | int ret; |
| 85 | |
Stefan Roese | d7f2c12 | 2015-04-17 18:13:06 +0200 | [diff] [blame] | 86 | /* |
| 87 | * Pin muxing needs to be done before UART output, since |
| 88 | * on A38x the UART pins need some re-muxing for output |
| 89 | * to work. |
| 90 | */ |
| 91 | board_early_init_f(); |
| 92 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 93 | /* Example code showing how to enable the debug UART on MVEBU */ |
| 94 | #ifdef EARLY_UART |
| 95 | /* |
| 96 | * Debug UART can be used from here if required: |
| 97 | * |
| 98 | * debug_uart_init(); |
| 99 | * printch('a'); |
| 100 | * printhex8(0x1234); |
| 101 | * printascii("string"); |
| 102 | */ |
| 103 | #endif |
| 104 | |
Stefan Roese | 85bddff | 2019-04-12 16:42:28 +0200 | [diff] [blame] | 105 | /* |
| 106 | * Use special translation offset for SPL. This needs to be |
| 107 | * configured *before* spl_init() is called as this function |
| 108 | * calls dm_init() which calls the bind functions of the |
| 109 | * device drivers. Here the base address needs to be configured |
| 110 | * (translated) correctly. |
| 111 | */ |
| 112 | gd->translation_offset = 0xd0000000 - 0xf1000000; |
| 113 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 114 | ret = spl_init(); |
| 115 | if (ret) { |
| 116 | debug("spl_init() failed: %d\n", ret); |
| 117 | hang(); |
| 118 | } |
| 119 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 120 | preloader_console_init(); |
| 121 | |
Stefan Roese | d04fe8b | 2015-07-15 15:36:52 +0200 | [diff] [blame] | 122 | timer_init(); |
| 123 | |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 124 | /* Armada 375 does not support SerDes and DDR3 init yet */ |
| 125 | #if !defined(CONFIG_ARMADA_375) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 126 | /* First init the serdes PHY's */ |
| 127 | serdes_phy_config(); |
| 128 | |
| 129 | /* Setup DDR */ |
| 130 | ddr3_init(); |
Stefan Roese | 479f9af | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 131 | #endif |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 132 | |
Baruch Siach | 056e107 | 2019-07-10 18:23:04 +0300 | [diff] [blame] | 133 | /* Initialize Auto Voltage Scaling */ |
| 134 | mv_avs_init(); |
| 135 | |
Chris Packham | 3667bec | 2020-02-26 19:53:50 +1300 | [diff] [blame] | 136 | /* Update read timing control for PCIe */ |
| 137 | mv_rtc_config(); |
| 138 | |
Stefan Roese | 99b3ea7 | 2015-08-25 13:49:41 +0200 | [diff] [blame] | 139 | /* |
| 140 | * Return to the BootROM to continue the Marvell xmodem |
| 141 | * UART boot protocol. As initiated by the kwboot tool. |
| 142 | * |
| 143 | * This can only be done by the BootROM and not by the |
| 144 | * U-Boot SPL infrastructure, since the beginning of the |
| 145 | * image is already read and interpreted by the BootROM. |
| 146 | * SPL has no chance to receive this information. So we |
| 147 | * need to return to the BootROM to enable this xmodem |
| 148 | * UART download. |
Sean Nyekjaer | 11d4466 | 2017-11-24 14:01:47 +0100 | [diff] [blame] | 149 | * |
| 150 | * If booting from NAND lets let the BootROM load the |
| 151 | * rest of the bootloader. |
Stefan Roese | 99b3ea7 | 2015-08-25 13:49:41 +0200 | [diff] [blame] | 152 | */ |
Sean Nyekjaer | 11d4466 | 2017-11-24 14:01:47 +0100 | [diff] [blame] | 153 | switch (get_boot_device()) { |
| 154 | case BOOT_DEVICE_UART: |
| 155 | #if defined(CONFIG_ARMADA_38X) |
| 156 | case BOOT_DEVICE_NAND: |
| 157 | #endif |
| 158 | return_to_bootrom(); |
| 159 | } |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 160 | } |