Merge tag 'xilinx-for-v2020.01' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / board / xilinx / common / board.c
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>
8 #include <dm/uclass.h>
9 #include <i2c.h>
10
11 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
12 {
13         int ret = -EINVAL;
14
15 #if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
16         struct udevice *dev;
17         ofnode eeprom;
18
19         eeprom = ofnode_get_chosen_node("xlnx,eeprom");
20         if (!ofnode_valid(eeprom))
21                 return -ENODEV;
22
23         debug("%s: Path to EEPROM %s\n", __func__,
24               ofnode_get_chosen_prop("xlnx,eeprom"));
25
26         ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
27         if (ret)
28                 return ret;
29
30         ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);
31         if (ret)
32                 debug("%s: I2C EEPROM MAC address read failed\n", __func__);
33         else
34                 debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr);
35 #endif
36
37         return ret;
38 }
39
40 #if defined(CONFIG_OF_BOARD)
41 void *board_fdt_blob_setup(void)
42 {
43         static void *fw_dtb = (void *)CONFIG_XILINX_OF_BOARD_DTB_ADDR;
44
45         if (fdt_magic(fw_dtb) != FDT_MAGIC) {
46                 printf("DTB is not passed via %p\n", fw_dtb);
47                 return NULL;
48         }
49
50         return fw_dtb;
51 }
52 #endif