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