Skip to content

Commit 25c4a07

Browse files
Bartosz Golaszewskikuba-moo
authored andcommitted
net: stmmac: dwmac-qcom-ethqos: prepare the driver for more PHY modes
In preparation for supporting SGMII, let's make the code a bit more generic. Add a new callback for MAC configuration so that we can assign a different variant of it in the future. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andrew Halaney <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent feeb271 commit 25c4a07

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ struct ethqos_emac_driver_data {
9292
struct qcom_ethqos {
9393
struct platform_device *pdev;
9494
void __iomem *rgmii_base;
95+
int (*configure_func)(struct qcom_ethqos *ethqos);
9596

9697
unsigned int link_clk_rate;
9798
struct clk *link_clk;
9899
struct phy *serdes_phy;
99100
unsigned int speed;
101+
int phy_mode;
100102

101103
const struct ethqos_emac_por *por;
102104
unsigned int num_por;
@@ -331,13 +333,11 @@ static int ethqos_rgmii_macro_init(struct qcom_ethqos *ethqos)
331333
{
332334
struct device *dev = &ethqos->pdev->dev;
333335
int phase_shift;
334-
int phy_mode;
335336
int loopback;
336337

337338
/* Determine if the PHY adds a 2 ns TX delay or the MAC handles it */
338-
phy_mode = device_get_phy_mode(dev);
339-
if (phy_mode == PHY_INTERFACE_MODE_RGMII_ID ||
340-
phy_mode == PHY_INTERFACE_MODE_RGMII_TXID)
339+
if (ethqos->phy_mode == PHY_INTERFACE_MODE_RGMII_ID ||
340+
ethqos->phy_mode == PHY_INTERFACE_MODE_RGMII_TXID)
341341
phase_shift = 0;
342342
else
343343
phase_shift = RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN;
@@ -483,7 +483,7 @@ static int ethqos_rgmii_macro_init(struct qcom_ethqos *ethqos)
483483
return 0;
484484
}
485485

486-
static int ethqos_configure(struct qcom_ethqos *ethqos)
486+
static int ethqos_configure_rgmii(struct qcom_ethqos *ethqos)
487487
{
488488
struct device *dev = &ethqos->pdev->dev;
489489
volatile unsigned int dll_lock;
@@ -559,6 +559,11 @@ static int ethqos_configure(struct qcom_ethqos *ethqos)
559559
return 0;
560560
}
561561

562+
static int ethqos_configure(struct qcom_ethqos *ethqos)
563+
{
564+
return ethqos->configure_func(ethqos);
565+
}
566+
562567
static void ethqos_fix_mac_speed(void *priv, unsigned int speed)
563568
{
564569
struct qcom_ethqos *ethqos = priv;
@@ -650,6 +655,22 @@ static int qcom_ethqos_probe(struct platform_device *pdev)
650655
goto out_config_dt;
651656
}
652657

658+
ethqos->phy_mode = device_get_phy_mode(dev);
659+
switch (ethqos->phy_mode) {
660+
case PHY_INTERFACE_MODE_RGMII:
661+
case PHY_INTERFACE_MODE_RGMII_ID:
662+
case PHY_INTERFACE_MODE_RGMII_RXID:
663+
case PHY_INTERFACE_MODE_RGMII_TXID:
664+
ethqos->configure_func = ethqos_configure_rgmii;
665+
break;
666+
case -ENODEV:
667+
ret = -ENODEV;
668+
goto out_config_dt;
669+
default:
670+
ret = -EINVAL;
671+
goto out_config_dt;
672+
}
673+
653674
ethqos->pdev = pdev;
654675
ethqos->rgmii_base = devm_platform_ioremap_resource_byname(pdev, "rgmii");
655676
if (IS_ERR(ethqos->rgmii_base)) {

0 commit comments

Comments
 (0)