
Add support for U-Boot DM.
Signed-off-by: Benedikt Spranger b.spranger@linutronix.de Reviewed-by: Kurt Kanzenbach kurt@linutronix.de --- 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);