All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <zonque@gmail.com>
To: f.fainelli@gmail.com
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	grant.likely@linaro.org, robh+dt@kernel.org,
	Daniel Mack <zonque@gmail.com>
Subject: [PATCH] net: mdio: of_mdio: check for already registered phy before creating new instances
Date: Tue,  6 May 2014 17:21:51 +0200	[thread overview]
Message-ID: <1399389711-32716-1-git-send-email-zonque@gmail.com> (raw)

In of_mdiobus_register_phy(), check if the phy with the given address is
already registered within the mii bus before calling phy_device_create()
or get_phy_device().

This allows us to augment auto-probed phy devices with extra information
via DT. Without this patch, a second instance of the phydev is created
unnecessarily.

Signed-off-by: Daniel Mack <zonque@gmail.com>
---
 drivers/of/of_mdio.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 9a95831..264ea3f 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -72,10 +72,15 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
 	is_c45 = of_device_is_compatible(child,
 					 "ethernet-phy-ieee802.3-c45");
 
-	if (!is_c45 && !of_get_phy_id(child, &phy_id))
-		phy = phy_device_create(mdio, addr, phy_id, 0, NULL);
-	else
-		phy = get_phy_device(mdio, addr, is_c45);
+	/* Check if the phy we're looking for is already registered */
+	phy = mdio->phy_map[addr];
+	if (!phy) {
+		if (!is_c45 && !of_get_phy_id(child, &phy_id))
+			phy = phy_device_create(mdio, addr, phy_id, 0, NULL);
+		else
+			phy = get_phy_device(mdio, addr, is_c45);
+	}
+
 	if (!phy || IS_ERR(phy))
 		return 1;
 
-- 
1.9.0

             reply	other threads:[~2014-05-06 15:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-06 15:21 Daniel Mack [this message]
2014-05-07  0:55 ` [PATCH] net: mdio: of_mdio: check for already registered phy before creating new instances Florian Fainelli
2014-05-07 16:01   ` Daniel Mack
2014-05-07 17:26     ` Florian Fainelli
2014-05-08  7:40       ` Daniel Mack

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=1399389711-32716-1-git-send-email-zonque@gmail.com \
    --to=zonque@gmail.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.