162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates. 462306a36Sopenharmony_ci * Synopsys DesignWare XPCS helpers 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Author: Jose Abreu <Jose.Abreu@synopsys.com> 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#define SYNOPSYS_XPCS_ID 0x7996ced0 1062306a36Sopenharmony_ci#define SYNOPSYS_XPCS_MASK 0xffffffff 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* Vendor regs access */ 1362306a36Sopenharmony_ci#define DW_VENDOR BIT(15) 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* VR_XS_PCS */ 1662306a36Sopenharmony_ci#define DW_USXGMII_RST BIT(10) 1762306a36Sopenharmony_ci#define DW_USXGMII_EN BIT(9) 1862306a36Sopenharmony_ci#define DW_VR_XS_PCS_DIG_CTRL1 0x0000 1962306a36Sopenharmony_ci#define DW_VR_RST BIT(15) 2062306a36Sopenharmony_ci#define DW_EN_VSMMD1 BIT(13) 2162306a36Sopenharmony_ci#define DW_CL37_BP BIT(12) 2262306a36Sopenharmony_ci#define DW_VR_XS_PCS_DIG_STS 0x0010 2362306a36Sopenharmony_ci#define DW_RXFIFO_ERR GENMASK(6, 5) 2462306a36Sopenharmony_ci#define DW_PSEQ_ST GENMASK(4, 2) 2562306a36Sopenharmony_ci#define DW_PSEQ_ST_GOOD FIELD_PREP(GENMASK(4, 2), 0x4) 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* SR_MII */ 2862306a36Sopenharmony_ci#define DW_USXGMII_FULL BIT(8) 2962306a36Sopenharmony_ci#define DW_USXGMII_SS_MASK (BIT(13) | BIT(6) | BIT(5)) 3062306a36Sopenharmony_ci#define DW_USXGMII_10000 (BIT(13) | BIT(6)) 3162306a36Sopenharmony_ci#define DW_USXGMII_5000 (BIT(13) | BIT(5)) 3262306a36Sopenharmony_ci#define DW_USXGMII_2500 (BIT(5)) 3362306a36Sopenharmony_ci#define DW_USXGMII_1000 (BIT(6)) 3462306a36Sopenharmony_ci#define DW_USXGMII_100 (BIT(13)) 3562306a36Sopenharmony_ci#define DW_USXGMII_10 (0) 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci/* SR_AN */ 3862306a36Sopenharmony_ci#define DW_SR_AN_ADV1 0x10 3962306a36Sopenharmony_ci#define DW_SR_AN_ADV2 0x11 4062306a36Sopenharmony_ci#define DW_SR_AN_ADV3 0x12 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci/* Clause 73 Defines */ 4362306a36Sopenharmony_ci/* AN_LP_ABL1 */ 4462306a36Sopenharmony_ci#define DW_C73_PAUSE BIT(10) 4562306a36Sopenharmony_ci#define DW_C73_ASYM_PAUSE BIT(11) 4662306a36Sopenharmony_ci#define DW_C73_AN_ADV_SF 0x1 4762306a36Sopenharmony_ci/* AN_LP_ABL2 */ 4862306a36Sopenharmony_ci#define DW_C73_1000KX BIT(5) 4962306a36Sopenharmony_ci#define DW_C73_10000KX4 BIT(6) 5062306a36Sopenharmony_ci#define DW_C73_10000KR BIT(7) 5162306a36Sopenharmony_ci/* AN_LP_ABL3 */ 5262306a36Sopenharmony_ci#define DW_C73_2500KX BIT(0) 5362306a36Sopenharmony_ci#define DW_C73_5000KR BIT(1) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* Clause 37 Defines */ 5662306a36Sopenharmony_ci/* VR MII MMD registers offsets */ 5762306a36Sopenharmony_ci#define DW_VR_MII_MMD_CTRL 0x0000 5862306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL1 0x8000 5962306a36Sopenharmony_ci#define DW_VR_MII_AN_CTRL 0x8001 6062306a36Sopenharmony_ci#define DW_VR_MII_AN_INTR_STS 0x8002 6162306a36Sopenharmony_ci/* Enable 2.5G Mode */ 6262306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL1_2G5_EN BIT(2) 6362306a36Sopenharmony_ci/* EEE Mode Control Register */ 6462306a36Sopenharmony_ci#define DW_VR_MII_EEE_MCTRL0 0x8006 6562306a36Sopenharmony_ci#define DW_VR_MII_EEE_MCTRL1 0x800b 6662306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL2 0x80e1 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* VR_MII_DIG_CTRL1 */ 6962306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW BIT(9) 7062306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL1_PHY_MODE_CTRL BIT(0) 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* VR_MII_DIG_CTRL2 */ 7362306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL2_TX_POL_INV BIT(4) 7462306a36Sopenharmony_ci#define DW_VR_MII_DIG_CTRL2_RX_POL_INV BIT(0) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* VR_MII_AN_CTRL */ 7762306a36Sopenharmony_ci#define DW_VR_MII_AN_CTRL_8BIT BIT(8) 7862306a36Sopenharmony_ci#define DW_VR_MII_AN_CTRL_TX_CONFIG_SHIFT 3 7962306a36Sopenharmony_ci#define DW_VR_MII_TX_CONFIG_MASK BIT(3) 8062306a36Sopenharmony_ci#define DW_VR_MII_TX_CONFIG_PHY_SIDE_SGMII 0x1 8162306a36Sopenharmony_ci#define DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII 0x0 8262306a36Sopenharmony_ci#define DW_VR_MII_AN_CTRL_PCS_MODE_SHIFT 1 8362306a36Sopenharmony_ci#define DW_VR_MII_PCS_MODE_MASK GENMASK(2, 1) 8462306a36Sopenharmony_ci#define DW_VR_MII_PCS_MODE_C37_1000BASEX 0x0 8562306a36Sopenharmony_ci#define DW_VR_MII_PCS_MODE_C37_SGMII 0x2 8662306a36Sopenharmony_ci#define DW_VR_MII_AN_INTR_EN BIT(0) 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* VR_MII_AN_INTR_STS */ 8962306a36Sopenharmony_ci#define DW_VR_MII_AN_STS_C37_ANCMPLT_INTR BIT(0) 9062306a36Sopenharmony_ci#define DW_VR_MII_AN_STS_C37_ANSGM_FD BIT(1) 9162306a36Sopenharmony_ci#define DW_VR_MII_AN_STS_C37_ANSGM_SP_SHIFT 2 9262306a36Sopenharmony_ci#define DW_VR_MII_AN_STS_C37_ANSGM_SP GENMASK(3, 2) 9362306a36Sopenharmony_ci#define DW_VR_MII_C37_ANSGM_SP_10 0x0 9462306a36Sopenharmony_ci#define DW_VR_MII_C37_ANSGM_SP_100 0x1 9562306a36Sopenharmony_ci#define DW_VR_MII_C37_ANSGM_SP_1000 0x2 9662306a36Sopenharmony_ci#define DW_VR_MII_C37_ANSGM_SP_LNKSTS BIT(4) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/* SR MII MMD Control defines */ 9962306a36Sopenharmony_ci#define AN_CL37_EN BIT(12) /* Enable Clause 37 auto-nego */ 10062306a36Sopenharmony_ci#define SGMII_SPEED_SS13 BIT(13) /* SGMII speed along with SS6 */ 10162306a36Sopenharmony_ci#define SGMII_SPEED_SS6 BIT(6) /* SGMII speed along with SS13 */ 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* SR MII MMD AN Advertisement defines */ 10462306a36Sopenharmony_ci#define DW_HALF_DUPLEX BIT(6) 10562306a36Sopenharmony_ci#define DW_FULL_DUPLEX BIT(5) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/* VR MII EEE Control 0 defines */ 10862306a36Sopenharmony_ci#define DW_VR_MII_EEE_LTX_EN BIT(0) /* LPI Tx Enable */ 10962306a36Sopenharmony_ci#define DW_VR_MII_EEE_LRX_EN BIT(1) /* LPI Rx Enable */ 11062306a36Sopenharmony_ci#define DW_VR_MII_EEE_TX_QUIET_EN BIT(2) /* Tx Quiet Enable */ 11162306a36Sopenharmony_ci#define DW_VR_MII_EEE_RX_QUIET_EN BIT(3) /* Rx Quiet Enable */ 11262306a36Sopenharmony_ci#define DW_VR_MII_EEE_TX_EN_CTRL BIT(4) /* Tx Control Enable */ 11362306a36Sopenharmony_ci#define DW_VR_MII_EEE_RX_EN_CTRL BIT(7) /* Rx Control Enable */ 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#define DW_VR_MII_EEE_MULT_FACT_100NS_SHIFT 8 11662306a36Sopenharmony_ci#define DW_VR_MII_EEE_MULT_FACT_100NS GENMASK(11, 8) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci/* VR MII EEE Control 1 defines */ 11962306a36Sopenharmony_ci#define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */ 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciint xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg); 12262306a36Sopenharmony_ciint xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val); 12362306a36Sopenharmony_ciint xpcs_read_vpcs(struct dw_xpcs *xpcs, int reg); 12462306a36Sopenharmony_ciint xpcs_write_vpcs(struct dw_xpcs *xpcs, int reg, u16 val); 12562306a36Sopenharmony_ciint nxp_sja1105_sgmii_pma_config(struct dw_xpcs *xpcs); 12662306a36Sopenharmony_ciint nxp_sja1110_sgmii_pma_config(struct dw_xpcs *xpcs); 12762306a36Sopenharmony_ciint nxp_sja1110_2500basex_pma_config(struct dw_xpcs *xpcs); 12862306a36Sopenharmony_ciint txgbe_xpcs_switch_mode(struct dw_xpcs *xpcs, phy_interface_t interface); 129