Skip to contentSkip to conversation

iio: adc: rzg2l_adc: Add fwnode_xlate() callback

PATCH New Biju Das 1 participant 1 message Nov 26

Subsystems (2)
lore
Share & tools
lore

Biju Das

author
#0 lore raw

PATCH 1/1 iio: adc: rzg2l_adc: Add fwnode_xlate() callback

From: Biju Das <[email protected]>

On RZ/G3L ADC1, IIO channel indices don't map 1:1 to hardware channel numbers. Add a fwnode_xlate() callback that finds the registered channel whose number matches the specifier argument and returns its index.

---
 drivers/iio/adc/rzg2l_adc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/iio/adc/rzg2l_adc.c +14 -0
index 340813f6f890..f00cfb897124 100644
@@ -286,9 +286,23 @@ static int rzg2l_adc_read_label(struct iio_dev *iio_dev,
 	return sysfs_emit(label, "%s\n", rzg2l_adc_channels[chan->channel].name);
 }
 
+static int rzg2l_adc_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 rzg2l_adc_iio_info = {
 	.read_raw = rzg2l_adc_read_raw,
 	.read_label = rzg2l_adc_read_label,
+	.fwnode_xlate = rzg2l_adc_fwnode_xlate,
 };
 
 static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id)
Signature · 1 line
2.43.0