brcm47xx: board detection, GPIO for Linksys E1000 V2.1
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.10 / 260-MIPS-BCM47XX-add-board-detection.patch
1 --- a/arch/mips/bcm47xx/Makefile
2 +++ b/arch/mips/bcm47xx/Makefile
3 @@ -4,4 +4,5 @@
4 #
5
6 obj-y += irq.o nvram.o prom.o serial.o setup.o time.o sprom.o
7 +obj-y += board.o
8 obj-$(CONFIG_BCM47XX_SSB) += wgt634u.o
9 --- /dev/null
10 +++ b/arch/mips/bcm47xx/board.c
11 @@ -0,0 +1,242 @@
12 +#include <linux/export.h>
13 +#include <linux/string.h>
14 +#include <bcm47xx_board.h>
15 +#include <bcm47xx_nvram.h>
16 +
17 +struct bcm47xx_board_type {
18 + const enum bcm47xx_board board;
19 + const char *name;
20 +};
21 +
22 +struct bcm47xx_board_type_list {
23 + struct bcm47xx_board_type board;
24 + const char *value1;
25 + const char *value2;
26 +};
27 +
28 +static const struct bcm47xx_board_type *bcm47xx_board = NULL;
29 +
30 +static const struct bcm47xx_board_type_list bcm47xx_board_list_model_name[] = {
31 + {{BCM47XX_BOARD_DLINK_DIR130, "D-Link DIR-130"}, "DIR-130",},
32 + {{BCM47XX_BOARD_DLINK_DIR330, "D-Link DIR-330"}, "DIR-330",},
33 + { {0}, 0},
34 +};
35 +
36 +static const struct bcm47xx_board_type_list bcm47xx_board_list_model_no[] = {
37 + {{BCM47XX_BOARD_ASUS_WL700GE, "Asus WL700"}, "WL700",},
38 + { {0}, 0},
39 +};
40 +
41 +static const struct bcm47xx_board_type_list bcm47xx_board_list_machine_name[] = {
42 + {{BCM47XX_BOARD_LINKSYS_WRTSL54GS, "Linksys WRTSL54GS"}, "WRTSL54GS",},
43 + { {0}, 0},
44 +};
45 +
46 +static const struct bcm47xx_board_type_list bcm47xx_board_list_hardware_version[] = {
47 + {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16-",},
48 + {{BCM47XX_BOARD_ASUS_WL320GE, "Asus WL320GE"}, "WL320G-",},
49 + {{BCM47XX_BOARD_ASUS_WL330GE, "Asus WL330GE"}, "WL330GE-",},
50 + {{BCM47XX_BOARD_ASUS_WL500GD, "Asus WL500GD"}, "WL500gd-",},
51 + {{BCM47XX_BOARD_ASUS_WL500GPV1, "Asus WL500GP V1"}, "WL500gp-",},
52 + {{BCM47XX_BOARD_ASUS_WL500GPV2, "Asus WL500GP V2"}, "WL500GPV2-",},
53 + {{BCM47XX_BOARD_ASUS_WL500W, "Asus WL500W"}, "WL500gW-",},
54 + {{BCM47XX_BOARD_ASUS_WL520GC, "Asus WL520GC"}, "WL520GC-",},
55 + {{BCM47XX_BOARD_ASUS_WL520GU, "Asus WL520GU"}, "WL520GU-",},
56 + {{BCM47XX_BOARD_BELKIN_F7D4301, "Belkin F7D4301"}, "F7D4301",},
57 + { {0}, 0},
58 +};
59 +
60 +static const struct bcm47xx_board_type_list bcm47xx_board_list_productid[] = {
61 + {{BCM47XX_BOARD_ASUS_RTAC66U, "Asus RT-AC66U"}, "RT-AC66U",},
62 + {{BCM47XX_BOARD_ASUS_RTN10D, "Asus RT-N10D"}, "RT-N10D",},
63 + {{BCM47XX_BOARD_ASUS_RTN10U, "Asus RT-N10U"}, "RT-N10U",},
64 + {{BCM47XX_BOARD_ASUS_RTN12, "Asus RT-N12"}, "RT-N12",},
65 + {{BCM47XX_BOARD_ASUS_RTN12B1, "Asus RT-N12B1"}, "RT-N12B1",},
66 + {{BCM47XX_BOARD_ASUS_RTN12C1, "Asus RT-N12C1"}, "RT-N12C1",},
67 + {{BCM47XX_BOARD_ASUS_RTN12D1, "Asus RT-N12D1"}, "RT-N12D1",},
68 + {{BCM47XX_BOARD_ASUS_RTN12HP, "Asus RT-N12HP"}, "RT-N12HP",},
69 + {{BCM47XX_BOARD_ASUS_RTN15U, "Asus RT-N15U"}, "RT-N15U",},
70 + {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16",},
71 + {{BCM47XX_BOARD_ASUS_RTN53, "Asus RT-N53"}, "RT-N53",},
72 + {{BCM47XX_BOARD_ASUS_RTN66U, "Asus RT-N66U"}, "RT-N66U",},
73 + {{BCM47XX_BOARD_ASUS_WL300G, "Asus WL300G"}, "WL300g",},
74 + {{BCM47XX_BOARD_ASUS_WLHDD, "Asus WLHDD"}, "WLHDD",},
75 + { {0}, 0},
76 +};
77 +
78 +static const struct bcm47xx_board_type_list bcm47xx_board_list_ModelId[] = {
79 + {{BCM47XX_BOARD_DELL_TM2300, "Dell WX-5565"}, "WX-5565",},
80 + {{BCM47XX_BOARD_MOTOROLA_WE800G, "Motorola WE800G"}, "WE800G",},
81 + {{BCM47XX_BOARD_MOTOROLA_WR850GP, "Motorola WR850GP"}, "WR850GP",},
82 + {{BCM47XX_BOARD_MOTOROLA_WR850GV2V3, "Motorola WR850G"}, "WR850G",},
83 + { {0}, 0},
84 +};
85 +
86 +static const struct bcm47xx_board_type_list bcm47xx_board_list_melco_id[] = {
87 + {{BCM47XX_BOARD_BUFFALO_WBR2_G54, "Buffalo WBR2-G54"}, "29bb0332",},
88 + {{BCM47XX_BOARD_BUFFALO_WHR2_A54G54, "Buffalo WHR2-A54G54"}, "290441dd",},
89 + {{BCM47XX_BOARD_BUFFALO_WHR_G125, "Buffalo WHR-G125"}, "32093",},
90 + {{BCM47XX_BOARD_BUFFALO_WHR_G54S, "Buffalo WHR-G54S"}, "30182",},
91 + {{BCM47XX_BOARD_BUFFALO_WHR_HP_G54, "Buffalo WHR-HP-G54"}, "30189",},
92 + {{BCM47XX_BOARD_BUFFALO_WLA2_G54L, "Buffalo WLA2-G54L"}, "29129",},
93 + {{BCM47XX_BOARD_BUFFALO_WZR_G300N, "Buffalo WZR-G300N"}, "31120",},
94 + {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54, "Buffalo WZR-RS-G54"}, "30083",},
95 + {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP, "Buffalo WZR-RS-G54HP"}, "30103",},
96 + { {0}, 0},
97 +};
98 +
99 +static const struct bcm47xx_board_type_list bcm47xx_board_list_boot_hw[] = {
100 + {{BCM47XX_BOARD_CISCO_M10V1, "Cisco M10"}, "M10", "1.0"}, /* like WRT160N v3.0 */
101 + {{BCM47XX_BOARD_CISCO_M20V1, "Cisco M20"}, "M20", "1.0"}, /* like WRT310N v2.0 */
102 + {{BCM47XX_BOARD_LINKSYS_E1000V1, "Linksys E1000 V1"}, "E100", "1.0"}, /* like WRT160N v3.0 */
103 + {{BCM47XX_BOARD_LINKSYS_E1000V2, "Linksys E1000 V2"}, "E1000", "2.0"},
104 + {{BCM47XX_BOARD_LINKSYS_E1000V21, "Linksys E1000 V2.1"}, "E1000", "2.1"},
105 + {{BCM47XX_BOARD_LINKSYS_E2000V1, "Linksys E2000 V1"}, "Linksys E2000", "1.0"},
106 + {{BCM47XX_BOARD_LINKSYS_E3000V1, "Linksys E3000 V1"}, "E300", "1.0"}, /* like WRT610N v2.0 */
107 + {{BCM47XX_BOARD_LINKSYS_E3200V1, "Linksys E3200 V1"}, "E3200", "1.0"},
108 + {{BCM47XX_BOARD_LINKSYS_E4200V1, "Linksys E4200 V1"}, "E4200", "1.0"},
109 + {{BCM47XX_BOARD_LINKSYS_WRT150NV11, "Linksys WRT150N V1.1"}, "WRT150N", "1.1"},
110 + {{BCM47XX_BOARD_LINKSYS_WRT150NV1, "Linksys WRT150N V1"}, "WRT150N", "1"},
111 + {{BCM47XX_BOARD_LINKSYS_WRT160NV1, "Linksys WRT160N V1"}, "WRT160N", "1.0"},
112 + {{BCM47XX_BOARD_LINKSYS_WRT160NV3, "Linksys WRT160N V3"}, "WRT160N", "3.0"},
113 + {{BCM47XX_BOARD_LINKSYS_WRT300NV11, "Linksys WRT300N V1.1"}, "WRT300N", "1.1"},
114 + {{BCM47XX_BOARD_LINKSYS_WRT310NV1, "Linksys WRT310N V1"}, "WRT310N", "1.0"},
115 + {{BCM47XX_BOARD_LINKSYS_WRT310NV2, "Linksys WRT310N V2"}, "WRT310N", "2.0"},
116 + {{BCM47XX_BOARD_LINKSYS_WRT54G3GV2, "Linksys WRT54G3GV2-VF"}, "WRT54G3GV2-VF", "1.0"},
117 + {{BCM47XX_BOARD_LINKSYS_WRT610NV1, "Linksys WRT610N V1"}, "WRT610N", "1.0"},
118 + {{BCM47XX_BOARD_LINKSYS_WRT610NV2, "Linksys WRT610N V2"}, "WRT610N", "2.0"},
119 + { {0}, 0},
120 +};
121 +
122 +static const struct bcm47xx_board_type_list bcm47xx_board_list_board_id[] = {
123 + {{BCM47XX_BOARD_NETGEAR_WGR614V8, "Netgear WGR614 V8"}, "U12H072T00_NETGEAR",},
124 + {{BCM47XX_BOARD_NETGEAR_WGR614V9, "Netgear WGR614 V9"}, "U12H094T00_NETGEAR",},
125 + {{BCM47XX_BOARD_NETGEAR_WNDR3300, "Netgear WNDR3300"}, "U12H093T00_NETGEAR",},
126 + {{BCM47XX_BOARD_NETGEAR_WNDR3400V1, "Netgear WNDR3400 V1"}, "U12H155T00_NETGEAR",},
127 + {{BCM47XX_BOARD_NETGEAR_WNDR3400V2, "Netgear WNDR3400 V2"}, "U12H187T00_NETGEAR",},
128 + {{BCM47XX_BOARD_NETGEAR_WNDR3400VCNA, "Netgear WNDR3400 Vcna"}, "U12H155T01_NETGEAR",},
129 + {{BCM47XX_BOARD_NETGEAR_WNDR3700V3, "Netgear WNDR3700 V3"}, "U12H194T00_NETGEAR",},
130 + {{BCM47XX_BOARD_NETGEAR_WNDR4000, "Netgear WNDR4000"}, "U12H181T00_NETGEAR",},
131 + {{BCM47XX_BOARD_NETGEAR_WNDR4500V1, "Netgear WNDR4500 V1"}, "U12H189T00_NETGEAR",},
132 + {{BCM47XX_BOARD_NETGEAR_WNDR4500V2, "Netgear WNDR4500 V2"}, "U12H224T00_NETGEAR",},
133 + {{BCM47XX_BOARD_NETGEAR_WNR2000, "Netgear WNR2000"}, "U12H114T00_NETGEAR",},
134 + {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "U12H136T99_NETGEAR",},
135 + {{BCM47XX_BOARD_NETGEAR_WNR3500U, "Netgear WNR3500U"}, "U12H136T00_NETGEAR",},
136 + {{BCM47XX_BOARD_NETGEAR_WNR3500V2, "Netgear WNR3500 V2"}, "U12H127T00_NETGEAR",},
137 + {{BCM47XX_BOARD_NETGEAR_WNR3500V2VC, "Netgear WNR3500 V2vc"}, "U12H127T70_NETGEAR",},
138 + {{BCM47XX_BOARD_NETGEAR_WNR834BV2, "Netgear WNR834B V2"}, "U12H081T00_NETGEAR",},
139 + { {0}, 0},
140 +};
141 +
142 +static const struct bcm47xx_board_type bcm47xx_board_unknown[] = {
143 + {BCM47XX_BOARD_UNKNOWN, "Unknown Board"},
144 +};
145 +
146 +static inline int startswith(char *source, char *cmp)
147 +{
148 + return !strncmp(source, cmp, strlen(cmp));
149 +}
150 +
151 +static const struct bcm47xx_board_type *bcm47xx_board_get_nvram(void)
152 +{
153 + char buf1[30];
154 + char buf2[30];
155 + const struct bcm47xx_board_type_list *e;
156 +
157 + if (bcm47xx_nvram_getenv("model_name", buf1, sizeof(buf1)) >= 0) {
158 + for (e = bcm47xx_board_list_model_name; e->value1; e++) {
159 + if (!strcmp(buf1, e->value1))
160 + return &e->board;
161 + }
162 + }
163 +
164 + if (bcm47xx_nvram_getenv("model_no", buf1, sizeof(buf1)) >= 0) {
165 + for (e = bcm47xx_board_list_model_no; e->value1; e++) {
166 + if (strstarts(buf1, e->value1))
167 + return &e->board;
168 + }
169 + }
170 +
171 + if (bcm47xx_nvram_getenv("machine_name", buf1, sizeof(buf1)) >= 0) {
172 + for (e = bcm47xx_board_list_machine_name; e->value1; e++) {
173 + if (strstarts(buf1, e->value1))
174 + return &e->board;
175 + }
176 + }
177 +
178 + if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0) {
179 + for (e = bcm47xx_board_list_hardware_version; e->value1; e++) {
180 + if (strstarts(buf1, e->value1))
181 + return &e->board;
182 + }
183 + }
184 +
185 + if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) {
186 + for (e = bcm47xx_board_list_productid; e->value1; e++) {
187 + if (!strcmp(buf1, e->value1))
188 + return &e->board;
189 + }
190 + }
191 +
192 + if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) {
193 + for (e = bcm47xx_board_list_ModelId; e->value1; e++) {
194 + if (!strcmp(buf1, e->value1))
195 + return &e->board;
196 + }
197 + }
198 +
199 + if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 ||
200 + bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) {
201 + /* buffalo hardware, check id for specific hardware matches */
202 + for (e = bcm47xx_board_list_melco_id; e->value1; e++) {
203 + if (!strcmp(buf1, e->value1))
204 + return &e->board;
205 + }
206 + }
207 +
208 + if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
209 + bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
210 + for (e = bcm47xx_board_list_boot_hw; e->value1; e++) {
211 + if (!strcmp(buf1, e->value1) && !strcmp(buf2, e->value2))
212 + return &e->board;
213 + }
214 + }
215 +
216 + if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) {
217 + for (e = bcm47xx_board_list_board_id; e->value1; e++) {
218 + if (!strcmp(buf1, e->value1))
219 + return &e->board;
220 + }
221 + }
222 + return bcm47xx_board_unknown;
223 +}
224 +
225 +static void bcm47xx_board_detect(void)
226 +{
227 + char buf[15];
228 +
229 + if (bcm47xx_board != NULL)
230 + return;
231 + /* check if the nvram is available */
232 + if (bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf)) == -ENXIO) {
233 + bcm47xx_board = bcm47xx_board_unknown;
234 + return;
235 + }
236 +
237 + bcm47xx_board = bcm47xx_board_get_nvram();
238 + pr_info("Found board: \"%s\"\n", bcm47xx_board->name);
239 +}
240 +
241 +enum bcm47xx_board bcm47xx_board_get(void)
242 +{
243 + bcm47xx_board_detect();
244 + return bcm47xx_board->board;
245 +}
246 +EXPORT_SYMBOL(bcm47xx_board_get);
247 +
248 +const char *bcm47xx_board_get_name(void)
249 +{
250 + bcm47xx_board_detect();
251 + return bcm47xx_board->name;
252 +}
253 +EXPORT_SYMBOL(bcm47xx_board_get_name);
254 --- /dev/null
255 +++ b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_board.h
256 @@ -0,0 +1,99 @@
257 +#ifndef __BCM47XX_BOARD_H
258 +#define __BCM47XX_BOARD_H
259 +
260 +enum bcm47xx_board {
261 + BCM47XX_BOARD_ASUS_RTAC66U,
262 + BCM47XX_BOARD_ASUS_RTN10D,
263 + BCM47XX_BOARD_ASUS_RTN10U,
264 + BCM47XX_BOARD_ASUS_RTN12,
265 + BCM47XX_BOARD_ASUS_RTN12B1,
266 + BCM47XX_BOARD_ASUS_RTN12C1,
267 + BCM47XX_BOARD_ASUS_RTN12D1,
268 + BCM47XX_BOARD_ASUS_RTN12HP,
269 + BCM47XX_BOARD_ASUS_RTN15U,
270 + BCM47XX_BOARD_ASUS_RTN16,
271 + BCM47XX_BOARD_ASUS_RTN53,
272 + BCM47XX_BOARD_ASUS_RTN66U,
273 + BCM47XX_BOARD_ASUS_WL300G,
274 + BCM47XX_BOARD_ASUS_WL320GE,
275 + BCM47XX_BOARD_ASUS_WL330GE,
276 + BCM47XX_BOARD_ASUS_WL500GD,
277 + BCM47XX_BOARD_ASUS_WL500GPV1,
278 + BCM47XX_BOARD_ASUS_WL500GPV2,
279 + BCM47XX_BOARD_ASUS_WL500W,
280 + BCM47XX_BOARD_ASUS_WL520GC,
281 + BCM47XX_BOARD_ASUS_WL520GU,
282 + BCM47XX_BOARD_ASUS_WL700GE,
283 + BCM47XX_BOARD_ASUS_WLHDD,
284 +
285 + BCM47XX_BOARD_BELKIN_F7D4301,
286 +
287 + BCM47XX_BOARD_BUFFALO_WBR2_G54,
288 + BCM47XX_BOARD_BUFFALO_WHR2_A54G54,
289 + BCM47XX_BOARD_BUFFALO_WHR_G125,
290 + BCM47XX_BOARD_BUFFALO_WHR_G54S,
291 + BCM47XX_BOARD_BUFFALO_WHR_HP_G54,
292 + BCM47XX_BOARD_BUFFALO_WLA2_G54L,
293 + BCM47XX_BOARD_BUFFALO_WZR_G300N,
294 + BCM47XX_BOARD_BUFFALO_WZR_RS_G54,
295 + BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP,
296 +
297 + BCM47XX_BOARD_CISCO_M10V1,
298 + BCM47XX_BOARD_CISCO_M20V1,
299 +
300 + BCM47XX_BOARD_DELL_TM2300,
301 +
302 + BCM47XX_BOARD_DLINK_DIR130,
303 + BCM47XX_BOARD_DLINK_DIR330,
304 +
305 + BCM47XX_BOARD_LINKSYS_E1000V1,
306 + BCM47XX_BOARD_LINKSYS_E1000V2,
307 + BCM47XX_BOARD_LINKSYS_E1000V21,
308 + BCM47XX_BOARD_LINKSYS_E2000V1,
309 + BCM47XX_BOARD_LINKSYS_E3000V1,
310 + BCM47XX_BOARD_LINKSYS_E3200V1,
311 + BCM47XX_BOARD_LINKSYS_E4200V1,
312 + BCM47XX_BOARD_LINKSYS_WRT150NV1,
313 + BCM47XX_BOARD_LINKSYS_WRT150NV11,
314 + BCM47XX_BOARD_LINKSYS_WRT160NV1,
315 + BCM47XX_BOARD_LINKSYS_WRT160NV3,
316 + BCM47XX_BOARD_LINKSYS_WRT300NV11,
317 + BCM47XX_BOARD_LINKSYS_WRT310NV1,
318 + BCM47XX_BOARD_LINKSYS_WRT310NV2,
319 + BCM47XX_BOARD_LINKSYS_WRT54G3GV2,
320 + BCM47XX_BOARD_LINKSYS_WRT610NV1,
321 + BCM47XX_BOARD_LINKSYS_WRT610NV2,
322 + BCM47XX_BOARD_LINKSYS_WRTSL54GS,
323 +
324 + BCM47XX_BOARD_MOTOROLA_WE800G,
325 + BCM47XX_BOARD_MOTOROLA_WR850GP,
326 + BCM47XX_BOARD_MOTOROLA_WR850GV2V3,
327 +
328 + BCM47XX_BOARD_NETGEAR_WGR614V8,
329 + BCM47XX_BOARD_NETGEAR_WGR614V9,
330 + BCM47XX_BOARD_NETGEAR_WNDR3300,
331 + BCM47XX_BOARD_NETGEAR_WNDR3400V1,
332 + BCM47XX_BOARD_NETGEAR_WNDR3400V2,
333 + BCM47XX_BOARD_NETGEAR_WNDR3400VCNA,
334 + BCM47XX_BOARD_NETGEAR_WNDR3700V3,
335 + BCM47XX_BOARD_NETGEAR_WNDR4000,
336 + BCM47XX_BOARD_NETGEAR_WNDR4500V1,
337 + BCM47XX_BOARD_NETGEAR_WNDR4500V2,
338 + BCM47XX_BOARD_NETGEAR_WNR2000,
339 + BCM47XX_BOARD_NETGEAR_WNR3500L,
340 + BCM47XX_BOARD_NETGEAR_WNR3500U,
341 + BCM47XX_BOARD_NETGEAR_WNR3500V2,
342 + BCM47XX_BOARD_NETGEAR_WNR3500V2VC,
343 + BCM47XX_BOARD_NETGEAR_WNR834BV2,
344 +
345 + /* TODO */
346 + BCM47XX_BOARD_SIMPLETECH_SIMPLESHARE,
347 +
348 + BCM47XX_BOARD_UNKNOWN,
349 + BCM47XX_BOARD_NON,
350 +};
351 +
352 +extern enum bcm47xx_board bcm47xx_board_get(void);
353 +extern const char *bcm47xx_board_get_name(void);
354 +
355 +#endif /* __BCM47XX_BOARD_H */