sys_eeprom.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2006, 2008-2009, 2011 Freescale Semiconductor
  4. * York Sun (yorksun@freescale.com)
  5. * Haiying Wang (haiying.wang@freescale.com)
  6. * Timur Tabi (timur@freescale.com)
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <env.h>
  11. #include <i2c.h>
  12. #include <linux/ctype.h>
  13. #include <u-boot/crc.h>
  14. #ifdef CONFIG_SYS_I2C_EEPROM_CCID
  15. #include "../common/eeprom.h"
  16. #define MAX_NUM_PORTS 8
  17. #endif
  18. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  19. /* some boards with non-256-bytes EEPROM have special define */
  20. /* for MAX_NUM_PORTS in board-specific file */
  21. #ifndef MAX_NUM_PORTS
  22. #define MAX_NUM_PORTS 16
  23. #endif
  24. #define NXID_VERSION 1
  25. #endif
  26. /**
  27. * static eeprom: EEPROM layout for CCID or NXID formats
  28. *
  29. * See application note AN3638 for details.
  30. */
  31. static struct __attribute__ ((__packed__)) eeprom {
  32. #ifdef CONFIG_SYS_I2C_EEPROM_CCID
  33. u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
  34. u8 major; /* 0x04 Board revision, major */
  35. u8 minor; /* 0x05 Board revision, minor */
  36. u8 sn[10]; /* 0x06 - 0x0F Serial Number*/
  37. u8 errata[2]; /* 0x10 - 0x11 Errata Level */
  38. u8 date[6]; /* 0x12 - 0x17 Build Date */
  39. u8 res_0[40]; /* 0x18 - 0x3f Reserved */
  40. u8 mac_count; /* 0x40 Number of MAC addresses */
  41. u8 mac_flag; /* 0x41 MAC table flags */
  42. u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0x71 MAC addresses */
  43. u32 crc; /* 0x72 CRC32 checksum */
  44. #endif
  45. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  46. u8 id[4]; /* 0x00 - 0x03 EEPROM Tag 'NXID' */
  47. u8 sn[12]; /* 0x04 - 0x0F Serial Number */
  48. u8 errata[5]; /* 0x10 - 0x14 Errata Level */
  49. u8 date[6]; /* 0x15 - 0x1a Build Date */
  50. u8 res_0; /* 0x1b Reserved */
  51. u32 version; /* 0x1c - 0x1f NXID Version */
  52. u8 tempcal[8]; /* 0x20 - 0x27 Temperature Calibration Factors */
  53. u8 tempcalsys[2]; /* 0x28 - 0x29 System Temperature Calibration Factors */
  54. u8 tempcalflags; /* 0x2a Temperature Calibration Flags */
  55. u8 res_1[21]; /* 0x2b - 0x3f Reserved */
  56. u8 mac_count; /* 0x40 Number of MAC addresses */
  57. u8 mac_flag; /* 0x41 MAC table flags */
  58. u8 mac[MAX_NUM_PORTS][6]; /* 0x42 - 0xa1 MAC addresses */
  59. u8 res_2[90]; /* 0xa2 - 0xfb Reserved */
  60. u32 crc; /* 0xfc - 0xff CRC32 checksum */
  61. #endif
  62. } e;
  63. /* Set to 1 if we've read EEPROM into memory */
  64. static int has_been_read = 0;
  65. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  66. /* Is this a valid NXID EEPROM? */
  67. #define is_valid ((e.id[0] == 'N') || (e.id[1] == 'X') || \
  68. (e.id[2] == 'I') || (e.id[3] == 'D'))
  69. #endif
  70. #ifdef CONFIG_SYS_I2C_EEPROM_CCID
  71. /* Is this a valid CCID EEPROM? */
  72. #define is_valid ((e.id[0] == 'C') || (e.id[1] == 'C') || \
  73. (e.id[2] == 'I') || (e.id[3] == 'D'))
  74. #endif
  75. /**
  76. * show_eeprom - display the contents of the EEPROM
  77. */
  78. static void show_eeprom(void)
  79. {
  80. int i;
  81. unsigned int crc;
  82. /* EEPROM tag ID, either CCID or NXID */
  83. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  84. printf("ID: %c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
  85. be32_to_cpu(e.version));
  86. #else
  87. printf("ID: %c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
  88. #endif
  89. /* Serial number */
  90. printf("SN: %s\n", e.sn);
  91. /* Errata level. */
  92. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  93. printf("Errata: %s\n", e.errata);
  94. #else
  95. printf("Errata: %c%c\n",
  96. e.errata[0] ? e.errata[0] : '.',
  97. e.errata[1] ? e.errata[1] : '.');
  98. #endif
  99. /* Build date, BCD date values, as YYMMDDhhmmss */
  100. printf("Build date: 20%02x/%02x/%02x %02x:%02x:%02x %s\n",
  101. e.date[0], e.date[1], e.date[2],
  102. e.date[3] & 0x7F, e.date[4], e.date[5],
  103. e.date[3] & 0x80 ? "PM" : "");
  104. /* Show MAC addresses */
  105. for (i = 0; i < min(e.mac_count, (u8)MAX_NUM_PORTS); i++) {
  106. u8 *p = e.mac[i];
  107. printf("Eth%u: %02x:%02x:%02x:%02x:%02x:%02x\n", i,
  108. p[0], p[1], p[2], p[3], p[4], p[5]);
  109. }
  110. crc = crc32(0, (void *)&e, sizeof(e) - 4);
  111. if (crc == be32_to_cpu(e.crc))
  112. printf("CRC: %08x\n", be32_to_cpu(e.crc));
  113. else
  114. printf("CRC: %08x (should be %08x)\n",
  115. be32_to_cpu(e.crc), crc);
  116. #ifdef DEBUG
  117. printf("EEPROM dump: (0x%x bytes)\n", sizeof(e));
  118. for (i = 0; i < sizeof(e); i++) {
  119. if ((i % 16) == 0)
  120. printf("%02X: ", i);
  121. printf("%02X ", ((u8 *)&e)[i]);
  122. if (((i % 16) == 15) || (i == sizeof(e) - 1))
  123. printf("\n");
  124. }
  125. #endif
  126. }
  127. /**
  128. * read_eeprom - read the EEPROM into memory
  129. */
  130. static int read_eeprom(void)
  131. {
  132. int ret;
  133. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  134. #ifndef CONFIG_DM_I2C
  135. unsigned int bus;
  136. #endif
  137. #endif
  138. if (has_been_read)
  139. return 0;
  140. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  141. #ifndef CONFIG_DM_I2C
  142. bus = i2c_get_bus_num();
  143. i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
  144. #endif
  145. #endif
  146. #ifndef CONFIG_DM_I2C
  147. ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
  148. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  149. (void *)&e, sizeof(e));
  150. #else
  151. struct udevice *dev;
  152. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  153. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  154. CONFIG_SYS_I2C_EEPROM_ADDR, 1, &dev);
  155. #else
  156. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR, 1, &dev);
  157. #endif
  158. if (!ret)
  159. ret = dm_i2c_read(dev, 0, (void *)&e, sizeof(e));
  160. #endif
  161. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  162. #ifndef CONFIG_DM_I2C
  163. i2c_set_bus_num(bus);
  164. #endif
  165. #endif
  166. #ifdef DEBUG
  167. show_eeprom();
  168. #endif
  169. has_been_read = (ret == 0) ? 1 : 0;
  170. return ret;
  171. }
  172. /**
  173. * update_crc - update the CRC
  174. *
  175. * This function should be called after each update to the EEPROM structure,
  176. * to make sure the CRC is always correct.
  177. */
  178. static void update_crc(void)
  179. {
  180. u32 crc;
  181. crc = crc32(0, (void *)&e, sizeof(e) - 4);
  182. e.crc = cpu_to_be32(crc);
  183. }
  184. /**
  185. * prog_eeprom - write the EEPROM from memory
  186. */
  187. static int prog_eeprom(void)
  188. {
  189. int ret = 0;
  190. int i;
  191. void *p;
  192. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  193. #ifndef CONFIG_DM_I2C
  194. unsigned int bus;
  195. #endif
  196. #endif
  197. /* Set the reserved values to 0xFF */
  198. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  199. e.res_0 = 0xFF;
  200. memset(e.res_1, 0xFF, sizeof(e.res_1));
  201. #else
  202. memset(e.res_0, 0xFF, sizeof(e.res_0));
  203. #endif
  204. update_crc();
  205. #ifndef CONFIG_DM_I2C
  206. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  207. bus = i2c_get_bus_num();
  208. i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
  209. #endif
  210. #endif
  211. /*
  212. * The AT24C02 datasheet says that data can only be written in page
  213. * mode, which means 8 bytes at a time, and it takes up to 5ms to
  214. * complete a given write.
  215. */
  216. for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
  217. #ifndef CONFIG_DM_I2C
  218. ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i,
  219. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  220. p, min((int)(sizeof(e) - i), 8));
  221. #else
  222. struct udevice *dev;
  223. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  224. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  225. CONFIG_SYS_I2C_EEPROM_ADDR,
  226. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  227. &dev);
  228. #else
  229. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  230. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  231. &dev);
  232. #endif
  233. if (!ret)
  234. ret = dm_i2c_write(dev, i, p, min((int)(sizeof(e) - i),
  235. 8));
  236. #endif
  237. if (ret)
  238. break;
  239. udelay(5000); /* 5ms write cycle timing */
  240. }
  241. if (!ret) {
  242. /* Verify the write by reading back the EEPROM and comparing */
  243. struct eeprom e2;
  244. #ifndef CONFIG_DM_I2C
  245. ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
  246. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  247. (void *)&e2, sizeof(e2));
  248. #else
  249. struct udevice *dev;
  250. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  251. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  252. CONFIG_SYS_I2C_EEPROM_ADDR,
  253. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  254. &dev);
  255. #else
  256. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  257. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  258. &dev);
  259. #endif
  260. if (!ret)
  261. ret = dm_i2c_read(dev, 0, (void *)&e2, sizeof(e2));
  262. #endif
  263. if (!ret && memcmp(&e, &e2, sizeof(e)))
  264. ret = -1;
  265. }
  266. #ifndef CONFIG_DM_I2C
  267. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  268. i2c_set_bus_num(bus);
  269. #endif
  270. #endif
  271. if (ret) {
  272. printf("Programming failed.\n");
  273. has_been_read = 0;
  274. return -1;
  275. }
  276. printf("Programming passed.\n");
  277. return 0;
  278. }
  279. /**
  280. * h2i - converts hex character into a number
  281. *
  282. * This function takes a hexadecimal character (e.g. '7' or 'C') and returns
  283. * the integer equivalent.
  284. */
  285. static inline u8 h2i(char p)
  286. {
  287. if ((p >= '0') && (p <= '9'))
  288. return p - '0';
  289. if ((p >= 'A') && (p <= 'F'))
  290. return (p - 'A') + 10;
  291. if ((p >= 'a') && (p <= 'f'))
  292. return (p - 'a') + 10;
  293. return 0;
  294. }
  295. /**
  296. * set_date - stores the build date into the EEPROM
  297. *
  298. * This function takes a pointer to a string in the format "YYMMDDhhmmss"
  299. * (2-digit year, 2-digit month, etc), converts it to a 6-byte BCD string,
  300. * and stores it in the build date field of the EEPROM local copy.
  301. */
  302. static void set_date(const char *string)
  303. {
  304. unsigned int i;
  305. if (strlen(string) != 12) {
  306. printf("Usage: mac date YYMMDDhhmmss\n");
  307. return;
  308. }
  309. for (i = 0; i < 6; i++)
  310. e.date[i] = h2i(string[2 * i]) << 4 | h2i(string[2 * i + 1]);
  311. update_crc();
  312. }
  313. /**
  314. * set_mac_address - stores a MAC address into the EEPROM
  315. *
  316. * This function takes a pointer to MAC address string
  317. * (i.e."XX:XX:XX:XX:XX:XX", where "XX" is a two-digit hex number) and
  318. * stores it in one of the MAC address fields of the EEPROM local copy.
  319. */
  320. static void set_mac_address(unsigned int index, const char *string)
  321. {
  322. char *p = (char *) string;
  323. unsigned int i;
  324. if ((index >= MAX_NUM_PORTS) || !string) {
  325. printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
  326. return;
  327. }
  328. for (i = 0; *p && (i < 6); i++) {
  329. e.mac[index][i] = simple_strtoul(p, &p, 16);
  330. if (*p == ':')
  331. p++;
  332. }
  333. update_crc();
  334. }
  335. int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  336. {
  337. char cmd;
  338. if (argc == 1) {
  339. show_eeprom();
  340. return 0;
  341. }
  342. cmd = argv[1][0];
  343. if (cmd == 'r') {
  344. read_eeprom();
  345. return 0;
  346. }
  347. if (cmd == 'i') {
  348. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  349. memcpy(e.id, "NXID", sizeof(e.id));
  350. e.version = cpu_to_be32(NXID_VERSION);
  351. #else
  352. memcpy(e.id, "CCID", sizeof(e.id));
  353. #endif
  354. update_crc();
  355. return 0;
  356. }
  357. if (!is_valid) {
  358. printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
  359. return 0;
  360. }
  361. if (argc == 2) {
  362. switch (cmd) {
  363. case 's': /* save */
  364. prog_eeprom();
  365. break;
  366. default:
  367. return cmd_usage(cmdtp);
  368. }
  369. return 0;
  370. }
  371. /* We know we have at least one parameter */
  372. switch (cmd) {
  373. case 'n': /* serial number */
  374. memset(e.sn, 0, sizeof(e.sn));
  375. strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
  376. update_crc();
  377. break;
  378. case 'e': /* errata */
  379. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  380. memset(e.errata, 0, 5);
  381. strncpy((char *)e.errata, argv[2], 4);
  382. #else
  383. e.errata[0] = argv[2][0];
  384. e.errata[1] = argv[2][1];
  385. #endif
  386. update_crc();
  387. break;
  388. case 'd': /* date BCD format YYMMDDhhmmss */
  389. set_date(argv[2]);
  390. break;
  391. case 'p': /* MAC table size */
  392. e.mac_count = simple_strtoul(argv[2], NULL, 16);
  393. update_crc();
  394. break;
  395. case '0' ... '9': /* "mac 0" through "mac 22" */
  396. set_mac_address(simple_strtoul(argv[1], NULL, 10), argv[2]);
  397. break;
  398. case 'h': /* help */
  399. default:
  400. return cmd_usage(cmdtp);
  401. }
  402. return 0;
  403. }
  404. /**
  405. * mac_read_from_eeprom - read the MAC addresses from EEPROM
  406. *
  407. * This function reads the MAC addresses from EEPROM and sets the
  408. * appropriate environment variables for each one read.
  409. *
  410. * The environment variables are only set if they haven't been set already.
  411. * This ensures that any user-saved variables are never overwritten.
  412. *
  413. * This function must be called after relocation.
  414. *
  415. * For NXID v1 EEPROMs, we support loading and up-converting the older NXID v0
  416. * format. In a v0 EEPROM, there are only eight MAC addresses and the CRC is
  417. * located at a different offset.
  418. */
  419. int mac_read_from_eeprom(void)
  420. {
  421. unsigned int i;
  422. u32 crc, crc_offset = offsetof(struct eeprom, crc);
  423. u32 *crcp; /* Pointer to the CRC in the data read from the EEPROM */
  424. puts("EEPROM: ");
  425. if (read_eeprom()) {
  426. printf("Read failed.\n");
  427. return 0;
  428. }
  429. if (!is_valid) {
  430. printf("Invalid ID (%02x %02x %02x %02x)\n",
  431. e.id[0], e.id[1], e.id[2], e.id[3]);
  432. return 0;
  433. }
  434. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  435. /*
  436. * If we've read an NXID v0 EEPROM, then we need to set the CRC offset
  437. * to where it is in v0.
  438. */
  439. if (e.version == 0)
  440. crc_offset = 0x72;
  441. #endif
  442. crc = crc32(0, (void *)&e, crc_offset);
  443. crcp = (void *)&e + crc_offset;
  444. if (crc != be32_to_cpu(*crcp)) {
  445. printf("CRC mismatch (%08x != %08x)\n", crc, be32_to_cpu(e.crc));
  446. return 0;
  447. }
  448. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  449. /*
  450. * MAC address #9 in v1 occupies the same position as the CRC in v0.
  451. * Erase it so that it's not mistaken for a MAC address. We'll
  452. * update the CRC later.
  453. */
  454. if (e.version == 0)
  455. memset(e.mac[8], 0xff, 6);
  456. #endif
  457. for (i = 0; i < min(e.mac_count, (u8)MAX_NUM_PORTS); i++) {
  458. if (memcmp(&e.mac[i], "\0\0\0\0\0\0", 6) &&
  459. memcmp(&e.mac[i], "\xFF\xFF\xFF\xFF\xFF\xFF", 6)) {
  460. char ethaddr[18];
  461. char enetvar[9];
  462. sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
  463. e.mac[i][0],
  464. e.mac[i][1],
  465. e.mac[i][2],
  466. e.mac[i][3],
  467. e.mac[i][4],
  468. e.mac[i][5]);
  469. sprintf(enetvar, i ? "eth%daddr" : "ethaddr", i);
  470. /* Only initialize environment variables that are blank
  471. * (i.e. have not yet been set)
  472. */
  473. if (!env_get(enetvar))
  474. env_set(enetvar, ethaddr);
  475. }
  476. }
  477. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  478. printf("%c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
  479. be32_to_cpu(e.version));
  480. #else
  481. printf("%c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
  482. #endif
  483. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  484. /*
  485. * Now we need to upconvert the data into v1 format. We do this last so
  486. * that at boot time, U-Boot will still say "NXID v0".
  487. */
  488. if (e.version == 0) {
  489. e.version = cpu_to_be32(NXID_VERSION);
  490. update_crc();
  491. }
  492. #endif
  493. return 0;
  494. }
  495. #ifdef CONFIG_SYS_I2C_EEPROM_CCID
  496. /**
  497. * get_cpu_board_revision - get the CPU board revision on 85xx boards
  498. *
  499. * Read the EEPROM to determine the board revision.
  500. *
  501. * This function is called before relocation, so we need to read a private
  502. * copy of the EEPROM into a local variable on the stack.
  503. *
  504. * Also, we assume that CONFIG_SYS_EEPROM_BUS_NUM == CONFIG_SYS_SPD_BUS_NUM. The global
  505. * variable i2c_bus_num must be compile-time initialized to CONFIG_SYS_SPD_BUS_NUM,
  506. * so that the SPD code will work. This means that all pre-relocation I2C
  507. * operations can only occur on the CONFIG_SYS_SPD_BUS_NUM bus. So if
  508. * CONFIG_SYS_EEPROM_BUS_NUM != CONFIG_SYS_SPD_BUS_NUM, then we can't read the EEPROM when
  509. * this function is called. Oh well.
  510. */
  511. unsigned int get_cpu_board_revision(void)
  512. {
  513. struct board_eeprom {
  514. u32 id; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
  515. u8 major; /* 0x04 Board revision, major */
  516. u8 minor; /* 0x05 Board revision, minor */
  517. } be;
  518. #ifndef CONFIG_DM_I2C
  519. i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  520. (void *)&be, sizeof(be));
  521. #else
  522. struct udevice *dev;
  523. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  524. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  525. CONFIG_SYS_I2C_EEPROM_ADDR,
  526. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  527. &dev);
  528. #else
  529. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  530. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  531. &dev)
  532. #endif
  533. if (!ret)
  534. dm_i2c_read(dev, 0, (void *)&be, sizeof(be));
  535. #endif
  536. if (be.id != (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
  537. return MPC85XX_CPU_BOARD_REV(0, 0);
  538. if ((be.major == 0xff) && (be.minor == 0xff))
  539. return MPC85XX_CPU_BOARD_REV(0, 0);
  540. return MPC85XX_CPU_BOARD_REV(be.major, be.minor);
  541. }
  542. #endif