2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-08-27 13:55:31 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000, 2001
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
2005-08-13 03:16:13 +08:00
|
|
|
/*
|
|
|
|
* Support for read and write access to EEPROM like memory devices. This
|
|
|
|
* includes regular EEPROM as well as FRAM (ferroelectic nonvolaile RAM).
|
|
|
|
* FRAM devices read and write data at bus speed. In particular, there is no
|
2012-02-08 13:31:53 +08:00
|
|
|
* write delay. Also, there is no limit imposed on the number of bytes that can
|
2005-08-13 03:16:13 +08:00
|
|
|
* be transferred with a single read or write.
|
2005-08-19 06:46:54 +08:00
|
|
|
*
|
2005-08-13 03:16:13 +08:00
|
|
|
* Use the following configuration options to ensure no unneeded performance
|
|
|
|
* degradation (typical for EEPROM) is incured for FRAM memory:
|
2005-08-19 06:46:54 +08:00
|
|
|
*
|
2008-10-16 21:01:15 +08:00
|
|
|
* #define CONFIG_SYS_I2C_FRAM
|
|
|
|
* #undef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
|
2005-08-13 03:16:13 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
#include <common.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <i2c.h>
|
2016-04-16 22:55:12 +08:00
|
|
|
#include <eeprom_layout.h>
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2015-11-11 03:53:18 +08:00
|
|
|
#ifndef CONFIG_SYS_I2C_SPEED
|
|
|
|
#define CONFIG_SYS_I2C_SPEED 50000
|
2005-09-22 15:04:17 +08:00
|
|
|
#endif
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2015-11-11 03:53:26 +08:00
|
|
|
#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
|
|
|
|
#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 0
|
|
|
|
#endif
|
|
|
|
|
2015-11-11 03:53:28 +08:00
|
|
|
#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
|
|
|
|
#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 8
|
|
|
|
#endif
|
|
|
|
|
2016-04-20 16:44:52 +08:00
|
|
|
#ifndef I2C_RXTX_LEN
|
|
|
|
#define I2C_RXTX_LEN 128
|
|
|
|
#endif
|
|
|
|
|
2015-11-11 03:53:28 +08:00
|
|
|
#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
|
|
|
|
#define EEPROM_PAGE_OFFSET(x) ((x) & (EEPROM_PAGE_SIZE - 1))
|
|
|
|
|
2015-11-11 03:53:18 +08:00
|
|
|
/*
|
2008-10-16 21:01:15 +08:00
|
|
|
* for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
|
2002-08-27 13:55:31 +08:00
|
|
|
* 0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
|
|
|
|
*
|
2008-10-16 21:01:15 +08:00
|
|
|
* for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
|
2002-08-27 13:55:31 +08:00
|
|
|
* 0x00000nxx for EEPROM address selectors and page number at n.
|
|
|
|
*/
|
2010-01-07 15:55:40 +08:00
|
|
|
#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2015-11-11 03:53:18 +08:00
|
|
|
#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || \
|
2015-11-11 03:53:33 +08:00
|
|
|
(CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1) || \
|
|
|
|
(CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2)
|
2008-10-16 21:01:15 +08:00
|
|
|
#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-11-11 03:53:25 +08:00
|
|
|
__weak int eeprom_write_enable(unsigned dev_addr, int state)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-11 03:53:18 +08:00
|
|
|
|
2015-11-11 03:53:31 +08:00
|
|
|
void eeprom_init(int bus)
|
2015-11-11 03:53:18 +08:00
|
|
|
{
|
|
|
|
/* SPI EEPROM */
|
2018-04-16 01:51:26 +08:00
|
|
|
#if defined(CONFIG_MPC8XX_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2015-11-11 03:53:27 +08:00
|
|
|
spi_init_f();
|
2015-11-11 03:53:18 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* I2C EEPROM */
|
2015-11-11 03:53:31 +08:00
|
|
|
#if defined(CONFIG_SYS_I2C)
|
|
|
|
if (bus >= 0)
|
|
|
|
i2c_set_bus_num(bus);
|
2015-11-11 03:53:18 +08:00
|
|
|
i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:53:24 +08:00
|
|
|
static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)
|
|
|
|
{
|
|
|
|
unsigned blk_off;
|
|
|
|
int alen;
|
|
|
|
|
|
|
|
blk_off = offset & 0xff; /* block offset */
|
|
|
|
#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
|
|
|
|
addr[0] = offset >> 8; /* block number */
|
|
|
|
addr[1] = blk_off; /* block offset */
|
|
|
|
alen = 2;
|
|
|
|
#else
|
|
|
|
addr[0] = offset >> 16; /* block number */
|
|
|
|
addr[1] = offset >> 8; /* upper address octet */
|
|
|
|
addr[2] = blk_off; /* lower address octet */
|
|
|
|
alen = 3;
|
|
|
|
#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
|
|
|
|
|
|
|
|
addr[0] |= dev_addr; /* insert device address */
|
|
|
|
|
|
|
|
return alen;
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:53:29 +08:00
|
|
|
static int eeprom_len(unsigned offset, unsigned end)
|
|
|
|
{
|
|
|
|
unsigned len = end - offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For a FRAM device there is no limit on the number of the
|
|
|
|
* bytes that can be ccessed with the single read or write
|
|
|
|
* operation.
|
|
|
|
*/
|
|
|
|
#if !defined(CONFIG_SYS_I2C_FRAM)
|
|
|
|
unsigned blk_off = offset & 0xff;
|
|
|
|
unsigned maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
|
|
|
|
|
|
|
|
if (maxlen > I2C_RXTX_LEN)
|
|
|
|
maxlen = I2C_RXTX_LEN;
|
|
|
|
|
|
|
|
if (len > maxlen)
|
|
|
|
len = maxlen;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:53:23 +08:00
|
|
|
static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
|
|
|
|
uchar *buffer, unsigned len, bool read)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* SPI */
|
2018-04-16 01:51:26 +08:00
|
|
|
#if defined(CONFIG_MPC8XX_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2015-11-11 03:53:23 +08:00
|
|
|
if (read)
|
|
|
|
spi_read(addr, alen, buffer, len);
|
|
|
|
else
|
|
|
|
spi_write(addr, alen, buffer, len);
|
|
|
|
#else /* I2C */
|
|
|
|
|
|
|
|
#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
|
|
|
|
i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (read)
|
|
|
|
ret = i2c_read(addr[0], offset, alen - 1, buffer, len);
|
|
|
|
else
|
|
|
|
ret = i2c_write(addr[0], offset, alen - 1, buffer, len);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
ret = 1;
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:53:30 +08:00
|
|
|
static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
|
|
|
|
unsigned cnt, bool read)
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
|
|
|
unsigned end = offset + cnt;
|
2015-11-11 03:53:30 +08:00
|
|
|
unsigned alen, len;
|
2002-08-27 13:55:31 +08:00
|
|
|
int rcode = 0;
|
2015-11-11 03:53:24 +08:00
|
|
|
uchar addr[3];
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
while (offset < end) {
|
2015-11-11 03:53:24 +08:00
|
|
|
alen = eeprom_addr(dev_addr, offset, addr);
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2015-11-11 03:53:29 +08:00
|
|
|
len = eeprom_len(offset, end);
|
2005-08-13 03:16:13 +08:00
|
|
|
|
2015-11-11 03:53:30 +08:00
|
|
|
rcode = eeprom_rw_block(offset, addr, alen, buffer, len, read);
|
2015-11-11 03:53:23 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
buffer += len;
|
|
|
|
offset += len;
|
2015-11-11 03:53:30 +08:00
|
|
|
|
|
|
|
if (!read)
|
|
|
|
udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
|
2002-08-27 13:55:31 +08:00
|
|
|
}
|
2005-08-13 03:16:13 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:53:30 +08:00
|
|
|
int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
2015-11-11 03:53:30 +08:00
|
|
|
/*
|
|
|
|
* Read data until done or would cross a page boundary.
|
|
|
|
* We must write the address again when changing pages
|
|
|
|
* because the next page may be in a different device.
|
|
|
|
*/
|
|
|
|
return eeprom_rw(dev_addr, offset, buffer, cnt, 1);
|
|
|
|
}
|
|
|
|
|
2015-11-11 03:53:33 +08:00
|
|
|
int eeprom_write(unsigned dev_addr, unsigned offset,
|
|
|
|
uchar *buffer, unsigned cnt)
|
2015-11-11 03:53:30 +08:00
|
|
|
{
|
|
|
|
int ret;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2015-11-11 03:53:25 +08:00
|
|
|
eeprom_write_enable(dev_addr, 1);
|
|
|
|
|
2015-11-11 03:53:18 +08:00
|
|
|
/*
|
|
|
|
* Write data until done or would cross a write page boundary.
|
2002-08-27 13:55:31 +08:00
|
|
|
* We must write the address again when changing pages
|
|
|
|
* because the address counter only increments within a page.
|
|
|
|
*/
|
2015-12-14 23:45:34 +08:00
|
|
|
ret = eeprom_rw(dev_addr, offset, buffer, cnt, 0);
|
2015-11-11 03:53:25 +08:00
|
|
|
|
|
|
|
eeprom_write_enable(dev_addr, 0);
|
2015-11-11 03:53:30 +08:00
|
|
|
return ret;
|
2002-08-27 13:55:31 +08:00
|
|
|
}
|
|
|
|
|
2016-04-16 22:55:11 +08:00
|
|
|
static int parse_numeric_param(char *str)
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
int value = simple_strtol(str, &endptr, 16);
|
|
|
|
|
|
|
|
return (*endptr != '\0') ? -1 : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse_i2c_bus_addr - parse the i2c bus and i2c devaddr parameters
|
|
|
|
*
|
|
|
|
* @i2c_bus: address to store the i2c bus
|
|
|
|
* @i2c_addr: address to store the device i2c address
|
|
|
|
* @argc: count of command line arguments left to parse
|
|
|
|
* @argv: command line arguments left to parse
|
|
|
|
* @argc_no_bus_addr: argc value we expect to see when bus & addr aren't given
|
|
|
|
*
|
|
|
|
* @returns: number of arguments parsed or CMD_RET_USAGE if error
|
|
|
|
*/
|
|
|
|
static int parse_i2c_bus_addr(int *i2c_bus, ulong *i2c_addr, int argc,
|
|
|
|
char * const argv[], int argc_no_bus_addr)
|
|
|
|
{
|
|
|
|
int argc_no_bus = argc_no_bus_addr + 1;
|
|
|
|
int argc_bus_addr = argc_no_bus_addr + 2;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_DEF_EEPROM_ADDR
|
|
|
|
if (argc == argc_no_bus_addr) {
|
|
|
|
*i2c_bus = -1;
|
|
|
|
*i2c_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (argc == argc_no_bus) {
|
|
|
|
*i2c_bus = -1;
|
|
|
|
*i2c_addr = parse_numeric_param(argv[0]);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == argc_bus_addr) {
|
|
|
|
*i2c_bus = parse_numeric_param(argv[0]);
|
|
|
|
*i2c_addr = parse_numeric_param(argv[1]);
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
2016-04-16 22:55:03 +08:00
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
|
|
|
|
|
|
|
__weak int eeprom_parse_layout_version(char *str)
|
|
|
|
{
|
|
|
|
return LAYOUT_VERSION_UNRECOGNIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char eeprom_buf[CONFIG_SYS_EEPROM_SIZE];
|
|
|
|
|
2016-04-16 22:55:12 +08:00
|
|
|
#endif
|
|
|
|
|
2016-04-16 22:55:03 +08:00
|
|
|
enum eeprom_action {
|
2016-04-16 22:55:12 +08:00
|
|
|
EEPROM_READ,
|
|
|
|
EEPROM_WRITE,
|
2016-04-16 22:55:03 +08:00
|
|
|
EEPROM_PRINT,
|
|
|
|
EEPROM_UPDATE,
|
|
|
|
EEPROM_ACTION_INVALID,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum eeprom_action parse_action(char *cmd)
|
|
|
|
{
|
2016-04-16 22:55:13 +08:00
|
|
|
if (!strncmp(cmd, "read", 4))
|
|
|
|
return EEPROM_READ;
|
|
|
|
if (!strncmp(cmd, "write", 5))
|
|
|
|
return EEPROM_WRITE;
|
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
2016-04-16 22:55:03 +08:00
|
|
|
if (!strncmp(cmd, "print", 5))
|
|
|
|
return EEPROM_PRINT;
|
|
|
|
if (!strncmp(cmd, "update", 6))
|
|
|
|
return EEPROM_UPDATE;
|
2016-04-16 22:55:13 +08:00
|
|
|
#endif
|
2016-04-16 22:55:03 +08:00
|
|
|
|
|
|
|
return EEPROM_ACTION_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eeprom_execute_command(enum eeprom_action action, int i2c_bus,
|
2016-04-16 22:55:12 +08:00
|
|
|
ulong i2c_addr, int layout_ver, char *key,
|
|
|
|
char *value, ulong addr, ulong off, ulong cnt)
|
2016-04-16 22:55:03 +08:00
|
|
|
{
|
2016-04-16 22:55:12 +08:00
|
|
|
int rcode = 0;
|
|
|
|
const char *const fmt =
|
|
|
|
"\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... ";
|
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
2016-04-16 22:55:03 +08:00
|
|
|
struct eeprom_layout layout;
|
2016-04-16 22:55:12 +08:00
|
|
|
#endif
|
2016-04-16 22:55:03 +08:00
|
|
|
|
|
|
|
if (action == EEPROM_ACTION_INVALID)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
eeprom_init(i2c_bus);
|
2016-04-16 22:55:12 +08:00
|
|
|
if (action == EEPROM_READ) {
|
|
|
|
printf(fmt, i2c_addr, "read", addr, off, cnt);
|
|
|
|
|
|
|
|
rcode = eeprom_read(i2c_addr, off, (uchar *)addr, cnt);
|
|
|
|
|
|
|
|
puts("done\n");
|
|
|
|
return rcode;
|
|
|
|
} else if (action == EEPROM_WRITE) {
|
|
|
|
printf(fmt, i2c_addr, "write", addr, off, cnt);
|
|
|
|
|
|
|
|
rcode = eeprom_write(i2c_addr, off, (uchar *)addr, cnt);
|
|
|
|
|
|
|
|
puts("done\n");
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
2016-04-16 22:55:03 +08:00
|
|
|
rcode = eeprom_read(i2c_addr, 0, eeprom_buf, CONFIG_SYS_EEPROM_SIZE);
|
|
|
|
if (rcode < 0)
|
|
|
|
return rcode;
|
|
|
|
|
|
|
|
eeprom_layout_setup(&layout, eeprom_buf, CONFIG_SYS_EEPROM_SIZE,
|
|
|
|
layout_ver);
|
|
|
|
|
|
|
|
if (action == EEPROM_PRINT) {
|
|
|
|
layout.print(&layout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.update(&layout, key, value);
|
|
|
|
|
|
|
|
rcode = eeprom_write(i2c_addr, 0, layout.data, CONFIG_SYS_EEPROM_SIZE);
|
2016-04-16 22:55:12 +08:00
|
|
|
#endif
|
2016-04-16 22:55:03 +08:00
|
|
|
|
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NEXT_PARAM(argc, index) { (argc)--; (index)++; }
|
2016-04-16 22:55:13 +08:00
|
|
|
int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2016-04-16 22:55:03 +08:00
|
|
|
{
|
|
|
|
int layout_ver = LAYOUT_VERSION_AUTODETECT;
|
|
|
|
enum eeprom_action action = EEPROM_ACTION_INVALID;
|
2016-04-16 22:55:13 +08:00
|
|
|
int i2c_bus = -1, index = 0;
|
|
|
|
ulong i2c_addr = -1, addr = 0, cnt = 0, off = 0;
|
|
|
|
int ret;
|
2016-04-16 22:55:03 +08:00
|
|
|
char *field_name = "";
|
|
|
|
char *field_value = "";
|
|
|
|
|
|
|
|
if (argc <= 1)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
NEXT_PARAM(argc, index); /* Skip program name */
|
|
|
|
|
|
|
|
action = parse_action(argv[index]);
|
|
|
|
NEXT_PARAM(argc, index);
|
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
if (action == EEPROM_ACTION_INVALID)
|
2016-04-16 22:55:03 +08:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
|
|
|
if (action == EEPROM_PRINT || action == EEPROM_UPDATE) {
|
|
|
|
if (!strcmp(argv[index], "-l")) {
|
|
|
|
NEXT_PARAM(argc, index);
|
|
|
|
layout_ver = eeprom_parse_layout_version(argv[index]);
|
|
|
|
NEXT_PARAM(argc, index);
|
|
|
|
}
|
2016-04-16 22:55:03 +08:00
|
|
|
}
|
2016-04-16 22:55:13 +08:00
|
|
|
#endif
|
2016-04-16 22:55:03 +08:00
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
switch (action) {
|
|
|
|
case EEPROM_READ:
|
|
|
|
case EEPROM_WRITE:
|
|
|
|
ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
|
|
|
|
argv + index, 3);
|
|
|
|
break;
|
|
|
|
case EEPROM_PRINT:
|
|
|
|
ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
|
|
|
|
argv + index, 0);
|
|
|
|
break;
|
|
|
|
case EEPROM_UPDATE:
|
|
|
|
ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc,
|
|
|
|
argv + index, 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Get compiler to stop whining */
|
2016-04-16 22:55:03 +08:00
|
|
|
return CMD_RET_USAGE;
|
2016-04-16 22:55:13 +08:00
|
|
|
}
|
2016-04-16 22:55:03 +08:00
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
if (ret == CMD_RET_USAGE)
|
|
|
|
return ret;
|
2016-04-16 22:55:03 +08:00
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
while (ret--)
|
2016-04-16 22:55:03 +08:00
|
|
|
NEXT_PARAM(argc, index);
|
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
if (action == EEPROM_READ || action == EEPROM_WRITE) {
|
|
|
|
addr = parse_numeric_param(argv[index]);
|
|
|
|
NEXT_PARAM(argc, index);
|
|
|
|
off = parse_numeric_param(argv[index]);
|
2016-04-16 22:55:03 +08:00
|
|
|
NEXT_PARAM(argc, index);
|
2016-04-16 22:55:13 +08:00
|
|
|
cnt = parse_numeric_param(argv[index]);
|
2016-04-16 22:55:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
2016-04-16 22:55:13 +08:00
|
|
|
if (action == EEPROM_UPDATE) {
|
|
|
|
field_name = argv[index];
|
|
|
|
NEXT_PARAM(argc, index);
|
|
|
|
field_value = argv[index];
|
|
|
|
NEXT_PARAM(argc, index);
|
2016-04-16 22:55:03 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-16 22:55:13 +08:00
|
|
|
return eeprom_execute_command(action, i2c_bus, i2c_addr, layout_ver,
|
|
|
|
field_name, field_value, addr, off, cnt);
|
2015-11-11 03:53:18 +08:00
|
|
|
}
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
2016-04-16 22:55:03 +08:00
|
|
|
eeprom, 8, 1, do_eeprom,
|
2009-01-28 08:03:12 +08:00
|
|
|
"EEPROM sub-system",
|
2015-11-11 03:53:32 +08:00
|
|
|
"read <bus> <devaddr> addr off cnt\n"
|
|
|
|
"eeprom write <bus> <devaddr> addr off cnt\n"
|
2009-05-24 23:06:54 +08:00
|
|
|
" - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
|
2016-04-16 22:55:03 +08:00
|
|
|
#ifdef CONFIG_CMD_EEPROM_LAYOUT
|
|
|
|
"\n"
|
2016-04-16 22:55:13 +08:00
|
|
|
"eeprom print [-l <layout_version>] <bus> <devaddr>\n"
|
2016-04-16 22:55:03 +08:00
|
|
|
" - Print layout fields and their data in human readable format\n"
|
2016-04-16 22:55:13 +08:00
|
|
|
"eeprom update [-l <layout_version>] <bus> <devaddr> field_name field_value\n"
|
2016-04-16 22:55:03 +08:00
|
|
|
" - Update a specific eeprom field with new data.\n"
|
|
|
|
" The new data must be written in the same human readable format as shown by the print command.\n"
|
|
|
|
"\n"
|
|
|
|
"LAYOUT VERSIONS\n"
|
|
|
|
"The -l option can be used to force the command to interpret the EEPROM data using the chosen layout.\n"
|
|
|
|
"If the -l option is omitted, the command will auto detect the layout based on the data in the EEPROM.\n"
|
|
|
|
"The values which can be provided with the -l option are:\n"
|
|
|
|
CONFIG_EEPROM_LAYOUT_HELP_STRING"\n"
|
|
|
|
#endif
|
2014-06-23 06:22:08 +08:00
|
|
|
)
|