1 --- a/drivers/net/phy/mdio_bus.c
2 +++ b/drivers/net/phy/mdio_bus.c
5 #include <asm/uaccess.h>
7 +#include "mdio-boardinfo.h"
10 * mdiobus_alloc - allocate a mii_bus structure
12 @@ -179,15 +181,33 @@ 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);
34 if (IS_ERR(phydev) || phydev == NULL)
37 + mutex_lock(&__mdio_board_lock);
38 + list_for_each_entry(be, &__mdio_board_list, list)
39 + mdiobus_setup_phydev_from_boardinfo(bus, phydev,
41 + mutex_unlock(&__mdio_board_lock);
43 err = phy_device_register(phydev);
45 phy_device_free(phydev);
46 --- a/include/linux/phy.h
47 +++ b/include/linux/phy.h
48 @@ -538,4 +538,22 @@ int __init mdio_bus_init(void);
49 void mdio_bus_exit(void);
51 extern struct bus_type mdio_bus_type;
53 +struct mdio_board_info {
57 + const void *platform_data;
60 +#ifdef CONFIG_MDIO_BOARDINFO
61 +int mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n);
64 +mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n)
71 --- a/drivers/net/phy/Kconfig
72 +++ b/drivers/net/phy/Kconfig
73 @@ -13,6 +13,10 @@ menuconfig PHYLIB
77 +config MDIO_BOARDINFO
82 tristate "Switch configuration API"
84 --- a/drivers/net/phy/Makefile
85 +++ b/drivers/net/phy/Makefile
88 libphy-objs := phy.o phy_device.o mdio_bus.o
90 +obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
92 obj-$(CONFIG_PHYLIB) += libphy.o
93 obj-$(CONFIG_SWCONFIG) += swconfig.o
94 obj-$(CONFIG_MARVELL_PHY) += marvell.o
96 +++ b/drivers/net/phy/mdio-boardinfo.c
99 + * mdio-boardinfo.c - collect pre-declarations of PHY devices
101 + * This program is free software; you can redistribute it and/or modify it
102 + * under the terms of the GNU General Public License as published by the
103 + * Free Software Foundation; either version 2 of the License, or (at your
104 + * option) any later version.
108 +#include <linux/kernel.h>
109 +#include <linux/phy.h>
110 +#include <linux/slab.h>
111 +#include <linux/export.h>
112 +#include <linux/mutex.h>
113 +#include <linux/phy.h>
115 +#include "mdio-boardinfo.h"
118 + * These symbols are exported ONLY FOR the mdio_bus component.
119 + * No other users will be supported.
122 +LIST_HEAD(__mdio_board_list);
123 +EXPORT_SYMBOL_GPL(__mdio_board_list);
125 +DEFINE_MUTEX(__mdio_board_lock);
126 +EXPORT_SYMBOL_GPL(__mdio_board_lock);
129 + * mdio_register_board_info - register PHY devices for a given board
130 + * @info: array of chip descriptors
131 + * @n: how many descriptors are provided
132 + * Context: can sleep
134 + * The board info passed can safely be __initdata ... but be careful of
135 + * any embedded pointers (platform_data, etc), they're copied as-is.
138 +mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
140 + struct mdio_board_entry *be;
143 + be = kzalloc(n * sizeof(*be), GFP_KERNEL);
147 + for (i = 0; i < n; i++, be++, info++) {
148 + memcpy(&be->board_info, info, sizeof(*info));
149 + mutex_lock(&__mdio_board_lock);
150 + list_add_tail(&be->list, &__mdio_board_list);
151 + mutex_unlock(&__mdio_board_lock);
157 +++ b/drivers/net/phy/mdio-boardinfo.h
160 + * mdio-boardinfo.h - boardinfo interface internal to the mdio_bus component
162 + * This program is free software; you can redistribute it and/or modify it
163 + * under the terms of the GNU General Public License as published by the
164 + * Free Software Foundation; either version 2 of the License, or (at your
165 + * option) any later version.
169 +#include <linux/mutex.h>
171 +struct mdio_board_entry {
172 + struct list_head list;
173 + struct mdio_board_info board_info;
176 +/* __mdio_board_lock protects __mdio_board_list
177 + * only mdio_bus components are allowed to use these symbols.
179 +extern struct mutex __mdio_board_lock;
180 +extern struct list_head __mdio_board_list;
181 --- a/drivers/net/Makefile
182 +++ b/drivers/net/Makefile
183 @@ -15,7 +15,7 @@ obj-$(CONFIG_MII) += mii.o
184 obj-$(CONFIG_MDIO) += mdio.o
185 obj-$(CONFIG_NET) += Space.o loopback.o
186 obj-$(CONFIG_NETCONSOLE) += netconsole.o
187 -obj-$(CONFIG_PHYLIB) += phy/
189 obj-$(CONFIG_RIONET) += rionet.o
190 obj-$(CONFIG_TUN) += tun.o
191 obj-$(CONFIG_VETH) += veth.o