blob: 87dc76a1f941cfdbba3620e37089471c00f1faf7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Markos Chandras4890e2e2014-02-19 10:17:18 +00002#include <linux/errno.h>
Hauke Mehrtens786c4972013-09-18 13:29:57 +02003#include <linux/export.h>
4#include <linux/string.h>
Rafał Miłecki138173d2014-12-01 07:58:18 +01005#include <bcm47xx.h>
Hauke Mehrtens786c4972013-09-18 13:29:57 +02006#include <bcm47xx_board.h>
Hauke Mehrtens786c4972013-09-18 13:29:57 +02007
8struct bcm47xx_board_type {
9 const enum bcm47xx_board board;
10 const char *name;
11};
12
13struct bcm47xx_board_type_list1 {
14 struct bcm47xx_board_type board;
15 const char *value1;
16};
17
18struct bcm47xx_board_type_list2 {
19 struct bcm47xx_board_type board;
20 const char *value1;
21 const char *value2;
22};
23
24struct bcm47xx_board_type_list3 {
25 struct bcm47xx_board_type board;
26 const char *value1;
27 const char *value2;
28 const char *value3;
29};
30
31struct bcm47xx_board_store {
32 enum bcm47xx_board board;
33 char name[BCM47XX_BOARD_MAX_NAME];
34};
35
36/* model_name */
37static const
38struct bcm47xx_board_type_list1 bcm47xx_board_list_model_name[] __initconst = {
39 {{BCM47XX_BOARD_DLINK_DIR130, "D-Link DIR-130"}, "DIR-130"},
40 {{BCM47XX_BOARD_DLINK_DIR330, "D-Link DIR-330"}, "DIR-330"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +010041 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020042};
43
Hauke Mehrtens786c4972013-09-18 13:29:57 +020044/* hardware_version */
45static const
46struct bcm47xx_board_type_list1 bcm47xx_board_list_hardware_version[] __initconst = {
Hauke Mehrtensa2ffb562014-01-03 20:41:58 +010047 {{BCM47XX_BOARD_ASUS_RTN10U, "Asus RT-N10U"}, "RTN10U"},
Rafał Miłecki9194b342014-07-17 23:24:30 +020048 {{BCM47XX_BOARD_ASUS_RTN10D, "Asus RT-N10D"}, "RTN10D"},
Hauke Mehrtensa2ffb562014-01-03 20:41:58 +010049 {{BCM47XX_BOARD_ASUS_RTN12, "Asus RT-N12"}, "RT-N12"},
50 {{BCM47XX_BOARD_ASUS_RTN12B1, "Asus RT-N12B1"}, "RTN12B1"},
51 {{BCM47XX_BOARD_ASUS_RTN12C1, "Asus RT-N12C1"}, "RTN12C1"},
52 {{BCM47XX_BOARD_ASUS_RTN12D1, "Asus RT-N12D1"}, "RTN12D1"},
53 {{BCM47XX_BOARD_ASUS_RTN12HP, "Asus RT-N12HP"}, "RTN12HP"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020054 {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16-"},
55 {{BCM47XX_BOARD_ASUS_WL320GE, "Asus WL320GE"}, "WL320G-"},
56 {{BCM47XX_BOARD_ASUS_WL330GE, "Asus WL330GE"}, "WL330GE-"},
57 {{BCM47XX_BOARD_ASUS_WL500GD, "Asus WL500GD"}, "WL500gd-"},
58 {{BCM47XX_BOARD_ASUS_WL500GPV1, "Asus WL500GP V1"}, "WL500gp-"},
59 {{BCM47XX_BOARD_ASUS_WL500GPV2, "Asus WL500GP V2"}, "WL500GPV2-"},
60 {{BCM47XX_BOARD_ASUS_WL500W, "Asus WL500W"}, "WL500gW-"},
61 {{BCM47XX_BOARD_ASUS_WL520GC, "Asus WL520GC"}, "WL520GC-"},
62 {{BCM47XX_BOARD_ASUS_WL520GU, "Asus WL520GU"}, "WL520GU-"},
Cody P Schafer0dae62e2014-03-02 17:49:29 +010063 {{BCM47XX_BOARD_BELKIN_F7D3301, "Belkin F7D3301"}, "F7D3301"},
64 {{BCM47XX_BOARD_BELKIN_F7D3302, "Belkin F7D3302"}, "F7D3302"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020065 {{BCM47XX_BOARD_BELKIN_F7D4301, "Belkin F7D4301"}, "F7D4301"},
Cody P Schafer0dae62e2014-03-02 17:49:29 +010066 {{BCM47XX_BOARD_BELKIN_F7D4302, "Belkin F7D4302"}, "F7D4302"},
67 {{BCM47XX_BOARD_BELKIN_F7D4401, "Belkin F7D4401"}, "F7D4401"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +010068 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020069};
70
Hauke Mehrtens250dc032014-07-29 00:12:09 +020071/* hardware_version, boardnum */
72static const
73struct bcm47xx_board_type_list2 bcm47xx_board_list_hw_version_num[] __initconst = {
74 {{BCM47XX_BOARD_MICROSOFT_MN700, "Microsoft MN-700"}, "WL500-", "mn700"},
75 {{BCM47XX_BOARD_ASUS_WL500G, "Asus WL500G"}, "WL500-", "asusX"},
76 { {0}, NULL},
77};
78
Hauke Mehrtens786c4972013-09-18 13:29:57 +020079/* productid */
80static const
81struct bcm47xx_board_type_list1 bcm47xx_board_list_productid[] __initconst = {
82 {{BCM47XX_BOARD_ASUS_RTAC66U, "Asus RT-AC66U"}, "RT-AC66U"},
83 {{BCM47XX_BOARD_ASUS_RTN10, "Asus RT-N10"}, "RT-N10"},
84 {{BCM47XX_BOARD_ASUS_RTN10D, "Asus RT-N10D"}, "RT-N10D"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020085 {{BCM47XX_BOARD_ASUS_RTN15U, "Asus RT-N15U"}, "RT-N15U"},
86 {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16"},
87 {{BCM47XX_BOARD_ASUS_RTN53, "Asus RT-N53"}, "RT-N53"},
88 {{BCM47XX_BOARD_ASUS_RTN66U, "Asus RT-N66U"}, "RT-N66U"},
89 {{BCM47XX_BOARD_ASUS_WL300G, "Asus WL300G"}, "WL300g"},
90 {{BCM47XX_BOARD_ASUS_WLHDD, "Asus WLHDD"}, "WLHDD"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +010091 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020092};
93
94/* ModelId */
95static const
96struct bcm47xx_board_type_list1 bcm47xx_board_list_ModelId[] __initconst = {
Rafał Miłecki9194b342014-07-17 23:24:30 +020097 {{BCM47XX_BOARD_DELL_TM2300, "Dell TrueMobile 2300"}, "WX-5565"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +020098 {{BCM47XX_BOARD_MOTOROLA_WE800G, "Motorola WE800G"}, "WE800G"},
99 {{BCM47XX_BOARD_MOTOROLA_WR850GP, "Motorola WR850GP"}, "WR850GP"},
100 {{BCM47XX_BOARD_MOTOROLA_WR850GV2V3, "Motorola WR850G"}, "WR850G"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +0100101 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200102};
103
104/* melco_id or buf1falo_id */
105static const
106struct bcm47xx_board_type_list1 bcm47xx_board_list_melco_id[] __initconst = {
107 {{BCM47XX_BOARD_BUFFALO_WBR2_G54, "Buffalo WBR2-G54"}, "29bb0332"},
108 {{BCM47XX_BOARD_BUFFALO_WHR2_A54G54, "Buffalo WHR2-A54G54"}, "290441dd"},
109 {{BCM47XX_BOARD_BUFFALO_WHR_G125, "Buffalo WHR-G125"}, "32093"},
110 {{BCM47XX_BOARD_BUFFALO_WHR_G54S, "Buffalo WHR-G54S"}, "30182"},
111 {{BCM47XX_BOARD_BUFFALO_WHR_HP_G54, "Buffalo WHR-HP-G54"}, "30189"},
112 {{BCM47XX_BOARD_BUFFALO_WLA2_G54L, "Buffalo WLA2-G54L"}, "29129"},
113 {{BCM47XX_BOARD_BUFFALO_WZR_G300N, "Buffalo WZR-G300N"}, "31120"},
114 {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54, "Buffalo WZR-RS-G54"}, "30083"},
115 {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP, "Buffalo WZR-RS-G54HP"}, "30103"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +0100116 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200117};
118
119/* boot_hw_model, boot_hw_ver */
120static const
121struct bcm47xx_board_type_list2 bcm47xx_board_list_boot_hw[] __initconst = {
122 /* like WRT160N v3.0 */
123 {{BCM47XX_BOARD_CISCO_M10V1, "Cisco M10"}, "M10", "1.0"},
124 /* like WRT310N v2.0 */
125 {{BCM47XX_BOARD_CISCO_M20V1, "Cisco M20"}, "M20", "1.0"},
126 {{BCM47XX_BOARD_LINKSYS_E900V1, "Linksys E900 V1"}, "E900", "1.0"},
127 /* like WRT160N v3.0 */
128 {{BCM47XX_BOARD_LINKSYS_E1000V1, "Linksys E1000 V1"}, "E100", "1.0"},
129 {{BCM47XX_BOARD_LINKSYS_E1000V2, "Linksys E1000 V2"}, "E1000", "2.0"},
130 {{BCM47XX_BOARD_LINKSYS_E1000V21, "Linksys E1000 V2.1"}, "E1000", "2.1"},
131 {{BCM47XX_BOARD_LINKSYS_E1200V2, "Linksys E1200 V2"}, "E1200", "2.0"},
132 {{BCM47XX_BOARD_LINKSYS_E2000V1, "Linksys E2000 V1"}, "Linksys E2000", "1.0"},
133 /* like WRT610N v2.0 */
134 {{BCM47XX_BOARD_LINKSYS_E3000V1, "Linksys E3000 V1"}, "E300", "1.0"},
135 {{BCM47XX_BOARD_LINKSYS_E3200V1, "Linksys E3200 V1"}, "E3200", "1.0"},
136 {{BCM47XX_BOARD_LINKSYS_E4200V1, "Linksys E4200 V1"}, "E4200", "1.0"},
137 {{BCM47XX_BOARD_LINKSYS_WRT150NV11, "Linksys WRT150N V1.1"}, "WRT150N", "1.1"},
138 {{BCM47XX_BOARD_LINKSYS_WRT150NV1, "Linksys WRT150N V1"}, "WRT150N", "1"},
139 {{BCM47XX_BOARD_LINKSYS_WRT160NV1, "Linksys WRT160N V1"}, "WRT160N", "1.0"},
140 {{BCM47XX_BOARD_LINKSYS_WRT160NV3, "Linksys WRT160N V3"}, "WRT160N", "3.0"},
141 {{BCM47XX_BOARD_LINKSYS_WRT300NV11, "Linksys WRT300N V1.1"}, "WRT300N", "1.1"},
142 {{BCM47XX_BOARD_LINKSYS_WRT310NV1, "Linksys WRT310N V1"}, "WRT310N", "1.0"},
143 {{BCM47XX_BOARD_LINKSYS_WRT310NV2, "Linksys WRT310N V2"}, "WRT310N", "2.0"},
Florian Fainelli3829e4f2022-01-06 19:51:38 -0800144 {{BCM47XX_BOARD_LINKSYS_WRT320N_V1, "Linksys WRT320N V1"}, "WRT320N", "1.0"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200145 {{BCM47XX_BOARD_LINKSYS_WRT54G3GV2, "Linksys WRT54G3GV2-VF"}, "WRT54G3GV2-VF", "1.0"},
146 {{BCM47XX_BOARD_LINKSYS_WRT610NV1, "Linksys WRT610N V1"}, "WRT610N", "1.0"},
147 {{BCM47XX_BOARD_LINKSYS_WRT610NV2, "Linksys WRT610N V2"}, "WRT610N", "2.0"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +0100148 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200149};
150
151/* board_id */
152static const
153struct bcm47xx_board_type_list1 bcm47xx_board_list_board_id[] __initconst = {
Dan Haabe7093052017-01-23 12:50:38 -0700154 {{BCM47XX_BOARD_LUXUL_ABR_4400_V1, "Luxul ABR-4400 V1"}, "luxul_abr4400_v1"},
155 {{BCM47XX_BOARD_LUXUL_XAP_310_V1, "Luxul XAP-310 V1"}, "luxul_xap310_v1"},
156 {{BCM47XX_BOARD_LUXUL_XAP_1210_V1, "Luxul XAP-1210 V1"}, "luxul_xap1210_v1"},
157 {{BCM47XX_BOARD_LUXUL_XAP_1230_V1, "Luxul XAP-1230 V1"}, "luxul_xap1230_v1"},
158 {{BCM47XX_BOARD_LUXUL_XAP_1240_V1, "Luxul XAP-1240 V1"}, "luxul_xap1240_v1"},
159 {{BCM47XX_BOARD_LUXUL_XAP_1500_V1, "Luxul XAP-1500 V1"}, "luxul_xap1500_v1"},
160 {{BCM47XX_BOARD_LUXUL_XBR_4400_V1, "Luxul XBR-4400 V1"}, "luxul_xbr4400_v1"},
161 {{BCM47XX_BOARD_LUXUL_XVW_P30_V1, "Luxul XVW-P30 V1"}, "luxul_xvwp30_v1"},
162 {{BCM47XX_BOARD_LUXUL_XWR_600_V1, "Luxul XWR-600 V1"}, "luxul_xwr600_v1"},
Dan Haab24f29702015-04-22 13:58:33 -0600163 {{BCM47XX_BOARD_LUXUL_XWR_1750_V1, "Luxul XWR-1750 V1"}, "luxul_xwr1750_v1"},
Edward Matijević42374b92019-06-17 00:26:46 -0500164 {{BCM47XX_BOARD_NETGEAR_R6200_V1, "Netgear R6200 V1"}, "U12H192T00_NETGEAR"},
Florian Fainelli15e690a2022-01-06 19:51:40 -0800165 {{BCM47XX_BOARD_NETGEAR_R6300_V1, "Netgear R6300 V1"}, "U12H218T00_NETGEAR"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200166 {{BCM47XX_BOARD_NETGEAR_WGR614V8, "Netgear WGR614 V8"}, "U12H072T00_NETGEAR"},
167 {{BCM47XX_BOARD_NETGEAR_WGR614V9, "Netgear WGR614 V9"}, "U12H094T00_NETGEAR"},
Rafał Miłecki160f1432015-04-01 18:18:02 +0200168 {{BCM47XX_BOARD_NETGEAR_WGR614_V10, "Netgear WGR614 V10"}, "U12H139T01_NETGEAR"},
Florian Fainelli4da27b62022-01-06 19:51:41 -0800169 {{BCM47XX_BOARD_NETGEAR_WN2500RP_V1, "Netgear WN2500RP V1"}, "U12H197T00_NETGEAR"},
170 {{BCM47XX_BOARD_NETGEAR_WN2500RP_V2, "Netgear WN2500RP V2"}, "U12H294T00_NETGEAR"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200171 {{BCM47XX_BOARD_NETGEAR_WNDR3300, "Netgear WNDR3300"}, "U12H093T00_NETGEAR"},
172 {{BCM47XX_BOARD_NETGEAR_WNDR3400V1, "Netgear WNDR3400 V1"}, "U12H155T00_NETGEAR"},
173 {{BCM47XX_BOARD_NETGEAR_WNDR3400V2, "Netgear WNDR3400 V2"}, "U12H187T00_NETGEAR"},
Rafał Miłecki160f1432015-04-01 18:18:02 +0200174 {{BCM47XX_BOARD_NETGEAR_WNDR3400_V3, "Netgear WNDR3400 V3"}, "U12H208T00_NETGEAR"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200175 {{BCM47XX_BOARD_NETGEAR_WNDR3400VCNA, "Netgear WNDR3400 Vcna"}, "U12H155T01_NETGEAR"},
176 {{BCM47XX_BOARD_NETGEAR_WNDR3700V3, "Netgear WNDR3700 V3"}, "U12H194T00_NETGEAR"},
177 {{BCM47XX_BOARD_NETGEAR_WNDR4000, "Netgear WNDR4000"}, "U12H181T00_NETGEAR"},
178 {{BCM47XX_BOARD_NETGEAR_WNDR4500V1, "Netgear WNDR4500 V1"}, "U12H189T00_NETGEAR"},
179 {{BCM47XX_BOARD_NETGEAR_WNDR4500V2, "Netgear WNDR4500 V2"}, "U12H224T00_NETGEAR"},
Rafał Miłecki425f1e62018-04-08 22:57:32 +0200180 {{BCM47XX_BOARD_NETGEAR_WNR1000_V3, "Netgear WNR1000 V3"}, "U12H139T00_NETGEAR"},
181 {{BCM47XX_BOARD_NETGEAR_WNR1000_V3, "Netgear WNR1000 V3"}, "U12H139T50_NETGEAR"},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200182 {{BCM47XX_BOARD_NETGEAR_WNR2000, "Netgear WNR2000"}, "U12H114T00_NETGEAR"},
183 {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "U12H136T99_NETGEAR"},
184 {{BCM47XX_BOARD_NETGEAR_WNR3500U, "Netgear WNR3500U"}, "U12H136T00_NETGEAR"},
185 {{BCM47XX_BOARD_NETGEAR_WNR3500V2, "Netgear WNR3500 V2"}, "U12H127T00_NETGEAR"},
186 {{BCM47XX_BOARD_NETGEAR_WNR3500V2VC, "Netgear WNR3500 V2vc"}, "U12H127T70_NETGEAR"},
187 {{BCM47XX_BOARD_NETGEAR_WNR834BV2, "Netgear WNR834B V2"}, "U12H081T00_NETGEAR"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +0100188 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200189};
190
191/* boardtype, boardnum, boardrev */
192static const
193struct bcm47xx_board_type_list3 bcm47xx_board_list_board[] __initconst = {
194 {{BCM47XX_BOARD_HUAWEI_E970, "Huawei E970"}, "0x048e", "0x5347", "0x11"},
195 {{BCM47XX_BOARD_PHICOMM_M1, "Phicomm M1"}, "0x0590", "80", "0x1104"},
196 {{BCM47XX_BOARD_ZTE_H218N, "ZTE H218N"}, "0x053d", "1234", "0x1305"},
Hauke Mehrtensa2ffb562014-01-03 20:41:58 +0100197 {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "0x04CF", "3500", "02"},
Rafał Miłecki41a867c2014-06-20 07:56:39 +0200198 {{BCM47XX_BOARD_LINKSYS_WRT54G_TYPE_0101, "Linksys WRT54G/GS/GL"}, "0x0101", "42", "0x10"},
199 {{BCM47XX_BOARD_LINKSYS_WRT54G_TYPE_0467, "Linksys WRT54G/GS/GL"}, "0x0467", "42", "0x10"},
200 {{BCM47XX_BOARD_LINKSYS_WRT54G_TYPE_0708, "Linksys WRT54G/GS/GL"}, "0x0708", "42", "0x10"},
Hauke Mehrtens89fb3ac2014-01-03 20:42:00 +0100201 { {0}, NULL},
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200202};
203
Hauke Mehrtensd508eb72014-03-02 17:49:28 +0100204/* boardtype, boardrev */
205static const
206struct bcm47xx_board_type_list2 bcm47xx_board_list_board_type_rev[] __initconst = {
207 {{BCM47XX_BOARD_SIEMENS_SE505V2, "Siemens SE505 V2"}, "0x0101", "0x10"},
208 { {0}, NULL},
209};
210
Rafał Miłecki7515c6f2015-04-01 18:18:01 +0200211/*
212 * Some devices don't use any common NVRAM entry for identification and they
213 * have only one model specific variable.
214 * They don't deserve own arrays, let's group them there using key-value array.
215 */
216static const
217struct bcm47xx_board_type_list2 bcm47xx_board_list_key_value[] __initconst = {
218 {{BCM47XX_BOARD_ASUS_WL700GE, "Asus WL700"}, "model_no", "WL700"},
Rafał Miłecki160f1432015-04-01 18:18:02 +0200219 {{BCM47XX_BOARD_LINKSYS_WRT300N_V1, "Linksys WRT300N V1"}, "router_name", "WRT300N"},
220 {{BCM47XX_BOARD_LINKSYS_WRT600N_V11, "Linksys WRT600N V1.1"}, "Model_Name", "WRT600N"},
Rafał Miłecki7515c6f2015-04-01 18:18:01 +0200221 {{BCM47XX_BOARD_LINKSYS_WRTSL54GS, "Linksys WRTSL54GS"}, "machine_name", "WRTSL54GS"},
222 { {0}, NULL},
223};
224
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200225static const
226struct bcm47xx_board_type bcm47xx_board_unknown[] __initconst = {
227 {BCM47XX_BOARD_UNKNOWN, "Unknown Board"},
228};
229
230static struct bcm47xx_board_store bcm47xx_board = {BCM47XX_BOARD_NO, "Unknown Board"};
231
232static __init const struct bcm47xx_board_type *bcm47xx_board_get_nvram(void)
233{
234 char buf1[30];
235 char buf2[30];
236 char buf3[30];
237 const struct bcm47xx_board_type_list1 *e1;
238 const struct bcm47xx_board_type_list2 *e2;
239 const struct bcm47xx_board_type_list3 *e3;
240
241 if (bcm47xx_nvram_getenv("model_name", buf1, sizeof(buf1)) >= 0) {
242 for (e1 = bcm47xx_board_list_model_name; e1->value1; e1++) {
243 if (!strcmp(buf1, e1->value1))
244 return &e1->board;
245 }
246 }
247
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200248 if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0) {
249 for (e1 = bcm47xx_board_list_hardware_version; e1->value1; e1++) {
250 if (strstarts(buf1, e1->value1))
251 return &e1->board;
252 }
253 }
254
Hauke Mehrtens250dc032014-07-29 00:12:09 +0200255 if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0 &&
Rafał Miłecki96f7c212015-04-01 16:01:02 +0200256 bcm47xx_nvram_getenv("boardnum", buf2, sizeof(buf2)) >= 0) {
257 for (e2 = bcm47xx_board_list_hw_version_num; e2->value1; e2++) {
Hauke Mehrtens250dc032014-07-29 00:12:09 +0200258 if (!strstarts(buf1, e2->value1) &&
259 !strcmp(buf2, e2->value2))
260 return &e2->board;
261 }
262 }
263
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200264 if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) {
265 for (e1 = bcm47xx_board_list_productid; e1->value1; e1++) {
266 if (!strcmp(buf1, e1->value1))
267 return &e1->board;
268 }
269 }
270
271 if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) {
272 for (e1 = bcm47xx_board_list_ModelId; e1->value1; e1++) {
273 if (!strcmp(buf1, e1->value1))
274 return &e1->board;
275 }
276 }
277
278 if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 ||
279 bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) {
280 /* buffalo hardware, check id for specific hardware matches */
281 for (e1 = bcm47xx_board_list_melco_id; e1->value1; e1++) {
282 if (!strcmp(buf1, e1->value1))
283 return &e1->board;
284 }
285 }
286
287 if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 &&
288 bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) {
289 for (e2 = bcm47xx_board_list_boot_hw; e2->value1; e2++) {
290 if (!strcmp(buf1, e2->value1) &&
291 !strcmp(buf2, e2->value2))
292 return &e2->board;
293 }
294 }
295
296 if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) {
297 for (e1 = bcm47xx_board_list_board_id; e1->value1; e1++) {
298 if (!strcmp(buf1, e1->value1))
299 return &e1->board;
300 }
301 }
302
303 if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 &&
304 bcm47xx_nvram_getenv("boardnum", buf2, sizeof(buf2)) >= 0 &&
305 bcm47xx_nvram_getenv("boardrev", buf3, sizeof(buf3)) >= 0) {
306 for (e3 = bcm47xx_board_list_board; e3->value1; e3++) {
307 if (!strcmp(buf1, e3->value1) &&
308 !strcmp(buf2, e3->value2) &&
309 !strcmp(buf3, e3->value3))
310 return &e3->board;
311 }
312 }
Hauke Mehrtensd508eb72014-03-02 17:49:28 +0100313
314 if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 &&
315 bcm47xx_nvram_getenv("boardrev", buf2, sizeof(buf2)) >= 0 &&
316 bcm47xx_nvram_getenv("boardnum", buf3, sizeof(buf3)) == -ENOENT) {
317 for (e2 = bcm47xx_board_list_board_type_rev; e2->value1; e2++) {
318 if (!strcmp(buf1, e2->value1) &&
319 !strcmp(buf2, e2->value2))
320 return &e2->board;
321 }
322 }
Rafał Miłecki7515c6f2015-04-01 18:18:01 +0200323
324 for (e2 = bcm47xx_board_list_key_value; e2->value1; e2++) {
325 if (bcm47xx_nvram_getenv(e2->value1, buf1, sizeof(buf1)) >= 0) {
326 if (!strcmp(buf1, e2->value2))
327 return &e2->board;
328 }
329 }
330
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200331 return bcm47xx_board_unknown;
332}
333
334void __init bcm47xx_board_detect(void)
335{
336 int err;
337 char buf[10];
338 const struct bcm47xx_board_type *board_detected;
339
340 if (bcm47xx_board.board != BCM47XX_BOARD_NO)
341 return;
342
343 /* check if the nvram is available */
344 err = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf));
345
346 /* init of nvram failed, probably too early now */
Rafał Miłeckid548ca62014-12-10 17:38:26 +0100347 if (err == -ENXIO)
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200348 return;
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200349
350 board_detected = bcm47xx_board_get_nvram();
351 bcm47xx_board.board = board_detected->board;
Jason Wang906c6bc2021-09-06 21:49:23 +0800352 strscpy(bcm47xx_board.name, board_detected->name,
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200353 BCM47XX_BOARD_MAX_NAME);
354}
355
356enum bcm47xx_board bcm47xx_board_get(void)
357{
358 return bcm47xx_board.board;
359}
360EXPORT_SYMBOL(bcm47xx_board_get);
361
362const char *bcm47xx_board_get_name(void)
363{
364 return bcm47xx_board.name;
365}
366EXPORT_SYMBOL(bcm47xx_board_get_name);