diff mbox series

[v8,3/6] IIO: Ingenic JZ47xx: Add xlate cb to retrieve correct channel idx

Message ID 20200709152200.10039-4-contact@artur-rojek.eu (mailing list archive)
State New, archived
Headers show
Series iio/adc: ingenic: Cleanups & add touchscreen mode. | expand

Commit Message

Artur Rojek July 9, 2020, 3:21 p.m. UTC
Provide an of_xlate callback in order to retrieve the correct channel
specifier index from the IIO channels array.

Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
Tested-by: Paul Cercueil <paul@crapouillou.net>
---

 Changes:

 v2-v8: no change

 drivers/iio/adc/ingenic-adc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Jonathan Cameron July 12, 2020, 12:05 p.m. UTC | #1
On Thu,  9 Jul 2020 17:21:57 +0200
Artur Rojek <contact@artur-rojek.eu> wrote:

> Provide an of_xlate callback in order to retrieve the correct channel
> specifier index from the IIO channels array.
> 
> Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
> Tested-by: Paul Cercueil <paul@crapouillou.net>
Applied.  Thanks,

Jonathan

> ---
> 
>  Changes:
> 
>  v2-v8: no change
> 
>  drivers/iio/adc/ingenic-adc.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c
> index c1946a9f1cca..89019fb59d48 100644
> --- a/drivers/iio/adc/ingenic-adc.c
> +++ b/drivers/iio/adc/ingenic-adc.c
> @@ -400,6 +400,21 @@ static int ingenic_adc_read_raw(struct iio_dev *iio_dev,
>  	}
>  }
>  
> +static int ingenic_adc_of_xlate(struct iio_dev *iio_dev,
> +				const struct of_phandle_args *iiospec)
> +{
> +	int i;
> +
> +	if (!iiospec->args_count)
> +		return -EINVAL;
> +
> +	for (i = 0; i < iio_dev->num_channels; ++i)
> +		if (iio_dev->channels[i].channel == iiospec->args[0])
> +			return i;
> +
> +	return -EINVAL;
> +}
> +
>  static void ingenic_adc_clk_cleanup(void *data)
>  {
>  	clk_unprepare(data);
> @@ -409,6 +424,7 @@ static const struct iio_info ingenic_adc_info = {
>  	.write_raw = ingenic_adc_write_raw,
>  	.read_raw = ingenic_adc_read_raw,
>  	.read_avail = ingenic_adc_read_avail,
> +	.of_xlate = ingenic_adc_of_xlate,
>  };
>  
>  static const struct iio_chan_spec ingenic_channels[] = {
diff mbox series

Patch

diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c
index c1946a9f1cca..89019fb59d48 100644
--- a/drivers/iio/adc/ingenic-adc.c
+++ b/drivers/iio/adc/ingenic-adc.c
@@ -400,6 +400,21 @@  static int ingenic_adc_read_raw(struct iio_dev *iio_dev,
 	}
 }
 
+static int ingenic_adc_of_xlate(struct iio_dev *iio_dev,
+				const struct of_phandle_args *iiospec)
+{
+	int i;
+
+	if (!iiospec->args_count)
+		return -EINVAL;
+
+	for (i = 0; i < iio_dev->num_channels; ++i)
+		if (iio_dev->channels[i].channel == iiospec->args[0])
+			return i;
+
+	return -EINVAL;
+}
+
 static void ingenic_adc_clk_cleanup(void *data)
 {
 	clk_unprepare(data);
@@ -409,6 +424,7 @@  static const struct iio_info ingenic_adc_info = {
 	.write_raw = ingenic_adc_write_raw,
 	.read_raw = ingenic_adc_read_raw,
 	.read_avail = ingenic_adc_read_avail,
+	.of_xlate = ingenic_adc_of_xlate,
 };
 
 static const struct iio_chan_spec ingenic_channels[] = {