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

Commit 3a93f2a9 authored by Mark Brown's avatar Mark Brown Committed by Liam Girdwood
Browse files

regulator: Report actual configured voltage to set_voltage()



Change the interface used by set_voltage() to report the selected value
to the regulator core in terms of a selector used by list_voltage().
This allows the regulator core to know the voltage that was chosen
without having to do an explict get_voltage(), which would be much more
expensive as it will generally access hardware.

Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent 63cee946
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
}

static int pm8607_set_voltage(struct regulator_dev *rdev,
			      int min_uV, int max_uV)
			      int min_uV, int max_uV, unsigned *selector)
{
	struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
	uint8_t val, mask;
@@ -263,6 +263,7 @@ static int pm8607_set_voltage(struct regulator_dev *rdev,
	ret = choose_voltage(rdev, min_uV, max_uV);
	if (ret < 0)
		return -EINVAL;
	*selector = ret;
	val = (uint8_t)(ret << info->vol_shift);
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;

+4 −1
Original line number Diff line number Diff line
@@ -362,7 +362,8 @@ static int ab3100_get_best_voltage_index(struct regulator_dev *reg,
}

static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
					int min_uV, int max_uV)
					int min_uV, int max_uV,
					unsigned *selector)
{
	struct ab3100_regulator *abreg = reg->reg_data;
	u8 regval;
@@ -373,6 +374,8 @@ static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
	if (bestindex < 0)
		return bestindex;

	*selector = bestindex;

	err = abx500_get_register_interruptible(abreg->dev, 0,
						abreg->regreg, &regval);
	if (err) {
+4 −1
Original line number Diff line number Diff line
@@ -215,7 +215,8 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
}

static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
		int min_uV, int max_uV)
					int min_uV, int max_uV,
					unsigned *selector)
{
	int regulator_id, ret;
	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
@@ -232,6 +233,8 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
		return ret;
	}

	*selector = ret;

	/* set the registers for the request */
	ret = abx500_mask_and_set_register_interruptible(info->dev,
		info->voltage_bank, info->voltage_reg,
+12 −2
Original line number Diff line number Diff line
@@ -723,13 +723,16 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
	struct regulator_ops *ops = rdev->desc->ops;
	const char *name = rdev_get_name(rdev);
	int ret;
	unsigned selector;

	/* do we need to apply the constraint voltage */
	if (rdev->constraints->apply_uV &&
		rdev->constraints->min_uV == rdev->constraints->max_uV &&
		ops->set_voltage) {
		ret = ops->set_voltage(rdev,
			rdev->constraints->min_uV, rdev->constraints->max_uV);
				       rdev->constraints->min_uV,
				       rdev->constraints->max_uV,
				       &selector);
			if (ret < 0) {
				printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
				       __func__,
@@ -1625,6 +1628,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
{
	struct regulator_dev *rdev = regulator->rdev;
	int ret;
	unsigned selector;

	mutex_lock(&rdev->mutex);

@@ -1640,7 +1644,13 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
		goto out;
	regulator->min_uV = min_uV;
	regulator->max_uV = max_uV;
	ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV);

	ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, &selector);

	if (rdev->desc->ops->list_voltage)
		selector = rdev->desc->ops->list_voltage(rdev, selector);
	else
		selector = -1;

out:
	_notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
+12 −5
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ static inline int check_range(struct da903x_regulator_info *info,

/* DA9030/DA9034 common operations */
static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
				  int min_uV, int max_uV)
				  int min_uV, int max_uV, unsigned *selector)
{
	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *da9034_dev = to_da903x_dev(rdev);
@@ -119,6 +119,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
	}

	val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
	*selector = val;
	val <<= info->vol_shift;
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;

@@ -187,7 +188,8 @@ static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)

/* DA9030 specific operations */
static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
				       int min_uV, int max_uV)
				      int min_uV, int max_uV,
				      unsigned *selector)
{
	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *da903x_dev = to_da903x_dev(rdev);
@@ -200,6 +202,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
	}

	val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
	*selector = val;
	val <<= info->vol_shift;
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
	val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
@@ -214,7 +217,8 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
}

static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
				  int min_uV, int max_uV)
				    int min_uV, int max_uV,
				    unsigned *selector)
{
	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *da903x_dev = to_da903x_dev(rdev);
@@ -234,6 +238,7 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
		val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
	}

	*selector = val;
	val <<= info->vol_shift;
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;

@@ -263,7 +268,7 @@ static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)

/* DA9034 specific operations */
static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
				  int min_uV, int max_uV)
				  int min_uV, int max_uV, unsigned *selector)
{
	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *da9034_dev = to_da903x_dev(rdev);
@@ -276,6 +281,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
	}

	val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
	*selector = val;
	val <<= info->vol_shift;
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;

@@ -289,7 +295,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
}

static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
				    int min_uV, int max_uV)
				    int min_uV, int max_uV, unsigned *selector)
{
	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
	struct device *da9034_dev = to_da903x_dev(rdev);
@@ -302,6 +308,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,

	val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
	val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
	*selector = val;
	val <<= info->vol_shift;
	mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;

Loading