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