* [PATCH net-next 1/9] net: stmmac: lpc18xx: convert to PHY_INTF_SEL_x
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 2/9] net: stmmac: lpc18xx: use PHY_INTF_SEL_x directly Russell King (Oracle)
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Use the common dwmac definitions for the PHY interface selection field.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
index 6fffc9dfbae5..66c309a7afb3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -22,8 +22,8 @@
/* Register defines for CREG syscon */
#define LPC18XX_CREG_CREG6 0x12c
# define LPC18XX_CREG_CREG6_ETHMODE_MASK 0x7
-# define LPC18XX_CREG_CREG6_ETHMODE_MII 0x0
-# define LPC18XX_CREG_CREG6_ETHMODE_RMII 0x4
+# define LPC18XX_CREG_CREG6_ETHMODE_MII PHY_INTF_SEL_GMII_MII
+# define LPC18XX_CREG_CREG6_ETHMODE_RMII PHY_INTF_SEL_RMII
static int lpc18xx_dwmac_probe(struct platform_device *pdev)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 2/9] net: stmmac: lpc18xx: use PHY_INTF_SEL_x directly
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 1/9] net: stmmac: lpc18xx: convert to PHY_INTF_SEL_x Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 3/9] net: stmmac: lpc18xx: use stmmac_get_phy_intf_sel() Russell King (Oracle)
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Use the PHY_INTF_SEL_x values directly rather than the driver private
LPC18XX_CREG_CREG6_ETHMODE_x definitions, and convert
LPC18XX_CREG_CREG6_ETHMODE_MASK to use GENMASK().
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
index 66c309a7afb3..895d16dc0a4b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -21,9 +21,7 @@
/* Register defines for CREG syscon */
#define LPC18XX_CREG_CREG6 0x12c
-# define LPC18XX_CREG_CREG6_ETHMODE_MASK 0x7
-# define LPC18XX_CREG_CREG6_ETHMODE_MII PHY_INTF_SEL_GMII_MII
-# define LPC18XX_CREG_CREG6_ETHMODE_RMII PHY_INTF_SEL_RMII
+# define LPC18XX_CREG_CREG6_ETHMODE_MASK GENMASK(2, 0)
static int lpc18xx_dwmac_probe(struct platform_device *pdev)
{
@@ -50,9 +48,9 @@ static int lpc18xx_dwmac_probe(struct platform_device *pdev)
}
if (plat_dat->phy_interface == PHY_INTERFACE_MODE_MII) {
- ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
+ ethmode = PHY_INTF_SEL_GMII_MII;
} else if (plat_dat->phy_interface == PHY_INTERFACE_MODE_RMII) {
- ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
+ ethmode = PHY_INTF_SEL_RMII;
} else {
dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
return -EINVAL;
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 3/9] net: stmmac: lpc18xx: use stmmac_get_phy_intf_sel()
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 1/9] net: stmmac: lpc18xx: convert to PHY_INTF_SEL_x Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 2/9] net: stmmac: lpc18xx: use PHY_INTF_SEL_x directly Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 4/9] net: stmmac: lpc18xx: validate phy_intf_sel Russell King (Oracle)
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Use stmmac_get_phy_intf_sel() to decode the PHY interface mode to the
phy_intf_sel value, and use the result to program the ethernet mode.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
index 895d16dc0a4b..0f6be2a17e65 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -47,15 +47,14 @@ static int lpc18xx_dwmac_probe(struct platform_device *pdev)
return PTR_ERR(reg);
}
- if (plat_dat->phy_interface == PHY_INTERFACE_MODE_MII) {
- ethmode = PHY_INTF_SEL_GMII_MII;
- } else if (plat_dat->phy_interface == PHY_INTERFACE_MODE_RMII) {
- ethmode = PHY_INTF_SEL_RMII;
- } else {
+ if (plat_dat->phy_interface != PHY_INTERFACE_MODE_MII &&
+ plat_dat->phy_interface != PHY_INTERFACE_MODE_RMII) {
dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
return -EINVAL;
}
+ ethmode = stmmac_get_phy_intf_sel(plat_dat->phy_interface);
+
regmap_update_bits(reg, LPC18XX_CREG_CREG6,
LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 4/9] net: stmmac: lpc18xx: validate phy_intf_sel
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
` (2 preceding siblings ...)
2025-11-06 11:23 ` [PATCH net-next 3/9] net: stmmac: lpc18xx: use stmmac_get_phy_intf_sel() Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 5/9] net: stmmac: lpc18xx: use ->set_phy_intf_sel() Russell King (Oracle)
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Validate the phy_intf_sel value rather than the PHY interface mode.
This will allow us to transition to the ->set_phy_intf_sel() method.
Note that this will allow GMII as well as MII as the phy_intf_sel
value is the same for both.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
index 0f6be2a17e65..ec60968113b8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -47,14 +47,13 @@ static int lpc18xx_dwmac_probe(struct platform_device *pdev)
return PTR_ERR(reg);
}
- if (plat_dat->phy_interface != PHY_INTERFACE_MODE_MII &&
- plat_dat->phy_interface != PHY_INTERFACE_MODE_RMII) {
+ ethmode = stmmac_get_phy_intf_sel(plat_dat->phy_interface);
+ if (ethmode != PHY_INTF_SEL_GMII_MII &&
+ ethmode != PHY_INTF_SEL_RMII) {
dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
return -EINVAL;
}
- ethmode = stmmac_get_phy_intf_sel(plat_dat->phy_interface);
-
regmap_update_bits(reg, LPC18XX_CREG_CREG6,
LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 5/9] net: stmmac: lpc18xx: use ->set_phy_intf_sel()
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
` (3 preceding siblings ...)
2025-11-06 11:23 ` [PATCH net-next 4/9] net: stmmac: lpc18xx: validate phy_intf_sel Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 6/9] net: stmmac: sti: use PHY_INTF_SEL_x to select PHY interface Russell King (Oracle)
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Move the configuration of the dwmac PHY interface selection to the new
->set_phy_intf_sel() method.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../ethernet/stmicro/stmmac/dwmac-lpc18xx.c | 36 +++++++++++--------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
index ec60968113b8..c68d7de1f8ac 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -23,12 +23,27 @@
#define LPC18XX_CREG_CREG6 0x12c
# define LPC18XX_CREG_CREG6_ETHMODE_MASK GENMASK(2, 0)
+static int lpc18xx_set_phy_intf_sel(void *bsp_priv, u8 phy_intf_sel)
+{
+ struct regmap *reg = bsp_priv;
+
+ if (phy_intf_sel != PHY_INTF_SEL_GMII_MII &&
+ phy_intf_sel != PHY_INTF_SEL_RMII)
+ return -EINVAL;
+
+ regmap_update_bits(reg, LPC18XX_CREG_CREG6,
+ LPC18XX_CREG_CREG6_ETHMODE_MASK,
+ FIELD_PREP(LPC18XX_CREG_CREG6_ETHMODE_MASK,
+ phy_intf_sel));
+
+ return 0;
+}
+
static int lpc18xx_dwmac_probe(struct platform_device *pdev)
{
struct plat_stmmacenet_data *plat_dat;
struct stmmac_resources stmmac_res;
- struct regmap *reg;
- u8 ethmode;
+ struct regmap *regmap;
int ret;
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
@@ -41,21 +56,14 @@ static int lpc18xx_dwmac_probe(struct platform_device *pdev)
plat_dat->core_type = DWMAC_CORE_GMAC;
- reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
- if (IS_ERR(reg)) {
+ regmap = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
+ if (IS_ERR(regmap)) {
dev_err(&pdev->dev, "syscon lookup failed\n");
- return PTR_ERR(reg);
- }
-
- ethmode = stmmac_get_phy_intf_sel(plat_dat->phy_interface);
- if (ethmode != PHY_INTF_SEL_GMII_MII &&
- ethmode != PHY_INTF_SEL_RMII) {
- dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
- return -EINVAL;
+ return PTR_ERR(regmap);
}
- regmap_update_bits(reg, LPC18XX_CREG_CREG6,
- LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
+ plat_dat->bsp_priv = regmap;
+ plat_dat->set_phy_intf_sel = lpc18xx_set_phy_intf_sel;
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 6/9] net: stmmac: sti: use PHY_INTF_SEL_x to select PHY interface
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
` (4 preceding siblings ...)
2025-11-06 11:23 ` [PATCH net-next 5/9] net: stmmac: lpc18xx: use ->set_phy_intf_sel() Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 7/9] net: stmmac: sti: use PHY_INTF_SEL_x directly Russell King (Oracle)
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Use the common dwmac definitions for the PHY interface selection field,
adding MII_PHY_SEL_VAL() temporarily to avoid line wrapping.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
index 53d5ce1f6dc6..1e8769a81d77 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -77,13 +77,15 @@
* 001-RGMII
* 010-SGMII
* 100-RMII
+ * These are the DW MAC phy_intf_sel values
*/
#define MII_PHY_SEL_MASK GENMASK(4, 2)
-#define ETH_PHY_SEL_RMII BIT(4)
-#define ETH_PHY_SEL_SGMII BIT(3)
-#define ETH_PHY_SEL_RGMII BIT(2)
-#define ETH_PHY_SEL_GMII 0x0
-#define ETH_PHY_SEL_MII 0x0
+#define MII_PHY_SEL_VAL(val) FIELD_PREP_CONST(MII_PHY_SEL_MASK, val)
+#define ETH_PHY_SEL_RMII MII_PHY_SEL_VAL(PHY_INTF_SEL_RMII)
+#define ETH_PHY_SEL_SGMII MII_PHY_SEL_VAL(PHY_INTF_SEL_SGMII)
+#define ETH_PHY_SEL_RGMII MII_PHY_SEL_VAL(PHY_INTF_SEL_RGMII)
+#define ETH_PHY_SEL_GMII MII_PHY_SEL_VAL(PHY_INTF_SEL_GMII_MII)
+#define ETH_PHY_SEL_MII MII_PHY_SEL_VAL(PHY_INTF_SEL_GMII_MII)
struct sti_dwmac {
phy_interface_t interface; /* MII interface */
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 7/9] net: stmmac: sti: use PHY_INTF_SEL_x directly
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
` (5 preceding siblings ...)
2025-11-06 11:23 ` [PATCH net-next 6/9] net: stmmac: sti: use PHY_INTF_SEL_x to select PHY interface Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 8/9] net: stmmac: sti: use stmmac_get_phy_intf_sel() Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 9/9] net: stmmac: sti: use ->set_phy_intf_sel() Russell King (Oracle)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Use the PHY_INTF_SEL_x values directly rather than the driver private
ETH_PHY_SEL_x values. Move the FIELD_PREP() into sti_dwmac_set_mode().
Use dwmac->interface directly.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/dwmac-sti.c | 27 +++++++++----------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
index 1e8769a81d77..c97535824be0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -81,11 +81,6 @@
*/
#define MII_PHY_SEL_MASK GENMASK(4, 2)
#define MII_PHY_SEL_VAL(val) FIELD_PREP_CONST(MII_PHY_SEL_MASK, val)
-#define ETH_PHY_SEL_RMII MII_PHY_SEL_VAL(PHY_INTF_SEL_RMII)
-#define ETH_PHY_SEL_SGMII MII_PHY_SEL_VAL(PHY_INTF_SEL_SGMII)
-#define ETH_PHY_SEL_RGMII MII_PHY_SEL_VAL(PHY_INTF_SEL_RGMII)
-#define ETH_PHY_SEL_GMII MII_PHY_SEL_VAL(PHY_INTF_SEL_GMII_MII)
-#define ETH_PHY_SEL_MII MII_PHY_SEL_VAL(PHY_INTF_SEL_GMII_MII)
struct sti_dwmac {
phy_interface_t interface; /* MII interface */
@@ -104,13 +99,13 @@ struct sti_dwmac_of_data {
void (*fix_retime_src)(void *priv, int speed, unsigned int mode);
};
-static u32 phy_intf_sels[] = {
- [PHY_INTERFACE_MODE_MII] = ETH_PHY_SEL_MII,
- [PHY_INTERFACE_MODE_GMII] = ETH_PHY_SEL_GMII,
- [PHY_INTERFACE_MODE_RGMII] = ETH_PHY_SEL_RGMII,
- [PHY_INTERFACE_MODE_RGMII_ID] = ETH_PHY_SEL_RGMII,
- [PHY_INTERFACE_MODE_SGMII] = ETH_PHY_SEL_SGMII,
- [PHY_INTERFACE_MODE_RMII] = ETH_PHY_SEL_RMII,
+static u8 phy_intf_sels[] = {
+ [PHY_INTERFACE_MODE_MII] = PHY_INTF_SEL_GMII_MII,
+ [PHY_INTERFACE_MODE_GMII] = PHY_INTF_SEL_GMII_MII,
+ [PHY_INTERFACE_MODE_RGMII] = PHY_INTF_SEL_RGMII,
+ [PHY_INTERFACE_MODE_RGMII_ID] = PHY_INTF_SEL_RGMII,
+ [PHY_INTERFACE_MODE_SGMII] = PHY_INTF_SEL_SGMII,
+ [PHY_INTERFACE_MODE_RMII] = PHY_INTF_SEL_RMII,
};
enum {
@@ -164,16 +159,18 @@ static void stih4xx_fix_retime_src(void *priv, int spd, unsigned int mode)
static int sti_dwmac_set_mode(struct sti_dwmac *dwmac)
{
struct regmap *regmap = dwmac->regmap;
- int iface = dwmac->interface;
u32 reg = dwmac->ctrl_reg;
+ u8 phy_intf_sel;
u32 val;
if (dwmac->gmac_en)
regmap_update_bits(regmap, reg, EN_MASK, EN);
- regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK, phy_intf_sels[iface]);
+ phy_intf_sel = phy_intf_sels[dwmac->interface];
+ regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK,
+ FIELD_PREP(MII_PHY_SEL_MASK, phy_intf_sel));
- val = (iface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
+ val = (dwmac->interface == PHY_INTERFACE_MODE_REVMII) ? 0 : ENMII;
regmap_update_bits(regmap, reg, ENMII_MASK, val);
dwmac->fix_retime_src(dwmac, dwmac->speed, 0);
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 8/9] net: stmmac: sti: use stmmac_get_phy_intf_sel()
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
` (6 preceding siblings ...)
2025-11-06 11:23 ` [PATCH net-next 7/9] net: stmmac: sti: use PHY_INTF_SEL_x directly Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
2025-11-06 11:23 ` [PATCH net-next 9/9] net: stmmac: sti: use ->set_phy_intf_sel() Russell King (Oracle)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Use stmmac_get_phy_intf_sel() to decode the PHY interface mode to the
phy_intf_sel value, validate the result and use that to set the
control register to select the operating mode for the DWMAC core.
Note that when an unsupported interface mode is used, the array would
decode this to PHY_INTF_SEL_GMII_MII, so preserve this behaviour.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/dwmac-sti.c | 22 ++++++++-----------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
index c97535824be0..593e154b5957 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -77,10 +77,9 @@
* 001-RGMII
* 010-SGMII
* 100-RMII
- * These are the DW MAC phy_intf_sel values
+ * These are the DW MAC phy_intf_sel values.
*/
#define MII_PHY_SEL_MASK GENMASK(4, 2)
-#define MII_PHY_SEL_VAL(val) FIELD_PREP_CONST(MII_PHY_SEL_MASK, val)
struct sti_dwmac {
phy_interface_t interface; /* MII interface */
@@ -99,15 +98,6 @@ struct sti_dwmac_of_data {
void (*fix_retime_src)(void *priv, int speed, unsigned int mode);
};
-static u8 phy_intf_sels[] = {
- [PHY_INTERFACE_MODE_MII] = PHY_INTF_SEL_GMII_MII,
- [PHY_INTERFACE_MODE_GMII] = PHY_INTF_SEL_GMII_MII,
- [PHY_INTERFACE_MODE_RGMII] = PHY_INTF_SEL_RGMII,
- [PHY_INTERFACE_MODE_RGMII_ID] = PHY_INTF_SEL_RGMII,
- [PHY_INTERFACE_MODE_SGMII] = PHY_INTF_SEL_SGMII,
- [PHY_INTERFACE_MODE_RMII] = PHY_INTF_SEL_RMII,
-};
-
enum {
TX_RETIME_SRC_NA = 0,
TX_RETIME_SRC_TXCLK = 1,
@@ -160,13 +150,19 @@ static int sti_dwmac_set_mode(struct sti_dwmac *dwmac)
{
struct regmap *regmap = dwmac->regmap;
u32 reg = dwmac->ctrl_reg;
- u8 phy_intf_sel;
+ int phy_intf_sel;
u32 val;
if (dwmac->gmac_en)
regmap_update_bits(regmap, reg, EN_MASK, EN);
- phy_intf_sel = phy_intf_sels[dwmac->interface];
+ phy_intf_sel = stmmac_get_phy_intf_sel(dwmac->interface);
+ if (phy_intf_sel != PHY_INTF_SEL_GMII_MII &&
+ phy_intf_sel != PHY_INTF_SEL_RGMII &&
+ phy_intf_sel != PHY_INTF_SEL_SGMII &&
+ phy_intf_sel != PHY_INTF_SEL_RMII)
+ phy_intf_sel = PHY_INTF_SEL_GMII_MII;
+
regmap_update_bits(regmap, reg, MII_PHY_SEL_MASK,
FIELD_PREP(MII_PHY_SEL_MASK, phy_intf_sel));
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next 9/9] net: stmmac: sti: use ->set_phy_intf_sel()
2025-11-06 11:21 [PATCH net-next 0/9] net: stmmac: lpc18xx and sti: convert to set_phy_intf_sel() Russell King (Oracle)
` (7 preceding siblings ...)
2025-11-06 11:23 ` [PATCH net-next 8/9] net: stmmac: sti: use stmmac_get_phy_intf_sel() Russell King (Oracle)
@ 2025-11-06 11:23 ` Russell King (Oracle)
8 siblings, 0 replies; 10+ messages in thread
From: Russell King (Oracle) @ 2025-11-06 11:23 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: Alexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, linux-arm-kernel, linux-stm32, Maxime Coquelin,
netdev, Paolo Abeni, Vladimir Zapolskiy
Rather than placing the phy_intf_sel() setup in the ->init() method,
move it to the new ->set_phy_intf_sel() method.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
.../net/ethernet/stmicro/stmmac/dwmac-sti.c | 25 +++++++------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
index 593e154b5957..b0509ab6b31c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -146,17 +146,18 @@ static void stih4xx_fix_retime_src(void *priv, int spd, unsigned int mode)
stih4xx_tx_retime_val[src]);
}
-static int sti_dwmac_set_mode(struct sti_dwmac *dwmac)
+static int sti_set_phy_intf_sel(void *bsp_priv, u8 phy_intf_sel)
{
- struct regmap *regmap = dwmac->regmap;
- u32 reg = dwmac->ctrl_reg;
- int phy_intf_sel;
- u32 val;
+ struct sti_dwmac *dwmac = bsp_priv;
+ struct regmap *regmap;
+ u32 reg, val;
+
+ regmap = dwmac->regmap;
+ reg = dwmac->ctrl_reg;
if (dwmac->gmac_en)
regmap_update_bits(regmap, reg, EN_MASK, EN);
- phy_intf_sel = stmmac_get_phy_intf_sel(dwmac->interface);
if (phy_intf_sel != PHY_INTF_SEL_GMII_MII &&
phy_intf_sel != PHY_INTF_SEL_RGMII &&
phy_intf_sel != PHY_INTF_SEL_SGMII &&
@@ -231,17 +232,8 @@ static int sti_dwmac_parse_data(struct sti_dwmac *dwmac,
static int sti_dwmac_init(struct platform_device *pdev, void *bsp_priv)
{
struct sti_dwmac *dwmac = bsp_priv;
- int ret;
-
- ret = clk_prepare_enable(dwmac->clk);
- if (ret)
- return ret;
-
- ret = sti_dwmac_set_mode(dwmac);
- if (ret)
- clk_disable_unprepare(dwmac->clk);
- return ret;
+ return clk_prepare_enable(dwmac->clk);
}
static void sti_dwmac_exit(struct platform_device *pdev, void *bsp_priv)
@@ -286,6 +278,7 @@ static int sti_dwmac_probe(struct platform_device *pdev)
dwmac->fix_retime_src = data->fix_retime_src;
plat_dat->bsp_priv = dwmac;
+ plat_dat->set_phy_intf_sel = sti_set_phy_intf_sel;
plat_dat->fix_mac_speed = data->fix_retime_src;
plat_dat->init = sti_dwmac_init;
plat_dat->exit = sti_dwmac_exit;
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread