From patchwork Wed Jan 22 08:33:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Holger Brunck X-Patchwork-Id: 239913 List-Id: U-Boot discussion From: holger.brunck at ch.abb.com (Holger Brunck) Date: Wed, 22 Jan 2020 09:33:27 +0100 Subject: [PATCH] bootcount: make i2c version ready for DM driver Message-ID: <20200122083327.29691-1-holger.brunck@ch.abb.com> If the board already uses DM_I2C we need to use the dm i2c calls. Signed-off-by: Holger Brunck CC: Heiko Schocher CC: Marek Vasut --- 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;