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

Commit ad02e846 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown
Browse files

regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel



Don't adjust the selector in [get|set]_voltage_sel, fix it in list_voltage() instead.

For smps*(except smps10), the vsel reg-value and voltage mapping as below:

reg-value       volt (uV) ( Assume RANGE is x1 )
0               0
1               500000
2               500000
3               500000
4               500000
5               500000
6               500000 (0.49V + 1 * 0.01V) * RANGE
7               510000 (0.49V + 2 * 0.01V) * RANGE
8               520000 (0.49V + 3 * 0.01V) * RANGE
9               530000 (0.49V + 4 * 0.01V) * RANGE
....

The linear mapping is start from selector 6.

Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 9489e9dc
Loading
Loading
Loading
Loading
+14 −24
Original line number Original line Diff line number Diff line
@@ -309,19 +309,22 @@ static int palmas_list_voltage_smps(struct regulator_dev *dev,
	int id = rdev_get_id(dev);
	int id = rdev_get_id(dev);
	int mult = 1;
	int mult = 1;


	if (!selector)
		return 0;

	/* Read the multiplier set in VSEL register to return
	/* Read the multiplier set in VSEL register to return
	 * the correct voltage.
	 * the correct voltage.
	 */
	 */
	if (pmic->range[id])
	if (pmic->range[id])
		mult = 2;
		mult = 2;


	/* Voltage is (0.49V + (selector * 0.01V)) * RANGE
	if (selector == 0)
	 * as defined in data sheet. RANGE is either x1 or x2
		return 0;
	else if (selector < 6)
		return 500000 * mult;
	else
		/* Voltage is linear mapping starting from selector 6,
		 * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE
		 * RANGE is either x1 or x2
		 */
		 */
	return  (490000 + (selector * 10000)) * mult;
		return (490000 + ((selector - 5) * 10000)) * mult;
}
}


static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
@@ -338,15 +341,6 @@ static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)


	selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
	selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;


	/* Adjust selector to match list_voltage ranges */
	if ((selector > 0) && (selector < 6))
		selector = 6;
	if (!selector)
		selector = 5;
	if (selector > 121)
		selector = 121;
	selector -= 5;

	return selector;
	return selector;
}
}


@@ -355,19 +349,15 @@ static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
{
{
	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
	int id = rdev_get_id(dev);
	int id = rdev_get_id(dev);
	unsigned int reg = 0;
	unsigned int reg, addr;
	unsigned int addr;


	addr = palmas_regs_info[id].vsel_addr;
	addr = palmas_regs_info[id].vsel_addr;
	reg = selector;


	/* Make sure we don't change the value of RANGE */
	/* Make sure we don't change the value of RANGE */
	if (pmic->range[id])
	if (pmic->range[id])
		reg |= PALMAS_SMPS12_VOLTAGE_RANGE;
		reg |= PALMAS_SMPS12_VOLTAGE_RANGE;


	/* Adjust the linux selector into range used in VSEL register */
	if (selector)
		reg |= selector + 5;

	palmas_smps_write(pmic->palmas, addr, reg);
	palmas_smps_write(pmic->palmas, addr, reg);


	return 0;
	return 0;
@@ -386,11 +376,11 @@ static int palmas_map_voltage_smps(struct regulator_dev *rdev,
	if (pmic->range[id]) { /* RANGE is x2 */
	if (pmic->range[id]) { /* RANGE is x2 */
		if (min_uV < 1000000)
		if (min_uV < 1000000)
			min_uV = 1000000;
			min_uV = 1000000;
		ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
		ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6;
	} else {		/* RANGE is x1 */
	} else {		/* RANGE is x1 */
		if (min_uV < 500000)
		if (min_uV < 500000)
			min_uV = 500000;
			min_uV = 500000;
		ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
		ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6;
	}
	}


	/* Map back into a voltage to verify we're still in bounds */
	/* Map back into a voltage to verify we're still in bounds */