[Letux-kernel] gab driver

H. Nikolaus Schaller hns at goldelico.com
Mon Dec 4 15:03:37 CET 2017


> Am 04.12.2017 um 14:41 schrieb H. Nikolaus Schaller <hns at goldelico.com>:
> 
> 
>> Am 04.12.2017 um 14:09 schrieb Belisko Marek <marek.belisko at gmail.com>:
>> 
>> Hi Nikolaus,
>> 
>> On Mon, Dec 4, 2017 at 1:22 PM, H. Nikolaus Schaller <hns at goldelico.com> wrote:
>>> Hi Marek,
>>> I have rebased the Letux kernel to 4.15-rc2 and did now test on Pyra.
>>> 
>>> Looks quite good:
>> +1
>>> 
>>> Battery /sys/class/power_supply/bq27421-0
>>> ==================
>>> type: Battery
>>> present: 1
>>> technology: Li-ion
>>> capacity: 1%
>>> status: Charging
>>> level: Low
>>> volt: 3751000uV
>>> current: 807000uA
>>> temp: 23.9°C
>>> charge: 110000uAh
>>> full: 5362000uAh
>>> design: 6000000uAh
>>> energy: J?
>>> power: W?
>>> cycles:
>>> health:
>>> discharge: s to empty average
>>> remaining: s to empty
>>> charging: s to full
>>> 
>>> Battery /sys/class/power_supply/pyra-battery
>>> ==================
>>> type: Battery
>>> present:
>>> technology: Li-ion
>>> capacity: 3%
>>> status: Discharging
>>> level:
>>> volt: 3710000uV
>>> current: 0uA
>>> temp: 7.6°C
>>> charge: 180000uAh
>>> full: uAh
>>> design: 6000000uAh
>>> energy: J?
>>> power: W?
>>> cycles:
>>> health:
>>> discharge: s to empty average
>>> remaining: s to empty
>>> charging: s to full
>>> 
>>> root at letux:~#
>>> 
>>> Only minor things are observed:
>>> * status says Discharging although it is being charged
>>> * current is 0mA (seems the reason for the first issue - I don't know how the Palmas can report the current)
>>> * temperature says 7.6°C... But this may be a calibration issue in the Palmas iio adc
>>> * can we somehow report "Present:"? Maybe by checking if battery voltage > some minimum
>>> * can we report "Level"? Maybe <10% => low <90% => good >= 90% => full?
>> OK I'll try to look but can I please use you as remote tester as I
>> don;t have pyra device.
> 
> Unfortunately I am not yet in a position to change that...
> 
>> Thanks.
> 
> Yes, sure for the Palmas things.
> 
> Some of the (new) features can also be tested on GTA04.
> 
> One more thing - maybe we can write a simple logging daemon that rund
> in the background and collects bq27xxx charge in % vs. *battery charge in %
> We can then simply run it while testing/using/charging devices and get an
> impression about the precision of the State-of-Charge prediction.
> 
> I think of something like:
> 
> battmon:
> 
> # run as daemon
> 
> BQ27=$(echo /sys/class/power_supply/bq27*)
> GAB=$(echo /sys/class/power_supply/*-battery)
> 
> 2>/dev/null
> 
> function values {
>        echo $(cat $1/capacity)% $(cat $1/charge_now)uAh $(cat $1/voltage_now)mV $(cat $1/status)
> }
> 
> while true
> do
>        echo $(date) - $(values $BQ27) - $(values $GAB) >>battmon.log
>        sleep 10
> done

I did now run a slightly modified version and here is the result:

root at letux:~# ./battmon 
Mon Dec 4 13:45:35 UTC 2017 - 22% 1073000uAh 3828000mV 746000uA Charging - 27% 1500000uAh 3782000mV 0uA Discharging
Mon Dec 4 13:45:45 UTC 2017 - 22% 1075000uAh 3827000mV 751000uA Charging - 38% 2340000uAh 3787000mV 0uA Discharging
Mon Dec 4 13:45:55 UTC 2017 - 22% 1077000uAh 3827000mV 751000uA Charging - 40% 2100000uAh 3787000mV 0uA Discharging
Mon Dec 4 13:46:06 UTC 2017 - 22% 1079000uAh 3827000mV 748000uA Charging - 29% 1500000uAh 3763000mV 0uA Discharging
Mon Dec 4 13:46:16 UTC 2017 - 22% 1081000uAh 3827000mV 746000uA Charging - 34% 2280000uAh 3769000mV 0uA Discharging
Mon Dec 4 13:46:26 UTC 2017 - 22% 1083000uAh 3825000mV 742000uA Charging - 29% 1740000uAh 3768000mV 0uA Discharging
Mon Dec 4 13:46:36 UTC 2017 - 22% 1085000uAh 3826000mV 744000uA Charging - 30% 2100000uAh 3770000mV 0uA Discharging
Mon Dec 4 13:46:46 UTC 2017 - 22% 1087000uAh 3828000mV 747000uA Charging - 35% 2040000uAh 3776000mV 0uA Discharging
Mon Dec 4 13:46:56 UTC 2017 - 22% 1090000uAh 3828000mV 742000uA Charging - 4% 2100000uAh 3789000mV 0uA Discharging
Mon Dec 4 13:47:06 UTC 2017 - 22% 1092000uAh 3828000mV 743000uA Charging - 33% 2280000uAh 3785000mV 0uA Discharging
Mon Dec 4 13:47:17 UTC 2017 - 22% 1094000uAh 3829000mV 737000uA Charging - 36% 2280000uAh 3788000mV 0uA Discharging
Mon Dec 4 13:47:27 UTC 2017 - 22% 1096000uAh 3829000mV 747000uA Charging - 31% 1620000uAh 3780000mV 0uA Discharging
Mon Dec 4 13:47:37 UTC 2017 - 22% 1098000uAh 3828000mV 744000uA Charging - 38% 2160000uAh 3785000mV 0uA Discharging
^Croot at letux:~# 

first set of values is from the bq27421 and values are monotonic raising as expected.
gab driver reports strange things :(

0uA may be ok, if not provided. And that there is some voltage difference and jitter is also ok (because it is
measured at different points).

But % value jumps up and down. Do we have an uninitalized variable here? Or integer overflow with scaling?

Here some values from gta04:

Mon Dec 4 13:54:23 UTC 2017 - 100% 633680uAh 4167000mV -379848uA Charging - 100% 1250000uAh 4205000mV 943000uA Charging
Mon Dec 4 13:54:34 UTC 2017 - 100% 633680uAh 4167000mV -375564uA Charging - 100% 1250000uAh 4205000mV 927000uA Charging
Mon Dec 4 13:54:44 UTC 2017 - 100% 633680uAh 4167000mV -372529uA Charging - 100% 1250000uAh 4205000mV 892000uA Charging
Mon Dec 4 13:54:55 UTC 2017 - 100% 633680uAh 4169000mV -369316uA Charging - 100% 1250000uAh 4205000mV 932000uA Charging
Mon Dec 4 13:55:05 UTC 2017 - 100% 633680uAh 4167000mV -364140uA Charging - 100% 1250000uAh 4217000mV 781000uA Charging
Mon Dec 4 13:55:16 UTC 2017 - 100% 632968uAh 4069000mV 262038uA Charging - 81% 1012500uAh 4011000mV -749000uA Discharging
Mon Dec 4 13:55:26 UTC 2017 - 100% 632256uAh 4061000mV 252756uA Not charging - 78% 987500uAh 4005000mV -750000uA Discharging
Mon Dec 4 13:55:37 UTC 2017 - 100% 631544uAh 4055000mV 251685uA Not charging - 77% 1000000uAh 4000000mV -750000uA Discharging
Mon Dec 4 13:55:47 UTC 2017 - 100% 630832uAh 4050000mV 253291uA Not charging - 76% 1000000uAh 4005000mV -750000uA Discharging
Mon Dec 4 13:55:58 UTC 2017 - 99% 630120uAh 4045000mV 253827uA Not charging - 75% 950000uAh 3982000mV -750000uA Discharging
Mon Dec 4 13:56:08 UTC 2017 - 99% 629230uAh 4042000mV 253470uA Not charging - 75% 937500uAh 3976000mV -750000uA Discharging
Mon Dec 4 13:56:19 UTC 2017 - 99% 628518uAh 4037000mV 254898uA Not charging - 75% 937500uAh 3976000mV -749000uA Discharging
Mon Dec 4 13:56:29 UTC 2017 - 99% 627806uAh 4037000mV 255969uA Not charging - 75% 925000uAh 3982000mV -750000uA Discharging
Mon Dec 4 13:56:39 UTC 2017 - 99% 627094uAh 4034000mV 254541uA Not charging - 75% 937500uAh 3970000mV -750000uA Discharging
Mon Dec 4 13:56:50 UTC 2017 - 99% 626382uAh 4031000mV 255076uA Not charging - 75% 937500uAh 3970000mV -750000uA Discharging
Mon Dec 4 13:57:00 UTC 2017 - 99% 625492uAh 4029000mV 254541uA Not charging - 75% 937500uAh 3988000mV -750000uA Discharging
Mon Dec 4 13:57:11 UTC 2017 - 99% 624780uAh 4026000mV 254184uA Not charging - 73% 937500uAh 3964000mV -750000uA Discharging
Mon Dec 4 13:57:21 UTC 2017 - 99% 624068uAh 4026000mV 254719uA Not charging - 73% 937500uAh 3964000mV -749000uA Discharging
Mon Dec 4 13:57:32 UTC 2017 - 98% 623356uAh 4023000mV 255612uA Not charging - 74% 912500uAh 3953000mV -750000uA Discharging
Mon Dec 4 13:57:42 UTC 2017 - 98% 622644uAh 4023000mV 254184uA Not charging - 77% 950000uAh 3988000mV -750000uA Discharging

Look a little better - but we do not estimate the real battery voltage very well.
Do we already have the series resistance estimate? And the compensation by system power demand?

Basic idea:

                             charging current
                                  v
                                  v
VBATT real --- series R ---- VBAT-measured ----> system power drain

I.e. the charging current is split up into a path to the system and one into the battery
During discharge, we should not have the charging current but the full power drain making a
voltage drop across the series R.

What I don't exactly know is why the twl4030 reports positive current during charging (~900mA)
and negative (~750mA) during discharge.

So this is less a software issue but modelling the electric circuit of the battery+charger+omap

BR,
Nikolaus



More information about the Letux-kernel mailing list