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

Commit 8a3c043c authored by Harry Yang's avatar Harry Yang
Browse files

qcom: qnovo: Update fcc and fv through batt psy



To force qnovo FCC and FV through parallel framework
more conveniently, batt psy is bridged to replace votable
in qnovo driver. The two properties are -
POWER_SUPPLY_PROP_CURRENT_QNOVO and
POWER_SUPPLY_PROP_VOLTAGE_QNOVO.

CRs-Fixed: 2004173
Change-Id: I40b179fe5535e0209fcdbc1cb7e64cbfdf45a14b
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 491c847c
Loading
Loading
Loading
Loading
+51 −29
Original line number Diff line number Diff line
@@ -148,8 +148,6 @@ struct qnovo {
	struct work_struct	status_change_work;
	int			fv_uV_request;
	int			fcc_uA_request;
	struct votable		*fcc_max_votable;
	struct votable		*fv_votable;
};

static int debug_mask;
@@ -226,24 +224,62 @@ unlock:
	return rc;
}

static int qnovo_disable_cb(struct votable *votable, void *data, int disable,
					const char *client)
static bool is_batt_available(struct qnovo *chip)
{
	struct qnovo *chip = data;
	if (!chip->batt_psy)
		chip->batt_psy = power_supply_get_by_name("battery");

	if (!chip->batt_psy)
		return false;

	return true;
}

static int qnovo_batt_psy_update(struct qnovo *chip, bool disable)
{
	union power_supply_propval pval = {0};
	int rc = 0;

	if (disable) {
	if (!is_batt_available(chip))
		return -EINVAL;

	if (chip->fv_uV_request != -EINVAL) {
			if (chip->fv_votable)
				vote(chip->fv_votable, QNOVO_VOTER, false, 0);
		pval.intval = disable ? -EINVAL : chip->fv_uV_request;
		rc = power_supply_set_property(chip->batt_psy,
			POWER_SUPPLY_PROP_VOLTAGE_QNOVO,
			&pval);
		if (rc < 0) {
			pr_err("Couldn't set prop qnovo_fv rc = %d\n", rc);
			return -EINVAL;
		}
	}

	if (chip->fcc_uA_request != -EINVAL) {
			if (chip->fcc_max_votable)
				vote(chip->fcc_max_votable, QNOVO_VOTER,
						false, 0);
		pval.intval = disable ? -EINVAL : chip->fcc_uA_request;
		rc = power_supply_set_property(chip->batt_psy,
			POWER_SUPPLY_PROP_CURRENT_QNOVO,
			&pval);
		if (rc < 0) {
			pr_err("Couldn't set prop qnovo_fcc rc = %d\n", rc);
			return -EINVAL;
		}
	}

	return rc;
}

static int qnovo_disable_cb(struct votable *votable, void *data, int disable,
					const char *client)
{
	struct qnovo *chip = data;
	int rc = 0;

	if (disable) {
		rc = qnovo_batt_psy_update(chip, true);
		if (rc < 0)
			return rc;
	}

	rc = qnovo_masked_write(chip, QNOVO_PTRAIN_EN, QNOVO_PTRAIN_EN_BIT,
				 disable ? 0 : QNOVO_PTRAIN_EN_BIT);
	if (rc < 0) {
@@ -253,20 +289,9 @@ static int qnovo_disable_cb(struct votable *votable, void *data, int disable,
	}

	if (!disable) {
		if (chip->fv_uV_request != -EINVAL) {
			if (!chip->fv_votable)
				chip->fv_votable = find_votable("FV");
			if (chip->fv_votable)
				vote(chip->fv_votable, QNOVO_VOTER,
						true, chip->fv_uV_request);
		}
		if (chip->fcc_uA_request != -EINVAL) {
			if (!chip->fcc_max_votable)
				chip->fcc_max_votable = find_votable("FCC_MAX");
			if (chip->fcc_max_votable)
				vote(chip->fcc_max_votable, QNOVO_VOTER,
						true, chip->fcc_uA_request);
		}
		rc = qnovo_batt_psy_update(chip, false);
		if (rc < 0)
			return rc;
	}

	return rc;
@@ -979,10 +1004,7 @@ static ssize_t batt_prop_show(struct class *c, struct class_attribute *attr,
	int prop = params[i].start_addr;
	union power_supply_propval pval = {0};

	if (!chip->batt_psy)
		chip->batt_psy = power_supply_get_by_name("battery");

	if (!chip->batt_psy)
	if (!is_batt_available(chip))
		return -EINVAL;

	rc = power_supply_get_property(chip->batt_psy, prop, &pval);