blob: f87e2e91059e3f82c36ea68a3cfb68b87451fefa [file] [log] [blame]
Michal Simek014d3042019-01-21 15:25:02 +01001// 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 Simek878ba362019-12-19 17:45:15 +01008#include <asm/sections.h>
Michal Simek014d3042019-01-21 15:25:02 +01009#include <dm/uclass.h>
10#include <i2c.h>
11
12int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
13{
Michal Simek13db6162019-01-21 16:29:07 +010014 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 Glassf3455962020-01-27 08:49:43 -070025 ofnode_read_chosen_string("xlnx,eeprom"));
Michal Simek13db6162019-01-21 16:29:07 +010026
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 Erkiaga6f658202019-10-02 15:57:36 +010040
Michal Simek878ba362019-12-19 17:45:15 +010041#if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
Ibai Erkiaga6f658202019-10-02 15:57:36 +010042void *board_fdt_blob_setup(void)
43{
Michal Simek6f462f2a2019-12-19 17:43:07 +010044 static void *fdt_blob = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
Ibai Erkiaga6f658202019-10-02 15:57:36 +010045
Michal Simek878ba362019-12-19 17:45:15 +010046 if (fdt_magic(fdt_blob) == FDT_MAGIC)
47 return fdt_blob;
48
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);
Ibai Erkiaga6f658202019-10-02 15:57:36 +010066
Michal Simek878ba362019-12-19 17:45:15 +010067 return NULL;
Ibai Erkiaga6f658202019-10-02 15:57:36 +010068}
69#endif