Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 1 | /* |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame^] | 2 | * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de> |
Stefan Roese | e463bf3 | 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 | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <debug_uart.h> |
| 10 | #include <fdtdec.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 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame^] | 18 | static u32 get_boot_device(void) |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 19 | { |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame^] | 20 | u32 val; |
| 21 | u32 boot_device; |
| 22 | |
| 23 | val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */ |
| 24 | boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS; |
| 25 | switch (boot_device) { |
| 26 | #ifdef CONFIG_SPL_MMC_SUPPORT |
| 27 | case BOOT_FROM_MMC: |
| 28 | case BOOT_FROM_MMC_ALT: |
| 29 | return BOOT_DEVICE_MMC1; |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 30 | #endif |
Stefan Roese | 44e7ebd | 2016-01-07 14:09:09 +0100 | [diff] [blame^] | 31 | case BOOT_FROM_UART: |
| 32 | return BOOT_DEVICE_UART; |
| 33 | case BOOT_FROM_SPI: |
| 34 | default: |
| 35 | return BOOT_DEVICE_SPI; |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | u32 spl_boot_device(void) |
| 40 | { |
| 41 | return get_boot_device(); |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | #ifdef CONFIG_SPL_MMC_SUPPORT |
| 45 | u32 spl_boot_mode(void) |
| 46 | { |
| 47 | return MMCSD_MODE_RAW; |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 48 | } |
Stefan Roese | 6396213 | 2015-07-20 11:20:36 +0200 | [diff] [blame] | 49 | #endif |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 50 | |
| 51 | void board_init_f(ulong dummy) |
| 52 | { |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 53 | int ret; |
| 54 | |
Stefan Roese | d7f2c12 | 2015-04-17 18:13:06 +0200 | [diff] [blame] | 55 | /* |
| 56 | * Pin muxing needs to be done before UART output, since |
| 57 | * on A38x the UART pins need some re-muxing for output |
| 58 | * to work. |
| 59 | */ |
| 60 | board_early_init_f(); |
| 61 | |
Stefan Roese | 83097cf | 2015-11-25 07:37:00 +0100 | [diff] [blame] | 62 | /* Example code showing how to enable the debug UART on MVEBU */ |
| 63 | #ifdef EARLY_UART |
| 64 | /* |
| 65 | * Debug UART can be used from here if required: |
| 66 | * |
| 67 | * debug_uart_init(); |
| 68 | * printch('a'); |
| 69 | * printhex8(0x1234); |
| 70 | * printascii("string"); |
| 71 | */ |
| 72 | #endif |
| 73 | |
| 74 | ret = spl_init(); |
| 75 | if (ret) { |
| 76 | debug("spl_init() failed: %d\n", ret); |
| 77 | hang(); |
| 78 | } |
| 79 | |
| 80 | /* Use special translation offset for SPL */ |
| 81 | dm_set_translation_offset(0xd0000000 - 0xf1000000); |
| 82 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 83 | preloader_console_init(); |
| 84 | |
Stefan Roese | d04fe8b | 2015-07-15 15:36:52 +0200 | [diff] [blame] | 85 | timer_init(); |
| 86 | |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 87 | /* First init the serdes PHY's */ |
| 88 | serdes_phy_config(); |
| 89 | |
| 90 | /* Setup DDR */ |
| 91 | ddr3_init(); |
| 92 | |
Stefan Roese | 99b3ea7 | 2015-08-25 13:49:41 +0200 | [diff] [blame] | 93 | #ifdef CONFIG_MVEBU_BOOTROM_UARTBOOT |
| 94 | /* |
| 95 | * Return to the BootROM to continue the Marvell xmodem |
| 96 | * UART boot protocol. As initiated by the kwboot tool. |
| 97 | * |
| 98 | * This can only be done by the BootROM and not by the |
| 99 | * U-Boot SPL infrastructure, since the beginning of the |
| 100 | * image is already read and interpreted by the BootROM. |
| 101 | * SPL has no chance to receive this information. So we |
| 102 | * need to return to the BootROM to enable this xmodem |
| 103 | * UART download. |
| 104 | */ |
| 105 | return_to_bootrom(); |
| 106 | #endif |
Stefan Roese | e463bf3 | 2015-01-19 11:33:42 +0100 | [diff] [blame] | 107 | } |