wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1 | /* |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 2 | * (C) Copyright 2009 |
| 3 | * Sergey Kubushyn, himself, ksi@koi8.net |
| 4 | * |
| 5 | * Changes for unified multibus/multiadapter I2C support. |
| 6 | * |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 7 | * (C) Copyright 2001 |
| 8 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. |
| 9 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * I2C Functions similar to the standard memory functions. |
| 15 | * |
| 16 | * There are several parameters in many of the commands that bear further |
| 17 | * explanations: |
| 18 | * |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 19 | * {i2c_chip} is the I2C chip address (the first byte sent on the bus). |
| 20 | * Each I2C chip on the bus has a unique address. On the I2C data bus, |
| 21 | * the address is the upper seven bits and the LSB is the "read/write" |
| 22 | * bit. Note that the {i2c_chip} address specified on the command |
| 23 | * line is not shifted up: e.g. a typical EEPROM memory chip may have |
| 24 | * an I2C address of 0x50, but the data put on the bus will be 0xA0 |
| 25 | * for write and 0xA1 for read. This "non shifted" address notation |
| 26 | * matches at least half of the data sheets :-/. |
| 27 | * |
| 28 | * {addr} is the address (or offset) within the chip. Small memory |
| 29 | * chips have 8 bit addresses. Large memory chips have 16 bit |
| 30 | * addresses. Other memory chips have 9, 10, or 11 bit addresses. |
| 31 | * Many non-memory chips have multiple registers and {addr} is used |
| 32 | * as the register index. Some non-memory chips have only one register |
| 33 | * and therefore don't need any {addr} parameter. |
| 34 | * |
| 35 | * The default {addr} parameter is one byte (.1) which works well for |
| 36 | * memories and registers with 8 bits of address space. |
| 37 | * |
| 38 | * You can specify the length of the {addr} field with the optional .0, |
| 39 | * .1, or .2 modifier (similar to the .b, .w, .l modifier). If you are |
| 40 | * manipulating a single register device which doesn't use an address |
| 41 | * field, use "0.0" for the address and the ".0" length field will |
| 42 | * suppress the address in the I2C data stream. This also works for |
| 43 | * successive reads using the I2C auto-incrementing memory pointer. |
| 44 | * |
| 45 | * If you are manipulating a large memory with 2-byte addresses, use |
| 46 | * the .2 address modifier, e.g. 210.2 addresses location 528 (decimal). |
| 47 | * |
| 48 | * Then there are the unfortunate memory chips that spill the most |
| 49 | * significant 1, 2, or 3 bits of address into the chip address byte. |
| 50 | * This effectively makes one chip (logically) look like 2, 4, or |
| 51 | * 8 chips. This is handled (awkwardly) by #defining |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | * CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW and using the .1 modifier on the |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 53 | * {addr} field (since .1 is the default, it doesn't actually have to |
| 54 | * be specified). Examples: given a memory chip at I2C chip address |
| 55 | * 0x50, the following would happen... |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 56 | * i2c md 50 0 10 display 16 bytes starting at 0x000 |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 57 | * On the bus: <S> A0 00 <E> <S> A1 <rd> ... <rd> |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 58 | * i2c md 50 100 10 display 16 bytes starting at 0x100 |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 59 | * On the bus: <S> A2 00 <E> <S> A3 <rd> ... <rd> |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 60 | * i2c md 50 210 10 display 16 bytes starting at 0x210 |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 61 | * On the bus: <S> A4 10 <E> <S> A5 <rd> ... <rd> |
| 62 | * This is awfully ugly. It would be nice if someone would think up |
| 63 | * a better way of handling this. |
| 64 | * |
| 65 | * Adapted from cmd_mem.c which is copyright Wolfgang Denk (wd@denx.de). |
| 66 | */ |
| 67 | |
| 68 | #include <common.h> |
Simon Glass | 18d6653 | 2014-04-10 20:01:25 -0600 | [diff] [blame^] | 69 | #include <cli.h> |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 70 | #include <command.h> |
Tom Wai-Hong Tam | 735987c | 2012-12-05 14:46:40 +0000 | [diff] [blame] | 71 | #include <edid.h> |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 72 | #include <environment.h> |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 73 | #include <i2c.h> |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 74 | #include <malloc.h> |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 75 | #include <asm/byteorder.h> |
Marek Vasut | 2515d84 | 2012-11-12 14:34:25 +0000 | [diff] [blame] | 76 | #include <linux/compiler.h> |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 77 | |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 78 | DECLARE_GLOBAL_DATA_PTR; |
| 79 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 80 | /* Display values from last command. |
| 81 | * Memory modify remembered values are different from display memory. |
| 82 | */ |
| 83 | static uchar i2c_dp_last_chip; |
| 84 | static uint i2c_dp_last_addr; |
| 85 | static uint i2c_dp_last_alen; |
| 86 | static uint i2c_dp_last_length = 0x10; |
| 87 | |
| 88 | static uchar i2c_mm_last_chip; |
| 89 | static uint i2c_mm_last_addr; |
| 90 | static uint i2c_mm_last_alen; |
| 91 | |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 92 | /* If only one I2C bus is present, the list of devices to ignore when |
| 93 | * the probe command is issued is represented by a 1D array of addresses. |
| 94 | * When multiple buses are present, the list is an array of bus-address |
| 95 | * pairs. The following macros take care of this */ |
| 96 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | #if defined(CONFIG_SYS_I2C_NOPROBES) |
Heiko Schocher | 9a2accb | 2012-10-25 10:32:14 +0200 | [diff] [blame] | 98 | #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 99 | static struct |
| 100 | { |
| 101 | uchar bus; |
| 102 | uchar addr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | } i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 104 | #define GET_BUS_NUM i2c_get_bus_num() |
| 105 | #define COMPARE_BUS(b,i) (i2c_no_probes[(i)].bus == (b)) |
| 106 | #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)].addr == (a)) |
| 107 | #define NO_PROBE_ADDR(i) i2c_no_probes[(i)].addr |
| 108 | #else /* single bus */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 109 | static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 110 | #define GET_BUS_NUM 0 |
| 111 | #define COMPARE_BUS(b,i) ((b) == 0) /* Make compiler happy */ |
| 112 | #define COMPARE_ADDR(a,i) (i2c_no_probes[(i)] == (a)) |
| 113 | #define NO_PROBE_ADDR(i) i2c_no_probes[(i)] |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 114 | #endif /* defined(CONFIG_SYS_I2C) */ |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 115 | #endif |
| 116 | |
Frans Meulenbroeks | a266fe9 | 2010-03-26 09:46:40 +0100 | [diff] [blame] | 117 | #define DISP_LINE_LEN 16 |
| 118 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 119 | /** |
| 120 | * i2c_init_board() - Board-specific I2C bus init |
| 121 | * |
| 122 | * This function is the default no-op implementation of I2C bus |
| 123 | * initialization. This function can be overriden by board-specific |
| 124 | * implementation if needed. |
| 125 | */ |
Marek Vasut | 2515d84 | 2012-11-12 14:34:25 +0000 | [diff] [blame] | 126 | __weak |
| 127 | void i2c_init_board(void) |
Stefan Bigler | c649dda | 2011-04-08 16:24:08 +0200 | [diff] [blame] | 128 | { |
Stefan Bigler | c649dda | 2011-04-08 16:24:08 +0200 | [diff] [blame] | 129 | } |
Stefan Bigler | c649dda | 2011-04-08 16:24:08 +0200 | [diff] [blame] | 130 | |
Peter Tyser | 655b34a | 2009-04-18 22:34:01 -0500 | [diff] [blame] | 131 | /* TODO: Implement architecture-specific get/set functions */ |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * i2c_get_bus_speed() - Return I2C bus speed |
| 135 | * |
| 136 | * This function is the default implementation of function for retrieveing |
| 137 | * the current I2C bus speed in Hz. |
| 138 | * |
| 139 | * A driver implementing runtime switching of I2C bus speed must override |
| 140 | * this function to report the speed correctly. Simple or legacy drivers |
| 141 | * can use this fallback. |
| 142 | * |
| 143 | * Returns I2C bus speed in Hz. |
| 144 | */ |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 145 | #if !defined(CONFIG_SYS_I2C) |
| 146 | /* |
| 147 | * TODO: Implement architecture-specific get/set functions |
| 148 | * Should go away, if we switched completely to new multibus support |
| 149 | */ |
Marek Vasut | 2515d84 | 2012-11-12 14:34:25 +0000 | [diff] [blame] | 150 | __weak |
| 151 | unsigned int i2c_get_bus_speed(void) |
Peter Tyser | 655b34a | 2009-04-18 22:34:01 -0500 | [diff] [blame] | 152 | { |
| 153 | return CONFIG_SYS_I2C_SPEED; |
| 154 | } |
Peter Tyser | 655b34a | 2009-04-18 22:34:01 -0500 | [diff] [blame] | 155 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 156 | /** |
| 157 | * i2c_set_bus_speed() - Configure I2C bus speed |
| 158 | * @speed: Newly set speed of the I2C bus in Hz |
| 159 | * |
| 160 | * This function is the default implementation of function for setting |
| 161 | * the I2C bus speed in Hz. |
| 162 | * |
| 163 | * A driver implementing runtime switching of I2C bus speed must override |
| 164 | * this function to report the speed correctly. Simple or legacy drivers |
| 165 | * can use this fallback. |
| 166 | * |
| 167 | * Returns zero on success, negative value on error. |
| 168 | */ |
Marek Vasut | 2515d84 | 2012-11-12 14:34:25 +0000 | [diff] [blame] | 169 | __weak |
| 170 | int i2c_set_bus_speed(unsigned int speed) |
Peter Tyser | 655b34a | 2009-04-18 22:34:01 -0500 | [diff] [blame] | 171 | { |
| 172 | if (speed != CONFIG_SYS_I2C_SPEED) |
| 173 | return -1; |
| 174 | |
| 175 | return 0; |
| 176 | } |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 177 | #endif |
Peter Tyser | 655b34a | 2009-04-18 22:34:01 -0500 | [diff] [blame] | 178 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 179 | /** |
| 180 | * get_alen() - Small parser helper function to get address length |
| 181 | * |
| 182 | * Returns the address length. |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 183 | */ |
| 184 | static uint get_alen(char *arg) |
| 185 | { |
| 186 | int j; |
| 187 | int alen; |
| 188 | |
| 189 | alen = 1; |
| 190 | for (j = 0; j < 8; j++) { |
| 191 | if (arg[j] == '.') { |
| 192 | alen = arg[j+1] - '0'; |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 193 | break; |
| 194 | } else if (arg[j] == '\0') |
| 195 | break; |
| 196 | } |
| 197 | return alen; |
| 198 | } |
| 199 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 200 | /** |
| 201 | * do_i2c_read() - Handle the "i2c read" command-line command |
| 202 | * @cmdtp: Command data struct pointer |
| 203 | * @flag: Command flag |
| 204 | * @argc: Command-line argument count |
| 205 | * @argv: Array of command-line arguments |
| 206 | * |
| 207 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 208 | * on error. |
| 209 | * |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 210 | * Syntax: |
| 211 | * i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr} |
| 212 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 213 | static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 214 | { |
| 215 | u_char chip; |
| 216 | uint devaddr, alen, length; |
| 217 | u_char *memaddr; |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 218 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 219 | if (argc != 5) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 220 | return CMD_RET_USAGE; |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 221 | |
| 222 | /* |
| 223 | * I2C chip address |
| 224 | */ |
| 225 | chip = simple_strtoul(argv[1], NULL, 16); |
| 226 | |
| 227 | /* |
| 228 | * I2C data address within the chip. This can be 1 or |
| 229 | * 2 bytes long. Some day it might be 3 bytes long :-). |
| 230 | */ |
| 231 | devaddr = simple_strtoul(argv[2], NULL, 16); |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 232 | alen = get_alen(argv[2]); |
Reinhard Meyer | 7a92e53 | 2010-08-25 14:41:16 +0200 | [diff] [blame] | 233 | if (alen > 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 234 | return CMD_RET_USAGE; |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * Length is the number of objects, not number of bytes. |
| 238 | */ |
| 239 | length = simple_strtoul(argv[3], NULL, 16); |
| 240 | |
| 241 | /* |
| 242 | * memaddr is the address where to store things in memory |
| 243 | */ |
| 244 | memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16); |
| 245 | |
| 246 | if (i2c_read(chip, devaddr, alen, memaddr, length) != 0) { |
| 247 | puts ("Error reading the chip.\n"); |
| 248 | return 1; |
| 249 | } |
| 250 | return 0; |
| 251 | } |
| 252 | |
York Sun | ff5d2dc | 2012-09-16 08:02:30 +0000 | [diff] [blame] | 253 | static int do_i2c_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 254 | { |
| 255 | u_char chip; |
| 256 | uint devaddr, alen, length; |
| 257 | u_char *memaddr; |
| 258 | |
| 259 | if (argc != 5) |
| 260 | return cmd_usage(cmdtp); |
| 261 | |
| 262 | /* |
| 263 | * memaddr is the address where to store things in memory |
| 264 | */ |
| 265 | memaddr = (u_char *)simple_strtoul(argv[1], NULL, 16); |
| 266 | |
| 267 | /* |
| 268 | * I2C chip address |
| 269 | */ |
| 270 | chip = simple_strtoul(argv[2], NULL, 16); |
| 271 | |
| 272 | /* |
| 273 | * I2C data address within the chip. This can be 1 or |
| 274 | * 2 bytes long. Some day it might be 3 bytes long :-). |
| 275 | */ |
| 276 | devaddr = simple_strtoul(argv[3], NULL, 16); |
| 277 | alen = get_alen(argv[3]); |
| 278 | if (alen > 3) |
| 279 | return cmd_usage(cmdtp); |
| 280 | |
| 281 | /* |
| 282 | * Length is the number of objects, not number of bytes. |
| 283 | */ |
| 284 | length = simple_strtoul(argv[4], NULL, 16); |
| 285 | |
| 286 | while (length-- > 0) { |
| 287 | if (i2c_write(chip, devaddr++, alen, memaddr++, 1) != 0) { |
| 288 | puts("Error writing to the chip.\n"); |
| 289 | return 1; |
| 290 | } |
| 291 | /* |
| 292 | * No write delay with FRAM devices. |
| 293 | */ |
| 294 | #if !defined(CONFIG_SYS_I2C_FRAM) |
| 295 | udelay(11000); |
| 296 | #endif |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 301 | /** |
| 302 | * do_i2c_md() - Handle the "i2c md" command-line command |
| 303 | * @cmdtp: Command data struct pointer |
| 304 | * @flag: Command flag |
| 305 | * @argc: Command-line argument count |
| 306 | * @argv: Array of command-line arguments |
| 307 | * |
| 308 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 309 | * on error. |
| 310 | * |
Frans Meulenbroeks | 4a8cf33 | 2010-03-26 09:46:39 +0100 | [diff] [blame] | 311 | * Syntax: |
| 312 | * i2c md {i2c_chip} {addr}{.0, .1, .2} {len} |
| 313 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 314 | static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 315 | { |
| 316 | u_char chip; |
| 317 | uint addr, alen, length; |
| 318 | int j, nbytes, linebytes; |
| 319 | |
| 320 | /* We use the last specified parameters, unless new ones are |
| 321 | * entered. |
| 322 | */ |
| 323 | chip = i2c_dp_last_chip; |
| 324 | addr = i2c_dp_last_addr; |
| 325 | alen = i2c_dp_last_alen; |
| 326 | length = i2c_dp_last_length; |
| 327 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 328 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 329 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 330 | |
| 331 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 332 | /* |
| 333 | * New command specified. |
| 334 | */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 335 | |
| 336 | /* |
| 337 | * I2C chip address |
| 338 | */ |
| 339 | chip = simple_strtoul(argv[1], NULL, 16); |
| 340 | |
| 341 | /* |
| 342 | * I2C data address within the chip. This can be 1 or |
| 343 | * 2 bytes long. Some day it might be 3 bytes long :-). |
| 344 | */ |
| 345 | addr = simple_strtoul(argv[2], NULL, 16); |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 346 | alen = get_alen(argv[2]); |
Reinhard Meyer | 7a92e53 | 2010-08-25 14:41:16 +0200 | [diff] [blame] | 347 | if (alen > 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 348 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * If another parameter, it is the length to display. |
| 352 | * Length is the number of objects, not number of bytes. |
| 353 | */ |
| 354 | if (argc > 3) |
| 355 | length = simple_strtoul(argv[3], NULL, 16); |
| 356 | } |
| 357 | |
| 358 | /* |
| 359 | * Print the lines. |
| 360 | * |
| 361 | * We buffer all read data, so we can make sure data is read only |
| 362 | * once. |
| 363 | */ |
| 364 | nbytes = length; |
| 365 | do { |
| 366 | unsigned char linebuf[DISP_LINE_LEN]; |
| 367 | unsigned char *cp; |
| 368 | |
| 369 | linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; |
| 370 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 371 | if (i2c_read(chip, addr, alen, linebuf, linebytes) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 372 | puts ("Error reading the chip.\n"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 373 | else { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 374 | printf("%04x:", addr); |
| 375 | cp = linebuf; |
| 376 | for (j=0; j<linebytes; j++) { |
| 377 | printf(" %02x", *cp++); |
| 378 | addr++; |
| 379 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 380 | puts (" "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 381 | cp = linebuf; |
| 382 | for (j=0; j<linebytes; j++) { |
| 383 | if ((*cp < 0x20) || (*cp > 0x7e)) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 384 | puts ("."); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 385 | else |
| 386 | printf("%c", *cp); |
| 387 | cp++; |
| 388 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 389 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 390 | } |
| 391 | nbytes -= linebytes; |
| 392 | } while (nbytes > 0); |
| 393 | |
| 394 | i2c_dp_last_chip = chip; |
| 395 | i2c_dp_last_addr = addr; |
| 396 | i2c_dp_last_alen = alen; |
| 397 | i2c_dp_last_length = length; |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 402 | /** |
| 403 | * do_i2c_mw() - Handle the "i2c mw" command-line command |
| 404 | * @cmdtp: Command data struct pointer |
| 405 | * @flag: Command flag |
| 406 | * @argc: Command-line argument count |
| 407 | * @argv: Array of command-line arguments |
| 408 | * |
| 409 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 410 | * on error. |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 411 | * |
| 412 | * Syntax: |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 413 | * i2c mw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}] |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 414 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 415 | static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 416 | { |
| 417 | uchar chip; |
| 418 | ulong addr; |
| 419 | uint alen; |
| 420 | uchar byte; |
| 421 | int count; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 422 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 423 | if ((argc < 4) || (argc > 5)) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 424 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 425 | |
| 426 | /* |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 427 | * Chip is always specified. |
| 428 | */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 429 | chip = simple_strtoul(argv[1], NULL, 16); |
| 430 | |
| 431 | /* |
| 432 | * Address is always specified. |
| 433 | */ |
| 434 | addr = simple_strtoul(argv[2], NULL, 16); |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 435 | alen = get_alen(argv[2]); |
Reinhard Meyer | 7a92e53 | 2010-08-25 14:41:16 +0200 | [diff] [blame] | 436 | if (alen > 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 437 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 438 | |
| 439 | /* |
| 440 | * Value to write is always specified. |
| 441 | */ |
| 442 | byte = simple_strtoul(argv[3], NULL, 16); |
| 443 | |
| 444 | /* |
| 445 | * Optional count |
| 446 | */ |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 447 | if (argc == 5) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 448 | count = simple_strtoul(argv[4], NULL, 16); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 449 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 450 | count = 1; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 451 | |
| 452 | while (count-- > 0) { |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 453 | if (i2c_write(chip, addr++, alen, &byte, 1) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 454 | puts ("Error writing the chip.\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 455 | /* |
| 456 | * Wait for the write to complete. The write can take |
| 457 | * up to 10mSec (we allow a little more time). |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 458 | */ |
| d4f5c72 | 2005-08-12 21:16:13 +0200 | [diff] [blame] | 459 | /* |
| 460 | * No write delay with FRAM devices. |
| 461 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 462 | #if !defined(CONFIG_SYS_I2C_FRAM) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 463 | udelay(11000); |
| d4f5c72 | 2005-08-12 21:16:13 +0200 | [diff] [blame] | 464 | #endif |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 467 | return 0; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 470 | /** |
| 471 | * do_i2c_crc() - Handle the "i2c crc32" command-line command |
| 472 | * @cmdtp: Command data struct pointer |
| 473 | * @flag: Command flag |
| 474 | * @argc: Command-line argument count |
| 475 | * @argv: Array of command-line arguments |
| 476 | * |
| 477 | * Calculate a CRC on memory |
| 478 | * |
| 479 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 480 | * on error. |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 481 | * |
| 482 | * Syntax: |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 483 | * i2c crc32 {i2c_chip} {addr}{.0, .1, .2} {count} |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 484 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 485 | static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 486 | { |
| 487 | uchar chip; |
| 488 | ulong addr; |
| 489 | uint alen; |
| 490 | int count; |
| 491 | uchar byte; |
| 492 | ulong crc; |
| 493 | ulong err; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 494 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 495 | if (argc < 4) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 496 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 497 | |
| 498 | /* |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 499 | * Chip is always specified. |
| 500 | */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 501 | chip = simple_strtoul(argv[1], NULL, 16); |
| 502 | |
| 503 | /* |
| 504 | * Address is always specified. |
| 505 | */ |
| 506 | addr = simple_strtoul(argv[2], NULL, 16); |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 507 | alen = get_alen(argv[2]); |
Reinhard Meyer | 7a92e53 | 2010-08-25 14:41:16 +0200 | [diff] [blame] | 508 | if (alen > 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 509 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 510 | |
| 511 | /* |
| 512 | * Count is always specified |
| 513 | */ |
| 514 | count = simple_strtoul(argv[3], NULL, 16); |
| 515 | |
| 516 | printf ("CRC32 for %08lx ... %08lx ==> ", addr, addr + count - 1); |
| 517 | /* |
| 518 | * CRC a byte at a time. This is going to be slooow, but hey, the |
| 519 | * memories are small and slow too so hopefully nobody notices. |
| 520 | */ |
| 521 | crc = 0; |
| 522 | err = 0; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 523 | while (count-- > 0) { |
| 524 | if (i2c_read(chip, addr, alen, &byte, 1) != 0) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 525 | err++; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 526 | crc = crc32 (crc, &byte, 1); |
| 527 | addr++; |
| 528 | } |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 529 | if (err > 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 530 | puts ("Error reading the chip,\n"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 531 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 532 | printf ("%08lx\n", crc); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 537 | /** |
| 538 | * mod_i2c_mem() - Handle the "i2c mm" and "i2c nm" command-line command |
| 539 | * @cmdtp: Command data struct pointer |
| 540 | * @flag: Command flag |
| 541 | * @argc: Command-line argument count |
| 542 | * @argv: Array of command-line arguments |
| 543 | * |
| 544 | * Modify memory. |
| 545 | * |
| 546 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 547 | * on error. |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 548 | * |
| 549 | * Syntax: |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 550 | * i2c mm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2} |
| 551 | * i2c nm{.b, .w, .l} {i2c_chip} {addr}{.0, .1, .2} |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 552 | */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 553 | static int |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 554 | mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 555 | { |
| 556 | uchar chip; |
| 557 | ulong addr; |
| 558 | uint alen; |
| 559 | ulong data; |
| 560 | int size = 1; |
| 561 | int nbytes; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 562 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 563 | if (argc != 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 564 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 565 | |
| 566 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 567 | reset_cmd_timeout(); /* got a good command to get here */ |
| 568 | #endif |
| 569 | /* |
| 570 | * We use the last specified parameters, unless new ones are |
| 571 | * entered. |
| 572 | */ |
| 573 | chip = i2c_mm_last_chip; |
| 574 | addr = i2c_mm_last_addr; |
| 575 | alen = i2c_mm_last_alen; |
| 576 | |
| 577 | if ((flag & CMD_FLAG_REPEAT) == 0) { |
| 578 | /* |
| 579 | * New command specified. Check for a size specification. |
| 580 | * Defaults to byte if no or incorrect specification. |
| 581 | */ |
| 582 | size = cmd_get_data_size(argv[0], 1); |
| 583 | |
| 584 | /* |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 585 | * Chip is always specified. |
| 586 | */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 587 | chip = simple_strtoul(argv[1], NULL, 16); |
| 588 | |
| 589 | /* |
| 590 | * Address is always specified. |
| 591 | */ |
| 592 | addr = simple_strtoul(argv[2], NULL, 16); |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 593 | alen = get_alen(argv[2]); |
Reinhard Meyer | 7a92e53 | 2010-08-25 14:41:16 +0200 | [diff] [blame] | 594 | if (alen > 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 595 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /* |
| 599 | * Print the address, followed by value. Then accept input for |
| 600 | * the next value. A non-converted value exits. |
| 601 | */ |
| 602 | do { |
| 603 | printf("%08lx:", addr); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 604 | if (i2c_read(chip, addr, alen, (uchar *)&data, size) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 605 | puts ("\nError reading the chip,\n"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 606 | else { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 607 | data = cpu_to_be32(data); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 608 | if (size == 1) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 609 | printf(" %02lx", (data >> 24) & 0x000000FF); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 610 | else if (size == 2) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 611 | printf(" %04lx", (data >> 16) & 0x0000FFFF); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 612 | else |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 613 | printf(" %08lx", data); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | nbytes = readline (" ? "); |
| 617 | if (nbytes == 0) { |
| 618 | /* |
| 619 | * <CR> pressed as only input, don't modify current |
| 620 | * location and move to next. |
| 621 | */ |
| 622 | if (incrflag) |
| 623 | addr += size; |
| 624 | nbytes = size; |
| 625 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 626 | reset_cmd_timeout(); /* good enough to not time out */ |
| 627 | #endif |
| 628 | } |
| 629 | #ifdef CONFIG_BOOT_RETRY_TIME |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 630 | else if (nbytes == -2) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 631 | break; /* timed out, exit the command */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 632 | #endif |
| 633 | else { |
| 634 | char *endp; |
| 635 | |
| 636 | data = simple_strtoul(console_buffer, &endp, 16); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 637 | if (size == 1) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 638 | data = data << 24; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 639 | else if (size == 2) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 640 | data = data << 16; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 641 | data = be32_to_cpu(data); |
| 642 | nbytes = endp - console_buffer; |
| 643 | if (nbytes) { |
| 644 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 645 | /* |
| 646 | * good enough to not time out |
| 647 | */ |
| 648 | reset_cmd_timeout(); |
| 649 | #endif |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 650 | if (i2c_write(chip, addr, alen, (uchar *)&data, size) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 651 | puts ("Error writing the chip.\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 652 | #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS |
| 653 | udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000); |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 654 | #endif |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 655 | if (incrflag) |
| 656 | addr += size; |
| 657 | } |
| 658 | } |
| 659 | } while (nbytes); |
| 660 | |
Peter Tyser | 0800707 | 2008-08-15 14:36:32 -0500 | [diff] [blame] | 661 | i2c_mm_last_chip = chip; |
| 662 | i2c_mm_last_addr = addr; |
| 663 | i2c_mm_last_alen = alen; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 668 | /** |
| 669 | * do_i2c_probe() - Handle the "i2c probe" command-line command |
| 670 | * @cmdtp: Command data struct pointer |
| 671 | * @flag: Command flag |
| 672 | * @argc: Command-line argument count |
| 673 | * @argv: Array of command-line arguments |
| 674 | * |
| 675 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 676 | * on error. |
| 677 | * |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 678 | * Syntax: |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 679 | * i2c probe {addr} |
| 680 | * |
| 681 | * Returns zero (success) if one or more I2C devices was found |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 682 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 683 | static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 684 | { |
| 685 | int j; |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 686 | int addr = -1; |
| 687 | int found = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 688 | #if defined(CONFIG_SYS_I2C_NOPROBES) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 689 | int k, skip; |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 690 | unsigned int bus = GET_BUS_NUM; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 691 | #endif /* NOPROBES */ |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 692 | |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 693 | if (argc == 2) |
| 694 | addr = simple_strtol(argv[1], 0, 16); |
| 695 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 696 | puts ("Valid chip addresses:"); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 697 | for (j = 0; j < 128; j++) { |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 698 | if ((0 <= addr) && (j != addr)) |
| 699 | continue; |
| 700 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 701 | #if defined(CONFIG_SYS_I2C_NOPROBES) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 702 | skip = 0; |
Axel Lin | cfb25cc | 2013-06-22 21:56:35 +0800 | [diff] [blame] | 703 | for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) { |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 704 | if (COMPARE_BUS(bus, k) && COMPARE_ADDR(j, k)) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 705 | skip = 1; |
| 706 | break; |
| 707 | } |
| 708 | } |
| 709 | if (skip) |
| 710 | continue; |
| 711 | #endif |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 712 | if (i2c_probe(j) == 0) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 713 | printf(" %02X", j); |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 714 | found++; |
| 715 | } |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 716 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 717 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 718 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 719 | #if defined(CONFIG_SYS_I2C_NOPROBES) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 720 | puts ("Excluded chip addresses:"); |
Axel Lin | cfb25cc | 2013-06-22 21:56:35 +0800 | [diff] [blame] | 721 | for (k = 0; k < ARRAY_SIZE(i2c_no_probes); k++) { |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 722 | if (COMPARE_BUS(bus,k)) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 723 | printf(" %02X", NO_PROBE_ADDR(k)); |
| 724 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 725 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 726 | #endif |
| 727 | |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 728 | return (0 == found); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 731 | /** |
| 732 | * do_i2c_loop() - Handle the "i2c loop" command-line command |
| 733 | * @cmdtp: Command data struct pointer |
| 734 | * @flag: Command flag |
| 735 | * @argc: Command-line argument count |
| 736 | * @argv: Array of command-line arguments |
| 737 | * |
| 738 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 739 | * on error. |
| 740 | * |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 741 | * Syntax: |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 742 | * i2c loop {i2c_chip} {addr}{.0, .1, .2} [{length}] [{delay}] |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 743 | * {length} - Number of bytes to read |
| 744 | * {delay} - A DECIMAL number and defaults to 1000 uSec |
| 745 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 746 | static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 747 | { |
| 748 | u_char chip; |
| 749 | ulong alen; |
| 750 | uint addr; |
| 751 | uint length; |
| 752 | u_char bytes[16]; |
| 753 | int delay; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 754 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 755 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 756 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 757 | |
| 758 | /* |
| 759 | * Chip is always specified. |
| 760 | */ |
| 761 | chip = simple_strtoul(argv[1], NULL, 16); |
| 762 | |
| 763 | /* |
| 764 | * Address is always specified. |
| 765 | */ |
| 766 | addr = simple_strtoul(argv[2], NULL, 16); |
Frans Meulenbroeks | 2c0dc99 | 2010-03-26 09:46:41 +0100 | [diff] [blame] | 767 | alen = get_alen(argv[2]); |
Reinhard Meyer | 7a92e53 | 2010-08-25 14:41:16 +0200 | [diff] [blame] | 768 | if (alen > 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 769 | return CMD_RET_USAGE; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 770 | |
| 771 | /* |
| 772 | * Length is the number of objects, not number of bytes. |
| 773 | */ |
| 774 | length = 1; |
| 775 | length = simple_strtoul(argv[3], NULL, 16); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 776 | if (length > sizeof(bytes)) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 777 | length = sizeof(bytes); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * The delay time (uSec) is optional. |
| 781 | */ |
| 782 | delay = 1000; |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 783 | if (argc > 3) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 784 | delay = simple_strtoul(argv[4], NULL, 10); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 785 | /* |
| 786 | * Run the loop... |
| 787 | */ |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 788 | while (1) { |
| 789 | if (i2c_read(chip, addr, alen, bytes, length) != 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 790 | puts ("Error reading the chip.\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 791 | udelay(delay); |
| 792 | } |
| 793 | |
| 794 | /* NOTREACHED */ |
| 795 | return 0; |
| 796 | } |
| 797 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 798 | /* |
| 799 | * The SDRAM command is separately configured because many |
| 800 | * (most?) embedded boards don't use SDRAM DIMMs. |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 801 | * |
| 802 | * FIXME: Document and probably move elsewhere! |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 803 | */ |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 804 | #if defined(CONFIG_CMD_SDRAM) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 805 | static void print_ddr2_tcyc (u_char const b) |
| 806 | { |
| 807 | printf ("%d.", (b >> 4) & 0x0F); |
| 808 | switch (b & 0x0F) { |
| 809 | case 0x0: |
| 810 | case 0x1: |
| 811 | case 0x2: |
| 812 | case 0x3: |
| 813 | case 0x4: |
| 814 | case 0x5: |
| 815 | case 0x6: |
| 816 | case 0x7: |
| 817 | case 0x8: |
| 818 | case 0x9: |
| 819 | printf ("%d ns\n", b & 0x0F); |
| 820 | break; |
| 821 | case 0xA: |
| 822 | puts ("25 ns\n"); |
| 823 | break; |
| 824 | case 0xB: |
| 825 | puts ("33 ns\n"); |
| 826 | break; |
| 827 | case 0xC: |
| 828 | puts ("66 ns\n"); |
| 829 | break; |
| 830 | case 0xD: |
| 831 | puts ("75 ns\n"); |
| 832 | break; |
| 833 | default: |
| 834 | puts ("?? ns\n"); |
| 835 | break; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | static void decode_bits (u_char const b, char const *str[], int const do_once) |
| 840 | { |
| 841 | u_char mask; |
| 842 | |
| 843 | for (mask = 0x80; mask != 0x00; mask >>= 1, ++str) { |
| 844 | if (b & mask) { |
| 845 | puts (*str); |
| 846 | if (do_once) |
| 847 | return; |
| 848 | } |
| 849 | } |
| 850 | } |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * Syntax: |
Peter Tyser | 0f89c54 | 2009-04-18 22:34:03 -0500 | [diff] [blame] | 854 | * i2c sdram {i2c_chip} |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 855 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 856 | static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 857 | { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 858 | enum { unknown, EDO, SDRAM, DDR2 } type; |
| 859 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 860 | u_char chip; |
| 861 | u_char data[128]; |
| 862 | u_char cksum; |
| 863 | int j; |
| 864 | |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 865 | static const char *decode_CAS_DDR2[] = { |
| 866 | " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD" |
| 867 | }; |
| 868 | |
| 869 | static const char *decode_CAS_default[] = { |
| 870 | " TBD", " 7", " 6", " 5", " 4", " 3", " 2", " 1" |
| 871 | }; |
| 872 | |
| 873 | static const char *decode_CS_WE_default[] = { |
| 874 | " TBD", " 6", " 5", " 4", " 3", " 2", " 1", " 0" |
| 875 | }; |
| 876 | |
| 877 | static const char *decode_byte21_default[] = { |
| 878 | " TBD (bit 7)\n", |
| 879 | " Redundant row address\n", |
| 880 | " Differential clock input\n", |
| 881 | " Registerd DQMB inputs\n", |
| 882 | " Buffered DQMB inputs\n", |
| 883 | " On-card PLL\n", |
| 884 | " Registered address/control lines\n", |
| 885 | " Buffered address/control lines\n" |
| 886 | }; |
| 887 | |
| 888 | static const char *decode_byte22_DDR2[] = { |
| 889 | " TBD (bit 7)\n", |
| 890 | " TBD (bit 6)\n", |
| 891 | " TBD (bit 5)\n", |
| 892 | " TBD (bit 4)\n", |
| 893 | " TBD (bit 3)\n", |
| 894 | " Supports partial array self refresh\n", |
| 895 | " Supports 50 ohm ODT\n", |
| 896 | " Supports weak driver\n" |
| 897 | }; |
| 898 | |
| 899 | static const char *decode_row_density_DDR2[] = { |
| 900 | "512 MiB", "256 MiB", "128 MiB", "16 GiB", |
| 901 | "8 GiB", "4 GiB", "2 GiB", "1 GiB" |
| 902 | }; |
| 903 | |
| 904 | static const char *decode_row_density_default[] = { |
| 905 | "512 MiB", "256 MiB", "128 MiB", "64 MiB", |
| 906 | "32 MiB", "16 MiB", "8 MiB", "4 MiB" |
| 907 | }; |
| 908 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 909 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 910 | return CMD_RET_USAGE; |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 911 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 912 | /* |
| 913 | * Chip is always specified. |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 914 | */ |
| 915 | chip = simple_strtoul (argv[1], NULL, 16); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 916 | |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 917 | if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 918 | puts ("No SDRAM Serial Presence Detect found.\n"); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 919 | return 1; |
| 920 | } |
| 921 | |
| 922 | cksum = 0; |
| 923 | for (j = 0; j < 63; j++) { |
| 924 | cksum += data[j]; |
| 925 | } |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 926 | if (cksum != data[63]) { |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 927 | printf ("WARNING: Configuration data checksum failure:\n" |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 928 | " is 0x%02x, calculated 0x%02x\n", data[63], cksum); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 929 | } |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 930 | printf ("SPD data revision %d.%d\n", |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 931 | (data[62] >> 4) & 0x0F, data[62] & 0x0F); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 932 | printf ("Bytes used 0x%02X\n", data[0]); |
| 933 | printf ("Serial memory size 0x%02X\n", 1 << data[1]); |
| 934 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 935 | puts ("Memory type "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 936 | switch (data[2]) { |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 937 | case 2: |
| 938 | type = EDO; |
| 939 | puts ("EDO\n"); |
| 940 | break; |
| 941 | case 4: |
| 942 | type = SDRAM; |
| 943 | puts ("SDRAM\n"); |
| 944 | break; |
| 945 | case 8: |
| 946 | type = DDR2; |
| 947 | puts ("DDR2\n"); |
| 948 | break; |
| 949 | default: |
| 950 | type = unknown; |
| 951 | puts ("unknown\n"); |
| 952 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 953 | } |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 954 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 955 | puts ("Row address bits "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 956 | if ((data[3] & 0x00F0) == 0) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 957 | printf ("%d\n", data[3] & 0x0F); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 958 | else |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 959 | printf ("%d/%d\n", data[3] & 0x0F, (data[3] >> 4) & 0x0F); |
| 960 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 961 | puts ("Column address bits "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 962 | if ((data[4] & 0x00F0) == 0) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 963 | printf ("%d\n", data[4] & 0x0F); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 964 | else |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 965 | printf ("%d/%d\n", data[4] & 0x0F, (data[4] >> 4) & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 966 | |
| 967 | switch (type) { |
| 968 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 969 | printf ("Number of ranks %d\n", |
| 970 | (data[5] & 0x07) + 1); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 971 | break; |
| 972 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 973 | printf ("Module rows %d\n", data[5]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 974 | break; |
| 975 | } |
| 976 | |
| 977 | switch (type) { |
| 978 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 979 | printf ("Module data width %d bits\n", data[6]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 980 | break; |
| 981 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 982 | printf ("Module data width %d bits\n", |
| 983 | (data[7] << 8) | data[6]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 984 | break; |
| 985 | } |
| 986 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 987 | puts ("Interface signal levels "); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 988 | switch(data[8]) { |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 989 | case 0: puts ("TTL 5.0 V\n"); break; |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 990 | case 1: puts ("LVTTL\n"); break; |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 991 | case 2: puts ("HSTL 1.5 V\n"); break; |
| 992 | case 3: puts ("SSTL 3.3 V\n"); break; |
| 993 | case 4: puts ("SSTL 2.5 V\n"); break; |
| 994 | case 5: puts ("SSTL 1.8 V\n"); break; |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 995 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 996 | } |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 997 | |
| 998 | switch (type) { |
| 999 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1000 | printf ("SDRAM cycle time "); |
| 1001 | print_ddr2_tcyc (data[9]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1002 | break; |
| 1003 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1004 | printf ("SDRAM cycle time %d.%d ns\n", |
| 1005 | (data[9] >> 4) & 0x0F, data[9] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | switch (type) { |
| 1010 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1011 | printf ("SDRAM access time 0.%d%d ns\n", |
| 1012 | (data[10] >> 4) & 0x0F, data[10] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1013 | break; |
| 1014 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1015 | printf ("SDRAM access time %d.%d ns\n", |
| 1016 | (data[10] >> 4) & 0x0F, data[10] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1017 | break; |
| 1018 | } |
| 1019 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1020 | puts ("EDC configuration "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1021 | switch (data[11]) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1022 | case 0: puts ("None\n"); break; |
| 1023 | case 1: puts ("Parity\n"); break; |
| 1024 | case 2: puts ("ECC\n"); break; |
| 1025 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1026 | } |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1027 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1028 | if ((data[12] & 0x80) == 0) |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1029 | puts ("No self refresh, rate "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1030 | else |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1031 | puts ("Self refresh, rate "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1032 | |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1033 | switch(data[12] & 0x7F) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1034 | case 0: puts ("15.625 us\n"); break; |
| 1035 | case 1: puts ("3.9 us\n"); break; |
| 1036 | case 2: puts ("7.8 us\n"); break; |
| 1037 | case 3: puts ("31.3 us\n"); break; |
| 1038 | case 4: puts ("62.5 us\n"); break; |
| 1039 | case 5: puts ("125 us\n"); break; |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1040 | default: puts ("unknown\n"); break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1041 | } |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1042 | |
| 1043 | switch (type) { |
| 1044 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1045 | printf ("SDRAM width (primary) %d\n", data[13]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1046 | break; |
| 1047 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1048 | printf ("SDRAM width (primary) %d\n", data[13] & 0x7F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1049 | if ((data[13] & 0x80) != 0) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1050 | printf (" (second bank) %d\n", |
| 1051 | 2 * (data[13] & 0x7F)); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1052 | } |
| 1053 | break; |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1054 | } |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1055 | |
| 1056 | switch (type) { |
| 1057 | case DDR2: |
| 1058 | if (data[14] != 0) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1059 | printf ("EDC width %d\n", data[14]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1060 | break; |
| 1061 | default: |
| 1062 | if (data[14] != 0) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1063 | printf ("EDC width %d\n", |
| 1064 | data[14] & 0x7F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1065 | |
| 1066 | if ((data[14] & 0x80) != 0) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1067 | printf (" (second bank) %d\n", |
| 1068 | 2 * (data[14] & 0x7F)); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | break; |
| 1072 | } |
| 1073 | |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1074 | if (DDR2 != type) { |
| 1075 | printf ("Min clock delay, back-to-back random column addresses " |
| 1076 | "%d\n", data[15]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1077 | } |
| 1078 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1079 | puts ("Burst length(s) "); |
| 1080 | if (data[16] & 0x80) puts (" Page"); |
| 1081 | if (data[16] & 0x08) puts (" 8"); |
| 1082 | if (data[16] & 0x04) puts (" 4"); |
| 1083 | if (data[16] & 0x02) puts (" 2"); |
| 1084 | if (data[16] & 0x01) puts (" 1"); |
| 1085 | putc ('\n'); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1086 | printf ("Number of banks %d\n", data[17]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1087 | |
| 1088 | switch (type) { |
| 1089 | case DDR2: |
| 1090 | puts ("CAS latency(s) "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1091 | decode_bits (data[18], decode_CAS_DDR2, 0); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1092 | putc ('\n'); |
| 1093 | break; |
| 1094 | default: |
| 1095 | puts ("CAS latency(s) "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1096 | decode_bits (data[18], decode_CAS_default, 0); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1097 | putc ('\n'); |
| 1098 | break; |
| 1099 | } |
| 1100 | |
| 1101 | if (DDR2 != type) { |
| 1102 | puts ("CS latency(s) "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1103 | decode_bits (data[19], decode_CS_WE_default, 0); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1104 | putc ('\n'); |
| 1105 | } |
| 1106 | |
| 1107 | if (DDR2 != type) { |
| 1108 | puts ("WE latency(s) "); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1109 | decode_bits (data[20], decode_CS_WE_default, 0); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1110 | putc ('\n'); |
| 1111 | } |
| 1112 | |
| 1113 | switch (type) { |
| 1114 | case DDR2: |
| 1115 | puts ("Module attributes:\n"); |
| 1116 | if (data[21] & 0x80) |
| 1117 | puts (" TBD (bit 7)\n"); |
| 1118 | if (data[21] & 0x40) |
| 1119 | puts (" Analysis probe installed\n"); |
| 1120 | if (data[21] & 0x20) |
| 1121 | puts (" TBD (bit 5)\n"); |
| 1122 | if (data[21] & 0x10) |
| 1123 | puts (" FET switch external enable\n"); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1124 | printf (" %d PLLs on DIMM\n", (data[21] >> 2) & 0x03); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1125 | if (data[20] & 0x11) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1126 | printf (" %d active registers on DIMM\n", |
| 1127 | (data[21] & 0x03) + 1); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1128 | } |
| 1129 | break; |
| 1130 | default: |
| 1131 | puts ("Module attributes:\n"); |
| 1132 | if (!data[21]) |
| 1133 | puts (" (none)\n"); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1134 | else |
| 1135 | decode_bits (data[21], decode_byte21_default, 0); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1136 | break; |
| 1137 | } |
| 1138 | |
| 1139 | switch (type) { |
| 1140 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1141 | decode_bits (data[22], decode_byte22_DDR2, 0); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1142 | break; |
| 1143 | default: |
| 1144 | puts ("Device attributes:\n"); |
| 1145 | if (data[22] & 0x80) puts (" TBD (bit 7)\n"); |
| 1146 | if (data[22] & 0x40) puts (" TBD (bit 6)\n"); |
| 1147 | if (data[22] & 0x20) puts (" Upper Vcc tolerance 5%\n"); |
| 1148 | else puts (" Upper Vcc tolerance 10%\n"); |
| 1149 | if (data[22] & 0x10) puts (" Lower Vcc tolerance 5%\n"); |
| 1150 | else puts (" Lower Vcc tolerance 10%\n"); |
| 1151 | if (data[22] & 0x08) puts (" Supports write1/read burst\n"); |
| 1152 | if (data[22] & 0x04) puts (" Supports precharge all\n"); |
| 1153 | if (data[22] & 0x02) puts (" Supports auto precharge\n"); |
| 1154 | if (data[22] & 0x01) puts (" Supports early RAS# precharge\n"); |
| 1155 | break; |
| 1156 | } |
| 1157 | |
| 1158 | switch (type) { |
| 1159 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1160 | printf ("SDRAM cycle time (2nd highest CAS latency) "); |
| 1161 | print_ddr2_tcyc (data[23]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1162 | break; |
| 1163 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1164 | printf ("SDRAM cycle time (2nd highest CAS latency) %d." |
| 1165 | "%d ns\n", (data[23] >> 4) & 0x0F, data[23] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1166 | break; |
| 1167 | } |
| 1168 | |
| 1169 | switch (type) { |
| 1170 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1171 | printf ("SDRAM access from clock (2nd highest CAS latency) 0." |
| 1172 | "%d%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1173 | break; |
| 1174 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1175 | printf ("SDRAM access from clock (2nd highest CAS latency) %d." |
| 1176 | "%d ns\n", (data[24] >> 4) & 0x0F, data[24] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1177 | break; |
| 1178 | } |
| 1179 | |
| 1180 | switch (type) { |
| 1181 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1182 | printf ("SDRAM cycle time (3rd highest CAS latency) "); |
| 1183 | print_ddr2_tcyc (data[25]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1184 | break; |
| 1185 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1186 | printf ("SDRAM cycle time (3rd highest CAS latency) %d." |
| 1187 | "%d ns\n", (data[25] >> 4) & 0x0F, data[25] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1188 | break; |
| 1189 | } |
| 1190 | |
| 1191 | switch (type) { |
| 1192 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1193 | printf ("SDRAM access from clock (3rd highest CAS latency) 0." |
| 1194 | "%d%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1195 | break; |
| 1196 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1197 | printf ("SDRAM access from clock (3rd highest CAS latency) %d." |
| 1198 | "%d ns\n", (data[26] >> 4) & 0x0F, data[26] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1199 | break; |
| 1200 | } |
| 1201 | |
| 1202 | switch (type) { |
| 1203 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1204 | printf ("Minimum row precharge %d.%02d ns\n", |
| 1205 | (data[27] >> 2) & 0x3F, 25 * (data[27] & 0x03)); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1206 | break; |
| 1207 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1208 | printf ("Minimum row precharge %d ns\n", data[27]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | switch (type) { |
| 1213 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1214 | printf ("Row active to row active min %d.%02d ns\n", |
| 1215 | (data[28] >> 2) & 0x3F, 25 * (data[28] & 0x03)); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1216 | break; |
| 1217 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1218 | printf ("Row active to row active min %d ns\n", data[28]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1219 | break; |
| 1220 | } |
| 1221 | |
| 1222 | switch (type) { |
| 1223 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1224 | printf ("RAS to CAS delay min %d.%02d ns\n", |
| 1225 | (data[29] >> 2) & 0x3F, 25 * (data[29] & 0x03)); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1226 | break; |
| 1227 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1228 | printf ("RAS to CAS delay min %d ns\n", data[29]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1229 | break; |
| 1230 | } |
| 1231 | |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1232 | printf ("Minimum RAS pulse width %d ns\n", data[30]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1233 | |
| 1234 | switch (type) { |
| 1235 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1236 | puts ("Density of each row "); |
| 1237 | decode_bits (data[31], decode_row_density_DDR2, 1); |
| 1238 | putc ('\n'); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1239 | break; |
| 1240 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1241 | puts ("Density of each row "); |
| 1242 | decode_bits (data[31], decode_row_density_default, 1); |
| 1243 | putc ('\n'); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | switch (type) { |
| 1248 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1249 | puts ("Command and Address setup "); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1250 | if (data[32] >= 0xA0) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1251 | printf ("1.%d%d ns\n", |
| 1252 | ((data[32] >> 4) & 0x0F) - 10, data[32] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1253 | } else { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1254 | printf ("0.%d%d ns\n", |
| 1255 | ((data[32] >> 4) & 0x0F), data[32] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1256 | } |
| 1257 | break; |
| 1258 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1259 | printf ("Command and Address setup %c%d.%d ns\n", |
| 1260 | (data[32] & 0x80) ? '-' : '+', |
| 1261 | (data[32] >> 4) & 0x07, data[32] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1262 | break; |
| 1263 | } |
| 1264 | |
| 1265 | switch (type) { |
| 1266 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1267 | puts ("Command and Address hold "); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1268 | if (data[33] >= 0xA0) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1269 | printf ("1.%d%d ns\n", |
| 1270 | ((data[33] >> 4) & 0x0F) - 10, data[33] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1271 | } else { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1272 | printf ("0.%d%d ns\n", |
| 1273 | ((data[33] >> 4) & 0x0F), data[33] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1274 | } |
| 1275 | break; |
| 1276 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1277 | printf ("Command and Address hold %c%d.%d ns\n", |
| 1278 | (data[33] & 0x80) ? '-' : '+', |
| 1279 | (data[33] >> 4) & 0x07, data[33] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1280 | break; |
| 1281 | } |
| 1282 | |
| 1283 | switch (type) { |
| 1284 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1285 | printf ("Data signal input setup 0.%d%d ns\n", |
| 1286 | (data[34] >> 4) & 0x0F, data[34] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1287 | break; |
| 1288 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1289 | printf ("Data signal input setup %c%d.%d ns\n", |
| 1290 | (data[34] & 0x80) ? '-' : '+', |
| 1291 | (data[34] >> 4) & 0x07, data[34] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1292 | break; |
| 1293 | } |
| 1294 | |
| 1295 | switch (type) { |
| 1296 | case DDR2: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1297 | printf ("Data signal input hold 0.%d%d ns\n", |
| 1298 | (data[35] >> 4) & 0x0F, data[35] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1299 | break; |
| 1300 | default: |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1301 | printf ("Data signal input hold %c%d.%d ns\n", |
| 1302 | (data[35] & 0x80) ? '-' : '+', |
| 1303 | (data[35] >> 4) & 0x07, data[35] & 0x0F); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1304 | break; |
| 1305 | } |
| 1306 | |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1307 | puts ("Manufacturer's JEDEC ID "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1308 | for (j = 64; j <= 71; j++) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1309 | printf ("%02X ", data[j]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1310 | putc ('\n'); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1311 | printf ("Manufacturing Location %02X\n", data[72]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1312 | puts ("Manufacturer's Part Number "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1313 | for (j = 73; j <= 90; j++) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1314 | printf ("%02X ", data[j]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1315 | putc ('\n'); |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1316 | printf ("Revision Code %02X %02X\n", data[91], data[92]); |
| 1317 | printf ("Manufacturing Date %02X %02X\n", data[93], data[94]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1318 | puts ("Assembly Serial Number "); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1319 | for (j = 95; j <= 98; j++) |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1320 | printf ("%02X ", data[j]); |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1321 | putc ('\n'); |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1322 | |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1323 | if (DDR2 != type) { |
Larry Johnson | 632de06 | 2008-01-11 23:26:18 -0500 | [diff] [blame] | 1324 | printf ("Speed rating PC%d\n", |
| 1325 | data[126] == 0x66 ? 66 : data[126]); |
Larry Johnson | 0df6b84 | 2008-01-10 22:23:39 -0500 | [diff] [blame] | 1326 | } |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1327 | return 0; |
| 1328 | } |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1329 | #endif |
wdenk | 81a8824 | 2002-10-26 15:22:42 +0000 | [diff] [blame] | 1330 | |
Tom Wai-Hong Tam | 735987c | 2012-12-05 14:46:40 +0000 | [diff] [blame] | 1331 | /* |
| 1332 | * Syntax: |
| 1333 | * i2c edid {i2c_chip} |
| 1334 | */ |
| 1335 | #if defined(CONFIG_I2C_EDID) |
| 1336 | int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 1337 | { |
| 1338 | u_char chip; |
| 1339 | struct edid1_info edid; |
| 1340 | |
| 1341 | if (argc < 2) { |
| 1342 | cmd_usage(cmdtp); |
| 1343 | return 1; |
| 1344 | } |
| 1345 | |
| 1346 | chip = simple_strtoul(argv[1], NULL, 16); |
| 1347 | if (i2c_read(chip, 0, 1, (uchar *)&edid, sizeof(edid)) != 0) { |
| 1348 | puts("Error reading EDID content.\n"); |
| 1349 | return 1; |
| 1350 | } |
| 1351 | |
| 1352 | if (edid_check_info(&edid)) { |
| 1353 | puts("Content isn't valid EDID.\n"); |
| 1354 | return 1; |
| 1355 | } |
| 1356 | |
| 1357 | edid_print_info(&edid); |
| 1358 | return 0; |
| 1359 | |
| 1360 | } |
| 1361 | #endif /* CONFIG_I2C_EDID */ |
| 1362 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1363 | /** |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1364 | * do_i2c_show_bus() - Handle the "i2c bus" command-line command |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1365 | * @cmdtp: Command data struct pointer |
| 1366 | * @flag: Command flag |
| 1367 | * @argc: Command-line argument count |
| 1368 | * @argv: Array of command-line arguments |
| 1369 | * |
| 1370 | * Returns zero always. |
| 1371 | */ |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1372 | #if defined(CONFIG_SYS_I2C) |
| 1373 | int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 1374 | { |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1375 | int i; |
| 1376 | #ifndef CONFIG_SYS_I2C_DIRECT_BUS |
| 1377 | int j; |
| 1378 | #endif |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 1379 | |
| 1380 | if (argc == 1) { |
| 1381 | /* show all busses */ |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1382 | for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) { |
| 1383 | printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name); |
| 1384 | #ifndef CONFIG_SYS_I2C_DIRECT_BUS |
| 1385 | for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) { |
| 1386 | if (i2c_bus[i].next_hop[j].chip == 0) |
| 1387 | break; |
| 1388 | printf("->%s@0x%2x:%d", |
| 1389 | i2c_bus[i].next_hop[j].mux.name, |
| 1390 | i2c_bus[i].next_hop[j].chip, |
| 1391 | i2c_bus[i].next_hop[j].channel); |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 1392 | } |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1393 | #endif |
| 1394 | printf("\n"); |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 1395 | } |
| 1396 | } else { |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1397 | /* show specific bus */ |
| 1398 | i = simple_strtoul(argv[1], NULL, 10); |
| 1399 | if (i >= CONFIG_SYS_NUM_I2C_BUSES) { |
| 1400 | printf("Invalid bus %d\n", i); |
| 1401 | return -1; |
| 1402 | } |
| 1403 | printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name); |
| 1404 | #ifndef CONFIG_SYS_I2C_DIRECT_BUS |
| 1405 | for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) { |
| 1406 | if (i2c_bus[i].next_hop[j].chip == 0) |
| 1407 | break; |
| 1408 | printf("->%s@0x%2x:%d", |
| 1409 | i2c_bus[i].next_hop[j].mux.name, |
| 1410 | i2c_bus[i].next_hop[j].chip, |
| 1411 | i2c_bus[i].next_hop[j].channel); |
| 1412 | } |
| 1413 | #endif |
| 1414 | printf("\n"); |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 1415 | } |
Heiko Schocher | 67b23a3 | 2008-10-15 09:39:47 +0200 | [diff] [blame] | 1416 | |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1417 | return 0; |
| 1418 | } |
| 1419 | #endif |
| 1420 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1421 | /** |
| 1422 | * do_i2c_bus_num() - Handle the "i2c dev" command-line command |
| 1423 | * @cmdtp: Command data struct pointer |
| 1424 | * @flag: Command flag |
| 1425 | * @argc: Command-line argument count |
| 1426 | * @argv: Array of command-line arguments |
| 1427 | * |
| 1428 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 1429 | * on error. |
| 1430 | */ |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1431 | #if defined(CONFIG_SYS_I2C) || defined(CONFIG_I2C_MULTI_BUS) |
| 1432 | int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1433 | { |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1434 | int ret = 0; |
| 1435 | unsigned int bus_no; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1436 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1437 | if (argc == 1) |
| 1438 | /* querying current setting */ |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1439 | printf("Current bus is %d\n", i2c_get_bus_num()); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1440 | else { |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1441 | bus_no = simple_strtoul(argv[1], NULL, 10); |
Heiko Schocher | 880a412 | 2013-08-23 09:39:16 +0200 | [diff] [blame] | 1442 | #if defined(CONFIG_SYS_I2C) |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1443 | if (bus_no >= CONFIG_SYS_NUM_I2C_BUSES) { |
| 1444 | printf("Invalid bus %d\n", bus_no); |
| 1445 | return -1; |
| 1446 | } |
Heiko Schocher | 880a412 | 2013-08-23 09:39:16 +0200 | [diff] [blame] | 1447 | #endif |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1448 | printf("Setting bus to %d\n", bus_no); |
| 1449 | ret = i2c_set_bus_num(bus_no); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1450 | if (ret) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1451 | printf("Failure changing bus number (%d)\n", ret); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1452 | } |
| 1453 | return ret; |
| 1454 | } |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1455 | #endif /* defined(CONFIG_SYS_I2C) */ |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1456 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1457 | /** |
| 1458 | * do_i2c_bus_speed() - Handle the "i2c speed" command-line command |
| 1459 | * @cmdtp: Command data struct pointer |
| 1460 | * @flag: Command flag |
| 1461 | * @argc: Command-line argument count |
| 1462 | * @argv: Array of command-line arguments |
| 1463 | * |
| 1464 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 1465 | * on error. |
| 1466 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1467 | static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1468 | { |
| 1469 | int speed, ret=0; |
| 1470 | |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1471 | if (argc == 1) |
| 1472 | /* querying current speed */ |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1473 | printf("Current bus speed=%d\n", i2c_get_bus_speed()); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1474 | else { |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1475 | speed = simple_strtoul(argv[1], NULL, 10); |
| 1476 | printf("Setting bus speed to %d Hz\n", speed); |
| 1477 | ret = i2c_set_bus_speed(speed); |
Timur Tabi | e857a5b | 2006-11-28 12:09:35 -0600 | [diff] [blame] | 1478 | if (ret) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1479 | printf("Failure changing bus speed (%d)\n", ret); |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1480 | } |
| 1481 | return ret; |
| 1482 | } |
| 1483 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1484 | /** |
| 1485 | * do_i2c_mm() - Handle the "i2c mm" command-line command |
| 1486 | * @cmdtp: Command data struct pointer |
| 1487 | * @flag: Command flag |
| 1488 | * @argc: Command-line argument count |
| 1489 | * @argv: Array of command-line arguments |
| 1490 | * |
| 1491 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 1492 | * on error. |
| 1493 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1494 | static int do_i2c_mm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1495 | { |
| 1496 | return mod_i2c_mem (cmdtp, 1, flag, argc, argv); |
| 1497 | } |
| 1498 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1499 | /** |
| 1500 | * do_i2c_nm() - Handle the "i2c nm" command-line command |
| 1501 | * @cmdtp: Command data struct pointer |
| 1502 | * @flag: Command flag |
| 1503 | * @argc: Command-line argument count |
| 1504 | * @argv: Array of command-line arguments |
| 1505 | * |
| 1506 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 1507 | * on error. |
| 1508 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1509 | static int do_i2c_nm(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1510 | { |
| 1511 | return mod_i2c_mem (cmdtp, 0, flag, argc, argv); |
| 1512 | } |
| 1513 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1514 | /** |
| 1515 | * do_i2c_reset() - Handle the "i2c reset" command-line command |
| 1516 | * @cmdtp: Command data struct pointer |
| 1517 | * @flag: Command flag |
| 1518 | * @argc: Command-line argument count |
| 1519 | * @argv: Array of command-line arguments |
| 1520 | * |
| 1521 | * Returns zero always. |
| 1522 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1523 | static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1524 | { |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1525 | #if defined(CONFIG_SYS_I2C) |
| 1526 | i2c_init(I2C_ADAP->speed, I2C_ADAP->slaveaddr); |
| 1527 | #else |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1528 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1529 | #endif |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static cmd_tbl_t cmd_i2c_sub[] = { |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1534 | #if defined(CONFIG_SYS_I2C) |
| 1535 | U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""), |
Heiko Schocher | 9a2accb | 2012-10-25 10:32:14 +0200 | [diff] [blame] | 1536 | #endif |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1537 | U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""), |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1538 | #if defined(CONFIG_SYS_I2C) || \ |
| 1539 | defined(CONFIG_I2C_MULTI_BUS) |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1540 | U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""), |
| 1541 | #endif /* CONFIG_I2C_MULTI_BUS */ |
Tom Wai-Hong Tam | 735987c | 2012-12-05 14:46:40 +0000 | [diff] [blame] | 1542 | #if defined(CONFIG_I2C_EDID) |
| 1543 | U_BOOT_CMD_MKENT(edid, 1, 1, do_edid, "", ""), |
| 1544 | #endif /* CONFIG_I2C_EDID */ |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1545 | U_BOOT_CMD_MKENT(loop, 3, 1, do_i2c_loop, "", ""), |
| 1546 | U_BOOT_CMD_MKENT(md, 3, 1, do_i2c_md, "", ""), |
| 1547 | U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""), |
| 1548 | U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""), |
| 1549 | U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""), |
| 1550 | U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""), |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 1551 | U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""), |
York Sun | ff5d2dc | 2012-09-16 08:02:30 +0000 | [diff] [blame] | 1552 | U_BOOT_CMD_MKENT(write, 5, 0, do_i2c_write, "", ""), |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1553 | U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""), |
| 1554 | #if defined(CONFIG_CMD_SDRAM) |
| 1555 | U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""), |
| 1556 | #endif |
| 1557 | U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""), |
| 1558 | }; |
| 1559 | |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 1560 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Heiko Schocher | f1d2b31 | 2010-09-17 13:10:39 +0200 | [diff] [blame] | 1561 | void i2c_reloc(void) { |
| 1562 | fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub)); |
| 1563 | } |
| 1564 | #endif |
| 1565 | |
Marek Vasut | 06afa38 | 2012-11-12 14:34:27 +0000 | [diff] [blame] | 1566 | /** |
| 1567 | * do_i2c() - Handle the "i2c" command-line command |
| 1568 | * @cmdtp: Command data struct pointer |
| 1569 | * @flag: Command flag |
| 1570 | * @argc: Command-line argument count |
| 1571 | * @argv: Array of command-line arguments |
| 1572 | * |
| 1573 | * Returns zero on success, CMD_RET_USAGE in case of misuse and negative |
| 1574 | * on error. |
| 1575 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1576 | static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1577 | { |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1578 | cmd_tbl_t *c; |
| 1579 | |
Heiko Schocher | 4444b22 | 2010-09-17 13:10:35 +0200 | [diff] [blame] | 1580 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1581 | return CMD_RET_USAGE; |
Heiko Schocher | 4444b22 | 2010-09-17 13:10:35 +0200 | [diff] [blame] | 1582 | |
Peter Tyser | e96ad5d | 2009-04-18 22:34:04 -0500 | [diff] [blame] | 1583 | /* Strip off leading 'i2c' command argument */ |
| 1584 | argc--; |
| 1585 | argv++; |
| 1586 | |
Frans Meulenbroeks | bfc3b77 | 2010-02-25 10:12:14 +0100 | [diff] [blame] | 1587 | c = find_cmd_tbl(argv[0], &cmd_i2c_sub[0], ARRAY_SIZE(cmd_i2c_sub)); |
| 1588 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 1589 | if (c) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1590 | return c->cmd(cmdtp, flag, argc, argv); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 1591 | else |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1592 | return CMD_RET_USAGE; |
Ben Warren | bb99ad6 | 2006-09-07 16:50:54 -0400 | [diff] [blame] | 1593 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1594 | |
| 1595 | /***************************************************/ |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1596 | #ifdef CONFIG_SYS_LONGHELP |
| 1597 | static char i2c_help_text[] = |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1598 | #if defined(CONFIG_SYS_I2C) |
| 1599 | "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n" |
Heiko Schocher | 9a2accb | 2012-10-25 10:32:14 +0200 | [diff] [blame] | 1600 | #endif |
Frans Meulenbroeks | fb0070e | 2010-02-25 10:12:15 +0100 | [diff] [blame] | 1601 | "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n" |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 1602 | #if defined(CONFIG_SYS_I2C) || \ |
| 1603 | defined(CONFIG_I2C_MULTI_BUS) |
Peter Tyser | 9bc2e4e | 2008-10-01 12:25:04 -0500 | [diff] [blame] | 1604 | "i2c dev [dev] - show or set current I2C bus\n" |
Matthias Fuchs | d9fc703 | 2007-03-08 16:25:47 +0100 | [diff] [blame] | 1605 | #endif /* CONFIG_I2C_MULTI_BUS */ |
Tom Wai-Hong Tam | 735987c | 2012-12-05 14:46:40 +0000 | [diff] [blame] | 1606 | #if defined(CONFIG_I2C_EDID) |
| 1607 | "i2c edid chip - print EDID configuration information\n" |
| 1608 | #endif /* CONFIG_I2C_EDID */ |
Frans Meulenbroeks | fb0070e | 2010-02-25 10:12:15 +0100 | [diff] [blame] | 1609 | "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n" |
Matthias Fuchs | d9fc703 | 2007-03-08 16:25:47 +0100 | [diff] [blame] | 1610 | "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n" |
| 1611 | "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n" |
| 1612 | "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n" |
| 1613 | "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n" |
Eric Nelson | 54b99e5 | 2012-09-23 10:12:56 +0000 | [diff] [blame] | 1614 | "i2c probe [address] - test for and show device(s) on the I2C bus\n" |
Frans Meulenbroeks | 652e535 | 2010-02-25 10:12:16 +0100 | [diff] [blame] | 1615 | "i2c read chip address[.0, .1, .2] length memaddress - read to memory \n" |
York Sun | ff5d2dc | 2012-09-16 08:02:30 +0000 | [diff] [blame] | 1616 | "i2c write memaddress chip address[.0, .1, .2] length - write memory to i2c\n" |
Heiko Schocher | e43a27c | 2008-10-15 09:33:30 +0200 | [diff] [blame] | 1617 | "i2c reset - re-init the I2C Controller\n" |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1618 | #if defined(CONFIG_CMD_SDRAM) |
Frans Meulenbroeks | fb0070e | 2010-02-25 10:12:15 +0100 | [diff] [blame] | 1619 | "i2c sdram chip - print SDRAM configuration information\n" |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1620 | #endif |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1621 | "i2c speed [speed] - show or set I2C bus speed"; |
| 1622 | #endif |
| 1623 | |
| 1624 | U_BOOT_CMD( |
| 1625 | i2c, 6, 1, do_i2c, |
| 1626 | "I2C sub-system", |
| 1627 | i2c_help_text |
Matthias Fuchs | d9fc703 | 2007-03-08 16:25:47 +0100 | [diff] [blame] | 1628 | ); |