1 // SPDX-License-Identifier: GPL-2.0+
4 * Sergey Kubushyn, himself, ksi@koi8.net
6 * Changes for unified multibus/multiadapter I2C support.
9 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
13 * I2C Functions similar to the standard memory functions.
15 * There are several parameters in many of the commands that bear further
18 * {i2c_chip} is the I2C chip address (the first byte sent on the bus).
19 * Each I2C chip on the bus has a unique address. On the I2C data bus,
20 * the address is the upper seven bits and the LSB is the "read/write"
21 * bit. Note that the {i2c_chip} address specified on the command
22 * line is not shifted up: e.g. a typical EEPROM memory chip may have
23 * an I2C address of 0x50, but the data put on the bus will be 0xA0
24 * for write and 0xA1 for read. This "non shifted" address notation
25 * matches at least half of the data sheets :-/.
27 * {addr} is the address (or offset) within the chip. Small memory
28 * chips have 8 bit addresses. Large memory chips have 16 bit
29 * addresses. Other memory chips have 9, 10, or 11 bit addresses.
30 * Many non-memory chips have multiple registers and {addr} is used
31 * as the register index. Some non-memory chips have only one register
32 * and therefore don't need any {addr} parameter.
34 * The default {addr} parameter is one byte (.1) which works well for
35 * memories and registers with 8 bits of address space.
37 * You can specify the length of the {addr} field with the optional .0,
38 * .1, or .2 modifier (similar to the .b, .w, .l modifier). If you are
39 * manipulating a single register device which doesn't use an address
40 * field, use "0.0" for the address and the ".0" length field will
41 * suppress the address in the I2C data stream. This also works for
42 * successive reads using the I2C auto-incrementing memory pointer.
44 * If you are manipulating a large memory with 2-byte addresses, use
45 * the .2 address modifier, e.g. 210.2 addresses location 528 (decimal).
47 * Then there are the unfortunate memory chips that spill the most
48 * significant 1, 2, or 3 bits of address into the chip address byte.
49 * This effectively makes one chip (logically) look like 2, 4, or
50 * 8 chips. This is handled (awkwardly) by #defining
51 * CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
52 * {addr} field (since .1 is the default, it doesn't actually have to
53 * be specified). Examples: given a memory chip at I2C chip address
54 * 0x50, the following would happen...
55 * i2c md 50 0 10 display 16 bytes starting at 0x000
56 * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
57 * i2c md 50 100 10 display 16 bytes starting at 0x100
58 * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
59 * i2c md 50 210 10 display 16 bytes starting at 0x210
60 * On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd>
61 * This is awfully ugly. It would be nice if someone would think up
62 * a better way of handling this.
64 * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
68 #include <bootretry.h>
78 #include <asm/byteorder.h>
79 #include <linux/compiler.h>
80 #include <linux/delay.h>
81 #include <u-boot/crc.h>
83 /* Display values from last command.
84 * Memory modify remembered values are different from display memory.
86 static uint i2c_dp_last_chip;
87 static uint i2c_dp_last_addr;
88 static uint i2c_dp_last_alen;
89 static uint i2c_dp_last_length = 0x10;
91 static uint i2c_mm_last_chip;
92 static uint i2c_mm_last_addr;
93 static uint i2c_mm_last_alen;
95 /* If only one I2C bus is present, the list of devices to ignore when
96 * the probe command is issued is represented by a 1D array of addresses.
97 * When multiple buses are present, the list is an array of bus-address
98 * pairs. The following macros take care of this */
100 #if defined(CONFIG_SYS_I2C_NOPROBES)
101 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
106 } i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
107 #define GET_BUS_NUM i2c_get_bus_num()
108 #define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b))
109 #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a))
110 #define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr
111 #else /* single bus */
112 static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
113 #define GET_BUS_NUM 0
114 #define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */
115 #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a))
116 #define NO_PROBE_ADDR(i) i2c_no_probes[(i)]
117 #endif /* defined(CONFIG_SYS_I2C) */
120 #define DISP_LINE_LEN 16
123 * Default for driver model is to use the chip's existing address length.
124 * For legacy code, this is not stored, so we need to use a suitable
128 #define DEFAULT_ADDR_LEN (-1)
130 #define DEFAULT_ADDR_LEN 1
134 static struct udevice *i2c_cur_bus;
136 static int cmd_i2c_set_bus_num(unsigned int busnum)
141 ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus);
143 debug("%s: No bus %d\n", __func__, busnum);
151 static int i2c_get_cur_bus(struct udevice **busp)
153 #ifdef CONFIG_I2C_SET_DEFAULT_BUS_NUM
155 if (cmd_i2c_set_bus_num(CONFIG_I2C_DEFAULT_BUS_NUMBER)) {
156 printf("Default I2C bus %d not found\n",
157 CONFIG_I2C_DEFAULT_BUS_NUMBER);
164 puts("No I2C bus selected\n");
172 static int i2c_get_cur_bus_chip(uint chip_addr, struct udevice **devp)
177 ret = i2c_get_cur_bus(&bus);
181 return i2c_get_chip(bus, chip_addr, 1, devp);
187 * i2c_init_board() - Board-specific I2C bus init
189 * This function is the default no-op implementation of I2C bus
190 * initialization. This function can be overridden by board-specific
191 * implementation if needed.
194 void i2c_init_board(void)
198 /* TODO: Implement architecture-specific get/set functions */
201 * i2c_get_bus_speed() - Return I2C bus speed
203 * This function is the default implementation of function for retrieveing
204 * the current I2C bus speed in Hz.
206 * A driver implementing runtime switching of I2C bus speed must override
207 * this function to report the speed correctly. Simple or legacy drivers
208 * can use this fallback.
210 * Returns I2C bus speed in Hz.
212 #if !defined(CONFIG_SYS_I2C) && !defined(CONFIG_DM_I2C)
214 * TODO: Implement architecture-specific get/set functions
215 * Should go away, if we switched completely to new multibus support
218 unsigned int i2c_get_bus_speed(void)
220 return CONFIG_SYS_I2C_SPEED;
224 * i2c_set_bus_speed() - Configure I2C bus speed
225 * @speed: Newly set speed of the I2C bus in Hz
227 * This function is the default implementation of function for setting
228 * the I2C bus speed in Hz.
230 * A driver implementing runtime switching of I2C bus speed must override
231 * this function to report the speed correctly. Simple or legacy drivers
232 * can use this fallback.
234 * Returns zero on success, negative value on error.
237 int i2c_set_bus_speed(unsigned int speed)
239 if (speed != CONFIG_SYS_I2C_SPEED)
247 * get_alen() - Small parser helper function to get address length
249 * Returns the address length.
251 static uint get_alen(char *arg, int default_len)
257 for (j = 0; j < 8; j++) {
259 alen = arg[j+1] - '0';
261 } else if (arg[j] == '\0')
272 static int i2c_report_err(int ret, enum i2c_err_op op)
274 printf("Error %s the chip: %d\n",
275 op == I2C_ERR_READ ? "reading" : "writing", ret);
277 return CMD_RET_FAILURE;
281 * do_i2c_read() - Handle the "i2c read" command-line command
282 * @cmdtp: Command data struct pointer
283 * @flag: Command flag
284 * @argc: Command-line argument count
285 * @argv: Array of command-line arguments
287 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
291 * i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr}
293 static int do_i2c_read(struct cmd_tbl *cmdtp, int flag, int argc,
297 uint devaddr, length;
306 return CMD_RET_USAGE;
311 chip = simple_strtoul(argv[1], NULL, 16);
314 * I2C data address within the chip. This can be 1 or
315 * 2 bytes long. Some day it might be 3 bytes long :-).
317 devaddr = simple_strtoul(argv[2], NULL, 16);
318 alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
320 return CMD_RET_USAGE;
323 * Length is the number of objects, not number of bytes.
325 length = simple_strtoul(argv[3], NULL, 16);
328 * memaddr is the address where to store things in memory
330 memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16);
333 ret = i2c_get_cur_bus_chip(chip, &dev);
334 if (!ret && alen != -1)
335 ret = i2c_set_chip_offset_len(dev, alen);
337 ret = dm_i2c_read(dev, devaddr, memaddr, length);
339 ret = i2c_read(chip, devaddr, alen, memaddr, length);
342 return i2c_report_err(ret, I2C_ERR_READ);
347 static int do_i2c_write(struct cmd_tbl *cmdtp, int flag, int argc,
351 uint devaddr, length;
357 struct dm_i2c_chip *i2c_chip;
360 if ((argc < 5) || (argc > 6))
361 return cmd_usage(cmdtp);
364 * memaddr is the address where to store things in memory
366 memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
371 chip = simple_strtoul(argv[2], NULL, 16);
374 * I2C data address within the chip. This can be 1 or
375 * 2 bytes long. Some day it might be 3 bytes long :-).
377 devaddr = simple_strtoul(argv[3], NULL, 16);
378 alen = get_alen(argv[3], DEFAULT_ADDR_LEN);
380 return cmd_usage(cmdtp);
383 * Length is the number of bytes.
385 length = simple_strtoul(argv[4], NULL, 16);
388 ret = i2c_get_cur_bus_chip(chip, &dev);
389 if (!ret && alen != -1)
390 ret = i2c_set_chip_offset_len(dev, alen);
392 return i2c_report_err(ret, I2C_ERR_WRITE);
393 i2c_chip = dev_get_parent_platdata(dev);
395 return i2c_report_err(ret, I2C_ERR_WRITE);
398 if (argc == 6 && !strcmp(argv[5], "-s")) {
400 * Write all bytes in a single I2C transaction. If the target
401 * device is an EEPROM, it is your responsibility to not cross
402 * a page boundary. No write delay upon completion, take this
403 * into account if linking commands.
406 i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS;
407 ret = dm_i2c_write(dev, devaddr, memaddr, length);
409 ret = i2c_write(chip, devaddr, alen, memaddr, length);
412 return i2c_report_err(ret, I2C_ERR_WRITE);
415 * Repeated addressing - perform <length> separate
416 * write transactions of one byte each
418 while (length-- > 0) {
420 i2c_chip->flags |= DM_I2C_CHIP_WR_ADDRESS;
421 ret = dm_i2c_write(dev, devaddr++, memaddr++, 1);
423 ret = i2c_write(chip, devaddr++, alen, memaddr++, 1);
426 return i2c_report_err(ret, I2C_ERR_WRITE);
428 * No write delay with FRAM devices.
430 #if !defined(CONFIG_SYS_I2C_FRAM)
439 static int do_i2c_flags(struct cmd_tbl *cmdtp, int flag, int argc,
448 return CMD_RET_USAGE;
450 chip = simple_strtoul(argv[1], NULL, 16);
451 ret = i2c_get_cur_bus_chip(chip, &dev);
453 return i2c_report_err(ret, I2C_ERR_READ);
456 flags = simple_strtoul(argv[2], NULL, 16);
457 ret = i2c_set_chip_flags(dev, flags);
459 ret = i2c_get_chip_flags(dev, &flags);
461 printf("%x\n", flags);
464 return i2c_report_err(ret, I2C_ERR_READ);
469 static int do_i2c_olen(struct cmd_tbl *cmdtp, int flag, int argc,
478 return CMD_RET_USAGE;
480 chip = simple_strtoul(argv[1], NULL, 16);
481 ret = i2c_get_cur_bus_chip(chip, &dev);
483 return i2c_report_err(ret, I2C_ERR_READ);
486 olen = simple_strtoul(argv[2], NULL, 16);
487 ret = i2c_set_chip_offset_len(dev, olen);
489 ret = i2c_get_chip_offset_len(dev);
496 return i2c_report_err(ret, I2C_ERR_READ);
503 * do_i2c_md() - Handle the "i2c md" command-line command
504 * @cmdtp: Command data struct pointer
505 * @flag: Command flag
506 * @argc: Command-line argument count
507 * @argv: Array of command-line arguments
509 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
513 * i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
515 static int do_i2c_md(struct cmd_tbl *cmdtp, int flag, int argc,
521 int j, nbytes, linebytes;
527 /* We use the last specified parameters, unless new ones are
530 chip = i2c_dp_last_chip;
531 addr = i2c_dp_last_addr;
532 alen = i2c_dp_last_alen;
533 length = i2c_dp_last_length;
536 return CMD_RET_USAGE;
538 if ((flag & CMD_FLAG_REPEAT) == 0) {
540 * New command specified.
546 chip = simple_strtoul(argv[1], NULL, 16);
549 * I2C data address within the chip. This can be 1 or
550 * 2 bytes long. Some day it might be 3 bytes long :-).
552 addr = simple_strtoul(argv[2], NULL, 16);
553 alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
555 return CMD_RET_USAGE;
558 * If another parameter, it is the length to display.
559 * Length is the number of objects, not number of bytes.
562 length = simple_strtoul(argv[3], NULL, 16);
566 ret = i2c_get_cur_bus_chip(chip, &dev);
567 if (!ret && alen != -1)
568 ret = i2c_set_chip_offset_len(dev, alen);
570 return i2c_report_err(ret, I2C_ERR_READ);
576 * We buffer all read data, so we can make sure data is read only
581 unsigned char linebuf[DISP_LINE_LEN];
584 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
587 ret = dm_i2c_read(dev, addr, linebuf, linebytes);
589 ret = i2c_read(chip, addr, alen, linebuf, linebytes);
592 return i2c_report_err(ret, I2C_ERR_READ);
594 printf("%04x:", addr);
596 for (j=0; j<linebytes; j++) {
597 printf(" %02x", *cp++);
602 for (j=0; j<linebytes; j++) {
603 if ((*cp < 0x20) || (*cp > 0x7e))
612 } while (nbytes > 0);
614 i2c_dp_last_chip = chip;
615 i2c_dp_last_addr = addr;
616 i2c_dp_last_alen = alen;
617 i2c_dp_last_length = length;
623 * do_i2c_mw() - Handle the "i2c mw" command-line command
624 * @cmdtp: Command data struct pointer
625 * @flag: Command flag
626 * @argc: Command-line argument count
627 * @argv: Array of command-line arguments
629 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
633 * i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
635 static int do_i2c_mw(struct cmd_tbl *cmdtp, int flag, int argc,
648 if ((argc < 4) || (argc > 5))
649 return CMD_RET_USAGE;
652 * Chip is always specified.
654 chip = simple_strtoul(argv[1], NULL, 16);
657 * Address is always specified.
659 addr = simple_strtoul(argv[2], NULL, 16);
660 alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
662 return CMD_RET_USAGE;
665 ret = i2c_get_cur_bus_chip(chip, &dev);
666 if (!ret && alen != -1)
667 ret = i2c_set_chip_offset_len(dev, alen);
669 return i2c_report_err(ret, I2C_ERR_WRITE);
672 * Value to write is always specified.
674 byte = simple_strtoul(argv[3], NULL, 16);
680 count = simple_strtoul(argv[4], NULL, 16);
684 while (count-- > 0) {
686 ret = dm_i2c_write(dev, addr++, &byte, 1);
688 ret = i2c_write(chip, addr++, alen, &byte, 1);
691 return i2c_report_err(ret, I2C_ERR_WRITE);
693 * Wait for the write to complete. The write can take
694 * up to 10mSec (we allow a little more time).
697 * No write delay with FRAM devices.
699 #if !defined(CONFIG_SYS_I2C_FRAM)
708 * do_i2c_crc() - Handle the "i2c crc32" command-line command
709 * @cmdtp: Command data struct pointer
710 * @flag: Command flag
711 * @argc: Command-line argument count
712 * @argv: Array of command-line arguments
714 * Calculate a CRC on memory
716 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
720 * i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
722 static int do_i2c_crc(struct cmd_tbl *cmdtp, int flag, int argc,
738 return CMD_RET_USAGE;
741 * Chip is always specified.
743 chip = simple_strtoul(argv[1], NULL, 16);
746 * Address is always specified.
748 addr = simple_strtoul(argv[2], NULL, 16);
749 alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
751 return CMD_RET_USAGE;
754 ret = i2c_get_cur_bus_chip(chip, &dev);
755 if (!ret && alen != -1)
756 ret = i2c_set_chip_offset_len(dev, alen);
758 return i2c_report_err(ret, I2C_ERR_READ);
761 * Count is always specified
763 count = simple_strtoul(argv[3], NULL, 16);
765 printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
767 * CRC a byte at a time. This is going to be slooow, but hey, the
768 * memories are small and slow too so hopefully nobody notices.
772 while (count-- > 0) {
774 ret = dm_i2c_read(dev, addr, &byte, 1);
776 ret = i2c_read(chip, addr, alen, &byte, 1);
780 crc = crc32(crc, &byte, 1);
784 i2c_report_err(ret, I2C_ERR_READ);
786 printf ("%08lx\n", crc);
792 * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
793 * @cmdtp: Command data struct pointer
794 * @flag: Command flag
795 * @argc: Command-line argument count
796 * @argv: Array of command-line arguments
800 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
804 * i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
805 * i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
807 static int mod_i2c_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
822 return CMD_RET_USAGE;
824 bootretry_reset_cmd_timeout(); /* got a good command to get here */
826 * We use the last specified parameters, unless new ones are
829 chip = i2c_mm_last_chip;
830 addr = i2c_mm_last_addr;
831 alen = i2c_mm_last_alen;
833 if ((flag & CMD_FLAG_REPEAT) == 0) {
835 * New command specified. Check for a size specification.
836 * Defaults to byte if no or incorrect specification.
838 size = cmd_get_data_size(argv[0], 1);
841 * Chip is always specified.
843 chip = simple_strtoul(argv[1], NULL, 16);
846 * Address is always specified.
848 addr = simple_strtoul(argv[2], NULL, 16);
849 alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
851 return CMD_RET_USAGE;
855 ret = i2c_get_cur_bus_chip(chip, &dev);
856 if (!ret && alen != -1)
857 ret = i2c_set_chip_offset_len(dev, alen);
859 return i2c_report_err(ret, I2C_ERR_WRITE);
863 * Print the address, followed by value. Then accept input for
864 * the next value. A non-converted value exits.
867 printf("%08lx:", addr);
869 ret = dm_i2c_read(dev, addr, (uchar *)&data, size);
871 ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
874 return i2c_report_err(ret, I2C_ERR_READ);
876 data = cpu_to_be32(data);
878 printf(" %02lx", (data >> 24) & 0x000000FF);
880 printf(" %04lx", (data >> 16) & 0x0000FFFF);
882 printf(" %08lx", data);
884 nbytes = cli_readline(" ? ");
887 * <CR> pressed as only input, don't modify current
888 * location and move to next.
893 /* good enough to not time out */
894 bootretry_reset_cmd_timeout();
896 #ifdef CONFIG_BOOT_RETRY_TIME
897 else if (nbytes == -2)
898 break; /* timed out, exit the command */
903 data = simple_strtoul(console_buffer, &endp, 16);
908 data = be32_to_cpu(data);
909 nbytes = endp - console_buffer;
912 * good enough to not time out
914 bootretry_reset_cmd_timeout();
916 ret = dm_i2c_write(dev, addr, (uchar *)&data,
919 ret = i2c_write(chip, addr, alen,
920 (uchar *)&data, size);
923 return i2c_report_err(ret,
925 #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
926 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
934 i2c_mm_last_chip = chip;
935 i2c_mm_last_addr = addr;
936 i2c_mm_last_alen = alen;
942 * do_i2c_probe() - Handle the "i2c probe" command-line command
943 * @cmdtp: Command data struct pointer
944 * @flag: Command flag
945 * @argc: Command-line argument count
946 * @argv: Array of command-line arguments
948 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
954 * Returns zero (success) if one or more I2C devices was found
956 static int do_i2c_probe(struct cmd_tbl *cmdtp, int flag, int argc,
962 #if defined(CONFIG_SYS_I2C_NOPROBES)
964 unsigned int bus = GET_BUS_NUM;
965 #endif /* NOPROBES */
968 struct udevice *bus, *dev;
970 if (i2c_get_cur_bus(&bus))
971 return CMD_RET_FAILURE;
975 addr = simple_strtol(argv[1], 0, 16);
977 puts ("Valid chip addresses:");
978 for (j = 0; j < 128; j++) {
979 if ((0 <= addr) && (j != addr))
982 #if defined(CONFIG_SYS_I2C_NOPROBES)
984 for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
985 if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
994 ret = dm_i2c_probe(bus, j, 0, &dev);
1005 #if defined(CONFIG_SYS_I2C_NOPROBES)
1006 puts ("Excluded chip addresses:");
1007 for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) {
1008 if (COMPARE_BUS(bus,k))
1009 printf(" %02X", NO_PROBE_ADDR(k));
1014 return (0 == found);
1018 * do_i2c_loop() - Handle the "i2c loop" command-line command
1019 * @cmdtp: Command data struct pointer
1020 * @flag: Command flag
1021 * @argc: Command-line argument count
1022 * @argv: Array of command-line arguments
1024 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1028 * i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
1029 * {length} - Number of bytes to read
1030 * {delay} - A DECIMAL number and defaults to 1000 uSec
1032 static int do_i2c_loop(struct cmd_tbl *cmdtp, int flag, int argc,
1042 #ifdef CONFIG_DM_I2C
1043 struct udevice *dev;
1047 return CMD_RET_USAGE;
1050 * Chip is always specified.
1052 chip = simple_strtoul(argv[1], NULL, 16);
1055 * Address is always specified.
1057 addr = simple_strtoul(argv[2], NULL, 16);
1058 alen = get_alen(argv[2], DEFAULT_ADDR_LEN);
1060 return CMD_RET_USAGE;
1061 #ifdef CONFIG_DM_I2C
1062 ret = i2c_get_cur_bus_chip(chip, &dev);
1063 if (!ret && alen != -1)
1064 ret = i2c_set_chip_offset_len(dev, alen);
1066 return i2c_report_err(ret, I2C_ERR_WRITE);
1070 * Length is the number of objects, not number of bytes.
1073 length = simple_strtoul(argv[3], NULL, 16);
1074 if (length > sizeof(bytes))
1075 length = sizeof(bytes);
1078 * The delay time (uSec) is optional.
1082 delay = simple_strtoul(argv[4], NULL, 10);
1087 #ifdef CONFIG_DM_I2C
1088 ret = dm_i2c_read(dev, addr, bytes, length);
1090 ret = i2c_read(chip, addr, alen, bytes, length);
1093 i2c_report_err(ret, I2C_ERR_READ);
1102 * The SDRAM command is separately configured because many
1103 * (most?) embedded boards don't use SDRAM DIMMs.
1105 * FIXME: Document and probably move elsewhere!
1107 #if defined(CONFIG_CMD_SDRAM)
1108 static void print_ddr2_tcyc (u_char const b)
1110 printf ("%d.", (b >> 4) & 0x0F);
1122 printf ("%d ns\n", b & 0x0F);
1142 static void decode_bits (u_char const b, char const *str[], int const do_once)
1146 for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) {
1157 * i2c sdram {i2c_chip}
1159 static int do_sdram(struct cmd_tbl *cmdtp, int flag, int argc,
1162 enum { unknown, EDO, SDRAM, DDR, DDR2, DDR3, DDR4 } type;
1168 #ifdef CONFIG_DM_I2C
1169 struct udevice *dev;
1172 static const char *decode_CAS_DDR2[] = {
1173 " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
1176 static const char *decode_CAS_default[] = {
1177 " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
1180 static const char *decode_CS_WE_default[] = {
1181 " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
1184 static const char *decode_byte21_default[] = {
1186 " Redundant row address\n",
1187 " Differential clock input\n",
1188 " Registerd DQMB inputs\n",
1189 " Buffered DQMB inputs\n",
1191 " Registered address/control lines\n",
1192 " Buffered address/control lines\n"
1195 static const char *decode_byte22_DDR2[] = {
1201 " Supports partial array self refresh\n",
1202 " Supports 50 ohm ODT\n",
1203 " Supports weak driver\n"
1206 static const char *decode_row_density_DDR2[] = {
1207 "512 MiB", "256 MiB", "128 MiB", "16 GiB",
1208 "8 GiB", "4 GiB", "2 GiB", "1 GiB"
1211 static const char *decode_row_density_default[] = {
1212 "512 MiB", "256 MiB", "128 MiB", "64 MiB",
1213 "32 MiB", "16 MiB", "8 MiB", "4 MiB"
1217 return CMD_RET_USAGE;
1220 * Chip is always specified.
1222 chip = simple_strtoul (argv[1], NULL, 16);
1224 #ifdef CONFIG_DM_I2C
1225 ret = i2c_get_cur_bus_chip(chip, &dev);
1227 ret = dm_i2c_read(dev, 0, data, sizeof(data));
1229 ret = i2c_read(chip, 0, 1, data, sizeof(data));
1232 puts ("No SDRAM Serial Presence Detect found.\n");
1237 for (j = 0; j < 63; j++) {
1240 if (cksum != data[63]) {
1241 printf ("WARNING: Configuration data checksum failure:\n"
1242 " is 0x%02x, calculated 0x%02x\n", data[63], cksum);
1244 printf ("SPD data revision %d.%d\n",
1245 (data[62] >> 4) & 0x0F, data[62] & 0x0F);
1246 printf ("Bytes used 0x%02X\n", data[0]);
1247 printf ("Serial memory size 0x%02X\n", 1 << data[1]);
1249 puts ("Memory type ");
1281 puts ("Row address bits ");
1282 if ((data[3] & 0x00F0) == 0)
1283 printf ("%d\n", data[3] & 0x0F);
1285 printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
1287 puts ("Column address bits ");
1288 if ((data[4] & 0x00F0) == 0)
1289 printf ("%d\n", data[4] & 0x0F);
1291 printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
1295 printf ("Number of ranks %d\n",
1296 (data[5] & 0x07) + 1);
1299 printf ("Module rows %d\n", data[5]);
1305 printf ("Module data width %d bits\n", data[6]);
1308 printf ("Module data width %d bits\n",
1309 (data[7] << 8) | data[6]);
1313 puts ("Interface signal levels ");
1315 case 0: puts ("TTL 5.0 V\n"); break;
1316 case 1: puts ("LVTTL\n"); break;
1317 case 2: puts ("HSTL 1.5 V\n"); break;
1318 case 3: puts ("SSTL 3.3 V\n"); break;
1319 case 4: puts ("SSTL 2.5 V\n"); break;
1320 case 5: puts ("SSTL 1.8 V\n"); break;
1321 default: puts ("unknown\n"); break;
1326 printf ("SDRAM cycle time ");
1327 print_ddr2_tcyc (data[9]);
1330 printf ("SDRAM cycle time %d.%d ns\n",
1331 (data[9] >> 4) & 0x0F, data[9] & 0x0F);
1337 printf ("SDRAM access time 0.%d%d ns\n",
1338 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
1341 printf ("SDRAM access time %d.%d ns\n",
1342 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
1346 puts ("EDC configuration ");
1348 case 0: puts ("None\n"); break;
1349 case 1: puts ("Parity\n"); break;
1350 case 2: puts ("ECC\n"); break;
1351 default: puts ("unknown\n"); break;
1354 if ((data[12] & 0x80) == 0)
1355 puts ("No self refresh, rate ");
1357 puts ("Self refresh, rate ");
1359 switch(data[12] & 0x7F) {
1360 case 0: puts ("15.625 us\n"); break;
1361 case 1: puts ("3.9 us\n"); break;
1362 case 2: puts ("7.8 us\n"); break;
1363 case 3: puts ("31.3 us\n"); break;
1364 case 4: puts ("62.5 us\n"); break;
1365 case 5: puts ("125 us\n"); break;
1366 default: puts ("unknown\n"); break;
1371 printf ("SDRAM width (primary) %d\n", data[13]);
1374 printf ("SDRAM width (primary) %d\n", data[13] & 0x7F);
1375 if ((data[13] & 0x80) != 0) {
1376 printf (" (second bank) %d\n",
1377 2 * (data[13] & 0x7F));
1385 printf ("EDC width %d\n", data[14]);
1388 if (data[14] != 0) {
1389 printf ("EDC width %d\n",
1392 if ((data[14] & 0x80) != 0) {
1393 printf (" (second bank) %d\n",
1394 2 * (data[14] & 0x7F));
1401 printf ("Min clock delay, back-to-back random column addresses "
1405 puts ("Burst length(s) ");
1406 if (data[16] & 0x80) puts (" Page");
1407 if (data[16] & 0x08) puts (" 8");
1408 if (data[16] & 0x04) puts (" 4");
1409 if (data[16] & 0x02) puts (" 2");
1410 if (data[16] & 0x01) puts (" 1");
1412 printf ("Number of banks %d\n", data[17]);
1416 puts ("CAS latency(s) ");
1417 decode_bits (data[18], decode_CAS_DDR2, 0);
1421 puts ("CAS latency(s) ");
1422 decode_bits (data[18], decode_CAS_default, 0);
1428 puts ("CS latency(s) ");
1429 decode_bits (data[19], decode_CS_WE_default, 0);
1434 puts ("WE latency(s) ");
1435 decode_bits (data[20], decode_CS_WE_default, 0);
1441 puts ("Module attributes:\n");
1442 if (data[21] & 0x80)
1443 puts (" TBD (bit 7)\n");
1444 if (data[21] & 0x40)
1445 puts (" Analysis probe installed\n");
1446 if (data[21] & 0x20)
1447 puts (" TBD (bit 5)\n");
1448 if (data[21] & 0x10)
1449 puts (" FET switch external enable\n");
1450 printf (" %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
1451 if (data[20] & 0x11) {
1452 printf (" %d active registers on DIMM\n",
1453 (data[21] & 0x03) + 1);
1457 puts ("Module attributes:\n");
1461 decode_bits (data[21], decode_byte21_default, 0);
1467 decode_bits (data[22], decode_byte22_DDR2, 0);
1470 puts ("Device attributes:\n");
1471 if (data[22] & 0x80) puts (" TBD (bit 7)\n");
1472 if (data[22] & 0x40) puts (" TBD (bit 6)\n");
1473 if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
1474 else puts (" Upper Vcc tolerance 10%\n");
1475 if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
1476 else puts (" Lower Vcc tolerance 10%\n");
1477 if (data[22] & 0x08) puts (" Supports write1/read burst\n");
1478 if (data[22] & 0x04) puts (" Supports precharge all\n");
1479 if (data[22] & 0x02) puts (" Supports auto precharge\n");
1480 if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
1486 printf ("SDRAM cycle time (2nd highest CAS latency) ");
1487 print_ddr2_tcyc (data[23]);
1490 printf ("SDRAM cycle time (2nd highest CAS latency) %d."
1491 "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
1497 printf ("SDRAM access from clock (2nd highest CAS latency) 0."
1498 "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
1501 printf ("SDRAM access from clock (2nd highest CAS latency) %d."
1502 "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
1508 printf ("SDRAM cycle time (3rd highest CAS latency) ");
1509 print_ddr2_tcyc (data[25]);
1512 printf ("SDRAM cycle time (3rd highest CAS latency) %d."
1513 "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
1519 printf ("SDRAM access from clock (3rd highest CAS latency) 0."
1520 "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
1523 printf ("SDRAM access from clock (3rd highest CAS latency) %d."
1524 "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
1530 printf ("Minimum row precharge %d.%02d ns\n",
1531 (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03));
1534 printf ("Minimum row precharge %d ns\n", data[27]);
1540 printf ("Row active to row active min %d.%02d ns\n",
1541 (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03));
1544 printf ("Row active to row active min %d ns\n", data[28]);
1550 printf ("RAS to CAS delay min %d.%02d ns\n",
1551 (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03));
1554 printf ("RAS to CAS delay min %d ns\n", data[29]);
1558 printf ("Minimum RAS pulse width %d ns\n", data[30]);
1562 puts ("Density of each row ");
1563 decode_bits (data[31], decode_row_density_DDR2, 1);
1567 puts ("Density of each row ");
1568 decode_bits (data[31], decode_row_density_default, 1);
1575 puts ("Command and Address setup ");
1576 if (data[32] >= 0xA0) {
1577 printf ("1.%d%d ns\n",
1578 ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
1580 printf ("0.%d%d ns\n",
1581 ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
1585 printf ("Command and Address setup %c%d.%d ns\n",
1586 (data[32] & 0x80) ? '-' : '+',
1587 (data[32] >> 4) & 0x07, data[32] & 0x0F);
1593 puts ("Command and Address hold ");
1594 if (data[33] >= 0xA0) {
1595 printf ("1.%d%d ns\n",
1596 ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
1598 printf ("0.%d%d ns\n",
1599 ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
1603 printf ("Command and Address hold %c%d.%d ns\n",
1604 (data[33] & 0x80) ? '-' : '+',
1605 (data[33] >> 4) & 0x07, data[33] & 0x0F);
1611 printf ("Data signal input setup 0.%d%d ns\n",
1612 (data[34] >> 4) & 0x0F, data[34] & 0x0F);
1615 printf ("Data signal input setup %c%d.%d ns\n",
1616 (data[34] & 0x80) ? '-' : '+',
1617 (data[34] >> 4) & 0x07, data[34] & 0x0F);
1623 printf ("Data signal input hold 0.%d%d ns\n",
1624 (data[35] >> 4) & 0x0F, data[35] & 0x0F);
1627 printf ("Data signal input hold %c%d.%d ns\n",
1628 (data[35] & 0x80) ? '-' : '+',
1629 (data[35] >> 4) & 0x07, data[35] & 0x0F);
1633 puts ("Manufacturer's JEDEC ID ");
1634 for (j = 64; j <= 71; j++)
1635 printf ("%02X ", data[j]);
1637 printf ("Manufacturing Location %02X\n", data[72]);
1638 puts ("Manufacturer's Part Number ");
1639 for (j = 73; j <= 90; j++)
1640 printf ("%02X ", data[j]);
1642 printf ("Revision Code %02X %02X\n", data[91], data[92]);
1643 printf ("Manufacturing Date %02X %02X\n", data[93], data[94]);
1644 puts ("Assembly Serial Number ");
1645 for (j = 95; j <= 98; j++)
1646 printf ("%02X ", data[j]);
1650 printf ("Speed rating PC%d\n",
1651 data[126] == 0x66 ? 66 : data[126]);
1659 * i2c edid {i2c_chip}
1661 #if defined(CONFIG_I2C_EDID)
1662 int do_edid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
1665 struct edid1_info edid;
1667 #ifdef CONFIG_DM_I2C
1668 struct udevice *dev;
1676 chip = simple_strtoul(argv[1], NULL, 16);
1677 #ifdef CONFIG_DM_I2C
1678 ret = i2c_get_cur_bus_chip(chip, &dev);
1680 ret = dm_i2c_read(dev, 0, (uchar *)&edid, sizeof(edid));
1682 ret = i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid));
1685 return i2c_report_err(ret, I2C_ERR_READ);
1687 if (edid_check_info(&edid)) {
1688 puts("Content isn't valid EDID.\n");
1692 edid_print_info(&edid);
1696 #endif /* CONFIG_I2C_EDID */
1698 #ifdef CONFIG_DM_I2C
1699 static void show_bus(struct udevice *bus)
1701 struct udevice *dev;
1703 printf("Bus %d:\t%s", bus->req_seq, bus->name);
1704 if (device_active(bus))
1705 printf(" (active %d)", bus->seq);
1707 for (device_find_first_child(bus, &dev);
1709 device_find_next_child(&dev)) {
1710 struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
1712 printf(" %02x: %s, offset len %x, flags %x\n",
1713 chip->chip_addr, dev->name, chip->offset_len,
1720 * do_i2c_show_bus() - Handle the "i2c bus" command-line command
1721 * @cmdtp: Command data struct pointer
1722 * @flag: Command flag
1723 * @argc: Command-line argument count
1724 * @argv: Array of command-line arguments
1726 * Returns zero always.
1728 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
1729 static int do_i2c_show_bus(struct cmd_tbl *cmdtp, int flag, int argc,
1733 /* show all busses */
1734 #ifdef CONFIG_DM_I2C
1735 struct udevice *bus;
1739 ret = uclass_get(UCLASS_I2C, &uc);
1741 return CMD_RET_FAILURE;
1742 uclass_foreach_dev(bus, uc)
1747 for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
1748 printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
1749 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
1752 for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
1753 if (i2c_bus[i].next_hop[j].chip == 0)
1755 printf("->%s@0x%2x:%d",
1756 i2c_bus[i].next_hop[j].mux.name,
1757 i2c_bus[i].next_hop[j].chip,
1758 i2c_bus[i].next_hop[j].channel);
1767 /* show specific bus */
1768 i = simple_strtoul(argv[1], NULL, 10);
1769 #ifdef CONFIG_DM_I2C
1770 struct udevice *bus;
1773 ret = uclass_get_device_by_seq(UCLASS_I2C, i, &bus);
1775 printf("Invalid bus %d: err=%d\n", i, ret);
1776 return CMD_RET_FAILURE;
1780 if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
1781 printf("Invalid bus %d\n", i);
1784 printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
1785 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
1787 for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
1788 if (i2c_bus[i].next_hop[j].chip == 0)
1790 printf("->%s@0x%2x:%d",
1791 i2c_bus[i].next_hop[j].mux.name,
1792 i2c_bus[i].next_hop[j].chip,
1793 i2c_bus[i].next_hop[j].channel);
1805 * do_i2c_bus_num() - Handle the "i2c dev" command-line command
1806 * @cmdtp: Command data struct pointer
1807 * @flag: Command flag
1808 * @argc: Command-line argument count
1809 * @argv: Array of command-line arguments
1811 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1814 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) || \
1815 defined(CONFIG_DM_I2C)
1816 static int do_i2c_bus_num(struct cmd_tbl *cmdtp, int flag, int argc,
1823 /* querying current setting */
1824 #ifdef CONFIG_DM_I2C
1825 struct udevice *bus;
1827 if (!i2c_get_cur_bus(&bus))
1832 bus_no = i2c_get_bus_num();
1834 printf("Current bus is %d\n", bus_no);
1836 bus_no = simple_strtoul(argv[1], NULL, 10);
1837 #if defined(CONFIG_SYS_I2C)
1838 if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
1839 printf("Invalid bus %d\n", bus_no);
1843 printf("Setting bus to %d\n", bus_no);
1844 #ifdef CONFIG_DM_I2C
1845 ret = cmd_i2c_set_bus_num(bus_no);
1847 ret = i2c_set_bus_num(bus_no);
1850 printf("Failure changing bus number (%d)\n", ret);
1853 return ret ? CMD_RET_FAILURE : 0;
1855 #endif /* defined(CONFIG_SYS_I2C) */
1858 * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
1859 * @cmdtp: Command data struct pointer
1860 * @flag: Command flag
1861 * @argc: Command-line argument count
1862 * @argv: Array of command-line arguments
1864 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1867 static int do_i2c_bus_speed(struct cmd_tbl *cmdtp, int flag, int argc,
1872 #ifdef CONFIG_DM_I2C
1873 struct udevice *bus;
1875 if (i2c_get_cur_bus(&bus))
1879 #ifdef CONFIG_DM_I2C
1880 speed = dm_i2c_get_bus_speed(bus);
1882 speed = i2c_get_bus_speed();
1884 /* querying current speed */
1885 printf("Current bus speed=%d\n", speed);
1887 speed = simple_strtoul(argv[1], NULL, 10);
1888 printf("Setting bus speed to %d Hz\n", speed);
1889 #ifdef CONFIG_DM_I2C
1890 ret = dm_i2c_set_bus_speed(bus, speed);
1892 ret = i2c_set_bus_speed(speed);
1895 printf("Failure changing bus speed (%d)\n", ret);
1898 return ret ? CMD_RET_FAILURE : 0;
1902 * do_i2c_mm() - Handle the "i2c mm" command-line command
1903 * @cmdtp: Command data struct pointer
1904 * @flag: Command flag
1905 * @argc: Command-line argument count
1906 * @argv: Array of command-line arguments
1908 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1911 static int do_i2c_mm(struct cmd_tbl *cmdtp, int flag, int argc,
1914 return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
1918 * do_i2c_nm() - Handle the "i2c nm" command-line command
1919 * @cmdtp: Command data struct pointer
1920 * @flag: Command flag
1921 * @argc: Command-line argument count
1922 * @argv: Array of command-line arguments
1924 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1927 static int do_i2c_nm(struct cmd_tbl *cmdtp, int flag, int argc,
1930 return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
1934 * do_i2c_reset() - Handle the "i2c reset" command-line command
1935 * @cmdtp: Command data struct pointer
1936 * @flag: Command flag
1937 * @argc: Command-line argument count
1938 * @argv: Array of command-line arguments
1940 * Returns zero always.
1942 static int do_i2c_reset(struct cmd_tbl *cmdtp, int flag, int argc,
1945 #if defined(CONFIG_DM_I2C)
1946 struct udevice *bus;
1948 if (i2c_get_cur_bus(&bus))
1949 return CMD_RET_FAILURE;
1950 if (i2c_deblock(bus)) {
1951 printf("Error: Not supported by the driver\n");
1952 return CMD_RET_FAILURE;
1954 #elif defined(CONFIG_SYS_I2C)
1955 i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
1957 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
1962 static struct cmd_tbl cmd_i2c_sub[] = {
1963 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
1964 U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
1966 U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
1967 #if defined(CONFIG_SYS_I2C) || \
1968 defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
1969 U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
1970 #endif /* CONFIG_I2C_MULTI_BUS */
1971 #if defined(CONFIG_I2C_EDID)
1972 U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
1973 #endif /* CONFIG_I2C_EDID */
1974 U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
1975 U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
1976 U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
1977 U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
1978 U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
1979 U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
1980 U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
1981 U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
1982 #ifdef CONFIG_DM_I2C
1983 U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
1984 U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""),
1986 U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
1987 #if defined(CONFIG_CMD_SDRAM)
1988 U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
1990 U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
1993 static __maybe_unused void i2c_reloc(void)
1995 static int relocated;
1998 fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
2004 * do_i2c() - Handle the "i2c" command-line command
2005 * @cmdtp: Command data struct pointer
2006 * @flag: Command flag
2007 * @argc: Command-line argument count
2008 * @argv: Array of command-line arguments
2010 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
2013 static int do_i2c(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
2017 #ifdef CONFIG_NEEDS_MANUAL_RELOC
2022 return CMD_RET_USAGE;
2024 /* Strip off leading 'i2c' command argument */
2028 c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub));
2031 return c->cmd(cmdtp, flag, argc, argv);
2033 return CMD_RET_USAGE;
2036 /***************************************************/
2037 #ifdef CONFIG_SYS_LONGHELP
2038 static char i2c_help_text[] =
2039 #if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
2040 "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
2041 "i2c " /* That's the prefix for the crc32 command below. */
2043 "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
2044 #if defined(CONFIG_SYS_I2C) || \
2045 defined(CONFIG_I2C_MULTI_BUS) || defined(CONFIG_DM_I2C)
2046 "i2c dev [dev] - show or set current I2C bus\n"
2047 #endif /* CONFIG_I2C_MULTI_BUS */
2048 #if defined(CONFIG_I2C_EDID)
2049 "i2c edid chip - print EDID configuration information\n"
2050 #endif /* CONFIG_I2C_EDID */
2051 "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
2052 "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
2053 "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
2054 "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
2055 "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
2056 "i2c probe [address] - test for and show device(s) on the I2C bus\n"
2057 "i2c read chip address[.0, .1, .2] length memaddress - read to memory\n"
2058 "i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory\n"
2059 " to I2C; the -s option selects bulk write in a single transaction\n"
2060 #ifdef CONFIG_DM_I2C
2061 "i2c flags chip [flags] - set or get chip flags\n"
2062 "i2c olen chip [offset_length] - set or get chip offset length\n"
2064 "i2c reset - re-init the I2C Controller\n"
2065 #if defined(CONFIG_CMD_SDRAM)
2066 "i2c sdram chip - print SDRAM configuration information\n"
2068 "i2c speed [speed] - show or set I2C bus speed";