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