Commit 60432176 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Greg Kroah-Hartman

staging: 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: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/1cf4f26540e65ffbb561c7d52e53f6be5bd63ac4.1597647359.git.mchehab+huawei@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c22aeb94
...@@ -86,8 +86,8 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) ...@@ -86,8 +86,8 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev)
/* set enable register */ /* set enable register */
hi6421_spmi_pmic_rmw(pmic, rdev->desc->enable_reg, 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", dev_dbg(&rdev->dev, "%s: enable_reg=0x%x, enable_mask=0x%x\n",
__func__, rdev->desc->enable_reg, __func__, rdev->desc->enable_reg,
rdev->desc->enable_mask); rdev->desc->enable_mask);
...@@ -109,64 +109,49 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) ...@@ -109,64 +109,49 @@ static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev)
return 0; 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 hi6421v600_regulator *sreg = rdev_get_drvdata(rdev);
struct hi6421_spmi_pmic *pmic = sreg->pmic; struct hi6421_spmi_pmic *pmic = sreg->pmic;
u32 reg_val, selector; u32 reg_val, selector;
int vol;
/* get voltage selector */ /* get voltage selector */
reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->vsel_reg); 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, dev_dbg(&rdev->dev,
"%s: vsel_reg=0x%x, val=0x%x, entry=0x%x, voltage=%d mV\n", "%s: vsel_reg=0x%x, value=0x%x, entry=0x%x, voltage=%d mV\n",
__func__, rdev->desc->vsel_reg, reg_val, selector, vol/ 1000); __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, static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev,
int min_uV, int max_uV, unsigned int *selector) unsigned int selector)
{ {
struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev);
struct hi6421_spmi_pmic *pmic = sreg->pmic; struct hi6421_spmi_pmic *pmic = sreg->pmic;
u32 vsel; u32 reg_val;
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;
}
/* unlikely to happen. sanity test done by regulator core */ /* 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; return -EINVAL;
*selector = vsel; reg_val = selector << (ffs(rdev->desc->vsel_mask) - 1);
/* set voltage selector */ /* set voltage selector */
hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg, hi6421_spmi_pmic_rmw(pmic, rdev->desc->vsel_reg,
rdev->desc->vsel_mask, rdev->desc->vsel_mask, reg_val);
vsel << (ffs(rdev->desc->vsel_mask) - 1));
dev_dbg(&rdev->dev, 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__, __func__,
rdev->desc->vsel_reg, rdev->desc->vsel_reg, rdev->desc->vsel_mask, reg_val,
rdev->desc->vsel_mask, rdev->desc->ops->list_voltage(rdev, selector) / 1000);
vsel << (ffs(rdev->desc->vsel_mask) - 1), uV / 1000);
return ret; return 0;
} }
static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev)
...@@ -315,8 +300,9 @@ static struct regulator_ops hi6421_spmi_ldo_rops = { ...@@ -315,8 +300,9 @@ static struct regulator_ops hi6421_spmi_ldo_rops = {
.enable = hi6421_spmi_regulator_enable, .enable = hi6421_spmi_regulator_enable,
.disable = hi6421_spmi_regulator_disable, .disable = hi6421_spmi_regulator_disable,
.list_voltage = regulator_list_voltage_table, .list_voltage = regulator_list_voltage_table,
.get_voltage = hi6421_spmi_regulator_get_voltage, .map_voltage = regulator_map_voltage_iterate,
.set_voltage = hi6421_spmi_regulator_set_voltage, .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, .get_mode = hi6421_spmi_regulator_get_mode,
.set_mode = hi6421_spmi_regulator_set_mode, .set_mode = hi6421_spmi_regulator_set_mode,
.get_optimum_mode = hi6421_spmi_regulator_get_optimum_mode, .get_optimum_mode = hi6421_spmi_regulator_get_optimum_mode,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment