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

Commit 0a7e10d7 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

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

parents b822f847 72c43f46
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -803,9 +803,31 @@ 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,
		float_volt_uv = 0;
		float_volt_uv = 0, valid = 0, charge_status = 0;
	s64 delta_ms;

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

	if (!valid) {
		*val = -EINVAL;
		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 = -EINVAL;
		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);
@@ -1103,7 +1125,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_VALID, &valid);
	if (rc < 0) {
		pr_err("failed to get ttf_valid rc=%d\n", rc);
		return rc;
	}

	if (!valid) {
		*val = -EINVAL;
		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 = -EINVAL;
		return 0;
	}

	rc = ttf_circ_buf_median(&ttf->ibatt, &ibatt_avg);
	if (rc < 0) {
@@ -1136,6 +1181,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
@@ -76,6 +76,7 @@ enum ttf_param {
	TTF_VFLOAT,
	TTF_CHG_TYPE,
	TTF_CHG_STATUS,
	TTF_VALID,
};

struct ttf_circ_buf {
+9 −5
Original line number Diff line number Diff line
@@ -1614,10 +1614,10 @@ 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_VALID:
		*val = (!chip->battery_missing && chip->profile_loaded);
		break;
	case TTF_MSOC:
		rc = qg_get_battery_capacity(chip, val);
		break;
@@ -2526,6 +2526,7 @@ static int qg_setup_battery(struct qpnp_qg *chip)
		qg_dbg(chip, QG_DEBUG_PROFILE, "Battery Missing!\n");
		chip->battery_missing = true;
		chip->profile_loaded = false;
		chip->soc_reporting_ready = true;
	} else {
		/* battery present */
		rc = get_batt_id_ohm(chip, &chip->batt_id_ohm);
@@ -2534,13 +2535,16 @@ static int qg_setup_battery(struct qpnp_qg *chip)
			chip->profile_loaded = false;
		} else {
			rc = qg_load_battery_profile(chip);
			if (rc < 0)
			if (rc < 0) {
				pr_err("Failed to load battery-profile rc=%d\n",
								rc);
			else
				chip->profile_loaded = false;
				chip->soc_reporting_ready = true;
			} else {
				chip->profile_loaded = true;
			}
		}
	}

	qg_dbg(chip, QG_DEBUG_PROFILE, "battery_missing=%d batt_id_ohm=%d Ohm profile_loaded=%d profile=%s\n",
			chip->battery_missing, chip->batt_id_ohm,