blob: b3fd37c8274b39567be1e6cf5a620e7faaca0e26 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000, 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
m8a484c602005-08-12 21:16:13 +02007/*
8 * Support for read and write access to EEPROM like memory devices. This
9 * includes regular EEPROM as well as FRAM (ferroelectic nonvolaile RAM).
10 * FRAM devices read and write data at bus speed. In particular, there is no
Peter Meerwaldc48ae8c2012-02-08 05:31:53 +000011 * write delay. Also, there is no limit imposed on the number of bytes that can
m8a484c602005-08-12 21:16:13 +020012 * be transferred with a single read or write.
Wolfgang Denke4e5e4e2005-08-19 00:46:54 +020013 *
m8a484c602005-08-12 21:16:13 +020014 * Use the following configuration options to ensure no unneeded performance
15 * degradation (typical for EEPROM) is incured for FRAM memory:
Wolfgang Denke4e5e4e2005-08-19 00:46:54 +020016 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020017 * #define CONFIG_SYS_I2C_FRAM
18 * #undef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
m8a484c602005-08-12 21:16:13 +020019 *
20 */
21
wdenk38635852002-08-27 05:55:31 +000022#include <common.h>
23#include <config.h>
24#include <command.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -070025#include <eeprom.h>
wdenk38635852002-08-27 05:55:31 +000026#include <i2c.h>
Nikita Kiryanov91f226a2016-04-16 17:55:12 +030027#include <eeprom_layout.h>
Simon Glassdbd79542020-05-10 11:40:11 -060028#include <linux/delay.h>
wdenk38635852002-08-27 05:55:31 +000029
Marek Vasut704a0962015-11-10 20:53:18 +010030#ifndef CONFIG_SYS_I2C_SPEED
31#define CONFIG_SYS_I2C_SPEED 50000
Stefan Roesed9d97742005-09-22 09:04:17 +020032#endif
wdenk38635852002-08-27 05:55:31 +000033
Marek Vasutd848b082015-11-10 20:53:26 +010034#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
35#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 0
36#endif
37
Marek Vasut42086792015-11-10 20:53:28 +010038#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
39#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 8
40#endif
41
Mario Sixdf0a9142016-04-20 10:44:52 +020042#ifndef I2C_RXTX_LEN
43#define I2C_RXTX_LEN 128
44#endif
45
Marek Vasut42086792015-11-10 20:53:28 +010046#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
47#define EEPROM_PAGE_OFFSET(x) ((x) & (EEPROM_PAGE_SIZE - 1))
48
Marek Vasut704a0962015-11-10 20:53:18 +010049/*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050 * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
wdenk38635852002-08-27 05:55:31 +000051 * 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
52 *
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053 * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
wdenk38635852002-08-27 05:55:31 +000054 * 0x00000nxx for EEPROM address selectors and page number at n.
55 */
Heiko Schocher9bb0dd52010-01-07 08:55:40 +010056#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
Marek Vasut704a0962015-11-10 20:53:18 +010057#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || \
Marek Vasuta24ea7a2015-11-10 20:53:33 +010058 (CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1) || \
59 (CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
wdenk38635852002-08-27 05:55:31 +000061#endif
Marek Vasut704a0962015-11-10 20:53:18 +010062#endif
63
Igor Opaniukf7c91762021-02-09 13:52:45 +020064#if CONFIG_IS_ENABLED(DM_I2C)
Marek Vasut75f3c192020-04-07 13:29:04 +020065static int eeprom_i2c_bus;
Simon Goldschmidt30946822019-03-26 13:38:52 +010066#endif
67
Marek Vasut2a632ffc2015-11-10 20:53:25 +010068__weak int eeprom_write_enable(unsigned dev_addr, int state)
69{
70 return 0;
71}
Marek Vasut704a0962015-11-10 20:53:18 +010072
Marek Vasutf422ae72015-11-10 20:53:31 +010073void eeprom_init(int bus)
Marek Vasut704a0962015-11-10 20:53:18 +010074{
Marek Vasut704a0962015-11-10 20:53:18 +010075 /* I2C EEPROM */
Igor Opaniukf7c91762021-02-09 13:52:45 +020076#if CONFIG_IS_ENABLED(DM_I2C)
Simon Goldschmidt30946822019-03-26 13:38:52 +010077 eeprom_i2c_bus = bus;
78#elif defined(CONFIG_SYS_I2C)
Marek Vasutf422ae72015-11-10 20:53:31 +010079 if (bus >= 0)
80 i2c_set_bus_num(bus);
Marek Vasut704a0962015-11-10 20:53:18 +010081 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk38635852002-08-27 05:55:31 +000082#endif
Marek Vasut704a0962015-11-10 20:53:18 +010083}
wdenk38635852002-08-27 05:55:31 +000084
Marek Vasut6ae59572015-11-10 20:53:24 +010085static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)
86{
87 unsigned blk_off;
88 int alen;
89
90 blk_off = offset & 0xff; /* block offset */
91#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
92 addr[0] = offset >> 8; /* block number */
93 addr[1] = blk_off; /* block offset */
94 alen = 2;
95#else
96 addr[0] = offset >> 16; /* block number */
97 addr[1] = offset >> 8; /* upper address octet */
98 addr[2] = blk_off; /* lower address octet */
99 alen = 3;
100#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
101
102 addr[0] |= dev_addr; /* insert device address */
103
104 return alen;
105}
106
Marek Vasutd062c482015-11-10 20:53:29 +0100107static int eeprom_len(unsigned offset, unsigned end)
108{
109 unsigned len = end - offset;
110
111 /*
112 * For a FRAM device there is no limit on the number of the
Lukasz Majewski20bfc572019-06-09 22:54:38 +0200113 * bytes that can be accessed with the single read or write
Marek Vasutd062c482015-11-10 20:53:29 +0100114 * operation.
115 */
116#if !defined(CONFIG_SYS_I2C_FRAM)
117 unsigned blk_off = offset & 0xff;
118 unsigned maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
119
120 if (maxlen > I2C_RXTX_LEN)
121 maxlen = I2C_RXTX_LEN;
122
123 if (len > maxlen)
124 len = maxlen;
125#endif
126
127 return len;
128}
129
Marek Vasut78990c72015-11-10 20:53:23 +0100130static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
131 uchar *buffer, unsigned len, bool read)
132{
133 int ret = 0;
134
Igor Opaniukf7c91762021-02-09 13:52:45 +0200135#if CONFIG_IS_ENABLED(DM_I2C)
Lukasz Majewskic71c2692018-11-21 23:40:43 +0100136 struct udevice *dev;
137
Simon Goldschmidt30946822019-03-26 13:38:52 +0100138 ret = i2c_get_chip_for_busnum(eeprom_i2c_bus, addr[0],
Lukasz Majewskic71c2692018-11-21 23:40:43 +0100139 alen - 1, &dev);
140 if (ret) {
141 printf("%s: Cannot find udev for a bus %d\n", __func__,
Simon Goldschmidt30946822019-03-26 13:38:52 +0100142 eeprom_i2c_bus);
Lukasz Majewskic71c2692018-11-21 23:40:43 +0100143 return CMD_RET_FAILURE;
144 }
145
146 if (read)
147 ret = dm_i2c_read(dev, offset, buffer, len);
148 else
149 ret = dm_i2c_write(dev, offset, buffer, len);
150
151#else /* Non DM I2C support - will be removed */
Marek Vasut78990c72015-11-10 20:53:23 +0100152
153 if (read)
154 ret = i2c_read(addr[0], offset, alen - 1, buffer, len);
155 else
156 ret = i2c_write(addr[0], offset, alen - 1, buffer, len);
Simon Goldschmidt30946822019-03-26 13:38:52 +0100157#endif /* CONFIG_DM_I2C */
Lukasz Majewskic71c2692018-11-21 23:40:43 +0100158 if (ret)
159 ret = CMD_RET_FAILURE;
160
Marek Vasut78990c72015-11-10 20:53:23 +0100161 return ret;
162}
163
Marek Vasut7a237212015-11-10 20:53:30 +0100164static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
165 unsigned cnt, bool read)
wdenk38635852002-08-27 05:55:31 +0000166{
167 unsigned end = offset + cnt;
Marek Vasut7a237212015-11-10 20:53:30 +0100168 unsigned alen, len;
wdenk38635852002-08-27 05:55:31 +0000169 int rcode = 0;
Marek Vasut6ae59572015-11-10 20:53:24 +0100170 uchar addr[3];
wdenk38635852002-08-27 05:55:31 +0000171
Simon Goldschmidt30946822019-03-26 13:38:52 +0100172#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
173 eeprom_init(CONFIG_SYS_I2C_EEPROM_BUS);
174#endif
175
wdenk38635852002-08-27 05:55:31 +0000176 while (offset < end) {
Marek Vasut6ae59572015-11-10 20:53:24 +0100177 alen = eeprom_addr(dev_addr, offset, addr);
wdenk38635852002-08-27 05:55:31 +0000178
Marek Vasutd062c482015-11-10 20:53:29 +0100179 len = eeprom_len(offset, end);
m8a484c602005-08-12 21:16:13 +0200180
Marek Vasut7a237212015-11-10 20:53:30 +0100181 rcode = eeprom_rw_block(offset, addr, alen, buffer, len, read);
Marek Vasut78990c72015-11-10 20:53:23 +0100182
wdenk38635852002-08-27 05:55:31 +0000183 buffer += len;
184 offset += len;
Marek Vasut7a237212015-11-10 20:53:30 +0100185
186 if (!read)
187 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
wdenk38635852002-08-27 05:55:31 +0000188 }
m8a484c602005-08-12 21:16:13 +0200189
wdenk38635852002-08-27 05:55:31 +0000190 return rcode;
191}
192
Marek Vasut7a237212015-11-10 20:53:30 +0100193int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
wdenk38635852002-08-27 05:55:31 +0000194{
Marek Vasut7a237212015-11-10 20:53:30 +0100195 /*
196 * Read data until done or would cross a page boundary.
197 * We must write the address again when changing pages
198 * because the next page may be in a different device.
199 */
200 return eeprom_rw(dev_addr, offset, buffer, cnt, 1);
201}
202
Marek Vasuta24ea7a2015-11-10 20:53:33 +0100203int eeprom_write(unsigned dev_addr, unsigned offset,
204 uchar *buffer, unsigned cnt)
Marek Vasut7a237212015-11-10 20:53:30 +0100205{
206 int ret;
wdenk38635852002-08-27 05:55:31 +0000207
Marek Vasut2a632ffc2015-11-10 20:53:25 +0100208 eeprom_write_enable(dev_addr, 1);
209
Marek Vasut704a0962015-11-10 20:53:18 +0100210 /*
211 * Write data until done or would cross a write page boundary.
wdenk38635852002-08-27 05:55:31 +0000212 * We must write the address again when changing pages
213 * because the address counter only increments within a page.
214 */
Alexey Brodkin90eed7f2015-12-14 18:45:34 +0300215 ret = eeprom_rw(dev_addr, offset, buffer, cnt, 0);
Marek Vasut2a632ffc2015-11-10 20:53:25 +0100216
217 eeprom_write_enable(dev_addr, 0);
Marek Vasut7a237212015-11-10 20:53:30 +0100218 return ret;
wdenk38635852002-08-27 05:55:31 +0000219}
220
Nikita Kiryanovadb62f02016-04-16 17:55:11 +0300221static int parse_numeric_param(char *str)
222{
223 char *endptr;
224 int value = simple_strtol(str, &endptr, 16);
225
226 return (*endptr != '\0') ? -1 : value;
227}
228
229/**
230 * parse_i2c_bus_addr - parse the i2c bus and i2c devaddr parameters
231 *
232 * @i2c_bus: address to store the i2c bus
233 * @i2c_addr: address to store the device i2c address
234 * @argc: count of command line arguments left to parse
235 * @argv: command line arguments left to parse
236 * @argc_no_bus_addr: argc value we expect to see when bus & addr aren't given
237 *
238 * @returns: number of arguments parsed or CMD_RET_USAGE if error
239 */
240static int parse_i2c_bus_addr(int *i2c_bus, ulong *i2c_addr, int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600241 char *const argv[], int argc_no_bus_addr)
Nikita Kiryanovadb62f02016-04-16 17:55:11 +0300242{
243 int argc_no_bus = argc_no_bus_addr + 1;
244 int argc_bus_addr = argc_no_bus_addr + 2;
245
246#ifdef CONFIG_SYS_DEF_EEPROM_ADDR
247 if (argc == argc_no_bus_addr) {
248 *i2c_bus = -1;
249 *i2c_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
250
251 return 0;
252 }
253#endif
254 if (argc == argc_no_bus) {
255 *i2c_bus = -1;
256 *i2c_addr = parse_numeric_param(argv[0]);
257
258 return 1;
259 }
260
261 if (argc == argc_bus_addr) {
262 *i2c_bus = parse_numeric_param(argv[0]);
263 *i2c_addr = parse_numeric_param(argv[1]);
264
265 return 2;
266 }
267
268 return CMD_RET_USAGE;
269}
270
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300271#ifdef CONFIG_CMD_EEPROM_LAYOUT
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300272
273__weak int eeprom_parse_layout_version(char *str)
274{
275 return LAYOUT_VERSION_UNRECOGNIZED;
276}
277
278static unsigned char eeprom_buf[CONFIG_SYS_EEPROM_SIZE];
279
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300280#endif
281
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300282enum eeprom_action {
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300283 EEPROM_READ,
284 EEPROM_WRITE,
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300285 EEPROM_PRINT,
286 EEPROM_UPDATE,
287 EEPROM_ACTION_INVALID,
288};
289
290static enum eeprom_action parse_action(char *cmd)
291{
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300292 if (!strncmp(cmd, "read", 4))
293 return EEPROM_READ;
294 if (!strncmp(cmd, "write", 5))
295 return EEPROM_WRITE;
296#ifdef CONFIG_CMD_EEPROM_LAYOUT
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300297 if (!strncmp(cmd, "print", 5))
298 return EEPROM_PRINT;
299 if (!strncmp(cmd, "update", 6))
300 return EEPROM_UPDATE;
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300301#endif
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300302
303 return EEPROM_ACTION_INVALID;
304}
305
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300306static int eeprom_execute_command(enum eeprom_action action, int i2c_bus,
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300307 ulong i2c_addr, int layout_ver, char *key,
308 char *value, ulong addr, ulong off, ulong cnt)
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300309{
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300310 int rcode = 0;
311 const char *const fmt =
Klaus H. Sorensen0c1ca6d2019-12-11 11:18:29 +0000312 "\nEEPROM @0x%lX %s: addr 0x%08lx off 0x%04lx count %ld ... ";
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300313#ifdef CONFIG_CMD_EEPROM_LAYOUT
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300314 struct eeprom_layout layout;
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300315#endif
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300316
317 if (action == EEPROM_ACTION_INVALID)
318 return CMD_RET_USAGE;
319
320 eeprom_init(i2c_bus);
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300321 if (action == EEPROM_READ) {
322 printf(fmt, i2c_addr, "read", addr, off, cnt);
323
324 rcode = eeprom_read(i2c_addr, off, (uchar *)addr, cnt);
325
326 puts("done\n");
327 return rcode;
328 } else if (action == EEPROM_WRITE) {
329 printf(fmt, i2c_addr, "write", addr, off, cnt);
330
331 rcode = eeprom_write(i2c_addr, off, (uchar *)addr, cnt);
332
333 puts("done\n");
334 return rcode;
335 }
336
337#ifdef CONFIG_CMD_EEPROM_LAYOUT
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300338 rcode = eeprom_read(i2c_addr, 0, eeprom_buf, CONFIG_SYS_EEPROM_SIZE);
339 if (rcode < 0)
340 return rcode;
341
342 eeprom_layout_setup(&layout, eeprom_buf, CONFIG_SYS_EEPROM_SIZE,
343 layout_ver);
344
345 if (action == EEPROM_PRINT) {
346 layout.print(&layout);
347 return 0;
348 }
349
350 layout.update(&layout, key, value);
351
352 rcode = eeprom_write(i2c_addr, 0, layout.data, CONFIG_SYS_EEPROM_SIZE);
Nikita Kiryanov91f226a2016-04-16 17:55:12 +0300353#endif
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300354
355 return rcode;
356}
357
358#define NEXT_PARAM(argc, index) { (argc)--; (index)++; }
Simon Glassed38aef2020-05-10 11:40:03 -0600359int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300360{
361 int layout_ver = LAYOUT_VERSION_AUTODETECT;
362 enum eeprom_action action = EEPROM_ACTION_INVALID;
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300363 int i2c_bus = -1, index = 0;
364 ulong i2c_addr = -1, addr = 0, cnt = 0, off = 0;
365 int ret;
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300366 char *field_name = "";
367 char *field_value = "";
368
369 if (argc <= 1)
370 return CMD_RET_USAGE;
371
372 NEXT_PARAM(argc, index); /* Skip program name */
373
374 action = parse_action(argv[index]);
375 NEXT_PARAM(argc, index);
376
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300377 if (action == EEPROM_ACTION_INVALID)
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300378 return CMD_RET_USAGE;
379
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300380#ifdef CONFIG_CMD_EEPROM_LAYOUT
381 if (action == EEPROM_PRINT || action == EEPROM_UPDATE) {
382 if (!strcmp(argv[index], "-l")) {
383 NEXT_PARAM(argc, index);
384 layout_ver = eeprom_parse_layout_version(argv[index]);
385 NEXT_PARAM(argc, index);
386 }
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300387 }
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300388#endif
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300389
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300390 switch (action) {
391 case EEPROM_READ:
392 case EEPROM_WRITE:
393 ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
394 argv + index, 3);
395 break;
396 case EEPROM_PRINT:
397 ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
398 argv + index, 0);
399 break;
400 case EEPROM_UPDATE:
401 ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
402 argv + index, 2);
403 break;
404 default:
405 /* Get compiler to stop whining */
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300406 return CMD_RET_USAGE;
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300407 }
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300408
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300409 if (ret == CMD_RET_USAGE)
410 return ret;
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300411
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300412 while (ret--)
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300413 NEXT_PARAM(argc, index);
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300414
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300415 if (action == EEPROM_READ || action == EEPROM_WRITE) {
416 addr = parse_numeric_param(argv[index]);
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300417 NEXT_PARAM(argc, index);
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300418 off = parse_numeric_param(argv[index]);
419 NEXT_PARAM(argc, index);
420 cnt = parse_numeric_param(argv[index]);
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300421 }
422
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300423#ifdef CONFIG_CMD_EEPROM_LAYOUT
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300424 if (action == EEPROM_UPDATE) {
425 field_name = argv[index];
426 NEXT_PARAM(argc, index);
427 field_value = argv[index];
428 NEXT_PARAM(argc, index);
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300429 }
430#endif
431
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300432 return eeprom_execute_command(action, i2c_bus, i2c_addr, layout_ver,
433 field_name, field_value, addr, off, cnt);
Marek Vasut704a0962015-11-10 20:53:18 +0100434}
wdenk57b2d802003-06-27 21:31:46 +0000435
wdenkf287a242003-07-01 21:06:45 +0000436U_BOOT_CMD(
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300437 eeprom, 8, 1, do_eeprom,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600438 "EEPROM sub-system",
Marek Vasut4d17f712015-11-10 20:53:32 +0100439 "read <bus> <devaddr> addr off cnt\n"
440 "eeprom write <bus> <devaddr> addr off cnt\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200441 " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300442#ifdef CONFIG_CMD_EEPROM_LAYOUT
443 "\n"
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300444 "eeprom print [-l <layout_version>] <bus> <devaddr>\n"
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300445 " - Print layout fields and their data in human readable format\n"
Nikita Kiryanov9e559fd2016-04-16 17:55:13 +0300446 "eeprom update [-l <layout_version>] <bus> <devaddr> field_name field_value\n"
Nikita Kiryanov37dda1c2016-04-16 17:55:03 +0300447 " - Update a specific eeprom field with new data.\n"
448 " The new data must be written in the same human readable format as shown by the print command.\n"
449 "\n"
450 "LAYOUT VERSIONS\n"
451 "The -l option can be used to force the command to interpret the EEPROM data using the chosen layout.\n"
452 "If the -l option is omitted, the command will auto detect the layout based on the data in the EEPROM.\n"
453 "The values which can be provided with the -l option are:\n"
454 CONFIG_EEPROM_LAYOUT_HELP_STRING"\n"
455#endif
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +0200456)