Michal Simek | 9755e3d | 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> |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 8 | #include <asm/sections.h> |
Michal Simek | 9755e3d | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 9 | #include <dm/uclass.h> |
| 10 | #include <i2c.h> |
Michal Simek | a29511e | 2020-04-08 10:51:36 +0200 | [diff] [blame] | 11 | #include <linux/sizes.h> |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 12 | #include "board.h" |
Michal Simek | 9755e3d | 2019-01-21 15:25:02 +0100 | [diff] [blame] | 13 | |
Michal Simek | 829e8c7 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 14 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 15 | { |
| 16 | int ret = -EINVAL; |
| 17 | |
| 18 | #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) |
| 19 | struct udevice *dev; |
| 20 | ofnode eeprom; |
| 21 | |
| 22 | eeprom = ofnode_get_chosen_node("xlnx,eeprom"); |
| 23 | if (!ofnode_valid(eeprom)) |
| 24 | return -ENODEV; |
| 25 | |
| 26 | debug("%s: Path to EEPROM %s\n", __func__, |
Simon Glass | 14ca9f7 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 27 | ofnode_read_chosen_string("xlnx,eeprom")); |
Michal Simek | 829e8c7 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 28 | |
| 29 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6); |
| 34 | if (ret) |
| 35 | debug("%s: I2C EEPROM MAC address read failed\n", __func__); |
| 36 | else |
| 37 | debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr); |
| 38 | #endif |
| 39 | |
| 40 | return ret; |
| 41 | } |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 42 | |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 43 | #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE) |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 44 | void *board_fdt_blob_setup(void) |
| 45 | { |
Michal Simek | 453bb77 | 2020-03-19 10:23:56 +0100 | [diff] [blame] | 46 | static void *fdt_blob; |
| 47 | |
| 48 | #if !defined(CONFIG_VERSAL_NO_DDR) && !defined(CONFIG_ZYNQMP_NO_DDR) |
| 49 | fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR; |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 50 | |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 51 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 52 | return fdt_blob; |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 53 | |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 54 | debug("DTB is not passed via %p\n", fdt_blob); |
Michal Simek | 453bb77 | 2020-03-19 10:23:56 +0100 | [diff] [blame] | 55 | #endif |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 56 | |
| 57 | #ifdef CONFIG_SPL_BUILD |
| 58 | /* FDT is at end of BSS unless it is in a different memory region */ |
| 59 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
| 60 | fdt_blob = (ulong *)&_image_binary_end; |
| 61 | else |
| 62 | fdt_blob = (ulong *)&__bss_end; |
| 63 | #else |
| 64 | /* FDT is at end of image */ |
| 65 | fdt_blob = (ulong *)&_end; |
| 66 | #endif |
| 67 | |
| 68 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 69 | return fdt_blob; |
| 70 | |
| 71 | debug("DTB is also not passed via %p\n", fdt_blob); |
| 72 | |
| 73 | return NULL; |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 74 | } |
| 75 | #endif |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 76 | |
| 77 | int board_late_init_xilinx(void) |
| 78 | { |
Michal Simek | a29511e | 2020-04-08 10:51:36 +0200 | [diff] [blame] | 79 | ulong initrd_hi; |
| 80 | |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 81 | env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET); |
| 82 | |
Michal Simek | a29511e | 2020-04-08 10:51:36 +0200 | [diff] [blame] | 83 | initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE; |
| 84 | initrd_hi = round_down(initrd_hi, SZ_16M); |
| 85 | env_set_addr("initrd_high", (void *)initrd_hi); |
| 86 | |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 87 | return 0; |
| 88 | } |