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