linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: "Arthur D." <spinal.by@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>, Merlijn Wajer <merlijn@wizzup.org>,
	Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org, linux-omap@vger.kernel.org
Subject: Re: [PATCH 1/3] RFC: power: supply: cpcap-battery: Add helper for rough capacity
Date: Wed, 11 Mar 2020 07:23:01 -0700	[thread overview]
Message-ID: <20200311142301.GV37466@atomide.com> (raw)
In-Reply-To: <op.0g90lfcdhxa7s4@supervisor.net28>

* Arthur D. <spinal.by@gmail.com> [200310 18:36]:
> Hi.
> 
> > > 1) RFC: power: supply: cpcap-battery: Add helper for rough capacity
> > > 
> > > CPCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_FULL, 4200000 - 18000, 100)
> > > 
> > > This line seems wrong, because Droid4 full battery is 4.35V, not 4.2V.
> > 
> > Hmm yeah this is now configurable and defaults to 4.2V so we
> > should use the confgured value. The reason we default to 4.2V
> > now is because we suspect that if left connected to the charger
> > at higher than 4.2V the battery ages faster.
> 
> 1. How to configure this value? I tried:
> echo 4350000 > /sys/class/power_supply/battery/constant_charge_voltage
> 
> ...but it didn't change the fully charged battery voltage.

If you really want to use it, first enable it for the battery in
/sys/class/power/supply/usb to allow it, then also enable it for the
charger in /sys/class/power/supply/usb to actually use it.

But as discussed earlier, it really seems the battery ages faster at
the higher charge rates. Especially if left connected to the charger
for longer times as also seen with Android earlier.

> 2. If the value is configurable, it probably shouldn't be hardcoded like
> this in the code:
> PCAP_CAP(POWER_SUPPLY_CAPACITY_LEVEL_FULL, 4200000 - 18000, 100)

Right, we should now use the configured voltage :)

> > > I think the kernel should return  -ENODATA
> > > for capacity values until the battery is "calibrated". By "calibration"
> > > I mean having high and low counter_uah values initialized with the data
> > > collected when the battery went a full charge or discharge cycle (from
> > > empty to full or vice versa).
> > 
> > Yes I like this idea. That leaves out the need for poor estimates
> > in the kernel.
> > 
> > I guess we should have the following new properties:
> > 
> > POWER_SUPPLY_PROP_CHARGE_COUNTER_FULL
> > POWER_SUPPLY_PROP_CHARGE_COUNTER_EMPTY
> > 
> > And these would be 0 on boot and then userspace can
> > update these based on battery data.
> 
> My idea is to only have one extra property which will store the delta of
> counter values for full and empty battery states. In this case, it's going
> to be more accurate than allowing the userspace to store/restore both full
> and empty counters.

Hmm OK. Sounds like you might have some patches coming then?

> Some users may have a dual boot setup. In this case restoring full & empty
> counters after reboot can make the kernel to report wrong battery
> percentage
> values.

Yeah no idea how that is handled. Also changing the battery can cause
issues with this. I was expecting the 1-wire EEPROM to contain some
battery specific data like a serial number, but it seems this data is
the same for all the same type batteries.

> Let's imagine the following situation:
> 
> 1. The user charges the battery to the full state and discharges it to be
> almost depleted, so the kernel has "calibrated" values for counter_full and
> counter_empty.
> 2. The user decides to reboot to another OS. Let's assume he has a fully
> charged battery before doing the reboot.
> For example the kernel provides the following values:
> POWER_SUPPLY_PROP_CHARGE_COUNTER_FULL = -250000
> POWER_SUPPLY_PROP_CHARGE_COUNTER_EMPTY = 950000
> /sys/class/power_supply/battery/charge_counter = -250000
> A daemon saves these values to a permanent storage.
> 3. The user boots another OS, works there for a while, the battery charge
> becomes 50%.
> 4. The user reboots back to our system, we restore the values:
> POWER_SUPPLY_PROP_CHARGE_COUNTER_FULL <- -250000
> POWER_SUPPLY_PROP_CHARGE_COUNTER_EMPTY <- 950000
> 5. /sys/class/power_supply/battery/charge_counter is initialized to 0 or
> -250000, it doesn't matter, because in both cases we will get the wrong
> battery percentage. We should report 50%, remember? In any case it can't
> be calculated to this value.

Maybe some charge counter offset limit can be used to validate
the saved data in the userspace before updating values for kernel?

> And here's how I suggest it to be implemented:
> 1. Same as above
> 2. Same as above, except the kernel provides a single value that the user
> should store between reboots (it's the delta I mentioned above):
> POWER_SUPPLY_PROP_CHARGE_FULL = 1200000
> 3. Same as above
> 4. The user reboots back to our system, we restore the value:
> POWER_SUPPLY_PROP_CHARGE_FULL <- 1200000
> 5. The kernel reports -ENODATA as battery capacity value until the battery
> goes to a reference point (fully charged or almost discharged state).
> When the battery is fully charged or discharged, the kernel can immediately
> calculate the opposite counter value. And no matter what was the initial
> value of /sys/class/power_supply/battery/charge_counter when the system
> booted.
> 
> Of course, the value of the delta will not be constant, it should be
> recalculated over time. The good news is that this value will be changed
> slowly over time. That is, it can vary from 2% to 10% per year.

Sounds good to me :)

Tony

      reply	other threads:[~2020-03-11 14:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-19 20:11 [PATCH 1/3] RFC: power: supply: cpcap-battery: Add helper for rough capacity Tony Lindgren
2020-01-19 20:11 ` [PATCH 2/3] RFC: power: supply: cpcap-battery: Save high and low states Tony Lindgren
2020-01-19 20:11 ` [PATCH 3/3] RFC: power: supply: cpcap-battery: Implement capacity percentage Tony Lindgren
2020-01-21  9:57 ` [PATCH 1/3] RFC: power: supply: cpcap-battery: Add helper for rough capacity Pavel Machek
2020-01-21 10:42   ` Merlijn Wajer
2020-01-21 22:25     ` Pavel Machek
2020-01-23 16:02       ` Tony Lindgren
2020-03-10  4:54         ` Arthur D.
2020-03-10 15:39           ` Tony Lindgren
2020-03-10 18:35             ` Arthur D.
2020-03-11 14:23               ` Tony Lindgren [this message]

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=20200311142301.GV37466@atomide.com \
    --to=tony@atomide.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=merlijn@wizzup.org \
    --cc=pavel@ucw.cz \
    --cc=spinal.by@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).