Skip to contentSkip to conversation

bq27x00_battery: Do not report nominal available capaciy if battery is not calibrated

PATCH In review Pali Rohár 2 participants 3 messages Nov 10, 2012 – Nov 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bq27x00_battery: Do not report nominal available capaciy if battery is not calibrated

---
 drivers/power/bq27x00_battery.c |    8 ++++++++
 1 file changed, 8 insertions(+)
drivers/power/bq27x00_battery.c +8 -0
index 5860d4d..41b3328 100644
@@ -230,6 +230,14 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
  */
 static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
 {
+	int flags;
+	bool is_bq27500 = di->chip == BQ27500;
+	bool is_higher = bq27xxx_is_chip_version_higher(di);
+
+	flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
+	if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI))
+		return -ENODATA;
+
 	return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC);
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · Pali Rohár
---
 drivers/power/bq27x00_battery.c |    8 ++++++++
 1 file changed, 8 insertions(+)

OK, I'm assuming we don't want this because otherwise we're getting bogus values in the sysfs, and so we confuse userland. I added this explanation to the commit message, but still would be great to hear some confirmation.

Anyways, this is applied now.

Thanks!

Quoted 21 lines
drivers/power/bq27x00_battery.c +8 -0
index 5860d4d..41b3328 100644
@@ -230,6 +230,14 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
  */
 static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
 {
+	int flags;
+	bool is_bq27500 = di->chip == BQ27500;
+	bool is_higher = bq27xxx_is_chip_version_higher(di);
+
+	flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
+	if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI))
+		return -ENODATA;
+
 	return bq27x00_battery_read_charge(di, BQ27x00_REG_NAC);
 }
 
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 7 lines · On Sunday 18 November 2012 16:05:52 Anton Vorontsov wrote:
Quoted 5 lines · Pali Rohár

---

 drivers/power/bq27x00_battery.c |    8 ++++++++
 1 file changed, 8 insertions(+)
Quoted 9 lines

OK, I'm assuming we don't want this because otherwise we're getting bogus values in the sysfs, and so we confuse userland. I added this explanation to the commit message, but still would be great to hear some confirmation.

Anyways, this is applied now.

Thanks!

Right.

Signature · 2 lines
Pali Rohár
[email protected]