blob: 5614a6d066452312d9a64d7450e30184a8bd64f4 [file] [log] [blame]
wdenk81a88242002-10-26 15:22:42 +00001/*
Heiko Schocher3f4978c2012-01-16 21:12:24 +00002 * (C) Copyright 2009
3 * Sergey Kubushyn, himself, ksi@koi8.net
4 *
5 * Changes for unified multibus/multiadapter I2C support.
6 *
wdenk81a88242002-10-26 15:22:42 +00007 * (C) Copyright 2001
8 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com.
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29/*
30 * I2C Functions similar to the standard memory functions.
31 *
32 * There are several parameters in many of the commands that bear further
33 * explanations:
34 *
wdenk81a88242002-10-26 15:22:42 +000035 * {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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020068 * CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the
wdenk81a88242002-10-26 15:22:42 +000069 * {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...
Peter Tyser0f89c542009-04-18 22:34:03 -050072 * i2c md 50 0 10 display 16 bytes starting at 0x000
wdenk81a88242002-10-26 15:22:42 +000073 * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd>
Peter Tyser0f89c542009-04-18 22:34:03 -050074 * i2c md 50 100 10 display 16 bytes starting at 0x100
wdenk81a88242002-10-26 15:22:42 +000075 * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd>
Peter Tyser0f89c542009-04-18 22:34:03 -050076 * i2c md 50 210 10 display 16 bytes starting at 0x210
wdenk81a88242002-10-26 15:22:42 +000077 * 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>
Tom Wai-Hong Tam735987c2012-12-05 14:46:40 +000086#include <edid.h>
Heiko Schocher67b23a32008-10-15 09:39:47 +020087#include <environment.h>
wdenk81a88242002-10-26 15:22:42 +000088#include <i2c.h>
Heiko Schocher67b23a32008-10-15 09:39:47 +020089#include <malloc.h>
wdenk81a88242002-10-26 15:22:42 +000090#include <asm/byteorder.h>
Marek Vasut2515d842012-11-12 14:34:25 +000091#include <linux/compiler.h>
wdenk81a88242002-10-26 15:22:42 +000092
Heiko Schocher3f4978c2012-01-16 21:12:24 +000093DECLARE_GLOBAL_DATA_PTR;
94
wdenk81a88242002-10-26 15:22:42 +000095/* Display values from last command.
96 * Memory modify remembered values are different from display memory.
97 */
98static uchar i2c_dp_last_chip;
99static uint i2c_dp_last_addr;
100static uint i2c_dp_last_alen;
101static uint i2c_dp_last_length = 0x10;
102
103static uchar i2c_mm_last_chip;
104static uint i2c_mm_last_addr;
105static uint i2c_mm_last_alen;
106
Ben Warrenbb99ad62006-09-07 16:50:54 -0400107/* If only one I2C bus is present, the list of devices to ignore when
108 * the probe command is issued is represented by a 1D array of addresses.
109 * When multiple buses are present, the list is an array of bus-address
110 * pairs. The following macros take care of this */
111
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200112#if defined(CONFIG_SYS_I2C_NOPROBES)
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000113#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MUX) || \
114 defined(CONFIG_I2C_MULTI_BUS)
Ben Warrenbb99ad62006-09-07 16:50:54 -0400115static struct
116{
117 uchar bus;
118 uchar addr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200119} i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
Ben Warrenbb99ad62006-09-07 16:50:54 -0400120#define GET_BUS_NUM i2c_get_bus_num()
121#define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b))
122#define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a))
123#define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr
124#else /* single bus */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200125static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
Ben Warrenbb99ad62006-09-07 16:50:54 -0400126#define GET_BUS_NUM 0
127#define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */
128#define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a))
129#define NO_PROBE_ADDR(i) i2c_no_probes[(i)]
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000130#endif /* defined(CONFIG_SYS_I2C) */
Ben Warrenbb99ad62006-09-07 16:50:54 -0400131
132#define NUM_ELEMENTS_NOPROBE (sizeof(i2c_no_probes)/sizeof(i2c_no_probes[0]))
wdenk81a88242002-10-26 15:22:42 +0000133#endif
134
Heiko Schocher67b23a32008-10-15 09:39:47 +0200135#if defined(CONFIG_I2C_MUX)
136static I2C_MUX_DEVICE *i2c_mux_devices = NULL;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200137static int i2c_mux_busid = CONFIG_SYS_MAX_I2C_BUS;
Heiko Schocher67b23a32008-10-15 09:39:47 +0200138#endif
139
Frans Meulenbroeksa266fe92010-03-26 09:46:40 +0100140#define DISP_LINE_LEN 16
141
Marek Vasut06afa382012-11-12 14:34:27 +0000142/**
143 * i2c_init_board() - Board-specific I2C bus init
144 *
145 * This function is the default no-op implementation of I2C bus
146 * initialization. This function can be overriden by board-specific
147 * implementation if needed.
148 */
Marek Vasut2515d842012-11-12 14:34:25 +0000149__weak
150void i2c_init_board(void)
Stefan Biglerc649dda2011-04-08 16:24:08 +0200151{
Stefan Biglerc649dda2011-04-08 16:24:08 +0200152}
Stefan Biglerc649dda2011-04-08 16:24:08 +0200153
Peter Tyser655b34a2009-04-18 22:34:01 -0500154/* TODO: Implement architecture-specific get/set functions */
Marek Vasut06afa382012-11-12 14:34:27 +0000155
156/**
157 * i2c_get_bus_speed() - Return I2C bus speed
158 *
159 * This function is the default implementation of function for retrieveing
160 * the current I2C bus speed in Hz.
161 *
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.
165 *
166 * Returns I2C bus speed in Hz.
167 */
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000168#if !defined(CONFIG_SYS_I2C)
169/*
170 * TODO: Implement architecture-specific get/set functions
171 * Should go away, if we switched completely to new multibus support
172 */
Marek Vasut2515d842012-11-12 14:34:25 +0000173__weak
174unsigned int i2c_get_bus_speed(void)
Peter Tyser655b34a2009-04-18 22:34:01 -0500175{
176 return CONFIG_SYS_I2C_SPEED;
177}
Peter Tyser655b34a2009-04-18 22:34:01 -0500178
Marek Vasut06afa382012-11-12 14:34:27 +0000179/**
180 * i2c_set_bus_speed() - Configure I2C bus speed
181 * @speed: Newly set speed of the I2C bus in Hz
182 *
183 * This function is the default implementation of function for setting
184 * the I2C bus speed in Hz.
185 *
186 * A driver implementing runtime switching of I2C bus speed must override
187 * this function to report the speed correctly. Simple or legacy drivers
188 * can use this fallback.
189 *
190 * Returns zero on success, negative value on error.
191 */
Marek Vasut2515d842012-11-12 14:34:25 +0000192__weak
193int i2c_set_bus_speed(unsigned int speed)
Peter Tyser655b34a2009-04-18 22:34:01 -0500194{
195 if (speed != CONFIG_SYS_I2C_SPEED)
196 return -1;
197
198 return 0;
199}
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000200#endif
Peter Tyser655b34a2009-04-18 22:34:01 -0500201
Marek Vasut06afa382012-11-12 14:34:27 +0000202/**
203 * get_alen() - Small parser helper function to get address length
204 *
205 * Returns the address length.
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100206 */
207static uint get_alen(char *arg)
208{
209 int j;
210 int alen;
211
212 alen = 1;
213 for (j = 0; j < 8; j++) {
214 if (arg[j] == '.') {
215 alen = arg[j+1] - '0';
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100216 break;
217 } else if (arg[j] == '\0')
218 break;
219 }
220 return alen;
221}
222
Marek Vasut06afa382012-11-12 14:34:27 +0000223/**
224 * do_i2c_read() - Handle the "i2c read" command-line command
225 * @cmdtp: Command data struct pointer
226 * @flag: Command flag
227 * @argc: Command-line argument count
228 * @argv: Array of command-line arguments
229 *
230 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
231 * on error.
232 *
Frans Meulenbroeks652e5352010-02-25 10:12:16 +0100233 * Syntax:
234 * i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr}
235 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200236static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Frans Meulenbroeks652e5352010-02-25 10:12:16 +0100237{
238 u_char chip;
239 uint devaddr, alen, length;
240 u_char *memaddr;
Frans Meulenbroeks652e5352010-02-25 10:12:16 +0100241
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200242 if (argc != 5)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000243 return CMD_RET_USAGE;
Frans Meulenbroeks652e5352010-02-25 10:12:16 +0100244
245 /*
246 * I2C chip address
247 */
248 chip = simple_strtoul(argv[1], NULL, 16);
249
250 /*
251 * I2C data address within the chip. This can be 1 or
252 * 2 bytes long. Some day it might be 3 bytes long :-).
253 */
254 devaddr = simple_strtoul(argv[2], NULL, 16);
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100255 alen = get_alen(argv[2]);
Reinhard Meyer7a92e532010-08-25 14:41:16 +0200256 if (alen > 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000257 return CMD_RET_USAGE;
Frans Meulenbroeks652e5352010-02-25 10:12:16 +0100258
259 /*
260 * Length is the number of objects, not number of bytes.
261 */
262 length = simple_strtoul(argv[3], NULL, 16);
263
264 /*
265 * memaddr is the address where to store things in memory
266 */
267 memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16);
268
269 if (i2c_read(chip, devaddr, alen, memaddr, length) != 0) {
270 puts ("Error reading the chip.\n");
271 return 1;
272 }
273 return 0;
274}
275
York Sunff5d2dc2012-09-16 08:02:30 +0000276static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
277{
278 u_char chip;
279 uint devaddr, alen, length;
280 u_char *memaddr;
281
282 if (argc != 5)
283 return cmd_usage(cmdtp);
284
285 /*
286 * memaddr is the address where to store things in memory
287 */
288 memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16);
289
290 /*
291 * I2C chip address
292 */
293 chip = simple_strtoul(argv[2], NULL, 16);
294
295 /*
296 * I2C data address within the chip. This can be 1 or
297 * 2 bytes long. Some day it might be 3 bytes long :-).
298 */
299 devaddr = simple_strtoul(argv[3], NULL, 16);
300 alen = get_alen(argv[3]);
301 if (alen > 3)
302 return cmd_usage(cmdtp);
303
304 /*
305 * Length is the number of objects, not number of bytes.
306 */
307 length = simple_strtoul(argv[4], NULL, 16);
308
309 while (length-- > 0) {
310 if (i2c_write(chip, devaddr++, alen, memaddr++, 1) != 0) {
311 puts("Error writing to the chip.\n");
312 return 1;
313 }
314/*
315 * No write delay with FRAM devices.
316 */
317#if !defined(CONFIG_SYS_I2C_FRAM)
318 udelay(11000);
319#endif
320 }
321 return 0;
322}
323
Marek Vasut06afa382012-11-12 14:34:27 +0000324/**
325 * do_i2c_md() - Handle the "i2c md" command-line command
326 * @cmdtp: Command data struct pointer
327 * @flag: Command flag
328 * @argc: Command-line argument count
329 * @argv: Array of command-line arguments
330 *
331 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
332 * on error.
333 *
Frans Meulenbroeks4a8cf332010-03-26 09:46:39 +0100334 * Syntax:
335 * i2c md {i2c_chip} {addr}{.0, .1, .2} {len}
336 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200337static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000338{
339 u_char chip;
340 uint addr, alen, length;
341 int j, nbytes, linebytes;
342
343 /* We use the last specified parameters, unless new ones are
344 * entered.
345 */
346 chip = i2c_dp_last_chip;
347 addr = i2c_dp_last_addr;
348 alen = i2c_dp_last_alen;
349 length = i2c_dp_last_length;
350
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200351 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000352 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000353
354 if ((flag & CMD_FLAG_REPEAT) == 0) {
355 /*
356 * New command specified.
357 */
wdenk81a88242002-10-26 15:22:42 +0000358
359 /*
360 * I2C chip address
361 */
362 chip = simple_strtoul(argv[1], NULL, 16);
363
364 /*
365 * I2C data address within the chip. This can be 1 or
366 * 2 bytes long. Some day it might be 3 bytes long :-).
367 */
368 addr = simple_strtoul(argv[2], NULL, 16);
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100369 alen = get_alen(argv[2]);
Reinhard Meyer7a92e532010-08-25 14:41:16 +0200370 if (alen > 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000371 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000372
373 /*
374 * If another parameter, it is the length to display.
375 * Length is the number of objects, not number of bytes.
376 */
377 if (argc > 3)
378 length = simple_strtoul(argv[3], NULL, 16);
379 }
380
381 /*
382 * Print the lines.
383 *
384 * We buffer all read data, so we can make sure data is read only
385 * once.
386 */
387 nbytes = length;
388 do {
389 unsigned char linebuf[DISP_LINE_LEN];
390 unsigned char *cp;
391
392 linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
393
Timur Tabie857a5b2006-11-28 12:09:35 -0600394 if (i2c_read(chip, addr, alen, linebuf, linebytes) != 0)
wdenk4b9206e2004-03-23 22:14:11 +0000395 puts ("Error reading the chip.\n");
Timur Tabie857a5b2006-11-28 12:09:35 -0600396 else {
wdenk81a88242002-10-26 15:22:42 +0000397 printf("%04x:", addr);
398 cp = linebuf;
399 for (j=0; j<linebytes; j++) {
400 printf(" %02x", *cp++);
401 addr++;
402 }
wdenk4b9206e2004-03-23 22:14:11 +0000403 puts (" ");
wdenk81a88242002-10-26 15:22:42 +0000404 cp = linebuf;
405 for (j=0; j<linebytes; j++) {
406 if ((*cp < 0x20) || (*cp > 0x7e))
wdenk4b9206e2004-03-23 22:14:11 +0000407 puts (".");
wdenk81a88242002-10-26 15:22:42 +0000408 else
409 printf("%c", *cp);
410 cp++;
411 }
wdenk4b9206e2004-03-23 22:14:11 +0000412 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000413 }
414 nbytes -= linebytes;
415 } while (nbytes > 0);
416
417 i2c_dp_last_chip = chip;
418 i2c_dp_last_addr = addr;
419 i2c_dp_last_alen = alen;
420 i2c_dp_last_length = length;
421
422 return 0;
423}
424
Marek Vasut06afa382012-11-12 14:34:27 +0000425/**
426 * do_i2c_mw() - Handle the "i2c mw" command-line command
427 * @cmdtp: Command data struct pointer
428 * @flag: Command flag
429 * @argc: Command-line argument count
430 * @argv: Array of command-line arguments
431 *
432 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
433 * on error.
wdenk81a88242002-10-26 15:22:42 +0000434 *
435 * Syntax:
Peter Tyser0f89c542009-04-18 22:34:03 -0500436 * i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
wdenk81a88242002-10-26 15:22:42 +0000437 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200438static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000439{
440 uchar chip;
441 ulong addr;
442 uint alen;
443 uchar byte;
444 int count;
wdenk81a88242002-10-26 15:22:42 +0000445
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200446 if ((argc < 4) || (argc > 5))
Simon Glass4c12eeb2011-12-10 08:44:01 +0000447 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000448
449 /*
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200450 * Chip is always specified.
451 */
wdenk81a88242002-10-26 15:22:42 +0000452 chip = simple_strtoul(argv[1], NULL, 16);
453
454 /*
455 * Address is always specified.
456 */
457 addr = simple_strtoul(argv[2], NULL, 16);
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100458 alen = get_alen(argv[2]);
Reinhard Meyer7a92e532010-08-25 14:41:16 +0200459 if (alen > 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000460 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000461
462 /*
463 * Value to write is always specified.
464 */
465 byte = simple_strtoul(argv[3], NULL, 16);
466
467 /*
468 * Optional count
469 */
Timur Tabie857a5b2006-11-28 12:09:35 -0600470 if (argc == 5)
wdenk81a88242002-10-26 15:22:42 +0000471 count = simple_strtoul(argv[4], NULL, 16);
Timur Tabie857a5b2006-11-28 12:09:35 -0600472 else
wdenk81a88242002-10-26 15:22:42 +0000473 count = 1;
wdenk81a88242002-10-26 15:22:42 +0000474
475 while (count-- > 0) {
Timur Tabie857a5b2006-11-28 12:09:35 -0600476 if (i2c_write(chip, addr++, alen, &byte, 1) != 0)
wdenk4b9206e2004-03-23 22:14:11 +0000477 puts ("Error writing the chip.\n");
wdenk81a88242002-10-26 15:22:42 +0000478 /*
479 * Wait for the write to complete. The write can take
480 * up to 10mSec (we allow a little more time).
wdenk81a88242002-10-26 15:22:42 +0000481 */
d4f5c722005-08-12 21:16:13 +0200482/*
483 * No write delay with FRAM devices.
484 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200485#if !defined(CONFIG_SYS_I2C_FRAM)
wdenk81a88242002-10-26 15:22:42 +0000486 udelay(11000);
d4f5c722005-08-12 21:16:13 +0200487#endif
wdenk81a88242002-10-26 15:22:42 +0000488 }
489
Marek Vasut06afa382012-11-12 14:34:27 +0000490 return 0;
wdenk81a88242002-10-26 15:22:42 +0000491}
492
Marek Vasut06afa382012-11-12 14:34:27 +0000493/**
494 * do_i2c_crc() - Handle the "i2c crc32" command-line command
495 * @cmdtp: Command data struct pointer
496 * @flag: Command flag
497 * @argc: Command-line argument count
498 * @argv: Array of command-line arguments
499 *
500 * Calculate a CRC on memory
501 *
502 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
503 * on error.
wdenk81a88242002-10-26 15:22:42 +0000504 *
505 * Syntax:
Peter Tyser0f89c542009-04-18 22:34:03 -0500506 * i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count}
wdenk81a88242002-10-26 15:22:42 +0000507 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200508static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000509{
510 uchar chip;
511 ulong addr;
512 uint alen;
513 int count;
514 uchar byte;
515 ulong crc;
516 ulong err;
wdenk81a88242002-10-26 15:22:42 +0000517
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200518 if (argc < 4)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000519 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000520
521 /*
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200522 * Chip is always specified.
523 */
wdenk81a88242002-10-26 15:22:42 +0000524 chip = simple_strtoul(argv[1], NULL, 16);
525
526 /*
527 * Address is always specified.
528 */
529 addr = simple_strtoul(argv[2], NULL, 16);
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100530 alen = get_alen(argv[2]);
Reinhard Meyer7a92e532010-08-25 14:41:16 +0200531 if (alen > 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000532 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000533
534 /*
535 * Count is always specified
536 */
537 count = simple_strtoul(argv[3], NULL, 16);
538
539 printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1);
540 /*
541 * CRC a byte at a time. This is going to be slooow, but hey, the
542 * memories are small and slow too so hopefully nobody notices.
543 */
544 crc = 0;
545 err = 0;
Timur Tabie857a5b2006-11-28 12:09:35 -0600546 while (count-- > 0) {
547 if (i2c_read(chip, addr, alen, &byte, 1) != 0)
wdenk81a88242002-10-26 15:22:42 +0000548 err++;
wdenk81a88242002-10-26 15:22:42 +0000549 crc = crc32 (crc, &byte, 1);
550 addr++;
551 }
Timur Tabie857a5b2006-11-28 12:09:35 -0600552 if (err > 0)
wdenk4b9206e2004-03-23 22:14:11 +0000553 puts ("Error reading the chip,\n");
Timur Tabie857a5b2006-11-28 12:09:35 -0600554 else
wdenk81a88242002-10-26 15:22:42 +0000555 printf ("%08lx\n", crc);
wdenk81a88242002-10-26 15:22:42 +0000556
557 return 0;
558}
559
Marek Vasut06afa382012-11-12 14:34:27 +0000560/**
561 * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command
562 * @cmdtp: Command data struct pointer
563 * @flag: Command flag
564 * @argc: Command-line argument count
565 * @argv: Array of command-line arguments
566 *
567 * Modify memory.
568 *
569 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
570 * on error.
wdenk81a88242002-10-26 15:22:42 +0000571 *
572 * Syntax:
Peter Tyser0f89c542009-04-18 22:34:03 -0500573 * i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
574 * i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2}
wdenk81a88242002-10-26 15:22:42 +0000575 */
wdenk81a88242002-10-26 15:22:42 +0000576static int
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200577mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000578{
579 uchar chip;
580 ulong addr;
581 uint alen;
582 ulong data;
583 int size = 1;
584 int nbytes;
wdenk81a88242002-10-26 15:22:42 +0000585
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200586 if (argc != 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000587 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000588
589#ifdef CONFIG_BOOT_RETRY_TIME
590 reset_cmd_timeout(); /* got a good command to get here */
591#endif
592 /*
593 * We use the last specified parameters, unless new ones are
594 * entered.
595 */
596 chip = i2c_mm_last_chip;
597 addr = i2c_mm_last_addr;
598 alen = i2c_mm_last_alen;
599
600 if ((flag & CMD_FLAG_REPEAT) == 0) {
601 /*
602 * New command specified. Check for a size specification.
603 * Defaults to byte if no or incorrect specification.
604 */
605 size = cmd_get_data_size(argv[0], 1);
606
607 /*
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200608 * Chip is always specified.
609 */
wdenk81a88242002-10-26 15:22:42 +0000610 chip = simple_strtoul(argv[1], NULL, 16);
611
612 /*
613 * Address is always specified.
614 */
615 addr = simple_strtoul(argv[2], NULL, 16);
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100616 alen = get_alen(argv[2]);
Reinhard Meyer7a92e532010-08-25 14:41:16 +0200617 if (alen > 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000618 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000619 }
620
621 /*
622 * Print the address, followed by value. Then accept input for
623 * the next value. A non-converted value exits.
624 */
625 do {
626 printf("%08lx:", addr);
Timur Tabie857a5b2006-11-28 12:09:35 -0600627 if (i2c_read(chip, addr, alen, (uchar *)&data, size) != 0)
wdenk4b9206e2004-03-23 22:14:11 +0000628 puts ("\nError reading the chip,\n");
Timur Tabie857a5b2006-11-28 12:09:35 -0600629 else {
wdenk81a88242002-10-26 15:22:42 +0000630 data = cpu_to_be32(data);
Timur Tabie857a5b2006-11-28 12:09:35 -0600631 if (size == 1)
wdenk81a88242002-10-26 15:22:42 +0000632 printf(" %02lx", (data >> 24) & 0x000000FF);
Timur Tabie857a5b2006-11-28 12:09:35 -0600633 else if (size == 2)
wdenk81a88242002-10-26 15:22:42 +0000634 printf(" %04lx", (data >> 16) & 0x0000FFFF);
Timur Tabie857a5b2006-11-28 12:09:35 -0600635 else
wdenk81a88242002-10-26 15:22:42 +0000636 printf(" %08lx", data);
wdenk81a88242002-10-26 15:22:42 +0000637 }
638
639 nbytes = readline (" ? ");
640 if (nbytes == 0) {
641 /*
642 * <CR> pressed as only input, don't modify current
643 * location and move to next.
644 */
645 if (incrflag)
646 addr += size;
647 nbytes = size;
648#ifdef CONFIG_BOOT_RETRY_TIME
649 reset_cmd_timeout(); /* good enough to not time out */
650#endif
651 }
652#ifdef CONFIG_BOOT_RETRY_TIME
Timur Tabie857a5b2006-11-28 12:09:35 -0600653 else if (nbytes == -2)
wdenk81a88242002-10-26 15:22:42 +0000654 break; /* timed out, exit the command */
wdenk81a88242002-10-26 15:22:42 +0000655#endif
656 else {
657 char *endp;
658
659 data = simple_strtoul(console_buffer, &endp, 16);
Timur Tabie857a5b2006-11-28 12:09:35 -0600660 if (size == 1)
wdenk81a88242002-10-26 15:22:42 +0000661 data = data << 24;
Timur Tabie857a5b2006-11-28 12:09:35 -0600662 else if (size == 2)
wdenk81a88242002-10-26 15:22:42 +0000663 data = data << 16;
wdenk81a88242002-10-26 15:22:42 +0000664 data = be32_to_cpu(data);
665 nbytes = endp - console_buffer;
666 if (nbytes) {
667#ifdef CONFIG_BOOT_RETRY_TIME
668 /*
669 * good enough to not time out
670 */
671 reset_cmd_timeout();
672#endif
Timur Tabie857a5b2006-11-28 12:09:35 -0600673 if (i2c_write(chip, addr, alen, (uchar *)&data, size) != 0)
wdenk4b9206e2004-03-23 22:14:11 +0000674 puts ("Error writing the chip.\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200675#ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
676 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
wdenk2535d602003-07-17 23:16:40 +0000677#endif
wdenk81a88242002-10-26 15:22:42 +0000678 if (incrflag)
679 addr += size;
680 }
681 }
682 } while (nbytes);
683
Peter Tyser08007072008-08-15 14:36:32 -0500684 i2c_mm_last_chip = chip;
685 i2c_mm_last_addr = addr;
686 i2c_mm_last_alen = alen;
wdenk81a88242002-10-26 15:22:42 +0000687
688 return 0;
689}
690
Marek Vasut06afa382012-11-12 14:34:27 +0000691/**
692 * do_i2c_probe() - Handle the "i2c probe" command-line command
693 * @cmdtp: Command data struct pointer
694 * @flag: Command flag
695 * @argc: Command-line argument count
696 * @argv: Array of command-line arguments
697 *
698 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
699 * on error.
700 *
wdenk81a88242002-10-26 15:22:42 +0000701 * Syntax:
Eric Nelson54b99e52012-09-23 10:12:56 +0000702 * i2c probe {addr}
703 *
704 * Returns zero (success) if one or more I2C devices was found
wdenk81a88242002-10-26 15:22:42 +0000705 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200706static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000707{
708 int j;
Eric Nelson54b99e52012-09-23 10:12:56 +0000709 int addr = -1;
710 int found = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200711#if defined(CONFIG_SYS_I2C_NOPROBES)
wdenk81a88242002-10-26 15:22:42 +0000712 int k, skip;
Heiko Schocher3f4978c2012-01-16 21:12:24 +0000713 unsigned int bus = GET_BUS_NUM;
Ben Warrenbb99ad62006-09-07 16:50:54 -0400714#endif /* NOPROBES */
wdenk81a88242002-10-26 15:22:42 +0000715
Eric Nelson54b99e52012-09-23 10:12:56 +0000716 if (argc == 2)
717 addr = simple_strtol(argv[1], 0, 16);
718
wdenk4b9206e2004-03-23 22:14:11 +0000719 puts ("Valid chip addresses:");
Timur Tabie857a5b2006-11-28 12:09:35 -0600720 for (j = 0; j < 128; j++) {
Eric Nelson54b99e52012-09-23 10:12:56 +0000721 if ((0 <= addr) && (j != addr))
722 continue;
723
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200724#if defined(CONFIG_SYS_I2C_NOPROBES)
wdenk81a88242002-10-26 15:22:42 +0000725 skip = 0;
Timur Tabie857a5b2006-11-28 12:09:35 -0600726 for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) {
727 if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) {
wdenk81a88242002-10-26 15:22:42 +0000728 skip = 1;
729 break;
730 }
731 }
732 if (skip)
733 continue;
734#endif
Eric Nelson54b99e52012-09-23 10:12:56 +0000735 if (i2c_probe(j) == 0) {
wdenk81a88242002-10-26 15:22:42 +0000736 printf(" %02X", j);
Eric Nelson54b99e52012-09-23 10:12:56 +0000737 found++;
738 }
wdenk81a88242002-10-26 15:22:42 +0000739 }
wdenk4b9206e2004-03-23 22:14:11 +0000740 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000741
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200742#if defined(CONFIG_SYS_I2C_NOPROBES)
wdenk81a88242002-10-26 15:22:42 +0000743 puts ("Excluded chip addresses:");
Timur Tabie857a5b2006-11-28 12:09:35 -0600744 for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) {
745 if (COMPARE_BUS(bus,k))
Ben Warrenbb99ad62006-09-07 16:50:54 -0400746 printf(" %02X", NO_PROBE_ADDR(k));
747 }
wdenk4b9206e2004-03-23 22:14:11 +0000748 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +0000749#endif
750
Eric Nelson54b99e52012-09-23 10:12:56 +0000751 return (0 == found);
wdenk81a88242002-10-26 15:22:42 +0000752}
753
Marek Vasut06afa382012-11-12 14:34:27 +0000754/**
755 * do_i2c_loop() - Handle the "i2c loop" command-line command
756 * @cmdtp: Command data struct pointer
757 * @flag: Command flag
758 * @argc: Command-line argument count
759 * @argv: Array of command-line arguments
760 *
761 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
762 * on error.
763 *
wdenk81a88242002-10-26 15:22:42 +0000764 * Syntax:
Peter Tyser0f89c542009-04-18 22:34:03 -0500765 * i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}]
wdenk81a88242002-10-26 15:22:42 +0000766 * {length} - Number of bytes to read
767 * {delay} - A DECIMAL number and defaults to 1000 uSec
768 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200769static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000770{
771 u_char chip;
772 ulong alen;
773 uint addr;
774 uint length;
775 u_char bytes[16];
776 int delay;
wdenk81a88242002-10-26 15:22:42 +0000777
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200778 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000779 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000780
781 /*
782 * Chip is always specified.
783 */
784 chip = simple_strtoul(argv[1], NULL, 16);
785
786 /*
787 * Address is always specified.
788 */
789 addr = simple_strtoul(argv[2], NULL, 16);
Frans Meulenbroeks2c0dc992010-03-26 09:46:41 +0100790 alen = get_alen(argv[2]);
Reinhard Meyer7a92e532010-08-25 14:41:16 +0200791 if (alen > 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000792 return CMD_RET_USAGE;
wdenk81a88242002-10-26 15:22:42 +0000793
794 /*
795 * Length is the number of objects, not number of bytes.
796 */
797 length = 1;
798 length = simple_strtoul(argv[3], NULL, 16);
Timur Tabie857a5b2006-11-28 12:09:35 -0600799 if (length > sizeof(bytes))
wdenk81a88242002-10-26 15:22:42 +0000800 length = sizeof(bytes);
wdenk81a88242002-10-26 15:22:42 +0000801
802 /*
803 * The delay time (uSec) is optional.
804 */
805 delay = 1000;
Timur Tabie857a5b2006-11-28 12:09:35 -0600806 if (argc > 3)
wdenk81a88242002-10-26 15:22:42 +0000807 delay = simple_strtoul(argv[4], NULL, 10);
wdenk81a88242002-10-26 15:22:42 +0000808 /*
809 * Run the loop...
810 */
Timur Tabie857a5b2006-11-28 12:09:35 -0600811 while (1) {
812 if (i2c_read(chip, addr, alen, bytes, length) != 0)
wdenk4b9206e2004-03-23 22:14:11 +0000813 puts ("Error reading the chip.\n");
wdenk81a88242002-10-26 15:22:42 +0000814 udelay(delay);
815 }
816
817 /* NOTREACHED */
818 return 0;
819}
820
wdenk81a88242002-10-26 15:22:42 +0000821/*
822 * The SDRAM command is separately configured because many
823 * (most?) embedded boards don't use SDRAM DIMMs.
Marek Vasut06afa382012-11-12 14:34:27 +0000824 *
825 * FIXME: Document and probably move elsewhere!
wdenk81a88242002-10-26 15:22:42 +0000826 */
Jon Loeligerc76fe472007-07-08 18:02:23 -0500827#if defined(CONFIG_CMD_SDRAM)
Larry Johnson632de062008-01-11 23:26:18 -0500828static void print_ddr2_tcyc (u_char const b)
829{
830 printf ("%d.", (b >> 4) & 0x0F);
831 switch (b & 0x0F) {
832 case 0x0:
833 case 0x1:
834 case 0x2:
835 case 0x3:
836 case 0x4:
837 case 0x5:
838 case 0x6:
839 case 0x7:
840 case 0x8:
841 case 0x9:
842 printf ("%d ns\n", b & 0x0F);
843 break;
844 case 0xA:
845 puts ("25 ns\n");
846 break;
847 case 0xB:
848 puts ("33 ns\n");
849 break;
850 case 0xC:
851 puts ("66 ns\n");
852 break;
853 case 0xD:
854 puts ("75 ns\n");
855 break;
856 default:
857 puts ("?? ns\n");
858 break;
859 }
860}
861
862static void decode_bits (u_char const b, char const *str[], int const do_once)
863{
864 u_char mask;
865
866 for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) {
867 if (b & mask) {
868 puts (*str);
869 if (do_once)
870 return;
871 }
872 }
873}
wdenk81a88242002-10-26 15:22:42 +0000874
875/*
876 * Syntax:
Peter Tyser0f89c542009-04-18 22:34:03 -0500877 * i2c sdram {i2c_chip}
wdenk81a88242002-10-26 15:22:42 +0000878 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200879static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk81a88242002-10-26 15:22:42 +0000880{
Larry Johnson632de062008-01-11 23:26:18 -0500881 enum { unknown, EDO, SDRAM, DDR2 } type;
882
wdenk81a88242002-10-26 15:22:42 +0000883 u_char chip;
884 u_char data[128];
885 u_char cksum;
886 int j;
887
Larry Johnson632de062008-01-11 23:26:18 -0500888 static const char *decode_CAS_DDR2[] = {
889 " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD"
890 };
891
892 static const char *decode_CAS_default[] = {
893 " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1"
894 };
895
896 static const char *decode_CS_WE_default[] = {
897 " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0"
898 };
899
900 static const char *decode_byte21_default[] = {
901 " TBD (bit 7)\n",
902 " Redundant row address\n",
903 " Differential clock input\n",
904 " Registerd DQMB inputs\n",
905 " Buffered DQMB inputs\n",
906 " On-card PLL\n",
907 " Registered address/control lines\n",
908 " Buffered address/control lines\n"
909 };
910
911 static const char *decode_byte22_DDR2[] = {
912 " TBD (bit 7)\n",
913 " TBD (bit 6)\n",
914 " TBD (bit 5)\n",
915 " TBD (bit 4)\n",
916 " TBD (bit 3)\n",
917 " Supports partial array self refresh\n",
918 " Supports 50 ohm ODT\n",
919 " Supports weak driver\n"
920 };
921
922 static const char *decode_row_density_DDR2[] = {
923 "512 MiB", "256 MiB", "128 MiB", "16 GiB",
924 "8 GiB", "4 GiB", "2 GiB", "1 GiB"
925 };
926
927 static const char *decode_row_density_default[] = {
928 "512 MiB", "256 MiB", "128 MiB", "64 MiB",
929 "32 MiB", "16 MiB", "8 MiB", "4 MiB"
930 };
931
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200932 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000933 return CMD_RET_USAGE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200934
wdenk81a88242002-10-26 15:22:42 +0000935 /*
936 * Chip is always specified.
Larry Johnson632de062008-01-11 23:26:18 -0500937 */
938 chip = simple_strtoul (argv[1], NULL, 16);
wdenk81a88242002-10-26 15:22:42 +0000939
Larry Johnson632de062008-01-11 23:26:18 -0500940 if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) {
wdenk4b9206e2004-03-23 22:14:11 +0000941 puts ("No SDRAM Serial Presence Detect found.\n");
wdenk81a88242002-10-26 15:22:42 +0000942 return 1;
943 }
944
945 cksum = 0;
946 for (j = 0; j < 63; j++) {
947 cksum += data[j];
948 }
Timur Tabie857a5b2006-11-28 12:09:35 -0600949 if (cksum != data[63]) {
wdenk81a88242002-10-26 15:22:42 +0000950 printf ("WARNING: Configuration data checksum failure:\n"
Larry Johnson632de062008-01-11 23:26:18 -0500951 " is 0x%02x, calculated 0x%02x\n", data[63], cksum);
wdenk81a88242002-10-26 15:22:42 +0000952 }
Larry Johnson632de062008-01-11 23:26:18 -0500953 printf ("SPD data revision %d.%d\n",
wdenk81a88242002-10-26 15:22:42 +0000954 (data[62] >> 4) & 0x0F, data[62] & 0x0F);
Larry Johnson632de062008-01-11 23:26:18 -0500955 printf ("Bytes used 0x%02X\n", data[0]);
956 printf ("Serial memory size 0x%02X\n", 1 << data[1]);
957
wdenk4b9206e2004-03-23 22:14:11 +0000958 puts ("Memory type ");
Larry Johnson632de062008-01-11 23:26:18 -0500959 switch (data[2]) {
Larry Johnson0df6b842008-01-10 22:23:39 -0500960 case 2:
961 type = EDO;
962 puts ("EDO\n");
963 break;
964 case 4:
965 type = SDRAM;
966 puts ("SDRAM\n");
967 break;
968 case 8:
969 type = DDR2;
970 puts ("DDR2\n");
971 break;
972 default:
973 type = unknown;
974 puts ("unknown\n");
975 break;
wdenk81a88242002-10-26 15:22:42 +0000976 }
Larry Johnson632de062008-01-11 23:26:18 -0500977
wdenk4b9206e2004-03-23 22:14:11 +0000978 puts ("Row address bits ");
Timur Tabie857a5b2006-11-28 12:09:35 -0600979 if ((data[3] & 0x00F0) == 0)
Larry Johnson632de062008-01-11 23:26:18 -0500980 printf ("%d\n", data[3] & 0x0F);
Timur Tabie857a5b2006-11-28 12:09:35 -0600981 else
Larry Johnson632de062008-01-11 23:26:18 -0500982 printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F);
983
wdenk4b9206e2004-03-23 22:14:11 +0000984 puts ("Column address bits ");
Timur Tabie857a5b2006-11-28 12:09:35 -0600985 if ((data[4] & 0x00F0) == 0)
Larry Johnson632de062008-01-11 23:26:18 -0500986 printf ("%d\n", data[4] & 0x0F);
Timur Tabie857a5b2006-11-28 12:09:35 -0600987 else
Larry Johnson632de062008-01-11 23:26:18 -0500988 printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -0500989
990 switch (type) {
991 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -0500992 printf ("Number of ranks %d\n",
993 (data[5] & 0x07) + 1);
Larry Johnson0df6b842008-01-10 22:23:39 -0500994 break;
995 default:
Larry Johnson632de062008-01-11 23:26:18 -0500996 printf ("Module rows %d\n", data[5]);
Larry Johnson0df6b842008-01-10 22:23:39 -0500997 break;
998 }
999
1000 switch (type) {
1001 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001002 printf ("Module data width %d bits\n", data[6]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001003 break;
1004 default:
Larry Johnson632de062008-01-11 23:26:18 -05001005 printf ("Module data width %d bits\n",
1006 (data[7] << 8) | data[6]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001007 break;
1008 }
1009
wdenk4b9206e2004-03-23 22:14:11 +00001010 puts ("Interface signal levels ");
wdenk81a88242002-10-26 15:22:42 +00001011 switch(data[8]) {
Larry Johnson0df6b842008-01-10 22:23:39 -05001012 case 0: puts ("TTL 5.0 V\n"); break;
wdenk4b9206e2004-03-23 22:14:11 +00001013 case 1: puts ("LVTTL\n"); break;
Larry Johnson0df6b842008-01-10 22:23:39 -05001014 case 2: puts ("HSTL 1.5 V\n"); break;
1015 case 3: puts ("SSTL 3.3 V\n"); break;
1016 case 4: puts ("SSTL 2.5 V\n"); break;
1017 case 5: puts ("SSTL 1.8 V\n"); break;
wdenk4b9206e2004-03-23 22:14:11 +00001018 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +00001019 }
Larry Johnson0df6b842008-01-10 22:23:39 -05001020
1021 switch (type) {
1022 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001023 printf ("SDRAM cycle time ");
1024 print_ddr2_tcyc (data[9]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001025 break;
1026 default:
Larry Johnson632de062008-01-11 23:26:18 -05001027 printf ("SDRAM cycle time %d.%d ns\n",
1028 (data[9] >> 4) & 0x0F, data[9] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001029 break;
1030 }
1031
1032 switch (type) {
1033 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001034 printf ("SDRAM access time 0.%d%d ns\n",
1035 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001036 break;
1037 default:
Larry Johnson632de062008-01-11 23:26:18 -05001038 printf ("SDRAM access time %d.%d ns\n",
1039 (data[10] >> 4) & 0x0F, data[10] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001040 break;
1041 }
1042
wdenk4b9206e2004-03-23 22:14:11 +00001043 puts ("EDC configuration ");
Larry Johnson632de062008-01-11 23:26:18 -05001044 switch (data[11]) {
wdenk4b9206e2004-03-23 22:14:11 +00001045 case 0: puts ("None\n"); break;
1046 case 1: puts ("Parity\n"); break;
1047 case 2: puts ("ECC\n"); break;
1048 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +00001049 }
Larry Johnson632de062008-01-11 23:26:18 -05001050
Timur Tabie857a5b2006-11-28 12:09:35 -06001051 if ((data[12] & 0x80) == 0)
wdenk4b9206e2004-03-23 22:14:11 +00001052 puts ("No self refresh, rate ");
Timur Tabie857a5b2006-11-28 12:09:35 -06001053 else
wdenk4b9206e2004-03-23 22:14:11 +00001054 puts ("Self refresh, rate ");
Larry Johnson632de062008-01-11 23:26:18 -05001055
wdenk81a88242002-10-26 15:22:42 +00001056 switch(data[12] & 0x7F) {
Larry Johnson632de062008-01-11 23:26:18 -05001057 case 0: puts ("15.625 us\n"); break;
1058 case 1: puts ("3.9 us\n"); break;
1059 case 2: puts ("7.8 us\n"); break;
1060 case 3: puts ("31.3 us\n"); break;
1061 case 4: puts ("62.5 us\n"); break;
1062 case 5: puts ("125 us\n"); break;
wdenk4b9206e2004-03-23 22:14:11 +00001063 default: puts ("unknown\n"); break;
wdenk81a88242002-10-26 15:22:42 +00001064 }
Larry Johnson0df6b842008-01-10 22:23:39 -05001065
1066 switch (type) {
1067 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001068 printf ("SDRAM width (primary) %d\n", data[13]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001069 break;
1070 default:
Larry Johnson632de062008-01-11 23:26:18 -05001071 printf ("SDRAM width (primary) %d\n", data[13] & 0x7F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001072 if ((data[13] & 0x80) != 0) {
Larry Johnson632de062008-01-11 23:26:18 -05001073 printf (" (second bank) %d\n",
1074 2 * (data[13] & 0x7F));
Larry Johnson0df6b842008-01-10 22:23:39 -05001075 }
1076 break;
wdenk81a88242002-10-26 15:22:42 +00001077 }
Larry Johnson0df6b842008-01-10 22:23:39 -05001078
1079 switch (type) {
1080 case DDR2:
1081 if (data[14] != 0)
Larry Johnson632de062008-01-11 23:26:18 -05001082 printf ("EDC width %d\n", data[14]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001083 break;
1084 default:
1085 if (data[14] != 0) {
Larry Johnson632de062008-01-11 23:26:18 -05001086 printf ("EDC width %d\n",
1087 data[14] & 0x7F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001088
1089 if ((data[14] & 0x80) != 0) {
Larry Johnson632de062008-01-11 23:26:18 -05001090 printf (" (second bank) %d\n",
1091 2 * (data[14] & 0x7F));
Larry Johnson0df6b842008-01-10 22:23:39 -05001092 }
1093 }
1094 break;
1095 }
1096
Larry Johnson632de062008-01-11 23:26:18 -05001097 if (DDR2 != type) {
1098 printf ("Min clock delay, back-to-back random column addresses "
1099 "%d\n", data[15]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001100 }
1101
wdenk4b9206e2004-03-23 22:14:11 +00001102 puts ("Burst length(s) ");
1103 if (data[16] & 0x80) puts (" Page");
1104 if (data[16] & 0x08) puts (" 8");
1105 if (data[16] & 0x04) puts (" 4");
1106 if (data[16] & 0x02) puts (" 2");
1107 if (data[16] & 0x01) puts (" 1");
1108 putc ('\n');
Larry Johnson632de062008-01-11 23:26:18 -05001109 printf ("Number of banks %d\n", data[17]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001110
1111 switch (type) {
1112 case DDR2:
1113 puts ("CAS latency(s) ");
Larry Johnson632de062008-01-11 23:26:18 -05001114 decode_bits (data[18], decode_CAS_DDR2, 0);
Larry Johnson0df6b842008-01-10 22:23:39 -05001115 putc ('\n');
1116 break;
1117 default:
1118 puts ("CAS latency(s) ");
Larry Johnson632de062008-01-11 23:26:18 -05001119 decode_bits (data[18], decode_CAS_default, 0);
Larry Johnson0df6b842008-01-10 22:23:39 -05001120 putc ('\n');
1121 break;
1122 }
1123
1124 if (DDR2 != type) {
1125 puts ("CS latency(s) ");
Larry Johnson632de062008-01-11 23:26:18 -05001126 decode_bits (data[19], decode_CS_WE_default, 0);
Larry Johnson0df6b842008-01-10 22:23:39 -05001127 putc ('\n');
1128 }
1129
1130 if (DDR2 != type) {
1131 puts ("WE latency(s) ");
Larry Johnson632de062008-01-11 23:26:18 -05001132 decode_bits (data[20], decode_CS_WE_default, 0);
Larry Johnson0df6b842008-01-10 22:23:39 -05001133 putc ('\n');
1134 }
1135
1136 switch (type) {
1137 case DDR2:
1138 puts ("Module attributes:\n");
1139 if (data[21] & 0x80)
1140 puts (" TBD (bit 7)\n");
1141 if (data[21] & 0x40)
1142 puts (" Analysis probe installed\n");
1143 if (data[21] & 0x20)
1144 puts (" TBD (bit 5)\n");
1145 if (data[21] & 0x10)
1146 puts (" FET switch external enable\n");
Larry Johnson632de062008-01-11 23:26:18 -05001147 printf (" %d PLLs on DIMM\n", (data[21] >> 2) & 0x03);
Larry Johnson0df6b842008-01-10 22:23:39 -05001148 if (data[20] & 0x11) {
Larry Johnson632de062008-01-11 23:26:18 -05001149 printf (" %d active registers on DIMM\n",
1150 (data[21] & 0x03) + 1);
Larry Johnson0df6b842008-01-10 22:23:39 -05001151 }
1152 break;
1153 default:
1154 puts ("Module attributes:\n");
1155 if (!data[21])
1156 puts (" (none)\n");
Larry Johnson632de062008-01-11 23:26:18 -05001157 else
1158 decode_bits (data[21], decode_byte21_default, 0);
Larry Johnson0df6b842008-01-10 22:23:39 -05001159 break;
1160 }
1161
1162 switch (type) {
1163 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001164 decode_bits (data[22], decode_byte22_DDR2, 0);
Larry Johnson0df6b842008-01-10 22:23:39 -05001165 break;
1166 default:
1167 puts ("Device attributes:\n");
1168 if (data[22] & 0x80) puts (" TBD (bit 7)\n");
1169 if (data[22] & 0x40) puts (" TBD (bit 6)\n");
1170 if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n");
1171 else puts (" Upper Vcc tolerance 10%\n");
1172 if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n");
1173 else puts (" Lower Vcc tolerance 10%\n");
1174 if (data[22] & 0x08) puts (" Supports write1/read burst\n");
1175 if (data[22] & 0x04) puts (" Supports precharge all\n");
1176 if (data[22] & 0x02) puts (" Supports auto precharge\n");
1177 if (data[22] & 0x01) puts (" Supports early RAS# precharge\n");
1178 break;
1179 }
1180
1181 switch (type) {
1182 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001183 printf ("SDRAM cycle time (2nd highest CAS latency) ");
1184 print_ddr2_tcyc (data[23]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001185 break;
1186 default:
Larry Johnson632de062008-01-11 23:26:18 -05001187 printf ("SDRAM cycle time (2nd highest CAS latency) %d."
1188 "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001189 break;
1190 }
1191
1192 switch (type) {
1193 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001194 printf ("SDRAM access from clock (2nd highest CAS latency) 0."
1195 "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001196 break;
1197 default:
Larry Johnson632de062008-01-11 23:26:18 -05001198 printf ("SDRAM access from clock (2nd highest CAS latency) %d."
1199 "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001200 break;
1201 }
1202
1203 switch (type) {
1204 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001205 printf ("SDRAM cycle time (3rd highest CAS latency) ");
1206 print_ddr2_tcyc (data[25]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001207 break;
1208 default:
Larry Johnson632de062008-01-11 23:26:18 -05001209 printf ("SDRAM cycle time (3rd highest CAS latency) %d."
1210 "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001211 break;
1212 }
1213
1214 switch (type) {
1215 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001216 printf ("SDRAM access from clock (3rd highest CAS latency) 0."
1217 "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001218 break;
1219 default:
Larry Johnson632de062008-01-11 23:26:18 -05001220 printf ("SDRAM access from clock (3rd highest CAS latency) %d."
1221 "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001222 break;
1223 }
1224
1225 switch (type) {
1226 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001227 printf ("Minimum row precharge %d.%02d ns\n",
1228 (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03));
Larry Johnson0df6b842008-01-10 22:23:39 -05001229 break;
1230 default:
Larry Johnson632de062008-01-11 23:26:18 -05001231 printf ("Minimum row precharge %d ns\n", data[27]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001232 break;
1233 }
1234
1235 switch (type) {
1236 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001237 printf ("Row active to row active min %d.%02d ns\n",
1238 (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03));
Larry Johnson0df6b842008-01-10 22:23:39 -05001239 break;
1240 default:
Larry Johnson632de062008-01-11 23:26:18 -05001241 printf ("Row active to row active min %d ns\n", data[28]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001242 break;
1243 }
1244
1245 switch (type) {
1246 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001247 printf ("RAS to CAS delay min %d.%02d ns\n",
1248 (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03));
Larry Johnson0df6b842008-01-10 22:23:39 -05001249 break;
1250 default:
Larry Johnson632de062008-01-11 23:26:18 -05001251 printf ("RAS to CAS delay min %d ns\n", data[29]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001252 break;
1253 }
1254
Larry Johnson632de062008-01-11 23:26:18 -05001255 printf ("Minimum RAS pulse width %d ns\n", data[30]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001256
1257 switch (type) {
1258 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001259 puts ("Density of each row ");
1260 decode_bits (data[31], decode_row_density_DDR2, 1);
1261 putc ('\n');
Larry Johnson0df6b842008-01-10 22:23:39 -05001262 break;
1263 default:
Larry Johnson632de062008-01-11 23:26:18 -05001264 puts ("Density of each row ");
1265 decode_bits (data[31], decode_row_density_default, 1);
1266 putc ('\n');
Larry Johnson0df6b842008-01-10 22:23:39 -05001267 break;
1268 }
1269
1270 switch (type) {
1271 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001272 puts ("Command and Address setup ");
Larry Johnson0df6b842008-01-10 22:23:39 -05001273 if (data[32] >= 0xA0) {
Larry Johnson632de062008-01-11 23:26:18 -05001274 printf ("1.%d%d ns\n",
1275 ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001276 } else {
Larry Johnson632de062008-01-11 23:26:18 -05001277 printf ("0.%d%d ns\n",
1278 ((data[32] >> 4) & 0x0F), data[32] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001279 }
1280 break;
1281 default:
Larry Johnson632de062008-01-11 23:26:18 -05001282 printf ("Command and Address setup %c%d.%d ns\n",
1283 (data[32] & 0x80) ? '-' : '+',
1284 (data[32] >> 4) & 0x07, data[32] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001285 break;
1286 }
1287
1288 switch (type) {
1289 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001290 puts ("Command and Address hold ");
Larry Johnson0df6b842008-01-10 22:23:39 -05001291 if (data[33] >= 0xA0) {
Larry Johnson632de062008-01-11 23:26:18 -05001292 printf ("1.%d%d ns\n",
1293 ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001294 } else {
Larry Johnson632de062008-01-11 23:26:18 -05001295 printf ("0.%d%d ns\n",
1296 ((data[33] >> 4) & 0x0F), data[33] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001297 }
1298 break;
1299 default:
Larry Johnson632de062008-01-11 23:26:18 -05001300 printf ("Command and Address hold %c%d.%d ns\n",
1301 (data[33] & 0x80) ? '-' : '+',
1302 (data[33] >> 4) & 0x07, data[33] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001303 break;
1304 }
1305
1306 switch (type) {
1307 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001308 printf ("Data signal input setup 0.%d%d ns\n",
1309 (data[34] >> 4) & 0x0F, data[34] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001310 break;
1311 default:
Larry Johnson632de062008-01-11 23:26:18 -05001312 printf ("Data signal input setup %c%d.%d ns\n",
1313 (data[34] & 0x80) ? '-' : '+',
1314 (data[34] >> 4) & 0x07, data[34] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001315 break;
1316 }
1317
1318 switch (type) {
1319 case DDR2:
Larry Johnson632de062008-01-11 23:26:18 -05001320 printf ("Data signal input hold 0.%d%d ns\n",
1321 (data[35] >> 4) & 0x0F, data[35] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001322 break;
1323 default:
Larry Johnson632de062008-01-11 23:26:18 -05001324 printf ("Data signal input hold %c%d.%d ns\n",
1325 (data[35] & 0x80) ? '-' : '+',
1326 (data[35] >> 4) & 0x07, data[35] & 0x0F);
Larry Johnson0df6b842008-01-10 22:23:39 -05001327 break;
1328 }
1329
wdenk4b9206e2004-03-23 22:14:11 +00001330 puts ("Manufacturer's JEDEC ID ");
Timur Tabie857a5b2006-11-28 12:09:35 -06001331 for (j = 64; j <= 71; j++)
Larry Johnson632de062008-01-11 23:26:18 -05001332 printf ("%02X ", data[j]);
wdenk4b9206e2004-03-23 22:14:11 +00001333 putc ('\n');
Larry Johnson632de062008-01-11 23:26:18 -05001334 printf ("Manufacturing Location %02X\n", data[72]);
wdenk4b9206e2004-03-23 22:14:11 +00001335 puts ("Manufacturer's Part Number ");
Timur Tabie857a5b2006-11-28 12:09:35 -06001336 for (j = 73; j <= 90; j++)
Larry Johnson632de062008-01-11 23:26:18 -05001337 printf ("%02X ", data[j]);
wdenk4b9206e2004-03-23 22:14:11 +00001338 putc ('\n');
Larry Johnson632de062008-01-11 23:26:18 -05001339 printf ("Revision Code %02X %02X\n", data[91], data[92]);
1340 printf ("Manufacturing Date %02X %02X\n", data[93], data[94]);
wdenk4b9206e2004-03-23 22:14:11 +00001341 puts ("Assembly Serial Number ");
Timur Tabie857a5b2006-11-28 12:09:35 -06001342 for (j = 95; j <= 98; j++)
Larry Johnson632de062008-01-11 23:26:18 -05001343 printf ("%02X ", data[j]);
wdenk4b9206e2004-03-23 22:14:11 +00001344 putc ('\n');
wdenk81a88242002-10-26 15:22:42 +00001345
Larry Johnson0df6b842008-01-10 22:23:39 -05001346 if (DDR2 != type) {
Larry Johnson632de062008-01-11 23:26:18 -05001347 printf ("Speed rating PC%d\n",
1348 data[126] == 0x66 ? 66 : data[126]);
Larry Johnson0df6b842008-01-10 22:23:39 -05001349 }
wdenk81a88242002-10-26 15:22:42 +00001350 return 0;
1351}
Jon Loeliger90253172007-07-10 11:02:44 -05001352#endif
wdenk81a88242002-10-26 15:22:42 +00001353
Tom Wai-Hong Tam735987c2012-12-05 14:46:40 +00001354/*
1355 * Syntax:
1356 * i2c edid {i2c_chip}
1357 */
1358#if defined(CONFIG_I2C_EDID)
1359int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
1360{
1361 u_char chip;
1362 struct edid1_info edid;
1363
1364 if (argc < 2) {
1365 cmd_usage(cmdtp);
1366 return 1;
1367 }
1368
1369 chip = simple_strtoul(argv[1], NULL, 16);
1370 if (i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid)) != 0) {
1371 puts("Error reading EDID content.\n");
1372 return 1;
1373 }
1374
1375 if (edid_check_info(&edid)) {
1376 puts("Content isn't valid EDID.\n");
1377 return 1;
1378 }
1379
1380 edid_print_info(&edid);
1381 return 0;
1382
1383}
1384#endif /* CONFIG_I2C_EDID */
1385
Marek Vasut06afa382012-11-12 14:34:27 +00001386/**
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001387 * do_i2c_show_bus() - Handle the "i2c bus" command-line command
Marek Vasut06afa382012-11-12 14:34:27 +00001388 * @cmdtp: Command data struct pointer
1389 * @flag: Command flag
1390 * @argc: Command-line argument count
1391 * @argv: Array of command-line arguments
1392 *
1393 * Returns zero always.
1394 */
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001395#if defined(CONFIG_SYS_I2C)
1396int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher67b23a32008-10-15 09:39:47 +02001397{
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001398 int i;
1399#ifndef CONFIG_SYS_I2C_DIRECT_BUS
1400 int j;
1401#endif
Heiko Schocher67b23a32008-10-15 09:39:47 +02001402
1403 if (argc == 1) {
1404 /* show all busses */
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001405 for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
1406 printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
1407#ifndef CONFIG_SYS_I2C_DIRECT_BUS
1408 for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
1409 if (i2c_bus[i].next_hop[j].chip == 0)
1410 break;
1411 printf("->%s@0x%2x:%d",
1412 i2c_bus[i].next_hop[j].mux.name,
1413 i2c_bus[i].next_hop[j].chip,
1414 i2c_bus[i].next_hop[j].channel);
Heiko Schocher67b23a32008-10-15 09:39:47 +02001415 }
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001416#endif
1417 printf("\n");
Heiko Schocher67b23a32008-10-15 09:39:47 +02001418 }
1419 } else {
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001420 /* show specific bus */
1421 i = simple_strtoul(argv[1], NULL, 10);
1422 if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
1423 printf("Invalid bus %d\n", i);
1424 return -1;
1425 }
1426 printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
1427#ifndef CONFIG_SYS_I2C_DIRECT_BUS
1428 for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
1429 if (i2c_bus[i].next_hop[j].chip == 0)
1430 break;
1431 printf("->%s@0x%2x:%d",
1432 i2c_bus[i].next_hop[j].mux.name,
1433 i2c_bus[i].next_hop[j].chip,
1434 i2c_bus[i].next_hop[j].channel);
1435 }
1436#endif
1437 printf("\n");
Heiko Schocher67b23a32008-10-15 09:39:47 +02001438 }
Heiko Schocher67b23a32008-10-15 09:39:47 +02001439
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001440 return 0;
1441}
1442#endif
1443
Marek Vasut06afa382012-11-12 14:34:27 +00001444/**
1445 * do_i2c_bus_num() - Handle the "i2c dev" command-line command
1446 * @cmdtp: Command data struct pointer
1447 * @flag: Command flag
1448 * @argc: Command-line argument count
1449 * @argv: Array of command-line arguments
1450 *
1451 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1452 * on error.
1453 */
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001454#if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS)
1455int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Ben Warrenbb99ad62006-09-07 16:50:54 -04001456{
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001457 int ret = 0;
1458 unsigned int bus_no;
Ben Warrenbb99ad62006-09-07 16:50:54 -04001459
Timur Tabie857a5b2006-11-28 12:09:35 -06001460 if (argc == 1)
1461 /* querying current setting */
Ben Warrenbb99ad62006-09-07 16:50:54 -04001462 printf("Current bus is %d\n", i2c_get_bus_num());
Timur Tabie857a5b2006-11-28 12:09:35 -06001463 else {
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001464 bus_no = simple_strtoul(argv[1], NULL, 10);
1465 if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) {
1466 printf("Invalid bus %d\n", bus_no);
1467 return -1;
1468 }
1469 printf("Setting bus to %d\n", bus_no);
1470 ret = i2c_set_bus_num(bus_no);
Timur Tabie857a5b2006-11-28 12:09:35 -06001471 if (ret)
Ben Warrenbb99ad62006-09-07 16:50:54 -04001472 printf("Failure changing bus number (%d)\n", ret);
Ben Warrenbb99ad62006-09-07 16:50:54 -04001473 }
1474 return ret;
1475}
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001476#endif /* defined(CONFIG_SYS_I2C) */
Ben Warrenbb99ad62006-09-07 16:50:54 -04001477
Marek Vasut06afa382012-11-12 14:34:27 +00001478/**
1479 * do_i2c_bus_speed() - Handle the "i2c speed" command-line command
1480 * @cmdtp: Command data struct pointer
1481 * @flag: Command flag
1482 * @argc: Command-line argument count
1483 * @argv: Array of command-line arguments
1484 *
1485 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1486 * on error.
1487 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001488static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Ben Warrenbb99ad62006-09-07 16:50:54 -04001489{
1490 int speed, ret=0;
1491
Timur Tabie857a5b2006-11-28 12:09:35 -06001492 if (argc == 1)
1493 /* querying current speed */
Ben Warrenbb99ad62006-09-07 16:50:54 -04001494 printf("Current bus speed=%d\n", i2c_get_bus_speed());
Timur Tabie857a5b2006-11-28 12:09:35 -06001495 else {
Ben Warrenbb99ad62006-09-07 16:50:54 -04001496 speed = simple_strtoul(argv[1], NULL, 10);
1497 printf("Setting bus speed to %d Hz\n", speed);
1498 ret = i2c_set_bus_speed(speed);
Timur Tabie857a5b2006-11-28 12:09:35 -06001499 if (ret)
Ben Warrenbb99ad62006-09-07 16:50:54 -04001500 printf("Failure changing bus speed (%d)\n", ret);
Ben Warrenbb99ad62006-09-07 16:50:54 -04001501 }
1502 return ret;
1503}
1504
Marek Vasut06afa382012-11-12 14:34:27 +00001505/**
1506 * do_i2c_mm() - Handle the "i2c mm" command-line command
1507 * @cmdtp: Command data struct pointer
1508 * @flag: Command flag
1509 * @argc: Command-line argument count
1510 * @argv: Array of command-line arguments
1511 *
1512 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1513 * on error.
1514 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001515static int do_i2c_mm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001516{
1517 return mod_i2c_mem (cmdtp, 1, flag, argc, argv);
1518}
1519
Marek Vasut06afa382012-11-12 14:34:27 +00001520/**
1521 * do_i2c_nm() - Handle the "i2c nm" command-line command
1522 * @cmdtp: Command data struct pointer
1523 * @flag: Command flag
1524 * @argc: Command-line argument count
1525 * @argv: Array of command-line arguments
1526 *
1527 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1528 * on error.
1529 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001530static int do_i2c_nm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001531{
1532 return mod_i2c_mem (cmdtp, 0, flag, argc, argv);
1533}
1534
Marek Vasut06afa382012-11-12 14:34:27 +00001535/**
1536 * do_i2c_reset() - Handle the "i2c reset" command-line command
1537 * @cmdtp: Command data struct pointer
1538 * @flag: Command flag
1539 * @argc: Command-line argument count
1540 * @argv: Array of command-line arguments
1541 *
1542 * Returns zero always.
1543 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001544static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001545{
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001546#if defined(CONFIG_SYS_I2C)
1547 i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr);
1548#else
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001549 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001550#endif
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001551 return 0;
1552}
1553
1554static cmd_tbl_t cmd_i2c_sub[] = {
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001555#if defined(CONFIG_SYS_I2C)
1556 U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001557#endif /* CONFIG_I2C_MUX */
1558 U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001559#if defined(CONFIG_SYS_I2C) || \
1560 defined(CONFIG_I2C_MULTI_BUS)
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001561 U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),
1562#endif /* CONFIG_I2C_MULTI_BUS */
Tom Wai-Hong Tam735987c2012-12-05 14:46:40 +00001563#if defined(CONFIG_I2C_EDID)
1564 U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""),
1565#endif /* CONFIG_I2C_EDID */
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001566 U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""),
1567 U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""),
1568 U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
1569 U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""),
1570 U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""),
1571 U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""),
Frans Meulenbroeks652e5352010-02-25 10:12:16 +01001572 U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""),
York Sunff5d2dc2012-09-16 08:02:30 +00001573 U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", ""),
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001574 U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
1575#if defined(CONFIG_CMD_SDRAM)
1576 U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""),
1577#endif
1578 U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
1579};
1580
Wolfgang Denk2e5167c2010-10-28 20:00:11 +02001581#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocherf1d2b312010-09-17 13:10:39 +02001582void i2c_reloc(void) {
1583 fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
1584}
1585#endif
1586
Marek Vasut06afa382012-11-12 14:34:27 +00001587/**
1588 * do_i2c() - Handle the "i2c" command-line command
1589 * @cmdtp: Command data struct pointer
1590 * @flag: Command flag
1591 * @argc: Command-line argument count
1592 * @argv: Array of command-line arguments
1593 *
1594 * Returns zero on success, CMD_RET_USAGE in case of misuse and negative
1595 * on error.
1596 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001597static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Ben Warrenbb99ad62006-09-07 16:50:54 -04001598{
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001599 cmd_tbl_t *c;
1600
Heiko Schocher4444b222010-09-17 13:10:35 +02001601 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001602 return CMD_RET_USAGE;
Heiko Schocher4444b222010-09-17 13:10:35 +02001603
Peter Tysere96ad5d2009-04-18 22:34:04 -05001604 /* Strip off leading 'i2c' command argument */
1605 argc--;
1606 argv++;
1607
Frans Meulenbroeksbfc3b772010-02-25 10:12:14 +01001608 c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub));
1609
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001610 if (c)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001611 return c->cmd(cmdtp, flag, argc, argv);
Wolfgang Denk47e26b12010-07-17 01:06:04 +02001612 else
Simon Glass4c12eeb2011-12-10 08:44:01 +00001613 return CMD_RET_USAGE;
Ben Warrenbb99ad62006-09-07 16:50:54 -04001614}
wdenk8bde7f72003-06-27 21:31:46 +00001615
1616/***************************************************/
Kim Phillips088f1b12012-10-29 13:34:31 +00001617#ifdef CONFIG_SYS_LONGHELP
1618static char i2c_help_text[] =
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001619#if defined(CONFIG_SYS_I2C)
1620 "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
Peter Tyser9166b772009-04-18 22:34:06 -05001621#endif /* CONFIG_I2C_MUX */
Frans Meulenbroeksfb0070e2010-02-25 10:12:15 +01001622 "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
Heiko Schocher3f4978c2012-01-16 21:12:24 +00001623#if defined(CONFIG_SYS_I2C) || \
1624 defined(CONFIG_I2C_MULTI_BUS)
Peter Tyser9bc2e4e2008-10-01 12:25:04 -05001625 "i2c dev [dev] - show or set current I2C bus\n"
Matthias Fuchsd9fc7032007-03-08 16:25:47 +01001626#endif /* CONFIG_I2C_MULTI_BUS */
Tom Wai-Hong Tam735987c2012-12-05 14:46:40 +00001627#if defined(CONFIG_I2C_EDID)
1628 "i2c edid chip - print EDID configuration information\n"
1629#endif /* CONFIG_I2C_EDID */
Frans Meulenbroeksfb0070e2010-02-25 10:12:15 +01001630 "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n"
Matthias Fuchsd9fc7032007-03-08 16:25:47 +01001631 "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
1632 "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
1633 "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
1634 "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n"
Eric Nelson54b99e52012-09-23 10:12:56 +00001635 "i2c probe [address] - test for and show device(s) on the I2C bus\n"
Frans Meulenbroeks652e5352010-02-25 10:12:16 +01001636 "i2c read chip address[.0, .1, .2] length memaddress - read to memory \n"
York Sunff5d2dc2012-09-16 08:02:30 +00001637 "i2c write memaddress chip address[.0, .1, .2] length - write memory to i2c\n"
Heiko Schochere43a27c2008-10-15 09:33:30 +02001638 "i2c reset - re-init the I2C Controller\n"
Jon Loeligerc76fe472007-07-08 18:02:23 -05001639#if defined(CONFIG_CMD_SDRAM)
Frans Meulenbroeksfb0070e2010-02-25 10:12:15 +01001640 "i2c sdram chip - print SDRAM configuration information\n"
Jon Loeliger90253172007-07-10 11:02:44 -05001641#endif
Kim Phillips088f1b12012-10-29 13:34:31 +00001642 "i2c speed [speed] - show or set I2C bus speed";
1643#endif
1644
1645U_BOOT_CMD(
1646 i2c, 6, 1, do_i2c,
1647 "I2C sub-system",
1648 i2c_help_text
Matthias Fuchsd9fc7032007-03-08 16:25:47 +01001649);
Heiko Schocher67b23a32008-10-15 09:39:47 +02001650
1651#if defined(CONFIG_I2C_MUX)
Frans Meulenbroeksfd03ea82010-03-26 09:46:42 +01001652static int i2c_mux_add_device(I2C_MUX_DEVICE *dev)
Heiko Schocher67b23a32008-10-15 09:39:47 +02001653{
1654 I2C_MUX_DEVICE *devtmp = i2c_mux_devices;
1655
1656 if (i2c_mux_devices == NULL) {
1657 i2c_mux_devices = dev;
1658 return 0;
1659 }
1660 while (devtmp->next != NULL)
1661 devtmp = devtmp->next;
1662
1663 devtmp->next = dev;
1664 return 0;
1665}
1666
1667I2C_MUX_DEVICE *i2c_mux_search_device(int id)
1668{
1669 I2C_MUX_DEVICE *device = i2c_mux_devices;
1670
1671 while (device != NULL) {
1672 if (device->busid == id)
1673 return device;
1674 device = device->next;
1675 }
1676 return NULL;
1677}
1678
1679/* searches in the buf from *pos the next ':'.
1680 * returns:
1681 * 0 if found (with *pos = where)
1682 * < 0 if an error occured
1683 * > 0 if the end of buf is reached
1684 */
1685static int i2c_mux_search_next (int *pos, uchar *buf, int len)
1686{
1687 while ((buf[*pos] != ':') && (*pos < len)) {
1688 *pos += 1;
1689 }
1690 if (*pos >= len)
1691 return 1;
1692 if (buf[*pos] != ':')
1693 return -1;
1694 return 0;
1695}
1696
1697static int i2c_mux_get_busid (void)
1698{
1699 int tmp = i2c_mux_busid;
1700
1701 i2c_mux_busid ++;
1702 return tmp;
1703}
1704
Michael Jonesf9a78b82011-07-14 22:09:28 +00001705/* Analyses a Muxstring and immediately sends the
1706 commands to the muxes. Runs from flash.
Heiko Schocher67b23a32008-10-15 09:39:47 +02001707 */
1708int i2c_mux_ident_muxstring_f (uchar *buf)
1709{
1710 int pos = 0;
1711 int oldpos;
1712 int ret = 0;
1713 int len = strlen((char *)buf);
1714 int chip;
1715 uchar channel;
1716 int was = 0;
1717
1718 while (ret == 0) {
1719 oldpos = pos;
1720 /* search name */
1721 ret = i2c_mux_search_next(&pos, buf, len);
1722 if (ret != 0)
1723 printf ("ERROR\n");
1724 /* search address */
1725 pos ++;
1726 oldpos = pos;
1727 ret = i2c_mux_search_next(&pos, buf, len);
1728 if (ret != 0)
1729 printf ("ERROR\n");
1730 buf[pos] = 0;
1731 chip = simple_strtoul((char *)&buf[oldpos], NULL, 16);
1732 buf[pos] = ':';
1733 /* search channel */
1734 pos ++;
1735 oldpos = pos;
1736 ret = i2c_mux_search_next(&pos, buf, len);
1737 if (ret < 0)
1738 printf ("ERROR\n");
1739 was = 0;
1740 if (buf[pos] != 0) {
1741 buf[pos] = 0;
1742 was = 1;
1743 }
1744 channel = simple_strtoul((char *)&buf[oldpos], NULL, 16);
1745 if (was)
1746 buf[pos] = ':';
1747 if (i2c_write(chip, 0, 0, &channel, 1) != 0) {
1748 printf ("Error setting Mux: chip:%x channel: \
1749 %x\n", chip, channel);
1750 return -1;
1751 }
1752 pos ++;
1753 oldpos = pos;
1754
1755 }
Holger Brunck8ec038a2012-06-28 04:30:22 +00001756 i2c_init_board();
Heiko Schocher67b23a32008-10-15 09:39:47 +02001757
1758 return 0;
1759}
1760
1761/* Analyses a Muxstring and if this String is correct
1762 * adds a new I2C Bus.
1763 */
1764I2C_MUX_DEVICE *i2c_mux_ident_muxstring (uchar *buf)
1765{
1766 I2C_MUX_DEVICE *device;
1767 I2C_MUX *mux;
1768 int pos = 0;
1769 int oldpos;
1770 int ret = 0;
1771 int len = strlen((char *)buf);
1772 int was = 0;
1773
1774 device = (I2C_MUX_DEVICE *)malloc (sizeof(I2C_MUX_DEVICE));
1775 device->mux = NULL;
1776 device->busid = i2c_mux_get_busid ();
1777 device->next = NULL;
1778 while (ret == 0) {
1779 mux = (I2C_MUX *)malloc (sizeof(I2C_MUX));
1780 mux->next = NULL;
1781 /* search name of mux */
1782 oldpos = pos;
1783 ret = i2c_mux_search_next(&pos, buf, len);
1784 if (ret != 0)
1785 printf ("%s no name.\n", __FUNCTION__);
1786 mux->name = (char *)malloc (pos - oldpos + 1);
1787 memcpy (mux->name, &buf[oldpos], pos - oldpos);
1788 mux->name[pos - oldpos] = 0;
1789 /* search address */
1790 pos ++;
1791 oldpos = pos;
1792 ret = i2c_mux_search_next(&pos, buf, len);
1793 if (ret != 0)
1794 printf ("%s no mux address.\n", __FUNCTION__);
1795 buf[pos] = 0;
1796 mux->chip = simple_strtoul((char *)&buf[oldpos], NULL, 16);
1797 buf[pos] = ':';
1798 /* search channel */
1799 pos ++;
1800 oldpos = pos;
1801 ret = i2c_mux_search_next(&pos, buf, len);
1802 if (ret < 0)
1803 printf ("%s no mux channel.\n", __FUNCTION__);
1804 was = 0;
1805 if (buf[pos] != 0) {
1806 buf[pos] = 0;
1807 was = 1;
1808 }
1809 mux->channel = simple_strtoul((char *)&buf[oldpos], NULL, 16);
1810 if (was)
1811 buf[pos] = ':';
1812 if (device->mux == NULL)
1813 device->mux = mux;
1814 else {
1815 I2C_MUX *muxtmp = device->mux;
1816 while (muxtmp->next != NULL) {
1817 muxtmp = muxtmp->next;
1818 }
1819 muxtmp->next = mux;
1820 }
1821 pos ++;
1822 oldpos = pos;
1823 }
1824 if (ret > 0) {
1825 /* Add Device */
1826 i2c_mux_add_device (device);
1827 return device;
1828 }
1829
1830 return NULL;
1831}
1832
1833int i2x_mux_select_mux(int bus)
1834{
1835 I2C_MUX_DEVICE *dev;
1836 I2C_MUX *mux;
1837
1838 if ((gd->flags & GD_FLG_RELOC) != GD_FLG_RELOC) {
1839 /* select Default Mux Bus */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001840#if defined(CONFIG_SYS_I2C_IVM_BUS)
1841 i2c_mux_ident_muxstring_f ((uchar *)CONFIG_SYS_I2C_IVM_BUS);
Heiko Schocher67b23a32008-10-15 09:39:47 +02001842#else
1843 {
1844 unsigned char *buf;
1845 buf = (unsigned char *) getenv("EEprom_ivm");
1846 if (buf != NULL)
1847 i2c_mux_ident_muxstring_f (buf);
1848 }
1849#endif
1850 return 0;
1851 }
1852 dev = i2c_mux_search_device(bus);
1853 if (dev == NULL)
1854 return -1;
1855
1856 mux = dev->mux;
1857 while (mux != NULL) {
Stefan Biglerc649dda2011-04-08 16:24:08 +02001858 /* do deblocking on each level of mux, before mux config */
1859 i2c_init_board();
Heiko Schocher67b23a32008-10-15 09:39:47 +02001860 if (i2c_write(mux->chip, 0, 0, &mux->channel, 1) != 0) {
1861 printf ("Error setting Mux: chip:%x channel: \
1862 %x\n", mux->chip, mux->channel);
1863 return -1;
1864 }
1865 mux = mux->next;
1866 }
Stefan Biglerc649dda2011-04-08 16:24:08 +02001867 /* do deblocking on each level of mux and after mux config */
1868 i2c_init_board();
Heiko Schocher67b23a32008-10-15 09:39:47 +02001869 return 0;
1870}
1871#endif /* CONFIG_I2C_MUX */