Skip to content

Commit 0060c87

Browse files
commododavem330
authored andcommitted
net: stmmac: implement support for passive mode converters via dt
In-between the MAC & PHY there can be a mode converter, which converts one mode to another (e.g. GMII-to-RGMII). The converter, can be passive (i.e. no driver or OS/SW information required), so the MAC & PHY need to be configured differently. For the `stmmac` driver, this is implemented via a `mac-mode` property in the device-tree, which configures the MAC into a certain mode, and for the PHY a `phy_interface` field will hold the mode of the PHY. The mode of the PHY will be passed to the PHY and from there-on it work in a different mode. If unspecified, the default `phy-mode` will be used for both. Signed-off-by: Alexandru Ardelean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c160994 commit 0060c87

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static int stmmac_init_phy(struct net_device *dev)
10361036
static int stmmac_phy_setup(struct stmmac_priv *priv)
10371037
{
10381038
struct fwnode_handle *fwnode = of_fwnode_handle(priv->plat->phylink_node);
1039-
int mode = priv->plat->interface;
1039+
int mode = priv->plat->phy_interface;
10401040
struct phylink *phylink;
10411041

10421042
priv->phylink_config.dev = &priv->dev->dev;

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,32 @@ static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
358358
return 0;
359359
}
360360

361+
/**
362+
* stmmac_of_get_mac_mode - retrieves the interface of the MAC
363+
* @np - device-tree node
364+
* Description:
365+
* Similar to `of_get_phy_mode()`, this function will retrieve (from
366+
* the device-tree) the interface mode on the MAC side. This assumes
367+
* that there is mode converter in-between the MAC & PHY
368+
* (e.g. GMII-to-RGMII).
369+
*/
370+
static int stmmac_of_get_mac_mode(struct device_node *np)
371+
{
372+
const char *pm;
373+
int err, i;
374+
375+
err = of_property_read_string(np, "mac-mode", &pm);
376+
if (err < 0)
377+
return err;
378+
379+
for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) {
380+
if (!strcasecmp(pm, phy_modes(i)))
381+
return i;
382+
}
383+
384+
return -ENODEV;
385+
}
386+
361387
/**
362388
* stmmac_probe_config_dt - parse device-tree driver parameters
363389
* @pdev: platform_device structure
@@ -386,7 +412,13 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
386412
*mac = NULL;
387413
}
388414

389-
plat->interface = of_get_phy_mode(np);
415+
plat->phy_interface = of_get_phy_mode(np);
416+
if (plat->phy_interface < 0)
417+
return ERR_PTR(plat->phy_interface);
418+
419+
plat->interface = stmmac_of_get_mac_mode(np);
420+
if (plat->interface < 0)
421+
plat->interface = plat->phy_interface;
390422

391423
/* Some wrapper drivers still rely on phy_node. Let's save it while
392424
* they are not converted to phylink. */

include/linux/stmmac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct plat_stmmacenet_data {
131131
int bus_id;
132132
int phy_addr;
133133
int interface;
134+
int phy_interface;
134135
struct stmmac_mdio_bus_data *mdio_bus_data;
135136
struct device_node *phy_node;
136137
struct device_node *phylink_node;

0 commit comments

Comments
 (0)