All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] xilinx: Move zynq_board_read_rom_ethaddr to shared location
@ 2019-01-28  8:52 Michal Simek
  2019-01-28  8:52 ` [U-Boot] [PATCH 2/2] xilinx: common: Add support for DM_I2C zynq_board_read_rom_ethaddr() Michal Simek
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Simek @ 2019-01-28  8:52 UTC (permalink / raw)
  To: u-boot

Zynq and ZynqMP are sharing similar code and there is no reason to do
code duplication. Move zynq_board_read_rom_ethaddr() to common file for
easier conversion to DM.
Use ZynqMP version that's why also add CONFIG_ZYNQ_EEPROM_BUS to Syzygy
which is only one Zynq board which is using this feature.

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

 board/opalkelly/zynq/board.c |  2 ++
 board/xilinx/common/board.c  | 25 +++++++++++++++++++++++++
 board/xilinx/zynq/Makefile   |  1 +
 board/xilinx/zynq/board.c    | 13 -------------
 board/xilinx/zynqmp/Makefile |  1 +
 board/xilinx/zynqmp/zynqmp.c | 17 -----------------
 include/configs/syzygy_hub.h |  1 +
 7 files changed, 30 insertions(+), 30 deletions(-)
 create mode 100644 board/xilinx/common/board.c

diff --git a/board/opalkelly/zynq/board.c b/board/opalkelly/zynq/board.c
index a95c9d1eff0f..ee666185ec09 100644
--- a/board/opalkelly/zynq/board.c
+++ b/board/opalkelly/zynq/board.c
@@ -1 +1,3 @@
+#include "../../xilinx/common/board.c"
+
 #include "../../xilinx/zynq/board.c"
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
new file mode 100644
index 000000000000..7e813d856404
--- /dev/null
+++ b/board/xilinx/common/board.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2014 - 2019 Xilinx, Inc.
+ * Michal Simek <michal.simek@xilinx.com>
+ */
+
+#include <common.h>
+#include <dm/uclass.h>
+#include <i2c.h>
+
+int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
+{
+#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
+    defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
+    defined(CONFIG_ZYNQ_EEPROM_BUS)
+	i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
+
+	if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
+			CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
+			ethaddr, 6))
+		printf("I2C EEPROM MAC address read failed\n");
+#endif
+
+	return 0;
+}
diff --git a/board/xilinx/zynq/Makefile b/board/xilinx/zynq/Makefile
index e7645be189c3..8d3301543959 100644
--- a/board/xilinx/zynq/Makefile
+++ b/board/xilinx/zynq/Makefile
@@ -4,6 +4,7 @@
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 
 obj-y	:= board.o
+obj-y	+= ../common/board.o
 
 ifneq ($(CONFIG_XILINX_PS_INIT_FILE),"")
 PS_INIT_FILE := $(shell cd $(srctree); readlink -f $(CONFIG_XILINX_PS_INIT_FILE))
diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
index 614d93c082a6..f9973840bf20 100644
--- a/board/xilinx/zynq/board.c
+++ b/board/xilinx/zynq/board.c
@@ -77,19 +77,6 @@ int board_late_init(void)
 	return 0;
 }
 
-int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
-{
-#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
-    defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
-	if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
-			CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
-			ethaddr, 6))
-		printf("I2C EEPROM MAC address read failed\n");
-#endif
-
-	return 0;
-}
-
 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
 int dram_init_banksize(void)
 {
diff --git a/board/xilinx/zynqmp/Makefile b/board/xilinx/zynqmp/Makefile
index 960b81fc5853..80f8ca7e1e4b 100644
--- a/board/xilinx/zynqmp/Makefile
+++ b/board/xilinx/zynqmp/Makefile
@@ -4,6 +4,7 @@
 # Michal Simek <michal.simek@xilinx.com>
 
 obj-y	:= zynqmp.o
+obj-y	+= ../common/board.o
 
 ifneq ($(CONFIG_XILINX_PS_INIT_FILE),"")
 PS_INIT_FILE := $(shell cd $(srctree); readlink -f $(CONFIG_XILINX_PS_INIT_FILE))
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 41e88b03f9d1..e7dfd49a3ccf 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -20,7 +20,6 @@
 #include <usb.h>
 #include <dwc3-uboot.h>
 #include <zynqmppl.h>
-#include <i2c.h>
 #include <g_dnl.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -409,22 +408,6 @@ int board_early_init_r(void)
 	return 0;
 }
 
-int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
-{
-#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
-    defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
-    defined(CONFIG_ZYNQ_EEPROM_BUS)
-	i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
-
-	if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
-			CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
-			ethaddr, 6))
-		printf("I2C EEPROM MAC address read failed\n");
-#endif
-
-	return 0;
-}
-
 unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
 			 char * const argv[])
 {
diff --git a/include/configs/syzygy_hub.h b/include/configs/syzygy_hub.h
index 88ee77284890..75036977d486 100644
--- a/include/configs/syzygy_hub.h
+++ b/include/configs/syzygy_hub.h
@@ -12,6 +12,7 @@
 
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_ZYNQ_GEM_EEPROM_ADDR    0x57
+#define CONFIG_ZYNQ_EEPROM_BUS		0
 
 #define CONFIG_EXTRA_ENV_SETTINGS       \
 	"fit_image=fit.itb\0"		\
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH 2/2] xilinx: common: Add support for DM_I2C zynq_board_read_rom_ethaddr()
  2019-01-28  8:52 [U-Boot] [PATCH 1/2] xilinx: Move zynq_board_read_rom_ethaddr to shared location Michal Simek
@ 2019-01-28  8:52 ` Michal Simek
  2019-02-12  7:08   ` Mike Looijmans
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Simek @ 2019-01-28  8:52 UTC (permalink / raw)
  To: u-boot

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
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH 2/2] xilinx: common: Add support for DM_I2C zynq_board_read_rom_ethaddr()
  2019-01-28  8:52 ` [U-Boot] [PATCH 2/2] xilinx: common: Add support for DM_I2C zynq_board_read_rom_ethaddr() Michal Simek
@ 2019-02-12  7:08   ` Mike Looijmans
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Looijmans @ 2019-02-12  7:08 UTC (permalink / raw)
  To: u-boot

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 at 50 {
	compatible = "at24,24c04";
	reg = <0x50>;
	#address-cells = <1>;
	#size-cells = <1>;
	/* NVMEM entries */
	gem0_mac: mac at 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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-12  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28  8:52 [U-Boot] [PATCH 1/2] xilinx: Move zynq_board_read_rom_ethaddr to shared location Michal Simek
2019-01-28  8:52 ` [U-Boot] [PATCH 2/2] xilinx: common: Add support for DM_I2C zynq_board_read_rom_ethaddr() Michal Simek
2019-02-12  7:08   ` Mike Looijmans

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.