710-phy-add-mdio_register_board_info.patch 4.9 KB

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