netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robherring2@gmail.com>
To: Florian Fainelli <florian@openwrt.org>, netdev@vger.kernel.org
Cc: davem@davemloft.net, grant.likely@linaro.org,
	devicetree@vger.kernel.org, abrodkin@synopsys.com,
	rob.herring@calxeda.com, mark.rutland@arm.com,
	sebastian.hesselbarth@gmail.com,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH 1/7] net: of_mdio: factor PHY registration from of_mdiobus_register
Date: Sun, 08 Dec 2013 10:00:16 -0600	[thread overview]
Message-ID: <52A49790.5080901@gmail.com> (raw)
In-Reply-To: <1386283936-26104-2-git-send-email-florian@openwrt.org>

On 12/05/2013 04:52 PM, Florian Fainelli wrote:
> From: Florian Fainelli <f.fainelli@gmail.com>
> 
> Since commit 779d835e ("net: of_mdio: scan mdiobus for PHYs without reg
> property") we have two foreach loops which do pretty much the same
> thing. Factor the PHY device registration in a function helper:
> of_mdiobus_register_phy() which takes care of the details and allows for
> future PHY specific extensions.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

A couple of formatting nits, but otherwise:

Acked-by: Rob Herring <rob.herring@calxeda.com>

BTW, unless David has objections, I'd like to see this file moved to
drivers/net. He tends to merge the of_mdio.c changes anyway. We've moved
most other subsystem parsing code out of drivers/of.

> ---
>  drivers/of/of_mdio.c | 109 ++++++++++++++++++++++-----------------------------
>  1 file changed, 46 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index d5a57a9..82485d2 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -22,6 +22,47 @@
>  MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
>  MODULE_LICENSE("GPL");
>  
> +static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child,
> +				   u32 addr)
> +{
> +	struct phy_device *phy;
> +	bool is_c45;
> +	int rc;
> +
> +	is_c45 = of_device_is_compatible(child,
> +					 "ethernet-phy-ieee802.3-c45");

This looks like it can be 1 line.

> +
> +	phy = get_phy_device(mdio, addr, is_c45);
> +	if (!phy || IS_ERR(phy))
> +		return 1;
> +
> +	if (mdio->irq) {
> +		mdio->irq[addr] =
> +			irq_of_parse_and_map(child, 0);

ditto

> +		if (!mdio->irq[addr])
> +			mdio->irq[addr] = PHY_POLL;
> +	}
> +
> +	/* Associate the OF node with the device structure so it
> +	 * can be looked up later */
> +	of_node_get(child);
> +	phy->dev.of_node = child;
> +
> +	/* All data is now stored in the phy struct;
> +	 * register it */
> +	rc = phy_device_register(phy);
> +	if (rc) {
> +		phy_device_free(phy);
> +		of_node_put(child);
> +		return 1;
> +	}
> +
> +	dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
> +		 child->name, addr);
> +
> +	return 0;
> +}
> +
>  /**
>   * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
>   * @mdio: pointer to mii_bus structure
> @@ -32,11 +73,10 @@ MODULE_LICENSE("GPL");
>   */
>  int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  {
> -	struct phy_device *phy;
>  	struct device_node *child;
>  	const __be32 *paddr;
>  	u32 addr;
> -	bool is_c45, scanphys = false;
> +	bool scanphys = false;
>  	int rc, i, len;
>  
>  	/* Mask out all PHYs from auto probing.  Instead the PHYs listed in
> @@ -73,38 +113,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  			continue;
>  		}
>  
> -		if (mdio->irq) {
> -			mdio->irq[addr] = irq_of_parse_and_map(child, 0);
> -			if (!mdio->irq[addr])
> -				mdio->irq[addr] = PHY_POLL;
> -		}
> -
> -		is_c45 = of_device_is_compatible(child,
> -						 "ethernet-phy-ieee802.3-c45");
> -		phy = get_phy_device(mdio, addr, is_c45);
> -
> -		if (!phy || IS_ERR(phy)) {
> -			dev_err(&mdio->dev,
> -				"cannot get PHY at address %i\n",
> -				addr);
> -			continue;
> -		}
> -
> -		/* Associate the OF node with the device structure so it
> -		 * can be looked up later */
> -		of_node_get(child);
> -		phy->dev.of_node = child;
> -
> -		/* All data is now stored in the phy struct; register it */
> -		rc = phy_device_register(phy);
> -		if (rc) {
> -			phy_device_free(phy);
> -			of_node_put(child);
> +		rc = of_mdiobus_register_phy(mdio, child, addr);
> +		if (rc)
>  			continue;
> -		}
> -
> -		dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
> -			child->name, addr);
>  	}
>  
>  	if (!scanphys)
> @@ -117,9 +128,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  		if (paddr)
>  			continue;
>  
> -		is_c45 = of_device_is_compatible(child,
> -						 "ethernet-phy-ieee802.3-c45");
> -
>  		for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
>  			/* skip already registered PHYs */
>  			if (mdio->phy_map[addr])
> @@ -129,34 +137,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  			dev_info(&mdio->dev, "scan phy %s at address %i\n",
>  				 child->name, addr);
>  
> -			phy = get_phy_device(mdio, addr, is_c45);
> -			if (!phy || IS_ERR(phy))
> +			rc = of_mdiobus_register_phy(mdio, child, addr);
> +			if (rc)
>  				continue;
> -
> -			if (mdio->irq) {
> -				mdio->irq[addr] =
> -					irq_of_parse_and_map(child, 0);
> -				if (!mdio->irq[addr])
> -					mdio->irq[addr] = PHY_POLL;
> -			}
> -
> -			/* Associate the OF node with the device structure so it
> -			 * can be looked up later */
> -			of_node_get(child);
> -			phy->dev.of_node = child;
> -
> -			/* All data is now stored in the phy struct;
> -			 * register it */
> -			rc = phy_device_register(phy);
> -			if (rc) {
> -				phy_device_free(phy);
> -				of_node_put(child);
> -				continue;
> -			}
> -
> -			dev_info(&mdio->dev, "registered phy %s at address %i\n",
> -				 child->name, addr);
> -			break;
>  		}
>  	}
>  
> 

  reply	other threads:[~2013-12-08 16:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05 22:52 [PATCH 0/7] net: of_mdio improvements Florian Fainelli
2013-12-05 22:52 ` [PATCH 1/7] net: of_mdio: factor PHY registration from of_mdiobus_register Florian Fainelli
2013-12-08 16:00   ` Rob Herring [this message]
     [not found] ` <1386283936-26104-1-git-send-email-florian-p3rKhJxN3npAfugRpC6u6w@public.gmane.org>
2013-12-05 22:52   ` [PATCH 2/7] net: of_mdio: use PHY_MAX_ADDR constant Florian Fainelli
2013-12-11 13:52     ` Grant Likely
2013-12-05 22:52 ` [PATCH 3/7] net: of_mdio: do not overwrite PHY interrupt configuration Florian Fainelli
2013-12-06  0:45   ` Sergei Shtylyov
2013-12-11 13:57   ` Grant Likely
2013-12-05 22:52 ` [PATCH 4/7] net: phy: breakdown PHY_*_FEATURES defines Florian Fainelli
2013-12-05 22:52 ` [PATCH 5/7] net: of_mdio: parse "max-speed" property to set PHY supported features Florian Fainelli
2013-12-06  0:49   ` Sergei Shtylyov
2013-12-05 23:53     ` Florian Fainelli
2013-12-06  0:03       ` Joe Perches
2013-12-06  0:47       ` David Miller
2013-12-08 15:51   ` Rob Herring
2013-12-11 14:02   ` Grant Likely
2013-12-05 22:52 ` [PATCH 6/7] arc_emac: remove custom "max-speed" parsing code Florian Fainelli
2013-12-05 22:52 ` [PATCH 7/7] Documentation: update Ethernet PHY devices binding with 'max-speed' Florian Fainelli
2013-12-06 19:57 ` [PATCH 0/7] net: of_mdio improvements David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52A49790.5080901@gmail.com \
    --to=robherring2@gmail.com \
    --cc=abrodkin@synopsys.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=florian@openwrt.org \
    --cc=grant.likely@linaro.org \
    --cc=mark.rutland@arm.com \
    --cc=netdev@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=sebastian.hesselbarth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).