Commit 7167f876 authored by Nick Elsmore's avatar Nick Elsmore

power: supply: bq27xxx: Add taper rate DM entry for bq27421

parent 6799af2d
......@@ -681,6 +681,7 @@ enum bq27xxx_dm_reg_id {
BQ27XXX_DM_DESIGN_CAPACITY = 0,
BQ27XXX_DM_DESIGN_ENERGY,
BQ27XXX_DM_TERMINATE_VOLTAGE,
BQ27XXX_DM_TAPER_RATE,
};
#define bq27000_dm_regs 0
......@@ -731,6 +732,7 @@ static struct bq27xxx_dm_reg bq27421_dm_regs[] = {
[BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 10, 2, 0, 8000 },
[BQ27XXX_DM_DESIGN_ENERGY] = { 82, 12, 2, 0, 32767 },
[BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 16, 2, 2500, 3700 },
[BQ27XXX_DM_TAPER_RATE] = { 82, 27, 2, 0, 2000 },
};
static struct bq27xxx_dm_reg bq27425_dm_regs[] = {
......@@ -1242,6 +1244,7 @@ static void bq27xxx_battery_set_config(struct bq27xxx_device_info *di,
{
struct bq27xxx_dm_buf bd = BQ27XXX_DM_BUF(di, BQ27XXX_DM_DESIGN_CAPACITY);
struct bq27xxx_dm_buf bt = BQ27XXX_DM_BUF(di, BQ27XXX_DM_TERMINATE_VOLTAGE);
struct bq27xxx_dm_buf btr = BQ27XXX_DM_BUF(di, BQ27XXX_DM_TAPER_RATE);
bool updated;
pr_info("%s\n", __func__);
......@@ -1264,8 +1267,27 @@ pr_info("%s\n", __func__);
bq27xxx_battery_update_dm_block(di, &bd,
BQ27XXX_DM_DESIGN_ENERGY,
info->energy_full_design_uwh / 1000);
} else {
pr_info("toastbucket: uah or uwh invalid\n");
}
if (info->charge_full_design_uah != -EINVAL &&
info->charge_term_current_ua != -EINVAL) {
bool same = (bd.class == btr.class) && (bd.block == btr.block);
int taper_rate;
int taper_current;
if (!same)
bq27xxx_battery_read_dm_block(di, &btr);
pr_info("toastbucket: term_uah=%d\n", info->charge_term_current_ua);
taper_current = (115 * (info->charge_term_current_ua / 1000)) / 100;
taper_rate = (info->charge_full_design_uah / 1000) / (taper_current / 10);
pr_info("toastbucket: taper_rate=%d\n", taper_rate);
bq27xxx_battery_update_dm_block(di, &btr,
BQ27XXX_DM_TAPER_RATE,
taper_rate);
}
if (info->voltage_min_design_uv != -EINVAL) {
......@@ -1277,10 +1299,11 @@ pr_info("%s\n", __func__);
info->voltage_min_design_uv / 1000);
}
updated = bd.dirty || bt.dirty;
updated = bd.dirty || bt.dirty || btr.dirty;
bq27xxx_battery_write_dm_block(di, &bd);
bq27xxx_battery_write_dm_block(di, &bt);
bq27xxx_battery_write_dm_block(di, &btr);
bq27xxx_battery_seal(di);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment