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> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 9 | #include <spl.h> |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <linux/libfdt.h> |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 13 | |
| 14 | u32 spl_boot_device(void) |
| 15 | { |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 16 | u32 boot_mode; |
| 17 | |
Patrick Delaunay | 7f63c1e | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 18 | boot_mode = get_bootmode(); |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 19 | |
| 20 | switch (boot_mode) { |
| 21 | case BOOT_FLASH_SD_1: |
| 22 | case BOOT_FLASH_EMMC_1: |
| 23 | return BOOT_DEVICE_MMC1; |
| 24 | case BOOT_FLASH_SD_2: |
| 25 | case BOOT_FLASH_EMMC_2: |
| 26 | return BOOT_DEVICE_MMC2; |
Patrick Delaunay | 7f63c1e | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 27 | case BOOT_SERIAL_UART_1: |
| 28 | case BOOT_SERIAL_UART_2: |
| 29 | case BOOT_SERIAL_UART_3: |
| 30 | case BOOT_SERIAL_UART_4: |
| 31 | case BOOT_SERIAL_UART_5: |
| 32 | case BOOT_SERIAL_UART_6: |
| 33 | case BOOT_SERIAL_UART_7: |
| 34 | case BOOT_SERIAL_UART_8: |
| 35 | return BOOT_DEVICE_UART; |
| 36 | case BOOT_SERIAL_USB_OTG: |
| 37 | return BOOT_DEVICE_USB; |
| 38 | case BOOT_FLASH_NAND_FMC: |
| 39 | return BOOT_DEVICE_NAND; |
| 40 | case BOOT_FLASH_NOR_QSPI: |
| 41 | return BOOT_DEVICE_SPI; |
Patrick Delaunay | b664a74 | 2020-03-18 09:22:52 +0100 | [diff] [blame] | 42 | case BOOT_FLASH_SPINAND_1: |
| 43 | return BOOT_DEVICE_NONE; /* SPINAND not supported in SPL */ |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 46 | return BOOT_DEVICE_MMC1; |
| 47 | } |
| 48 | |
Harald Seiler | e975906 | 2020-04-15 11:33:30 +0200 | [diff] [blame] | 49 | u32 spl_mmc_boot_mode(const u32 boot_device) |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 50 | { |
| 51 | return MMCSD_MODE_RAW; |
| 52 | } |
| 53 | |
Harald Seiler | c51b751 | 2020-04-15 11:33:31 +0200 | [diff] [blame] | 54 | int spl_mmc_boot_partition(const u32 boot_device) |
Patrick Delaunay | 11dfd1a | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 55 | { |
| 56 | switch (boot_device) { |
| 57 | case BOOT_DEVICE_MMC1: |
| 58 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; |
| 59 | case BOOT_DEVICE_MMC2: |
| 60 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2; |
| 61 | default: |
| 62 | return -EINVAL; |
| 63 | } |
| 64 | } |
| 65 | |
Patrick Delaunay | 006ea18 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_SPL_DISPLAY_PRINT |
| 67 | void spl_display_print(void) |
| 68 | { |
| 69 | DECLARE_GLOBAL_DATA_PTR; |
| 70 | const char *model; |
| 71 | |
| 72 | /* same code than show_board_info() but not compiled for SPL |
| 73 | * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c |
| 74 | */ |
| 75 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 76 | if (model) |
| 77 | printf("Model: %s\n", model); |
| 78 | } |
| 79 | #endif |
| 80 | |
Marek Vasut | 65e38e8 | 2020-04-22 13:18:10 +0200 | [diff] [blame] | 81 | __weak int board_early_init_f(void) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 86 | void board_init_f(ulong dummy) |
| 87 | { |
| 88 | struct udevice *dev; |
| 89 | int ret; |
| 90 | |
| 91 | arch_cpu_init(); |
| 92 | |
| 93 | ret = spl_early_init(); |
| 94 | if (ret) { |
| 95 | debug("spl_early_init() failed: %d\n", ret); |
| 96 | hang(); |
| 97 | } |
| 98 | |
| 99 | ret = uclass_get_device(UCLASS_CLK, 0, &dev); |
| 100 | if (ret) { |
| 101 | debug("Clock init failed: %d\n", ret); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | ret = uclass_get_device(UCLASS_RESET, 0, &dev); |
| 106 | if (ret) { |
| 107 | debug("Reset init failed: %d\n", ret); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev); |
| 112 | if (ret) { |
| 113 | debug("%s: Cannot find pinctrl device\n", __func__); |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | /* enable console uart printing */ |
| 118 | preloader_console_init(); |
| 119 | |
Marek Vasut | 65e38e8 | 2020-04-22 13:18:10 +0200 | [diff] [blame] | 120 | ret = board_early_init_f(); |
| 121 | if (ret) { |
| 122 | debug("board_early_init_f() failed: %d\n", ret); |
| 123 | hang(); |
| 124 | } |
| 125 | |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 126 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 127 | if (ret) { |
Patrick Delaunay | 105a5ad | 2019-02-27 17:01:17 +0100 | [diff] [blame] | 128 | printf("DRAM init failed: %d\n", ret); |
| 129 | hang(); |
Patrick Delaunay | 2514c2d | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 130 | } |
| 131 | } |