net: add dm_eth_phy_connect helper to link eth/PHY based on DT
Subsystems (2)
PATCH 1/3 net: add dm_eth_phy_connect helper to link eth/PHY based on DT
The helper is useful for platforms that link ethernet interfaces and PHYs in device tree using current bindings. Drivers could do this directly, but the code is generic enough and helps keep drivers simpler.
--- include/miiphy.h | 12 +++++ net/mdio-uclass.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+)
include/miiphy.h +12 -0
@@ -165,6 +165,18 @@ struct phy_device *dm_mdio_phy_connect(struct udevice *dev, int addr,struct udevice *ethdev, phy_interface_t interface); +/** +* dm_eth_phy_connect - Connect an Eth device to a PHY based on device tree +* +* Picks up the DT phy-handle/mdio-handle and phy-mode from ethernet device node +* and connects the ethernet device to the linked PHY. +* +* @dev: ethernet device +* +* @return pointer to phy_device, or 0 on error +*/ +struct phy_device *dm_eth_phy_connect (struct udevice *dev); +#endif #ifdef CONFIG_DM_MDIO_MUX
net/mdio-uclass.c +118 -0
124 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/3 doc: bindings: add mdio-handle property to ethernet nodes
Adds an optional mdio-handle property which identifies a MDIO bus which can be scanned to find the relevant PHY. The property is ignored if phy-handle is also present.
--- doc/device-tree-bindings/net/ethernet.txt | 2 ++ 1 file changed, 2 insertions(+)
doc/device-tree-bindings/net/ethernet.txt +2 -0
@@ -9,6 +9,8 @@ The following properties are common to the Ethernet controllers: - max-speed: number, specifies maximum speed in Mbit/s supported by the device; - max-frame-size: number, maximum transfer unit (IEEE defined MTU), rather than the maximum frame size (there's contradiction in ePAPR). +- mdio-handle: phandle, specifies a reference to a MDIO bus to be scanned to + find the PHY device. Ignored if phy-handle is also present. - phy-mode: string, operation mode of the PHY interface; supported values are "mii", "gmii", "sgmii", "qsgmii", "tbi", "rev-mii", "rmii", "rgmii", "rgmii-id", "rgmii-rxid", "rgmii-txid", "rtbi", "smii", "xgmii"; this is now a de-facto
Signature · 1 line
2.17.1
PATCH 3/3 drivers: net: fsl_enetc: use dm_eth_phy_connect helper
In reply to Alex MargineanUses the new dm_eth_phy_connect helper to connect to the PHY to simplify the code.
--- drivers/net/fsl_enetc.c | 52 ++++++----------------------------------- drivers/net/fsl_enetc.h | 1 + 2 files changed, 8 insertions(+), 45 deletions(-)
drivers/net/fsl_enetc.c +7 -45
@@ -200,56 +200,17 @@ static void enetc_start_pcs(struct udevice *dev) }/* Configure the actual/external ethernet PHY, if one is found */ -static void enetc_start_phy (struct udevice *dev) +static void enetc_config_phy (struct udevice *dev) {struct enetc_priv *priv =dev_get_priv (dev); -struct udevice *miidev; -struct phy_device *phy; -u32 phandle, phy_id; -ofnode phy_node;int supported; -if (!ofnode_valid (dev->node)) { -enetc_dbg (dev,"no enetc ofnode found, skipping PHY set-up\n" ); -return ; - } - -if (ofnode_read_u32 (dev->node,"phy-handle" , &phandle)) { -enetc_dbg (dev,"phy-handle not found, skipping PHY set-up\n" ); -return ; - } - - phy_node =ofnode_get_by_phandle (phandle); -if (!ofnode_valid (phy_node)) { -enetc_dbg (dev,"invalid phy node, skipping PHY set-up\n" ); -return ; - } -enetc_dbg (dev,"phy node: %s\n" ,ofnode_get_name (phy_node)); - -if (ofnode_read_u32 (phy_node,"reg" , &phy_id)) { -enetc_dbg (dev, -"missing reg in PHY node, skipping PHY set-up\n" ); -return ; - } - -if (uclass_get_device_by_ofnode (UCLASS_MDIO , -ofnode_get_parent (phy_node), - &miidev)) { -enetc_dbg (dev,"can't find MDIO bus for node %s\n" , -ofnode_get_name (ofnode_get_parent (phy_node))); -return ; - } - - phy =dm_mdio_phy_connect (miidev, phy_id, dev, priv->if_type); -if (!phy) { -enetc_dbg (dev,"dm_mdio_phy_connect returned null\n" ); -return ; - } + priv->phy =dm_eth_phy_connect (dev); supported =GENMASK (6 ,0 );/* speeds up to 1G & AN */ - phy->advertising = phy->supported & supported; -phy_config (phy); -phy_startup (phy); + priv->phy->advertising = priv->phy->supported & supported; + +phy_config (priv->phy); }/*
@@ -464,7 +425,8 @@ static int enetc_start(struct udevice *dev)enetc_setup_rx_bdr (dev);enetc_start_pcs (dev); -enetc_start_phy (dev); +enetc_config_phy (dev); +phy_startup (priv->phy);return 0 ; }
drivers/net/fsl_enetc.h +1 -0
@@ -154,6 +154,7 @@ struct enetc_priv {int if_type;struct mii_dev imdio; +struct phy_device *phy; };/* register accessors */
Signature · 1 line
2.17.1
PATCH 1/3 net: add dm_eth_phy_connect helper to link eth/PHY based on DT
In reply to Alex MargineanQuoted 10 lines · Alex Marginean
The helper is useful for platforms that link ethernet interfaces and PHYs in device tree using current bindings. Drivers could do this directly, but the code is generic enough and helps keep drivers simpler.
Signed-off-by Alex Marginean <[email protected]>--- include/miiphy.h | 12 +++++ net/mdio-uclass.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+)
superseded by
https://patchwork.ozlabs.org/project/uboot/list/?series=124537
Thanks!
Alex