diff mbox series

ARM: imx: Auto-detect PHY on Data Modul i.MX8M Mini/Plus eDM SBC

Message ID 20240101210650.87314-1-marex@denx.de
State Accepted
Commit 32a41b7c378315088ebc7392c91121261b84bad9
Delegated to: Fabio Estevam
Headers show
Series ARM: imx: Auto-detect PHY on Data Modul i.MX8M Mini/Plus eDM SBC | expand

Commit Message

Marek Vasut Jan. 1, 2024, 9:05 p.m. UTC
Implement fdtdec_board_setup() auto-detection of ethernet PHY.
This uses properties of the hardware and pull resistor placement.

If GPIO1_16 RGMII_MDC is HIGH, then R530 (MX8MM eDM SBC) or
R390 (MX8MP eDM SBC) is populated. R530 or R390 is populated
only on boards with AR8031 PHY.

If GPIO1_16 RGMII_MDC is LOW, then the in-SoM pull down is the
dominant pull resistor. This is the case on boards with BCM54213PE
PHY.

In case AR8031 PHY is populated, the PHY MDIO address is 0, in
case BCM54213PE PHY is populated, the PHY MDIO address is 1, the
fdtdec_board_setup() is used to patch the correct address into
the U-Boot control DT.

Enable broadcom PHY support to support both PHYs.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "NXP i.MX U-Boot Team" <uboot-imx@nxp.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 .../dts/imx8mp-data-modul-edm-sbc-u-boot.dtsi |  6 ---
 .../imx8mm_data_modul_edm_sbc.c               | 42 ++++++++++++++++
 .../imx8mp_data_modul_edm_sbc.c               | 50 +++++++++++++++++++
 configs/imx8mm_data_modul_edm_sbc_defconfig   |  1 +
 configs/imx8mp_data_modul_edm_sbc_defconfig   |  1 +
 5 files changed, 94 insertions(+), 6 deletions(-)

Comments

Fabio Estevam Jan. 3, 2024, 7:33 p.m. UTC | #1
On Mon, Jan 1, 2024 at 6:07 PM Marek Vasut <marex@denx.de> wrote:
>
> Implement fdtdec_board_setup() auto-detection of ethernet PHY.
> This uses properties of the hardware and pull resistor placement.
>
> If GPIO1_16 RGMII_MDC is HIGH, then R530 (MX8MM eDM SBC) or
> R390 (MX8MP eDM SBC) is populated. R530 or R390 is populated
> only on boards with AR8031 PHY.
>
> If GPIO1_16 RGMII_MDC is LOW, then the in-SoM pull down is the
> dominant pull resistor. This is the case on boards with BCM54213PE
> PHY.
>
> In case AR8031 PHY is populated, the PHY MDIO address is 0, in
> case BCM54213PE PHY is populated, the PHY MDIO address is 1, the
> fdtdec_board_setup() is used to patch the correct address into
> the U-Boot control DT.
>
> Enable broadcom PHY support to support both PHYs.
>
> Signed-off-by: Marek Vasut <marex@denx.de>

Reviewed-by: Fabio Estevam <festevam@gmail.com>
Fabio Estevam Jan. 8, 2024, 6:24 p.m. UTC | #2
On Mon, Jan 1, 2024 at 6:07 PM Marek Vasut <marex@denx.de> wrote:
>
> Implement fdtdec_board_setup() auto-detection of ethernet PHY.
> This uses properties of the hardware and pull resistor placement.
>
> If GPIO1_16 RGMII_MDC is HIGH, then R530 (MX8MM eDM SBC) or
> R390 (MX8MP eDM SBC) is populated. R530 or R390 is populated
> only on boards with AR8031 PHY.
>
> If GPIO1_16 RGMII_MDC is LOW, then the in-SoM pull down is the
> dominant pull resistor. This is the case on boards with BCM54213PE
> PHY.
>
> In case AR8031 PHY is populated, the PHY MDIO address is 0, in
> case BCM54213PE PHY is populated, the PHY MDIO address is 1, the
> fdtdec_board_setup() is used to patch the correct address into
> the U-Boot control DT.
>
> Enable broadcom PHY support to support both PHYs.
>
> Signed-off-by: Marek Vasut <marex@denx.de>

Applied, thanks.
diff mbox series

Patch

diff --git a/arch/arm/dts/imx8mp-data-modul-edm-sbc-u-boot.dtsi b/arch/arm/dts/imx8mp-data-modul-edm-sbc-u-boot.dtsi
index a2b5976b6bd..cb6ea356fd7 100644
--- a/arch/arm/dts/imx8mp-data-modul-edm-sbc-u-boot.dtsi
+++ b/arch/arm/dts/imx8mp-data-modul-edm-sbc-u-boot.dtsi
@@ -51,12 +51,6 @@ 
 	};
 };
 
-&eqos {
-	/delete-property/ assigned-clocks;
-	/delete-property/ assigned-clock-parents;
-	/delete-property/ assigned-clock-rates;
-};
-
 &gpio1 {
 	bootph-pre-ram;
 };
diff --git a/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c b/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c
index ff89333b732..bfb2bddc1d1 100644
--- a/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c
+++ b/board/data_modul/imx8mm_edm_sbc/imx8mm_data_modul_edm_sbc.c
@@ -5,9 +5,11 @@ 
 
 #include <common.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/imx8mm_pins.h>
 #include <asm/io.h>
 #include <dm.h>
 #include <dm/device-internal.h>
+#include <linux/bitfield.h>
 #include <malloc.h>
 #include <spl.h>
 
@@ -34,3 +36,43 @@  int board_late_init(void)
 
 	return 0;
 }
+
+int fdtdec_board_setup(const void *fdt_blob)
+{
+	const void __iomem *mux = (void __iomem *)IOMUXC_BASE_ADDR +
+		FIELD_GET(MUX_CTRL_OFS_MASK, IMX8MM_PAD_ENET_MDC_GPIO1_IO16);
+	const char *phy_compat = "ethernet-phy-ieee802.3-c22";
+	bool is_bcmphy;
+	int phy_node;
+	int ret;
+
+	/* Do nothing if not i.MX8MM eDM SBC */
+	ret = fdt_node_check_compatible(fdt_blob, 0, "dmo,imx8mm-data-modul-edm-sbc");
+	if (ret)
+		return 0;
+
+	/*
+	 * If GPIO1_16 RGMII_MDC is HIGH, then R530 is populated.
+	 * R530 is populated only on boards with AR8031 PHY.
+	 *
+	 * If GPIO1_16 RGMII_MDC is LOW, then the in-SoM pull down
+	 * is the dominant pull resistor. This is the case on boards
+	 * with BCM54213PE PHY.
+	 */
+	setbits_le32(mux, IOMUX_CONFIG_SION);
+	is_bcmphy = !(readl(GPIO1_BASE_ADDR) & BIT(16));
+	clrbits_le32(mux, IOMUX_CONFIG_SION);
+
+	phy_node = fdt_node_offset_by_compatible(fdt_blob, -1, phy_compat);
+	if (phy_node < 0)
+		return 0;
+
+	/*
+	 * Update PHY MDC address in control DT based on the populated
+	 * PHY type. AR8031 is at address 0, BCM54213PE is at address 1.
+	 */
+	fdt_setprop_inplace_u32((void *)fdt_blob, phy_node,
+				"reg", is_bcmphy ? 1 : 0);
+
+	return 0;
+}
diff --git a/board/data_modul/imx8mp_edm_sbc/imx8mp_data_modul_edm_sbc.c b/board/data_modul/imx8mp_edm_sbc/imx8mp_data_modul_edm_sbc.c
index 9fbbbc1b77e..f0f373aa280 100644
--- a/board/data_modul/imx8mp_edm_sbc/imx8mp_data_modul_edm_sbc.c
+++ b/board/data_modul/imx8mp_edm_sbc/imx8mp_data_modul_edm_sbc.c
@@ -5,11 +5,13 @@ 
 
 #include <common.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/imx8mp_pins.h>
 #include <asm/io.h>
 #include <dm.h>
 #include <dm/device-internal.h>
 #include <env.h>
 #include <env_internal.h>
