cmd_i2c.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. /*
  2. * (C) Copyright 2001
  3. * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * I2C Functions similar to the standard memory functions.
  25. *
  26. * There are several parameters in many of the commands that bear further
  27. * explanations:
  28. *
  29. * Two of the commands (imm and imw) take a byte/word/long modifier
  30. * (e.g. imm.w specifies the word-length modifier). This was done to
  31. * allow manipulating word-length registers. It was not done on any other
  32. * commands because it was not deemed useful.
  33. *
  34. * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
  35. * Each I2C chip on the bus has a unique address. On the I2C data bus,
  36. * the address is the upper seven bits and the LSB is the "read/write"
  37. * bit. Note that the {i2c_chip} address specified on the command
  38. * line is not shifted up: e.g. a typical EEPROM memory chip may have
  39. * an I2C address of 0x50, but the data put on the bus will be 0xA0
  40. * for write and 0xA1 for read. This "non shifted" address notation
  41. * matches at least half of the data sheets :-/.
  42. *
  43. * {addr} is the address (or offset) within the chip. Small memory
  44. * chips have 8 bit addresses. Large memory chips have 16 bit
  45. * addresses. Other memory chips have 9, 10, or 11 bit addresses.
  46. * Many non-memory chips have multiple registers and {addr} is used
  47. * as the register index. Some non-memory chips have only one register
  48. * and therefore don't need any {addr} parameter.
  49. *
  50. * The default {addr} parameter is one byte (.1) which works well for
  51. * memories and registers with 8 bits of address space.
  52. *
  53. * You can specify the length of the {addr} field with the optional .0,
  54. * .1, or .2 modifier (similar to the .b, .w, .l modifier). If you are
  55. * manipulating a single register device which doesn't use an address
  56. * field, use "0.0" for the address and the ".0" length field will
  57. * suppress the address in the I2C data stream. This also works for
  58. * successive reads using the I2C auto-incrementing memory pointer.
  59. *
  60. * If you are manipulating a large memory with 2-byte addresses, use
  61. * the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
  62. *
  63. * Then there are the unfortunate memory chips that spill the most
  64. * significant 1, 2, or 3 bits of address into the chip address byte.
  65. * This effectively makes one chip (logically) look like 2, 4, or
  66. * 8 chips. This is handled (awkwardly) by #defining
  67. * CFG_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
  68. * {addr} field (since .1 is the default, it doesn't actually have to
  69. * be specified). Examples: given a memory chip at I2C chip address
  70. * 0x50, the following would happen...
  71. * imd 50 0 10 display 16 bytes starting at 0x000
  72. * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
  73. * imd 50 100 10 display 16 bytes starting at 0x100
  74. * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
  75. * imd 50 210 10 display 16 bytes starting at 0x210
  76. * On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
  77. * This is awfully ugly. It would be nice if someone would think up
  78. * a better way of handling this.
  79. *
  80. * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
  81. */
  82. #include <common.h>
  83. #include <command.h>
  84. #include <i2c.h>
  85. #include <asm/byteorder.h>
  86. #if (CONFIG_COMMANDS & CFG_CMD_I2C)
  87. /* Display values from last command.
  88. * Memory modify remembered values are different from display memory.
  89. */
  90. static uchar i2c_dp_last_chip;
  91. static uint i2c_dp_last_addr;
  92. static uint i2c_dp_last_alen;
  93. static uint i2c_dp_last_length = 0x10;
  94. static uchar i2c_mm_last_chip;
  95. static uint i2c_mm_last_addr;
  96. static uint i2c_mm_last_alen;
  97. #if defined(CFG_I2C_NOPROBES)
  98. static uchar i2c_no_probes[] = CFG_I2C_NOPROBES;
  99. #endif
  100. static int
  101. mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]);
  102. extern int cmd_get_data_size(char* arg, int default_size);
  103. /*
  104. * Syntax:
  105. * imd {i2c_chip} {addr}{.0, .1, .2} {len}
  106. */
  107. #define DISP_LINE_LEN 16
  108. int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  109. {
  110. u_char chip;
  111. uint addr, alen, length;
  112. int j, nbytes, linebytes;
  113. /* We use the last specified parameters, unless new ones are
  114. * entered.
  115. */
  116. chip = i2c_dp_last_chip;
  117. addr = i2c_dp_last_addr;
  118. alen = i2c_dp_last_alen;
  119. length = i2c_dp_last_length;
  120. if (argc < 3) {
  121. printf ("Usage:\n%s\n", cmdtp->usage);
  122. return 1;
  123. }
  124. if ((flag & CMD_FLAG_REPEAT) == 0) {
  125. /*
  126. * New command specified.
  127. */
  128. alen = 1;
  129. /*
  130. * I2C chip address
  131. */
  132. chip = simple_strtoul(argv[1], NULL, 16);
  133. /*
  134. * I2C data address within the chip. This can be 1 or
  135. * 2 bytes long. Some day it might be 3 bytes long :-).
  136. */
  137. addr = simple_strtoul(argv[2], NULL, 16);
  138. alen = 1;
  139. for(j = 0; j < 8; j++) {
  140. if (argv[2][j] == '.') {
  141. alen = argv[2][j+1] - '0';
  142. if (alen > 4) {
  143. printf ("Usage:\n%s\n", cmdtp->usage);
  144. return 1;
  145. }
  146. break;
  147. } else if (argv[2][j] == '\0') {
  148. break;
  149. }
  150. }
  151. /*
  152. * If another parameter, it is the length to display.
  153. * Length is the number of objects, not number of bytes.
  154. */
  155. if (argc > 3)
  156. length = simple_strtoul(argv[3], NULL, 16);
  157. }
  158. /*
  159. * Print the lines.
  160. *
  161. * We buffer all read data, so we can make sure data is read only
  162. * once.
  163. */
  164. nbytes = length;
  165. do {
  166. unsigned char linebuf[DISP_LINE_LEN];
  167. unsigned char *cp;
  168. linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
  169. if(i2c_read(chip, addr, alen, linebuf, linebytes) != 0) {
  170. puts ("Error reading the chip.\n");
  171. } else {
  172. printf("%04x:", addr);
  173. cp = linebuf;
  174. for (j=0; j<linebytes; j++) {
  175. printf(" %02x", *cp++);
  176. addr++;
  177. }
  178. puts (" ");
  179. cp = linebuf;
  180. for (j=0; j<linebytes; j++) {
  181. if ((*cp < 0x20) || (*cp > 0x7e))
  182. puts (".");
  183. else
  184. printf("%c", *cp);
  185. cp++;
  186. }
  187. putc ('\n');
  188. }
  189. nbytes -= linebytes;
  190. } while (nbytes > 0);
  191. i2c_dp_last_chip = chip;
  192. i2c_dp_last_addr = addr;
  193. i2c_dp_last_alen = alen;
  194. i2c_dp_last_length = length;
  195. return 0;
  196. }
  197. int do_i2c_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  198. {
  199. return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
  200. }
  201. int do_i2c_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  202. {
  203. return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
  204. }
  205. /* Write (fill) memory
  206. *
  207. * Syntax:
  208. * imw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
  209. */
  210. int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  211. {
  212. uchar chip;
  213. ulong addr;
  214. uint alen;
  215. uchar byte;
  216. int count;
  217. int j;
  218. if ((argc < 4) || (argc > 5)) {
  219. printf ("Usage:\n%s\n", cmdtp->usage);
  220. return 1;
  221. }
  222. /*
  223. * Chip is always specified.
  224. */
  225. chip = simple_strtoul(argv[1], NULL, 16);
  226. /*
  227. * Address is always specified.
  228. */
  229. addr = simple_strtoul(argv[2], NULL, 16);
  230. alen = 1;
  231. for(j = 0; j < 8; j++) {
  232. if (argv[2][j] == '.') {
  233. alen = argv[2][j+1] - '0';
  234. if(alen > 4) {
  235. printf ("Usage:\n%s\n", cmdtp->usage);
  236. return 1;
  237. }
  238. break;
  239. } else if (argv[2][j] == '\0') {
  240. break;
  241. }
  242. }
  243. /*
  244. * Value to write is always specified.
  245. */
  246. byte = simple_strtoul(argv[3], NULL, 16);
  247. /*
  248. * Optional count
  249. */
  250. if(argc == 5) {
  251. count = simple_strtoul(argv[4], NULL, 16);
  252. } else {
  253. count = 1;
  254. }
  255. while (count-- > 0) {
  256. if(i2c_write(chip, addr++, alen, &byte, 1) != 0) {
  257. puts ("Error writing the chip.\n");
  258. }
  259. /*
  260. * Wait for the write to complete. The write can take
  261. * up to 10mSec (we allow a little more time).
  262. *
  263. * On some chips, while the write is in progress, the
  264. * chip doesn't respond. This apparently isn't a
  265. * universal feature so we don't take advantage of it.
  266. */
  267. /*
  268. * No write delay with FRAM devices.
  269. */
  270. #if !defined(CFG_I2C_FRAM)
  271. udelay(11000);
  272. #endif
  273. #if 0
  274. for(timeout = 0; timeout < 10; timeout++) {
  275. udelay(2000);
  276. if(i2c_probe(chip) == 0)
  277. break;
  278. }
  279. #endif
  280. }
  281. return (0);
  282. }
  283. /* Calculate a CRC on memory
  284. *
  285. * Syntax:
  286. * icrc32 {i2c_chip} {addr}{.0, .1, .2} {count}
  287. */
  288. int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  289. {
  290. uchar chip;
  291. ulong addr;
  292. uint alen;
  293. int count;
  294. uchar byte;
  295. ulong crc;
  296. ulong err;
  297. int j;
  298. if (argc < 4) {
  299. printf ("Usage:\n%s\n", cmdtp->usage);
  300. return 1;
  301. }
  302. /*
  303. * Chip is always specified.
  304. */
  305. chip = simple_strtoul(argv[1], NULL, 16);
  306. /*
  307. * Address is always specified.
  308. */
  309. addr = simple_strtoul(argv[2], NULL, 16);
  310. alen = 1;
  311. for(j = 0; j < 8; j++) {
  312. if (argv[2][j] == '.') {
  313. alen = argv[2][j+1] - '0';
  314. if(alen > 4) {
  315. printf ("Usage:\n%s\n", cmdtp->usage);
  316. return 1;
  317. }
  318. break;
  319. } else if (argv[2][j] == '\0') {
  320. break;
  321. }
  322. }
  323. /*
  324. * Count is always specified
  325. */
  326. count = simple_strtoul(argv[3], NULL, 16);
  327. printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
  328. /*
  329. * CRC a byte at a time. This is going to be slooow, but hey, the
  330. * memories are small and slow too so hopefully nobody notices.
  331. */
  332. crc = 0;
  333. err = 0;
  334. while(count-- > 0) {
  335. if(i2c_read(chip, addr, alen, &byte, 1) != 0) {
  336. err++;
  337. }
  338. crc = crc32 (crc, &byte, 1);
  339. addr++;
  340. }
  341. if(err > 0)
  342. {
  343. puts ("Error reading the chip,\n");
  344. } else {
  345. printf ("%08lx\n", crc);
  346. }
  347. return 0;
  348. }
  349. /* Modify memory.
  350. *
  351. * Syntax:
  352. * imm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  353. * inm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  354. */
  355. static int
  356. mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
  357. {
  358. uchar chip;
  359. ulong addr;
  360. uint alen;
  361. ulong data;
  362. int size = 1;
  363. int nbytes;
  364. int j;
  365. extern char console_buffer[];
  366. if (argc != 3) {
  367. printf ("Usage:\n%s\n", cmdtp->usage);
  368. return 1;
  369. }
  370. #ifdef CONFIG_BOOT_RETRY_TIME
  371. reset_cmd_timeout(); /* got a good command to get here */
  372. #endif
  373. /*
  374. * We use the last specified parameters, unless new ones are
  375. * entered.
  376. */
  377. chip = i2c_mm_last_chip;
  378. addr = i2c_mm_last_addr;
  379. alen = i2c_mm_last_alen;
  380. if ((flag & CMD_FLAG_REPEAT) == 0) {
  381. /*
  382. * New command specified. Check for a size specification.
  383. * Defaults to byte if no or incorrect specification.
  384. */
  385. size = cmd_get_data_size(argv[0], 1);
  386. /*
  387. * Chip is always specified.
  388. */
  389. chip = simple_strtoul(argv[1], NULL, 16);
  390. /*
  391. * Address is always specified.
  392. */
  393. addr = simple_strtoul(argv[2], NULL, 16);
  394. alen = 1;
  395. for(j = 0; j < 8; j++) {
  396. if (argv[2][j] == '.') {
  397. alen = argv[2][j+1] - '0';
  398. if(alen > 4) {
  399. printf ("Usage:\n%s\n", cmdtp->usage);
  400. return 1;
  401. }
  402. break;
  403. } else if (argv[2][j] == '\0') {
  404. break;
  405. }
  406. }
  407. }
  408. /*
  409. * Print the address, followed by value. Then accept input for
  410. * the next value. A non-converted value exits.
  411. */
  412. do {
  413. printf("%08lx:", addr);
  414. if(i2c_read(chip, addr, alen, (uchar *)&data, size) != 0) {
  415. puts ("\nError reading the chip,\n");
  416. } else {
  417. data = cpu_to_be32(data);
  418. if(size == 1) {
  419. printf(" %02lx", (data >> 24) & 0x000000FF);
  420. } else if(size == 2) {
  421. printf(" %04lx", (data >> 16) & 0x0000FFFF);
  422. } else {
  423. printf(" %08lx", data);
  424. }
  425. }
  426. nbytes = readline (" ? ");
  427. if (nbytes == 0) {
  428. /*
  429. * <CR> pressed as only input, don't modify current
  430. * location and move to next.
  431. */
  432. if (incrflag)
  433. addr += size;
  434. nbytes = size;
  435. #ifdef CONFIG_BOOT_RETRY_TIME
  436. reset_cmd_timeout(); /* good enough to not time out */
  437. #endif
  438. }
  439. #ifdef CONFIG_BOOT_RETRY_TIME
  440. else if (nbytes == -2) {
  441. break; /* timed out, exit the command */
  442. }
  443. #endif
  444. else {
  445. char *endp;
  446. data = simple_strtoul(console_buffer, &endp, 16);
  447. if(size == 1) {
  448. data = data << 24;
  449. } else if(size == 2) {
  450. data = data << 16;
  451. }
  452. data = be32_to_cpu(data);
  453. nbytes = endp - console_buffer;
  454. if (nbytes) {
  455. #ifdef CONFIG_BOOT_RETRY_TIME
  456. /*
  457. * good enough to not time out
  458. */
  459. reset_cmd_timeout();
  460. #endif
  461. if(i2c_write(chip, addr, alen, (uchar *)&data, size) != 0) {
  462. puts ("Error writing the chip.\n");
  463. }
  464. #ifdef CFG_EEPROM_PAGE_WRITE_DELAY_MS
  465. udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  466. #endif
  467. if (incrflag)
  468. addr += size;
  469. }
  470. }
  471. } while (nbytes);
  472. chip = i2c_mm_last_chip;
  473. addr = i2c_mm_last_addr;
  474. alen = i2c_mm_last_alen;
  475. return 0;
  476. }
  477. /*
  478. * Syntax:
  479. * iprobe {addr}{.0, .1, .2}
  480. */
  481. int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  482. {
  483. int j;
  484. #if defined(CFG_I2C_NOPROBES)
  485. int k, skip;
  486. #endif
  487. puts ("Valid chip addresses:");
  488. for(j = 0; j < 128; j++) {
  489. #if defined(CFG_I2C_NOPROBES)
  490. skip = 0;
  491. for (k = 0; k < sizeof(i2c_no_probes); k++){
  492. if (j == i2c_no_probes[k]){
  493. skip = 1;
  494. break;
  495. }
  496. }
  497. if (skip)
  498. continue;
  499. #endif
  500. if(i2c_probe(j) == 0) {
  501. printf(" %02X", j);
  502. }
  503. }
  504. putc ('\n');
  505. #if defined(CFG_I2C_NOPROBES)
  506. puts ("Excluded chip addresses:");
  507. for( k = 0; k < sizeof(i2c_no_probes); k++ )
  508. printf(" %02X", i2c_no_probes[k] );
  509. putc ('\n');
  510. #endif
  511. return 0;
  512. }
  513. /*
  514. * Syntax:
  515. * iloop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
  516. * {length} - Number of bytes to read
  517. * {delay} - A DECIMAL number and defaults to 1000 uSec
  518. */
  519. int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  520. {
  521. u_char chip;
  522. ulong alen;
  523. uint addr;
  524. uint length;
  525. u_char bytes[16];
  526. int delay;
  527. int j;
  528. if (argc < 3) {
  529. printf ("Usage:\n%s\n", cmdtp->usage);
  530. return 1;
  531. }
  532. /*
  533. * Chip is always specified.
  534. */
  535. chip = simple_strtoul(argv[1], NULL, 16);
  536. /*
  537. * Address is always specified.
  538. */
  539. addr = simple_strtoul(argv[2], NULL, 16);
  540. alen = 1;
  541. for(j = 0; j < 8; j++) {
  542. if (argv[2][j] == '.') {
  543. alen = argv[2][j+1] - '0';
  544. if (alen > 4) {
  545. printf ("Usage:\n%s\n", cmdtp->usage);
  546. return 1;
  547. }
  548. break;
  549. } else if (argv[2][j] == '\0') {
  550. break;
  551. }
  552. }
  553. /*
  554. * Length is the number of objects, not number of bytes.
  555. */
  556. length = 1;
  557. length = simple_strtoul(argv[3], NULL, 16);
  558. if(length > sizeof(bytes)) {
  559. length = sizeof(bytes);
  560. }
  561. /*
  562. * The delay time (uSec) is optional.
  563. */
  564. delay = 1000;
  565. if (argc > 3) {
  566. delay = simple_strtoul(argv[4], NULL, 10);
  567. }
  568. /*
  569. * Run the loop...
  570. */
  571. while(1) {
  572. if(i2c_read(chip, addr, alen, bytes, length) != 0) {
  573. puts ("Error reading the chip.\n");
  574. }
  575. udelay(delay);
  576. }
  577. /* NOTREACHED */
  578. return 0;
  579. }
  580. /*
  581. * The SDRAM command is separately configured because many
  582. * (most?) embedded boards don't use SDRAM DIMMs.
  583. */
  584. #if (CONFIG_COMMANDS & CFG_CMD_SDRAM)
  585. /*
  586. * Syntax:
  587. * sdram {i2c_chip}
  588. */
  589. int do_sdram ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  590. {
  591. u_char chip;
  592. u_char data[128];
  593. u_char cksum;
  594. int j;
  595. if (argc < 2) {
  596. printf ("Usage:\n%s\n", cmdtp->usage);
  597. return 1;
  598. }
  599. /*
  600. * Chip is always specified.
  601. */
  602. chip = simple_strtoul(argv[1], NULL, 16);
  603. if(i2c_read(chip, 0, 1, data, sizeof(data)) != 0) {
  604. puts ("No SDRAM Serial Presence Detect found.\n");
  605. return 1;
  606. }
  607. cksum = 0;
  608. for (j = 0; j < 63; j++) {
  609. cksum += data[j];
  610. }
  611. if(cksum != data[63]) {
  612. printf ("WARNING: Configuration data checksum failure:\n"
  613. " is 0x%02x, calculated 0x%02x\n",
  614. data[63], cksum);
  615. }
  616. printf("SPD data revision %d.%d\n",
  617. (data[62] >> 4) & 0x0F, data[62] & 0x0F);
  618. printf("Bytes used 0x%02X\n", data[0]);
  619. printf("Serial memory size 0x%02X\n", 1 << data[1]);
  620. puts ("Memory type ");
  621. switch(data[2]) {
  622. case 2: puts ("EDO\n"); break;
  623. case 4: puts ("SDRAM\n"); break;
  624. default: puts ("unknown\n"); break;
  625. }
  626. puts ("Row address bits ");
  627. if((data[3] & 0x00F0) == 0) {
  628. printf("%d\n", data[3] & 0x0F);
  629. } else {
  630. printf("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
  631. }
  632. puts ("Column address bits ");
  633. if((data[4] & 0x00F0) == 0) {
  634. printf("%d\n", data[4] & 0x0F);
  635. } else {
  636. printf("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
  637. }
  638. printf("Module rows %d\n", data[5]);
  639. printf("Module data width %d bits\n", (data[7] << 8) | data[6]);
  640. puts ("Interface signal levels ");
  641. switch(data[8]) {
  642. case 0: puts ("5.0v/TTL\n"); break;
  643. case 1: puts ("LVTTL\n"); break;
  644. case 2: puts ("HSTL 1.5\n"); break;
  645. case 3: puts ("SSTL 3.3\n"); break;
  646. case 4: puts ("SSTL 2.5\n"); break;
  647. default: puts ("unknown\n"); break;
  648. }
  649. printf("SDRAM cycle time %d.%d nS\n",
  650. (data[9] >> 4) & 0x0F, data[9] & 0x0F);
  651. printf("SDRAM access time %d.%d nS\n",
  652. (data[10] >> 4) & 0x0F, data[10] & 0x0F);
  653. puts ("EDC configuration ");
  654. switch(data[11]) {
  655. case 0: puts ("None\n"); break;
  656. case 1: puts ("Parity\n"); break;
  657. case 2: puts ("ECC\n"); break;
  658. default: puts ("unknown\n"); break;
  659. }
  660. if((data[12] & 0x80) == 0) {
  661. puts ("No self refresh, rate ");
  662. } else {
  663. puts ("Self refresh, rate ");
  664. }
  665. switch(data[12] & 0x7F) {
  666. case 0: puts ("15.625uS\n"); break;
  667. case 1: puts ("3.9uS\n"); break;
  668. case 2: puts ("7.8uS\n"); break;
  669. case 3: puts ("31.3uS\n"); break;
  670. case 4: puts ("62.5uS\n"); break;
  671. case 5: puts ("125uS\n"); break;
  672. default: puts ("unknown\n"); break;
  673. }
  674. printf("SDRAM width (primary) %d\n", data[13] & 0x7F);
  675. if((data[13] & 0x80) != 0) {
  676. printf(" (second bank) %d\n",
  677. 2 * (data[13] & 0x7F));
  678. }
  679. if(data[14] != 0) {
  680. printf("EDC width %d\n",
  681. data[14] & 0x7F);
  682. if((data[14] & 0x80) != 0) {
  683. printf(" (second bank) %d\n",
  684. 2 * (data[14] & 0x7F));
  685. }
  686. }
  687. printf("Min clock delay, back-to-back random column addresses %d\n",
  688. data[15]);
  689. puts ("Burst length(s) ");
  690. if (data[16] & 0x80) puts (" Page");
  691. if (data[16] & 0x08) puts (" 8");
  692. if (data[16] & 0x04) puts (" 4");
  693. if (data[16] & 0x02) puts (" 2");
  694. if (data[16] & 0x01) puts (" 1");
  695. putc ('\n');
  696. printf("Number of banks %d\n", data[17]);
  697. puts ("CAS latency(s) ");
  698. if (data[18] & 0x80) puts (" TBD");
  699. if (data[18] & 0x40) puts (" 7");
  700. if (data[18] & 0x20) puts (" 6");
  701. if (data[18] & 0x10) puts (" 5");
  702. if (data[18] & 0x08) puts (" 4");
  703. if (data[18] & 0x04) puts (" 3");
  704. if (data[18] & 0x02) puts (" 2");
  705. if (data[18] & 0x01) puts (" 1");
  706. putc ('\n');
  707. puts ("CS latency(s) ");
  708. if (data[19] & 0x80) puts (" TBD");
  709. if (data[19] & 0x40) puts (" 6");
  710. if (data[19] & 0x20) puts (" 5");
  711. if (data[19] & 0x10) puts (" 4");
  712. if (data[19] & 0x08) puts (" 3");
  713. if (data[19] & 0x04) puts (" 2");
  714. if (data[19] & 0x02) puts (" 1");
  715. if (data[19] & 0x01) puts (" 0");
  716. putc ('\n');
  717. puts ("WE latency(s) ");
  718. if (data[20] & 0x80) puts (" TBD");
  719. if (data[20] & 0x40) puts (" 6");
  720. if (data[20] & 0x20) puts (" 5");
  721. if (data[20] & 0x10) puts (" 4");
  722. if (data[20] & 0x08) puts (" 3");
  723. if (data[20] & 0x04) puts (" 2");
  724. if (data[20] & 0x02) puts (" 1");
  725. if (data[20] & 0x01) puts (" 0");
  726. putc ('\n');
  727. puts ("Module attributes:\n");
  728. if (!data[21]) puts (" (none)\n");
  729. if (data[21] & 0x80) puts (" TBD (bit 7)\n");
  730. if (data[21] & 0x40) puts (" Redundant row address\n");
  731. if (data[21] & 0x20) puts (" Differential clock input\n");
  732. if (data[21] & 0x10) puts (" Registerd DQMB inputs\n");
  733. if (data[21] & 0x08) puts (" Buffered DQMB inputs\n");
  734. if (data[21] & 0x04) puts (" On-card PLL\n");
  735. if (data[21] & 0x02) puts (" Registered address/control lines\n");
  736. if (data[21] & 0x01) puts (" Buffered address/control lines\n");
  737. puts ("Device attributes:\n");
  738. if (data[22] & 0x80) puts (" TBD (bit 7)\n");
  739. if (data[22] & 0x40) puts (" TBD (bit 6)\n");
  740. if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
  741. else puts (" Upper Vcc tolerance 10%\n");
  742. if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
  743. else puts (" Lower Vcc tolerance 10%\n");
  744. if (data[22] & 0x08) puts (" Supports write1/read burst\n");
  745. if (data[22] & 0x04) puts (" Supports precharge all\n");
  746. if (data[22] & 0x02) puts (" Supports auto precharge\n");
  747. if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
  748. printf("SDRAM cycle time (2nd highest CAS latency) %d.%d nS\n",
  749. (data[23] >> 4) & 0x0F, data[23] & 0x0F);
  750. printf("SDRAM access from clock (2nd highest CAS latency) %d.%d nS\n",
  751. (data[24] >> 4) & 0x0F, data[24] & 0x0F);
  752. printf("SDRAM cycle time (3rd highest CAS latency) %d.%d nS\n",
  753. (data[25] >> 4) & 0x0F, data[25] & 0x0F);
  754. printf("SDRAM access from clock (3rd highest CAS latency) %d.%d nS\n",
  755. (data[26] >> 4) & 0x0F, data[26] & 0x0F);
  756. printf("Minimum row precharge %d nS\n", data[27]);
  757. printf("Row active to row active min %d nS\n", data[28]);
  758. printf("RAS to CAS delay min %d nS\n", data[29]);
  759. printf("Minimum RAS pulse width %d nS\n", data[30]);
  760. puts ("Density of each row ");
  761. if (data[31] & 0x80) puts (" 512");
  762. if (data[31] & 0x40) puts (" 256");
  763. if (data[31] & 0x20) puts (" 128");
  764. if (data[31] & 0x10) puts (" 64");
  765. if (data[31] & 0x08) puts (" 32");
  766. if (data[31] & 0x04) puts (" 16");
  767. if (data[31] & 0x02) puts (" 8");
  768. if (data[31] & 0x01) puts (" 4");
  769. puts ("MByte\n");
  770. printf("Command and Address setup %c%d.%d nS\n",
  771. (data[32] & 0x80) ? '-' : '+',
  772. (data[32] >> 4) & 0x07, data[32] & 0x0F);
  773. printf("Command and Address hold %c%d.%d nS\n",
  774. (data[33] & 0x80) ? '-' : '+',
  775. (data[33] >> 4) & 0x07, data[33] & 0x0F);
  776. printf("Data signal input setup %c%d.%d nS\n",
  777. (data[34] & 0x80) ? '-' : '+',
  778. (data[34] >> 4) & 0x07, data[34] & 0x0F);
  779. printf("Data signal input hold %c%d.%d nS\n",
  780. (data[35] & 0x80) ? '-' : '+',
  781. (data[35] >> 4) & 0x07, data[35] & 0x0F);
  782. puts ("Manufacturer's JEDEC ID ");
  783. for(j = 64; j <= 71; j++)
  784. printf("%02X ", data[j]);
  785. putc ('\n');
  786. printf("Manufacturing Location %02X\n", data[72]);
  787. puts ("Manufacturer's Part Number ");
  788. for(j = 73; j <= 90; j++)
  789. printf("%02X ", data[j]);
  790. putc ('\n');
  791. printf("Revision Code %02X %02X\n", data[91], data[92]);
  792. printf("Manufacturing Date %02X %02X\n", data[93], data[94]);
  793. puts ("Assembly Serial Number ");
  794. for(j = 95; j <= 98; j++)
  795. printf("%02X ", data[j]);
  796. putc ('\n');
  797. printf("Speed rating PC%d\n",
  798. data[126] == 0x66 ? 66 : data[126]);
  799. return 0;
  800. }
  801. #endif /* CFG_CMD_SDRAM */
  802. /***************************************************/
  803. U_BOOT_CMD(
  804. imd, 4, 1, do_i2c_md, \
  805. "imd - i2c memory display\n", \
  806. "chip address[.0, .1, .2] [# of objects]\n - i2c memory display\n" \
  807. );
  808. U_BOOT_CMD(
  809. imm, 3, 1, do_i2c_mm,
  810. "imm - i2c memory modify (auto-incrementing)\n",
  811. "chip address[.0, .1, .2]\n"
  812. " - memory modify, auto increment address\n"
  813. );
  814. U_BOOT_CMD(
  815. inm, 3, 1, do_i2c_nm,
  816. "inm - memory modify (constant address)\n",
  817. "chip address[.0, .1, .2]\n - memory modify, read and keep address\n"
  818. );
  819. U_BOOT_CMD(
  820. imw, 5, 1, do_i2c_mw,
  821. "imw - memory write (fill)\n",
  822. "chip address[.0, .1, .2] value [count]\n - memory write (fill)\n"
  823. );
  824. U_BOOT_CMD(
  825. icrc32, 5, 1, do_i2c_crc,
  826. "icrc32 - checksum calculation\n",
  827. "chip address[.0, .1, .2] count\n - compute CRC32 checksum\n"
  828. );
  829. U_BOOT_CMD(
  830. iprobe, 1, 1, do_i2c_probe,
  831. "iprobe - probe to discover valid I2C chip addresses\n",
  832. "\n -discover valid I2C chip addresses\n"
  833. );
  834. /*
  835. * Require full name for "iloop" because it is an infinite loop!
  836. */
  837. U_BOOT_CMD(
  838. iloop, 5, 1, do_i2c_loop,
  839. "iloop - infinite loop on address range\n",
  840. "chip address[.0, .1, .2] [# of objects]\n"
  841. " - loop, reading a set of addresses\n"
  842. );
  843. #if (CONFIG_COMMANDS & CFG_CMD_SDRAM)
  844. U_BOOT_CMD(
  845. isdram, 2, 1, do_sdram,
  846. "isdram - print SDRAM configuration information\n",
  847. "chip\n - print SDRAM configuration information\n"
  848. " (valid chip values 50..57)\n"
  849. );
  850. #endif
  851. #endif /* CFG_CMD_I2C */