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