From patchwork Fri May 29 16:28:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benedikt Spranger X-Patchwork-Id: 246830 List-Id: U-Boot discussion From: b.spranger at linutronix.de (Benedikt Spranger) Date: Fri, 29 May 2020 18:28:38 +0200 Subject: [PATCH 3/4] sunxi: pmic_bus: Add DM I2C support In-Reply-To: <20200529162839.3544366-1-b.spranger@linutronix.de> References: <20200529162839.3544366-1-b.spranger@linutronix.de> Message-ID: <20200529162839.3544366-4-b.spranger@linutronix.de> Add support for U-Boot DM. Signed-off-by: Benedikt Spranger Reviewed-by: Kurt Kanzenbach --- arch/arm/mach-sunxi/pmic_bus.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c index 091c59331b..8ecd037528 100644 --- a/arch/arm/mach-sunxi/pmic_bus.c +++ b/arch/arm/mach-sunxi/pmic_bus.c @@ -34,6 +34,8 @@ #undef PMIC_I2C_ADDR #endif +struct udevice *pmic_dev __section(.data) = NULL; + int pmic_bus_init(void) { /* This cannot be 0 because it is used in SPL before BSS is ready */ @@ -43,6 +45,16 @@ int pmic_bus_init(void) if (!needs_init) return 0; +#if defined PMIC_I2C_ADDR && defined CONFIG_DM_I2C + struct udevice *dev = NULL; + int rc; + + rc = i2c_get_chip_for_busnum(0, PMIC_I2C_ADDR, 1, &dev); + if (rc) + return rc; + pmic_dev = dev; +#endif + #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I p2wi_init(); @@ -69,7 +81,11 @@ int pmic_bus_init(void) int pmic_bus_read(u8 reg, u8 *data) { #ifdef PMIC_I2C_ADDR +#ifndef CONFIG_DM_I2C return i2c_read(PMIC_I2C_ADDR, reg, 1, data, 1); +#else + return dm_i2c_read(pmic_dev, reg, data, 1); +#endif #elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I return p2wi_read(reg, data); @@ -84,7 +100,11 @@ int pmic_bus_read(u8 reg, u8 *data) int pmic_bus_write(u8 reg, u8 data) { #ifdef PMIC_I2C_ADDR +#ifndef CONFIG_DM_I2C return i2c_write(PMIC_I2C_ADDR, reg, 1, &data, 1); +#else + return dm_i2c_read(pmic_dev, reg, &data, 1); +#endif #elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I return p2wi_write(reg, data);