blob: 491cac56a81a04f9576e926a045909f0a61dc1f2 [file] [log] [blame]
Weijie Gao23f17162018-12-20 16:12:53 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2018 MediaTek Inc.
4 *
5 * Author: Weijie Gao <weijie.gao@mediatek.com>
6 * Author: Mark Lee <mark-mc.lee@mediatek.com>
7 */
8
9#ifndef _MTK_ETH_H_
10#define _MTK_ETH_H_
11
Simon Glasscd93d622020-05-10 11:40:13 -060012#include <linux/bitops.h>
Weijie Gao7d928c32022-09-09 19:59:24 +080013#include <linux/bitfield.h>
Weijie Gao62596722022-09-09 19:59:21 +080014
15enum mkt_eth_capabilities {
16 MTK_TRGMII_BIT,
17 MTK_TRGMII_MT7621_CLK_BIT,
Weijie Gao585a1a42023-07-19 17:17:22 +080018 MTK_U3_COPHY_V2_BIT,
19 MTK_INFRA_BIT,
Weijie Gaoe7ad0462022-09-09 19:59:26 +080020 MTK_NETSYS_V2_BIT,
Weijie Gao76281942023-07-19 17:17:37 +080021 MTK_NETSYS_V3_BIT,
Weijie Gao62596722022-09-09 19:59:21 +080022
23 /* PATH BITS */
24 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
Weijie Gao585a1a42023-07-19 17:17:22 +080025 MTK_ETH_PATH_GMAC2_SGMII_BIT,
Weijie Gao62596722022-09-09 19:59:21 +080026};
27
28#define MTK_TRGMII BIT(MTK_TRGMII_BIT)
29#define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT)
Weijie Gao585a1a42023-07-19 17:17:22 +080030#define MTK_U3_COPHY_V2 BIT(MTK_U3_COPHY_V2_BIT)
31#define MTK_INFRA BIT(MTK_INFRA_BIT)
Weijie Gaoe7ad0462022-09-09 19:59:26 +080032#define MTK_NETSYS_V2 BIT(MTK_NETSYS_V2_BIT)
Weijie Gao76281942023-07-19 17:17:37 +080033#define MTK_NETSYS_V3 BIT(MTK_NETSYS_V3_BIT)
Weijie Gao62596722022-09-09 19:59:21 +080034
35/* Supported path present on SoCs */
36#define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
37
Weijie Gao585a1a42023-07-19 17:17:22 +080038#define MTK_ETH_PATH_GMAC2_SGMII BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
39
Weijie Gao62596722022-09-09 19:59:21 +080040#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
41
Weijie Gao585a1a42023-07-19 17:17:22 +080042#define MTK_GMAC2_U3_QPHY (MTK_ETH_PATH_GMAC2_SGMII | MTK_U3_COPHY_V2 | MTK_INFRA)
43
Weijie Gao62596722022-09-09 19:59:21 +080044#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
45
46#define MT7621_CAPS (MTK_GMAC1_TRGMII | MTK_TRGMII_MT7621_CLK)
47
48#define MT7623_CAPS (MTK_GMAC1_TRGMII)
49
Weijie Gao585a1a42023-07-19 17:17:22 +080050#define MT7981_CAPS (MTK_GMAC2_U3_QPHY | MTK_NETSYS_V2)
51
Weijie Gao29a48bf2022-09-09 19:59:28 +080052#define MT7986_CAPS (MTK_NETSYS_V2)
53
Weijie Gao93eb7072023-07-19 17:17:41 +080054#define MT7988_CAPS (MTK_NETSYS_V3 | MTK_INFRA)
55
Weijie Gao62596722022-09-09 19:59:21 +080056/* Frame Engine Register Bases */
Weijie Gaoe7ad0462022-09-09 19:59:26 +080057#define PDMA_V1_BASE 0x0800
58#define PDMA_V2_BASE 0x6000
Weijie Gao76281942023-07-19 17:17:37 +080059#define PDMA_V3_BASE 0x6800
Weijie Gao23f17162018-12-20 16:12:53 +080060#define GDMA1_BASE 0x0500
61#define GDMA2_BASE 0x1500
Weijie Gao76281942023-07-19 17:17:37 +080062#define GDMA3_BASE 0x0540
Weijie Gao23f17162018-12-20 16:12:53 +080063#define GMAC_BASE 0x10000
Weijie Gao93eb7072023-07-19 17:17:41 +080064#define GSW_BASE 0x20000
Weijie Gao23f17162018-12-20 16:12:53 +080065
66/* Ethernet subsystem registers */
67
68#define ETHSYS_SYSCFG0_REG 0x14
69#define SYSCFG0_GE_MODE_S(n) (12 + ((n) * 2))
70#define SYSCFG0_GE_MODE_M 0x3
MarkLeeb4ef49a2020-01-21 19:31:57 +080071#define SYSCFG0_SGMII_SEL_M (0x3 << 8)
72#define SYSCFG0_SGMII_SEL(gmac) ((!(gmac)) ? BIT(9) : BIT(8))
Weijie Gao23f17162018-12-20 16:12:53 +080073
74#define ETHSYS_CLKCFG0_REG 0x2c
75#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
76
Weijie Gao585a1a42023-07-19 17:17:22 +080077/* Top misc registers */
Weijie Gaoba026eb2023-07-19 17:17:31 +080078#define TOPMISC_NETSYS_PCS_MUX 0x84
79#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
80#define MUX_G2_USXGMII_SEL BIT(1)
81#define MUX_HSGMII1_G1_SEL BIT(0)
82
Weijie Gao585a1a42023-07-19 17:17:22 +080083#define USB_PHY_SWITCH_REG 0x218
84#define QPHY_SEL_MASK 0x3
85#define SGMII_QPHY_SEL 0x2
86
Weijie Gao23f17162018-12-20 16:12:53 +080087/* SYSCFG0_GE_MODE: GE Modes */
88#define GE_MODE_RGMII 0
89#define GE_MODE_MII 1
90#define GE_MODE_MII_PHY 2
91#define GE_MODE_RMII 3
92
MarkLeeb4ef49a2020-01-21 19:31:57 +080093/* SGMII subsystem config registers */
94#define SGMSYS_PCS_CONTROL_1 0x0
Landen Chao532de8d2020-02-18 16:49:37 +080095#define SGMII_LINK_STATUS BIT(18)
MarkLeeb4ef49a2020-01-21 19:31:57 +080096#define SGMII_AN_ENABLE BIT(12)
Landen Chao532de8d2020-02-18 16:49:37 +080097#define SGMII_AN_RESTART BIT(9)
MarkLeeb4ef49a2020-01-21 19:31:57 +080098
99#define SGMSYS_SGMII_MODE 0x20
Weijie Gaobd70f3c2023-07-19 17:17:13 +0800100#define SGMII_AN_MODE 0x31120103
MarkLeeb4ef49a2020-01-21 19:31:57 +0800101#define SGMII_FORCE_MODE 0x31120019
102
103#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
104#define SGMII_PHYA_PWD BIT(4)
105
Weijie Gao29a48bf2022-09-09 19:59:28 +0800106#define SGMSYS_QPHY_WRAP_CTRL 0xec
107#define SGMII_PN_SWAP_TX_RX 0x03
108
MarkLeeb4ef49a2020-01-21 19:31:57 +0800109#define SGMSYS_GEN2_SPEED 0x2028
MarkLeef0236b72020-06-19 19:17:16 +0800110#define SGMSYS_GEN2_SPEED_V2 0x128
MarkLeeb4ef49a2020-01-21 19:31:57 +0800111#define SGMSYS_SPEED_2500 BIT(2)
112
Weijie Gaoba026eb2023-07-19 17:17:31 +0800113/* USXGMII subsystem config registers */
114/* Register to control USXGMII XFI PLL digital */
115#define XFI_PLL_DIG_GLB8 0x08
116#define RG_XFI_PLL_EN BIT(31)
117
118/* Register to control USXGMII XFI PLL analog */
119#define XFI_PLL_ANA_GLB8 0x108
120#define RG_XFI_PLL_ANA_SWWA 0x02283248
121
Weijie Gao23f17162018-12-20 16:12:53 +0800122/* Frame Engine Registers */
Weijie Gao93eb7072023-07-19 17:17:41 +0800123#define PSE_NO_DROP_CFG_REG 0x108
124#define PSE_NO_DROP_GDM1 BIT(1)
125
Weijie Gaoe7ad0462022-09-09 19:59:26 +0800126#define FE_GLO_MISC_REG 0x124
127#define PDMA_VER_V2 BIT(4)
Weijie Gao23f17162018-12-20 16:12:53 +0800128
129/* PDMA */
130#define TX_BASE_PTR_REG(n) (0x000 + (n) * 0x10)
131#define TX_MAX_CNT_REG(n) (0x004 + (n) * 0x10)
132#define TX_CTX_IDX_REG(n) (0x008 + (n) * 0x10)
133#define TX_DTX_IDX_REG(n) (0x00c + (n) * 0x10)
134
135#define RX_BASE_PTR_REG(n) (0x100 + (n) * 0x10)
136#define RX_MAX_CNT_REG(n) (0x104 + (n) * 0x10)
137#define RX_CRX_IDX_REG(n) (0x108 + (n) * 0x10)
138#define RX_DRX_IDX_REG(n) (0x10c + (n) * 0x10)
139
140#define PDMA_GLO_CFG_REG 0x204
141#define TX_WB_DDONE BIT(6)
142#define RX_DMA_BUSY BIT(3)
143#define RX_DMA_EN BIT(2)
144#define TX_DMA_BUSY BIT(1)
145#define TX_DMA_EN BIT(0)
146
147#define PDMA_RST_IDX_REG 0x208
148#define RST_DRX_IDX0 BIT(16)
149#define RST_DTX_IDX0 BIT(0)
150
151/* GDMA */
152#define GDMA_IG_CTRL_REG 0x000
153#define GDM_ICS_EN BIT(22)
154#define GDM_TCS_EN BIT(21)
155#define GDM_UCS_EN BIT(20)
156#define STRP_CRC BIT(16)
157#define MYMAC_DP_S 12
158#define MYMAC_DP_M 0xf000
159#define BC_DP_S 8
160#define BC_DP_M 0xf00
161#define MC_DP_S 4
162#define MC_DP_M 0xf0
163#define UN_DP_S 0
164#define UN_DP_M 0x0f
165
Weijie Gao76281942023-07-19 17:17:37 +0800166#define GDMA_EG_CTRL_REG 0x004
167#define GDMA_CPU_BRIDGE_EN BIT(31)
168
Weijie Gao23f17162018-12-20 16:12:53 +0800169#define GDMA_MAC_LSB_REG 0x008
170
171#define GDMA_MAC_MSB_REG 0x00c
172
173/* MYMAC_DP/BC_DP/MC_DP/UN_DP: Destination ports */
174#define DP_PDMA 0
175#define DP_GDMA1 1
176#define DP_GDMA2 2
177#define DP_PPE 4
178#define DP_QDMA 5
179#define DP_DISCARD 7
180
181/* GMAC Registers */
182
183#define GMAC_PIAC_REG 0x0004
184#define PHY_ACS_ST BIT(31)
185#define MDIO_REG_ADDR_S 25
186#define MDIO_REG_ADDR_M 0x3e000000
187#define MDIO_PHY_ADDR_S 20
188#define MDIO_PHY_ADDR_M 0x1f00000
189#define MDIO_CMD_S 18
190#define MDIO_CMD_M 0xc0000
191#define MDIO_ST_S 16
192#define MDIO_ST_M 0x30000
193#define MDIO_RW_DATA_S 0
194#define MDIO_RW_DATA_M 0xffff
195
Weijie Gao93eb7072023-07-19 17:17:41 +0800196#define GMAC_XGMAC_STS_REG 0x000c
197#define P1_XGMAC_FORCE_LINK BIT(15)
198
199#define GMAC_MAC_MISC_REG 0x0010
200
201#define GMAC_GSW_CFG_REG 0x0080
202#define GSWTX_IPG_M 0xF0000
203#define GSWTX_IPG_S 16
204#define GSWRX_IPG_M 0xF
205#define GSWRX_IPG_S 0
206
Weijie Gao23f17162018-12-20 16:12:53 +0800207/* MDIO_CMD: MDIO commands */
208#define MDIO_CMD_ADDR 0
209#define MDIO_CMD_WRITE 1
210#define MDIO_CMD_READ 2
211#define MDIO_CMD_READ_C45 3
212
213/* MDIO_ST: MDIO start field */
214#define MDIO_ST_C45 0
215#define MDIO_ST_C22 1
216
217#define GMAC_PORT_MCR(p) (0x0100 + (p) * 0x100)
218#define MAC_RX_PKT_LEN_S 24
219#define MAC_RX_PKT_LEN_M 0x3000000
220#define IPG_CFG_S 18
221#define IPG_CFG_M 0xc0000
222#define MAC_MODE BIT(16)
223#define FORCE_MODE BIT(15)
224#define MAC_TX_EN BIT(14)
225#define MAC_RX_EN BIT(13)
Weijie Gaobd70f3c2023-07-19 17:17:13 +0800226#define DEL_RXFIFO_CLR BIT(12)
Weijie Gao23f17162018-12-20 16:12:53 +0800227#define BKOFF_EN BIT(9)
228#define BACKPR_EN BIT(8)
229#define FORCE_RX_FC BIT(5)
230#define FORCE_TX_FC BIT(4)
231#define FORCE_SPD_S 2
232#define FORCE_SPD_M 0x0c
233#define FORCE_DPX BIT(1)
234#define FORCE_LINK BIT(0)
235
Landen Chao532de8d2020-02-18 16:49:37 +0800236/* Values of IPG_CFG */
237#define IPG_96BIT 0
238#define IPG_96BIT_WITH_SHORT_IPG 1
239#define IPG_64BIT 2
240
Weijie Gao23f17162018-12-20 16:12:53 +0800241/* MAC_RX_PKT_LEN: Max RX packet length */
242#define MAC_RX_PKT_LEN_1518 0
243#define MAC_RX_PKT_LEN_1536 1
244#define MAC_RX_PKT_LEN_1552 2
245#define MAC_RX_PKT_LEN_JUMBO 3
246
247/* FORCE_SPD: Forced link speed */
248#define SPEED_10M 0
249#define SPEED_100M 1
250#define SPEED_1000M 2
251
252#define GMAC_TRGMII_RCK_CTRL 0x300
253#define RX_RST BIT(31)
254#define RXC_DQSISEL BIT(30)
255
256#define GMAC_TRGMII_TD_ODT(n) (0x354 + (n) * 8)
257#define TD_DM_DRVN_S 4
258#define TD_DM_DRVN_M 0xf0
259#define TD_DM_DRVP_S 0
260#define TD_DM_DRVP_M 0x0f
261
Weijie Gaoba026eb2023-07-19 17:17:31 +0800262/* XGMAC Status Registers */
263#define XGMAC_STS(x) (((x) == 2) ? 0x001C : 0x000C)
264#define XGMAC_FORCE_LINK BIT(15)
265
266/* XGMAC Registers */
267#define XGMAC_PORT_MCR(x) (0x2000 + (((x) - 1) * 0x1000))
268#define XGMAC_TRX_DISABLE 0xf
269#define XGMAC_FORCE_TX_FC BIT(5)
270#define XGMAC_FORCE_RX_FC BIT(4)
271
Weijie Gao23f17162018-12-20 16:12:53 +0800272/* MT7530 Registers */
273
274#define PCR_REG(p) (0x2004 + (p) * 0x100)
275#define PORT_MATRIX_S 16
276#define PORT_MATRIX_M 0xff0000
277
278#define PVC_REG(p) (0x2010 + (p) * 0x100)
279#define STAG_VPID_S 16
280#define STAG_VPID_M 0xffff0000
281#define VLAN_ATTR_S 6
282#define VLAN_ATTR_M 0xc0
283
284/* VLAN_ATTR: VLAN attributes */
285#define VLAN_ATTR_USER 0
286#define VLAN_ATTR_STACK 1
287#define VLAN_ATTR_TRANSLATION 2
288#define VLAN_ATTR_TRANSPARENT 3
289
Landen Chao532de8d2020-02-18 16:49:37 +0800290#define PMCR_REG(p) (0x3000 + (p) * 0x100)
291/* XXX: all fields of MT7530 are defined under GMAC_PORT_MCR
292 * MT7531 specific fields are defined below
293 */
294#define FORCE_MODE_EEE1G BIT(25)
295#define FORCE_MODE_EEE100 BIT(26)
296#define FORCE_MODE_TX_FC BIT(27)
297#define FORCE_MODE_RX_FC BIT(28)
298#define FORCE_MODE_DPX BIT(29)
299#define FORCE_MODE_SPD BIT(30)
300#define FORCE_MODE_LNK BIT(31)
301#define MT7531_FORCE_MODE FORCE_MODE_EEE1G | FORCE_MODE_EEE100 |\
302 FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
303 FORCE_MODE_DPX | FORCE_MODE_SPD | \
304 FORCE_MODE_LNK
Weijie Gao93eb7072023-07-19 17:17:41 +0800305#define MT7988_FORCE_MODE FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
306 FORCE_MODE_DPX | FORCE_MODE_SPD | \
307 FORCE_MODE_LNK
Weijie Gao23f17162018-12-20 16:12:53 +0800308
Landen Chao532de8d2020-02-18 16:49:37 +0800309/* MT7531 SGMII Registers */
310#define MT7531_SGMII_REG_BASE 0x5000
311#define MT7531_SGMII_REG_PORT_BASE 0x1000
312#define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \
313 (p) * MT7531_SGMII_REG_PORT_BASE + (r))
314#define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(((p) - 5), 0x00)
315#define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(((p) - 5), 0x20)
316#define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(((p) - 5), 0xe8)
317#define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(((p) - 5), 0x128)
318/* XXX: all fields of MT7531 SGMII are defined under SGMSYS */
319
320/* MT753x System Control Register */
Weijie Gao23f17162018-12-20 16:12:53 +0800321#define SYS_CTRL_REG 0x7000
322#define SW_PHY_RST BIT(2)
323#define SW_SYS_RST BIT(1)
324#define SW_REG_RST BIT(0)
325
Landen Chao532de8d2020-02-18 16:49:37 +0800326/* MT7531 */
327#define MT7531_PHY_IAC 0x701c
328/* XXX: all fields are defined under GMAC_PIAC_REG */
329
330#define MT7531_CLKGEN_CTRL 0x7500
331#define CLK_SKEW_OUT_S 8
332#define CLK_SKEW_OUT_M 0x300
333#define CLK_SKEW_IN_S 6
334#define CLK_SKEW_IN_M 0xc0
335#define RXCLK_NO_DELAY BIT(5)
336#define TXCLK_NO_REVERSE BIT(4)
337#define GP_MODE_S 1
338#define GP_MODE_M 0x06
339#define GP_CLK_EN BIT(0)
340
341/* Values of GP_MODE */
342#define GP_MODE_RGMII 0
343#define GP_MODE_MII 1
344#define GP_MODE_REV_MII 2
345
346/* Values of CLK_SKEW_IN */
347#define CLK_SKEW_IN_NO_CHANGE 0
348#define CLK_SKEW_IN_DELAY_100PPS 1
349#define CLK_SKEW_IN_DELAY_200PPS 2
350#define CLK_SKEW_IN_REVERSE 3
351
352/* Values of CLK_SKEW_OUT */
353#define CLK_SKEW_OUT_NO_CHANGE 0
354#define CLK_SKEW_OUT_DELAY_100PPS 1
355#define CLK_SKEW_OUT_DELAY_200PPS 2
356#define CLK_SKEW_OUT_REVERSE 3
Weijie Gao23f17162018-12-20 16:12:53 +0800357
358#define HWTRAP_REG 0x7800
Landen Chao532de8d2020-02-18 16:49:37 +0800359/* MT7530 Modified Hardware Trap Status Registers */
Weijie Gao23f17162018-12-20 16:12:53 +0800360#define MHWTRAP_REG 0x7804
361#define CHG_TRAP BIT(16)
362#define LOOPDET_DIS BIT(14)
363#define P5_INTF_SEL_S 13
364#define P5_INTF_SEL_M 0x2000
365#define SMI_ADDR_S 11
366#define SMI_ADDR_M 0x1800
367#define XTAL_FSEL_S 9
368#define XTAL_FSEL_M 0x600
369#define P6_INTF_DIS BIT(8)
370#define P5_INTF_MODE_S 7
371#define P5_INTF_MODE_M 0x80
372#define P5_INTF_DIS BIT(6)
373#define C_MDIO_BPS BIT(5)
374#define CHIP_MODE_S 0
375#define CHIP_MODE_M 0x0f
376
377/* P5_INTF_SEL: Interface type of Port5 */
378#define P5_INTF_SEL_GPHY 0
379#define P5_INTF_SEL_GMAC5 1
380
381/* P5_INTF_MODE: Interface mode of Port5 */
382#define P5_INTF_MODE_GMII_MII 0
383#define P5_INTF_MODE_RGMII 1
384
385#define MT7530_P6ECR 0x7830
386#define P6_INTF_MODE_M 0x3
387#define P6_INTF_MODE_S 0
388
389/* P6_INTF_MODE: Interface mode of Port6 */
390#define P6_INTF_MODE_RGMII 0
391#define P6_INTF_MODE_TRGMII 1
392
Landen Chao532de8d2020-02-18 16:49:37 +0800393#define NUM_TRGMII_CTRL 5
394
Weijie Gao23f17162018-12-20 16:12:53 +0800395#define MT7530_TRGMII_RD(n) (0x7a10 + (n) * 8)
396#define RD_TAP_S 0
397#define RD_TAP_M 0x7f
398
399#define MT7530_TRGMII_TD_ODT(n) (0x7a54 + (n) * 8)
400/* XXX: all fields are defined under GMAC_TRGMII_TD_ODT */
401
Landen Chao532de8d2020-02-18 16:49:37 +0800402/* TOP Signals Status Register */
403#define MT7531_TOP_SIG_SR 0x780c
404#define PAD_MCM_SMI_EN BIT(0)
405#define PAD_DUAL_SGMII_EN BIT(1)
Weijie Gao23f17162018-12-20 16:12:53 +0800406
Landen Chao532de8d2020-02-18 16:49:37 +0800407/* MT7531 PLLGP Registers */
408#define MT7531_PLLGP_EN 0x7820
409#define EN_COREPLL BIT(2)
410#define SW_CLKSW BIT(1)
411#define SW_PLLGP BIT(0)
412
413#define MT7531_PLLGP_CR0 0x78a8
414#define RG_COREPLL_EN BIT(22)
415#define RG_COREPLL_POSDIV_S 23
416#define RG_COREPLL_POSDIV_M 0x3800000
417#define RG_COREPLL_SDM_PCW_S 1
418#define RG_COREPLL_SDM_PCW_M 0x3ffffe
419#define RG_COREPLL_SDM_PCW_CHG BIT(0)
420
421/* MT7531 RGMII and SGMII PLL clock */
422#define MT7531_ANA_PLLGP_CR2 0x78b0
423#define MT7531_ANA_PLLGP_CR5 0x78bc
424
425/* MT7531 GPIO GROUP IOLB SMT0 Control */
426#define MT7531_SMT0_IOLB 0x7f04
427#define SMT_IOLB_5_SMI_MDC_EN BIT(5)
428
429/* MT7530 GPHY MDIO Indirect Access Registers */
Weijie Gao23f17162018-12-20 16:12:53 +0800430#define MII_MMD_ACC_CTL_REG 0x0d
431#define MMD_CMD_S 14
432#define MMD_CMD_M 0xc000
433#define MMD_DEVAD_S 0
434#define MMD_DEVAD_M 0x1f
435
436/* MMD_CMD: MMD commands */
437#define MMD_ADDR 0
438#define MMD_DATA 1
439#define MMD_DATA_RW_POST_INC 2
440#define MMD_DATA_W_POST_INC 3
441
442#define MII_MMD_ADDR_DATA_REG 0x0e
443
444/* MT7530 GPHY MDIO MMD Registers */
Weijie Gao23f17162018-12-20 16:12:53 +0800445#define CORE_PLL_GROUP2 0x401
446#define RG_SYSPLL_EN_NORMAL BIT(15)
447#define RG_SYSPLL_VODEN BIT(14)
448#define RG_SYSPLL_POSDIV_S 5
449#define RG_SYSPLL_POSDIV_M 0x60
450
451#define CORE_PLL_GROUP4 0x403
Landen Chao532de8d2020-02-18 16:49:37 +0800452#define MT7531_BYPASS_MODE BIT(4)
453#define MT7531_POWER_ON_OFF BIT(5)
Weijie Gao23f17162018-12-20 16:12:53 +0800454#define RG_SYSPLL_DDSFBK_EN BIT(12)
455#define RG_SYSPLL_BIAS_EN BIT(11)
456#define RG_SYSPLL_BIAS_LPF_EN BIT(10)
457
458#define CORE_PLL_GROUP5 0x404
459#define RG_LCDDS_PCW_NCPO1_S 0
460#define RG_LCDDS_PCW_NCPO1_M 0xffff
461
462#define CORE_PLL_GROUP6 0x405
463#define RG_LCDDS_PCW_NCPO0_S 0
464#define RG_LCDDS_PCW_NCPO0_M 0xffff
465
466#define CORE_PLL_GROUP7 0x406
467#define RG_LCDDS_PWDB BIT(15)
468#define RG_LCDDS_ISO_EN BIT(13)
469#define RG_LCCDS_C_S 4
470#define RG_LCCDS_C_M 0x70
471#define RG_LCDDS_PCW_NCPO_CHG BIT(3)
472
473#define CORE_PLL_GROUP10 0x409
474#define RG_LCDDS_SSC_DELTA_S 0
475#define RG_LCDDS_SSC_DELTA_M 0xfff
476
477#define CORE_PLL_GROUP11 0x40a
478#define RG_LCDDS_SSC_DELTA1_S 0
479#define RG_LCDDS_SSC_DELTA1_M 0xfff
480
481#define CORE_GSWPLL_GRP1 0x40d
482#define RG_GSWPLL_POSDIV_200M_S 12
483#define RG_GSWPLL_POSDIV_200M_M 0x3000
484#define RG_GSWPLL_EN_PRE BIT(11)
485#define RG_GSWPLL_FBKDIV_200M_S 0
486#define RG_GSWPLL_FBKDIV_200M_M 0xff
487
488#define CORE_GSWPLL_GRP2 0x40e
489#define RG_GSWPLL_POSDIV_500M_S 8
490#define RG_GSWPLL_POSDIV_500M_M 0x300
491#define RG_GSWPLL_FBKDIV_500M_S 0
492#define RG_GSWPLL_FBKDIV_500M_M 0xff
493
494#define CORE_TRGMII_GSW_CLK_CG 0x410
495#define REG_GSWCK_EN BIT(0)
496#define REG_TRGMIICK_EN BIT(1)
497
Landen Chao532de8d2020-02-18 16:49:37 +0800498/* Extend PHY Control Register 3 */
499#define PHY_EXT_REG_14 0x14
500
501/* Fields of PHY_EXT_REG_14 */
502#define PHY_EN_DOWN_SHFIT BIT(4)
503
504/* Extend PHY Control Register 4 */
505#define PHY_EXT_REG_17 0x17
506
507/* Fields of PHY_EXT_REG_17 */
508#define PHY_LINKDOWN_POWER_SAVING_EN BIT(4)
509
510/* PHY RXADC Control Register 7 */
511#define PHY_DEV1E_REG_0C6 0x0c6
512
513/* Fields of PHY_DEV1E_REG_0C6 */
514#define PHY_POWER_SAVING_S 8
515#define PHY_POWER_SAVING_M 0x300
516#define PHY_POWER_SAVING_TX 0x0
517
Weijie Gao7d928c32022-09-09 19:59:24 +0800518/* PDMA descriptors */
519struct mtk_rx_dma {
520 unsigned int rxd1;
521 unsigned int rxd2;
522 unsigned int rxd3;
523 unsigned int rxd4;
524} __packed __aligned(4);
525
Weijie Gaoe7ad0462022-09-09 19:59:26 +0800526struct mtk_rx_dma_v2 {
527 unsigned int rxd1;
528 unsigned int rxd2;
529 unsigned int rxd3;
530 unsigned int rxd4;
531 unsigned int rxd5;
532 unsigned int rxd6;
533 unsigned int rxd7;
534 unsigned int rxd8;
535} __packed __aligned(4);
536
Weijie Gao7d928c32022-09-09 19:59:24 +0800537struct mtk_tx_dma {
538 unsigned int txd1;
539 unsigned int txd2;
540 unsigned int txd3;
541 unsigned int txd4;
542} __packed __aligned(4);
543
Weijie Gaoe7ad0462022-09-09 19:59:26 +0800544struct mtk_tx_dma_v2 {
545 unsigned int txd1;
546 unsigned int txd2;
547 unsigned int txd3;
548 unsigned int txd4;
549 unsigned int txd5;
550 unsigned int txd6;
551 unsigned int txd7;
552 unsigned int txd8;
553} __packed __aligned(4);
554
Weijie Gao7d928c32022-09-09 19:59:24 +0800555/* PDMA TXD fields */
556#define PDMA_TXD2_DDONE BIT(31)
557#define PDMA_TXD2_LS0 BIT(30)
Weijie Gaoe7ad0462022-09-09 19:59:26 +0800558#define PDMA_V1_TXD2_SDL0_M GENMASK(29, 16)
559#define PDMA_V1_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V1_TXD2_SDL0_M, (_v))
560#define PDMA_V2_TXD2_SDL0_M GENMASK(23, 8)
561#define PDMA_V2_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V2_TXD2_SDL0_M, (_v))
Weijie Gao7d928c32022-09-09 19:59:24 +0800562
Weijie Gaoe7ad0462022-09-09 19:59:26 +0800563#define PDMA_V1_TXD4_FPORT_M GENMASK(27, 25)
564#define PDMA_V1_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V1_TXD4_FPORT_M, (_v))
565#define PDMA_V2_TXD4_FPORT_M GENMASK(27, 24)
566#define PDMA_V2_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD4_FPORT_M, (_v))
567
568#define PDMA_V2_TXD5_FPORT_M GENMASK(19, 16)
569#define PDMA_V2_TXD5_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD5_FPORT_M, (_v))
Weijie Gao7d928c32022-09-09 19:59:24 +0800570
571/* PDMA RXD fields */
572#define PDMA_RXD2_DDONE BIT(31)
573#define PDMA_RXD2_LS0 BIT(30)
Weijie Gaoe7ad0462022-09-09 19:59:26 +0800574#define PDMA_V1_RXD2_PLEN0_M GENMASK(29, 16)
575#define PDMA_V1_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V1_RXD2_PLEN0_M, (_v))
576#define PDMA_V1_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V1_RXD2_PLEN0_M, (_v))
577#define PDMA_V2_RXD2_PLEN0_M GENMASK(23, 8)
578#define PDMA_V2_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V2_RXD2_PLEN0_M, (_v))
579#define PDMA_V2_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V2_RXD2_PLEN0_M, (_v))
Weijie Gao7d928c32022-09-09 19:59:24 +0800580
Weijie Gao23f17162018-12-20 16:12:53 +0800581#endif /* _MTK_ETH_H_ */