Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-11 Thread Jonathan Cameron
On Thu, 8 Nov 2018 16:48:02 +
"Popa, Stefan Serban"  wrote:

> On Jo, 2018-11-08 at 10:34 -0600, Rob Herring wrote:
> > On Thu, Nov 8, 2018 at 9:02 AM Popa, Stefan Serban
> >  wrote:  
> > > 
> > > 
> > > On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:  
> > > > 
> > > > On Mon, 29 Oct 2018 18:38:31 +0200
> > > > Stefan Popa  wrote:
> > > >   
> > > > > 
> > > > > 
> > > > > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-
> > > > > delta
> > > > > ADCs
> > > > > with 24-bit precision and reference.
> > > > > 
> > > > > Three power modes are available which in turn affect the output
> > > > > data
> > > > > rate:
> > > > >  * Full power: 9.38 SPS to 19,200 SPS
> > > > >  * Mid power: 2.34 SPS to 4800 SPS
> > > > >  * Low power: 1.17 SPS to 2400 SPS
> > > > > 
> > > > > The ad7124-4 can be configured to have four differential inputs,
> > > > > while
> > > > > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > > > > configuration. Each configuration consists of gain, reference
> > > > > source,
> > > > > output data rate and bipolar/unipolar configuration.
> > > > > 
> > > > > Datasheets:
> > > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > > heet
> > > > > s/AD7124-4.pdf
> > > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > > heet
> > > > > s/ad7124-8.pdf
> > > > > 
> > > > > Signed-off-by: Stefan Popa   
> > > > Hi Stefan,
> > > > 
> > > > The discussion around the DT binding has gotten me looking at bit
> > > > more closely at that for this version.
> > > > 
> > > > Some most comments in that section.  Also a really minor ordering
> > > > issue
> > > > in
> > > > remove which I'd just have fixed if we weren't going around again for
> > > > the binding.
> > > > 
> > > > Main binding thing is I don't think the odr value belongs in DT.
> > > > Gain is more marginal (unless the part can actually be damaged by
> > > > a wrong value - which I hope it can't!).  I'm not that fussed
> > > > as there are definitely reasons to specify a default scale to
> > > > cover the reasonable range on a pin.
> > > > 
> > > > Thanks,
> > > > 
> > > > Jonathan  
> > > Hi Jonathan,
> > > 
> > > Thank you for the review! So, how should I proceed?
> > > 
> > > First, we need an adc.txt file where "bipolar" and something like
> > > "diff-
> > > channels" should be documented. Should the file be placed under
> > > Documentation/devicetree/bindings/iio/adc?  
> > Yes.
> >   
> > > 
> > > Regarding the "odr-hz" property, it totally makes sense to remove it
> > > from
> > > the DT. How about the "gain"? Should we leave it in the DT and also add
> > > the
> > > possibility to be configured from user space?  
> > Look at other bindings. I think there are others having gain. If not,
> > then it probably should only be user space configurable. If so, then
> > can it be a common property too.
> > 
> > Rob
> >   
> 
> Hi Rob,
> 
> I found only a couple of examples using gain in other bindings, so I guess
> it's not common practice. I will remove the gain as well from the DT and
> set it with the default of 1.
> 
> @Jonathan: I think that IIO_CHAN_INFO_HARDWAREGAIN is the attribute that
> can be used in user space?
Sorry, I missed this.  Guess you will see my review anyway around now.
Nope, hardwaregain is an oddity for devices where we aren't controlling
the thing being measured, but something like the amplifier of a
time of flight device.

There is some argument to potentially provide sane limits on gain in DT
(particularly if a device really doesn't like going out of range) but
in general I'm not keen on it as it is rather an application specific
question so best left to userspace.

Jonathan

> 
> Thank you!
> -Stefan


Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-11 Thread Jonathan Cameron
On Thu, 8 Nov 2018 16:48:02 +
"Popa, Stefan Serban"  wrote:

> On Jo, 2018-11-08 at 10:34 -0600, Rob Herring wrote:
> > On Thu, Nov 8, 2018 at 9:02 AM Popa, Stefan Serban
> >  wrote:  
> > > 
> > > 
> > > On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:  
> > > > 
> > > > On Mon, 29 Oct 2018 18:38:31 +0200
> > > > Stefan Popa  wrote:
> > > >   
> > > > > 
> > > > > 
> > > > > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-
> > > > > delta
> > > > > ADCs
> > > > > with 24-bit precision and reference.
> > > > > 
> > > > > Three power modes are available which in turn affect the output
> > > > > data
> > > > > rate:
> > > > >  * Full power: 9.38 SPS to 19,200 SPS
> > > > >  * Mid power: 2.34 SPS to 4800 SPS
> > > > >  * Low power: 1.17 SPS to 2400 SPS
> > > > > 
> > > > > The ad7124-4 can be configured to have four differential inputs,
> > > > > while
> > > > > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > > > > configuration. Each configuration consists of gain, reference
> > > > > source,
> > > > > output data rate and bipolar/unipolar configuration.
> > > > > 
> > > > > Datasheets:
> > > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > > heet
> > > > > s/AD7124-4.pdf
> > > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > > heet
> > > > > s/ad7124-8.pdf
> > > > > 
> > > > > Signed-off-by: Stefan Popa   
> > > > Hi Stefan,
> > > > 
> > > > The discussion around the DT binding has gotten me looking at bit
> > > > more closely at that for this version.
> > > > 
> > > > Some most comments in that section.  Also a really minor ordering
> > > > issue
> > > > in
> > > > remove which I'd just have fixed if we weren't going around again for
> > > > the binding.
> > > > 
> > > > Main binding thing is I don't think the odr value belongs in DT.
> > > > Gain is more marginal (unless the part can actually be damaged by
> > > > a wrong value - which I hope it can't!).  I'm not that fussed
> > > > as there are definitely reasons to specify a default scale to
> > > > cover the reasonable range on a pin.
> > > > 
> > > > Thanks,
> > > > 
> > > > Jonathan  
> > > Hi Jonathan,
> > > 
> > > Thank you for the review! So, how should I proceed?
> > > 
> > > First, we need an adc.txt file where "bipolar" and something like
> > > "diff-
> > > channels" should be documented. Should the file be placed under
> > > Documentation/devicetree/bindings/iio/adc?  
> > Yes.
> >   
> > > 
> > > Regarding the "odr-hz" property, it totally makes sense to remove it
> > > from
> > > the DT. How about the "gain"? Should we leave it in the DT and also add
> > > the
> > > possibility to be configured from user space?  
> > Look at other bindings. I think there are others having gain. If not,
> > then it probably should only be user space configurable. If so, then
> > can it be a common property too.
> > 
> > Rob
> >   
> 
> Hi Rob,
> 
> I found only a couple of examples using gain in other bindings, so I guess
> it's not common practice. I will remove the gain as well from the DT and
> set it with the default of 1.
> 
> @Jonathan: I think that IIO_CHAN_INFO_HARDWAREGAIN is the attribute that
> can be used in user space?
Sorry, I missed this.  Guess you will see my review anyway around now.
Nope, hardwaregain is an oddity for devices where we aren't controlling
the thing being measured, but something like the amplifier of a
time of flight device.

There is some argument to potentially provide sane limits on gain in DT
(particularly if a device really doesn't like going out of range) but
in general I'm not keen on it as it is rather an application specific
question so best left to userspace.

Jonathan

> 
> Thank you!
> -Stefan


Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-08 Thread Popa, Stefan Serban
On Jo, 2018-11-08 at 10:34 -0600, Rob Herring wrote:
> On Thu, Nov 8, 2018 at 9:02 AM Popa, Stefan Serban
>  wrote:
> > 
> > 
> > On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:
> > > 
> > > On Mon, 29 Oct 2018 18:38:31 +0200
> > > Stefan Popa  wrote:
> > > 
> > > > 
> > > > 
> > > > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-
> > > > delta
> > > > ADCs
> > > > with 24-bit precision and reference.
> > > > 
> > > > Three power modes are available which in turn affect the output
> > > > data
> > > > rate:
> > > >  * Full power: 9.38 SPS to 19,200 SPS
> > > >  * Mid power: 2.34 SPS to 4800 SPS
> > > >  * Low power: 1.17 SPS to 2400 SPS
> > > > 
> > > > The ad7124-4 can be configured to have four differential inputs,
> > > > while
> > > > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > > > configuration. Each configuration consists of gain, reference
> > > > source,
> > > > output data rate and bipolar/unipolar configuration.
> > > > 
> > > > Datasheets:
> > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > heet
> > > > s/AD7124-4.pdf
> > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > heet
> > > > s/ad7124-8.pdf
> > > > 
> > > > Signed-off-by: Stefan Popa 
> > > Hi Stefan,
> > > 
> > > The discussion around the DT binding has gotten me looking at bit
> > > more closely at that for this version.
> > > 
> > > Some most comments in that section.  Also a really minor ordering
> > > issue
> > > in
> > > remove which I'd just have fixed if we weren't going around again for
> > > the binding.
> > > 
> > > Main binding thing is I don't think the odr value belongs in DT.
> > > Gain is more marginal (unless the part can actually be damaged by
> > > a wrong value - which I hope it can't!).  I'm not that fussed
> > > as there are definitely reasons to specify a default scale to
> > > cover the reasonable range on a pin.
> > > 
> > > Thanks,
> > > 
> > > Jonathan
> > Hi Jonathan,
> > 
> > Thank you for the review! So, how should I proceed?
> > 
> > First, we need an adc.txt file where "bipolar" and something like
> > "diff-
> > channels" should be documented. Should the file be placed under
> > Documentation/devicetree/bindings/iio/adc?
> Yes.
> 
> > 
> > Regarding the "odr-hz" property, it totally makes sense to remove it
> > from
> > the DT. How about the "gain"? Should we leave it in the DT and also add
> > the
> > possibility to be configured from user space?
> Look at other bindings. I think there are others having gain. If not,
> then it probably should only be user space configurable. If so, then
> can it be a common property too.
> 
> Rob
> 

Hi Rob,

I found only a couple of examples using gain in other bindings, so I guess
it's not common practice. I will remove the gain as well from the DT and
set it with the default of 1.

@Jonathan: I think that IIO_CHAN_INFO_HARDWAREGAIN is the attribute that
can be used in user space?

Thank you!
-Stefan

Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-08 Thread Popa, Stefan Serban
On Jo, 2018-11-08 at 10:34 -0600, Rob Herring wrote:
> On Thu, Nov 8, 2018 at 9:02 AM Popa, Stefan Serban
>  wrote:
> > 
> > 
> > On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:
> > > 
> > > On Mon, 29 Oct 2018 18:38:31 +0200
> > > Stefan Popa  wrote:
> > > 
> > > > 
> > > > 
> > > > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-
> > > > delta
> > > > ADCs
> > > > with 24-bit precision and reference.
> > > > 
> > > > Three power modes are available which in turn affect the output
> > > > data
> > > > rate:
> > > >  * Full power: 9.38 SPS to 19,200 SPS
> > > >  * Mid power: 2.34 SPS to 4800 SPS
> > > >  * Low power: 1.17 SPS to 2400 SPS
> > > > 
> > > > The ad7124-4 can be configured to have four differential inputs,
> > > > while
> > > > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > > > configuration. Each configuration consists of gain, reference
> > > > source,
> > > > output data rate and bipolar/unipolar configuration.
> > > > 
> > > > Datasheets:
> > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > heet
> > > > s/AD7124-4.pdf
> > > > Link: http://www.analog.com/media/en/technical-documentation/data-s
> > > > heet
> > > > s/ad7124-8.pdf
> > > > 
> > > > Signed-off-by: Stefan Popa 
> > > Hi Stefan,
> > > 
> > > The discussion around the DT binding has gotten me looking at bit
> > > more closely at that for this version.
> > > 
> > > Some most comments in that section.  Also a really minor ordering
> > > issue
> > > in
> > > remove which I'd just have fixed if we weren't going around again for
> > > the binding.
> > > 
> > > Main binding thing is I don't think the odr value belongs in DT.
> > > Gain is more marginal (unless the part can actually be damaged by
> > > a wrong value - which I hope it can't!).  I'm not that fussed
> > > as there are definitely reasons to specify a default scale to
> > > cover the reasonable range on a pin.
> > > 
> > > Thanks,
> > > 
> > > Jonathan
> > Hi Jonathan,
> > 
> > Thank you for the review! So, how should I proceed?
> > 
> > First, we need an adc.txt file where "bipolar" and something like
> > "diff-
> > channels" should be documented. Should the file be placed under
> > Documentation/devicetree/bindings/iio/adc?
> Yes.
> 
> > 
> > Regarding the "odr-hz" property, it totally makes sense to remove it
> > from
> > the DT. How about the "gain"? Should we leave it in the DT and also add
> > the
> > possibility to be configured from user space?
> Look at other bindings. I think there are others having gain. If not,
> then it probably should only be user space configurable. If so, then
> can it be a common property too.
> 
> Rob
> 

Hi Rob,

I found only a couple of examples using gain in other bindings, so I guess
it's not common practice. I will remove the gain as well from the DT and
set it with the default of 1.

@Jonathan: I think that IIO_CHAN_INFO_HARDWAREGAIN is the attribute that
can be used in user space?

Thank you!
-Stefan

Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-08 Thread Rob Herring
On Thu, Nov 8, 2018 at 9:02 AM Popa, Stefan Serban
 wrote:
>
> On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:
> > On Mon, 29 Oct 2018 18:38:31 +0200
> > Stefan Popa  wrote:
> >
> > >
> > > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta
> > > ADCs
> > > with 24-bit precision and reference.
> > >
> > > Three power modes are available which in turn affect the output data
> > > rate:
> > >  * Full power: 9.38 SPS to 19,200 SPS
> > >  * Mid power: 2.34 SPS to 4800 SPS
> > >  * Low power: 1.17 SPS to 2400 SPS
> > >
> > > The ad7124-4 can be configured to have four differential inputs, while
> > > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > > configuration. Each configuration consists of gain, reference source,
> > > output data rate and bipolar/unipolar configuration.
> > >
> > > Datasheets:
> > > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > > s/AD7124-4.pdf
> > > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > > s/ad7124-8.pdf
> > >
> > > Signed-off-by: Stefan Popa 
> > Hi Stefan,
> >
> > The discussion around the DT binding has gotten me looking at bit
> > more closely at that for this version.
> >
> > Some most comments in that section.  Also a really minor ordering issue
> > in
> > remove which I'd just have fixed if we weren't going around again for
> > the binding.
> >
> > Main binding thing is I don't think the odr value belongs in DT.
> > Gain is more marginal (unless the part can actually be damaged by
> > a wrong value - which I hope it can't!).  I'm not that fussed
> > as there are definitely reasons to specify a default scale to
> > cover the reasonable range on a pin.
> >
> > Thanks,
> >
> > Jonathan
>
> Hi Jonathan,
>
> Thank you for the review! So, how should I proceed?
>
> First, we need an adc.txt file where "bipolar" and something like "diff-
> channels" should be documented. Should the file be placed under
> Documentation/devicetree/bindings/iio/adc?

Yes.

> Regarding the "odr-hz" property, it totally makes sense to remove it from
> the DT. How about the "gain"? Should we leave it in the DT and also add the
> possibility to be configured from user space?

Look at other bindings. I think there are others having gain. If not,
then it probably should only be user space configurable. If so, then
can it be a common property too.

Rob


Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-08 Thread Rob Herring
On Thu, Nov 8, 2018 at 9:02 AM Popa, Stefan Serban
 wrote:
>
> On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:
> > On Mon, 29 Oct 2018 18:38:31 +0200
> > Stefan Popa  wrote:
> >
> > >
> > > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta
> > > ADCs
> > > with 24-bit precision and reference.
> > >
> > > Three power modes are available which in turn affect the output data
> > > rate:
> > >  * Full power: 9.38 SPS to 19,200 SPS
> > >  * Mid power: 2.34 SPS to 4800 SPS
> > >  * Low power: 1.17 SPS to 2400 SPS
> > >
> > > The ad7124-4 can be configured to have four differential inputs, while
> > > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > > configuration. Each configuration consists of gain, reference source,
> > > output data rate and bipolar/unipolar configuration.
> > >
> > > Datasheets:
> > > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > > s/AD7124-4.pdf
> > > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > > s/ad7124-8.pdf
> > >
> > > Signed-off-by: Stefan Popa 
> > Hi Stefan,
> >
> > The discussion around the DT binding has gotten me looking at bit
> > more closely at that for this version.
> >
> > Some most comments in that section.  Also a really minor ordering issue
> > in
> > remove which I'd just have fixed if we weren't going around again for
> > the binding.
> >
> > Main binding thing is I don't think the odr value belongs in DT.
> > Gain is more marginal (unless the part can actually be damaged by
> > a wrong value - which I hope it can't!).  I'm not that fussed
> > as there are definitely reasons to specify a default scale to
> > cover the reasonable range on a pin.
> >
> > Thanks,
> >
> > Jonathan
>
> Hi Jonathan,
>
> Thank you for the review! So, how should I proceed?
>
> First, we need an adc.txt file where "bipolar" and something like "diff-
> channels" should be documented. Should the file be placed under
> Documentation/devicetree/bindings/iio/adc?

Yes.

> Regarding the "odr-hz" property, it totally makes sense to remove it from
> the DT. How about the "gain"? Should we leave it in the DT and also add the
> possibility to be configured from user space?

Look at other bindings. I think there are others having gain. If not,
then it probably should only be user space configurable. If so, then
can it be a common property too.

Rob


Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-08 Thread Popa, Stefan Serban
On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:
> On Mon, 29 Oct 2018 18:38:31 +0200
> Stefan Popa  wrote:
> 
> > 
> > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta
> > ADCs
> > with 24-bit precision and reference.
> > 
> > Three power modes are available which in turn affect the output data
> > rate:
> >  * Full power: 9.38 SPS to 19,200 SPS
> >  * Mid power: 2.34 SPS to 4800 SPS
> >  * Low power: 1.17 SPS to 2400 SPS
> > 
> > The ad7124-4 can be configured to have four differential inputs, while
> > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > configuration. Each configuration consists of gain, reference source,
> > output data rate and bipolar/unipolar configuration.
> > 
> > Datasheets:
> > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > s/AD7124-4.pdf
> > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > s/ad7124-8.pdf
> > 
> > Signed-off-by: Stefan Popa 
> Hi Stefan,
> 
> The discussion around the DT binding has gotten me looking at bit
> more closely at that for this version.
> 
> Some most comments in that section.  Also a really minor ordering issue
> in
> remove which I'd just have fixed if we weren't going around again for
> the binding.
> 
> Main binding thing is I don't think the odr value belongs in DT.
> Gain is more marginal (unless the part can actually be damaged by
> a wrong value - which I hope it can't!).  I'm not that fussed
> as there are definitely reasons to specify a default scale to
> cover the reasonable range on a pin.
> 
> Thanks,
> 
> Jonathan

Hi Jonathan,

Thank you for the review! So, how should I proceed?

First, we need an adc.txt file where "bipolar" and something like "diff-
channels" should be documented. Should the file be placed under
Documentation/devicetree/bindings/iio/adc?

Regarding the "odr-hz" property, it totally makes sense to remove it from
the DT. How about the "gain"? Should we leave it in the DT and also add the
possibility to be configured from user space?

Regards,
-Stefan
> > 
> > ---
> > Changes in v2:
> > - Added this commit.
> > Changes in v3:
> > - Removed channel, address, scan_index and shift fields from
> >   ad7124_channel_template.
> > - Added a sanity check for val2 in ad7124_write_raw().
> > - Used the "reg" property to get the channel address and "adi,diff-
> > channels"
> >   for the differential pins. The "adi,channel-number" property was
> > removed.
> > - When calling regulator_get_optional, the probe is given up in
> > case of error,
> >   but continues in case of -ENODEV.
> > - clk_disable_unprepare() is called before
> > ad_sd_cleanup_buffer_and_trigger
> >   in ad7124_remove().
> > 
> >  MAINTAINERS  |   7 +
> >  drivers/iio/adc/Kconfig  |  11 +
> >  drivers/iio/adc/Makefile |   1 +
> >  drivers/iio/adc/ad7124.c | 648
> > +++
> >  4 files changed, 667 insertions(+)
> >  create mode 100644 drivers/iio/adc/ad7124.c
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index f642044..3a1bfcb 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -839,6 +839,13 @@ S: Supported
> >  F: drivers/iio/dac/ad5758.c
> >  F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
> >  
> > +ANALOG DEVICES INC AD7124 DRIVER
> > +M: Stefan Popa 
> > +L: linux-...@vger.kernel.org
> > +W: http://ez.analog.com/community/linux-device-drivers
> > +S: Supported
> > +F: drivers/iio/adc/ad7124.c
> > +
> >  ANALOG DEVICES INC AD9389B DRIVER
> >  M: Hans Verkuil 
> >  L: linux-me...@vger.kernel.org
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index a52fea8..148a10f 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
> >     select IIO_BUFFER
> >     select IIO_TRIGGERED_BUFFER
> >  
> > +config AD7124
> > +   tristate "Analog Devices AD7124 and similar sigma-delta ADCs
> > driver"
> > +   depends on SPI_MASTER
> > +   select AD_SIGMA_DELTA
> > +   help
> > +     Say yes here to build support for Analog Devices AD7124-4
> > and AD7124-8
> > +     SPI analog to digital converters (ADC).
> > +
> > +     To compile this driver as a module, choose M here: the
> > module will be
> > +     called ad7124.
> > +
> >  config AD7266
> >     tristate "Analog Devices AD7265/AD7266 ADC driver"
> >     depends on SPI_MASTER
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index a6e6a0b..76168b2 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -5,6 +5,7 @@
> >  
> >  # When adding new entries keep the list in alphabetical order
> >  obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
> > +obj-$(CONFIG_AD7124) += ad7124.o
> >  obj-$(CONFIG_AD7266) += ad7266.o
> >  obj-$(CONFIG_AD7291) += ad7291.o
> >  obj-$(CONFIG_AD7298) += ad7298.o
> > diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> > new file 

Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-08 Thread Popa, Stefan Serban
On Sb, 2018-11-03 at 12:16 +, Jonathan Cameron wrote:
> On Mon, 29 Oct 2018 18:38:31 +0200
> Stefan Popa  wrote:
> 
> > 
> > The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta
> > ADCs
> > with 24-bit precision and reference.
> > 
> > Three power modes are available which in turn affect the output data
> > rate:
> >  * Full power: 9.38 SPS to 19,200 SPS
> >  * Mid power: 2.34 SPS to 4800 SPS
> >  * Low power: 1.17 SPS to 2400 SPS
> > 
> > The ad7124-4 can be configured to have four differential inputs, while
> > ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> > configuration. Each configuration consists of gain, reference source,
> > output data rate and bipolar/unipolar configuration.
> > 
> > Datasheets:
> > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > s/AD7124-4.pdf
> > Link: http://www.analog.com/media/en/technical-documentation/data-sheet
> > s/ad7124-8.pdf
> > 
> > Signed-off-by: Stefan Popa 
> Hi Stefan,
> 
> The discussion around the DT binding has gotten me looking at bit
> more closely at that for this version.
> 
> Some most comments in that section.  Also a really minor ordering issue
> in
> remove which I'd just have fixed if we weren't going around again for
> the binding.
> 
> Main binding thing is I don't think the odr value belongs in DT.
> Gain is more marginal (unless the part can actually be damaged by
> a wrong value - which I hope it can't!).  I'm not that fussed
> as there are definitely reasons to specify a default scale to
> cover the reasonable range on a pin.
> 
> Thanks,
> 
> Jonathan

Hi Jonathan,

Thank you for the review! So, how should I proceed?

First, we need an adc.txt file where "bipolar" and something like "diff-
channels" should be documented. Should the file be placed under
Documentation/devicetree/bindings/iio/adc?

Regarding the "odr-hz" property, it totally makes sense to remove it from
the DT. How about the "gain"? Should we leave it in the DT and also add the
possibility to be configured from user space?

Regards,
-Stefan
> > 
> > ---
> > Changes in v2:
> > - Added this commit.
> > Changes in v3:
> > - Removed channel, address, scan_index and shift fields from
> >   ad7124_channel_template.
> > - Added a sanity check for val2 in ad7124_write_raw().
> > - Used the "reg" property to get the channel address and "adi,diff-
> > channels"
> >   for the differential pins. The "adi,channel-number" property was
> > removed.
> > - When calling regulator_get_optional, the probe is given up in
> > case of error,
> >   but continues in case of -ENODEV.
> > - clk_disable_unprepare() is called before
> > ad_sd_cleanup_buffer_and_trigger
> >   in ad7124_remove().
> > 
> >  MAINTAINERS  |   7 +
> >  drivers/iio/adc/Kconfig  |  11 +
> >  drivers/iio/adc/Makefile |   1 +
> >  drivers/iio/adc/ad7124.c | 648
> > +++
> >  4 files changed, 667 insertions(+)
> >  create mode 100644 drivers/iio/adc/ad7124.c
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index f642044..3a1bfcb 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -839,6 +839,13 @@ S: Supported
> >  F: drivers/iio/dac/ad5758.c
> >  F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
> >  
> > +ANALOG DEVICES INC AD7124 DRIVER
> > +M: Stefan Popa 
> > +L: linux-...@vger.kernel.org
> > +W: http://ez.analog.com/community/linux-device-drivers
> > +S: Supported
> > +F: drivers/iio/adc/ad7124.c
> > +
> >  ANALOG DEVICES INC AD9389B DRIVER
> >  M: Hans Verkuil 
> >  L: linux-me...@vger.kernel.org
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index a52fea8..148a10f 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
> >     select IIO_BUFFER
> >     select IIO_TRIGGERED_BUFFER
> >  
> > +config AD7124
> > +   tristate "Analog Devices AD7124 and similar sigma-delta ADCs
> > driver"
> > +   depends on SPI_MASTER
> > +   select AD_SIGMA_DELTA
> > +   help
> > +     Say yes here to build support for Analog Devices AD7124-4
> > and AD7124-8
> > +     SPI analog to digital converters (ADC).
> > +
> > +     To compile this driver as a module, choose M here: the
> > module will be
> > +     called ad7124.
> > +
> >  config AD7266
> >     tristate "Analog Devices AD7265/AD7266 ADC driver"
> >     depends on SPI_MASTER
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index a6e6a0b..76168b2 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -5,6 +5,7 @@
> >  
> >  # When adding new entries keep the list in alphabetical order
> >  obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
> > +obj-$(CONFIG_AD7124) += ad7124.o
> >  obj-$(CONFIG_AD7266) += ad7266.o
> >  obj-$(CONFIG_AD7291) += ad7291.o
> >  obj-$(CONFIG_AD7298) += ad7298.o
> > diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> > new file 

Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-03 Thread Jonathan Cameron
On Mon, 29 Oct 2018 18:38:31 +0200
Stefan Popa  wrote:

> The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
> with 24-bit precision and reference.
> 
> Three power modes are available which in turn affect the output data rate:
>  * Full power: 9.38 SPS to 19,200 SPS
>  * Mid power: 2.34 SPS to 4800 SPS
>  * Low power: 1.17 SPS to 2400 SPS
> 
> The ad7124-4 can be configured to have four differential inputs, while
> ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> configuration. Each configuration consists of gain, reference source,
> output data rate and bipolar/unipolar configuration.
> 
> Datasheets:
> Link: 
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
> Link: 
> http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf
> 
> Signed-off-by: Stefan Popa 
Hi Stefan,

The discussion around the DT binding has gotten me looking at bit
more closely at that for this version.

Some most comments in that section.  Also a really minor ordering issue in
remove which I'd just have fixed if we weren't going around again for
the binding.

Main binding thing is I don't think the odr value belongs in DT.
Gain is more marginal (unless the part can actually be damaged by
a wrong value - which I hope it can't!).  I'm not that fussed
as there are definitely reasons to specify a default scale to
cover the reasonable range on a pin.

Thanks,

Jonathan
> ---
> Changes in v2:
>   - Added this commit.
> Changes in v3:
>   - Removed channel, address, scan_index and shift fields from
> ad7124_channel_template.
>   - Added a sanity check for val2 in ad7124_write_raw().
>   - Used the "reg" property to get the channel address and 
> "adi,diff-channels"
> for the differential pins. The "adi,channel-number" property was 
> removed.
>   - When calling regulator_get_optional, the probe is given up in case of 
> error,
> but continues in case of -ENODEV.
>   - clk_disable_unprepare() is called before 
> ad_sd_cleanup_buffer_and_trigger
> in ad7124_remove().
> 
>  MAINTAINERS  |   7 +
>  drivers/iio/adc/Kconfig  |  11 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ad7124.c | 648 
> +++
>  4 files changed, 667 insertions(+)
>  create mode 100644 drivers/iio/adc/ad7124.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index f642044..3a1bfcb 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -839,6 +839,13 @@ S:   Supported
>  F:   drivers/iio/dac/ad5758.c
>  F:   Documentation/devicetree/bindings/iio/dac/ad5758.txt
>  
> +ANALOG DEVICES INC AD7124 DRIVER
> +M:   Stefan Popa 
> +L:   linux-...@vger.kernel.org
> +W:   http://ez.analog.com/community/linux-device-drivers
> +S:   Supported
> +F:   drivers/iio/adc/ad7124.c
> +
>  ANALOG DEVICES INC AD9389B DRIVER
>  M:   Hans Verkuil 
>  L:   linux-me...@vger.kernel.org
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index a52fea8..148a10f 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
>   select IIO_BUFFER
>   select IIO_TRIGGERED_BUFFER
>  
> +config AD7124
> + tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
> + depends on SPI_MASTER
> + select AD_SIGMA_DELTA
> + help
> +   Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
> +   SPI analog to digital converters (ADC).
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called ad7124.
> +
>  config AD7266
>   tristate "Analog Devices AD7265/AD7266 ADC driver"
>   depends on SPI_MASTER
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index a6e6a0b..76168b2 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -5,6 +5,7 @@
>  
>  # When adding new entries keep the list in alphabetical order
>  obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
> +obj-$(CONFIG_AD7124) += ad7124.o
>  obj-$(CONFIG_AD7266) += ad7266.o
>  obj-$(CONFIG_AD7291) += ad7291.o
>  obj-$(CONFIG_AD7298) += ad7298.o
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> new file mode 100644
> index 000..0660135
> --- /dev/null
> +++ b/drivers/iio/adc/ad7124.c
> @@ -0,0 +1,648 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * AD7124 SPI ADC driver
> + *
> + * Copyright 2018 Analog Devices Inc.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +/* AD7124 registers */
> +#define AD7124_COMMS 0x00
> +#define AD7124_STATUS0x00
> +#define AD7124_ADC_CONTROL   0x01
> +#define AD7124_DATA  0x02
> +#define AD7124_IO_CONTROL_1  0x03
> +#define AD7124_IO_CONTROL_2  0x04
> +#define AD7124_ID 

Re: [PATCH v3 2/3] iio: adc: Add ad7124 support

2018-11-03 Thread Jonathan Cameron
On Mon, 29 Oct 2018 18:38:31 +0200
Stefan Popa  wrote:

> The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
> with 24-bit precision and reference.
> 
> Three power modes are available which in turn affect the output data rate:
>  * Full power: 9.38 SPS to 19,200 SPS
>  * Mid power: 2.34 SPS to 4800 SPS
>  * Low power: 1.17 SPS to 2400 SPS
> 
> The ad7124-4 can be configured to have four differential inputs, while
> ad7124-8 can have 8. Moreover, ad7124 also supports per channel
> configuration. Each configuration consists of gain, reference source,
> output data rate and bipolar/unipolar configuration.
> 
> Datasheets:
> Link: 
> http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
> Link: 
> http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf
> 
> Signed-off-by: Stefan Popa 
Hi Stefan,

The discussion around the DT binding has gotten me looking at bit
more closely at that for this version.

Some most comments in that section.  Also a really minor ordering issue in
remove which I'd just have fixed if we weren't going around again for
the binding.

Main binding thing is I don't think the odr value belongs in DT.
Gain is more marginal (unless the part can actually be damaged by
a wrong value - which I hope it can't!).  I'm not that fussed
as there are definitely reasons to specify a default scale to
cover the reasonable range on a pin.

Thanks,

Jonathan
> ---
> Changes in v2:
>   - Added this commit.
> Changes in v3:
>   - Removed channel, address, scan_index and shift fields from
> ad7124_channel_template.
>   - Added a sanity check for val2 in ad7124_write_raw().
>   - Used the "reg" property to get the channel address and 
> "adi,diff-channels"
> for the differential pins. The "adi,channel-number" property was 
> removed.
>   - When calling regulator_get_optional, the probe is given up in case of 
> error,
> but continues in case of -ENODEV.
>   - clk_disable_unprepare() is called before 
> ad_sd_cleanup_buffer_and_trigger
> in ad7124_remove().
> 
>  MAINTAINERS  |   7 +
>  drivers/iio/adc/Kconfig  |  11 +
>  drivers/iio/adc/Makefile |   1 +
>  drivers/iio/adc/ad7124.c | 648 
> +++
>  4 files changed, 667 insertions(+)
>  create mode 100644 drivers/iio/adc/ad7124.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index f642044..3a1bfcb 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -839,6 +839,13 @@ S:   Supported
>  F:   drivers/iio/dac/ad5758.c
>  F:   Documentation/devicetree/bindings/iio/dac/ad5758.txt
>  
> +ANALOG DEVICES INC AD7124 DRIVER
> +M:   Stefan Popa 
> +L:   linux-...@vger.kernel.org
> +W:   http://ez.analog.com/community/linux-device-drivers
> +S:   Supported
> +F:   drivers/iio/adc/ad7124.c
> +
>  ANALOG DEVICES INC AD9389B DRIVER
>  M:   Hans Verkuil 
>  L:   linux-me...@vger.kernel.org
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index a52fea8..148a10f 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
>   select IIO_BUFFER
>   select IIO_TRIGGERED_BUFFER
>  
> +config AD7124
> + tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
> + depends on SPI_MASTER
> + select AD_SIGMA_DELTA
> + help
> +   Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
> +   SPI analog to digital converters (ADC).
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called ad7124.
> +
>  config AD7266
>   tristate "Analog Devices AD7265/AD7266 ADC driver"
>   depends on SPI_MASTER
> diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> index a6e6a0b..76168b2 100644
> --- a/drivers/iio/adc/Makefile
> +++ b/drivers/iio/adc/Makefile
> @@ -5,6 +5,7 @@
>  
>  # When adding new entries keep the list in alphabetical order
>  obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
> +obj-$(CONFIG_AD7124) += ad7124.o
>  obj-$(CONFIG_AD7266) += ad7266.o
>  obj-$(CONFIG_AD7291) += ad7291.o
>  obj-$(CONFIG_AD7298) += ad7298.o
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> new file mode 100644
> index 000..0660135
> --- /dev/null
> +++ b/drivers/iio/adc/ad7124.c
> @@ -0,0 +1,648 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * AD7124 SPI ADC driver
> + *
> + * Copyright 2018 Analog Devices Inc.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +/* AD7124 registers */
> +#define AD7124_COMMS 0x00
> +#define AD7124_STATUS0x00
> +#define AD7124_ADC_CONTROL   0x01
> +#define AD7124_DATA  0x02
> +#define AD7124_IO_CONTROL_1  0x03
> +#define AD7124_IO_CONTROL_2  0x04
> +#define AD7124_ID 

[PATCH v3 2/3] iio: adc: Add ad7124 support

2018-10-29 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added this commit.
Changes in v3:
- Removed channel, address, scan_index and shift fields from
  ad7124_channel_template.
- Added a sanity check for val2 in ad7124_write_raw().
- Used the "reg" property to get the channel address and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- When calling regulator_get_optional, the probe is given up in case of 
error,
  but continues in case of -ENODEV.
- clk_disable_unprepare() is called before 
ad_sd_cleanup_buffer_and_trigger
  in ad7124_remove().

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 648 +++
 4 files changed, 667 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..0660135
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,648 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x)  (0x09 + (x))
+#define AD7124_CONFIG(x)   (0x19 + (x))
+#define AD7124_FILTER(x)   (0x21 + (x))
+#define AD7124_OFFSET(x)   (0x29 + (x))
+#define AD7124_GAIN(x) (0x31 + (x))
+
+/* AD7124_STATUS */
+#define AD7124_STATUS_POR_FLAG_MSK BIT(4)
+
+/* AD7124_ADC_CONTROL */
+#define AD7124_ADC_CTRL_PWR_MSKGENMASK(7, 6)
+#define AD7124_ADC_CTRL_PWR(x) FIELD_PREP(AD7124_ADC_CTRL_PWR_MSK, x)
+#define AD7124_ADC_CTRL_MODE_MSK   GENMASK(5, 2)
+#define AD7124_ADC_CTRL_MODE(x)FIELD_PREP(AD7124_ADC_CTRL_MODE_MSK, x)
+
+/* AD7124_CHANNEL_X */
+#define AD7124_CHANNEL_EN_MSK  

[PATCH v3 2/3] iio: adc: Add ad7124 support

2018-10-29 Thread Stefan Popa
The ad7124-4 and ad7124-8 are a family of 4 and 8 channel sigma-delta ADCs
with 24-bit precision and reference.

Three power modes are available which in turn affect the output data rate:
 * Full power: 9.38 SPS to 19,200 SPS
 * Mid power: 2.34 SPS to 4800 SPS
 * Low power: 1.17 SPS to 2400 SPS

The ad7124-4 can be configured to have four differential inputs, while
ad7124-8 can have 8. Moreover, ad7124 also supports per channel
configuration. Each configuration consists of gain, reference source,
output data rate and bipolar/unipolar configuration.

Datasheets:
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7124-4.pdf
Link: 
http://www.analog.com/media/en/technical-documentation/data-sheets/ad7124-8.pdf

Signed-off-by: Stefan Popa 
---
Changes in v2:
- Added this commit.
Changes in v3:
- Removed channel, address, scan_index and shift fields from
  ad7124_channel_template.
- Added a sanity check for val2 in ad7124_write_raw().
- Used the "reg" property to get the channel address and 
"adi,diff-channels"
  for the differential pins. The "adi,channel-number" property was 
removed.
- When calling regulator_get_optional, the probe is given up in case of 
error,
  but continues in case of -ENODEV.
- clk_disable_unprepare() is called before 
ad_sd_cleanup_buffer_and_trigger
  in ad7124_remove().

 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  11 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7124.c | 648 +++
 4 files changed, 667 insertions(+)
 create mode 100644 drivers/iio/adc/ad7124.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f642044..3a1bfcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -839,6 +839,13 @@ S: Supported
 F: drivers/iio/dac/ad5758.c
 F: Documentation/devicetree/bindings/iio/dac/ad5758.txt
 
+ANALOG DEVICES INC AD7124 DRIVER
+M: Stefan Popa 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7124.c
+
 ANALOG DEVICES INC AD9389B DRIVER
 M: Hans Verkuil 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index a52fea8..148a10f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -10,6 +10,17 @@ config AD_SIGMA_DELTA
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
 
+config AD7124
+   tristate "Analog Devices AD7124 and similar sigma-delta ADCs driver"
+   depends on SPI_MASTER
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7124-4 and AD7124-8
+ SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the module will be
+ called ad7124.
+
 config AD7266
tristate "Analog Devices AD7265/AD7266 ADC driver"
depends on SPI_MASTER
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index a6e6a0b..76168b2 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -5,6 +5,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
+obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7298) += ad7298.o
diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
new file mode 100644
index 000..0660135
--- /dev/null
+++ b/drivers/iio/adc/ad7124.c
@@ -0,0 +1,648 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AD7124 SPI ADC driver
+ *
+ * Copyright 2018 Analog Devices Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+/* AD7124 registers */
+#define AD7124_COMMS   0x00
+#define AD7124_STATUS  0x00
+#define AD7124_ADC_CONTROL 0x01
+#define AD7124_DATA0x02
+#define AD7124_IO_CONTROL_10x03
+#define AD7124_IO_CONTROL_20x04
+#define AD7124_ID  0x05
+#define AD7124_ERROR   0x06
+#define AD7124_ERROR_EN0x07
+#define AD7124_MCLK_COUNT  0x08
+#define AD7124_CHANNEL(x)  (0x09 + (x))
+#define AD7124_CONFIG(x)   (0x19 + (x))
+#define AD7124_FILTER(x)   (0x21 + (x))
+#define AD7124_OFFSET(x)   (0x29 + (x))
+#define AD7124_GAIN(x) (0x31 + (x))
+
+/* AD7124_STATUS */
+#define AD7124_STATUS_POR_FLAG_MSK BIT(4)
+
+/* AD7124_ADC_CONTROL */
+#define AD7124_ADC_CTRL_PWR_MSKGENMASK(7, 6)
+#define AD7124_ADC_CTRL_PWR(x) FIELD_PREP(AD7124_ADC_CTRL_PWR_MSK, x)
+#define AD7124_ADC_CTRL_MODE_MSK   GENMASK(5, 2)
+#define AD7124_ADC_CTRL_MODE(x)FIELD_PREP(AD7124_ADC_CTRL_MODE_MSK, x)
+
+/* AD7124_CHANNEL_X */
+#define AD7124_CHANNEL_EN_MSK