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