Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2024 PHYTEC Messtechnik GmbH |
| 4 | * Author: Wadim Egorov <w.egorov@phytec.de> |
| 5 | */ |
| 6 | |
| 7 | #include <env_internal.h> |
Wadim Egorov | 4baf2a6 | 2024-06-10 15:33:42 +0200 | [diff] [blame] | 8 | #include <fdt_support.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <spl.h> |
| 10 | #include <asm/arch/hardware.h> |
| 11 | |
Daniel Schultz | 80677cb | 2024-05-21 23:18:26 -0700 | [diff] [blame] | 12 | #include "../am6_som_detection.h" |
| 13 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 14 | #if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC) |
| 15 | int mmc_get_env_dev(void) |
| 16 | { |
| 17 | u32 boot_device = get_boot_device(); |
| 18 | |
| 19 | switch (boot_device) { |
| 20 | case BOOT_DEVICE_MMC1: |
| 21 | return 0; |
| 22 | case BOOT_DEVICE_MMC2: |
| 23 | return 1; |
| 24 | }; |
| 25 | |
| 26 | return CONFIG_SYS_MMC_ENV_DEV; |
| 27 | } |
| 28 | #endif |
| 29 | |
| 30 | enum env_location env_get_location(enum env_operation op, int prio) |
| 31 | { |
| 32 | u32 boot_device = get_boot_device(); |
| 33 | |
| 34 | if (prio) |
| 35 | return ENVL_UNKNOWN; |
| 36 | |
| 37 | switch (boot_device) { |
| 38 | case BOOT_DEVICE_MMC1: |
| 39 | case BOOT_DEVICE_MMC2: |
| 40 | if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT)) |
| 41 | return ENVL_FAT; |
| 42 | if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC)) |
| 43 | return ENVL_MMC; |
| 44 | case BOOT_DEVICE_SPI: |
| 45 | if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) |
| 46 | return ENVL_SPI_FLASH; |
| 47 | default: |
| 48 | return ENVL_NOWHERE; |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | #if IS_ENABLED(CONFIG_BOARD_LATE_INIT) |
| 53 | int board_late_init(void) |
| 54 | { |
| 55 | u32 boot_device = get_boot_device(); |
| 56 | |
| 57 | switch (boot_device) { |
| 58 | case BOOT_DEVICE_MMC1: |
| 59 | env_set_ulong("mmcdev", 0); |
| 60 | env_set("boot", "mmc"); |
| 61 | break; |
| 62 | case BOOT_DEVICE_MMC2: |
| 63 | env_set_ulong("mmcdev", 1); |
| 64 | env_set("boot", "mmc"); |
| 65 | break; |
| 66 | case BOOT_DEVICE_SPI: |
| 67 | env_set("boot", "spi"); |
| 68 | break; |
| 69 | case BOOT_DEVICE_ETHERNET: |
| 70 | env_set("boot", "net"); |
| 71 | break; |
| 72 | }; |
| 73 | |
Daniel Schultz | 80677cb | 2024-05-21 23:18:26 -0700 | [diff] [blame] | 74 | if (IS_ENABLED(CONFIG_PHYTEC_SOM_DETECTION_BLOCKS)) { |
| 75 | struct phytec_api3_element *block_element; |
| 76 | struct phytec_eeprom_data data; |
| 77 | int ret; |
| 78 | |
| 79 | ret = phytec_eeprom_data_setup(&data, 0, EEPROM_ADDR); |
| 80 | if (ret || !data.valid) |
| 81 | return 0; |
| 82 | |
| 83 | PHYTEC_API3_FOREACH_BLOCK(block_element, &data) { |
| 84 | switch (block_element->block_type) { |
| 85 | case PHYTEC_API3_BLOCK_MAC: |
| 86 | phytec_blocks_add_mac_to_env(block_element); |
| 87 | break; |
| 88 | default: |
| 89 | debug("%s: Unknown block type %i\n", __func__, |
| 90 | block_element->block_type); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | #endif |
Wadim Egorov | 4baf2a6 | 2024-06-10 15:33:42 +0200 | [diff] [blame] | 98 | |
| 99 | #if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP) |
| 100 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 101 | { |
| 102 | fdt_copy_fixed_partitions(blob); |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | #endif |