]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: adc: sun20i-gpadc: support non-contiguous channel lookups
authorMichal Piekos <michal.piekos@mmpsystems.pl>
Sat, 16 May 2026 05:48:37 +0000 (07:48 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sun, 31 May 2026 09:59:41 +0000 (10:59 +0100)
Using consumer driver like iio-hwmon which resolve channels through
io-channels phandles will fail for sparse channels because IIO core by
default treats phandle argument as index into channel array.
        eg. <&gpadc 1> will fail if there is only channel@1 specified

Add .fwnode_xlate() which maps DT phandle to the registered channel
whose chan->channel matches the hardware channel number. It allows
sparse channel maps to be consumed by drivers like iio-hwmon.

Tested on Radxa Cubie A5E.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Michal Piekos <michal.piekos@mmpsystems.pl>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/adc/sun20i-gpadc-iio.c

index f5fd2240b808d15a6f689311590d076a70f4b3b9..81fc4610e15e6a9e1e68b30f3481abe8706f240a 100644 (file)
@@ -139,8 +139,23 @@ static irqreturn_t sun20i_gpadc_irq_handler(int irq, void *data)
        return IRQ_HANDLED;
 }
 
+static int
+sun20i_gpadc_fwnode_xlate(struct iio_dev *indio_dev,
+                         const struct fwnode_reference_args *iiospec)
+{
+       if (iiospec->nargs != 1)
+               return -EINVAL;
+
+       for (unsigned int i = 0; i < indio_dev->num_channels; i++)
+               if (indio_dev->channels[i].channel == iiospec->args[0])
+                       return i;
+
+       return -EINVAL;
+}
+
 static const struct iio_info sun20i_gpadc_iio_info = {
        .read_raw = sun20i_gpadc_read_raw,
+       .fwnode_xlate = sun20i_gpadc_fwnode_xlate,
 };
 
 static void sun20i_gpadc_reset_assert(void *data)