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

iio: adc: ad7887: invert/rework external ref logic

This change inverts/reworks the logic to use an external reference via a
provided regulator.

Now the driver tries to obtain a regulator. If one is found, then it is
used. The rest of the driver logic already checks if there is a non-NULL
reference to a regulator, so it should be fine.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20201002082723.184810-1-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
5483b8d5 ead1c9f3

+8 -8
+8 -4
drivers/iio/adc/ad7887.c
··· 246 246 247 247 st = iio_priv(indio_dev); 248 248 249 - if (!pdata || !pdata->use_onchip_ref) { 250 - st->reg = devm_regulator_get(&spi->dev, "vref"); 251 - if (IS_ERR(st->reg)) 249 + st->reg = devm_regulator_get_optional(&spi->dev, "vref"); 250 + if (IS_ERR(st->reg)) { 251 + if (PTR_ERR(st->reg) != -ENODEV) 252 252 return PTR_ERR(st->reg); 253 253 254 + st->reg = NULL; 255 + } 256 + 257 + if (st->reg) { 254 258 ret = regulator_enable(st->reg); 255 259 if (ret) 256 260 return ret; ··· 273 269 /* Setup default message */ 274 270 275 271 mode = AD7887_PM_MODE4; 276 - if (!pdata || !pdata->use_onchip_ref) 272 + if (!st->reg) 277 273 mode |= AD7887_REF_DIS; 278 274 if (pdata && pdata->en_dual) 279 275 mode |= AD7887_DUAL;
-4
include/linux/platform_data/ad7887.h
··· 13 13 * second input channel, and Vref is internally connected to Vdd. If set to 14 14 * false the device is used in single channel mode and AIN1/Vref is used as 15 15 * VREF input. 16 - * @use_onchip_ref: Whether to use the onchip reference. If set to true the 17 - * internal 2.5V reference is used. If set to false a external reference is 18 - * used. 19 16 */ 20 17 struct ad7887_platform_data { 21 18 bool en_dual; 22 - bool use_onchip_ref; 23 19 }; 24 20 25 21 #endif /* IIO_ADC_AD7887_H_ */