blob: fd31c782c7f2a3b9e0811818aca3537e92e8373a [file] [log] [blame]
developerc3ac93d2018-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 Glass4dcacfc2020-05-10 11:40:13 -060012#include <linux/bitops.h>
developer65089f72022-09-09 19:59:24 +080013#include <linux/bitfield.h>
developer1d3b1f62022-09-09 19:59:21 +080014
15enum mkt_eth_capabilities {
16 MTK_TRGMII_BIT,
17 MTK_TRGMII_MT7621_CLK_BIT,
developera5d712a2023-07-19 17:17:22 +080018 MTK_U3_COPHY_V2_BIT,
19 MTK_INFRA_BIT,
developera7cdebf2022-09-09 19:59:26 +080020 MTK_NETSYS_V2_BIT,
developer78fed682023-07-19 17:17:37 +080021 MTK_NETSYS_V3_BIT,
developer1d3b1f62022-09-09 19:59:21 +080022
23 /* PATH BITS */
24 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
developera5d712a2023-07-19 17:17:22 +080025 MTK_ETH_PATH_GMAC2_SGMII_BIT,
developer1d3b1f62022-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)
developera5d712a2023-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)
developera7cdebf2022-09-09 19:59:26 +080032#define MTK_NETSYS_V2 BIT(MTK_NETSYS_V2_BIT)
developer78fed682023-07-19 17:17:37 +080033#define MTK_NETSYS_V3 BIT(MTK_NETSYS_V3_BIT)
developer1d3b1f62022-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
developera5d712a2023-07-19 17:17:22 +080038#define MTK_ETH_PATH_GMAC2_SGMII BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
39
developer1d3b1f62022-09-09 19:59:21 +080040#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
41
developera5d712a2023-07-19 17:17:22 +080042#define MTK_GMAC2_U3_QPHY (MTK_ETH_PATH_GMAC2_SGMII | MTK_U3_COPHY_V2 | MTK_INFRA)
43
developer1d3b1f62022-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
developera5d712a2023-07-19 17:17:22 +080050#define MT7981_CAPS (MTK_GMAC2_U3_QPHY | MTK_NETSYS_V2)
51
developer053929c2022-09-09 19:59:28 +080052#define MT7986_CAPS (MTK_NETSYS_V2)
53
developer76e14722023-07-19 17:17:41 +080054#define MT7988_CAPS (MTK_NETSYS_V3 | MTK_INFRA)
55
developer1d3b1f62022-09-09 19:59:21 +080056/* Frame Engine Register Bases */
developera7cdebf2022-09-09 19:59:26 +080057#define PDMA_V1_BASE 0x0800
58#define PDMA_V2_BASE 0x6000
developer78fed682023-07-19 17:17:37 +080059#define PDMA_V3_BASE 0x6800
developerc3ac93d2018-12-20 16:12:53 +080060#define GDMA1_BASE 0x0500
61#define GDMA2_BASE 0x1500
developer78fed682023-07-19 17:17:37 +080062#define GDMA3_BASE 0x0540
developerc3ac93d2018-12-20 16:12:53 +080063#define GMAC_BASE 0x10000
developer76e14722023-07-19 17:17:41 +080064#define GSW_BASE 0x20000
developerc3ac93d2018-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
developer9a12c242020-01-21 19:31:57 +080071#define SYSCFG0_SGMII_SEL_M (0x3 << 8)
72#define SYSCFG0_SGMII_SEL(gmac) ((!(gmac)) ? BIT(9) : BIT(8))
developerc3ac93d2018-12-20 16:12:53 +080073
74#define ETHSYS_CLKCFG0_REG 0x2c
75#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
76
developera5d712a2023-07-19 17:17:22 +080077/* Top misc registers */
developer03ce27b2023-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
developera5d712a2023-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
developerc3ac93d2018-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
developer9a12c242020-01-21 19:31:57 +080093/* SGMII subsystem config registers */
94#define SGMSYS_PCS_CONTROL_1 0x0
developerd5d73952020-02-18 16:49:37 +080095#define SGMII_LINK_STATUS BIT(18)
developer9a12c242020-01-21 19:31:57 +080096#define SGMII_AN_ENABLE BIT(12)
developerd5d73952020-02-18 16:49:37 +080097#define SGMII_AN_RESTART BIT(9)
developer9a12c242020-01-21 19:31:57 +080098
99#define SGMSYS_SGMII_MODE 0x20
developer4aafc992023-07-19 17:17:13 +0800100#define SGMII_AN_MODE 0x31120103
developer9a12c242020-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
developer053929c2022-09-09 19:59:28 +0800106#define SGMSYS_QPHY_WRAP_CTRL 0xec
107#define SGMII_PN_SWAP_TX_RX 0x03
108
developer9a12c242020-01-21 19:31:57 +0800109#define SGMSYS_GEN2_SPEED 0x2028
developerf6f0ccb2020-06-19 19:17:16 +0800110#define SGMSYS_GEN2_SPEED_V2 0x128
developer9a12c242020-01-21 19:31:57 +0800111#define SGMSYS_SPEED_2500 BIT(2)
112
developer03ce27b2023-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
developerc3ac93d2018-12-20 16:12:53 +0800122/* Frame Engine Registers */
developer76e14722023-07-19 17:17:41 +0800123#define PSE_NO_DROP_CFG_REG 0x108
124#define PSE_NO_DROP_GDM1 BIT(1)
125
developera7cdebf2022-09-09 19:59:26 +0800126#define FE_GLO_MISC_REG 0x124
127#define PDMA_VER_V2 BIT(4)
developerc3ac93d2018-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
developer78fed682023-07-19 17:17:37 +0800166#define GDMA_EG_CTRL_REG 0x004
167#define GDMA_CPU_BRIDGE_EN BIT(31)
168
developerc3ac93d2018-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
developer4843ad32024-01-22 10:08:11 +0800183#define GMAC_PPSC_REG 0x0000
184#define PHY_MDC_CFG GENMASK(29, 24)
185#define MDC_TURBO BIT(20)
186#define MDC_MAX_FREQ 25000000
187#define MDC_MAX_DIVIDER 63
188
developerc3ac93d2018-12-20 16:12:53 +0800189#define GMAC_PIAC_REG 0x0004
190#define PHY_ACS_ST BIT(31)
191#define MDIO_REG_ADDR_S 25
192#define MDIO_REG_ADDR_M 0x3e000000
193#define MDIO_PHY_ADDR_S 20
194#define MDIO_PHY_ADDR_M 0x1f00000
195#define MDIO_CMD_S 18
196#define MDIO_CMD_M 0xc0000
197#define MDIO_ST_S 16
198#define MDIO_ST_M 0x30000
199#define MDIO_RW_DATA_S 0
200#define MDIO_RW_DATA_M 0xffff
201
developer76e14722023-07-19 17:17:41 +0800202#define GMAC_XGMAC_STS_REG 0x000c
203#define P1_XGMAC_FORCE_LINK BIT(15)
204
205#define GMAC_MAC_MISC_REG 0x0010
developer4843ad32024-01-22 10:08:11 +0800206#define MISC_MDC_TURBO BIT(4)
developer76e14722023-07-19 17:17:41 +0800207
208#define GMAC_GSW_CFG_REG 0x0080
209#define GSWTX_IPG_M 0xF0000
210#define GSWTX_IPG_S 16
211#define GSWRX_IPG_M 0xF
212#define GSWRX_IPG_S 0
213
developerc3ac93d2018-12-20 16:12:53 +0800214/* MDIO_CMD: MDIO commands */
215#define MDIO_CMD_ADDR 0
216#define MDIO_CMD_WRITE 1
217#define MDIO_CMD_READ 2
218#define MDIO_CMD_READ_C45 3
219
220/* MDIO_ST: MDIO start field */
221#define MDIO_ST_C45 0
222#define MDIO_ST_C22 1
223
224#define GMAC_PORT_MCR(p) (0x0100 + (p) * 0x100)
225#define MAC_RX_PKT_LEN_S 24
226#define MAC_RX_PKT_LEN_M 0x3000000
227#define IPG_CFG_S 18
228#define IPG_CFG_M 0xc0000
229#define MAC_MODE BIT(16)
230#define FORCE_MODE BIT(15)
231#define MAC_TX_EN BIT(14)
232#define MAC_RX_EN BIT(13)
developer4aafc992023-07-19 17:17:13 +0800233#define DEL_RXFIFO_CLR BIT(12)
developerc3ac93d2018-12-20 16:12:53 +0800234#define BKOFF_EN BIT(9)
235#define BACKPR_EN BIT(8)
236#define FORCE_RX_FC BIT(5)
237#define FORCE_TX_FC BIT(4)
238#define FORCE_SPD_S 2
239#define FORCE_SPD_M 0x0c
240#define FORCE_DPX BIT(1)
241#define FORCE_LINK BIT(0)
242
developerd5d73952020-02-18 16:49:37 +0800243/* Values of IPG_CFG */
244#define IPG_96BIT 0
245#define IPG_96BIT_WITH_SHORT_IPG 1
246#define IPG_64BIT 2
247
developerc3ac93d2018-12-20 16:12:53 +0800248/* MAC_RX_PKT_LEN: Max RX packet length */
249#define MAC_RX_PKT_LEN_1518 0
250#define MAC_RX_PKT_LEN_1536 1
251#define MAC_RX_PKT_LEN_1552 2
252#define MAC_RX_PKT_LEN_JUMBO 3
253
254/* FORCE_SPD: Forced link speed */
255#define SPEED_10M 0
256#define SPEED_100M 1
257#define SPEED_1000M 2
258
259#define GMAC_TRGMII_RCK_CTRL 0x300
260#define RX_RST BIT(31)
261#define RXC_DQSISEL BIT(30)
262
263#define GMAC_TRGMII_TD_ODT(n) (0x354 + (n) * 8)
264#define TD_DM_DRVN_S 4
265#define TD_DM_DRVN_M 0xf0
266#define TD_DM_DRVP_S 0
267#define TD_DM_DRVP_M 0x0f
268
developer03ce27b2023-07-19 17:17:31 +0800269/* XGMAC Status Registers */
270#define XGMAC_STS(x) (((x) == 2) ? 0x001C : 0x000C)
developeref7b6502024-01-22 10:08:16 +0800271#define XGMAC_FORCE_LINK(x) (((x) == 1) ? BIT(31) : BIT(15))
developer03ce27b2023-07-19 17:17:31 +0800272
273/* XGMAC Registers */
274#define XGMAC_PORT_MCR(x) (0x2000 + (((x) - 1) * 0x1000))
275#define XGMAC_TRX_DISABLE 0xf
276#define XGMAC_FORCE_TX_FC BIT(5)
277#define XGMAC_FORCE_RX_FC BIT(4)
278
developerc3ac93d2018-12-20 16:12:53 +0800279/* MT7530 Registers */
280
281#define PCR_REG(p) (0x2004 + (p) * 0x100)
282#define PORT_MATRIX_S 16
283#define PORT_MATRIX_M 0xff0000
284
285#define PVC_REG(p) (0x2010 + (p) * 0x100)
286#define STAG_VPID_S 16
287#define STAG_VPID_M 0xffff0000
288#define VLAN_ATTR_S 6
289#define VLAN_ATTR_M 0xc0
290
291/* VLAN_ATTR: VLAN attributes */
292#define VLAN_ATTR_USER 0
293#define VLAN_ATTR_STACK 1
294#define VLAN_ATTR_TRANSLATION 2
295#define VLAN_ATTR_TRANSPARENT 3
296
developerd5d73952020-02-18 16:49:37 +0800297#define PMCR_REG(p) (0x3000 + (p) * 0x100)
298/* XXX: all fields of MT7530 are defined under GMAC_PORT_MCR
299 * MT7531 specific fields are defined below
300 */
301#define FORCE_MODE_EEE1G BIT(25)
302#define FORCE_MODE_EEE100 BIT(26)
303#define FORCE_MODE_TX_FC BIT(27)
304#define FORCE_MODE_RX_FC BIT(28)
305#define FORCE_MODE_DPX BIT(29)
306#define FORCE_MODE_SPD BIT(30)
307#define FORCE_MODE_LNK BIT(31)
308#define MT7531_FORCE_MODE FORCE_MODE_EEE1G | FORCE_MODE_EEE100 |\
309 FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
310 FORCE_MODE_DPX | FORCE_MODE_SPD | \
311 FORCE_MODE_LNK
developer76e14722023-07-19 17:17:41 +0800312#define MT7988_FORCE_MODE FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
313 FORCE_MODE_DPX | FORCE_MODE_SPD | \
314 FORCE_MODE_LNK
developerc3ac93d2018-12-20 16:12:53 +0800315
developerd5d73952020-02-18 16:49:37 +0800316/* MT7531 SGMII Registers */
317#define MT7531_SGMII_REG_BASE 0x5000
318#define MT7531_SGMII_REG_PORT_BASE 0x1000
319#define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \
320 (p) * MT7531_SGMII_REG_PORT_BASE + (r))
321#define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(((p) - 5), 0x00)
322#define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(((p) - 5), 0x20)
323#define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(((p) - 5), 0xe8)
324#define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(((p) - 5), 0x128)
325/* XXX: all fields of MT7531 SGMII are defined under SGMSYS */
326
327/* MT753x System Control Register */
developerc3ac93d2018-12-20 16:12:53 +0800328#define SYS_CTRL_REG 0x7000
329#define SW_PHY_RST BIT(2)
330#define SW_SYS_RST BIT(1)
331#define SW_REG_RST BIT(0)
332
developerd5d73952020-02-18 16:49:37 +0800333/* MT7531 */
334#define MT7531_PHY_IAC 0x701c
335/* XXX: all fields are defined under GMAC_PIAC_REG */
336
337#define MT7531_CLKGEN_CTRL 0x7500
338#define CLK_SKEW_OUT_S 8
339#define CLK_SKEW_OUT_M 0x300
340#define CLK_SKEW_IN_S 6
341#define CLK_SKEW_IN_M 0xc0
342#define RXCLK_NO_DELAY BIT(5)
343#define TXCLK_NO_REVERSE BIT(4)
344#define GP_MODE_S 1
345#define GP_MODE_M 0x06
346#define GP_CLK_EN BIT(0)
347
348/* Values of GP_MODE */
349#define GP_MODE_RGMII 0
350#define GP_MODE_MII 1
351#define GP_MODE_REV_MII 2
352
353/* Values of CLK_SKEW_IN */
354#define CLK_SKEW_IN_NO_CHANGE 0
355#define CLK_SKEW_IN_DELAY_100PPS 1
356#define CLK_SKEW_IN_DELAY_200PPS 2
357#define CLK_SKEW_IN_REVERSE 3
358
359/* Values of CLK_SKEW_OUT */
360#define CLK_SKEW_OUT_NO_CHANGE 0
361#define CLK_SKEW_OUT_DELAY_100PPS 1
362#define CLK_SKEW_OUT_DELAY_200PPS 2
363#define CLK_SKEW_OUT_REVERSE 3
developerc3ac93d2018-12-20 16:12:53 +0800364
365#define HWTRAP_REG 0x7800
developerd5d73952020-02-18 16:49:37 +0800366/* MT7530 Modified Hardware Trap Status Registers */
developerc3ac93d2018-12-20 16:12:53 +0800367#define MHWTRAP_REG 0x7804
368#define CHG_TRAP BIT(16)
369#define LOOPDET_DIS BIT(14)
370#define P5_INTF_SEL_S 13
371#define P5_INTF_SEL_M 0x2000
372#define SMI_ADDR_S 11
373#define SMI_ADDR_M 0x1800
374#define XTAL_FSEL_S 9
375#define XTAL_FSEL_M 0x600
376#define P6_INTF_DIS BIT(8)
377#define P5_INTF_MODE_S 7
378#define P5_INTF_MODE_M 0x80
379#define P5_INTF_DIS BIT(6)
380#define C_MDIO_BPS BIT(5)
381#define CHIP_MODE_S 0
382#define CHIP_MODE_M 0x0f
383
384/* P5_INTF_SEL: Interface type of Port5 */
385#define P5_INTF_SEL_GPHY 0
386#define P5_INTF_SEL_GMAC5 1
387
388/* P5_INTF_MODE: Interface mode of Port5 */
389#define P5_INTF_MODE_GMII_MII 0
390#define P5_INTF_MODE_RGMII 1
391
392#define MT7530_P6ECR 0x7830
393#define P6_INTF_MODE_M 0x3
394#define P6_INTF_MODE_S 0
395
396/* P6_INTF_MODE: Interface mode of Port6 */
397#define P6_INTF_MODE_RGMII 0
398#define P6_INTF_MODE_TRGMII 1
399
developerd5d73952020-02-18 16:49:37 +0800400#define NUM_TRGMII_CTRL 5
401
developerc3ac93d2018-12-20 16:12:53 +0800402#define MT7530_TRGMII_RD(n) (0x7a10 + (n) * 8)
403#define RD_TAP_S 0
404#define RD_TAP_M 0x7f
405
406#define MT7530_TRGMII_TD_ODT(n) (0x7a54 + (n) * 8)
407/* XXX: all fields are defined under GMAC_TRGMII_TD_ODT */
408
developerd5d73952020-02-18 16:49:37 +0800409/* TOP Signals Status Register */
410#define MT7531_TOP_SIG_SR 0x780c
411#define PAD_MCM_SMI_EN BIT(0)
412#define PAD_DUAL_SGMII_EN BIT(1)
413
414/* MT7531 PLLGP Registers */
415#define MT7531_PLLGP_EN 0x7820
416#define EN_COREPLL BIT(2)
417#define SW_CLKSW BIT(1)
418#define SW_PLLGP BIT(0)
developerc3ac93d2018-12-20 16:12:53 +0800419
developerd5d73952020-02-18 16:49:37 +0800420#define MT7531_PLLGP_CR0 0x78a8
421#define RG_COREPLL_EN BIT(22)
422#define RG_COREPLL_POSDIV_S 23
423#define RG_COREPLL_POSDIV_M 0x3800000
424#define RG_COREPLL_SDM_PCW_S 1
425#define RG_COREPLL_SDM_PCW_M 0x3ffffe
426#define RG_COREPLL_SDM_PCW_CHG BIT(0)
427
428/* MT7531 RGMII and SGMII PLL clock */
429#define MT7531_ANA_PLLGP_CR2 0x78b0
430#define MT7531_ANA_PLLGP_CR5 0x78bc
431
432/* MT7531 GPIO GROUP IOLB SMT0 Control */
433#define MT7531_SMT0_IOLB 0x7f04
434#define SMT_IOLB_5_SMI_MDC_EN BIT(5)
435
436/* MT7530 GPHY MDIO Indirect Access Registers */
developerc3ac93d2018-12-20 16:12:53 +0800437#define MII_MMD_ACC_CTL_REG 0x0d
438#define MMD_CMD_S 14
439#define MMD_CMD_M 0xc000
440#define MMD_DEVAD_S 0
441#define MMD_DEVAD_M 0x1f
442
443/* MMD_CMD: MMD commands */
444#define MMD_ADDR 0
445#define MMD_DATA 1
446#define MMD_DATA_RW_POST_INC 2
447#define MMD_DATA_W_POST_INC 3
448
449#define MII_MMD_ADDR_DATA_REG 0x0e
450
451/* MT7530 GPHY MDIO MMD Registers */
developerc3ac93d2018-12-20 16:12:53 +0800452#define CORE_PLL_GROUP2 0x401
453#define RG_SYSPLL_EN_NORMAL BIT(15)
454#define RG_SYSPLL_VODEN BIT(14)
455#define RG_SYSPLL_POSDIV_S 5
456#define RG_SYSPLL_POSDIV_M 0x60
457
458#define CORE_PLL_GROUP4 0x403
developerd5d73952020-02-18 16:49:37 +0800459#define MT7531_BYPASS_MODE BIT(4)
460#define MT7531_POWER_ON_OFF BIT(5)
developerc3ac93d2018-12-20 16:12:53 +0800461#define RG_SYSPLL_DDSFBK_EN BIT(12)
462#define RG_SYSPLL_BIAS_EN BIT(11)
463#define RG_SYSPLL_BIAS_LPF_EN BIT(10)
464
465#define CORE_PLL_GROUP5 0x404
466#define RG_LCDDS_PCW_NCPO1_S 0
467#define RG_LCDDS_PCW_NCPO1_M 0xffff
468
469#define CORE_PLL_GROUP6 0x405
470#define RG_LCDDS_PCW_NCPO0_S 0
471#define RG_LCDDS_PCW_NCPO0_M 0xffff
472
473#define CORE_PLL_GROUP7 0x406
474#define RG_LCDDS_PWDB BIT(15)
475#define RG_LCDDS_ISO_EN BIT(13)
476#define RG_LCCDS_C_S 4
477#define RG_LCCDS_C_M 0x70
478#define RG_LCDDS_PCW_NCPO_CHG BIT(3)
479
480#define CORE_PLL_GROUP10 0x409
481#define RG_LCDDS_SSC_DELTA_S 0
482#define RG_LCDDS_SSC_DELTA_M 0xfff
483
484#define CORE_PLL_GROUP11 0x40a
485#define RG_LCDDS_SSC_DELTA1_S 0
486#define RG_LCDDS_SSC_DELTA1_M 0xfff
487
488#define CORE_GSWPLL_GRP1 0x40d
489#define RG_GSWPLL_POSDIV_200M_S 12
490#define RG_GSWPLL_POSDIV_200M_M 0x3000
491#define RG_GSWPLL_EN_PRE BIT(11)
492#define RG_GSWPLL_FBKDIV_200M_S 0
493#define RG_GSWPLL_FBKDIV_200M_M 0xff
494
495#define CORE_GSWPLL_GRP2 0x40e
496#define RG_GSWPLL_POSDIV_500M_S 8
497#define RG_GSWPLL_POSDIV_500M_M 0x300
498#define RG_GSWPLL_FBKDIV_500M_S 0
499#define RG_GSWPLL_FBKDIV_500M_M 0xff
500
501#define CORE_TRGMII_GSW_CLK_CG 0x410
502#define REG_GSWCK_EN BIT(0)
503#define REG_TRGMIICK_EN BIT(1)
504
developerd5d73952020-02-18 16:49:37 +0800505/* Extend PHY Control Register 3 */
506#define PHY_EXT_REG_14 0x14
507
508/* Fields of PHY_EXT_REG_14 */
509#define PHY_EN_DOWN_SHFIT BIT(4)
510
511/* Extend PHY Control Register 4 */
512#define PHY_EXT_REG_17 0x17
513
514/* Fields of PHY_EXT_REG_17 */
515#define PHY_LINKDOWN_POWER_SAVING_EN BIT(4)
516
517/* PHY RXADC Control Register 7 */
518#define PHY_DEV1E_REG_0C6 0x0c6
519
520/* Fields of PHY_DEV1E_REG_0C6 */
521#define PHY_POWER_SAVING_S 8
522#define PHY_POWER_SAVING_M 0x300
523#define PHY_POWER_SAVING_TX 0x0
524
developer65089f72022-09-09 19:59:24 +0800525/* PDMA descriptors */
526struct mtk_rx_dma {
527 unsigned int rxd1;
528 unsigned int rxd2;
529 unsigned int rxd3;
530 unsigned int rxd4;
531} __packed __aligned(4);
532
developera7cdebf2022-09-09 19:59:26 +0800533struct mtk_rx_dma_v2 {
534 unsigned int rxd1;
535 unsigned int rxd2;
536 unsigned int rxd3;
537 unsigned int rxd4;
538 unsigned int rxd5;
539 unsigned int rxd6;
540 unsigned int rxd7;
541 unsigned int rxd8;
542} __packed __aligned(4);
543
developer65089f72022-09-09 19:59:24 +0800544struct mtk_tx_dma {
545 unsigned int txd1;
546 unsigned int txd2;
547 unsigned int txd3;
548 unsigned int txd4;
549} __packed __aligned(4);
550
developera7cdebf2022-09-09 19:59:26 +0800551struct mtk_tx_dma_v2 {
552 unsigned int txd1;
553 unsigned int txd2;
554 unsigned int txd3;
555 unsigned int txd4;
556 unsigned int txd5;
557 unsigned int txd6;
558 unsigned int txd7;
559 unsigned int txd8;
560} __packed __aligned(4);
561
developer65089f72022-09-09 19:59:24 +0800562/* PDMA TXD fields */
563#define PDMA_TXD2_DDONE BIT(31)
564#define PDMA_TXD2_LS0 BIT(30)
developera7cdebf2022-09-09 19:59:26 +0800565#define PDMA_V1_TXD2_SDL0_M GENMASK(29, 16)
566#define PDMA_V1_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V1_TXD2_SDL0_M, (_v))
567#define PDMA_V2_TXD2_SDL0_M GENMASK(23, 8)
568#define PDMA_V2_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V2_TXD2_SDL0_M, (_v))
developer65089f72022-09-09 19:59:24 +0800569
developera7cdebf2022-09-09 19:59:26 +0800570#define PDMA_V1_TXD4_FPORT_M GENMASK(27, 25)
571#define PDMA_V1_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V1_TXD4_FPORT_M, (_v))
572#define PDMA_V2_TXD4_FPORT_M GENMASK(27, 24)
573#define PDMA_V2_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD4_FPORT_M, (_v))
574
575#define PDMA_V2_TXD5_FPORT_M GENMASK(19, 16)
576#define PDMA_V2_TXD5_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD5_FPORT_M, (_v))
developer65089f72022-09-09 19:59:24 +0800577
578/* PDMA RXD fields */
579#define PDMA_RXD2_DDONE BIT(31)
580#define PDMA_RXD2_LS0 BIT(30)
developera7cdebf2022-09-09 19:59:26 +0800581#define PDMA_V1_RXD2_PLEN0_M GENMASK(29, 16)
582#define PDMA_V1_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V1_RXD2_PLEN0_M, (_v))
583#define PDMA_V1_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V1_RXD2_PLEN0_M, (_v))
584#define PDMA_V2_RXD2_PLEN0_M GENMASK(23, 8)
585#define PDMA_V2_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V2_RXD2_PLEN0_M, (_v))
586#define PDMA_V2_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V2_RXD2_PLEN0_M, (_v))
developer65089f72022-09-09 19:59:24 +0800587
developerc3ac93d2018-12-20 16:12:53 +0800588#endif /* _MTK_ETH_H_ */