sys_eeprom.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. #if !CONFIG_IS_ENABLED(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. #if !CONFIG_IS_ENABLED(DM_I2C)
  144. bus = i2c_get_bus_num();
  145. i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
  146. #endif
  147. #endif
  148. #if !CONFIG_IS_ENABLED(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,
  157. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, &dev);
  158. #else
  159. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  160. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, &dev);
  161. #endif
  162. if (!ret)
  163. ret = dm_i2c_read(dev, 0, (void *)&e, sizeof(e));
  164. #endif
  165. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  166. #if !CONFIG_IS_ENABLED(DM_I2C)
  167. i2c_set_bus_num(bus);
  168. #endif
  169. #endif
  170. #ifdef DEBUG
  171. show_eeprom();
  172. #endif
  173. has_been_read = (ret == 0) ? 1 : 0;
  174. return ret;
  175. }
  176. /**
  177. * update_crc - update the CRC
  178. *
  179. * This function should be called after each update to the EEPROM structure,
  180. * to make sure the CRC is always correct.
  181. */
  182. static void update_crc(void)
  183. {
  184. u32 crc;
  185. crc = crc32(0, (void *)&e, sizeof(e) - 4);
  186. e.crc = cpu_to_be32(crc);
  187. }
  188. /**
  189. * prog_eeprom - write the EEPROM from memory
  190. */
  191. static int prog_eeprom(void)
  192. {
  193. int ret = 0;
  194. int i;
  195. void *p;
  196. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  197. #if !CONFIG_IS_ENABLED(DM_I2C)
  198. unsigned int bus;
  199. #endif
  200. #endif
  201. /* Set the reserved values to 0xFF */
  202. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  203. e.res_0 = 0xFF;
  204. memset(e.res_1, 0xFF, sizeof(e.res_1));
  205. #else
  206. memset(e.res_0, 0xFF, sizeof(e.res_0));
  207. #endif
  208. update_crc();
  209. #if !CONFIG_IS_ENABLED(DM_I2C)
  210. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  211. bus = i2c_get_bus_num();
  212. i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
  213. #endif
  214. #endif
  215. /*
  216. * The AT24C02 datasheet says that data can only be written in page
  217. * mode, which means 8 bytes at a time, and it takes up to 5ms to
  218. * complete a given write.
  219. */
  220. for (i = 0, p = &e; i < sizeof(e); i += 8, p += 8) {
  221. #if !CONFIG_IS_ENABLED(DM_I2C)
  222. ret = i2c_write(CONFIG_SYS_I2C_EEPROM_ADDR, i,
  223. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  224. p, min((int)(sizeof(e) - i), 8));
  225. #else
  226. struct udevice *dev;
  227. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  228. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  229. CONFIG_SYS_I2C_EEPROM_ADDR,
  230. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  231. &dev);
  232. #else
  233. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  234. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  235. &dev);
  236. #endif
  237. if (!ret)
  238. ret = dm_i2c_write(dev, i, p, min((int)(sizeof(e) - i),
  239. 8));
  240. #endif
  241. if (ret)
  242. break;
  243. udelay(5000); /* 5ms write cycle timing */
  244. }
  245. if (!ret) {
  246. /* Verify the write by reading back the EEPROM and comparing */
  247. struct eeprom e2;
  248. #if !CONFIG_IS_ENABLED(DM_I2C)
  249. ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
  250. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  251. (void *)&e2, sizeof(e2));
  252. #else
  253. struct udevice *dev;
  254. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  255. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  256. CONFIG_SYS_I2C_EEPROM_ADDR,
  257. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  258. &dev);
  259. #else
  260. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  261. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  262. &dev);
  263. #endif
  264. if (!ret)
  265. ret = dm_i2c_read(dev, 0, (void *)&e2, sizeof(e2));
  266. #endif
  267. if (!ret && memcmp(&e, &e2, sizeof(e)))
  268. ret = -1;
  269. }
  270. #if !CONFIG_IS_ENABLED(DM_I2C)
  271. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  272. i2c_set_bus_num(bus);
  273. #endif
  274. #endif
  275. if (ret) {
  276. printf("Programming failed.\n");
  277. has_been_read = 0;
  278. return -1;
  279. }
  280. printf("Programming passed.\n");
  281. return 0;
  282. }
  283. /**
  284. * h2i - converts hex character into a number
  285. *
  286. * This function takes a hexadecimal character (e.g. '7' or 'C') and returns
  287. * the integer equivalent.
  288. */
  289. static inline u8 h2i(char p)
  290. {
  291. if ((p >= '0') && (p <= '9'))
  292. return p - '0';
  293. if ((p >= 'A') && (p <= 'F'))
  294. return (p - 'A') + 10;
  295. if ((p >= 'a') && (p <= 'f'))
  296. return (p - 'a') + 10;
  297. return 0;
  298. }
  299. /**
  300. * set_date - stores the build date into the EEPROM
  301. *
  302. * This function takes a pointer to a string in the format "YYMMDDhhmmss"
  303. * (2-digit year, 2-digit month, etc), converts it to a 6-byte BCD string,
  304. * and stores it in the build date field of the EEPROM local copy.
  305. */
  306. static void set_date(const char *string)
  307. {
  308. unsigned int i;
  309. if (strlen(string) != 12) {
  310. printf("Usage: mac date YYMMDDhhmmss\n");
  311. return;
  312. }
  313. for (i = 0; i < 6; i++)
  314. e.date[i] = h2i(string[2 * i]) << 4 | h2i(string[2 * i + 1]);
  315. update_crc();
  316. }
  317. /**
  318. * set_mac_address - stores a MAC address into the EEPROM
  319. *
  320. * This function takes a pointer to MAC address string
  321. * (i.e."XX:XX:XX:XX:XX:XX", where "XX" is a two-digit hex number) and
  322. * stores it in one of the MAC address fields of the EEPROM local copy.
  323. */
  324. static void set_mac_address(unsigned int index, const char *string)
  325. {
  326. char *p = (char *) string;
  327. unsigned int i;
  328. if ((index >= MAX_NUM_PORTS) || !string) {
  329. printf("Usage: mac <n> XX:XX:XX:XX:XX:XX\n");
  330. return;
  331. }
  332. for (i = 0; *p && (i < 6); i++) {
  333. e.mac[index][i] = hextoul(p, &p);
  334. if (*p == ':')
  335. p++;
  336. }
  337. update_crc();
  338. }
  339. int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  340. {
  341. char cmd;
  342. if (argc == 1) {
  343. show_eeprom();
  344. return 0;
  345. }
  346. cmd = argv[1][0];
  347. if (cmd == 'r') {
  348. read_eeprom();
  349. return 0;
  350. }
  351. if (cmd == 'i') {
  352. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  353. memcpy(e.id, "NXID", sizeof(e.id));
  354. e.version = cpu_to_be32(NXID_VERSION);
  355. #else
  356. memcpy(e.id, "CCID", sizeof(e.id));
  357. #endif
  358. update_crc();
  359. return 0;
  360. }
  361. if (!is_valid) {
  362. printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
  363. return 0;
  364. }
  365. if (argc == 2) {
  366. switch (cmd) {
  367. case 's': /* save */
  368. prog_eeprom();
  369. break;
  370. default:
  371. return cmd_usage(cmdtp);
  372. }
  373. return 0;
  374. }
  375. /* We know we have at least one parameter */
  376. switch (cmd) {
  377. case 'n': /* serial number */
  378. memset(e.sn, 0, sizeof(e.sn));
  379. strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
  380. update_crc();
  381. break;
  382. case 'e': /* errata */
  383. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  384. memset(e.errata, 0, 5);
  385. strncpy((char *)e.errata, argv[2], 4);
  386. #else
  387. e.errata[0] = argv[2][0];
  388. e.errata[1] = argv[2][1];
  389. #endif
  390. update_crc();
  391. break;
  392. case 'd': /* date BCD format YYMMDDhhmmss */
  393. set_date(argv[2]);
  394. break;
  395. case 'p': /* MAC table size */
  396. e.mac_count = hextoul(argv[2], NULL);
  397. update_crc();
  398. break;
  399. case '0' ... '9': /* "mac 0" through "mac 22" */
  400. set_mac_address(dectoul(argv[1], NULL), argv[2]);
  401. break;
  402. case 'h': /* help */
  403. default:
  404. return cmd_usage(cmdtp);
  405. }
  406. return 0;
  407. }
  408. /**
  409. * mac_read_from_eeprom - read the MAC addresses from EEPROM
  410. *
  411. * This function reads the MAC addresses from EEPROM and sets the
  412. * appropriate environment variables for each one read.
  413. *
  414. * The environment variables are only set if they haven't been set already.
  415. * This ensures that any user-saved variables are never overwritten.
  416. *
  417. * This function must be called after relocation.
  418. *
  419. * For NXID v1 EEPROMs, we support loading and up-converting the older NXID v0
  420. * format. In a v0 EEPROM, there are only eight MAC addresses and the CRC is
  421. * located at a different offset.
  422. */
  423. int mac_read_from_eeprom(void)
  424. {
  425. unsigned int i;
  426. u32 crc, crc_offset = offsetof(struct eeprom, crc);
  427. u32 *crcp; /* Pointer to the CRC in the data read from the EEPROM */
  428. puts("EEPROM: ");
  429. if (read_eeprom()) {
  430. printf("Read failed.\n");
  431. return 0;
  432. }
  433. if (!is_valid) {
  434. printf("Invalid ID (%02x %02x %02x %02x)\n",
  435. e.id[0], e.id[1], e.id[2], e.id[3]);
  436. return 0;
  437. }
  438. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  439. /*
  440. * If we've read an NXID v0 EEPROM, then we need to set the CRC offset
  441. * to where it is in v0.
  442. */
  443. if (e.version == 0)
  444. crc_offset = 0x72;
  445. #endif
  446. crc = crc32(0, (void *)&e, crc_offset);
  447. crcp = (void *)&e + crc_offset;
  448. if (crc != be32_to_cpu(*crcp)) {
  449. printf("CRC mismatch (%08x != %08x)\n", crc, be32_to_cpu(e.crc));
  450. return 0;
  451. }
  452. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  453. /*
  454. * MAC address #9 in v1 occupies the same position as the CRC in v0.
  455. * Erase it so that it's not mistaken for a MAC address. We'll
  456. * update the CRC later.
  457. */
  458. if (e.version == 0)
  459. memset(e.mac[8], 0xff, 6);
  460. #endif
  461. for (i = 0; i < min(e.mac_count, (u8)MAX_NUM_PORTS); i++) {
  462. if (memcmp(&e.mac[i], "\0\0\0\0\0\0", 6) &&
  463. memcmp(&e.mac[i], "\xFF\xFF\xFF\xFF\xFF\xFF", 6)) {
  464. char ethaddr[18];
  465. char enetvar[9];
  466. sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
  467. e.mac[i][0],
  468. e.mac[i][1],
  469. e.mac[i][2],
  470. e.mac[i][3],
  471. e.mac[i][4],
  472. e.mac[i][5]);
  473. sprintf(enetvar, i ? "eth%daddr" : "ethaddr", i);
  474. /* Only initialize environment variables that are blank
  475. * (i.e. have not yet been set)
  476. */
  477. if (!env_get(enetvar))
  478. env_set(enetvar, ethaddr);
  479. }
  480. }
  481. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  482. printf("%c%c%c%c v%u\n", e.id[0], e.id[1], e.id[2], e.id[3],
  483. be32_to_cpu(e.version));
  484. #else
  485. printf("%c%c%c%c\n", e.id[0], e.id[1], e.id[2], e.id[3]);
  486. #endif
  487. #ifdef CONFIG_SYS_I2C_EEPROM_NXID
  488. /*
  489. * Now we need to upconvert the data into v1 format. We do this last so
  490. * that at boot time, U-Boot will still say "NXID v0".
  491. */
  492. if (e.version == 0) {
  493. e.version = cpu_to_be32(NXID_VERSION);
  494. update_crc();
  495. }
  496. #endif
  497. return 0;
  498. }
  499. #ifdef CONFIG_SYS_I2C_EEPROM_CCID
  500. /**
  501. * get_cpu_board_revision - get the CPU board revision on 85xx boards
  502. *
  503. * Read the EEPROM to determine the board revision.
  504. *
  505. * This function is called before relocation, so we need to read a private
  506. * copy of the EEPROM into a local variable on the stack.
  507. *
  508. * Also, we assume that CONFIG_SYS_EEPROM_BUS_NUM == CONFIG_SYS_SPD_BUS_NUM. The global
  509. * variable i2c_bus_num must be compile-time initialized to CONFIG_SYS_SPD_BUS_NUM,
  510. * so that the SPD code will work. This means that all pre-relocation I2C
  511. * operations can only occur on the CONFIG_SYS_SPD_BUS_NUM bus. So if
  512. * CONFIG_SYS_EEPROM_BUS_NUM != CONFIG_SYS_SPD_BUS_NUM, then we can't read the EEPROM when
  513. * this function is called. Oh well.
  514. */
  515. unsigned int get_cpu_board_revision(void)
  516. {
  517. struct board_eeprom {
  518. u32 id; /* 0x00 - 0x03 EEPROM Tag 'CCID' */
  519. u8 major; /* 0x04 Board revision, major */
  520. u8 minor; /* 0x05 Board revision, minor */
  521. } be;
  522. #if !CONFIG_IS_ENABLED(DM_I2C)
  523. i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  524. (void *)&be, sizeof(be));
  525. #else
  526. struct udevice *dev;
  527. int ret;
  528. #ifdef CONFIG_SYS_EEPROM_BUS_NUM
  529. ret = i2c_get_chip_for_busnum(CONFIG_SYS_EEPROM_BUS_NUM,
  530. CONFIG_SYS_I2C_EEPROM_ADDR,
  531. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  532. &dev);
  533. #else
  534. ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_EEPROM_ADDR,
  535. CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
  536. &dev);
  537. #endif
  538. if (!ret)
  539. dm_i2c_read(dev, 0, (void *)&be, sizeof(be));
  540. #endif
  541. if (be.id != (('C' << 24) | ('C' << 16) | ('I' << 8) | 'D'))
  542. return MPC85XX_CPU_BOARD_REV(0, 0);
  543. if ((be.major == 0xff) && (be.minor == 0xff))
  544. return MPC85XX_CPU_BOARD_REV(0, 0);
  545. return MPC85XX_CPU_BOARD_REV(be.major, be.minor);
  546. }
  547. #endif