Skip to contentSkip to conversation

eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS

PATCH New Simon Goldschmidt 2 participants 4 messages Apr 23, 2019 – Apr 24, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS

The current device model enabled eeprom code only works if CONFIG_SYS_I2C_EEPROM_BUS is set.

This patch makes it work without that define so that the bus number passed to 'eeprom_init' is used.

---

Changes in v3:
- use eeprom_init() to set CONFIG_SYS_I2C_EEPROM_BUS, not i2c_set_bus_num to make things work with CONFIG_DM_I2C

Changes in v2: None

 cmd/eeprom.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
cmd/eeprom.c +15 -8
index 6c29b33ba3..7b1f81477f 100644
@@ -59,6 +59,10 @@
 #endif
 #endif
 
+#if defined(CONFIG_DM_I2C)
+int eeprom_i2c_bus;
+#endif
+
 __weak int eeprom_write_enable(unsigned dev_addr, int state)
 {
 	return 0;
@@ -67,7 +71,9 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state)
 void eeprom_init(int bus)
 {
 	/* I2C EEPROM */
-#if defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_DM_I2C)
+	eeprom_i2c_bus = bus;
+#elif defined(CONFIG_SYS_I2C)
 	if (bus >= 0)
 		i2c_set_bus_num(bus);
 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
@@ -124,14 +130,14 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 {
 	int ret = 0;
 
-#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS)
+#if defined(CONFIG_DM_I2C)
 	struct udevice *dev;
 
-	ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS, addr[0],
+	ret = i2c_get_chip_for_busnum(eeprom_i2c_bus, addr[0],
 				      alen - 1, &dev);
 	if (ret) {
 		printf("%s: Cannot find udev for a bus %d\n", __func__,
-		       CONFIG_SYS_I2C_EEPROM_BUS);
+		       eeprom_i2c_bus);
 		return CMD_RET_FAILURE;
 	}
 
@@ -141,15 +147,12 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
 		ret = dm_i2c_write(dev, offset, buffer, len);
 
 #else /* Non DM I2C support - will be removed */
-#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);
-#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */
+#endif /* CONFIG_DM_I2C */
 	if (ret)
 		ret = CMD_RET_FAILURE;
 
@@ -164,6 +167,10 @@ static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
 	int rcode = 0;
 	uchar addr[3];
 
+#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
+	eeprom_init(CONFIG_SYS_I2C_EEPROM_BUS);
+#endif
+
 	while (offset < end) {
 		alen = eeprom_addr(dev_addr, offset, addr);
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/2 eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS

Am 23.04.2019 um 21:18 schrieb Simon Goldschmidt:

Quoted 8 lines

The current device model enabled eeprom code only works if CONFIG_SYS_I2C_EEPROM_BUS is set.

This patch makes it work without that define so that the bus number passed to 'eeprom_init' is used.

Please ignore this version, I've sent a diff for this fix instead.

Regards,
Simon

Quoted 84 lines

---

Changes in v3:
- use eeprom_init() to set CONFIG_SYS_I2C_EEPROM_BUS, not i2c_set_bus_num to make things work with CONFIG_DM_I2C

Changes in v2: None

  cmd/eeprom.c | 23 +++++++++++++++--------
  1 file changed, 15 insertions(+), 8 deletions(-)
cmd/eeprom.c +15 -8
index 6c29b33ba3..7b1f81477f 100644
@@ -59,6 +59,10 @@
  #endif
  #endif
 
+#if defined(CONFIG_DM_I2C)
+int eeprom_i2c_bus;
+#endif
+
  __weak int eeprom_write_enable(unsigned dev_addr, int state)
  {
  	return 0;
@@ -67,7 +71,9 @@ __weak int eeprom_write_enable(unsigned dev_addr, int state)
  void eeprom_init(int bus)
  {
  	/* I2C EEPROM */
-#if defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_DM_I2C)
+	eeprom_i2c_bus = bus;
+#elif defined(CONFIG_SYS_I2C)
  	if (bus >= 0)
  		i2c_set_bus_num(bus);
  	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
@@ -124,14 +130,14 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
  {
  	int ret = 0;
 
-#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS)
+#if defined(CONFIG_DM_I2C)
  	struct udevice *dev;
 
-	ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS, addr[0],
+	ret = i2c_get_chip_for_busnum(eeprom_i2c_bus, addr[0],
  				      alen - 1, &dev);
  	if (ret) {
  		printf("%s: Cannot find udev for a bus %d\n", __func__,
-		       CONFIG_SYS_I2C_EEPROM_BUS);
+		       eeprom_i2c_bus);
  		return CMD_RET_FAILURE;
  	}
 
@@ -141,15 +147,12 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
  		ret = dm_i2c_write(dev, offset, buffer, len);
 
  #else /* Non DM I2C support - will be removed */
-#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);
-#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */
+#endif /* CONFIG_DM_I2C */
  	if (ret)
  		ret = CMD_RET_FAILURE;
 
@@ -164,6 +167,10 @@ static int eeprom_rw(unsigned dev_addr, unsigned offset, uchar *buffer,
  	int rcode = 0;
  	uchar addr[3];
 
+#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
+	eeprom_init(CONFIG_SYS_I2C_EEPROM_BUS);
+#endif
+
  	while (offset < end) {
  		alen = eeprom_addr(dev_addr, offset, addr);
 
#2 lore raw

PATCH v3 1/2 eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS

In reply to Simon Goldschmidt

Hi Simon,

Quoted 5 lines

The current device model enabled eeprom code only works if CONFIG_SYS_I2C_EEPROM_BUS is set.

This patch makes it work without that define so that the bus number passed to 'eeprom_init' is used.

Quoted 78 lines

---

Changes in v3:
- use eeprom_init() to set CONFIG_SYS_I2C_EEPROM_BUS, not i2c_set_bus_num to make things work with CONFIG_DM_I2C

Changes in v2: None

 cmd/eeprom.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
cmd/eeprom.c +10 -4
index 6c29b33ba3..7b1f81477f 100644
@@ -59,6 +59,10 @@
 #endif
 #endif
 
+#if defined(CONFIG_DM_I2C)
+int eeprom_i2c_bus;
+#endif
+
 __weak int eeprom_write_enable(unsigned dev_addr, int state)
 {
 	return 0;
@@ -67,7 +71,9 @@ __weak int eeprom_write_enable(unsigned dev_addr,
 int state) void eeprom_init(int bus)
 {
 	/* I2C EEPROM */
-#if defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_DM_I2C)
+	eeprom_i2c_bus = bus;
+#elif defined(CONFIG_SYS_I2C)
 	if (bus >= 0)
 		i2c_set_bus_num(bus);
 	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
@@ -124,14 +130,14 @@ static int eeprom_rw_block(unsigned offset,
 uchar *addr, unsigned alen, {
 	int ret = 0;
 
-#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS)
+#if defined(CONFIG_DM_I2C)
 	struct udevice *dev;
 
-	ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS,
 addr[0],
+	ret = i2c_get_chip_for_busnum(eeprom_i2c_bus, addr[0],
 				      alen - 1, &dev);
 	if (ret) {
 		printf("%s: Cannot find udev for a bus %d\n",
 __func__,
-		       CONFIG_SYS_I2C_EEPROM_BUS);
+		       eeprom_i2c_bus);
 		return CMD_RET_FAILURE;
cmd/eeprom.c +0 -3
 	}
@@ -141,15 +147,12 @@ static int eeprom_rw_block(unsigned offset,
 uchar *addr, unsigned alen, ret = dm_i2c_write(dev, offset, buffer,
 len); 
 #else /* Non DM I2C support - will be removed */
-#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); -#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */

cmd/eeprom.c +1 -0
+#endif /* CONFIG_DM_I2C */
 	if (ret)
 		ret = CMD_RET_FAILURE;

cmd/eeprom.c static int eeprom_rw(unsigned dev_addr, unsigned · line 176

Quoted 10 lines
cmd/eeprom.c +4 -0
@@ -164,6 +167,10 @@ static int eeprom_rw(unsigned dev_addr, unsigned
 offset, uchar *buffer, int rcode = 0;
 	uchar addr[3];
 
+#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
+	eeprom_init(CONFIG_SYS_I2C_EEPROM_BUS);
+#endif
+
 	while (offset < end) {
 		alen = eeprom_addr(dev_addr, offset, addr);
 

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190423/5a8676a2/attachment.sig>

#3 lore raw

PATCH v3 2/2 Revert "cmd: Kconfig: Do not include EEPROM if DM_I2C is used without DM_I2C_COMPAT"

In reply to Simon Goldschmidt

This reverts commit 65a97e7fcf54feb7c4ebe1aee8a572830af4cf51.

The 'eeprom' command has been converted to work with DM_I2C in a patch submitted around the same time as this commit:
commit 0c07a9b4078d ("eeprom: Add device model based I2C support to eeprom command")

---

Changes in v3: None
Changes in v2:
- added patch to fix DM_I2C eeprom code to work without CONFIG_SYS_I2C_EEPROM_BUS

 cmd/Kconfig | 1 -
 1 file changed, 1 deletion(-)
cmd/Kconfig +0 -1
index 2bdbfcb3d0..87012670e0 100644
@@ -455,7 +455,6 @@ config CRC32_VERIFY
 
 config CMD_EEPROM
 	bool "eeprom - EEPROM subsystem"
-	depends on !DM_I2C || DM_I2C_COMPAT
 	help
 	  (deprecated, needs conversion to driver model)
 	  Provides commands to read and write EEPROM (Electrically Erasable
Signature · 1 line
2.17.1