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

Commit 491c847c authored by Harry Yang's avatar Harry Yang
Browse files

qpnp-smb2: expose forcing fcc/fv values via battery psy



CURRENT_QNOVO and VOLTAGE_QNOVO allow "forcing" fast charge
current and float voltage value, implemented around votable
such that one can have previlige in FCC and FV voting.

CRs-Fixed: 2004173
Change-Id: I2df30220aa89e15c4bace9980990f227218a5bdd
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 5e55ca18
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -298,6 +298,19 @@ static int pl_fcc_vote_callback(struct votable *votable, void *data,
	if (!chip->main_psy)
		return 0;

	if (chip->batt_psy) {
		rc = power_supply_get_property(chip->batt_psy,
			POWER_SUPPLY_PROP_CURRENT_QNOVO,
			&pval);
		if (rc < 0) {
			pr_err("Couldn't get qnovo fcc, rc=%d\n", rc);
			return rc;
		}

		if (pval.intval != -EINVAL)
			total_fcc_ua = pval.intval;
	}

	if (chip->pl_mode == POWER_SUPPLY_PARALLEL_NONE
	    || get_effective_result_locked(chip->pl_disable_votable)) {
		pval.intval = total_fcc_ua;
@@ -343,6 +356,7 @@ static int pl_fv_vote_callback(struct votable *votable, void *data,
	struct pl_data *chip = data;
	union power_supply_propval pval = {0, };
	int rc = 0;
	int effective_fv_uv = fv_uv;

	if (fv_uv < 0)
		return 0;
@@ -350,7 +364,21 @@ static int pl_fv_vote_callback(struct votable *votable, void *data,
	if (!chip->main_psy)
		return 0;

	pval.intval = fv_uv;
	if (chip->batt_psy) {
		rc = power_supply_get_property(chip->batt_psy,
			POWER_SUPPLY_PROP_VOLTAGE_QNOVO,
			&pval);
		if (rc < 0) {
			pr_err("Couldn't get qnovo fv, rc=%d\n", rc);
			return rc;
		}

		if (pval.intval != -EINVAL)
			effective_fv_uv = pval.intval;
	}

	pval.intval = effective_fv_uv;

	rc = power_supply_set_property(chip->main_psy,
			POWER_SUPPLY_PROP_VOLTAGE_MAX, &pval);
	if (rc < 0) {
@@ -359,7 +387,7 @@ static int pl_fv_vote_callback(struct votable *votable, void *data,
	}

	if (chip->pl_mode != POWER_SUPPLY_PARALLEL_NONE) {
		pval.intval = fv_uv + PARALLEL_FLOAT_VOLTAGE_DELTA_UV;
		pval.intval += PARALLEL_FLOAT_VOLTAGE_DELTA_UV;
		rc = power_supply_set_property(chip->pl_psy,
				POWER_SUPPLY_PROP_VOLTAGE_MAX, &pval);
		if (rc < 0) {
@@ -514,9 +542,9 @@ static bool is_parallel_available(struct pl_data *chip)
		return false;
	}
	/*
	 * Note that pl_mode only be udpated to anything other than a _NONE
	 * Note that pl_mode will be updated to anything other than a _NONE
	 * only after pl_psy is found. IOW pl_mode != _NONE implies that
	 * pl_psy is present and valid
	 * pl_psy is present and valid.
	 */
	chip->pl_mode = pval.intval;
	vote(chip->pl_disable_votable, PARALLEL_PSY_VOTER, false, 0);
+14 −0
Original line number Diff line number Diff line
@@ -894,9 +894,15 @@ static int smb2_batt_get_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_VOLTAGE_MAX:
		val->intval = get_client_vote(chg->fv_votable, DEFAULT_VOTER);
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_QNOVO:
		val->intval = chg->qnovo_fv_uv;
		break;
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		rc = smblib_get_prop_batt_current_now(chg, val);
		break;
	case POWER_SUPPLY_PROP_CURRENT_QNOVO:
		val->intval = chg->qnovo_fcc_ua;
		break;
	case POWER_SUPPLY_PROP_TEMP:
		rc = smblib_get_prop_batt_temp(chg, val);
		break;
@@ -953,6 +959,14 @@ static int smb2_batt_set_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_VOLTAGE_MAX:
		vote(chg->fv_votable, DEFAULT_VOTER, true, val->intval);
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_QNOVO:
		chg->qnovo_fv_uv = val->intval;
		rc = rerun_election(chg->fv_votable);
		break;
	case POWER_SUPPLY_PROP_CURRENT_QNOVO:
		chg->qnovo_fcc_ua = val->intval;
		rc = rerun_election(chg->fcc_votable);
		break;
	case POWER_SUPPLY_PROP_SET_SHIP_MODE:
		/* Not in ship mode as long as the device is active */
		if (!val->intval)
+2 −0
Original line number Diff line number Diff line
@@ -3891,6 +3891,8 @@ int smblib_init(struct smb_charger *chg)

	switch (chg->mode) {
	case PARALLEL_MASTER:
		chg->qnovo_fcc_ua = -EINVAL;
		chg->qnovo_fv_uv = -EINVAL;
		rc = smblib_create_votables(chg);
		if (rc < 0) {
			smblib_err(chg, "Couldn't create votables rc=%d\n",
+4 −0
Original line number Diff line number Diff line
@@ -257,6 +257,10 @@ struct smb_charger {
	bool			usb_ever_removed;

	int			icl_reduction_ua;

	/* qnovo */
	int			qnovo_fcc_ua;
	int			qnovo_fv_uv;
};

int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);