of_mdio.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * OF helpers for the MDIO (Ethernet PHY) API
  4. *
  5. * Copyright (c) 2009 Secret Lab Technologies, Ltd.
  6. */
  7. #ifndef __LINUX_OF_MDIO_H
  8. #define __LINUX_OF_MDIO_H
  9. #include <linux/device.h>
  10. #include <linux/phy.h>
  11. #include <linux/of.h>
  12. #if IS_ENABLED(CONFIG_OF_MDIO)
  13. bool of_mdiobus_child_is_phy(struct device_node *child);
  14. int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
  15. int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
  16. struct device_node *np);
  17. struct mdio_device *of_mdio_find_device(struct device_node *np);
  18. struct phy_device *of_phy_find_device(struct device_node *phy_np);
  19. struct phy_device *
  20. of_phy_connect(struct net_device *dev, struct device_node *phy_np,
  21. void (*hndlr)(struct net_device *), u32 flags,
  22. phy_interface_t iface);
  23. struct phy_device *
  24. of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
  25. void (*hndlr)(struct net_device *));
  26. struct phy_device *
  27. of_phy_attach(struct net_device *dev, struct device_node *phy_np,
  28. u32 flags, phy_interface_t iface);
  29. struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
  30. int of_phy_register_fixed_link(struct device_node *np);
  31. void of_phy_deregister_fixed_link(struct device_node *np);
  32. bool of_phy_is_fixed_link(struct device_node *np);
  33. int of_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy,
  34. struct device_node *child, u32 addr);
  35. static inline int of_mdio_parse_addr(struct device *dev,
  36. const struct device_node *np)
  37. {
  38. u32 addr;
  39. int ret;
  40. ret = of_property_read_u32(np, "reg", &addr);
  41. if (ret < 0) {
  42. dev_err(dev, "%s has invalid PHY address\n", np->full_name);
  43. return ret;
  44. }
  45. /* A PHY must have a reg property in the range [0-31] */
  46. if (addr >= PHY_MAX_ADDR) {
  47. dev_err(dev, "%s PHY address %i is too large\n",
  48. np->full_name, addr);
  49. return -EINVAL;
  50. }
  51. return addr;
  52. }
  53. #else /* CONFIG_OF_MDIO */
  54. static inline bool of_mdiobus_child_is_phy(struct device_node *child)
  55. {
  56. return false;
  57. }
  58. static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
  59. {
  60. /*
  61. * Fall back to the non-DT function to register a bus.
  62. * This way, we don't have to keep compat bits around in drivers.
  63. */
  64. return mdiobus_register(mdio);
  65. }
  66. static inline int devm_of_mdiobus_register(struct device *dev,
  67. struct mii_bus *mdio,
  68. struct device_node *np)
  69. {
  70. return devm_mdiobus_register(dev, mdio);
  71. }
  72. static inline struct mdio_device *of_mdio_find_device(struct device_node *np)
  73. {
  74. return NULL;
  75. }
  76. static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)
  77. {
  78. return NULL;
  79. }
  80. static inline struct phy_device *of_phy_connect(struct net_device *dev,
  81. struct device_node *phy_np,
  82. void (*hndlr)(struct net_device *),
  83. u32 flags, phy_interface_t iface)
  84. {
  85. return NULL;
  86. }
  87. static inline struct phy_device *
  88. of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
  89. void (*hndlr)(struct net_device *))
  90. {
  91. return NULL;
  92. }
  93. static inline struct phy_device *of_phy_attach(struct net_device *dev,
  94. struct device_node *phy_np,
  95. u32 flags, phy_interface_t iface)
  96. {
  97. return NULL;
  98. }
  99. static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np)
  100. {
  101. return NULL;
  102. }
  103. static inline int of_mdio_parse_addr(struct device *dev,
  104. const struct device_node *np)
  105. {
  106. return -ENOSYS;
  107. }
  108. static inline int of_phy_register_fixed_link(struct device_node *np)
  109. {
  110. return -ENOSYS;
  111. }
  112. static inline void of_phy_deregister_fixed_link(struct device_node *np)
  113. {
  114. }
  115. static inline bool of_phy_is_fixed_link(struct device_node *np)
  116. {
  117. return false;
  118. }
  119. static inline int of_mdiobus_phy_device_register(struct mii_bus *mdio,
  120. struct phy_device *phy,
  121. struct device_node *child, u32 addr)
  122. {
  123. return -ENOSYS;
  124. }
  125. #endif
  126. #endif /* __LINUX_OF_MDIO_H */