diff options
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 44 | ||||
-rw-r--r-- | drivers/of/of_mdio.c | 34 | ||||
-rw-r--r-- | include/linux/of_mdio.h | 8 |
3 files changed, 44 insertions, 42 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 2e58aa54484c..4eaadcfcb0fe 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -187,6 +187,50 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np) | |||
187 | return d ? to_mii_bus(d) : NULL; | 187 | return d ? to_mii_bus(d) : NULL; |
188 | } | 188 | } |
189 | EXPORT_SYMBOL(of_mdio_find_bus); | 189 | EXPORT_SYMBOL(of_mdio_find_bus); |
190 | |||
191 | /* Walk the list of subnodes of a mdio bus and look for a node that matches the | ||
192 | * phy's address with its 'reg' property. If found, set the of_node pointer for | ||
193 | * the phy. This allows auto-probed pyh devices to be supplied with information | ||
194 | * passed in via DT. | ||
195 | */ | ||
196 | static void of_mdiobus_link_phydev(struct mii_bus *mdio, | ||
197 | struct phy_device *phydev) | ||
198 | { | ||
199 | struct device *dev = &phydev->dev; | ||
200 | struct device_node *child; | ||
201 | |||
202 | if (dev->of_node || !mdio->dev.of_node) | ||
203 | return; | ||
204 | |||
205 | for_each_available_child_of_node(mdio->dev.of_node, child) { | ||
206 | int addr; | ||
207 | int ret; | ||
208 | |||
209 | ret = of_property_read_u32(child, "reg", &addr); | ||
210 | if (ret < 0) { | ||
211 | dev_err(dev, "%s has invalid PHY address\n", | ||
212 | child->full_name); | ||
213 | continue; | ||
214 | } | ||
215 | |||
216 | /* A PHY must have a reg property in the range [0-31] */ | ||
217 | if (addr >= PHY_MAX_ADDR) { | ||
218 | dev_err(dev, "%s PHY address %i is too large\n", | ||
219 | child->full_name, addr); | ||
220 | continue; | ||
221 | } | ||
222 | |||
223 | if (addr == phydev->addr) { | ||
224 | dev->of_node = child; | ||
225 | return; | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | #else /* !IS_ENABLED(CONFIG_OF_MDIO) */ | ||
230 | static inline void of_mdiobus_link_phydev(struct mii_bus *mdio, | ||
231 | struct phy_device *phydev) | ||
232 | { | ||
233 | } | ||
190 | #endif | 234 | #endif |
191 | 235 | ||
192 | /** | 236 | /** |
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index a3bf2122a8d5..401b2453da45 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c | |||
@@ -182,40 +182,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) | |||
182 | } | 182 | } |
183 | EXPORT_SYMBOL(of_mdiobus_register); | 183 | EXPORT_SYMBOL(of_mdiobus_register); |
184 | 184 | ||
185 | /** | ||
186 | * of_mdiobus_link_phydev - Find a device node for a phy | ||
187 | * @mdio: pointer to mii_bus structure | ||
188 | * @phydev: phydev for which the of_node pointer should be set | ||
189 | * | ||
190 | * Walk the list of subnodes of a mdio bus and look for a node that matches the | ||
191 | * phy's address with its 'reg' property. If found, set the of_node pointer for | ||
192 | * the phy. This allows auto-probed pyh devices to be supplied with information | ||
193 | * passed in via DT. | ||
194 | */ | ||
195 | void of_mdiobus_link_phydev(struct mii_bus *mdio, | ||
196 | struct phy_device *phydev) | ||
197 | { | ||
198 | struct device *dev = &phydev->dev; | ||
199 | struct device_node *child; | ||
200 | |||
201 | if (dev->of_node || !mdio->dev.of_node) | ||
202 | return; | ||
203 | |||
204 | for_each_available_child_of_node(mdio->dev.of_node, child) { | ||
205 | int addr; | ||
206 | |||
207 | addr = of_mdio_parse_addr(&mdio->dev, child); | ||
208 | if (addr < 0) | ||
209 | continue; | ||
210 | |||
211 | if (addr == phydev->addr) { | ||
212 | dev->of_node = child; | ||
213 | return; | ||
214 | } | ||
215 | } | ||
216 | } | ||
217 | EXPORT_SYMBOL(of_mdiobus_link_phydev); | ||
218 | |||
219 | /* Helper function for of_phy_find_device */ | 185 | /* Helper function for of_phy_find_device */ |
220 | static int of_phy_match(struct device *dev, void *phy_np) | 186 | static int of_phy_match(struct device *dev, void *phy_np) |
221 | { | 187 | { |
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h index a70c9493d55a..d449018d0726 100644 --- a/include/linux/of_mdio.h +++ b/include/linux/of_mdio.h | |||
@@ -25,9 +25,6 @@ struct phy_device *of_phy_attach(struct net_device *dev, | |||
25 | 25 | ||
26 | extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np); | 26 | extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np); |
27 | 27 | ||
28 | extern void of_mdiobus_link_phydev(struct mii_bus *mdio, | ||
29 | struct phy_device *phydev); | ||
30 | |||
31 | #else /* CONFIG_OF */ | 28 | #else /* CONFIG_OF */ |
32 | static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) | 29 | static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) |
33 | { | 30 | { |
@@ -63,11 +60,6 @@ static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np) | |||
63 | { | 60 | { |
64 | return NULL; | 61 | return NULL; |
65 | } | 62 | } |
66 | |||
67 | static inline void of_mdiobus_link_phydev(struct mii_bus *mdio, | ||
68 | struct phy_device *phydev) | ||
69 | { | ||
70 | } | ||
71 | #endif /* CONFIG_OF */ | 63 | #endif /* CONFIG_OF */ |
72 | 64 | ||
73 | #if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY) | 65 | #if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY) |