Tom Rini | 4549e78 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <spl.h> |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 9 | #include <asm/io.h> |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <linux/libfdt.h> |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 12 | |
| 13 | u32 spl_boot_device(void) |
| 14 | { |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 15 | u32 boot_mode; |
| 16 | |
Patrick Delaunay | 7f63c1e | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 17 | boot_mode = get_bootmode(); |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 18 | |
| 19 | switch (boot_mode) { |
| 20 | case BOOT_FLASH_SD_1: |
| 21 | case BOOT_FLASH_EMMC_1: |
| 22 | return BOOT_DEVICE_MMC1; |
| 23 | case BOOT_FLASH_SD_2: |
| 24 | case BOOT_FLASH_EMMC_2: |
| 25 | return BOOT_DEVICE_MMC2; |
Patrick Delaunay | 7f63c1e | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 26 | case BOOT_SERIAL_UART_1: |
| 27 | case BOOT_SERIAL_UART_2: |
| 28 | case BOOT_SERIAL_UART_3: |
| 29 | case BOOT_SERIAL_UART_4: |
| 30 | case BOOT_SERIAL_UART_5: |
| 31 | case BOOT_SERIAL_UART_6: |
| 32 | case BOOT_SERIAL_UART_7: |
| 33 | case BOOT_SERIAL_UART_8: |
| 34 | return BOOT_DEVICE_UART; |
| 35 | case BOOT_SERIAL_USB_OTG: |
| 36 | return BOOT_DEVICE_USB; |
| 37 | case BOOT_FLASH_NAND_FMC: |
| 38 | return BOOT_DEVICE_NAND; |
| 39 | case BOOT_FLASH_NOR_QSPI: |
| 40 | return BOOT_DEVICE_SPI; |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 41 | } |
| 42 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 43 | return BOOT_DEVICE_MMC1; |
| 44 | } |
| 45 | |
| 46 | u32 spl_boot_mode(const u32 boot_device) |
| 47 | { |
| 48 | return MMCSD_MODE_RAW; |
| 49 | } |
| 50 | |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 51 | int spl_boot_partition(const u32 boot_device) |
| 52 | { |
| 53 | switch (boot_device) { |
| 54 | case BOOT_DEVICE_MMC1: |
| 55 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; |
| 56 | case BOOT_DEVICE_MMC2: |
| 57 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2; |
| 58 | default: |
| 59 | return -EINVAL; |
| 60 | } |
| 61 | } |
| 62 | |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 63 | #ifdef CONFIG_SPL_DISPLAY_PRINT |
| 64 | void spl_display_print(void) |
| 65 | { |
| 66 | DECLARE_GLOBAL_DATA_PTR; |
| 67 | const char *model; |
| 68 | |
| 69 | /* same code than show_board_info() but not compiled for SPL |
| 70 | * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c |
| 71 | */ |
| 72 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 73 | if (model) |
| 74 | printf("Model: %s\n", model); |
| 75 | } |
| 76 | #endif |
| 77 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 78 | void board_init_f(ulong dummy) |
| 79 | { |
| 80 | struct udevice *dev; |
| 81 | int ret; |
| 82 | |
| 83 | arch_cpu_init(); |
| 84 | |
| 85 | ret = spl_early_init(); |
| 86 | if (ret) { |
| 87 | debug("spl_early_init() failed: %d\n", ret); |
| 88 | hang(); |
| 89 | } |
| 90 | |
| 91 | ret = uclass_get_device(UCLASS_CLK, 0, &dev); |
| 92 | if (ret) { |
| 93 | debug("Clock init failed: %d\n", ret); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | ret = uclass_get_device(UCLASS_RESET, 0, &dev); |
| 98 | if (ret) { |
| 99 | debug("Reset init failed: %d\n", ret); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev); |
| 104 | if (ret) { |
| 105 | debug("%s: Cannot find pinctrl device\n", __func__); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | /* enable console uart printing */ |
| 110 | preloader_console_init(); |
| 111 | |
| 112 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 113 | if (ret) { |
Patrick Delaunay | 105a5ad | 2019-02-27 17:01:17 +0100 | [diff] [blame] | 114 | printf("DRAM init failed: %d\n", ret); |
| 115 | hang(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 116 | } |
| 117 | } |