1 From 542d455466bdf32e1bb70230ebcdefd8ed09643b Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Wed, 19 Jul 2023 17:17:22 +0800
4 Subject: [PATCH 22/29] net: mediatek: add support for GMAC/USB3 PHY mux mode
7 MT7981 has its GMAC2 PHY shared with USB3. To enable GMAC2, mux
8 register must be set to connect the SGMII phy to GMAC2.
10 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
12 drivers/net/mtk_eth.c | 33 ++++++++++++++++++++++++++++++++-
13 drivers/net/mtk_eth.h | 16 ++++++++++++++++
14 2 files changed, 48 insertions(+), 1 deletion(-)
16 --- a/drivers/net/mtk_eth.c
17 +++ b/drivers/net/mtk_eth.c
18 @@ -103,6 +103,8 @@ struct mtk_eth_priv {
20 struct regmap *ethsys_regmap;
22 + struct regmap *infra_regmap;
24 struct mii_dev *mdio_bus;
25 int (*mii_read)(struct mtk_eth_priv *priv, u8 phy, u8 reg);
26 int (*mii_write)(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 val);
27 @@ -186,6 +188,17 @@ static void mtk_ethsys_rmw(struct mtk_et
28 regmap_write(priv->ethsys_regmap, reg, val);
31 +static void mtk_infra_rmw(struct mtk_eth_priv *priv, u32 reg, u32 clr,
36 + regmap_read(priv->infra_regmap, reg, &val);
39 + regmap_write(priv->infra_regmap, reg, val);
42 /* Direct MDIO clause 22/45 access via SoC */
43 static int mtk_mii_rw(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 data,
45 @@ -1139,6 +1152,11 @@ static void mtk_mac_init(struct mtk_eth_
47 case PHY_INTERFACE_MODE_SGMII:
48 case PHY_INTERFACE_MODE_2500BASEX:
49 + if (MTK_HAS_CAPS(priv->soc->caps, MTK_GMAC2_U3_QPHY)) {
50 + mtk_infra_rmw(priv, USB_PHY_SWITCH_REG, QPHY_SEL_MASK,
54 ge_mode = GE_MODE_RGMII;
55 mtk_ethsys_rmw(priv, ETHSYS_SYSCFG0_REG, SYSCFG0_SGMII_SEL_M,
56 SYSCFG0_SGMII_SEL(priv->gmac_id));
57 @@ -1497,6 +1515,19 @@ static int mtk_eth_of_to_plat(struct ude
58 if (IS_ERR(priv->ethsys_regmap))
59 return PTR_ERR(priv->ethsys_regmap);
61 + if (MTK_HAS_CAPS(priv->soc->caps, MTK_INFRA)) {
62 + /* get corresponding infracfg phandle */
63 + ret = dev_read_phandle_with_args(dev, "mediatek,infracfg",
69 + priv->infra_regmap = syscon_node_to_regmap(args.node);
70 + if (IS_ERR(priv->infra_regmap))
71 + return PTR_ERR(priv->infra_regmap);
74 /* Reset controllers */
75 ret = reset_get_by_name(dev, "fe", &priv->rst_fe);
77 @@ -1614,7 +1645,7 @@ static const struct mtk_soc_data mt7986_
80 static const struct mtk_soc_data mt7981_data = {
81 - .caps = MT7986_CAPS,
82 + .caps = MT7981_CAPS,
84 .pdma_base = PDMA_V2_BASE,
85 .txd_size = sizeof(struct mtk_tx_dma_v2),
86 --- a/drivers/net/mtk_eth.h
87 +++ b/drivers/net/mtk_eth.h
89 enum mkt_eth_capabilities {
91 MTK_TRGMII_MT7621_CLK_BIT,
92 + MTK_U3_COPHY_V2_BIT,
97 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
98 + MTK_ETH_PATH_GMAC2_SGMII_BIT,
101 #define MTK_TRGMII BIT(MTK_TRGMII_BIT)
102 #define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT)
103 +#define MTK_U3_COPHY_V2 BIT(MTK_U3_COPHY_V2_BIT)
104 +#define MTK_INFRA BIT(MTK_INFRA_BIT)
105 #define MTK_NETSYS_V2 BIT(MTK_NETSYS_V2_BIT)
107 /* Supported path present on SoCs */
108 #define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
110 +#define MTK_ETH_PATH_GMAC2_SGMII BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
112 #define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
114 +#define MTK_GMAC2_U3_QPHY (MTK_ETH_PATH_GMAC2_SGMII | MTK_U3_COPHY_V2 | MTK_INFRA)
116 #define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
118 #define MT7621_CAPS (MTK_GMAC1_TRGMII | MTK_TRGMII_MT7621_CLK)
120 #define MT7623_CAPS (MTK_GMAC1_TRGMII)
122 +#define MT7981_CAPS (MTK_GMAC2_U3_QPHY | MTK_NETSYS_V2)
124 #define MT7986_CAPS (MTK_NETSYS_V2)
126 /* Frame Engine Register Bases */
127 @@ -56,6 +67,11 @@ enum mkt_eth_capabilities {
128 #define ETHSYS_CLKCFG0_REG 0x2c
129 #define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
131 +/* Top misc registers */
132 +#define USB_PHY_SWITCH_REG 0x218
133 +#define QPHY_SEL_MASK 0x3
134 +#define SGMII_QPHY_SEL 0x2
136 /* SYSCFG0_GE_MODE: GE Modes */
137 #define GE_MODE_RGMII 0
138 #define GE_MODE_MII 1