Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: add of_mdio_find_device() api

Add a helper function which finds the mdio_device structure given a
device tree node. This is helpful for finding the PCS device based on a
DTS node but managing it as a mdio_device instead of a phy_device.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Russell King and committed by
David S. Miller
b5b6775d e7e95c90

+35 -9
+29 -9
drivers/of/of_mdio.c
··· 338 338 EXPORT_SYMBOL(of_mdiobus_register); 339 339 340 340 /** 341 + * of_mdio_find_device - Given a device tree node, find the mdio_device 342 + * @np: pointer to the mdio_device's device tree node 343 + * 344 + * If successful, returns a pointer to the mdio_device with the embedded 345 + * struct device refcount incremented by one, or NULL on failure. 346 + * The caller should call put_device() on the mdio_device after its use 347 + */ 348 + struct mdio_device *of_mdio_find_device(struct device_node *np) 349 + { 350 + struct device *d; 351 + 352 + if (!np) 353 + return NULL; 354 + 355 + d = bus_find_device_by_of_node(&mdio_bus_type, np); 356 + if (!d) 357 + return NULL; 358 + 359 + return to_mdio_device(d); 360 + } 361 + EXPORT_SYMBOL(of_mdio_find_device); 362 + 363 + /** 341 364 * of_phy_find_device - Give a PHY node, find the phy_device 342 365 * @phy_np: Pointer to the phy's device tree node 343 366 * ··· 369 346 */ 370 347 struct phy_device *of_phy_find_device(struct device_node *phy_np) 371 348 { 372 - struct device *d; 373 349 struct mdio_device *mdiodev; 374 350 375 - if (!phy_np) 351 + mdiodev = of_mdio_find_device(phy_np); 352 + if (!mdiodev) 376 353 return NULL; 377 354 378 - d = bus_find_device_by_of_node(&mdio_bus_type, phy_np); 379 - if (d) { 380 - mdiodev = to_mdio_device(d); 381 - if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) 382 - return to_phy_device(d); 383 - put_device(d); 384 - } 355 + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) 356 + return to_phy_device(&mdiodev->dev); 357 + 358 + put_device(&mdiodev->dev); 385 359 386 360 return NULL; 387 361 }
+6
include/linux/of_mdio.h
··· 17 17 int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np); 18 18 int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio, 19 19 struct device_node *np); 20 + struct mdio_device *of_mdio_find_device(struct device_node *np); 20 21 struct phy_device *of_phy_find_device(struct device_node *phy_np); 21 22 struct phy_device * 22 23 of_phy_connect(struct net_device *dev, struct device_node *phy_np, ··· 73 72 */ 74 73 75 74 return mdiobus_register(mdio); 75 + } 76 + 77 + static inline struct mdio_device *of_mdio_find_device(struct device_node *np) 78 + { 79 + return NULL; 76 80 } 77 81 78 82 static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)