kernel/3.1[02]: move MTD root device setup code to mtdcore
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.10 / 710-phy-add-mdio_register_board_info.patch
1 --- a/drivers/net/phy/mdio_bus.c
2 +++ b/drivers/net/phy/mdio_bus.c
3 @@ -41,6 +41,8 @@
4 #include <asm/irq.h>
5 #include <asm/uaccess.h>
6
7 +#include "mdio-boardinfo.h"
8 +
9 /**
10 * mdiobus_alloc_size - allocate a mii_bus structure
11 * @size: extra amount of memory to allocate for private storage.
12 @@ -229,15 +231,33 @@ void mdiobus_free(struct mii_bus *bus)
13 }
14 EXPORT_SYMBOL(mdiobus_free);
15
16 +static void mdiobus_setup_phydev_from_boardinfo(struct mii_bus *bus,
17 + struct phy_device *phydev,
18 + struct mdio_board_info *bi)
19 +{
20 + if (strcmp(bus->id, bi->bus_id) ||
21 + bi->phy_addr != phydev->addr)
22 + return;
23 +
24 + phydev->dev.platform_data = (void *) bi->platform_data;
25 +}
26 +
27 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
28 {
29 struct phy_device *phydev;
30 + struct mdio_board_entry *be;
31 int err;
32
33 phydev = get_phy_device(bus, addr, false);
34 if (IS_ERR(phydev) || phydev == NULL)
35 return phydev;
36
37 + mutex_lock(&__mdio_board_lock);
38 + list_for_each_entry(be, &__mdio_board_list, list)
39 + mdiobus_setup_phydev_from_boardinfo(bus, phydev,
40 + &be->board_info);
41 + mutex_unlock(&__mdio_board_lock);
42 +
43 err = phy_device_register(phydev);
44 if (err) {
45 phy_device_free(phydev);
46 --- a/include/linux/phy.h
47 +++ b/include/linux/phy.h
48 @@ -591,4 +591,22 @@ int __init mdio_bus_init(void);
49 void mdio_bus_exit(void);
50
51 extern struct bus_type mdio_bus_type;
52 +
53 +struct mdio_board_info {
54 + const char *bus_id;
55 + int phy_addr;
56 +
57 + const void *platform_data;
58 +};
59 +
60 +#ifdef CONFIG_MDIO_BOARDINFO
61 +int mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n);
62 +#else
63 +static inline int
64 +mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n)
65 +{
66 + return 0;
67 +}
68 +#endif
69 +
70 #endif /* __PHY_H */
71 --- a/drivers/net/phy/Kconfig
72 +++ b/drivers/net/phy/Kconfig
73 @@ -12,6 +12,10 @@ menuconfig PHYLIB
74
75 if PHYLIB
76
77 +config MDIO_BOARDINFO
78 + bool
79 + default y
80 +
81 config SWCONFIG
82 tristate "Switch configuration API"
83 ---help---
84 --- a/drivers/net/phy/Makefile
85 +++ b/drivers/net/phy/Makefile
86 @@ -2,6 +2,8 @@
87
88 libphy-objs := phy.o phy_device.o mdio_bus.o
89
90 +obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
91 +
92 obj-$(CONFIG_PHYLIB) += libphy.o
93 obj-$(CONFIG_SWCONFIG) += swconfig.o
94 obj-$(CONFIG_MARVELL_PHY) += marvell.o
95 --- /dev/null
96 +++ b/drivers/net/phy/mdio-boardinfo.c
97 @@ -0,0 +1,58 @@
98 +/*
99 + * mdio-boardinfo.c - collect pre-declarations of PHY devices
100 + *
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.
105 + *
106 + */
107 +
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>
114 +
115 +#include "mdio-boardinfo.h"
116 +
117 +/*
118 + * These symbols are exported ONLY FOR the mdio_bus component.
119 + * No other users will be supported.
120 + */
121 +
122 +LIST_HEAD(__mdio_board_list);
123 +EXPORT_SYMBOL_GPL(__mdio_board_list);
124 +
125 +DEFINE_MUTEX(__mdio_board_lock);
126 +EXPORT_SYMBOL_GPL(__mdio_board_lock);
127 +
128 +/**
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
133 + *
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.
136 + */
137 +int __init
138 +mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n)
139 +{
140 + struct mdio_board_entry *be;
141 + int i;
142 +
143 + be = kzalloc(n * sizeof(*be), GFP_KERNEL);
144 + if (!be)
145 + return -ENOMEM;
146 +
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);
152 + }
153 +
154 + return 0;
155 +}
156 --- /dev/null
157 +++ b/drivers/net/phy/mdio-boardinfo.h
158 @@ -0,0 +1,22 @@
159 +/*
160 + * mdio-boardinfo.h - boardinfo interface internal to the mdio_bus component
161 + *
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.
166 + *
167 + */
168 +
169 +#include <linux/mutex.h>
170 +
171 +struct mdio_board_entry {
172 + struct list_head list;
173 + struct mdio_board_info board_info;
174 +};
175 +
176 +/* __mdio_board_lock protects __mdio_board_list
177 + * only mdio_bus components are allowed to use these symbols.
178 + */
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/
188 +obj-y += phy/
189 obj-$(CONFIG_RIONET) += rionet.o
190 obj-$(CONFIG_NET_TEAM) += team/
191 obj-$(CONFIG_TUN) += tun.o