0021-phy-add-mdio-boardinfo.patch 6.2 KB

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