mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-01 10:43:43 +00:00
iio: dac: ad5624r: use devm_regulator_get_enable_read_voltage()
Simplify the code by using devm_regulator_get_enable_read_voltage(). Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20241023-iio-regulator-refactor-round-5-v1-7-d0bd396b3f50@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
86ab529704
commit
a88a6cf4f7
@ -54,7 +54,6 @@ struct ad5624r_chip_info {
|
||||
struct ad5624r_state {
|
||||
struct spi_device *us;
|
||||
const struct ad5624r_chip_info *chip_info;
|
||||
struct regulator *reg;
|
||||
unsigned short vref_mv;
|
||||
unsigned pwr_down_mask;
|
||||
unsigned pwr_down_mode;
|
||||
|
@ -223,50 +223,27 @@ static int ad5624r_probe(struct spi_device *spi)
|
||||
{
|
||||
struct ad5624r_state *st;
|
||||
struct iio_dev *indio_dev;
|
||||
int ret, voltage_uv = 0;
|
||||
bool external_vref;
|
||||
int ret;
|
||||
|
||||
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
|
||||
if (!indio_dev)
|
||||
return -ENOMEM;
|
||||
st = iio_priv(indio_dev);
|
||||
st->reg = devm_regulator_get_optional(&spi->dev, "vref");
|
||||
if (!IS_ERR(st->reg)) {
|
||||
ret = regulator_enable(st->reg);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = regulator_get_voltage(st->reg);
|
||||
if (ret < 0)
|
||||
goto error_disable_reg;
|
||||
|
||||
voltage_uv = ret;
|
||||
} else {
|
||||
if (PTR_ERR(st->reg) != -ENODEV)
|
||||
return PTR_ERR(st->reg);
|
||||
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
|
||||
if (ret == -ENODEV)
|
||||
/* Backwards compatibility. This naming is not correct */
|
||||
st->reg = devm_regulator_get_optional(&spi->dev, "vcc");
|
||||
if (!IS_ERR(st->reg)) {
|
||||
ret = regulator_enable(st->reg);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc");
|
||||
if (ret < 0 && ret != -ENODEV)
|
||||
return ret;
|
||||
|
||||
ret = regulator_get_voltage(st->reg);
|
||||
if (ret < 0)
|
||||
goto error_disable_reg;
|
||||
|
||||
voltage_uv = ret;
|
||||
}
|
||||
}
|
||||
external_vref = ret != -ENODEV;
|
||||
st->vref_mv = external_vref ? ret / 1000 : st->chip_info->int_vref_mv;
|
||||
|
||||
spi_set_drvdata(spi, indio_dev);
|
||||
st->chip_info =
|
||||
&ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data];
|
||||
|
||||
if (voltage_uv)
|
||||
st->vref_mv = voltage_uv / 1000;
|
||||
else
|
||||
st->vref_mv = st->chip_info->int_vref_mv;
|
||||
|
||||
st->us = spi;
|
||||
|
||||
indio_dev->name = spi_get_device_id(spi)->name;
|
||||
@ -276,31 +253,18 @@ static int ad5624r_probe(struct spi_device *spi)
|
||||
indio_dev->num_channels = AD5624R_DAC_CHANNELS;
|
||||
|
||||
ret = ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0,
|
||||
!!voltage_uv, 16);
|
||||
external_vref, 16);
|
||||
if (ret)
|
||||
goto error_disable_reg;
|
||||
return ret;
|
||||
|
||||
ret = iio_device_register(indio_dev);
|
||||
if (ret)
|
||||
goto error_disable_reg;
|
||||
|
||||
return 0;
|
||||
|
||||
error_disable_reg:
|
||||
if (!IS_ERR(st->reg))
|
||||
regulator_disable(st->reg);
|
||||
|
||||
return ret;
|
||||
return iio_device_register(indio_dev);
|
||||
}
|
||||
|
||||
static void ad5624r_remove(struct spi_device *spi)
|
||||
{
|
||||
struct iio_dev *indio_dev = spi_get_drvdata(spi);
|
||||
struct ad5624r_state *st = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
if (!IS_ERR(st->reg))
|
||||
regulator_disable(st->reg);
|
||||
}
|
||||
|
||||
static const struct spi_device_id ad5624r_id[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user