Hauke Mehrtens | 786c497 | 2013-09-18 13:29:57 +0200 | [diff] [blame] | 1 | #include <linux/export.h> |
| 2 | #include <linux/string.h> |
| 3 | #include <bcm47xx_board.h> |
| 4 | #include <bcm47xx_nvram.h> |
| 5 | |
| 6 | struct bcm47xx_board_type { |
| 7 | const enum bcm47xx_board board; |
| 8 | const char *name; |
| 9 | }; |
| 10 | |
| 11 | struct bcm47xx_board_type_list1 { |
| 12 | struct bcm47xx_board_type board; |
| 13 | const char *value1; |
| 14 | }; |
| 15 | |
| 16 | struct bcm47xx_board_type_list2 { |
| 17 | struct bcm47xx_board_type board; |
| 18 | const char *value1; |
| 19 | const char *value2; |
| 20 | }; |
| 21 | |
| 22 | struct bcm47xx_board_type_list3 { |
| 23 | struct bcm47xx_board_type board; |
| 24 | const char *value1; |
| 25 | const char *value2; |
| 26 | const char *value3; |
| 27 | }; |
| 28 | |
| 29 | struct bcm47xx_board_store { |
| 30 | enum bcm47xx_board board; |
| 31 | char name[BCM47XX_BOARD_MAX_NAME]; |
| 32 | }; |
| 33 | |
| 34 | /* model_name */ |
| 35 | static const |
| 36 | struct bcm47xx_board_type_list1 bcm47xx_board_list_model_name[] __initconst = { |
| 37 | {{BCM47XX_BOARD_DLINK_DIR130, "D-Link DIR-130"}, "DIR-130"}, |
| 38 | {{BCM47XX_BOARD_DLINK_DIR330, "D-Link DIR-330"}, "DIR-330"}, |
| 39 | { {0}, 0}, |
| 40 | }; |
| 41 | |
| 42 | /* model_no */ |
| 43 | static const |
| 44 | struct bcm47xx_board_type_list1 bcm47xx_board_list_model_no[] __initconst = { |
| 45 | {{BCM47XX_BOARD_ASUS_WL700GE, "Asus WL700"}, "WL700"}, |
| 46 | { {0}, 0}, |
| 47 | }; |
| 48 | |
| 49 | /* machine_name */ |
| 50 | static const |
| 51 | struct bcm47xx_board_type_list1 bcm47xx_board_list_machine_name[] __initconst = { |
| 52 | {{BCM47XX_BOARD_LINKSYS_WRTSL54GS, "Linksys WRTSL54GS"}, "WRTSL54GS"}, |
| 53 | { {0}, 0}, |
| 54 | }; |
| 55 | |
| 56 | /* hardware_version */ |
| 57 | static const |
| 58 | struct bcm47xx_board_type_list1 bcm47xx_board_list_hardware_version[] __initconst = { |
| 59 | {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16-"}, |
| 60 | {{BCM47XX_BOARD_ASUS_WL320GE, "Asus WL320GE"}, "WL320G-"}, |
| 61 | {{BCM47XX_BOARD_ASUS_WL330GE, "Asus WL330GE"}, "WL330GE-"}, |
| 62 | {{BCM47XX_BOARD_ASUS_WL500GD, "Asus WL500GD"}, "WL500gd-"}, |
| 63 | {{BCM47XX_BOARD_ASUS_WL500GPV1, "Asus WL500GP V1"}, "WL500gp-"}, |
| 64 | {{BCM47XX_BOARD_ASUS_WL500GPV2, "Asus WL500GP V2"}, "WL500GPV2-"}, |
| 65 | {{BCM47XX_BOARD_ASUS_WL500W, "Asus WL500W"}, "WL500gW-"}, |
| 66 | {{BCM47XX_BOARD_ASUS_WL520GC, "Asus WL520GC"}, "WL520GC-"}, |
| 67 | {{BCM47XX_BOARD_ASUS_WL520GU, "Asus WL520GU"}, "WL520GU-"}, |
| 68 | {{BCM47XX_BOARD_BELKIN_F7D4301, "Belkin F7D4301"}, "F7D4301"}, |
| 69 | { {0}, 0}, |
| 70 | }; |
| 71 | |
| 72 | /* productid */ |
| 73 | static const |
| 74 | struct bcm47xx_board_type_list1 bcm47xx_board_list_productid[] __initconst = { |
| 75 | {{BCM47XX_BOARD_ASUS_RTAC66U, "Asus RT-AC66U"}, "RT-AC66U"}, |
| 76 | {{BCM47XX_BOARD_ASUS_RTN10, "Asus RT-N10"}, "RT-N10"}, |
| 77 | {{BCM47XX_BOARD_ASUS_RTN10D, "Asus RT-N10D"}, "RT-N10D"}, |
| 78 | {{BCM47XX_BOARD_ASUS_RTN10U, "Asus RT-N10U"}, "RT-N10U"}, |
| 79 | {{BCM47XX_BOARD_ASUS_RTN12, "Asus RT-N12"}, "RT-N12"}, |
| 80 | {{BCM47XX_BOARD_ASUS_RTN12B1, "Asus RT-N12B1"}, "RT-N12B1"}, |
| 81 | {{BCM47XX_BOARD_ASUS_RTN12C1, "Asus RT-N12C1"}, "RT-N12C1"}, |
| 82 | {{BCM47XX_BOARD_ASUS_RTN12D1, "Asus RT-N12D1"}, "RT-N12D1"}, |
| 83 | {{BCM47XX_BOARD_ASUS_RTN12HP, "Asus RT-N12HP"}, "RT-N12HP"}, |
| 84 | {{BCM47XX_BOARD_ASUS_RTN15U, "Asus RT-N15U"}, "RT-N15U"}, |
| 85 | {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16"}, |
| 86 | {{BCM47XX_BOARD_ASUS_RTN53, "Asus RT-N53"}, "RT-N53"}, |
| 87 | {{BCM47XX_BOARD_ASUS_RTN66U, "Asus RT-N66U"}, "RT-N66U"}, |
| 88 | {{BCM47XX_BOARD_ASUS_WL300G, "Asus WL300G"}, "WL300g"}, |
| 89 | {{BCM47XX_BOARD_ASUS_WLHDD, "Asus WLHDD"}, "WLHDD"}, |
| 90 | { {0}, 0}, |
| 91 | }; |
| 92 | |
| 93 | /* ModelId */ |
| 94 | static const |
| 95 | struct bcm47xx_board_type_list1 bcm47xx_board_list_ModelId[] __initconst = { |
| 96 | {{BCM47XX_BOARD_DELL_TM2300, "Dell WX-5565"}, "WX-5565"}, |
| 97 | {{BCM47XX_BOARD_MOTOROLA_WE800G, "Motorola WE800G"}, "WE800G"}, |
| 98 | {{BCM47XX_BOARD_MOTOROLA_WR850GP, "Motorola WR850GP"}, "WR850GP"}, |
| 99 | {{BCM47XX_BOARD_MOTOROLA_WR850GV2V3, "Motorola WR850G"}, "WR850G"}, |
| 100 | { {0}, 0}, |
| 101 | }; |
| 102 | |
| 103 | /* melco_id or buf1falo_id */ |
| 104 | static const |
| 105 | struct bcm47xx_board_type_list1 bcm47xx_board_list_melco_id[] __initconst = { |
| 106 | {{BCM47XX_BOARD_BUFFALO_WBR2_G54, "Buffalo WBR2-G54"}, "29bb0332"}, |
| 107 | {{BCM47XX_BOARD_BUFFALO_WHR2_A54G54, "Buffalo WHR2-A54G54"}, "290441dd"}, |
| 108 | {{BCM47XX_BOARD_BUFFALO_WHR_G125, "Buffalo WHR-G125"}, "32093"}, |
| 109 | {{BCM47XX_BOARD_BUFFALO_WHR_G54S, "Buffalo WHR-G54S"}, "30182"}, |
| 110 | {{BCM47XX_BOARD_BUFFALO_WHR_HP_G54, "Buffalo WHR-HP-G54"}, "30189"}, |
| 111 | {{BCM47XX_BOARD_BUFFALO_WLA2_G54L, "Buffalo WLA2-G54L"}, "29129"}, |
| 112 | {{BCM47XX_BOARD_BUFFALO_WZR_G300N, "Buffalo WZR-G300N"}, "31120"}, |
| 113 | {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54, "Buffalo WZR-RS-G54"}, "30083"}, |
| 114 | {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP, "Buffalo WZR-RS-G54HP"}, "30103"}, |
| 115 | { {0}, 0}, |
| 116 | }; |
| 117 | |
| 118 | /* boot_hw_model, boot_hw_ver */ |
| 119 | static const |
| 120 | struct bcm47xx_board_type_list2 bcm47xx_board_list_boot_hw[] __initconst = { |
| 121 | /* like WRT160N v3.0 */ |
| 122 | {{BCM47XX_BOARD_CISCO_M10V1, "Cisco M10"}, "M10", "1.0"}, |
| 123 | /* like WRT310N v2.0 */ |
| 124 | {{BCM47XX_BOARD_CISCO_M20V1, "Cisco M20"}, "M20", "1.0"}, |
| 125 | {{BCM47XX_BOARD_LINKSYS_E900V1, "Linksys E900 V1"}, "E900", "1.0"}, |
| 126 | /* like WRT160N v3.0 */ |
| 127 | {{BCM47XX_BOARD_LINKSYS_E1000V1, "Linksys E1000 V1"}, "E100", "1.0"}, |
| 128 | {{BCM47XX_BOARD_LINKSYS_E1000V2, "Linksys E1000 V2"}, "E1000", "2.0"}, |
| 129 | {{BCM47XX_BOARD_LINKSYS_E1000V21, "Linksys E1000 V2.1"}, "E1000", "2.1"}, |
| 130 | {{BCM47XX_BOARD_LINKSYS_E1200V2, "Linksys E1200 V2"}, "E1200", "2.0"}, |
| 131 | {{BCM47XX_BOARD_LINKSYS_E2000V1, "Linksys E2000 V1"}, "Linksys E2000", "1.0"}, |
| 132 | /* like WRT610N v2.0 */ |
| 133 | {{BCM47XX_BOARD_LINKSYS_E3000V1, "Linksys E3000 V1"}, "E300", "1.0"}, |
| 134 | {{BCM47XX_BOARD_LINKSYS_E3200V1, "Linksys E3200 V1"}, "E3200", "1.0"}, |
| 135 | {{BCM47XX_BOARD_LINKSYS_E4200V1, "Linksys E4200 V1"}, "E4200", "1.0"}, |
| 136 | {{BCM47XX_BOARD_LINKSYS_WRT150NV11, "Linksys WRT150N V1.1"}, "WRT150N", "1.1"}, |
| 137 | {{BCM47XX_BOARD_LINKSYS_WRT150NV1, "Linksys WRT150N V1"}, "WRT150N", "1"}, |
| 138 | {{BCM47XX_BOARD_LINKSYS_WRT160NV1, "Linksys WRT160N V1"}, "WRT160N", "1.0"}, |
| 139 | {{BCM47XX_BOARD_LINKSYS_WRT160NV3, "Linksys WRT160N V3"}, "WRT160N", "3.0"}, |
| 140 | {{BCM47XX_BOARD_LINKSYS_WRT300NV11, "Linksys WRT300N V1.1"}, "WRT300N", "1.1"}, |
| 141 | {{BCM47XX_BOARD_LINKSYS_WRT310NV1, "Linksys WRT310N V1"}, "WRT310N", "1.0"}, |
| 142 | {{BCM47XX_BOARD_LINKSYS_WRT310NV2, "Linksys WRT310N V2"}, "WRT310N", "2.0"}, |
| 143 | {{BCM47XX_BOARD_LINKSYS_WRT54G3GV2, "Linksys WRT54G3GV2-VF"}, "WRT54G3GV2-VF", "1.0"}, |
| 144 | {{BCM47XX_BOARD_LINKSYS_WRT610NV1, "Linksys WRT610N V1"}, "WRT610N", "1.0"}, |
| 145 | {{BCM47XX_BOARD_LINKSYS_WRT610NV2, "Linksys WRT610N V2"}, "WRT610N", "2.0"}, |
| 146 | { {0}, 0}, |
| 147 | }; |
| 148 | |
| 149 | /* board_id */ |
| 150 | static const |
| 151 | struct bcm47xx_board_type_list1 bcm47xx_board_list_board_id[] __initconst = { |
| 152 | {{BCM47XX_BOARD_NETGEAR_WGR614V8, "Netgear WGR614 V8"}, "U12H072T00_NETGEAR"}, |
| 153 | {{BCM47XX_BOARD_NETGEAR_WGR614V9, "Netgear WGR614 V9"}, "U12H094T00_NETGEAR"}, |
| 154 | {{BCM47XX_BOARD_NETGEAR_WNDR3300, "Netgear WNDR3300"}, "U12H093T00_NETGEAR"}, |
| 155 | {{BCM47XX_BOARD_NETGEAR_WNDR3400V1, "Netgear WNDR3400 V1"}, "U12H155T00_NETGEAR"}, |
| 156 | {{BCM47XX_BOARD_NETGEAR_WNDR3400V2, "Netgear WNDR3400 V2"}, "U12H187T00_NETGEAR"}, |
| 157 | {{BCM47XX_BOARD_NETGEAR_WNDR3400VCNA, "Netgear WNDR3400 Vcna"}, "U12H155T01_NETGEAR"}, |
| 158 | {{BCM47XX_BOARD_NETGEAR_WNDR3700V3, "Netgear WNDR3700 V3"}, "U12H194T00_NETGEAR"}, |
| 159 | {{BCM47XX_BOARD_NETGEAR_WNDR4000, "Netgear WNDR4000"}, "U12H181T00_NETGEAR"}, |
| 160 | {{BCM47XX_BOARD_NETGEAR_WNDR4500V1, "Netgear WNDR4500 V1"}, "U12H189T00_NETGEAR"}, |
| 161 | {{BCM47XX_BOARD_NETGEAR_WNDR4500V2, "Netgear WNDR4500 V2"}, "U12H224T00_NETGEAR"}, |
| 162 | {{BCM47XX_BOARD_NETGEAR_WNR2000, "Netgear WNR2000"}, "U12H114T00_NETGEAR"}, |
| 163 | {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "U12H136T99_NETGEAR"}, |
| 164 | {{BCM47XX_BOARD_NETGEAR_WNR3500U, "Netgear WNR3500U"}, "U12H136T00_NETGEAR"}, |
| 165 | {{BCM47XX_BOARD_NETGEAR_WNR3500V2, "Netgear WNR3500 V2"}, "U12H127T00_NETGEAR"}, |
| 166 | {{BCM47XX_BOARD_NETGEAR_WNR3500V2VC, "Netgear WNR3500 V2vc"}, "U12H127T70_NETGEAR"}, |
| 167 | {{BCM47XX_BOARD_NETGEAR_WNR834BV2, "Netgear WNR834B V2"}, "U12H081T00_NETGEAR"}, |
| 168 | { {0}, 0}, |
| 169 | }; |
| 170 | |
| 171 | /* boardtype, boardnum, boardrev */ |
| 172 | static const |
| 173 | struct bcm47xx_board_type_list3 bcm47xx_board_list_board[] __initconst = { |
| 174 | {{BCM47XX_BOARD_HUAWEI_E970, "Huawei E970"}, "0x048e", "0x5347", "0x11"}, |
| 175 | {{BCM47XX_BOARD_PHICOMM_M1, "Phicomm M1"}, "0x0590", "80", "0x1104"}, |
| 176 | {{BCM47XX_BOARD_ZTE_H218N, "ZTE H218N"}, "0x053d", "1234", "0x1305"}, |
| 177 | { {0}, 0}, |
| 178 | }; |
| 179 | |
| 180 | static const |
| 181 | struct bcm47xx_board_type bcm47xx_board_unknown[] __initconst = { |
| 182 | {BCM47XX_BOARD_UNKNOWN, "Unknown Board"}, |
| 183 | }; |
| 184 | |
| 185 | static struct bcm47xx_board_store bcm47xx_board = {BCM47XX_BOARD_NO, "Unknown Board"}; |
| 186 | |
| 187 | static __init const struct bcm47xx_board_type *bcm47xx_board_get_nvram(void) |
| 188 | { |
| 189 | char buf1[30]; |
| 190 | char buf2[30]; |
| 191 | char buf3[30]; |
| 192 | const struct bcm47xx_board_type_list1 *e1; |
| 193 | const struct bcm47xx_board_type_list2 *e2; |
| 194 | const struct bcm47xx_board_type_list3 *e3; |
| 195 | |
| 196 | if (bcm47xx_nvram_getenv("model_name", buf1, sizeof(buf1)) >= 0) { |
| 197 | for (e1 = bcm47xx_board_list_model_name; e1->value1; e1++) { |
| 198 | if (!strcmp(buf1, e1->value1)) |
| 199 | return &e1->board; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (bcm47xx_nvram_getenv("model_no", buf1, sizeof(buf1)) >= 0) { |
| 204 | for (e1 = bcm47xx_board_list_model_no; e1->value1; e1++) { |
| 205 | if (strstarts(buf1, e1->value1)) |
| 206 | return &e1->board; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (bcm47xx_nvram_getenv("machine_name", buf1, sizeof(buf1)) >= 0) { |
| 211 | for (e1 = bcm47xx_board_list_machine_name; e1->value1; e1++) { |
| 212 | if (strstarts(buf1, e1->value1)) |
| 213 | return &e1->board; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0) { |
| 218 | for (e1 = bcm47xx_board_list_hardware_version; e1->value1; e1++) { |
| 219 | if (strstarts(buf1, e1->value1)) |
| 220 | return &e1->board; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) { |
| 225 | for (e1 = bcm47xx_board_list_productid; e1->value1; e1++) { |
| 226 | if (!strcmp(buf1, e1->value1)) |
| 227 | return &e1->board; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) { |
| 232 | for (e1 = bcm47xx_board_list_ModelId; e1->value1; e1++) { |
| 233 | if (!strcmp(buf1, e1->value1)) |
| 234 | return &e1->board; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 || |
| 239 | bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) { |
| 240 | /* buffalo hardware, check id for specific hardware matches */ |
| 241 | for (e1 = bcm47xx_board_list_melco_id; e1->value1; e1++) { |
| 242 | if (!strcmp(buf1, e1->value1)) |
| 243 | return &e1->board; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 && |
| 248 | bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) { |
| 249 | for (e2 = bcm47xx_board_list_boot_hw; e2->value1; e2++) { |
| 250 | if (!strcmp(buf1, e2->value1) && |
| 251 | !strcmp(buf2, e2->value2)) |
| 252 | return &e2->board; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) { |
| 257 | for (e1 = bcm47xx_board_list_board_id; e1->value1; e1++) { |
| 258 | if (!strcmp(buf1, e1->value1)) |
| 259 | return &e1->board; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 && |
| 264 | bcm47xx_nvram_getenv("boardnum", buf2, sizeof(buf2)) >= 0 && |
| 265 | bcm47xx_nvram_getenv("boardrev", buf3, sizeof(buf3)) >= 0) { |
| 266 | for (e3 = bcm47xx_board_list_board; e3->value1; e3++) { |
| 267 | if (!strcmp(buf1, e3->value1) && |
| 268 | !strcmp(buf2, e3->value2) && |
| 269 | !strcmp(buf3, e3->value3)) |
| 270 | return &e3->board; |
| 271 | } |
| 272 | } |
| 273 | return bcm47xx_board_unknown; |
| 274 | } |
| 275 | |
| 276 | void __init bcm47xx_board_detect(void) |
| 277 | { |
| 278 | int err; |
| 279 | char buf[10]; |
| 280 | const struct bcm47xx_board_type *board_detected; |
| 281 | |
| 282 | if (bcm47xx_board.board != BCM47XX_BOARD_NO) |
| 283 | return; |
| 284 | |
| 285 | /* check if the nvram is available */ |
| 286 | err = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf)); |
| 287 | |
| 288 | /* init of nvram failed, probably too early now */ |
| 289 | if (err == -ENXIO) { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | board_detected = bcm47xx_board_get_nvram(); |
| 294 | bcm47xx_board.board = board_detected->board; |
| 295 | strlcpy(bcm47xx_board.name, board_detected->name, |
| 296 | BCM47XX_BOARD_MAX_NAME); |
| 297 | } |
| 298 | |
| 299 | enum bcm47xx_board bcm47xx_board_get(void) |
| 300 | { |
| 301 | return bcm47xx_board.board; |
| 302 | } |
| 303 | EXPORT_SYMBOL(bcm47xx_board_get); |
| 304 | |
| 305 | const char *bcm47xx_board_get_name(void) |
| 306 | { |
| 307 | return bcm47xx_board.name; |
| 308 | } |
| 309 | EXPORT_SYMBOL(bcm47xx_board_get_name); |