From 30d71d545774e0ef98f66551455938b75bbd0ffe Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Tue, 30 Aug 2022 13:04:56 -0500 Subject: [PATCH] drivers: regulator: move I2C reg reads to regulator_read_register Move I2C register reads to regulator_read_register in regulator driver, to enable better abstraction of regulator I2C reads Signed-off-by: Daniel DeGrasse --- drivers/regulator/regulator_pmic.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/regulator_pmic.c b/drivers/regulator/regulator_pmic.c index 84c7e30ad7e..9955c03cb6e 100644 --- a/drivers/regulator/regulator_pmic.c +++ b/drivers/regulator/regulator_pmic.c @@ -58,6 +58,16 @@ struct regulator_config { uint32_t *current_array; }; +/** + * Reads a register from the PMIC + * Returns 0 on success, or errno on error + */ +static int regulator_read_register(const struct regulator_config *conf, + uint8_t reg, uint8_t *out) +{ + return i2c_reg_read_byte_dt(&conf->i2c, reg, out); +} + /** * Modifies a register within the PMIC * Returns 0 on success, or errno on error @@ -68,7 +78,7 @@ static int regulator_modify_register(const struct regulator_config *conf, uint8_t reg_current; int rc; - rc = i2c_reg_read_byte_dt(&conf->i2c, reg, ®_current); + rc = regulator_read_register(conf, reg, ®_current); if (rc) { return rc; } @@ -162,7 +172,7 @@ int regulator_get_voltage(const struct device *dev) int rc, i = 0; uint8_t raw_reg; - rc = i2c_reg_read_byte_dt(&config->i2c, config->vsel_reg, &raw_reg); + rc = regulator_read_register(config, config->vsel_reg, &raw_reg); if (rc) { return rc; } @@ -221,7 +231,7 @@ int regulator_get_current_limit(const struct device *dev) if (config->num_current_levels == 0) { return -ENOTSUP; } - rc = i2c_reg_read_byte_dt(&config->i2c, config->ilim_reg, &raw_reg); + rc = regulator_read_register(config, config->ilim_reg, &raw_reg); if (rc) { return rc; }