2002-08-27 13:55:31 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000, 2001
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-08-27 13:55:31 +08:00
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
extern void eeprom_init (void);
|
|
|
|
extern int eeprom_read (unsigned dev_addr, unsigned offset,
|
|
|
|
uchar *buffer, unsigned cnt);
|
|
|
|
extern int eeprom_write (unsigned dev_addr, unsigned offset,
|
|
|
|
uchar *buffer, unsigned cnt);
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_WREN)
|
2005-09-22 15:04:17 +08:00
|
|
|
extern int eeprom_write_enable (unsigned dev_addr, int state);
|
|
|
|
#endif
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_X40430)
|
2002-08-27 13:55:31 +08:00
|
|
|
/* Maximum number of times to poll for acknowledge after write */
|
|
|
|
#define MAX_ACKNOWLEDGE_POLLS 10
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2007-07-09 06:51:39 +08:00
|
|
|
#if defined(CONFIG_CMD_EEPROM)
|
2014-06-23 06:22:08 +08:00
|
|
|
static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
|
|
|
const char *const fmt =
|
|
|
|
"\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... ";
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
|
2002-08-27 13:55:31 +08:00
|
|
|
if (argc == 6) {
|
|
|
|
ulong dev_addr = simple_strtoul (argv[2], NULL, 16);
|
|
|
|
ulong addr = simple_strtoul (argv[3], NULL, 16);
|
|
|
|
ulong off = simple_strtoul (argv[4], NULL, 16);
|
|
|
|
ulong cnt = simple_strtoul (argv[5], NULL, 16);
|
|
|
|
#else
|
|
|
|
if (argc == 5) {
|
2008-10-16 21:01:15 +08:00
|
|
|
ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
|
2002-08-27 13:55:31 +08:00
|
|
|
ulong addr = simple_strtoul (argv[2], NULL, 16);
|
|
|
|
ulong off = simple_strtoul (argv[3], NULL, 16);
|
|
|
|
ulong cnt = simple_strtoul (argv[4], NULL, 16);
|
2008-10-16 21:01:15 +08:00
|
|
|
#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2010-01-07 15:55:40 +08:00
|
|
|
# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2002-08-27 13:55:31 +08:00
|
|
|
eeprom_init ();
|
|
|
|
# endif /* !CONFIG_SPI */
|
|
|
|
|
|
|
|
if (strcmp (argv[1], "read") == 0) {
|
|
|
|
int rcode;
|
|
|
|
|
|
|
|
printf (fmt, dev_addr, argv[1], addr, off, cnt);
|
|
|
|
|
|
|
|
rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt);
|
|
|
|
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("done\n");
|
2002-08-27 13:55:31 +08:00
|
|
|
return rcode;
|
|
|
|
} else if (strcmp (argv[1], "write") == 0) {
|
|
|
|
int rcode;
|
|
|
|
|
|
|
|
printf (fmt, dev_addr, argv[1], addr, off, cnt);
|
|
|
|
|
|
|
|
rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt);
|
|
|
|
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("done\n");
|
2002-08-27 13:55:31 +08:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-08-27 13:55:31 +08:00
|
|
|
}
|
2007-07-11 00:02:44 +08:00
|
|
|
#endif
|
2002-08-27 13:55:31 +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)
|
2008-10-16 21:01:15 +08:00
|
|
|
#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1 || CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2
|
|
|
|
#error CONFIG_SYS_I2C_EEPROM_ADDR_LEN must be 1 or 2
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
|
|
|
|
{
|
|
|
|
unsigned end = offset + cnt;
|
|
|
|
unsigned blk_off;
|
|
|
|
int rcode = 0;
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
while (offset < end) {
|
2005-08-13 03:16:13 +08:00
|
|
|
unsigned alen, len;
|
2008-10-16 21:01:15 +08:00
|
|
|
#if !defined(CONFIG_SYS_I2C_FRAM)
|
2005-08-13 03:16:13 +08:00
|
|
|
unsigned maxlen;
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
|
2002-08-27 13:55:31 +08:00
|
|
|
uchar addr[2];
|
|
|
|
|
|
|
|
blk_off = offset & 0xFF; /* block offset */
|
|
|
|
|
|
|
|
addr[0] = offset >> 8; /* block number */
|
|
|
|
addr[1] = blk_off; /* block offset */
|
|
|
|
alen = 2;
|
|
|
|
#else
|
|
|
|
uchar addr[3];
|
|
|
|
|
|
|
|
blk_off = offset & 0xFF; /* block offset */
|
|
|
|
|
|
|
|
addr[0] = offset >> 16; /* block number */
|
|
|
|
addr[1] = offset >> 8; /* upper address octet */
|
|
|
|
addr[2] = blk_off; /* lower address octet */
|
|
|
|
alen = 3;
|
2008-10-16 21:01:15 +08:00
|
|
|
#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
addr[0] |= dev_addr; /* insert device address */
|
|
|
|
|
2005-08-13 03:16:13 +08:00
|
|
|
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.
|
|
|
|
*/
|
2008-10-16 21:01:15 +08:00
|
|
|
#if !defined(CONFIG_SYS_I2C_FRAM)
|
2002-08-27 13:55:31 +08:00
|
|
|
maxlen = 0x100 - blk_off;
|
|
|
|
if (maxlen > I2C_RXTX_LEN)
|
|
|
|
maxlen = I2C_RXTX_LEN;
|
|
|
|
if (len > maxlen)
|
|
|
|
len = maxlen;
|
2005-08-13 03:16:13 +08:00
|
|
|
#endif
|
|
|
|
|
2010-01-07 15:55:40 +08:00
|
|
|
#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2002-08-27 13:55:31 +08:00
|
|
|
spi_read (addr, alen, buffer, len);
|
|
|
|
#else
|
2015-02-11 22:19:31 +08:00
|
|
|
#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
|
|
|
|
i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
|
|
|
|
#endif
|
2013-12-02 16:02:59 +08:00
|
|
|
if (i2c_read(addr[0], offset, alen - 1, buffer, len))
|
2002-08-27 13:55:31 +08:00
|
|
|
rcode = 1;
|
|
|
|
#endif
|
|
|
|
buffer += len;
|
|
|
|
offset += len;
|
|
|
|
}
|
2005-08-13 03:16:13 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
|
|
|
|
{
|
|
|
|
unsigned end = offset + cnt;
|
|
|
|
unsigned blk_off;
|
|
|
|
int rcode = 0;
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_X40430)
|
2002-08-27 13:55:31 +08:00
|
|
|
uchar contr_r_addr[2];
|
|
|
|
uchar addr_void[2];
|
|
|
|
uchar contr_reg[2];
|
|
|
|
uchar ctrl_reg_v;
|
|
|
|
int i;
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_WREN)
|
2005-09-22 15:04:17 +08:00
|
|
|
eeprom_write_enable (dev_addr,1);
|
|
|
|
#endif
|
2002-08-27 13:55:31 +08:00
|
|
|
/* Write data until done or would cross a write page boundary.
|
|
|
|
* We must write the address again when changing pages
|
|
|
|
* because the address counter only increments within a page.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (offset < end) {
|
2005-08-13 03:16:13 +08:00
|
|
|
unsigned alen, len;
|
2008-10-16 21:01:15 +08:00
|
|
|
#if !defined(CONFIG_SYS_I2C_FRAM)
|
2005-08-13 03:16:13 +08:00
|
|
|
unsigned maxlen;
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
|
2002-08-27 13:55:31 +08:00
|
|
|
uchar addr[2];
|
|
|
|
|
|
|
|
blk_off = offset & 0xFF; /* block offset */
|
|
|
|
|
|
|
|
addr[0] = offset >> 8; /* block number */
|
|
|
|
addr[1] = blk_off; /* block offset */
|
|
|
|
alen = 2;
|
|
|
|
#else
|
|
|
|
uchar addr[3];
|
|
|
|
|
|
|
|
blk_off = offset & 0xFF; /* block offset */
|
|
|
|
|
|
|
|
addr[0] = offset >> 16; /* block number */
|
|
|
|
addr[1] = offset >> 8; /* upper address octet */
|
|
|
|
addr[2] = blk_off; /* lower address octet */
|
|
|
|
alen = 3;
|
2008-10-16 21:01:15 +08:00
|
|
|
#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
|
2002-08-27 13:55:31 +08:00
|
|
|
|
|
|
|
addr[0] |= dev_addr; /* insert device address */
|
|
|
|
|
2005-08-13 03:16:13 +08:00
|
|
|
len = end - offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For a FRAM device there is no limit on the number of the
|
2011-07-15 06:09:28 +08:00
|
|
|
* bytes that can be accessed with the single read or write
|
2005-08-13 03:16:13 +08:00
|
|
|
* operation.
|
|
|
|
*/
|
2008-10-16 21:01:15 +08:00
|
|
|
#if !defined(CONFIG_SYS_I2C_FRAM)
|
2005-08-13 03:16:13 +08:00
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#define EEPROM_PAGE_SIZE (1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
|
2002-08-27 13:55:31 +08:00
|
|
|
#define EEPROM_PAGE_OFFSET(x) ((x) & (EEPROM_PAGE_SIZE - 1))
|
|
|
|
|
|
|
|
maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
|
|
|
|
#else
|
|
|
|
maxlen = 0x100 - blk_off;
|
|
|
|
#endif
|
|
|
|
if (maxlen > I2C_RXTX_LEN)
|
|
|
|
maxlen = I2C_RXTX_LEN;
|
|
|
|
|
|
|
|
if (len > maxlen)
|
|
|
|
len = maxlen;
|
2005-08-13 03:16:13 +08:00
|
|
|
#endif
|
|
|
|
|
2010-01-07 15:55:40 +08:00
|
|
|
#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2002-08-27 13:55:31 +08:00
|
|
|
spi_write (addr, alen, buffer, len);
|
|
|
|
#else
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_X40430)
|
2002-08-27 13:55:31 +08:00
|
|
|
/* Get the value of the control register.
|
|
|
|
* Set current address (internal pointer in the x40430)
|
|
|
|
* to 0x1ff.
|
|
|
|
*/
|
|
|
|
contr_r_addr[0] = 9;
|
|
|
|
contr_r_addr[1] = 0xff;
|
|
|
|
addr_void[0] = 0;
|
|
|
|
addr_void[1] = addr[1];
|
2008-10-16 21:01:15 +08:00
|
|
|
#ifdef CONFIG_SYS_I2C_EEPROM_ADDR
|
|
|
|
contr_r_addr[0] |= CONFIG_SYS_I2C_EEPROM_ADDR;
|
|
|
|
addr_void[0] |= CONFIG_SYS_I2C_EEPROM_ADDR;
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
contr_reg[0] = 0xff;
|
|
|
|
if (i2c_read (contr_r_addr[0], contr_r_addr[1], 1, contr_reg, 1) != 0) {
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
ctrl_reg_v = contr_reg[0];
|
|
|
|
|
|
|
|
/* Are any of the eeprom blocks write protected?
|
|
|
|
*/
|
|
|
|
if (ctrl_reg_v & 0x18) {
|
|
|
|
ctrl_reg_v &= ~0x18; /* reset block protect bits */
|
|
|
|
ctrl_reg_v |= 0x02; /* set write enable latch */
|
|
|
|
ctrl_reg_v &= ~0x04; /* clear RWEL */
|
|
|
|
|
|
|
|
/* Set write enable latch.
|
|
|
|
*/
|
|
|
|
contr_reg[0] = 0x02;
|
|
|
|
if (i2c_write (contr_r_addr[0], 0xff, 1, contr_reg, 1) != 0) {
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set register write enable latch.
|
|
|
|
*/
|
|
|
|
contr_reg[0] = 0x06;
|
|
|
|
if (i2c_write (contr_r_addr[0], 0xFF, 1, contr_reg, 1) != 0) {
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Modify ctrl register.
|
|
|
|
*/
|
|
|
|
contr_reg[0] = ctrl_reg_v;
|
|
|
|
if (i2c_write (contr_r_addr[0], 0xFF, 1, contr_reg, 1) != 0) {
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The write (above) is an operation on NV memory.
|
|
|
|
* These can take some time (~5ms), and the device
|
|
|
|
* will not respond to further I2C messages till
|
|
|
|
* it's completed the write.
|
|
|
|
* So poll device for an I2C acknowledge.
|
|
|
|
* When we get one we know we can continue with other
|
|
|
|
* operations.
|
|
|
|
*/
|
|
|
|
contr_reg[0] = 0;
|
|
|
|
for (i = 0; i < MAX_ACKNOWLEDGE_POLLS; i++) {
|
2003-01-18 00:27:01 +08:00
|
|
|
if (i2c_read (addr_void[0], addr_void[1], 1, contr_reg, 1) == 0)
|
2002-08-27 13:55:31 +08:00
|
|
|
break; /* got ack */
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
|
|
|
|
udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (i == MAX_ACKNOWLEDGE_POLLS) {
|
2004-03-24 06:14:11 +08:00
|
|
|
puts ("EEPROM poll acknowledge failed\n");
|
2002-08-27 13:55:31 +08:00
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the write enable latch on?.
|
|
|
|
*/
|
|
|
|
else if (!(ctrl_reg_v & 0x02)) {
|
|
|
|
/* Set write enable latch.
|
|
|
|
*/
|
|
|
|
contr_reg[0] = 0x02;
|
|
|
|
if (i2c_write (contr_r_addr[0], 0xFF, 1, contr_reg, 1) != 0) {
|
|
|
|
rcode = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Write is enabled ... now write eeprom value.
|
|
|
|
*/
|
2015-02-11 22:19:31 +08:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
|
|
|
|
i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
2013-12-02 16:02:59 +08:00
|
|
|
if (i2c_write(addr[0], offset, alen - 1, buffer, len))
|
2002-08-27 13:55:31 +08:00
|
|
|
rcode = 1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
buffer += len;
|
|
|
|
offset += len;
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
|
|
|
|
udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
}
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_EEPROM_WREN)
|
2005-09-22 15:04:17 +08:00
|
|
|
eeprom_write_enable (dev_addr,0);
|
|
|
|
#endif
|
2002-08-27 13:55:31 +08:00
|
|
|
return rcode;
|
|
|
|
}
|
|
|
|
|
2010-01-07 15:55:40 +08:00
|
|
|
#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2003-06-20 07:40:20 +08:00
|
|
|
int
|
|
|
|
eeprom_probe (unsigned dev_addr, unsigned offset)
|
|
|
|
{
|
|
|
|
unsigned char chip;
|
|
|
|
|
|
|
|
/* Probe the chip address
|
|
|
|
*/
|
2008-10-16 21:01:15 +08:00
|
|
|
#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
|
2003-06-20 07:40:20 +08:00
|
|
|
chip = offset >> 8; /* block number */
|
|
|
|
#else
|
|
|
|
chip = offset >> 16; /* block number */
|
2008-10-16 21:01:15 +08:00
|
|
|
#endif /* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
|
2003-06-20 07:40:20 +08:00
|
|
|
|
|
|
|
chip |= dev_addr; /* insert device address */
|
|
|
|
|
|
|
|
return (i2c_probe (chip));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* Set default values
|
|
|
|
*/
|
2008-10-16 21:01:15 +08:00
|
|
|
#ifndef CONFIG_SYS_I2C_SPEED
|
|
|
|
#define CONFIG_SYS_I2C_SPEED 50000
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void eeprom_init (void)
|
|
|
|
{
|
2010-01-07 15:55:40 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
|
2002-08-27 13:55:31 +08:00
|
|
|
spi_init_f ();
|
|
|
|
#endif
|
2014-10-14 17:16:33 +08:00
|
|
|
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
|
|
|
|
i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
|
2002-08-27 13:55:31 +08:00
|
|
|
#endif
|
|
|
|
}
|
2010-01-07 15:55:40 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
*/
|
2007-07-11 00:02:44 +08:00
|
|
|
|
2003-06-28 05:31:46 +08:00
|
|
|
/***************************************************/
|
|
|
|
|
2007-07-09 06:51:39 +08:00
|
|
|
#if defined(CONFIG_CMD_EEPROM)
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
eeprom, 6, 1, do_eeprom,
|
2009-01-28 08:03:12 +08:00
|
|
|
"EEPROM sub-system",
|
2003-06-28 05:31:46 +08:00
|
|
|
"read devaddr addr off cnt\n"
|
|
|
|
"eeprom write devaddr addr off cnt\n"
|
2009-05-24 23:06:54 +08:00
|
|
|
" - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
|
2014-06-23 06:22:08 +08:00
|
|
|
)
|
2003-06-28 05:31:46 +08:00
|
|
|
#else /* One EEPROM */
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
|
|
|
eeprom, 5, 1, do_eeprom,
|
2009-01-28 08:03:12 +08:00
|
|
|
"EEPROM sub-system",
|
2003-06-28 05:31:46 +08:00
|
|
|
"read addr off cnt\n"
|
|
|
|
"eeprom write addr off cnt\n"
|
2009-05-24 23:06:54 +08:00
|
|
|
" - read/write `cnt' bytes at EEPROM offset `off'"
|
2014-06-23 06:22:08 +08:00
|
|
|
)
|
2008-10-16 21:01:15 +08:00
|
|
|
#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
|
2003-06-28 05:31:46 +08:00
|
|
|
|
2007-07-11 00:02:44 +08:00
|
|
|
#endif
|