1*23f17164SWeijie Gao /* SPDX-License-Identifier: GPL-2.0 */ 2*23f17164SWeijie Gao /* 3*23f17164SWeijie Gao * Copyright (C) 2018 MediaTek Inc. 4*23f17164SWeijie Gao * 5*23f17164SWeijie Gao * Author: Weijie Gao <weijie.gao@mediatek.com> 6*23f17164SWeijie Gao * Author: Mark Lee <mark-mc.lee@mediatek.com> 7*23f17164SWeijie Gao */ 8*23f17164SWeijie Gao 9*23f17164SWeijie Gao #ifndef _MTK_ETH_H_ 10*23f17164SWeijie Gao #define _MTK_ETH_H_ 11*23f17164SWeijie Gao 12*23f17164SWeijie Gao /* Frame Engine Register Bases */ 13*23f17164SWeijie Gao #define PDMA_BASE 0x0800 14*23f17164SWeijie Gao #define GDMA1_BASE 0x0500 15*23f17164SWeijie Gao #define GDMA2_BASE 0x1500 16*23f17164SWeijie Gao #define GMAC_BASE 0x10000 17*23f17164SWeijie Gao 18*23f17164SWeijie Gao /* Ethernet subsystem registers */ 19*23f17164SWeijie Gao 20*23f17164SWeijie Gao #define ETHSYS_SYSCFG0_REG 0x14 21*23f17164SWeijie Gao #define SYSCFG0_GE_MODE_S(n) (12 + ((n) * 2)) 22*23f17164SWeijie Gao #define SYSCFG0_GE_MODE_M 0x3 23*23f17164SWeijie Gao 24*23f17164SWeijie Gao #define ETHSYS_CLKCFG0_REG 0x2c 25*23f17164SWeijie Gao #define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11) 26*23f17164SWeijie Gao 27*23f17164SWeijie Gao /* SYSCFG0_GE_MODE: GE Modes */ 28*23f17164SWeijie Gao #define GE_MODE_RGMII 0 29*23f17164SWeijie Gao #define GE_MODE_MII 1 30*23f17164SWeijie Gao #define GE_MODE_MII_PHY 2 31*23f17164SWeijie Gao #define GE_MODE_RMII 3 32*23f17164SWeijie Gao 33*23f17164SWeijie Gao /* Frame Engine Registers */ 34*23f17164SWeijie Gao 35*23f17164SWeijie Gao /* PDMA */ 36*23f17164SWeijie Gao #define TX_BASE_PTR_REG(n) (0x000 + (n) * 0x10) 37*23f17164SWeijie Gao #define TX_MAX_CNT_REG(n) (0x004 + (n) * 0x10) 38*23f17164SWeijie Gao #define TX_CTX_IDX_REG(n) (0x008 + (n) * 0x10) 39*23f17164SWeijie Gao #define TX_DTX_IDX_REG(n) (0x00c + (n) * 0x10) 40*23f17164SWeijie Gao 41*23f17164SWeijie Gao #define RX_BASE_PTR_REG(n) (0x100 + (n) * 0x10) 42*23f17164SWeijie Gao #define RX_MAX_CNT_REG(n) (0x104 + (n) * 0x10) 43*23f17164SWeijie Gao #define RX_CRX_IDX_REG(n) (0x108 + (n) * 0x10) 44*23f17164SWeijie Gao #define RX_DRX_IDX_REG(n) (0x10c + (n) * 0x10) 45*23f17164SWeijie Gao 46*23f17164SWeijie Gao #define PDMA_GLO_CFG_REG 0x204 47*23f17164SWeijie Gao #define TX_WB_DDONE BIT(6) 48*23f17164SWeijie Gao #define RX_DMA_BUSY BIT(3) 49*23f17164SWeijie Gao #define RX_DMA_EN BIT(2) 50*23f17164SWeijie Gao #define TX_DMA_BUSY BIT(1) 51*23f17164SWeijie Gao #define TX_DMA_EN BIT(0) 52*23f17164SWeijie Gao 53*23f17164SWeijie Gao #define PDMA_RST_IDX_REG 0x208 54*23f17164SWeijie Gao #define RST_DRX_IDX0 BIT(16) 55*23f17164SWeijie Gao #define RST_DTX_IDX0 BIT(0) 56*23f17164SWeijie Gao 57*23f17164SWeijie Gao /* GDMA */ 58*23f17164SWeijie Gao #define GDMA_IG_CTRL_REG 0x000 59*23f17164SWeijie Gao #define GDM_ICS_EN BIT(22) 60*23f17164SWeijie Gao #define GDM_TCS_EN BIT(21) 61*23f17164SWeijie Gao #define GDM_UCS_EN BIT(20) 62*23f17164SWeijie Gao #define STRP_CRC BIT(16) 63*23f17164SWeijie Gao #define MYMAC_DP_S 12 64*23f17164SWeijie Gao #define MYMAC_DP_M 0xf000 65*23f17164SWeijie Gao #define BC_DP_S 8 66*23f17164SWeijie Gao #define BC_DP_M 0xf00 67*23f17164SWeijie Gao #define MC_DP_S 4 68*23f17164SWeijie Gao #define MC_DP_M 0xf0 69*23f17164SWeijie Gao #define UN_DP_S 0 70*23f17164SWeijie Gao #define UN_DP_M 0x0f 71*23f17164SWeijie Gao 72*23f17164SWeijie Gao #define GDMA_MAC_LSB_REG 0x008 73*23f17164SWeijie Gao 74*23f17164SWeijie Gao #define GDMA_MAC_MSB_REG 0x00c 75*23f17164SWeijie Gao 76*23f17164SWeijie Gao /* MYMAC_DP/BC_DP/MC_DP/UN_DP: Destination ports */ 77*23f17164SWeijie Gao #define DP_PDMA 0 78*23f17164SWeijie Gao #define DP_GDMA1 1 79*23f17164SWeijie Gao #define DP_GDMA2 2 80*23f17164SWeijie Gao #define DP_PPE 4 81*23f17164SWeijie Gao #define DP_QDMA 5 82*23f17164SWeijie Gao #define DP_DISCARD 7 83*23f17164SWeijie Gao 84*23f17164SWeijie Gao /* GMAC Registers */ 85*23f17164SWeijie Gao 86*23f17164SWeijie Gao #define GMAC_PIAC_REG 0x0004 87*23f17164SWeijie Gao #define PHY_ACS_ST BIT(31) 88*23f17164SWeijie Gao #define MDIO_REG_ADDR_S 25 89*23f17164SWeijie Gao #define MDIO_REG_ADDR_M 0x3e000000 90*23f17164SWeijie Gao #define MDIO_PHY_ADDR_S 20 91*23f17164SWeijie Gao #define MDIO_PHY_ADDR_M 0x1f00000 92*23f17164SWeijie Gao #define MDIO_CMD_S 18 93*23f17164SWeijie Gao #define MDIO_CMD_M 0xc0000 94*23f17164SWeijie Gao #define MDIO_ST_S 16 95*23f17164SWeijie Gao #define MDIO_ST_M 0x30000 96*23f17164SWeijie Gao #define MDIO_RW_DATA_S 0 97*23f17164SWeijie Gao #define MDIO_RW_DATA_M 0xffff 98*23f17164SWeijie Gao 99*23f17164SWeijie Gao /* MDIO_CMD: MDIO commands */ 100*23f17164SWeijie Gao #define MDIO_CMD_ADDR 0 101*23f17164SWeijie Gao #define MDIO_CMD_WRITE 1 102*23f17164SWeijie Gao #define MDIO_CMD_READ 2 103*23f17164SWeijie Gao #define MDIO_CMD_READ_C45 3 104*23f17164SWeijie Gao 105*23f17164SWeijie Gao /* MDIO_ST: MDIO start field */ 106*23f17164SWeijie Gao #define MDIO_ST_C45 0 107*23f17164SWeijie Gao #define MDIO_ST_C22 1 108*23f17164SWeijie Gao 109*23f17164SWeijie Gao #define GMAC_PORT_MCR(p) (0x0100 + (p) * 0x100) 110*23f17164SWeijie Gao #define MAC_RX_PKT_LEN_S 24 111*23f17164SWeijie Gao #define MAC_RX_PKT_LEN_M 0x3000000 112*23f17164SWeijie Gao #define IPG_CFG_S 18 113*23f17164SWeijie Gao #define IPG_CFG_M 0xc0000 114*23f17164SWeijie Gao #define MAC_MODE BIT(16) 115*23f17164SWeijie Gao #define FORCE_MODE BIT(15) 116*23f17164SWeijie Gao #define MAC_TX_EN BIT(14) 117*23f17164SWeijie Gao #define MAC_RX_EN BIT(13) 118*23f17164SWeijie Gao #define BKOFF_EN BIT(9) 119*23f17164SWeijie Gao #define BACKPR_EN BIT(8) 120*23f17164SWeijie Gao #define FORCE_RX_FC BIT(5) 121*23f17164SWeijie Gao #define FORCE_TX_FC BIT(4) 122*23f17164SWeijie Gao #define FORCE_SPD_S 2 123*23f17164SWeijie Gao #define FORCE_SPD_M 0x0c 124*23f17164SWeijie Gao #define FORCE_DPX BIT(1) 125*23f17164SWeijie Gao #define FORCE_LINK BIT(0) 126*23f17164SWeijie Gao 127*23f17164SWeijie Gao /* MAC_RX_PKT_LEN: Max RX packet length */ 128*23f17164SWeijie Gao #define MAC_RX_PKT_LEN_1518 0 129*23f17164SWeijie Gao #define MAC_RX_PKT_LEN_1536 1 130*23f17164SWeijie Gao #define MAC_RX_PKT_LEN_1552 2 131*23f17164SWeijie Gao #define MAC_RX_PKT_LEN_JUMBO 3 132*23f17164SWeijie Gao 133*23f17164SWeijie Gao /* FORCE_SPD: Forced link speed */ 134*23f17164SWeijie Gao #define SPEED_10M 0 135*23f17164SWeijie Gao #define SPEED_100M 1 136*23f17164SWeijie Gao #define SPEED_1000M 2 137*23f17164SWeijie Gao 138*23f17164SWeijie Gao #define GMAC_TRGMII_RCK_CTRL 0x300 139*23f17164SWeijie Gao #define RX_RST BIT(31) 140*23f17164SWeijie Gao #define RXC_DQSISEL BIT(30) 141*23f17164SWeijie Gao 142*23f17164SWeijie Gao #define GMAC_TRGMII_TD_ODT(n) (0x354 + (n) * 8) 143*23f17164SWeijie Gao #define TD_DM_DRVN_S 4 144*23f17164SWeijie Gao #define TD_DM_DRVN_M 0xf0 145*23f17164SWeijie Gao #define TD_DM_DRVP_S 0 146*23f17164SWeijie Gao #define TD_DM_DRVP_M 0x0f 147*23f17164SWeijie Gao 148*23f17164SWeijie Gao /* MT7530 Registers */ 149*23f17164SWeijie Gao 150*23f17164SWeijie Gao #define PCR_REG(p) (0x2004 + (p) * 0x100) 151*23f17164SWeijie Gao #define PORT_MATRIX_S 16 152*23f17164SWeijie Gao #define PORT_MATRIX_M 0xff0000 153*23f17164SWeijie Gao 154*23f17164SWeijie Gao #define PVC_REG(p) (0x2010 + (p) * 0x100) 155*23f17164SWeijie Gao #define STAG_VPID_S 16 156*23f17164SWeijie Gao #define STAG_VPID_M 0xffff0000 157*23f17164SWeijie Gao #define VLAN_ATTR_S 6 158*23f17164SWeijie Gao #define VLAN_ATTR_M 0xc0 159*23f17164SWeijie Gao 160*23f17164SWeijie Gao /* VLAN_ATTR: VLAN attributes */ 161*23f17164SWeijie Gao #define VLAN_ATTR_USER 0 162*23f17164SWeijie Gao #define VLAN_ATTR_STACK 1 163*23f17164SWeijie Gao #define VLAN_ATTR_TRANSLATION 2 164*23f17164SWeijie Gao #define VLAN_ATTR_TRANSPARENT 3 165*23f17164SWeijie Gao 166*23f17164SWeijie Gao #define PCMR_REG(p) (0x3000 + (p) * 0x100) 167*23f17164SWeijie Gao /* XXX: all fields are defined under GMAC_PORT_MCR */ 168*23f17164SWeijie Gao 169*23f17164SWeijie Gao #define SYS_CTRL_REG 0x7000 170*23f17164SWeijie Gao #define SW_PHY_RST BIT(2) 171*23f17164SWeijie Gao #define SW_SYS_RST BIT(1) 172*23f17164SWeijie Gao #define SW_REG_RST BIT(0) 173*23f17164SWeijie Gao 174*23f17164SWeijie Gao #define NUM_TRGMII_CTRL 5 175*23f17164SWeijie Gao 176*23f17164SWeijie Gao #define HWTRAP_REG 0x7800 177*23f17164SWeijie Gao #define MHWTRAP_REG 0x7804 178*23f17164SWeijie Gao #define CHG_TRAP BIT(16) 179*23f17164SWeijie Gao #define LOOPDET_DIS BIT(14) 180*23f17164SWeijie Gao #define P5_INTF_SEL_S 13 181*23f17164SWeijie Gao #define P5_INTF_SEL_M 0x2000 182*23f17164SWeijie Gao #define SMI_ADDR_S 11 183*23f17164SWeijie Gao #define SMI_ADDR_M 0x1800 184*23f17164SWeijie Gao #define XTAL_FSEL_S 9 185*23f17164SWeijie Gao #define XTAL_FSEL_M 0x600 186*23f17164SWeijie Gao #define P6_INTF_DIS BIT(8) 187*23f17164SWeijie Gao #define P5_INTF_MODE_S 7 188*23f17164SWeijie Gao #define P5_INTF_MODE_M 0x80 189*23f17164SWeijie Gao #define P5_INTF_DIS BIT(6) 190*23f17164SWeijie Gao #define C_MDIO_BPS BIT(5) 191*23f17164SWeijie Gao #define CHIP_MODE_S 0 192*23f17164SWeijie Gao #define CHIP_MODE_M 0x0f 193*23f17164SWeijie Gao 194*23f17164SWeijie Gao /* P5_INTF_SEL: Interface type of Port5 */ 195*23f17164SWeijie Gao #define P5_INTF_SEL_GPHY 0 196*23f17164SWeijie Gao #define P5_INTF_SEL_GMAC5 1 197*23f17164SWeijie Gao 198*23f17164SWeijie Gao /* P5_INTF_MODE: Interface mode of Port5 */ 199*23f17164SWeijie Gao #define P5_INTF_MODE_GMII_MII 0 200*23f17164SWeijie Gao #define P5_INTF_MODE_RGMII 1 201*23f17164SWeijie Gao 202*23f17164SWeijie Gao #define MT7530_P6ECR 0x7830 203*23f17164SWeijie Gao #define P6_INTF_MODE_M 0x3 204*23f17164SWeijie Gao #define P6_INTF_MODE_S 0 205*23f17164SWeijie Gao 206*23f17164SWeijie Gao /* P6_INTF_MODE: Interface mode of Port6 */ 207*23f17164SWeijie Gao #define P6_INTF_MODE_RGMII 0 208*23f17164SWeijie Gao #define P6_INTF_MODE_TRGMII 1 209*23f17164SWeijie Gao 210*23f17164SWeijie Gao #define MT7530_TRGMII_RD(n) (0x7a10 + (n) * 8) 211*23f17164SWeijie Gao #define RD_TAP_S 0 212*23f17164SWeijie Gao #define RD_TAP_M 0x7f 213*23f17164SWeijie Gao 214*23f17164SWeijie Gao #define MT7530_TRGMII_TD_ODT(n) (0x7a54 + (n) * 8) 215*23f17164SWeijie Gao /* XXX: all fields are defined under GMAC_TRGMII_TD_ODT */ 216*23f17164SWeijie Gao 217*23f17164SWeijie Gao /* MT7530 GPHY MDIO Indirect Access Registers */ 218*23f17164SWeijie Gao 219*23f17164SWeijie Gao #define MII_MMD_ACC_CTL_REG 0x0d 220*23f17164SWeijie Gao #define MMD_CMD_S 14 221*23f17164SWeijie Gao #define MMD_CMD_M 0xc000 222*23f17164SWeijie Gao #define MMD_DEVAD_S 0 223*23f17164SWeijie Gao #define MMD_DEVAD_M 0x1f 224*23f17164SWeijie Gao 225*23f17164SWeijie Gao /* MMD_CMD: MMD commands */ 226*23f17164SWeijie Gao #define MMD_ADDR 0 227*23f17164SWeijie Gao #define MMD_DATA 1 228*23f17164SWeijie Gao #define MMD_DATA_RW_POST_INC 2 229*23f17164SWeijie Gao #define MMD_DATA_W_POST_INC 3 230*23f17164SWeijie Gao 231*23f17164SWeijie Gao #define MII_MMD_ADDR_DATA_REG 0x0e 232*23f17164SWeijie Gao 233*23f17164SWeijie Gao /* MT7530 GPHY MDIO MMD Registers */ 234*23f17164SWeijie Gao 235*23f17164SWeijie Gao #define CORE_PLL_GROUP2 0x401 236*23f17164SWeijie Gao #define RG_SYSPLL_EN_NORMAL BIT(15) 237*23f17164SWeijie Gao #define RG_SYSPLL_VODEN BIT(14) 238*23f17164SWeijie Gao #define RG_SYSPLL_POSDIV_S 5 239*23f17164SWeijie Gao #define RG_SYSPLL_POSDIV_M 0x60 240*23f17164SWeijie Gao 241*23f17164SWeijie Gao #define CORE_PLL_GROUP4 0x403 242*23f17164SWeijie Gao #define RG_SYSPLL_DDSFBK_EN BIT(12) 243*23f17164SWeijie Gao #define RG_SYSPLL_BIAS_EN BIT(11) 244*23f17164SWeijie Gao #define RG_SYSPLL_BIAS_LPF_EN BIT(10) 245*23f17164SWeijie Gao 246*23f17164SWeijie Gao #define CORE_PLL_GROUP5 0x404 247*23f17164SWeijie Gao #define RG_LCDDS_PCW_NCPO1_S 0 248*23f17164SWeijie Gao #define RG_LCDDS_PCW_NCPO1_M 0xffff 249*23f17164SWeijie Gao 250*23f17164SWeijie Gao #define CORE_PLL_GROUP6 0x405 251*23f17164SWeijie Gao #define RG_LCDDS_PCW_NCPO0_S 0 252*23f17164SWeijie Gao #define RG_LCDDS_PCW_NCPO0_M 0xffff 253*23f17164SWeijie Gao 254*23f17164SWeijie Gao #define CORE_PLL_GROUP7 0x406 255*23f17164SWeijie Gao #define RG_LCDDS_PWDB BIT(15) 256*23f17164SWeijie Gao #define RG_LCDDS_ISO_EN BIT(13) 257*23f17164SWeijie Gao #define RG_LCCDS_C_S 4 258*23f17164SWeijie Gao #define RG_LCCDS_C_M 0x70 259*23f17164SWeijie Gao #define RG_LCDDS_PCW_NCPO_CHG BIT(3) 260*23f17164SWeijie Gao 261*23f17164SWeijie Gao #define CORE_PLL_GROUP10 0x409 262*23f17164SWeijie Gao #define RG_LCDDS_SSC_DELTA_S 0 263*23f17164SWeijie Gao #define RG_LCDDS_SSC_DELTA_M 0xfff 264*23f17164SWeijie Gao 265*23f17164SWeijie Gao #define CORE_PLL_GROUP11 0x40a 266*23f17164SWeijie Gao #define RG_LCDDS_SSC_DELTA1_S 0 267*23f17164SWeijie Gao #define RG_LCDDS_SSC_DELTA1_M 0xfff 268*23f17164SWeijie Gao 269*23f17164SWeijie Gao #define CORE_GSWPLL_GRP1 0x40d 270*23f17164SWeijie Gao #define RG_GSWPLL_POSDIV_200M_S 12 271*23f17164SWeijie Gao #define RG_GSWPLL_POSDIV_200M_M 0x3000 272*23f17164SWeijie Gao #define RG_GSWPLL_EN_PRE BIT(11) 273*23f17164SWeijie Gao #define RG_GSWPLL_FBKDIV_200M_S 0 274*23f17164SWeijie Gao #define RG_GSWPLL_FBKDIV_200M_M 0xff 275*23f17164SWeijie Gao 276*23f17164SWeijie Gao #define CORE_GSWPLL_GRP2 0x40e 277*23f17164SWeijie Gao #define RG_GSWPLL_POSDIV_500M_S 8 278*23f17164SWeijie Gao #define RG_GSWPLL_POSDIV_500M_M 0x300 279*23f17164SWeijie Gao #define RG_GSWPLL_FBKDIV_500M_S 0 280*23f17164SWeijie Gao #define RG_GSWPLL_FBKDIV_500M_M 0xff 281*23f17164SWeijie Gao 282*23f17164SWeijie Gao #define CORE_TRGMII_GSW_CLK_CG 0x410 283*23f17164SWeijie Gao #define REG_GSWCK_EN BIT(0) 284*23f17164SWeijie Gao #define REG_TRGMIICK_EN BIT(1) 285*23f17164SWeijie Gao 286*23f17164SWeijie Gao #endif /* _MTK_ETH_H_ */ 287