Skip to content

Commit 56df9eb

Browse files
bcchen28411frank-w
authored andcommitted
net: pcs: mtk-lynxi: add individual polarity control
The user can add the following property to the sgmiisys node of the DTS to control the SGMII PN polarity. - mediatek,pnswap: Swap TX and RX PN polarity - mediatek,pnswap-tx: Swap TX PN polarity - mediatek,pnswap-rx: Swap RX PN polarity Without this patch, the TX/RX polarity of the SGMII cannot be controlled individually. Signed-off-by: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
1 parent 93f47df commit 56df9eb

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

drivers/net/dsa/mt7530-mdio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ mt7531_create_sgmii(struct mt7530_priv *priv)
114114
break;
115115
}
116116
pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
117-
MT7531_PHYA_CTRL_SIGNAL3, 0);
117+
MT7531_PHYA_CTRL_SIGNAL3,
118+
MTK_SGMII_FLAG_PN_SWAP_TX);
118119
if (!pcs) {
119120
ret = -ENXIO;
120121
break;

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5324,7 +5324,11 @@ static int mtk_sgmii_init(struct mtk_eth *eth)
53245324
regmap = syscon_node_to_regmap(np);
53255325
flags = 0;
53265326
if (of_property_read_bool(np, "mediatek,pnswap"))
5327-
flags |= MTK_SGMII_FLAG_PN_SWAP;
5327+
flags |= MTK_SGMII_FLAG_PN_SWAP_TX | MTK_SGMII_FLAG_PN_SWAP_RX;
5328+
else if (of_property_read_bool(np, "mediatek,pnswap-tx"))
5329+
flags |= MTK_SGMII_FLAG_PN_SWAP_TX;
5330+
else if (of_property_read_bool(np, "mediatek,pnswap-rx"))
5331+
flags |= MTK_SGMII_FLAG_PN_SWAP_RX;
53285332

53295333
of_node_put(np);
53305334

drivers/net/pcs/pcs-mtk-lynxi.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
/* Register to QPHY wrapper control */
7373
#define SGMSYS_QPHY_WRAP_CTRL 0xec
7474
#define SGMII_PN_SWAP_MASK GENMASK(1, 0)
75-
#define SGMII_PN_SWAP_TX_RX (BIT(0) | BIT(1))
75+
#define SGMII_PN_SWAP_RX BIT(1)
76+
#define SGMII_PN_SWAP_TX BIT(0)
7677

7778
#define MTK_NETSYS_V3_AMA_RGC3 0x128
7879

@@ -163,6 +164,7 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
163164
struct mtk_pcs_lynxi *mpcs = pcs_to_mtk_pcs_lynxi(pcs);
164165
bool mode_changed = false, changed;
165166
unsigned int rgc3, sgm_mode, bmcr;
167+
unsigned int pnswap_tx, pnswap_rx;
166168
int link_timer;
167169

168170
if (advertising) {
@@ -209,10 +211,14 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
209211
regmap_set_bits(mpcs->regmap, SGMSYS_RESERVED_0,
210212
SGMII_SW_RESET);
211213

212-
if (mpcs->flags & MTK_SGMII_FLAG_PN_SWAP)
213-
regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_WRAP_CTRL,
214-
SGMII_PN_SWAP_MASK,
215-
SGMII_PN_SWAP_TX_RX);
214+
/* Configure the interface polarity */
215+
pnswap_tx = (mpcs->flags & MTK_SGMII_FLAG_PN_SWAP_TX) ?
216+
SGMII_PN_SWAP_TX : 0;
217+
pnswap_rx = (mpcs->flags & MTK_SGMII_FLAG_PN_SWAP_RX) ?
218+
SGMII_PN_SWAP_RX : 0;
219+
regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_WRAP_CTRL,
220+
SGMII_PN_SWAP_MASK,
221+
pnswap_tx | pnswap_rx);
216222

217223
if (interface == PHY_INTERFACE_MODE_2500BASEX)
218224
rgc3 = SGMII_PHY_SPEED_3_125G;
@@ -433,7 +439,11 @@ static int mtk_pcs_lynxi_probe(struct platform_device *pdev)
433439
return PTR_ERR(regmap);
434440

435441
if (of_property_read_bool(np->parent, "mediatek,pnswap"))
436-
flags |= MTK_SGMII_FLAG_PN_SWAP;
442+
flags |= MTK_SGMII_FLAG_PN_SWAP_TX | MTK_SGMII_FLAG_PN_SWAP_RX;
443+
else if (of_property_read_bool(np->parent, "mediatek,pnswap-tx"))
444+
flags |= MTK_SGMII_FLAG_PN_SWAP_TX;
445+
else if (of_property_read_bool(np->parent, "mediatek,pnswap-rx"))
446+
flags |= MTK_SGMII_FLAG_PN_SWAP_RX;
437447

438448
if (of_parse_phandle(np->parent, "resets", 0)) {
439449
mpcs->rstc = of_reset_control_get_shared(np->parent, NULL);

include/linux/pcs/pcs-mtk-lynxi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include <linux/phylink.h>
66
#include <linux/regmap.h>
77

8-
#define MTK_SGMII_FLAG_PN_SWAP BIT(0)
8+
#define MTK_SGMII_FLAG_PN_SWAP_TX BIT(0)
9+
#define MTK_SGMII_FLAG_PN_SWAP_RX BIT(1)
910
struct phylink_pcs *mtk_pcs_lynxi_create(struct device *dev,
1011
struct regmap *regmap,
1112
u32 ana_rgc3, u32 flags);

0 commit comments

Comments
 (0)