706-net-phy-at803x-fix-probe-error-if-copper-page-is-sel.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 8f7e876273e294b732b42af2e5e6bba91d798954 Mon Sep 17 00:00:00 2001
  2. From: Michael Walle <[email protected]>
  3. Date: Tue, 20 Apr 2021 12:29:29 +0200
  4. Subject: [PATCH] net: phy: at803x: fix probe error if copper page is selected
  5. The commit c329e5afb42f ("net: phy: at803x: select correct page on
  6. config init") selects the copper page during probe. This fails if the
  7. copper page was already selected. In this case, the value of the copper
  8. page (which is 1) is propagated through phy_restore_page() and is
  9. finally returned for at803x_probe(). Fix it, by just using the
  10. at803x_page_write() directly.
  11. Also in case of an error, the regulator is not disabled and leads to a
  12. WARN_ON() when the probe fails. This couldn't happen before, because
  13. at803x_parse_dt() was the last call in at803x_probe(). It is hard to
  14. see, that the parse_dt() actually enables the regulator. Thus move the
  15. regulator_enable() to the probe function and undo it in case of an
  16. error.
  17. Fixes: c329e5afb42f ("net: phy: at803x: select correct page on config init")
  18. Signed-off-by: Michael Walle <[email protected]>
  19. Reviewed-by: David Bauer <[email protected]>
  20. Signed-off-by: David S. Miller <[email protected]>
  21. ---
  22. drivers/net/phy/at803x.c | 23 +++++++++++++++++------
  23. 1 file changed, 17 insertions(+), 6 deletions(-)
  24. --- a/drivers/net/phy/at803x.c
  25. +++ b/drivers/net/phy/at803x.c
  26. @@ -527,10 +527,6 @@ static int at803x_parse_dt(struct phy_de
  27. phydev_err(phydev, "failed to get VDDIO regulator\n");
  28. return PTR_ERR(priv->vddio);
  29. }
  30. -
  31. - ret = regulator_enable(priv->vddio);
  32. - if (ret < 0)
  33. - return ret;
  34. }
  35. return 0;
  36. @@ -552,15 +548,30 @@ static int at803x_probe(struct phy_devic
  37. if (ret)
  38. return ret;
  39. + if (priv->vddio) {
  40. + ret = regulator_enable(priv->vddio);
  41. + if (ret < 0)
  42. + return ret;
  43. + }
  44. +
  45. /* Some bootloaders leave the fiber page selected.
  46. * Switch to the copper page, as otherwise we read
  47. * the PHY capabilities from the fiber side.
  48. */
  49. if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
  50. - ret = phy_select_page(phydev, AT803X_PAGE_COPPER);
  51. - ret = phy_restore_page(phydev, AT803X_PAGE_COPPER, ret);
  52. + phy_lock_mdio_bus(phydev);
  53. + ret = at803x_write_page(phydev, AT803X_PAGE_COPPER);
  54. + phy_unlock_mdio_bus(phydev);
  55. + if (ret)
  56. + goto err;
  57. }
  58. + return 0;
  59. +
  60. +err:
  61. + if (priv->vddio)
  62. + regulator_disable(priv->vddio);
  63. +
  64. return ret;
  65. }