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

Commit b3702971 authored by Osvaldo Banuelos's avatar Osvaldo Banuelos Committed by Gerrit - the friendly Code Review server
Browse files

regulator: spm-regulator: selectively use SPM API to get regulator voltage



msm_spm_get_vdd() may be used to determine the current regulator
voltage when SPM isn't bypassed. This function call has a lower
latency compared to the SPMI read interface used to find the
regulator voltage at the PMIC. Enable usage of this API when AVS
regulator is in use and fall back to SPMI read if the API is
unavailable.

Change-Id: I4631132af92a5dda10132e05ccb342bbb40faeed
Signed-off-by: default avatarOsvaldo Banuelos <osvaldob@codeaurora.org>
parent 07c0864f
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -174,21 +174,47 @@ static int qpnp_fts2_set_mode(struct spm_vreg *vreg, u8 mode)
	return rc;
}

static int _spm_regulator_set_voltage(struct regulator_dev *rdev)
static int spm_regulator_get_voltage(struct regulator_dev *rdev)
{
	struct spm_vreg *vreg = rdev_get_drvdata(rdev);
	bool spm_failed = false;
	int rc = 0;
	u8 reg;
	int vlevel, rc;

	if (spm_regulator_using_avs(vreg)) {
		vlevel = msm_spm_get_vdd(vreg->cpu_num);

		if (IS_ERR_VALUE(vlevel)) {
			pr_debug("%s: msm_spm_get_vdd failed, rc=%d; falling back on SPMI read\n",
				vreg->rdesc.name, vlevel);

			rc = qpnp_smps_read_voltage(vreg);
			if (rc) {
				pr_err("%s: voltage read failed, rc=%d\n",
				       vreg->rdesc.name, rc);
				return rc;
			}

			return vreg->last_set_uV;
		}

		vreg->last_set_vlevel = vlevel;
		vreg->last_set_uV = vlevel * vreg->range->step_uV
			+ vreg->range->min_uV;
		return vreg->last_set_uV;
	} else {
		return vreg->uV;
	}
};

static int _spm_regulator_set_voltage(struct regulator_dev *rdev)
{
	struct spm_vreg *vreg = rdev_get_drvdata(rdev);
	bool spm_failed = false;
	int rc = 0;
	u8 reg;

	rc = spm_regulator_get_voltage(rdev);
	if (IS_ERR_VALUE(rc))
		return rc;

	if (vreg->vlevel == vreg->last_set_vlevel)
		return 0;
@@ -297,25 +323,6 @@ static int spm_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
	return _spm_regulator_set_voltage(rdev);
}

static int spm_regulator_get_voltage(struct regulator_dev *rdev)
{
	struct spm_vreg *vreg = rdev_get_drvdata(rdev);
	int rc;

	if (spm_regulator_using_avs(vreg)) {
		rc = qpnp_smps_read_voltage(vreg);
		if (rc) {
			pr_err("%s: voltage read failed, rc=%d\n",
				vreg->rdesc.name, rc);
			return rc;
		}

		return vreg->last_set_uV;
	} else {
		return vreg->uV;
	}
}

static int spm_regulator_list_voltage(struct regulator_dev *rdev,
					unsigned selector)
{