Commit 2f4bb1fa authored by David Lechner's avatar David Lechner Committed by Mark Brown

iio: frequency: admv1013: Use devm_regulator_get_enable_read_voltage()

We can reduce boilerplate code by using
devm_regulator_get_enable_read_voltage().

The common mode voltage is now passed as a parameter in the init
functions so we can avoid adding a state member that is only used
during init.
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarDavid Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20240429-regulator-get-enable-get-votlage-v2-5-b1f11ab766c1@baylibre.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 41b94bc6
...@@ -95,7 +95,6 @@ struct admv1013_state { ...@@ -95,7 +95,6 @@ struct admv1013_state {
struct clk *clkin; struct clk *clkin;
/* Protect against concurrent accesses to the device and to data */ /* Protect against concurrent accesses to the device and to data */
struct mutex lock; struct mutex lock;
struct regulator *reg;
struct notifier_block nb; struct notifier_block nb;
unsigned int input_mode; unsigned int input_mode;
unsigned int quad_se_mode; unsigned int quad_se_mode;
...@@ -342,14 +341,9 @@ static int admv1013_update_quad_filters(struct admv1013_state *st) ...@@ -342,14 +341,9 @@ static int admv1013_update_quad_filters(struct admv1013_state *st)
FIELD_PREP(ADMV1013_QUAD_FILTERS_MSK, filt_raw)); FIELD_PREP(ADMV1013_QUAD_FILTERS_MSK, filt_raw));
} }
static int admv1013_update_mixer_vgate(struct admv1013_state *st) static int admv1013_update_mixer_vgate(struct admv1013_state *st, int vcm)
{ {
unsigned int mixer_vgate; unsigned int mixer_vgate;
int vcm;
vcm = regulator_get_voltage(st->reg);
if (vcm < 0)
return vcm;
if (vcm <= 1800000) if (vcm <= 1800000)
mixer_vgate = (2389 * vcm / 1000000 + 8100) / 100; mixer_vgate = (2389 * vcm / 1000000 + 8100) / 100;
...@@ -443,7 +437,7 @@ static const struct iio_chan_spec admv1013_channels[] = { ...@@ -443,7 +437,7 @@ static const struct iio_chan_spec admv1013_channels[] = {
ADMV1013_CHAN_CALIB(1, Q), ADMV1013_CHAN_CALIB(1, Q),
}; };
static int admv1013_init(struct admv1013_state *st) static int admv1013_init(struct admv1013_state *st, int vcm_uv)
{ {
int ret; int ret;
unsigned int data; unsigned int data;
...@@ -483,7 +477,7 @@ static int admv1013_init(struct admv1013_state *st) ...@@ -483,7 +477,7 @@ static int admv1013_init(struct admv1013_state *st)
if (ret) if (ret)
return ret; return ret;
ret = admv1013_update_mixer_vgate(st); ret = admv1013_update_mixer_vgate(st, vcm_uv);
if (ret) if (ret)
return ret; return ret;
...@@ -498,11 +492,6 @@ static int admv1013_init(struct admv1013_state *st) ...@@ -498,11 +492,6 @@ static int admv1013_init(struct admv1013_state *st)
st->input_mode); st->input_mode);
} }
static void admv1013_reg_disable(void *data)
{
regulator_disable(data);
}
static void admv1013_powerdown(void *data) static void admv1013_powerdown(void *data)
{ {
unsigned int enable_reg, enable_reg_msk; unsigned int enable_reg, enable_reg_msk;
...@@ -557,11 +546,6 @@ static int admv1013_properties_parse(struct admv1013_state *st) ...@@ -557,11 +546,6 @@ static int admv1013_properties_parse(struct admv1013_state *st)
else else
return -EINVAL; return -EINVAL;
st->reg = devm_regulator_get(&spi->dev, "vcm");
if (IS_ERR(st->reg))
return dev_err_probe(&spi->dev, PTR_ERR(st->reg),
"failed to get the common-mode voltage\n");
ret = devm_regulator_bulk_get_enable(&st->spi->dev, ret = devm_regulator_bulk_get_enable(&st->spi->dev,
ARRAY_SIZE(admv1013_vcc_regs), ARRAY_SIZE(admv1013_vcc_regs),
admv1013_vcc_regs); admv1013_vcc_regs);
...@@ -578,7 +562,7 @@ static int admv1013_probe(struct spi_device *spi) ...@@ -578,7 +562,7 @@ static int admv1013_probe(struct spi_device *spi)
{ {
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct admv1013_state *st; struct admv1013_state *st;
int ret; int ret, vcm_uv;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev) if (!indio_dev)
...@@ -597,16 +581,12 @@ static int admv1013_probe(struct spi_device *spi) ...@@ -597,16 +581,12 @@ static int admv1013_probe(struct spi_device *spi)
if (ret) if (ret)
return ret; return ret;
ret = regulator_enable(st->reg); ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcm");
if (ret) { if (ret < 0)
dev_err(&spi->dev, "Failed to enable specified Common-Mode Voltage!\n"); return dev_err_probe(&spi->dev, ret,
return ret; "failed to get the common-mode voltage\n");
}
ret = devm_add_action_or_reset(&spi->dev, admv1013_reg_disable, vcm_uv = ret;
st->reg);
if (ret)
return ret;
st->clkin = devm_clk_get_enabled(&spi->dev, "lo_in"); st->clkin = devm_clk_get_enabled(&spi->dev, "lo_in");
if (IS_ERR(st->clkin)) if (IS_ERR(st->clkin))
...@@ -620,7 +600,7 @@ static int admv1013_probe(struct spi_device *spi) ...@@ -620,7 +600,7 @@ static int admv1013_probe(struct spi_device *spi)
mutex_init(&st->lock); mutex_init(&st->lock);
ret = admv1013_init(st); ret = admv1013_init(st, vcm_uv);
if (ret) { if (ret) {
dev_err(&spi->dev, "admv1013 init failed\n"); dev_err(&spi->dev, "admv1013 init failed\n");
return ret; return ret;
......
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