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> |
| 11 | |
Michal Simek | 829e8c7 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 12 | int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) |
| 13 | { |
| 14 | int ret = -EINVAL; |
| 15 | |
| 16 | #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) |
| 17 | struct udevice *dev; |
| 18 | ofnode eeprom; |
| 19 | |
| 20 | eeprom = ofnode_get_chosen_node("xlnx,eeprom"); |
| 21 | if (!ofnode_valid(eeprom)) |
| 22 | return -ENODEV; |
| 23 | |
| 24 | debug("%s: Path to EEPROM %s\n", __func__, |
Simon Glass | 14ca9f7 | 2020-01-27 08:49:43 -0700 | [diff] [blame] | 25 | ofnode_read_chosen_string("xlnx,eeprom")); |
Michal Simek | 829e8c7 | 2019-01-21 16:29:07 +0100 | [diff] [blame] | 26 | |
| 27 | ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); |
| 28 | if (ret) |
| 29 | return ret; |
| 30 | |
| 31 | ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6); |
| 32 | if (ret) |
| 33 | debug("%s: I2C EEPROM MAC address read failed\n", __func__); |
| 34 | else |
| 35 | debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr); |
| 36 | #endif |
| 37 | |
| 38 | return ret; |
| 39 | } |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 40 | |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 41 | #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE) |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 42 | void *board_fdt_blob_setup(void) |
| 43 | { |
Michal Simek | db5b253 | 2019-12-19 17:43:07 +0100 | [diff] [blame] | 44 | static void *fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR; |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 45 | |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 46 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 47 | return fdt_blob; |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 48 | |
Michal Simek | fc274a5 | 2019-12-19 17:45:15 +0100 | [diff] [blame] | 49 | debug("DTB is not passed via %p\n", fdt_blob); |
| 50 | |
| 51 | #ifdef CONFIG_SPL_BUILD |
| 52 | /* FDT is at end of BSS unless it is in a different memory region */ |
| 53 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) |
| 54 | fdt_blob = (ulong *)&_image_binary_end; |
| 55 | else |
| 56 | fdt_blob = (ulong *)&__bss_end; |
| 57 | #else |
| 58 | /* FDT is at end of image */ |
| 59 | fdt_blob = (ulong *)&_end; |
| 60 | #endif |
| 61 | |
| 62 | if (fdt_magic(fdt_blob) == FDT_MAGIC) |
| 63 | return fdt_blob; |
| 64 | |
| 65 | debug("DTB is also not passed via %p\n", fdt_blob); |
| 66 | |
| 67 | return NULL; |
Ibai Erkiaga | fec657b | 2019-10-02 15:57:36 +0100 | [diff] [blame] | 68 | } |
| 69 | #endif |