[RFC PATCH net-next 09/12] net: dsa: mt7530: move enabling port 6 to mt7530_setup_port6()
From: arinc9 . unal
Date: Wed Apr 05 2023 - 16:40:31 EST
From: Arınç ÜNAL <arinc.unal@xxxxxxxxxx>
Enable port 6 only when port 6 is being used. Read the HWTRAP_XTAL_MASK
value from val now that val is equal to the value of MT7530_MHWTRAP.
Update the comment on mt7530_setup() with a better explanation.
Tested-by: Arınç ÜNAL <arinc.unal@xxxxxxxxxx>
Signed-off-by: Arınç ÜNAL <arinc.unal@xxxxxxxxxx>
---
Do I need to protect the register from being accessed by processes while
this operation is being done? I don't see this on mt7530_setup() but it's
being done on mt7530_setup_port5().
There's an oddity here. The XTAL mask is defined on the MT7530_HWTRAP
register, but it's being read from MT7530_MHWTRAP instead which is at a
different address.
HWTRAP_XTAL_MASK and reading HWTRAP_XTAL_MASK from MT7530_MHWTRAP was both
added with:
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit?id=7ef6f6f8d237fa6724108b57d9706cb5069688e4
I did this to test it:
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 46749aee3c49..7aa3b5828ac3 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -404,7 +404,7 @@ static int
mt7530_setup_port6(struct dsa_switch *ds, phy_interface_t interface)
{
struct mt7530_priv *priv = ds->priv;
- u32 ncpo1, ssc_delta, trgint, xtal, val;
+ u32 ncpo1, ssc_delta, trgint, xtal, xtal2, val;
/* Enable port 6 */
val = mt7530_read(priv, MT7530_MHWTRAP);
@@ -413,6 +413,21 @@ mt7530_setup_port6(struct dsa_switch *ds, phy_interface_t interface)
mt7530_write(priv, MT7530_MHWTRAP, val);
xtal = val & HWTRAP_XTAL_MASK;
+ xtal2 = mt7530_read(priv, MT7530_HWTRAP) & HWTRAP_XTAL_MASK;
+
+ if (xtal == HWTRAP_XTAL_20MHZ)
+ dev_info(priv->dev, "xtal 20 Mhz\n");
+ if (xtal == HWTRAP_XTAL_25MHZ)
+ dev_info(priv->dev, "xtal 25 Mhz\n");
+ if (xtal == HWTRAP_XTAL_40MHZ)
+ dev_info(priv->dev, "xtal 40 Mhz\n");
+
+ if (xtal2 == HWTRAP_XTAL_20MHZ)
+ dev_info(priv->dev, "actual xtal 20 Mhz\n");
+ if (xtal2 == HWTRAP_XTAL_25MHZ)
+ dev_info(priv->dev, "actual xtal 25 Mhz\n");
+ if (xtal2 == HWTRAP_XTAL_40MHZ)
+ dev_info(priv->dev, "actual xtal 40 Mhz\n");
if (xtal == HWTRAP_XTAL_20MHZ) {
dev_err(priv->dev,
Both ended up reporting 40 Mhz so I'm not sure if this is a bug or intended
to be done this way.
Please advise.
Arınç
---
drivers/net/dsa/mt7530.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 0a6d1c0872be..70a673347cf9 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -404,9 +404,13 @@ static int
mt7530_setup_port6(struct dsa_switch *ds, phy_interface_t interface)
{
struct mt7530_priv *priv = ds->priv;
- u32 ncpo1, ssc_delta, trgint, xtal;
+ u32 ncpo1, ssc_delta, trgint, xtal, val;
- xtal = mt7530_read(priv, MT7530_MHWTRAP) & HWTRAP_XTAL_MASK;
+ val = mt7530_read(priv, MT7530_MHWTRAP);
+ val &= ~MHWTRAP_P6_DIS;
+ mt7530_write(priv, MT7530_MHWTRAP, val);
+
+ xtal = val & HWTRAP_XTAL_MASK;
if (xtal == HWTRAP_XTAL_20MHZ) {
dev_err(priv->dev,
@@ -2235,9 +2239,9 @@ mt7530_setup(struct dsa_switch *ds)
mt7530_rmw(priv, MT7530_TRGMII_RD(i),
RD_TAP_MASK, RD_TAP(16));
- /* Enable port 6 */
+ /* Enable PHY access and operate in manual mode */
val = mt7530_read(priv, MT7530_MHWTRAP);
- val &= ~MHWTRAP_P6_DIS & ~MHWTRAP_PHY_ACCESS;
+ val &= ~MHWTRAP_PHY_ACCESS;
val |= MHWTRAP_MANUAL;
mt7530_write(priv, MT7530_MHWTRAP, val);
--
2.37.2