Re: [PATCH v4 03/10] iio: adc: add helpers for parsing ADC nodes

Matti Vaittinen
2025-03-02T13:00:26Z

On 02/03/2025 05:35, Jonathan Cameron wrote:
> On Mon, 24 Feb 2025 20:33:16 +0200
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>
>> There are ADC ICs which may have some of the AIN pins usable for other
>> functions. These ICs may have some of the AIN pins wired so that they
>> should not be used for ADC.
>>
>> (Preferred?) way for marking pins which can be used as ADC inputs is to
>> add corresponding channels@N nodes in the device tree as described in
>> the ADC binding yaml.
> I think it's worth exploring if we can tweak this slightly to make
> that something a driver specifies. Either skip the unspecified or
> fill them with default values depending on a parameter.
>
> Would make this code cover the existing cases better.
> Might be a little fiddly as we'd want to maintain ordering so
> the code would need to index slightly differently. I've not tried it
> so maybe not worth it for now.

Thanks for the review!

I don't remember seeing users which would have benefited from this (but
maybe I just quickly discarded them as unsuitable for this API and
forgot them). Anyways, I think it might be cleaner (from the caller's
perspective) to have own function for supporting such cases.

>> +
>> +int iio_adc_device_num_channels(struct device *dev)
>> +{
>> + return device_get_child_node_count_named(dev, "channel");
>> +}
>> +EXPORT_SYMBOL_GPL(iio_adc_device_num_channels);
>
> Maybe one to promote to a static inline in the header and avoid need for
> the export given it is very simple.

Makes sense, thanks.

...

>> +
>> + if (max_chan_id != -1)
>> + if (ch > max_chan_id)
>> + return -ERANGE;
>
> Might as well combine.
> if (max_chan_id != -1 && ch > max_chan_id)
> return -ERANGE;

Ack.

Yours,
-- Matti