Re: [PATCH v9 5/8] iio: adc: fsl,imx25-gcq driver

2015-12-14 Thread Markus Pargmann
Hi,

On Saturday 12 December 2015 17:14:24 Jonathan Cameron wrote:
> On 06/12/15 19:52, Markus Pargmann wrote:
> > This is a conversion queue driver for the mx25 SoC. It uses the central
> > ADC which is used by two seperate independent queues. This driver
> > prepares different conversion configurations for each possible input.
> > For a conversion it creates a conversionqueue of one item with the
> conversion queue
> > correct configuration for the chosen channel. It then executes the queue
> > once and disables the conversion queue afterwards.
> > 
> > The reference voltages are configurable through devicetree subnodes,
> > depending on the connections of the ADC inputs.
> > 
> > Signed-off-by: Markus Pargmann 
> > Signed-off-by: Denis Carikli 
> A couple of little bits inline.  Fix the return of 0 on fail in probe
> and you can add

Thanks, I fixed all your comments for the next version.

Best Regards,

Markus

> 
> Acked-by: Jonathan Cameron 
> > ---
> > 
> > Notes:
> > Changes in v7:
> >  - Remove separate functions mx25_gcq_disable/enable_eoq() as they were 
> > used at
> >only one position
> >  - Enforce an external reference regulator if one of the conversions 
> > uses it as
> >reference. The devm_regulator_get() call was moved into
> >mx25_gcq_setup_cfgs() to be able to acquire the reference regulator 
> > when
> >necessary.
> >  - Store indio_dev as platform driver data instead of the private data. 
> > This
> >was changed in probe() and remove().
> > 
> > Changes in v6:
> >  - Added defines for a complete list of references in the dt binding 
> > macros
> > 
> >  drivers/iio/adc/Kconfig |   7 +
> >  drivers/iio/adc/Makefile|   1 +
> >  drivers/iio/adc/fsl-imx25-gcq.c | 415 
> > 
> >  3 files changed, 423 insertions(+)
> >  create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c
> > 
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index 7868c744fd4b..73145c53ec2c 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -183,6 +183,13 @@ config EXYNOS_ADC
> >   To compile this driver as a module, choose M here: the module will be
> >   called exynos_adc.
> >  
> > +config FSL_MX25_ADC
> > +   tristate "Freescale MX25 ADC driver"
> > +   depends on MFD_MX25_TSADC
> > +   help
> > + Generic Conversion Queue driver used for general purpose ADC in the
> > + MX25. This driver supports single measurements using the MX25 ADC.
> > +
> >  config HI8435
> > tristate "Holt Integrated Circuits HI-8435 threshold detector"
> > select IIO_TRIGGERED_EVENT
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index 99b37a963a1e..2fe9b78e4b02 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -19,6 +19,7 @@ obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
> >  obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
> >  obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
> >  obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
> > +obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o
> >  obj-$(CONFIG_HI8435) += hi8435.o
> >  obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
> >  obj-$(CONFIG_MAX1027) += max1027.o
> > diff --git a/drivers/iio/adc/fsl-imx25-gcq.c 
> > b/drivers/iio/adc/fsl-imx25-gcq.c
> > new file mode 100644
> > index ..eb9570876291
> > --- /dev/null
> > +++ b/drivers/iio/adc/fsl-imx25-gcq.c
> > @@ -0,0 +1,415 @@
> > +/*
> > + * Copyright (C) 2014-2015 Pengutronix, Markus Pargmann 
> > 
> > + *
> > + * This program is free software; you can redistribute it and/or modify it 
> > under
> > + * the terms of the GNU General Public License version 2 as published by 
> > the
> > + * Free Software Foundation.
> > + *
> > + * This is the driver for the imx25 GCQ (Generic Conversion Queue)
> > + * connected to the imx25 ADC.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define MX25_GCQ_TIMEOUT (msecs_to_jiffies(2000))
> > +
> > +static const char * const driver_name = "mx25-gcq";
> > +
> > +enum mx25_gcq_cfgs {
> > +   MX25_CFG_XP = 0,
> > +   MX25_CFG_YP,
> > +   MX25_CFG_XN,
> > +   MX25_CFG_YN,
> > +   MX25_CFG_WIPER,
> > +   MX25_CFG_INAUX0,
> > +   MX25_CFG_INAUX1,
> > +   MX25_CFG_INAUX2,
> > +   MX25_NUM_CFGS,
> > +};
> > +
> > +struct mx25_gcq_priv {
> > +   struct regmap *regs;
> > +   struct completion completed;
> > +   struct clk *clk;
> > +   int irq;
> > +   struct regulator *vref[4];
> > +   u32 channel_vref_mv[MX25_NUM_CFGS];
> > +};
> > +
> > +#define MX25_CQG_CHAN(chan, id) {\
> > +   .type = IIO_VOLTAGE,\
> > +   .indexed = 1,\
> > +   .channel = chan,\
> > +   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> > + BIT(IIO_CHAN_INFO_SCALE),\
> > +   

Re: [PATCH v9 5/8] iio: adc: fsl,imx25-gcq driver

2015-12-12 Thread Jonathan Cameron
On 06/12/15 19:52, Markus Pargmann wrote:
> This is a conversion queue driver for the mx25 SoC. It uses the central
> ADC which is used by two seperate independent queues. This driver
> prepares different conversion configurations for each possible input.
> For a conversion it creates a conversionqueue of one item with the
conversion queue
> correct configuration for the chosen channel. It then executes the queue
> once and disables the conversion queue afterwards.
> 
> The reference voltages are configurable through devicetree subnodes,
> depending on the connections of the ADC inputs.
> 
> Signed-off-by: Markus Pargmann 
> Signed-off-by: Denis Carikli 
A couple of little bits inline.  Fix the return of 0 on fail in probe
and you can add

Acked-by: Jonathan Cameron 
> ---
> 
> Notes:
> Changes in v7:
>  - Remove separate functions mx25_gcq_disable/enable_eoq() as they were 
> used at
>only one position
>  - Enforce an external reference regulator if one of the conversions uses 
> it as
>reference. The devm_regulator_get() call was moved into
>mx25_gcq_setup_cfgs() to be able to acquire the reference regulator 
> when
>necessary.
>  - Store indio_dev as platform driver data instead of the private data. 
> This
>was changed in probe() and remove().
> 
> Changes in v6:
>  - Added defines for a complete list of references in the dt binding 
> macros
> 
>  drivers/iio/adc/Kconfig |   7 +
>  drivers/iio/adc/Makefile|   1 +
>  drivers/iio/adc/fsl-imx25-gcq.c | 415 
> 
>  3 files changed, 423 insertions(+)
>  create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 7868c744fd4b..73145c53ec2c 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -183,6 +183,13 @@ config EXYNOS_ADC
> To compile this driver as a module, choose M here: the module will be
> called exynos_adc.
>  
> +config FSL_MX25_ADC
> + tristate "Freescale MX25 ADC driver"
> + depends on MFD_MX25_TSADC
> + help
> +   Generic Conversion Queue driver used for general purpose ADC in the
> +   MX25. This driver supports single measurements using the MX25 ADC.
> +
>  config HI8435
>   tristate "Holt Integrated Circuits HI-8435 threshold detector"
>   select IIO_TRIGGERED_EVENT
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index 99b37a963a1e..2fe9b78e4b02 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -19,6 +19,7 @@ obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
>  obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
>  obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
>  obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
> +obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o
>  obj-$(CONFIG_HI8435) += hi8435.o
>  obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
>  obj-$(CONFIG_MAX1027) += max1027.o
> diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
> new file mode 100644
> index ..eb9570876291
> --- /dev/null
> +++ b/drivers/iio/adc/fsl-imx25-gcq.c
> @@ -0,0 +1,415 @@
> +/*
> + * Copyright (C) 2014-2015 Pengutronix, Markus Pargmann 
> + *
> + * This program is free software; you can redistribute it and/or modify it 
> under
> + * the terms of the GNU General Public License version 2 as published by the
> + * Free Software Foundation.
> + *
> + * This is the driver for the imx25 GCQ (Generic Conversion Queue)
> + * connected to the imx25 ADC.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MX25_GCQ_TIMEOUT (msecs_to_jiffies(2000))
> +
> +static const char * const driver_name = "mx25-gcq";
> +
> +enum mx25_gcq_cfgs {
> + MX25_CFG_XP = 0,
> + MX25_CFG_YP,
> + MX25_CFG_XN,
> + MX25_CFG_YN,
> + MX25_CFG_WIPER,
> + MX25_CFG_INAUX0,
> + MX25_CFG_INAUX1,
> + MX25_CFG_INAUX2,
> + MX25_NUM_CFGS,
> +};
> +
> +struct mx25_gcq_priv {
> + struct regmap *regs;
> + struct completion completed;
> + struct clk *clk;
> + int irq;
> + struct regulator *vref[4];
> + u32 channel_vref_mv[MX25_NUM_CFGS];
> +};
> +
> +#define MX25_CQG_CHAN(chan, id) {\
> + .type = IIO_VOLTAGE,\
> + .indexed = 1,\
> + .channel = chan,\
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> +   BIT(IIO_CHAN_INFO_SCALE),\
> + .datasheet_name = id,\
> +}
> +
> +static const struct iio_chan_spec mx25_gcq_channels[MX25_NUM_CFGS] = {
> + MX25_CQG_CHAN(MX25_CFG_XP, "xp"),
> + MX25_CQG_CHAN(MX25_CFG_YP, "yp"),
> + MX25_CQG_CHAN(MX25_CFG_XN, "xn"),
> + MX25_CQG_CHAN(MX25_CFG_YN, "yn"),
> + MX25_CQG_CHAN(MX25_CFG_WIPER, "wiper"),
> + MX25_CQG_CHAN(MX25_CFG_INAUX0, "inaux0"),
> + 

[PATCH v9 5/8] iio: adc: fsl,imx25-gcq driver

2015-12-06 Thread Markus Pargmann
This is a conversion queue driver for the mx25 SoC. It uses the central
ADC which is used by two seperate independent queues. This driver
prepares different conversion configurations for each possible input.
For a conversion it creates a conversionqueue of one item with the
correct configuration for the chosen channel. It then executes the queue
once and disables the conversion queue afterwards.

The reference voltages are configurable through devicetree subnodes,
depending on the connections of the ADC inputs.

Signed-off-by: Markus Pargmann 
Signed-off-by: Denis Carikli 
---

Notes:
Changes in v7:
 - Remove separate functions mx25_gcq_disable/enable_eoq() as they were 
used at
   only one position
 - Enforce an external reference regulator if one of the conversions uses 
it as
   reference. The devm_regulator_get() call was moved into
   mx25_gcq_setup_cfgs() to be able to acquire the reference regulator when
   necessary.
 - Store indio_dev as platform driver data instead of the private data. This
   was changed in probe() and remove().

Changes in v6:
 - Added defines for a complete list of references in the dt binding macros

 drivers/iio/adc/Kconfig |   7 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/fsl-imx25-gcq.c | 415 
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7868c744fd4b..73145c53ec2c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -183,6 +183,13 @@ config EXYNOS_ADC
  To compile this driver as a module, choose M here: the module will be
  called exynos_adc.
 
+config FSL_MX25_ADC
+   tristate "Freescale MX25 ADC driver"
+   depends on MFD_MX25_TSADC
+   help
+ Generic Conversion Queue driver used for general purpose ADC in the
+ MX25. This driver supports single measurements using the MX25 ADC.
+
 config HI8435
tristate "Holt Integrated Circuits HI-8435 threshold detector"
select IIO_TRIGGERED_EVENT
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 99b37a963a1e..2fe9b78e4b02 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
 obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
 obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
+obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o
 obj-$(CONFIG_HI8435) += hi8435.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
new file mode 100644
index ..eb9570876291
--- /dev/null
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -0,0 +1,415 @@
+/*
+ * Copyright (C) 2014-2015 Pengutronix, Markus Pargmann 
+ *
+ * This program is free software; you can redistribute it and/or modify it 
under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ *
+ * This is the driver for the imx25 GCQ (Generic Conversion Queue)
+ * connected to the imx25 ADC.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MX25_GCQ_TIMEOUT (msecs_to_jiffies(2000))
+
+static const char * const driver_name = "mx25-gcq";
+
+enum mx25_gcq_cfgs {
+   MX25_CFG_XP = 0,
+   MX25_CFG_YP,
+   MX25_CFG_XN,
+   MX25_CFG_YN,
+   MX25_CFG_WIPER,
+   MX25_CFG_INAUX0,
+   MX25_CFG_INAUX1,
+   MX25_CFG_INAUX2,
+   MX25_NUM_CFGS,
+};
+
+struct mx25_gcq_priv {
+   struct regmap *regs;
+   struct completion completed;
+   struct clk *clk;
+   int irq;
+   struct regulator *vref[4];
+   u32 channel_vref_mv[MX25_NUM_CFGS];
+};
+
+#define MX25_CQG_CHAN(chan, id) {\
+   .type = IIO_VOLTAGE,\
+   .indexed = 1,\
+   .channel = chan,\
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+ BIT(IIO_CHAN_INFO_SCALE),\
+   .datasheet_name = id,\
+}
+
+static const struct iio_chan_spec mx25_gcq_channels[MX25_NUM_CFGS] = {
+   MX25_CQG_CHAN(MX25_CFG_XP, "xp"),
+   MX25_CQG_CHAN(MX25_CFG_YP, "yp"),
+   MX25_CQG_CHAN(MX25_CFG_XN, "xn"),
+   MX25_CQG_CHAN(MX25_CFG_YN, "yn"),
+   MX25_CQG_CHAN(MX25_CFG_WIPER, "wiper"),
+   MX25_CQG_CHAN(MX25_CFG_INAUX0, "inaux0"),
+   MX25_CQG_CHAN(MX25_CFG_INAUX1, "inaux1"),
+   MX25_CQG_CHAN(MX25_CFG_INAUX2, "inaux2"),
+};
+
+static const char * const mx25_gcq_refp_names[] = {
+   [MX25_ADC_REFP_YP] = "yp",
+   [MX25_ADC_REFP_XP] = "xp",
+   [MX25_ADC_REFP_INT] = "int",
+   [MX25_ADC_REFP_EXT] = "ext",
+};
+
+static irqreturn_t mx25_gcq_irq(int irq, void *data)
+{
+   struct mx25_gcq_priv *priv = data;
+