summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2015-11-10 20:53:23 +0100
committerTom Rini <trini@konsulko.com>2015-11-21 21:50:22 -0500
commit9132088b00b6ba4d57536f2a3895ee71f28509d0 (patch)
tree62bbed9cb9acbd9c7570b4827c7f1550789573ef
parent53a85ad79adb43fac2a57cfd241450a9d2f4ce42 (diff)
downloadu-boot-imx-9132088b00b6ba4d57536f2a3895ee71f28509d0.zip
u-boot-imx-9132088b00b6ba4d57536f2a3895ee71f28509d0.tar.gz
u-boot-imx-9132088b00b6ba4d57536f2a3895ee71f28509d0.tar.bz2
eeprom: Pull out the I/O code
Pull out the code which does the I2C or SPI read/write, so that the beefy ifdef around it is contained in a single function. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com> Cc: Heiko Schocher <hs@denx.de> Reviewed-by: Heiko Schocher <hs@denx.de>
-rw-r--r--common/cmd_eeprom.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/common/cmd_eeprom.c b/common/cmd_eeprom.c
index 728606e..7797d0e 100644
--- a/common/cmd_eeprom.c
+++ b/common/cmd_eeprom.c
@@ -61,6 +61,34 @@ void eeprom_init(void)
#endif
}
+static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
+ uchar *buffer, unsigned len, bool read)
+{
+ int ret = 0;
+
+ /* SPI */
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+ 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;
+}
+
int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
{
unsigned end = offset + cnt;
@@ -114,15 +142,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
len = maxlen;
#endif
-#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
- spi_read (addr, alen, buffer, len);
-#else
-#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
- i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
-#endif
- if (i2c_read(addr[0], offset, alen - 1, buffer, len))
- rcode = 1;
-#endif
+ rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 1);
+
buffer += len;
offset += len;
}
@@ -197,17 +218,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
len = maxlen;
#endif
-#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
- spi_write (addr, alen, buffer, len);
-#else
+ rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 0);
-#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
- i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
-#endif
- if (i2c_write(addr[0], offset, alen - 1, buffer, len))
- rcode = 1;
-
-#endif
buffer += len;
offset += len;