Skip to contentSkip to conversation

power: supply: max17042_battery: use VFSOC for capacity when no rsns

PATCH In review Henrik Grimler 4 participants 5 messages Sep 29, 2021 – Oct 2, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 power: supply: max17042_battery: use VFSOC for capacity when no rsns

On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no current sense resistor (rsns), the RepSOC register does not provide an accurate state of charge value. The reported value is wrong, and does not change over time. VFSOC however, which uses the voltage fuel gauge to determine the state of charge, always shows an accurate value.

For devices without current sense, VFSOC is already used for the soc-alert (0x0003 is written to MiscCFG register), so with this change the source of the alert and the PROP_CAPACITY value match.

Fixes 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver")

---
Changes in v2:
Re-write commit message to highlight that VFSOC is already used for alert, after Krzysztof's comments

---
 drivers/power/supply/max17042_battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/max17042_battery.c +4 -1
index 8dffae76b6a3..5809ba997093 100644
@@ -313,7 +313,10 @@ static int max17042_get_property(struct power_supply *psy,
 		val->intval = data * 625 / 8;
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
-		ret = regmap_read(map, MAX17042_RepSOC, &data);
+		if (chip->pdata->enable_current_sense)
+			ret = regmap_read(map, MAX17042_RepSOC, &data);
+		else
+			ret = regmap_read(map, MAX17042_VFSOC, &data);
 		if (ret < 0)
 			return ret;
 

base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29

Signature · 1 line
2.33.0
#1 lore raw

PATCH v2 2/2 power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty

Datasheet gives the name IAvg_empty, not LAvg_empty.

---
 drivers/power/supply/max17042_battery.c | 2 +-
 include/linux/power/max17042_battery.h  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/power/supply/max17042_battery.c +1 -1
index 5809ba997093..32f331480487 100644
@@ -786,7 +786,7 @@ static inline void max17042_override_por_values(struct max17042_chip *chip)
 	if ((chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) ||
 	    (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047) ||
 	    (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)) {
-		max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty);
+		max17042_override_por(map, MAX17042_IAvg_empty, config->iavg_empty);
 		max17042_override_por(map, MAX17042_TempNom, config->temp_nom);
 		max17042_override_por(map, MAX17042_TempLim, config->temp_lim);
 		max17042_override_por(map, MAX17042_FCTC, config->fctc);
include/linux/power/max17042_battery.h +2 -2
index dd24756a8af7..c417abd2ab70 100644
@@ -78,7 +78,7 @@ enum max17042_register {
 	MAX17042_T_empty	= 0x34,
 
 	MAX17042_FullCAP0       = 0x35,
-	MAX17042_LAvg_empty	= 0x36,
+	MAX17042_IAvg_empty	= 0x36,
 	MAX17042_FCTC		= 0x37,
 	MAX17042_RCOMP0		= 0x38,
 	MAX17042_TempCo		= 0x39,
@@ -221,7 +221,7 @@ struct max17042_config_data {
 	u16	fullcap;	/* 0x10 */
 	u16	fullcapnom;	/* 0x23 */
 	u16	socempty;	/* 0x33 */
-	u16	lavg_empty;	/* 0x36 */
+	u16	iavg_empty;	/* 0x36 */
 	u16	dqacc;		/* 0x45 */
 	u16	dpacc;		/* 0x46 */
 	u16	qrtbl00;	/* 0x12 */
Signature · 1 line
2.33.0
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty

Quoted 8 lines · Henrik Grimler

Datasheet gives the name IAvg_empty, not LAvg_empty.

---
 drivers/power/supply/max17042_battery.c | 2 +-
 include/linux/power/max17042_battery.h  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Best regards,
Krzysztof

Reviewed-by on v2 1/2
#3 lore raw
In reply to Henrik Grimler

Hi,

Quoted 15 lines · Henrik Grimler

On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no current sense resistor (rsns), the RepSOC register does not provide an accurate state of charge value. The reported value is wrong, and does not change over time. VFSOC however, which uses the voltage fuel gauge to determine the state of charge, always shows an accurate value.

For devices without current sense, VFSOC is already used for the soc-alert (0x0003 is written to MiscCFG register), so with this change the source of the alert and the PROP_CAPACITY value match.

Fixes 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver")
Quoted 4 lines

---
Changes in v2:
Re-write commit message to highlight that VFSOC is already used for alert, after Krzysztof's comments

Thanks, both patches looks good to me:

for the series.

Regards,

Hans

Quoted 23 lines
---
 drivers/power/supply/max17042_battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/max17042_battery.c +4 -1
index 8dffae76b6a3..5809ba997093 100644
@@ -313,7 +313,10 @@ static int max17042_get_property(struct power_supply *psy,
 		val->intval = data * 625 / 8;
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
-		ret = regmap_read(map, MAX17042_RepSOC, &data);
+		if (chip->pdata->enable_current_sense)
+			ret = regmap_read(map, MAX17042_RepSOC, &data);
+		else
+			ret = regmap_read(map, MAX17042_VFSOC, &data);
 		if (ret < 0)
 			return ret;
 

base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29

#4 lore raw

Hi,

Quoted 21 lines · Hans de Goede
Quoted 15 lines · Henrik Grimler

On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no current sense resistor (rsns), the RepSOC register does not provide an accurate state of charge value. The reported value is wrong, and does not change over time. VFSOC however, which uses the voltage fuel gauge to determine the state of charge, always shows an accurate value.

For devices without current sense, VFSOC is already used for the soc-alert (0x0003 is written to MiscCFG register), so with this change the source of the alert and the PROP_CAPACITY value match.

Fixes 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver")
Quoted 4 lines

---
Changes in v2:
Re-write commit message to highlight that VFSOC is already used for alert, after Krzysztof's comments

Quoted 5 lines

Thanks, both patches looks good to me:

for the series.

Thanks, both queued.

-- Sebastian

Quoted 31 lines

Regards,

Hans

Quoted 23 lines
---
 drivers/power/supply/max17042_battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/max17042_battery.c +4 -1
index 8dffae76b6a3..5809ba997093 100644
@@ -313,7 +313,10 @@ static int max17042_get_property(struct power_supply *psy,
 		val->intval = data * 625 / 8;
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
-		ret = regmap_read(map, MAX17042_RepSOC, &data);
+		if (chip->pdata->enable_current_sense)
+			ret = regmap_read(map, MAX17042_RepSOC, &data);
+		else
+			ret = regmap_read(map, MAX17042_VFSOC, &data);
 		if (ret < 0)
 			return ret;
 

base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29