board.c 13 KB

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