mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	net: mdiobus: Introduce fwnode_mdbiobus_register()
This patch introduces a new helper function that wraps acpi_/of_ mdiobus_register() and allows its usage via common fwnode_ interface. Fall back to raw mdiobus_register() in case CONFIG_FWNODE_MDIO is not enabled, in order to satisfy compatibility in all future user drivers. Signed-off-by: Marcin Wojtas <mw@semihalf.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									7c4d7ca8cc
								
							
						
					
					
						commit
						62a6ef6a99
					
				
					 2 changed files with 34 additions and 0 deletions
				
			
		| 
						 | 
					@ -7,8 +7,10 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <linux/acpi.h>
 | 
					#include <linux/acpi.h>
 | 
				
			||||||
 | 
					#include <linux/acpi_mdio.h>
 | 
				
			||||||
#include <linux/fwnode_mdio.h>
 | 
					#include <linux/fwnode_mdio.h>
 | 
				
			||||||
#include <linux/of.h>
 | 
					#include <linux/of.h>
 | 
				
			||||||
 | 
					#include <linux/of_mdio.h>
 | 
				
			||||||
#include <linux/phy.h>
 | 
					#include <linux/phy.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
 | 
					MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
 | 
				
			||||||
| 
						 | 
					@ -142,3 +144,23 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(fwnode_mdiobus_register_phy);
 | 
					EXPORT_SYMBOL(fwnode_mdiobus_register_phy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * fwnode_mdiobus_register - bring up all the PHYs on a given MDIO bus and
 | 
				
			||||||
 | 
					 *	attach them to it.
 | 
				
			||||||
 | 
					 * @bus: Target MDIO bus.
 | 
				
			||||||
 | 
					 * @fwnode: Pointer to fwnode of the MDIO controller.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Return values are determined accordingly to acpi_/of_ mdiobus_register()
 | 
				
			||||||
 | 
					 * operation.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int fwnode_mdiobus_register(struct mii_bus *bus, struct fwnode_handle *fwnode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (is_acpi_node(fwnode))
 | 
				
			||||||
 | 
							return acpi_mdiobus_register(bus, fwnode);
 | 
				
			||||||
 | 
						else if (is_of_node(fwnode))
 | 
				
			||||||
 | 
							return of_mdiobus_register(bus, to_of_node(fwnode));
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL(fwnode_mdiobus_register);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,7 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
 | 
				
			||||||
int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 | 
					int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 | 
				
			||||||
				struct fwnode_handle *child, u32 addr);
 | 
									struct fwnode_handle *child, u32 addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int fwnode_mdiobus_register(struct mii_bus *bus, struct fwnode_handle *fwnode);
 | 
				
			||||||
#else /* CONFIG_FWNODE_MDIO */
 | 
					#else /* CONFIG_FWNODE_MDIO */
 | 
				
			||||||
int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
 | 
					int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
 | 
				
			||||||
				       struct phy_device *phy,
 | 
									       struct phy_device *phy,
 | 
				
			||||||
| 
						 | 
					@ -30,6 +31,17 @@ static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return -EINVAL;
 | 
						return -EINVAL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int fwnode_mdiobus_register(struct mii_bus *bus,
 | 
				
			||||||
 | 
										  struct fwnode_handle *fwnode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Fall back to mdiobus_register() function to register a bus.
 | 
				
			||||||
 | 
						 * This way, we don't have to keep compat bits around in drivers.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return mdiobus_register(mdio);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* __LINUX_FWNODE_MDIO_H */
 | 
					#endif /* __LINUX_FWNODE_MDIO_H */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue