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

Commit 6a4db4ee authored by Shyam Kumar Thella's avatar Shyam Kumar Thella
Browse files

power: fg-alg: Fix condition to schedule TTF work



In the TTF algorithm, if we exit ttf work due to charging status
change or due to error, the work is not rescheduled. Fix this by
always scheduling the ttf work as long as the charging is not
terminated or SOC reaches 100.

Change-Id: Iec20b0b22cb97b99ddd1fb3ec8099a9cad634d00
Signed-off-by: default avatarShyam Kumar Thella <sthella@codeaurora.org>
parent 7bd947be
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -1413,7 +1413,8 @@ static void ttf_work(struct work_struct *work)
{
	struct ttf *ttf = container_of(work,
				struct ttf, ttf_work.work);
	int rc, ibatt_now, vbatt_now, ttf_now, charge_status, ibatt_avg;
	int rc, ibatt_now, vbatt_now, ttf_now, charge_status, ibatt_avg,
		msoc = 0, charge_done;
	ktime_t ktime_now;

	mutex_lock(&ttf->lock);
@@ -1422,8 +1423,25 @@ static void ttf_work(struct work_struct *work)
		pr_err("failed to get charge_status rc=%d\n", rc);
		goto end_work;
	}
	if (charge_status != POWER_SUPPLY_STATUS_CHARGING &&
			charge_status != POWER_SUPPLY_STATUS_DISCHARGING)

	rc =  ttf->get_ttf_param(ttf->data, TTF_CHG_DONE, &charge_done);
	if (rc < 0) {
		pr_err("failed to get charge_done rc=%d\n", rc);
		goto end_work;
	}

	rc =  ttf->get_ttf_param(ttf->data, TTF_MSOC, &msoc);
	if (rc < 0) {
		pr_err("failed to get msoc, rc=%d\n", rc);
		goto end_work;
	}
	pr_debug("TTF: charge_status:%d charge_done:%d msoc:%d\n",
			charge_status, charge_done, msoc);
	/*
	 * Do not schedule ttf work when SOC is 100%
	 * or charge terminated
	 */
	if ((msoc == 100) || charge_done)
		goto end_work;

	rc =  ttf->get_ttf_param(ttf->data, TTF_IBAT, &ibatt_now);
+1 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ enum ttf_param {
	TTF_CHG_TYPE,
	TTF_CHG_STATUS,
	TTF_TTE_VALID,
	TTF_CHG_DONE,
};

struct ttf_circ_buf {
+3 −0
Original line number Diff line number Diff line
@@ -1273,6 +1273,9 @@ static int fg_gen4_get_ttf_param(void *data, enum ttf_param param, int *val)
	case TTF_CHG_STATUS:
		*val = fg->charge_status;
		break;
	case TTF_CHG_DONE:
		*val = fg->charge_done;
		break;
	default:
		pr_err_ratelimited("Unsupported parameter %d\n", param);
		rc = -EINVAL;
+3 −0
Original line number Diff line number Diff line
@@ -1880,6 +1880,9 @@ static int qg_get_ttf_param(void *data, enum ttf_param param, int *val)
	case TTF_CHG_STATUS:
		*val = chip->charge_status;
		break;
	case TTF_CHG_DONE:
		*val = chip->charge_done;
		break;
	default:
		pr_err("Unsupported property %d\n", param);
		rc = -EINVAL;