power: qpnp-fg-gen3: improve cycle counter algorithm

Currently, when the charging status transitions to a state other
than charging, cycle counter algorithm stores the cycle count for
all the buckets for which the counting had started. This is fine
with respect to the algorithm.

However with qnovo enabled charging, this can cause issues when
charging status can go to not charging intermittently causing the
cycle count to be stored multiple times for a bucket. Modify the
logic to check for the charge termination or the presence of
input to go through all the buckets for storing the count. Also,
increment and store the counter only if battery SOC had increased
more than 2 LSBs for that SOC bucket.

While at it, run cycle_counter algorithm as a function instead
of a work. Also, keep the usage of cycle counter feature enable
flag inside the cycle counter APIs.

Change-Id: I62a92964ccbc6b965af09696deddc6fa8366a841
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2 files changed