[U-Boot] [PATCH v2 25/41] board: ge: bx50v3: use DM i2c for PMIC initialization

Robert Beckett bob.beckett at collabora.com
Wed Oct 23 18:21:46 UTC 2019


Use DM i2c for PMIC dc-dc buck converter initialization.

Signed-off-by: Robert Beckett <bob.beckett at collabora.com>
---
 board/ge/bx50v3/bx50v3.c | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
index dce76808d7..c1a71e1c9a 100644
--- a/board/ge/bx50v3/bx50v3.c
+++ b/board/ge/bx50v3/bx50v3.c
@@ -488,7 +488,6 @@ static const struct boot_mode board_boot_modes[] = {
 
 void pmic_init(void)
 {
-#define I2C_PMIC                0x2
 #define DA9063_I2C_ADDR         0x58
 #define DA9063_REG_BCORE2_CFG   0x9D
 #define DA9063_REG_BCORE1_CFG   0x9E
@@ -503,38 +502,51 @@ void pmic_init(void)
 #define DA9063_BUCK_MODE_AUTO   0xC0
 
 	uchar val;
+	struct udevice *dev, *bus;
+	int ret;
+
+	// TODO: Add a da9063 DM PMIC driver and use that.
+	ret = uclass_get_device_by_name(UCLASS_I2C, "i2c at 21a8000", &bus);
+	if (ret) {
+		printf("%s: Unable to get I2C bus: %d\n", __func__, ret);
+		return;
+	}
 
-	i2c_set_bus_num(I2C_PMIC);
+	ret = dm_i2c_probe(bus, DA9063_I2C_ADDR, 0, &dev);
+	if (ret) {
+		printf("%s: Unable to get PMIC device: %d\n", __func__, ret);
+		return;
+	}
 
-	i2c_read(DA9063_I2C_ADDR, DA9063_REG_BCORE2_CFG, 1, &val, 1);
+	dm_i2c_read(dev, DA9063_REG_BCORE2_CFG, &val, 1);
 	val &= ~DA9063_BUCK_MODE_MASK;
 	val |= DA9063_BUCK_MODE_SYNC;
-	i2c_write(DA9063_I2C_ADDR, DA9063_REG_BCORE2_CFG, 1, &val, 1);
+	dm_i2c_write(dev, DA9063_REG_BCORE2_CFG, &val, 1);
 
-	i2c_read(DA9063_I2C_ADDR, DA9063_REG_BCORE1_CFG, 1, &val, 1);
+	dm_i2c_read(dev, DA9063_REG_BCORE1_CFG, &val, 1);
 	val &= ~DA9063_BUCK_MODE_MASK;
 	val |= DA9063_BUCK_MODE_SYNC;
-	i2c_write(DA9063_I2C_ADDR, DA9063_REG_BCORE1_CFG, 1, &val, 1);
+	dm_i2c_write(dev, DA9063_REG_BCORE1_CFG, &val, 1);
 
-	i2c_read(DA9063_I2C_ADDR, DA9063_REG_BPRO_CFG, 1, &val, 1);
+	dm_i2c_read(dev, DA9063_REG_BPRO_CFG, &val, 1);
 	val &= ~DA9063_BUCK_MODE_MASK;
 	val |= DA9063_BUCK_MODE_SYNC;
-	i2c_write(DA9063_I2C_ADDR, DA9063_REG_BPRO_CFG, 1, &val, 1);
+	dm_i2c_write(dev, DA9063_REG_BPRO_CFG, &val, 1);
 
-	i2c_read(DA9063_I2C_ADDR, DA9063_REG_BIO_CFG, 1, &val, 1);
+	dm_i2c_read(dev, DA9063_REG_BIO_CFG, &val, 1);
 	val &= ~DA9063_BUCK_MODE_MASK;
 	val |= DA9063_BUCK_MODE_SYNC;
-	i2c_write(DA9063_I2C_ADDR, DA9063_REG_BIO_CFG, 1, &val, 1);
+	dm_i2c_write(dev, DA9063_REG_BIO_CFG, &val, 1);
 
-	i2c_read(DA9063_I2C_ADDR, DA9063_REG_BMEM_CFG, 1, &val, 1);
+	dm_i2c_read(dev, DA9063_REG_BMEM_CFG, &val, 1);
 	val &= ~DA9063_BUCK_MODE_MASK;
 	val |= DA9063_BUCK_MODE_SYNC;
-	i2c_write(DA9063_I2C_ADDR, DA9063_REG_BMEM_CFG, 1, &val, 1);
+	dm_i2c_write(dev, DA9063_REG_BMEM_CFG, &val, 1);
 
-	i2c_read(DA9063_I2C_ADDR, DA9063_REG_BPERI_CFG, 1, &val, 1);
+	dm_i2c_read(dev, DA9063_REG_BPERI_CFG, &val, 1);
 	val &= ~DA9063_BUCK_MODE_MASK;
 	val |= DA9063_BUCK_MODE_SYNC;
-	i2c_write(DA9063_I2C_ADDR, DA9063_REG_BPERI_CFG, 1, &val, 1);
+	dm_i2c_write(dev, DA9063_REG_BPERI_CFG, &val, 1);
 }
 
 int board_late_init(void)
-- 
2.20.1



More information about the U-Boot mailing list