blob: 10cab4609a5da87c2d7a1fc67db302d40f4991b9 [file] [log] [blame]
wdenk81a88242002-10-26 15:22:42 +00001/*
2 * (C) Copyright 2001
3 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * I2C Functions similar to the standard memory functions.
26 *
27 * There are several parameters in many of the commands that bear further
28 * explanations:
29 *
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.
34 *
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 :-/.
43 *
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.
50 *
51 * The default {addr} parameter is one byte (.1) which works well for
52 * memories and registers with 8 bits of address space.
53 *
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.
60 *
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).
63 *
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.
80 *
81 * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de).
82 */
83
84#include <common.h>
85#include <command.h>
wdenk81a88242002-10-26 15:22:42 +000086#include <i2c.h>
87#include <asm/byteorder.h>
88
wdenk81a88242002-10-26 15:22:42 +000089/* Display values from last command.
90 * Memory modify remembered values are different from display memory.
91 */
92static uchar i2c_dp_last_chip;
93static uint i2c_dp_last_addr;
94static uint i2c_dp_last_alen;
95static uint i2c_dp_last_length = 0x10;
96
97static uchar i2c_mm_last_chip;
98static uint i2c_mm_last_addr;
99static uint i2c_mm_last_alen;
100
Ben Warren45657152006-09-07 16:50:54 -0400101/* 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 */
105
wdenk81a88242002-10-26 15:22:42 +0000106#if defined(CFG_I2C_NOPROBES)
Ben Warren45657152006-09-07 16:50:54 -0400107#if defined(CONFIG_I2C_MULTI_BUS)
108static struct
109{
110 uchar bus;
111 uchar addr;
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 */
wdenk81a88242002-10-26 15:22:42 +0000118static uchar i2c_no_probes[] = CFG_I2C_NOPROBES;
Ben Warren45657152006-09-07 16:50:54 -0400119#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 */
124
125#define NUM_ELEMENTS_NOPROBE (sizeof(i2c_no_probes)/sizeof(i2c_no_probes[0]))
wdenk81a88242002-10-26 15:22:42 +0000126#endif
127
128static int
129mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]);
130extern int cmd_get_data_size(char* arg, int default_size);
131
132/*
133 * Syntax:
134 * imd {i2c_chip} {addr}{.0, .1, .2} {len}
135 */
136#define DISP_LINE_LEN 16
137
138int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
139{
140 u_char chip;
141 uint addr, alen, length;
142 int j, nbytes, linebytes;
143
144 /* We use the last specified parameters, unless new ones are
145 * entered.
146 */
147 chip = i2c_dp_last_chip;
148 addr = i2c_dp_last_addr;
149 alen = i2c_dp_last_alen;
150 length = i2c_dp_last_length;
151
152 if (argc < 3) {
153 printf ("Usage:\n%s\n", cmdtp->usage);
154 return 1;
155 }
156
157 if ((flag & CMD_FLAG_REPEAT) == 0) {
158 /*
159 * New command specified.
160 */
161 alen = 1;
162
163 /*
164 * I2C chip address
165 */
166 chip = simple_strtoul(argv[1], NULL, 16);
167
168 /*
169 * I2C data address within the chip. This can be 1 or
170 * 2 bytes long. Some day it might be 3 bytes long :-).
171 */
172 addr = simple_strtoul(argv[2], NULL, 16);
173 alen = 1;
Timur Tabiff0215a2006-11-28 12:09:35 -0600174 for (j = 0; j < 8; j++) {
wdenk81a88242002-10-26 15:22:42 +0000175 if (argv[2][j] == '.') {
176 alen = argv[2][j+1] - '0';
177 if (alen > 4) {
178 printf ("Usage:\n%s\n", cmdtp->usage);
179 return 1;
180 }
181 break;
Timur Tabiff0215a2006-11-28 12:09:35 -0600182 } else if (argv[2][j] == '\0')
wdenk81a88242002-10-26 15:22:42 +0000183 break;
wdenk81a88242002-10-26 15:22:42 +0000184 }
185
186 /*
187 * If another parameter, it is the length to display.
188 * Length is the number of objects, not number of bytes.
189 */
190 if (argc > 3)
191 length = simple_strtoul(argv[3], NULL, 16);
192 }
193
194 /*
195 * Print the lines.
196 *
197 * We buffer all read data, so we can make sure data is read only
198 * once.
199 */
200 nbytes = length;
201 do {
202 unsigned char linebuf[DISP_LINE_LEN];
203 unsigned char *cp;
204
205 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
206
Timur Tabiff0215a2006-11-28 12:09:35 -0600207 if (i2c_read(chip, addr, alen, linebuf, linebytes) != 0)
wdenk42c05472004-03-23 22:14:11 +0000208 puts ("Error reading the chip.\n");
Timur Tabiff0215a2006-11-28 12:09:35 -0600209 else {
wdenk81a88242002-10-26 15:22:42 +0000210 printf("%04x:", addr);
211 cp = linebuf;
212 for (j=0; j<linebytes; j++) {
213 printf(" %02x", *cp++);
214 addr++;
215 }
wdenk42c05472004-03-23 22:14:11 +0000216 puts (" ");
wdenk81a88242002-10-26 15:22:42 +0000217 cp = linebuf;
218 for (j=0; j<linebytes; j++) {
219 if ((*cp < 0x20) || (*cp > 0x7e))
wdenk42c05472004-03-23 22:14:11 +0000220 puts (".");
wdenk81a88242002-10-26 15:22:42 +0000221 else
222 printf("%c", *cp);
223 cp++;
224 }
wdenk42c05472004-03-23 22:14:11 +0000225 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000226 }
227 nbytes -= linebytes;
228 } while (nbytes > 0);
229
230 i2c_dp_last_chip = chip;
231 i2c_dp_last_addr = addr;
232 i2c_dp_last_alen = alen;
233 i2c_dp_last_length = length;
234
235 return 0;
236}
237
238int do_i2c_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
239{
240 return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
241}
242
243
244int do_i2c_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
245{
246 return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
247}
248
249/* Write (fill) memory
250 *
251 * Syntax:
252 * imw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
253 */
254int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
255{
256 uchar chip;
257 ulong addr;
258 uint alen;
259 uchar byte;
260 int count;
261 int j;
262
263 if ((argc < 4) || (argc > 5)) {
264 printf ("Usage:\n%s\n", cmdtp->usage);
265 return 1;
266 }
267
268 /*
269 * Chip is always specified.
270 */
271 chip = simple_strtoul(argv[1], NULL, 16);
272
273 /*
274 * Address is always specified.
275 */
276 addr = simple_strtoul(argv[2], NULL, 16);
277 alen = 1;
Timur Tabiff0215a2006-11-28 12:09:35 -0600278 for (j = 0; j < 8; j++) {
wdenk81a88242002-10-26 15:22:42 +0000279 if (argv[2][j] == '.') {
280 alen = argv[2][j+1] - '0';
Timur Tabiff0215a2006-11-28 12:09:35 -0600281 if (alen > 4) {
wdenk81a88242002-10-26 15:22:42 +0000282 printf ("Usage:\n%s\n", cmdtp->usage);
283 return 1;
284 }
285 break;
Timur Tabiff0215a2006-11-28 12:09:35 -0600286 } else if (argv[2][j] == '\0')
wdenk81a88242002-10-26 15:22:42 +0000287 break;
wdenk81a88242002-10-26 15:22:42 +0000288 }
289
290 /*
291 * Value to write is always specified.
292 */
293 byte = simple_strtoul(argv[3], NULL, 16);
294
295 /*
296 * Optional count
297 */
Timur Tabiff0215a2006-11-28 12:09:35 -0600298 if (argc == 5)
wdenk81a88242002-10-26 15:22:42 +0000299 count = simple_strtoul(argv[4], NULL, 16);
Timur Tabiff0215a2006-11-28 12:09:35 -0600300 else
wdenk81a88242002-10-26 15:22:42 +0000301 count = 1;
wdenk81a88242002-10-26 15:22:42 +0000302
303 while (count-- > 0) {
Timur Tabiff0215a2006-11-28 12:09:35 -0600304 if (i2c_write(chip, addr++, alen, &byte, 1) != 0)
wdenk42c05472004-03-23 22:14:11 +0000305 puts ("Error writing the chip.\n");
wdenk81a88242002-10-26 15:22:42 +0000306 /*
307 * Wait for the write to complete. The write can take
308 * up to 10mSec (we allow a little more time).
309 *
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.
313 */
m8a484c602005-08-12 21:16:13 +0200314/*
315 * No write delay with FRAM devices.
316 */
317#if !defined(CFG_I2C_FRAM)
wdenk81a88242002-10-26 15:22:42 +0000318 udelay(11000);
m8a484c602005-08-12 21:16:13 +0200319#endif
320
wdenk81a88242002-10-26 15:22:42 +0000321#if 0
Timur Tabiff0215a2006-11-28 12:09:35 -0600322 for (timeout = 0; timeout < 10; timeout++) {
wdenk81a88242002-10-26 15:22:42 +0000323 udelay(2000);
Timur Tabiff0215a2006-11-28 12:09:35 -0600324 if (i2c_probe(chip) == 0)
wdenk81a88242002-10-26 15:22:42 +0000325 break;
326 }
327#endif
328 }
329
330 return (0);
331}
332
333
334/* Calculate a CRC on memory
335 *
336 * Syntax:
337 * icrc32 {i2c_chip} {addr}{.0, .1, .2} {count}
338 */
339int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
340{
341 uchar chip;
342 ulong addr;
343 uint alen;
344 int count;
345 uchar byte;
346 ulong crc;
347 ulong err;
348 int j;
349
350 if (argc < 4) {
351 printf ("Usage:\n%s\n", cmdtp->usage);
352 return 1;
353 }
354
355 /*
356 * Chip is always specified.
357 */
358 chip = simple_strtoul(argv[1], NULL, 16);
359
360 /*
361 * Address is always specified.
362 */
363 addr = simple_strtoul(argv[2], NULL, 16);
364 alen = 1;
Timur Tabiff0215a2006-11-28 12:09:35 -0600365 for (j = 0; j < 8; j++) {
wdenk81a88242002-10-26 15:22:42 +0000366 if (argv[2][j] == '.') {
367 alen = argv[2][j+1] - '0';
Timur Tabiff0215a2006-11-28 12:09:35 -0600368 if (alen > 4) {
wdenk81a88242002-10-26 15:22:42 +0000369 printf ("Usage:\n%s\n", cmdtp->usage);
370 return 1;
371 }
372 break;
Timur Tabiff0215a2006-11-28 12:09:35 -0600373 } else if (argv[2][j] == '\0')
wdenk81a88242002-10-26 15:22:42 +0000374 break;
wdenk81a88242002-10-26 15:22:42 +0000375 }
376
377 /*
378 * Count is always specified
379 */
380 count = simple_strtoul(argv[3], NULL, 16);
381
382 printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
383 /*
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.
386 */
387 crc = 0;
388 err = 0;
Timur Tabiff0215a2006-11-28 12:09:35 -0600389 while (count-- > 0) {
390 if (i2c_read(chip, addr, alen, &byte, 1) != 0)
wdenk81a88242002-10-26 15:22:42 +0000391 err++;
wdenk81a88242002-10-26 15:22:42 +0000392 crc = crc32 (crc, &byte, 1);
393 addr++;
394 }
Timur Tabiff0215a2006-11-28 12:09:35 -0600395 if (err > 0)
wdenk42c05472004-03-23 22:14:11 +0000396 puts ("Error reading the chip,\n");
Timur Tabiff0215a2006-11-28 12:09:35 -0600397 else
wdenk81a88242002-10-26 15:22:42 +0000398 printf ("%08lx\n", crc);
wdenk81a88242002-10-26 15:22:42 +0000399
400 return 0;
401}
402
403
404/* Modify memory.
405 *
406 * Syntax:
407 * imm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
408 * inm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
409 */
410
411static int
412mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
413{
414 uchar chip;
415 ulong addr;
416 uint alen;
417 ulong data;
418 int size = 1;
419 int nbytes;
420 int j;
421 extern char console_buffer[];
422
423 if (argc != 3) {
424 printf ("Usage:\n%s\n", cmdtp->usage);
425 return 1;
426 }
427
428#ifdef CONFIG_BOOT_RETRY_TIME
429 reset_cmd_timeout(); /* got a good command to get here */
430#endif
431 /*
432 * We use the last specified parameters, unless new ones are
433 * entered.
434 */
435 chip = i2c_mm_last_chip;
436 addr = i2c_mm_last_addr;
437 alen = i2c_mm_last_alen;
438
439 if ((flag & CMD_FLAG_REPEAT) == 0) {
440 /*
441 * New command specified. Check for a size specification.
442 * Defaults to byte if no or incorrect specification.
443 */
444 size = cmd_get_data_size(argv[0], 1);
445
446 /*
447 * Chip is always specified.
448 */
449 chip = simple_strtoul(argv[1], NULL, 16);
450
451 /*
452 * Address is always specified.
453 */
454 addr = simple_strtoul(argv[2], NULL, 16);
455 alen = 1;
Timur Tabiff0215a2006-11-28 12:09:35 -0600456 for (j = 0; j < 8; j++) {
wdenk81a88242002-10-26 15:22:42 +0000457 if (argv[2][j] == '.') {
458 alen = argv[2][j+1] - '0';
Timur Tabiff0215a2006-11-28 12:09:35 -0600459 if (alen > 4) {
wdenk81a88242002-10-26 15:22:42 +0000460 printf ("Usage:\n%s\n", cmdtp->usage);
461 return 1;
462 }
463 break;
Timur Tabiff0215a2006-11-28 12:09:35 -0600464 } else if (argv[2][j] == '\0')
wdenk81a88242002-10-26 15:22:42 +0000465 break;
wdenk81a88242002-10-26 15:22:42 +0000466 }
467 }
468
469 /*
470 * Print the address, followed by value. Then accept input for
471 * the next value. A non-converted value exits.
472 */
473 do {
474 printf("%08lx:", addr);
Timur Tabiff0215a2006-11-28 12:09:35 -0600475 if (i2c_read(chip, addr, alen, (uchar *)&data, size) != 0)
wdenk42c05472004-03-23 22:14:11 +0000476 puts ("\nError reading the chip,\n");
Timur Tabiff0215a2006-11-28 12:09:35 -0600477 else {
wdenk81a88242002-10-26 15:22:42 +0000478 data = cpu_to_be32(data);
Timur Tabiff0215a2006-11-28 12:09:35 -0600479 if (size == 1)
wdenk81a88242002-10-26 15:22:42 +0000480 printf(" %02lx", (data >> 24) & 0x000000FF);
Timur Tabiff0215a2006-11-28 12:09:35 -0600481 else if (size == 2)
wdenk81a88242002-10-26 15:22:42 +0000482 printf(" %04lx", (data >> 16) & 0x0000FFFF);
Timur Tabiff0215a2006-11-28 12:09:35 -0600483 else
wdenk81a88242002-10-26 15:22:42 +0000484 printf(" %08lx", data);
wdenk81a88242002-10-26 15:22:42 +0000485 }
486
487 nbytes = readline (" ? ");
488 if (nbytes == 0) {
489 /*
490 * <CR> pressed as only input, don't modify current
491 * location and move to next.
492 */
493 if (incrflag)
494 addr += size;
495 nbytes = size;
496#ifdef CONFIG_BOOT_RETRY_TIME
497 reset_cmd_timeout(); /* good enough to not time out */
498#endif
499 }
500#ifdef CONFIG_BOOT_RETRY_TIME
Timur Tabiff0215a2006-11-28 12:09:35 -0600501 else if (nbytes == -2)
wdenk81a88242002-10-26 15:22:42 +0000502 break; /* timed out, exit the command */
wdenk81a88242002-10-26 15:22:42 +0000503#endif
504 else {
505 char *endp;
506
507 data = simple_strtoul(console_buffer, &endp, 16);
Timur Tabiff0215a2006-11-28 12:09:35 -0600508 if (size == 1)
wdenk81a88242002-10-26 15:22:42 +0000509 data = data << 24;
Timur Tabiff0215a2006-11-28 12:09:35 -0600510 else if (size == 2)
wdenk81a88242002-10-26 15:22:42 +0000511 data = data << 16;
wdenk81a88242002-10-26 15:22:42 +0000512 data = be32_to_cpu(data);
513 nbytes = endp - console_buffer;
514 if (nbytes) {
515#ifdef CONFIG_BOOT_RETRY_TIME
516 /*
517 * good enough to not time out
518 */
519 reset_cmd_timeout();
520#endif
Timur Tabiff0215a2006-11-28 12:09:35 -0600521 if (i2c_write(chip, addr, alen, (uchar *)&data, size) != 0)
wdenk42c05472004-03-23 22:14:11 +0000522 puts ("Error writing the chip.\n");
wdenk2bb11052003-07-17 23:16:40 +0000523#ifdef CFG_EEPROM_PAGE_WRITE_DELAY_MS
524 udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
525#endif
wdenk81a88242002-10-26 15:22:42 +0000526 if (incrflag)
527 addr += size;
528 }
529 }
530 } while (nbytes);
531
532 chip = i2c_mm_last_chip;
533 addr = i2c_mm_last_addr;
534 alen = i2c_mm_last_alen;
535
536 return 0;
537}
538
539/*
540 * Syntax:
541 * iprobe {addr}{.0, .1, .2}
542 */
543int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
544{
545 int j;
546#if defined(CFG_I2C_NOPROBES)
547 int k, skip;
Ben Warren45657152006-09-07 16:50:54 -0400548 uchar bus = GET_BUS_NUM;
549#endif /* NOPROBES */
wdenk81a88242002-10-26 15:22:42 +0000550
wdenk42c05472004-03-23 22:14:11 +0000551 puts ("Valid chip addresses:");
Timur Tabiff0215a2006-11-28 12:09:35 -0600552 for (j = 0; j < 128; j++) {
wdenk81a88242002-10-26 15:22:42 +0000553#if defined(CFG_I2C_NOPROBES)
554 skip = 0;
Timur Tabiff0215a2006-11-28 12:09:35 -0600555 for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) {
556 if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
wdenk81a88242002-10-26 15:22:42 +0000557 skip = 1;
558 break;
559 }
560 }
561 if (skip)
562 continue;
563#endif
Timur Tabiff0215a2006-11-28 12:09:35 -0600564 if (i2c_probe(j) == 0)
wdenk81a88242002-10-26 15:22:42 +0000565 printf(" %02X", j);
wdenk81a88242002-10-26 15:22:42 +0000566 }
wdenk42c05472004-03-23 22:14:11 +0000567 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000568
569#if defined(CFG_I2C_NOPROBES)
570 puts ("Excluded chip addresses:");
Timur Tabiff0215a2006-11-28 12:09:35 -0600571 for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) {
572 if (COMPARE_BUS(bus,k))
Ben Warren45657152006-09-07 16:50:54 -0400573 printf(" %02X", NO_PROBE_ADDR(k));
574 }
wdenk42c05472004-03-23 22:14:11 +0000575 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000576#endif
577
578 return 0;
579}
580
581
582/*
583 * Syntax:
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
587 */
588int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
589{
590 u_char chip;
591 ulong alen;
592 uint addr;
593 uint length;
594 u_char bytes[16];
595 int delay;
596 int j;
597
598 if (argc < 3) {
599 printf ("Usage:\n%s\n", cmdtp->usage);
600 return 1;
601 }
602
603 /*
604 * Chip is always specified.
605 */
606 chip = simple_strtoul(argv[1], NULL, 16);
607
608 /*
609 * Address is always specified.
610 */
611 addr = simple_strtoul(argv[2], NULL, 16);
612 alen = 1;
Timur Tabiff0215a2006-11-28 12:09:35 -0600613 for (j = 0; j < 8; j++) {
wdenk81a88242002-10-26 15:22:42 +0000614 if (argv[2][j] == '.') {
615 alen = argv[2][j+1] - '0';
616 if (alen > 4) {
617 printf ("Usage:\n%s\n", cmdtp->usage);
618 return 1;
619 }
620 break;
Timur Tabiff0215a2006-11-28 12:09:35 -0600621 } else if (argv[2][j] == '\0')
wdenk81a88242002-10-26 15:22:42 +0000622 break;
wdenk81a88242002-10-26 15:22:42 +0000623 }
624
625 /*
626 * Length is the number of objects, not number of bytes.
627 */
628 length = 1;
629 length = simple_strtoul(argv[3], NULL, 16);
Timur Tabiff0215a2006-11-28 12:09:35 -0600630 if (length > sizeof(bytes))
wdenk81a88242002-10-26 15:22:42 +0000631 length = sizeof(bytes);
wdenk81a88242002-10-26 15:22:42 +0000632
633 /*
634 * The delay time (uSec) is optional.
635 */
636 delay = 1000;
Timur Tabiff0215a2006-11-28 12:09:35 -0600637 if (argc > 3)
wdenk81a88242002-10-26 15:22:42 +0000638 delay = simple_strtoul(argv[4], NULL, 10);
wdenk81a88242002-10-26 15:22:42 +0000639 /*
640 * Run the loop...
641 */
Timur Tabiff0215a2006-11-28 12:09:35 -0600642 while (1) {
643 if (i2c_read(chip, addr, alen, bytes, length) != 0)
wdenk42c05472004-03-23 22:14:11 +0000644 puts ("Error reading the chip.\n");
wdenk81a88242002-10-26 15:22:42 +0000645 udelay(delay);
646 }
647
648 /* NOTREACHED */
649 return 0;
650}
651
652
653/*
654 * The SDRAM command is separately configured because many
655 * (most?) embedded boards don't use SDRAM DIMMs.
656 */
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500657#if defined(CONFIG_CMD_SDRAM)
wdenk81a88242002-10-26 15:22:42 +0000658
659/*
660 * Syntax:
661 * sdram {i2c_chip}
662 */
663int do_sdram ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
664{
665 u_char chip;
666 u_char data[128];
667 u_char cksum;
668 int j;
669
670 if (argc < 2) {
671 printf ("Usage:\n%s\n", cmdtp->usage);
672 return 1;
673 }
674 /*
675 * Chip is always specified.
676 */
677 chip = simple_strtoul(argv[1], NULL, 16);
678
Timur Tabiff0215a2006-11-28 12:09:35 -0600679 if (i2c_read(chip, 0, 1, data, sizeof(data)) != 0) {
wdenk42c05472004-03-23 22:14:11 +0000680 puts ("No SDRAM Serial Presence Detect found.\n");
wdenk81a88242002-10-26 15:22:42 +0000681 return 1;
682 }
683
684 cksum = 0;
685 for (j = 0; j < 63; j++) {
686 cksum += data[j];
687 }
Timur Tabiff0215a2006-11-28 12:09:35 -0600688 if (cksum != data[63]) {
wdenk81a88242002-10-26 15:22:42 +0000689 printf ("WARNING: Configuration data checksum failure:\n"
690 " is 0x%02x, calculated 0x%02x\n",
691 data[63], cksum);
692 }
693 printf("SPD data revision %d.%d\n",
694 (data[62] >> 4) & 0x0F, data[62] & 0x0F);
695 printf("Bytes used 0x%02X\n", data[0]);
696 printf("Serial memory size 0x%02X\n", 1 << data[1]);
wdenk42c05472004-03-23 22:14:11 +0000697 puts ("Memory type ");
wdenk81a88242002-10-26 15:22:42 +0000698 switch(data[2]) {
wdenk42c05472004-03-23 22:14:11 +0000699 case 2: puts ("EDO\n"); break;
700 case 4: puts ("SDRAM\n"); break;
Matthias Fuchsb60b5e22007-03-08 16:26:52 +0100701 case 8: puts ("DDR2\n"); break;
wdenk42c05472004-03-23 22:14:11 +0000702 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +0000703 }
wdenk42c05472004-03-23 22:14:11 +0000704 puts ("Row address bits ");
Timur Tabiff0215a2006-11-28 12:09:35 -0600705 if ((data[3] & 0x00F0) == 0)
wdenk81a88242002-10-26 15:22:42 +0000706 printf("%d\n", data[3] & 0x0F);
Timur Tabiff0215a2006-11-28 12:09:35 -0600707 else
wdenk81a88242002-10-26 15:22:42 +0000708 printf("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
wdenk42c05472004-03-23 22:14:11 +0000709 puts ("Column address bits ");
Timur Tabiff0215a2006-11-28 12:09:35 -0600710 if ((data[4] & 0x00F0) == 0)
wdenk81a88242002-10-26 15:22:42 +0000711 printf("%d\n", data[4] & 0x0F);
Timur Tabiff0215a2006-11-28 12:09:35 -0600712 else
wdenk81a88242002-10-26 15:22:42 +0000713 printf("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
wdenk81a88242002-10-26 15:22:42 +0000714 printf("Module rows %d\n", data[5]);
715 printf("Module data width %d bits\n", (data[7] << 8) | data[6]);
wdenk42c05472004-03-23 22:14:11 +0000716 puts ("Interface signal levels ");
wdenk81a88242002-10-26 15:22:42 +0000717 switch(data[8]) {
wdenk42c05472004-03-23 22:14:11 +0000718 case 0: puts ("5.0v/TTL\n"); break;
719 case 1: puts ("LVTTL\n"); break;
720 case 2: puts ("HSTL 1.5\n"); break;
721 case 3: puts ("SSTL 3.3\n"); break;
722 case 4: puts ("SSTL 2.5\n"); break;
Matthias Fuchsb60b5e22007-03-08 16:26:52 +0100723 case 5: puts ("SSTL 1.8\n"); break;
wdenk42c05472004-03-23 22:14:11 +0000724 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +0000725 }
726 printf("SDRAM cycle time %d.%d nS\n",
727 (data[9] >> 4) & 0x0F, data[9] & 0x0F);
728 printf("SDRAM access time %d.%d nS\n",
729 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
wdenk42c05472004-03-23 22:14:11 +0000730 puts ("EDC configuration ");
wdenk81a88242002-10-26 15:22:42 +0000731 switch(data[11]) {
wdenk42c05472004-03-23 22:14:11 +0000732 case 0: puts ("None\n"); break;
733 case 1: puts ("Parity\n"); break;
734 case 2: puts ("ECC\n"); break;
735 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +0000736 }
Timur Tabiff0215a2006-11-28 12:09:35 -0600737 if ((data[12] & 0x80) == 0)
wdenk42c05472004-03-23 22:14:11 +0000738 puts ("No self refresh, rate ");
Timur Tabiff0215a2006-11-28 12:09:35 -0600739 else
wdenk42c05472004-03-23 22:14:11 +0000740 puts ("Self refresh, rate ");
wdenk81a88242002-10-26 15:22:42 +0000741 switch(data[12] & 0x7F) {
wdenk42c05472004-03-23 22:14:11 +0000742 case 0: puts ("15.625uS\n"); break;
743 case 1: puts ("3.9uS\n"); break;
744 case 2: puts ("7.8uS\n"); break;
745 case 3: puts ("31.3uS\n"); break;
746 case 4: puts ("62.5uS\n"); break;
747 case 5: puts ("125uS\n"); break;
748 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +0000749 }
750 printf("SDRAM width (primary) %d\n", data[13] & 0x7F);
Timur Tabiff0215a2006-11-28 12:09:35 -0600751 if ((data[13] & 0x80) != 0) {
wdenk81a88242002-10-26 15:22:42 +0000752 printf(" (second bank) %d\n",
753 2 * (data[13] & 0x7F));
754 }
Timur Tabiff0215a2006-11-28 12:09:35 -0600755 if (data[14] != 0) {
wdenk81a88242002-10-26 15:22:42 +0000756 printf("EDC width %d\n",
757 data[14] & 0x7F);
Timur Tabiff0215a2006-11-28 12:09:35 -0600758 if ((data[14] & 0x80) != 0)
wdenk81a88242002-10-26 15:22:42 +0000759 printf(" (second bank) %d\n",
760 2 * (data[14] & 0x7F));
wdenk81a88242002-10-26 15:22:42 +0000761 }
762 printf("Min clock delay, back-to-back random column addresses %d\n",
763 data[15]);
wdenk42c05472004-03-23 22:14:11 +0000764 puts ("Burst length(s) ");
765 if (data[16] & 0x80) puts (" Page");
766 if (data[16] & 0x08) puts (" 8");
767 if (data[16] & 0x04) puts (" 4");
768 if (data[16] & 0x02) puts (" 2");
769 if (data[16] & 0x01) puts (" 1");
770 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000771 printf("Number of banks %d\n", data[17]);
wdenk42c05472004-03-23 22:14:11 +0000772 puts ("CAS latency(s) ");
773 if (data[18] & 0x80) puts (" TBD");
774 if (data[18] & 0x40) puts (" 7");
775 if (data[18] & 0x20) puts (" 6");
776 if (data[18] & 0x10) puts (" 5");
777 if (data[18] & 0x08) puts (" 4");
778 if (data[18] & 0x04) puts (" 3");
779 if (data[18] & 0x02) puts (" 2");
780 if (data[18] & 0x01) puts (" 1");
781 putc ('\n');
782 puts ("CS latency(s) ");
783 if (data[19] & 0x80) puts (" TBD");
784 if (data[19] & 0x40) puts (" 6");
785 if (data[19] & 0x20) puts (" 5");
786 if (data[19] & 0x10) puts (" 4");
787 if (data[19] & 0x08) puts (" 3");
788 if (data[19] & 0x04) puts (" 2");
789 if (data[19] & 0x02) puts (" 1");
790 if (data[19] & 0x01) puts (" 0");
791 putc ('\n');
792 puts ("WE latency(s) ");
793 if (data[20] & 0x80) puts (" TBD");
794 if (data[20] & 0x40) puts (" 6");
795 if (data[20] & 0x20) puts (" 5");
796 if (data[20] & 0x10) puts (" 4");
797 if (data[20] & 0x08) puts (" 3");
798 if (data[20] & 0x04) puts (" 2");
799 if (data[20] & 0x02) puts (" 1");
800 if (data[20] & 0x01) puts (" 0");
801 putc ('\n');
802 puts ("Module attributes:\n");
803 if (!data[21]) puts (" (none)\n");
804 if (data[21] & 0x80) puts (" TBD (bit 7)\n");
805 if (data[21] & 0x40) puts (" Redundant row address\n");
806 if (data[21] & 0x20) puts (" Differential clock input\n");
807 if (data[21] & 0x10) puts (" Registerd DQMB inputs\n");
808 if (data[21] & 0x08) puts (" Buffered DQMB inputs\n");
809 if (data[21] & 0x04) puts (" On-card PLL\n");
810 if (data[21] & 0x02) puts (" Registered address/control lines\n");
811 if (data[21] & 0x01) puts (" Buffered address/control lines\n");
812 puts ("Device attributes:\n");
813 if (data[22] & 0x80) puts (" TBD (bit 7)\n");
814 if (data[22] & 0x40) puts (" TBD (bit 6)\n");
815 if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
816 else puts (" Upper Vcc tolerance 10%\n");
817 if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
818 else puts (" Lower Vcc tolerance 10%\n");
819 if (data[22] & 0x08) puts (" Supports write1/read burst\n");
820 if (data[22] & 0x04) puts (" Supports precharge all\n");
821 if (data[22] & 0x02) puts (" Supports auto precharge\n");
822 if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
wdenk81a88242002-10-26 15:22:42 +0000823 printf("SDRAM cycle time (2nd highest CAS latency) %d.%d nS\n",
824 (data[23] >> 4) & 0x0F, data[23] & 0x0F);
825 printf("SDRAM access from clock (2nd highest CAS latency) %d.%d nS\n",
826 (data[24] >> 4) & 0x0F, data[24] & 0x0F);
827 printf("SDRAM cycle time (3rd highest CAS latency) %d.%d nS\n",
828 (data[25] >> 4) & 0x0F, data[25] & 0x0F);
829 printf("SDRAM access from clock (3rd highest CAS latency) %d.%d nS\n",
830 (data[26] >> 4) & 0x0F, data[26] & 0x0F);
831 printf("Minimum row precharge %d nS\n", data[27]);
832 printf("Row active to row active min %d nS\n", data[28]);
833 printf("RAS to CAS delay min %d nS\n", data[29]);
834 printf("Minimum RAS pulse width %d nS\n", data[30]);
wdenk42c05472004-03-23 22:14:11 +0000835 puts ("Density of each row ");
836 if (data[31] & 0x80) puts (" 512");
837 if (data[31] & 0x40) puts (" 256");
838 if (data[31] & 0x20) puts (" 128");
839 if (data[31] & 0x10) puts (" 64");
840 if (data[31] & 0x08) puts (" 32");
841 if (data[31] & 0x04) puts (" 16");
842 if (data[31] & 0x02) puts (" 8");
843 if (data[31] & 0x01) puts (" 4");
844 puts ("MByte\n");
wdenk81a88242002-10-26 15:22:42 +0000845 printf("Command and Address setup %c%d.%d nS\n",
846 (data[32] & 0x80) ? '-' : '+',
847 (data[32] >> 4) & 0x07, data[32] & 0x0F);
848 printf("Command and Address hold %c%d.%d nS\n",
849 (data[33] & 0x80) ? '-' : '+',
850 (data[33] >> 4) & 0x07, data[33] & 0x0F);
851 printf("Data signal input setup %c%d.%d nS\n",
852 (data[34] & 0x80) ? '-' : '+',
853 (data[34] >> 4) & 0x07, data[34] & 0x0F);
854 printf("Data signal input hold %c%d.%d nS\n",
855 (data[35] & 0x80) ? '-' : '+',
856 (data[35] >> 4) & 0x07, data[35] & 0x0F);
wdenk42c05472004-03-23 22:14:11 +0000857 puts ("Manufacturer's JEDEC ID ");
Timur Tabiff0215a2006-11-28 12:09:35 -0600858 for (j = 64; j <= 71; j++)
wdenk81a88242002-10-26 15:22:42 +0000859 printf("%02X ", data[j]);
wdenk42c05472004-03-23 22:14:11 +0000860 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000861 printf("Manufacturing Location %02X\n", data[72]);
wdenk42c05472004-03-23 22:14:11 +0000862 puts ("Manufacturer's Part Number ");
Timur Tabiff0215a2006-11-28 12:09:35 -0600863 for (j = 73; j <= 90; j++)
wdenk81a88242002-10-26 15:22:42 +0000864 printf("%02X ", data[j]);
wdenk42c05472004-03-23 22:14:11 +0000865 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000866 printf("Revision Code %02X %02X\n", data[91], data[92]);
867 printf("Manufacturing Date %02X %02X\n", data[93], data[94]);
wdenk42c05472004-03-23 22:14:11 +0000868 puts ("Assembly Serial Number ");
Timur Tabiff0215a2006-11-28 12:09:35 -0600869 for (j = 95; j <= 98; j++)
wdenk81a88242002-10-26 15:22:42 +0000870 printf("%02X ", data[j]);
wdenk42c05472004-03-23 22:14:11 +0000871 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000872 printf("Speed rating PC%d\n",
873 data[126] == 0x66 ? 66 : data[126]);
874
875 return 0;
876}
Jon Loeligerd704d912007-07-10 11:02:44 -0500877#endif
wdenk81a88242002-10-26 15:22:42 +0000878
Ben Warren45657152006-09-07 16:50:54 -0400879#if defined(CONFIG_I2C_CMD_TREE)
880#if defined(CONFIG_I2C_MULTI_BUS)
881int do_i2c_bus_num(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
882{
883 int bus_idx, ret=0;
884
Timur Tabiff0215a2006-11-28 12:09:35 -0600885 if (argc == 1)
886 /* querying current setting */
Ben Warren45657152006-09-07 16:50:54 -0400887 printf("Current bus is %d\n", i2c_get_bus_num());
Timur Tabiff0215a2006-11-28 12:09:35 -0600888 else {
Ben Warren45657152006-09-07 16:50:54 -0400889 bus_idx = simple_strtoul(argv[1], NULL, 10);
890 printf("Setting bus to %d\n", bus_idx);
891 ret = i2c_set_bus_num(bus_idx);
Timur Tabiff0215a2006-11-28 12:09:35 -0600892 if (ret)
Ben Warren45657152006-09-07 16:50:54 -0400893 printf("Failure changing bus number (%d)\n", ret);
Ben Warren45657152006-09-07 16:50:54 -0400894 }
895 return ret;
896}
897#endif /* CONFIG_I2C_MULTI_BUS */
898
899int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
900{
901 int speed, ret=0;
902
Timur Tabiff0215a2006-11-28 12:09:35 -0600903 if (argc == 1)
904 /* querying current speed */
Ben Warren45657152006-09-07 16:50:54 -0400905 printf("Current bus speed=%d\n", i2c_get_bus_speed());
Timur Tabiff0215a2006-11-28 12:09:35 -0600906 else {
Ben Warren45657152006-09-07 16:50:54 -0400907 speed = simple_strtoul(argv[1], NULL, 10);
908 printf("Setting bus speed to %d Hz\n", speed);
909 ret = i2c_set_bus_speed(speed);
Timur Tabiff0215a2006-11-28 12:09:35 -0600910 if (ret)
Ben Warren45657152006-09-07 16:50:54 -0400911 printf("Failure changing bus speed (%d)\n", ret);
Ben Warren45657152006-09-07 16:50:54 -0400912 }
913 return ret;
914}
915
916int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
917{
918#if defined(CONFIG_I2C_MULTI_BUS)
Timur Tabiff0215a2006-11-28 12:09:35 -0600919 if (!strncmp(argv[1], "de", 2))
Ben Warren45657152006-09-07 16:50:54 -0400920 return do_i2c_bus_num(cmdtp, flag, --argc, ++argv);
Ben Warren45657152006-09-07 16:50:54 -0400921#endif /* CONFIG_I2C_MULTI_BUS */
Timur Tabiff0215a2006-11-28 12:09:35 -0600922 if (!strncmp(argv[1], "sp", 2))
Ben Warren45657152006-09-07 16:50:54 -0400923 return do_i2c_bus_speed(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600924 if (!strncmp(argv[1], "md", 2))
Ben Warren45657152006-09-07 16:50:54 -0400925 return do_i2c_md(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600926 if (!strncmp(argv[1], "mm", 2))
Ben Warren45657152006-09-07 16:50:54 -0400927 return do_i2c_mm(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600928 if (!strncmp(argv[1], "mw", 2))
Ben Warren45657152006-09-07 16:50:54 -0400929 return do_i2c_mw(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600930 if (!strncmp(argv[1], "nm", 2))
Ben Warren45657152006-09-07 16:50:54 -0400931 return do_i2c_nm(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600932 if (!strncmp(argv[1], "cr", 2))
Ben Warren45657152006-09-07 16:50:54 -0400933 return do_i2c_crc(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600934 if (!strncmp(argv[1], "pr", 2))
Ben Warren45657152006-09-07 16:50:54 -0400935 return do_i2c_probe(cmdtp, flag, --argc, ++argv);
Timur Tabiff0215a2006-11-28 12:09:35 -0600936 if (!strncmp(argv[1], "lo", 2))
Ben Warren45657152006-09-07 16:50:54 -0400937 return do_i2c_loop(cmdtp, flag, --argc, ++argv);
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500938#if defined(CONFIG_CMD_SDRAM)
Timur Tabiff0215a2006-11-28 12:09:35 -0600939 if (!strncmp(argv[1], "sd", 2))
Ben Warren45657152006-09-07 16:50:54 -0400940 return do_sdram(cmdtp, flag, --argc, ++argv);
Jon Loeligerd704d912007-07-10 11:02:44 -0500941#endif
Ben Warren45657152006-09-07 16:50:54 -0400942 else
Ben Warren45657152006-09-07 16:50:54 -0400943 printf ("Usage:\n%s\n", cmdtp->usage);
Ben Warren45657152006-09-07 16:50:54 -0400944 return 0;
945}
946#endif /* CONFIG_I2C_CMD_TREE */
wdenk57b2d802003-06-27 21:31:46 +0000947
948/***************************************************/
949
Matthias Fuchsdd6cffc2007-03-08 16:25:47 +0100950#if defined(CONFIG_I2C_CMD_TREE)
951U_BOOT_CMD(
952 i2c, 6, 1, do_i2c,
953 "i2c - I2C sub-system\n",
954#if defined(CONFIG_I2C_MULTI_BUS)
955 "dev [dev] - show or set current I2C bus\n"
956#endif /* CONFIG_I2C_MULTI_BUS */
957 "i2c speed [speed] - show or set I2C bus speed\n"
958 "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
959 "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
960 "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
961 "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
962 "i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
963 "i2c probe - show devices on the I2C bus\n"
964 "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500965#if defined(CONFIG_CMD_SDRAM)
Matthias Fuchsdd6cffc2007-03-08 16:25:47 +0100966 "i2c sdram chip - print SDRAM configuration information\n"
Jon Loeligerd704d912007-07-10 11:02:44 -0500967#endif
Matthias Fuchsdd6cffc2007-03-08 16:25:47 +0100968);
Stefan Roesed09d6012007-03-28 14:52:12 +0200969#endif /* CONFIG_I2C_CMD_TREE */
wdenkf287a242003-07-01 21:06:45 +0000970U_BOOT_CMD(
971 imd, 4, 1, do_i2c_md, \
wdenk57b2d802003-06-27 21:31:46 +0000972 "imd - i2c memory display\n", \
973 "chip address[.0, .1, .2] [# of objects]\n - i2c memory display\n" \
974);
975
wdenkf287a242003-07-01 21:06:45 +0000976U_BOOT_CMD(
977 imm, 3, 1, do_i2c_mm,
wdenk57b2d802003-06-27 21:31:46 +0000978 "imm - i2c memory modify (auto-incrementing)\n",
979 "chip address[.0, .1, .2]\n"
980 " - memory modify, auto increment address\n"
981);
wdenkf287a242003-07-01 21:06:45 +0000982U_BOOT_CMD(
983 inm, 3, 1, do_i2c_nm,
wdenk57b2d802003-06-27 21:31:46 +0000984 "inm - memory modify (constant address)\n",
985 "chip address[.0, .1, .2]\n - memory modify, read and keep address\n"
986);
987
wdenkf287a242003-07-01 21:06:45 +0000988U_BOOT_CMD(
989 imw, 5, 1, do_i2c_mw,
wdenk57b2d802003-06-27 21:31:46 +0000990 "imw - memory write (fill)\n",
991 "chip address[.0, .1, .2] value [count]\n - memory write (fill)\n"
992);
993
wdenkf287a242003-07-01 21:06:45 +0000994U_BOOT_CMD(
995 icrc32, 5, 1, do_i2c_crc,
wdenk57b2d802003-06-27 21:31:46 +0000996 "icrc32 - checksum calculation\n",
997 "chip address[.0, .1, .2] count\n - compute CRC32 checksum\n"
998);
999
wdenkf287a242003-07-01 21:06:45 +00001000U_BOOT_CMD(
1001 iprobe, 1, 1, do_i2c_probe,
wdenk57b2d802003-06-27 21:31:46 +00001002 "iprobe - probe to discover valid I2C chip addresses\n",
1003 "\n -discover valid I2C chip addresses\n"
1004);
1005
1006/*
1007 * Require full name for "iloop" because it is an infinite loop!
1008 */
wdenkf287a242003-07-01 21:06:45 +00001009U_BOOT_CMD(
1010 iloop, 5, 1, do_i2c_loop,
wdenk57b2d802003-06-27 21:31:46 +00001011 "iloop - infinite loop on address range\n",
1012 "chip address[.0, .1, .2] [# of objects]\n"
1013 " - loop, reading a set of addresses\n"
1014);
1015
Jon Loeligerd76b5c12007-07-08 18:02:23 -05001016#if defined(CONFIG_CMD_SDRAM)
wdenkf287a242003-07-01 21:06:45 +00001017U_BOOT_CMD(
1018 isdram, 2, 1, do_sdram,
wdenk57b2d802003-06-27 21:31:46 +00001019 "isdram - print SDRAM configuration information\n",
1020 "chip\n - print SDRAM configuration information\n"
1021 " (valid chip values 50..57)\n"
1022);
1023#endif