[PATCH] bootcount: make i2c version ready for DM driver

Holger Brunck holger.brunck at ch.abb.com
Wed Jan 22 09:33:27 CET 2020


If the board already uses DM_I2C we need to use the dm i2c calls.

Signed-off-by: Holger Brunck <holger.brunck at ch.abb.com>
CC: Heiko Schocher <hs at denx.de>
CC: Marek Vasut <marex at denx.de>
---
 drivers/bootcount/bootcount_i2c.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/bootcount/bootcount_i2c.c b/drivers/bootcount/bootcount_i2c.c
index 496741d63f..24b9bd2fed 100644
--- a/drivers/bootcount/bootcount_i2c.c
+++ b/drivers/bootcount/bootcount_i2c.c
@@ -14,11 +14,21 @@ void bootcount_store(ulong a)
 {
 	unsigned char buf[3];
 	int ret;
+#ifdef CONFIG_DM_I2C
+	struct udevice *eedev = NULL;
+#endif
 
 	buf[0] = BC_MAGIC;
 	buf[1] = (a & 0xff);
+#ifdef CONFIG_DM_I2C
+	ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_RTC_ADDR,
+				      1, &eedev);
+	if (ret == 0)
+		ret = dm_i2c_write(eedev, CONFIG_SYS_BOOTCOUNT_ADDR, buf, 2);
+#else
 	ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, CONFIG_SYS_BOOTCOUNT_ADDR,
 		  CONFIG_BOOTCOUNT_ALEN, buf, 2);
+#endif
 	if (ret != 0)
 		puts("Error writing bootcount\n");
 }
@@ -27,9 +37,20 @@ ulong bootcount_load(void)
 {
 	unsigned char buf[3];
 	int ret;
+#ifdef CONFIG_DM_I2C
+	struct udevice *eedev = NULL;
 
+	ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_RTC_ADDR,
+				      1, &eedev);
+	if (ret) {
+		puts("Error getting i2c bus for bootcount\n");
+		return 0;
+	}
+	ret = dm_i2c_read(eedev, CONFIG_SYS_BOOTCOUNT_ADDR, buf, 2);
+#else
 	ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, CONFIG_SYS_BOOTCOUNT_ADDR,
 		       CONFIG_BOOTCOUNT_ALEN, buf, 2);
+#endif
 	if (ret != 0) {
 		puts("Error loading bootcount\n");
 		return 0;
-- 
2.24.0.rc1



More information about the U-Boot mailing list