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
5 EXPORT_SYMBOL(mdiobus_is_registered_device);
7 +#include "mdio-boardinfo.h"
10 * mdiobus_alloc_size - allocate a mii_bus structure
11 * @size: extra amount of memory to allocate for private storage.
12 @@ -401,6 +403,17 @@ void mdiobus_free(struct mii_bus *bus)
14 EXPORT_SYMBOL(mdiobus_free);
16 +static void mdiobus_setup_phydev_from_boardinfo(struct mii_bus *bus,
17 + struct phy_device *phydev,
18 + struct mdio_board_info *bi)
20 + if (strcmp(bus->id, bi->bus_id) ||
21 + bi->phy_addr != phydev->mdio.addr)
24 + phydev->mdio.dev.platform_data = (void *) bi->platform_data;
28 * mdiobus_scan - scan a bus for MDIO devices.
29 * @bus: mii_bus to scan
30 @@ -416,6 +429,7 @@ EXPORT_SYMBOL(mdiobus_free);
31 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
33 struct phy_device *phydev;
34 + struct mdio_board_entry *be;
37 phydev = get_phy_device(bus, addr, false);
38 @@ -428,6 +442,12 @@ struct phy_device *mdiobus_scan(struct m
40 of_mdiobus_link_mdiodev(bus, &phydev->mdio);
42 + mutex_lock(&__mdio_board_lock);
43 + list_for_each_entry(be, &__mdio_board_list, list)
44 + mdiobus_setup_phydev_from_boardinfo(bus, phydev,
46 + mutex_unlock(&__mdio_board_lock);
48 err = phy_device_register(phydev);
50 phy_device_free(phydev);
51 --- a/include/linux/phy.h
52 +++ b/include/linux/phy.h
53 @@ -855,6 +855,23 @@ void mdio_bus_exit(void);
55 extern struct bus_type mdio_bus_type;
57 +struct mdio_board_info {
61 + const void *platform_data;
64 +#ifdef CONFIG_MDIO_BOARDINFO
65 +int mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n);
68 +mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n)
75 * module_phy_driver() - Helper macro for registering PHY drivers
76 * @__phy_drivers: array of PHY drivers to register
77 --- a/drivers/net/phy/Kconfig
78 +++ b/drivers/net/phy/Kconfig
79 @@ -149,6 +149,10 @@ config MDIO_XGENE
81 comment "Switch configuration API + drivers"
83 +config MDIO_BOARDINFO
88 tristate "Switch configuration API"
90 --- a/drivers/net/phy/Makefile
91 +++ b/drivers/net/phy/Makefile
93 libphy-y := phy.o phy_device.o mdio_bus.o mdio_device.o
94 libphy-$(CONFIG_SWPHY) += swphy.o
96 +obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
98 obj-$(CONFIG_PHYLIB) += libphy.o
100 obj-$(CONFIG_SWCONFIG) += swconfig.o
102 +++ b/drivers/net/phy/mdio-boardinfo.c
105 + * mdio-boardinfo.c - collect pre-declarations of PHY devices
107 + * This program is free software; you can redistribute it and/or modify it
108 + * under the terms of the GNU General Public License as published by the
109 + * Free Software Foundation; either version 2 of the License, or (at your
110 + * option) any later version.
114 +#include <linux/kernel.h>
115 +#include <linux/phy.h>
116 +#include <linux/slab.h>
117 +#include <linux/export.h>
118 +#include <linux/mutex.h>
119 +#include <linux/phy.h>
121 +#include "mdio-boardinfo.h"
124 + * These symbols are exported ONLY FOR the mdio_bus component.
125 + * No other users will be supported.
128 +LIST_HEAD(__mdio_board_list);
129 +EXPORT_SYMBOL_GPL(__mdio_board_list);
131 +DEFINE_MUTEX(__mdio_board_lock);
132 +EXPORT_SYMBOL_GPL(__mdio_board_lock);
135 + * mdio_register_board_info - register PHY devices for a given board
136 + * @info: array of chip descriptors
137 + * @n: how many descriptors are provided
138 + * Context: can sleep
140 + * The board info passed can safely be __initdata ... but be careful of
141 + * any embedded pointers (platform_data, etc), they're copied as-is.
144 +mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
146 + struct mdio_board_entry *be;
149 + be = kzalloc(n * sizeof(*be), GFP_KERNEL);
153 + for (i = 0; i < n; i++, be++, info++) {
154 + memcpy(&be->board_info, info, sizeof(*info));
155 + mutex_lock(&__mdio_board_lock);
156 + list_add_tail(&be->list, &__mdio_board_list);
157 + mutex_unlock(&__mdio_board_lock);
163 +++ b/drivers/net/phy/mdio-boardinfo.h
166 + * mdio-boardinfo.h - boardinfo interface internal to the mdio_bus component
168 + * This program is free software; you can redistribute it and/or modify it
169 + * under the terms of the GNU General Public License as published by the
170 + * Free Software Foundation; either version 2 of the License, or (at your
171 + * option) any later version.
175 +#include <linux/mutex.h>
177 +struct mdio_board_entry {
178 + struct list_head list;
179 + struct mdio_board_info board_info;
182 +/* __mdio_board_lock protects __mdio_board_list
183 + * only mdio_bus components are allowed to use these symbols.
185 +extern struct mutex __mdio_board_lock;
186 +extern struct list_head __mdio_board_list;
187 --- a/drivers/net/Makefile
188 +++ b/drivers/net/Makefile
189 @@ -17,7 +17,7 @@ obj-$(CONFIG_MII) += mii.o
190 obj-$(CONFIG_MDIO) += mdio.o
191 obj-$(CONFIG_NET) += Space.o loopback.o
192 obj-$(CONFIG_NETCONSOLE) += netconsole.o
193 -obj-$(CONFIG_PHYLIB) += phy/
195 obj-$(CONFIG_RIONET) += rionet.o
196 obj-$(CONFIG_NET_TEAM) += team/
197 obj-$(CONFIG_TUN) += tun.o