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