3 * Sergey Kubushyn, himself, ksi@koi8.net
5 * Changes for unified multibus/multiadapter I2C support.
8 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
10 * SPDX-License-Identifier: GPL-2.0+
14 * I2C Functions similar to the standard memory functions.
16 * There are several parameters in many of the commands that bear further
19 * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
20 * Each I2C chip on the bus has a unique address. On the I2C data bus,
21 * the address is the upper seven bits and the LSB is the "read/write"
22 * bit. Note that the {i2c_chip} address specified on the command
23 * line is not shifted up: e.g. a typical EEPROM memory chip may have
24 * an I2C address of 0x50, but the data put on the bus will be 0xA0
25 * for write and 0xA1 for read. This "non shifted" address notation
26 * matches at least half of the data sheets :-/.
28 * {addr} is the address (or offset) within the chip. Small memory
29 * chips have 8 bit addresses. Large memory chips have 16 bit
30 * addresses. Other memory chips have 9, 10, or 11 bit addresses.
31 * Many non-memory chips have multiple registers and {addr} is used
32 * as the register index. Some non-memory chips have only one register
33 * and therefore don't need any {addr} parameter.
35 * The default {addr} parameter is one byte (.1) which works well for
36 * memories and registers with 8 bits of address space.
38 * You can specify the length of the {addr} field with the optional .0,
39 * .1, or .2 modifier (similar to the .b, .w, .l modifier). If you are
40 * manipulating a single register device which doesn't use an address
41 * field, use "0.0" for the address and the ".0" length field will
42 * suppress the address in the I2C data stream. This also works for
43 * successive reads using the I2C auto-incrementing memory pointer.
45 * If you are manipulating a large memory with 2-byte addresses, use
46 * the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
48 * Then there are the unfortunate memory chips that spill the most
49 * significant 1, 2, or 3 bits of address into the chip address byte.
50 * This effectively makes one chip (logically) look like 2, 4, or
51 * 8 chips. This is handled (awkwardly) by #defining
52 * CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
53 * {addr} field (since .1 is the default, it doesn't actually have to
54 * be specified). Examples: given a memory chip at I2C chip address
55 * 0x50, the following would happen...
56 * i2c md 50 0 10 display 16 bytes starting at 0x000
57 * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
58 * i2c md 50 100 10 display 16 bytes starting at 0x100
59 * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
60 * i2c md 50 210 10 display 16 bytes starting at 0x210
61 * On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
62 * This is awfully ugly. It would be nice if someone would think up
63 * a better way of handling this.
65 * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
71 #include <environment.h>
74 #include <asm/byteorder.h>
75 #include <linux/compiler.h>
77 DECLARE_GLOBAL_DATA_PTR
;
79 /* Display values from last command.
80 * Memory modify remembered values are different from display memory.
82 static uchar i2c_dp_last_chip
;
83 static uint i2c_dp_last_addr
;
84 static uint i2c_dp_last_alen
;
85 static uint i2c_dp_last_length
= 0x10;
87 static uchar i2c_mm_last_chip
;
88 static uint i2c_mm_last_addr
;
89 static uint i2c_mm_last_alen
;
91 /* If only one I2C bus is present, the list of devices to ignore when
92 * the probe command is issued is represented by a 1D array of addresses.
93 * When multiple buses are present, the list is an array of bus-address
94 * pairs. The following macros take care of this */
96 #if defined(CONFIG_SYS_I2C_NOPROBES)
97 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
102 } i2c_no_probes
[] = CONFIG_SYS_I2C_NOPROBES
;
103 #define GET_BUS_NUM i2c_get_bus_num()
104 #define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b))
105 #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a))
106 #define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr
107 #else /* single bus */
108 static uchar i2c_no_probes
[] = CONFIG_SYS_I2C_NOPROBES
;
109 #define GET_BUS_NUM 0
110 #define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */
111 #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a))
112 #define NO_PROBE_ADDR(i) i2c_no_probes[(i)]
113 #endif /* defined(CONFIG_SYS_I2C) */
116 #define DISP_LINE_LEN 16
119 * i2c_init_board() - Board-specific I2C bus init
121 * This function is the default no-op implementation of I2C bus
122 * initialization. This function can be overriden by board-specific
123 * implementation if needed.
126 void i2c_init_board(void)
130 /* TODO: Implement architecture-specific get/set functions */
133 * i2c_get_bus_speed() - Return I2C bus speed
135 * This function is the default implementation of function for retrieveing
136 * the current I2C bus speed in Hz.
138 * A driver implementing runtime switching of I2C bus speed must override
139 * this function to report the speed correctly. Simple or legacy drivers
140 * can use this fallback.
142 * Returns I2C bus speed in Hz.
144 #if !defined(CONFIG_SYS_I2C)
146 * TODO: Implement architecture-specific get/set functions
147 * Should go away, if we switched completely to new multibus support
150 unsigned int i2c_get_bus_speed(void)
152 return CONFIG_SYS_I2C_SPEED
;
156 * i2c_set_bus_speed() - Configure I2C bus speed
157 * @speed: Newly set speed of the I2C bus in Hz
159 * This function is the default implementation of function for setting
160 * the I2C bus speed in Hz.
162 * A driver implementing runtime switching of I2C bus speed must override
163 * this function to report the speed correctly. Simple or legacy drivers
164 * can use this fallback.
166 * Returns zero on success, negative value on error.
169 int i2c_set_bus_speed(unsigned int speed
)
171 if (speed
!= CONFIG_SYS_I2C_SPEED
)
179 * get_alen() - Small parser helper function to get address length
181 * Returns the address length.
183 static uint
get_alen(char *arg
)
189 for (j
= 0; j
< 8; j
++) {
191 alen
= arg
[j
+1] - '0';
193 } else if (arg
[j
] == '\0')
200 * do_i2c_read() - Handle the "i2c read" command-line command
201 * @cmdtp: Command data struct pointer
202 * @flag: Command flag
203 * @argc: Command-line argument count
204 * @argv: Array of command-line arguments
206 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
210 * i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr}
212 static int do_i2c_read ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
215 uint devaddr
, alen
, length
;
219 return CMD_RET_USAGE
;
224 chip
= simple_strtoul(argv
[1], NULL
, 16);
227 * I2C data address within the chip. This can be 1 or
228 * 2 bytes long. Some day it might be 3 bytes long :-).
230 devaddr
= simple_strtoul(argv
[2], NULL
, 16);
231 alen
= get_alen(argv
[2]);
233 return CMD_RET_USAGE
;
236 * Length is the number of objects, not number of bytes.
238 length
= simple_strtoul(argv
[3], NULL
, 16);
241 * memaddr is the address where to store things in memory
243 memaddr
= (u_char
*)simple_strtoul(argv
[4], NULL
, 16);
245 if (i2c_read(chip
, devaddr
, alen
, memaddr
, length
) != 0) {
246 puts ("Error reading the chip.\n");
252 static int do_i2c_write(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
255 uint devaddr
, alen
, length
;
259 return cmd_usage(cmdtp
);
262 * memaddr is the address where to store things in memory
264 memaddr
= (u_char
*)simple_strtoul(argv
[1], NULL
, 16);
269 chip
= simple_strtoul(argv
[2], NULL
, 16);
272 * I2C data address within the chip. This can be 1 or
273 * 2 bytes long. Some day it might be 3 bytes long :-).
275 devaddr
= simple_strtoul(argv
[3], NULL
, 16);
276 alen
= get_alen(argv
[3]);
278 return cmd_usage(cmdtp
);
281 * Length is the number of objects, not number of bytes.
283 length
= simple_strtoul(argv
[4], NULL
, 16);
285 while (length
-- > 0) {
286 if (i2c_write(chip
, devaddr
++, alen
, memaddr
++, 1) != 0) {
287 puts("Error writing to the chip.\n");
291 * No write delay with FRAM devices.
293 #if !defined(CONFIG_SYS_I2C_FRAM)
301 * do_i2c_md() - Handle the "i2c md" command-line command
302 * @cmdtp: Command data struct pointer
303 * @flag: Command flag
304 * @argc: Command-line argument count
305 * @argv: Array of command-line arguments
307 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
311 * i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
313 static int do_i2c_md ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
316 uint addr
, alen
, length
;
317 int j
, nbytes
, linebytes
;
319 /* We use the last specified parameters, unless new ones are
322 chip
= i2c_dp_last_chip
;
323 addr
= i2c_dp_last_addr
;
324 alen
= i2c_dp_last_alen
;
325 length
= i2c_dp_last_length
;
328 return CMD_RET_USAGE
;
330 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
332 * New command specified.
338 chip
= simple_strtoul(argv
[1], NULL
, 16);
341 * I2C data address within the chip. This can be 1 or
342 * 2 bytes long. Some day it might be 3 bytes long :-).
344 addr
= simple_strtoul(argv
[2], NULL
, 16);
345 alen
= get_alen(argv
[2]);
347 return CMD_RET_USAGE
;
350 * If another parameter, it is the length to display.
351 * Length is the number of objects, not number of bytes.
354 length
= simple_strtoul(argv
[3], NULL
, 16);
360 * We buffer all read data, so we can make sure data is read only
365 unsigned char linebuf
[DISP_LINE_LEN
];
368 linebytes
= (nbytes
> DISP_LINE_LEN
) ? DISP_LINE_LEN
: nbytes
;
370 if (i2c_read(chip
, addr
, alen
, linebuf
, linebytes
) != 0)
371 puts ("Error reading the chip.\n");
373 printf("%04x:", addr
);
375 for (j
=0; j
<linebytes
; j
++) {
376 printf(" %02x", *cp
++);
381 for (j
=0; j
<linebytes
; j
++) {
382 if ((*cp
< 0x20) || (*cp
> 0x7e))
391 } while (nbytes
> 0);
393 i2c_dp_last_chip
= chip
;
394 i2c_dp_last_addr
= addr
;
395 i2c_dp_last_alen
= alen
;
396 i2c_dp_last_length
= length
;
402 * do_i2c_mw() - Handle the "i2c mw" command-line command
403 * @cmdtp: Command data struct pointer
404 * @flag: Command flag
405 * @argc: Command-line argument count
406 * @argv: Array of command-line arguments
408 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
412 * i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
414 static int do_i2c_mw ( cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
422 if ((argc
< 4) || (argc
> 5))
423 return CMD_RET_USAGE
;
426 * Chip is always specified.
428 chip
= simple_strtoul(argv
[1], NULL
, 16);
431 * Address is always specified.
433 addr
= simple_strtoul(argv
[2], NULL
, 16);
434 alen
= get_alen(argv
[2]);
436 return CMD_RET_USAGE
;
439 * Value to write is always specified.
441 byte
= simple_strtoul(argv
[3], NULL
, 16);
447 count
= simple_strtoul(argv
[4], NULL
, 16);
451 while (count
-- > 0) {
452 if (i2c_write(chip
, addr
++, alen
, &byte
, 1) != 0)
453 puts ("Error writing the chip.\n");
455 * Wait for the write to complete. The write can take
456 * up to 10mSec (we allow a little more time).
459 * No write delay with FRAM devices.
461 #if !defined(CONFIG_SYS_I2C_FRAM)
470 * do_i2c_crc() - Handle the "i2c crc32" command-line command
471 * @cmdtp: Command data struct pointer
472 * @flag: Command flag
473 * @argc: Command-line argument count
474 * @argv: Array of command-line arguments
476 * Calculate a CRC on memory
478 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
482 * i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
484 static int do_i2c_crc (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
495 return CMD_RET_USAGE
;
498 * Chip is always specified.
500 chip
= simple_strtoul(argv
[1], NULL
, 16);
503 * Address is always specified.
505 addr
= simple_strtoul(argv
[2], NULL
, 16);
506 alen
= get_alen(argv
[2]);
508 return CMD_RET_USAGE
;
511 * Count is always specified
513 count
= simple_strtoul(argv
[3], NULL
, 16);
515 printf ("CRC32 for %08lx ... %08lx ==> ", addr
, addr
+ count
- 1);
517 * CRC a byte at a time. This is going to be slooow, but hey, the
518 * memories are small and slow too so hopefully nobody notices.
522 while (count
-- > 0) {
523 if (i2c_read(chip
, addr
, alen
, &byte
, 1) != 0)
525 crc
= crc32 (crc
, &byte
, 1);
529 puts ("Error reading the chip,\n");
531 printf ("%08lx\n", crc
);
537 * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
538 * @cmdtp: Command data struct pointer
539 * @flag: Command flag
540 * @argc: Command-line argument count
541 * @argv: Array of command-line arguments
545 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
549 * i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
550 * i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
553 mod_i2c_mem(cmd_tbl_t
*cmdtp
, int incrflag
, int flag
, int argc
, char * const argv
[])
563 return CMD_RET_USAGE
;
565 #ifdef CONFIG_BOOT_RETRY_TIME
566 reset_cmd_timeout(); /* got a good command to get here */
569 * We use the last specified parameters, unless new ones are
572 chip
= i2c_mm_last_chip
;
573 addr
= i2c_mm_last_addr
;
574 alen
= i2c_mm_last_alen
;
576 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
578 * New command specified. Check for a size specification.
579 * Defaults to byte if no or incorrect specification.
581 size
= cmd_get_data_size(argv
[0], 1);
584 * Chip is always specified.
586 chip
= simple_strtoul(argv
[1], NULL
, 16);
589 * Address is always specified.
591 addr
= simple_strtoul(argv
[2], NULL
, 16);
592 alen
= get_alen(argv
[2]);
594 return CMD_RET_USAGE
;
598 * Print the address, followed by value. Then accept input for
599 * the next value. A non-converted value exits.
602 printf("%08lx:", addr
);
603 if (i2c_read(chip
, addr
, alen
, (uchar
*)&data
, size
) != 0)
604 puts ("\nError reading the chip,\n");
606 data
= cpu_to_be32(data
);
608 printf(" %02lx", (data
>> 24) & 0x000000FF);
610 printf(" %04lx", (data
>> 16) & 0x0000FFFF);
612 printf(" %08lx", data
);
615 nbytes
= readline (" ? ");
618 * <CR> pressed as only input, don't modify current
619 * location and move to next.
624 #ifdef CONFIG_BOOT_RETRY_TIME
625 reset_cmd_timeout(); /* good enough to not time out */
628 #ifdef CONFIG_BOOT_RETRY_TIME
629 else if (nbytes
== -2)
630 break; /* timed out, exit the command */
635 data
= simple_strtoul(console_buffer
, &endp
, 16);
640 data
= be32_to_cpu(data
);
641 nbytes
= endp
- console_buffer
;
643 #ifdef CONFIG_BOOT_RETRY_TIME
645 * good enough to not time out
649 if (i2c_write(chip
, addr
, alen
, (uchar
*)&data
, size
) != 0)
650 puts ("Error writing the chip.\n");
651 #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
652 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
* 1000);
660 i2c_mm_last_chip
= chip
;
661 i2c_mm_last_addr
= addr
;
662 i2c_mm_last_alen
= alen
;
668 * do_i2c_probe() - Handle the "i2c probe" command-line command
669 * @cmdtp: Command data struct pointer
670 * @flag: Command flag
671 * @argc: Command-line argument count
672 * @argv: Array of command-line arguments
674 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
680 * Returns zero (success) if one or more I2C devices was found
682 static int do_i2c_probe (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
687 #if defined(CONFIG_SYS_I2C_NOPROBES)
689 unsigned int bus
= GET_BUS_NUM
;
690 #endif /* NOPROBES */
693 addr
= simple_strtol(argv
[1], 0, 16);
695 puts ("Valid chip addresses:");
696 for (j
= 0; j
< 128; j
++) {
697 if ((0 <= addr
) && (j
!= addr
))
700 #if defined(CONFIG_SYS_I2C_NOPROBES)
702 for (k
= 0; k
< ARRAY_SIZE(i2c_no_probes
); k
++) {
703 if (COMPARE_BUS(bus
, k
) && COMPARE_ADDR(j
, k
)) {
711 if (i2c_probe(j
) == 0) {
718 #if defined(CONFIG_SYS_I2C_NOPROBES)
719 puts ("Excluded chip addresses:");
720 for (k
= 0; k
< ARRAY_SIZE(i2c_no_probes
); k
++) {
721 if (COMPARE_BUS(bus
,k
))
722 printf(" %02X", NO_PROBE_ADDR(k
));
731 * do_i2c_loop() - Handle the "i2c loop" command-line command
732 * @cmdtp: Command data struct pointer
733 * @flag: Command flag
734 * @argc: Command-line argument count
735 * @argv: Array of command-line arguments
737 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
741 * i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
742 * {length} - Number of bytes to read
743 * {delay} - A DECIMAL number and defaults to 1000 uSec
745 static int do_i2c_loop(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
755 return CMD_RET_USAGE
;
758 * Chip is always specified.
760 chip
= simple_strtoul(argv
[1], NULL
, 16);
763 * Address is always specified.
765 addr
= simple_strtoul(argv
[2], NULL
, 16);
766 alen
= get_alen(argv
[2]);
768 return CMD_RET_USAGE
;
771 * Length is the number of objects, not number of bytes.
774 length
= simple_strtoul(argv
[3], NULL
, 16);
775 if (length
> sizeof(bytes
))
776 length
= sizeof(bytes
);
779 * The delay time (uSec) is optional.
783 delay
= simple_strtoul(argv
[4], NULL
, 10);
788 if (i2c_read(chip
, addr
, alen
, bytes
, length
) != 0)
789 puts ("Error reading the chip.\n");
798 * The SDRAM command is separately configured because many
799 * (most?) embedded boards don't use SDRAM DIMMs.
801 * FIXME: Document and probably move elsewhere!
803 #if defined(CONFIG_CMD_SDRAM)
804 static void print_ddr2_tcyc (u_char
const b
)
806 printf ("%d.", (b
>> 4) & 0x0F);
818 printf ("%d ns\n", b
& 0x0F);
838 static void decode_bits (u_char
const b
, char const *str
[], int const do_once
)
842 for (mask
= 0x80; mask
!= 0x00; mask
>>= 1, ++str
) {
853 * i2c sdram {i2c_chip}
855 static int do_sdram (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
857 enum { unknown
, EDO
, SDRAM
, DDR2
} type
;
864 static const char *decode_CAS_DDR2
[] = {
865 " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
868 static const char *decode_CAS_default
[] = {
869 " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
872 static const char *decode_CS_WE_default
[] = {
873 " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
876 static const char *decode_byte21_default
[] = {
878 " Redundant row address\n",
879 " Differential clock input\n",
880 " Registerd DQMB inputs\n",
881 " Buffered DQMB inputs\n",
883 " Registered address/control lines\n",
884 " Buffered address/control lines\n"
887 static const char *decode_byte22_DDR2
[] = {
893 " Supports partial array self refresh\n",
894 " Supports 50 ohm ODT\n",
895 " Supports weak driver\n"
898 static const char *decode_row_density_DDR2
[] = {
899 "512 MiB", "256 MiB", "128 MiB", "16 GiB",
900 "8 GiB", "4 GiB", "2 GiB", "1 GiB"
903 static const char *decode_row_density_default
[] = {
904 "512 MiB", "256 MiB", "128 MiB", "64 MiB",
905 "32 MiB", "16 MiB", "8 MiB", "4 MiB"
909 return CMD_RET_USAGE
;
912 * Chip is always specified.
914 chip
= simple_strtoul (argv
[1], NULL
, 16);
916 if (i2c_read (chip
, 0, 1, data
, sizeof (data
)) != 0) {
917 puts ("No SDRAM Serial Presence Detect found.\n");
922 for (j
= 0; j
< 63; j
++) {
925 if (cksum
!= data
[63]) {
926 printf ("WARNING: Configuration data checksum failure:\n"
927 " is 0x%02x, calculated 0x%02x\n", data
[63], cksum
);
929 printf ("SPD data revision %d.%d\n",
930 (data
[62] >> 4) & 0x0F, data
[62] & 0x0F);
931 printf ("Bytes used 0x%02X\n", data
[0]);
932 printf ("Serial memory size 0x%02X\n", 1 << data
[1]);
934 puts ("Memory type ");
954 puts ("Row address bits ");
955 if ((data
[3] & 0x00F0) == 0)
956 printf ("%d\n", data
[3] & 0x0F);
958 printf ("%d/%d\n", data
[3] & 0x0F, (data
[3] >> 4) & 0x0F);
960 puts ("Column address bits ");
961 if ((data
[4] & 0x00F0) == 0)
962 printf ("%d\n", data
[4] & 0x0F);
964 printf ("%d/%d\n", data
[4] & 0x0F, (data
[4] >> 4) & 0x0F);
968 printf ("Number of ranks %d\n",
969 (data
[5] & 0x07) + 1);
972 printf ("Module rows %d\n", data
[5]);
978 printf ("Module data width %d bits\n", data
[6]);
981 printf ("Module data width %d bits\n",
982 (data
[7] << 8) | data
[6]);
986 puts ("Interface signal levels ");
988 case 0: puts ("TTL 5.0 V\n"); break;
989 case 1: puts ("LVTTL\n"); break;
990 case 2: puts ("HSTL 1.5 V\n"); break;
991 case 3: puts ("SSTL 3.3 V\n"); break;
992 case 4: puts ("SSTL 2.5 V\n"); break;
993 case 5: puts ("SSTL 1.8 V\n"); break;
994 default: puts ("unknown\n"); break;
999 printf ("SDRAM cycle time ");
1000 print_ddr2_tcyc (data
[9]);
1003 printf ("SDRAM cycle time %d.%d ns\n",
1004 (data
[9] >> 4) & 0x0F, data
[9] & 0x0F);
1010 printf ("SDRAM access time 0.%d%d ns\n",
1011 (data
[10] >> 4) & 0x0F, data
[10] & 0x0F);
1014 printf ("SDRAM access time %d.%d ns\n",
1015 (data
[10] >> 4) & 0x0F, data
[10] & 0x0F);
1019 puts ("EDC configuration ");
1021 case 0: puts ("None\n"); break;
1022 case 1: puts ("Parity\n"); break;
1023 case 2: puts ("ECC\n"); break;
1024 default: puts ("unknown\n"); break;
1027 if ((data
[12] & 0x80) == 0)
1028 puts ("No self refresh, rate ");
1030 puts ("Self refresh, rate ");
1032 switch(data
[12] & 0x7F) {
1033 case 0: puts ("15.625 us\n"); break;
1034 case 1: puts ("3.9 us\n"); break;
1035 case 2: puts ("7.8 us\n"); break;
1036 case 3: puts ("31.3 us\n"); break;
1037 case 4: puts ("62.5 us\n"); break;
1038 case 5: puts ("125 us\n"); break;
1039 default: puts ("unknown\n"); break;
1044 printf ("SDRAM width (primary) %d\n", data
[13]);
1047 printf ("SDRAM width (primary) %d\n", data
[13] & 0x7F);
1048 if ((data
[13] & 0x80) != 0) {
1049 printf (" (second bank) %d\n",
1050 2 * (data
[13] & 0x7F));
1058 printf ("EDC width %d\n", data
[14]);
1061 if (data
[14] != 0) {
1062 printf ("EDC width %d\n",
1065 if ((data
[14] & 0x80) != 0) {
1066 printf (" (second bank) %d\n",
1067 2 * (data
[14] & 0x7F));
1074 printf ("Min clock delay, back-to-back random column addresses "
1078 puts ("Burst length(s) ");
1079 if (data
[16] & 0x80) puts (" Page");
1080 if (data
[16] & 0x08) puts (" 8");
1081 if (data
[16] & 0x04) puts (" 4");
1082 if (data
[16] & 0x02) puts (" 2");
1083 if (data
[16] & 0x01) puts (" 1");
1085 printf ("Number of banks %d\n", data
[17]);
1089 puts ("CAS latency(s) ");
1090 decode_bits (data
[18], decode_CAS_DDR2
, 0);
1094 puts ("CAS latency(s) ");
1095 decode_bits (data
[18], decode_CAS_default
, 0);
1101 puts ("CS latency(s) ");
1102 decode_bits (data
[19], decode_CS_WE_default
, 0);
1107 puts ("WE latency(s) ");
1108 decode_bits (data
[20], decode_CS_WE_default
, 0);
1114 puts ("Module attributes:\n");
1115 if (data
[21] & 0x80)
1116 puts (" TBD (bit 7)\n");
1117 if (data
[21] & 0x40)
1118 puts (" Analysis probe installed\n");
1119 if (data
[21] & 0x20)
1120 puts (" TBD (bit 5)\n");
1121 if (data
[21] & 0x10)
1122 puts (" FET switch external enable\n");
1123 printf (" %d PLLs on DIMM\n", (data
[21] >> 2) & 0x03);
1124 if (data
[20] & 0x11) {
1125 printf (" %d active registers on DIMM\n",
1126 (data
[21] & 0x03) + 1);
1130 puts ("Module attributes:\n");
1134 decode_bits (data
[21], decode_byte21_default
, 0);
1140 decode_bits (data
[22], decode_byte22_DDR2
, 0);
1143 puts ("Device attributes:\n");
1144 if (data
[22] & 0x80) puts (" TBD (bit 7)\n");
1145 if (data
[22] & 0x40) puts (" TBD (bit 6)\n");
1146 if (data
[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
1147 else puts (" Upper Vcc tolerance 10%\n");
1148 if (data
[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
1149 else puts (" Lower Vcc tolerance 10%\n");
1150 if (data
[22] & 0x08) puts (" Supports write1/read burst\n");
1151 if (data
[22] & 0x04) puts (" Supports precharge all\n");
1152 if (data
[22] & 0x02) puts (" Supports auto precharge\n");
1153 if (data
[22] & 0x01) puts (" Supports early RAS# precharge\n");
1159 printf ("SDRAM cycle time (2nd highest CAS latency) ");
1160 print_ddr2_tcyc (data
[23]);
1163 printf ("SDRAM cycle time (2nd highest CAS latency) %d."
1164 "%d ns\n", (data
[23] >> 4) & 0x0F, data
[23] & 0x0F);
1170 printf ("SDRAM access from clock (2nd highest CAS latency) 0."
1171 "%d%d ns\n", (data
[24] >> 4) & 0x0F, data
[24] & 0x0F);
1174 printf ("SDRAM access from clock (2nd highest CAS latency) %d."
1175 "%d ns\n", (data
[24] >> 4) & 0x0F, data
[24] & 0x0F);
1181 printf ("SDRAM cycle time (3rd highest CAS latency) ");
1182 print_ddr2_tcyc (data
[25]);
1185 printf ("SDRAM cycle time (3rd highest CAS latency) %d."
1186 "%d ns\n", (data
[25] >> 4) & 0x0F, data
[25] & 0x0F);
1192 printf ("SDRAM access from clock (3rd highest CAS latency) 0."
1193 "%d%d ns\n", (data
[26] >> 4) & 0x0F, data
[26] & 0x0F);
1196 printf ("SDRAM access from clock (3rd highest CAS latency) %d."
1197 "%d ns\n", (data
[26] >> 4) & 0x0F, data
[26] & 0x0F);
1203 printf ("Minimum row precharge %d.%02d ns\n",
1204 (data
[27] >> 2) & 0x3F, 25 * (data
[27] & 0x03));
1207 printf ("Minimum row precharge %d ns\n", data
[27]);
1213 printf ("Row active to row active min %d.%02d ns\n",
1214 (data
[28] >> 2) & 0x3F, 25 * (data
[28] & 0x03));
1217 printf ("Row active to row active min %d ns\n", data
[28]);
1223 printf ("RAS to CAS delay min %d.%02d ns\n",
1224 (data
[29] >> 2) & 0x3F, 25 * (data
[29] & 0x03));
1227 printf ("RAS to CAS delay min %d ns\n", data
[29]);
1231 printf ("Minimum RAS pulse width %d ns\n", data
[30]);
1235 puts ("Density of each row ");
1236 decode_bits (data
[31], decode_row_density_DDR2
, 1);
1240 puts ("Density of each row ");
1241 decode_bits (data
[31], decode_row_density_default
, 1);
1248 puts ("Command and Address setup ");
1249 if (data
[32] >= 0xA0) {
1250 printf ("1.%d%d ns\n",
1251 ((data
[32] >> 4) & 0x0F) - 10, data
[32] & 0x0F);
1253 printf ("0.%d%d ns\n",
1254 ((data
[32] >> 4) & 0x0F), data
[32] & 0x0F);
1258 printf ("Command and Address setup %c%d.%d ns\n",
1259 (data
[32] & 0x80) ? '-' : '+',
1260 (data
[32] >> 4) & 0x07, data
[32] & 0x0F);
1266 puts ("Command and Address hold ");
1267 if (data
[33] >= 0xA0) {
1268 printf ("1.%d%d ns\n",
1269 ((data
[33] >> 4) & 0x0F) - 10, data
[33] & 0x0F);
1271 printf ("0.%d%d ns\n",
1272 ((data
[33] >> 4) & 0x0F), data
[33] & 0x0F);
1276 printf ("Command and Address hold %c%d.%d ns\n",
1277 (data
[33] & 0x80) ? '-' : '+',
1278 (data
[33] >> 4) & 0x07, data
[33] & 0x0F);
1284 printf ("Data signal input setup 0.%d%d ns\n",
1285 (data
[34] >> 4) & 0x0F, data
[34] & 0x0F);
1288 printf ("Data signal input setup %c%d.%d ns\n",
1289 (data
[34] & 0x80) ? '-' : '+',
1290 (data
[34] >> 4) & 0x07, data
[34] & 0x0F);
1296 printf ("Data signal input hold 0.%d%d ns\n",
1297 (data
[35] >> 4) & 0x0F, data
[35] & 0x0F);
1300 printf ("Data signal input hold %c%d.%d ns\n",
1301 (data
[35] & 0x80) ? '-' : '+',
1302 (data
[35] >> 4) & 0x07, data
[35] & 0x0F);
1306 puts ("Manufacturer's JEDEC ID ");
1307 for (j
= 64; j
<= 71; j
++)
1308 printf ("%02X ", data
[j
]);
1310 printf ("Manufacturing Location %02X\n", data
[72]);
1311 puts ("Manufacturer's Part Number ");
1312 for (j
= 73; j
<= 90; j
++)
1313 printf ("%02X ", data
[j
]);
1315 printf ("Revision Code %02X %02X\n", data
[91], data
[92]);
1316 printf ("Manufacturing Date %02X %02X\n", data
[93], data
[94]);
1317 puts ("Assembly Serial Number ");
1318 for (j
= 95; j
<= 98; j
++)
1319 printf ("%02X ", data
[j
]);
1323 printf ("Speed rating PC%d\n",
1324 data
[126] == 0x66 ? 66 : data
[126]);
1332 * i2c edid {i2c_chip}
1334 #if defined(CONFIG_I2C_EDID)
1335 int do_edid(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
1338 struct edid1_info edid
;
1345 chip
= simple_strtoul(argv
[1], NULL
, 16);
1346 if (i2c_read(chip
, 0, 1, (uchar
*)&edid
, sizeof(edid
)) != 0) {
1347 puts("Error reading EDID content.\n");
1351 if (edid_check_info(&edid
)) {
1352 puts("Content isn't valid EDID.\n");
1356 edid_print_info(&edid
);
1360 #endif /* CONFIG_I2C_EDID */
1363 * do_i2c_show_bus() - Handle the "i2c bus" command-line command
1364 * @cmdtp: Command data struct pointer
1365 * @flag: Command flag
1366 * @argc: Command-line argument count
1367 * @argv: Array of command-line arguments
1369 * Returns zero always.
1371 #if defined(CONFIG_SYS_I2C)
1372 int do_i2c_show_bus(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1375 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
1380 /* show all busses */
1381 for (i
= 0; i
< CONFIG_SYS_NUM_I2C_BUSES
; i
++) {
1382 printf("Bus %d:\t%s", i
, I2C_ADAP_NR(i
)->name
);
1383 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
1384 for (j
= 0; j
< CONFIG_SYS_I2C_MAX_HOPS
; j
++) {
1385 if (i2c_bus
[i
].next_hop
[j
].chip
== 0)
1387 printf("->%s@0x%2x:%d",
1388 i2c_bus
[i
].next_hop
[j
].mux
.name
,
1389 i2c_bus
[i
].next_hop
[j
].chip
,
1390 i2c_bus
[i
].next_hop
[j
].channel
);
1396 /* show specific bus */
1397 i
= simple_strtoul(argv
[1], NULL
, 10);
1398 if (i
>= CONFIG_SYS_NUM_I2C_BUSES
) {
1399 printf("Invalid bus %d\n", i
);
1402 printf("Bus %d:\t%s", i
, I2C_ADAP_NR(i
)->name
);
1403 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
1404 for (j
= 0; j
< CONFIG_SYS_I2C_MAX_HOPS
; j
++) {
1405 if (i2c_bus
[i
].next_hop
[j
].chip
== 0)
1407 printf("->%s@0x%2x:%d",
1408 i2c_bus
[i
].next_hop
[j
].mux
.name
,
1409 i2c_bus
[i
].next_hop
[j
].chip
,
1410 i2c_bus
[i
].next_hop
[j
].channel
);
1421 * do_i2c_bus_num() - Handle the "i2c dev" command-line command
1422 * @cmdtp: Command data struct pointer
1423 * @flag: Command flag
1424 * @argc: Command-line argument count
1425 * @argv: Array of command-line arguments
1427 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1430 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
1431 int do_i2c_bus_num(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1434 unsigned int bus_no
;
1437 /* querying current setting */
1438 printf("Current bus is %d\n", i2c_get_bus_num());
1440 bus_no
= simple_strtoul(argv
[1], NULL
, 10);
1441 #if defined(CONFIG_SYS_I2C)
1442 if (bus_no
>= CONFIG_SYS_NUM_I2C_BUSES
) {
1443 printf("Invalid bus %d\n", bus_no
);
1447 printf("Setting bus to %d\n", bus_no
);
1448 ret
= i2c_set_bus_num(bus_no
);
1450 printf("Failure changing bus number (%d)\n", ret
);
1454 #endif /* defined(CONFIG_SYS_I2C) */
1457 * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
1458 * @cmdtp: Command data struct pointer
1459 * @flag: Command flag
1460 * @argc: Command-line argument count
1461 * @argv: Array of command-line arguments
1463 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1466 static int do_i2c_bus_speed(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
1471 /* querying current speed */
1472 printf("Current bus speed=%d\n", i2c_get_bus_speed());
1474 speed
= simple_strtoul(argv
[1], NULL
, 10);
1475 printf("Setting bus speed to %d Hz\n", speed
);
1476 ret
= i2c_set_bus_speed(speed
);
1478 printf("Failure changing bus speed (%d)\n", ret
);
1484 * do_i2c_mm() - Handle the "i2c mm" command-line command
1485 * @cmdtp: Command data struct pointer
1486 * @flag: Command flag
1487 * @argc: Command-line argument count
1488 * @argv: Array of command-line arguments
1490 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1493 static int do_i2c_mm(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
1495 return mod_i2c_mem (cmdtp
, 1, flag
, argc
, argv
);
1499 * do_i2c_nm() - Handle the "i2c nm" command-line command
1500 * @cmdtp: Command data struct pointer
1501 * @flag: Command flag
1502 * @argc: Command-line argument count
1503 * @argv: Array of command-line arguments
1505 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1508 static int do_i2c_nm(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
1510 return mod_i2c_mem (cmdtp
, 0, flag
, argc
, argv
);
1514 * do_i2c_reset() - Handle the "i2c reset" command-line command
1515 * @cmdtp: Command data struct pointer
1516 * @flag: Command flag
1517 * @argc: Command-line argument count
1518 * @argv: Array of command-line arguments
1520 * Returns zero always.
1522 static int do_i2c_reset(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
1524 #if defined(CONFIG_SYS_I2C)
1525 i2c_init(I2C_ADAP
->speed
, I2C_ADAP
->slaveaddr
);
1527 i2c_init(CONFIG_SYS_I2C_SPEED
, CONFIG_SYS_I2C_SLAVE
);
1532 static cmd_tbl_t cmd_i2c_sub
[] = {
1533 #if defined(CONFIG_SYS_I2C)
1534 U_BOOT_CMD_MKENT(bus
, 1, 1, do_i2c_show_bus
, "", ""),
1536 U_BOOT_CMD_MKENT(crc32
, 3, 1, do_i2c_crc
, "", ""),
1537 #if defined(CONFIG_SYS_I2C) || \
1538 defined(CONFIG_I2C_MULTI_BUS)
1539 U_BOOT_CMD_MKENT(dev
, 1, 1, do_i2c_bus_num
, "", ""),
1540 #endif /* CONFIG_I2C_MULTI_BUS */
1541 #if defined(CONFIG_I2C_EDID)
1542 U_BOOT_CMD_MKENT(edid
, 1, 1, do_edid
, "", ""),
1543 #endif /* CONFIG_I2C_EDID */
1544 U_BOOT_CMD_MKENT(loop
, 3, 1, do_i2c_loop
, "", ""),
1545 U_BOOT_CMD_MKENT(md
, 3, 1, do_i2c_md
, "", ""),
1546 U_BOOT_CMD_MKENT(mm
, 2, 1, do_i2c_mm
, "", ""),
1547 U_BOOT_CMD_MKENT(mw
, 3, 1, do_i2c_mw
, "", ""),
1548 U_BOOT_CMD_MKENT(nm
, 2, 1, do_i2c_nm
, "", ""),
1549 U_BOOT_CMD_MKENT(probe
, 0, 1, do_i2c_probe
, "", ""),
1550 U_BOOT_CMD_MKENT(read
, 5, 1, do_i2c_read
, "", ""),
1551 U_BOOT_CMD_MKENT(write
, 5, 0, do_i2c_write
, "", ""),
1552 U_BOOT_CMD_MKENT(reset
, 0, 1, do_i2c_reset
, "", ""),
1553 #if defined(CONFIG_CMD_SDRAM)
1554 U_BOOT_CMD_MKENT(sdram
, 1, 1, do_sdram
, "", ""),
1556 U_BOOT_CMD_MKENT(speed
, 1, 1, do_i2c_bus_speed
, "", ""),
1559 #ifdef CONFIG_NEEDS_MANUAL_RELOC
1560 void i2c_reloc(void) {
1561 fixup_cmdtable(cmd_i2c_sub
, ARRAY_SIZE(cmd_i2c_sub
));
1566 * do_i2c() - Handle the "i2c" command-line command
1567 * @cmdtp: Command data struct pointer
1568 * @flag: Command flag
1569 * @argc: Command-line argument count
1570 * @argv: Array of command-line arguments
1572 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1575 static int do_i2c(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
1580 return CMD_RET_USAGE
;
1582 /* Strip off leading 'i2c' command argument */
1586 c
= find_cmd_tbl(argv
[0], &cmd_i2c_sub
[0], ARRAY_SIZE(cmd_i2c_sub
));
1589 return c
->cmd(cmdtp
, flag
, argc
, argv
);
1591 return CMD_RET_USAGE
;
1594 /***************************************************/
1595 #ifdef CONFIG_SYS_LONGHELP
1596 static char i2c_help_text
[] =
1597 #if defined(CONFIG_SYS_I2C)
1598 "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
1600 "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
1601 #if defined(CONFIG_SYS_I2C) || \
1602 defined(CONFIG_I2C_MULTI_BUS)
1603 "i2c dev [dev] - show or set current I2C bus\n"
1604 #endif /* CONFIG_I2C_MULTI_BUS */
1605 #if defined(CONFIG_I2C_EDID)
1606 "i2c edid chip - print EDID configuration information\n"
1607 #endif /* CONFIG_I2C_EDID */
1608 "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
1609 "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
1610 "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
1611 "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
1612 "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
1613 "i2c probe [address] - test for and show device(s) on the I2C bus\n"
1614 "i2c read chip address[.0, .1, .2] length memaddress - read to memory \n"
1615 "i2c write memaddress chip address[.0, .1, .2] length - write memory to i2c\n"
1616 "i2c reset - re-init the I2C Controller\n"
1617 #if defined(CONFIG_CMD_SDRAM)
1618 "i2c sdram chip - print SDRAM configuration information\n"
1620 "i2c speed [speed] - show or set I2C bus speed";