wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1 | /* |
| 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> |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 86 | #include <i2c.h> |
| 87 | #include <asm/byteorder.h> |
| 88 | |
| 89 | #if (CONFIG_COMMANDS & CFG_CMD_I2C) |
| 90 | |
| 91 | |
| 92 | /* Display values from last command. |
| 93 | * Memory modify remembered values are different from display memory. |
| 94 | */ |
| 95 | static uchar i2c_dp_last_chip; |
| 96 | static uint i2c_dp_last_addr; |
| 97 | static uint i2c_dp_last_alen; |
| 98 | static uint i2c_dp_last_length = 0x10; |
| 99 | |
| 100 | static uchar i2c_mm_last_chip; |
| 101 | static uint i2c_mm_last_addr; |
| 102 | static uint i2c_mm_last_alen; |
| 103 | |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 104 | /* If only one I2C bus is present, the list of devices to ignore when |
| 105 | * the probe command is issued is represented by a 1D array of addresses. |
| 106 | * When multiple buses are present, the list is an array of bus-address |
| 107 | * pairs. The following macros take care of this */ |
| 108 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 109 | #if defined(CFG_I2C_NOPROBES) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 110 | #if defined(CONFIG_I2C_MULTI_BUS) |
| 111 | static struct |
| 112 | { |
| 113 | uchar bus; |
| 114 | uchar addr; |
| 115 | } i2c_no_probes[] = CFG_I2C_NOPROBES; |
| 116 | #define GET_BUS_NUM i2c_get_bus_num() |
| 117 | #define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b)) |
| 118 | #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a)) |
| 119 | #define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr |
| 120 | #else /* single bus */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 121 | static uchar i2c_no_probes[] = CFG_I2C_NOPROBES; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 122 | #define GET_BUS_NUM 0 |
| 123 | #define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */ |
| 124 | #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a)) |
| 125 | #define NO_PROBE_ADDR(i) i2c_no_probes[(i)] |
| 126 | #endif /* CONFIG_MULTI_BUS */ |
| 127 | |
| 128 | #define NUM_ELEMENTS_NOPROBE (sizeof(i2c_no_probes)/sizeof(i2c_no_probes[0])) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 129 | #endif |
| 130 | |
| 131 | static int |
| 132 | mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]); |
| 133 | extern int cmd_get_data_size(char* arg, int default_size); |
| 134 | |
| 135 | /* |
| 136 | * Syntax: |
| 137 | * imd {i2c_chip} {addr}{.0, .1, .2} {len} |
| 138 | */ |
| 139 | #define DISP_LINE_LEN 16 |
| 140 | |
| 141 | int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 142 | { |
| 143 | u_char chip; |
| 144 | uint addr, alen, length; |
| 145 | int j, nbytes, linebytes; |
| 146 | |
| 147 | /* We use the last specified parameters, unless new ones are |
| 148 | * entered. |
| 149 | */ |
| 150 | chip = i2c_dp_last_chip; |
| 151 | addr = i2c_dp_last_addr; |
| 152 | alen = i2c_dp_last_alen; |
| 153 | length = i2c_dp_last_length; |
| 154 | |
| 155 | if (argc < 3) { |
| 156 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 161 | /* |
| 162 | * New command specified. |
| 163 | */ |
| 164 | alen = 1; |
| 165 | |
| 166 | /* |
| 167 | * I2C chip address |
| 168 | */ |
| 169 | chip = simple_strtoul(argv[1], NULL, 16); |
| 170 | |
| 171 | /* |
| 172 | * I2C data address within the chip. This can be 1 or |
| 173 | * 2 bytes long. Some day it might be 3 bytes long :-). |
| 174 | */ |
| 175 | addr = simple_strtoul(argv[2], NULL, 16); |
| 176 | alen = 1; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 177 | for (j = 0; j < 8; j++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 178 | if (argv[2][j] == '.') { |
| 179 | alen = argv[2][j+1] - '0'; |
| 180 | if (alen > 4) { |
| 181 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 182 | return 1; |
| 183 | } |
| 184 | break; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 185 | } else if (argv[2][j] == '\0') |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 186 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* |
| 190 | * If another parameter, it is the length to display. |
| 191 | * Length is the number of objects, not number of bytes. |
| 192 | */ |
| 193 | if (argc > 3) |
| 194 | length = simple_strtoul(argv[3], NULL, 16); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Print the lines. |
| 199 | * |
| 200 | * We buffer all read data, so we can make sure data is read only |
| 201 | * once. |
| 202 | */ |
| 203 | nbytes = length; |
| 204 | do { |
| 205 | unsigned char linebuf[DISP_LINE_LEN]; |
| 206 | unsigned char *cp; |
| 207 | |
| 208 | linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; |
| 209 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 210 | if (i2c_read(chip, addr, alen, linebuf, linebytes) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 211 | puts ("Error reading the chip.\n"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 212 | else { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 213 | printf("%04x:", addr); |
| 214 | cp = linebuf; |
| 215 | for (j=0; j<linebytes; j++) { |
| 216 | printf(" %02x", *cp++); |
| 217 | addr++; |
| 218 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 219 | puts (" "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 220 | cp = linebuf; |
| 221 | for (j=0; j<linebytes; j++) { |
| 222 | if ((*cp < 0x20) || (*cp > 0x7e)) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 223 | puts ("."); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 224 | else |
| 225 | printf("%c", *cp); |
| 226 | cp++; |
| 227 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 228 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 229 | } |
| 230 | nbytes -= linebytes; |
| 231 | } while (nbytes > 0); |
| 232 | |
| 233 | i2c_dp_last_chip = chip; |
| 234 | i2c_dp_last_addr = addr; |
| 235 | i2c_dp_last_alen = alen; |
| 236 | i2c_dp_last_length = length; |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | int do_i2c_mm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 242 | { |
| 243 | return mod_i2c_mem (cmdtp, 1, flag, argc, argv); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | int do_i2c_nm ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 248 | { |
| 249 | return mod_i2c_mem (cmdtp, 0, flag, argc, argv); |
| 250 | } |
| 251 | |
| 252 | /* Write (fill) memory |
| 253 | * |
| 254 | * Syntax: |
| 255 | * imw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}] |
| 256 | */ |
| 257 | int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 258 | { |
| 259 | uchar chip; |
| 260 | ulong addr; |
| 261 | uint alen; |
| 262 | uchar byte; |
| 263 | int count; |
| 264 | int j; |
| 265 | |
| 266 | if ((argc < 4) || (argc > 5)) { |
| 267 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 268 | return 1; |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * Chip is always specified. |
| 273 | */ |
| 274 | chip = simple_strtoul(argv[1], NULL, 16); |
| 275 | |
| 276 | /* |
| 277 | * Address is always specified. |
| 278 | */ |
| 279 | addr = simple_strtoul(argv[2], NULL, 16); |
| 280 | alen = 1; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 281 | for (j = 0; j < 8; j++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 282 | if (argv[2][j] == '.') { |
| 283 | alen = argv[2][j+1] - '0'; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 284 | if (alen > 4) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 285 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 286 | return 1; |
| 287 | } |
| 288 | break; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 289 | } else if (argv[2][j] == '\0') |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 290 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Value to write is always specified. |
| 295 | */ |
| 296 | byte = simple_strtoul(argv[3], NULL, 16); |
| 297 | |
| 298 | /* |
| 299 | * Optional count |
| 300 | */ |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 301 | if (argc == 5) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 302 | count = simple_strtoul(argv[4], NULL, 16); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 303 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 304 | count = 1; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 305 | |
| 306 | while (count-- > 0) { |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 307 | if (i2c_write(chip, addr++, alen, &byte, 1) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 308 | puts ("Error writing the chip.\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 309 | /* |
| 310 | * Wait for the write to complete. The write can take |
| 311 | * up to 10mSec (we allow a little more time). |
| 312 | * |
| 313 | * On some chips, while the write is in progress, the |
| 314 | * chip doesn't respond. This apparently isn't a |
| 315 | * universal feature so we don't take advantage of it. |
| 316 | */ |
| d4f5c72 | 2005-08-12 21:16:13 +0200 | [diff] [blame] | 317 | /* |
| 318 | * No write delay with FRAM devices. |
| 319 | */ |
| 320 | #if !defined(CFG_I2C_FRAM) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 321 | udelay(11000); |
| d4f5c72 | 2005-08-12 21:16:13 +0200 | [diff] [blame] | 322 | #endif |
| 323 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 324 | #if 0 |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 325 | for (timeout = 0; timeout < 10; timeout++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 326 | udelay(2000); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 327 | if (i2c_probe(chip) == 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 328 | break; |
| 329 | } |
| 330 | #endif |
| 331 | } |
| 332 | |
| 333 | return (0); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | /* Calculate a CRC on memory |
| 338 | * |
| 339 | * Syntax: |
| 340 | * icrc32 {i2c_chip} {addr}{.0, .1, .2} {count} |
| 341 | */ |
| 342 | int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 343 | { |
| 344 | uchar chip; |
| 345 | ulong addr; |
| 346 | uint alen; |
| 347 | int count; |
| 348 | uchar byte; |
| 349 | ulong crc; |
| 350 | ulong err; |
| 351 | int j; |
| 352 | |
| 353 | if (argc < 4) { |
| 354 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 355 | return 1; |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Chip is always specified. |
| 360 | */ |
| 361 | chip = simple_strtoul(argv[1], NULL, 16); |
| 362 | |
| 363 | /* |
| 364 | * Address is always specified. |
| 365 | */ |
| 366 | addr = simple_strtoul(argv[2], NULL, 16); |
| 367 | alen = 1; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 368 | for (j = 0; j < 8; j++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 369 | if (argv[2][j] == '.') { |
| 370 | alen = argv[2][j+1] - '0'; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 371 | if (alen > 4) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 372 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 373 | return 1; |
| 374 | } |
| 375 | break; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 376 | } else if (argv[2][j] == '\0') |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 377 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Count is always specified |
| 382 | */ |
| 383 | count = simple_strtoul(argv[3], NULL, 16); |
| 384 | |
| 385 | printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1); |
| 386 | /* |
| 387 | * CRC a byte at a time. This is going to be slooow, but hey, the |
| 388 | * memories are small and slow too so hopefully nobody notices. |
| 389 | */ |
| 390 | crc = 0; |
| 391 | err = 0; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 392 | while (count-- > 0) { |
| 393 | if (i2c_read(chip, addr, alen, &byte, 1) != 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 394 | err++; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 395 | crc = crc32 (crc, &byte, 1); |
| 396 | addr++; |
| 397 | } |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 398 | if (err > 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 399 | puts ("Error reading the chip,\n"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 400 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 401 | printf ("%08lx\n", crc); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | |
| 407 | /* Modify memory. |
| 408 | * |
| 409 | * Syntax: |
| 410 | * imm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2} |
| 411 | * inm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2} |
| 412 | */ |
| 413 | |
| 414 | static int |
| 415 | mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) |
| 416 | { |
| 417 | uchar chip; |
| 418 | ulong addr; |
| 419 | uint alen; |
| 420 | ulong data; |
| 421 | int size = 1; |
| 422 | int nbytes; |
| 423 | int j; |
| 424 | extern char console_buffer[]; |
| 425 | |
| 426 | if (argc != 3) { |
| 427 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 428 | return 1; |
| 429 | } |
| 430 | |
| 431 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 432 | reset_cmd_timeout(); /* got a good command to get here */ |
| 433 | #endif |
| 434 | /* |
| 435 | * We use the last specified parameters, unless new ones are |
| 436 | * entered. |
| 437 | */ |
| 438 | chip = i2c_mm_last_chip; |
| 439 | addr = i2c_mm_last_addr; |
| 440 | alen = i2c_mm_last_alen; |
| 441 | |
| 442 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 443 | /* |
| 444 | * New command specified. Check for a size specification. |
| 445 | * Defaults to byte if no or incorrect specification. |
| 446 | */ |
| 447 | size = cmd_get_data_size(argv[0], 1); |
| 448 | |
| 449 | /* |
| 450 | * Chip is always specified. |
| 451 | */ |
| 452 | chip = simple_strtoul(argv[1], NULL, 16); |
| 453 | |
| 454 | /* |
| 455 | * Address is always specified. |
| 456 | */ |
| 457 | addr = simple_strtoul(argv[2], NULL, 16); |
| 458 | alen = 1; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 459 | for (j = 0; j < 8; j++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 460 | if (argv[2][j] == '.') { |
| 461 | alen = argv[2][j+1] - '0'; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 462 | if (alen > 4) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 463 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 464 | return 1; |
| 465 | } |
| 466 | break; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 467 | } else if (argv[2][j] == '\0') |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 468 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | * Print the address, followed by value. Then accept input for |
| 474 | * the next value. A non-converted value exits. |
| 475 | */ |
| 476 | do { |
| 477 | printf("%08lx:", addr); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 478 | if (i2c_read(chip, addr, alen, (uchar *)&data, size) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 479 | puts ("\nError reading the chip,\n"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 480 | else { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 481 | data = cpu_to_be32(data); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 482 | if (size == 1) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 483 | printf(" %02lx", (data >> 24) & 0x000000FF); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 484 | else if (size == 2) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 485 | printf(" %04lx", (data >> 16) & 0x0000FFFF); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 486 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 487 | printf(" %08lx", data); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | nbytes = readline (" ? "); |
| 491 | if (nbytes == 0) { |
| 492 | /* |
| 493 | * <CR> pressed as only input, don't modify current |
| 494 | * location and move to next. |
| 495 | */ |
| 496 | if (incrflag) |
| 497 | addr += size; |
| 498 | nbytes = size; |
| 499 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 500 | reset_cmd_timeout(); /* good enough to not time out */ |
| 501 | #endif |
| 502 | } |
| 503 | #ifdef CONFIG_BOOT_RETRY_TIME |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 504 | else if (nbytes == -2) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 505 | break; /* timed out, exit the command */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 506 | #endif |
| 507 | else { |
| 508 | char *endp; |
| 509 | |
| 510 | data = simple_strtoul(console_buffer, &endp, 16); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 511 | if (size == 1) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 512 | data = data << 24; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 513 | else if (size == 2) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 514 | data = data << 16; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 515 | data = be32_to_cpu(data); |
| 516 | nbytes = endp - console_buffer; |
| 517 | if (nbytes) { |
| 518 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 519 | /* |
| 520 | * good enough to not time out |
| 521 | */ |
| 522 | reset_cmd_timeout(); |
| 523 | #endif |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 524 | if (i2c_write(chip, addr, alen, (uchar *)&data, size) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 525 | puts ("Error writing the chip.\n"); |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 526 | #ifdef CFG_EEPROM_PAGE_WRITE_DELAY_MS |
| 527 | udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000); |
| 528 | #endif |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 529 | if (incrflag) |
| 530 | addr += size; |
| 531 | } |
| 532 | } |
| 533 | } while (nbytes); |
| 534 | |
| 535 | chip = i2c_mm_last_chip; |
| 536 | addr = i2c_mm_last_addr; |
| 537 | alen = i2c_mm_last_alen; |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | * Syntax: |
| 544 | * iprobe {addr}{.0, .1, .2} |
| 545 | */ |
| 546 | int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 547 | { |
| 548 | int j; |
| 549 | #if defined(CFG_I2C_NOPROBES) |
| 550 | int k, skip; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 551 | uchar bus = GET_BUS_NUM; |
| 552 | #endif /* NOPROBES */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 553 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 554 | puts ("Valid chip addresses:"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 555 | for (j = 0; j < 128; j++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 556 | #if defined(CFG_I2C_NOPROBES) |
| 557 | skip = 0; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 558 | for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) { |
| 559 | if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 560 | skip = 1; |
| 561 | break; |
| 562 | } |
| 563 | } |
| 564 | if (skip) |
| 565 | continue; |
| 566 | #endif |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 567 | if (i2c_probe(j) == 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 568 | printf(" %02X", j); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 569 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 570 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 571 | |
| 572 | #if defined(CFG_I2C_NOPROBES) |
| 573 | puts ("Excluded chip addresses:"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 574 | for (k=0; k < NUM_ELEMENTS_NOPROBE; k++) { |
| 575 | if (COMPARE_BUS(bus,k)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 576 | printf(" %02X", NO_PROBE_ADDR(k)); |
| 577 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 578 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 579 | #endif |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | /* |
| 586 | * Syntax: |
| 587 | * iloop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}] |
| 588 | * {length} - Number of bytes to read |
| 589 | * {delay} - A DECIMAL number and defaults to 1000 uSec |
| 590 | */ |
| 591 | int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 592 | { |
| 593 | u_char chip; |
| 594 | ulong alen; |
| 595 | uint addr; |
| 596 | uint length; |
| 597 | u_char bytes[16]; |
| 598 | int delay; |
| 599 | int j; |
| 600 | |
| 601 | if (argc < 3) { |
| 602 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 603 | return 1; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Chip is always specified. |
| 608 | */ |
| 609 | chip = simple_strtoul(argv[1], NULL, 16); |
| 610 | |
| 611 | /* |
| 612 | * Address is always specified. |
| 613 | */ |
| 614 | addr = simple_strtoul(argv[2], NULL, 16); |
| 615 | alen = 1; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 616 | for (j = 0; j < 8; j++) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 617 | if (argv[2][j] == '.') { |
| 618 | alen = argv[2][j+1] - '0'; |
| 619 | if (alen > 4) { |
| 620 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 621 | return 1; |
| 622 | } |
| 623 | break; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 624 | } else if (argv[2][j] == '\0') |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 625 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* |
| 629 | * Length is the number of objects, not number of bytes. |
| 630 | */ |
| 631 | length = 1; |
| 632 | length = simple_strtoul(argv[3], NULL, 16); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 633 | if (length > sizeof(bytes)) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 634 | length = sizeof(bytes); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 635 | |
| 636 | /* |
| 637 | * The delay time (uSec) is optional. |
| 638 | */ |
| 639 | delay = 1000; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 640 | if (argc > 3) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 641 | delay = simple_strtoul(argv[4], NULL, 10); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 642 | /* |
| 643 | * Run the loop... |
| 644 | */ |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 645 | while (1) { |
| 646 | if (i2c_read(chip, addr, alen, bytes, length) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 647 | puts ("Error reading the chip.\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 648 | udelay(delay); |
| 649 | } |
| 650 | |
| 651 | /* NOTREACHED */ |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | |
| 656 | /* |
| 657 | * The SDRAM command is separately configured because many |
| 658 | * (most?) embedded boards don't use SDRAM DIMMs. |
| 659 | */ |
| 660 | #if (CONFIG_COMMANDS & CFG_CMD_SDRAM) |
| 661 | |
| 662 | /* |
| 663 | * Syntax: |
| 664 | * sdram {i2c_chip} |
| 665 | */ |
| 666 | int do_sdram ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 667 | { |
| 668 | u_char chip; |
| 669 | u_char data[128]; |
| 670 | u_char cksum; |
| 671 | int j; |
| 672 | |
| 673 | if (argc < 2) { |
| 674 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 675 | return 1; |
| 676 | } |
| 677 | /* |
| 678 | * Chip is always specified. |
| 679 | */ |
| 680 | chip = simple_strtoul(argv[1], NULL, 16); |
| 681 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 682 | if (i2c_read(chip, 0, 1, data, sizeof(data)) != 0) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 683 | puts ("No SDRAM Serial Presence Detect found.\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 684 | return 1; |
| 685 | } |
| 686 | |
| 687 | cksum = 0; |
| 688 | for (j = 0; j < 63; j++) { |
| 689 | cksum += data[j]; |
| 690 | } |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 691 | if (cksum != data[63]) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 692 | printf ("WARNING: Configuration data checksum failure:\n" |
| 693 | " is 0x%02x, calculated 0x%02x\n", |
| 694 | data[63], cksum); |
| 695 | } |
| 696 | printf("SPD data revision %d.%d\n", |
| 697 | (data[62] >> 4) & 0x0F, data[62] & 0x0F); |
| 698 | printf("Bytes used 0x%02X\n", data[0]); |
| 699 | printf("Serial memory size 0x%02X\n", 1 << data[1]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 700 | puts ("Memory type "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 701 | switch(data[2]) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 702 | case 2: puts ("EDO\n"); break; |
| 703 | case 4: puts ("SDRAM\n"); break; |
Matthias Fuchs | 650a330 | 2007-03-08 16:26:52 +0100 | [diff] [blame] | 704 | case 8: puts ("DDR2\n"); break; |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 705 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 706 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 707 | puts ("Row address bits "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 708 | if ((data[3] & 0x00F0) == 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 709 | printf("%d\n", data[3] & 0x0F); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 710 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 711 | printf("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 712 | puts ("Column address bits "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 713 | if ((data[4] & 0x00F0) == 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 714 | printf("%d\n", data[4] & 0x0F); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 715 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 716 | printf("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 717 | printf("Module rows %d\n", data[5]); |
| 718 | printf("Module data width %d bits\n", (data[7] << 8) | data[6]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 719 | puts ("Interface signal levels "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 720 | switch(data[8]) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 721 | case 0: puts ("5.0v/TTL\n"); break; |
| 722 | case 1: puts ("LVTTL\n"); break; |
| 723 | case 2: puts ("HSTL 1.5\n"); break; |
| 724 | case 3: puts ("SSTL 3.3\n"); break; |
| 725 | case 4: puts ("SSTL 2.5\n"); break; |
Matthias Fuchs | 650a330 | 2007-03-08 16:26:52 +0100 | [diff] [blame] | 726 | case 5: puts ("SSTL 1.8\n"); break; |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 727 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 728 | } |
| 729 | printf("SDRAM cycle time %d.%d nS\n", |
| 730 | (data[9] >> 4) & 0x0F, data[9] & 0x0F); |
| 731 | printf("SDRAM access time %d.%d nS\n", |
| 732 | (data[10] >> 4) & 0x0F, data[10] & 0x0F); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 733 | puts ("EDC configuration "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 734 | switch(data[11]) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 735 | case 0: puts ("None\n"); break; |
| 736 | case 1: puts ("Parity\n"); break; |
| 737 | case 2: puts ("ECC\n"); break; |
| 738 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 739 | } |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 740 | if ((data[12] & 0x80) == 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 741 | puts ("No self refresh, rate "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 742 | else |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 743 | puts ("Self refresh, rate "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 744 | switch(data[12] & 0x7F) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 745 | case 0: puts ("15.625uS\n"); break; |
| 746 | case 1: puts ("3.9uS\n"); break; |
| 747 | case 2: puts ("7.8uS\n"); break; |
| 748 | case 3: puts ("31.3uS\n"); break; |
| 749 | case 4: puts ("62.5uS\n"); break; |
| 750 | case 5: puts ("125uS\n"); break; |
| 751 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 752 | } |
| 753 | printf("SDRAM width (primary) %d\n", data[13] & 0x7F); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 754 | if ((data[13] & 0x80) != 0) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 755 | printf(" (second bank) %d\n", |
| 756 | 2 * (data[13] & 0x7F)); |
| 757 | } |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 758 | if (data[14] != 0) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 759 | printf("EDC width %d\n", |
| 760 | data[14] & 0x7F); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 761 | if ((data[14] & 0x80) != 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 762 | printf(" (second bank) %d\n", |
| 763 | 2 * (data[14] & 0x7F)); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 764 | } |
| 765 | printf("Min clock delay, back-to-back random column addresses %d\n", |
| 766 | data[15]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 767 | puts ("Burst length(s) "); |
| 768 | if (data[16] & 0x80) puts (" Page"); |
| 769 | if (data[16] & 0x08) puts (" 8"); |
| 770 | if (data[16] & 0x04) puts (" 4"); |
| 771 | if (data[16] & 0x02) puts (" 2"); |
| 772 | if (data[16] & 0x01) puts (" 1"); |
| 773 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 774 | printf("Number of banks %d\n", data[17]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 775 | puts ("CAS latency(s) "); |
| 776 | if (data[18] & 0x80) puts (" TBD"); |
| 777 | if (data[18] & 0x40) puts (" 7"); |
| 778 | if (data[18] & 0x20) puts (" 6"); |
| 779 | if (data[18] & 0x10) puts (" 5"); |
| 780 | if (data[18] & 0x08) puts (" 4"); |
| 781 | if (data[18] & 0x04) puts (" 3"); |
| 782 | if (data[18] & 0x02) puts (" 2"); |
| 783 | if (data[18] & 0x01) puts (" 1"); |
| 784 | putc ('\n'); |
| 785 | puts ("CS latency(s) "); |
| 786 | if (data[19] & 0x80) puts (" TBD"); |
| 787 | if (data[19] & 0x40) puts (" 6"); |
| 788 | if (data[19] & 0x20) puts (" 5"); |
| 789 | if (data[19] & 0x10) puts (" 4"); |
| 790 | if (data[19] & 0x08) puts (" 3"); |
| 791 | if (data[19] & 0x04) puts (" 2"); |
| 792 | if (data[19] & 0x02) puts (" 1"); |
| 793 | if (data[19] & 0x01) puts (" 0"); |
| 794 | putc ('\n'); |
| 795 | puts ("WE latency(s) "); |
| 796 | if (data[20] & 0x80) puts (" TBD"); |
| 797 | if (data[20] & 0x40) puts (" 6"); |
| 798 | if (data[20] & 0x20) puts (" 5"); |
| 799 | if (data[20] & 0x10) puts (" 4"); |
| 800 | if (data[20] & 0x08) puts (" 3"); |
| 801 | if (data[20] & 0x04) puts (" 2"); |
| 802 | if (data[20] & 0x02) puts (" 1"); |
| 803 | if (data[20] & 0x01) puts (" 0"); |
| 804 | putc ('\n'); |
| 805 | puts ("Module attributes:\n"); |
| 806 | if (!data[21]) puts (" (none)\n"); |
| 807 | if (data[21] & 0x80) puts (" TBD (bit 7)\n"); |
| 808 | if (data[21] & 0x40) puts (" Redundant row address\n"); |
| 809 | if (data[21] & 0x20) puts (" Differential clock input\n"); |
| 810 | if (data[21] & 0x10) puts (" Registerd DQMB inputs\n"); |
| 811 | if (data[21] & 0x08) puts (" Buffered DQMB inputs\n"); |
| 812 | if (data[21] & 0x04) puts (" On-card PLL\n"); |
| 813 | if (data[21] & 0x02) puts (" Registered address/control lines\n"); |
| 814 | if (data[21] & 0x01) puts (" Buffered address/control lines\n"); |
| 815 | puts ("Device attributes:\n"); |
| 816 | if (data[22] & 0x80) puts (" TBD (bit 7)\n"); |
| 817 | if (data[22] & 0x40) puts (" TBD (bit 6)\n"); |
| 818 | if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n"); |
| 819 | else puts (" Upper Vcc tolerance 10%\n"); |
| 820 | if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n"); |
| 821 | else puts (" Lower Vcc tolerance 10%\n"); |
| 822 | if (data[22] & 0x08) puts (" Supports write1/read burst\n"); |
| 823 | if (data[22] & 0x04) puts (" Supports precharge all\n"); |
| 824 | if (data[22] & 0x02) puts (" Supports auto precharge\n"); |
| 825 | if (data[22] & 0x01) puts (" Supports early RAS# precharge\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 826 | printf("SDRAM cycle time (2nd highest CAS latency) %d.%d nS\n", |
| 827 | (data[23] >> 4) & 0x0F, data[23] & 0x0F); |
| 828 | printf("SDRAM access from clock (2nd highest CAS latency) %d.%d nS\n", |
| 829 | (data[24] >> 4) & 0x0F, data[24] & 0x0F); |
| 830 | printf("SDRAM cycle time (3rd highest CAS latency) %d.%d nS\n", |
| 831 | (data[25] >> 4) & 0x0F, data[25] & 0x0F); |
| 832 | printf("SDRAM access from clock (3rd highest CAS latency) %d.%d nS\n", |
| 833 | (data[26] >> 4) & 0x0F, data[26] & 0x0F); |
| 834 | printf("Minimum row precharge %d nS\n", data[27]); |
| 835 | printf("Row active to row active min %d nS\n", data[28]); |
| 836 | printf("RAS to CAS delay min %d nS\n", data[29]); |
| 837 | printf("Minimum RAS pulse width %d nS\n", data[30]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 838 | puts ("Density of each row "); |
| 839 | if (data[31] & 0x80) puts (" 512"); |
| 840 | if (data[31] & 0x40) puts (" 256"); |
| 841 | if (data[31] & 0x20) puts (" 128"); |
| 842 | if (data[31] & 0x10) puts (" 64"); |
| 843 | if (data[31] & 0x08) puts (" 32"); |
| 844 | if (data[31] & 0x04) puts (" 16"); |
| 845 | if (data[31] & 0x02) puts (" 8"); |
| 846 | if (data[31] & 0x01) puts (" 4"); |
| 847 | puts ("MByte\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 848 | printf("Command and Address setup %c%d.%d nS\n", |
| 849 | (data[32] & 0x80) ? '-' : '+', |
| 850 | (data[32] >> 4) & 0x07, data[32] & 0x0F); |
| 851 | printf("Command and Address hold %c%d.%d nS\n", |
| 852 | (data[33] & 0x80) ? '-' : '+', |
| 853 | (data[33] >> 4) & 0x07, data[33] & 0x0F); |
| 854 | printf("Data signal input setup %c%d.%d nS\n", |
| 855 | (data[34] & 0x80) ? '-' : '+', |
| 856 | (data[34] >> 4) & 0x07, data[34] & 0x0F); |
| 857 | printf("Data signal input hold %c%d.%d nS\n", |
| 858 | (data[35] & 0x80) ? '-' : '+', |
| 859 | (data[35] >> 4) & 0x07, data[35] & 0x0F); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 860 | puts ("Manufacturer's JEDEC ID "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 861 | for (j = 64; j <= 71; j++) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 862 | printf("%02X ", data[j]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 863 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 864 | printf("Manufacturing Location %02X\n", data[72]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 865 | puts ("Manufacturer's Part Number "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 866 | for (j = 73; j <= 90; j++) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 867 | printf("%02X ", data[j]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 868 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 869 | printf("Revision Code %02X %02X\n", data[91], data[92]); |
| 870 | printf("Manufacturing Date %02X %02X\n", data[93], data[94]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 871 | puts ("Assembly Serial Number "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 872 | for (j = 95; j <= 98; j++) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 873 | printf("%02X ", data[j]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 874 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 875 | printf("Speed rating PC%d\n", |
| 876 | data[126] == 0x66 ? 66 : data[126]); |
| 877 | |
| 878 | return 0; |
| 879 | } |
| 880 | #endif /* CFG_CMD_SDRAM */ |
| 881 | |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 882 | #if defined(CONFIG_I2C_CMD_TREE) |
| 883 | #if defined(CONFIG_I2C_MULTI_BUS) |
| 884 | int do_i2c_bus_num(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 885 | { |
| 886 | int bus_idx, ret=0; |
| 887 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 888 | if (argc == 1) |
| 889 | /* querying current setting */ |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 890 | printf("Current bus is %d\n", i2c_get_bus_num()); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 891 | else { |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 892 | bus_idx = simple_strtoul(argv[1], NULL, 10); |
| 893 | printf("Setting bus to %d\n", bus_idx); |
| 894 | ret = i2c_set_bus_num(bus_idx); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 895 | if (ret) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 896 | printf("Failure changing bus number (%d)\n", ret); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 897 | } |
| 898 | return ret; |
| 899 | } |
| 900 | #endif /* CONFIG_I2C_MULTI_BUS */ |
| 901 | |
| 902 | int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 903 | { |
| 904 | int speed, ret=0; |
| 905 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 906 | if (argc == 1) |
| 907 | /* querying current speed */ |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 908 | printf("Current bus speed=%d\n", i2c_get_bus_speed()); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 909 | else { |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 910 | speed = simple_strtoul(argv[1], NULL, 10); |
| 911 | printf("Setting bus speed to %d Hz\n", speed); |
| 912 | ret = i2c_set_bus_speed(speed); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 913 | if (ret) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 914 | printf("Failure changing bus speed (%d)\n", ret); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 915 | } |
| 916 | return ret; |
| 917 | } |
| 918 | |
| 919 | int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 920 | { |
| 921 | #if defined(CONFIG_I2C_MULTI_BUS) |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 922 | if (!strncmp(argv[1], "de", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 923 | return do_i2c_bus_num(cmdtp, flag, --argc, ++argv); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 924 | #endif /* CONFIG_I2C_MULTI_BUS */ |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 925 | if (!strncmp(argv[1], "sp", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 926 | return do_i2c_bus_speed(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 927 | if (!strncmp(argv[1], "md", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 928 | return do_i2c_md(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 929 | if (!strncmp(argv[1], "mm", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 930 | return do_i2c_mm(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 931 | if (!strncmp(argv[1], "mw", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 932 | return do_i2c_mw(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 933 | if (!strncmp(argv[1], "nm", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 934 | return do_i2c_nm(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 935 | if (!strncmp(argv[1], "cr", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 936 | return do_i2c_crc(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 937 | if (!strncmp(argv[1], "pr", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 938 | return do_i2c_probe(cmdtp, flag, --argc, ++argv); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 939 | if (!strncmp(argv[1], "lo", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 940 | return do_i2c_loop(cmdtp, flag, --argc, ++argv); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 941 | #if (CONFIG_COMMANDS & CFG_CMD_SDRAM) |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 942 | if (!strncmp(argv[1], "sd", 2)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 943 | return do_sdram(cmdtp, flag, --argc, ++argv); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 944 | #endif /* CFG_CMD_SDRAM */ |
| 945 | else |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 946 | printf ("Usage:\n%s\n", cmdtp->usage); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 947 | return 0; |
| 948 | } |
| 949 | #endif /* CONFIG_I2C_CMD_TREE */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 950 | |
| 951 | /***************************************************/ |
| 952 | |
Matthias Fuchs | d9fc703 | 2007-03-08 16:25:47 +0100 | [diff] [blame] | 953 | #if defined(CONFIG_I2C_CMD_TREE) |
| 954 | U_BOOT_CMD( |
| 955 | i2c, 6, 1, do_i2c, |
| 956 | "i2c - I2C sub-system\n", |
| 957 | #if defined(CONFIG_I2C_MULTI_BUS) |
| 958 | "dev [dev] - show or set current I2C bus\n" |
| 959 | #endif /* CONFIG_I2C_MULTI_BUS */ |
| 960 | "i2c speed [speed] - show or set I2C bus speed\n" |
| 961 | "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n" |
| 962 | "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n" |
| 963 | "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n" |
| 964 | "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n" |
| 965 | "i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n" |
| 966 | "i2c probe - show devices on the I2C bus\n" |
| 967 | "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n" |
| 968 | #if (CONFIG_COMMANDS & CFG_CMD_SDRAM) |
| 969 | "i2c sdram chip - print SDRAM configuration information\n" |
| 970 | #endif /* CFG_CMD_SDRAM */ |
| 971 | ); |
| 972 | #else /* CONFIG_I2C_CMD_TREE */ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 973 | U_BOOT_CMD( |
| 974 | imd, 4, 1, do_i2c_md, \ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 975 | "imd - i2c memory display\n", \ |
| 976 | "chip address[.0, .1, .2] [# of objects]\n - i2c memory display\n" \ |
| 977 | ); |
| 978 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 979 | U_BOOT_CMD( |
| 980 | imm, 3, 1, do_i2c_mm, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 981 | "imm - i2c memory modify (auto-incrementing)\n", |
| 982 | "chip address[.0, .1, .2]\n" |
| 983 | " - memory modify, auto increment address\n" |
| 984 | ); |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 985 | U_BOOT_CMD( |
| 986 | inm, 3, 1, do_i2c_nm, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 987 | "inm - memory modify (constant address)\n", |
| 988 | "chip address[.0, .1, .2]\n - memory modify, read and keep address\n" |
| 989 | ); |
| 990 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 991 | U_BOOT_CMD( |
| 992 | imw, 5, 1, do_i2c_mw, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 993 | "imw - memory write (fill)\n", |
| 994 | "chip address[.0, .1, .2] value [count]\n - memory write (fill)\n" |
| 995 | ); |
| 996 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 997 | U_BOOT_CMD( |
| 998 | icrc32, 5, 1, do_i2c_crc, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 999 | "icrc32 - checksum calculation\n", |
| 1000 | "chip address[.0, .1, .2] count\n - compute CRC32 checksum\n" |
| 1001 | ); |
| 1002 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1003 | U_BOOT_CMD( |
| 1004 | iprobe, 1, 1, do_i2c_probe, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1005 | "iprobe - probe to discover valid I2C chip addresses\n", |
| 1006 | "\n -discover valid I2C chip addresses\n" |
| 1007 | ); |
| 1008 | |
| 1009 | /* |
| 1010 | * Require full name for "iloop" because it is an infinite loop! |
| 1011 | */ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1012 | U_BOOT_CMD( |
| 1013 | iloop, 5, 1, do_i2c_loop, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1014 | "iloop - infinite loop on address range\n", |
| 1015 | "chip address[.0, .1, .2] [# of objects]\n" |
| 1016 | " - loop, reading a set of addresses\n" |
| 1017 | ); |
| 1018 | |
| 1019 | #if (CONFIG_COMMANDS & CFG_CMD_SDRAM) |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1020 | U_BOOT_CMD( |
| 1021 | isdram, 2, 1, do_sdram, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1022 | "isdram - print SDRAM configuration information\n", |
| 1023 | "chip\n - print SDRAM configuration information\n" |
| 1024 | " (valid chip values 50..57)\n" |
| 1025 | ); |
| 1026 | #endif |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1027 | #endif /* CONFIG_I2C_CMD_TREE */ |
| 1028 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1029 | #endif /* CFG_CMD_I2C */ |