790-04-v6.9-net-dsa-mt7530-support-OF-based-registration-of-swit.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. From af26b0d1bf934bbaa7cafb871a51e95087a088a0 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <[email protected]>
  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. Currently the MDIO bus of the switches the MT7530 DSA subdriver controls
  10. can only be registered as non-OF-based. Bring support for registering the
  11. bus OF-based.
  12. The subdrivers that control switches [with MDIO bus] probed on OF must
  13. follow this logic to support all cases properly:
  14. No switch MDIO bus defined: Populate ds->user_mii_bus, register the MDIO
  15. bus, set the interrupts for PHYs if "interrupt-controller" is defined at
  16. the switch node. This case should only be covered for the switches which
  17. their dt-bindings documentation didn't document the MDIO bus from the
  18. start. This is to keep supporting the device trees that do not describe the
  19. MDIO bus on the device tree but the MDIO bus is being used nonetheless.
  20. Switch MDIO bus defined: Don't populate ds->user_mii_bus, register the MDIO
  21. bus, set the interrupts for PHYs if ["interrupt-controller" is defined at
  22. the switch node and "interrupts" is defined at the PHY nodes under the
  23. switch MDIO bus node].
  24. Switch MDIO bus defined but explicitly disabled: If the device tree says
  25. status = "disabled" for the MDIO bus, we shouldn't need an MDIO bus at all.
  26. Instead, just exit as early as possible and do not call any MDIO API.
  27. The use of ds->user_mii_bus is inappropriate when the MDIO bus of the
  28. switch is described on the device tree [1], which is why we don't populate
  29. ds->user_mii_bus in that case.
  30. Link: https://lore.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/ [1]
  31. Suggested-by: David Bauer <[email protected]>
  32. Signed-off-by: Arınç ÜNAL <[email protected]>
  33. Reviewed-by: Vladimir Oltean <[email protected]>
  34. Link: https://lore.kernel.org/r/[email protected]
  35. Signed-off-by: Paolo Abeni <[email protected]>
  36. ---
  37. drivers/net/dsa/mt7530.c | 34 ++++++++++++++++++++++++++--------
  38. 1 file changed, 26 insertions(+), 8 deletions(-)
  39. --- a/drivers/net/dsa/mt7530.c
  40. +++ b/drivers/net/dsa/mt7530.c
  41. @@ -2345,24 +2345,40 @@ mt7530_free_irq_common(struct mt7530_pri
  42. static void
  43. mt7530_free_irq(struct mt7530_priv *priv)
  44. {
  45. - mt7530_free_mdio_irq(priv);
  46. + struct device_node *mnp, *np = priv->dev->of_node;
  47. +
  48. + mnp = of_get_child_by_name(np, "mdio");
  49. + if (!mnp)
  50. + mt7530_free_mdio_irq(priv);
  51. + of_node_put(mnp);
  52. +
  53. mt7530_free_irq_common(priv);
  54. }
  55. static int
  56. mt7530_setup_mdio(struct mt7530_priv *priv)
  57. {
  58. + struct device_node *mnp, *np = priv->dev->of_node;
  59. struct dsa_switch *ds = priv->ds;
  60. struct device *dev = priv->dev;
  61. struct mii_bus *bus;
  62. static int idx;
  63. - int ret;
  64. + int ret = 0;
  65. +
  66. + mnp = of_get_child_by_name(np, "mdio");
  67. +
  68. + if (mnp && !of_device_is_available(mnp))
  69. + goto out;
  70. bus = devm_mdiobus_alloc(dev);
  71. - if (!bus)
  72. - return -ENOMEM;
  73. + if (!bus) {
  74. + ret = -ENOMEM;
  75. + goto out;
  76. + }
  77. +
  78. + if (!mnp)
  79. + ds->slave_mii_bus = bus;
  80. - ds->slave_mii_bus = bus;
  81. bus->priv = priv;
  82. bus->name = KBUILD_MODNAME "-mii";
  83. snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++);
  84. @@ -2373,16 +2389,18 @@ mt7530_setup_mdio(struct mt7530_priv *pr
  85. bus->parent = dev;
  86. bus->phy_mask = ~ds->phys_mii_mask;
  87. - if (priv->irq)
  88. + if (priv->irq && !mnp)
  89. mt7530_setup_mdio_irq(priv);
  90. - ret = devm_mdiobus_register(dev, bus);
  91. + ret = devm_of_mdiobus_register(dev, bus, mnp);
  92. if (ret) {
  93. dev_err(dev, "failed to register MDIO bus: %d\n", ret);
  94. - if (priv->irq)
  95. + if (priv->irq && !mnp)
  96. mt7530_free_mdio_irq(priv);
  97. }
  98. +out:
  99. + of_node_put(mnp);
  100. return ret;
  101. }