drivers: regulator: regulator_pmic: Update driver to use i2c_dt_spec
Simplify driver by using i2c_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
6098e1894b
commit
4e841aea8d
1 changed files with 9 additions and 15 deletions
|
@ -53,8 +53,7 @@ struct regulator_config {
|
||||||
bool enable_inverted;
|
bool enable_inverted;
|
||||||
uint8_t ilim_reg;
|
uint8_t ilim_reg;
|
||||||
uint8_t ilim_mask;
|
uint8_t ilim_mask;
|
||||||
uint8_t i2c_address;
|
struct i2c_dt_spec i2c;
|
||||||
const struct device *i2c_dev;
|
|
||||||
uint32_t *voltage_array;
|
uint32_t *voltage_array;
|
||||||
uint32_t *current_array;
|
uint32_t *current_array;
|
||||||
};
|
};
|
||||||
|
@ -69,17 +68,15 @@ static int regulator_modify_register(const struct regulator_config *conf,
|
||||||
uint8_t reg_current;
|
uint8_t reg_current;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = i2c_reg_read_byte(conf->i2c_dev, conf->i2c_address,
|
rc = i2c_reg_read_byte_dt(&conf->i2c, reg, ®_current);
|
||||||
reg, ®_current);
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
reg_current &= ~reg_mask;
|
reg_current &= ~reg_mask;
|
||||||
reg_current |= reg_val;
|
reg_current |= reg_val;
|
||||||
LOG_DBG("Writing 0x%02X to reg 0x%02X at I2C addr 0x%02X",
|
LOG_DBG("Writing 0x%02X to reg 0x%02X at I2C addr 0x%02X", reg_current, reg,
|
||||||
reg_current, reg, conf->i2c_address);
|
conf->i2c.addr);
|
||||||
return i2c_reg_write_byte(conf->i2c_dev, conf->i2c_address, reg,
|
return i2c_reg_write_byte_dt(&conf->i2c, reg, reg_current);
|
||||||
reg_current);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,8 +162,7 @@ int regulator_get_voltage(const struct device *dev)
|
||||||
int rc, i = 0;
|
int rc, i = 0;
|
||||||
uint8_t raw_reg;
|
uint8_t raw_reg;
|
||||||
|
|
||||||
rc = i2c_reg_read_byte(config->i2c_dev, config->i2c_address,
|
rc = i2c_reg_read_byte_dt(&config->i2c, config->vsel_reg, &raw_reg);
|
||||||
config->vsel_reg, &raw_reg);
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -225,8 +221,7 @@ int regulator_get_current_limit(const struct device *dev)
|
||||||
if (config->num_current_levels == 0) {
|
if (config->num_current_levels == 0) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
rc = i2c_reg_read_byte(config->i2c_dev, config->i2c_address,
|
rc = i2c_reg_read_byte_dt(&config->i2c, config->ilim_reg, &raw_reg);
|
||||||
config->ilim_reg, &raw_reg);
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -301,7 +296,7 @@ static int pmic_reg_init(const struct device *dev)
|
||||||
/* Do the same cast for current limit ranges */
|
/* Do the same cast for current limit ranges */
|
||||||
data->current_levels = (struct current_range *)config->current_array;
|
data->current_levels = (struct current_range *)config->current_array;
|
||||||
/* Check to verify we have a valid I2C device */
|
/* Check to verify we have a valid I2C device */
|
||||||
if (!device_is_ready(config->i2c_dev)) {
|
if (!device_is_ready(config->i2c.bus)) {
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -332,8 +327,7 @@ static const struct regulator_driver_api api = {
|
||||||
.ilim_reg = DT_INST_PROP_OR(id, ilim_reg, 0), \
|
.ilim_reg = DT_INST_PROP_OR(id, ilim_reg, 0), \
|
||||||
.ilim_mask = DT_INST_PROP_OR(id, ilim_mask, 0), \
|
.ilim_mask = DT_INST_PROP_OR(id, ilim_mask, 0), \
|
||||||
.enable_inverted = DT_INST_PROP(id, enable_inverted), \
|
.enable_inverted = DT_INST_PROP(id, enable_inverted), \
|
||||||
.i2c_address = DT_REG_ADDR(DT_INST_PARENT(id)), \
|
.i2c = I2C_DT_SPEC_INST_GET(id), \
|
||||||
.i2c_dev = DEVICE_DT_GET(DT_BUS(DT_INST_PARENT(id))), \
|
|
||||||
.voltage_array = pmic_reg_##id##_vol_range, \
|
.voltage_array = pmic_reg_##id##_vol_range, \
|
||||||
.current_array = pmic_reg_##id##_cur_limits, \
|
.current_array = pmic_reg_##id##_cur_limits, \
|
||||||
}; \
|
}; \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue