From: Vikas Singh <vikas.singh@puresoftware.com>
To: andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, netdev@vger.kernel.org
Cc: calvin.johnson@oss.nxp.com, kuldip.dwivedi@puresoftware.com,
madalin.bucur@oss.nxp.com, vikas.singh@nxp.com,
Vikas Singh <vikas.singh@puresoftware.com>
Subject: [PATCH 1/2] net: phy: Add fwnode helper functions
Date: Tue, 28 Jul 2020 17:43:19 +0530 [thread overview]
Message-ID: <1595938400-13279-2-git-send-email-vikas.singh@puresoftware.com> (raw)
In-Reply-To: <1595938400-13279-1-git-send-email-vikas.singh@puresoftware.com>
Add support of fwnode helper functions to MDIO bus driver.
1. fwnode_phy_find_device() to find phy_device associated to a fwnod
2. fwnode_phy_connect() to attach the mac to the phy
Signed-off-by: Vikas Singh <vikas.singh@puresoftware.com>
---
drivers/net/phy/mdio_bus.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
include/linux/mdio.h | 4 +++
2 files changed, 70 insertions(+)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 46b3370..ab8fcea 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -40,6 +40,72 @@
#include "mdio-boardinfo.h"
+/* Helper function for fwnode_phy_find_device */
+static int fwnode_phy_match(struct device *dev, const void *phy_fwnode)
+{
+ return dev->fwnode == phy_fwnode;
+}
+
+/**
+ * fwnode_phy_find_device - find the phy_device associated to fwnode
+ * @phy_fwnode: Pointer to the PHY's fwnode
+ *
+ * If successful, returns a pointer to the phy_device with the
+ * embedded struct device refcount incremented by one, NULL on
+ * failure.
+ */
+struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
+{
+ struct device *d;
+ struct mdio_device *mdiodev;
+
+ if (!phy_fwnode)
+ return NULL;
+
+ d = bus_find_device(&mdio_bus_type, NULL, phy_fwnode, fwnode_phy_match);
+ if (d) {
+ mdiodev = to_mdio_device(d);
+ if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
+ return to_phy_device(d);
+ put_device(d);
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(fwnode_phy_find_device);
+
+/**
+ * fwnode_phy_connect - Connect to the phy described in the device tree
+ * @dev: pointer to net_device claiming the phy
+ * @phy_fwnode: Pointer to fwnode for the PHY
+ * @hndlr: Link state callback for the network device
+ * @flags: flags to pass to the PHY
+ * @iface: PHY data interface type
+ *
+ * If successful, returns a pointer to the phy_device with the embedded
+ * struct device refcount incremented by one, or NULL on failure. The
+ * refcount must be dropped by calling phy_disconnect() or phy_detach().
+ */
+struct phy_device *fwnode_phy_connect(
+ struct net_device *dev, struct fwnode_handle *phy_fwnode,
+ void (*hndlr)(struct net_device *), u32 flags, u32 iface)
+{
+ struct phy_device *phy_dev;
+
+ phy_dev = fwnode_phy_find_device(phy_fwnode);
+ if (!phy_dev)
+ return NULL;
+
+ phy_dev->dev_flags = flags;
+
+ /* If in case we fail to attach to PHY,then phy_dev must be NULL */
+ if (phy_connect_direct(dev, phy_dev, hndlr, iface))
+ return NULL;
+
+ return phy_dev;
+}
+EXPORT_SYMBOL(fwnode_phy_connect);
+
static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
{
/* Deassert the optional reset signal */
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 898cbf0..501da6a 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -362,6 +362,10 @@ int mdiobus_register_device(struct mdio_device *mdiodev);
int mdiobus_unregister_device(struct mdio_device *mdiodev);
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
+struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
+struct phy_device *fwnode_phy_connect(
+ struct net_device *dev, struct fwnode_handle *phy_fwnode,
+ void (*hndlr)(struct net_device *), u32 flags, u32 iface);
/**
* mdio_module_driver() - Helper macro for registering mdio drivers
--
2.7.4
next prev parent reply other threads:[~2020-07-28 12:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-28 12:13 [PATCH 0/2] Add fwnode helper functions to MDIO bus driver Vikas Singh
2020-07-28 12:13 ` Vikas Singh [this message]
2020-08-01 8:10 ` [PATCH 1/2] net: phy: Add fwnode helper functions kernel test robot
2020-07-28 12:13 ` [PATCH 2/2] net: phy: Associate device node with fixed PHY Vikas Singh
2020-07-28 13:00 ` Andrew Lunn
[not found] ` <CADvVLtXVVfU3-U8DYPtDnvGoEK2TOXhpuE=1vz6nnXaFBA8pNA@mail.gmail.com>
2020-07-31 15:31 ` Andrew Lunn
[not found] ` <CADvVLtUrZDGqwEPO_ApCWK1dELkUEjrH47s1CbYEYOH9XgZMRg@mail.gmail.com>
2020-08-01 9:41 ` Russell King - ARM Linux admin
2020-08-01 15:11 ` Andrew Lunn
2020-08-03 8:33 ` Madalin Bucur (OSS)
2020-08-03 9:07 ` Russell King - ARM Linux admin
2020-08-03 11:45 ` Madalin Bucur (OSS)
2020-08-03 12:57 ` Andrew Lunn
2020-08-03 14:33 ` Madalin Bucur (OSS)
2020-08-03 15:00 ` Andrew Lunn
2020-08-03 16:59 ` Russell King - ARM Linux admin
2020-08-03 14:10 ` Russell King - ARM Linux admin
2020-08-03 14:47 ` Madalin Bucur (OSS)
2020-08-03 16:53 ` Russell King - ARM Linux admin
2020-08-04 5:36 ` Madalin Bucur (OSS)
-- strict thread matches above, loose matches on Subject: below --
2020-07-22 11:32 [PATCH 0/2] Add fwnode helper functions to MDIO bus driver Vikas Singh
2020-07-22 11:32 ` [PATCH 1/2] net: phy: Add fwnode helper functions Vikas Singh
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=1595938400-13279-2-git-send-email-vikas.singh@puresoftware.com \
--to=vikas.singh@puresoftware.com \
--cc=andrew@lunn.ch \
--cc=calvin.johnson@oss.nxp.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kuldip.dwivedi@puresoftware.com \
--cc=linux@armlinux.org.uk \
--cc=madalin.bucur@oss.nxp.com \
--cc=netdev@vger.kernel.org \
--cc=vikas.singh@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;
as well as URLs for NNTP newsgroup(s).