blob: 1aa037907c5991a2d5da40b3321e53e83208fd0b [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,
developer2da7d4a2024-12-17 16:39:41 +080026 MTK_ETH_PATH_MT7622_SGMII_BIT,
developere8f42692024-12-17 16:39:46 +080027 MTK_ETH_PATH_MT7629_GMAC2_BIT,
developer1d3b1f62022-09-09 19:59:21 +080028};
29
30#define MTK_TRGMII BIT(MTK_TRGMII_BIT)
31#define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT)
developera5d712a2023-07-19 17:17:22 +080032#define MTK_U3_COPHY_V2 BIT(MTK_U3_COPHY_V2_BIT)
33#define MTK_INFRA BIT(MTK_INFRA_BIT)
developera7cdebf2022-09-09 19:59:26 +080034#define MTK_NETSYS_V2 BIT(MTK_NETSYS_V2_BIT)
developer78fed682023-07-19 17:17:37 +080035#define MTK_NETSYS_V3 BIT(MTK_NETSYS_V3_BIT)
developer1d3b1f62022-09-09 19:59:21 +080036
37/* Supported path present on SoCs */
38#define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
39
developera5d712a2023-07-19 17:17:22 +080040#define MTK_ETH_PATH_GMAC2_SGMII BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
developer2da7d4a2024-12-17 16:39:41 +080041#define MTK_ETH_PATH_MT7622_SGMII BIT(MTK_ETH_PATH_MT7622_SGMII_BIT)
developere8f42692024-12-17 16:39:46 +080042#define MTK_ETH_PATH_MT7629_GMAC2 BIT(MTK_ETH_PATH_MT7629_GMAC2_BIT)
developera5d712a2023-07-19 17:17:22 +080043
developer1d3b1f62022-09-09 19:59:21 +080044#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
45
developera5d712a2023-07-19 17:17:22 +080046#define MTK_GMAC2_U3_QPHY (MTK_ETH_PATH_GMAC2_SGMII | MTK_U3_COPHY_V2 | MTK_INFRA)
47
developer1d3b1f62022-09-09 19:59:21 +080048#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
49
50#define MT7621_CAPS (MTK_GMAC1_TRGMII | MTK_TRGMII_MT7621_CLK)
51
developer2da7d4a2024-12-17 16:39:41 +080052#define MT7622_CAPS (MTK_ETH_PATH_MT7622_SGMII)
53
developer1d3b1f62022-09-09 19:59:21 +080054#define MT7623_CAPS (MTK_GMAC1_TRGMII)
55
developere8f42692024-12-17 16:39:46 +080056#define MT7629_CAPS (MTK_ETH_PATH_MT7629_GMAC2 | MTK_INFRA)
57
developera5d712a2023-07-19 17:17:22 +080058#define MT7981_CAPS (MTK_GMAC2_U3_QPHY | MTK_NETSYS_V2)
59
developer053929c2022-09-09 19:59:28 +080060#define MT7986_CAPS (MTK_NETSYS_V2)
61
developer76e14722023-07-19 17:17:41 +080062#define MT7988_CAPS (MTK_NETSYS_V3 | MTK_INFRA)
63
developer1d3b1f62022-09-09 19:59:21 +080064/* Frame Engine Register Bases */
developera7cdebf2022-09-09 19:59:26 +080065#define PDMA_V1_BASE 0x0800
66#define PDMA_V2_BASE 0x6000
developer78fed682023-07-19 17:17:37 +080067#define PDMA_V3_BASE 0x6800
developerc3ac93d2018-12-20 16:12:53 +080068#define GDMA1_BASE 0x0500
69#define GDMA2_BASE 0x1500
developer78fed682023-07-19 17:17:37 +080070#define GDMA3_BASE 0x0540
developerc3ac93d2018-12-20 16:12:53 +080071#define GMAC_BASE 0x10000
developer76e14722023-07-19 17:17:41 +080072#define GSW_BASE 0x20000
developerc3ac93d2018-12-20 16:12:53 +080073
74/* Ethernet subsystem registers */
75
developer0b584952024-12-17 16:39:27 +080076#define ETHSYS_SYSCFG1_REG 0x14
77#define SYSCFG1_GE_MODE_S(n) (12 + ((n) * 2))
78#define SYSCFG1_GE_MODE_M 0x3
developer2da7d4a2024-12-17 16:39:41 +080079#define SYSCFG1_SGMII_SEL_M GENMASK(9, 8)
80#define SYSCFG1_SGMII_SEL(gmac) BIT(9 - (gmac))
developerc3ac93d2018-12-20 16:12:53 +080081
82#define ETHSYS_CLKCFG0_REG 0x2c
83#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
84
developera5d712a2023-07-19 17:17:22 +080085/* Top misc registers */
developer03ce27b2023-07-19 17:17:31 +080086#define TOPMISC_NETSYS_PCS_MUX 0x84
87#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
88#define MUX_G2_USXGMII_SEL BIT(1)
89#define MUX_HSGMII1_G1_SEL BIT(0)
90
developera5d712a2023-07-19 17:17:22 +080091#define USB_PHY_SWITCH_REG 0x218
92#define QPHY_SEL_MASK 0x3
93#define SGMII_QPHY_SEL 0x2
94
developere8f42692024-12-17 16:39:46 +080095#define MT7629_INFRA_MISC2_REG 0x70c
96#define INFRA_MISC2_BONDING_OPTION GENMASK(15, 0)
97
developer0b584952024-12-17 16:39:27 +080098/* SYSCFG1_GE_MODE: GE Modes */
developerc3ac93d2018-12-20 16:12:53 +080099#define GE_MODE_RGMII 0
100#define GE_MODE_MII 1
101#define GE_MODE_MII_PHY 2
102#define GE_MODE_RMII 3
103
developer9a12c242020-01-21 19:31:57 +0800104/* SGMII subsystem config registers */
105#define SGMSYS_PCS_CONTROL_1 0x0
developerd5d73952020-02-18 16:49:37 +0800106#define SGMII_LINK_STATUS BIT(18)
developer9a12c242020-01-21 19:31:57 +0800107#define SGMII_AN_ENABLE BIT(12)
developerd5d73952020-02-18 16:49:37 +0800108#define SGMII_AN_RESTART BIT(9)
developer9a12c242020-01-21 19:31:57 +0800109
110#define SGMSYS_SGMII_MODE 0x20
developer4aafc992023-07-19 17:17:13 +0800111#define SGMII_AN_MODE 0x31120103
developer9a12c242020-01-21 19:31:57 +0800112#define SGMII_FORCE_MODE 0x31120019
113
114#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
115#define SGMII_PHYA_PWD BIT(4)
116
developer053929c2022-09-09 19:59:28 +0800117#define SGMSYS_QPHY_WRAP_CTRL 0xec
118#define SGMII_PN_SWAP_TX_RX 0x03
119
developer9a12c242020-01-21 19:31:57 +0800120#define SGMSYS_GEN2_SPEED 0x2028
developerf6f0ccb2020-06-19 19:17:16 +0800121#define SGMSYS_GEN2_SPEED_V2 0x128
developer0535efd2024-12-17 16:39:23 +0800122#define SGMSYS_SPEED_MASK GENMASK(3, 2)
123#define SGMSYS_SPEED_2500 1
developer9a12c242020-01-21 19:31:57 +0800124
developer03ce27b2023-07-19 17:17:31 +0800125/* USXGMII subsystem config registers */
126/* Register to control USXGMII XFI PLL digital */
127#define XFI_PLL_DIG_GLB8 0x08
128#define RG_XFI_PLL_EN BIT(31)
129
130/* Register to control USXGMII XFI PLL analog */
131#define XFI_PLL_ANA_GLB8 0x108
132#define RG_XFI_PLL_ANA_SWWA 0x02283248
133
developerc3ac93d2018-12-20 16:12:53 +0800134/* Frame Engine Registers */
developer76e14722023-07-19 17:17:41 +0800135#define PSE_NO_DROP_CFG_REG 0x108
136#define PSE_NO_DROP_GDM1 BIT(1)
137
developera7cdebf2022-09-09 19:59:26 +0800138#define FE_GLO_MISC_REG 0x124
139#define PDMA_VER_V2 BIT(4)
developerc3ac93d2018-12-20 16:12:53 +0800140
141/* PDMA */
142#define TX_BASE_PTR_REG(n) (0x000 + (n) * 0x10)
143#define TX_MAX_CNT_REG(n) (0x004 + (n) * 0x10)
144#define TX_CTX_IDX_REG(n) (0x008 + (n) * 0x10)
145#define TX_DTX_IDX_REG(n) (0x00c + (n) * 0x10)
146
147#define RX_BASE_PTR_REG(n) (0x100 + (n) * 0x10)
148#define RX_MAX_CNT_REG(n) (0x104 + (n) * 0x10)
149#define RX_CRX_IDX_REG(n) (0x108 + (n) * 0x10)
150#define RX_DRX_IDX_REG(n) (0x10c + (n) * 0x10)
151
152#define PDMA_GLO_CFG_REG 0x204
153#define TX_WB_DDONE BIT(6)
154#define RX_DMA_BUSY BIT(3)
155#define RX_DMA_EN BIT(2)
156#define TX_DMA_BUSY BIT(1)
157#define TX_DMA_EN BIT(0)
158
159#define PDMA_RST_IDX_REG 0x208
160#define RST_DRX_IDX0 BIT(16)
161#define RST_DTX_IDX0 BIT(0)
162
163/* GDMA */
164#define GDMA_IG_CTRL_REG 0x000
165#define GDM_ICS_EN BIT(22)
166#define GDM_TCS_EN BIT(21)
167#define GDM_UCS_EN BIT(20)
168#define STRP_CRC BIT(16)
169#define MYMAC_DP_S 12
170#define MYMAC_DP_M 0xf000
171#define BC_DP_S 8
172#define BC_DP_M 0xf00
173#define MC_DP_S 4
174#define MC_DP_M 0xf0
175#define UN_DP_S 0
176#define UN_DP_M 0x0f
177
developer78fed682023-07-19 17:17:37 +0800178#define GDMA_EG_CTRL_REG 0x004
179#define GDMA_CPU_BRIDGE_EN BIT(31)
180
developerc3ac93d2018-12-20 16:12:53 +0800181#define GDMA_MAC_LSB_REG 0x008
182
183#define GDMA_MAC_MSB_REG 0x00c
184
185/* MYMAC_DP/BC_DP/MC_DP/UN_DP: Destination ports */
186#define DP_PDMA 0
187#define DP_GDMA1 1
188#define DP_GDMA2 2
189#define DP_PPE 4
190#define DP_QDMA 5
191#define DP_DISCARD 7
192
193/* GMAC Registers */
194
developer4843ad32024-01-22 10:08:11 +0800195#define GMAC_PPSC_REG 0x0000
196#define PHY_MDC_CFG GENMASK(29, 24)
197#define MDC_TURBO BIT(20)
198#define MDC_MAX_FREQ 25000000
199#define MDC_MAX_DIVIDER 63
200
developerc3ac93d2018-12-20 16:12:53 +0800201#define GMAC_PIAC_REG 0x0004
202#define PHY_ACS_ST BIT(31)
203#define MDIO_REG_ADDR_S 25
204#define MDIO_REG_ADDR_M 0x3e000000
205#define MDIO_PHY_ADDR_S 20
206#define MDIO_PHY_ADDR_M 0x1f00000
207#define MDIO_CMD_S 18
208#define MDIO_CMD_M 0xc0000
209#define MDIO_ST_S 16
210#define MDIO_ST_M 0x30000
211#define MDIO_RW_DATA_S 0
212#define MDIO_RW_DATA_M 0xffff
213
developer76e14722023-07-19 17:17:41 +0800214#define GMAC_XGMAC_STS_REG 0x000c
215#define P1_XGMAC_FORCE_LINK BIT(15)
216
217#define GMAC_MAC_MISC_REG 0x0010
developer4843ad32024-01-22 10:08:11 +0800218#define MISC_MDC_TURBO BIT(4)
developer76e14722023-07-19 17:17:41 +0800219
220#define GMAC_GSW_CFG_REG 0x0080
221#define GSWTX_IPG_M 0xF0000
222#define GSWTX_IPG_S 16
223#define GSWRX_IPG_M 0xF
224#define GSWRX_IPG_S 0
225
developerc3ac93d2018-12-20 16:12:53 +0800226/* MDIO_CMD: MDIO commands */
227#define MDIO_CMD_ADDR 0
228#define MDIO_CMD_WRITE 1
229#define MDIO_CMD_READ 2
230#define MDIO_CMD_READ_C45 3
231
232/* MDIO_ST: MDIO start field */
233#define MDIO_ST_C45 0
234#define MDIO_ST_C22 1
235
236#define GMAC_PORT_MCR(p) (0x0100 + (p) * 0x100)
237#define MAC_RX_PKT_LEN_S 24
238#define MAC_RX_PKT_LEN_M 0x3000000
239#define IPG_CFG_S 18
240#define IPG_CFG_M 0xc0000
241#define MAC_MODE BIT(16)
242#define FORCE_MODE BIT(15)
243#define MAC_TX_EN BIT(14)
244#define MAC_RX_EN BIT(13)
developer4aafc992023-07-19 17:17:13 +0800245#define DEL_RXFIFO_CLR BIT(12)
developerc3ac93d2018-12-20 16:12:53 +0800246#define BKOFF_EN BIT(9)
247#define BACKPR_EN BIT(8)
248#define FORCE_RX_FC BIT(5)
249#define FORCE_TX_FC BIT(4)
250#define FORCE_SPD_S 2
251#define FORCE_SPD_M 0x0c
252#define FORCE_DPX BIT(1)
253#define FORCE_LINK BIT(0)
254
developerd5d73952020-02-18 16:49:37 +0800255/* Values of IPG_CFG */
256#define IPG_96BIT 0
257#define IPG_96BIT_WITH_SHORT_IPG 1
258#define IPG_64BIT 2
259
developerc3ac93d2018-12-20 16:12:53 +0800260/* MAC_RX_PKT_LEN: Max RX packet length */
261#define MAC_RX_PKT_LEN_1518 0
262#define MAC_RX_PKT_LEN_1536 1
263#define MAC_RX_PKT_LEN_1552 2
264#define MAC_RX_PKT_LEN_JUMBO 3
265
266/* FORCE_SPD: Forced link speed */
267#define SPEED_10M 0
268#define SPEED_100M 1
269#define SPEED_1000M 2
270
271#define GMAC_TRGMII_RCK_CTRL 0x300
272#define RX_RST BIT(31)
273#define RXC_DQSISEL BIT(30)
274
275#define GMAC_TRGMII_TD_ODT(n) (0x354 + (n) * 8)
276#define TD_DM_DRVN_S 4
277#define TD_DM_DRVN_M 0xf0
278#define TD_DM_DRVP_S 0
279#define TD_DM_DRVP_M 0x0f
280
developer03ce27b2023-07-19 17:17:31 +0800281/* XGMAC Status Registers */
282#define XGMAC_STS(x) (((x) == 2) ? 0x001C : 0x000C)
developeref7b6502024-01-22 10:08:16 +0800283#define XGMAC_FORCE_LINK(x) (((x) == 1) ? BIT(31) : BIT(15))
developer03ce27b2023-07-19 17:17:31 +0800284
285/* XGMAC Registers */
286#define XGMAC_PORT_MCR(x) (0x2000 + (((x) - 1) * 0x1000))
287#define XGMAC_TRX_DISABLE 0xf
288#define XGMAC_FORCE_TX_FC BIT(5)
289#define XGMAC_FORCE_RX_FC BIT(4)
290
developerc3ac93d2018-12-20 16:12:53 +0800291/* MT7530 Registers */
292
293#define PCR_REG(p) (0x2004 + (p) * 0x100)
294#define PORT_MATRIX_S 16
295#define PORT_MATRIX_M 0xff0000
296
297#define PVC_REG(p) (0x2010 + (p) * 0x100)
298#define STAG_VPID_S 16
299#define STAG_VPID_M 0xffff0000
300#define VLAN_ATTR_S 6
301#define VLAN_ATTR_M 0xc0
302
303/* VLAN_ATTR: VLAN attributes */
304#define VLAN_ATTR_USER 0
305#define VLAN_ATTR_STACK 1
306#define VLAN_ATTR_TRANSLATION 2
307#define VLAN_ATTR_TRANSPARENT 3
308
developerd5d73952020-02-18 16:49:37 +0800309#define PMCR_REG(p) (0x3000 + (p) * 0x100)
310/* XXX: all fields of MT7530 are defined under GMAC_PORT_MCR
311 * MT7531 specific fields are defined below
312 */
313#define FORCE_MODE_EEE1G BIT(25)
314#define FORCE_MODE_EEE100 BIT(26)
315#define FORCE_MODE_TX_FC BIT(27)
316#define FORCE_MODE_RX_FC BIT(28)
317#define FORCE_MODE_DPX BIT(29)
318#define FORCE_MODE_SPD BIT(30)
319#define FORCE_MODE_LNK BIT(31)
320#define MT7531_FORCE_MODE FORCE_MODE_EEE1G | FORCE_MODE_EEE100 |\
321 FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
322 FORCE_MODE_DPX | FORCE_MODE_SPD | \
323 FORCE_MODE_LNK
developer76e14722023-07-19 17:17:41 +0800324#define MT7988_FORCE_MODE FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
325 FORCE_MODE_DPX | FORCE_MODE_SPD | \
326 FORCE_MODE_LNK
developerc3ac93d2018-12-20 16:12:53 +0800327
developerd5d73952020-02-18 16:49:37 +0800328/* MT7531 SGMII Registers */
329#define MT7531_SGMII_REG_BASE 0x5000
330#define MT7531_SGMII_REG_PORT_BASE 0x1000
331#define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \
332 (p) * MT7531_SGMII_REG_PORT_BASE + (r))
333#define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(((p) - 5), 0x00)
334#define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(((p) - 5), 0x20)
335#define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(((p) - 5), 0xe8)
336#define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(((p) - 5), 0x128)
337/* XXX: all fields of MT7531 SGMII are defined under SGMSYS */
338
339/* MT753x System Control Register */
developerc3ac93d2018-12-20 16:12:53 +0800340#define SYS_CTRL_REG 0x7000
341#define SW_PHY_RST BIT(2)
342#define SW_SYS_RST BIT(1)
343#define SW_REG_RST BIT(0)
344
developerd5d73952020-02-18 16:49:37 +0800345/* MT7531 */
346#define MT7531_PHY_IAC 0x701c
347/* XXX: all fields are defined under GMAC_PIAC_REG */
348
349#define MT7531_CLKGEN_CTRL 0x7500
350#define CLK_SKEW_OUT_S 8
351#define CLK_SKEW_OUT_M 0x300
352#define CLK_SKEW_IN_S 6
353#define CLK_SKEW_IN_M 0xc0
354#define RXCLK_NO_DELAY BIT(5)
355#define TXCLK_NO_REVERSE BIT(4)
356#define GP_MODE_S 1
357#define GP_MODE_M 0x06
358#define GP_CLK_EN BIT(0)
359
360/* Values of GP_MODE */
361#define GP_MODE_RGMII 0
362#define GP_MODE_MII 1
363#define GP_MODE_REV_MII 2
364
365/* Values of CLK_SKEW_IN */
366#define CLK_SKEW_IN_NO_CHANGE 0
367#define CLK_SKEW_IN_DELAY_100PPS 1
368#define CLK_SKEW_IN_DELAY_200PPS 2
369#define CLK_SKEW_IN_REVERSE 3
370
371/* Values of CLK_SKEW_OUT */
372#define CLK_SKEW_OUT_NO_CHANGE 0
373#define CLK_SKEW_OUT_DELAY_100PPS 1
374#define CLK_SKEW_OUT_DELAY_200PPS 2
375#define CLK_SKEW_OUT_REVERSE 3
developerc3ac93d2018-12-20 16:12:53 +0800376
377#define HWTRAP_REG 0x7800
developerd5d73952020-02-18 16:49:37 +0800378/* MT7530 Modified Hardware Trap Status Registers */
developerc3ac93d2018-12-20 16:12:53 +0800379#define MHWTRAP_REG 0x7804
380#define CHG_TRAP BIT(16)
381#define LOOPDET_DIS BIT(14)
382#define P5_INTF_SEL_S 13
383#define P5_INTF_SEL_M 0x2000
384#define SMI_ADDR_S 11
385#define SMI_ADDR_M 0x1800
386#define XTAL_FSEL_S 9
387#define XTAL_FSEL_M 0x600
388#define P6_INTF_DIS BIT(8)
389#define P5_INTF_MODE_S 7
390#define P5_INTF_MODE_M 0x80
391#define P5_INTF_DIS BIT(6)
392#define C_MDIO_BPS BIT(5)
393#define CHIP_MODE_S 0
394#define CHIP_MODE_M 0x0f
395
396/* P5_INTF_SEL: Interface type of Port5 */
397#define P5_INTF_SEL_GPHY 0
398#define P5_INTF_SEL_GMAC5 1
399
400/* P5_INTF_MODE: Interface mode of Port5 */
401#define P5_INTF_MODE_GMII_MII 0
402#define P5_INTF_MODE_RGMII 1
403
404#define MT7530_P6ECR 0x7830
405#define P6_INTF_MODE_M 0x3
406#define P6_INTF_MODE_S 0
407
408/* P6_INTF_MODE: Interface mode of Port6 */
409#define P6_INTF_MODE_RGMII 0
410#define P6_INTF_MODE_TRGMII 1
411
developerd5d73952020-02-18 16:49:37 +0800412#define NUM_TRGMII_CTRL 5
413
developerc3ac93d2018-12-20 16:12:53 +0800414#define MT7530_TRGMII_RD(n) (0x7a10 + (n) * 8)
415#define RD_TAP_S 0
416#define RD_TAP_M 0x7f
417
418#define MT7530_TRGMII_TD_ODT(n) (0x7a54 + (n) * 8)
419/* XXX: all fields are defined under GMAC_TRGMII_TD_ODT */
420
developerd5d73952020-02-18 16:49:37 +0800421/* TOP Signals Status Register */
422#define MT7531_TOP_SIG_SR 0x780c
423#define PAD_MCM_SMI_EN BIT(0)
424#define PAD_DUAL_SGMII_EN BIT(1)
425
426/* MT7531 PLLGP Registers */
427#define MT7531_PLLGP_EN 0x7820
428#define EN_COREPLL BIT(2)
429#define SW_CLKSW BIT(1)
430#define SW_PLLGP BIT(0)
developerc3ac93d2018-12-20 16:12:53 +0800431
developerd5d73952020-02-18 16:49:37 +0800432#define MT7531_PLLGP_CR0 0x78a8
433#define RG_COREPLL_EN BIT(22)
434#define RG_COREPLL_POSDIV_S 23
435#define RG_COREPLL_POSDIV_M 0x3800000
436#define RG_COREPLL_SDM_PCW_S 1
437#define RG_COREPLL_SDM_PCW_M 0x3ffffe
438#define RG_COREPLL_SDM_PCW_CHG BIT(0)
439
440/* MT7531 RGMII and SGMII PLL clock */
441#define MT7531_ANA_PLLGP_CR2 0x78b0
442#define MT7531_ANA_PLLGP_CR5 0x78bc
443
444/* MT7531 GPIO GROUP IOLB SMT0 Control */
445#define MT7531_SMT0_IOLB 0x7f04
446#define SMT_IOLB_5_SMI_MDC_EN BIT(5)
447
448/* MT7530 GPHY MDIO Indirect Access Registers */
developerc3ac93d2018-12-20 16:12:53 +0800449#define MII_MMD_ACC_CTL_REG 0x0d
450#define MMD_CMD_S 14
451#define MMD_CMD_M 0xc000
452#define MMD_DEVAD_S 0
453#define MMD_DEVAD_M 0x1f
454
455/* MMD_CMD: MMD commands */
456#define MMD_ADDR 0
457#define MMD_DATA 1
458#define MMD_DATA_RW_POST_INC 2
459#define MMD_DATA_W_POST_INC 3
460
461#define MII_MMD_ADDR_DATA_REG 0x0e
462
463/* MT7530 GPHY MDIO MMD Registers */
developerc3ac93d2018-12-20 16:12:53 +0800464#define CORE_PLL_GROUP2 0x401
465#define RG_SYSPLL_EN_NORMAL BIT(15)
466#define RG_SYSPLL_VODEN BIT(14)
467#define RG_SYSPLL_POSDIV_S 5
468#define RG_SYSPLL_POSDIV_M 0x60
469
470#define CORE_PLL_GROUP4 0x403
developerd5d73952020-02-18 16:49:37 +0800471#define MT7531_BYPASS_MODE BIT(4)
472#define MT7531_POWER_ON_OFF BIT(5)
developerc3ac93d2018-12-20 16:12:53 +0800473#define RG_SYSPLL_DDSFBK_EN BIT(12)
474#define RG_SYSPLL_BIAS_EN BIT(11)
475#define RG_SYSPLL_BIAS_LPF_EN BIT(10)
476
477#define CORE_PLL_GROUP5 0x404
478#define RG_LCDDS_PCW_NCPO1_S 0
479#define RG_LCDDS_PCW_NCPO1_M 0xffff
480
481#define CORE_PLL_GROUP6 0x405
482#define RG_LCDDS_PCW_NCPO0_S 0
483#define RG_LCDDS_PCW_NCPO0_M 0xffff
484
485#define CORE_PLL_GROUP7 0x406
486#define RG_LCDDS_PWDB BIT(15)
487#define RG_LCDDS_ISO_EN BIT(13)
488#define RG_LCCDS_C_S 4
489#define RG_LCCDS_C_M 0x70
490#define RG_LCDDS_PCW_NCPO_CHG BIT(3)
491
492#define CORE_PLL_GROUP10 0x409
493#define RG_LCDDS_SSC_DELTA_S 0
494#define RG_LCDDS_SSC_DELTA_M 0xfff
495
496#define CORE_PLL_GROUP11 0x40a
497#define RG_LCDDS_SSC_DELTA1_S 0
498#define RG_LCDDS_SSC_DELTA1_M 0xfff
499
500#define CORE_GSWPLL_GRP1 0x40d
501#define RG_GSWPLL_POSDIV_200M_S 12
502#define RG_GSWPLL_POSDIV_200M_M 0x3000
503#define RG_GSWPLL_EN_PRE BIT(11)
504#define RG_GSWPLL_FBKDIV_200M_S 0
505#define RG_GSWPLL_FBKDIV_200M_M 0xff
506
507#define CORE_GSWPLL_GRP2 0x40e
508#define RG_GSWPLL_POSDIV_500M_S 8
509#define RG_GSWPLL_POSDIV_500M_M 0x300
510#define RG_GSWPLL_FBKDIV_500M_S 0
511#define RG_GSWPLL_FBKDIV_500M_M 0xff
512
513#define CORE_TRGMII_GSW_CLK_CG 0x410
514#define REG_GSWCK_EN BIT(0)
515#define REG_TRGMIICK_EN BIT(1)
516
developerd5d73952020-02-18 16:49:37 +0800517/* Extend PHY Control Register 3 */
518#define PHY_EXT_REG_14 0x14
519
520/* Fields of PHY_EXT_REG_14 */
521#define PHY_EN_DOWN_SHFIT BIT(4)
522
523/* Extend PHY Control Register 4 */
524#define PHY_EXT_REG_17 0x17
525
526/* Fields of PHY_EXT_REG_17 */
527#define PHY_LINKDOWN_POWER_SAVING_EN BIT(4)
528
529/* PHY RXADC Control Register 7 */
530#define PHY_DEV1E_REG_0C6 0x0c6
531
532/* Fields of PHY_DEV1E_REG_0C6 */
533#define PHY_POWER_SAVING_S 8
534#define PHY_POWER_SAVING_M 0x300
535#define PHY_POWER_SAVING_TX 0x0
536
developer65089f72022-09-09 19:59:24 +0800537/* PDMA descriptors */
538struct mtk_rx_dma {
539 unsigned int rxd1;
540 unsigned int rxd2;
541 unsigned int rxd3;
542 unsigned int rxd4;
543} __packed __aligned(4);
544
developera7cdebf2022-09-09 19:59:26 +0800545struct mtk_rx_dma_v2 {
546 unsigned int rxd1;
547 unsigned int rxd2;
548 unsigned int rxd3;
549 unsigned int rxd4;
550 unsigned int rxd5;
551 unsigned int rxd6;
552 unsigned int rxd7;
553 unsigned int rxd8;
554} __packed __aligned(4);
555
developer65089f72022-09-09 19:59:24 +0800556struct mtk_tx_dma {
557 unsigned int txd1;
558 unsigned int txd2;
559 unsigned int txd3;
560 unsigned int txd4;
561} __packed __aligned(4);
562
developera7cdebf2022-09-09 19:59:26 +0800563struct mtk_tx_dma_v2 {
564 unsigned int txd1;
565 unsigned int txd2;
566 unsigned int txd3;
567 unsigned int txd4;
568 unsigned int txd5;
569 unsigned int txd6;
570 unsigned int txd7;
571 unsigned int txd8;
572} __packed __aligned(4);
573
developer65089f72022-09-09 19:59:24 +0800574/* PDMA TXD fields */
575#define PDMA_TXD2_DDONE BIT(31)
576#define PDMA_TXD2_LS0 BIT(30)
developera7cdebf2022-09-09 19:59:26 +0800577#define PDMA_V1_TXD2_SDL0_M GENMASK(29, 16)
578#define PDMA_V1_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V1_TXD2_SDL0_M, (_v))
579#define PDMA_V2_TXD2_SDL0_M GENMASK(23, 8)
580#define PDMA_V2_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V2_TXD2_SDL0_M, (_v))
developer65089f72022-09-09 19:59:24 +0800581
developera7cdebf2022-09-09 19:59:26 +0800582#define PDMA_V1_TXD4_FPORT_M GENMASK(27, 25)
583#define PDMA_V1_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V1_TXD4_FPORT_M, (_v))
584#define PDMA_V2_TXD4_FPORT_M GENMASK(27, 24)
585#define PDMA_V2_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD4_FPORT_M, (_v))
586
587#define PDMA_V2_TXD5_FPORT_M GENMASK(19, 16)
588#define PDMA_V2_TXD5_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD5_FPORT_M, (_v))
developer65089f72022-09-09 19:59:24 +0800589
590/* PDMA RXD fields */
591#define PDMA_RXD2_DDONE BIT(31)
592#define PDMA_RXD2_LS0 BIT(30)
developera7cdebf2022-09-09 19:59:26 +0800593#define PDMA_V1_RXD2_PLEN0_M GENMASK(29, 16)
594#define PDMA_V1_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V1_RXD2_PLEN0_M, (_v))
595#define PDMA_V1_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V1_RXD2_PLEN0_M, (_v))
596#define PDMA_V2_RXD2_PLEN0_M GENMASK(23, 8)
597#define PDMA_V2_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V2_RXD2_PLEN0_M, (_v))
598#define PDMA_V2_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V2_RXD2_PLEN0_M, (_v))
developer65089f72022-09-09 19:59:24 +0800599
developerc3ac93d2018-12-20 16:12:53 +0800600#endif /* _MTK_ETH_H_ */