Skip to content

Commit 9035997

Browse files
sicelosre
authored andcommitted
power: supply: bq27xxx: Add voltage_max_design property for bq270x0 and bq27x10
Report VOLTAGE_MAX_DESIGN for the bq27x00 and bq27x10 fuel gauges. Per the datasheet, this value is stored in the Charge Termination Voltage Settings (QV0 and QV1) of the Pack Configuration register. Tested on the Nokia N900 with bq27200. Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com> Link: https://lore.kernel.org/r/20250207211521.103357-1-absicsz@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 4ad5c72 commit 9035997

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

drivers/power/supply/bq27xxx_battery.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ enum bq27xxx_reg_index {
124124
BQ27XXX_DM_DATA, /* Block Data */
125125
BQ27XXX_DM_CKSUM, /* Block Data Checksum */
126126
BQ27XXX_REG_SEDVF, /* End-of-discharge Voltage */
127+
BQ27XXX_REG_PKCFG, /* Pack Configuration */
127128
BQ27XXX_REG_MAX, /* sentinel */
128129
};
129130

@@ -161,6 +162,7 @@ static u8
161162
[BQ27XXX_DM_DATA] = INVALID_REG_ADDR,
162163
[BQ27XXX_DM_CKSUM] = INVALID_REG_ADDR,
163164
[BQ27XXX_REG_SEDVF] = 0x77,
165+
[BQ27XXX_REG_PKCFG] = 0x7C,
164166
},
165167
bq27010_regs[BQ27XXX_REG_MAX] = {
166168
[BQ27XXX_REG_CTRL] = 0x00,
@@ -187,6 +189,7 @@ static u8
187189
[BQ27XXX_DM_DATA] = INVALID_REG_ADDR,
188190
[BQ27XXX_DM_CKSUM] = INVALID_REG_ADDR,
189191
[BQ27XXX_REG_SEDVF] = 0x77,
192+
[BQ27XXX_REG_PKCFG] = 0x7C,
190193
},
191194
bq2750x_regs[BQ27XXX_REG_MAX] = {
192195
[BQ27XXX_REG_CTRL] = 0x00,
@@ -583,6 +586,7 @@ static enum power_supply_property bq27000_props[] = {
583586
POWER_SUPPLY_PROP_HEALTH,
584587
POWER_SUPPLY_PROP_MANUFACTURER,
585588
POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
589+
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
586590
};
587591

588592
static enum power_supply_property bq27010_props[] = {
@@ -604,6 +608,7 @@ static enum power_supply_property bq27010_props[] = {
604608
POWER_SUPPLY_PROP_HEALTH,
605609
POWER_SUPPLY_PROP_MANUFACTURER,
606610
POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
611+
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
607612
};
608613

609614
#define bq2750x_props bq27510g3_props
@@ -2044,6 +2049,35 @@ static int bq27xxx_battery_voltage(struct bq27xxx_device_info *di,
20442049
return 0;
20452050
}
20462051

2052+
/*
2053+
* Return the design maximum battery Voltage in microvolts, or < 0 if something
2054+
* fails. The programmed value of the maximum battery voltage is determined by
2055+
* QV0 and QV1 (bits 5 and 6) in the Pack Configuration register.
2056+
*/
2057+
static int bq27xxx_battery_read_dmax_volt(struct bq27xxx_device_info *di,
2058+
union power_supply_propval *val)
2059+
{
2060+
int reg_val, qv;
2061+
2062+
if (di->voltage_max_design > 0) {
2063+
val->intval = di->voltage_max_design;
2064+
return 0;
2065+
}
2066+
2067+
reg_val = bq27xxx_read(di, BQ27XXX_REG_PKCFG, true);
2068+
if (reg_val < 0) {
2069+
dev_err(di->dev, "error reading design max voltage\n");
2070+
return reg_val;
2071+
}
2072+
2073+
qv = (reg_val >> 5) & 0x3;
2074+
val->intval = 3968000 + 48000 * qv;
2075+
2076+
di->voltage_max_design = val->intval;
2077+
2078+
return 0;
2079+
}
2080+
20472081
/*
20482082
* Return the design minimum battery Voltage in microvolts
20492083
* Or < 0 if something fails.
@@ -2158,6 +2192,9 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
21582192
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
21592193
ret = bq27xxx_battery_read_dmin_volt(di, val);
21602194
break;
2195+
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
2196+
ret = bq27xxx_battery_read_dmax_volt(di, val);
2197+
break;
21612198
case POWER_SUPPLY_PROP_CYCLE_COUNT:
21622199
ret = bq27xxx_battery_read_cyct(di, val);
21632200
break;

include/linux/power/bq27xxx_battery.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct bq27xxx_device_info {
6262
struct bq27xxx_reg_cache cache;
6363
int charge_design_full;
6464
int voltage_min_design;
65+
int voltage_max_design;
6566
bool removed;
6667
unsigned long last_update;
6768
union power_supply_propval last_status;

0 commit comments

Comments
 (0)