1786c497aSHauke Mehrtens #include <linux/export.h> 2786c497aSHauke Mehrtens #include <linux/string.h> 3786c497aSHauke Mehrtens #include <bcm47xx_board.h> 4786c497aSHauke Mehrtens #include <bcm47xx_nvram.h> 5786c497aSHauke Mehrtens 6786c497aSHauke Mehrtens struct bcm47xx_board_type { 7786c497aSHauke Mehrtens const enum bcm47xx_board board; 8786c497aSHauke Mehrtens const char *name; 9786c497aSHauke Mehrtens }; 10786c497aSHauke Mehrtens 11786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 { 12786c497aSHauke Mehrtens struct bcm47xx_board_type board; 13786c497aSHauke Mehrtens const char *value1; 14786c497aSHauke Mehrtens }; 15786c497aSHauke Mehrtens 16786c497aSHauke Mehrtens struct bcm47xx_board_type_list2 { 17786c497aSHauke Mehrtens struct bcm47xx_board_type board; 18786c497aSHauke Mehrtens const char *value1; 19786c497aSHauke Mehrtens const char *value2; 20786c497aSHauke Mehrtens }; 21786c497aSHauke Mehrtens 22786c497aSHauke Mehrtens struct bcm47xx_board_type_list3 { 23786c497aSHauke Mehrtens struct bcm47xx_board_type board; 24786c497aSHauke Mehrtens const char *value1; 25786c497aSHauke Mehrtens const char *value2; 26786c497aSHauke Mehrtens const char *value3; 27786c497aSHauke Mehrtens }; 28786c497aSHauke Mehrtens 29786c497aSHauke Mehrtens struct bcm47xx_board_store { 30786c497aSHauke Mehrtens enum bcm47xx_board board; 31786c497aSHauke Mehrtens char name[BCM47XX_BOARD_MAX_NAME]; 32786c497aSHauke Mehrtens }; 33786c497aSHauke Mehrtens 34786c497aSHauke Mehrtens /* model_name */ 35786c497aSHauke Mehrtens static const 36786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_model_name[] __initconst = { 37786c497aSHauke Mehrtens {{BCM47XX_BOARD_DLINK_DIR130, "D-Link DIR-130"}, "DIR-130"}, 38786c497aSHauke Mehrtens {{BCM47XX_BOARD_DLINK_DIR330, "D-Link DIR-330"}, "DIR-330"}, 3989fb3ac8SHauke Mehrtens { {0}, NULL}, 40786c497aSHauke Mehrtens }; 41786c497aSHauke Mehrtens 42786c497aSHauke Mehrtens /* model_no */ 43786c497aSHauke Mehrtens static const 44786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_model_no[] __initconst = { 45786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL700GE, "Asus WL700"}, "WL700"}, 4689fb3ac8SHauke Mehrtens { {0}, NULL}, 47786c497aSHauke Mehrtens }; 48786c497aSHauke Mehrtens 49786c497aSHauke Mehrtens /* machine_name */ 50786c497aSHauke Mehrtens static const 51786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_machine_name[] __initconst = { 52786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRTSL54GS, "Linksys WRTSL54GS"}, "WRTSL54GS"}, 5389fb3ac8SHauke Mehrtens { {0}, NULL}, 54786c497aSHauke Mehrtens }; 55786c497aSHauke Mehrtens 56786c497aSHauke Mehrtens /* hardware_version */ 57786c497aSHauke Mehrtens static const 58786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_hardware_version[] __initconst = { 59a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN10U, "Asus RT-N10U"}, "RTN10U"}, 60a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN12, "Asus RT-N12"}, "RT-N12"}, 61a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN12B1, "Asus RT-N12B1"}, "RTN12B1"}, 62a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN12C1, "Asus RT-N12C1"}, "RTN12C1"}, 63a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN12D1, "Asus RT-N12D1"}, "RTN12D1"}, 64a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN12HP, "Asus RT-N12HP"}, "RTN12HP"}, 65786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16-"}, 66786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL320GE, "Asus WL320GE"}, "WL320G-"}, 67786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL330GE, "Asus WL330GE"}, "WL330GE-"}, 68786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL500GD, "Asus WL500GD"}, "WL500gd-"}, 69786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL500GPV1, "Asus WL500GP V1"}, "WL500gp-"}, 70786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL500GPV2, "Asus WL500GP V2"}, "WL500GPV2-"}, 71786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL500W, "Asus WL500W"}, "WL500gW-"}, 72786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL520GC, "Asus WL520GC"}, "WL520GC-"}, 73786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL520GU, "Asus WL520GU"}, "WL520GU-"}, 74786c497aSHauke Mehrtens {{BCM47XX_BOARD_BELKIN_F7D4301, "Belkin F7D4301"}, "F7D4301"}, 7589fb3ac8SHauke Mehrtens { {0}, NULL}, 76786c497aSHauke Mehrtens }; 77786c497aSHauke Mehrtens 78786c497aSHauke Mehrtens /* productid */ 79786c497aSHauke Mehrtens static const 80786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_productid[] __initconst = { 81786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTAC66U, "Asus RT-AC66U"}, "RT-AC66U"}, 82786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN10, "Asus RT-N10"}, "RT-N10"}, 83786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN10D, "Asus RT-N10D"}, "RT-N10D"}, 84786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN15U, "Asus RT-N15U"}, "RT-N15U"}, 85786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN16, "Asus RT-N16"}, "RT-N16"}, 86786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN53, "Asus RT-N53"}, "RT-N53"}, 87786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_RTN66U, "Asus RT-N66U"}, "RT-N66U"}, 88786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WL300G, "Asus WL300G"}, "WL300g"}, 89786c497aSHauke Mehrtens {{BCM47XX_BOARD_ASUS_WLHDD, "Asus WLHDD"}, "WLHDD"}, 9089fb3ac8SHauke Mehrtens { {0}, NULL}, 91786c497aSHauke Mehrtens }; 92786c497aSHauke Mehrtens 93786c497aSHauke Mehrtens /* ModelId */ 94786c497aSHauke Mehrtens static const 95786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_ModelId[] __initconst = { 96786c497aSHauke Mehrtens {{BCM47XX_BOARD_DELL_TM2300, "Dell WX-5565"}, "WX-5565"}, 97786c497aSHauke Mehrtens {{BCM47XX_BOARD_MOTOROLA_WE800G, "Motorola WE800G"}, "WE800G"}, 98786c497aSHauke Mehrtens {{BCM47XX_BOARD_MOTOROLA_WR850GP, "Motorola WR850GP"}, "WR850GP"}, 99786c497aSHauke Mehrtens {{BCM47XX_BOARD_MOTOROLA_WR850GV2V3, "Motorola WR850G"}, "WR850G"}, 10089fb3ac8SHauke Mehrtens { {0}, NULL}, 101786c497aSHauke Mehrtens }; 102786c497aSHauke Mehrtens 103786c497aSHauke Mehrtens /* melco_id or buf1falo_id */ 104786c497aSHauke Mehrtens static const 105786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_melco_id[] __initconst = { 106786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WBR2_G54, "Buffalo WBR2-G54"}, "29bb0332"}, 107786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WHR2_A54G54, "Buffalo WHR2-A54G54"}, "290441dd"}, 108786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WHR_G125, "Buffalo WHR-G125"}, "32093"}, 109786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WHR_G54S, "Buffalo WHR-G54S"}, "30182"}, 110786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WHR_HP_G54, "Buffalo WHR-HP-G54"}, "30189"}, 111786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WLA2_G54L, "Buffalo WLA2-G54L"}, "29129"}, 112786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WZR_G300N, "Buffalo WZR-G300N"}, "31120"}, 113786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54, "Buffalo WZR-RS-G54"}, "30083"}, 114786c497aSHauke Mehrtens {{BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP, "Buffalo WZR-RS-G54HP"}, "30103"}, 11589fb3ac8SHauke Mehrtens { {0}, NULL}, 116786c497aSHauke Mehrtens }; 117786c497aSHauke Mehrtens 118786c497aSHauke Mehrtens /* boot_hw_model, boot_hw_ver */ 119786c497aSHauke Mehrtens static const 120786c497aSHauke Mehrtens struct bcm47xx_board_type_list2 bcm47xx_board_list_boot_hw[] __initconst = { 121786c497aSHauke Mehrtens /* like WRT160N v3.0 */ 122786c497aSHauke Mehrtens {{BCM47XX_BOARD_CISCO_M10V1, "Cisco M10"}, "M10", "1.0"}, 123786c497aSHauke Mehrtens /* like WRT310N v2.0 */ 124786c497aSHauke Mehrtens {{BCM47XX_BOARD_CISCO_M20V1, "Cisco M20"}, "M20", "1.0"}, 125786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E900V1, "Linksys E900 V1"}, "E900", "1.0"}, 126786c497aSHauke Mehrtens /* like WRT160N v3.0 */ 127786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E1000V1, "Linksys E1000 V1"}, "E100", "1.0"}, 128786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E1000V2, "Linksys E1000 V2"}, "E1000", "2.0"}, 129786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E1000V21, "Linksys E1000 V2.1"}, "E1000", "2.1"}, 130786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E1200V2, "Linksys E1200 V2"}, "E1200", "2.0"}, 131786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E2000V1, "Linksys E2000 V1"}, "Linksys E2000", "1.0"}, 132786c497aSHauke Mehrtens /* like WRT610N v2.0 */ 133786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E3000V1, "Linksys E3000 V1"}, "E300", "1.0"}, 134786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E3200V1, "Linksys E3200 V1"}, "E3200", "1.0"}, 135786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_E4200V1, "Linksys E4200 V1"}, "E4200", "1.0"}, 136786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT150NV11, "Linksys WRT150N V1.1"}, "WRT150N", "1.1"}, 137786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT150NV1, "Linksys WRT150N V1"}, "WRT150N", "1"}, 138786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT160NV1, "Linksys WRT160N V1"}, "WRT160N", "1.0"}, 139786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT160NV3, "Linksys WRT160N V3"}, "WRT160N", "3.0"}, 140786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT300NV11, "Linksys WRT300N V1.1"}, "WRT300N", "1.1"}, 141786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT310NV1, "Linksys WRT310N V1"}, "WRT310N", "1.0"}, 142786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT310NV2, "Linksys WRT310N V2"}, "WRT310N", "2.0"}, 143786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT54G3GV2, "Linksys WRT54G3GV2-VF"}, "WRT54G3GV2-VF", "1.0"}, 144786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT610NV1, "Linksys WRT610N V1"}, "WRT610N", "1.0"}, 145786c497aSHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT610NV2, "Linksys WRT610N V2"}, "WRT610N", "2.0"}, 14689fb3ac8SHauke Mehrtens { {0}, NULL}, 147786c497aSHauke Mehrtens }; 148786c497aSHauke Mehrtens 149786c497aSHauke Mehrtens /* board_id */ 150786c497aSHauke Mehrtens static const 151786c497aSHauke Mehrtens struct bcm47xx_board_type_list1 bcm47xx_board_list_board_id[] __initconst = { 152786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WGR614V8, "Netgear WGR614 V8"}, "U12H072T00_NETGEAR"}, 153786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WGR614V9, "Netgear WGR614 V9"}, "U12H094T00_NETGEAR"}, 154786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR3300, "Netgear WNDR3300"}, "U12H093T00_NETGEAR"}, 155786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR3400V1, "Netgear WNDR3400 V1"}, "U12H155T00_NETGEAR"}, 156786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR3400V2, "Netgear WNDR3400 V2"}, "U12H187T00_NETGEAR"}, 157786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR3400VCNA, "Netgear WNDR3400 Vcna"}, "U12H155T01_NETGEAR"}, 158786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR3700V3, "Netgear WNDR3700 V3"}, "U12H194T00_NETGEAR"}, 159786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR4000, "Netgear WNDR4000"}, "U12H181T00_NETGEAR"}, 160786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR4500V1, "Netgear WNDR4500 V1"}, "U12H189T00_NETGEAR"}, 161786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNDR4500V2, "Netgear WNDR4500 V2"}, "U12H224T00_NETGEAR"}, 162786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR2000, "Netgear WNR2000"}, "U12H114T00_NETGEAR"}, 163786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "U12H136T99_NETGEAR"}, 164786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR3500U, "Netgear WNR3500U"}, "U12H136T00_NETGEAR"}, 165786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR3500V2, "Netgear WNR3500 V2"}, "U12H127T00_NETGEAR"}, 166786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR3500V2VC, "Netgear WNR3500 V2vc"}, "U12H127T70_NETGEAR"}, 167786c497aSHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR834BV2, "Netgear WNR834B V2"}, "U12H081T00_NETGEAR"}, 16889fb3ac8SHauke Mehrtens { {0}, NULL}, 169786c497aSHauke Mehrtens }; 170786c497aSHauke Mehrtens 171786c497aSHauke Mehrtens /* boardtype, boardnum, boardrev */ 172786c497aSHauke Mehrtens static const 173786c497aSHauke Mehrtens struct bcm47xx_board_type_list3 bcm47xx_board_list_board[] __initconst = { 174786c497aSHauke Mehrtens {{BCM47XX_BOARD_HUAWEI_E970, "Huawei E970"}, "0x048e", "0x5347", "0x11"}, 175786c497aSHauke Mehrtens {{BCM47XX_BOARD_PHICOMM_M1, "Phicomm M1"}, "0x0590", "80", "0x1104"}, 176786c497aSHauke Mehrtens {{BCM47XX_BOARD_ZTE_H218N, "ZTE H218N"}, "0x053d", "1234", "0x1305"}, 177a2ffb564SHauke Mehrtens {{BCM47XX_BOARD_NETGEAR_WNR3500L, "Netgear WNR3500L"}, "0x04CF", "3500", "02"}, 178848eeb66SHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT54G, "Linksys WRT54G/GS/GL"}, "0x0101", "42", "0x10"}, 179848eeb66SHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT54G, "Linksys WRT54G/GS/GL"}, "0x0467", "42", "0x10"}, 180848eeb66SHauke Mehrtens {{BCM47XX_BOARD_LINKSYS_WRT54G, "Linksys WRT54G/GS/GL"}, "0x0708", "42", "0x10"}, 18189fb3ac8SHauke Mehrtens { {0}, NULL}, 182786c497aSHauke Mehrtens }; 183786c497aSHauke Mehrtens 184*d508eb79SHauke Mehrtens /* boardtype, boardrev */ 185*d508eb79SHauke Mehrtens static const 186*d508eb79SHauke Mehrtens struct bcm47xx_board_type_list2 bcm47xx_board_list_board_type_rev[] __initconst = { 187*d508eb79SHauke Mehrtens {{BCM47XX_BOARD_SIEMENS_SE505V2, "Siemens SE505 V2"}, "0x0101", "0x10"}, 188*d508eb79SHauke Mehrtens { {0}, NULL}, 189*d508eb79SHauke Mehrtens }; 190*d508eb79SHauke Mehrtens 191786c497aSHauke Mehrtens static const 192786c497aSHauke Mehrtens struct bcm47xx_board_type bcm47xx_board_unknown[] __initconst = { 193786c497aSHauke Mehrtens {BCM47XX_BOARD_UNKNOWN, "Unknown Board"}, 194786c497aSHauke Mehrtens }; 195786c497aSHauke Mehrtens 196786c497aSHauke Mehrtens static struct bcm47xx_board_store bcm47xx_board = {BCM47XX_BOARD_NO, "Unknown Board"}; 197786c497aSHauke Mehrtens 198786c497aSHauke Mehrtens static __init const struct bcm47xx_board_type *bcm47xx_board_get_nvram(void) 199786c497aSHauke Mehrtens { 200786c497aSHauke Mehrtens char buf1[30]; 201786c497aSHauke Mehrtens char buf2[30]; 202786c497aSHauke Mehrtens char buf3[30]; 203786c497aSHauke Mehrtens const struct bcm47xx_board_type_list1 *e1; 204786c497aSHauke Mehrtens const struct bcm47xx_board_type_list2 *e2; 205786c497aSHauke Mehrtens const struct bcm47xx_board_type_list3 *e3; 206786c497aSHauke Mehrtens 207786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("model_name", buf1, sizeof(buf1)) >= 0) { 208786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_model_name; e1->value1; e1++) { 209786c497aSHauke Mehrtens if (!strcmp(buf1, e1->value1)) 210786c497aSHauke Mehrtens return &e1->board; 211786c497aSHauke Mehrtens } 212786c497aSHauke Mehrtens } 213786c497aSHauke Mehrtens 214786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("model_no", buf1, sizeof(buf1)) >= 0) { 215786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_model_no; e1->value1; e1++) { 216786c497aSHauke Mehrtens if (strstarts(buf1, e1->value1)) 217786c497aSHauke Mehrtens return &e1->board; 218786c497aSHauke Mehrtens } 219786c497aSHauke Mehrtens } 220786c497aSHauke Mehrtens 221786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("machine_name", buf1, sizeof(buf1)) >= 0) { 222786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_machine_name; e1->value1; e1++) { 223786c497aSHauke Mehrtens if (strstarts(buf1, e1->value1)) 224786c497aSHauke Mehrtens return &e1->board; 225786c497aSHauke Mehrtens } 226786c497aSHauke Mehrtens } 227786c497aSHauke Mehrtens 228786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("hardware_version", buf1, sizeof(buf1)) >= 0) { 229786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_hardware_version; e1->value1; e1++) { 230786c497aSHauke Mehrtens if (strstarts(buf1, e1->value1)) 231786c497aSHauke Mehrtens return &e1->board; 232786c497aSHauke Mehrtens } 233786c497aSHauke Mehrtens } 234786c497aSHauke Mehrtens 235786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("productid", buf1, sizeof(buf1)) >= 0) { 236786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_productid; e1->value1; e1++) { 237786c497aSHauke Mehrtens if (!strcmp(buf1, e1->value1)) 238786c497aSHauke Mehrtens return &e1->board; 239786c497aSHauke Mehrtens } 240786c497aSHauke Mehrtens } 241786c497aSHauke Mehrtens 242786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("ModelId", buf1, sizeof(buf1)) >= 0) { 243786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_ModelId; e1->value1; e1++) { 244786c497aSHauke Mehrtens if (!strcmp(buf1, e1->value1)) 245786c497aSHauke Mehrtens return &e1->board; 246786c497aSHauke Mehrtens } 247786c497aSHauke Mehrtens } 248786c497aSHauke Mehrtens 249786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("melco_id", buf1, sizeof(buf1)) >= 0 || 250786c497aSHauke Mehrtens bcm47xx_nvram_getenv("buf1falo_id", buf1, sizeof(buf1)) >= 0) { 251786c497aSHauke Mehrtens /* buffalo hardware, check id for specific hardware matches */ 252786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_melco_id; e1->value1; e1++) { 253786c497aSHauke Mehrtens if (!strcmp(buf1, e1->value1)) 254786c497aSHauke Mehrtens return &e1->board; 255786c497aSHauke Mehrtens } 256786c497aSHauke Mehrtens } 257786c497aSHauke Mehrtens 258786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("boot_hw_model", buf1, sizeof(buf1)) >= 0 && 259786c497aSHauke Mehrtens bcm47xx_nvram_getenv("boot_hw_ver", buf2, sizeof(buf2)) >= 0) { 260786c497aSHauke Mehrtens for (e2 = bcm47xx_board_list_boot_hw; e2->value1; e2++) { 261786c497aSHauke Mehrtens if (!strcmp(buf1, e2->value1) && 262786c497aSHauke Mehrtens !strcmp(buf2, e2->value2)) 263786c497aSHauke Mehrtens return &e2->board; 264786c497aSHauke Mehrtens } 265786c497aSHauke Mehrtens } 266786c497aSHauke Mehrtens 267786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("board_id", buf1, sizeof(buf1)) >= 0) { 268786c497aSHauke Mehrtens for (e1 = bcm47xx_board_list_board_id; e1->value1; e1++) { 269786c497aSHauke Mehrtens if (!strcmp(buf1, e1->value1)) 270786c497aSHauke Mehrtens return &e1->board; 271786c497aSHauke Mehrtens } 272786c497aSHauke Mehrtens } 273786c497aSHauke Mehrtens 274786c497aSHauke Mehrtens if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 && 275786c497aSHauke Mehrtens bcm47xx_nvram_getenv("boardnum", buf2, sizeof(buf2)) >= 0 && 276786c497aSHauke Mehrtens bcm47xx_nvram_getenv("boardrev", buf3, sizeof(buf3)) >= 0) { 277786c497aSHauke Mehrtens for (e3 = bcm47xx_board_list_board; e3->value1; e3++) { 278786c497aSHauke Mehrtens if (!strcmp(buf1, e3->value1) && 279786c497aSHauke Mehrtens !strcmp(buf2, e3->value2) && 280786c497aSHauke Mehrtens !strcmp(buf3, e3->value3)) 281786c497aSHauke Mehrtens return &e3->board; 282786c497aSHauke Mehrtens } 283786c497aSHauke Mehrtens } 284*d508eb79SHauke Mehrtens 285*d508eb79SHauke Mehrtens if (bcm47xx_nvram_getenv("boardtype", buf1, sizeof(buf1)) >= 0 && 286*d508eb79SHauke Mehrtens bcm47xx_nvram_getenv("boardrev", buf2, sizeof(buf2)) >= 0 && 287*d508eb79SHauke Mehrtens bcm47xx_nvram_getenv("boardnum", buf3, sizeof(buf3)) == -ENOENT) { 288*d508eb79SHauke Mehrtens for (e2 = bcm47xx_board_list_board_type_rev; e2->value1; e2++) { 289*d508eb79SHauke Mehrtens if (!strcmp(buf1, e2->value1) && 290*d508eb79SHauke Mehrtens !strcmp(buf2, e2->value2)) 291*d508eb79SHauke Mehrtens return &e2->board; 292*d508eb79SHauke Mehrtens } 293*d508eb79SHauke Mehrtens } 294786c497aSHauke Mehrtens return bcm47xx_board_unknown; 295786c497aSHauke Mehrtens } 296786c497aSHauke Mehrtens 297786c497aSHauke Mehrtens void __init bcm47xx_board_detect(void) 298786c497aSHauke Mehrtens { 299786c497aSHauke Mehrtens int err; 300786c497aSHauke Mehrtens char buf[10]; 301786c497aSHauke Mehrtens const struct bcm47xx_board_type *board_detected; 302786c497aSHauke Mehrtens 303786c497aSHauke Mehrtens if (bcm47xx_board.board != BCM47XX_BOARD_NO) 304786c497aSHauke Mehrtens return; 305786c497aSHauke Mehrtens 306786c497aSHauke Mehrtens /* check if the nvram is available */ 307786c497aSHauke Mehrtens err = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf)); 308786c497aSHauke Mehrtens 309786c497aSHauke Mehrtens /* init of nvram failed, probably too early now */ 310786c497aSHauke Mehrtens if (err == -ENXIO) { 311786c497aSHauke Mehrtens return; 312786c497aSHauke Mehrtens } 313786c497aSHauke Mehrtens 314786c497aSHauke Mehrtens board_detected = bcm47xx_board_get_nvram(); 315786c497aSHauke Mehrtens bcm47xx_board.board = board_detected->board; 316786c497aSHauke Mehrtens strlcpy(bcm47xx_board.name, board_detected->name, 317786c497aSHauke Mehrtens BCM47XX_BOARD_MAX_NAME); 318786c497aSHauke Mehrtens } 319786c497aSHauke Mehrtens 320786c497aSHauke Mehrtens enum bcm47xx_board bcm47xx_board_get(void) 321786c497aSHauke Mehrtens { 322786c497aSHauke Mehrtens return bcm47xx_board.board; 323786c497aSHauke Mehrtens } 324786c497aSHauke Mehrtens EXPORT_SYMBOL(bcm47xx_board_get); 325786c497aSHauke Mehrtens 326786c497aSHauke Mehrtens const char *bcm47xx_board_get_name(void) 327786c497aSHauke Mehrtens { 328786c497aSHauke Mehrtens return bcm47xx_board.name; 329786c497aSHauke Mehrtens } 330786c497aSHauke Mehrtens EXPORT_SYMBOL(bcm47xx_board_get_name); 331