Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2014 - 2019 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 10 | #include <asm/sections.h> |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 11 | #include <dm/uclass.h> |
| 12 | #include <i2c.h> |
Michal Simek | b90b97e | 2020-04-08 10:51:36 +0200 | [diff] [blame] | 13 | #include <linux/sizes.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 14 | #include "board.h" |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 15 | |
Michal Simek | aee22b3 | 2020-08-03 12:59:28 +0200 | [diff] [blame] | 16 | #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) |
Michal Simek | 014d304 | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 17 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 18 | { |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 19 | int ret = -EINVAL; |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 20 | struct udevice *dev; |
| 21 | ofnode eeprom; |
| 22 | |
| 23 | eeprom = ofnode_get_chosen_node("xlnx,eeprom"); |
| 24 | if (!ofnode_valid(eeprom)) |
| 25 | return -ENODEV; |
| 26 | |
| 27 | debug("%s: Path to EEPROM %s\n", __func__, |
Simon Glass | f345596 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 28 | ofnode_read_chosen_string("xlnx,eeprom")); |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 29 | |
| 30 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
| 31 | if (ret) |
| 32 | return ret; |
| 33 | |
| 34 | ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6); |
| 35 | if (ret) |
| 36 | debug("%s: I2C EEPROM MAC address read failed\n", __func__); |
| 37 | else |
| 38 | debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr); |
Michal Simek | 13db616 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 39 | |
| 40 | return ret; |
| 41 | } |
Michal Simek | aee22b3 | 2020-08-03 12:59:28 +0200 | [diff] [blame] | 42 | #endif |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 43 | |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 44 | #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE) |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 45 | void *board_fdt_blob_setup(void) |
| 46 | { |
Michal Simek | c89f429 | 2020-03-19 10:23:56 +0100 | [diff] [blame] | 47 | static void *fdt_blob; |
| 48 | |
| 49 | #if !defined(CONFIG_VERSAL_NO_DDR) && !defined(CONFIG_ZYNQMP_NO_DDR) |
| 50 | fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR; |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 51 | |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 52 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 53 | return fdt_blob; |
| 54 | |
| 55 | debug("DTB is not passed via %p\n", fdt_blob); |
Michal Simek | c89f429 | 2020-03-19 10:23:56 +0100 | [diff] [blame] | 56 | #endif |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 57 | |
| 58 | #ifdef CONFIG_SPL_BUILD |
| 59 | /* FDT is at end of BSS unless it is in a different memory region */ |
| 60 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
| 61 | fdt_blob = (ulong *)&_image_binary_end; |
| 62 | else |
| 63 | fdt_blob = (ulong *)&__bss_end; |
| 64 | #else |
| 65 | /* FDT is at end of image */ |
| 66 | fdt_blob = (ulong *)&_end; |
| 67 | #endif |
| 68 | |
| 69 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 70 | return fdt_blob; |
| 71 | |
| 72 | debug("DTB is also not passed via %p\n", fdt_blob); |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 73 | |
Michal Simek | 878ba36 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 74 | return NULL; |
Ibai Erkiaga | 6f65820 | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 75 | } |
| 76 | #endif |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 77 | |
| 78 | int board_late_init_xilinx(void) |
| 79 | { |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 80 | u32 ret = 0; |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame^] | 81 | phys_size_t bootm_size = gd->ram_size; |
| 82 | |
| 83 | if (CONFIG_IS_ENABLED(ARCH_ZYNQ)) |
| 84 | bootm_size = min(bootm_size, (phys_size_t)(SZ_512M + SZ_256M)); |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 85 | |
| 86 | ret |= env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET); |
| 87 | |
| 88 | ret |= env_set_addr("bootm_low", (void *)gd->ram_base); |
Michal Simek | c86ce0c | 2020-08-12 12:17:53 +0200 | [diff] [blame^] | 89 | ret |= env_set_addr("bootm_size", (void *)bootm_size); |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 90 | |
Michal Simek | bd07b5d | 2020-08-12 12:16:49 +0200 | [diff] [blame] | 91 | if (ret) |
| 92 | printf("%s: Saving run time variables FAILED\n", __func__); |
Michal Simek | 8ba62d2 | 2020-07-09 15:57:56 +0200 | [diff] [blame] | 93 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 94 | return 0; |
| 95 | } |