Commit 425775ed authored by Calvin Johnson's avatar Calvin Johnson Committed by David S. Miller
Browse files

net: phy: Introduce phy related fwnode functions



Define fwnode_phy_find_device() to iterate an mdiobus and find the
phy device of the provided phy fwnode. Additionally define
device_phy_find_device() to find phy device of provided device.

Define fwnode_get_phy_node() to get phy_node using named reference.

Signed-off-by: default avatarCalvin Johnson <calvin.johnson@oss.nxp.com>
Signed-off-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Acked-by: default avatarGrant Likely <grant.likely@arm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0fb16976
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/acpi.h>
#include <linux/bitmap.h>
#include <linux/delay.h>
#include <linux/errno.h>
@@ -2898,6 +2899,67 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
}
EXPORT_SYMBOL(fwnode_mdio_find_device);

/**
 * fwnode_phy_find_device - For provided phy_fwnode, find phy_device.
 *
 * @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, or NULL on failure.
 */
struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
{
	struct mdio_device *mdiodev;

	mdiodev = fwnode_mdio_find_device(phy_fwnode);
	if (!mdiodev)
		return NULL;

	if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
		return to_phy_device(&mdiodev->dev);

	put_device(&mdiodev->dev);

	return NULL;
}
EXPORT_SYMBOL(fwnode_phy_find_device);

/**
 * device_phy_find_device - For the given device, get the phy_device
 * @dev: Pointer to the given device
 *
 * Refer return conditions of fwnode_phy_find_device().
 */
struct phy_device *device_phy_find_device(struct device *dev)
{
	return fwnode_phy_find_device(dev_fwnode(dev));
}
EXPORT_SYMBOL_GPL(device_phy_find_device);

/**
 * fwnode_get_phy_node - Get the phy_node using the named reference.
 * @fwnode: Pointer to fwnode from which phy_node has to be obtained.
 *
 * Refer return conditions of fwnode_find_reference().
 * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy"
 * and "phy-device" are not supported in ACPI. DT supports all the three
 * named references to the phy node.
 */
struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode)
{
	struct fwnode_handle *phy_node;

	/* Only phy-handle is used for ACPI */
	phy_node = fwnode_find_reference(fwnode, "phy-handle", 0);
	if (is_acpi_node(fwnode) || !IS_ERR(phy_node))
		return phy_node;
	phy_node = fwnode_find_reference(fwnode, "phy", 0);
	if (IS_ERR(phy_node))
		phy_node = fwnode_find_reference(fwnode, "phy-device", 0);
	return phy_node;
}
EXPORT_SYMBOL_GPL(fwnode_get_phy_node);

/**
 * phy_probe - probe and init a PHY device
 * @dev: device to probe and init
+20 −0
Original line number Diff line number Diff line
@@ -1378,6 +1378,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
				     struct phy_c45_device_ids *c45_ids);
#if IS_ENABLED(CONFIG_PHYLIB)
struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode);
struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
struct phy_device *device_phy_find_device(struct device *dev);
struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode);
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
int phy_device_register(struct phy_device *phy);
void phy_device_free(struct phy_device *phydev);
@@ -1388,6 +1391,23 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
	return 0;
}

static inline
struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode)
{
	return NULL;
}

static inline struct phy_device *device_phy_find_device(struct device *dev)
{
	return NULL;
}

static inline
struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode)
{
	return NULL;
}

static inline
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
{