710-phy-add-mdio_register_board_info.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. --- a/drivers/net/phy/mdio_bus.c
  2. +++ b/drivers/net/phy/mdio_bus.c
  3. @@ -80,6 +80,8 @@ bool mdiobus_is_registered_device(struct
  4. }
  5. EXPORT_SYMBOL(mdiobus_is_registered_device);
  6. +#include "mdio-boardinfo.h"
  7. +
  8. /**
  9. * mdiobus_alloc_size - allocate a mii_bus structure
  10. * @size: extra amount of memory to allocate for private storage.
  11. @@ -401,6 +403,17 @@ void mdiobus_free(struct mii_bus *bus)
  12. }
  13. EXPORT_SYMBOL(mdiobus_free);
  14. +static void mdiobus_setup_phydev_from_boardinfo(struct mii_bus *bus,
  15. + struct phy_device *phydev,
  16. + struct mdio_board_info *bi)
  17. +{
  18. + if (strcmp(bus->id, bi->bus_id) ||
  19. + bi->phy_addr != phydev->mdio.addr)
  20. + return;
  21. +
  22. + phydev->mdio.dev.platform_data = (void *) bi->platform_data;
  23. +}
  24. +
  25. /**
  26. * mdiobus_scan - scan a bus for MDIO devices.
  27. * @bus: mii_bus to scan
  28. @@ -416,6 +429,7 @@ EXPORT_SYMBOL(mdiobus_free);
  29. struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
  30. {
  31. struct phy_device *phydev;
  32. + struct mdio_board_entry *be;
  33. int err;
  34. phydev = get_phy_device(bus, addr, false);
  35. @@ -428,6 +442,12 @@ struct phy_device *mdiobus_scan(struct m
  36. */
  37. of_mdiobus_link_mdiodev(bus, &phydev->mdio);
  38. + mutex_lock(&__mdio_board_lock);
  39. + list_for_each_entry(be, &__mdio_board_list, list)
  40. + mdiobus_setup_phydev_from_boardinfo(bus, phydev,
  41. + &be->board_info);
  42. + mutex_unlock(&__mdio_board_lock);
  43. +
  44. err = phy_device_register(phydev);
  45. if (err) {
  46. phy_device_free(phydev);
  47. --- a/include/linux/phy.h
  48. +++ b/include/linux/phy.h
  49. @@ -859,6 +859,23 @@ void mdio_bus_exit(void);
  50. extern struct bus_type mdio_bus_type;
  51. +struct mdio_board_info {
  52. + const char *bus_id;
  53. + int phy_addr;
  54. +
  55. + const void *platform_data;
  56. +};
  57. +
  58. +#ifdef CONFIG_MDIO_BOARDINFO
  59. +int mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n);
  60. +#else
  61. +static inline int
  62. +mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n)
  63. +{
  64. + return 0;
  65. +}
  66. +#endif
  67. +
  68. /**
  69. * module_phy_driver() - Helper macro for registering PHY drivers
  70. * @__phy_drivers: array of PHY drivers to register
  71. --- a/drivers/net/phy/Kconfig
  72. +++ b/drivers/net/phy/Kconfig
  73. @@ -149,6 +149,10 @@ config MDIO_XGENE
  74. comment "Switch configuration API + drivers"
  75. +config MDIO_BOARDINFO
  76. + bool
  77. + default y
  78. +
  79. config SWCONFIG
  80. tristate "Switch configuration API"
  81. ---help---
  82. --- a/drivers/net/phy/Makefile
  83. +++ b/drivers/net/phy/Makefile
  84. @@ -3,6 +3,8 @@
  85. libphy-y := phy.o phy_device.o mdio_bus.o mdio_device.o
  86. libphy-$(CONFIG_SWPHY) += swphy.o
  87. +obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
  88. +
  89. obj-$(CONFIG_PHYLIB) += libphy.o
  90. obj-$(CONFIG_SWCONFIG) += swconfig.o
  91. --- /dev/null
  92. +++ b/drivers/net/phy/mdio-boardinfo.c
  93. @@ -0,0 +1,58 @@
  94. +/*
  95. + * mdio-boardinfo.c - collect pre-declarations of PHY devices
  96. + *
  97. + * This program is free software; you can redistribute it and/or modify it
  98. + * under the terms of the GNU General Public License as published by the
  99. + * Free Software Foundation; either version 2 of the License, or (at your
  100. + * option) any later version.
  101. + *
  102. + */
  103. +
  104. +#include <linux/kernel.h>
  105. +#include <linux/phy.h>
  106. +#include <linux/slab.h>
  107. +#include <linux/export.h>
  108. +#include <linux/mutex.h>
  109. +#include <linux/phy.h>
  110. +
  111. +#include "mdio-boardinfo.h"
  112. +
  113. +/*
  114. + * These symbols are exported ONLY FOR the mdio_bus component.
  115. + * No other users will be supported.
  116. + */
  117. +
  118. +LIST_HEAD(__mdio_board_list);
  119. +EXPORT_SYMBOL_GPL(__mdio_board_list);
  120. +
  121. +DEFINE_MUTEX(__mdio_board_lock);
  122. +EXPORT_SYMBOL_GPL(__mdio_board_lock);
  123. +
  124. +/**
  125. + * mdio_register_board_info - register PHY devices for a given board
  126. + * @info: array of chip descriptors
  127. + * @n: how many descriptors are provided
  128. + * Context: can sleep
  129. + *
  130. + * The board info passed can safely be __initdata ... but be careful of
  131. + * any embedded pointers (platform_data, etc), they're copied as-is.
  132. + */
  133. +int __init
  134. +mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
  135. +{
  136. + struct mdio_board_entry *be;
  137. + int i;
  138. +
  139. + be = kzalloc(n * sizeof(*be), GFP_KERNEL);
  140. + if (!be)
  141. + return -ENOMEM;
  142. +
  143. + for (i = 0; i < n; i++, be++, info++) {
  144. + memcpy(&be->board_info, info, sizeof(*info));
  145. + mutex_lock(&__mdio_board_lock);
  146. + list_add_tail(&be->list, &__mdio_board_list);
  147. + mutex_unlock(&__mdio_board_lock);
  148. + }
  149. +
  150. + return 0;
  151. +}
  152. --- /dev/null
  153. +++ b/drivers/net/phy/mdio-boardinfo.h
  154. @@ -0,0 +1,22 @@
  155. +/*
  156. + * mdio-boardinfo.h - boardinfo interface internal to the mdio_bus component
  157. + *
  158. + * This program is free software; you can redistribute it and/or modify it
  159. + * under the terms of the GNU General Public License as published by the
  160. + * Free Software Foundation; either version 2 of the License, or (at your
  161. + * option) any later version.
  162. + *
  163. + */
  164. +
  165. +#include <linux/mutex.h>
  166. +
  167. +struct mdio_board_entry {
  168. + struct list_head list;
  169. + struct mdio_board_info board_info;
  170. +};
  171. +
  172. +/* __mdio_board_lock protects __mdio_board_list
  173. + * only mdio_bus components are allowed to use these symbols.
  174. + */
  175. +extern struct mutex __mdio_board_lock;
  176. +extern struct list_head __mdio_board_list;
  177. --- a/drivers/net/Makefile
  178. +++ b/drivers/net/Makefile
  179. @@ -17,7 +17,7 @@ obj-$(CONFIG_MII) += mii.o
  180. obj-$(CONFIG_MDIO) += mdio.o
  181. obj-$(CONFIG_NET) += Space.o loopback.o
  182. obj-$(CONFIG_NETCONSOLE) += netconsole.o
  183. -obj-$(CONFIG_PHYLIB) += phy/
  184. +obj-y += phy/
  185. obj-$(CONFIG_RIONET) += rionet.o
  186. obj-$(CONFIG_NET_TEAM) += team/
  187. obj-$(CONFIG_TUN) += tun.o