Skip to contentSkip to conversation

bq27x00_battery: Some fixes

PATCH In review Anton Vorontsov 4 participants 7 messages Jan 31, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bq27x00_battery: Some fixes

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time()
fix to a separate patch.

----- Forwarded message from Pali Rohár <[email protected]> -----

Date: Wed, 26 Jan 2011 21:42:39 +0100
From: Pali Rohár <[email protected]>
To: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
Subject: Re: [PATCH] bq27x00_battery

This patch fix reporting correct (devided by resistor sense) values on bq27000/bq27200 batteries.

drivers/power/bq27x00_battery.c +8 -5
@@ -37,10 +37,11 @@
 #define BQ27x00_REG_TTF			0x18
 #define BQ27x00_REG_TTECP		0x26
 
+#define BQ27000_RS			20 /* Resistor sense */
 #define BQ27000_REG_RSOC		0x0B /* Relative State-of-Charge */
 #define BQ27000_FLAG_CHGS		BIT(7)
 
-#define BQ27500_REG_SOC			0x2c
+#define BQ27500_REG_SOC			0x2C
 #define BQ27500_FLAG_DSC		BIT(0)
 #define BQ27500_FLAG_FC			BIT(9)
 
@@ -112,7 +113,7 @@ static int bq27x00_battery_temperature(s
 }
 
 /*
- * Return the battery Voltage in milivolts
+ * Return the battery Voltage in µV
  * Or < 0 if something fails.
  */
 static int bq27x00_battery_voltage(struct bq27x00_device_info *di)
@@ -130,7 +131,7 @@ static int bq27x00_battery_voltage(struc
 }
 
 /*
- * Return the battery average current
+ * Return the battery average current in µA
  * Note that current can be negative signed as well
  * Or 0 if something fails.
  */
@@ -149,6 +150,7 @@ static int bq27x00_battery_current(struc
 	if (di->chip == BQ27500) {
 		/* bq27500 returns signed value */
 		curr = (int)(s16)curr;
+		curr *= 1000;
 	} else {
 		ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
 		if (ret < 0) {
@@ -159,9 +161,10 @@ static int bq27x00_battery_current(struc
 			dev_dbg(di->dev, "negative current!\n");
 			curr = -curr;
 		}
+		curr = curr * 3570 / BQ27000_RS;
 	}
 
-	return curr * 1000;
+	return curr;
 }
 
 /*
@@ -233,7 +236,7 @@ static int bq27x00_battery_time(struct b
 	}
 
 	if (tval == 65535)
-		return -ENODATA;
+		tval = 0;
 
 	val->intval = tval * 60;
 	return 0;

----- End forwarded message -----

#1 lore raw
Quoted 46 lines · Anton Vorontsov

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time()
fix to a separate patch.

----- Forwarded message from Pali Rohár <[email protected]> -----

Date: Wed, 26 Jan 2011 21:42:39 +0100
From: Pali Rohár <[email protected]>
To: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
Subject: Re: [PATCH] bq27x00_battery

This patch fix reporting correct (devided by resistor sense) values on bq27000/bq27200 batteries.

drivers/power/bq27x00_battery.c +3 -2
@@ -37,10 +37,11 @@
 #define BQ27x00_REG_TTF			0x18
 #define BQ27x00_REG_TTECP		0x26
 
+#define BQ27000_RS			20 /* Resistor sense */
 #define BQ27000_REG_RSOC		0x0B /* Relative State-of-Charge */
 #define BQ27000_FLAG_CHGS		BIT(7)
 
-#define BQ27500_REG_SOC			0x2c
+#define BQ27500_REG_SOC			0x2C
 #define BQ27500_FLAG_DSC		BIT(0)
 #define BQ27500_FLAG_FC			BIT(9)
 
@@ -112,7 +113,7 @@ static int bq27x00_battery_temperature(s
 }
 
 /*
- * Return the battery Voltage in milivolts
+ * Return the battery Voltage in µV
  * Or < 0 if something fails.
  */
 static int bq27x00_battery_voltage(struct bq27x00_device_info *di)

drivers/power/bq27x00_battery.c static int bq27x00_battery_voltage(struc · line 131

Quoted 1 line
drivers/power/bq27x00_battery.c +0 -0
@@ -130,7 +131,7 @@ static int bq27x00_battery_voltage(struc
 }

Ok, but I think we should change the function name adding _mV...

Quoted 16 lines
drivers/power/bq27x00_battery.c +2 -1
 /*
- * Return the battery average current
+ * Return the battery average current in µA
  * Note that current can be negative signed as well
  * Or 0 if something fails.
  */
@@ -149,6 +150,7 @@ static int bq27x00_battery_current(struc
 	if (di->chip == BQ27500) {
 		/* bq27500 returns signed value */
 		curr = (int)(s16)curr;
+		curr *= 1000;
 	} else {
 		ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
 		if (ret < 0) {

drivers/power/bq27x00_battery.c static int bq27x00_battery_current(struc · line 168

Quoted 9 lines
drivers/power/bq27x00_battery.c +2 -1
@@ -159,9 +161,10 @@ static int bq27x00_battery_current(struc
 			dev_dbg(di->dev, "negative current!\n");
 			curr = -curr;
 		}
+		curr = curr * 3570 / BQ27000_RS;
 	}
 
-	return curr * 1000;
+	return curr;
 }

And here _mA.

drivers/power/bq27x00_battery.c static int bq27x00_battery_time(struct b

Quoted 12 lines
drivers/power/bq27x00_battery.c +1 -2
 /*
@@ -233,7 +236,7 @@ static int bq27x00_battery_time(struct b
 	}
 
 	if (tval == 65535)
-		return -ENODATA;
+		tval = 0;
 
 	val->intval = tval * 60;
 	return 0;
 
----- End forwarded message -----

Ciao,

Rodolfo

Signature · 5 lines
GNU/Linux Solutions                  e-mail: [email protected]
Linux Device Driver                          [email protected]
Embedded Systems                     phone:  +39 349 2432127
UNIX programming                     skype:  rodolfo.giometti
Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it
#2 lore raw

2011/1/31 Rodolfo Giometti <[email protected]>:

Quoted 96 lines · Anton Vorontsov
Quoted 46 lines

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time() fix to a separate patch.

----- Forwarded message from Pali Rohár <[email protected]> -----

Date: Wed, 26 Jan 2011 21:42:39 +0100
From: Pali Rohár <[email protected]>
To: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
Subject: Re: [PATCH] bq27x00_battery

This patch fix reporting correct (devided by resistor sense) values on bq27000/bq27200 batteries.

drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 renamed from drivers/power/bq27x00_battery.c 2011-01-26 21:30:40.000000000 +0100 +3 -2
@@ -37,10 +37,11 @@
  #define BQ27x00_REG_TTF                      0x18
  #define BQ27x00_REG_TTECP            0x26
 
+#define BQ27000_RS                   20 /* Resistor sense */
  #define BQ27000_REG_RSOC             0x0B /* Relative State-of-Charge */
  #define BQ27000_FLAG_CHGS            BIT(7)
 
-#define BQ27500_REG_SOC                      0x2c
+#define BQ27500_REG_SOC                      0x2C
  #define BQ27500_FLAG_DSC             BIT(0)
  #define BQ27500_FLAG_FC                      BIT(9)
 
@@ -112,7 +113,7 @@ static int bq27x00_battery_temperature(s
  }
 
  /*
- * Return the battery Voltage in milivolts
+ * Return the battery Voltage in µV
   * Or < 0 if something fails.
   */
  static int bq27x00_battery_voltage(struct bq27x00_device_info *di)

drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 static int bq27x00_battery_voltage(struc · line 131

Quoted 1 line
drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 renamed from drivers/power/bq27x00_battery.c 2011-01-26 21:30:40.000000000 +0100 +0 -0
@@ -130,7 +131,7 @@ static int bq27x00_battery_voltage(struc
  }

Ok, but I think we should change the function name adding _mV...

Quoted 16 lines
drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 renamed from drivers/power/bq27x00_battery.c 2011-01-26 21:30:40.000000000 +0100 +2 -1
  /*
- * Return the battery average current
+ * Return the battery average current in µA
   * Note that current can be negative signed as well
   * Or 0 if something fails.
   */
@@ -149,6 +150,7 @@ static int bq27x00_battery_current(struc
       if (di->chip == BQ27500) {
               /* bq27500 returns signed value */
               curr = (int)(s16)curr;
+             curr *= 1000;
       } else {
               ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
               if (ret < 0) {

drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 static int bq27x00_battery_current(struc · line 168

Quoted 9 lines
drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 renamed from drivers/power/bq27x00_battery.c 2011-01-26 21:30:40.000000000 +0100 +2 -1
@@ -159,9 +161,10 @@ static int bq27x00_battery_current(struc
                       dev_dbg(di->dev, "negative current!\n");
                       curr = -curr;
               }
+             curr = curr * 3570 / BQ27000_RS;
       }
 
-     return curr * 1000;
+     return curr;
  }

And here _mA.

drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 static int bq27x00_battery_time(struct b

Quoted 12 lines
drivers/power/bq27x00_battery.c 2011-01-26 21:32:34.000000000 +0100 renamed from drivers/power/bq27x00_battery.c 2011-01-26 21:30:40.000000000 +0100 +1 -2
  /*
@@ -233,7 +236,7 @@ static int bq27x00_battery_time(struct b
       }
 
       if (tval == 65535)
-             return -ENODATA;
+             tval = 0;
 
       val->intval = tval * 60;
       return 0;
 
----- End forwarded message -----

Ciao,

Rodolfo

Quoted 8 lines

--

GNU/Linux Solutions                  e-mail: [email protected] Linux Device Driver                          [email protected] Embedded Systems                     phone:  +39 349 2432127 UNIX programming                     skype:  rodolfo.giometti Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it

Why rename to _mA/_mV? Functions return values in µA/µV (units from Documentation/power/power_supply_class.txt)

Signature · 2 lines
Pali Rohár
[email protected]
#3 lore raw
In reply to Anton Vorontsov
Quoted 7 lines · Anton Vorontsov

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time()
fix to a separate patch.

Hi

I have a larger series pending which adds support for the bq27000 chip and polling to the bq27x00 driver. Since this series does some refactoring of the bq27x00 driver, it might make sense to rebase this (and the other) patch ontop of that series instead of the other way around.

I'll try to send it in later today or tomorrow. For now you can take a look at it at
http://git.metafoo.de/?p=linux-2.6;a=shortlog;h=refs/heads/bq27x00-for-upstream

- Lars

Quoted 83 lines

----- Forwarded message from Pali Rohár <[email protected]> -----

Date: Wed, 26 Jan 2011 21:42:39 +0100
From: Pali Rohár <[email protected]>
To: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
Subject: Re: [PATCH] bq27x00_battery

This patch fix reporting correct (devided by resistor sense) values on bq27000/bq27200 batteries.

drivers/power/bq27x00_battery.c +8 -7
@@ -37,10 +37,11 @@
 #define BQ27x00_REG_TTF			0x18
 #define BQ27x00_REG_TTECP		0x26
 
+#define BQ27000_RS			20 /* Resistor sense */
 #define BQ27000_REG_RSOC		0x0B /* Relative State-of-Charge */
 #define BQ27000_FLAG_CHGS		BIT(7)
 
-#define BQ27500_REG_SOC			0x2c
+#define BQ27500_REG_SOC			0x2C
 #define BQ27500_FLAG_DSC		BIT(0)
 #define BQ27500_FLAG_FC			BIT(9)
 
@@ -112,7 +113,7 @@ static int bq27x00_battery_temperature(s
 }
 
 /*
- * Return the battery Voltage in milivolts
+ * Return the battery Voltage in µV
  * Or < 0 if something fails.
  */
 static int bq27x00_battery_voltage(struct bq27x00_device_info *di)
@@ -130,7 +131,7 @@ static int bq27x00_battery_voltage(struc
 }
 
 /*
- * Return the battery average current
+ * Return the battery average current in µA
  * Note that current can be negative signed as well
  * Or 0 if something fails.
  */
@@ -149,6 +150,7 @@ static int bq27x00_battery_current(struc
 	if (di->chip == BQ27500) {
 		/* bq27500 returns signed value */
 		curr = (int)(s16)curr;
+		curr *= 1000;
 	} else {
 		ret = bq27x00_read(BQ27x00_REG_FLAGS, &flags, 0, di);
 		if (ret < 0) {
@@ -159,9 +161,10 @@ static int bq27x00_battery_current(struc
 			dev_dbg(di->dev, "negative current!\n");
 			curr = -curr;
 		}
+		curr = curr * 3570 / BQ27000_RS;
 	}
 
-	return curr * 1000;
+	return curr;
 }
 
 /*
@@ -233,7 +236,7 @@ static int bq27x00_battery_time(struct b
 	}
 
 	if (tval == 65535)
-		return -ENODATA;
+		tval = 0;
 
 	val->intval = tval * 60;
 	return 0;
 
----- End forwarded message -----
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
Quoted 9 lines · Lars-Peter Clausen
Quoted 7 lines · Anton Vorontsov

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time()
fix to a separate patch.

Quoted 6 lines

Hi

I have a larger series pending which adds support for the bq27000 chip and polling to the bq27x00 driver. Since this series does some refactoring of the bq27x00 driver, it might make sense to rebase this (and the other) patch ontop of that series instead of the other way around.

Pali was first to send out his work, so I think that it would make sense to ask you to rebase your work on top. Especially since Pali's patches were somewhat reviewed already.

I hope Pali will resend the fixed versions quickly enough so that I'll apply the patches asap and you'll easily use git for rebasing.

Thanks!

Signature · 2 lines
Anton Vorontsov
Email: [email protected]
#5 lore raw
Quoted 12 lines · Anton Vorontsov
Quoted 11 lines · Lars-Peter Clausen
Quoted 7 lines · Anton Vorontsov

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time()
fix to a separate patch.

Hi

Quoted 8 lines
Quoted 4 lines

I have a larger series pending which adds support for the bq27000 chip and polling to the bq27x00 driver. Since this series does some refactoring of the bq27x00 driver, it might make sense to rebase this (and the other) patch ontop of that series instead of the other way around.

Pali was first to send out his work, so I think that it would make sense to ask you to rebase your work on top. Especially since Pali's patches were somewhat reviewed already.

I suspect it to be substantial more work to rebase mine on top of his. That's why I'm asking for a exception in this case. I would be willing to adjust his patches, so they can be applied on top of mine.

Quoted 5 lines

I hope Pali will resend the fixed versions quickly enough so that I'll apply the patches asap and you'll easily use git for rebasing.

git won't help in this case, because my patches basically rewrite the parts changed by Palis patches. It would be one merge conflict after another, I guess.

Quoted 2 lines

Thanks!

#6 lore raw

2011/1/31 Lars-Peter Clausen <[email protected]>:

Quoted 27 lines · Anton Vorontsov
Quoted 12 lines · Lars-Peter Clausen
Quoted 11 lines · Anton Vorontsov
Quoted 7 lines

The same is for this patch.

Comments, Reviewed-by or Acked-by?

p.s. FWIW, I already asked Pali to factor out bq27x00_battery_time() fix to a separate patch.

Hi

Quoted 8 lines
Quoted 4 lines

I have a larger series pending which adds support for the bq27000 chip and polling to the bq27x00 driver. Since this series does some refactoring of the bq27x00 driver, it might make sense to rebase this (and the other) patch ontop of that series instead of the other way around.

Pali was first to send out his work, so I think that it would make sense to ask you to rebase your work on top. Especially since Pali's patches were somewhat reviewed already.

I suspect it to be substantial more work to rebase mine on top of his. That's why I'm asking for a exception in this case. I would be willing to adjust his patches, so they can be applied on top of mine.

Quoted 1 line
Quoted 12 lines
Quoted 4 lines

I hope Pali will resend the fixed versions quickly enough so that I'll apply the patches asap and you'll easily use git for rebasing.

git won't help in this case, because my patches basically rewrite the parts changed by Palis patches. It would be one merge conflict after another, I guess.

Quoted 2 lines

Thanks!

Can you then merge my changes with your in git?

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