generic: 5.10: replace ramips AR8033 fiber patch with 5.18 patches
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 705-net-phy-at803x-select-correct-page-on-config-init.patch
1 From c329e5afb42ff0a88285eb4d8a391a18793e4777 Mon Sep 17 00:00:00 2001
2 From: David Bauer <mail@david-bauer.net>
3 Date: Thu, 15 Apr 2021 03:26:50 +0200
4 Subject: [PATCH] net: phy: at803x: select correct page on config init
5
6 The Atheros AR8031 and AR8033 expose different registers for SGMII/Fiber
7 as well as the copper side of the PHY depending on the BT_BX_REG_SEL bit
8 in the chip configure register.
9
10 The driver assumes the copper side is selected on probe, but this might
11 not be the case depending which page was last selected by the
12 bootloader. Notably, Ubiquiti UniFi bootloaders show this behavior.
13
14 Select the copper page when probing to circumvent this.
15
16 Signed-off-by: David Bauer <mail@david-bauer.net>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
18 ---
19 drivers/net/phy/at803x.c | 50 +++++++++++++++++++++++++++++++++++++++-
20 1 file changed, 49 insertions(+), 1 deletion(-)
21
22 --- a/drivers/net/phy/at803x.c
23 +++ b/drivers/net/phy/at803x.c
24 @@ -139,6 +139,9 @@
25 #define ATH8035_PHY_ID 0x004dd072
26 #define AT8030_PHY_ID_MASK 0xffffffef
27
28 +#define AT803X_PAGE_FIBER 0
29 +#define AT803X_PAGE_COPPER 1
30 +
31 MODULE_DESCRIPTION("Qualcomm Atheros AR803x PHY driver");
32 MODULE_AUTHOR("Matus Ujhelyi");
33 MODULE_LICENSE("GPL");
34 @@ -190,6 +193,35 @@ static int at803x_debug_reg_mask(struct
35 return phy_write(phydev, AT803X_DEBUG_DATA, val);
36 }
37
38 +static int at803x_write_page(struct phy_device *phydev, int page)
39 +{
40 + int mask;
41 + int set;
42 +
43 + if (page == AT803X_PAGE_COPPER) {
44 + set = AT803X_BT_BX_REG_SEL;
45 + mask = 0;
46 + } else {
47 + set = 0;
48 + mask = AT803X_BT_BX_REG_SEL;
49 + }
50 +
51 + return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
52 +}
53 +
54 +static int at803x_read_page(struct phy_device *phydev)
55 +{
56 + int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
57 +
58 + if (ccr < 0)
59 + return ccr;
60 +
61 + if (ccr & AT803X_BT_BX_REG_SEL)
62 + return AT803X_PAGE_COPPER;
63 +
64 + return AT803X_PAGE_FIBER;
65 +}
66 +
67 static int at803x_enable_rx_delay(struct phy_device *phydev)
68 {
69 return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0,
70 @@ -508,6 +540,7 @@ static int at803x_probe(struct phy_devic
71 {
72 struct device *dev = &phydev->mdio.dev;
73 struct at803x_priv *priv;
74 + int ret;
75
76 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
77 if (!priv)
78 @@ -515,7 +548,20 @@ static int at803x_probe(struct phy_devic
79
80 phydev->priv = priv;
81
82 - return at803x_parse_dt(phydev);
83 + ret = at803x_parse_dt(phydev);
84 + if (ret)
85 + return ret;
86 +
87 + /* Some bootloaders leave the fiber page selected.
88 + * Switch to the copper page, as otherwise we read
89 + * the PHY capabilities from the fiber side.
90 + */
91 + if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
92 + ret = phy_select_page(phydev, AT803X_PAGE_COPPER);
93 + ret = phy_restore_page(phydev, AT803X_PAGE_COPPER, ret);
94 + }
95 +
96 + return ret;
97 }
98
99 static void at803x_remove(struct phy_device *phydev)
100 @@ -1097,6 +1143,8 @@ static struct phy_driver at803x_driver[]
101 .get_wol = at803x_get_wol,
102 .suspend = at803x_suspend,
103 .resume = at803x_resume,
104 + .read_page = at803x_read_page,
105 + .write_page = at803x_write_page,
106 /* PHY_GBIT_FEATURES */
107 .read_status = at803x_read_status,
108 .aneg_done = at803x_aneg_done,