0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _MSCC_PHY_H_
0009 #define _MSCC_PHY_H_
0010
0011 #if IS_ENABLED(CONFIG_MACSEC)
0012 #include "mscc_macsec.h"
0013 #endif
0014
0015 enum rgmii_clock_delay {
0016 RGMII_CLK_DELAY_0_2_NS = 0,
0017 RGMII_CLK_DELAY_0_8_NS = 1,
0018 RGMII_CLK_DELAY_1_1_NS = 2,
0019 RGMII_CLK_DELAY_1_7_NS = 3,
0020 RGMII_CLK_DELAY_2_0_NS = 4,
0021 RGMII_CLK_DELAY_2_3_NS = 5,
0022 RGMII_CLK_DELAY_2_6_NS = 6,
0023 RGMII_CLK_DELAY_3_4_NS = 7
0024 };
0025
0026
0027
0028 #define MSCC_PHY_BYPASS_CONTROL 18
0029 #define DISABLE_HP_AUTO_MDIX_MASK 0x0080
0030 #define DISABLE_PAIR_SWAP_CORR_MASK 0x0020
0031 #define DISABLE_POLARITY_CORR_MASK 0x0010
0032 #define PARALLEL_DET_IGNORE_ADVERTISED 0x0008
0033
0034 #define MSCC_PHY_EXT_CNTL_STATUS 22
0035 #define SMI_BROADCAST_WR_EN 0x0001
0036
0037 #define MSCC_PHY_ERR_RX_CNT 19
0038 #define MSCC_PHY_ERR_FALSE_CARRIER_CNT 20
0039 #define MSCC_PHY_ERR_LINK_DISCONNECT_CNT 21
0040 #define ERR_CNT_MASK GENMASK(7, 0)
0041
0042 #define MSCC_PHY_EXT_PHY_CNTL_1 23
0043 #define MAC_IF_SELECTION_MASK 0x1800
0044 #define MAC_IF_SELECTION_GMII 0
0045 #define MAC_IF_SELECTION_RMII 1
0046 #define MAC_IF_SELECTION_RGMII 2
0047 #define MAC_IF_SELECTION_POS 11
0048 #define VSC8584_MAC_IF_SELECTION_MASK 0x1000
0049 #define VSC8584_MAC_IF_SELECTION_SGMII 0
0050 #define VSC8584_MAC_IF_SELECTION_1000BASEX 1
0051 #define VSC8584_MAC_IF_SELECTION_POS 12
0052 #define FAR_END_LOOPBACK_MODE_MASK 0x0008
0053 #define MEDIA_OP_MODE_MASK 0x0700
0054 #define MEDIA_OP_MODE_COPPER 0
0055 #define MEDIA_OP_MODE_SERDES 1
0056 #define MEDIA_OP_MODE_1000BASEX 2
0057 #define MEDIA_OP_MODE_100BASEFX 3
0058 #define MEDIA_OP_MODE_AMS_COPPER_SERDES 5
0059 #define MEDIA_OP_MODE_AMS_COPPER_1000BASEX 6
0060 #define MEDIA_OP_MODE_AMS_COPPER_100BASEFX 7
0061 #define MEDIA_OP_MODE_POS 8
0062
0063 #define MSCC_PHY_EXT_PHY_CNTL_2 24
0064
0065 #define MII_VSC85XX_INT_MASK 25
0066 #define MII_VSC85XX_INT_MASK_MDINT BIT(15)
0067 #define MII_VSC85XX_INT_MASK_LINK_CHG BIT(13)
0068 #define MII_VSC85XX_INT_MASK_WOL BIT(6)
0069 #define MII_VSC85XX_INT_MASK_EXT BIT(5)
0070 #define MII_VSC85XX_INT_STATUS 26
0071
0072 #define MII_VSC85XX_INT_MASK_MASK (MII_VSC85XX_INT_MASK_MDINT | \
0073 MII_VSC85XX_INT_MASK_LINK_CHG | \
0074 MII_VSC85XX_INT_MASK_EXT)
0075
0076 #define MSCC_PHY_WOL_MAC_CONTROL 27
0077 #define EDGE_RATE_CNTL_POS 5
0078 #define EDGE_RATE_CNTL_MASK 0x00E0
0079
0080 #define MSCC_PHY_DEV_AUX_CNTL 28
0081 #define HP_AUTO_MDIX_X_OVER_IND_MASK 0x2000
0082
0083 #define MSCC_PHY_LED_MODE_SEL 29
0084 #define LED_MODE_SEL_POS(x) ((x) * 4)
0085 #define LED_MODE_SEL_MASK(x) (GENMASK(3, 0) << LED_MODE_SEL_POS(x))
0086 #define LED_MODE_SEL(x, mode) (((mode) << LED_MODE_SEL_POS(x)) & LED_MODE_SEL_MASK(x))
0087
0088 #define MSCC_EXT_PAGE_CSR_CNTL_17 17
0089 #define MSCC_EXT_PAGE_CSR_CNTL_18 18
0090
0091 #define MSCC_EXT_PAGE_CSR_CNTL_19 19
0092 #define MSCC_PHY_CSR_CNTL_19_REG_ADDR(x) (x)
0093 #define MSCC_PHY_CSR_CNTL_19_TARGET(x) ((x) << 12)
0094 #define MSCC_PHY_CSR_CNTL_19_READ BIT(14)
0095 #define MSCC_PHY_CSR_CNTL_19_CMD BIT(15)
0096
0097 #define MSCC_EXT_PAGE_CSR_CNTL_20 20
0098 #define MSCC_PHY_CSR_CNTL_20_TARGET(x) (x)
0099
0100 #define PHY_MCB_TARGET 0x07
0101 #define PHY_MCB_S6G_WRITE BIT(31)
0102 #define PHY_MCB_S6G_READ BIT(30)
0103
0104 #define PHY_S6G_PLL5G_CFG0 0x06
0105 #define PHY_S6G_PLL5G_CFG2 0x08
0106 #define PHY_S6G_LCPLL_CFG 0x11
0107 #define PHY_S6G_PLL_CFG 0x2b
0108 #define PHY_S6G_COMMON_CFG 0x2c
0109 #define PHY_S6G_GPC_CFG 0x2e
0110 #define PHY_S6G_MISC_CFG 0x3b
0111 #define PHY_MCB_S6G_CFG 0x3f
0112 #define PHY_S6G_DFT_CFG2 0x3e
0113 #define PHY_S6G_PLL_STATUS 0x31
0114 #define PHY_S6G_IB_STATUS0 0x2f
0115
0116 #define PHY_S6G_SYS_RST_POS 31
0117 #define PHY_S6G_ENA_LANE_POS 18
0118 #define PHY_S6G_ENA_LOOP_POS 8
0119 #define PHY_S6G_QRATE_POS 6
0120 #define PHY_S6G_IF_MODE_POS 4
0121 #define PHY_S6G_PLL_ENA_OFFS_POS 21
0122 #define PHY_S6G_PLL_FSM_CTRL_DATA_POS 8
0123 #define PHY_S6G_PLL_FSM_ENA_POS 7
0124
0125 #define PHY_S6G_CFG2_FSM_DIS 1
0126 #define PHY_S6G_CFG2_FSM_CLK_BP 23
0127
0128 #define MSCC_EXT_PAGE_ACCESS 31
0129 #define MSCC_PHY_PAGE_STANDARD 0x0000
0130 #define MSCC_PHY_PAGE_EXTENDED 0x0001
0131 #define MSCC_PHY_PAGE_EXTENDED_2 0x0002
0132 #define MSCC_PHY_PAGE_EXTENDED_3 0x0003
0133 #define MSCC_PHY_PAGE_EXTENDED_4 0x0004
0134 #define MSCC_PHY_PAGE_CSR_CNTL MSCC_PHY_PAGE_EXTENDED_4
0135 #define MSCC_PHY_PAGE_MACSEC MSCC_PHY_PAGE_EXTENDED_4
0136
0137
0138
0139 #define MSCC_PHY_PAGE_EXTENDED_GPIO 0x0010
0140 #define MSCC_PHY_PAGE_1588 0x1588
0141 #define MSCC_PHY_PAGE_TEST 0x2a30
0142 #define MSCC_PHY_PAGE_TR 0x52b5
0143 #define MSCC_PHY_GPIO_CONTROL_2 14
0144
0145 #define MSCC_PHY_COMA_MODE 0x2000
0146 #define MSCC_PHY_COMA_OUTPUT 0x1000
0147
0148
0149 #define MSCC_PHY_CU_MEDIA_CRC_VALID_CNT 18
0150 #define VALID_CRC_CNT_CRC_MASK GENMASK(13, 0)
0151
0152 #define MSCC_PHY_EXT_MODE_CNTL 19
0153 #define FORCE_MDI_CROSSOVER_MASK 0x000C
0154 #define FORCE_MDI_CROSSOVER_MDIX 0x000C
0155 #define FORCE_MDI_CROSSOVER_MDI 0x0008
0156
0157 #define MSCC_PHY_ACTIPHY_CNTL 20
0158 #define PHY_ADDR_REVERSED 0x0200
0159 #define DOWNSHIFT_CNTL_MASK 0x001C
0160 #define DOWNSHIFT_EN 0x0010
0161 #define DOWNSHIFT_CNTL_POS 2
0162
0163 #define MSCC_PHY_EXT_PHY_CNTL_4 23
0164 #define PHY_CNTL_4_ADDR_POS 11
0165
0166 #define MSCC_PHY_VERIPHY_CNTL_2 25
0167
0168 #define MSCC_PHY_VERIPHY_CNTL_3 26
0169
0170
0171 #define MSCC_PHY_CU_PMD_TX_CNTL 16
0172
0173
0174 #define VSC8572_RGMII_CNTL 18
0175 #define VSC8572_RGMII_RX_DELAY_MASK 0x000E
0176 #define VSC8572_RGMII_TX_DELAY_MASK 0x0070
0177
0178
0179 #define VSC8502_RGMII_CNTL 20
0180 #define VSC8502_RGMII_RX_DELAY_MASK 0x0070
0181 #define VSC8502_RGMII_TX_DELAY_MASK 0x0007
0182
0183 #define MSCC_PHY_WOL_LOWER_MAC_ADDR 21
0184 #define MSCC_PHY_WOL_MID_MAC_ADDR 22
0185 #define MSCC_PHY_WOL_UPPER_MAC_ADDR 23
0186 #define MSCC_PHY_WOL_LOWER_PASSWD 24
0187 #define MSCC_PHY_WOL_MID_PASSWD 25
0188 #define MSCC_PHY_WOL_UPPER_PASSWD 26
0189
0190 #define MSCC_PHY_WOL_MAC_CONTROL 27
0191 #define SECURE_ON_ENABLE 0x8000
0192 #define SECURE_ON_PASSWD_LEN_4 0x4000
0193
0194 #define MSCC_PHY_EXTENDED_INT 28
0195 #define MSCC_PHY_EXTENDED_INT_MS_EGR BIT(9)
0196
0197
0198 #define MSCC_PHY_SERDES_TX_VALID_CNT 21
0199 #define MSCC_PHY_SERDES_TX_CRC_ERR_CNT 22
0200 #define MSCC_PHY_SERDES_RX_VALID_CNT 28
0201 #define MSCC_PHY_SERDES_RX_CRC_ERR_CNT 29
0202
0203
0204 #define MSCC_DW8051_CNTL_STATUS 0
0205 #define MICRO_NSOFT_RESET 0x8000
0206 #define RUN_FROM_INT_ROM 0x4000
0207 #define AUTOINC_ADDR 0x2000
0208 #define PATCH_RAM_CLK 0x1000
0209 #define MICRO_PATCH_EN 0x0080
0210 #define DW8051_CLK_EN 0x0010
0211 #define MICRO_CLK_EN 0x0008
0212 #define MICRO_CLK_DIVIDE(x) ((x) >> 1)
0213 #define MSCC_DW8051_VLD_MASK 0xf1ff
0214
0215
0216 #define MSCC_TRAP_ROM_ADDR(x) ((x) * 2 + 1)
0217 #define MSCC_PATCH_RAM_ADDR(x) (((x) + 1) * 2)
0218 #define MSCC_INT_MEM_ADDR 11
0219
0220 #define MSCC_INT_MEM_CNTL 12
0221 #define READ_SFR 0x6000
0222 #define READ_PRAM 0x4000
0223 #define READ_ROM 0x2000
0224 #define READ_RAM 0x0000
0225 #define INT_MEM_WRITE_EN 0x1000
0226 #define EN_PATCH_RAM_TRAP_ADDR(x) (0x0100 << ((x) - 1))
0227 #define INT_MEM_DATA_M 0x00ff
0228 #define INT_MEM_DATA(x) (INT_MEM_DATA_M & (x))
0229
0230 #define MSCC_PHY_PROC_CMD 18
0231 #define PROC_CMD_NCOMPLETED 0x8000
0232 #define PROC_CMD_FAILED 0x4000
0233 #define PROC_CMD_SGMII_PORT(x) ((x) << 8)
0234 #define PROC_CMD_FIBER_PORT(x) (0x0100 << (x) % 4)
0235 #define PROC_CMD_QSGMII_PORT 0x0c00
0236 #define PROC_CMD_RST_CONF_PORT 0x0080
0237 #define PROC_CMD_RECONF_PORT 0x0000
0238 #define PROC_CMD_READ_MOD_WRITE_PORT 0x0040
0239 #define PROC_CMD_WRITE 0x0040
0240 #define PROC_CMD_READ 0x0000
0241 #define PROC_CMD_FIBER_DISABLE 0x0020
0242 #define PROC_CMD_FIBER_100BASE_FX 0x0010
0243 #define PROC_CMD_FIBER_1000BASE_X 0x0000
0244 #define PROC_CMD_SGMII_MAC 0x0030
0245 #define PROC_CMD_QSGMII_MAC 0x0020
0246 #define PROC_CMD_NO_MAC_CONF 0x0000
0247 #define PROC_CMD_1588_DEFAULT_INIT 0x0010
0248 #define PROC_CMD_NOP 0x000f
0249 #define PROC_CMD_PHY_INIT 0x000a
0250 #define PROC_CMD_CRC16 0x0008
0251 #define PROC_CMD_FIBER_MEDIA_CONF 0x0001
0252 #define PROC_CMD_MCB_ACCESS_MAC_CONF 0x0000
0253 #define PROC_CMD_NCOMPLETED_TIMEOUT_MS 500
0254
0255 #define MSCC_PHY_MAC_CFG_FASTLINK 19
0256 #define MAC_CFG_MASK 0xc000
0257 #define MAC_CFG_SGMII 0x0000
0258 #define MAC_CFG_QSGMII 0x4000
0259 #define MAC_CFG_RGMII 0x8000
0260
0261
0262 #define MSCC_PHY_TEST_PAGE_5 5
0263 #define MSCC_PHY_TEST_PAGE_8 8
0264 #define TR_CLK_DISABLE 0x8000
0265 #define MSCC_PHY_TEST_PAGE_9 9
0266 #define MSCC_PHY_TEST_PAGE_20 20
0267 #define MSCC_PHY_TEST_PAGE_24 24
0268
0269
0270 #define MSCC_PHY_TR_CNTL 16
0271 #define TR_WRITE 0x8000
0272 #define TR_ADDR(x) (0x7fff & (x))
0273 #define MSCC_PHY_TR_LSB 17
0274 #define MSCC_PHY_TR_MSB 18
0275
0276
0277
0278
0279 #define PHY_ID_VSC8502 0x00070630
0280 #define PHY_ID_VSC8504 0x000704c0
0281 #define PHY_ID_VSC8514 0x00070670
0282 #define PHY_ID_VSC8530 0x00070560
0283 #define PHY_ID_VSC8531 0x00070570
0284 #define PHY_ID_VSC8540 0x00070760
0285 #define PHY_ID_VSC8541 0x00070770
0286 #define PHY_ID_VSC8552 0x000704e0
0287 #define PHY_ID_VSC856X 0x000707e0
0288 #define PHY_ID_VSC8572 0x000704d0
0289 #define PHY_ID_VSC8574 0x000704a0
0290 #define PHY_ID_VSC8575 0x000707d0
0291 #define PHY_ID_VSC8582 0x000707b0
0292 #define PHY_ID_VSC8584 0x000707c0
0293
0294 #define MSCC_VDDMAC_1500 1500
0295 #define MSCC_VDDMAC_1800 1800
0296 #define MSCC_VDDMAC_2500 2500
0297 #define MSCC_VDDMAC_3300 3300
0298
0299 #define DOWNSHIFT_COUNT_MAX 5
0300
0301 #define MAX_LEDS 4
0302
0303 #define VSC8584_SUPP_LED_MODES (BIT(VSC8531_LINK_ACTIVITY) | \
0304 BIT(VSC8531_LINK_1000_ACTIVITY) | \
0305 BIT(VSC8531_LINK_100_ACTIVITY) | \
0306 BIT(VSC8531_LINK_10_ACTIVITY) | \
0307 BIT(VSC8531_LINK_100_1000_ACTIVITY) | \
0308 BIT(VSC8531_LINK_10_1000_ACTIVITY) | \
0309 BIT(VSC8531_LINK_10_100_ACTIVITY) | \
0310 BIT(VSC8584_LINK_100FX_1000X_ACTIVITY) | \
0311 BIT(VSC8531_DUPLEX_COLLISION) | \
0312 BIT(VSC8531_COLLISION) | \
0313 BIT(VSC8531_ACTIVITY) | \
0314 BIT(VSC8584_100FX_1000X_ACTIVITY) | \
0315 BIT(VSC8531_AUTONEG_FAULT) | \
0316 BIT(VSC8531_SERIAL_MODE) | \
0317 BIT(VSC8531_FORCE_LED_OFF) | \
0318 BIT(VSC8531_FORCE_LED_ON))
0319
0320 #define VSC85XX_SUPP_LED_MODES (BIT(VSC8531_LINK_ACTIVITY) | \
0321 BIT(VSC8531_LINK_1000_ACTIVITY) | \
0322 BIT(VSC8531_LINK_100_ACTIVITY) | \
0323 BIT(VSC8531_LINK_10_ACTIVITY) | \
0324 BIT(VSC8531_LINK_100_1000_ACTIVITY) | \
0325 BIT(VSC8531_LINK_10_1000_ACTIVITY) | \
0326 BIT(VSC8531_LINK_10_100_ACTIVITY) | \
0327 BIT(VSC8531_DUPLEX_COLLISION) | \
0328 BIT(VSC8531_COLLISION) | \
0329 BIT(VSC8531_ACTIVITY) | \
0330 BIT(VSC8531_AUTONEG_FAULT) | \
0331 BIT(VSC8531_SERIAL_MODE) | \
0332 BIT(VSC8531_FORCE_LED_OFF) | \
0333 BIT(VSC8531_FORCE_LED_ON))
0334
0335 #define MSCC_VSC8584_REVB_INT8051_FW "microchip/mscc_vsc8584_revb_int8051_fb48.bin"
0336 #define MSCC_VSC8584_REVB_INT8051_FW_START_ADDR 0xe800
0337 #define MSCC_VSC8584_REVB_INT8051_FW_CRC 0xfb48
0338
0339 #define MSCC_VSC8574_REVB_INT8051_FW "microchip/mscc_vsc8574_revb_int8051_29e8.bin"
0340 #define MSCC_VSC8574_REVB_INT8051_FW_START_ADDR 0x4000
0341 #define MSCC_VSC8574_REVB_INT8051_FW_CRC 0x29e8
0342
0343 #define VSC8584_REVB 0x0001
0344 #define MSCC_DEV_REV_MASK GENMASK(3, 0)
0345
0346 #define MSCC_ROM_TRAP_SERDES_6G_CFG 0x1E48
0347 #define MSCC_RAM_TRAP_SERDES_6G_CFG 0x1E4F
0348 #define PATCH_VEC_ZERO_EN 0x0100
0349
0350 struct reg_val {
0351 u16 reg;
0352 u32 val;
0353 };
0354
0355 struct vsc85xx_hw_stat {
0356 const char *string;
0357 u8 reg;
0358 u16 page;
0359 u16 mask;
0360 };
0361
0362 struct vsc8531_private {
0363 int rate_magic;
0364 u16 supp_led_modes;
0365 u32 leds_mode[MAX_LEDS];
0366 u8 nleds;
0367 const struct vsc85xx_hw_stat *hw_stats;
0368 u64 *stats;
0369 int nstats;
0370
0371 u8 addr;
0372
0373
0374
0375 unsigned int base_addr;
0376
0377 #if IS_ENABLED(CONFIG_MACSEC)
0378
0379
0380
0381
0382
0383
0384 struct macsec_secy *secy;
0385 struct list_head macsec_flows;
0386 unsigned long ingr_flows;
0387 unsigned long egr_flows;
0388 #endif
0389
0390 struct mii_timestamper mii_ts;
0391
0392 bool input_clk_init;
0393 struct vsc85xx_ptp *ptp;
0394
0395 struct gpio_desc *load_save;
0396
0397
0398
0399
0400
0401
0402 unsigned int ts_base_addr;
0403 u8 ts_base_phy;
0404
0405
0406
0407
0408 struct mutex ts_lock;
0409 struct mutex phc_lock;
0410 };
0411
0412
0413
0414
0415
0416 struct vsc85xx_shared_private {
0417 struct mutex gpio_lock;
0418 };
0419
0420 #if IS_ENABLED(CONFIG_OF_MDIO)
0421 struct vsc8531_edge_rate_table {
0422 u32 vddmac;
0423 u32 slowdown[8];
0424 };
0425 #endif
0426
0427 enum csr_target {
0428 MACRO_CTRL = 0x07,
0429 };
0430
0431 u32 vsc85xx_csr_read(struct phy_device *phydev,
0432 enum csr_target target, u32 reg);
0433
0434 int vsc85xx_csr_write(struct phy_device *phydev,
0435 enum csr_target target, u32 reg, u32 val);
0436
0437 int phy_base_write(struct phy_device *phydev, u32 regnum, u16 val);
0438 int phy_base_read(struct phy_device *phydev, u32 regnum);
0439 int phy_update_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb);
0440 int phy_commit_mcb_s6g(struct phy_device *phydev, u32 reg, u8 mcb);
0441 int vsc8584_cmd(struct phy_device *phydev, u16 val);
0442
0443 #if IS_ENABLED(CONFIG_MACSEC)
0444 int vsc8584_macsec_init(struct phy_device *phydev);
0445 void vsc8584_handle_macsec_interrupt(struct phy_device *phydev);
0446 void vsc8584_config_macsec_intr(struct phy_device *phydev);
0447 #else
0448 static inline int vsc8584_macsec_init(struct phy_device *phydev)
0449 {
0450 return 0;
0451 }
0452 static inline void vsc8584_handle_macsec_interrupt(struct phy_device *phydev)
0453 {
0454 }
0455 static inline void vsc8584_config_macsec_intr(struct phy_device *phydev)
0456 {
0457 }
0458 #endif
0459
0460 #if IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)
0461 void vsc85xx_link_change_notify(struct phy_device *phydev);
0462 void vsc8584_config_ts_intr(struct phy_device *phydev);
0463 int vsc8584_ptp_init(struct phy_device *phydev);
0464 int vsc8584_ptp_probe_once(struct phy_device *phydev);
0465 int vsc8584_ptp_probe(struct phy_device *phydev);
0466 irqreturn_t vsc8584_handle_ts_interrupt(struct phy_device *phydev);
0467 #else
0468 static inline void vsc85xx_link_change_notify(struct phy_device *phydev)
0469 {
0470 }
0471 static inline void vsc8584_config_ts_intr(struct phy_device *phydev)
0472 {
0473 }
0474 static inline int vsc8584_ptp_init(struct phy_device *phydev)
0475 {
0476 return 0;
0477 }
0478 static inline int vsc8584_ptp_probe_once(struct phy_device *phydev)
0479 {
0480 return 0;
0481 }
0482 static inline int vsc8584_ptp_probe(struct phy_device *phydev)
0483 {
0484 return 0;
0485 }
0486 static inline irqreturn_t vsc8584_handle_ts_interrupt(struct phy_device *phydev)
0487 {
0488 return IRQ_NONE;
0489 }
0490 #endif
0491
0492 #endif