Skip to content

Commit

Permalink
bq769x2: Add support for configuring REG0 (pre-regulator)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjaeger committed Dec 12, 2024
1 parent 8f6a949 commit 97ac0b5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
26 changes: 22 additions & 4 deletions drivers/bms_ic/bq769x2/bq769x2.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ static int bq769x2_configure_voltage_regs(const struct device *dev, struct bms_i
{
int err = 0;

uint8_t reg0_config = 0;
uint8_t reg12_config;
uint8_t vregs_enable = 0;

err = bq769x2_datamem_read_u1(dev, BQ769X2_SET_CONF_REG12, &reg12_config);
if (err != 0) {
return -EIO;
Expand All @@ -463,19 +466,30 @@ static int bq769x2_configure_voltage_regs(const struct device *dev, struct bms_i
/* clear REG2_EN and REG1_EN bits and keep voltage setting untouched */
reg12_config &= ~0x11;

if (ic_conf->vregs_enable & BIT(0)) {
reg0_config |= 0x01; /* REG0_EN */
vregs_enable |= BIT(0);
}

if (ic_conf->vregs_enable & BIT(1)) {
reg12_config |= 0x01; /* REG1_EN */
ic_conf->vregs_enable |= BIT(1);
vregs_enable |= BIT(1);
}

if (ic_conf->vregs_enable & BIT(2)) {
reg12_config |= 0x10; /* REG2_EN */
ic_conf->vregs_enable |= BIT(2);
vregs_enable |= BIT(2);
}

err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_CONF_REG0, reg0_config);
err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_CONF_REG12, reg12_config);
if (err != 0) {
return -EIO;
}

err = bq769x2_datamem_write_u1(dev, BQ769X2_SET_CONF_REG12, reg12_config);
ic_conf->vregs_enable = vregs_enable;

return err == 0 ? 0 : -EIO;
return 0;
}

static int bq769x2_init_config(const struct device *dev)
Expand Down Expand Up @@ -534,6 +548,9 @@ static int bq769x2_init_config(const struct device *dev)
err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_CONF_CFETOFF + i, config->pin_config[i]);
}

/* Configure REG0 (pre-regulator for REG1/2) */
err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_CONF_REG0, config->reg0_config);

/* Configure REG1 and REG2 voltages and default enable/disable setting */
err |= bq769x2_datamem_write_u1(dev, BQ769X2_SET_CONF_REG12, config->reg12_config);

Expand Down Expand Up @@ -984,6 +1001,7 @@ static const struct bms_ic_driver_api bq769x2_driver_api = {
.fet_temp_pin = DT_INST_PROP_OR(index, fet_temp_pin, UINT8_MAX), \
.crc_enabled = DT_INST_PROP(index, crc_enabled), \
.auto_pdsg = DT_INST_PROP(index, auto_pdsg), \
.reg0_config = DT_INST_PROP(index, reg0_config), \
.reg12_config = DT_INST_PROP(index, reg12_config), \
.write_bytes = bq769x2_write_bytes_i2c, \
.read_bytes = bq769x2_read_bytes_i2c, \
Expand Down
1 change: 1 addition & 0 deletions drivers/bms_ic/bq769x2/bq769x2_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct bms_ic_bq769x2_config
uint8_t fet_temp_pin;
bool crc_enabled;
bool auto_pdsg;
uint8_t reg0_config;
uint8_t reg12_config;
bq769x2_write_bytes_t write_bytes;
bq769x2_read_bytes_t read_bytes;
Expand Down
8 changes: 8 additions & 0 deletions dts/bindings/bms_ic/ti,bq769x2-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ properties:
description: |
Enable automatic pre-discharge (bus precharge) before switching on DSG FETs.
reg0-config:
type: int
default: 0
description: |
Configuration of the REG0 Config Register. REG0 is the pre-regulator for REG1/2 and must be
enabled if REG1 or REG2 are used and REGIN is not supplied externally.
Valid values: 0 and 1
reg12-config:
type: int
default: 0
Expand Down

0 comments on commit 97ac0b5

Please sign in to comment.