All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: netdev@vger.kernel.org
Cc: David Miller <davem@davemloft.net>,
	devicetree@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Miroslav Lichvar <mlichvar@redhat.com>,
	Murali Karicheri <m-karicheri2@ti.com>,
	Rob Herring <robh+dt@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Wingman Kwok <w-kwok2@ti.com>, Rob Herring <robh@kernel.org>
Subject: [PATCH V7 net-next 09/11] net: mdio: of: Register discovered MII time stampers.
Date: Fri, 20 Dec 2019 10:15:18 -0800	[thread overview]
Message-ID: <9af33891bfa5f3d4c42654228eabab2e3d39c259.1576865315.git.richardcochran@gmail.com> (raw)
In-Reply-To: <cover.1576865315.git.richardcochran@gmail.com>

When parsing a PHY node, register its time stamper, if any, and attach
the instance to the PHY device.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 drivers/net/phy/phy_device.c |  3 +++
 drivers/of/of_mdio.c         | 30 +++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index ee45838f90c9..debbda61e12b 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -881,6 +881,9 @@ EXPORT_SYMBOL(phy_device_register);
  */
 void phy_device_remove(struct phy_device *phydev)
 {
+	if (phydev->mii_ts)
+		unregister_mii_timestamper(phydev->mii_ts);
+
 	device_del(&phydev->mdio.dev);
 
 	/* Assert the reset signal */
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index c6b87ce2b0cc..0b7aee235813 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -42,14 +42,37 @@ static int of_get_phy_id(struct device_node *device, u32 *phy_id)
 	return -EINVAL;
 }
 
+static struct mii_timestamper *of_find_mii_timestamper(struct device_node *node)
+{
+	struct of_phandle_args arg;
+	int err;
+
+	err = of_parse_phandle_with_fixed_args(node, "timestamper", 1, 0, &arg);
+
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (arg.args_count != 1)
+		return ERR_PTR(-EINVAL);
+
+	return register_mii_timestamper(arg.np, arg.args[0]);
+}
+
 static int of_mdiobus_register_phy(struct mii_bus *mdio,
 				    struct device_node *child, u32 addr)
 {
+	struct mii_timestamper *mii_ts;
 	struct phy_device *phy;
 	bool is_c45;
 	int rc;
 	u32 phy_id;
 
+	mii_ts = of_find_mii_timestamper(child);
+	if (IS_ERR(mii_ts))
+		return PTR_ERR(mii_ts);
+
 	is_c45 = of_device_is_compatible(child,
 					 "ethernet-phy-ieee802.3-c45");
 
@@ -57,11 +80,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
 		phy = phy_device_create(mdio, addr, phy_id, 0, NULL);
 	else
 		phy = get_phy_device(mdio, addr, is_c45);
-	if (IS_ERR(phy))
+	if (IS_ERR(phy)) {
+		unregister_mii_timestamper(mii_ts);
 		return PTR_ERR(phy);
+	}
 
 	rc = of_irq_get(child, 0);
 	if (rc == -EPROBE_DEFER) {
+		unregister_mii_timestamper(mii_ts);
 		phy_device_free(phy);
 		return rc;
 	}
@@ -90,10 +116,12 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
 	 * register it */
 	rc = phy_device_register(phy);
 	if (rc) {
+		unregister_mii_timestamper(mii_ts);
 		phy_device_free(phy);
 		of_node_put(child);
 		return rc;
 	}
+	phy->mii_ts = mii_ts;
 
 	dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n",
 		child, addr);
-- 
2.20.1


  parent reply	other threads:[~2019-12-20 18:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20 18:15 [PATCH V7 net-next 00/11] Peer to Peer One-Step time stamping Richard Cochran
2019-12-20 18:15 ` [PATCH V7 net-next 01/11] net: phy: Introduce helper functions for time stamping support Richard Cochran
2019-12-20 22:24   ` Florian Fainelli
2019-12-20 18:15 ` [PATCH V7 net-next 02/11] net: macvlan: Use the PHY time stamping interface Richard Cochran
2019-12-20 22:26   ` Florian Fainelli
2019-12-20 18:15 ` [PATCH V7 net-next 03/11] net: vlan: " Richard Cochran
2019-12-20 22:26   ` Florian Fainelli
2019-12-20 18:15 ` [PATCH V7 net-next 04/11] net: ethtool: " Richard Cochran
2019-12-20 22:26   ` Florian Fainelli
2019-12-20 18:15 ` [PATCH V7 net-next 05/11] net: netcp_ethss: " Richard Cochran
2019-12-20 22:38   ` Florian Fainelli
2019-12-20 18:15 ` [PATCH V7 net-next 06/11] net: Introduce a new MII " Richard Cochran
2019-12-20 18:15 ` [PATCH V7 net-next 07/11] net: Add a layer for non-PHY MII time stamping drivers Richard Cochran
2019-12-21 10:32   ` Andrew Lunn
2019-12-20 18:15 ` [PATCH V7 net-next 08/11] dt-bindings: ptp: Introduce MII time stamping devices Richard Cochran
2019-12-20 18:15 ` Richard Cochran [this message]
2019-12-20 22:41   ` [PATCH V7 net-next 09/11] net: mdio: of: Register discovered MII time stampers Florian Fainelli
2019-12-20 18:15 ` [PATCH V7 net-next 10/11] net: Introduce peer to peer one step PTP time stamping Richard Cochran
2019-12-20 18:15 ` [PATCH V7 net-next 11/11] ptp: Add a driver for InES time stamping IP core Richard Cochran
2019-12-21 10:56   ` Andrew Lunn

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=9af33891bfa5f3d4c42654228eabab2e3d39c259.1576865315.git.richardcochran@gmail.com \
    --to=richardcochran@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=jacob.e.keller@intel.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=m-karicheri2@ti.com \
    --cc=mark.rutland@arm.com \
    --cc=mlichvar@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=w-kwok2@ti.com \
    --cc=willemb@google.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 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.