regulator: fan53555: use set_ramp_delay to set the ramp up slew rate

The regulator constraints already provide a field for the ramp_delay, so
there is no need to set this manually. Therefore implement the set_ramp_delay
callback and convert the pdata value to the constraint value if necessary.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Heiko Stuebner 2014-09-16 17:54:01 +02:00 committed by Mark Brown
parent 3415d60113
commit dd7e71fbee
1 changed files with 42 additions and 11 deletions

View File

@ -135,6 +135,38 @@ static unsigned int fan53555_get_mode(struct regulator_dev *rdev)
return REGULATOR_MODE_NORMAL;
}
static int slew_rates[] = {
64000,
32000,
16000,
8000,
4000,
2000,
1000,
500,
};
static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp)
{
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
int regval = -1, i;
for (i = 0; i < ARRAY_SIZE(slew_rates); i++) {
if (ramp <= slew_rates[i])
regval = i;
else
break;
}
if (regval < 0) {
dev_err(di->dev, "unsupported ramp value %d\n", ramp);
return -EINVAL;
}
return regmap_update_bits(di->regmap, FAN53555_CONTROL,
CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT);
}
static struct regulator_ops fan53555_regulator_ops = {
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
@ -146,6 +178,7 @@ static struct regulator_ops fan53555_regulator_ops = {
.is_enabled = regulator_is_enabled_regmap,
.set_mode = fan53555_set_mode,
.get_mode = fan53555_get_mode,
.set_ramp_delay = fan53555_set_ramp,
};
/* For 00,01,03,05 options:
@ -156,8 +189,6 @@ static struct regulator_ops fan53555_regulator_ops = {
static int fan53555_device_setup(struct fan53555_device_info *di,
struct fan53555_platform_data *pdata)
{
unsigned int reg, data, mask;
/* Setup voltage control register */
switch (pdata->sleep_vsel_id) {
case FAN53555_VSEL_ID_0:
@ -190,15 +221,8 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
"Chip ID[%d]\n not supported!\n", di->chip_id);
return -EINVAL;
}
/* Init slew rate */
if (pdata->slew_rate & 0x7)
di->slew_rate = pdata->slew_rate;
else
di->slew_rate = FAN53555_SLEW_RATE_64MV;
reg = FAN53555_CONTROL;
data = di->slew_rate << CTL_SLEW_SHIFT;
mask = CTL_SLEW_MASK;
return regmap_update_bits(di->regmap, reg, mask, data);
return 0;
}
static int fan53555_regulator_register(struct fan53555_device_info *di,
@ -248,6 +272,13 @@ static int fan53555_regulator_probe(struct i2c_client *client,
if (!di)
return -ENOMEM;
/* if no ramp constraint set, get the pdata ramp_delay */
if (!di->regulator->constraints.ramp_delay) {
int slew_idx = (pdata->slew_rate & 0x7) ? pdata->slew_rate : 0;
di->regulator->constraints.ramp_delay = slew_rates[slew_idx];
}
di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
if (IS_ERR(di->regmap)) {
dev_err(&client->dev, "Failed to allocate regmap!\n");