[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <a3bd0953e0fbac188c60781a882b9e100ff5b5c4.1597160086.git.mchehab+huawei@kernel.org>
Date: Tue, 11 Aug 2020 17:41:51 +0200
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: unlisted-recipients:; (no To-header on input)
Cc: linuxarm@...wei.com, mauro.chehab@...wei.com,
Mauro Carvalho Chehab <mchehab+huawei@...nel.org>,
Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>, linux-kernel@...r.kernel.org
Subject: [PATCH 25/33] regulator: hi6421v600-regulator: convert to use get/set voltage_sel
As the supported LDOs on this driver are all using a selector,
change the implementation to use get_voltage_sel and
set_voltage_sel ops.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
---
drivers/regulator/hi6421v600-regulator.c | 58 +++++++++---------------
1 file changed, 22 insertions(+), 36 deletions(-)
diff --git a/drivers/regulator/hi6421v600-regulator.c b/drivers/regulator/hi6421v600-regulator.c
index f77ecea78597..abd1f43dd5ec 100644
--- a/drivers/regulator/hi6421v600-regulator.c
+++ b/drivers/regulator/hi6421v600-regulator.c
@@ -86,8 +86,8 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev)
/* set enable register */
hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg,
- rdev->desc->enable_mask,
- rdev->desc->enable_mask);
+ rdev->desc->enable_mask,
+ rdev->desc->enable_mask);
dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, enable_mask=0x%x\n",
__func__, rdev->desc->enable_reg,
rdev->desc->enable_mask);
@@ -109,64 +109,49 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev)
return 0;
}
-static int hi6421_spmi_regulator_get_voltage(struct regulator_dev *rdev)
+static int hi6421_spmi_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev);
struct hi6421_spmi_pmic *pmic = sreg->pmic;
u32 reg_val, selector;
- int vol;
/* get voltage selector */
reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->vsel_reg);
- selector = (reg_val & rdev->desc->vsel_mask) >>
- (ffs(rdev->desc->vsel_mask) - 1);
- vol = rdev->desc->ops->list_voltage(rdev, selector);
+ selector = (reg_val & rdev->desc->vsel_mask) >> (ffs(rdev->desc->vsel_mask) - 1);
dev_dbg(&rdev->dev,
- "%s: vsel_reg=0x%x, val=0x%x, entry=0x%x, voltage=%d mV\n",
- __func__, rdev->desc->vsel_reg, reg_val, selector, vol/ 1000);
+ "%s: vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n",
+ __func__, rdev->desc->vsel_reg, reg_val, selector,
+ rdev->desc->ops->list_voltage(rdev, selector) / 1000);
- return vol;
+ return selector;
}
-static int hi6421_spmi_regulator_set_voltage(struct regulator_dev *rdev,
- int min_uV, int max_uV, unsigned int *selector)
+static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev,
+ unsigned int selector)
{
struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev);
struct hi6421_spmi_pmic *pmic = sreg->pmic;
- u32 vsel;
- int uV, ret = 0;
-
- for (vsel = 0; vsel < rdev->desc->n_voltages; vsel++) {
- uV = rdev->desc->volt_table[vsel];
- dev_dbg(&rdev->dev,
- "%s: min %d, max %d, value[%u] = %d\n",
- __func__, min_uV, max_uV, vsel, uV);
-
- /* Break at the first in-range value */
- if (min_uV <= uV && uV <= max_uV)
- break;
- }
+ u32 reg_val;
/* unlikely to happen. sanity test done by regulator core */
- if (unlikely(vsel == rdev->desc->n_voltages))
+ if (unlikely(selector >= rdev->desc->n_voltages))
return -EINVAL;
- *selector = vsel;
+ reg_val = selector << (ffs(rdev->desc->vsel_mask) - 1);
+
/* set voltage selector */
hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg,
- rdev->desc->vsel_mask,
- vsel << (ffs(rdev->desc->vsel_mask) - 1));
+ rdev->desc->vsel_mask, reg_val);
dev_dbg(&rdev->dev,
- "%s: vsel_reg=0x%x, vsel_mask=0x%x, value=0x%x, voltage=%d mV\n",
+ "%s: vsel_reg=0x%x, mask=0x%x, value=0x%x, voltage=%d mV\n",
__func__,
- rdev->desc->vsel_reg,
- rdev->desc->vsel_mask,
- vsel << (ffs(rdev->desc->vsel_mask) - 1), uV / 1000);
+ rdev->desc->vsel_reg, rdev->desc->vsel_mask, reg_val,
+ rdev->desc->ops->list_voltage(rdev, selector) / 1000);
- return ret;
+ return 0;
}
static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev)
@@ -315,8 +300,9 @@ static struct regulator_ops hi6421_spmi_ldo_rops = {
.enable = hi6421_spmi_regulator_enable,
.disable = hi6421_spmi_regulator_disable,
.list_voltage = regulator_list_voltage_table,
- .get_voltage = hi6421_spmi_regulator_get_voltage,
- .set_voltage = hi6421_spmi_regulator_set_voltage,
+ .map_voltage = regulator_map_voltage_iterate,
+ .get_voltage_sel = hi6421_spmi_regulator_get_voltage_sel,
+ .set_voltage_sel = hi6421_spmi_regulator_set_voltage_sel,
.get_mode = hi6421_spmi_regulator_get_mode,
.set_mode = hi6421_spmi_regulator_set_mode,
.get_optimum_mode = hi6421_spmi_regulator_get_optimum_mode,
--
2.26.2
Powered by blists - more mailing lists