diff mbox series

[U-Boot,2/2] xilinx: common: Add support for DM_I2C zynq_board_read_rom_ethaddr()

Message ID c4cc28041e1872cc7ad359b0a5a4bca7f563bf18.1548665564.git.michal.simek@xilinx.com
State Accepted
Commit 829e8c73dd75eb49c00a6916963ec7b0b1a771c5
Delegated to: Michal Simek
Headers show
Series [U-Boot,1/2] xilinx: Move zynq_board_read_rom_ethaddr to shared location | expand

Commit Message

Michal Simek Jan. 28, 2019, 8:52 a.m. UTC
It is much easier to point to eeprom which stores information like MAC
address directly via DT. eeprom which contains this information is
pointed by /chosen/xlnx,eeprom parameter.

For example:
        chosen {
                bootargs = "earlycon";
                stdout-path = "serial0:115200n8";
+               xlnx,eeprom = &eeprom;
        };

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 board/xilinx/common/board.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Mike Looijmans Feb. 12, 2019, 7:08 a.m. UTC | #1
It would even be better to adopt the Linux kernel way of storing MAC address 
through nvmem. That works for basically any board - and you get rid of the 
vendor prefix. Any nvmem provider can store the data, not just I2C eeproms. It 
reduces the total code size since all gem drivers can call the same function.

Example:

eeprom: eeprom@50 {
	compatible = "at24,24c04";
	reg = <0x50>;
	#address-cells = <1>;
	#size-cells = <1>;
	/* NVMEM entries */
	gem0_mac: mac@0x1e8 {
		reg = <0x1e8 6>;
	};
};

&gem0 {
	/* MAC address stored in NVMEM */
	nvmem-cells = <&gem0_mac>;
	nvmem-cell-names = "mac-address";
};


On 28-01-19 09:52, Michal Simek wrote:
> It is much easier to point to eeprom which stores information like MAC
> address directly via DT. eeprom which contains this information is
> pointed by /chosen/xlnx,eeprom parameter.
> 
> For example:
>          chosen {
>                  bootargs = "earlycon";
>                  stdout-path = "serial0:115200n8";
> +               xlnx,eeprom = &eeprom;
>          };
> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
> 
>   board/xilinx/common/board.c | 32 ++++++++++++++++++++++++++++++++
>   1 file changed, 32 insertions(+)
> 
> diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
> index 7e813d856404..b14f530c72c5 100644
> --- a/board/xilinx/common/board.c
> +++ b/board/xilinx/common/board.c
> @@ -8,6 +8,7 @@
>   #include <dm/uclass.h>
>   #include <i2c.h>
>   
> +#if !defined(CONFIG_DM_I2C)
>   int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
>   {
>   #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
> @@ -23,3 +24,34 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
>   
>   	return 0;
>   }
> +
> +#else
> +int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
> +{
> +	int ret = -EINVAL;
> +
> +#if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
> +	struct udevice *dev;
> +	ofnode eeprom;
> +
> +	eeprom = ofnode_get_chosen_node("xlnx,eeprom");
> +	if (!ofnode_valid(eeprom))
> +		return -ENODEV;
> +
> +	debug("%s: Path to EEPROM %s\n", __func__,
> +	      ofnode_get_chosen_prop("xlnx,eeprom"));
> +
> +	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);
> +	if (ret)
> +		debug("%s: I2C EEPROM MAC address read failed\n", __func__);
> +	else
> +		debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr);
> +#endif
> +
> +	return ret;
> +}
> +#endif
>
diff mbox series

Patch

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index 7e813d856404..b14f530c72c5 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -8,6 +8,7 @@ 
 #include <dm/uclass.h>
 #include <i2c.h>
 
+#if !defined(CONFIG_DM_I2C)
 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
 {
 #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
@@ -23,3 +24,34 @@  int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
 
 	return 0;
 }
+
+#else
+int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
+{
+	int ret = -EINVAL;
+
+#if defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
+	struct udevice *dev;
+	ofnode eeprom;
+
+	eeprom = ofnode_get_chosen_node("xlnx,eeprom");
+	if (!ofnode_valid(eeprom))
+		return -ENODEV;
+
+	debug("%s: Path to EEPROM %s\n", __func__,
+	      ofnode_get_chosen_prop("xlnx,eeprom"));
+
+	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
+	if (ret)
+		return ret;
+
+	ret = dm_i2c_read(dev, CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET, ethaddr, 6);
+	if (ret)
+		debug("%s: I2C EEPROM MAC address read failed\n", __func__);
+	else
+		debug("%s: I2C EEPROM MAC %pM\n", __func__, ethaddr);
+#endif
+
+	return ret;
+}
+#endif