1 From 2982f395c9a513b168f1e685588f70013cba2f5f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com>
3 Date: Mon, 22 Apr 2024 10:15:14 +0300
4 Subject: [PATCH 07/15] net: dsa: mt7530: move MT753X_MTRAP operations for
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 On MT7530, the media-independent interfaces of port 5 and 6 are controlled
11 by the MT7530_P5_DIS and MT7530_P6_DIS bits of the hardware trap. Deal with
12 these bits only when the relevant port is being enabled or disabled. This
13 ensures that these ports will be disabled when they are not in use.
15 Do not set MT7530_CHG_TRAP on mt7530_setup_port5() as that's already being
16 done on mt7530_setup().
18 Instead of globally setting MT7530_P5_MAC_SEL, clear it, then set it only
19 on the appropriate case.
21 If PHY muxing is detected, clear MT7530_P5_DIS before calling
24 Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
26 drivers/net/dsa/mt7530.c | 38 +++++++++++++++++++++++++++-----------
27 1 file changed, 27 insertions(+), 11 deletions(-)
29 --- a/drivers/net/dsa/mt7530.c
30 +++ b/drivers/net/dsa/mt7530.c
31 @@ -880,8 +880,7 @@ static void mt7530_setup_port5(struct ds
33 val = mt7530_read(priv, MT753X_MTRAP);
35 - val |= MT7530_CHG_TRAP | MT7530_P5_MAC_SEL | MT7530_P5_DIS;
36 - val &= ~MT7530_P5_RGMII_MODE & ~MT7530_P5_PHY0_SEL;
37 + val &= ~MT7530_P5_PHY0_SEL & ~MT7530_P5_MAC_SEL & ~MT7530_P5_RGMII_MODE;
39 switch (priv->p5_mode) {
40 /* MUX_PHY_P0: P0 -> P5 -> SoC MAC */
41 @@ -891,15 +890,13 @@ static void mt7530_setup_port5(struct ds
43 /* MUX_PHY_P4: P4 -> P5 -> SoC MAC */
45 - val &= ~MT7530_P5_MAC_SEL & ~MT7530_P5_DIS;
47 /* Setup the MAC by default for the cpu port */
48 mt7530_write(priv, MT753X_PMCR_P(5), 0x56300);
51 /* GMAC5: P5 -> SoC MAC or external PHY */
53 - val &= ~MT7530_P5_DIS;
54 + val |= MT7530_P5_MAC_SEL;
58 @@ -1193,6 +1190,14 @@ mt7530_port_enable(struct dsa_switch *ds
60 mutex_unlock(&priv->reg_mutex);
62 + if (priv->id != ID_MT7530 && priv->id != ID_MT7621)
66 + mt7530_clear(priv, MT753X_MTRAP, MT7530_P5_DIS);
68 + mt7530_clear(priv, MT753X_MTRAP, MT7530_P6_DIS);
73 @@ -1211,6 +1216,14 @@ mt7530_port_disable(struct dsa_switch *d
76 mutex_unlock(&priv->reg_mutex);
78 + if (priv->id != ID_MT7530 && priv->id != ID_MT7621)
82 + mt7530_set(priv, MT753X_MTRAP, MT7530_P5_DIS);
84 + mt7530_set(priv, MT753X_MTRAP, MT7530_P6_DIS);
88 @@ -2401,11 +2414,11 @@ mt7530_setup(struct dsa_switch *ds)
89 mt7530_rmw(priv, MT7530_TRGMII_RD(i),
90 RD_TAP_MASK, RD_TAP(16));
93 - val = mt7530_read(priv, MT753X_MTRAP);
94 - val &= ~MT7530_P6_DIS & ~MT7530_PHY_INDIRECT_ACCESS;
95 - val |= MT7530_CHG_TRAP;
96 - mt7530_write(priv, MT753X_MTRAP, val);
97 + /* Allow modifying the trap and directly access PHY registers via the
98 + * MDIO bus the switch is on.
100 + mt7530_rmw(priv, MT753X_MTRAP, MT7530_CHG_TRAP |
101 + MT7530_PHY_INDIRECT_ACCESS, MT7530_CHG_TRAP);
103 if ((val & MT7530_XTAL_MASK) == MT7530_XTAL_40MHZ)
104 mt7530_pll_setup(priv);
105 @@ -2488,8 +2501,11 @@ mt7530_setup(struct dsa_switch *ds)
109 - if (priv->p5_mode == MUX_PHY_P0 || priv->p5_mode == MUX_PHY_P4)
110 + if (priv->p5_mode == MUX_PHY_P0 ||
111 + priv->p5_mode == MUX_PHY_P4) {
112 + mt7530_clear(priv, MT753X_MTRAP, MT7530_P5_DIS);
113 mt7530_setup_port5(ds, interface);
117 #ifdef CONFIG_GPIOLIB