cmd_i2c.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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 <cmd_i2c.h>
  85. #include <i2c.h>
  86. #include <asm/byteorder.h>
  87. #if (CONFIG_COMMANDS & CFG_CMD_I2C)
  88. /* Display values from last command.
  89. * Memory modify remembered values are different from display memory.
  90. */
  91. static uchar i2c_dp_last_chip;
  92. static uint i2c_dp_last_addr;
  93. static uint i2c_dp_last_alen;
  94. static uint i2c_dp_last_length = 0x10;
  95. static uchar i2c_mm_last_chip;
  96. static uint i2c_mm_last_addr;
  97. static uint i2c_mm_last_alen;
  98. #if defined(CFG_I2C_NOPROBES)
  99. static uchar i2c_no_probes[] = CFG_I2C_NOPROBES;
  100. #endif
  101. static int
  102. mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]);
  103. extern int cmd_get_data_size(char* arg, int default_size);
  104. /*
  105. * Syntax:
  106. * imd {i2c_chip} {addr}{.0, .1, .2} {len}
  107. */
  108. #define DISP_LINE_LEN 16
  109. int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  110. {
  111. u_char chip;
  112. uint addr, alen, length;
  113. int j, nbytes, linebytes;
  114. /* We use the last specified parameters, unless new ones are
  115. * entered.
  116. */
  117. chip = i2c_dp_last_chip;
  118. addr = i2c_dp_last_addr;
  119. alen = i2c_dp_last_alen;
  120. length = i2c_dp_last_length;
  121. if (argc < 3) {
  122. printf ("Usage:\n%s\n", cmdtp->usage);
  123. return 1;
  124. }
  125. if ((flag & CMD_FLAG_REPEAT) == 0) {
  126. /*
  127. * New command specified.
  128. */
  129. alen = 1;
  130. /*
  131. * I2C chip address
  132. */
  133. chip = simple_strtoul(argv[1], NULL, 16);
  134. /*
  135. * I2C data address within the chip. This can be 1 or
  136. * 2 bytes long. Some day it might be 3 bytes long :-).
  137. */
  138. addr = simple_strtoul(argv[2], NULL, 16);
  139. alen = 1;
  140. for(j = 0; j < 8; j++) {
  141. if (argv[2][j] == '.') {
  142. alen = argv[2][j+1] - '0';
  143. if (alen > 4) {
  144. printf ("Usage:\n%s\n", cmdtp->usage);
  145. return 1;
  146. }
  147. break;
  148. } else if (argv[2][j] == '\0') {
  149. break;
  150. }
  151. }
  152. /*
  153. * If another parameter, it is the length to display.
  154. * Length is the number of objects, not number of bytes.
  155. */
  156. if (argc > 3)
  157. length = simple_strtoul(argv[3], NULL, 16);
  158. }
  159. /*
  160. * Print the lines.
  161. *
  162. * We buffer all read data, so we can make sure data is read only
  163. * once.
  164. */
  165. nbytes = length;
  166. do {
  167. unsigned char linebuf[DISP_LINE_LEN];
  168. unsigned char *cp;
  169. linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
  170. if(i2c_read(chip, addr, alen, linebuf, linebytes) != 0) {
  171. printf("Error reading the chip.\n");
  172. } else {
  173. printf("%04x:", addr);
  174. cp = linebuf;
  175. for (j=0; j<linebytes; j++) {
  176. printf(" %02x", *cp++);
  177. addr++;
  178. }
  179. printf(" ");
  180. cp = linebuf;
  181. for (j=0; j<linebytes; j++) {
  182. if ((*cp < 0x20) || (*cp > 0x7e))
  183. printf(".");
  184. else
  185. printf("%c", *cp);
  186. cp++;
  187. }
  188. printf("\n");
  189. }
  190. nbytes -= linebytes;
  191. } while (nbytes > 0);
  192. i2c_dp_last_chip = chip;
  193. i2c_dp_last_addr = addr;
  194. i2c_dp_last_alen = alen;
  195. i2c_dp_last_length = length;
  196. return 0;
  197. }
  198. int do_i2c_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  199. {
  200. return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
  201. }
  202. int do_i2c_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  203. {
  204. return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
  205. }
  206. /* Write (fill) memory
  207. *
  208. * Syntax:
  209. * imw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
  210. */
  211. int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  212. {
  213. uchar chip;
  214. ulong addr;
  215. uint alen;
  216. uchar byte;
  217. int count;
  218. int j;
  219. if ((argc < 4) || (argc > 5)) {
  220. printf ("Usage:\n%s\n", cmdtp->usage);
  221. return 1;
  222. }
  223. /*
  224. * Chip is always specified.
  225. */
  226. chip = simple_strtoul(argv[1], NULL, 16);
  227. /*
  228. * Address is always specified.
  229. */
  230. addr = simple_strtoul(argv[2], NULL, 16);
  231. alen = 1;
  232. for(j = 0; j < 8; j++) {
  233. if (argv[2][j] == '.') {
  234. alen = argv[2][j+1] - '0';
  235. if(alen > 4) {
  236. printf ("Usage:\n%s\n", cmdtp->usage);
  237. return 1;
  238. }
  239. break;
  240. } else if (argv[2][j] == '\0') {
  241. break;
  242. }
  243. }
  244. /*
  245. * Value to write is always specified.
  246. */
  247. byte = simple_strtoul(argv[3], NULL, 16);
  248. /*
  249. * Optional count
  250. */
  251. if(argc == 5) {
  252. count = simple_strtoul(argv[4], NULL, 16);
  253. } else {
  254. count = 1;
  255. }
  256. while (count-- > 0) {
  257. if(i2c_write(chip, addr++, alen, &byte, 1) != 0) {
  258. printf("Error writing the chip.\n");
  259. }
  260. /*
  261. * Wait for the write to complete. The write can take
  262. * up to 10mSec (we allow a little more time).
  263. *
  264. * On some chips, while the write is in progress, the
  265. * chip doesn't respond. This apparently isn't a
  266. * universal feature so we don't take advantage of it.
  267. */
  268. udelay(11000);
  269. #if 0
  270. for(timeout = 0; timeout < 10; timeout++) {
  271. udelay(2000);
  272. if(i2c_probe(chip) == 0)
  273. break;
  274. }
  275. #endif
  276. }
  277. return (0);
  278. }
  279. /* Calculate a CRC on memory
  280. *
  281. * Syntax:
  282. * icrc32 {i2c_chip} {addr}{.0, .1, .2} {count}
  283. */
  284. int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  285. {
  286. uchar chip;
  287. ulong addr;
  288. uint alen;
  289. int count;
  290. uchar byte;
  291. ulong crc;
  292. ulong err;
  293. int j;
  294. if (argc < 4) {
  295. printf ("Usage:\n%s\n", cmdtp->usage);
  296. return 1;
  297. }
  298. /*
  299. * Chip is always specified.
  300. */
  301. chip = simple_strtoul(argv[1], NULL, 16);
  302. /*
  303. * Address is always specified.
  304. */
  305. addr = simple_strtoul(argv[2], NULL, 16);
  306. alen = 1;
  307. for(j = 0; j < 8; j++) {
  308. if (argv[2][j] == '.') {
  309. alen = argv[2][j+1] - '0';
  310. if(alen > 4) {
  311. printf ("Usage:\n%s\n", cmdtp->usage);
  312. return 1;
  313. }
  314. break;
  315. } else if (argv[2][j] == '\0') {
  316. break;
  317. }
  318. }
  319. /*
  320. * Count is always specified
  321. */
  322. count = simple_strtoul(argv[3], NULL, 16);
  323. printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
  324. /*
  325. * CRC a byte at a time. This is going to be slooow, but hey, the
  326. * memories are small and slow too so hopefully nobody notices.
  327. */
  328. crc = 0;
  329. err = 0;
  330. while(count-- > 0) {
  331. if(i2c_read(chip, addr, alen, &byte, 1) != 0) {
  332. err++;
  333. }
  334. crc = crc32 (crc, &byte, 1);
  335. addr++;
  336. }
  337. if(err > 0)
  338. {
  339. printf("Error reading the chip,\n");
  340. } else {
  341. printf ("%08lx\n", crc);
  342. }
  343. return 0;
  344. }
  345. /* Modify memory.
  346. *
  347. * Syntax:
  348. * imm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  349. * inm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
  350. */
  351. static int
  352. mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
  353. {
  354. uchar chip;
  355. ulong addr;
  356. uint alen;
  357. ulong data;
  358. int size = 1;
  359. int nbytes;
  360. int j;
  361. extern char console_buffer[];
  362. if (argc != 3) {
  363. printf ("Usage:\n%s\n", cmdtp->usage);
  364. return 1;
  365. }
  366. #ifdef CONFIG_BOOT_RETRY_TIME
  367. reset_cmd_timeout(); /* got a good command to get here */
  368. #endif
  369. /*
  370. * We use the last specified parameters, unless new ones are
  371. * entered.
  372. */
  373. chip = i2c_mm_last_chip;
  374. addr = i2c_mm_last_addr;
  375. alen = i2c_mm_last_alen;
  376. if ((flag & CMD_FLAG_REPEAT) == 0) {
  377. /*
  378. * New command specified. Check for a size specification.
  379. * Defaults to byte if no or incorrect specification.
  380. */
  381. size = cmd_get_data_size(argv[0], 1);
  382. /*
  383. * Chip is always specified.
  384. */
  385. chip = simple_strtoul(argv[1], NULL, 16);
  386. /*
  387. * Address is always specified.
  388. */
  389. addr = simple_strtoul(argv[2], NULL, 16);
  390. alen = 1;
  391. for(j = 0; j < 8; j++) {
  392. if (argv[2][j] == '.') {
  393. alen = argv[2][j+1] - '0';
  394. if(alen > 4) {
  395. printf ("Usage:\n%s\n", cmdtp->usage);
  396. return 1;
  397. }
  398. break;
  399. } else if (argv[2][j] == '\0') {
  400. break;
  401. }
  402. }
  403. }
  404. /*
  405. * Print the address, followed by value. Then accept input for
  406. * the next value. A non-converted value exits.
  407. */
  408. do {
  409. printf("%08lx:", addr);
  410. if(i2c_read(chip, addr, alen, (char *)&data, size) != 0) {
  411. printf("\nError reading the chip,\n");
  412. } else {
  413. data = cpu_to_be32(data);
  414. if(size == 1) {
  415. printf(" %02lx", (data >> 24) & 0x000000FF);
  416. } else if(size == 2) {
  417. printf(" %04lx", (data >> 16) & 0x0000FFFF);
  418. } else {
  419. printf(" %08lx", data);
  420. }
  421. }
  422. nbytes = readline (" ? ");
  423. if (nbytes == 0) {
  424. /*
  425. * <CR> pressed as only input, don't modify current
  426. * location and move to next.
  427. */
  428. if (incrflag)
  429. addr += size;
  430. nbytes = size;
  431. #ifdef CONFIG_BOOT_RETRY_TIME
  432. reset_cmd_timeout(); /* good enough to not time out */
  433. #endif
  434. }
  435. #ifdef CONFIG_BOOT_RETRY_TIME
  436. else if (nbytes == -2) {
  437. break; /* timed out, exit the command */
  438. }
  439. #endif
  440. else {
  441. char *endp;
  442. data = simple_strtoul(console_buffer, &endp, 16);
  443. if(size == 1) {
  444. data = data << 24;
  445. } else if(size == 2) {
  446. data = data << 16;
  447. }
  448. data = be32_to_cpu(data);
  449. nbytes = endp - console_buffer;
  450. if (nbytes) {
  451. #ifdef CONFIG_BOOT_RETRY_TIME
  452. /*
  453. * good enough to not time out
  454. */
  455. reset_cmd_timeout();
  456. #endif
  457. if(i2c_write(chip, addr, alen, (char *)&data, size) != 0) {
  458. printf("Error writing the chip.\n");
  459. }
  460. if (incrflag)
  461. addr += size;
  462. }
  463. }
  464. } while (nbytes);
  465. chip = i2c_mm_last_chip;
  466. addr = i2c_mm_last_addr;
  467. alen = i2c_mm_last_alen;
  468. return 0;
  469. }
  470. /*
  471. * Syntax:
  472. * iprobe {addr}{.0, .1, .2}
  473. */
  474. int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  475. {
  476. int j;
  477. #if defined(CFG_I2C_NOPROBES)
  478. int k, skip;
  479. #endif
  480. printf("Valid chip addresses:");
  481. for(j = 0; j < 128; j++) {
  482. #if defined(CFG_I2C_NOPROBES)
  483. skip = 0;
  484. for (k = 0; k < sizeof(i2c_no_probes); k++){
  485. if (j == i2c_no_probes[k]){
  486. skip = 1;
  487. break;
  488. }
  489. }
  490. if (skip)
  491. continue;
  492. #endif
  493. if(i2c_probe(j) == 0) {
  494. printf(" %02X", j);
  495. }
  496. }
  497. printf("\n");
  498. #if defined(CFG_I2C_NOPROBES)
  499. puts ("Excluded chip addresses:");
  500. for( k = 0; k < sizeof(i2c_no_probes); k++ )
  501. printf(" %02X", i2c_no_probes[k] );
  502. puts ("\n");
  503. #endif
  504. return 0;
  505. }
  506. /*
  507. * Syntax:
  508. * iloop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
  509. * {length} - Number of bytes to read
  510. * {delay} - A DECIMAL number and defaults to 1000 uSec
  511. */
  512. int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  513. {
  514. u_char chip;
  515. ulong alen;
  516. uint addr;
  517. uint length;
  518. u_char bytes[16];
  519. int delay;
  520. int j;
  521. if (argc < 3) {
  522. printf ("Usage:\n%s\n", cmdtp->usage);
  523. return 1;
  524. }
  525. /*
  526. * Chip is always specified.
  527. */
  528. chip = simple_strtoul(argv[1], NULL, 16);
  529. /*
  530. * Address is always specified.
  531. */
  532. addr = simple_strtoul(argv[2], NULL, 16);
  533. alen = 1;
  534. for(j = 0; j < 8; j++) {
  535. if (argv[2][j] == '.') {
  536. alen = argv[2][j+1] - '0';
  537. if (alen > 4) {
  538. printf ("Usage:\n%s\n", cmdtp->usage);
  539. return 1;
  540. }
  541. break;
  542. } else if (argv[2][j] == '\0') {
  543. break;
  544. }
  545. }
  546. /*
  547. * Length is the number of objects, not number of bytes.
  548. */
  549. length = 1;
  550. length = simple_strtoul(argv[3], NULL, 16);
  551. if(length > sizeof(bytes)) {
  552. length = sizeof(bytes);
  553. }
  554. /*
  555. * The delay time (uSec) is optional.
  556. */
  557. delay = 1000;
  558. if (argc > 3) {
  559. delay = simple_strtoul(argv[4], NULL, 10);
  560. }
  561. /*
  562. * Run the loop...
  563. */
  564. while(1) {
  565. if(i2c_read(chip, addr, alen, bytes, length) != 0) {
  566. printf("Error reading the chip.\n");
  567. }
  568. udelay(delay);
  569. }
  570. /* NOTREACHED */
  571. return 0;
  572. }
  573. /*
  574. * The SDRAM command is separately configured because many
  575. * (most?) embedded boards don't use SDRAM DIMMs.
  576. */
  577. #if (CONFIG_COMMANDS & CFG_CMD_SDRAM)
  578. /*
  579. * Syntax:
  580. * sdram {i2c_chip}
  581. */
  582. int do_sdram ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  583. {
  584. u_char chip;
  585. u_char data[128];
  586. u_char cksum;
  587. int j;
  588. if (argc < 2) {
  589. printf ("Usage:\n%s\n", cmdtp->usage);
  590. return 1;
  591. }
  592. /*
  593. * Chip is always specified.
  594. */
  595. chip = simple_strtoul(argv[1], NULL, 16);
  596. if(i2c_read(chip, 0, 1, data, sizeof(data)) != 0) {
  597. printf("No SDRAM Serial Presence Detect found.\n");
  598. return 1;
  599. }
  600. cksum = 0;
  601. for (j = 0; j < 63; j++) {
  602. cksum += data[j];
  603. }
  604. if(cksum != data[63]) {
  605. printf ("WARNING: Configuration data checksum failure:\n"
  606. " is 0x%02x, calculated 0x%02x\n",
  607. data[63], cksum);
  608. }
  609. printf("SPD data revision %d.%d\n",
  610. (data[62] >> 4) & 0x0F, data[62] & 0x0F);
  611. printf("Bytes used 0x%02X\n", data[0]);
  612. printf("Serial memory size 0x%02X\n", 1 << data[1]);
  613. printf("Memory type ");
  614. switch(data[2]) {
  615. case 2: printf("EDO\n"); break;
  616. case 4: printf("SDRAM\n"); break;
  617. default: printf("unknown\n"); break;
  618. }
  619. printf("Row address bits ");
  620. if((data[3] & 0x00F0) == 0) {
  621. printf("%d\n", data[3] & 0x0F);
  622. } else {
  623. printf("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
  624. }
  625. printf("Column address bits ");
  626. if((data[4] & 0x00F0) == 0) {
  627. printf("%d\n", data[4] & 0x0F);
  628. } else {
  629. printf("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
  630. }
  631. printf("Module rows %d\n", data[5]);
  632. printf("Module data width %d bits\n", (data[7] << 8) | data[6]);
  633. printf("Interface signal levels ");
  634. switch(data[8]) {
  635. case 0: printf("5.0v/TTL\n"); break;
  636. case 1: printf("LVTTL\n"); break;
  637. case 2: printf("HSTL 1.5\n"); break;
  638. case 3: printf("SSTL 3.3\n"); break;
  639. case 4: printf("SSTL 2.5\n"); break;
  640. default: printf("unknown\n"); break;
  641. }
  642. printf("SDRAM cycle time %d.%d nS\n",
  643. (data[9] >> 4) & 0x0F, data[9] & 0x0F);
  644. printf("SDRAM access time %d.%d nS\n",
  645. (data[10] >> 4) & 0x0F, data[10] & 0x0F);
  646. printf("EDC configuration ");
  647. switch(data[11]) {
  648. case 0: printf("None\n"); break;
  649. case 1: printf("Parity\n"); break;
  650. case 2: printf("ECC\n"); break;
  651. default: printf("unknown\n"); break;
  652. }
  653. if((data[12] & 0x80) == 0) {
  654. printf("No self refresh, rate ");
  655. } else {
  656. printf("Self refresh, rate ");
  657. }
  658. switch(data[12] & 0x7F) {
  659. case 0: printf("15.625uS\n"); break;
  660. case 1: printf("3.9uS\n"); break;
  661. case 2: printf("7.8uS\n"); break;
  662. case 3: printf("31.3uS\n"); break;
  663. case 4: printf("62.5uS\n"); break;
  664. case 5: printf("125uS\n"); break;
  665. default: printf("unknown\n"); break;
  666. }
  667. printf("SDRAM width (primary) %d\n", data[13] & 0x7F);
  668. if((data[13] & 0x80) != 0) {
  669. printf(" (second bank) %d\n",
  670. 2 * (data[13] & 0x7F));
  671. }
  672. if(data[14] != 0) {
  673. printf("EDC width %d\n",
  674. data[14] & 0x7F);
  675. if((data[14] & 0x80) != 0) {
  676. printf(" (second bank) %d\n",
  677. 2 * (data[14] & 0x7F));
  678. }
  679. }
  680. printf("Min clock delay, back-to-back random column addresses %d\n",
  681. data[15]);
  682. printf("Burst length(s) ");
  683. if(data[16] & 0x80) printf(" Page");
  684. if(data[16] & 0x08) printf(" 8");
  685. if(data[16] & 0x04) printf(" 4");
  686. if(data[16] & 0x02) printf(" 2");
  687. if(data[16] & 0x01) printf(" 1");
  688. printf("\n");
  689. printf("Number of banks %d\n", data[17]);
  690. printf("CAS latency(s) ");
  691. if(data[18] & 0x80) printf(" TBD");
  692. if(data[18] & 0x40) printf(" 7");
  693. if(data[18] & 0x20) printf(" 6");
  694. if(data[18] & 0x10) printf(" 5");
  695. if(data[18] & 0x08) printf(" 4");
  696. if(data[18] & 0x04) printf(" 3");
  697. if(data[18] & 0x02) printf(" 2");
  698. if(data[18] & 0x01) printf(" 1");
  699. printf("\n");
  700. printf("CS latency(s) ");
  701. if(data[19] & 0x80) printf(" TBD");
  702. if(data[19] & 0x40) printf(" 6");
  703. if(data[19] & 0x20) printf(" 5");
  704. if(data[19] & 0x10) printf(" 4");
  705. if(data[19] & 0x08) printf(" 3");
  706. if(data[19] & 0x04) printf(" 2");
  707. if(data[19] & 0x02) printf(" 1");
  708. if(data[19] & 0x01) printf(" 0");
  709. printf("\n");
  710. printf("WE latency(s) ");
  711. if(data[20] & 0x80) printf(" TBD");
  712. if(data[20] & 0x40) printf(" 6");
  713. if(data[20] & 0x20) printf(" 5");
  714. if(data[20] & 0x10) printf(" 4");
  715. if(data[20] & 0x08) printf(" 3");
  716. if(data[20] & 0x04) printf(" 2");
  717. if(data[20] & 0x02) printf(" 1");
  718. if(data[20] & 0x01) printf(" 0");
  719. printf("\n");
  720. printf("Module attributes:\n");
  721. if(!data[21]) printf(" (none)\n");
  722. if(data[21] & 0x80) printf(" TBD (bit 7)\n");
  723. if(data[21] & 0x40) printf(" Redundant row address\n");
  724. if(data[21] & 0x20) printf(" Differential clock input\n");
  725. if(data[21] & 0x10) printf(" Registerd DQMB inputs\n");
  726. if(data[21] & 0x08) printf(" Buffered DQMB inputs\n");
  727. if(data[21] & 0x04) printf(" On-card PLL\n");
  728. if(data[21] & 0x02) printf(" Registered address/control lines\n");
  729. if(data[21] & 0x01) printf(" Buffered address/control lines\n");
  730. printf("Device attributes:\n");
  731. if(data[22] & 0x80) printf(" TBD (bit 7)\n");
  732. if(data[22] & 0x40) printf(" TBD (bit 6)\n");
  733. if(data[22] & 0x20) printf(" Upper Vcc tolerance 5%%\n");
  734. else printf(" Upper Vcc tolerance 10%%\n");
  735. if(data[22] & 0x10) printf(" Lower Vcc tolerance 5%%\n");
  736. else printf(" Lower Vcc tolerance 10%%\n");
  737. if(data[22] & 0x08) printf(" Supports write1/read burst\n");
  738. if(data[22] & 0x04) printf(" Supports precharge all\n");
  739. if(data[22] & 0x02) printf(" Supports auto precharge\n");
  740. if(data[22] & 0x01) printf(" Supports early RAS# precharge\n");
  741. printf("SDRAM cycle time (2nd highest CAS latency) %d.%d nS\n",
  742. (data[23] >> 4) & 0x0F, data[23] & 0x0F);
  743. printf("SDRAM access from clock (2nd highest CAS latency) %d.%d nS\n",
  744. (data[24] >> 4) & 0x0F, data[24] & 0x0F);
  745. printf("SDRAM cycle time (3rd highest CAS latency) %d.%d nS\n",
  746. (data[25] >> 4) & 0x0F, data[25] & 0x0F);
  747. printf("SDRAM access from clock (3rd highest CAS latency) %d.%d nS\n",
  748. (data[26] >> 4) & 0x0F, data[26] & 0x0F);
  749. printf("Minimum row precharge %d nS\n", data[27]);
  750. printf("Row active to row active min %d nS\n", data[28]);
  751. printf("RAS to CAS delay min %d nS\n", data[29]);
  752. printf("Minimum RAS pulse width %d nS\n", data[30]);
  753. printf("Density of each row ");
  754. if(data[31] & 0x80) printf(" 512MByte");
  755. if(data[31] & 0x40) printf(" 256MByte");
  756. if(data[31] & 0x20) printf(" 128MByte");
  757. if(data[31] & 0x10) printf(" 64MByte");
  758. if(data[31] & 0x08) printf(" 32MByte");
  759. if(data[31] & 0x04) printf(" 16MByte");
  760. if(data[31] & 0x02) printf(" 8MByte");
  761. if(data[31] & 0x01) printf(" 4MByte");
  762. printf("\n");
  763. printf("Command and Address setup %c%d.%d nS\n",
  764. (data[32] & 0x80) ? '-' : '+',
  765. (data[32] >> 4) & 0x07, data[32] & 0x0F);
  766. printf("Command and Address hold %c%d.%d nS\n",
  767. (data[33] & 0x80) ? '-' : '+',
  768. (data[33] >> 4) & 0x07, data[33] & 0x0F);
  769. printf("Data signal input setup %c%d.%d nS\n",
  770. (data[34] & 0x80) ? '-' : '+',
  771. (data[34] >> 4) & 0x07, data[34] & 0x0F);
  772. printf("Data signal input hold %c%d.%d nS\n",
  773. (data[35] & 0x80) ? '-' : '+',
  774. (data[35] >> 4) & 0x07, data[35] & 0x0F);
  775. printf("Manufacturer's JEDEC ID ");
  776. for(j = 64; j <= 71; j++)
  777. printf("%02X ", data[j]);
  778. printf("\n");
  779. printf("Manufacturing Location %02X\n", data[72]);
  780. printf("Manufacturer's Part Number ");
  781. for(j = 73; j <= 90; j++)
  782. printf("%02X ", data[j]);
  783. printf("\n");
  784. printf("Revision Code %02X %02X\n", data[91], data[92]);
  785. printf("Manufacturing Date %02X %02X\n", data[93], data[94]);
  786. printf("Assembly Serial Number ");
  787. for(j = 95; j <= 98; j++)
  788. printf("%02X ", data[j]);
  789. printf("\n");
  790. printf("Speed rating PC%d\n",
  791. data[126] == 0x66 ? 66 : data[126]);
  792. return 0;
  793. }
  794. #endif /* CFG_CMD_SDRAM */
  795. #endif /* CFG_CMD_I2C */