power: pm8921-bms: fine tune the uuc scaling algorithm

For every soc calculations there are three unusable charge (uuc)
values.
uuc_uah_itest:
	The uuc value in micro amp hour (uah) based on the max current
	(itest). Typically this value is very high and changes as the
	battery resistance changes
uuc_uah_iavg:
	The uuc value based on the average current (iavg). Typically
	this is lower than uuc_itest
uuc_reported:
	The reported uuc based on state of charge (SOC) of the battery
	which chooses a stepsize value and approaches towards
	uuc_uah_itest or uuc_uah_iavg based on whether the device is
	being charged.

The expectation is that the reported uuc increase as the battery looses SOC
and decrease as SOC approaches full condition.

To help us coming up with a satisfactory algorithm the following
parameters are introduced.
uuc_multiplier:
	The multiplier used in stepsize calculation
uuc_iavg_div:
	The divisor to use in calculation of stepsize when there
	is a significant jump in average current from the
	previous attempt
uuc_min_step_size:
	The minimum stepsize to use if the calculated stepsize is very less

Also, in order to ignore the high bootup time load a timer is introduced
which makes the algorithm ignore iavg values upon bootup.

The algorithm also uses the previous uuc based on iavg in
"uuc_uah_iavg_prev". This aids in checking if there was a significant
increase in average current from the previous time uuc was calculated.
The algorithm keeps track of the previous reported uuc in last_uuc_uah.

Change-Id: I360fd74e7fd2c939dd67023c128b2d70da923e9a
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
1 file changed