ath79: ag71xx: fix error handling for of_get_phy_mode
[openwrt/openwrt.git] / target / linux / ath79 / files / drivers / net / ethernet / atheros / ag71xx / ag71xx_main.c
index 2767ad76421244c3eb7afa48b824325a68ff249c..463083628fbeeefe05d45bd0cf2c29ff21021212 100644 (file)
@@ -602,6 +602,11 @@ static void ag71xx_sgmii_serdes_init_qca956x(struct device_node *np)
                goto err_iomap;
        }
 
+       t = __raw_readl(gmac_base + QCA956X_GMAC_REG_SGMII_CONFIG);
+       t &= ~(QCA956X_SGMII_CONFIG_MODE_CTRL_MASK << QCA956X_SGMII_CONFIG_MODE_CTRL_SHIFT);
+       t |= QCA956X_SGMII_CONFIG_MODE_CTRL_SGMII_MAC;
+       __raw_writel(t, gmac_base + QCA956X_GMAC_REG_SGMII_CONFIG);
+
        pr_debug("%pOF: fixup SERDES calibration to value %i\n",
                np_dev, serdes_cal);
        t = __raw_readl(gmac_base + QCA956X_GMAC_REG_SGMII_SERDES);
@@ -936,11 +941,7 @@ __ag71xx_link_adjust(struct ag71xx *ag, bool update)
                 * The wr, rr functions cannot be used since this hidden register
                 * is outside of the normal ag71xx register block.
                 */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
                void __iomem *dam = ioremap(0xb90001bc, 0x4);
-#else
-               void __iomem *dam = ioremap_nocache(0xb90001bc, 0x4);
-#endif
                if (dam) {
                        __raw_writel(__raw_readl(dam) & ~BIT(27), dam);
                        (void)__raw_readl(dam);
@@ -1587,25 +1588,15 @@ static int ag71xx_probe(struct platform_device *pdev)
                ag->pllregmap = NULL;
        }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
        ag->mac_base = devm_ioremap(&pdev->dev, res->start,
                                    res->end - res->start + 1);
-#else
-       ag->mac_base = devm_ioremap_nocache(&pdev->dev, res->start,
-                                           res->end - res->start + 1);
-#endif
        if (!ag->mac_base)
                return -ENOMEM;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
        if (res) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
                ag->mii_base = devm_ioremap(&pdev->dev, res->start,
                                            res->end - res->start + 1);
-#else
-               ag->mii_base = devm_ioremap_nocache(&pdev->dev, res->start,
-                                                   res->end - res->start + 1);
-#endif
                if (!ag->mii_base)
                        return -ENOMEM;
        }
@@ -1686,12 +1677,12 @@ static int ag71xx_probe(struct platform_device *pdev)
        }
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0)
-       of_get_phy_mode(np, &ag->phy_if_mode);
+       err = of_get_phy_mode(np, &ag->phy_if_mode);
+       if (err < 0) {
 #else
        ag->phy_if_mode = of_get_phy_mode(np);
-#endif
-
        if (ag->phy_if_mode < 0) {
+#endif
                dev_err(&pdev->dev, "missing phy-mode property in DT\n");
                return ag->phy_if_mode;
        }