3 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 * I2C Functions similar to the standard memory functions.
27 * There are several parameters in many of the commands that bear further
30 * Two of the commands (imm and imw) take a byte/word/long modifier
31 * (e.g. imm.w specifies the word-length modifier). This was done to
32 * allow manipulating word-length registers. It was not done on any other
33 * commands because it was not deemed useful.
35 * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
36 * Each I2C chip on the bus has a unique address. On the I2C data bus,
37 * the address is the upper seven bits and the LSB is the "read/write"
38 * bit. Note that the {i2c_chip} address specified on the command
39 * line is not shifted up: e.g. a typical EEPROM memory chip may have
40 * an I2C address of 0x50, but the data put on the bus will be 0xA0
41 * for write and 0xA1 for read. This "non shifted" address notation
42 * matches at least half of the data sheets :-/.
44 * {addr} is the address (or offset) within the chip. Small memory
45 * chips have 8 bit addresses. Large memory chips have 16 bit
46 * addresses. Other memory chips have 9, 10, or 11 bit addresses.
47 * Many non-memory chips have multiple registers and {addr} is used
48 * as the register index. Some non-memory chips have only one register
49 * and therefore don't need any {addr} parameter.
51 * The default {addr} parameter is one byte (.1) which works well for
52 * memories and registers with 8 bits of address space.
54 * You can specify the length of the {addr} field with the optional .0,
55 * .1, or .2 modifier (similar to the .b, .w, .l modifier). If you are
56 * manipulating a single register device which doesn't use an address
57 * field, use "0.0" for the address and the ".0" length field will
58 * suppress the address in the I2C data stream. This also works for
59 * successive reads using the I2C auto-incrementing memory pointer.
61 * If you are manipulating a large memory with 2-byte addresses, use
62 * the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
64 * Then there are the unfortunate memory chips that spill the most
65 * significant 1, 2, or 3 bits of address into the chip address byte.
66 * This effectively makes one chip (logically) look like 2, 4, or
67 * 8 chips. This is handled (awkwardly) by #defining
68 * CFG_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
69 * {addr} field (since .1 is the default, it doesn't actually have to
70 * be specified). Examples: given a memory chip at I2C chip address
71 * 0x50, the following would happen...
72 * imd 50 0 10 display 16 bytes starting at 0x000
73 * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
74 * imd 50 100 10 display 16 bytes starting at 0x100
75 * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
76 * imd 50 210 10 display 16 bytes starting at 0x210
77 * On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
78 * This is awfully ugly. It would be nice if someone would think up
79 * a better way of handling this.
81 * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
87 #include <asm/byteorder.h>
89 /* Display values from last command.
90 * Memory modify remembered values are different from display memory.
92 static uchar i2c_dp_last_chip;
93 static uint i2c_dp_last_addr;
94 static uint i2c_dp_last_alen;
95 static uint i2c_dp_last_length = 0x10;
97 static uchar i2c_mm_last_chip;
98 static uint i2c_mm_last_addr;
99 static uint i2c_mm_last_alen;
101 /* If only one I2C bus is present, the list of devices to ignore when
102 * the probe command is issued is represented by a 1D array of addresses.
103 * When multiple buses are present, the list is an array of bus-address
104 * pairs. The following macros take care of this */
106 #if defined(CFG_I2C_NOPROBES)
107 #if defined(CONFIG_I2C_MULTI_BUS)
112 } i2c_no_probes[] = CFG_I2C_NOPROBES;
113 #define GET_BUS_NUM i2c_get_bus_num()
114 #define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b))
115 #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a))
116 #define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr
117 #else /* single bus */
118 static uchar i2c_no_probes[] = CFG_I2C_NOPROBES;
119 #define GET_BUS_NUM 0
120 #define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */
121 #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a))
122 #define NO_PROBE_ADDR(i) i2c_no_probes[(i)]
123 #endif /* CONFIG_MULTI_BUS */
125 #define NUM_ELEMENTS_NOPROBE (sizeof(i2c_no_probes)/sizeof(i2c_no_probes[0]))
129 mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]);
130 extern int cmd_get_data_size(char* arg, int default_size);
134 * imd {i2c_chip} {addr}{.0, .1, .2} {len}
136 #define DISP_LINE_LEN 16
138 int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
141 uint addr, alen, length;
142 int j, nbytes, linebytes;
144 /* We use the last specified parameters, unless new ones are
147 chip = i2c_dp_last_chip;
148 addr = i2c_dp_last_addr;
149 alen = i2c_dp_last_alen;
150 length = i2c_dp_last_length;
153 printf ("Usage:\n%s\n", cmdtp->usage);
157 if ((flag & CMD_FLAG_REPEAT) == 0) {
159 * New command specified.
166 chip = simple_strtoul(argv[1], NULL, 16);
169 * I2C data address within the chip. This can be 1 or
170 * 2 bytes long. Some day it might be 3 bytes long :-).
172 addr = simple_strtoul(argv[2], NULL, 16);
174 for (j = 0; j < 8; j++) {
175 if (argv[2][j] == '.') {
176 alen = argv[2][j+1] - '0';
178 printf ("Usage:\n%s\n", cmdtp->usage);
182 } else if (argv[2][j] == '\0')
187 * If another parameter, it is the length to display.
188 * Length is the number of objects, not number of bytes.
191 length = simple_strtoul(argv[3], NULL, 16);
197 * We buffer all read data, so we can make sure data is read only
202 unsigned char linebuf[DISP_LINE_LEN];
205 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
207 if (i2c_read(chip, addr, alen, linebuf, linebytes) != 0)
208 puts ("Error reading the chip.\n");
210 printf("%04x:", addr);
212 for (j=0; j<linebytes; j++) {
213 printf(" %02x", *cp++);
218 for (j=0; j<linebytes; j++) {
219 if ((*cp < 0x20) || (*cp > 0x7e))
228 } while (nbytes > 0);
230 i2c_dp_last_chip = chip;
231 i2c_dp_last_addr = addr;
232 i2c_dp_last_alen = alen;
233 i2c_dp_last_length = length;
238 int do_i2c_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
240 return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
244 int do_i2c_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
246 return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
249 /* Write (fill) memory
252 * imw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
254 int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
263 if ((argc < 4) || (argc > 5)) {
264 printf ("Usage:\n%s\n", cmdtp->usage);
269 * Chip is always specified.
271 chip = simple_strtoul(argv[1], NULL, 16);
274 * Address is always specified.
276 addr = simple_strtoul(argv[2], NULL, 16);
278 for (j = 0; j < 8; j++) {
279 if (argv[2][j] == '.') {
280 alen = argv[2][j+1] - '0';
282 printf ("Usage:\n%s\n", cmdtp->usage);
286 } else if (argv[2][j] == '\0')
291 * Value to write is always specified.
293 byte = simple_strtoul(argv[3], NULL, 16);
299 count = simple_strtoul(argv[4], NULL, 16);
303 while (count-- > 0) {
304 if (i2c_write(chip, addr++, alen, &byte, 1) != 0)
305 puts ("Error writing the chip.\n");
307 * Wait for the write to complete. The write can take
308 * up to 10mSec (we allow a little more time).
310 * On some chips, while the write is in progress, the
311 * chip doesn't respond. This apparently isn't a
312 * universal feature so we don't take advantage of it.
315 * No write delay with FRAM devices.
317 #if !defined(CFG_I2C_FRAM)
322 for (timeout = 0; timeout < 10; timeout++) {
324 if (i2c_probe(chip) == 0)
334 /* Calculate a CRC on memory
337 * icrc32 {i2c_chip} {addr}{.0, .1, .2} {count}
339 int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
351 printf ("Usage:\n%s\n", cmdtp->usage);
356 * Chip is always specified.
358 chip = simple_strtoul(argv[1], NULL, 16);
361 * Address is always specified.
363 addr = simple_strtoul(argv[2], NULL, 16);
365 for (j = 0; j < 8; j++) {
366 if (argv[2][j] == '.') {
367 alen = argv[2][j+1] - '0';
369 printf ("Usage:\n%s\n", cmdtp->usage);
373 } else if (argv[2][j] == '\0')
378 * Count is always specified
380 count = simple_strtoul(argv[3], NULL, 16);
382 printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
384 * CRC a byte at a time. This is going to be slooow, but hey, the
385 * memories are small and slow too so hopefully nobody notices.
389 while (count-- > 0) {
390 if (i2c_read(chip, addr, alen, &byte, 1) != 0)
392 crc = crc32 (crc, &byte, 1);
396 puts ("Error reading the chip,\n");
398 printf ("%08lx\n", crc);
407 * imm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
408 * inm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
412 mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
421 extern char console_buffer[];
424 printf ("Usage:\n%s\n", cmdtp->usage);
428 #ifdef CONFIG_BOOT_RETRY_TIME
429 reset_cmd_timeout(); /* got a good command to get here */
432 * We use the last specified parameters, unless new ones are
435 chip = i2c_mm_last_chip;
436 addr = i2c_mm_last_addr;
437 alen = i2c_mm_last_alen;
439 if ((flag & CMD_FLAG_REPEAT) == 0) {
441 * New command specified. Check for a size specification.
442 * Defaults to byte if no or incorrect specification.
444 size = cmd_get_data_size(argv[0], 1);
447 * Chip is always specified.
449 chip = simple_strtoul(argv[1], NULL, 16);
452 * Address is always specified.
454 addr = simple_strtoul(argv[2], NULL, 16);
456 for (j = 0; j < 8; j++) {
457 if (argv[2][j] == '.') {
458 alen = argv[2][j+1] - '0';
460 printf ("Usage:\n%s\n", cmdtp->usage);
464 } else if (argv[2][j] == '\0')
470 * Print the address, followed by value. Then accept input for
471 * the next value. A non-converted value exits.
474 printf("%08lx:", addr);
475 if (i2c_read(chip, addr, alen, (uchar *)&data, size) != 0)
476 puts ("\nError reading the chip,\n");
478 data = cpu_to_be32(data);
480 printf(" %02lx", (data >> 24) & 0x000000FF);
482 printf(" %04lx", (data >> 16) & 0x0000FFFF);
484 printf(" %08lx", data);
487 nbytes = readline (" ? ");
490 * <CR> pressed as only input, don't modify current
491 * location and move to next.
496 #ifdef CONFIG_BOOT_RETRY_TIME
497 reset_cmd_timeout(); /* good enough to not time out */
500 #ifdef CONFIG_BOOT_RETRY_TIME
501 else if (nbytes == -2)
502 break; /* timed out, exit the command */
507 data = simple_strtoul(console_buffer, &endp, 16);
512 data = be32_to_cpu(data);
513 nbytes = endp - console_buffer;
515 #ifdef CONFIG_BOOT_RETRY_TIME
517 * good enough to not time out
521 if (i2c_write(chip, addr, alen, (uchar *)&data, size) != 0)
522 puts ("Error writing the chip.\n");
523 #ifdef CFG_EEPROM_PAGE_WRITE_DELAY_MS
524 udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
532 chip = i2c_mm_last_chip;
533 addr = i2c_mm_last_addr;
534 alen = i2c_mm_last_alen;
541 * iprobe {addr}{.0, .1, .2}
543 int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
546 #if defined(CFG_I2C_NOPROBES)
548 uchar bus = GET_BUS_NUM;
549 #endif /* NOPROBES */
551 puts ("Valid chip addresses:");
552 for (j = 0; j < 128; j++) {
553 #if defined(CFG_I2C_NOPROBES)
555 for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) {
556 if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
564 if (i2c_probe(j) == 0)
569 #if defined(CFG_I2C_NOPROBES)
570 puts ("Excluded chip addresses:");
571 for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) {
572 if (COMPARE_BUS(bus,k))
573 printf(" %02X", NO_PROBE_ADDR(k));
584 * iloop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
585 * {length} - Number of bytes to read
586 * {delay} - A DECIMAL number and defaults to 1000 uSec
588 int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
599 printf ("Usage:\n%s\n", cmdtp->usage);
604 * Chip is always specified.
606 chip = simple_strtoul(argv[1], NULL, 16);
609 * Address is always specified.
611 addr = simple_strtoul(argv[2], NULL, 16);
613 for (j = 0; j < 8; j++) {
614 if (argv[2][j] == '.') {
615 alen = argv[2][j+1] - '0';
617 printf ("Usage:\n%s\n", cmdtp->usage);
621 } else if (argv[2][j] == '\0')
626 * Length is the number of objects, not number of bytes.
629 length = simple_strtoul(argv[3], NULL, 16);
630 if (length > sizeof(bytes))
631 length = sizeof(bytes);
634 * The delay time (uSec) is optional.
638 delay = simple_strtoul(argv[4], NULL, 10);
643 if (i2c_read(chip, addr, alen, bytes, length) != 0)
644 puts ("Error reading the chip.\n");
654 * The SDRAM command is separately configured because many
655 * (most?) embedded boards don't use SDRAM DIMMs.
657 #if defined(CONFIG_CMD_SDRAM)
663 int do_sdram ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
665 enum {unknown, EDO, SDRAM, DDR2} type;
672 printf ("Usage:\n%s\n", cmdtp->usage);
676 * Chip is always specified.
678 chip = simple_strtoul(argv[1], NULL, 16);
680 if (i2c_read(chip, 0, 1, data, sizeof(data)) != 0) {
681 puts ("No SDRAM Serial Presence Detect found.\n");
686 for (j = 0; j < 63; j++) {
689 if (cksum != data[63]) {
690 printf ("WARNING: Configuration data checksum failure:\n"
691 " is 0x%02x, calculated 0x%02x\n",
694 printf("SPD data revision %d.%d\n",
695 (data[62] >> 4) & 0x0F, data[62] & 0x0F);
696 printf("Bytes used 0x%02X\n", data[0]);
697 printf("Serial memory size 0x%02X\n", 1 << data[1]);
698 puts ("Memory type ");
717 puts ("Row address bits ");
718 if ((data[3] & 0x00F0) == 0)
719 printf("%d\n", data[3] & 0x0F);
721 printf("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
722 puts ("Column address bits ");
723 if ((data[4] & 0x00F0) == 0)
724 printf("%d\n", data[4] & 0x0F);
726 printf("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
730 printf("Number of ranks %d\n",
731 (data[5] & 0x07) + 1);
734 printf("Module rows %d\n", data[5]);
740 printf("Module data width %d bits\n", data[6]);
743 printf("Module data width %d bits\n",
744 (data[7] << 8) | data[6]);
748 puts ("Interface signal levels ");
750 case 0: puts ("TTL 5.0 V\n"); break;
751 case 1: puts ("LVTTL\n"); break;
752 case 2: puts ("HSTL 1.5 V\n"); break;
753 case 3: puts ("SSTL 3.3 V\n"); break;
754 case 4: puts ("SSTL 2.5 V\n"); break;
755 case 5: puts ("SSTL 1.8 V\n"); break;
756 default: puts ("unknown\n"); break;
761 printf("SDRAM cycle time %d.",
762 (data[9] >> 4) & 0x0F);
763 switch (data[9] & 0x0F) {
774 printf("%d ns\n", data[9] & 0x0F);
794 printf("SDRAM cycle time %d.%d nS\n",
795 (data[9] >> 4) & 0x0F, data[9] & 0x0F);
801 printf("SDRAM access time 0.%d%d ns\n",
802 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
805 printf("SDRAM access time %d.%d nS\n",
806 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
810 puts ("EDC configuration ");
812 case 0: puts ("None\n"); break;
813 case 1: puts ("Parity\n"); break;
814 case 2: puts ("ECC\n"); break;
815 default: puts ("unknown\n"); break;
817 if ((data[12] & 0x80) == 0)
818 puts ("No self refresh, rate ");
820 puts ("Self refresh, rate ");
821 switch(data[12] & 0x7F) {
822 case 0: puts ("15.625 uS\n"); break;
823 case 1: puts ("3.9 uS\n"); break;
824 case 2: puts ("7.8 uS \n"); break;
825 case 3: puts ("31.3 uS\n"); break;
826 case 4: puts ("62.5 uS\n"); break;
827 case 5: puts ("125 uS\n"); break;
828 default: puts ("unknown\n"); break;
833 printf("SDRAM width (primary) %d\n", data[13]);
836 printf("SDRAM width (primary) %d\n", data[13] & 0x7F);
837 if ((data[13] & 0x80) != 0) {
838 printf(" (second bank) %d\n",
839 2 * (data[13] & 0x7F));
847 printf("EDC width %d\n", data[14]);
851 printf("EDC width %d\n",
854 if ((data[14] & 0x80) != 0) {
855 printf(" (second bank) %d\n",
856 2 * (data[14] & 0x7F));
863 printf("Min clock delay, back-to-back random column addresses "
867 puts ("Burst length(s) ");
868 if (data[16] & 0x80) puts (" Page");
869 if (data[16] & 0x08) puts (" 8");
870 if (data[16] & 0x04) puts (" 4");
871 if (data[16] & 0x02) puts (" 2");
872 if (data[16] & 0x01) puts (" 1");
874 printf("Number of banks %d\n", data[17]);
878 puts ("CAS latency(s) ");
879 if (data[18] & 0x83) puts (" TBD");
880 if (data[18] & 0x40) puts (" 6");
881 if (data[18] & 0x20) puts (" 5");
882 if (data[18] & 0x10) puts (" 4");
883 if (data[18] & 0x08) puts (" 3");
884 if (data[18] & 0x04) puts (" 2");
888 puts ("CAS latency(s) ");
889 if (data[18] & 0x80) puts (" TBD");
890 if (data[18] & 0x40) puts (" 7");
891 if (data[18] & 0x20) puts (" 6");
892 if (data[18] & 0x10) puts (" 5");
893 if (data[18] & 0x08) puts (" 4");
894 if (data[18] & 0x04) puts (" 3");
895 if (data[18] & 0x02) puts (" 2");
896 if (data[18] & 0x01) puts (" 1");
902 puts ("CS latency(s) ");
903 if (data[19] & 0x80) puts (" TBD");
904 if (data[19] & 0x40) puts (" 6");
905 if (data[19] & 0x20) puts (" 5");
906 if (data[19] & 0x10) puts (" 4");
907 if (data[19] & 0x08) puts (" 3");
908 if (data[19] & 0x04) puts (" 2");
909 if (data[19] & 0x02) puts (" 1");
910 if (data[19] & 0x01) puts (" 0");
915 puts ("WE latency(s) ");
916 if (data[20] & 0x80) puts (" TBD");
917 if (data[20] & 0x40) puts (" 6");
918 if (data[20] & 0x20) puts (" 5");
919 if (data[20] & 0x10) puts (" 4");
920 if (data[20] & 0x08) puts (" 3");
921 if (data[20] & 0x04) puts (" 2");
922 if (data[20] & 0x02) puts (" 1");
923 if (data[20] & 0x01) puts (" 0");
929 puts ("Module attributes:\n");
931 puts (" TBD (bit 7)\n");
933 puts (" Analysis probe installed\n");
935 puts (" TBD (bit 5)\n");
937 puts (" FET switch external enable\n");
938 printf(" %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
939 if (data[20] & 0x11) {
940 printf(" %d active registers on DIMM\n",
941 (data[21] & 0x03) + 1);
945 puts ("Module attributes:\n");
949 puts (" TBD (bit 7)\n");
951 puts (" Redundant row address\n");
953 puts (" Differential clock input\n");
955 puts (" Registerd DQMB inputs\n");
957 puts (" Buffered DQMB inputs\n");
959 puts (" On-card PLL\n");
961 puts (" Registered address/control lines\n");
963 puts (" Buffered address/control lines\n");
969 if (data[22] & 0x80) puts (" TBD (bit 7)\n");
970 if (data[22] & 0x40) puts (" TBD (bit 6)\n");
971 if (data[22] & 0x20) puts (" TBD (bit 5)\n");
972 if (data[22] & 0x10) puts (" TBD (bit 4)\n");
973 if (data[22] & 0x08) puts (" TBD (bit 3)\n");
975 puts (" Supports parital array self refresh\n");
977 puts (" Supports 50 ohm ODT\n");
979 puts (" Supports weak driver\n");
982 puts ("Device attributes:\n");
983 if (data[22] & 0x80) puts (" TBD (bit 7)\n");
984 if (data[22] & 0x40) puts (" TBD (bit 6)\n");
985 if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
986 else puts (" Upper Vcc tolerance 10%\n");
987 if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
988 else puts (" Lower Vcc tolerance 10%\n");
989 if (data[22] & 0x08) puts (" Supports write1/read burst\n");
990 if (data[22] & 0x04) puts (" Supports precharge all\n");
991 if (data[22] & 0x02) puts (" Supports auto precharge\n");
992 if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
998 printf("SDRAM cycle time (2nd highest CAS latency) %d.",
999 (data[23] >> 4) & 0x0F);
1001 switch (data[23] & 0x0F) {
1012 printf("%d ns\n", data[23] & 0x0F);
1032 printf("SDRAM cycle time (2nd highest CAS latency) %d."
1033 "%d nS\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
1039 printf("SDRAM access from clock (2nd highest CAS latency) 0."
1040 "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
1043 printf("SDRAM access from clock (2nd highest CAS latency) %d."
1044 "%d nS\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
1050 printf("SDRAM cycle time (3rd highest CAS latency) %d.",
1051 (data[25] >> 4) & 0x0F);
1053 switch (data[25] & 0x0F) {
1064 printf("%d ns\n", data[25] & 0x0F);
1084 printf("SDRAM cycle time (3rd highest CAS latency) %d."
1085 "%d nS\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
1091 printf("SDRAM access from clock (3rd highest CAS latency) 0."
1092 "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
1095 printf("SDRAM access from clock (3rd highest CAS latency) %d."
1096 "%d nS\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
1102 printf("Minimum row precharge %d", data[27] >> 2);
1103 switch (data[27] & 0x03) {
1104 case 0x0: puts(".00 ns\n"); break;
1105 case 0x1: puts(".25 ns\n"); break;
1106 case 0x2: puts(".50 ns\n"); break;
1107 case 0x3: puts(".75 ns\n"); break;
1111 printf("Minimum row precharge %d nS\n", data[27]);
1117 printf("Row active to row active min %d", data[28] >> 2);
1118 switch (data[28] & 0x03) {
1119 case 0x0: puts(".00 ns\n"); break;
1120 case 0x1: puts(".25 ns\n"); break;
1121 case 0x2: puts(".50 ns\n"); break;
1122 case 0x3: puts(".75 ns\n"); break;
1126 printf("Row active to row active min %d nS\n", data[28]);
1132 printf("RAS to CAS delay min %d", data[29] >> 2);
1133 switch (data[29] & 0x03) {
1134 case 0x0: puts(".00 ns\n"); break;
1135 case 0x1: puts(".25 ns\n"); break;
1136 case 0x2: puts(".50 ns\n"); break;
1137 case 0x3: puts(".75 ns\n"); break;
1141 printf("RAS to CAS delay min %d nS\n", data[29]);
1145 printf("Minimum RAS pulse width %d nS\n", data[30]);
1149 puts ("Density of each row ");
1150 if (data[31] & 0x80) puts (" 512 MiB\n");
1151 if (data[31] & 0x40) puts (" 256 MiB\n");
1152 if (data[31] & 0x20) puts (" 128 MiB\n");
1153 if (data[31] & 0x10) puts (" 16 GiB\n");
1154 if (data[31] & 0x08) puts (" 8 GiB\n");
1155 if (data[31] & 0x04) puts (" 4 GiB\n");
1156 if (data[31] & 0x02) puts (" 2 GiB\n");
1157 if (data[31] & 0x01) puts (" 1 GiB\n");
1160 puts ("Density of each row ");
1161 if (data[31] & 0x80) puts (" 512 MiB\n");
1162 if (data[31] & 0x40) puts (" 256 MiB\n");
1163 if (data[31] & 0x20) puts (" 128 MiB\n");
1164 if (data[31] & 0x10) puts (" 64 MiB\n");
1165 if (data[31] & 0x08) puts (" 32 MiB\n");
1166 if (data[31] & 0x04) puts (" 16 MiB\n");
1167 if (data[31] & 0x02) puts (" 8 MiB\n");
1168 if (data[31] & 0x01) puts (" 4 MiB\n");
1174 puts("Command and Address setup ");
1175 if (data[32] >= 0xA0) {
1176 printf("1.%d%d ns\n",
1177 ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
1179 printf("0.%d%d ns\n",
1180 ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
1184 printf("Command and Address setup %c%d.%d nS\n",
1185 (data[32] & 0x80) ? '-' : '+',
1186 (data[32] >> 4) & 0x07, data[32] & 0x0F);
1192 puts("Command and Address hold ");
1193 if (data[33] >= 0xA0) {
1194 printf("1.%d%d ns\n",
1195 ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
1197 printf("0.%d%d ns\n",
1198 ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
1202 printf("Command and Address hold %c%d.%d nS\n",
1203 (data[33] & 0x80) ? '-' : '+',
1204 (data[33] >> 4) & 0x07, data[33] & 0x0F);
1210 printf("Data signal input setup 0.%d%d ns\n",
1211 (data[34] >> 4) & 0x0F, data[34] & 0x0F);
1214 printf("Data signal input setup %c%d.%d nS\n",
1215 (data[34] & 0x80) ? '-' : '+',
1216 (data[34] >> 4) & 0x07, data[34] & 0x0F);
1222 printf("Data signal input hold 0.%d%d ns\n",
1223 (data[35] >> 4) & 0x0F, data[35] & 0x0F);
1226 printf("Data signal input hold %c%d.%d nS\n",
1227 (data[35] & 0x80) ? '-' : '+',
1228 (data[35] >> 4) & 0x07, data[35] & 0x0F);
1232 puts ("Manufacturer's JEDEC ID ");
1233 for (j = 64; j <= 71; j++)
1234 printf("%02X ", data[j]);
1236 printf("Manufacturing Location %02X\n", data[72]);
1237 puts ("Manufacturer's Part Number ");
1238 for (j = 73; j <= 90; j++)
1239 printf("%02X ", data[j]);
1241 printf("Revision Code %02X %02X\n", data[91], data[92]);
1242 printf("Manufacturing Date %02X %02X\n", data[93], data[94]);
1243 puts ("Assembly Serial Number ");
1244 for (j = 95; j <= 98; j++)
1245 printf("%02X ", data[j]);
1249 printf("Speed rating PC%d\n",
1250 data[126] == 0x66 ? 66 : data[126]);
1256 #if defined(CONFIG_I2C_CMD_TREE)
1257 #if defined(CONFIG_I2C_MULTI_BUS)
1258 int do_i2c_bus_num(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
1263 /* querying current setting */
1264 printf("Current bus is %d\n", i2c_get_bus_num());
1266 bus_idx = simple_strtoul(argv[1], NULL, 10);
1267 printf("Setting bus to %d\n", bus_idx);
1268 ret = i2c_set_bus_num(bus_idx);
1270 printf("Failure changing bus number (%d)\n", ret);
1274 #endif /* CONFIG_I2C_MULTI_BUS */
1276 int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
1281 /* querying current speed */
1282 printf("Current bus speed=%d\n", i2c_get_bus_speed());
1284 speed = simple_strtoul(argv[1], NULL, 10);
1285 printf("Setting bus speed to %d Hz\n", speed);
1286 ret = i2c_set_bus_speed(speed);
1288 printf("Failure changing bus speed (%d)\n", ret);
1293 int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
1295 #if defined(CONFIG_I2C_MULTI_BUS)
1296 if (!strncmp(argv[1], "de", 2))
1297 return do_i2c_bus_num(cmdtp, flag, --argc, ++argv);
1298 #endif /* CONFIG_I2C_MULTI_BUS */
1299 if (!strncmp(argv[1], "sp", 2))
1300 return do_i2c_bus_speed(cmdtp, flag, --argc, ++argv);
1301 if (!strncmp(argv[1], "md", 2))
1302 return do_i2c_md(cmdtp, flag, --argc, ++argv);
1303 if (!strncmp(argv[1], "mm", 2))
1304 return do_i2c_mm(cmdtp, flag, --argc, ++argv);
1305 if (!strncmp(argv[1], "mw", 2))
1306 return do_i2c_mw(cmdtp, flag, --argc, ++argv);
1307 if (!strncmp(argv[1], "nm", 2))
1308 return do_i2c_nm(cmdtp, flag, --argc, ++argv);
1309 if (!strncmp(argv[1], "cr", 2))
1310 return do_i2c_crc(cmdtp, flag, --argc, ++argv);
1311 if (!strncmp(argv[1], "pr", 2))
1312 return do_i2c_probe(cmdtp, flag, --argc, ++argv);
1313 if (!strncmp(argv[1], "lo", 2))
1314 return do_i2c_loop(cmdtp, flag, --argc, ++argv);
1315 #if defined(CONFIG_CMD_SDRAM)
1316 if (!strncmp(argv[1], "sd", 2))
1317 return do_sdram(cmdtp, flag, --argc, ++argv);
1320 printf ("Usage:\n%s\n", cmdtp->usage);
1323 #endif /* CONFIG_I2C_CMD_TREE */
1325 /***************************************************/
1327 #if defined(CONFIG_I2C_CMD_TREE)
1330 "i2c - I2C sub-system\n",
1331 #if defined(CONFIG_I2C_MULTI_BUS)
1332 "dev [dev] - show or set current I2C bus\n"
1333 #endif /* CONFIG_I2C_MULTI_BUS */
1334 "i2c speed [speed] - show or set I2C bus speed\n"
1335 "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
1336 "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
1337 "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
1338 "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
1339 "i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
1340 "i2c probe - show devices on the I2C bus\n"
1341 "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
1342 #if defined(CONFIG_CMD_SDRAM)
1343 "i2c sdram chip - print SDRAM configuration information\n"
1346 #endif /* CONFIG_I2C_CMD_TREE */
1348 imd, 4, 1, do_i2c_md, \
1349 "imd - i2c memory display\n", \
1350 "chip address[.0, .1, .2] [# of objects]\n - i2c memory display\n" \
1354 imm, 3, 1, do_i2c_mm,
1355 "imm - i2c memory modify (auto-incrementing)\n",
1356 "chip address[.0, .1, .2]\n"
1357 " - memory modify, auto increment address\n"
1360 inm, 3, 1, do_i2c_nm,
1361 "inm - memory modify (constant address)\n",
1362 "chip address[.0, .1, .2]\n - memory modify, read and keep address\n"
1366 imw, 5, 1, do_i2c_mw,
1367 "imw - memory write (fill)\n",
1368 "chip address[.0, .1, .2] value [count]\n - memory write (fill)\n"
1372 icrc32, 5, 1, do_i2c_crc,
1373 "icrc32 - checksum calculation\n",
1374 "chip address[.0, .1, .2] count\n - compute CRC32 checksum\n"
1378 iprobe, 1, 1, do_i2c_probe,
1379 "iprobe - probe to discover valid I2C chip addresses\n",
1380 "\n -discover valid I2C chip addresses\n"
1384 * Require full name for "iloop" because it is an infinite loop!
1387 iloop, 5, 1, do_i2c_loop,
1388 "iloop - infinite loop on address range\n",
1389 "chip address[.0, .1, .2] [# of objects]\n"
1390 " - loop, reading a set of addresses\n"
1393 #if defined(CONFIG_CMD_SDRAM)
1395 isdram, 2, 1, do_sdram,
1396 "isdram - print SDRAM configuration information\n",
1397 "chip\n - print SDRAM configuration information\n"
1398 " (valid chip values 50..57)\n"