summaryrefslogtreecommitdiff
path: root/drivers/power/pmic/pmic_tps65910.c
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@ti.com>2018-12-07 14:50:46 +0100
committerHeiko Schocher <hs@denx.de>2018-12-10 06:17:30 +0100
commitfb1b7712ad3f375f83e74629f03236c300b0b896 (patch)
treecc21eacc979ff5f7d2f5a7c2f336a4fcb8561e75 /drivers/power/pmic/pmic_tps65910.c
parent2b30b38b269e87cbd727862a08ae99843c3ab29e (diff)
power: make most tps drivers and the twl4030 driver compatible with DM_I2C
Those driver are not DM drivers per se (not using the PMIC/regulator framework) and are using the legacy I2C API. Make them compatible with the DM_I2C API. This impacts the following drivers: - palmas (used by am57xx/dra7xx evms) - tps65218 (used by am43xx evms) - tps65217 and tps65910 (used by am335x evms and am335x boneblack vboot) - twl4030 (used by omap3_logicpd) - tps65217 (used by brppt1) - twl6030 Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'drivers/power/pmic/pmic_tps65910.c')
-rw-r--r--drivers/power/pmic/pmic_tps65910.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/drivers/power/pmic/pmic_tps65910.c b/drivers/power/pmic/pmic_tps65910.c
index f4d2aa1b7a..4772de11be 100644
--- a/drivers/power/pmic/pmic_tps65910.c
+++ b/drivers/power/pmic/pmic_tps65910.c
@@ -8,6 +8,47 @@
#include <i2c.h>
#include <power/tps65910.h>
+struct udevice *tps65910_dev __attribute__((section(".data"))) = NULL;
+
+static inline int tps65910_read_reg(int addr, uchar *buf)
+{
+#ifndef CONFIG_DM_I2C
+ return i2c_read(TPS65910_CTRL_I2C_ADDR, addr, 1, buf, 1);
+#else
+ int rc;
+
+ rc = dm_i2c_reg_read(tps65910_dev, addr);
+ if (rc < 0)
+ return rc;
+ *buf = (uchar)rc;
+ return 0;
+#endif
+}
+
+static inline int tps65910_write_reg(int addr, uchar *buf)
+{
+#ifndef CONFIG_DM_I2C
+ return i2c_write(TPS65910_CTRL_I2C_ADDR, addr, 1, buf, 1);
+#else
+ return dm_i2c_reg_write(tps65910_dev, addr, *buf);
+#endif
+}
+
+int power_tps65910_init(unsigned char bus)
+{
+#ifdef CONFIG_DM_I2C
+ struct udevice *dev = NULL;
+ int rc;
+
+ rc = i2c_get_chip_for_busnum(bus, TPS65910_CTRL_I2C_ADDR, 1, &dev);
+
+ if (rc)
+ return rc;
+ tps65910_dev = dev;
+#endif
+ return 0;
+}
+
/*
* tps65910_set_i2c_control() - Set the TPS65910 to be controlled via the I2C
* interface.
@@ -19,16 +60,14 @@ int tps65910_set_i2c_control(void)
uchar buf;
/* VDD1/2 voltage selection register access by control i/f */
- ret = i2c_read(TPS65910_CTRL_I2C_ADDR, TPS65910_DEVCTRL_REG, 1,
- &buf, 1);
+ ret = tps65910_read_reg(TPS65910_DEVCTRL_REG, &buf);
if (ret)
return ret;
buf |= TPS65910_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C;
- return i2c_write(TPS65910_CTRL_I2C_ADDR, TPS65910_DEVCTRL_REG, 1,
- &buf, 1);
+ return tps65910_write_reg(TPS65910_DEVCTRL_REG, &buf);
}
/*
@@ -49,29 +88,29 @@ int tps65910_voltage_update(unsigned int module, unsigned char vddx_op_vol_sel)
reg_offset = TPS65910_VDD2_OP_REG;
/* Select VDDx OP */
- ret = i2c_read(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
+ ret = tps65910_read_reg(reg_offset, &buf);
if (ret)
return ret;
buf &= ~TPS65910_OP_REG_CMD_MASK;
- ret = i2c_write(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
+ ret = tps65910_write_reg(reg_offset, &buf);
if (ret)
return ret;
/* Configure VDDx OP Voltage */
- ret = i2c_read(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
+ ret = tps65910_read_reg(reg_offset, &buf);
if (ret)
return ret;
buf &= ~TPS65910_OP_REG_SEL_MASK;
buf |= vddx_op_vol_sel;
- ret = i2c_write(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
+ ret = tps65910_write_reg(reg_offset, &buf);
if (ret)
return ret;
- ret = i2c_read(TPS65910_CTRL_I2C_ADDR, reg_offset, 1, &buf, 1);
+ ret = tps65910_read_reg(reg_offset, &buf);
if (ret)
return ret;