All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM
@ 2020-10-08 13:14 Marek Vasut
  2020-10-09  7:28 ` Patrice CHOTARD
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marek Vasut @ 2020-10-08 13:14 UTC (permalink / raw)
  To: u-boot

In case the KS8851 has external EEPROM attached to it, do not set
eth1addr at all. The network stack will read the MAC out of the
KS8851 and set eth1addr accordingly.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Patrice Chotard <patrice.chotard@st.com>
Cc: Patrick Delaunay <patrick.delaunay@st.com>
---
 board/dhelectronics/dh_stm32mp1/board.c | 40 ++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
index c9abe3cc6d..f42d395098 100644
--- a/board/dhelectronics/dh_stm32mp1/board.c
+++ b/board/dhelectronics/dh_stm32mp1/board.c
@@ -81,6 +81,11 @@
  */
 DECLARE_GLOBAL_DATA_PTR;
 
+#define KS_CCR		0x08
+#define KS_CCR_EEPROM	BIT(9)
+#define KS_BE0		BIT(12)
+#define KS_BE1		BIT(13)
+
 int setup_mac_address(void)
 {
 	unsigned char enetaddr[6];
@@ -97,12 +102,39 @@ int setup_mac_address(void)
 	if (off < 0) {
 		/* ethernet1 is not present in the system */
 		skip_eth1 = true;
-	} else {
-		ret = eth_env_get_enetaddr("eth1addr", enetaddr);
-		if (ret)	/* eth1addr is already set */
-			skip_eth1 = true;
+		goto out_set_ethaddr;
+	}
+
+	ret = eth_env_get_enetaddr("eth1addr", enetaddr);
+	if (ret) {
+		/* eth1addr is already set */
+		skip_eth1 = true;
+		goto out_set_ethaddr;
+	}
+
+	ret = fdt_node_check_compatible(gd->fdt_blob, off, "micrel,ks8851-mll");
+	if (ret)
+		goto out_set_ethaddr;
+
+	/*
+	 * KS8851 with EEPROM may use custom MAC from EEPROM, read
+	 * out the KS8851 CCR register to determine whether EEPROM
+	 * is present. If EEPROM is present, it must contain valid
+	 * MAC address.
+	 */
+	u32 reg, ccr;
+	reg = fdt_get_base_address(gd->fdt_blob, off);
+	if (!reg)
+		goto out_set_ethaddr;
+
+	writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2);
+	ccr = readw(reg);
+	if (ccr & KS_CCR_EEPROM) {
+		skip_eth1 = true;
+		goto out_set_ethaddr;
 	}
 
+out_set_ethaddr:
 	if (skip_eth0 && skip_eth1)
 		return 0;
 
-- 
2.28.0

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

* [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM
  2020-10-08 13:14 [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM Marek Vasut
@ 2020-10-09  7:28 ` Patrice CHOTARD
  2020-10-13 17:03 ` Patrick DELAUNAY
  2020-10-21  9:25 ` Patrick DELAUNAY
  2 siblings, 0 replies; 4+ messages in thread
From: Patrice CHOTARD @ 2020-10-09  7:28 UTC (permalink / raw)
  To: u-boot

Hi Marek

