mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Calvin Johnson <calvin.johnson@nxp.com>
To: linux.cj@gmail.com, Jon Nettleton <jon@solid-run.com>,
	linux@armlinux.org.uk, Makarand Pawagi <makarand.pawagi@nxp.com>,
	cristian.sovaiala@nxp.com, laurentiu.tudor@nxp.com,
	ioana.ciornei@nxp.com, V.Sethi@nxp.com, pankaj.bansal@nxp.com,
	"Rajesh V . Bikkina" <rajesh.bikkina@nxp.com>
Cc: Calvin Johnson <calvin.johnson@oss.nxp.com>,
	Andrew Lunn <andrew@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH v1 2/7] mdio_bus: modify fwnode phy related functions
Date: Fri, 31 Jan 2020 21:04:35 +0530	[thread overview]
Message-ID: <20200131153440.20870-3-calvin.johnson@nxp.com> (raw)
In-Reply-To: <20200131153440.20870-1-calvin.johnson@nxp.com>

From: Calvin Johnson <calvin.johnson@oss.nxp.com>

-Add fwnode_get_phy_id to extract phy_id from fwnode compatible property.
-Modify fwnode_mdiobus_register_phy and fwnode_mdiobus_child_is_phy to
get the compatible string and process accordingly.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
---

 drivers/net/phy/mdio_bus.c | 58 +++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 16 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index b1830ae2abd9..d806b8294651 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -726,19 +726,43 @@ static int mdio_uevent(struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
+/* Extract the clause 22 phy ID from the compatible string of the form
+ * ethernet-phy-idAAAA.BBBB
+ */
+static int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id)
+{
+	const char *cp;
+	unsigned int upper, lower;
+	int ret;
+
+	ret = fwnode_property_read_string(fwnode, "compatible", &cp);
+	if (!ret) {
+		if (sscanf(cp, "ethernet-phy-id%4x.%4x",
+			   &upper, &lower) == 2) {
+			*phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF);
+			return 0;
+		}
+	}
+	return -EINVAL;
+}
+
 static int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 				       struct fwnode_handle *child, u32 addr)
 {
 	struct phy_device *phy;
 	bool is_c45 = false;
 	int rc;
+	const char *cp;
+	u32 phy_id;
 
-	rc = fwnode_property_match_string(child, "compatible",
-					  "ethernet-phy-ieee802.3-c45");
-	if (!rc)
+	fwnode_property_read_string(child, "compatible", &cp);
+	if (!strcmp(cp, "ethernet-phy-ieee802.3-c45"))
 		is_c45 = true;
 
-	phy = get_phy_device(bus, addr, is_c45);
+	if (!is_c45 && !fwnode_get_phy_id(child, &phy_id))
+		phy = phy_device_create(bus, addr, phy_id, 0, NULL);
+	else
+		phy = get_phy_device(bus, addr, is_c45);
 	if (IS_ERR(phy))
 		return PTR_ERR(phy);
 
@@ -835,21 +859,23 @@ static int fwnode_mdio_parse_addr(struct device *dev,
 static bool fwnode_mdiobus_child_is_phy(struct fwnode_handle *child)
 {
 	int ret;
+	const char *cp;
+	u32 phy_id;
 
-	ret = fwnode_property_match_string(child, "compatible",
-					   "ethernet-phy-ieee802.3-c45");
-	if (!ret)
-		return true;
-
-	ret = fwnode_property_match_string(child, "compatible",
-					   "ethernet-phy-ieee802.3-c22");
-	if (!ret)
-		return true;
-
-	if (!fwnode_property_present(child, "compatible"))
+	if (fwnode_get_phy_id(child, &phy_id) != -EINVAL)
 		return true;
 
-	return false;
+	ret = fwnode_property_read_string(child, "compatible", &cp);
+	if (!ret) {
+		if (!strcmp(cp, "ethernet-phy-ieee802.3-c22"))
+			return true;
+		else if (!strcmp(cp, "ethernet-phy-ieee802.3-c45"))
+			return true;
+		else
+			return false;
+	} else {
+		return false;
+	}
 }
 
 /**
-- 
2.17.1


  parent reply	other threads:[~2020-01-31 15:35 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 15:34 [PATCH v1 0/7] ACPI support for xgmac_mdio and dpaa2-mac drivers Calvin Johnson
2020-01-31 15:34 ` [PATCH v1 1/7] mdio_bus: Introduce fwnode MDIO helpers Calvin Johnson
2020-01-31 16:28   ` Andrew Lunn
2020-02-05  7:11     ` [EXT] " Calvin Johnson (OSS)
2020-02-03  9:49   ` kbuild test robot
2020-02-05 14:17   ` Jeremy Linton
2020-02-07  9:42     ` [EXT] " Calvin Johnson (OSS)
2020-03-17 11:36   ` Calvin Johnson
2020-03-17 14:04     ` Andrew Lunn
2020-03-18  6:03       ` Calvin Johnson
2020-01-31 15:34 ` Calvin Johnson [this message]
2020-01-31 15:34 ` [PATCH v1 3/7] net/fsl: add ACPI support for mdio bus Calvin Johnson
2020-01-31 16:08   ` Andy Shevchenko
2020-02-04  7:18     ` Calvin Johnson (OSS)
2020-02-04 11:17       ` Andy Shevchenko
2020-02-03  3:44   ` Florian Fainelli
2020-02-04 18:46     ` Calvin Johnson
2020-01-31 15:34 ` [PATCH v1 4/7] device property: fwnode_get_phy_mode: Change API to solve int/unit warnings Calvin Johnson
2020-01-31 15:55   ` Andy Shevchenko
2020-02-03  9:13     ` Calvin Johnson (OSS)
2020-02-03  9:22       ` Andy Shevchenko
2020-02-03  2:32   ` kbuild test robot
2020-02-03  8:41   ` kbuild test robot
2020-01-31 15:34 ` [PATCH v1 5/7] device property: Introduce fwnode_phy_is_fixed_link() Calvin Johnson
2020-01-31 15:57   ` Andy Shevchenko
2020-02-03  9:21     ` Calvin Johnson (OSS)
2020-01-31 15:34 ` [PATCH v1 6/7] net: phylink: Introduce phylink_fwnode_phy_connect() Calvin Johnson
2020-02-03 18:21   ` kbuild test robot
2020-02-03 18:41   ` Russell King - ARM Linux admin
2020-02-03 18:43     ` Russell King - ARM Linux admin
2020-02-05 11:33     ` [EXT] " Calvin Johnson (OSS)
2020-01-31 15:34 ` [PATCH v1 7/7] dpaa2-eth: Add ACPI support for DPAA2 MAC driver Calvin Johnson
2020-02-03 18:02 ` [PATCH v1 0/7] ACPI support for xgmac_mdio and dpaa2-mac drivers Florian Fainelli
2020-02-05  8:31   ` [EXT] " Calvin Johnson (OSS)

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=20200131153440.20870-3-calvin.johnson@nxp.com \
    --to=calvin.johnson@nxp.com \
    --cc=V.Sethi@nxp.com \
    --cc=andrew@lunn.ch \
    --cc=calvin.johnson@oss.nxp.com \
    --cc=cristian.sovaiala@nxp.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=ioana.ciornei@nxp.com \
    --cc=jon@solid-run.com \
    --cc=laurentiu.tudor@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux.cj@gmail.com \
    --cc=linux@armlinux.org.uk \
    --cc=makarand.pawagi@nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=pankaj.bansal@nxp.com \
    --cc=rajesh.bikkina@nxp.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

all inboxes | Powered by JetHome®