diff mbox series

power: bq27xxx: fix polarity of current_now

Message ID 20201204144950.8062-1-andreas@kemnade.info
State Accepted
Commit cd060b4d0868c806c2738a5e64e8ab9bd0fbec07
Headers show
Series power: bq27xxx: fix polarity of current_now | expand

Commit Message

Andreas Kemnade Dec. 4, 2020, 2:49 p.m. UTC
current_now has to be negative during discharging and positive during
charging, the behavior seen is the other way round.

Tested on GTA04 with Openmoko battery

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
 drivers/power/supply/bq27xxx_battery.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Sebastian Reichel Jan. 16, 2021, 2:57 p.m. UTC | #1
Hi,

On Fri, Dec 04, 2020 at 03:49:50PM +0100, Andreas Kemnade wrote:
> current_now has to be negative during discharging and positive during

> charging, the behavior seen is the other way round.

> 

> Tested on GTA04 with Openmoko battery

> 

> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>

> ---


Thanks, queued.

-- Sebastian

>  drivers/power/supply/bq27xxx_battery.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c

> index 315e0909e6a4..3ecc18b01d49 100644

> --- a/drivers/power/supply/bq27xxx_battery.c

> +++ b/drivers/power/supply/bq27xxx_battery.c

> @@ -1789,7 +1789,7 @@ static int bq27xxx_battery_current(struct bq27xxx_device_info *di,

>  

>  	if (di->opts & BQ27XXX_O_ZERO) {

>  		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);

> -		if (flags & BQ27000_FLAG_CHGS) {

> +		if (!(flags & BQ27000_FLAG_CHGS)) {

>  			dev_dbg(di->dev, "negative current!\n");

>  			curr = -curr;

>  		}

> @@ -1797,7 +1797,7 @@ static int bq27xxx_battery_current(struct bq27xxx_device_info *di,

>  		val->intval = curr * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;

>  	} else {

>  		/* Other gauges return signed value */

> -		val->intval = (int)((s16)curr) * 1000;

> +		val->intval = -(int)((s16)curr) * 1000;

>  	}

>  

>  	return 0;

> -- 

> 2.20.1

>
diff mbox series

Patch

diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 315e0909e6a4..3ecc18b01d49 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -1789,7 +1789,7 @@  static int bq27xxx_battery_current(struct bq27xxx_device_info *di,
 
 	if (di->opts & BQ27XXX_O_ZERO) {
 		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);
-		if (flags & BQ27000_FLAG_CHGS) {
+		if (!(flags & BQ27000_FLAG_CHGS)) {
 			dev_dbg(di->dev, "negative current!\n");
 			curr = -curr;
 		}
@@ -1797,7 +1797,7 @@  static int bq27xxx_battery_current(struct bq27xxx_device_info *di,
 		val->intval = curr * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
 	} else {
 		/* Other gauges return signed value */
-		val->intval = (int)((s16)curr) * 1000;
+		val->intval = -(int)((s16)curr) * 1000;
 	}
 
 	return 0;