Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 1 | /* |
Stefan Roese | a5f8887 | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 2 | * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de> |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Stefan Roese | 6451223 | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <debug_uart.h> |
| 10 | #include <fdtdec.h> |
Stefan Roese | b0f80b9 | 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 | a5f8887 | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 16 | static u32 get_boot_device(void) |
| 17 | { |
| 18 | u32 val; |
| 19 | u32 boot_device; |
| 20 | |
Stefan Roese | f4db6c9 | 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 | |
| 32 | /* |
| 33 | * Now check the SAR register for the strapped boot-device |
| 34 | */ |
Stefan Roese | a5f8887 | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 35 | val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ |
| 36 | boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; |
Stefan Roese | f4db6c9 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 37 | debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device); |
Stefan Roese | a5f8887 | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 38 | 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; |
| 43 | #endif |
| 44 | case BOOT_FROM_UART: |
| 45 | return BOOT_DEVICE_UART; |
| 46 | case BOOT_FROM_SPI: |
| 47 | default: |
| 48 | return BOOT_DEVICE_SPI; |
| 49 | }; |
| 50 | } |
| 51 | |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 52 | u32 spl_boot_device(void) |
| 53 | { |
Stefan Roese | a5f8887 | 2016-01-07 14:09:09 +0100 | [diff] [blame] | 54 | return get_boot_device(); |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Stefan Roese | 8ed43b9 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 57 | #ifdef CONFIG_SPL_MMC_SUPPORT |
Marek Vasut | 2b1cdaf | 2016-05-14 23:42:07 +0200 | [diff] [blame] | 58 | u32 spl_boot_mode(const u32 boot_device) |
Stefan Roese | 8ed43b9 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 59 | { |
| 60 | return MMCSD_MODE_RAW; |
| 61 | } |
| 62 | #endif |
| 63 | |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 64 | void board_init_f(ulong dummy) |
| 65 | { |
Stefan Roese | 6451223 | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 66 | int ret; |
| 67 | |
Stefan Roese | e3cccf9 | 2015-04-17 18:13:06 +0200 | [diff] [blame] | 68 | /* |
| 69 | * Pin muxing needs to be done before UART output, since |
| 70 | * on A38x the UART pins need some re-muxing for output |
| 71 | * to work. |
| 72 | */ |
| 73 | board_early_init_f(); |
| 74 | |
Stefan Roese | 6451223 | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 75 | /* Example code showing how to enable the debug UART on MVEBU */ |
| 76 | #ifdef EARLY_UART |
| 77 | /* |
| 78 | * Debug UART can be used from here if required: |
| 79 | * |
| 80 | * debug_uart_init(); |
| 81 | * printch('a'); |
| 82 | * printhex8(0x1234); |
| 83 | * printascii("string"); |
| 84 | */ |
| 85 | #endif |
| 86 | |
| 87 | ret = spl_init(); |
| 88 | if (ret) { |
| 89 | debug("spl_init() failed: %d\n", ret); |
| 90 | hang(); |
| 91 | } |
| 92 | |
| 93 | /* Use special translation offset for SPL */ |
| 94 | dm_set_translation_offset(0xd0000000 - 0xf1000000); |
| 95 | |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 96 | preloader_console_init(); |
| 97 | |
Stefan Roese | ade741b | 2015-07-15 15:36:52 +0200 | [diff] [blame] | 98 | timer_init(); |
| 99 | |
Stefan Roese | 09e89ab | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 100 | /* Armada 375 does not support SerDes and DDR3 init yet */ |
| 101 | #if !defined(CONFIG_ARMADA_375) |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 102 | /* First init the serdes PHY's */ |
| 103 | serdes_phy_config(); |
| 104 | |
| 105 | /* Setup DDR */ |
| 106 | ddr3_init(); |
Stefan Roese | 09e89ab | 2016-02-10 07:23:00 +0100 | [diff] [blame] | 107 | #endif |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 108 | |
Stefan Roese | 944c7a3 | 2015-08-25 13:49:41 +0200 | [diff] [blame] | 109 | /* |
| 110 | * Return to the BootROM to continue the Marvell xmodem |
| 111 | * UART boot protocol. As initiated by the kwboot tool. |
| 112 | * |
| 113 | * This can only be done by the BootROM and not by the |
| 114 | * U-Boot SPL infrastructure, since the beginning of the |
| 115 | * image is already read and interpreted by the BootROM. |
| 116 | * SPL has no chance to receive this information. So we |
| 117 | * need to return to the BootROM to enable this xmodem |
| 118 | * UART download. |
| 119 | */ |
Stefan Roese | f4db6c9 | 2016-01-07 14:12:04 +0100 | [diff] [blame] | 120 | if (get_boot_device() == BOOT_DEVICE_UART) |
| 121 | return_to_bootrom(); |
Stefan Roese | b0f80b9 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 122 | } |