mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net: phy: scan PHYs referenced by phandle
@ 2017-12-14 15:14 Lucas Stach
  2017-12-15  7:42 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Lucas Stach @ 2017-12-14 15:14 UTC (permalink / raw)
  To: barebox

If we point to a PHY node by phandle, that PHY might well be on a MDIO
bus that hasn't been scanned when we look for the PHY. Fortunately we
know exactly where to look for the PHY, so make sure to scan the bus
at the right address.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/net/phy/phy.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 35a9ce7ea823..9993fe5c30fd 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -319,6 +319,8 @@ static struct phy_device *of_mdio_find_phy(struct eth_device *edev)
 {
 	struct device_d *dev;
 	struct device_node *phy_node;
+	struct mii_bus *bus;
+	int addr = -1;
 
 	if (!IS_ENABLED(CONFIG_OFDEVICE))
 		return NULL;
@@ -340,6 +342,18 @@ static struct phy_device *of_mdio_find_phy(struct eth_device *edev)
 	if (!phy_node)
 		return NULL;
 
+	of_property_read_u32(phy_node, "reg", &addr);
+	for_each_mii_bus(bus) {
+		if (addr < 0)
+			break;
+
+		if (bus->parent->device_node == phy_node->parent) {
+			struct phy_device *phy = mdiobus_scan(bus, addr);
+			if (!IS_ERR(phy))
+				return phy;
+		}
+	}
+
 	bus_for_each_device(&mdio_bus_type, dev) {
 		if (dev->device_node == phy_node)
 			return container_of(dev, struct phy_device, dev);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: phy: scan PHYs referenced by phandle
  2017-12-14 15:14 [PATCH] net: phy: scan PHYs referenced by phandle Lucas Stach
@ 2017-12-15  7:42 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-12-15  7:42 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

On Thu, Dec 14, 2017 at 04:14:22PM +0100, Lucas Stach wrote:
> If we point to a PHY node by phandle, that PHY might well be on a MDIO
> bus that hasn't been scanned when we look for the PHY. Fortunately we
> know exactly where to look for the PHY, so make sure to scan the bus
> at the right address.
> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  drivers/net/phy/phy.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 35a9ce7ea823..9993fe5c30fd 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -319,6 +319,8 @@ static struct phy_device *of_mdio_find_phy(struct eth_device *edev)
>  {
>  	struct device_d *dev;
>  	struct device_node *phy_node;
> +	struct mii_bus *bus;
> +	int addr = -1;
>  
>  	if (!IS_ENABLED(CONFIG_OFDEVICE))
>  		return NULL;
> @@ -340,6 +342,18 @@ static struct phy_device *of_mdio_find_phy(struct eth_device *edev)
>  	if (!phy_node)
>  		return NULL;
>  
> +	of_property_read_u32(phy_node, "reg", &addr);
> +	for_each_mii_bus(bus) {
> +		if (addr < 0)
> +			break;

I think it would be better readable if you just do not enter the loop
when of_property_read_u32() fails.

Otherwise looks good.

Sascha

> +
> +		if (bus->parent->device_node == phy_node->parent) {
> +			struct phy_device *phy = mdiobus_scan(bus, addr);
> +			if (!IS_ERR(phy))
> +				return phy;
> +		}
> +	}
> +
>  	bus_for_each_device(&mdio_bus_type, dev) {
>  		if (dev->device_node == phy_node)
>  			return container_of(dev, struct phy_device, dev);
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-15  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14 15:14 [PATCH] net: phy: scan PHYs referenced by phandle Lucas Stach
2017-12-15  7:42 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox