0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __LINUX_OF_MDIO_H
0009 #define __LINUX_OF_MDIO_H
0010
0011 #include <linux/device.h>
0012 #include <linux/phy.h>
0013 #include <linux/of.h>
0014
0015 #if IS_ENABLED(CONFIG_OF_MDIO)
0016 bool of_mdiobus_child_is_phy(struct device_node *child);
0017 int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
0018 int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
0019 struct device_node *np);
0020 struct mdio_device *of_mdio_find_device(struct device_node *np);
0021 struct phy_device *of_phy_find_device(struct device_node *phy_np);
0022 struct phy_device *
0023 of_phy_connect(struct net_device *dev, struct device_node *phy_np,
0024 void (*hndlr)(struct net_device *), u32 flags,
0025 phy_interface_t iface);
0026 struct phy_device *
0027 of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
0028 void (*hndlr)(struct net_device *));
0029
0030 struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
0031 int of_phy_register_fixed_link(struct device_node *np);
0032 void of_phy_deregister_fixed_link(struct device_node *np);
0033 bool of_phy_is_fixed_link(struct device_node *np);
0034 int of_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy,
0035 struct device_node *child, u32 addr);
0036
0037 static inline int of_mdio_parse_addr(struct device *dev,
0038 const struct device_node *np)
0039 {
0040 u32 addr;
0041 int ret;
0042
0043 ret = of_property_read_u32(np, "reg", &addr);
0044 if (ret < 0) {
0045 dev_err(dev, "%s has invalid PHY address\n", np->full_name);
0046 return ret;
0047 }
0048
0049
0050 if (addr >= PHY_MAX_ADDR) {
0051 dev_err(dev, "%s PHY address %i is too large\n",
0052 np->full_name, addr);
0053 return -EINVAL;
0054 }
0055
0056 return addr;
0057 }
0058
0059 #else
0060 static inline bool of_mdiobus_child_is_phy(struct device_node *child)
0061 {
0062 return false;
0063 }
0064
0065 static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
0066 {
0067
0068
0069
0070
0071
0072 return mdiobus_register(mdio);
0073 }
0074
0075 static inline int devm_of_mdiobus_register(struct device *dev,
0076 struct mii_bus *mdio,
0077 struct device_node *np)
0078 {
0079 return devm_mdiobus_register(dev, mdio);
0080 }
0081
0082 static inline struct mdio_device *of_mdio_find_device(struct device_node *np)
0083 {
0084 return NULL;
0085 }
0086
0087 static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)
0088 {
0089 return NULL;
0090 }
0091
0092 static inline struct phy_device *of_phy_connect(struct net_device *dev,
0093 struct device_node *phy_np,
0094 void (*hndlr)(struct net_device *),
0095 u32 flags, phy_interface_t iface)
0096 {
0097 return NULL;
0098 }
0099
0100 static inline struct phy_device *
0101 of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
0102 void (*hndlr)(struct net_device *))
0103 {
0104 return NULL;
0105 }
0106
0107 static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np)
0108 {
0109 return NULL;
0110 }
0111
0112 static inline int of_mdio_parse_addr(struct device *dev,
0113 const struct device_node *np)
0114 {
0115 return -ENOSYS;
0116 }
0117 static inline int of_phy_register_fixed_link(struct device_node *np)
0118 {
0119 return -ENOSYS;
0120 }
0121 static inline void of_phy_deregister_fixed_link(struct device_node *np)
0122 {
0123 }
0124 static inline bool of_phy_is_fixed_link(struct device_node *np)
0125 {
0126 return false;
0127 }
0128
0129 static inline int of_mdiobus_phy_device_register(struct mii_bus *mdio,
0130 struct phy_device *phy,
0131 struct device_node *child, u32 addr)
0132 {
0133 return -ENOSYS;
0134 }
0135 #endif
0136
0137
0138 #endif