From: Marek Vasut Date: Mon, 1 Jan 2024 21:05:54 +0000 (+0100) Subject: ARM: imx: Auto-detect PHY on Data Modul i.MX8M Mini/Plus eDM SBC X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=32a41b7c378315088ebc7392c91121261b84bad9;p=u-boot.git ARM: imx: Auto-detect PHY on Data Modul i.MX8M Mini/Plus eDM SBC 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 Reviewed-by: Fabio Estevam --- 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 a2b5976b6b..cb6ea356fd 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 ff89333b73..bfb2bddc1d 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 #include +#include #include #include #include +#include #include #include @@ -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 9fbbbc1b77..f0f373aa28 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 #include +#include #include #include #include #include #include +#include #include #include #include @@ -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 b16800dfc8..7e9c48e224 100644 --- a/configs/imx8mm_data_modul_edm_sbc_defconfig +++ b/configs/imx8mm_data_modul_edm_sbc_defconfig @@ -195,6 +195,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 b6a3730c78..ba4730a495 100644 --- a/configs/imx8mp_data_modul_edm_sbc_defconfig +++ b/configs/imx8mp_data_modul_edm_sbc_defconfig @@ -207,6 +207,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