Skip to content

Commit 7026533

Browse files
bcchen28411frank-w
authored andcommitted
net: pcs: mtk-lynxi: add phya tx rx clock path
In NETSYSv3.1, the SGMII hardware introduces a new clock path from PHYA. Consequently, users can switch the SGMII PCS to this new clock source for better performance on the MT7987. Signed-off-by: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
1 parent c542ce1 commit 7026533

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,9 @@ static int mtk_sgmii_init(struct mtk_eth *eth)
53305330
else if (of_property_read_bool(np, "mediatek,pnswap-rx"))
53315331
flags |= MTK_SGMII_FLAG_PN_SWAP_RX;
53325332

5333+
if (of_property_read_bool(np->parent, "mediatek,phya_trx_ck"))
5334+
flags |= MTK_SGMII_FLAG_PHYA_TRX_CK;
5335+
53335336
of_node_put(np);
53345337

53355338
if (IS_ERR(regmap))

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define SGMSYS_PCS_CONTROL_1 0x0
2929
#define SGMII_BMCR GENMASK(15, 0)
3030
#define SGMII_BMSR GENMASK(31, 16)
31+
#define SGMII_REF_CK_SEL BIT(24)
3132

3233
#define SGMSYS_PCS_DEVICE_ID 0x4
3334
#define SGMII_LYNXI_DEV_ID 0x4d544950
@@ -55,6 +56,8 @@
5556
#define SGMII_SPEED_1000 FIELD_PREP(SGMII_SPEED_MASK, 2)
5657
#define SGMII_DUPLEX_HALF BIT(4)
5758
#define SGMII_REMOTE_FAULT_DIS BIT(8)
59+
#define SGMII_TRXBUF_THR_MASK GENMASK(31, 16)
60+
#define SGMII_TRXBUF_THR(x) FIELD_PREP(SGMII_TRXBUF_THR_MASK, (x))
5861

5962
/* Register to reset SGMII design */
6063
#define SGMSYS_RESERVED_0 0x34
@@ -163,7 +166,7 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
163166
{
164167
struct mtk_pcs_lynxi *mpcs = pcs_to_mtk_pcs_lynxi(pcs);
165168
bool mode_changed = false, changed;
166-
unsigned int rgc3, sgm_mode, bmcr;
169+
unsigned int rgc3, sgm_mode, bmcr = 0, trxbuf_thr = 0x3112;
167170
unsigned int pnswap_tx, pnswap_rx;
168171
int link_timer;
169172

@@ -194,6 +197,12 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
194197
bmcr = 0;
195198
}
196199

200+
/* Configure SGMII PCS clock source */
201+
if (mpcs->flags & MTK_SGMII_FLAG_PHYA_TRX_CK) {
202+
bmcr |= SGMII_REF_CK_SEL;
203+
trxbuf_thr = 0x2111;
204+
}
205+
197206
if (mpcs->interface != interface) {
198207
link_timer = phylink_get_link_timer_ns(interface);
199208
if (link_timer < 0)
@@ -243,12 +252,14 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
243252

244253
/* Update the sgmsys mode register */
245254
regmap_update_bits(mpcs->regmap, SGMSYS_SGMII_MODE,
246-
SGMII_REMOTE_FAULT_DIS | SGMII_SPEED_DUPLEX_AN |
247-
SGMII_IF_MODE_SGMII, sgm_mode);
255+
SGMII_TRXBUF_THR_MASK |
256+
SGMII_REMOTE_FAULT_DIS | SGMII_DUPLEX_HALF |
257+
SGMII_SPEED_DUPLEX_AN | SGMII_IF_MODE_SGMII,
258+
SGMII_TRXBUF_THR(trxbuf_thr) | sgm_mode);
248259

249260
/* Update the BMCR */
250261
regmap_update_bits(mpcs->regmap, SGMSYS_PCS_CONTROL_1,
251-
BMCR_ANENABLE, bmcr);
262+
SGMII_REF_CK_SEL | BMCR_ANENABLE, bmcr);
252263

253264
/* Release PHYA power down state
254265
* Only removing bit SGMII_PHYA_PWD isn't enough.
@@ -445,6 +456,9 @@ static int mtk_pcs_lynxi_probe(struct platform_device *pdev)
445456
else if (of_property_read_bool(np->parent, "mediatek,pnswap-rx"))
446457
flags |= MTK_SGMII_FLAG_PN_SWAP_RX;
447458

459+
if (of_property_read_bool(np->parent, "mediatek,phya_trx_ck"))
460+
flags |= MTK_SGMII_FLAG_PHYA_TRX_CK;
461+
448462
if (of_parse_phandle(np->parent, "resets", 0)) {
449463
mpcs->rstc = of_reset_control_get_shared(np->parent, NULL);
450464
if (IS_ERR(mpcs->rstc))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#define MTK_SGMII_FLAG_PN_SWAP_TX BIT(0)
99
#define MTK_SGMII_FLAG_PN_SWAP_RX BIT(1)
10+
#define MTK_SGMII_FLAG_PHYA_TRX_CK BIT(2)
1011
struct phylink_pcs *mtk_pcs_lynxi_create(struct device *dev,
1112
struct regmap *regmap,
1213
u32 ana_rgc3, u32 flags);

0 commit comments

Comments
 (0)