[PATCH 1/4] sunxi: pmic_bus: Refactor pmic_bus_read() and pmic_bus_write()
Benedikt Spranger
b.spranger at linutronix.de
Fri May 29 18:28:36 CEST 2020
Unify I2C calls to ease the driver model conversion.
Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
Reviewed-by: Kurt Kanzenbach <kurt at linutronix.de>
---
arch/arm/mach-sunxi/pmic_bus.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c
index dea42de833..091c59331b 100644
--- a/arch/arm/mach-sunxi/pmic_bus.c
+++ b/arch/arm/mach-sunxi/pmic_bus.c
@@ -26,6 +26,14 @@
#define AXP223_DEVICE_ADDR 0x3a3
#define AXP223_RUNTIME_ADDR 0x2d
+#ifdef CONFIG_AXP152_POWER
+#define PMIC_I2C_ADDR AXP152_I2C_ADDR
+#elif defined CONFIG_AXP209_POWER
+#define PMIC_I2C_ADDR AXP209_I2C_ADDR
+#else
+#undef PMIC_I2C_ADDR
+#endif
+
int pmic_bus_init(void)
{
/* This cannot be 0 because it is used in SPL before BSS is ready */
@@ -60,35 +68,31 @@ int pmic_bus_init(void)
int pmic_bus_read(u8 reg, u8 *data)
{
-#ifdef CONFIG_AXP152_POWER
- return i2c_read(AXP152_I2C_ADDR, reg, 1, data, 1);
-#elif defined CONFIG_AXP209_POWER
- return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1);
+#ifdef PMIC_I2C_ADDR
+ return i2c_read(PMIC_I2C_ADDR, reg, 1, data, 1);
#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
# ifdef CONFIG_MACH_SUN6I
return p2wi_read(reg, data);
-# elif defined CONFIG_MACH_SUN8I_R40
- return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1);
# else
return rsb_read(AXP223_RUNTIME_ADDR, reg, data);
# endif
+#else
+#error "unknown PMIC"
#endif
}
int pmic_bus_write(u8 reg, u8 data)
{
-#ifdef CONFIG_AXP152_POWER
- return i2c_write(AXP152_I2C_ADDR, reg, 1, &data, 1);
-#elif defined CONFIG_AXP209_POWER
- return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1);
+#ifdef PMIC_I2C_ADDR
+ return i2c_write(PMIC_I2C_ADDR, reg, 1, &data, 1);
#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
# ifdef CONFIG_MACH_SUN6I
return p2wi_write(reg, data);
-# elif defined CONFIG_MACH_SUN8I_R40
- return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1);
# else
return rsb_write(AXP223_RUNTIME_ADDR, reg, data);
# endif
+#else
+#error "unknown PMIC"
#endif
}
--
2.19.0
More information about the U-Boot
mailing list