linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Paul Kocialkowski <contact@paulk.fr>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Andrew F . Davis" <afd@ti.com>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Chris Lapa" <chris@lapa.com.au>,
	"Matt Ranostay" <mranostay@gmail.com>
Subject: Re: [PATCH 5/5] power: supply: bq27xxx: Correct supply status with current draw
Date: Wed, 31 May 2017 19:32:07 +0200	[thread overview]
Message-ID: <20170531173207.GA10763@amd> (raw)
In-Reply-To: <1496249719.1774.1.camel@paulk.fr>

[-- Attachment #1: Type: text/plain, Size: 3060 bytes --]

Hi!

> > > The status reported directly by the battery controller is not always
> > > reliable and should be corrected based on the current draw information.
> > > 
> > > This implements such a correction with a dedicated function, called
> > > when retrieving the supply status.

> > > @@ -1182,6 +1196,8 @@ static int bq27xxx_battery_status(struct
> > > bq27xxx_device_info *di,
> > >  		else
> > >  			status = POWER_SUPPLY_STATUS_DISCHARGING;
> > >  	} else {
> > > +		curr = (int)((s16)curr) * 1000;
> > 
> > Umm.

As in "two casts in one expression -- too ugly to live".

> > > @@ -1190,6 +1206,18 @@ static int bq27xxx_battery_status(struct
> > > bq27xxx_device_info *di,
> > >  			status = POWER_SUPPLY_STATUS_CHARGING;
> > >  	}
> > >  
> > > +
> > > +	if (curr == 0 && status != POWER_SUPPLY_STATUS_NOT_CHARGING)
> > > +		status = POWER_SUPPLY_STATUS_FULL;
> > > +
> > > +	if (status == POWER_SUPPLY_STATUS_FULL) {
> > > +		/* Drawing or providing current when full */
> > > +		if (curr > 0)
> > > +			status = POWER_SUPPLY_STATUS_CHARGING;
> > > +		else if (curr < 0)
> > > +			status = POWER_SUPPLY_STATUS_DISCHARGING;
> > > +	}
> > 
> > Are you sure this works? On N900, we normally see small currents to/from
> > "full" battery.
> 
> In my case, this works perfectly and I am quite surprised of what you're
> describing. Is it the case when the battery has a PSU connected?

"PSU"? This is cellphone. It has USB connection and charges from that.

It has been charging for long while now, and current_now fluctuates
between 20706 and -2856. USB has limitted current, so I guess "draw
current from battery if we need more than USB can provide" is quite common.

pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
5355
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
5355
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
-4105
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
-4105
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
-7675
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
-5712
pavel@n900:~$ #screen on
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
4641
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
4641
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
37842
pavel@n900:~$ cat /sys/class/power_supply/bq27200-0/current_now
16600
pavel@n900:~$

> I guess I would consider this a hardware issue (leak currents) and we could
> definitely set some range (in device-tree) to distinguish between full + leak
> currents and bad reporting from the fuel gauge. That would work well in my case
> too.

I'd pass to userspace what the controller reports. Yes, I seldom see
"STATUS_FULL" but that may be a problem we need to track down.



       	  	 	     		 	      	    	    	 Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2017-05-31 17:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-30 18:27 [PATCH 1/5] power: supply: bq27xxx: Pass of_node along to allow device-tree supply Paul Kocialkowski
2017-04-30 18:27 ` [PATCH 2/5] power: supply: bq27xxx: Register power supply with devm Paul Kocialkowski
2017-05-01 10:55   ` Sebastian Reichel
2017-05-07 17:43     ` Paul Kocialkowski
2017-04-30 18:27 ` [PATCH 3/5] power: supply: bq27xxx: Rename work structure member to poll_work Paul Kocialkowski
2017-04-30 18:27 ` [PATCH 4/5] power: supply: bq27xxx: Look for status change on external power change Paul Kocialkowski
2017-05-05  8:04   ` Pali Rohár
2017-05-07 17:37     ` Paul Kocialkowski
2017-05-08 13:04       ` Pali Rohár
2017-04-30 18:27 ` [PATCH 5/5] power: supply: bq27xxx: Correct supply status with current draw Paul Kocialkowski
2017-05-28 19:16   ` Pavel Machek
2017-05-31 16:55     ` Paul Kocialkowski
2017-05-31 17:32       ` Pavel Machek [this message]
2017-05-31 19:28         ` Paul Kocialkowski
2017-06-07  7:15           ` Paul Kocialkowski
2017-06-07  7:52             ` Pavel Machek
2017-06-07 15:20               ` Paul Kocialkowski
2017-06-07 19:50                 ` Pavel Machek
2017-06-08 10:08                   ` Paul Kocialkowski
2017-06-08 19:27                     ` Sebastian Reichel
2017-06-09  6:16                       ` Paul Kocialkowski
2017-06-13 12:14                         ` Sebastian Reichel
     [not found] <20170430203801.32357-1-contact@paulk.fr>
     [not found] ` <20170430203801.32357-5-contact@paulk.fr>
2017-04-30 22:35   ` Liam Breck
2017-05-01 10:39     ` Paul Kocialkowski
2017-05-01 18:18       ` Liam Breck
2017-05-01 18:37         ` Paul Kocialkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170531173207.GA10763@amd \
    --to=pavel@ucw.cz \
    --cc=afd@ti.com \
    --cc=chris@lapa.com.au \
    --cc=contact@paulk.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=pali.rohar@gmail.com \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).