mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 09:13:38 +00:00
iio: dac: ad5770r: 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-11-d0bd396b3f50@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
7af0ad4dfa
commit
a3920a2318
@ -122,7 +122,6 @@ struct ad5770r_out_range {
|
||||
* struct ad5770r_state - driver instance specific data
|
||||
* @spi: spi_device
|
||||
* @regmap: regmap
|
||||
* @vref_reg: fixed regulator for reference configuration
|
||||
* @gpio_reset: gpio descriptor
|
||||
* @output_mode: array contains channels output ranges
|
||||
* @vref: reference value
|
||||
@ -134,7 +133,6 @@ struct ad5770r_out_range {
|
||||
struct ad5770r_state {
|
||||
struct spi_device *spi;
|
||||
struct regmap *regmap;
|
||||
struct regulator *vref_reg;
|
||||
struct gpio_desc *gpio_reset;
|
||||
struct ad5770r_out_range output_mode[AD5770R_MAX_CHANNELS];
|
||||
int vref;
|
||||
@ -591,13 +589,6 @@ static int ad5770r_init(struct ad5770r_state *st)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ad5770r_disable_regulator(void *data)
|
||||
{
|
||||
struct ad5770r_state *st = data;
|
||||
|
||||
regulator_disable(st->vref_reg);
|
||||
}
|
||||
|
||||
static int ad5770r_probe(struct spi_device *spi)
|
||||
{
|
||||
struct ad5770r_state *st;
|
||||
@ -622,34 +613,12 @@ static int ad5770r_probe(struct spi_device *spi)
|
||||
}
|
||||
st->regmap = regmap;
|
||||
|
||||
st->vref_reg = devm_regulator_get_optional(&spi->dev, "vref");
|
||||
if (!IS_ERR(st->vref_reg)) {
|
||||
ret = regulator_enable(st->vref_reg);
|
||||
if (ret) {
|
||||
dev_err(&spi->dev,
|
||||
"Failed to enable vref regulators: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
|
||||
if (ret < 0 && ret != -ENODEV)
|
||||
return dev_err_probe(&spi->dev, ret, "Failed to get vref voltage\n");
|
||||
|
||||
ret = devm_add_action_or_reset(&spi->dev,
|
||||
ad5770r_disable_regulator,
|
||||
st);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = regulator_get_voltage(st->vref_reg);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
st->vref = ret / 1000;
|
||||
} else {
|
||||
if (PTR_ERR(st->vref_reg) == -ENODEV) {
|
||||
st->vref = AD5770R_LOW_VREF_mV;
|
||||
st->internal_ref = true;
|
||||
} else {
|
||||
return PTR_ERR(st->vref_reg);
|
||||
}
|
||||
}
|
||||
st->internal_ref = ret == -ENODEV;
|
||||
st->vref = st->internal_ref ? AD5770R_LOW_VREF_mV : ret / 1000;
|
||||
|
||||
indio_dev->name = spi_get_device_id(spi)->name;
|
||||
indio_dev->info = &ad5770r_info;
|
||||
|
Loading…
Reference in New Issue
Block a user