linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Arthur D." <spinal.by@gmail.com>
To: "Tony Lindgren" <tony@atomide.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: Tue, 10 Mar 2020 21:35:29 +0300	[thread overview]
Message-ID: <op.0g90lfcdhxa7s4@supervisor.net28> (raw)
In-Reply-To: <20200310153951.GR37466@atomide.com>

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.

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)

>> 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.

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.

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.

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.

--
Best regards, Spinal

  reply	other threads:[~2020-03-10 18:35 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. [this message]
2020-03-11 14:23               ` Tony Lindgren

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=op.0g90lfcdhxa7s4@supervisor.net28 \
    --to=spinal.by@gmail.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=merlijn@wizzup.org \
    --cc=pavel@ucw.cz \
    --cc=sre@kernel.org \
    --cc=tony@atomide.com \
    /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).