brcm47xx: change board detection for some Asus devices
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.8 / 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,240 @@
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_E2000V1, "Linksys E2000 V1"}, "Linksys E2000", "1.0"},
105 + {{BCM47XX_BOARD_LINKSYS_E3000V1, "Linksys E3000 V1"}, "E300", "1.0"}, /* like WRT610N v2.0 */
106 + {{BCM47XX_BOARD_LINKSYS_E3200V1, "Linksys E3200 V1"}, "E3200", "1.0"},
107 + {{BCM47XX_BOARD_LINKSYS_E4200V1, "Linksys E4200 V1"}, "E4200", "1.0"},
108 + {{BCM47XX_BOARD_LINKSYS_WRT150NV11, "Linksys WRT150N V1.1"}, "WRT150N", "1.1"},
109 + {{BCM47XX_BOARD_LINKSYS_WRT150NV1, "Linksys WRT150N V1"}, "WRT150N", "1"},
110 + {{BCM47XX_BOARD_LINKSYS_WRT160NV1, "Linksys WRT160N V1"}, "WRT160N", "1.0"},
111 + {{BCM47XX_BOARD_LINKSYS_WRT160NV3, "Linksys WRT160N V3"}, "WRT160N", "3.0"},
112 + {{BCM47XX_BOARD_LINKSYS_WRT300NV11, "Linksys WRT300N V1.1"}, "WRT300N", "1.1"},
113 + {{BCM47XX_BOARD_LINKSYS_WRT310NV2, "Linksys WRT310N V2"}, "WRT310N", "2.0"},
114 + {{BCM47XX_BOARD_LINKSYS_WRT54G3GV2, "Linksys WRT54G3GV2-VF"}, "WRT54G3GV2-VF", "1.0"},
115 + {{BCM47XX_BOARD_LINKSYS_WRT610NV1, "Linksys WRT610N V1"}, "WRT610N", "1.0"},
116 + {{BCM47XX_BOARD_LINKSYS_WRT610NV2, "Linksys WRT610N V2"}, "WRT610N", "2.0"},
117 + { {0}, 0},
118 +};
119 +
120 +static const struct bcm47xx_board_type_list bcm47xx_board_list_board_id[] = {
121 + {{BCM47XX_BOARD_NETGEAR_WGR614V8, "Netgear WGR614 V8"}, "U12H072T00_NETGEAR",},
122 + {{BCM47XX_BOARD_NETGEAR_WGR614V9, "Netgear WGR614 V9"}, "U12H094T00_NETGEAR",},
123 + {{BCM47XX_BOARD_NETGEAR_WNDR3300, "Netgear WNDR3300"}, "U12H093T00_NETGEAR",},
124 + {{BCM47XX_BOARD_NETGEAR_WNDR3400V1, "Netgear WNDR3400 V1"}, "U12H155T00_NETGEAR",},
125 + {{BCM47XX_BOARD_NETGEAR_WNDR3400V2, "Netgear WNDR3400 V2"}, "U12H187T00_NETGEAR",},
126 + {{BCM47XX_BOARD_NETGEAR_WNDR3400VCNA, "Netgear WNDR3400 Vcna"}, "U12H155T01_NETGEAR",},
127 + {{BCM47XX_BOARD_NETGEAR_WNDR3700V3, "Netgear WNDR3700 V3"}, "U12H194T00_NETGEAR",},
128 + {{BCM47XX_BOARD_NETGEAR_WNDR4000, "Netgear WNDR4000"}, "U12H181T00_NETGEAR",},
129 + {{BCM47XX_BOARD_NETGEAR_WNDR4500V1, "Netgear WNDR4500 V1"}, "U12H189T00_NETGEAR",},
130 + {{BCM47XX_BOARD_NETGEAR_WNDR4500V2, "Netgear WNDR4500 V2"}, "U12H224T00_NETGEAR",},
131 + {{BCM47XX_BOARD_NETGEAR_WNR2000, "Netgear WNR2000"}, "U12H114T00_NETGEAR",},
132 + {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "U12H136T99_NETGEAR",},
133 + {{BCM47XX_BOARD_NETGEAR_WNR3500U, "Netgear WNR3500U"}, "U12H136T00_NETGEAR",},
134 + {{BCM47XX_BOARD_NETGEAR_WNR3500V2, "Netgear WNR3500 V2"}, "U12H127T00_NETGEAR",},
135 + {{BCM47XX_BOARD_NETGEAR_WNR3500V2VC, "Netgear WNR3500 V2vc"}, "U12H127T70_NETGEAR",},
136 + {{BCM47XX_BOARD_NETGEAR_WNR834BV2, "Netgear WNR834B V2"}, "U12H081T00_NETGEAR",},
137 + { {0}, 0},
138 +};
139 +
140 +static const struct bcm47xx_board_type bcm47xx_board_unknown[] = {
141 + {BCM47XX_BOARD_UNKNOWN, "Unknown Board"},
142 +};
143 +
144 +static inline int startswith(char *source, char *cmp)
145 +{
146 + return !strncmp(source, cmp, strlen(cmp));
147 +}
148 +
149 +static const struct bcm47xx_board_type *bcm47xx_board_get_nvram(void)
150 +{
151 + char buf1[30];
152 + char buf2[30];
153 + const struct bcm47xx_board_type_list *e;
154 +
155 + if (bcm47xx_nvram_getenv("model_name", buf1, sizeof(buf1)) >= 0) {
156 + for (e = bcm47xx_board_list_model_name; e->value1; e++) {
157 + if (!strcmp(buf1, e->value1))
158 + return &e->board;
159 + }
160 + }
161 +
162 + if (bcm47xx_nvram_getenv("model_no", buf1, sizeof(buf1)) >= 0) {
163 + for (e = bcm47xx_board_list_model_no; e->value1; e++) {
164 + if (strstarts(buf1, e->value1))
165 + return &e->board;
166 + }
167 + }
168 +
169 + if (bcm47xx_nvram_getenv("machine_name", buf1, sizeof(buf1)) >= 0) {
170 + for (e = bcm47xx_board_list_machine_name; e->value1; e++) {
171 + if (strstarts(buf1, e->value1))
172 + return &e->board;
173 + }
174 + }
175 +
176 + if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0) {
177 + for (e = bcm47xx_board_list_hardware_version; e->value1; e++) {
178 + if (strstarts(buf1, e->value1))
179 + return &e->board;
180 + }
181 + }
182 +
183 + if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) {
184 + for (e = bcm47xx_board_list_productid; e->value1; e++) {
185 + if (!strcmp(buf1, e->value1))
186 + return &e->board;
187 + }
188 + }
189 +
190 + if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) {
191 + for (e = bcm47xx_board_list_ModelId; e->value1; e++) {
192 + if (!strcmp(buf1, e->value1))
193 + return &e->board;
194 + }
195 + }
196 +
197 + if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 ||
198 + bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) {
199 + /* buffalo hardware, check id for specific hardware matches */
200 + for (e = bcm47xx_board_list_melco_id; e->value1; e++) {
201 + if (!strcmp(buf1, e->value1))
202 + return &e->board;
203 + }
204 + }
205 +
206 + if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
207 + bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
208 + for (e = bcm47xx_board_list_boot_hw; e->value1; e++) {
209 + if (!strcmp(buf1, e->value1) && !strcmp(buf2, e->value2))
210 + return &e->board;
211 + }
212 + }
213 +
214 + if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) {
215 + for (e = bcm47xx_board_list_board_id; e->value1; e++) {
216 + if (!strcmp(buf1, e->value1))
217 + return &e->board;
218 + }
219 + }
220 + return bcm47xx_board_unknown;
221 +}
222 +
223 +static void bcm47xx_board_detect(void)
224 +{
225 + char buf[15];
226 +
227 + if (bcm47xx_board != NULL)
228 + return;
229 + /* check if the nvram is available */
230 + if (bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf)) == -ENXIO) {
231 + bcm47xx_board = bcm47xx_board_unknown;
232 + return;
233 + }
234 +
235 + bcm47xx_board = bcm47xx_board_get_nvram();
236 + pr_info("Found board: \"%s\"\n", bcm47xx_board->name);
237 +}
238 +
239 +enum bcm47xx_board bcm47xx_board_get(void)
240 +{
241 + bcm47xx_board_detect();
242 + return bcm47xx_board->board;
243 +}
244 +EXPORT_SYMBOL(bcm47xx_board_get);
245 +
246 +const char *bcm47xx_board_get_name(void)
247 +{
248 + bcm47xx_board_detect();
249 + return bcm47xx_board->name;
250 +}
251 +EXPORT_SYMBOL(bcm47xx_board_get_name);
252 --- /dev/null
253 +++ b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_board.h
254 @@ -0,0 +1,97 @@
255 +#ifndef __BCM47XX_BOARD_H
256 +#define __BCM47XX_BOARD_H
257 +
258 +enum bcm47xx_board {
259 + BCM47XX_BOARD_ASUS_RTAC66U,
260 + BCM47XX_BOARD_ASUS_RTN10D,
261 + BCM47XX_BOARD_ASUS_RTN10U,
262 + BCM47XX_BOARD_ASUS_RTN12,
263 + BCM47XX_BOARD_ASUS_RTN12B1,
264 + BCM47XX_BOARD_ASUS_RTN12C1,
265 + BCM47XX_BOARD_ASUS_RTN12D1,
266 + BCM47XX_BOARD_ASUS_RTN12HP,
267 + BCM47XX_BOARD_ASUS_RTN15U,
268 + BCM47XX_BOARD_ASUS_RTN16,
269 + BCM47XX_BOARD_ASUS_RTN53,
270 + BCM47XX_BOARD_ASUS_RTN66U,
271 + BCM47XX_BOARD_ASUS_WL300G,
272 + BCM47XX_BOARD_ASUS_WL320GE,
273 + BCM47XX_BOARD_ASUS_WL330GE,
274 + BCM47XX_BOARD_ASUS_WL500GD,
275 + BCM47XX_BOARD_ASUS_WL500GPV1,
276 + BCM47XX_BOARD_ASUS_WL500GPV2,
277 + BCM47XX_BOARD_ASUS_WL500W,
278 + BCM47XX_BOARD_ASUS_WL520GC,
279 + BCM47XX_BOARD_ASUS_WL520GU,
280 + BCM47XX_BOARD_ASUS_WL700GE,
281 + BCM47XX_BOARD_ASUS_WLHDD,
282 +
283 + BCM47XX_BOARD_BELKIN_F7D4301,
284 +
285 + BCM47XX_BOARD_BUFFALO_WBR2_G54,
286 + BCM47XX_BOARD_BUFFALO_WHR2_A54G54,
287 + BCM47XX_BOARD_BUFFALO_WHR_G125,
288 + BCM47XX_BOARD_BUFFALO_WHR_G54S,
289 + BCM47XX_BOARD_BUFFALO_WHR_HP_G54,
290 + BCM47XX_BOARD_BUFFALO_WLA2_G54L,
291 + BCM47XX_BOARD_BUFFALO_WZR_G300N,
292 + BCM47XX_BOARD_BUFFALO_WZR_RS_G54,
293 + BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP,
294 +
295 + BCM47XX_BOARD_CISCO_M10V1,
296 + BCM47XX_BOARD_CISCO_M20V1,
297 +
298 + BCM47XX_BOARD_DELL_TM2300,
299 +
300 + BCM47XX_BOARD_DLINK_DIR130,
301 + BCM47XX_BOARD_DLINK_DIR330,
302 +
303 + BCM47XX_BOARD_LINKSYS_E1000V1,
304 + BCM47XX_BOARD_LINKSYS_E1000V2,
305 + BCM47XX_BOARD_LINKSYS_E2000V1,
306 + BCM47XX_BOARD_LINKSYS_E3000V1,
307 + BCM47XX_BOARD_LINKSYS_E3200V1,
308 + BCM47XX_BOARD_LINKSYS_E4200V1,
309 + BCM47XX_BOARD_LINKSYS_WRT150NV1,
310 + BCM47XX_BOARD_LINKSYS_WRT150NV11,
311 + BCM47XX_BOARD_LINKSYS_WRT160NV1,
312 + BCM47XX_BOARD_LINKSYS_WRT160NV3,
313 + BCM47XX_BOARD_LINKSYS_WRT300NV11,
314 + BCM47XX_BOARD_LINKSYS_WRT310NV2,
315 + BCM47XX_BOARD_LINKSYS_WRT54G3GV2,
316 + BCM47XX_BOARD_LINKSYS_WRT610NV1,
317 + BCM47XX_BOARD_LINKSYS_WRT610NV2,
318 + BCM47XX_BOARD_LINKSYS_WRTSL54GS,
319 +
320 + BCM47XX_BOARD_MOTOROLA_WE800G,
321 + BCM47XX_BOARD_MOTOROLA_WR850GP,
322 + BCM47XX_BOARD_MOTOROLA_WR850GV2V3,
323 +
324 + BCM47XX_BOARD_NETGEAR_WGR614V8,
325 + BCM47XX_BOARD_NETGEAR_WGR614V9,
326 + BCM47XX_BOARD_NETGEAR_WNDR3300,
327 + BCM47XX_BOARD_NETGEAR_WNDR3400V1,
328 + BCM47XX_BOARD_NETGEAR_WNDR3400V2,
329 + BCM47XX_BOARD_NETGEAR_WNDR3400VCNA,
330 + BCM47XX_BOARD_NETGEAR_WNDR3700V3,
331 + BCM47XX_BOARD_NETGEAR_WNDR4000,
332 + BCM47XX_BOARD_NETGEAR_WNDR4500V1,
333 + BCM47XX_BOARD_NETGEAR_WNDR4500V2,
334 + BCM47XX_BOARD_NETGEAR_WNR2000,
335 + BCM47XX_BOARD_NETGEAR_WNR3500L,
336 + BCM47XX_BOARD_NETGEAR_WNR3500U,
337 + BCM47XX_BOARD_NETGEAR_WNR3500V2,
338 + BCM47XX_BOARD_NETGEAR_WNR3500V2VC,
339 + BCM47XX_BOARD_NETGEAR_WNR834BV2,
340 +
341 + /* TODO */
342 + BCM47XX_BOARD_SIMPLETECH_SIMPLESHARE,
343 +
344 + BCM47XX_BOARD_UNKNOWN,
345 + BCM47XX_BOARD_NON,
346 +};
347 +
348 +extern enum bcm47xx_board bcm47xx_board_get(void);
349 +extern const char *bcm47xx_board_get_name(void);
350 +
351 +#endif /* __BCM47XX_BOARD_H */