]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: stmmac: dwmac-sophgo: Add phy interface filter
authorInochi Amaoto <inochiama@gmail.com>
Fri, 14 Nov 2025 00:38:05 +0000 (08:38 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Dec 2025 13:03:04 +0000 (14:03 +0100)
[ Upstream commit db37c6e510deabc9b0ee27c08f1c5aaa19f2e8ef ]

As the SG2042 has an internal rx delay, the delay should be removed
when initializing the mac, otherwise the phy will be misconfigurated.

Fixes: 543009e2d4cd ("net: stmmac: dwmac-sophgo: Add support for Sophgo SG2042 SoC")
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
Tested-by: Han Gao <rabenda.cn@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20251114003805.494387-4-inochiama@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c

index 3b7947a7a7ba70fdee93b162158585e1512ea5ab..fcdda2401968b519e28e200c46084a8eadf92a03 100644 (file)
@@ -7,11 +7,16 @@
 
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 
 #include "stmmac_platform.h"
 
+struct sophgo_dwmac_data {
+       bool has_internal_rx_delay;
+};
+
 static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
                                    struct plat_stmmacenet_data *plat_dat,
                                    struct stmmac_resources *stmmac_res)
@@ -32,6 +37,7 @@ static int sophgo_sg2044_dwmac_init(struct platform_device *pdev,
 static int sophgo_dwmac_probe(struct platform_device *pdev)
 {
        struct plat_stmmacenet_data *plat_dat;
+       const struct sophgo_dwmac_data *data;
        struct stmmac_resources stmmac_res;
        struct device *dev = &pdev->dev;
        int ret;
@@ -50,11 +56,23 @@ static int sophgo_dwmac_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
+       data = device_get_match_data(&pdev->dev);
+       if (data && data->has_internal_rx_delay) {
+               plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface,
+                                                                         false, true);
+               if (plat_dat->phy_interface == PHY_INTERFACE_MODE_NA)
+                       return -EINVAL;
+       }
+
        return stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
 }
 
+static const struct sophgo_dwmac_data sg2042_dwmac_data = {
+       .has_internal_rx_delay = true,
+};
+
 static const struct of_device_id sophgo_dwmac_match[] = {
-       { .compatible = "sophgo,sg2042-dwmac" },
+       { .compatible = "sophgo,sg2042-dwmac", .data = &sg2042_dwmac_data },
        { .compatible = "sophgo,sg2044-dwmac" },
        { /* sentinel */ }
 };