> QMP v5 and v7 use different offsets for the COM ready and common-status > registers, while the Ethernet SerDes readiness checks otherwise match. > > Move the polling sequence into a helper and supply these two offsets > through match data. Populate the v5 offsets for SA8775P, preserving the > check order, masks, timeouts and error handling. > > Signed-off-by: Mohd Ayaan Anwar Reviewed-by: Lorenzo Bianconi > --- > drivers/phy/qualcomm/phy-qcom-sgmii-eth.c | 92 +++++++++++++++++-------------- > 1 file changed, 52 insertions(+), 40 deletions(-) > > diff --git a/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c b/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c > index 25e49f2b6824..2aa32870dd69 100644 > --- a/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c > +++ b/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c > @@ -39,6 +39,8 @@ struct qcom_dwmac_sgmii_phy_match_data { > phy_interface_t interface; > void (*init_1g)(struct regmap *regmap); > void (*init_2p5g)(struct regmap *regmap); > + u32 com_c_ready_status; > + u32 com_cmn_status; > }; > > struct qcom_dwmac_sgmii_phy_data { > @@ -49,6 +51,53 @@ struct qcom_dwmac_sgmii_phy_data { > phy_interface_t interface; > }; > > +static inline int > +qcom_dwmac_sgmii_phy_poll_status(struct regmap *regmap, unsigned int reg, > + unsigned int bit) > +{ > + unsigned int val; > + > + return regmap_read_poll_timeout(regmap, reg, val, > + val & bit, 1500, 750000); > +} > + > +static int qcom_dwmac_sgmii_phy_poll_ready(struct phy *phy) > +{ > + struct qcom_dwmac_sgmii_phy_data *data = phy_get_drvdata(phy); > + const struct qcom_dwmac_sgmii_phy_match_data *match_data = data->match_data; > + struct device *dev = phy->dev.parent; > + > + if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > + QSERDES_QMP_PLL + match_data->com_c_ready_status, > + QSERDES_COM_C_READY)) { > + dev_err(dev, "QSERDES_COM_C_READY_STATUS timed-out"); > + return -ETIMEDOUT; > + } > + > + if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > + QSERDES_PCS + QPHY_PCS_PCS_READY_STATUS, > + QSERDES_PCS_READY)) { > + dev_err(dev, "PCS_READY timed-out"); > + return -ETIMEDOUT; > + } > + > + if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > + QSERDES_PCS + QPHY_PCS_PCS_READY_STATUS, > + QSERDES_PCS_SGMIIPHY_READY)) { > + dev_err(dev, "SGMIIPHY_READY timed-out"); > + return -ETIMEDOUT; > + } > + > + if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > + QSERDES_QMP_PLL + match_data->com_cmn_status, > + QSERDES_COM_C_PLL_LOCKED)) { > + dev_err(dev, "PLL Lock Status timed-out"); > + return -ETIMEDOUT; > + } > + > + return 0; > +} > + > static int > qcom_dwmac_sgmii_phy_select_init(const struct qcom_dwmac_sgmii_phy_match_data *match_data, > int submode, void (**init)(struct regmap *regmap)) > @@ -246,20 +295,9 @@ static void qcom_dwmac_sgmii_phy_init_v5_2p5g(struct regmap *regmap) > regmap_write(regmap, QSERDES_PCS + QPHY_PCS_PHY_START, 0x01); > } > > -static inline int > -qcom_dwmac_sgmii_phy_poll_status(struct regmap *regmap, unsigned int reg, > - unsigned int bit) > -{ > - unsigned int val; > - > - return regmap_read_poll_timeout(regmap, reg, val, > - val & bit, 1500, 750000); > -} > - > static int qcom_dwmac_sgmii_phy_calibrate(struct phy *phy) > { > struct qcom_dwmac_sgmii_phy_data *data = phy_get_drvdata(phy); > - struct device *dev = phy->dev.parent; > void (*init)(struct regmap *regmap); > int ret; > > @@ -269,35 +307,7 @@ static int qcom_dwmac_sgmii_phy_calibrate(struct phy *phy) > > init(data->regmap); > > - if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > - QSERDES_QMP_PLL + QSERDES_V5_COM_C_READY_STATUS, > - QSERDES_COM_C_READY)) { > - dev_err(dev, "QSERDES_COM_C_READY_STATUS timed-out"); > - return -ETIMEDOUT; > - } > - > - if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > - QSERDES_PCS + QPHY_PCS_PCS_READY_STATUS, > - QSERDES_PCS_READY)) { > - dev_err(dev, "PCS_READY timed-out"); > - return -ETIMEDOUT; > - } > - > - if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > - QSERDES_PCS + QPHY_PCS_PCS_READY_STATUS, > - QSERDES_PCS_SGMIIPHY_READY)) { > - dev_err(dev, "SGMIIPHY_READY timed-out"); > - return -ETIMEDOUT; > - } > - > - if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > - QSERDES_QMP_PLL + QSERDES_V5_COM_CMN_STATUS, > - QSERDES_COM_C_PLL_LOCKED)) { > - dev_err(dev, "PLL Lock Status timed-out"); > - return -ETIMEDOUT; > - } > - > - return 0; > + return qcom_dwmac_sgmii_phy_poll_ready(phy); > } > > static int qcom_dwmac_sgmii_phy_power_on(struct phy *phy) > @@ -448,6 +458,8 @@ static const struct qcom_dwmac_sgmii_phy_match_data sa8775p_match_data = { > .interface = PHY_INTERFACE_MODE_SGMII, > .init_1g = qcom_dwmac_sgmii_phy_init_v5_1g, > .init_2p5g = qcom_dwmac_sgmii_phy_init_v5_2p5g, > + .com_c_ready_status = QSERDES_V5_COM_C_READY_STATUS, > + .com_cmn_status = QSERDES_V5_COM_CMN_STATUS, > }; > > static const struct of_device_id qcom_dwmac_sgmii_phy_of_match[] = { > > -- > 2.34.1 >