0001
0002
0003
0004
0005
0006 #ifndef __MT7530_H
0007 #define __MT7530_H
0008
0009 #define MT7530_NUM_PORTS 7
0010 #define MT7530_NUM_PHYS 5
0011 #define MT7530_NUM_FDB_RECORDS 2048
0012 #define MT7530_ALL_MEMBERS 0xff
0013
0014 #define MTK_HDR_LEN 4
0015 #define MT7530_MAX_MTU (15 * 1024 - ETH_HLEN - ETH_FCS_LEN - MTK_HDR_LEN)
0016
0017 enum mt753x_id {
0018 ID_MT7530 = 0,
0019 ID_MT7621 = 1,
0020 ID_MT7531 = 2,
0021 };
0022
0023 #define NUM_TRGMII_CTRL 5
0024
0025 #define TRGMII_BASE(x) (0x10000 + (x))
0026
0027
0028 #define ETHSYS_CLKCFG0 0x2c
0029 #define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
0030
0031 #define SYSC_REG_RSTCTRL 0x34
0032 #define RESET_MCM BIT(2)
0033
0034
0035 #define MT7530_MFC 0x10
0036 #define BC_FFP(x) (((x) & 0xff) << 24)
0037 #define BC_FFP_MASK BC_FFP(~0)
0038 #define UNM_FFP(x) (((x) & 0xff) << 16)
0039 #define UNM_FFP_MASK UNM_FFP(~0)
0040 #define UNU_FFP(x) (((x) & 0xff) << 8)
0041 #define UNU_FFP_MASK UNU_FFP(~0)
0042 #define CPU_EN BIT(7)
0043 #define CPU_PORT(x) ((x) << 4)
0044 #define CPU_MASK (0xf << 4)
0045 #define MIRROR_EN BIT(3)
0046 #define MIRROR_PORT(x) ((x) & 0x7)
0047 #define MIRROR_MASK 0x7
0048
0049
0050 #define MT7531_CFC 0x4
0051 #define MT7531_MIRROR_EN BIT(19)
0052 #define MT7531_MIRROR_MASK (MIRROR_MASK << 16)
0053 #define MT7531_MIRROR_PORT_GET(x) (((x) >> 16) & MIRROR_MASK)
0054 #define MT7531_MIRROR_PORT_SET(x) (((x) & MIRROR_MASK) << 16)
0055 #define MT7531_CPU_PMAP_MASK GENMASK(7, 0)
0056
0057 #define MT753X_MIRROR_REG(id) (((id) == ID_MT7531) ? \
0058 MT7531_CFC : MT7530_MFC)
0059 #define MT753X_MIRROR_EN(id) (((id) == ID_MT7531) ? \
0060 MT7531_MIRROR_EN : MIRROR_EN)
0061 #define MT753X_MIRROR_MASK(id) (((id) == ID_MT7531) ? \
0062 MT7531_MIRROR_MASK : MIRROR_MASK)
0063
0064
0065 #define MT753X_BPC 0x24
0066 #define MT753X_BPDU_PORT_FW_MASK GENMASK(2, 0)
0067
0068 enum mt753x_bpdu_port_fw {
0069 MT753X_BPDU_FOLLOW_MFC,
0070 MT753X_BPDU_CPU_EXCLUDE = 4,
0071 MT753X_BPDU_CPU_INCLUDE = 5,
0072 MT753X_BPDU_CPU_ONLY = 6,
0073 MT753X_BPDU_DROP = 7,
0074 };
0075
0076
0077 #define MT7530_ATA1 0x74
0078 #define STATIC_EMP 0
0079 #define STATIC_ENT 3
0080 #define MT7530_ATA2 0x78
0081 #define ATA2_IVL BIT(15)
0082 #define ATA2_FID(x) (((x) & 0x7) << 12)
0083
0084
0085 #define MT7530_ATWD 0x7c
0086
0087
0088 #define MT7530_ATC 0x80
0089 #define ATC_HASH (((x) & 0xfff) << 16)
0090 #define ATC_BUSY BIT(15)
0091 #define ATC_SRCH_END BIT(14)
0092 #define ATC_SRCH_HIT BIT(13)
0093 #define ATC_INVALID BIT(12)
0094 #define ATC_MAT(x) (((x) & 0xf) << 8)
0095 #define ATC_MAT_MACTAB ATC_MAT(0)
0096
0097 enum mt7530_fdb_cmd {
0098 MT7530_FDB_READ = 0,
0099 MT7530_FDB_WRITE = 1,
0100 MT7530_FDB_FLUSH = 2,
0101 MT7530_FDB_START = 4,
0102 MT7530_FDB_NEXT = 5,
0103 };
0104
0105
0106 #define MT7530_TSRA1 0x84
0107 #define MAC_BYTE_0 24
0108 #define MAC_BYTE_1 16
0109 #define MAC_BYTE_2 8
0110 #define MAC_BYTE_3 0
0111 #define MAC_BYTE_MASK 0xff
0112
0113 #define MT7530_TSRA2 0x88
0114 #define MAC_BYTE_4 24
0115 #define MAC_BYTE_5 16
0116 #define CVID 0
0117 #define CVID_MASK 0xfff
0118
0119 #define MT7530_ATRD 0x8C
0120 #define AGE_TIMER 24
0121 #define AGE_TIMER_MASK 0xff
0122 #define PORT_MAP 4
0123 #define PORT_MAP_MASK 0xff
0124 #define ENT_STATUS 2
0125 #define ENT_STATUS_MASK 0x3
0126
0127
0128 #define MT7530_VTCR 0x90
0129 #define VTCR_BUSY BIT(31)
0130 #define VTCR_INVALID BIT(16)
0131 #define VTCR_FUNC(x) (((x) & 0xf) << 12)
0132 #define VTCR_VID ((x) & 0xfff)
0133
0134 enum mt7530_vlan_cmd {
0135
0136
0137
0138 MT7530_VTCR_RD_VID = 0,
0139 MT7530_VTCR_WR_VID = 1,
0140 };
0141
0142
0143 #define MT7530_VAWD1 0x94
0144 #define PORT_STAG BIT(31)
0145
0146 #define IVL_MAC BIT(30)
0147
0148 #define EG_CON BIT(29)
0149
0150 #define VTAG_EN BIT(28)
0151
0152 #define PORT_MEM(x) (((x) & 0xff) << 16)
0153
0154 #define FID(x) (((x) & 0x7) << 1)
0155
0156 #define VLAN_VALID BIT(0)
0157 #define PORT_MEM_SHFT 16
0158 #define PORT_MEM_MASK 0xff
0159
0160 enum mt7530_fid {
0161 FID_STANDALONE = 0,
0162 FID_BRIDGED = 1,
0163 };
0164
0165 #define MT7530_VAWD2 0x98
0166
0167 #define ETAG_CTRL_P(p, x) (((x) & 0x3) << ((p) << 1))
0168 #define ETAG_CTRL_P_MASK(p) ETAG_CTRL_P(p, 3)
0169
0170 enum mt7530_vlan_egress_attr {
0171 MT7530_VLAN_EGRESS_UNTAG = 0,
0172 MT7530_VLAN_EGRESS_TAG = 2,
0173 MT7530_VLAN_EGRESS_STACK = 3,
0174 };
0175
0176
0177 #define MT7530_AAC 0xa0
0178
0179 #define AGE_DIS BIT(20)
0180
0181 #define AGE_CNT_MASK GENMASK(19, 12)
0182 #define AGE_CNT_MAX 0xff
0183 #define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12))
0184
0185 #define AGE_UNIT_MASK GENMASK(11, 0)
0186 #define AGE_UNIT_MAX 0xfff
0187 #define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
0188
0189
0190 #define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
0191 #define FID_PST(fid, state) (((state) & 0x3) << ((fid) * 2))
0192 #define FID_PST_MASK(fid) FID_PST(fid, 0x3)
0193
0194 enum mt7530_stp_state {
0195 MT7530_STP_DISABLED = 0,
0196 MT7530_STP_BLOCKING = 1,
0197 MT7530_STP_LISTENING = 1,
0198 MT7530_STP_LEARNING = 2,
0199 MT7530_STP_FORWARDING = 3
0200 };
0201
0202
0203 #define MT7530_PCR_P(x) (0x2004 + ((x) * 0x100))
0204 #define PORT_TX_MIR BIT(9)
0205 #define PORT_RX_MIR BIT(8)
0206 #define PORT_VLAN(x) ((x) & 0x3)
0207
0208 enum mt7530_port_mode {
0209
0210 MT7530_PORT_MATRIX_MODE = PORT_VLAN(0),
0211
0212
0213
0214
0215
0216 MT7530_PORT_FALLBACK_MODE = PORT_VLAN(1),
0217
0218
0219
0220
0221 MT7530_PORT_SECURITY_MODE = PORT_VLAN(3),
0222 };
0223
0224 #define PCR_MATRIX(x) (((x) & 0xff) << 16)
0225 #define PORT_PRI(x) (((x) & 0x7) << 24)
0226 #define EG_TAG(x) (((x) & 0x3) << 28)
0227 #define PCR_MATRIX_MASK PCR_MATRIX(0xff)
0228 #define PCR_MATRIX_CLR PCR_MATRIX(0)
0229 #define PCR_PORT_VLAN_MASK PORT_VLAN(3)
0230
0231
0232 #define MT7530_PSC_P(x) (0x200c + ((x) * 0x100))
0233 #define SA_DIS BIT(4)
0234
0235
0236 #define MT7530_PVC_P(x) (0x2010 + ((x) * 0x100))
0237 #define PORT_SPEC_TAG BIT(5)
0238 #define PVC_EG_TAG(x) (((x) & 0x7) << 8)
0239 #define PVC_EG_TAG_MASK PVC_EG_TAG(7)
0240 #define VLAN_ATTR(x) (((x) & 0x3) << 6)
0241 #define VLAN_ATTR_MASK VLAN_ATTR(3)
0242 #define ACC_FRM_MASK GENMASK(1, 0)
0243
0244 enum mt7530_vlan_port_eg_tag {
0245 MT7530_VLAN_EG_DISABLED = 0,
0246 MT7530_VLAN_EG_CONSISTENT = 1,
0247 };
0248
0249 enum mt7530_vlan_port_attr {
0250 MT7530_VLAN_USER = 0,
0251 MT7530_VLAN_TRANSPARENT = 3,
0252 };
0253
0254 enum mt7530_vlan_port_acc_frm {
0255 MT7530_VLAN_ACC_ALL = 0,
0256 MT7530_VLAN_ACC_TAGGED = 1,
0257 MT7530_VLAN_ACC_UNTAGGED = 2,
0258 };
0259
0260 #define STAG_VPID (((x) & 0xffff) << 16)
0261
0262
0263 #define MT7530_PPBV1_P(x) (0x2014 + ((x) * 0x100))
0264 #define G0_PORT_VID(x) (((x) & 0xfff) << 0)
0265 #define G0_PORT_VID_MASK G0_PORT_VID(0xfff)
0266 #define G0_PORT_VID_DEF G0_PORT_VID(0)
0267
0268
0269 #define MT7530_PMCR_P(x) (0x3000 + ((x) * 0x100))
0270 #define PMCR_IFG_XMIT(x) (((x) & 0x3) << 18)
0271 #define PMCR_EXT_PHY BIT(17)
0272 #define PMCR_MAC_MODE BIT(16)
0273 #define PMCR_FORCE_MODE BIT(15)
0274 #define PMCR_TX_EN BIT(14)
0275 #define PMCR_RX_EN BIT(13)
0276 #define PMCR_BACKOFF_EN BIT(9)
0277 #define PMCR_BACKPR_EN BIT(8)
0278 #define PMCR_FORCE_EEE1G BIT(7)
0279 #define PMCR_FORCE_EEE100 BIT(6)
0280 #define PMCR_TX_FC_EN BIT(5)
0281 #define PMCR_RX_FC_EN BIT(4)
0282 #define PMCR_FORCE_SPEED_1000 BIT(3)
0283 #define PMCR_FORCE_SPEED_100 BIT(2)
0284 #define PMCR_FORCE_FDX BIT(1)
0285 #define PMCR_FORCE_LNK BIT(0)
0286 #define PMCR_SPEED_MASK (PMCR_FORCE_SPEED_100 | \
0287 PMCR_FORCE_SPEED_1000)
0288 #define MT7531_FORCE_LNK BIT(31)
0289 #define MT7531_FORCE_SPD BIT(30)
0290 #define MT7531_FORCE_DPX BIT(29)
0291 #define MT7531_FORCE_RX_FC BIT(28)
0292 #define MT7531_FORCE_TX_FC BIT(27)
0293 #define MT7531_FORCE_MODE (MT7531_FORCE_LNK | \
0294 MT7531_FORCE_SPD | \
0295 MT7531_FORCE_DPX | \
0296 MT7531_FORCE_RX_FC | \
0297 MT7531_FORCE_TX_FC)
0298 #define PMCR_FORCE_MODE_ID(id) (((id) == ID_MT7531) ? \
0299 MT7531_FORCE_MODE : \
0300 PMCR_FORCE_MODE)
0301 #define PMCR_LINK_SETTINGS_MASK (PMCR_TX_EN | PMCR_FORCE_SPEED_1000 | \
0302 PMCR_RX_EN | PMCR_FORCE_SPEED_100 | \
0303 PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
0304 PMCR_FORCE_FDX | PMCR_FORCE_LNK | \
0305 PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100)
0306 #define PMCR_CPU_PORT_SETTING(id) (PMCR_FORCE_MODE_ID((id)) | \
0307 PMCR_IFG_XMIT(1) | PMCR_MAC_MODE | \
0308 PMCR_BACKOFF_EN | PMCR_BACKPR_EN | \
0309 PMCR_TX_EN | PMCR_RX_EN | \
0310 PMCR_TX_FC_EN | PMCR_RX_FC_EN | \
0311 PMCR_FORCE_SPEED_1000 | \
0312 PMCR_FORCE_FDX | PMCR_FORCE_LNK)
0313
0314 #define MT7530_PMEEECR_P(x) (0x3004 + (x) * 0x100)
0315 #define WAKEUP_TIME_1000(x) (((x) & 0xFF) << 24)
0316 #define WAKEUP_TIME_100(x) (((x) & 0xFF) << 16)
0317 #define LPI_THRESH_MASK GENMASK(15, 4)
0318 #define LPI_THRESH_SHT 4
0319 #define SET_LPI_THRESH(x) (((x) << LPI_THRESH_SHT) & LPI_THRESH_MASK)
0320 #define GET_LPI_THRESH(x) (((x) & LPI_THRESH_MASK) >> LPI_THRESH_SHT)
0321 #define LPI_MODE_EN BIT(0)
0322
0323 #define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100)
0324 #define PMSR_EEE1G BIT(7)
0325 #define PMSR_EEE100M BIT(6)
0326 #define PMSR_RX_FC BIT(5)
0327 #define PMSR_TX_FC BIT(4)
0328 #define PMSR_SPEED_1000 BIT(3)
0329 #define PMSR_SPEED_100 BIT(2)
0330 #define PMSR_SPEED_10 0x00
0331 #define PMSR_SPEED_MASK (PMSR_SPEED_100 | PMSR_SPEED_1000)
0332 #define PMSR_DPX BIT(1)
0333 #define PMSR_LINK BIT(0)
0334
0335
0336 #define MT7531_DBG_CNT(x) (0x3018 + (x) * 0x100)
0337 #define MT7531_DIS_CLR BIT(31)
0338
0339 #define MT7530_GMACCR 0x30e0
0340 #define MAX_RX_JUMBO(x) ((x) << 2)
0341 #define MAX_RX_JUMBO_MASK GENMASK(5, 2)
0342 #define MAX_RX_PKT_LEN_MASK GENMASK(1, 0)
0343 #define MAX_RX_PKT_LEN_1522 0x0
0344 #define MAX_RX_PKT_LEN_1536 0x1
0345 #define MAX_RX_PKT_LEN_1552 0x2
0346 #define MAX_RX_PKT_LEN_JUMBO 0x3
0347
0348
0349 #define MT7530_PORT_MIB_COUNTER(x) (0x4000 + (x) * 0x100)
0350 #define MT7530_MIB_CCR 0x4fe0
0351 #define CCR_MIB_ENABLE BIT(31)
0352 #define CCR_RX_OCT_CNT_GOOD BIT(7)
0353 #define CCR_RX_OCT_CNT_BAD BIT(6)
0354 #define CCR_TX_OCT_CNT_GOOD BIT(5)
0355 #define CCR_TX_OCT_CNT_BAD BIT(4)
0356 #define CCR_MIB_FLUSH (CCR_RX_OCT_CNT_GOOD | \
0357 CCR_RX_OCT_CNT_BAD | \
0358 CCR_TX_OCT_CNT_GOOD | \
0359 CCR_TX_OCT_CNT_BAD)
0360 #define CCR_MIB_ACTIVATE (CCR_MIB_ENABLE | \
0361 CCR_RX_OCT_CNT_GOOD | \
0362 CCR_RX_OCT_CNT_BAD | \
0363 CCR_TX_OCT_CNT_GOOD | \
0364 CCR_TX_OCT_CNT_BAD)
0365
0366
0367 #define MT7531_SGMII_REG_BASE 0x5000
0368 #define MT7531_SGMII_REG(p, r) (MT7531_SGMII_REG_BASE + \
0369 ((p) - 5) * 0x1000 + (r))
0370
0371
0372 #define MT7531_PCS_CONTROL_1(p) MT7531_SGMII_REG(p, 0x00)
0373 #define MT7531_SGMII_LINK_STATUS BIT(18)
0374 #define MT7531_SGMII_AN_ENABLE BIT(12)
0375 #define MT7531_SGMII_AN_RESTART BIT(9)
0376
0377
0378 #define MT7531_PCS_SPEED_ABILITY(p) MT7531_SGMII_REG(p, 0x08)
0379 #define MT7531_SGMII_TX_CONFIG_MASK GENMASK(15, 0)
0380 #define MT7531_SGMII_TX_CONFIG BIT(0)
0381
0382
0383 #define MT7531_SGMII_MODE(p) MT7531_SGMII_REG(p, 0x20)
0384 #define MT7531_SGMII_REMOTE_FAULT_DIS BIT(8)
0385 #define MT7531_SGMII_IF_MODE_MASK GENMASK(5, 1)
0386 #define MT7531_SGMII_FORCE_DUPLEX BIT(4)
0387 #define MT7531_SGMII_FORCE_SPEED_MASK GENMASK(3, 2)
0388 #define MT7531_SGMII_FORCE_SPEED_1000 BIT(3)
0389 #define MT7531_SGMII_FORCE_SPEED_100 BIT(2)
0390 #define MT7531_SGMII_FORCE_SPEED_10 0
0391 #define MT7531_SGMII_SPEED_DUPLEX_AN BIT(1)
0392
0393 enum mt7531_sgmii_force_duplex {
0394 MT7531_SGMII_FORCE_FULL_DUPLEX = 0,
0395 MT7531_SGMII_FORCE_HALF_DUPLEX = 0x10,
0396 };
0397
0398
0399 #define MT7531_QPHY_PWR_STATE_CTRL(p) MT7531_SGMII_REG(p, 0xe8)
0400 #define MT7531_SGMII_PHYA_PWD BIT(4)
0401
0402
0403 #define MT7531_PHYA_CTRL_SIGNAL3(p) MT7531_SGMII_REG(p, 0x128)
0404 #define MT7531_RG_TPHY_SPEED_MASK (BIT(2) | BIT(3))
0405 #define MT7531_RG_TPHY_SPEED_1_25G 0x0
0406 #define MT7531_RG_TPHY_SPEED_3_125G BIT(2)
0407
0408
0409 #define MT7530_SYS_CTRL 0x7000
0410 #define SYS_CTRL_PHY_RST BIT(2)
0411 #define SYS_CTRL_SW_RST BIT(1)
0412 #define SYS_CTRL_REG_RST BIT(0)
0413
0414
0415 #define MT7530_SYS_INT_EN 0x7008
0416
0417
0418 #define MT7530_SYS_INT_STS 0x700c
0419
0420
0421 #define MT7531_PHY_IAC 0x701C
0422 #define MT7531_PHY_ACS_ST BIT(31)
0423 #define MT7531_MDIO_REG_ADDR_MASK (0x1f << 25)
0424 #define MT7531_MDIO_PHY_ADDR_MASK (0x1f << 20)
0425 #define MT7531_MDIO_CMD_MASK (0x3 << 18)
0426 #define MT7531_MDIO_ST_MASK (0x3 << 16)
0427 #define MT7531_MDIO_RW_DATA_MASK (0xffff)
0428 #define MT7531_MDIO_REG_ADDR(x) (((x) & 0x1f) << 25)
0429 #define MT7531_MDIO_DEV_ADDR(x) (((x) & 0x1f) << 25)
0430 #define MT7531_MDIO_PHY_ADDR(x) (((x) & 0x1f) << 20)
0431 #define MT7531_MDIO_CMD(x) (((x) & 0x3) << 18)
0432 #define MT7531_MDIO_ST(x) (((x) & 0x3) << 16)
0433
0434 enum mt7531_phy_iac_cmd {
0435 MT7531_MDIO_ADDR = 0,
0436 MT7531_MDIO_WRITE = 1,
0437 MT7531_MDIO_READ = 2,
0438 MT7531_MDIO_READ_CL45 = 3,
0439 };
0440
0441
0442 enum mt7531_mdio_st {
0443 MT7531_MDIO_ST_CL45 = 0,
0444 MT7531_MDIO_ST_CL22 = 1,
0445 };
0446
0447 #define MT7531_MDIO_CL22_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \
0448 MT7531_MDIO_CMD(MT7531_MDIO_READ))
0449 #define MT7531_MDIO_CL22_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \
0450 MT7531_MDIO_CMD(MT7531_MDIO_WRITE))
0451 #define MT7531_MDIO_CL45_ADDR (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
0452 MT7531_MDIO_CMD(MT7531_MDIO_ADDR))
0453 #define MT7531_MDIO_CL45_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
0454 MT7531_MDIO_CMD(MT7531_MDIO_READ))
0455 #define MT7531_MDIO_CL45_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
0456 MT7531_MDIO_CMD(MT7531_MDIO_WRITE))
0457
0458
0459 #define MT7531_CLKGEN_CTRL 0x7500
0460 #define CLK_SKEW_OUT(x) (((x) & 0x3) << 8)
0461 #define CLK_SKEW_OUT_MASK GENMASK(9, 8)
0462 #define CLK_SKEW_IN(x) (((x) & 0x3) << 6)
0463 #define CLK_SKEW_IN_MASK GENMASK(7, 6)
0464 #define RXCLK_NO_DELAY BIT(5)
0465 #define TXCLK_NO_REVERSE BIT(4)
0466 #define GP_MODE(x) (((x) & 0x3) << 1)
0467 #define GP_MODE_MASK GENMASK(2, 1)
0468 #define GP_CLK_EN BIT(0)
0469
0470 enum mt7531_gp_mode {
0471 MT7531_GP_MODE_RGMII = 0,
0472 MT7531_GP_MODE_MII = 1,
0473 MT7531_GP_MODE_REV_MII = 2
0474 };
0475
0476 enum mt7531_clk_skew {
0477 MT7531_CLK_SKEW_NO_CHG = 0,
0478 MT7531_CLK_SKEW_DLY_100PPS = 1,
0479 MT7531_CLK_SKEW_DLY_200PPS = 2,
0480 MT7531_CLK_SKEW_REVERSE = 3,
0481 };
0482
0483
0484 #define MT7530_HWTRAP 0x7800
0485 #define HWTRAP_XTAL_MASK (BIT(10) | BIT(9))
0486 #define HWTRAP_XTAL_25MHZ (BIT(10) | BIT(9))
0487 #define HWTRAP_XTAL_40MHZ (BIT(10))
0488 #define HWTRAP_XTAL_20MHZ (BIT(9))
0489
0490 #define MT7531_HWTRAP 0x7800
0491 #define HWTRAP_XTAL_FSEL_MASK BIT(7)
0492 #define HWTRAP_XTAL_FSEL_25MHZ BIT(7)
0493 #define HWTRAP_XTAL_FSEL_40MHZ 0
0494
0495 #define XTAL_FSEL_S 7
0496 #define XTAL_FSEL_M BIT(7)
0497 #define PHY_EN BIT(6)
0498 #define CHG_STRAP BIT(8)
0499
0500
0501 #define MT7530_MHWTRAP 0x7804
0502 #define MHWTRAP_PHY0_SEL BIT(20)
0503 #define MHWTRAP_MANUAL BIT(16)
0504 #define MHWTRAP_P5_MAC_SEL BIT(13)
0505 #define MHWTRAP_P6_DIS BIT(8)
0506 #define MHWTRAP_P5_RGMII_MODE BIT(7)
0507 #define MHWTRAP_P5_DIS BIT(6)
0508 #define MHWTRAP_PHY_ACCESS BIT(5)
0509
0510
0511 #define MT7530_TOP_SIG_CTRL 0x7808
0512 #define TOP_SIG_CTRL_NORMAL (BIT(17) | BIT(16))
0513
0514 #define MT7531_TOP_SIG_SR 0x780c
0515 #define PAD_DUAL_SGMII_EN BIT(1)
0516 #define PAD_MCM_SMI_EN BIT(0)
0517
0518 #define MT7530_IO_DRV_CR 0x7810
0519 #define P5_IO_CLK_DRV(x) ((x) & 0x3)
0520 #define P5_IO_DATA_DRV(x) (((x) & 0x3) << 4)
0521
0522 #define MT7531_CHIP_REV 0x781C
0523
0524 #define MT7531_PLLGP_EN 0x7820
0525 #define EN_COREPLL BIT(2)
0526 #define SW_CLKSW BIT(1)
0527 #define SW_PLLGP BIT(0)
0528
0529 #define MT7530_P6ECR 0x7830
0530 #define P6_INTF_MODE_MASK 0x3
0531 #define P6_INTF_MODE(x) ((x) & 0x3)
0532
0533 #define MT7531_PLLGP_CR0 0x78a8
0534 #define RG_COREPLL_EN BIT(22)
0535 #define RG_COREPLL_POSDIV_S 23
0536 #define RG_COREPLL_POSDIV_M 0x3800000
0537 #define RG_COREPLL_SDM_PCW_S 1
0538 #define RG_COREPLL_SDM_PCW_M 0x3ffffe
0539 #define RG_COREPLL_SDM_PCW_CHG BIT(0)
0540
0541
0542 #define MT7531_ANA_PLLGP_CR2 0x78b0
0543 #define MT7531_ANA_PLLGP_CR5 0x78bc
0544
0545
0546 #define MT7530_TRGMII_RCK_CTRL 0x7a00
0547 #define RX_RST BIT(31)
0548 #define RXC_DQSISEL BIT(30)
0549 #define DQSI1_TAP_MASK (0x7f << 8)
0550 #define DQSI0_TAP_MASK 0x7f
0551 #define DQSI1_TAP(x) (((x) & 0x7f) << 8)
0552 #define DQSI0_TAP(x) ((x) & 0x7f)
0553
0554 #define MT7530_TRGMII_RCK_RTT 0x7a04
0555 #define DQS1_GATE BIT(31)
0556 #define DQS0_GATE BIT(30)
0557
0558 #define MT7530_TRGMII_RD(x) (0x7a10 + (x) * 8)
0559 #define BSLIP_EN BIT(31)
0560 #define EDGE_CHK BIT(30)
0561 #define RD_TAP_MASK 0x7f
0562 #define RD_TAP(x) ((x) & 0x7f)
0563
0564 #define MT7530_TRGMII_TXCTRL 0x7a40
0565 #define TRAIN_TXEN BIT(31)
0566 #define TXC_INV BIT(30)
0567 #define TX_RST BIT(28)
0568
0569 #define MT7530_TRGMII_TD_ODT(i) (0x7a54 + 8 * (i))
0570 #define TD_DM_DRVP(x) ((x) & 0xf)
0571 #define TD_DM_DRVN(x) (((x) & 0xf) << 4)
0572
0573 #define MT7530_TRGMII_TCK_CTRL 0x7a78
0574 #define TCK_TAP(x) (((x) & 0xf) << 8)
0575
0576 #define MT7530_P5RGMIIRXCR 0x7b00
0577 #define CSR_RGMII_EDGE_ALIGN BIT(8)
0578 #define CSR_RGMII_RXC_0DEG_CFG(x) ((x) & 0xf)
0579
0580 #define MT7530_P5RGMIITXCR 0x7b04
0581 #define CSR_RGMII_TXC_CFG(x) ((x) & 0x1f)
0582
0583
0584 #define MT7531_GPIO_MODE0 0x7c0c
0585 #define MT7531_GPIO0_MASK GENMASK(3, 0)
0586 #define MT7531_GPIO0_INTERRUPT 1
0587
0588 #define MT7531_GPIO_MODE1 0x7c10
0589 #define MT7531_GPIO11_RG_RXD2_MASK GENMASK(15, 12)
0590 #define MT7531_EXT_P_MDC_11 (2 << 12)
0591 #define MT7531_GPIO12_RG_RXD3_MASK GENMASK(19, 16)
0592 #define MT7531_EXT_P_MDIO_12 (2 << 16)
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604 #define MT7530_LED_EN 0x7d00
0605
0606 #define MT7530_LED_IO_MODE 0x7d04
0607
0608 #define MT7530_LED_GPIO_DIR 0x7d10
0609
0610 #define MT7530_LED_GPIO_OE 0x7d14
0611
0612 #define MT7530_LED_GPIO_DATA 0x7d18
0613
0614 #define MT7530_CREV 0x7ffc
0615 #define CHIP_NAME_SHIFT 16
0616 #define MT7530_ID 0x7530
0617
0618 #define MT7531_CREV 0x781C
0619 #define CHIP_REV_M 0x0f
0620 #define MT7531_ID 0x7531
0621
0622
0623 #define CORE_PLL_GROUP2 0x401
0624 #define RG_SYSPLL_EN_NORMAL BIT(15)
0625 #define RG_SYSPLL_VODEN BIT(14)
0626 #define RG_SYSPLL_LF BIT(13)
0627 #define RG_SYSPLL_RST_DLY(x) (((x) & 0x3) << 12)
0628 #define RG_SYSPLL_LVROD_EN BIT(10)
0629 #define RG_SYSPLL_PREDIV(x) (((x) & 0x3) << 8)
0630 #define RG_SYSPLL_POSDIV(x) (((x) & 0x3) << 5)
0631 #define RG_SYSPLL_FBKSEL BIT(4)
0632 #define RT_SYSPLL_EN_AFE_OLT BIT(0)
0633
0634 #define CORE_PLL_GROUP4 0x403
0635 #define RG_SYSPLL_DDSFBK_EN BIT(12)
0636 #define RG_SYSPLL_BIAS_EN BIT(11)
0637 #define RG_SYSPLL_BIAS_LPF_EN BIT(10)
0638 #define MT7531_PHY_PLL_OFF BIT(5)
0639 #define MT7531_PHY_PLL_BYPASS_MODE BIT(4)
0640
0641 #define MT753X_CTRL_PHY_ADDR 0
0642
0643 #define CORE_PLL_GROUP5 0x404
0644 #define RG_LCDDS_PCW_NCPO1(x) ((x) & 0xffff)
0645
0646 #define CORE_PLL_GROUP6 0x405
0647 #define RG_LCDDS_PCW_NCPO0(x) ((x) & 0xffff)
0648
0649 #define CORE_PLL_GROUP7 0x406
0650 #define RG_LCDDS_PWDB BIT(15)
0651 #define RG_LCDDS_ISO_EN BIT(13)
0652 #define RG_LCCDS_C(x) (((x) & 0x7) << 4)
0653 #define RG_LCDDS_PCW_NCPO_CHG BIT(3)
0654
0655 #define CORE_PLL_GROUP10 0x409
0656 #define RG_LCDDS_SSC_DELTA(x) ((x) & 0xfff)
0657
0658 #define CORE_PLL_GROUP11 0x40a
0659 #define RG_LCDDS_SSC_DELTA1(x) ((x) & 0xfff)
0660
0661 #define CORE_GSWPLL_GRP1 0x40d
0662 #define RG_GSWPLL_PREDIV(x) (((x) & 0x3) << 14)
0663 #define RG_GSWPLL_POSDIV_200M(x) (((x) & 0x3) << 12)
0664 #define RG_GSWPLL_EN_PRE BIT(11)
0665 #define RG_GSWPLL_FBKSEL BIT(10)
0666 #define RG_GSWPLL_BP BIT(9)
0667 #define RG_GSWPLL_BR BIT(8)
0668 #define RG_GSWPLL_FBKDIV_200M(x) ((x) & 0xff)
0669
0670 #define CORE_GSWPLL_GRP2 0x40e
0671 #define RG_GSWPLL_POSDIV_500M(x) (((x) & 0x3) << 8)
0672 #define RG_GSWPLL_FBKDIV_500M(x) ((x) & 0xff)
0673
0674 #define CORE_TRGMII_GSW_CLK_CG 0x410
0675 #define REG_GSWCK_EN BIT(0)
0676 #define REG_TRGMIICK_EN BIT(1)
0677
0678 #define MIB_DESC(_s, _o, _n) \
0679 { \
0680 .size = (_s), \
0681 .offset = (_o), \
0682 .name = (_n), \
0683 }
0684
0685 struct mt7530_mib_desc {
0686 unsigned int size;
0687 unsigned int offset;
0688 const char *name;
0689 };
0690
0691 struct mt7530_fdb {
0692 u16 vid;
0693 u8 port_mask;
0694 u8 aging;
0695 u8 mac[6];
0696 bool noarp;
0697 };
0698
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708 struct mt7530_port {
0709 bool enable;
0710 u32 pm;
0711 u16 pvid;
0712 };
0713
0714
0715 enum p5_interface_select {
0716 P5_DISABLED = 0,
0717 P5_INTF_SEL_PHY_P0,
0718 P5_INTF_SEL_PHY_P4,
0719 P5_INTF_SEL_GMAC5,
0720 P5_INTF_SEL_GMAC5_SGMII,
0721 };
0722
0723 static const char *p5_intf_modes(unsigned int p5_interface)
0724 {
0725 switch (p5_interface) {
0726 case P5_DISABLED:
0727 return "DISABLED";
0728 case P5_INTF_SEL_PHY_P0:
0729 return "PHY P0";
0730 case P5_INTF_SEL_PHY_P4:
0731 return "PHY P4";
0732 case P5_INTF_SEL_GMAC5:
0733 return "GMAC5";
0734 case P5_INTF_SEL_GMAC5_SGMII:
0735 return "GMAC5_SGMII";
0736 default:
0737 return "unknown";
0738 }
0739 }
0740
0741 struct mt7530_priv;
0742
0743 struct mt753x_pcs {
0744 struct phylink_pcs pcs;
0745 struct mt7530_priv *priv;
0746 int port;
0747 };
0748
0749
0750
0751
0752
0753
0754
0755
0756
0757
0758
0759
0760
0761
0762
0763 struct mt753x_info {
0764 enum mt753x_id id;
0765
0766 const struct phylink_pcs_ops *pcs_ops;
0767
0768 int (*sw_setup)(struct dsa_switch *ds);
0769 int (*phy_read)(struct mt7530_priv *priv, int port, int regnum);
0770 int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val);
0771 int (*pad_setup)(struct dsa_switch *ds, phy_interface_t interface);
0772 int (*cpu_port_config)(struct dsa_switch *ds, int port);
0773 void (*mac_port_get_caps)(struct dsa_switch *ds, int port,
0774 struct phylink_config *config);
0775 void (*mac_port_validate)(struct dsa_switch *ds, int port,
0776 phy_interface_t interface,
0777 unsigned long *supported);
0778 int (*mac_port_config)(struct dsa_switch *ds, int port,
0779 unsigned int mode,
0780 phy_interface_t interface);
0781 };
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804 struct mt7530_priv {
0805 struct device *dev;
0806 struct dsa_switch *ds;
0807 struct mii_bus *bus;
0808 struct reset_control *rstc;
0809 struct regulator *core_pwr;
0810 struct regulator *io_pwr;
0811 struct gpio_desc *reset;
0812 const struct mt753x_info *info;
0813 unsigned int id;
0814 bool mcm;
0815 phy_interface_t p6_interface;
0816 phy_interface_t p5_interface;
0817 unsigned int p5_intf_sel;
0818 u8 mirror_rx;
0819 u8 mirror_tx;
0820
0821 struct mt7530_port ports[MT7530_NUM_PORTS];
0822 struct mt753x_pcs pcs[MT7530_NUM_PORTS];
0823
0824 struct mutex reg_mutex;
0825 int irq;
0826 struct irq_domain *irq_domain;
0827 u32 irq_enable;
0828 };
0829
0830 struct mt7530_hw_vlan_entry {
0831 int port;
0832 u8 old_members;
0833 bool untagged;
0834 };
0835
0836 static inline void mt7530_hw_vlan_entry_init(struct mt7530_hw_vlan_entry *e,
0837 int port, bool untagged)
0838 {
0839 e->port = port;
0840 e->untagged = untagged;
0841 }
0842
0843 typedef void (*mt7530_vlan_op)(struct mt7530_priv *,
0844 struct mt7530_hw_vlan_entry *);
0845
0846 struct mt7530_hw_stats {
0847 const char *string;
0848 u16 reg;
0849 u8 sizeof_stat;
0850 };
0851
0852 struct mt7530_dummy_poll {
0853 struct mt7530_priv *priv;
0854 u32 reg;
0855 };
0856
0857 static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p,
0858 struct mt7530_priv *priv, u32 reg)
0859 {
0860 p->priv = priv;
0861 p->reg = reg;
0862 }
0863
0864 #endif