Skip to contentSkip to conversation

tricorder: rewrite tricordereeprom command

PATCH New Marek Vasut 3 participants 52 messages Nov 10, 2015 – Nov 22, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/17 tricorder: rewrite tricordereeprom command

From: Andreas Bie?mann <[email protected]>

This rewrite uses lately promoted eeprom_init(int) function to choose the right I2C bus when writing data to the EEPROM.

Cc Marek Vasut <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 board/corscience/tricorder/tricorder-eeprom.c | 36 +++++++--------------------
 1 file changed, 9 insertions(+), 27 deletions(-)
board/corscience/tricorder/tricorder-eeprom.c +9 -27
index 1c74a0f..340a009 100644
@@ -77,17 +77,13 @@ static int handle_eeprom_v1(struct tricorder_eeprom *eeprom)
 
 int tricorder_get_eeprom(int addr, struct tricorder_eeprom *eeprom)
 {
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	unsigned int bus = i2c_get_bus_num();
 	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
-#endif
 
 	memset(eeprom, 0, TRICORDER_EEPROM_SIZE);
 
 	i2c_read(addr, 0, 2, (unsigned char *)eeprom, TRICORDER_EEPROM_SIZE);
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
 	i2c_set_bus_num(bus);
-#endif
 
 	if (be32_to_cpu(eeprom->magic) != TRICORDER_EEPROM_MAGIC) {
 		warn_wrong_value("magic", TRICORDER_EEPROM_MAGIC,
@@ -138,9 +134,6 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,
 	int ret;
 	unsigned char *p;
 	int i;
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
-	unsigned int bus;
-#endif
 
 	memset(eeprom, 0, TRICORDER_EEPROM_SIZE);
 	memset(eeprom_verify, 0, TRICORDER_EEPROM_SIZE);
@@ -172,33 +165,23 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,
 	print_buffer(0, &eeprom, 1, sizeof(eeprom), 16);
 #endif
 
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
-	bus = i2c_get_bus_num();
-	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
-#endif
+	eeprom_init(CONFIG_SYS_EEPROM_BUS_NUM);
 
-	/* do page write to the eeprom */
-	for (i = 0, p = (unsigned char *)&eeprom;
-	     i < sizeof(eeprom);
-	     i += 32, p += 32) {
-		ret = i2c_write(devaddr, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
-				p, min(sizeof(eeprom) - i, 32));
-		if (ret)
-			break;
-		udelay(5000); /* 5ms write cycle timing */
-	}
+	ret = eeprom_write(devaddr, 0, (unsigned char *)&eeprom,
+			TRICORDER_EEPROM_SIZE);
+	if (ret)
+		printf("Tricorder: Could not write EEPROM content!\n");
 
-	ret = i2c_read(devaddr, 0, 2, (unsigned char *)&eeprom_verify,
+	ret = eeprom_read(devaddr, 0, (unsigned char *)&eeprom_verify,
 			TRICORDER_EEPROM_SIZE);
+	if (ret)
+		printf("Tricorder: Could not read EEPROM content!\n");
 
 	if (memcmp(&eeprom, &eeprom_verify, sizeof(eeprom)) != 0) {
 		printf("Tricorder: Could not verify EEPROM content!\n");
 		ret = 1;
 	}
 
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
-	i2c_set_bus_num(bus);
-#endif
 	return ret;
 }
 
@@ -206,7 +189,7 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	if (argc == 3) {
 		ulong dev_addr = simple_strtoul(argv[2], NULL, 16);
-		eeprom_init();
+
 		if (strcmp(argv[1], "read") == 0) {
 			int rcode;
 
@@ -220,7 +203,6 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 		char *version = argv[4];
 		char *serial = argv[5];
 		char *interface = NULL;
-		eeprom_init();
 
 		if (argc == 7)
 			interface = argv[6];
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/17 eeprom: Shuffle code around

Just move the code around so that the forward declarations are not necessary. Also zap a few checkpatch issues where applicable and zap the use of #ifdef CONFIG_CMD_EEPROM in the code, since this is always true.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 168 ++++++++++++++++++++++------------------------------
 1 file changed, 70 insertions(+), 98 deletions(-)
common/cmd_eeprom.c +70 -98
index e9904cd..4335079 100644
@@ -25,94 +25,55 @@
 #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);
-#if defined(CONFIG_SYS_EEPROM_WREN)
-extern int eeprom_write_enable (unsigned dev_addr, int state);
+#ifndef	CONFIG_SYS_I2C_SPEED
+#define	CONFIG_SYS_I2C_SPEED	50000
 #endif
 
-
+/* Maximum number of times to poll for acknowledge after write */
 #if defined(CONFIG_SYS_EEPROM_X40430)
-	/* Maximum number of times to poll for acknowledge after write */
 #define MAX_ACKNOWLEDGE_POLLS	10
 #endif
 
-/* ------------------------------------------------------------------------- */
-
-#if defined(CONFIG_CMD_EEPROM)
-static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-	const char *const fmt =
-		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
-
-#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
-	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) {
-		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
-		ulong addr = simple_strtoul (argv[2], NULL, 16);
-		ulong off  = simple_strtoul (argv[3], NULL, 16);
-		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
-#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
-
-# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-		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);
-
-			puts ("done\n");
-			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);
-
-			puts ("done\n");
-			return rcode;
-		}
-	}
-
-	return CMD_RET_USAGE;
-}
-#endif
-
-/*-----------------------------------------------------------------------
- *
+/*
  * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
  *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
  *
  * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
  *   0x00000nxx for EEPROM address selectors and page number at n.
  */
-
 #if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1 || CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2
+#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
 #endif
 #endif
 
+#if defined(CONFIG_SYS_EEPROM_WREN)
+extern int eeprom_write_enable (unsigned dev_addr, int state);
+#endif
+
+void eeprom_init(void)
+{
+	/* SPI EEPROM */
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+	spi_init_f ();
+#endif
+
+	/* I2C EEPROM */
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
+	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#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.
+	/*
+	 * 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.
 	 */
@@ -174,15 +135,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 	return rcode;
 }
 
-/*-----------------------------------------------------------------------
- *
- * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
- *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
- *
- * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
- *   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;
@@ -200,7 +152,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 #if defined(CONFIG_SYS_EEPROM_WREN)
 	eeprom_write_enable (dev_addr,1);
 #endif
-	/* Write data until done or would cross a write page boundary.
+	/*
+	 * 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.
 	 */
@@ -363,8 +316,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 }
 
 #if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-int
-eeprom_probe (unsigned dev_addr, unsigned offset)
+int eeprom_probe(unsigned dev_addr, unsigned offset)
 {
 	unsigned char chip;
 
@@ -382,30 +334,52 @@ eeprom_probe (unsigned dev_addr, unsigned offset)
 }
 #endif
 
-/*-----------------------------------------------------------------------
- * Set default values
- */
-#ifndef	CONFIG_SYS_I2C_SPEED
-#define	CONFIG_SYS_I2C_SPEED	50000
-#endif
-
-void eeprom_init  (void)
+static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
+	const char *const fmt =
+		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
 
-#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-	spi_init_f ();
-#endif
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
-	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
-#endif
-}
+#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
+	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) {
+		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
+		ulong addr = simple_strtoul (argv[2], NULL, 16);
+		ulong off  = simple_strtoul (argv[3], NULL, 16);
+		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
+#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
 
-/*-----------------------------------------------------------------------
- */
+# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+		eeprom_init ();
+# endif /* !CONFIG_SPI */
 
-/***************************************************/
+		if (strcmp (argv[1], "read") == 0) {
+			int rcode;
+
+			printf (fmt, dev_addr, argv[1], addr, off, cnt);
 
-#if defined(CONFIG_CMD_EEPROM)
+			rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt);
+
+			puts ("done\n");
+			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);
+
+			puts ("done\n");
+			return rcode;
+		}
+	}
+
+	return CMD_RET_USAGE;
+}
 
 #ifdef CONFIG_SYS_I2C_MULTI_EEPROMS
 U_BOOT_CMD(
@@ -424,5 +398,3 @@ U_BOOT_CMD(
 	"       - read/write `cnt' bytes at EEPROM offset `off'"
 )
 #endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
-
-#endif
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/17 eeprom: Shuffle code around

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 5 lines

Just move the code around so that the forward declarations are not necessary. Also zap a few checkpatch issues where applicable and zap the use of #ifdef CONFIG_CMD_EEPROM in the code, since this is always true.

Quoted 7 lines
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 168 ++++++++++++++++++++++------------------------------
  1 file changed, 70 insertions(+), 98 deletions(-)

bye,
Heiko

Quoted 241 lines
common/cmd_eeprom.c +70 -98
index e9904cd..4335079 100644
@@ -25,94 +25,55 @@
  #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);
-#if defined(CONFIG_SYS_EEPROM_WREN)
-extern int eeprom_write_enable (unsigned dev_addr, int state);
+#ifndef	CONFIG_SYS_I2C_SPEED
+#define	CONFIG_SYS_I2C_SPEED	50000
  #endif
 
-
+/* Maximum number of times to poll for acknowledge after write */
  #if defined(CONFIG_SYS_EEPROM_X40430)
-	/* Maximum number of times to poll for acknowledge after write */
  #define MAX_ACKNOWLEDGE_POLLS	10
  #endif
 
-/* ------------------------------------------------------------------------- */
-
-#if defined(CONFIG_CMD_EEPROM)
-static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-	const char *const fmt =
-		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
-
-#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
-	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) {
-		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
-		ulong addr = simple_strtoul (argv[2], NULL, 16);
-		ulong off  = simple_strtoul (argv[3], NULL, 16);
-		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
-#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
-
-# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-		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);
-
-			puts ("done\n");
-			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);
-
-			puts ("done\n");
-			return rcode;
-		}
-	}
-
-	return CMD_RET_USAGE;
-}
-#endif
-
-/*-----------------------------------------------------------------------
- *
+/*
   * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
   *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
   *
   * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
   *   0x00000nxx for EEPROM address selectors and page number at n.
   */
-
  #if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-#if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1 || CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2
+#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
  #endif
  #endif
 
+#if defined(CONFIG_SYS_EEPROM_WREN)
+extern int eeprom_write_enable (unsigned dev_addr, int state);
+#endif
+
+void eeprom_init(void)
+{
+	/* SPI EEPROM */
+#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+	spi_init_f ();
+#endif
+
+	/* I2C EEPROM */
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
+	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#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.
+	/*
+	 * 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.
  	 */
@@ -174,15 +135,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  	return rcode;
  }
 
-/*-----------------------------------------------------------------------
- *
- * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
- *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
- *
- * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 (8-bit EEPROM page address) offset is
- *   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;
@@ -200,7 +152,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  #if defined(CONFIG_SYS_EEPROM_WREN)
  	eeprom_write_enable (dev_addr,1);
  #endif
-	/* Write data until done or would cross a write page boundary.
+	/*
+	 * 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.
  	 */
@@ -363,8 +316,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  }
 
  #if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-int
-eeprom_probe (unsigned dev_addr, unsigned offset)
+int eeprom_probe(unsigned dev_addr, unsigned offset)
  {
  	unsigned char chip;
 
@@ -382,30 +334,52 @@ eeprom_probe (unsigned dev_addr, unsigned offset)
  }
  #endif
 
-/*-----------------------------------------------------------------------
- * Set default values
- */
-#ifndef	CONFIG_SYS_I2C_SPEED
-#define	CONFIG_SYS_I2C_SPEED	50000
-#endif
-
-void eeprom_init  (void)
+static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
+	const char *const fmt =
+		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
 
-#if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-	spi_init_f ();
-#endif
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
-	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
-#endif
-}
+#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
+	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) {
+		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
+		ulong addr = simple_strtoul (argv[2], NULL, 16);
+		ulong off  = simple_strtoul (argv[3], NULL, 16);
+		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
+#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
 
-/*-----------------------------------------------------------------------
- */
+# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
+		eeprom_init ();
+# endif /* !CONFIG_SPI */
 
-/***************************************************/
+		if (strcmp (argv[1], "read") == 0) {
+			int rcode;
+
+			printf (fmt, dev_addr, argv[1], addr, off, cnt);
 
-#if defined(CONFIG_CMD_EEPROM)
+			rcode = eeprom_read (dev_addr, off, (uchar *) addr, cnt);
+
+			puts ("done\n");
+			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);
+
+			puts ("done\n");
+			return rcode;
+		}
+	}
+
+	return CMD_RET_USAGE;
+}
 
  #ifdef CONFIG_SYS_I2C_MULTI_EEPROMS
  U_BOOT_CMD(
@@ -424,5 +398,3 @@ U_BOOT_CMD(
  	"       - read/write `cnt' bytes at EEPROM offset `off'"
  )
  #endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
-
-#endif
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

PATCH 2/17 eeprom: Shuffle code around

In reply to Marek Vasut
Quoted 10 lines · Marek Vasut

Just move the code around so that the forward declarations are not necessary. Also zap a few checkpatch issues where applicable and zap the use of #ifdef CONFIG_CMD_EEPROM in the code, since this is always true.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/94feae2e/attachment.sig>
#4 lore raw

PATCH 3/17 eeprom: Zap CONFIG_SYS_I2C_MULTI_EEPROMS

In reply to Marek Vasut

This option only complicates the code unnecessarily, just use CONFIG_SYS_DEF_EEPROM_ADDR as the default address if there are only five arguments to eeprom {read/write} if this is defined. If CONFIG_SYS_DEF_EEPROM_ADDR is not defined, we mandate all six arguments.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c             | 69 ++++++++++++++++++-----------------------
 include/configs/BSC9131RDB.h    |  1 -
 include/configs/BSC9132QDS.h    |  1 -
 include/configs/C29XPCIE.h      |  1 -
 include/configs/P1010RDB.h      |  1 -
 include/configs/PMC440.h        |  1 -
 include/configs/TQM834x.h       |  1 -
 include/configs/acadia.h        |  1 -
 include/configs/am335x_evm.h    |  1 -
 include/configs/am43xx_evm.h    |  1 -
 include/configs/axs101.h        |  1 -
 include/configs/bamboo.h        |  1 -
 include/configs/canyonlands.h   |  1 -
 include/configs/icon.h          |  1 -
 include/configs/intip.h         |  1 -
 include/configs/katmai.h        |  1 -
 include/configs/km/km-powerpc.h |  1 -
 include/configs/km/km_arm.h     |  1 -
 include/configs/luan.h          |  1 -
 include/configs/m28evk.h        |  1 -
 include/configs/motionpro.h     |  1 -
 include/configs/p1_p2_rdb_pc.h  |  1 -
 include/configs/p1_twr.h        |  1 -
 include/configs/pcm051.h        |  1 -
 include/configs/pengwyn.h       |  1 -
 include/configs/sequoia.h       |  1 -
 include/configs/t3corp.h        |  1 -
 include/configs/tricorder.h     |  1 -
 include/configs/walnut.h        |  1 -
 include/configs/yosemite.h      |  1 -
 30 files changed, 30 insertions(+), 68 deletions(-)
common/cmd_eeprom.c +30 -39
index 4335079..0b59bea 100644
@@ -338,50 +338,50 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	const char *const fmt =
 		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
+	char * const *args = &argv[2];
+	int rcode;
+	ulong dev_addr, addr, off, cnt;
+
+	switch (argc) {
+#ifdef CONFIG_SYS_DEF_EEPROM_ADDR
+	case 5:
+		dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
+		break;
+#endif
+	case 6:
+		dev_addr = simple_strtoul(*args++, NULL, 16);
+		break;
+	default:
+		return CMD_RET_USAGE;
+	}
 
-#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
-	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) {
-		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
-		ulong addr = simple_strtoul (argv[2], NULL, 16);
-		ulong off  = simple_strtoul (argv[3], NULL, 16);
-		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
-#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
+	addr = simple_strtoul(*args++, NULL, 16);
+	off = simple_strtoul(*args++, NULL, 16);
+	cnt = simple_strtoul(*args++, NULL, 16);
 
 # if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-		eeprom_init ();
+	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);
+	if (strcmp (argv[1], "read") == 0) {
+		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-			puts ("done\n");
-			return rcode;
-		} else if (strcmp (argv[1], "write") == 0) {
-			int rcode;
+		rcode = eeprom_read(dev_addr, off, (uchar *) addr, cnt);
 
-			printf (fmt, dev_addr, argv[1], addr, off, cnt);
+		puts ("done\n");
+		return rcode;
+	} else if (strcmp (argv[1], "write") == 0) {
+		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-			rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt);
+		rcode = eeprom_write(dev_addr, off, (uchar *) addr, cnt);
 
-			puts ("done\n");
-			return rcode;
-		}
+		puts ("done\n");
+		return rcode;
 	}
 
 	return CMD_RET_USAGE;
 }
 
-#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS
 U_BOOT_CMD(
 	eeprom,	6,	1,	do_eeprom,
 	"EEPROM sub-system",
@@ -389,12 +389,3 @@ U_BOOT_CMD(
 	"eeprom write devaddr addr off cnt\n"
 	"       - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
 )
-#else /* One EEPROM */
-U_BOOT_CMD(
-	eeprom,	5,	1,	do_eeprom,
-	"EEPROM sub-system",
-	"read  addr off cnt\n"
-	"eeprom write addr off cnt\n"
-	"       - read/write `cnt' bytes at EEPROM offset `off'"
-)
-#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
include/configs/BSC9131RDB.h +0 -1
index 2754016..193ffbc 100644
@@ -267,7 +267,6 @@ extern unsigned long get_sdram_size(void);
 
 /* I2C EEPROM */
 #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/BSC9132QDS.h +0 -1
index 54dcf3b..4b0e5f1 100644
@@ -463,7 +463,6 @@ combinations. this should be removed later
 
 /* enable read and write access to EEPROM */
 #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/C29XPCIE.h +0 -1
index 94f991b..c76d05f 100644
@@ -420,7 +420,6 @@
 /* I2C EEPROM */
 /* enable read and write access to EEPROM */
 #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/P1010RDB.h +0 -1
index 81b0855..8a137d0 100644
@@ -660,7 +660,6 @@ extern unsigned long get_sdram_size(void);
 #endif
 /* enable read and write access to EEPROM */
 #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/PMC440.h +0 -1
index 0227649..26a1444 100644
@@ -159,7 +159,6 @@
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_1		400000
 #define CONFIG_SYS_I2C_PPC4XX_SLAVE_1		0x7F
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
 #define CONFIG_SYS_I2C_EEPROM_ADDR		0x54
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		2
include/configs/TQM834x.h +0 -1
index 0b046d1..9f6bd0f 100644
@@ -183,7 +183,6 @@
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		2	/* 16 bit */
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	5	/* 32 bytes/write */
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	12	/* 10ms +/- 20% */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS		/* more than one eeprom */
 
 /* I2C RTC */
 #define CONFIG_RTC_DS1337			/* use ds1337 rtc via i2c */
include/configs/acadia.h +0 -1
index 4dd5720..2f53d73 100644
@@ -120,7 +120,6 @@
  *----------------------------------------------------------------------*/
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/am335x_evm.h +0 -1
index d58816d..a4b8e0f 100644
@@ -213,7 +213,6 @@
 #define CONFIG_ENV_EEPROM_IS_ON_I2C
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
 /* PMIC support */
 #define CONFIG_POWER_TPS65217
include/configs/am43xx_evm.h +0 -1
index d93e3e7..5821137 100644
@@ -36,7 +36,6 @@
 #define CONFIG_ENV_EEPROM_IS_ON_I2C
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
 /* Power */
 #define CONFIG_POWER
include/configs/axs101.h +0 -1
index 450291c..e921f19 100644
@@ -91,7 +91,6 @@
 /*
  * EEPROM configuration
  */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xA8 >> 1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
 #define CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW	1
include/configs/bamboo.h +0 -1
index 6ba4aaf..5b8b22f 100644
@@ -139,7 +139,6 @@
  *----------------------------------------------------------------------*/
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/canyonlands.h +0 -1
index ed790cc..e136824 100644
@@ -248,7 +248,6 @@
  *----------------------------------------------------------------------*/
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
include/configs/icon.h +0 -1
index bbe9b59..d9a3671 100644
@@ -107,7 +107,6 @@
 
 #define CONFIG_SYS_SPD_BUS_NUM	0	/* The I2C bus for SPD		*/
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/intip.h +0 -1
index a676a20..60c9e2c 100644
@@ -214,7 +214,6 @@
  */
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
include/configs/katmai.h +0 -1
index fa72eb0..664896b 100644
@@ -109,7 +109,6 @@
 #define IIC0_BOOTPROM_ADDR	0x50
 #define IIC0_ALT_BOOTPROM_ADDR	0x54
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0x50)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/km/km-powerpc.h +0 -1
index eb85a74..2b0b9dc 100644
@@ -21,7 +21,6 @@
 #define CONFIG_KM_COMMON_ETH_INIT
 
 /* EEprom support 24C08, 24C16, 24C64 */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3  /* 8 Byte write page */
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	10
include/configs/km/km_arm.h +0 -1
index b89af53..798c9a7 100644
@@ -215,7 +215,6 @@ int get_scl(void);
 #define	CONFIG_SYS_I2C_SOFT_SPEED	100000
 
 /* EEprom support 24C128, 24C256 valid for environment eeprom */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	6 /* 64 Byte write page */
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	10
include/configs/luan.h +0 -1
index 15e4a7e..e22d0e8 100644
@@ -119,7 +119,6 @@
  *----------------------------------------------------------------------*/
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/m28evk.h +0 -1
index 29c60b7..f9fc66f 100644
@@ -92,7 +92,6 @@
 
 /* EEPROM */
 #ifdef CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
 #endif
 
include/configs/motionpro.h +0 -1
index 97c614b..a8cf201 100644
@@ -285,7 +285,6 @@
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	1	/* 2 bytes per write cycle */
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	5	/* 2ms/cycle + 3ms extra */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS		1	/* 2 EEPROMs (addr:50,52) */
 
 /*
  * RTC configuration
include/configs/p1_p2_rdb_pc.h +0 -1
index 433c409..e039af4 100644
@@ -701,7 +701,6 @@
 
 /* enable read and write access to EEPROM */
 #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/p1_twr.h +0 -1
index d83daa0..3089969 100644
@@ -262,7 +262,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 
 /* enable read and write access to EEPROM */
 #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/pcm051.h +0 -1
index 275e952..64cfd81 100644
@@ -115,7 +115,6 @@
 #define CONFIG_ENV_EEPROM_IS_ON_I2C
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
 #define CONFIG_SYS_BAUDRATE_TABLE	{ 110, 300, 600, 1200, 2400, \
 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 }
include/configs/pengwyn.h +0 -1
index ccb5dd3..b057539 100644
@@ -112,7 +112,6 @@
 #define CONFIG_ENV_EEPROM_IS_ON_I2C
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
 /* SPL */
 #define CONFIG_SPL_POWER_SUPPORT
include/configs/sequoia.h +0 -1
index 1f1beea..f32459b 100644
@@ -151,7 +151,6 @@
  */
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/t3corp.h +0 -1
index 502e795..7942865 100644
@@ -307,7 +307,6 @@
  */
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0			400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
include/configs/tricorder.h +0 -1
index 02b0e63..e453151 100644
@@ -112,7 +112,6 @@
  
 
 /* EEPROM */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_CMD_EEPROM
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
 #define CONFIG_SYS_EEPROM_BUS_NUM	1
include/configs/walnut.h +0 -1
index 8b803a2..dd6b519 100644
@@ -80,7 +80,6 @@
  */
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/yosemite.h +0 -1
index 8508a80..0cffab8 100644
@@ -122,7 +122,6 @@
  *----------------------------------------------------------------------*/
 #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
Signature · 1 line
2.1.4
#5 lore raw

PATCH 3/17 eeprom: Zap CONFIG_SYS_I2C_MULTI_EEPROMS

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 34 lines

This option only complicates the code unnecessarily, just use CONFIG_SYS_DEF_EEPROM_ADDR as the default address if there are only five arguments to eeprom {read/write} if this is defined. If CONFIG_SYS_DEF_EEPROM_ADDR is not defined, we mandate all six arguments.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c             | 69 ++++++++++++++++++-----------------------
  include/configs/BSC9131RDB.h    |  1 -
  include/configs/BSC9132QDS.h    |  1 -
  include/configs/C29XPCIE.h      |  1 -
  include/configs/P1010RDB.h      |  1 -
  include/configs/PMC440.h        |  1 -
  include/configs/TQM834x.h       |  1 -
  include/configs/acadia.h        |  1 -
  include/configs/am335x_evm.h    |  1 -
  include/configs/am43xx_evm.h    |  1 -
  include/configs/axs101.h        |  1 -
  include/configs/bamboo.h        |  1 -
  include/configs/canyonlands.h   |  1 -
  include/configs/icon.h          |  1 -
  include/configs/intip.h         |  1 -
  include/configs/katmai.h        |  1 -
  include/configs/km/km-powerpc.h |  1 -
  include/configs/km/km_arm.h     |  1 -
  include/configs/luan.h          |  1 -
  include/configs/m28evk.h        |  1 -
  include/configs/motionpro.h     |  1 -
  include/configs/p1_p2_rdb_pc.h  |  1 -
  include/configs/p1_twr.h        |  1 -
Quoted 8 lines
  include/configs/pcm051.h        |  1 -
  include/configs/pengwyn.h       |  1 -
  include/configs/sequoia.h       |  1 -
  include/configs/t3corp.h        |  1 -
  include/configs/tricorder.h     |  1 -
  include/configs/walnut.h        |  1 -
  include/configs/yosemite.h      |  1 -
  30 files changed, 30 insertions(+), 68 deletions(-)

bye,
Heiko

Quoted 448 lines
common/cmd_eeprom.c +30 -39
index 4335079..0b59bea 100644
@@ -338,50 +338,50 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	const char *const fmt =
  		"\nEEPROM @0x%lX %s: addr %08lx  off %04lx  count %ld ... ";
+	char * const *args = &argv[2];
+	int rcode;
+	ulong dev_addr, addr, off, cnt;
+
+	switch (argc) {
+#ifdef CONFIG_SYS_DEF_EEPROM_ADDR
+	case 5:
+		dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
+		break;
+#endif
+	case 6:
+		dev_addr = simple_strtoul(*args++, NULL, 16);
+		break;
+	default:
+		return CMD_RET_USAGE;
+	}
 
-#if defined(CONFIG_SYS_I2C_MULTI_EEPROMS)
-	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) {
-		ulong dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
-		ulong addr = simple_strtoul (argv[2], NULL, 16);
-		ulong off  = simple_strtoul (argv[3], NULL, 16);
-		ulong cnt  = simple_strtoul (argv[4], NULL, 16);
-#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
+	addr = simple_strtoul(*args++, NULL, 16);
+	off = simple_strtoul(*args++, NULL, 16);
+	cnt = simple_strtoul(*args++, NULL, 16);
 
  # if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-		eeprom_init ();
+	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);
+	if (strcmp (argv[1], "read") == 0) {
+		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-			puts ("done\n");
-			return rcode;
-		} else if (strcmp (argv[1], "write") == 0) {
-			int rcode;
+		rcode = eeprom_read(dev_addr, off, (uchar *) addr, cnt);
 
-			printf (fmt, dev_addr, argv[1], addr, off, cnt);
+		puts ("done\n");
+		return rcode;
+	} else if (strcmp (argv[1], "write") == 0) {
+		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-			rcode = eeprom_write (dev_addr, off, (uchar *) addr, cnt);
+		rcode = eeprom_write(dev_addr, off, (uchar *) addr, cnt);
 
-			puts ("done\n");
-			return rcode;
-		}
+		puts ("done\n");
+		return rcode;
  	}
 
  	return CMD_RET_USAGE;
  }
 
-#ifdef CONFIG_SYS_I2C_MULTI_EEPROMS
  U_BOOT_CMD(
  	eeprom,	6,	1,	do_eeprom,
  	"EEPROM sub-system",
@@ -389,12 +389,3 @@ U_BOOT_CMD(
  	"eeprom write devaddr addr off cnt\n"
  	"       - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
  )
-#else /* One EEPROM */
-U_BOOT_CMD(
-	eeprom,	5,	1,	do_eeprom,
-	"EEPROM sub-system",
-	"read  addr off cnt\n"
-	"eeprom write addr off cnt\n"
-	"       - read/write `cnt' bytes at EEPROM offset `off'"
-)
-#endif /* CONFIG_SYS_I2C_MULTI_EEPROMS */
include/configs/BSC9131RDB.h +0 -1
index 2754016..193ffbc 100644
@@ -267,7 +267,6 @@ extern unsigned long get_sdram_size(void);
 
  /* I2C EEPROM */
  #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/BSC9132QDS.h +0 -1
index 54dcf3b..4b0e5f1 100644
@@ -463,7 +463,6 @@ combinations. this should be removed later
 
  /* enable read and write access to EEPROM */
  #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/C29XPCIE.h +0 -1
index 94f991b..c76d05f 100644
@@ -420,7 +420,6 @@
  /* I2C EEPROM */
  /* enable read and write access to EEPROM */
  #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/P1010RDB.h +0 -1
index 81b0855..8a137d0 100644
@@ -660,7 +660,6 @@ extern unsigned long get_sdram_size(void);
  #endif
  /* enable read and write access to EEPROM */
  #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/PMC440.h +0 -1
index 0227649..26a1444 100644
@@ -159,7 +159,6 @@
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_1		400000
  #define CONFIG_SYS_I2C_PPC4XX_SLAVE_1		0x7F
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
  #define CONFIG_SYS_I2C_EEPROM_ADDR		0x54
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		2
include/configs/TQM834x.h +0 -1
index 0b046d1..9f6bd0f 100644
@@ -183,7 +183,6 @@
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		2	/* 16 bit */
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	5	/* 32 bytes/write */
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	12	/* 10ms +/- 20% */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS		/* more than one eeprom */
 
  /* I2C RTC */
  #define CONFIG_RTC_DS1337			/* use ds1337 rtc via i2c */
include/configs/acadia.h +0 -1
index 4dd5720..2f53d73 100644
@@ -120,7 +120,6 @@
   *----------------------------------------------------------------------*/
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/am335x_evm.h +0 -1
index d58816d..a4b8e0f 100644
@@ -213,7 +213,6 @@
  #define CONFIG_ENV_EEPROM_IS_ON_I2C
  #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
  /* PMIC support */
  #define CONFIG_POWER_TPS65217
include/configs/am43xx_evm.h +0 -1
index d93e3e7..5821137 100644
@@ -36,7 +36,6 @@
  #define CONFIG_ENV_EEPROM_IS_ON_I2C
  #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
  /* Power */
  #define CONFIG_POWER
include/configs/axs101.h +0 -1
index 450291c..e921f19 100644
@@ -91,7 +91,6 @@
  /*
   * EEPROM configuration
   */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xA8 >> 1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
  #define CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW	1
include/configs/bamboo.h +0 -1
index 6ba4aaf..5b8b22f 100644
@@ -139,7 +139,6 @@
   *----------------------------------------------------------------------*/
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/canyonlands.h +0 -1
index ed790cc..e136824 100644
@@ -248,7 +248,6 @@
   *----------------------------------------------------------------------*/
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
include/configs/icon.h +0 -1
index bbe9b59..d9a3671 100644
@@ -107,7 +107,6 @@
 
  #define CONFIG_SYS_SPD_BUS_NUM	0	/* The I2C bus for SPD		*/
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/intip.h +0 -1
index a676a20..60c9e2c 100644
@@ -214,7 +214,6 @@
   */
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
include/configs/katmai.h +0 -1
index fa72eb0..664896b 100644
@@ -109,7 +109,6 @@
  #define IIC0_BOOTPROM_ADDR	0x50
  #define IIC0_ALT_BOOTPROM_ADDR	0x54
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0x50)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/km/km-powerpc.h +0 -1
index eb85a74..2b0b9dc 100644
@@ -21,7 +21,6 @@
  #define CONFIG_KM_COMMON_ETH_INIT
 
  /* EEprom support 24C08, 24C16, 24C64 */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3  /* 8 Byte write page */
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	10
include/configs/km/km_arm.h +0 -1
index b89af53..798c9a7 100644
@@ -215,7 +215,6 @@ int get_scl(void);
  #define	CONFIG_SYS_I2C_SOFT_SPEED	100000
 
  /* EEprom support 24C128, 24C256 valid for environment eeprom */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_ENABLE
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	6 /* 64 Byte write page */
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	10
include/configs/luan.h +0 -1
index 15e4a7e..e22d0e8 100644
@@ -119,7 +119,6 @@
   *----------------------------------------------------------------------*/
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/m28evk.h +0 -1
index 29c60b7..f9fc66f 100644
@@ -92,7 +92,6 @@
 
  /* EEPROM */
  #ifdef CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
  #endif
 
include/configs/motionpro.h +0 -1
index 97c614b..a8cf201 100644
@@ -285,7 +285,6 @@
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	1	/* 2 bytes per write cycle */
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	5	/* 2ms/cycle + 3ms extra */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS		1	/* 2 EEPROMs (addr:50,52) */
 
  /*
   * RTC configuration
include/configs/p1_p2_rdb_pc.h +0 -1
index 433c409..e039af4 100644
@@ -701,7 +701,6 @@
 
  /* enable read and write access to EEPROM */
  #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/p1_twr.h +0 -1
index d83daa0..3089969 100644
@@ -262,7 +262,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 
  /* enable read and write access to EEPROM */
  #define CONFIG_CMD_EEPROM
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 5
include/configs/pcm051.h +0 -1
index 275e952..64cfd81 100644
@@ -115,7 +115,6 @@
  #define CONFIG_ENV_EEPROM_IS_ON_I2C
  #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
  #define CONFIG_SYS_BAUDRATE_TABLE	{ 110, 300, 600, 1200, 2400, \
  4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 }
include/configs/pengwyn.h +0 -1
index ccb5dd3..b057539 100644
@@ -112,7 +112,6 @@
  #define CONFIG_ENV_EEPROM_IS_ON_I2C
  #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
 
  /* SPL */
  #define CONFIG_SPL_POWER_SUPPORT
include/configs/sequoia.h +0 -1
index 1f1beea..f32459b 100644
@@ -151,7 +151,6 @@
   */
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/t3corp.h +0 -1
index 502e795..7942865 100644
@@ -307,7 +307,6 @@
   */
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0			400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR		(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
include/configs/tricorder.h +0 -1
index 02b0e63..e453151 100644
@@ -112,7 +112,6 @@
 
 
  /* EEPROM */
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_CMD_EEPROM
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
  #define CONFIG_SYS_EEPROM_BUS_NUM	1
include/configs/walnut.h +0 -1
index 8b803a2..dd6b519 100644
@@ -80,7 +80,6 @@
   */
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
include/configs/yosemite.h +0 -1
index 8508a80..0cffab8 100644
@@ -122,7 +122,6 @@
   *----------------------------------------------------------------------*/
  #define CONFIG_SYS_I2C_PPC4XX_SPEED_0		400000
 
-#define CONFIG_SYS_I2C_MULTI_EEPROMS
  #define CONFIG_SYS_I2C_EEPROM_ADDR	(0xa8>>1)
  #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 3
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#6 lore raw

PATCH 3/17 eeprom: Zap CONFIG_SYS_I2C_MULTI_EEPROMS

In reply to Marek Vasut
Quoted 11 lines · Marek Vasut

This option only complicates the code unnecessarily, just use CONFIG_SYS_DEF_EEPROM_ADDR as the default address if there are only five arguments to eeprom {read/write} if this is defined. If CONFIG_SYS_DEF_EEPROM_ADDR is not defined, we mandate all six arguments.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/61493f78/attachment.sig>
#7 lore raw

PATCH 4/17 eeprom: Zap CONFIG_SYS_EEPROM_X40430

In reply to Marek Vasut

Now that the only user of CONFIG_SYS_EEPROM_X40430 was removed, remove this unused code from cmd_eeprom.c

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 94 -----------------------------------------------------
 1 file changed, 94 deletions(-)
common/cmd_eeprom.c +0 -94
index 0b59bea..266f954 100644
@@ -29,11 +29,6 @@
 #define	CONFIG_SYS_I2C_SPEED	50000
 #endif
 
-/* Maximum number of times to poll for acknowledge after write */
-#if defined(CONFIG_SYS_EEPROM_X40430)
-#define MAX_ACKNOWLEDGE_POLLS	10
-#endif
-
 /*
  * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
  *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -141,14 +136,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 	unsigned blk_off;
 	int rcode = 0;
 
-#if defined(CONFIG_SYS_EEPROM_X40430)
-	uchar	contr_r_addr[2];
-	uchar	addr_void[2];
-	uchar	contr_reg[2];
-	uchar	ctrl_reg_v;
-	int	i;
-#endif
-
 #if defined(CONFIG_SYS_EEPROM_WREN)
 	eeprom_write_enable (dev_addr,1);
 #endif
@@ -213,88 +200,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
 		spi_write (addr, alen, buffer, len);
 #else
-#if defined(CONFIG_SYS_EEPROM_X40430)
-		/* 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];
-#ifdef CONFIG_SYS_I2C_EEPROM_ADDR
-		contr_r_addr[0] |= CONFIG_SYS_I2C_EEPROM_ADDR;
-		addr_void[0]    |= CONFIG_SYS_I2C_EEPROM_ADDR;
-#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++) {
-				if (i2c_read (addr_void[0], addr_void[1], 1, contr_reg, 1) == 0)
-					break;	/* got ack */
-#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
-				udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-#endif
-			}
-			if (i == MAX_ACKNOWLEDGE_POLLS) {
-				puts ("EEPROM poll acknowledge failed\n");
-				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.
-		 */
-#endif
 #if defined(CONFIG_SYS_I2C_EEPROM_BUS)
 		i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
 #endif
Signature · 1 line
2.1.4
#8 lore raw

PATCH 4/17 eeprom: Zap CONFIG_SYS_EEPROM_X40430

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

Now that the only user of CONFIG_SYS_EEPROM_X40430 was removed, remove this unused code from cmd_eeprom.c

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 94 -----------------------------------------------------
  1 file changed, 94 deletions(-)

bye,
Heiko

Quoted 122 lines
common/cmd_eeprom.c +0 -94
index 0b59bea..266f954 100644
@@ -29,11 +29,6 @@
  #define	CONFIG_SYS_I2C_SPEED	50000
  #endif
 
-/* Maximum number of times to poll for acknowledge after write */
-#if defined(CONFIG_SYS_EEPROM_X40430)
-#define MAX_ACKNOWLEDGE_POLLS	10
-#endif
-
  /*
   * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
   *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -141,14 +136,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  	unsigned blk_off;
  	int rcode = 0;
 
-#if defined(CONFIG_SYS_EEPROM_X40430)
-	uchar	contr_r_addr[2];
-	uchar	addr_void[2];
-	uchar	contr_reg[2];
-	uchar	ctrl_reg_v;
-	int	i;
-#endif
-
  #if defined(CONFIG_SYS_EEPROM_WREN)
  	eeprom_write_enable (dev_addr,1);
  #endif
@@ -213,88 +200,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
  		spi_write (addr, alen, buffer, len);
  #else
-#if defined(CONFIG_SYS_EEPROM_X40430)
-		/* 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];
-#ifdef CONFIG_SYS_I2C_EEPROM_ADDR
-		contr_r_addr[0] |= CONFIG_SYS_I2C_EEPROM_ADDR;
-		addr_void[0]    |= CONFIG_SYS_I2C_EEPROM_ADDR;
-#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++) {
-				if (i2c_read (addr_void[0], addr_void[1], 1, contr_reg, 1) == 0)
-					break;	/* got ack */
-#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
-				udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-#endif
-			}
-			if (i == MAX_ACKNOWLEDGE_POLLS) {
-				puts ("EEPROM poll acknowledge failed\n");
-				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.
-		 */
-#endif
  #if defined(CONFIG_SYS_I2C_EEPROM_BUS)
  		i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
  #endif
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#9 lore raw

PATCH 4/17 eeprom: Zap CONFIG_SYS_EEPROM_X40430

In reply to Marek Vasut
Quoted 8 lines · Marek Vasut

Now that the only user of CONFIG_SYS_EEPROM_X40430 was removed, remove this unused code from cmd_eeprom.c

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/284a924a/attachment.sig>
#10 lore raw

PATCH 5/17 eeprom: Zap eeprom_probe()

In reply to Marek Vasut

Remove this function as it's no longer used.

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 19 -------------------
 include/common.h    |  3 ---
 2 files changed, 22 deletions(-)
common/cmd_eeprom.c +0 -19
index 266f954..ea1d447 100644
@@ -221,25 +221,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 	return rcode;
 }
 
-#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-int eeprom_probe(unsigned dev_addr, unsigned offset)
-{
-	unsigned char chip;
-
-	/* Probe the chip address
-	 */
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
-	chip = offset >> 8;		/* block number */
-#else
-	chip = offset >> 16;		/* block number */
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
-
-	chip |= dev_addr;		/* insert device address */
-
-	return (i2c_probe (chip));
-}
-#endif
-
 static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	const char *const fmt =
include/common.h +0 -3
index 09a131d..ceb1ad3 100644
@@ -476,9 +476,6 @@ void	fdc_hw_init   (void);
 
 /* $(BOARD)/eeprom.c */
 void eeprom_init  (void);
-#ifndef CONFIG_SPI
-int  eeprom_probe (unsigned dev_addr, unsigned offset);
-#endif
 int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
 int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
 
Signature · 1 line
2.1.4
#11 lore raw

PATCH 5/17 eeprom: Zap eeprom_probe()

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

Remove this function as it's no longer used.

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 19 -------------------
  include/common.h    |  3 ---
  2 files changed, 22 deletions(-)

bye,
Heiko

Quoted 46 lines
common/cmd_eeprom.c +0 -19
index 266f954..ea1d447 100644
@@ -221,25 +221,6 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  	return rcode;
  }
 
-#if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-int eeprom_probe(unsigned dev_addr, unsigned offset)
-{
-	unsigned char chip;
-
-	/* Probe the chip address
-	 */
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
-	chip = offset >> 8;		/* block number */
-#else
-	chip = offset >> 16;		/* block number */
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
-
-	chip |= dev_addr;		/* insert device address */
-
-	return (i2c_probe (chip));
-}
-#endif
-
  static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	const char *const fmt =
include/common.h +0 -3
index 09a131d..ceb1ad3 100644
@@ -476,9 +476,6 @@ void	fdc_hw_init   (void);
 
  /* $(BOARD)/eeprom.c */
  void eeprom_init  (void);
-#ifndef CONFIG_SPI
-int  eeprom_probe (unsigned dev_addr, unsigned offset);
-#endif
  int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#12 lore raw

PATCH 5/17 eeprom: Zap eeprom_probe()

In reply to Marek Vasut
Quoted 7 lines · Marek Vasut

Remove this function as it's no longer used.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/5cf52cf2/attachment.sig>
#13 lore raw

PATCH 6/17 eeprom: Zap CONFIG_SPI_X

In reply to Marek Vasut

This macro is no longer used, so just reap it.

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 README              | 5 -----
 common/cmd_eeprom.c | 8 ++++----
 2 files changed, 4 insertions(+), 9 deletions(-)
README +0 -5
index ef8d437..8fb81e9 100644
@@ -2705,11 +2705,6 @@ CBFS (Coreboot Filesystem) support
 		Enables the driver for SPI controller on SuperH. Currently
 		only SH7757 is supported.
 
-		CONFIG_SPI_X
-
-		Enables extended (16-bit) SPI EEPROM addressing.
-		(symmetrical to CONFIG_I2C_X)
-
 		CONFIG_SOFT_SPI
 
 		Enables a software (bit-bang) SPI driver rather than
common/cmd_eeprom.c +4 -4
index ea1d447..728606e 100644
@@ -78,7 +78,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 		unsigned maxlen;
 #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
+#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
 		uchar addr[2];
 
 		blk_off = offset & 0xFF;	/* block offset */
@@ -95,7 +95,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 		addr[1] = offset >>  8;		/* upper address octet */
 		addr[2] = blk_off;		/* lower address octet */
 		alen	= 3;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
+#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
 
 		addr[0] |= dev_addr;		/* insert device address */
 
@@ -151,7 +151,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 		unsigned maxlen;
 #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
+#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
 		uchar addr[2];
 
 		blk_off = offset & 0xFF;	/* block offset */
@@ -168,7 +168,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 		addr[1] = offset >>  8;		/* upper address octet */
 		addr[2] = blk_off;		/* lower address octet */
 		alen	= 3;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
+#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
 
 		addr[0] |= dev_addr;		/* insert device address */
 
Signature · 1 line
2.1.4
#14 lore raw

PATCH 6/17 eeprom: Zap CONFIG_SPI_X

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

This macro is no longer used, so just reap it.

Cc Tom Rini <[email protected]>
Cc Simon Glass <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  README              | 5 -----
  common/cmd_eeprom.c | 8 ++++----
  2 files changed, 4 insertions(+), 9 deletions(-)

bye,
Heiko

Quoted 58 lines
README +0 -5
index ef8d437..8fb81e9 100644
@@ -2705,11 +2705,6 @@ CBFS (Coreboot Filesystem) support
  		Enables the driver for SPI controller on SuperH. Currently
  		only SH7757 is supported.
 
-		CONFIG_SPI_X
-
-		Enables extended (16-bit) SPI EEPROM addressing.
-		(symmetrical to CONFIG_I2C_X)
-
  		CONFIG_SOFT_SPI
 
  		Enables a software (bit-bang) SPI driver rather than
common/cmd_eeprom.c +4 -4
index ea1d447..728606e 100644
@@ -78,7 +78,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  		unsigned maxlen;
  #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
+#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
  		uchar addr[2];
 
  		blk_off = offset & 0xFF;	/* block offset */
@@ -95,7 +95,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  		addr[1] = offset >>  8;		/* upper address octet */
  		addr[2] = blk_off;		/* lower address octet */
  		alen	= 3;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
+#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
 
  		addr[0] |= dev_addr;		/* insert device address */
 
@@ -151,7 +151,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  		unsigned maxlen;
  #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1 && !defined(CONFIG_SPI_X)
+#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
  		uchar addr[2];
 
  		blk_off = offset & 0xFF;	/* block offset */
@@ -168,7 +168,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  		addr[1] = offset >>  8;		/* upper address octet */
  		addr[2] = blk_off;		/* lower address octet */
  		alen	= 3;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN, CONFIG_SPI_X */
+#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
 
  		addr[0] |= dev_addr;		/* insert device address */
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#15 lore raw

PATCH 6/17 eeprom: Zap CONFIG_SPI_X

In reply to Marek Vasut
Quoted 7 lines · Marek Vasut

This macro is no longer used, so just reap it.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/48cc885b/attachment.sig>
#16 lore raw

PATCH 7/17 eeprom: Pull out the I/O code

In reply to Marek Vasut

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.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 50 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 19 deletions(-)
common/cmd_eeprom.c +31 -19
index 728606e..7797d0e 100644
@@ -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;
 
Signature · 1 line
2.1.4
#17 lore raw

PATCH 7/17 eeprom: Pull out the I/O code

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

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.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 50 +++++++++++++++++++++++++++++++-------------------
  1 file changed, 31 insertions(+), 19 deletions(-)

bye,
Heiko

Quoted 78 lines
common/cmd_eeprom.c +31 -19
index 728606e..7797d0e 100644
@@ -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;
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#18 lore raw

PATCH 7/17 eeprom: Pull out the I/O code

In reply to Marek Vasut
Quoted 8 lines · Marek Vasut

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/d719b9af/attachment.sig>
#19 lore raw

PATCH 8/17 eeprom: Pull out address computation

In reply to Marek Vasut

Pull out the code computing the EEPROM address into separate function so that it's not duplicated.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 64 ++++++++++++++++++++++-------------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)
common/cmd_eeprom.c +26 -38
index 7797d0e..5979993 100644
@@ -61,6 +61,28 @@ void eeprom_init(void)
 #endif
 }
 
+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;
+}
+
 static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 			   uchar *buffer, unsigned len, bool read)
 {
@@ -94,6 +116,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 	unsigned end = offset + cnt;
 	unsigned blk_off;
 	int rcode = 0;
+	uchar addr[3];
 
 	/*
 	 * Read data until done or would cross a page boundary.
@@ -106,26 +129,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 		unsigned maxlen;
 #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
-		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;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
-
-		addr[0] |= dev_addr;		/* insert device address */
+		alen = eeprom_addr(dev_addr, offset, addr);
 
 		len = end - offset;
 
@@ -156,6 +161,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 	unsigned end = offset + cnt;
 	unsigned blk_off;
 	int rcode = 0;
+	uchar addr[3];
 
 #if defined(CONFIG_SYS_EEPROM_WREN)
 	eeprom_write_enable (dev_addr,1);
@@ -172,26 +178,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 		unsigned maxlen;
 #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
-		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;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
-
-		addr[0] |= dev_addr;		/* insert device address */
+		alen = eeprom_addr(dev_addr, offset, addr);
 
 		len = end - offset;
 
Signature · 1 line
2.1.4
#20 lore raw

PATCH 8/17 eeprom: Pull out address computation

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

Pull out the code computing the EEPROM address into separate function so that it's not duplicated.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 64 ++++++++++++++++++++++-------------------------------
  1 file changed, 26 insertions(+), 38 deletions(-)

bye,
Heiko

Quoted 107 lines
common/cmd_eeprom.c +26 -38
index 7797d0e..5979993 100644
@@ -61,6 +61,28 @@ void eeprom_init(void)
  #endif
  }
 
