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

Commit 89556e9d authored by Guru Das Srinagesh's avatar Guru Das Srinagesh
Browse files

power: step-chg-jeita: Clip voltages higher than max allowed



Currently, if the current battery voltage is out of bounds of the Step
Charge ranges, the step charging voter is disabled. In tapered charging
situations where Vbatt sometimes exceeds the highest allowed voltage,
this leads to a sudden change in the charging current due to the MIN
voter mechanism selecting the next minimum value out of all the votes,
which is undesirable.

Fix this by choosing highest possible range value for battery voltage
when the observed value exceeds the range of acceptable values. This
results in the step charge voter remaining enabled and retaining its
vote, which, in turn, ensures that the charging current remains the same
even when the battery voltage exceeds the maximum allowed value
(assuming battery temperature is unchanged).

The current behaviour is retained for those situations where the
observed value is lesser than the minimum acceptable range value.

Also enable this behaviour for JEITA functionality as well.

CRs-Fixed: 2255514
Change-Id: I3c33c76306f0290005fe9bbe0345c76b284c56e6
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent f0ee97bd
Loading
Loading
Loading
Loading
+34 −5
Original line number Diff line number Diff line
@@ -347,17 +347,46 @@ static int get_val(struct range_data *range, int hysteresis, int current_index,
	int i;

	*new_index = -EINVAL;
	/* first find the matching index without hysteresis */
	for (i = 0; i < MAX_STEP_CHG_ENTRIES; i++)

	/*
	 * If the threshold is lesser than the minimum allowed range,
	 * return -ENODATA.
	 */
	if (threshold < range[0].low_threshold)
		return -ENODATA;

	/* First try to find the matching index without hysteresis */
	for (i = 0; i < MAX_STEP_CHG_ENTRIES; i++) {
		if (!range[i].high_threshold && !range[i].low_threshold) {
			/* First invalid table entry; exit loop */
			break;
		}

		if (is_between(range[i].low_threshold,
			range[i].high_threshold, threshold)) {
			*new_index = i;
			*val = range[i].value;
			break;
		}
	}

	/* if nothing was found, return -ENODATA */
	if (*new_index == -EINVAL)
	/*
	 * If nothing was found, the threshold exceeds the max range for sure
	 * as the other case where it is lesser than the min range is handled
	 * at the very beginning of this function. Therefore, clip it to the
	 * max allowed range value, which is the one corresponding to the last
	 * valid entry in the battery profile data array.
	 */
	if (*new_index == -EINVAL) {
		if (i == 0) {
			/* Battery profile data array is completely invalid */
			return -ENODATA;
		}

		*new_index = (i - 1);
		*val = range[*new_index].value;
	}

	/*
	 * If we don't have a current_index return this
	 * newfound value. There is no hysterisis from out of range