[PATCH 1/3] net: phy: Make eth_phy_get_addr() generic

Move eth_phy_get_addr() from drivers/net/eth-phy-uclass.c to drivers/net/phy/phy.c . The eth_phy_get_addr() code is generic and does not depend on DM_ETH_PHY , make it always available.
The dm/device_compat.h is pulled in to make dev_dbg() available.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Joe Hershberger joe.hershberger@ni.com Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com --- drivers/net/eth-phy-uclass.c | 16 ---------------- drivers/net/phy/phy.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c index 9d1e8d38ffa..237c3b7de15 100644 --- a/drivers/net/eth-phy-uclass.c +++ b/drivers/net/eth-phy-uclass.c @@ -109,22 +109,6 @@ struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev) return NULL; }
-int eth_phy_get_addr(struct udevice *dev) -{ - struct ofnode_phandle_args phandle_args; - int reg; - - if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, - &phandle_args)) { - dev_dbg(dev, "Failed to find phy-handle"); - return -ENODEV; - } - - reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); - - return reg; -} - /* parsing generic properties of devicetree/bindings/net/ethernet-phy.yaml */ static int eth_phy_of_to_plat(struct udevice *dev) { diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 63b3e46f101..0d1a98bbbca 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -18,6 +18,7 @@ #include <phy.h> #include <errno.h> #include <asm/global_data.h> +#include <dm/device_compat.h> #include <dm/of_extra.h> #include <linux/bitops.h> #include <linux/delay.h> @@ -28,6 +29,30 @@ DECLARE_GLOBAL_DATA_PTR;
/* Generic PHY support and helper functions */
+/** + * eth_phy_get_addr - get PHY MDIO address from DT + * @dev: the udevice struct of the MAC + * + * Return PHY MDIO address read out of a PHY DT node "reg" property. + * The PHY DT node is located by resolving MAC "phy-handle" property. + * Returns PHY MDIO address on success, negative on failure. + */ +int eth_phy_get_addr(struct udevice *dev) +{ + struct ofnode_phandle_args phandle_args; + int reg; + + if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, + &phandle_args)) { + dev_dbg(dev, "Failed to find phy-handle"); + return -ENODEV; + } + + reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); + + return reg; +} + /** * genphy_config_advert - sanitize and advertise auto-negotiation parameters * @phydev: target phy_device struct

In case the PHY is fully described in DT, use PHY MDIO address from DT directly instead of always using auto-detection. This also fixes the behavior of 'mdio list' in such DT setup, which now prints the PHY connected to the MAC correctly.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Joe Hershberger joe.hershberger@ni.com Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com --- drivers/net/ravb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 0bcd6cfd3f3..e1f61f514c8 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -12,6 +12,7 @@ #include <clk.h> #include <cpu_func.h> #include <dm.h> +#include <eth_phy.h> #include <errno.h> #include <log.h> #include <miiphy.h> @@ -309,9 +310,14 @@ static int ravb_phy_config(struct udevice *dev) struct ravb_priv *eth = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); struct phy_device *phydev; + int phy_addr; int reg;
- phydev = phy_connect(eth->bus, -1, dev, pdata->phy_interface); + phy_addr = eth_phy_get_addr(dev); + if (phy_addr < 0) + phy_addr = -1; + + phydev = phy_connect(eth->bus, phy_addr, dev, pdata->phy_interface); if (!phydev) return -ENODEV;

In case the PHY is fully described in DT, use PHY MDIO address from DT directly instead of always using auto-detection. This also fixes the behavior of 'mdio list' in such DT setup, which now prints the PHY connected to the MAC correctly.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Joe Hershberger joe.hershberger@ni.com Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com --- drivers/net/sh_eth.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 7b1f59dc498..5e2e3054ecf 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -12,6 +12,7 @@ #include <common.h> #include <cpu_func.h> #include <env.h> +#include <eth_phy.h> #include <log.h> #include <malloc.h> #include <net.h> @@ -597,11 +598,16 @@ static int sh_eth_phy_config(struct udevice *dev) struct sh_ether_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); struct sh_eth_dev *eth = &priv->shdev; - int ret = 0; struct sh_eth_info *port_info = ð->port_info[eth->port]; struct phy_device *phydev; + int phy_addr; + int ret = 0; + + phy_addr = eth_phy_get_addr(dev); + if (phy_addr < 0) + phy_addr = -1;
- phydev = phy_connect(priv->bus, -1, dev, pdata->phy_interface); + phydev = phy_connect(priv->bus, phy_addr, dev, pdata->phy_interface); if (!phydev) return -ENODEV;

On 21/01/2024 17:29, Marek Vasut wrote:
In case the PHY is fully described in DT, use PHY MDIO address from DT directly instead of always using auto-detection. This also fixes the behavior of 'mdio list' in such DT setup, which now prints the PHY connected to the MAC correctly.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Joe Hershberger joe.hershberger@ni.com Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com
drivers/net/sh_eth.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
I think the commit summaries are mixed up here - this patch says 'ravb' but changes 'sh_eth.c' and vice-versa with the other patch.
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 7b1f59dc498..5e2e3054ecf 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -12,6 +12,7 @@ #include <common.h> #include <cpu_func.h> #include <env.h> +#include <eth_phy.h> #include <log.h> #include <malloc.h> #include <net.h> @@ -597,11 +598,16 @@ static int sh_eth_phy_config(struct udevice *dev) struct sh_ether_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); struct sh_eth_dev *eth = &priv->shdev;
- int ret = 0; struct sh_eth_info *port_info = ð->port_info[eth->port]; struct phy_device *phydev;
- int phy_addr;
- int ret = 0;
- phy_addr = eth_phy_get_addr(dev);
- if (phy_addr < 0)
phy_addr = -1;
- phydev = phy_connect(priv->bus, -1, dev, pdata->phy_interface);
- phydev = phy_connect(priv->bus, phy_addr, dev, pdata->phy_interface); if (!phydev) return -ENODEV;
I have a local patch to handle (phy_addr < 0) in phy_connect_phy_id() and lookup the address there. I think that's the better place to handle this as it's a universal fix for all users of CONFIG_PHY_ETHERNET_ID. Unfortunately I've been distracted by some higher priority work but I'm hoping to get back to this soon.
I can do some quick testing with that patch and send it this week if that's helpful.
Thanks, Paul

On 1/21/24 22:37, Paul Barker wrote:
On 21/01/2024 17:29, Marek Vasut wrote:
In case the PHY is fully described in DT, use PHY MDIO address from DT directly instead of always using auto-detection. This also fixes the behavior of 'mdio list' in such DT setup, which now prints the PHY connected to the MAC correctly.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Cc: Joe Hershberger joe.hershberger@ni.com Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com
drivers/net/sh_eth.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
I think the commit summaries are mixed up here - this patch says 'ravb' but changes 'sh_eth.c' and vice-versa with the other patch.
Sigh ... too much git commit --fixup/rebase --autosquash .
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 7b1f59dc498..5e2e3054ecf 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -12,6 +12,7 @@ #include <common.h> #include <cpu_func.h> #include <env.h> +#include <eth_phy.h> #include <log.h> #include <malloc.h> #include <net.h> @@ -597,11 +598,16 @@ static int sh_eth_phy_config(struct udevice *dev) struct sh_ether_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); struct sh_eth_dev *eth = &priv->shdev;
- int ret = 0; struct sh_eth_info *port_info = ð->port_info[eth->port]; struct phy_device *phydev;
- int phy_addr;
- int ret = 0;
- phy_addr = eth_phy_get_addr(dev);
- if (phy_addr < 0)
phy_addr = -1;
- phydev = phy_connect(priv->bus, -1, dev, pdata->phy_interface);
- phydev = phy_connect(priv->bus, phy_addr, dev, pdata->phy_interface); if (!phydev) return -ENODEV;
I have a local patch to handle (phy_addr < 0) in phy_connect_phy_id() and lookup the address there. I think that's the better place to handle this as it's a universal fix for all users of CONFIG_PHY_ETHERNET_ID. Unfortunately I've been distracted by some higher priority work but I'm hoping to get back to this soon.
I can do some quick testing with that patch and send it this week if that's helpful.
Please do send it, yes.
participants (3)
-
Marek Vasut
-
Marek Vasut
-
Paul Barker