Re: [PATCH v2 5/5] iio: adc: add support for ad4052

From: David Lechner
Date: Mon Jun 02 2025 - 11:55:27 EST


On 6/2/25 6:16 AM, Jorge Marques wrote:
> Hi David,
>
> On Fri, Apr 25, 2025 at 06:13:48PM -0500, David Lechner wrote:
>> On 4/22/25 6:34 AM, Jorge Marques wrote:

...

>>> +static int ad4052_probe(struct spi_device *spi)
>>> +{
>>> + const struct ad4052_chip_info *chip;
>>> + struct device *dev = &spi->dev;
>>> + struct iio_dev *indio_dev;
>>> + struct ad4052_state *st;
>>> + int ret = 0;
>>> +
>>> + chip = spi_get_device_match_data(spi);
>>> + if (!chip)
>>> + return dev_err_probe(dev, -ENODEV,
>>> + "Could not find chip info data\n");
>>> +
>>> + indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>>> + if (!indio_dev)
>>> + return -ENOMEM;
>>> +
>>> + st = iio_priv(indio_dev);
>>> + st->spi = spi;
>>> + spi_set_drvdata(spi, st);
>>> + init_completion(&st->completion);
>>> +
>>> + st->regmap = devm_regmap_init_spi(spi, &ad4052_regmap_config);
>>> + if (IS_ERR(st->regmap))
>>> + return dev_err_probe(dev, PTR_ERR(st->regmap),
>>> + "Failed to initialize regmap\n");
>>> +
>>> + st->mode = AD4052_SAMPLE_MODE;
>>> + st->wait_event = false;
>>> + st->chip = chip;
>>> + st->grade = chip->prod_id <= 0x75 ? AD4052_2MSPS : AD4052_500KSPS;
>>> + st->oversampling_frequency = AD4052_FS_OFFSET(st->grade);
>>> + st->events_frequency = AD4052_FS_OFFSET(st->grade);
>>
>> Somewhere around here, we should be turning on the power supplies. Also, it
>> looks like we need some special handling to get the reference voltage. If there
>> is a supply connected to REF, use that, if not, use VDD which requires writing
>> to a register to let the chip know.
>>
> Yes, v3 will add regulators.
> Vref can be sourced from either REF (default) or VDD.
> So the idea is, if REF node not provided, set VDD as REF?
>
Yes, you can do this with devm_regulator_get_enable_read_voltage() if it
returns -ENODEV, for the REF supply, then call it again on the VDD supply.