46651e32dfb1c1f340b55bad84a40ffa1820c496
[openwrt/openwrt.git] /
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
5 switch MDIO bus
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
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
12 bus OF-based.
13
14 The subdrivers that control switches [with MDIO bus] probed on OF must
15 follow this logic to support all cases properly:
16
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.
23
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].
28
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.
32
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.
36
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>
43 ---
44 drivers/net/dsa/mt7530.c | 34 ++++++++++++++++++++++++++--------
45 1 file changed, 26 insertions(+), 8 deletions(-)
46
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
50 static void
51 mt7530_free_irq(struct mt7530_priv *priv)
52 {
53 - mt7530_free_mdio_irq(priv);
54 + struct device_node *mnp, *np = priv->dev->of_node;
55 +
56 + mnp = of_get_child_by_name(np, "mdio");
57 + if (!mnp)
58 + mt7530_free_mdio_irq(priv);
59 + of_node_put(mnp);
60 +
61 mt7530_free_irq_common(priv);
62 }
63
64 static int
65 mt7530_setup_mdio(struct mt7530_priv *priv)
66 {
67 + struct device_node *mnp, *np = priv->dev->of_node;
68 struct dsa_switch *ds = priv->ds;
69 struct device *dev = priv->dev;
70 struct mii_bus *bus;
71 static int idx;
72 - int ret;
73 + int ret = 0;
74 +
75 + mnp = of_get_child_by_name(np, "mdio");
76 +
77 + if (mnp && !of_device_is_available(mnp))
78 + goto out;
79
80 bus = devm_mdiobus_alloc(dev);
81 - if (!bus)
82 - return -ENOMEM;
83 + if (!bus) {
84 + ret = -ENOMEM;
85 + goto out;
86 + }
87 +
88 + if (!mnp)
89 + ds->slave_mii_bus = bus;
90
91 - ds->slave_mii_bus = bus;
92 bus->priv = priv;
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
96 bus->parent = dev;
97 bus->phy_mask = ~ds->phys_mii_mask;
98
99 - if (priv->irq)
100 + if (priv->irq && !mnp)
101 mt7530_setup_mdio_irq(priv);
102
103 - ret = devm_mdiobus_register(dev, bus);
104 + ret = devm_of_mdiobus_register(dev, bus, mnp);
105 if (ret) {
106 dev_err(dev, "failed to register MDIO bus: %d\n", ret);
107 - if (priv->irq)
108 + if (priv->irq && !mnp)
109 mt7530_free_mdio_irq(priv);
110 }
111
112 +out:
113 + of_node_put(mnp);
114 return ret;
115 }
116