Re: [PATCH] iio: adc: ti-ads112c14: add gpio support

From: David Lechner

Date: Fri Oct 09 2026 - 19:05:34 EST


On 9/28/26 3:36 AM, Andy Shevchenko wrote:
> On Fri, Sep 25, 2026 at 04:50:47PM -0500, David Lechner (TI) wrote:
>> Add support for using the AIN4/GPIO0 to AIN7/GPIO3 pins as GPIOs when
>> the gpio-controller property is present.
>>
>> Pins that are already used for something else according to the
>> devicetree are excluded from the valid GPIO mask. This includes analog
>> inputs and excitation current outputs used by channels, REFP/REFN when
>> an external reference is used, the /FAULT and /DRDY interrupts and the
>> external clock input.
>>
>> The per-pin register field macros are replaced with parameterized ones
>> so that they can be used with the GPIO offset.
>
> ...
>
>> + DECLARE_BITMAP(gpio_reserved_mask, ADS112C14_NUM_GPIO);
>
> Why not use valid_mask in GPIO chip directly?

Because gc.valid_mask doesn't exist until gpiochip_add_data(). So we would
need to track other things longer or read the firmware properties twice. I
went with Jonathan's suggestion to do it where the pins are parsed instead.


>> +static int ads112c14_gpio_init(struct iio_dev *indio_dev)
>> +{
>> + struct ads112c14_data *data = iio_priv(indio_dev);
>> + struct device *dev = indio_dev->dev.parent;
>> +
>> + for (unsigned int i = 0; i < ADS112C14_NUM_GPIO; i++) {
>> + data->gpio_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%s:GPIO%u",
>> + dev_name(&indio_dev->dev), i);
>> + if (!data->gpio_names[i])
>> + return -ENOMEM;
>
> Wondering if you can utilise devm_kasprintf_strarray().
>
That uses "%s-%zu" internally, so would add a "-" where I don't want it.