Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sicelo A. Mhlongo and committed by
Sebastian Reichel
90359976 4ad5c726

+38
+37
drivers/power/supply/bq27xxx_battery.c
··· 124 124 BQ27XXX_DM_DATA, /* Block Data */ 125 125 BQ27XXX_DM_CKSUM, /* Block Data Checksum */ 126 126 BQ27XXX_REG_SEDVF, /* End-of-discharge Voltage */ 127 + BQ27XXX_REG_PKCFG, /* Pack Configuration */ 127 128 BQ27XXX_REG_MAX, /* sentinel */ 128 129 }; 129 130 ··· 162 161 [BQ27XXX_DM_DATA] = INVALID_REG_ADDR, 163 162 [BQ27XXX_DM_CKSUM] = INVALID_REG_ADDR, 164 163 [BQ27XXX_REG_SEDVF] = 0x77, 164 + [BQ27XXX_REG_PKCFG] = 0x7C, 165 165 }, 166 166 bq27010_regs[BQ27XXX_REG_MAX] = { 167 167 [BQ27XXX_REG_CTRL] = 0x00, ··· 189 187 [BQ27XXX_DM_DATA] = INVALID_REG_ADDR, 190 188 [BQ27XXX_DM_CKSUM] = INVALID_REG_ADDR, 191 189 [BQ27XXX_REG_SEDVF] = 0x77, 190 + [BQ27XXX_REG_PKCFG] = 0x7C, 192 191 }, 193 192 bq2750x_regs[BQ27XXX_REG_MAX] = { 194 193 [BQ27XXX_REG_CTRL] = 0x00, ··· 586 583 POWER_SUPPLY_PROP_HEALTH, 587 584 POWER_SUPPLY_PROP_MANUFACTURER, 588 585 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 586 + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 589 587 }; 590 588 591 589 static enum power_supply_property bq27010_props[] = { ··· 608 604 POWER_SUPPLY_PROP_HEALTH, 609 605 POWER_SUPPLY_PROP_MANUFACTURER, 610 606 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 607 + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 611 608 }; 612 609 613 610 #define bq2750x_props bq27510g3_props ··· 2050 2045 } 2051 2046 2052 2047 /* 2048 + * Return the design maximum battery Voltage in microvolts, or < 0 if something 2049 + * fails. The programmed value of the maximum battery voltage is determined by 2050 + * QV0 and QV1 (bits 5 and 6) in the Pack Configuration register. 2051 + */ 2052 + static int bq27xxx_battery_read_dmax_volt(struct bq27xxx_device_info *di, 2053 + union power_supply_propval *val) 2054 + { 2055 + int reg_val, qv; 2056 + 2057 + if (di->voltage_max_design > 0) { 2058 + val->intval = di->voltage_max_design; 2059 + return 0; 2060 + } 2061 + 2062 + reg_val = bq27xxx_read(di, BQ27XXX_REG_PKCFG, true); 2063 + if (reg_val < 0) { 2064 + dev_err(di->dev, "error reading design max voltage\n"); 2065 + return reg_val; 2066 + } 2067 + 2068 + qv = (reg_val >> 5) & 0x3; 2069 + val->intval = 3968000 + 48000 * qv; 2070 + 2071 + di->voltage_max_design = val->intval; 2072 + 2073 + return 0; 2074 + } 2075 + 2076 + /* 2053 2077 * Return the design minimum battery Voltage in microvolts 2054 2078 * Or < 0 if something fails. 2055 2079 */ ··· 2191 2157 return -EINVAL; 2192 2158 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 2193 2159 ret = bq27xxx_battery_read_dmin_volt(di, val); 2160 + break; 2161 + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 2162 + ret = bq27xxx_battery_read_dmax_volt(di, val); 2194 2163 break; 2195 2164 case POWER_SUPPLY_PROP_CYCLE_COUNT: 2196 2165 ret = bq27xxx_battery_read_cyct(di, val);
+1
include/linux/power/bq27xxx_battery.h
··· 62 62 struct bq27xxx_reg_cache cache; 63 63 int charge_design_full; 64 64 int voltage_min_design; 65 + int voltage_max_design; 65 66 bool removed; 66 67 unsigned long last_update; 67 68 union power_supply_propval last_status;