+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;
+}
+
  static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
  			   uchar *buffer, unsigned len, bool read)
  {
@@ -94,6 +116,7 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  	unsigned end = offset + cnt;
  	unsigned blk_off;
  	int rcode = 0;
+	uchar addr[3];
 
  	/*
  	 * Read data until done or would cross a page boundary.
@@ -106,26 +129,8 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  		unsigned maxlen;
  #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
-		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;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
-
-		addr[0] |= dev_addr;		/* insert device address */
+		alen = eeprom_addr(dev_addr, offset, addr);
 
  		len = end - offset;
 
@@ -156,6 +161,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  	unsigned end = offset + cnt;
  	unsigned blk_off;
  	int rcode = 0;
+	uchar addr[3];
 
  #if defined(CONFIG_SYS_EEPROM_WREN)
  	eeprom_write_enable (dev_addr,1);
@@ -172,26 +178,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  		unsigned maxlen;
  #endif
 
-#if CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 1
-		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;
-#endif	/* CONFIG_SYS_I2C_EEPROM_ADDR_LEN */
-
-		addr[0] |= dev_addr;		/* insert device address */
+		alen = eeprom_addr(dev_addr, offset, addr);
 
  		len = end - offset;
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#21 lore raw

PATCH 8/17 eeprom: Pull out address computation

In reply to Marek Vasut
Quoted 8 lines · Marek Vasut

Pull out the code computing the EEPROM address into separate function so that it's not duplicated.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/79184d2e/attachment.sig>
#22 lore raw

PATCH 9/17 eeprom: Make eeprom_write_enable() weak

In reply to Marek Vasut

Make this function weak and implement it's weak implementation so that the boards can just reimplement it. This zaps the horrid CONFIG_SYS_EEPROM_WREN macro.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
common/cmd_eeprom.c +9 -9
index 5979993..040ab5f 100644
@@ -44,9 +44,10 @@
 #endif
 #endif
 
-#if defined(CONFIG_SYS_EEPROM_WREN)
-extern int eeprom_write_enable (unsigned dev_addr, int state);
-#endif
+__weak int eeprom_write_enable(unsigned dev_addr, int state)
+{
+	return 0;
+}
 
 void eeprom_init(void)
 {
@@ -163,9 +164,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 	int rcode = 0;
 	uchar addr[3];
 
-#if defined(CONFIG_SYS_EEPROM_WREN)
-	eeprom_write_enable (dev_addr,1);
-#endif
+	eeprom_write_enable(dev_addr, 1);
+
 	/*
 	 * Write data until done or would cross a write page boundary.
 	 * We must write the address again when changing pages
@@ -215,9 +215,9 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 		udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
 #endif
 	}
-#if defined(CONFIG_SYS_EEPROM_WREN)
-	eeprom_write_enable (dev_addr,0);
-#endif
+
+	eeprom_write_enable(dev_addr, 0);
+
 	return rcode;
 }
 
Signature · 1 line
2.1.4
#23 lore raw

PATCH 9/17 eeprom: Make eeprom_write_enable() weak

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 11 lines

Make this function weak and implement it's weak implementation so that the boards can just reimplement it. This zaps the horrid CONFIG_SYS_EEPROM_WREN macro.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 18 +++++++++---------
  1 file changed, 9 insertions(+), 9 deletions(-)

bye,
Heiko

Quoted 45 lines
common/cmd_eeprom.c +9 -9
index 5979993..040ab5f 100644
@@ -44,9 +44,10 @@
  #endif
  #endif
 
-#if defined(CONFIG_SYS_EEPROM_WREN)
-extern int eeprom_write_enable (unsigned dev_addr, int state);
-#endif
+__weak int eeprom_write_enable(unsigned dev_addr, int state)
+{
+	return 0;
+}
 
  void eeprom_init(void)
  {
@@ -163,9 +164,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  	int rcode = 0;
  	uchar addr[3];
 
-#if defined(CONFIG_SYS_EEPROM_WREN)
-	eeprom_write_enable (dev_addr,1);
-#endif
+	eeprom_write_enable(dev_addr, 1);
+
  	/*
  	 * Write data until done or would cross a write page boundary.
  	 * We must write the address again when changing pages
@@ -215,9 +215,9 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  		udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  #endif
  	}
-#if defined(CONFIG_SYS_EEPROM_WREN)
-	eeprom_write_enable (dev_addr,0);
-#endif
+
+	eeprom_write_enable(dev_addr, 0);
+
  	return rcode;
  }
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#24 lore raw

PATCH 9/17 eeprom: Make eeprom_write_enable() weak

In reply to Marek Vasut
Quoted 9 lines · Marek Vasut

Make this function weak and implement it's weak implementation so that the boards can just reimplement it. This zaps the horrid CONFIG_SYS_EEPROM_WREN macro.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/2c247ad0/attachment.sig>
#25 lore raw

PATCH 10/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS

In reply to Marek Vasut

Pull this macro to the beginning of the cmd_eeprom.c and remove another nasty ifdef from the code. Note that this is legal, since udelay(0) changes the behavior only such that it pings the WDT if WDT is enabled and otherwise does not wait.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
common/cmd_eeprom.c +4 -2
index 040ab5f..8451d63 100644
@@ -29,6 +29,10 @@
 #define	CONFIG_SYS_I2C_SPEED	50000
 #endif
 
+#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
+#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	0
+#endif
+
 /*
  * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
  *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -211,9 +215,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 		buffer += len;
 		offset += len;
 
-#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
 		udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-#endif
 	}
 
 	eeprom_write_enable(dev_addr, 0);
Signature · 1 line
2.1.4
#26 lore raw

PATCH 10/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 5 lines

Pull this macro to the beginning of the cmd_eeprom.c and remove another nasty ifdef from the code. Note that this is legal, since udelay(0) changes the behavior only such that it pings the WDT if WDT is enabled and otherwise does not wait.

Quoted 7 lines
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

bye,
Heiko

Quoted 27 lines
common/cmd_eeprom.c +4 -2
index 040ab5f..8451d63 100644
@@ -29,6 +29,10 @@
  #define	CONFIG_SYS_I2C_SPEED	50000
  #endif
 
+#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
+#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	0
+#endif
+
  /*
   * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
   *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -211,9 +215,7 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  		buffer += len;
  		offset += len;
 
-#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
  		udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-#endif
  	}
 
  	eeprom_write_enable(dev_addr, 0);
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#27 lore raw

PATCH 10/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS

In reply to Marek Vasut
Quoted 10 lines · Marek Vasut

Pull this macro to the beginning of the cmd_eeprom.c and remove another nasty ifdef from the code. Note that this is legal, since udelay(0) changes the behavior only such that it pings the WDT if WDT is enabled and otherwise does not wait.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/c107b23e/attachment.sig>
#28 lore raw

PATCH 11/17 eeprom: Suck the ifdef into eeprom_init()

In reply to Marek Vasut

Just suck the ugly ifdef around eeprom_init() call into eeprom_init() function itself. This puts all of the ifdef mess into one place.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
common/cmd_eeprom.c +2 -4
index 8451d63..c38c534 100644
@@ -57,7 +57,7 @@ void eeprom_init(void)
 {
 	/* SPI EEPROM */
 #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-	spi_init_f ();
+	spi_init_f();
 #endif
 
 	/* I2C EEPROM */
@@ -248,9 +248,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	off = simple_strtoul(*args++, NULL, 16);
 	cnt = simple_strtoul(*args++, NULL, 16);
 
-# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-	eeprom_init ();
-# endif /* !CONFIG_SPI */
+	eeprom_init();
 
 	if (strcmp (argv[1], "read") == 0) {
 		printf(fmt, dev_addr, argv[1], addr, off, cnt);
Signature · 1 line
2.1.4
#29 lore raw

PATCH 11/17 eeprom: Suck the ifdef into eeprom_init()

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

Just suck the ugly ifdef around eeprom_init() call into eeprom_init() function itself. This puts all of the ifdef mess into one place.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

bye,
Heiko

Quoted 26 lines
common/cmd_eeprom.c +2 -4
index 8451d63..c38c534 100644
@@ -57,7 +57,7 @@ void eeprom_init(void)
  {
  	/* SPI EEPROM */
  #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-	spi_init_f ();
+	spi_init_f();
  #endif
 
  	/* I2C EEPROM */
@@ -248,9 +248,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  	off = simple_strtoul(*args++, NULL, 16);
  	cnt = simple_strtoul(*args++, NULL, 16);
 
-# if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
-	eeprom_init ();
-# endif /* !CONFIG_SPI */
+	eeprom_init();
 
  	if (strcmp (argv[1], "read") == 0) {
  		printf(fmt, dev_addr, argv[1], addr, off, cnt);
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#30 lore raw

PATCH 11/17 eeprom: Suck the ifdef into eeprom_init()

In reply to Marek Vasut
Quoted 8 lines · Marek Vasut

Just suck the ugly ifdef around eeprom_init() call into eeprom_init() function itself. This puts all of the ifdef mess into one place.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/8b57ffc1/attachment.sig>
#31 lore raw

PATCH 12/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_BITS

In reply to Marek Vasut

Implement default value of 8 for this macro and pull out all of this macro out of the code. The default value of 8 actually does implement exactly the same behavior as the previous code which was in the #else clause of the ifdef.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
common/cmd_eeprom.c +8 -8
index c38c534..162a05c 100644
@@ -33,6 +33,13 @@
 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	0
 #endif
 
+#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
+#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	8
+#endif
+
+#define	EEPROM_PAGE_SIZE	(1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
+#define	EEPROM_PAGE_OFFSET(x)	((x) & (EEPROM_PAGE_SIZE - 1))
+
 /*
  * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
  *   0x000nxxxx for EEPROM address selectors@n, offset xxxx in EEPROM.
@@ -194,15 +201,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 		 */
 #if !defined(CONFIG_SYS_I2C_FRAM)
 
-#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
-
-#define	EEPROM_PAGE_SIZE	(1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
-#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;
 
Signature · 1 line
2.1.4
#32 lore raw

PATCH 12/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_BITS

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 5 lines

Implement default value of 8 for this macro and pull out all of this macro out of the code. The default value of 8 actually does implement exactly the same behavior as the previous code which was in the #else clause of the ifdef.

Quoted 7 lines
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)

bye,
Heiko

Quoted 37 lines
common/cmd_eeprom.c +8 -8
index c38c534..162a05c 100644
@@ -33,6 +33,13 @@
  #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	0
  #endif
 
+#ifndef CONFIG_SYS_EEPROM_PAGE_WRITE_BITS
+#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	8
+#endif
+
+#define	EEPROM_PAGE_SIZE	(1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
+#define	EEPROM_PAGE_OFFSET(x)	((x) & (EEPROM_PAGE_SIZE - 1))
+
  /*
   * for CONFIG_SYS_I2C_EEPROM_ADDR_LEN == 2 (16-bit EEPROM address) offset is
   *   0x000nxxxx for EEPROM address selectors at n, offset xxxx in EEPROM.
@@ -194,15 +201,8 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  		 */
  #if !defined(CONFIG_SYS_I2C_FRAM)
 
-#if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
-
-#define	EEPROM_PAGE_SIZE	(1 << CONFIG_SYS_EEPROM_PAGE_WRITE_BITS)
-#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;
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#33 lore raw

PATCH 12/17 eeprom: Pull out CONFIG_SYS_EEPROM_PAGE_WRITE_BITS

In reply to Marek Vasut
Quoted 10 lines · Marek Vasut

Implement default value of 8 for this macro and pull out all of this macro out of the code. The default value of 8 actually does implement exactly the same behavior as the previous code which was in the #else clause of the ifdef.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/0f4139a3/attachment.sig>
#34 lore raw

PATCH 13/17 eeprom: Pull out transfer length computation

In reply to Marek Vasut

Pull out the code which computes the length of the transfer into separate code and clean it up a little. This again trims down the code duplication.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 66 ++++++++++++++++++++---------------------------------
 1 file changed, 25 insertions(+), 41 deletions(-)
common/cmd_eeprom.c +25 -41
index 162a05c..b39ca5d 100644
@@ -95,6 +95,29 @@ static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)
 	return alen;
 }
 
+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;
+}
+
 static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 			   uchar *buffer, unsigned len, bool read)
 {
@@ -126,7 +149,6 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
 {
 	unsigned end = offset + cnt;
-	unsigned blk_off;
 	int rcode = 0;
 	uchar addr[3];
 
@@ -137,27 +159,10 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 	 */
 	while (offset < end) {
 		unsigned alen, len;
-#if !defined(CONFIG_SYS_I2C_FRAM)
-		unsigned maxlen;
-#endif
 
-		blk_off = offset & 0xFF;	/* block offset */
 		alen = eeprom_addr(dev_addr, offset, addr);
 
-		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)
-		maxlen = 0x100 - blk_off;
-		if (maxlen > I2C_RXTX_LEN)
-			maxlen = I2C_RXTX_LEN;
-		if (len > maxlen)
-			len = maxlen;
-#endif
+		len = eeprom_len(offset, end);
 
 		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 1);
 
@@ -171,7 +176,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
 int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
 {
 	unsigned end = offset + cnt;
-	unsigned blk_off;
 	int rcode = 0;
 	uchar addr[3];
 
@@ -185,30 +189,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 
 	while (offset < end) {
 		unsigned alen, len;
-#if !defined(CONFIG_SYS_I2C_FRAM)
-		unsigned maxlen;
-#endif
 
-		blk_off = offset & 0xFF;	/* block offset */
 		alen = eeprom_addr(dev_addr, offset, addr);
 
-		len = end - offset;
-
-		/*
-		 * For a FRAM device there is no limit on the number of the
-		 * bytes that can be accessed with the single read or write
-		 * operation.
-		 */
-#if !defined(CONFIG_SYS_I2C_FRAM)
-
-		maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
-
-		if (maxlen > I2C_RXTX_LEN)
-			maxlen = I2C_RXTX_LEN;
-
-		if (len > maxlen)
-			len = maxlen;
-#endif
+		len = eeprom_len(offset, end);
 
 		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 0);
 
Signature · 1 line
2.1.4
#35 lore raw

PATCH 13/17 eeprom: Pull out transfer length computation

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 11 lines

Pull out the code which computes the length of the transfer into separate code and clean it up a little. This again trims down the code duplication.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 66 ++++++++++++++++++++---------------------------------
  1 file changed, 25 insertions(+), 41 deletions(-)

bye,
Heiko

Quoted 113 lines
common/cmd_eeprom.c +25 -41
index 162a05c..b39ca5d 100644
@@ -95,6 +95,29 @@ static int eeprom_addr(unsigned dev_addr, unsigned offset, uchar *addr)
  	return alen;
  }
 
+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;
+}
+
  static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
  			   uchar *buffer, unsigned len, bool read)
  {
@@ -126,7 +149,6 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
  int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
  {
  	unsigned end = offset + cnt;
-	unsigned blk_off;
  	int rcode = 0;
  	uchar addr[3];
 
@@ -137,27 +159,10 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  	 */
  	while (offset < end) {
  		unsigned alen, len;
-#if !defined(CONFIG_SYS_I2C_FRAM)
-		unsigned maxlen;
-#endif
 
-		blk_off = offset & 0xFF;	/* block offset */
  		alen = eeprom_addr(dev_addr, offset, addr);
 
-		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)
-		maxlen = 0x100 - blk_off;
-		if (maxlen > I2C_RXTX_LEN)
-			maxlen = I2C_RXTX_LEN;
-		if (len > maxlen)
-			len = maxlen;
-#endif
+		len = eeprom_len(offset, end);
 
  		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 1);
 
@@ -171,7 +176,6 @@ int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt
  int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
  {
  	unsigned end = offset + cnt;
-	unsigned blk_off;
  	int rcode = 0;
  	uchar addr[3];
 
@@ -185,30 +189,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 
  	while (offset < end) {
  		unsigned alen, len;
-#if !defined(CONFIG_SYS_I2C_FRAM)
-		unsigned maxlen;
-#endif
 
-		blk_off = offset & 0xFF;	/* block offset */
  		alen = eeprom_addr(dev_addr, offset, addr);
 
-		len = end - offset;
-
-		/*
-		 * For a FRAM device there is no limit on the number of the
-		 * bytes that can be accessed with the single read or write
-		 * operation.
-		 */
-#if !defined(CONFIG_SYS_I2C_FRAM)
-
-		maxlen = EEPROM_PAGE_SIZE - EEPROM_PAGE_OFFSET(blk_off);
-
-		if (maxlen > I2C_RXTX_LEN)
-			maxlen = I2C_RXTX_LEN;
-
-		if (len > maxlen)
-			len = maxlen;
-#endif
+		len = eeprom_len(offset, end);
 
  		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 0);
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#36 lore raw

PATCH 13/17 eeprom: Pull out transfer length computation

In reply to Marek Vasut
Quoted 9 lines · Marek Vasut

Pull out the code which computes the length of the transfer into separate code and clean it up a little. This again trims down the code duplication.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/cde76822/attachment.sig>
#37 lore raw

PATCH 14/17 eeprom: Pull out the RW loop

In reply to Marek Vasut

Unify the code for doing read/write into single function, since the code for both the read and write is almost identical. This again trims down the code duplication.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 51 +++++++++++++++++++++------------------------------
 1 file changed, 21 insertions(+), 30 deletions(-)
common/cmd_eeprom.c +21 -30
index b39ca5d..d0942ef 100644
@@ -146,38 +146,44 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 	return ret;
 }
 
-int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
+		     unsigned cnt, bool read)
 {
 	unsigned end = offset + cnt;
+	unsigned alen, len;
 	int rcode = 0;
 	uchar addr[3];
 
-	/*
-	 * 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) {
-		unsigned alen, len;
-
 		alen = eeprom_addr(dev_addr, offset, addr);
 
 		len = eeprom_len(offset, end);
 
-		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 1);
+		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, read);
 
 		buffer += len;
 		offset += len;
+
+		if (!read)
+			udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
 	}
 
 	return rcode;
 }
 
-int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
 {
-	unsigned end = offset + cnt;
-	int rcode = 0;
-	uchar addr[3];
+	/*
+	 * 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);
+}
+
+int eeprom_write(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+{
+	int ret;
 
 	eeprom_write_enable(dev_addr, 1);
 
@@ -186,25 +192,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
 	 * We must write the address again when changing pages
 	 * because the address counter only increments within a page.
 	 */
-
-	while (offset < end) {
-		unsigned alen, len;
-
-		alen = eeprom_addr(dev_addr, offset, addr);
-
-		len = eeprom_len(offset, end);
-
-		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 0);
-
-		buffer += len;
-		offset += len;
-
-		udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-	}
+	ret = eeprom_rw(dev_addr, offset, buffer, cnt, 1);
 
 	eeprom_write_enable(dev_addr, 0);
-
-	return rcode;
+	return ret;
 }
 
 static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Signature · 1 line
2.1.4
#38 lore raw

PATCH 14/17 eeprom: Pull out the RW loop

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 11 lines

Unify the code for doing read/write into single function, since the code for both the read and write is almost identical. This again trims down the code duplication.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 51 +++++++++++++++++++++------------------------------
  1 file changed, 21 insertions(+), 30 deletions(-)

bye,
Heiko

Quoted 92 lines
common/cmd_eeprom.c +21 -30
index b39ca5d..d0942ef 100644
@@ -146,38 +146,44 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
  	return ret;
  }
 
-int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
+		     unsigned cnt, bool read)
  {
  	unsigned end = offset + cnt;
+	unsigned alen, len;
  	int rcode = 0;
  	uchar addr[3];
 
-	/*
-	 * 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) {
-		unsigned alen, len;
-
  		alen = eeprom_addr(dev_addr, offset, addr);
 
  		len = eeprom_len(offset, end);
 
-		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 1);
+		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, read);
 
  		buffer += len;
  		offset += len;
+
+		if (!read)
+			udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  	}
 
  	return rcode;
  }
 
-int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
  {
-	unsigned end = offset + cnt;
-	int rcode = 0;
-	uchar addr[3];
+	/*
+	 * 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);
+}
+
+int eeprom_write(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+{
+	int ret;
 
  	eeprom_write_enable(dev_addr, 1);
 
@@ -186,25 +192,10 @@ int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cn
  	 * We must write the address again when changing pages
  	 * because the address counter only increments within a page.
  	 */
-
-	while (offset < end) {
-		unsigned alen, len;
-
-		alen = eeprom_addr(dev_addr, offset, addr);
-
-		len = eeprom_len(offset, end);
-
-		rcode = eeprom_rw_block(offset, addr, alen, buffer, len, 0);
-
-		buffer += len;
-		offset += len;
-
-		udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
-	}
+	ret = eeprom_rw(dev_addr, offset, buffer, cnt, 1);
 
  	eeprom_write_enable(dev_addr, 0);
-
-	return rcode;
+	return ret;
  }
 
  static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#39 lore raw

PATCH 14/17 eeprom: Pull out the RW loop

In reply to Marek Vasut
Quoted 9 lines · Marek Vasut

Unify the code for doing read/write into single function, since the code for both the read and write is almost identical. This again trims down the code duplication.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/0797280d/attachment.sig>
#40 lore raw

PATCH 15/17 eeprom: Add bus argument to eeprom_init()

In reply to Marek Vasut

Add bus argument to eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 6 ++++--
 common/env_eeprom.c | 4 ++--
 include/common.h    | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)
common/cmd_eeprom.c +4 -2
index d0942ef..9247036 100644
@@ -60,7 +60,7 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state)
 	return 0;
 }
 
-void eeprom_init(void)
+void eeprom_init(int bus)
 {
 	/* SPI EEPROM */
 #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
@@ -69,6 +69,8 @@ void eeprom_init(void)
 
 	/* I2C EEPROM */
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
+	if (bus >= 0)
+		i2c_set_bus_num(bus);
 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
 #endif
 }
@@ -223,7 +225,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	off = simple_strtoul(*args++, NULL, 16);
 	cnt = simple_strtoul(*args++, NULL, 16);
 
-	eeprom_init();
+	eeprom_init(-1);
 
 	if (strcmp (argv[1], "read") == 0) {
 		printf(fmt, dev_addr, argv[1], addr, off, cnt);
common/env_eeprom.c +2 -2
index eea169d..72b1373 100644
@@ -91,7 +91,7 @@ void env_relocate_spec(void)
 	uchar rdbuf[64], flags[2];
 	int i, crc_ok[2] = {0, 0};
 
-	eeprom_init();	/* prepare for EEPROM read/write */
+	eeprom_init(-1);	/* prepare for EEPROM read/write */
 
 	off_env[0] = CONFIG_ENV_OFFSET;
 	off_env[1] = CONFIG_ENV_OFFSET_REDUND;
@@ -154,7 +154,7 @@ void env_relocate_spec(void)
 	ulong crc, len, new;
 	uchar rdbuf[64];
 
-	eeprom_init();	/* prepare for EEPROM read/write */
+	eeprom_init(-1);	/* prepare for EEPROM read/write */
 
 	/* read old CRC */
 	eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
include/common.h +1 -1
index ceb1ad3..39ba5c9 100644
@@ -475,7 +475,7 @@ void	reset_phy     (void);
 void	fdc_hw_init   (void);
 
 /* $(BOARD)/eeprom.c */
-void eeprom_init  (void);
+void eeprom_init  (int bus);
 int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
 int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
 
Signature · 1 line
2.1.4
#41 lore raw

PATCH 15/17 eeprom: Add bus argument to eeprom_init()

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 9 lines

Add bus argument to eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
Quoted 5 lines
---
  common/cmd_eeprom.c | 6 ++++--
  common/env_eeprom.c | 4 ++--
  include/common.h    | 2 +-
  3 files changed, 7 insertions(+), 5 deletions(-)

bye,
Heiko

Quoted 68 lines
common/cmd_eeprom.c +4 -2
index d0942ef..9247036 100644
@@ -60,7 +60,7 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state)
  	return 0;
  }
 
-void eeprom_init(void)
+void eeprom_init(int bus)
  {
  	/* SPI EEPROM */
  #if defined(CONFIG_SPI) && !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
@@ -69,6 +69,8 @@ void eeprom_init(void)
 
  	/* I2C EEPROM */
  #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
+	if (bus >= 0)
+		i2c_set_bus_num(bus);
  	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  #endif
  }
@@ -223,7 +225,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  	off = simple_strtoul(*args++, NULL, 16);
  	cnt = simple_strtoul(*args++, NULL, 16);
 
-	eeprom_init();
+	eeprom_init(-1);
 
  	if (strcmp (argv[1], "read") == 0) {
  		printf(fmt, dev_addr, argv[1], addr, off, cnt);
common/env_eeprom.c +2 -2
index eea169d..72b1373 100644
@@ -91,7 +91,7 @@ void env_relocate_spec(void)
  	uchar rdbuf[64], flags[2];
  	int i, crc_ok[2] = {0, 0};
 
-	eeprom_init();	/* prepare for EEPROM read/write */
+	eeprom_init(-1);	/* prepare for EEPROM read/write */
 
  	off_env[0] = CONFIG_ENV_OFFSET;
  	off_env[1] = CONFIG_ENV_OFFSET_REDUND;
@@ -154,7 +154,7 @@ void env_relocate_spec(void)
  	ulong crc, len, new;
  	uchar rdbuf[64];
 
-	eeprom_init();	/* prepare for EEPROM read/write */
+	eeprom_init(-1);	/* prepare for EEPROM read/write */
 
  	/* read old CRC */
  	eeprom_bus_read(CONFIG_SYS_DEF_EEPROM_ADDR,
include/common.h +1 -1
index ceb1ad3..39ba5c9 100644
@@ -475,7 +475,7 @@ void	reset_phy     (void);
  void	fdc_hw_init   (void);
 
  /* $(BOARD)/eeprom.c */
-void eeprom_init  (void);
+void eeprom_init  (int bus);
  int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#42 lore raw

PATCH 15/17 eeprom: Add bus argument to eeprom_init()

Quoted 7 lines · Heiko Schocher

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 4 lines

Add bus argument to eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.

[snip]

Quoted 9 lines

common/cmd_eeprom.c void eeprom_init(void) · line 76

Quoted 9 lines
common/cmd_eeprom.c +2 -0
@@ -69,6 +69,8 @@ void eeprom_init(void)
 
 	/* I2C EEPROM */
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C_SOFT)
+	if (bus >= 0)
+		i2c_set_bus_num(bus);
 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
 #endif
 }

Note that we need to wrap this call in CONFIG_SYS_I2C as CONFIG_HARD_I2C doesn't provide this function. Fixing up and testing again locally.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151121/bbb130ac/attachment.sig>
#43 lore raw

PATCH 15/17 eeprom: Add bus argument to eeprom_init()

In reply to Marek Vasut
Quoted 10 lines · Marek Vasut

Add bus argument to eeprom_init(), so that it can select the I2C bus number on which the eeprom resides. Any negative value of the $bus argument will preserve the old behavior. This is in place so that old code does not randomly break.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/d66c9b4a/attachment.sig>
#44 lore raw

PATCH 16/17 eeprom: Add support for selecting i2c bus

In reply to Marek Vasut

Add additional parameter into the eeprom command to select the I2C bus on which the eeprom resides.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
common/cmd_eeprom.c +11 -4
index 9247036..13c946e 100644
@@ -207,14 +207,21 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	char * const *args = &argv[2];
 	int rcode;
 	ulong dev_addr, addr, off, cnt;
