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

iio: dac: ad7293: add adc reference configuration

Add support for configurating the ADC reference (internal/external).

According to the datasheet, the external reference is enabled by
default.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250422085529.4407-2-antoniu.miclaus@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
cdbc8b99 55d0392f

+13
+13
drivers/iio/dac/ad7293.c
··· 114 114 #define AD7293_REG_DATA_RAW_MSK GENMASK(15, 4) 115 115 #define AD7293_REG_VINX_RANGE_GET_CH_MSK(x, ch) (((x) >> (ch)) & 0x1) 116 116 #define AD7293_REG_VINX_RANGE_SET_CH_MSK(x, ch) (((x) & 0x1) << (ch)) 117 + #define AD7293_GENERAL_ADC_REF_MSK BIT(7) 117 118 #define AD7293_CHIP_ID 0x18 118 119 119 120 enum ad7293_ch_type { ··· 142 141 /* Protect against concurrent accesses to the device, page selection and data content */ 143 142 struct mutex lock; 144 143 struct gpio_desc *gpio_reset; 144 + bool vrefin_en; 145 145 u8 page_select; 146 146 u8 data[3] __aligned(IIO_DMA_MINALIGN); 147 147 }; ··· 787 785 if (ret) 788 786 return dev_err_probe(&spi->dev, ret, "failed to enable VDRIVE\n"); 789 787 788 + ret = devm_regulator_get_enable_optional(&spi->dev, "vrefin"); 789 + if (ret < 0 && ret != -ENODEV) 790 + return dev_err_probe(&spi->dev, ret, "failed to enable VREFIN\n"); 791 + 792 + st->vrefin_en = ret != -ENODEV; 793 + 790 794 st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset", 791 795 GPIOD_OUT_HIGH); 792 796 if (IS_ERR(st->gpio_reset)) ··· 825 817 dev_err(&spi->dev, "Invalid Chip ID.\n"); 826 818 return -EINVAL; 827 819 } 820 + 821 + if (!st->vrefin_en) 822 + return __ad7293_spi_update_bits(st, AD7293_REG_GENERAL, 823 + AD7293_GENERAL_ADC_REF_MSK, 824 + AD7293_GENERAL_ADC_REF_MSK); 828 825 829 826 return 0; 830 827 }