Skip to content

Commit 801a8ef

Browse files
lunndavem330
authored andcommitted
of: phy: Only register a phy device for phys
We will soon support devices other than phys on the mdio bus. Look at a child's compatibility string to determine if it is a phy, before registering a phy device. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e5a03bf commit 801a8ef

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

drivers/of/of_mdio.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,35 @@ int of_mdio_parse_addr(struct device *dev, const struct device_node *np)
114114
}
115115
EXPORT_SYMBOL(of_mdio_parse_addr);
116116

117+
/*
118+
* Return true if the child node is for a phy. It must either:
119+
* o Compatible string of "ethernet-phy-idX.X"
120+
* o Compatible string of "ethernet-phy-ieee802.3-c45"
121+
* o Compatible string of "ethernet-phy-ieee802.3-c22"
122+
* o No compatibility string
123+
*
124+
* A device which is not a phy is expected to have a compatible string
125+
* indicating what sort of device it is.
126+
*/
127+
static bool of_mdiobus_child_is_phy(struct device_node *child)
128+
{
129+
u32 phy_id;
130+
131+
if (of_get_phy_id(child, &phy_id) != -EINVAL)
132+
return true;
133+
134+
if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"))
135+
return true;
136+
137+
if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22"))
138+
return true;
139+
140+
if (!of_find_property(child, "compatible", NULL))
141+
return true;
142+
143+
return false;
144+
}
145+
117146
/**
118147
* of_mdiobus_register - Register mii_bus and create PHYs from the device tree
119148
* @mdio: pointer to mii_bus structure
@@ -140,17 +169,16 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
140169
if (rc)
141170
return rc;
142171

143-
/* Loop over the child nodes and register a phy_device for each one */
172+
/* Loop over the child nodes and register a phy_device for each phy */
144173
for_each_available_child_of_node(np, child) {
145174
addr = of_mdio_parse_addr(&mdio->dev, child);
146175
if (addr < 0) {
147176
scanphys = true;
148177
continue;
149178
}
150179

151-
rc = of_mdiobus_register_phy(mdio, child, addr);
152-
if (rc)
153-
continue;
180+
if (of_mdiobus_child_is_phy(child))
181+
of_mdiobus_register_phy(mdio, child, addr);
154182
}
155183

156184
if (!scanphys)
@@ -172,9 +200,8 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
172200
dev_info(&mdio->dev, "scan phy %s at address %i\n",
173201
child->name, addr);
174202

175-
rc = of_mdiobus_register_phy(mdio, child, addr);
176-
if (rc)
177-
continue;
203+
if (of_mdiobus_child_is_phy(child))
204+
of_mdiobus_register_phy(mdio, child, addr);
178205
}
179206
}
180207

0 commit comments

Comments
 (0)