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: adc: ad7768-1: use devm_regulator_get_enable_read_voltage()

Use devm_regulator_get_enable_read_voltage() function as a standard and
concise way of reading the voltage from the regulator and keep the
regulator enabled. Replace the regulator descriptor with the direct
voltage value in the device struct.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
Link: https://patch.msgid.link/20250824041003.9727-1-Jonathan.Santos@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jonathan Santos and committed by
Jonathan Cameron
91812d38 681386fe

+8 -27
+8 -27
drivers/iio/adc/ad7768-1.c
··· 217 217 struct spi_device *spi; 218 218 struct regmap *regmap; 219 219 struct regmap *regmap24; 220 - struct regulator *vref; 220 + int vref_uv; 221 221 struct regulator_dev *vcm_rdev; 222 222 unsigned int vcm_output_sel; 223 223 struct clk *mclk; ··· 774 774 { 775 775 struct ad7768_state *st = iio_priv(indio_dev); 776 776 const struct iio_scan_type *scan_type; 777 - int scale_uv, ret, temp; 777 + int ret, temp; 778 778 779 779 scan_type = iio_get_current_scan_type(indio_dev, chan); 780 780 if (IS_ERR(scan_type)) ··· 795 795 return IIO_VAL_INT; 796 796 797 797 case IIO_CHAN_INFO_SCALE: 798 - scale_uv = regulator_get_voltage(st->vref); 799 - if (scale_uv < 0) 800 - return scale_uv; 801 - 802 - *val = (scale_uv * 2) / 1000; 798 + *val = (st->vref_uv * 2) / 1000; 803 799 *val2 = scan_type->realbits; 804 800 805 801 return IIO_VAL_FRACTIONAL_LOG2; ··· 1128 1132 .validate_device = iio_trigger_validate_own_device, 1129 1133 }; 1130 1134 1131 - static void ad7768_regulator_disable(void *data) 1132 - { 1133 - struct ad7768_state *st = data; 1134 - 1135 - regulator_disable(st->vref); 1136 - } 1137 - 1138 1135 static int ad7768_set_channel_label(struct iio_dev *indio_dev, 1139 1136 int num_channels) 1140 1137 { ··· 1359 1370 return dev_err_probe(&spi->dev, PTR_ERR(st->regmap24), 1360 1371 "Failed to initialize regmap24"); 1361 1372 1362 - st->vref = devm_regulator_get(&spi->dev, "vref"); 1363 - if (IS_ERR(st->vref)) 1364 - return PTR_ERR(st->vref); 1365 - 1366 - ret = regulator_enable(st->vref); 1367 - if (ret) { 1368 - dev_err(&spi->dev, "Failed to enable specified vref supply\n"); 1369 - return ret; 1370 - } 1371 - 1372 - ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st); 1373 - if (ret) 1374 - return ret; 1373 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); 1374 + if (ret < 0) 1375 + return dev_err_probe(&spi->dev, ret, 1376 + "Failed to get VREF voltage\n"); 1377 + st->vref_uv = ret; 1375 1378 1376 1379 st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); 1377 1380 if (IS_ERR(st->mclk))