1 --- a/drivers/net/phy/mdio_bus.c
2 +++ b/drivers/net/phy/mdio_bus.c
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 @@ -335,9 +337,21 @@ 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->addr)
24 + phydev->dev.platform_data = (void *) bi->platform_data;
27 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
29 struct phy_device *phydev;
30 + struct mdio_board_entry *be;
33 phydev = get_phy_device(bus, addr, false);
34 @@ -350,6 +364,12 @@ struct phy_device *mdiobus_scan(struct m
36 of_mdiobus_link_phydev(bus, phydev);
38 + mutex_lock(&__mdio_board_lock);
39 + list_for_each_entry(be, &__mdio_board_list, list)
40 + mdiobus_setup_phydev_from_boardinfo(bus, phydev,
42 + mutex_unlock(&__mdio_board_lock);
44 err = phy_device_register(phydev);
46 phy_device_free(phydev);
47 --- a/include/linux/phy.h
48 +++ b/include/linux/phy.h
49 @@ -785,4 +785,22 @@ int __init mdio_bus_init(void);
50 void mdio_bus_exit(void);
52 extern struct bus_type mdio_bus_type;
54 +struct mdio_board_info {
58 + const void *platform_data;
61 +#ifdef CONFIG_MDIO_BOARDINFO
62 +int mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n);
65 +mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n)
72 --- a/drivers/net/phy/Kconfig
73 +++ b/drivers/net/phy/Kconfig
74 @@ -12,6 +12,10 @@ menuconfig PHYLIB
78 +config MDIO_BOARDINFO
83 tristate "Switch configuration API"
85 --- a/drivers/net/phy/Makefile
86 +++ b/drivers/net/phy/Makefile
89 libphy-objs := phy.o phy_device.o mdio_bus.o
91 +obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
93 obj-$(CONFIG_PHYLIB) += libphy.o
94 obj-$(CONFIG_SWCONFIG) += swconfig.o
95 obj-$(CONFIG_MARVELL_PHY) += marvell.o
97 +++ b/drivers/net/phy/mdio-boardinfo.c
100 + * mdio-boardinfo.c - collect pre-declarations of PHY devices
102 + * This program is free software; you can redistribute it and/or modify it
103 + * under the terms of the GNU General Public License as published by the
104 + * Free Software Foundation; either version 2 of the License, or (at your
105 + * option) any later version.
109 +#include <linux/kernel.h>
110 +#include <linux/phy.h>
111 +#include <linux/slab.h>
112 +#include <linux/export.h>
113 +#include <linux/mutex.h>
114 +#include <linux/phy.h>
116 +#include "mdio-boardinfo.h"
119 + * These symbols are exported ONLY FOR the mdio_bus component.
120 + * No other users will be supported.
123 +LIST_HEAD(__mdio_board_list);
124 +EXPORT_SYMBOL_GPL(__mdio_board_list);
126 +DEFINE_MUTEX(__mdio_board_lock);
127 +EXPORT_SYMBOL_GPL(__mdio_board_lock);
130 + * mdio_register_board_info - register PHY devices for a given board
131 + * @info: array of chip descriptors
132 + * @n: how many descriptors are provided
133 + * Context: can sleep
135 + * The board info passed can safely be __initdata ... but be careful of
136 + * any embedded pointers (platform_data, etc), they're copied as-is.
139 +mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
141 + struct mdio_board_entry *be;
144 + be = kzalloc(n * sizeof(*be), GFP_KERNEL);
148 + for (i = 0; i < n; i++, be++, info++) {
149 + memcpy(&be->board_info, info, sizeof(*info));
150 + mutex_lock(&__mdio_board_lock);
151 + list_add_tail(&be->list, &__mdio_board_list);
152 + mutex_unlock(&__mdio_board_lock);
158 +++ b/drivers/net/phy/mdio-boardinfo.h
161 + * mdio-boardinfo.h - boardinfo interface internal to the mdio_bus component
163 + * This program is free software; you can redistribute it and/or modify it
164 + * under the terms of the GNU General Public License as published by the
165 + * Free Software Foundation; either version 2 of the License, or (at your
166 + * option) any later version.
170 +#include <linux/mutex.h>
172 +struct mdio_board_entry {
173 + struct list_head list;
174 + struct mdio_board_info board_info;
177 +/* __mdio_board_lock protects __mdio_board_list
178 + * only mdio_bus components are allowed to use these symbols.
180 +extern struct mutex __mdio_board_lock;
181 +extern struct list_head __mdio_board_list;
182 --- a/drivers/net/Makefile
183 +++ b/drivers/net/Makefile
184 @@ -15,7 +15,7 @@ obj-$(CONFIG_MII) += mii.o
185 obj-$(CONFIG_MDIO) += mdio.o
186 obj-$(CONFIG_NET) += Space.o loopback.o
187 obj-$(CONFIG_NETCONSOLE) += netconsole.o
188 -obj-$(CONFIG_PHYLIB) += phy/
190 obj-$(CONFIG_RIONET) += rionet.o
191 obj-$(CONFIG_NET_TEAM) += team/
192 obj-$(CONFIG_TUN) += tun.o