From: Luo Jie <quic_luoj@quicinc.com>
To: <andrew@lunn.ch>, <davem@davemloft.net>, <edumazet@google.com>,
<kuba@kernel.org>, <pabeni@redhat.com>, <robh+dt@kernel.org>,
<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
<hkallweit1@gmail.com>, <linux@armlinux.org.uk>, <corbet@lwn.net>,
<p.zabel@pengutronix.de>, <f.fainelli@gmail.com>
Cc: <netdev@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>
Subject: [PATCH v8 08/14] net: phy: at803x: add qca8084 switch registe access
Date: Fri, 15 Dec 2023 15:39:58 +0800 [thread overview]
Message-ID: <20231215074005.26976-9-quic_luoj@quicinc.com> (raw)
In-Reply-To: <20231215074005.26976-1-quic_luoj@quicinc.com>
For qca8084 chip, there are GCC, TLMM and security control
modules besides the PHY, these moudles are accessed with 32
bits value, which has the special MDIO sequences to read or
write this 32bit register.
There are initial configurations configured to make qca8084 PHY
probeable, and the MDIO address of qca8084 can be programmed for
the PHY device and PCS device.
Signed-off-by: Luo Jie <quic_luoj@quicinc.com>
---
drivers/net/phy/at803x.c | 85 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index cd1bdb61d122..4982bde5a8a5 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -296,6 +296,13 @@
#define QCA8084_MMD7_IPG_OP 0x901d
#define QCA8084_IPG_10_TO_11_EN BIT(0)
+/* QCA8084 includes secure control module, which supports customizing the
+ * MDIO address of PHY device and PCS device, the register of secure control
+ * is accessed by MDIO bus with the special MDIO sequences.
+ */
+#define QCA8084_HIGH_ADDR_PREFIX 0x18
+#define QCA8084_LOW_ADDR_PREFIX 0x10
+
MODULE_DESCRIPTION("Qualcomm Atheros AR803x and QCA808X PHY driver");
MODULE_AUTHOR("Matus Ujhelyi");
MODULE_LICENSE("GPL");
@@ -408,6 +415,84 @@ static int at803x_read_page(struct phy_device *phydev)
return AT803X_PAGE_FIBER;
}
+static void qca8084_split_addr(u32 regaddr, u16 *r1, u16 *r2,
+ u16 *page, u16 *sw_addr)
+{
+ *r1 = regaddr & 0x1c;
+
+ regaddr >>= 5;
+ *r2 = regaddr & 0x7;
+
+ regaddr >>= 3;
+ *page = regaddr & 0xffff;
+
+ regaddr >>= 16;
+ *sw_addr = regaddr & 0xff;
+}
+
+static int __qca8084_set_page(struct mii_bus *bus, u16 sw_addr, u16 page)
+{
+ return __mdiobus_write(bus, QCA8084_HIGH_ADDR_PREFIX | (sw_addr >> 5),
+ sw_addr & 0x1f, page);
+}
+
+static int __qca8084_mii_read(struct mii_bus *bus, u16 addr, u16 reg, u32 *val)
+{
+ int ret, data;
+
+ ret = __mdiobus_read(bus, addr, reg);
+ if (ret >= 0) {
+ data = ret;
+
+ ret = __mdiobus_read(bus, addr, reg | BIT(1));
+ if (ret >= 0)
+ *val = data | ret << 16;
+ }
+
+ return ret < 0 ? ret : 0;
+}
+
+static int __qca8084_mii_write(struct mii_bus *bus, u16 addr, u16 reg, u32 val)
+{
+ int ret;
+
+ ret = __mdiobus_write(bus, addr, reg, lower_16_bits(val));
+ if (!ret)
+ ret = __mdiobus_write(bus, addr, reg | BIT(1), upper_16_bits(val));
+
+ return ret;
+}
+
+static int qca8084_mii_modify(struct phy_device *phydev, u32 regaddr,
+ u32 clear, u32 set)
+{
+ struct mii_bus *bus;
+ u16 reg, addr, page, sw_addr;
+ u32 val;
+ int ret;
+
+ bus = phydev->mdio.bus;
+ mutex_lock(&bus->mdio_lock);
+
+ qca8084_split_addr(regaddr, ®, &addr, &page, &sw_addr);
+ ret = __qca8084_set_page(bus, sw_addr, page);
+ if (ret < 0)
+ goto qca8084_mii_modify_exit;
+
+ ret = __qca8084_mii_read(bus, QCA8084_LOW_ADDR_PREFIX | addr,
+ reg, &val);
+ if (ret < 0)
+ goto qca8084_mii_modify_exit;
+
+ val &= ~clear;
+ val |= set;
+ ret = __qca8084_mii_write(bus, QCA8084_LOW_ADDR_PREFIX | addr,
+ reg, val);
+qca8084_mii_modify_exit:
+ mutex_unlock(&bus->mdio_lock);
+ return ret;
+};
+
static int at803x_enable_rx_delay(struct phy_device *phydev)
{
return at803x_debug_reg_mask(phydev, AT803X_DEBUG_ANALOG_TEST_CTRL, 0,
--
2.42.0
next prev parent reply other threads:[~2023-12-15 7:41 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 7:39 [PATCH v8 00/14] add qca8084 ethernet phy driver Luo Jie
2023-12-15 7:39 ` [PATCH v8 01/14] net: phy: introduce core support for phy-mode = "10g-qxgmii" Luo Jie
2023-12-15 7:39 ` [PATCH v8 02/14] dt-bindings: net: ethernet-controller: add 10g-qxgmii mode Luo Jie
2023-12-15 7:39 ` [PATCH v8 03/14] net: phy: at803x: add QCA8084 ethernet phy support Luo Jie
2023-12-15 7:39 ` [PATCH v8 04/14] net: phy: at803x: add the function phydev_id_is_qca808x Luo Jie
2023-12-15 7:39 ` [PATCH v8 05/14] net: phy: at803x: Add qca8084_config_init function Luo Jie
2023-12-15 7:39 ` [PATCH v8 06/14] net: phy: at803x: add qca8084_link_change_notify Luo Jie
2023-12-15 7:39 ` [PATCH v8 07/14] net: phy: at803x: add the possible_interfaces Luo Jie
2023-12-15 7:39 ` Luo Jie [this message]
2023-12-15 7:39 ` [PATCH v8 09/14] net: phy: at803x: set MDIO address of qca8084 PHY Luo Jie
2023-12-15 7:40 ` [PATCH v8 10/14] net: phy: at803x: parse qca8084 clocks and resets Luo Jie
2023-12-15 7:40 ` [PATCH v8 11/14] net: phy: at803x: add qca808x initial config sequence Luo Jie
2023-12-15 7:40 ` [PATCH v8 12/14] net: phy: at803x: configure qca8084 common clocks Luo Jie
2023-12-15 7:40 ` [PATCH v8 13/14] net: phy: at803x: configure qca8084 work mode Luo Jie
2023-12-17 13:02 ` Simon Horman
2023-12-18 3:33 ` Jie Luo
2023-12-15 7:40 ` [PATCH v8 14/14] dt-bindings: net: ar803x: add qca8084 PHY properties Luo Jie
2023-12-15 8:22 ` Krzysztof Kozlowski
2023-12-15 10:16 ` Jie Luo
2023-12-15 11:25 ` Andrew Lunn
2023-12-15 12:16 ` Jie Luo
2023-12-15 13:42 ` Russell King (Oracle)
2023-12-16 7:57 ` Jie Luo
2023-12-16 17:17 ` Andrew Lunn
2023-12-18 4:53 ` Jie Luo
2023-12-18 9:34 ` Andrew Lunn
2023-12-19 8:52 ` Jie Luo
2023-12-15 12:12 ` Andrew Lunn
2023-12-15 12:33 ` Jie Luo
2023-12-15 13:31 ` Andrew Lunn
2023-12-16 7:37 ` Jie Luo
2023-12-16 10:21 ` Andrew Lunn
2023-12-16 13:25 ` Jie Luo
2023-12-16 13:51 ` Russell King (Oracle)
2023-12-16 14:41 ` Jie Luo
2023-12-16 16:01 ` Christian Marangi
2023-12-18 5:22 ` Jie Luo
2023-12-16 16:09 ` Russell King (Oracle)
2023-12-18 3:01 ` Jie Luo
2024-01-02 9:57 ` Russell King (Oracle)
2024-01-02 10:08 ` Christian Marangi
2024-01-03 13:27 ` Jie Luo
2024-01-03 14:22 ` Andrew Lunn
2024-01-04 9:53 ` Jie Luo
2024-01-04 13:57 ` Andrew Lunn
2024-01-05 10:26 ` Jie Luo
2024-01-05 13:37 ` Andrew Lunn
2024-01-08 8:27 ` Jie Luo
2023-12-16 17:30 ` Andrew Lunn
2023-12-16 19:08 ` Russell King (Oracle)
2023-12-18 3:31 ` Jie Luo
2023-12-18 3:27 ` Jie Luo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231215074005.26976-9-quic_luoj@quicinc.com \
--to=quic_luoj@quicinc.com \
--cc=andrew@lunn.ch \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®