+	int bus_addr;
 
 	switch (argc) {
 #ifdef CONFIG_SYS_DEF_EEPROM_ADDR
 	case 5:
+		bus_addr = -1;
 		dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
 		break;
 #endif
 	case 6:
+		bus_addr = -1;
+		dev_addr = simple_strtoul(*args++, NULL, 16);
+		break;
+	case 7:
+		bus_addr = simple_strtoul(*args++, NULL, 16);
 		dev_addr = simple_strtoul(*args++, NULL, 16);
 		break;
 	default:
@@ -225,7 +232,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	off = simple_strtoul(*args++, NULL, 16);
 	cnt = simple_strtoul(*args++, NULL, 16);
 
-	eeprom_init(-1);
+	eeprom_init(bus_addr);
 
 	if (strcmp (argv[1], "read") == 0) {
 		printf(fmt, dev_addr, argv[1], addr, off, cnt);
@@ -247,9 +254,9 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-	eeprom,	6,	1,	do_eeprom,
+	eeprom,	7,	1,	do_eeprom,
 	"EEPROM sub-system",
-	"read  devaddr addr off cnt\n"
-	"eeprom write devaddr addr off cnt\n"
+	"read  <bus> <devaddr> addr off cnt\n"
+	"eeprom write <bus> <devaddr> addr off cnt\n"
 	"       - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
 )
Signature · 1 line
2.1.4
#45 lore raw

PATCH 16/17 eeprom: Add support for selecting i2c bus

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 10 lines

Add additional parameter into the eeprom command to select the I2C bus on which the eeprom resides.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 15 +++++++++++----
  1 file changed, 11 insertions(+), 4 deletions(-)

bye,
Heiko

Quoted 50 lines
common/cmd_eeprom.c +11 -4
index 9247036..13c946e 100644
@@ -207,14 +207,21 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  	char * const *args = &argv[2];
  	int rcode;
  	ulong dev_addr, addr, off, cnt;
+	int bus_addr;
 
  	switch (argc) {
  #ifdef CONFIG_SYS_DEF_EEPROM_ADDR
  	case 5:
+		bus_addr = -1;
  		dev_addr = CONFIG_SYS_DEF_EEPROM_ADDR;
  		break;
  #endif
  	case 6:
+		bus_addr = -1;
+		dev_addr = simple_strtoul(*args++, NULL, 16);
+		break;
+	case 7:
+		bus_addr = simple_strtoul(*args++, NULL, 16);
  		dev_addr = simple_strtoul(*args++, NULL, 16);
  		break;
  	default:
@@ -225,7 +232,7 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  	off = simple_strtoul(*args++, NULL, 16);
  	cnt = simple_strtoul(*args++, NULL, 16);
 
-	eeprom_init(-1);
+	eeprom_init(bus_addr);
 
  	if (strcmp (argv[1], "read") == 0) {
  		printf(fmt, dev_addr, argv[1], addr, off, cnt);
@@ -247,9 +254,9 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  }
 
  U_BOOT_CMD(
-	eeprom,	6,	1,	do_eeprom,
+	eeprom,	7,	1,	do_eeprom,
  	"EEPROM sub-system",
-	"read  devaddr addr off cnt\n"
-	"eeprom write devaddr addr off cnt\n"
+	"read  <bus> <devaddr> addr off cnt\n"
+	"eeprom write <bus> <devaddr> addr off cnt\n"
  	"       - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'"
  )
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#46 lore raw

PATCH 16/17 eeprom: Add support for selecting i2c bus

In reply to Marek Vasut
Quoted 8 lines · Marek Vasut

Add additional parameter into the eeprom command to select the I2C bus on which the eeprom resides.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/bff55239/attachment.sig>
#47 lore raw

PATCH 17/17 eeprom: Clean up checkpatch issues

In reply to Marek Vasut

Cosmetic fixes to the file, make it checkpatch clean.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/cmd_eeprom.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
common/cmd_eeprom.c +10 -9
index 13c946e..376c57d 100644
@@ -49,8 +49,8 @@
  */
 #if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
 #if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || \
-    (CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1) || \
-    (CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2)
+	(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
 #endif
 #endif
@@ -183,7 +183,8 @@ int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
 	return eeprom_rw(dev_addr, offset, buffer, cnt, 1);
 }
 
-int eeprom_write(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+int eeprom_write(unsigned dev_addr, unsigned offset,
+		 uchar *buffer, unsigned cnt)
 {
 	int ret;
 
@@ -234,19 +235,19 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	eeprom_init(bus_addr);
 
-	if (strcmp (argv[1], "read") == 0) {
+	if (strcmp(argv[1], "read") == 0) {
 		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-		rcode = eeprom_read(dev_addr, off, (uchar *) addr, cnt);
+		rcode = eeprom_read(dev_addr, off, (uchar *)addr, cnt);
 
-		puts ("done\n");
+		puts("done\n");
 		return rcode;
-	} else if (strcmp (argv[1], "write") == 0) {
+	} else if (strcmp(argv[1], "write") == 0) {
 		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-		rcode = eeprom_write(dev_addr, off, (uchar *) addr, cnt);
+		rcode = eeprom_write(dev_addr, off, (uchar *)addr, cnt);
 
-		puts ("done\n");
+		puts("done\n");
 		return rcode;
 	}
 
Signature · 1 line
2.1.4
#48 lore raw

PATCH 17/17 eeprom: Clean up checkpatch issues

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 9 lines

Cosmetic fixes to the file, make it checkpatch clean.

Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  common/cmd_eeprom.c | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)

bye,
Heiko

Quoted 53 lines
common/cmd_eeprom.c +10 -9
index 13c946e..376c57d 100644
@@ -49,8 +49,8 @@
   */
  #if !defined(CONFIG_SPI) || defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
  #if !defined(CONFIG_SYS_I2C_EEPROM_ADDR_LEN) || \
-    (CONFIG_SYS_I2C_EEPROM_ADDR_LEN < 1) || \
-    (CONFIG_SYS_I2C_EEPROM_ADDR_LEN > 2)
+	(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
  #endif
  #endif
@@ -183,7 +183,8 @@ int eeprom_read(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
  	return eeprom_rw(dev_addr, offset, buffer, cnt, 1);
  }
 
-int eeprom_write(unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt)
+int eeprom_write(unsigned dev_addr, unsigned offset,
+		 uchar *buffer, unsigned cnt)
  {
  	int ret;
 
@@ -234,19 +235,19 @@ static int do_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
  	eeprom_init(bus_addr);
 
-	if (strcmp (argv[1], "read") == 0) {
+	if (strcmp(argv[1], "read") == 0) {
  		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-		rcode = eeprom_read(dev_addr, off, (uchar *) addr, cnt);
+		rcode = eeprom_read(dev_addr, off, (uchar *)addr, cnt);
 
-		puts ("done\n");
+		puts("done\n");
  		return rcode;
-	} else if (strcmp (argv[1], "write") == 0) {
+	} else if (strcmp(argv[1], "write") == 0) {
  		printf(fmt, dev_addr, argv[1], addr, off, cnt);
 
-		rcode = eeprom_write(dev_addr, off, (uchar *) addr, cnt);
+		rcode = eeprom_write(dev_addr, off, (uchar *)addr, cnt);
 
-		puts ("done\n");
+		puts("done\n");
  		return rcode;
  	}
 
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#49 lore raw

PATCH 17/17 eeprom: Clean up checkpatch issues

In reply to Marek Vasut
Quoted 7 lines · Marek Vasut

Cosmetic fixes to the file, make it checkpatch clean.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/2d99adb8/attachment.sig>
#50 lore raw

PATCH 1/17 tricorder: rewrite tricordereeprom command

In reply to Marek Vasut

Hello Marek,

Am 10.11.2015 um 20:53 schrieb Marek Vasut:

Quoted 5 lines

From: Andreas Bie?mann <[email protected]>

This rewrite uses lately promoted eeprom_init(int) function to choose the right I2C bus when writing data to the EEPROM.

Quoted 8 lines
Cc Marek Vasut <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
Cc Heiko Schocher <[email protected]>
---
  board/corscience/tricorder/tricorder-eeprom.c | 36 +++++++--------------------
  1 file changed, 9 insertions(+), 27 deletions(-)

Thanks for this cleanup! ... eeprom code is really ugly ...

bye,
Heiko

Quoted 93 lines
board/corscience/tricorder/tricorder-eeprom.c +9 -27
index 1c74a0f..340a009 100644
@@ -77,17 +77,13 @@ static int handle_eeprom_v1(struct tricorder_eeprom *eeprom)
 
  int tricorder_get_eeprom(int addr, struct tricorder_eeprom *eeprom)
  {
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
  	unsigned int bus = i2c_get_bus_num();
  	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
-#endif
 
  	memset(eeprom, 0, TRICORDER_EEPROM_SIZE);
 
  	i2c_read(addr, 0, 2, (unsigned char *)eeprom, TRICORDER_EEPROM_SIZE);
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
  	i2c_set_bus_num(bus);
-#endif
 
  	if (be32_to_cpu(eeprom->magic) != TRICORDER_EEPROM_MAGIC) {
  		warn_wrong_value("magic", TRICORDER_EEPROM_MAGIC,
@@ -138,9 +134,6 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,
  	int ret;
  	unsigned char *p;
  	int i;
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
-	unsigned int bus;
-#endif
 
  	memset(eeprom, 0, TRICORDER_EEPROM_SIZE);
  	memset(eeprom_verify, 0, TRICORDER_EEPROM_SIZE);
@@ -172,33 +165,23 @@ int tricorder_eeprom_write(unsigned devaddr, const char *name,
  	print_buffer(0, &eeprom, 1, sizeof(eeprom), 16);
  #endif
 
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
-	bus = i2c_get_bus_num();
-	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
-#endif
+	eeprom_init(CONFIG_SYS_EEPROM_BUS_NUM);
 
-	/* do page write to the eeprom */
-	for (i = 0, p = (unsigned char *)&eeprom;
-	     i < sizeof(eeprom);
-	     i += 32, p += 32) {
-		ret = i2c_write(devaddr, i, CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
-				p, min(sizeof(eeprom) - i, 32));
-		if (ret)
-			break;
-		udelay(5000); /* 5ms write cycle timing */
-	}
+	ret = eeprom_write(devaddr, 0, (unsigned char *)&eeprom,
+			TRICORDER_EEPROM_SIZE);
+	if (ret)
+		printf("Tricorder: Could not write EEPROM content!\n");
 
-	ret = i2c_read(devaddr, 0, 2, (unsigned char *)&eeprom_verify,
+	ret = eeprom_read(devaddr, 0, (unsigned char *)&eeprom_verify,
  			TRICORDER_EEPROM_SIZE);
+	if (ret)
+		printf("Tricorder: Could not read EEPROM content!\n");
 
  	if (memcmp(&eeprom, &eeprom_verify, sizeof(eeprom)) != 0) {
  		printf("Tricorder: Could not verify EEPROM content!\n");
  		ret = 1;
  	}
 
-#ifdef CONFIG_SYS_EEPROM_BUS_NUM
-	i2c_set_bus_num(bus);
-#endif
  	return ret;
  }
 
@@ -206,7 +189,7 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  {
  	if (argc == 3) {
  		ulong dev_addr = simple_strtoul(argv[2], NULL, 16);
-		eeprom_init();
+
  		if (strcmp(argv[1], "read") == 0) {
  			int rcode;
 
@@ -220,7 +203,6 @@ int do_tricorder_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  		char *version = argv[4];
  		char *serial = argv[5];
  		char *interface = NULL;
-		eeprom_init();
 
  		if (argc == 7)
  			interface = argv[6];
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#51 lore raw

PATCH 1/17 tricorder: rewrite tricordereeprom command

In reply to Marek Vasut
Quoted 11 lines · Marek Vasut

From: Andreas Bie?mann <[email protected]>

This rewrite uses lately promoted eeprom_init(int) function to choose the right I2C bus when writing data to the EEPROM.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151122/b48fe37a/attachment.sig>