iio: dac: ad7293: add adc reference configuration
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Tue, 22 Apr 2025 08:55:29 +0000 (11:55 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 21 May 2025 13:20:29 +0000 (14:20 +0100)
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>
drivers/iio/dac/ad7293.c

index 99fa2d1f8299eb29996e5816e822394b4d1acf21..c3797e40cdd9f5f6335dd4d4b2fe52d56eb4075a 100644 (file)
 #define AD7293_REG_DATA_RAW_MSK                        GENMASK(15, 4)
 #define AD7293_REG_VINX_RANGE_GET_CH_MSK(x, ch)        (((x) >> (ch)) & 0x1)
 #define AD7293_REG_VINX_RANGE_SET_CH_MSK(x, ch)        (((x) & 0x1) << (ch))
+#define AD7293_GENERAL_ADC_REF_MSK                     BIT(7)
 #define AD7293_CHIP_ID                         0x18
 
 enum ad7293_ch_type {
@@ -141,6 +142,7 @@ struct ad7293_state {
        /* Protect against concurrent accesses to the device, page selection and data content */
        struct mutex lock;
        struct gpio_desc *gpio_reset;
+       bool vrefin_en;
        u8 page_select;
        u8 data[3] __aligned(IIO_DMA_MINALIGN);
 };
@@ -785,6 +787,12 @@ static int ad7293_properties_parse(struct ad7293_state *st)
        if (ret)
                return dev_err_probe(&spi->dev, ret, "failed to enable VDRIVE\n");
 
+       ret = devm_regulator_get_enable_optional(&spi->dev, "vrefin");
+       if (ret < 0 && ret != -ENODEV)
+               return dev_err_probe(&spi->dev, ret, "failed to enable VREFIN\n");
+
+       st->vrefin_en = ret != -ENODEV;
+
        st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset",
                                                 GPIOD_OUT_HIGH);
        if (IS_ERR(st->gpio_reset))
@@ -818,6 +826,11 @@ static int ad7293_init(struct ad7293_state *st)
                return -EINVAL;
        }
 
+       if (!st->vrefin_en)
+               return __ad7293_spi_update_bits(st, AD7293_REG_GENERAL,
+                                               AD7293_GENERAL_ADC_REF_MSK,
+                                               AD7293_GENERAL_ADC_REF_MSK);
+
        return 0;
 }