blob: 896dd6636c76cd5efc059364d156ac79f373706f [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
developer0b584952024-12-17 16:39:27 +080068#define ETHSYS_SYSCFG1_REG 0x14
69#define SYSCFG1_GE_MODE_S(n) (12 + ((n) * 2))
70#define SYSCFG1_GE_MODE_M 0x3
71#define SYSCFG1_SGMII_SEL_M (0x3 << 8)
72#define SYSCFG1_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
developer0b584952024-12-17 16:39:27 +080087/* SYSCFG1_GE_MODE: GE Modes */
developerc3ac93d2018-12-20 16:12:53 +080088#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
developer0535efd2024-12-17 16:39:23 +0800111#define SGMSYS_SPEED_MASK GENMASK(3, 2)
112#define SGMSYS_SPEED_2500 1
developer9a12c242020-01-21 19:31:57 +0800113
developer03ce27b2023-07-19 17:17:31 +0800114/* USXGMII subsystem config registers */
115/* Register to control USXGMII XFI PLL digital */
116#define XFI_PLL_DIG_GLB8 0x08
117#define RG_XFI_PLL_EN BIT(31)
118
119/* Register to control USXGMII XFI PLL analog */
120#define XFI_PLL_ANA_GLB8 0x108
121#define RG_XFI_PLL_ANA_SWWA 0x02283248
122
developerc3ac93d2018-12-20 16:12:53 +0800123/* Frame Engine Registers */
developer76e14722023-07-19 17:17:41 +0800124#define PSE_NO_DROP_CFG_REG 0x108
125#define PSE_NO_DROP_GDM1 BIT(1)
126
developera7cdebf2022-09-09 19:59:26 +0800127#define FE_GLO_MISC_REG 0x124
128#define PDMA_VER_V2 BIT(4)
developerc3ac93d2018-12-20 16:12:53 +0800129
130/* PDMA */
131#define TX_BASE_PTR_REG(n) (0x000 + (n) * 0x10)
132#define TX_MAX_CNT_REG(n) (0x004 + (n) * 0x10)
133#define TX_CTX_IDX_REG(n) (0x008 + (n) * 0x10)
134#define TX_DTX_IDX_REG(n) (0x00c + (n) * 0x10)
135
136#define RX_BASE_PTR_REG(n) (0x100 + (n) * 0x10)
137#define RX_MAX_CNT_REG(n) (0x104 + (n) * 0x10)
138#define RX_CRX_IDX_REG(n) (0x108 + (n) * 0x10)
139#define RX_DRX_IDX_REG(n) (0x10c + (n) * 0x10)
140
141#define PDMA_GLO_CFG_REG 0x204
142#define TX_WB_DDONE BIT(6)
143#define RX_DMA_BUSY BIT(3)
144#define RX_DMA_EN BIT(2)
145#define TX_DMA_BUSY BIT(1)
146#define TX_DMA_EN BIT(0)
147
148#define PDMA_RST_IDX_REG 0x208
149#define RST_DRX_IDX0 BIT(16)
150#define RST_DTX_IDX0 BIT(0)
151
152/* GDMA */
153#define GDMA_IG_CTRL_REG 0x000
154#define GDM_ICS_EN BIT(22)
155#define GDM_TCS_EN BIT(21)
156#define GDM_UCS_EN BIT(20)
157#define STRP_CRC BIT(16)
158#define MYMAC_DP_S 12
159#define MYMAC_DP_M 0xf000
160#define BC_DP_S 8
161#define BC_DP_M 0xf00
162#define MC_DP_S 4
163#define MC_DP_M 0xf0
164#define UN_DP_S 0
165#define UN_DP_M 0x0f
166
developer78fed682023-07-19 17:17:37 +0800167#define GDMA_EG_CTRL_REG 0x004
168#define GDMA_CPU_BRIDGE_EN BIT(31)
169
developerc3ac93d2018-12-20 16:12:53 +0800170#define GDMA_MAC_LSB_REG 0x008
171
172#define GDMA_MAC_MSB_REG 0x00c
173
174/* MYMAC_DP/BC_DP/MC_DP/UN_DP: Destination ports */
175#define DP_PDMA 0
176#define DP_GDMA1 1
177#define DP_GDMA2 2
178#define DP_PPE 4
179#define DP_QDMA 5
180#define DP_DISCARD 7
181
182/* GMAC Registers */
183
developer4843ad32024-01-22 10:08:11 +0800184#define GMAC_PPSC_REG 0x0000
185#define PHY_MDC_CFG GENMASK(29, 24)
186#define MDC_TURBO BIT(20)
187#define MDC_MAX_FREQ 25000000
188#define MDC_MAX_DIVIDER 63
189
developerc3ac93d2018-12-20 16:12:53 +0800190#define GMAC_PIAC_REG 0x0004
191#define PHY_ACS_ST BIT(31)
192#define MDIO_REG_ADDR_S 25
193#define MDIO_REG_ADDR_M 0x3e000000
194#define MDIO_PHY_ADDR_S 20
195#define MDIO_PHY_ADDR_M 0x1f00000
196#define MDIO_CMD_S 18
197#define MDIO_CMD_M 0xc0000
198#define MDIO_ST_S 16
199#define MDIO_ST_M 0x30000
200#define MDIO_RW_DATA_S 0
201#define MDIO_RW_DATA_M 0xffff
202
developer76e14722023-07-19 17:17:41 +0800203#define GMAC_XGMAC_STS_REG 0x000c
204#define P1_XGMAC_FORCE_LINK BIT(15)
205
206#define GMAC_MAC_MISC_REG 0x0010
developer4843ad32024-01-22 10:08:11 +0800207#define MISC_MDC_TURBO BIT(4)
developer76e14722023-07-19 17:17:41 +0800208
209#define GMAC_GSW_CFG_REG 0x0080
210#define GSWTX_IPG_M 0xF0000
211#define GSWTX_IPG_S 16
212#define GSWRX_IPG_M 0xF
213#define GSWRX_IPG_S 0
214
developerc3ac93d2018-12-20 16:12:53 +0800215/* MDIO_CMD: MDIO commands */
216#define MDIO_CMD_ADDR 0
217#define MDIO_CMD_WRITE 1
218#define MDIO_CMD_READ 2
219#define MDIO_CMD_READ_C45 3
220
221/* MDIO_ST: MDIO start field */
222#define MDIO_ST_C45 0
223#define MDIO_ST_C22 1
224
225#define GMAC_PORT_MCR(p) (0x0100 + (p) * 0x100)
226#define MAC_RX_PKT_LEN_S 24
227#define MAC_RX_PKT_LEN_M 0x3000000
228#define IPG_CFG_S 18
229#define IPG_CFG_M 0xc0000
230#define MAC_MODE BIT(16)
231#define FORCE_MODE BIT(15)
232#define MAC_TX_EN BIT(14)
233#define MAC_RX_EN BIT(13)
developer4aafc992023-07-19 17:17:13 +0800234#define DEL_RXFIFO_CLR BIT(12)
developerc3ac93d2018-12-20 16:12:53 +0800235#define BKOFF_EN BIT(9)
236#define BACKPR_EN BIT(8)
237#define FORCE_RX_FC BIT(5)
238#define FORCE_TX_FC BIT(4)
239#define FORCE_SPD_S 2
240#define FORCE_SPD_M 0x0c
241#define FORCE_DPX BIT(1)
242#define FORCE_LINK BIT(0)
243
developerd5d73952020-02-18 16:49:37 +0800244/* Values of IPG_CFG */
245#define IPG_96BIT 0
246#define IPG_96BIT_WITH_SHORT_IPG 1
247#define IPG_64BIT 2
248
developerc3ac93d2018-12-20 16:12:53 +0800249/* MAC_RX_PKT_LEN: Max RX packet length */
250#define MAC_RX_PKT_LEN_1518 0
251#define MAC_RX_PKT_LEN_1536 1
252#define MAC_RX_PKT_LEN_1552 2
253#define MAC_RX_PKT_LEN_JUMBO 3
254
255/* FORCE_SPD: Forced link speed */
256#define SPEED_10M 0
257#define SPEED_100M 1
258#define SPEED_1000M 2
259
260#define GMAC_TRGMII_RCK_CTRL 0x300
261#define RX_RST BIT(31)
262#define RXC_DQSISEL BIT(30)
263
264#define GMAC_TRGMII_TD_ODT(n) (0x354 + (n) * 8)
265#define TD_DM_DRVN_S 4
266#define TD_DM_DRVN_M 0xf0
267#define TD_DM_DRVP_S 0
268#define TD_DM_DRVP_M 0x0f
269
developer03ce27b2023-07-19 17:17:31 +0800270/* XGMAC Status Registers */
271#define XGMAC_STS(x) (((x) == 2) ? 0x001C : 0x000C)
developeref7b6502024-01-22 10:08:16 +0800272#define XGMAC_FORCE_LINK(x) (((x) == 1) ? BIT(31) : BIT(15))
developer03ce27b2023-07-19 17:17:31 +0800273
274/* XGMAC Registers */
275#define XGMAC_PORT_MCR(x) (0x2000 + (((x) - 1) * 0x1000))
276#define XGMAC_TRX_DISABLE 0xf
277#define XGMAC_FORCE_TX_FC BIT(5)
278#define XGMAC_FORCE_RX_FC BIT(4)
279
developerc3ac93d2018-12-20 16:12:53 +0800280/* MT7530 Registers */
281
282#define PCR_REG(p) (0x2004 + (p) * 0x100)
283#define PORT_MATRIX_S 16
284#define PORT_MATRIX_M 0xff0000
285
286#define PVC_REG(p) (0x2010 + (p) * 0x100)
287#define STAG_VPID_S 16
288#define STAG_VPID_M 0xffff0000
289#define VLAN_ATTR_S 6
290#define VLAN_ATTR_M 0xc0
291
292/* VLAN_ATTR: VLAN attributes */
293#define VLAN_ATTR_USER 0
294#define VLAN_ATTR_STACK 1
295#define VLAN_ATTR_TRANSLATION 2
296#define VLAN_ATTR_TRANSPARENT 3
297
developerd5d73952020-02-18 16:49:37 +0800298#define PMCR_REG(p) (0x3000 + (p) * 0x100)
299/* XXX: all fields of MT7530 are defined under GMAC_PORT_MCR
300 * MT7531 specific fields are defined below
301 */
302#define FORCE_MODE_EEE1G BIT(25)
303#define FORCE_MODE_EEE100 BIT(26)
304#define FORCE_MODE_TX_FC BIT(27)
305#define FORCE_MODE_RX_FC BIT(28)
306#define FORCE_MODE_DPX BIT(29)
307#define FORCE_MODE_SPD BIT(30)
308#define FORCE_MODE_LNK BIT(31)
309#define MT7531_FORCE_MODE FORCE_MODE_EEE1G | FORCE_MODE_EEE100 |\
310 FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
311 FORCE_MODE_DPX | FORCE_MODE_SPD | \
312 FORCE_MODE_LNK
developer76e14722023-07-19 17:17:41 +0800313#define MT7988_FORCE_MODE FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
314 FORCE_MODE_DPX | FORCE_MODE_SPD | \
315 FORCE_MODE_LNK
developerc3ac93d2018-12-20 16:12:53 +0800316
developerd5d73952020-02-18 16:49:37 +0800317/* MT7531 SGMII Registers */
318#define MT7531_SGMII_REG_BASE 0x5000
319#define MT7531_SGMII_REG_PORT_BASE 0x1000
320#define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \
321 (p) * MT7531_SGMII_REG_PORT_BASE + (r))
322#define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(((p) - 5), 0x00)
323#define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(((p) - 5), 0x20)
324#define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(((p) - 5), 0xe8)
325#define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(((p) - 5), 0x128)
326/* XXX: all fields of MT7531 SGMII are defined under SGMSYS */
327
328/* MT753x System Control Register */
developerc3ac93d2018-12-20 16:12:53 +0800329#define SYS_CTRL_REG 0x7000
330#define SW_PHY_RST BIT(2)
331#define SW_SYS_RST BIT(1)
332#define SW_REG_RST BIT(0)
333
developerd5d73952020-02-18 16:49:37 +0800334/* MT7531 */
335#define MT7531_PHY_IAC 0x701c
336/* XXX: all fields are defined under GMAC_PIAC_REG */
337
338#define MT7531_CLKGEN_CTRL 0x7500
339#define CLK_SKEW_OUT_S 8
340#define CLK_SKEW_OUT_M 0x300
341#define CLK_SKEW_IN_S 6
342#define CLK_SKEW_IN_M 0xc0
343#define RXCLK_NO_DELAY BIT(5)
344#define TXCLK_NO_REVERSE BIT(4)
345#define GP_MODE_S 1
346#define GP_MODE_M 0x06
347#define GP_CLK_EN BIT(0)
348
349/* Values of GP_MODE */
350#define GP_MODE_RGMII 0
351#define GP_MODE_MII 1
352#define GP_MODE_REV_MII 2
353
354/* Values of CLK_SKEW_IN */
355#define CLK_SKEW_IN_NO_CHANGE 0
356#define CLK_SKEW_IN_DELAY_100PPS 1
357#define CLK_SKEW_IN_DELAY_200PPS 2
358#define CLK_SKEW_IN_REVERSE 3
359
360/* Values of CLK_SKEW_OUT */
361#define CLK_SKEW_OUT_NO_CHANGE 0
362#define CLK_SKEW_OUT_DELAY_100PPS 1
363#define CLK_SKEW_OUT_DELAY_200PPS 2
364#define CLK_SKEW_OUT_REVERSE 3
developerc3ac93d2018-12-20 16:12:53 +0800365
366#define HWTRAP_REG 0x7800
developerd5d73952020-02-18 16:49:37 +0800367/* MT7530 Modified Hardware Trap Status Registers */
developerc3ac93d2018-12-20 16:12:53 +0800368#define MHWTRAP_REG 0x7804
369#define CHG_TRAP BIT(16)
370#define LOOPDET_DIS BIT(14)
371#define P5_INTF_SEL_S 13
372#define P5_INTF_SEL_M 0x2000
373#define SMI_ADDR_S 11
374#define SMI_ADDR_M 0x1800
375#define XTAL_FSEL_S 9
376#define XTAL_FSEL_M 0x600
377#define P6_INTF_DIS BIT(8)
378#define P5_INTF_MODE_S 7
379#define P5_INTF_MODE_M 0x80
380#define P5_INTF_DIS BIT(6)
381#define C_MDIO_BPS BIT(5)
382#define CHIP_MODE_S 0
383#define CHIP_MODE_M 0x0f
384
385/* P5_INTF_SEL: Interface type of Port5 */
386#define P5_INTF_SEL_GPHY 0
387#define P5_INTF_SEL_GMAC5 1
388
389/* P5_INTF_MODE: Interface mode of Port5 */
390#define P5_INTF_MODE_GMII_MII 0
391#define P5_INTF_MODE_RGMII 1
392
393#define MT7530_P6ECR 0x7830
394#define P6_INTF_MODE_M 0x3
395#define P6_INTF_MODE_S 0
396
397/* P6_INTF_MODE: Interface mode of Port6 */
398#define P6_INTF_MODE_RGMII 0
399#define P6_INTF_MODE_TRGMII 1
400
developerd5d73952020-02-18 16:49:37 +0800401#define NUM_TRGMII_CTRL 5
402
developerc3ac93d2018-12-20 16:12:53 +0800403#define MT7530_TRGMII_RD(n) (0x7a10 + (n) * 8)
404#define RD_TAP_S 0
405#define RD_TAP_M 0x7f
406
407#define MT7530_TRGMII_TD_ODT(n) (0x7a54 + (n) * 8)
408/* XXX: all fields are defined under GMAC_TRGMII_TD_ODT */
409
developerd5d73952020-02-18 16:49:37 +0800410/* TOP Signals Status Register */
411#define MT7531_TOP_SIG_SR 0x780c
412#define PAD_MCM_SMI_EN BIT(0)
413#define PAD_DUAL_SGMII_EN BIT(1)
414
415/* MT7531 PLLGP Registers */
416#define MT7531_PLLGP_EN 0x7820
417#define EN_COREPLL BIT(2)
418#define SW_CLKSW BIT(1)
419#define SW_PLLGP BIT(0)
developerc3ac93d2018-12-20 16:12:53 +0800420
developerd5d73952020-02-18 16:49:37 +0800421#define MT7531_PLLGP_CR0 0x78a8
422#define RG_COREPLL_EN BIT(22)
423#define RG_COREPLL_POSDIV_S 23
424#define RG_COREPLL_POSDIV_M 0x3800000
425#define RG_COREPLL_SDM_PCW_S 1
426#define RG_COREPLL_SDM_PCW_M 0x3ffffe
427#define RG_COREPLL_SDM_PCW_CHG BIT(0)
428
429/* MT7531 RGMII and SGMII PLL clock */
430#define MT7531_ANA_PLLGP_CR2 0x78b0
431#define MT7531_ANA_PLLGP_CR5 0x78bc
432
433/* MT7531 GPIO GROUP IOLB SMT0 Control */
434#define MT7531_SMT0_IOLB 0x7f04
435#define SMT_IOLB_5_SMI_MDC_EN BIT(5)
436
437/* MT7530 GPHY MDIO Indirect Access Registers */
developerc3ac93d2018-12-20 16:12:53 +0800438#define MII_MMD_ACC_CTL_REG 0x0d
439#define MMD_CMD_S 14
440#define MMD_CMD_M 0xc000
441#define MMD_DEVAD_S 0
442#define MMD_DEVAD_M 0x1f
443
444/* MMD_CMD: MMD commands */
445#define MMD_ADDR 0
446#define MMD_DATA 1
447#define MMD_DATA_RW_POST_INC 2
448#define MMD_DATA_W_POST_INC 3
449
450#define MII_MMD_ADDR_DATA_REG 0x0e
451
452/* MT7530 GPHY MDIO MMD Registers */
developerc3ac93d2018-12-20 16:12:53 +0800453#define CORE_PLL_GROUP2 0x401
454#define RG_SYSPLL_EN_NORMAL BIT(15)
455#define RG_SYSPLL_VODEN BIT(14)
456#define RG_SYSPLL_POSDIV_S 5
457#define RG_SYSPLL_POSDIV_M 0x60
458
459#define CORE_PLL_GROUP4 0x403
developerd5d73952020-02-18 16:49:37 +0800460#define MT7531_BYPASS_MODE BIT(4)
461#define MT7531_POWER_ON_OFF BIT(5)
developerc3ac93d2018-12-20 16:12:53 +0800462#define RG_SYSPLL_DDSFBK_EN BIT(12)
463#define RG_SYSPLL_BIAS_EN BIT(11)
464#define RG_SYSPLL_BIAS_LPF_EN BIT(10)
465
466#define CORE_PLL_GROUP5 0x404
467#define RG_LCDDS_PCW_NCPO1_S 0
468#define RG_LCDDS_PCW_NCPO1_M 0xffff
469
470#define CORE_PLL_GROUP6 0x405
471#define RG_LCDDS_PCW_NCPO0_S 0
472#define RG_LCDDS_PCW_NCPO0_M 0xffff
473
474#define CORE_PLL_GROUP7 0x406
475#define RG_LCDDS_PWDB BIT(15)
476#define RG_LCDDS_ISO_EN BIT(13)
477#define RG_LCCDS_C_S 4
478#define RG_LCCDS_C_M 0x70
479#define RG_LCDDS_PCW_NCPO_CHG BIT(3)
480
481#define CORE_PLL_GROUP10 0x409
482#define RG_LCDDS_SSC_DELTA_S 0
483#define RG_LCDDS_SSC_DELTA_M 0xfff
484
485#define CORE_PLL_GROUP11 0x40a
486#define RG_LCDDS_SSC_DELTA1_S 0
487#define RG_LCDDS_SSC_DELTA1_M 0xfff
488
489#define CORE_GSWPLL_GRP1 0x40d
490#define RG_GSWPLL_POSDIV_200M_S 12
491#define RG_GSWPLL_POSDIV_200M_M 0x3000
492#define RG_GSWPLL_EN_PRE BIT(11)
493#define RG_GSWPLL_FBKDIV_200M_S 0
494#define RG_GSWPLL_FBKDIV_200M_M 0xff
495
496#define CORE_GSWPLL_GRP2 0x40e
497#define RG_GSWPLL_POSDIV_500M_S 8
498#define RG_GSWPLL_POSDIV_500M_M 0x300
499#define RG_GSWPLL_FBKDIV_500M_S 0
500#define RG_GSWPLL_FBKDIV_500M_M 0xff
501
502#define CORE_TRGMII_GSW_CLK_CG 0x410
503#define REG_GSWCK_EN BIT(0)
504#define REG_TRGMIICK_EN BIT(1)
505
developerd5d73952020-02-18 16:49:37 +0800506/* Extend PHY Control Register 3 */
507#define PHY_EXT_REG_14 0x14
508
509/* Fields of PHY_EXT_REG_14 */
510#define PHY_EN_DOWN_SHFIT BIT(4)
511
512/* Extend PHY Control Register 4 */
513#define PHY_EXT_REG_17 0x17
514
515/* Fields of PHY_EXT_REG_17 */
516#define PHY_LINKDOWN_POWER_SAVING_EN BIT(4)
517
518/* PHY RXADC Control Register 7 */
519#define PHY_DEV1E_REG_0C6 0x0c6
520
521/* Fields of PHY_DEV1E_REG_0C6 */
522#define PHY_POWER_SAVING_S 8
523#define PHY_POWER_SAVING_M 0x300
524#define PHY_POWER_SAVING_TX 0x0
525
developer65089f72022-09-09 19:59:24 +0800526/* PDMA descriptors */
527struct mtk_rx_dma {
528 unsigned int rxd1;
529 unsigned int rxd2;
530 unsigned int rxd3;
531 unsigned int rxd4;
532} __packed __aligned(4);
533
developera7cdebf2022-09-09 19:59:26 +0800534struct mtk_rx_dma_v2 {
535 unsigned int rxd1;
536 unsigned int rxd2;
537 unsigned int rxd3;
538 unsigned int rxd4;
539 unsigned int rxd5;
540 unsigned int rxd6;
541 unsigned int rxd7;
542 unsigned int rxd8;
543} __packed __aligned(4);
544
developer65089f72022-09-09 19:59:24 +0800545struct mtk_tx_dma {
546 unsigned int txd1;
547 unsigned int txd2;
548 unsigned int txd3;
549 unsigned int txd4;
550} __packed __aligned(4);
551
developera7cdebf2022-09-09 19:59:26 +0800552struct mtk_tx_dma_v2 {
553 unsigned int txd1;
554 unsigned int txd2;
555 unsigned int txd3;
556 unsigned int txd4;
557 unsigned int txd5;
558 unsigned int txd6;
559 unsigned int txd7;
560 unsigned int txd8;
561} __packed __aligned(4);
562
developer65089f72022-09-09 19:59:24 +0800563/* PDMA TXD fields */
564#define PDMA_TXD2_DDONE BIT(31)
565#define PDMA_TXD2_LS0 BIT(30)
developera7cdebf2022-09-09 19:59:26 +0800566#define PDMA_V1_TXD2_SDL0_M GENMASK(29, 16)
567#define PDMA_V1_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V1_TXD2_SDL0_M, (_v))
568#define PDMA_V2_TXD2_SDL0_M GENMASK(23, 8)
569#define PDMA_V2_TXD2_SDL0_SET(_v) FIELD_PREP(PDMA_V2_TXD2_SDL0_M, (_v))
developer65089f72022-09-09 19:59:24 +0800570
developera7cdebf2022-09-09 19:59:26 +0800571#define PDMA_V1_TXD4_FPORT_M GENMASK(27, 25)
572#define PDMA_V1_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V1_TXD4_FPORT_M, (_v))
573#define PDMA_V2_TXD4_FPORT_M GENMASK(27, 24)
574#define PDMA_V2_TXD4_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD4_FPORT_M, (_v))
575
576#define PDMA_V2_TXD5_FPORT_M GENMASK(19, 16)
577#define PDMA_V2_TXD5_FPORT_SET(_v) FIELD_PREP(PDMA_V2_TXD5_FPORT_M, (_v))
developer65089f72022-09-09 19:59:24 +0800578
579/* PDMA RXD fields */
580#define PDMA_RXD2_DDONE BIT(31)
581#define PDMA_RXD2_LS0 BIT(30)
developera7cdebf2022-09-09 19:59:26 +0800582#define PDMA_V1_RXD2_PLEN0_M GENMASK(29, 16)
583#define PDMA_V1_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V1_RXD2_PLEN0_M, (_v))
584#define PDMA_V1_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V1_RXD2_PLEN0_M, (_v))
585#define PDMA_V2_RXD2_PLEN0_M GENMASK(23, 8)
586#define PDMA_V2_RXD2_PLEN0_GET(_v) FIELD_GET(PDMA_V2_RXD2_PLEN0_M, (_v))
587#define PDMA_V2_RXD2_PLEN0_SET(_v) FIELD_PREP(PDMA_V2_RXD2_PLEN0_M, (_v))
developer65089f72022-09-09 19:59:24 +0800588
developerc3ac93d2018-12-20 16:12:53 +0800589#endif /* _MTK_ETH_H_ */