[PATCH net-next 1/2] net: phy: at803x: add pages support to AR8031/33

From: Michael Walle
Date: Sat Feb 13 2021 - 20:07:50 EST


The AR8031 has two register sets: Copper and Fiber. The fiber page is
used in case of 100Base-FX and 1000Base-X. But more importantly it is
also used for the SGMII link. Add support to switch between these two.

Signed-off-by: Michael Walle <michael@xxxxxxxx>
---
drivers/net/phy/at803x.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index d67bddc111e3..a3aa10f14638 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -144,6 +144,9 @@
#define ATH8035_PHY_ID 0x004dd072
#define AT8030_PHY_ID_MASK 0xffffffef

+#define AT803X_FIBER_PAGE 0
+#define AT803X_COPPER_PAGE 1
+
MODULE_DESCRIPTION("Qualcomm Atheros AR803x PHY driver");
MODULE_AUTHOR("Matus Ujhelyi");
MODULE_LICENSE("GPL");
@@ -1143,6 +1146,36 @@ static int at803x_cable_test_start(struct phy_device *phydev)
return 0;
}

+static int at803x_read_page(struct phy_device *phydev)
+{
+ int val;
+
+ val = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
+ if (val < 0)
+ return val;
+
+ return (val & AT803X_BT_BX_REG_SEL) ? AT803X_COPPER_PAGE : AT803X_FIBER_PAGE;
+}
+
+static int at803x_write_page(struct phy_device *phydev, int page)
+{
+ u16 sel;
+
+ switch (page) {
+ case AT803X_FIBER_PAGE:
+ sel = 0;
+ break;
+ case AT803X_COPPER_PAGE:
+ sel = AT803X_BT_BX_REG_SEL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG,
+ AT803X_BT_BX_REG_SEL, sel);
+}
+
static struct phy_driver at803x_driver[] = {
{
/* Qualcomm Atheros AR8035 */
@@ -1189,6 +1222,8 @@ static struct phy_driver at803x_driver[] = {
.flags = PHY_POLL_CABLE_TEST,
.probe = at803x_probe,
.remove = at803x_remove,
+ .read_page = at803x_read_page,
+ .write_page = at803x_write_page,
.config_init = at803x_config_init,
.soft_reset = genphy_soft_reset,
.set_wol = at803x_set_wol,
--
2.20.1