1 From af26b0d1bf934bbaa7cafb871a51e95087a088a0 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com>
3 Date: Mon, 22 Jan 2024 08:34:31 +0300
4 Subject: [PATCH 04/30] net: dsa: mt7530: support OF-based registration of
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Currently the MDIO bus of the switches the MT7530 DSA subdriver controls
11 can only be registered as non-OF-based. Bring support for registering the
14 The subdrivers that control switches [with MDIO bus] probed on OF must
15 follow this logic to support all cases properly:
17 No switch MDIO bus defined: Populate ds->user_mii_bus, register the MDIO
18 bus, set the interrupts for PHYs if "interrupt-controller" is defined at
19 the switch node. This case should only be covered for the switches which
20 their dt-bindings documentation didn't document the MDIO bus from the
21 start. This is to keep supporting the device trees that do not describe the
22 MDIO bus on the device tree but the MDIO bus is being used nonetheless.
24 Switch MDIO bus defined: Don't populate ds->user_mii_bus, register the MDIO
25 bus, set the interrupts for PHYs if ["interrupt-controller" is defined at
26 the switch node and "interrupts" is defined at the PHY nodes under the
27 switch MDIO bus node].
29 Switch MDIO bus defined but explicitly disabled: If the device tree says
30 status = "disabled" for the MDIO bus, we shouldn't need an MDIO bus at all.
31 Instead, just exit as early as possible and do not call any MDIO API.
33 The use of ds->user_mii_bus is inappropriate when the MDIO bus of the
34 switch is described on the device tree [1], which is why we don't populate
35 ds->user_mii_bus in that case.
37 Link: https://lore.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/ [1]
38 Suggested-by: David Bauer <mail@david-bauer.net>
39 Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
40 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
41 Link: https://lore.kernel.org/r/20240122053431.7751-1-arinc.unal@arinc9.com
42 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
44 drivers/net/dsa/mt7530.c | 34 ++++++++++++++++++++++++++--------
45 1 file changed, 26 insertions(+), 8 deletions(-)
47 --- a/drivers/net/dsa/mt7530.c
48 +++ b/drivers/net/dsa/mt7530.c
49 @@ -2343,24 +2343,40 @@ mt7530_free_irq_common(struct mt7530_pri
51 mt7530_free_irq(struct mt7530_priv *priv)
53 - mt7530_free_mdio_irq(priv);
54 + struct device_node *mnp, *np = priv->dev->of_node;
56 + mnp = of_get_child_by_name(np, "mdio");
58 + mt7530_free_mdio_irq(priv);
61 mt7530_free_irq_common(priv);
65 mt7530_setup_mdio(struct mt7530_priv *priv)
67 + struct device_node *mnp, *np = priv->dev->of_node;
68 struct dsa_switch *ds = priv->ds;
69 struct device *dev = priv->dev;
75 + mnp = of_get_child_by_name(np, "mdio");
77 + if (mnp && !of_device_is_available(mnp))
80 bus = devm_mdiobus_alloc(dev);
89 + ds->slave_mii_bus = bus;
91 - ds->slave_mii_bus = bus;
93 bus->name = KBUILD_MODNAME "-mii";
94 snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++);
95 @@ -2371,16 +2387,18 @@ mt7530_setup_mdio(struct mt7530_priv *pr
97 bus->phy_mask = ~ds->phys_mii_mask;
100 + if (priv->irq && !mnp)
101 mt7530_setup_mdio_irq(priv);
103 - ret = devm_mdiobus_register(dev, bus);
104 + ret = devm_of_mdiobus_register(dev, bus, mnp);
106 dev_err(dev, "failed to register MDIO bus: %d\n", ret);
108 + if (priv->irq && !mnp)
109 mt7530_free_mdio_irq(priv);