Skip to content

Commit 114dea6

Browse files
calvinjolinuxdavem330
authored andcommitted
net: phy: Introduce fwnode_get_phy_id()
Extract phy_id from compatible string. This will be used by fwnode_mdiobus_register_phy() to create phy device using the phy_id. Signed-off-by: Calvin Johnson <[email protected]> Signed-off-by: Ioana Ciornei <[email protected]> Acked-by: Grant Likely <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2d7b8bf commit 114dea6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

drivers/net/phy/phy_device.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,27 @@ static int get_phy_c22_id(struct mii_bus *bus, int addr, u32 *phy_id)
834834
return 0;
835835
}
836836

837+
/* Extract the phy ID from the compatible string of the form
838+
* ethernet-phy-idAAAA.BBBB.
839+
*/
840+
int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id)
841+
{
842+
unsigned int upper, lower;
843+
const char *cp;
844+
int ret;
845+
846+
ret = fwnode_property_read_string(fwnode, "compatible", &cp);
847+
if (ret)
848+
return ret;
849+
850+
if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) != 2)
851+
return -EINVAL;
852+
853+
*phy_id = ((upper & GENMASK(15, 0)) << 16) | (lower & GENMASK(15, 0));
854+
return 0;
855+
}
856+
EXPORT_SYMBOL(fwnode_get_phy_id);
857+
837858
/**
838859
* get_phy_device - reads the specified PHY device and returns its @phy_device
839860
* struct

include/linux/phy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
13771377
bool is_c45,
13781378
struct phy_c45_device_ids *c45_ids);
13791379
#if IS_ENABLED(CONFIG_PHYLIB)
1380+
int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id);
13801381
struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode);
13811382
struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode);
13821383
struct phy_device *device_phy_find_device(struct device *dev);
@@ -1385,6 +1386,10 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
13851386
int phy_device_register(struct phy_device *phy);
13861387
void phy_device_free(struct phy_device *phydev);
13871388
#else
1389+
static inline int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id)
1390+
{
1391+
return 0;
1392+
}
13881393
static inline
13891394
struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode)
13901395
{

0 commit comments

Comments
 (0)