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