Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 342dce5e authored by Vamshi Krishna B V's avatar Vamshi Krishna B V
Browse files

power: fg-alg: Improve capcity learning accuracy



Currently batt_soc_msb and delta_cc_pct are used for initial and
delta cc_uah calculation which resulting in losing some mah
during the calcualtions. Instead use 32 bit batt_soc and delta
cc_soc in centi percentage to improve the accuracy.

CRs-Fixed: 2225348
Change-Id: Idd3fea47a5e15a5db5734a3959a82d4e92aafa24
Signed-off-by: default avatarVamshi Krishna B V <vbv@codeaurora.org>
parent c4feb89e
Loading
Loading
Loading
Loading
+12 −10
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include "fg-alg.h"
#include "fg-alg.h"


#define FULL_SOC_RAW		255
#define FULL_SOC_RAW		255
#define FULL_BATT_SOC		GENMASK(31, 0)
#define CAPACITY_DELTA_DECIPCT	500
#define CAPACITY_DELTA_DECIPCT	500


/* Cycle counter APIs */
/* Cycle counter APIs */
@@ -351,7 +352,7 @@ static void cap_learning_post_process(struct cap_learning *cl)
 */
 */
static int cap_learning_process_full_data(struct cap_learning *cl)
static int cap_learning_process_full_data(struct cap_learning *cl)
{
{
	int rc, cc_soc_sw, cc_soc_delta_pct;
	int rc, cc_soc_sw, cc_soc_delta_centi_pct;
	int64_t delta_cap_uah;
	int64_t delta_cap_uah;


	rc = cl->get_cc_soc(cl->data, &cc_soc_sw);
	rc = cl->get_cc_soc(cl->data, &cc_soc_sw);
@@ -360,20 +361,21 @@ static int cap_learning_process_full_data(struct cap_learning *cl)
		return rc;
		return rc;
	}
	}


	cc_soc_delta_pct =
	cc_soc_delta_centi_pct =
		div64_s64((int64_t)(cc_soc_sw - cl->init_cc_soc_sw) * 100,
		div64_s64((int64_t)(cc_soc_sw - cl->init_cc_soc_sw) * 10000,
			cl->cc_soc_max);
			cl->cc_soc_max);


	/* If the delta is < 50%, then skip processing full data */
	/* If the delta is < 50%, then skip processing full data */
	if (cc_soc_delta_pct < 50) {
	if (cc_soc_delta_centi_pct < 5000) {
		pr_err("cc_soc_delta_pct: %d\n", cc_soc_delta_pct);
		pr_err("cc_soc_delta_centi_pct: %d\n", cc_soc_delta_centi_pct);
		return -ERANGE;
		return -ERANGE;
	}
	}


	delta_cap_uah = div64_s64(cl->learned_cap_uah * cc_soc_delta_pct, 100);
	delta_cap_uah = div64_s64(cl->learned_cap_uah * cc_soc_delta_centi_pct,
				 10000);
	cl->final_cap_uah = cl->init_cap_uah + delta_cap_uah;
	cl->final_cap_uah = cl->init_cap_uah + delta_cap_uah;
	pr_debug("Current cc_soc=%d cc_soc_delta_pct=%d total_cap_uah=%lld\n",
	pr_debug("Current cc_soc=%d cc_soc_delta_centi_pct=%d total_cap_uah=%lld\n",
		cc_soc_sw, cc_soc_delta_pct, cl->final_cap_uah);
		cc_soc_sw, cc_soc_delta_centi_pct, cl->final_cap_uah);
	return 0;
	return 0;
}
}


@@ -401,8 +403,8 @@ static int cap_learning_begin(struct cap_learning *cl, u32 batt_soc)
		return -EINVAL;
		return -EINVAL;
	}
	}


	cl->init_cap_uah = div64_s64(cl->learned_cap_uah * batt_soc_msb,
	cl->init_cap_uah = div64_s64(cl->learned_cap_uah * batt_soc,
					FULL_SOC_RAW);
					FULL_BATT_SOC);


	if (cl->prime_cc_soc) {
	if (cl->prime_cc_soc) {
		/*
		/*