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

Commit ff98dbb5 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: qpnp-fg-gen4/qg: Add TTF_VALID param for valid TTF/TTE reporting"

parents a589362a 4f73e8cf
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -1068,11 +1068,33 @@ static int get_time_to_full_locked(struct ttf *ttf, int *val)
		i, soc_per_step, msoc_this_step, msoc_next_step,
		ibatt_this_step, t_predicted_this_step, ttf_slope,
		t_predicted_cv, t_predicted = 0, charge_type = 0, i_step,
		float_volt_uv = 0;
		float_volt_uv = 0, valid = 0, charge_status = 0;
	int multiplier, curr_window = 0, pbatt_avg;
	bool power_approx = false;
	s64 delta_ms;

	rc = ttf->get_ttf_param(ttf->data, TTF_TTE_VALID, &valid);
	if (rc < 0) {
		pr_err("failed to get ttf_tte_valid rc=%d\n", rc);
		return rc;
	}

	if (!valid) {
		*val = -1;
		return 0;
	}

	rc =  ttf->get_ttf_param(ttf->data, TTF_CHG_STATUS, &charge_status);
	if (rc < 0) {
		pr_err("failed to get charge-status rc=%d\n", rc);
		return rc;
	}

	if (charge_status != POWER_SUPPLY_STATUS_CHARGING) {
		*val = -1;
		return 0;
	}

	rc = ttf->get_ttf_param(ttf->data, TTF_MSOC, &msoc);
	if (rc < 0) {
		pr_err("failed to get msoc rc=%d\n", rc);
@@ -1469,7 +1491,30 @@ static void ttf_work(struct work_struct *work)
 */
int ttf_get_time_to_empty(struct ttf *ttf, int *val)
{
	int rc, ibatt_avg, msoc, act_cap_mah, divisor;
	int rc, ibatt_avg, msoc, act_cap_mah, divisor, valid = 0,
		charge_status = 0;

	rc = ttf->get_ttf_param(ttf->data, TTF_TTE_VALID, &valid);
	if (rc < 0) {
		pr_err("failed to get ttf_tte_valid rc=%d\n", rc);
		return rc;
	}

	if (!valid) {
		*val = -1;
		return 0;
	}

	rc =  ttf->get_ttf_param(ttf->data, TTF_CHG_STATUS, &charge_status);
	if (rc < 0) {
		pr_err("failed to get charge-status rc=%d\n", rc);
		return rc;
	}

	if (charge_status == POWER_SUPPLY_STATUS_CHARGING) {
		*val = -1;
		return 0;
	}

	rc = ttf_circ_buf_median(&ttf->ibatt, &ibatt_avg);
	if (rc < 0) {
@@ -1502,6 +1547,10 @@ int ttf_get_time_to_empty(struct ttf *ttf, int *val)
	divisor = ibatt_avg * divisor / 100;
	divisor = max(100, divisor);
	*val = act_cap_mah * msoc * HOURS_TO_SECONDS / divisor;

	pr_debug("TTF: ibatt_avg=%d msoc=%d act_cap_mah=%d TTE=%d\n",
			ibatt_avg, msoc, act_cap_mah, *val);

	return 0;
}

+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ enum ttf_param {
	TTF_VFLOAT,
	TTF_CHG_TYPE,
	TTF_CHG_STATUS,
	TTF_TTE_VALID,
};

struct ttf_circ_buf {
+5 −2
Original line number Diff line number Diff line
@@ -1197,10 +1197,13 @@ static int fg_gen4_get_ttf_param(void *data, enum ttf_param param, int *val)
		return -ENODEV;

	fg = &chip->fg;
	if (fg->battery_missing)
		return -EPERM;

	switch (param) {
	case TTF_TTE_VALID:
		*val = 1;
		if (fg->battery_missing || is_debug_batt_id(fg))
			*val = 0;
		break;
	case TTF_MSOC:
		rc = fg_gen4_get_prop_capacity(fg, val);
		break;
+5 −3
Original line number Diff line number Diff line
@@ -1828,10 +1828,12 @@ static int qg_get_ttf_param(void *data, enum ttf_param param, int *val)
	if (!chip)
		return -ENODEV;

	if (chip->battery_missing || !chip->profile_loaded)
		return -ENODEV;

	switch (param) {
	case TTF_TTE_VALID:
		*val = 1;
		if (chip->battery_missing || is_debug_batt_id(chip))
			*val = 0;
		break;
	case TTF_MSOC:
		rc = qg_get_battery_capacity(chip, val);
		break;