sys_eeprom.c 15 KB

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