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

Commit 683a5c23 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg: add support to limit the learned capacity



For capacity learning algorithm, there is a requirement to cap
the learned capacity based on the specified limits. When the
capacity learning cycle completes, validate the current learning
capacity to see if it falls within the specified max/min limits.
If it goes above the max limit or goes below the min limit, then
cap the learned capacity to one of those limits as specified.

Add support for this requirement through the following device
tree properties.
- qcom,cl-max-limit-deciperc
- qcom,cl-min-limit-deciperc

CRs-Fixed: 978333
Change-Id: I9e42f6a4fd1d2e0e24d2e2a02379685463717b78
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent b174bcb2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -143,6 +143,14 @@ Parent node optional properties:
					battery voltage shadow and the current
					predicted voltage in uV to initiate
					capacity learning.
- qcom,cl-max-limit-deciperc:		The maximum percent that the capacity
					cannot go above during any capacity
					learning cycle. This property is in the
					unit of .1% increments.
- qcom,cl-min-limit-deciperc:		The minimum percent that the capacity
					cannot go below during any capacity
					learning cycle. This property is in the
					unit of .1% increments.
- qcom,capacity-estimation-on:		A boolean property to have the fuel
					gauge driver attempt to estimate the
					battery capacity using battery
+32 −0
Original line number Diff line number Diff line
@@ -148,6 +148,8 @@ struct fg_learning_data {
	int			min_temp;
	int			max_temp;
	int			vbat_est_thr_uv;
	int			max_cap_limit;
	int			min_cap_limit;
};

struct fg_rslow_data {
@@ -3205,6 +3207,32 @@ static void fg_cap_learning_post_process(struct fg_chip *chip)
		chip->learning_data.learned_cc_uah =
			chip->learning_data.cc_uah;

	if (chip->learning_data.max_cap_limit) {
		max_inc_val = (int64_t)chip->nom_cap_uah * (1000 +
				chip->learning_data.max_cap_limit);
		do_div(max_inc_val, 1000);
		if (chip->learning_data.cc_uah > max_inc_val) {
			if (fg_debug_mask & FG_AGING)
				pr_info("learning capacity %lld goes above max limit %lld\n",
					chip->learning_data.cc_uah,
					max_inc_val);
			chip->learning_data.learned_cc_uah = max_inc_val;
		}
	}

	if (chip->learning_data.min_cap_limit) {
		min_dec_val = (int64_t)chip->nom_cap_uah * (1000 -
				chip->learning_data.min_cap_limit);
		do_div(min_dec_val, 1000);
		if (chip->learning_data.cc_uah < min_dec_val) {
			if (fg_debug_mask & FG_AGING)
				pr_info("learning capacity %lld goes below min limit %lld\n",
					chip->learning_data.cc_uah,
					min_dec_val);
			chip->learning_data.learned_cc_uah = min_dec_val;
		}
	}

	fg_cap_learning_save_data(chip);
	if (fg_debug_mask & FG_AGING)
		pr_info("final cc_uah = %lld, learned capacity %lld -> %lld uah\n",
@@ -5558,6 +5586,10 @@ static int fg_of_init(struct fg_chip *chip)
			"cl-max-start-capacity", rc, 15);
	OF_READ_PROPERTY(chip->learning_data.vbat_est_thr_uv,
			"cl-vbat-est-thr-uv", rc, 40000);
	OF_READ_PROPERTY(chip->learning_data.max_cap_limit,
			"cl-max-limit-deciperc", rc, 0);
	OF_READ_PROPERTY(chip->learning_data.min_cap_limit,
			"cl-min-limit-deciperc", rc, 0);
	OF_READ_PROPERTY(chip->evaluation_current,
			"aging-eval-current-ma", rc,
			DEFAULT_EVALUATION_CURRENT_MA);