Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: dac: max5522: simplify probe with devm_regulator_get_enable_read_voltage()

Simplify probe by using devm_regulator_get_enable_read_voltage() to
get, enable and read the regulator voltage in a single call, caching
the value at probe time.

The reference voltage for this DAC is a fixed hardware configuration
that is not expected to change at runtime, so reading it once during
probe and caching the millivolt value is sufficient.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
65d887ff 93f60f67

+7 -15
+7 -15
drivers/iio/dac/max5522.c
··· 14 14 #include <linux/regulator/consumer.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/spi/spi.h> 17 + #include <linux/units.h> 17 18 18 19 #include <linux/iio/iio.h> 19 20 ··· 35 34 struct regmap *regmap; 36 35 const struct max5522_chip_info *chip_info; 37 36 unsigned short dac_cache[2]; 38 - struct regulator *vrefin_reg; 37 + int vref_mV; 39 38 }; 40 39 41 40 #define MAX5522_CHANNEL(chan) { \ ··· 80 79 int *val, int *val2, long info) 81 80 { 82 81 struct max5522_state *state = iio_priv(indio_dev); 83 - int ret; 84 82 85 83 switch (info) { 86 84 case IIO_CHAN_INFO_RAW: 87 85 *val = state->dac_cache[chan->channel]; 88 86 return IIO_VAL_INT; 89 87 case IIO_CHAN_INFO_SCALE: 90 - ret = regulator_get_voltage(state->vrefin_reg); 91 - if (ret < 0) 92 - return -EINVAL; 93 - *val = ret / 1000; 88 + *val = state->vref_mV; 94 89 *val2 = 10; 95 90 return IIO_VAL_FRACTIONAL_LOG2; 96 91 default: ··· 144 147 if (!state->chip_info) 145 148 return -EINVAL; 146 149 147 - state->vrefin_reg = devm_regulator_get(&spi->dev, "vrefin"); 148 - if (IS_ERR(state->vrefin_reg)) 149 - return dev_err_probe(&spi->dev, PTR_ERR(state->vrefin_reg), 150 - "Vrefin regulator not specified\n"); 151 - 152 - ret = regulator_enable(state->vrefin_reg); 153 - if (ret) { 150 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vrefin"); 151 + if (ret < 0) 154 152 return dev_err_probe(&spi->dev, ret, 155 - "Failed to enable vref regulators\n"); 156 - } 153 + "Failed to get vrefin regulator\n"); 154 + state->vref_mV = ret / (MICRO / MILLI); 157 155 158 156 state->regmap = devm_regmap_init_spi(spi, &max5522_regmap_config); 159 157