Commit 24c896f5 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: Convert lp3972 to set_voltage_sel

Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Acked-By: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent dd8e2314
...@@ -245,6 +245,11 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val) ...@@ -245,6 +245,11 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val)
static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
{ {
int ldo = rdev_get_id(dev) - LP3972_LDO1; int ldo = rdev_get_id(dev) - LP3972_LDO1;
if (index < LP3972_LDO_VOL_MIN_IDX(ldo) ||
index > LP3972_LDO_VOL_MAX_IDX(ldo))
return -EINVAL;
return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index];
} }
...@@ -292,34 +297,16 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev) ...@@ -292,34 +297,16 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev)
return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val];
} }
static int lp3972_ldo_set_voltage(struct regulator_dev *dev, static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned int selector)
unsigned int *selector)
{ {
struct lp3972 *lp3972 = rdev_get_drvdata(dev); struct lp3972 *lp3972 = rdev_get_drvdata(dev);
int ldo = rdev_get_id(dev) - LP3972_LDO1; int ldo = rdev_get_id(dev) - LP3972_LDO1;
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const int *vol_map = LP3972_LDO_VOL_VALUE_MAP(ldo);
u16 val;
int shift, ret; int shift, ret;
if (min_vol < vol_map[LP3972_LDO_VOL_MIN_IDX(ldo)] ||
min_vol > vol_map[LP3972_LDO_VOL_MAX_IDX(ldo)])
return -EINVAL;
for (val = LP3972_LDO_VOL_MIN_IDX(ldo);
val <= LP3972_LDO_VOL_MAX_IDX(ldo); val++)
if (vol_map[val] >= min_vol)
break;
if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol)
return -EINVAL;
*selector = val;
shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo);
ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo),
LP3972_LDO_VOL_MASK(ldo) << shift, val << shift); LP3972_LDO_VOL_MASK(ldo) << shift, selector << shift);
if (ret) if (ret)
return ret; return ret;
...@@ -355,12 +342,17 @@ static struct regulator_ops lp3972_ldo_ops = { ...@@ -355,12 +342,17 @@ static struct regulator_ops lp3972_ldo_ops = {
.enable = lp3972_ldo_enable, .enable = lp3972_ldo_enable,
.disable = lp3972_ldo_disable, .disable = lp3972_ldo_disable,
.get_voltage = lp3972_ldo_get_voltage, .get_voltage = lp3972_ldo_get_voltage,
.set_voltage = lp3972_ldo_set_voltage, .set_voltage_sel = lp3972_ldo_set_voltage_sel,
}; };
static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
{ {
int buck = rdev_get_id(dev) - LP3972_DCDC1; int buck = rdev_get_id(dev) - LP3972_DCDC1;
if (index < LP3972_BUCK_VOL_MIN_IDX(buck) ||
index > LP3972_BUCK_VOL_MAX_IDX(buck))
return -EINVAL;
return 1000 * buck_voltage_map[buck][index]; return 1000 * buck_voltage_map[buck][index];
} }
...@@ -419,34 +411,15 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev) ...@@ -419,34 +411,15 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev)
return val; return val;
} }
static int lp3972_dcdc_set_voltage(struct regulator_dev *dev, static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned int selector)
unsigned int *selector)
{ {
struct lp3972 *lp3972 = rdev_get_drvdata(dev); struct lp3972 *lp3972 = rdev_get_drvdata(dev);
int buck = rdev_get_id(dev) - LP3972_DCDC1; int buck = rdev_get_id(dev) - LP3972_DCDC1;
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const int *vol_map = buck_voltage_map[buck];
u16 val;
int ret; int ret;
if (min_vol < vol_map[LP3972_BUCK_VOL_MIN_IDX(buck)] ||
min_vol > vol_map[LP3972_BUCK_VOL_MAX_IDX(buck)])
return -EINVAL;
for (val = LP3972_BUCK_VOL_MIN_IDX(buck);
val <= LP3972_BUCK_VOL_MAX_IDX(buck); val++)
if (vol_map[val] >= min_vol)
break;
if (val > LP3972_BUCK_VOL_MAX_IDX(buck) ||
vol_map[val] > max_vol)
return -EINVAL;
*selector = val;
ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck),
LP3972_BUCK_VOL_MASK, val); LP3972_BUCK_VOL_MASK, selector);
if (ret) if (ret)
return ret; return ret;
...@@ -468,7 +441,7 @@ static struct regulator_ops lp3972_dcdc_ops = { ...@@ -468,7 +441,7 @@ static struct regulator_ops lp3972_dcdc_ops = {
.enable = lp3972_dcdc_enable, .enable = lp3972_dcdc_enable,
.disable = lp3972_dcdc_disable, .disable = lp3972_dcdc_disable,
.get_voltage = lp3972_dcdc_get_voltage, .get_voltage = lp3972_dcdc_get_voltage,
.set_voltage = lp3972_dcdc_set_voltage, .set_voltage_sel = lp3972_dcdc_set_voltage_sel,
}; };
static struct regulator_desc regulators[] = { static struct regulator_desc regulators[] = {
......
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