Commit 3c6f5592 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by David S. Miller

of_mdio: Allow the DT to specify the phy ID and avoid autoprobing

This makes the generic of_mdiobus_register parse the DT compatible string for
the pattern ethernet-phy-idAAAA.BBBB. If present it should be a value that
matches the phy-id register normally readable through MDIO.

When the ID is given the phy autoprobing is defeated and the phy is
created directly.

This is necessary to support phy's that cannot be autoprobed when
of_mdiobus_register is called. Specifically, my case has the phy in reset at
of_mdiobus_register, the reset is only released once the ethernet driver
starts, before it attaches to the phy.

Tested on ARM Kirkwood with phy id 0x01410e90 (Marvell 88E1318)
Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Acked-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f00e756e
...@@ -43,6 +43,23 @@ static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed) ...@@ -43,6 +43,23 @@ static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed)
} }
} }
/* Extract the clause 22 phy ID from the compatible string of the form
* ethernet-phy-idAAAA.BBBB */
static int of_get_phy_id(struct device_node *device, u32 *phy_id)
{
struct property *prop;
const char *cp;
unsigned int upper, lower;
of_property_for_each_string(device, "compatible", prop, cp) {
if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) {
*phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF);
return 0;
}
}
return -EINVAL;
}
static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child, static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child,
u32 addr) u32 addr)
{ {
...@@ -50,11 +67,15 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi ...@@ -50,11 +67,15 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi
bool is_c45; bool is_c45;
int rc; int rc;
u32 max_speed = 0; u32 max_speed = 0;
u32 phy_id;
is_c45 = of_device_is_compatible(child, is_c45 = of_device_is_compatible(child,
"ethernet-phy-ieee802.3-c45"); "ethernet-phy-ieee802.3-c45");
phy = get_phy_device(mdio, addr, is_c45); if (!is_c45 && !of_get_phy_id(child, &phy_id))
phy = phy_device_create(mdio, addr, phy_id, 0, NULL);
else
phy = get_phy_device(mdio, addr, is_c45);
if (!phy || IS_ERR(phy)) if (!phy || IS_ERR(phy))
return 1; return 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment