power: pm8921-bms: adjust OCV and cc for 100% charge
The remaining usable charge is calculated as below
RUC = RC - CC - UUC
RC is the remaining charge when an OCV (open circuit voltage) is
measured by the bms hw. It is some percent of full charge capacity.
The BMS hw continuously monitors the battery current and when it is
low enough it reads the battery voltage and calls it OCV.
CC is the charge based on coulomb counter and represents the
absolute charge provided since an OCV was taken. When OCV happens,
the coulomb counter is reset to zero.
UUC is the unusable charge that the system cannot use because of
internal battery resistance. For the most part this value remains
constant, it changes slowly as the battery ages.
The state of charge (SOC) is calculated as below
SOC = RUC / (FCC - UUC)
When an end of charging event happens, the driver calculates (RC - CC)
and sets that as the new full charge capacity (FCC). However since the
system uses the old OCV value which translates to some percent of full
charge capacity, the soc calculated after this FCC adjustment will be
less than 100%.
To workaround this problem, the software needs to behave as if the
OCV had just happened after charging finishes. IOW force OCV to max
possible value which translates to 100% FCC and force CC to zero.
Substituting RC = 100% FCC = FCC and CC = 0
we get
RUC = FCC - UUC
and
SOC = (FCC - UUC)/ (FCC - UUC)
which is 100%
As the battery now discharges the CC part of the RUC increases lowering
the SOC.
To force CC to zero the driver notes the CC readings when end of charge
happens (cc_reading_at_100) and subtracts this reading for all subsequent
cc reads.
To force an OCV that will translate to 100% FCC the driver uses the
lookup table and picks the highest profiled OCV. This happens to be the
first row and the last column in the profile table.
This software faking the OCV to 100% FCC and CC to zero needs to cease
when a new OCV measurement is taken by the BMS hw. The driver remembers
the old OCV in ocv_reading_at_100 and knows a new OCV is taken if a
different OCV reading is read. It sets the cc_reading_at_100 and
ocv_reading_at_100 to zero.
Note that the system will never read zero as the ocv, a zero OCV
translate to a -ve 2.3986 volt battery voltage - a physical impossibility.
Change-Id: Icfef5b6242185009af7ae443088f86c230ccbe64
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
1 file changed