+#include <linux/bitfield.h>
 #include <malloc.h>
 #include <net.h>
 #include <spl.h>
@@ -65,3 +67,51 @@  int board_late_init(void)
 
 	return 0;
 }
+
+int fdtdec_board_setup(const void *fdt_blob)
+{
+	const void __iomem *mux = (void __iomem *)IOMUXC_BASE_ADDR +
+		FIELD_GET(MUX_CTRL_OFS_MASK, MX8MP_PAD_ENET_MDC__ENET_QOS_MDC);
+	const char *phy_compat = "ethernet-phy-ieee802.3-c22";
+	bool is_bcmphy;
+	int phy_node;
+	int ret;
+
+	/* Do nothing if not i.MX8MP eDM SBC */
+	ret = fdt_node_check_compatible(fdt_blob, 0, "dmo,imx8mp-data-modul-edm-sbc");
+	if (ret)
+		return 0;
+
+	/*
+	 * If GPIO1_16 RGMII_MDC is HIGH, then R390 is populated.
+	 * R390 is populated only on boards with AR8031 PHY.
+	 *
+	 * If GPIO1_16 RGMII_MDC is LOW, then the in-SoM pull down
+	 * is the dominant pull resistor. This is the case on boards
+	 * with BCM54213PE PHY.
+	 */
+	setbits_le32(mux, IOMUX_CONFIG_SION);
+	is_bcmphy = !(readl(GPIO1_BASE_ADDR) & BIT(16));
+	clrbits_le32(mux, IOMUX_CONFIG_SION);
+
+	phy_node = fdt_node_offset_by_compatible(fdt_blob, -1, phy_compat);
+	if (phy_node < 0)
+		return 0;
+
+	/*
+	 * Update PHY MDC address in control DT based on the populated
+	 * PHY type. AR8031 is at address 0, BCM54213PE is at address 1.
+	 */
+	fdt_setprop_inplace_u32((void *)fdt_blob, phy_node,
+				"reg", is_bcmphy ? 1 : 0);
+
+	/* Apply the same modification to EQoS PHY */
+	phy_node = fdt_node_offset_by_compatible(fdt_blob, phy_node, phy_compat);
+	if (phy_node < 0)
+		return 0;
+
+	fdt_setprop_inplace_u32((void *)fdt_blob, phy_node,
+				"reg", is_bcmphy ? 1 : 0);
+
+	return 0;
+}
diff --git a/configs/imx8mm_data_modul_edm_sbc_defconfig b/configs/imx8mm_data_modul_edm_sbc_defconfig
index 6a4244e3084..3f3a79e55af 100644
--- a/configs/imx8mm_data_modul_edm_sbc_defconfig
+++ b/configs/imx8mm_data_modul_edm_sbc_defconfig
@@ -197,6 +197,7 @@  CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHYLIB=y
 CONFIG_PHY_ATHEROS=y
+CONFIG_PHY_BROADCOM=y
 CONFIG_DM_MDIO=y
 CONFIG_DM_ETH_PHY=y
 CONFIG_FEC_MXC=y
diff --git a/configs/imx8mp_data_modul_edm_sbc_defconfig b/configs/imx8mp_data_modul_edm_sbc_defconfig
index f5914ac2a80..c4e39ff9cb8 100644
--- a/configs/imx8mp_data_modul_edm_sbc_defconfig
+++ b/configs/imx8mp_data_modul_edm_sbc_defconfig
@@ -209,6 +209,7 @@  CONFIG_SPI_FLASH_SFDP_SUPPORT=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_ATHEROS=y
+CONFIG_PHY_BROADCOM=y
 CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
 CONFIG_DM_MDIO=y