realtek: Allow PHY-IDs to differ from Port numbers
authorBirger Koblitz <git@birger-koblitz.de>
Sun, 16 Jan 2022 06:03:11 +0000 (07:03 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Thu, 17 Feb 2022 15:21:47 +0000 (15:21 +0000)
We were using the PHY-ids (the reg entries in the PHY
sections of the .dts) as the port numbers. Now scan the
ports section in the .dts, and use the actual port numbers,
following the phy-handle to the PHY properties.

Signed-off-by: Birger Koblitz <git@birger-koblitz.de>
target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/common.c

index 6d2996f0afc17eb776d6ab484717ab205f95edaf..5a90e53da276f02e4fa3f53529aa61e12143e06e 100644 (file)
@@ -257,7 +257,7 @@ int write_phy(u32 port, u32 page, u32 reg, u32 val)
 static int __init rtl83xx_mdio_probe(struct rtl838x_switch_priv *priv)
 {
        struct device *dev = priv->dev;
-       struct device_node *dn, *mii_np = dev->of_node;
+       struct device_node *dn, *phy_node, *mii_np = dev->of_node;
        struct mii_bus *bus;
        int ret;
        u32 pn;
@@ -303,29 +303,54 @@ static int __init rtl83xx_mdio_probe(struct rtl838x_switch_priv *priv)
                return ret;
        }
 
-       dn = mii_np;
-       for_each_node_by_name(dn, "ethernet-phy") {
+       dn = of_find_compatible_node(NULL, NULL, "realtek,rtl83xx-switch");
+       if (!dn) {
+               dev_err(priv->dev, "No RTL switch node in DTS\n");
+               return -ENODEV;
+       }
+
+       for_each_node_by_name(dn, "port") {
                if (of_property_read_u32(dn, "reg", &pn))
                        continue;
 
+               pr_info("%s found port %d\n", __func__, pn);
+               phy_node = of_parse_phandle(dn, "phy-handle", 0);
+               if (!phy_node) {
+                       if (pn != priv->cpu_port)
+                               dev_err(priv->dev, "Port node %d misses phy-handle\n", pn);
+                       continue;
+               }
+
                // Check for the integrated SerDes of the RTL8380M first
-               if (of_property_read_bool(dn, "phy-is-integrated") && priv->id == 0x8380 && pn >= 24) {
+               if (of_property_read_bool(phy_node, "phy-is-integrated")
+                   && priv->id == 0x8380 && pn >= 24) {
                        pr_debug("----> FĂ“UND A SERDES\n");
                        priv->ports[pn].phy = PHY_RTL838X_SDS;
                        continue;
                }
 
-               if (of_property_read_bool(dn, "phy-is-integrated") && !of_property_read_bool(dn, "sfp")) {
-                       priv->ports[pn].phy = PHY_RTL8218B_INT;
-                       continue;
+               if (priv->id >= 0x9300) {
+                       priv->ports[pn].phy_is_integrated = false;
+                       if (of_property_read_bool(phy_node, "phy-is-integrated")) {
+                               priv->ports[pn].phy_is_integrated = true;
+                               priv->ports[pn].phy = PHY_RTL930X_SDS;
+                       }
+               } else {
+                       if (of_property_read_bool(phy_node, "phy-is-integrated")
+                               && !of_property_read_bool(phy_node, "sfp")) {
+                               priv->ports[pn].phy = PHY_RTL8218B_INT;
+                               continue;
+                       }
                }
 
-               if (!of_property_read_bool(dn, "phy-is-integrated") && of_property_read_bool(dn, "sfp")) {
+               if (!of_property_read_bool(phy_node, "phy-is-integrated")
+                   && of_property_read_bool(phy_node, "sfp")) {
                        priv->ports[pn].phy = PHY_RTL8214FC;
                        continue;
                }
 
-               if (!of_property_read_bool(dn, "phy-is-integrated") && !of_property_read_bool(dn, "sfp")) {
+               if (!of_property_read_bool(phy_node, "phy-is-integrated")
+                   && !of_property_read_bool(phy_node, "sfp")) {
                        priv->ports[pn].phy = PHY_RTL8218B_EXT;
                        continue;
                }