> The current initialization sequences use QMP v5 registers. Adding > support for a new SerDes generation requires selecting its sequences by > the compatible. > > Store the initial interface and per-rate initializer callbacks in match > data. Use a selector for validation and calibration, rejecting modes > without an initializer before accessing registers. This also protects > calibration invoked directly or through power-on. > > Populate the existing SGMII/1000BASE-X and 2500BASE-X initializers for > SA8775P and retain SGMII as its initial interface. Register programming > and readiness checks are unchanged. > > Signed-off-by: Mohd Ayaan Anwar Hi Mohd, I think the patch is fine, just few comments inline. Regards, Lorenzo > --- > drivers/phy/qualcomm/phy-qcom-sgmii-eth.c | 76 ++++++++++++++++++++++--------- > 1 file changed, 55 insertions(+), 21 deletions(-) > > diff --git a/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c b/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c > index 196e9f057387..25e49f2b6824 100644 > --- a/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c > +++ b/drivers/phy/qualcomm/phy-qcom-sgmii-eth.c > @@ -34,13 +34,42 @@ static const struct regulator_bulk_data qcom_dwmac_sgmii_phy_vregs[] = { > > #define QCOM_SGMII_NUM_SUPPLIES ARRAY_SIZE(qcom_dwmac_sgmii_phy_vregs) > > +struct qcom_dwmac_sgmii_phy_match_data { > + /* Initial interface used before the consumer selects a mode. */ > + phy_interface_t interface; > + void (*init_1g)(struct regmap *regmap); > + void (*init_2p5g)(struct regmap *regmap); > +}; > + > struct qcom_dwmac_sgmii_phy_data { > + const struct qcom_dwmac_sgmii_phy_match_data *match_data; > struct regulator_bulk_data *vregs; > struct regmap *regmap; > struct clk *refclk; > phy_interface_t interface; > }; > > +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)) > +{ > + switch (submode) { > + case PHY_INTERFACE_MODE_SGMII: > + case PHY_INTERFACE_MODE_1000BASEX: > + /* 1.25 Gbaud */ > + *init = match_data->init_1g; > + break; > + case PHY_INTERFACE_MODE_2500BASEX: > + /* 3.125 Gbaud */ > + *init = match_data->init_2p5g; > + break; > + default: > + return -EINVAL; > + } > + > + return *init ? 0 : -EINVAL; I guess you can run the function here instead of returning it, right? > +} > + > static void qcom_dwmac_sgmii_phy_init_v5_1g(struct regmap *regmap) > { > regmap_write(regmap, QSERDES_PCS + QPHY_PCS_SW_RESET, 0x01); > @@ -231,20 +260,14 @@ 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; > > - switch (data->interface) { > - case PHY_INTERFACE_MODE_SGMII: > - case PHY_INTERFACE_MODE_1000BASEX: > - /* 1.25Gbps mode */ > - qcom_dwmac_sgmii_phy_init_v5_1g(data->regmap); > - break; > - case PHY_INTERFACE_MODE_2500BASEX: > - /* 3.125Gbps mode */ > - qcom_dwmac_sgmii_phy_init_v5_2p5g(data->regmap); > - break; > - default: > - return -EINVAL; > - } > + ret = qcom_dwmac_sgmii_phy_select_init(data->match_data, data->interface, &init); > + if (ret) > + return ret; > + > + init(data->regmap); > > if (qcom_dwmac_sgmii_phy_poll_status(data->regmap, > QSERDES_QMP_PLL + QSERDES_V5_COM_C_READY_STATUS, > @@ -325,15 +348,13 @@ static int qcom_dwmac_sgmii_phy_validate(struct phy *phy, enum phy_mode mode, > int submode, > union phy_configure_opts *opts) > { > + struct qcom_dwmac_sgmii_phy_data *data = phy_get_drvdata(phy); > + void (*init)(struct regmap *regmap); > + > if (mode != PHY_MODE_ETHERNET) > return -EINVAL; > > - if (submode == PHY_INTERFACE_MODE_SGMII || > - submode == PHY_INTERFACE_MODE_1000BASEX || > - submode == PHY_INTERFACE_MODE_2500BASEX) > - return 0; > - > - return -EINVAL; > + return qcom_dwmac_sgmii_phy_select_init(data->match_data, submode, &init); Why is it needed here? It seems you are not using the init function pointer, right? > } > > static int qcom_dwmac_sgmii_phy_set_mode(struct phy *phy, enum phy_mode mode, > @@ -385,7 +406,11 @@ static int qcom_dwmac_sgmii_phy_probe(struct platform_device *pdev) > if (!data) > return -ENOMEM; > > - data->interface = PHY_INTERFACE_MODE_SGMII; > + data->match_data = device_get_match_data(dev); > + if (!data->match_data) > + return -EINVAL; > + > + data->interface = data->match_data->interface; > > base = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(base)) > @@ -419,8 +444,17 @@ static int qcom_dwmac_sgmii_phy_probe(struct platform_device *pdev) > return 0; > } > > +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, > +}; > + > static const struct of_device_id qcom_dwmac_sgmii_phy_of_match[] = { > - { .compatible = "qcom,sa8775p-dwmac-sgmii-phy" }, > + { > + .compatible = "qcom,sa8775p-dwmac-sgmii-phy", > + .data = &sa8775p_match_data, > + }, > { }, > }; > MODULE_DEVICE_TABLE(of, qcom_dwmac_sgmii_phy_of_match); > > -- > 2.34.1 >