Tom Rini | 8b0c8a1 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 9 | #include <spl.h> |
Patrick Delaunay | fc69c68 | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
Patrick Delaunay | aa4e685 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <linux/libfdt.h> |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 13 | |
| 14 | u32 spl_boot_device(void) |
| 15 | { |
Patrick Delaunay | fc69c68 | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 16 | u32 boot_mode; |
| 17 | |
Patrick Delaunay | 18660a6 | 2019-02-27 17:01:12 +0100 | [diff] [blame] | 18 | boot_mode = get_bootmode(); |
Patrick Delaunay | fc69c68 | 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 | 18660a6 | 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 | fc69c68 | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 44 | return BOOT_DEVICE_MMC1; |
| 45 | } |
| 46 | |
| 47 | u32 spl_boot_mode(const u32 boot_device) |
| 48 | { |
| 49 | return MMCSD_MODE_RAW; |
| 50 | } |
| 51 | |
Patrick Delaunay | fc69c68 | 2018-03-20 10:54:54 +0100 | [diff] [blame] | 52 | int spl_boot_partition(const u32 boot_device) |
| 53 | { |
| 54 | switch (boot_device) { |
| 55 | case BOOT_DEVICE_MMC1: |
| 56 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; |
| 57 | case BOOT_DEVICE_MMC2: |
| 58 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2; |
| 59 | default: |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | } |
| 63 | |
Patrick Delaunay | aa4e685 | 2019-02-27 17:01:14 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_SPL_DISPLAY_PRINT |
| 65 | void spl_display_print(void) |
| 66 | { |
| 67 | DECLARE_GLOBAL_DATA_PTR; |
| 68 | const char *model; |
| 69 | |
| 70 | /* same code than show_board_info() but not compiled for SPL |
| 71 | * see CONFIG_DISPLAY_BOARDINFO & common/board_info.c |
| 72 | */ |
| 73 | model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 74 | if (model) |
| 75 | printf("Model: %s\n", model); |
| 76 | } |
| 77 | #endif |
| 78 | |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 79 | void board_init_f(ulong dummy) |
| 80 | { |
| 81 | struct udevice *dev; |
| 82 | int ret; |
| 83 | |
| 84 | arch_cpu_init(); |
| 85 | |
| 86 | ret = spl_early_init(); |
| 87 | if (ret) { |
| 88 | debug("spl_early_init() failed: %d\n", ret); |
| 89 | hang(); |
| 90 | } |
| 91 | |
| 92 | ret = uclass_get_device(UCLASS_CLK, 0, &dev); |
| 93 | if (ret) { |
| 94 | debug("Clock init failed: %d\n", ret); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | ret = uclass_get_device(UCLASS_RESET, 0, &dev); |
| 99 | if (ret) { |
| 100 | debug("Reset init failed: %d\n", ret); |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | ret = uclass_get_device(UCLASS_PINCTRL, 0, &dev); |
| 105 | if (ret) { |
| 106 | debug("%s: Cannot find pinctrl device\n", __func__); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | /* enable console uart printing */ |
| 111 | preloader_console_init(); |
| 112 | |
| 113 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 114 | if (ret) { |
Patrick Delaunay | bb8de08 | 2019-02-27 17:01:17 +0100 | [diff] [blame] | 115 | printf("DRAM init failed: %d\n", ret); |
| 116 | hang(); |
Patrick Delaunay | 85b5397 | 2018-03-12 10:46:10 +0100 | [diff] [blame] | 117 | } |
| 118 | } |