On 10/8/20 3:14 PM, Marek Vasut wrote:
> In case the KS8851 has external EEPROM attached to it, do not set
> eth1addr at all. The network stack will read the MAC out of the
> KS8851 and set eth1addr accordingly.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Patrice Chotard <patrice.chotard@st.com>
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>  board/dhelectronics/dh_stm32mp1/board.c | 40 ++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 4 deletions(-)
>
> diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
> index c9abe3cc6d..f42d395098 100644
> --- a/board/dhelectronics/dh_stm32mp1/board.c
> +++ b/board/dhelectronics/dh_stm32mp1/board.c
> @@ -81,6 +81,11 @@
>   */
>  DECLARE_GLOBAL_DATA_PTR;
>  
> +#define KS_CCR		0x08
> +#define KS_CCR_EEPROM	BIT(9)
> +#define KS_BE0		BIT(12)
> +#define KS_BE1		BIT(13)
> +
>  int setup_mac_address(void)
>  {
>  	unsigned char enetaddr[6];
> @@ -97,12 +102,39 @@ int setup_mac_address(void)
>  	if (off < 0) {
>  		/* ethernet1 is not present in the system */
>  		skip_eth1 = true;
> -	} else {
> -		ret = eth_env_get_enetaddr("eth1addr", enetaddr);
> -		if (ret)	/* eth1addr is already set */
> -			skip_eth1 = true;
> +		goto out_set_ethaddr;
> +	}
> +
> +	ret = eth_env_get_enetaddr("eth1addr", enetaddr);
> +	if (ret) {
> +		/* eth1addr is already set */
> +		skip_eth1 = true;
> +		goto out_set_ethaddr;
> +	}
> +
> +	ret = fdt_node_check_compatible(gd->fdt_blob, off, "micrel,ks8851-mll");
> +	if (ret)
> +		goto out_set_ethaddr;
> +
> +	/*
> +	 * KS8851 with EEPROM may use custom MAC from EEPROM, read
> +	 * out the KS8851 CCR register to determine whether EEPROM
> +	 * is present. If EEPROM is present, it must contain valid
> +	 * MAC address.
> +	 */
> +	u32 reg, ccr;
> +	reg = fdt_get_base_address(gd->fdt_blob, off);
> +	if (!reg)
> +		goto out_set_ethaddr;
> +
> +	writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2);
> +	ccr = readw(reg);
> +	if (ccr & KS_CCR_EEPROM) {
> +		skip_eth1 = true;
> +		goto out_set_ethaddr;
>  	}
>  
> +out_set_ethaddr:
>  	if (skip_eth0 && skip_eth1)
>  		return 0;
>  

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks

Patrice

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

* [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM
  2020-10-08 13:14 [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM Marek Vasut
  2020-10-09  7:28 ` Patrice CHOTARD
@ 2020-10-13 17:03 ` Patrick DELAUNAY
  2020-10-21  9:25 ` Patrick DELAUNAY
  2 siblings, 0 replies; 4+ messages in thread
From: Patrick DELAUNAY @ 2020-10-13 17:03 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> From: Marek Vasut <marex@denx.de>
> Sent: jeudi 8 octobre 2020 15:15
> 
> In case the KS8851 has external EEPROM attached to it, do not set eth1addr at
> all. The network stack will read the MAC out of the
> KS8851 and set eth1addr accordingly.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Patrice Chotard <patrice.chotard@st.com>
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>  board/dhelectronics/dh_stm32mp1/board.c | 40 ++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 4 deletions(-)
> 

Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>

Thanks

Patrick

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

* [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM
  2020-10-08 13:14 [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM Marek Vasut
  2020-10-09  7:28 ` Patrice CHOTARD
  2020-10-13 17:03 ` Patrick DELAUNAY
@ 2020-10-21  9:25 ` Patrick DELAUNAY
  2 siblings, 0 replies; 4+ messages in thread
From: Patrick DELAUNAY @ 2020-10-21  9:25 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> From: Marek Vasut <marex@denx.de>
> Sent: jeudi 8 octobre 2020 15:15
> 
> In case the KS8851 has external EEPROM attached to it, do not set eth1addr at
> all. The network stack will read the MAC out of the
> KS8851 and set eth1addr accordingly.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Patrice Chotard <patrice.chotard@st.com>
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>  board/dhelectronics/dh_stm32mp1/board.c | 40 ++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 4 deletions(-)
> 

Applied to u-boot-stm/master, thanks!

Regards

Patrick

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

end of thread, other threads:[~2020-10-21  9:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 13:14 [PATCH] ARM: dts: stm32: Do not set eth1addr if KS8851 has EEPROM Marek Vasut
2020-10-09  7:28 ` Patrice CHOTARD
2020-10-13 17:03 ` Patrick DELAUNAY
2020-10-21  9:25 ` Patrick DELAUNAY

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.