Re: [PATCH] iio: adc: ad7292: Modify the bool initialization assignment

2021-03-20 Thread Marcelo Schmitt
Okay, looks good to me.

Reviewed-by: Marcelo Schmitt 

On 03/19, Guoqing chi wrote:
> From: Guoqing Chi 
> 
> A bool initializer is best assigned to false rather than 0.
> 
> Signed-off-by: Guoqing Chi 
> ---
>  drivers/iio/adc/ad7292.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> index 70e33dd1c9f7..3271a31afde1 100644
> --- a/drivers/iio/adc/ad7292.c
> +++ b/drivers/iio/adc/ad7292.c
> @@ -260,7 +260,7 @@ static int ad7292_probe(struct spi_device *spi)
>   struct ad7292_state *st;
>   struct iio_dev *indio_dev;
>   struct device_node *child;
> - bool diff_channels = 0;
> + bool diff_channels = false;
>   int ret;
>  
>   indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
> -- 
> 2.17.1
> 
> 


Re: [PATCH] iio: adc: ad7292: remove unneeded spi_set_drvdata()

2020-11-20 Thread Marcelo Schmitt
LGTM.
Tested on raspberry pi kernel - rpi-5.9.y.

ad7292 was heavily based on ad7768-1. 
Maybe this might apply to ad7768-1 as well.

Reviewed-by: Marcelo Schmitt 
Tested-by: Marcelo Schmitt 

On 11/19, Alexandru Ardelean wrote:
> This seems to have been copied from a driver that calls spi_set_drvdata()
> but doesn't call spi_get_drvdata().
> Setting a private object on the SPI device's object isn't necessary if it
> won't be accessed.
> This change removes the spi_set_drvdata() call.
> 
> Signed-off-by: Alexandru Ardelean 
> ---
>  drivers/iio/adc/ad7292.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> index ab204e9199e9..70e33dd1c9f7 100644
> --- a/drivers/iio/adc/ad7292.c
> +++ b/drivers/iio/adc/ad7292.c
> @@ -276,8 +276,6 @@ static int ad7292_probe(struct spi_device *spi)
>   return -EINVAL;
>   }
>  
> - spi_set_drvdata(spi, indio_dev);
> -
>   st->reg = devm_regulator_get_optional(>dev, "vref");
>   if (!IS_ERR(st->reg)) {
>   ret = regulator_enable(st->reg);
> -- 
> 2.17.1
> 


[PATCH] kunit: tool: adjust parse regex

2020-07-28 Thread Marcelo Schmitt
kunit config subcommand terminates with error if .config has a
configuration assigned with a string, for instance:

CONFIG_CC_VERSION_TEXT="gcc (distro package version) ..."

This patch adjusts the parse regex to consider such string assignments.

Signed-off-by: Marcelo Schmitt 
---
 tools/testing/kunit/kunit_config.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/kunit/kunit_config.py 
b/tools/testing/kunit/kunit_config.py
index e75063d603b5..8e55693fe812 100644
--- a/tools/testing/kunit/kunit_config.py
+++ b/tools/testing/kunit/kunit_config.py
@@ -10,7 +10,7 @@ import collections
 import re
 
 CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$'
-CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+)$'
+CONFIG_PATTERN = r'^CONFIG_(\w+)=((\S+)|(".*"))$'
 
 KconfigEntryBase = collections.namedtuple('KconfigEntry', ['name', 'value'])
 
-- 
2.27.0



Re: [PATCH v2 2/2] dt-bindings: iio: adc: Add DT docs for AD7292

2019-10-22 Thread Marcelo Schmitt
Hi Rob,

OK, thanks for the explanation.

I indeed missed some details from the documentation. I will be more
careful on my next readings.

I see there are other documentation files at Documentation/devicetree/
and Documentation/devicetree/bindings/. Besides these, would you
recommend other documentation and/or material for those who want to
write dt-bindings that validate with dt-schema?

Thanks in advance,

Marcelo

On 10/22, Rob Herring wrote:
> On Tue, Oct 22, 2019 at 9:06 AM Marcelo Schmitt
>  wrote:
> >
> > Hi,
> >
> > I ran the DTC and CHECK for AD7292 schema however, the target '__build'
> > did not run due to errors found in regulator/fixed-regulator.yaml and
> > arm/allwinner,sun4i-a10-csi.yaml.
> 
> Fixes for those are still pending in -next. Use 'make -k' and ignore those.
> 
> >
> > I recall seeing something about the maxItems requirement over regulator
> > supplies being changed on the iio mailing list, so I updated my repo
> > locally, cloned and reinstalled the dt-schema toolset. However, I still
> > can't make it go through the '__build' target.
> >
> > Python 3.7.5rc1 is my default python and I got the following pip3
> > packages installed:
> >
> > ruamel.yaml0.16.5
> > ruamel.yaml.clib   0.2.0
> > rfc39871.3.8
> > jsonschema 3.0.1
> > dtschema   0.0.1  at $HOME//dt-schema
> >
> > Debian Bullseye packages installed:
> > python3-yaml/testing,now 5.1.2-1
> > libyaml-dev/testing,now 0.2.2-1
> >
> > I was only able to run DTC after installing the libyaml-dev package, so
> > I think it might be worth to add it to the project dependencies at
> > https://github.com/robherring/dt-schema.
> 
> Strictly speaking, it's not a dependency for dt-schema. It's
> documented in Documentation/devicetree/writing-schema.rst. I've added
> a pointer to that in bindings/submitting-patches.txt. I'm not sure how
> else to make it more obvious.
> 
> BTW, You will get a useful error message if libyaml is missing when
> building 'make dtbs_check'. I need to make that work for
> dt_binding_check.
> 
> > apt-get install libyaml-dev
> 
> You need the lib too, but that tends to already be installed. IIRC,
> installing the headers doesn't install the lib automatically.
> 
> In any case, I wanted to avoid putting in distro specific instructions
> in the kernel.
> 
> Rob
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Kernel USP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to kernel-usp+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/kernel-usp/CAL_JsqLf8kpOu0MQN-TAhQkiZCGfMKWmztnHNo%2B2BAVqfX8yGQ%40mail.gmail.com.


Re: [PATCH v2 1/2] iio: adc: Add driver support for AD7292

2019-10-22 Thread Marcelo Schmitt
Hi Jonathan,

Should I send a V3 for the whole patchset or just for the DT binding patch?

Thanks,

Marcelo

On 10/21, Jonathan Cameron wrote:
> On Tue, 15 Oct 2019 23:51:22 -0300
> Marcelo Schmitt  wrote:
> 
> > The AD7292 is a 10-bit monitor and control system with ADC, DACs,
> > temperature sensor, and GPIOs.
> > 
> > Configure AD7292 devices in direct access mode, enabling single-ended
> > ADC readings.
> > 
> > Datasheet:
> > Link: 
> > https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf
> > 
> > Signed-off-by: Marcelo Schmitt 
> This looks fine to me.
> 
> Assuming nothing else comes up, I'll pick this up once the binding was tidied 
> up.
> 
> Thanks,
> 
> Jonathan
> 


Re: [PATCH v2 2/2] dt-bindings: iio: adc: Add DT docs for AD7292

2019-10-22 Thread Marcelo Schmitt
Hi,

I ran the DTC and CHECK for AD7292 schema however, the target '__build'
did not run due to errors found in regulator/fixed-regulator.yaml and
arm/allwinner,sun4i-a10-csi.yaml.

I recall seeing something about the maxItems requirement over regulator
supplies being changed on the iio mailing list, so I updated my repo
locally, cloned and reinstalled the dt-schema toolset. However, I still
can't make it go through the '__build' target.

Python 3.7.5rc1 is my default python and I got the following pip3
packages installed:

ruamel.yaml0.16.5
ruamel.yaml.clib   0.2.0
rfc39871.3.8
jsonschema 3.0.1
dtschema   0.0.1  at $HOME//dt-schema

Debian Bullseye packages installed:
python3-yaml/testing,now 5.1.2-1
libyaml-dev/testing,now 0.2.2-1

I was only able to run DTC after installing the libyaml-dev package, so
I think it might be worth to add it to the project dependencies at
https://github.com/robherring/dt-schema.

apt-get install libyaml-dev

Thanks,
Marcelo

On 10/20, Rob Herring wrote:
> On Sat, Oct 19, 2019 at 10:07 AM Marcelo Schmitt
>  wrote:
> >
> > Hi Rob
> >
> > Thanks for the review.
> >
> > I'm having some trouble with the DTC.
> > I installed the DT tool from https://github.com/robherring/dt-schema.
> > Running make -k dt_binding_check goes through all the checks (CHKDT), 
> > producing
> > the .example.dts files but then gives errors like:
> >
> >   DTC Documentation/devicetree/bindings/arm/calxeda.example.dt.yaml
> > FATAL ERROR: Unknown output format "yaml"
> > make[1]: *** [scripts/Makefile.lib:314: 
> > Documentation/devicetree/bindings/arm/calxeda.example.dt.yaml] Error 1
> > make[1]: *** Deleting file 
> > 'Documentation/devicetree/bindings/arm/calxeda.example.dt.yaml'
> >
> > My pip3 installation has:
> > jsonschema jsonschema-3.1.2.dev6+g0d827f3
> > rfc3987 1.3.8
> >
> > $HOME/.local/bin is listed in my shell's PATH variable.
> >
> > I was trying to follow the documentation at:
> > Documentation/devicetree/writing-schema.rst
> >
> > Are there any other DTC dependencies that I am missing?
> 
> Yes, libyaml. See Documentation/devicetree/writing-schema.rst.
> 
> Rob


Re: [PATCH v2 2/2] dt-bindings: iio: adc: Add DT docs for AD7292

2019-10-19 Thread Marcelo Schmitt
Hi Rob

Thanks for the review.

I'm having some trouble with the DTC.
I installed the DT tool from https://github.com/robherring/dt-schema.
Running make -k dt_binding_check goes through all the checks (CHKDT), producing
the .example.dts files but then gives errors like:

  DTC Documentation/devicetree/bindings/arm/calxeda.example.dt.yaml
FATAL ERROR: Unknown output format "yaml"
make[1]: *** [scripts/Makefile.lib:314: 
Documentation/devicetree/bindings/arm/calxeda.example.dt.yaml] Error 1
make[1]: *** Deleting file 
'Documentation/devicetree/bindings/arm/calxeda.example.dt.yaml'

My pip3 installation has:
jsonschema jsonschema-3.1.2.dev6+g0d827f3
rfc3987 1.3.8

$HOME/.local/bin is listed in my shell's PATH variable.

I was trying to follow the documentation at:
Documentation/devicetree/writing-schema.rst

Are there any other DTC dependencies that I am missing?

On 10/17, Rob Herring wrote:
> On Tue, Oct 15, 2019 at 11:52:23PM -0300, Marcelo Schmitt wrote:
> > Add a device tree binding doc for AD7292 monitor and control system.
> > 
> > Signed-off-by: Marcelo Schmitt 
> > ---
> >  .../bindings/iio/adc/adi,ad7292.yaml  | 107 ++
> >  MAINTAINERS   |   1 +
> >  2 files changed, 108 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
> > 
> > diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml 
> > b/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
> > new file mode 100644
> > index ..40028332d9e2
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
> > @@ -0,0 +1,107 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/iio/adc/adi,ad7292.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Analog Devices AD7292 10-Bit Monitor and Control System
> > +
> > +maintainers:
> > +  - Marcelo Schmitt 
> > +
> > +description: |
> > +  Analog Devices AD7292 10-Bit Monitor and Control System with ADC, DACs,
> > +  Temperature Sensor, and GPIOs
> > +
> > +  Specifications about the part can be found at:
> > +
> > https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf
> > +
> > +properties:
> > +  compatible:
> > +enum:
> > +  - adi,ad7292
> > +
> > +  reg:
> > +maxItems: 1
> > +
> > +  vref-supply:
> > +description: |
> > +  The regulator supply for ADC and DAC reference voltage.
> > +maxItems: 1
> 
> Not necessary, regulator supplies are always 1 item, so drop maxItems.
> 
> > +
> > +  spi-cpha:
> > +description: |
> > +  See Documentation/devicetree/bindings/spi/spi-controller.yaml
> > +maxItems: 1
> 
> This is just wrong because spi-cpha is a boolean. Just 'spi-cpha: true' 
> is sufficient. If this device needs this property, then it should 
> probably be required.
> 
> > +
> > +  '#address-cells':
> > +const: 1
> > +
> > +  '#size-cells':
> > +const: 0
> > +
> > +required:
> > +  - compatible
> > +  - reg
> > +
> > +patternProperties:
> > +  "^channel@[0-7]$":
> > +type: object
> > +description: |
> > +  Represents the external channels which are connected to the ADC.
> > +  See Documentation/devicetree/bindings/iio/adc/adc.txt.
> > +
> > +properties:
> > +  reg:
> > +description: |
> > +  The channel number. It can have up to 8 channels numbered from 0 
> > to 7.
> > +maxItems: 1
> > +
> > +  diff-channels:
> > +description: see Documentation/devicetree/bindings/iio/adc/adc.txt
> > +maxItems: 1
> > +
> > +required:
> > +  - reg
> > +
> > +examples:
> > +  - |
> > +spi {
> > +  #address-cells = <1>;
> > +  #size-cells = <0>;
> > +
> > +  ad7292: ad7292@0 {
> 
> adc@0
> 
> > +compatible = "adi,ad7292";
> > +reg = <0>;
> > +
> > +#address-cells = <1>;
> > +#size-cells = <0>;
> > +
> > +spi-max-frequency = <2500>;
> > +vref-supply = <_vref>;
> > +spi-cpha;
> > +
> > +channel@0 {
> > +  reg = <0>;
> > +  diff-channels = <0 1>;
> > +};
> > +channel@2 {
> > +  reg = <2>;
> > +};
> > +channel@3 {
> > +  reg = <3>;
> > +};
> > +channel@4 {
> > +  reg = <4>;
> > +};
> > +channel@5 {
> > +  reg = <5>;
> > +};
> > +channel@6 {
> > +  reg = <6>;
> > +};
> > +channel@7 {
> > +  reg = <7>;
> > +};
> > +  };
> > +}
> 
> Missing ';'. Make sure this builds with 'make -k dt_binding_check'. The 
> '-k' is due to some other breakage ATM.
> 
> Rob


[PATCH v2 2/2] dt-bindings: iio: adc: Add DT docs for AD7292

2019-10-15 Thread Marcelo Schmitt
Add a device tree binding doc for AD7292 monitor and control system.

Signed-off-by: Marcelo Schmitt 
---
 .../bindings/iio/adc/adi,ad7292.yaml  | 107 ++
 MAINTAINERS   |   1 +
 2 files changed, 108 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
new file mode 100644
index ..40028332d9e2
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
@@ -0,0 +1,107 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7292.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7292 10-Bit Monitor and Control System
+
+maintainers:
+  - Marcelo Schmitt 
+
+description: |
+  Analog Devices AD7292 10-Bit Monitor and Control System with ADC, DACs,
+  Temperature Sensor, and GPIOs
+
+  Specifications about the part can be found at:
+
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,ad7292
+
+  reg:
+maxItems: 1
+
+  vref-supply:
+description: |
+  The regulator supply for ADC and DAC reference voltage.
+maxItems: 1
+
+  spi-cpha:
+description: |
+  See Documentation/devicetree/bindings/spi/spi-controller.yaml
+maxItems: 1
+
+  '#address-cells':
+const: 1
+
+  '#size-cells':
+const: 0
+
+required:
+  - compatible
+  - reg
+
+patternProperties:
+  "^channel@[0-7]$":
+type: object
+description: |
+  Represents the external channels which are connected to the ADC.
+  See Documentation/devicetree/bindings/iio/adc/adc.txt.
+
+properties:
+  reg:
+description: |
+  The channel number. It can have up to 8 channels numbered from 0 to 
7.
+maxItems: 1
+
+  diff-channels:
+description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+maxItems: 1
+
+required:
+  - reg
+
+examples:
+  - |
+spi {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  ad7292: ad7292@0 {
+compatible = "adi,ad7292";
+reg = <0>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+spi-max-frequency = <2500>;
+vref-supply = <_vref>;
+spi-cpha;
+
+channel@0 {
+  reg = <0>;
+  diff-channels = <0 1>;
+};
+channel@2 {
+  reg = <2>;
+};
+channel@3 {
+  reg = <3>;
+};
+channel@4 {
+  reg = <4>;
+};
+channel@5 {
+  reg = <5>;
+};
+channel@6 {
+  reg = <6>;
+};
+channel@7 {
+  reg = <7>;
+};
+  };
+}
diff --git a/MAINTAINERS b/MAINTAINERS
index e78317a5f4f1..5941cfc0d6f7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -819,6 +819,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7292.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
 
 ANALOG DEVICES INC AD7606 DRIVER
 M: Stefan Popa 
-- 
2.23.0



[PATCH v2 1/2] iio: adc: Add driver support for AD7292

2019-10-15 Thread Marcelo Schmitt
The AD7292 is a 10-bit monitor and control system with ADC, DACs,
temperature sensor, and GPIOs.

Configure AD7292 devices in direct access mode, enabling single-ended
ADC readings.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf

Signed-off-by: Marcelo Schmitt 
---
 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  10 ++
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7292.c | 350 +++
 4 files changed, 368 insertions(+)
 create mode 100644 drivers/iio/adc/ad7292.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 32bf5f8116d0..e78317a5f4f1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -813,6 +813,13 @@ S: Supported
 F: drivers/iio/adc/ad7124.c
 F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
+ANALOG DEVICES INC AD7292 DRIVER
+M: Marcelo Schmitt 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7292.c
+
 ANALOG DEVICES INC AD7606 DRIVER
 M: Stefan Popa 
 L: linux-...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 632b331429c6..02587c990cb5 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -59,6 +59,16 @@ config AD7291
  To compile this driver as a module, choose M here: the
  module will be called ad7291.
 
+config AD7292
+   tristate "Analog Devices AD7292 ADC driver"
+   depends on SPI
+   help
+ Say yes here to build support for Analog Devices AD7292
+ 8 Channel ADC with temperature sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad7292.
+
 config AD7298
tristate "Analog Devices AD7298 ADC driver"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 4779ab3ff8fb..1818f2f66566 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7173) += ad7173.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
+obj-$(CONFIG_AD7292) += ad7292.o
 obj-$(CONFIG_AD7298) += ad7298.o
 obj-$(CONFIG_AD738X) += ad738x.o
 obj-$(CONFIG_AD7768) += ad7768-1.o
diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
new file mode 100644
index ..d90c7af8f6c2
--- /dev/null
+++ b/drivers/iio/adc/ad7292.c
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices AD7292 SPI ADC driver
+ *
+ * Copyright 2019 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define ADI_VENDOR_ID 0x0018
+
+/* AD7292 registers definition */
+#define AD7292_REG_VENDOR_ID   0x00
+#define AD7292_REG_CONF_BANK   0x05
+#define AD7292_REG_CONV_COMM   0x0E
+#define AD7292_REG_ADC_CH(x)   (0x10 + (x))
+
+/* AD7292 configuration bank subregisters definition */
+#define AD7292_BANK_REG_VIN_RNG0   0x10
+#define AD7292_BANK_REG_VIN_RNG1   0x11
+#define AD7292_BANK_REG_SAMP_MODE  0x12
+
+#define AD7292_RD_FLAG_MSK(x)  (BIT(7) | ((x) & 0x3F))
+
+/* AD7292_REG_ADC_CONVERSION */
+#define AD7292_ADC_DATA_MASK   GENMASK(15, 6)
+#define AD7292_ADC_DATA(x) FIELD_GET(AD7292_ADC_DATA_MASK, x)
+
+/* AD7292_CHANNEL_SAMPLING_MODE */
+#define AD7292_CH_SAMP_MODE(reg, ch)   ((reg >> 8) & BIT(ch))
+
+/* AD7292_CHANNEL_VIN_RANGE */
+#define AD7292_CH_VIN_RANGE(reg, ch)   (reg & BIT(ch))
+
+#define AD7291_VOLTAGE_CHAN(_chan) \
+{  \
+   .type = IIO_VOLTAGE,\
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
+ BIT(IIO_CHAN_INFO_SCALE), \
+   .indexed = 1,   \
+   .channel = _chan,   \
+}
+
+static const struct iio_chan_spec ad7292_channels[] = {
+   AD7291_VOLTAGE_CHAN(0),
+   AD7291_VOLTAGE_CHAN(1),
+   AD7291_VOLTAGE_CHAN(2),
+   AD7291_VOLTAGE_CHAN(3),
+   AD7291_VOLTAGE_CHAN(4),
+   AD7291_VOLTAGE_CHAN(5),
+   AD7291_VOLTAGE_CHAN(6),
+   AD7291_VOLTAGE_CHAN(7)
+};
+
+static const struct iio_chan_spec ad7292_channels_diff[] = {
+   {
+   .type = IIO_VOLTAGE,
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+   .indexed = 1,
+   .differential = 1,
+   .channel = 0,
+   .channel2 = 1,
+   },
+   AD7291_VOLTAGE_CHAN(2),
+   AD7291_VOLTAGE_CHAN(3),
+   AD7291_VOLTAGE_CHAN(4),
+   AD7291_VOLTAGE_CHAN(5),
+   AD7291_VOLTAGE_CHAN(6),
+   AD7291_VOLTAGE_CHAN(7)
+};
+
+struct ad7292_state {
+   struct spi_devi

[PATCH v2 0/2] iio: adc: Add driver support for AD7292

2019-10-15 Thread Marcelo Schmitt
This patchset adds a basic driver for the AD7292 ADC/DAC system along
with device tree binding documentation.

Changelog V2:
- made SPI rx/tx buffers separated fields in the state struct
- adjusted spi_transfer tx_buf pointer
- at probe, stored vref supply for later reference 
- removed regulator_get_voltage() from read_raw() INFO_SCALE
- added a comment to make clear when internal voltage reference will be used
- use standard channel definition to specify the ADC channels in dt-binding doc

Marcelo Schmitt (2):
  iio: adc: Add driver support for AD7292
  dt-bindings: iio: adc: Add DT docs for AD7292

 .../bindings/iio/adc/adi,ad7292.yaml  | 107 ++
 MAINTAINERS   |   8 +
 drivers/iio/adc/Kconfig   |  10 +
 drivers/iio/adc/Makefile  |   1 +
 drivers/iio/adc/ad7292.c  | 350 ++
 5 files changed, 476 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
 create mode 100644 drivers/iio/adc/ad7292.c

-- 
2.23.0



Re: [PATCH 1/2] iio: adc: Add driver support for AD7292

2019-10-15 Thread Marcelo Schmitt
Hi Jonathan,

Thanks for the review. I'll send a v2 soon.

On 10/14, Jonathan Cameron wrote:
> On Sun, 13 Oct 2019 11:13:22 -0300
> Marcelo Schmitt  wrote:
> 
> > The AD7292 is a 10-bit monitor and control system with ADC, DACs,
> > temperature sensor, and GPIOs.
> > 
> > Configure AD7292 devices in direct access mode, enabling single-ended
> > ADC readings.
> > 
> > Datasheet:
> > Link: 
> > https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf
> > 
> > Signed-off-by: Marcelo Schmitt 
> Hi Marcelo
> 
> A few minor bits inline.  Mostly just the DT binding question.
> 
> Thanks,
> 
> Jonathan
> 
> > ---
> >  MAINTAINERS  |   7 +
> >  drivers/iio/adc/Kconfig  |  10 ++
> >  drivers/iio/adc/Makefile |   1 +
> >  drivers/iio/adc/ad7292.c | 350 +++
> >  4 files changed, 368 insertions(+)
> >  create mode 100644 drivers/iio/adc/ad7292.c
> > 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 32bf5f8116d0..e78317a5f4f1 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -813,6 +813,13 @@ S:     Supported
> >  F: drivers/iio/adc/ad7124.c
> >  F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
> >  
> > +ANALOG DEVICES INC AD7292 DRIVER
> > +M: Marcelo Schmitt 
> > +L: linux-...@vger.kernel.org
> > +W: http://ez.analog.com/community/linux-device-drivers
> > +S: Supported
> > +F: drivers/iio/adc/ad7292.c
> > +
> >  ANALOG DEVICES INC AD7606 DRIVER
> >  M: Stefan Popa 
> >  L: linux-...@vger.kernel.org
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index 632b331429c6..02587c990cb5 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -59,6 +59,16 @@ config AD7291
> >   To compile this driver as a module, choose M here: the
> >   module will be called ad7291.
> >  
> > +config AD7292
> > +   tristate "Analog Devices AD7292 ADC driver"
> > +   depends on SPI
> > +   help
> > + Say yes here to build support for Analog Devices AD7292
> > + 8 Channel ADC with temperature sensor.
> > +
> > + To compile this driver as a module, choose M here: the
> > + module will be called ad7292.
> > +
> >  config AD7298
> > tristate "Analog Devices AD7298 ADC driver"
> > depends on SPI
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
> > index 4779ab3ff8fb..1818f2f66566 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -11,6 +11,7 @@ obj-$(CONFIG_AD7124) += ad7124.o
> >  obj-$(CONFIG_AD7173) += ad7173.o
> >  obj-$(CONFIG_AD7266) += ad7266.o
> >  obj-$(CONFIG_AD7291) += ad7291.o
> > +obj-$(CONFIG_AD7292) += ad7292.o
> >  obj-$(CONFIG_AD7298) += ad7298.o
> >  obj-$(CONFIG_AD738X) += ad738x.o
> >  obj-$(CONFIG_AD7768) += ad7768-1.o
> > diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> > new file mode 100644
> > index ..076bd49a2571
> > --- /dev/null
> > +++ b/drivers/iio/adc/ad7292.c
> > @@ -0,0 +1,350 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Analog Devices AD7292 SPI ADC driver
> > + *
> > + * Copyright 2019 Analog Devices Inc.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +
> > +#define ADI_VENDOR_ID 0x0018
> > +
> > +/* AD7292 registers definition */
> > +#define AD7292_REG_VENDOR_ID   0x00
> > +#define AD7292_REG_CONF_BANK   0x05
> > +#define AD7292_REG_CONV_COMM   0x0E
> > +#define AD7292_REG_ADC_CH(x)   (0x10 + (x))
> > +
> > +/* AD7292 configuration bank subregisters definition */
> > +#define AD7292_BANK_REG_VIN_RNG0   0x10
> > +#define AD7292_BANK_REG_VIN_RNG1   0x11
> > +#define AD7292_BANK_REG_SAMP_MODE  0x12
> > +
> > +#define AD7292_RD_FLAG_MSK(x)  (BIT(7) | ((x) & 0x3F))
> > +
> > +/* AD7292_REG_ADC_CONVERSION */
> > +#define AD7292_ADC_DATA_MASK   GENMASK(15, 6)
> > +#define AD7292_ADC_DATA(x) FIELD_GET(AD7292_ADC_DATA_MASK, x)
> > +
> > +/* AD7292_CHANNEL_SAMPLING_MODE */
> > +#define AD7292_CH_SAMP_MODE(reg, ch)   ((reg >> 8) & BIT(ch))
> > +
> > +/* AD7292_CHANNEL_VIN_RANGE */
> > +#define AD7292_CH_VIN_RANGE(reg, ch)   (reg & BIT

[PATCH 1/2] iio: adc: Add driver support for AD7292

2019-10-13 Thread Marcelo Schmitt
The AD7292 is a 10-bit monitor and control system with ADC, DACs,
temperature sensor, and GPIOs.

Configure AD7292 devices in direct access mode, enabling single-ended
ADC readings.

Datasheet:
Link: 
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf

Signed-off-by: Marcelo Schmitt 
---
 MAINTAINERS  |   7 +
 drivers/iio/adc/Kconfig  |  10 ++
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad7292.c | 350 +++
 4 files changed, 368 insertions(+)
 create mode 100644 drivers/iio/adc/ad7292.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 32bf5f8116d0..e78317a5f4f1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -813,6 +813,13 @@ S: Supported
 F: drivers/iio/adc/ad7124.c
 F: Documentation/devicetree/bindings/iio/adc/adi,ad7124.txt
 
+ANALOG DEVICES INC AD7292 DRIVER
+M: Marcelo Schmitt 
+L: linux-...@vger.kernel.org
+W: http://ez.analog.com/community/linux-device-drivers
+S: Supported
+F: drivers/iio/adc/ad7292.c
+
 ANALOG DEVICES INC AD7606 DRIVER
 M: Stefan Popa 
 L: linux-...@vger.kernel.org
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 632b331429c6..02587c990cb5 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -59,6 +59,16 @@ config AD7291
  To compile this driver as a module, choose M here: the
  module will be called ad7291.
 
+config AD7292
+   tristate "Analog Devices AD7292 ADC driver"
+   depends on SPI
+   help
+ Say yes here to build support for Analog Devices AD7292
+ 8 Channel ADC with temperature sensor.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad7292.
+
 config AD7298
tristate "Analog Devices AD7298 ADC driver"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 4779ab3ff8fb..1818f2f66566 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_AD7124) += ad7124.o
 obj-$(CONFIG_AD7173) += ad7173.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7291) += ad7291.o
+obj-$(CONFIG_AD7292) += ad7292.o
 obj-$(CONFIG_AD7298) += ad7298.o
 obj-$(CONFIG_AD738X) += ad738x.o
 obj-$(CONFIG_AD7768) += ad7768-1.o
diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
new file mode 100644
index ..076bd49a2571
--- /dev/null
+++ b/drivers/iio/adc/ad7292.c
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices AD7292 SPI ADC driver
+ *
+ * Copyright 2019 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define ADI_VENDOR_ID 0x0018
+
+/* AD7292 registers definition */
+#define AD7292_REG_VENDOR_ID   0x00
+#define AD7292_REG_CONF_BANK   0x05
+#define AD7292_REG_CONV_COMM   0x0E
+#define AD7292_REG_ADC_CH(x)   (0x10 + (x))
+
+/* AD7292 configuration bank subregisters definition */
+#define AD7292_BANK_REG_VIN_RNG0   0x10
+#define AD7292_BANK_REG_VIN_RNG1   0x11
+#define AD7292_BANK_REG_SAMP_MODE  0x12
+
+#define AD7292_RD_FLAG_MSK(x)  (BIT(7) | ((x) & 0x3F))
+
+/* AD7292_REG_ADC_CONVERSION */
+#define AD7292_ADC_DATA_MASK   GENMASK(15, 6)
+#define AD7292_ADC_DATA(x) FIELD_GET(AD7292_ADC_DATA_MASK, x)
+
+/* AD7292_CHANNEL_SAMPLING_MODE */
+#define AD7292_CH_SAMP_MODE(reg, ch)   ((reg >> 8) & BIT(ch))
+
+/* AD7292_CHANNEL_VIN_RANGE */
+#define AD7292_CH_VIN_RANGE(reg, ch)   (reg & BIT(ch))
+
+#define AD7291_VOLTAGE_CHAN(_chan) \
+{  \
+   .type = IIO_VOLTAGE,\
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
+ BIT(IIO_CHAN_INFO_SCALE), \
+   .indexed = 1,   \
+   .channel = _chan,   \
+}
+
+static const struct iio_chan_spec ad7292_channels[] = {
+   AD7291_VOLTAGE_CHAN(0),
+   AD7291_VOLTAGE_CHAN(1),
+   AD7291_VOLTAGE_CHAN(2),
+   AD7291_VOLTAGE_CHAN(3),
+   AD7291_VOLTAGE_CHAN(4),
+   AD7291_VOLTAGE_CHAN(5),
+   AD7291_VOLTAGE_CHAN(6),
+   AD7291_VOLTAGE_CHAN(7)
+};
+
+static const struct iio_chan_spec ad7292_channels_diff[] = {
+   {
+   .type = IIO_VOLTAGE,
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+   .indexed = 1,
+   .differential = 1,
+   .channel = 0,
+   .channel2 = 1,
+   },
+   AD7291_VOLTAGE_CHAN(2),
+   AD7291_VOLTAGE_CHAN(3),
+   AD7291_VOLTAGE_CHAN(4),
+   AD7291_VOLTAGE_CHAN(5),
+   AD7291_VOLTAGE_CHAN(6),
+   AD7291_VOLTAGE_CHAN(7)
+};
+
+struct ad7292_state {
+   struct spi_devi

[PATCH 2/2] dt-bindings: iio: adc: Add DT docs for AD7292

2019-10-13 Thread Marcelo Schmitt
Add a device tree binding doc for AD7292 monitor and control system.

Signed-off-by: Marcelo Schmitt 
---
 .../bindings/iio/adc/adi,ad7292.yaml  | 71 +++
 MAINTAINERS   |  1 +
 2 files changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
new file mode 100644
index ..16be9ea4194d
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad7292.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7292 10-Bit Monitor and Control System
+
+maintainers:
+  - Marcelo Schmitt 
+
+description: |
+  Analog Devices AD7292 10-Bit Monitor and Control System with ADC, DACs,
+  Temperature Sensor, and GPIOs
+
+  Specifications about the part can be found at:
+
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7292.pdf
+
+properties:
+  compatible:
+enum:
+  - adi,ad7292
+
+  reg:
+maxItems: 1
+
+  vref-supply:
+description: |
+  The regulator supply for ADC and DAC reference voltage.
+maxItems: 1
+
+  spi-cpha:
+description: |
+  See Documentation/devicetree/bindings/spi/spi-controller.yaml
+maxItems: 1
+
+  diff-channels:
+description: |
+  Empty property to tell whether VIN0 and VIN1 shall work as differential
+  inputs.
+maxItems: 1
+
+  '#address-cells':
+const: 1
+
+  '#size-cells':
+const: 0
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+spi0 {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  ad7292: ad7292@0 {
+compatible = "adi,ad7292";
+reg = <0>;
+
+#address-cells = <1>;
+#size-cells = <0>;
+
+spi-max-frequency = <2500>;
+vref-supply = <_vref>;
+spi-cpha;
+diff-channels;
+  };
+}
diff --git a/MAINTAINERS b/MAINTAINERS
index e78317a5f4f1..5941cfc0d6f7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -819,6 +819,7 @@ L:  linux-...@vger.kernel.org
 W: http://ez.analog.com/community/linux-device-drivers
 S: Supported
 F: drivers/iio/adc/ad7292.c
+F: Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
 
 ANALOG DEVICES INC AD7606 DRIVER
 M: Stefan Popa 
-- 
2.23.0



[PATCH 0/2] iio: adc: Add driver support for AD7292

2019-10-13 Thread Marcelo Schmitt
This patchset adds a basic driver for the AD7292 ADC/DAC system along
with device tree binding documentation.

Marcelo Schmitt (2):
  iio: adc: Add driver support for AD7292
  dt-bindings: iio: adc: Add DT docs for AD7292

 .../bindings/iio/adc/adi,ad7292.yaml  |  71 
 MAINTAINERS   |   8 +
 drivers/iio/adc/Kconfig   |  10 +
 drivers/iio/adc/Makefile  |   1 +
 drivers/iio/adc/ad7292.c  | 350 ++
 5 files changed, 440 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7292.yaml
 create mode 100644 drivers/iio/adc/ad7292.c

-- 
2.23.0



Re: [PATCH v2] dt-bindings: iio: accel: add binding documentation for ADIS16240

2019-09-22 Thread Marcelo Schmitt
Hi,

Could anyone with some experience in devicetree give us a hint on what
to do here?

I have built a binding doc using the same spi-cpha property.
https://github.com/analogdevicesinc/linux/commit/bb2945e489dfdf2faa0255dd2cf09ae4ee77d826

On 09/13, Ardelean, Alexandru wrote:
> On Thu, 2019-09-12 at 18:39 -0300, Rodrigo Carvalho wrote:
> > This patch add device tree binding documentation for ADIS16240.
> > 
> > Signed-off-by: Rodrigo Ribeiro Carvalho 
> > ---
> > V2:
> >   - Remove true constant for spi-cpha and spi-cpol
> >   - Add description field for spi-cpha and spi-cpol
> >   - Add maxItems field for spi-cpha and spi-cpol
> > 
> >  .../bindings/iio/accel/adi,adis16240.yaml | 61 +++
> >  1 file changed, 61 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> > 
> > diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> > b/Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> > new file mode 100644
> > index ..4b1bd2419604
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> > @@ -0,0 +1,61 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/iio/accel/adi,adis16240.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: ADIS16240 Programmable Impact Sensor and Recorder driver
> > +
> > +maintainers:
> > +  - Alexandru Ardelean 
> > +
> > +description: |
> > +  ADIS16240 Programmable Impact Sensor and Recorder driver that supports
> > +  SPI interface.
> > +https://www.analog.com/en/products/adis16240.html
> > +
> > +properties:
> > +  compatible:
> > +enum:
> > +  - adi,adis16240
> > +
> > +  reg:
> > +maxItems: 1
> > +
> > +  spi-cpha:
> > +description: |
> > +  See Documentation/devicetree/bindings/spi/spi-controller.yaml
> > +maxItems: 1
> 
> Description for standard properties is not required.
> 
> For spi-cpha/cpol just "true" seems sufficient.
> 
> So
> 
>  spi-cpha: true
> 
>  spi-cpol: true
> 
I'm not Rob, but I think it is not necessary to explicitly say the
property is true. In this case, it should be enough if it is present. If
needed to know whether some property is "true" or not, one can use the
of_property_read_bool function. For the AD7292 driver on it was enough
to just add the property names. The spi-chpa did not need any further
care. Without the spi-cpha property, the AD7292 vendor ID came as 0x0C
(one bit shifted to the right).

Rodrigo is participating at FLUSP students group. It would be good if we
could test whether these properties are really needed. However, I don't
think we have the ADIS16240 part. Would anyone test it?

> > +
> > +  spi-cpol: |
> > +description: |
> > +  See Documentation/devicetree/bindings/spi/spi-controller.yaml
> > +maxItems: 1
> > +
> > +  interrupts:
> > +maxItems: 1
> > +
> > +required:
> > +  - compatible
> > +  - reg
> > +  - interrupts
> > +
> 
> If spi-cpha & spi-cpol are true, they should typically be also required.
> Though, I think Rob would answer things better here.
> 
Some feedback about the need (or not) to link to the spi-controller doc
would also be appreciated.

> > +examples:
> > +  - |
> > +#include 
> > +#include 
> > +spi0 {
> > +#address-cells = <1>;
> > +#size-cells = <0>;
> > +
> > +/* Example for a SPI device node */
> > +accelerometer@0 {
> > +compatible = "adi,adis16240";
> > +reg = <0>;
> > +spi-max-frequency = <250>;
> > +spi-cpol;
> > +spi-cpha;
> > +interrupt-parent = <>;
> > +interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
> > +};
> > +};

Thanks,

Marcelo


Re: [PATCH 1/2] dt-bindings: iio: accel: add binding documentation for ADIS16240

2019-09-02 Thread Marcelo Schmitt
Hi Rodrigo,

This dt doc looks overal fine IMHO.
I would just add some inline comments about the cpha and cpol
properties.

On 09/01, Rodrigo Carvalho wrote:
> This patch add device tree binding documentation for ADIS16240.
> 
> Signed-off-by: Rodrigo Ribeiro Carvalho 
> ---
> I have doubt about what maintainer I may to put in that documentation. I
> put Alexandru as maintainer because he reviewed my last patch on this
> driver, so I think that he is a good candidate.
>  .../bindings/iio/accel/adi,adis16240.yaml | 55 +++
>  1 file changed, 55 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> 
> diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml 
> b/Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> new file mode 100644
> index ..08019b51611c
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/accel/adi,adis16240.yaml
> @@ -0,0 +1,55 @@
> +# SPDX-License-Identifier: GPL-2.0
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/accel/adi,adis16240.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: ADIS16240 Programmable Impact Sensor and Recorder driver
> +
> +maintainers:
> +  - Alexandru Ardelean 
> +
> +description: |
> +  ADIS16240 Programmable Impact Sensor and Recorder driver that supports
> +  SPI interface.
> +https://www.analog.com/en/products/adis16240.html
> +
> +properties:
> +  compatible:
> +enum:
> +  - adi,adis16240
> +
> +  reg:
> +maxItems: 1
> +
> +  spi-cpha: true
> +
> +  spi-cpol: true
Boolean properties don't require to be explicitly set. It would also be
nice to add a description pointing to the spi-bus documentation. Like
this:

  spi-cpha:
description: |
  See Documentation/devicetree/bindings/spi/spi-bus.txt
maxItems: 1

  spi-cpol:
description: |
  See Documentation/devicetree/bindings/spi/spi-bus.txt
maxItems: 1

As far as I know, spi-cpol and spi-cpha stand for SPI chip polarity and
SPI chip phase respectively. By default, it is assumed that SPI
input/output data is available at uprising clock edges, however, some
chips may work with different configuration (taking input data and/or
push it out in falling edges). I'm not 100% sure but, from what I've
seen on IIO, cpol is set to invert the input/output logic (making IO be
taken on falling edges) while cpha is usually set when MISO valid out
data is available on SCLK falling edge. If anyone has more comments
about this please, add them here, I'm curious about it. :)

> +
> +  interrupts:
> +maxItems: 1
> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts
> +
> +examples:
> +  - |
> +#include 
> +#include 
> +spi0 {
> +#address-cells = <1>;
> +#size-cells = <0>;
> +
> +/* Example for a SPI device node */
> +accelerometer@0 {
> +compatible = "adi,adis16240";
> +reg = <0>;
> +spi-max-frequency = <250>;
> +spi-cpol;
> +spi-cpha;
> +interrupt-parent = <>;
> +interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
> +};
> +};
> -- 
> 2.23.0.rc1
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Kernel USP" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to kernel-usp+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/kernel-usp/20190902005938.7734-1-rodrigorsdc%40gmail.com.


Re: [PATCH] staging: iio: adis16240: add of_match_table entry

2019-05-24 Thread Marcelo Schmitt
Hi Alexandru,

On 05/24, Alexandru Ardelean wrote:
> On Fri, May 24, 2019 at 6:30 AM Rodrigo Ribeiro  wrote:
> >
> > This patch adds of_match_table entry in device driver in order to
> > enable spi fallback probing.
> >
> > Signed-off-by: Rodrigo Ribeiro 
> > Reviewed-by: Marcelo Schmitt 
> > ---
> >  drivers/staging/iio/accel/adis16240.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/staging/iio/accel/adis16240.c 
> > b/drivers/staging/iio/accel/adis16240.c
> > index 8c6d23604eca..b80c8529784b 100644
> > --- a/drivers/staging/iio/accel/adis16240.c
> > +++ b/drivers/staging/iio/accel/adis16240.c
> > @@ -444,6 +444,7 @@ MODULE_DEVICE_TABLE(of, adis16240_of_match);
> >  static struct spi_driver adis16240_driver = {
> > .driver = {
> > .name = "adis16240",
> > +   .of_match_table = adis16240_of_match,
> 
> This patch is missing the actual table.

Struct with compatible devices table was included separately in a
previous patch at commit d9e533b6c0a26c7ef8116b7f3477c164c07bb6fb.
Yeah, I also thought it was missing the match table the first time I was
this patch. It's really confusing when we have two patches, one
depending on another, that are not part of the same patch set. We're
trying to avoid things like this the most but that slipped out from our
internal review. We're sorry about that.

> 
> > },
> > .probe = adis16240_probe,
> > .remove = adis16240_remove,
> > --
> > 2.20.1
> >


Re: [PATCH 4/4] staging: iio: ad9832: add devicetree documentation

2019-04-02 Thread Marcelo Schmitt
On 04/02, Alexandru Ardelean wrote:
> On Mon, Apr 1, 2019 at 5:38 PM Marcelo Schmitt
>  wrote:
> >
> > Add a devicetree documentation for the ad9832 direct digital
> > synthesizer, waveform generator.
> >
> > Signed-off-by: Marcelo Schmitt 
> > ---
> >  .../bindings/iio/frequency/ad9832.txt | 26 +++
> >  1 file changed, 26 insertions(+)
> >  create mode 100644 
> > Documentation/devicetree/bindings/iio/frequency/ad9832.txt
> >
> > diff --git a/Documentation/devicetree/bindings/iio/frequency/ad9832.txt 
> > b/Documentation/devicetree/bindings/iio/frequency/ad9832.txt
> > new file mode 100644
> > index ..6a35fdff5a48
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/iio/frequency/ad9832.txt
> > @@ -0,0 +1,26 @@
> > +Analog Devices AD9832 Direct Digital Synthesizer, Waveform Generator
> > +
> > +Data sheet:
> > +https://www.analog.com/media/en/technical-documentation/data-sheets/AD9832.pdf
> > +
> > +Required properties:
> > +   - compatible : Must be "adi,ad9832"
> > +   - reg : SPI chip select number for the device
> > +   - spi-max-frequency = Max SPI frequency to use (< 2500)
> > +   - clocks : The clock reference for the DDS output
> > +   - clock-names : Must be "mclk"
> 
> It's always a good idea to reference other base dt docs.
> For SPI you could:
> 
> ```
> For more information on SPI properties, please consult
>  Documentation/devicetree/bindings/spi/spi-bus.txt
> ```
> 
> For clock:
> ```
> For more information on clock bindings properties, please consult
>  Documentation/devicetree/bindings/clock/clock-bindings.txt
> ```
> 
> For regulator:
> ```
> For more information on regulator bindings properties, please consult
>  Documentation/devicetree/bindings/regulator/regulator.txt
> ```

Thanks for the advice. I'll have a look at them.

> 
> > +
> > +Optional properties:
> > +   - avdd-supply:  Definition of the regulator used as analog supply
> > +   - dvdd-supply : Definition of the regulator used as digital supply
> > +
> > +Example:
> > +   adi9832-dds@0 {
> > +   compatible = "adi,ad9832";
> > +   reg = <0>;
> > +   spi-max-frequency = <2500>;
> > +   clocks = <_mclk>;
> > +   clock-names = "mclk";
> > +   avdd-suppy = <>;
> > +   dvdd-suppy = <>;
> > +   };
> > --
> > 2.20.1
> >


Re: Work on iio: stating: frequency: ad9832

2019-04-02 Thread Marcelo Schmitt
On 04/02, Alexandru Ardelean wrote:
> On Mon, Apr 1, 2019 at 7:13 PM Jonathan Cameron
>  wrote:
> >
> > On Mon, 1 Apr 2019 11:25:29 -0300
> > Marcelo Schmitt  wrote:
> >
> > > Hello,
> > >
> > > I was looking for some work on staging: iio: ad9832 and made some
> > > observations while reading the driver.
> > >
> > > Apparently it had no devicetree documentation so I tried to elaborate
> > > one.
> > > It uses a platform_data variable to load external clock
> > > frequency (I tried to make it use linux's clock framework).
> > Good.
> >
> > > Some device attributes don't seem to be standardized on
> > > Documentation/ABI/testing/sysfs-bus-iio and there's no specific ABI
> > > for ad9832 nearby nor at staging/iio/Documentation. So maybe those
> > > missing ABI could be documented.
> > Beware. It's an old driver, so it may be that we actually want to change
> > it's ABI rather than documenting what is there (I have haven't looked!)
> >

OK, I'll take more time studying the device's datasheet to better 
understand the current ABI.

> 
> This one can actually be coupled a bit with the AD9834 driver.
> There's been some work on trying to move that one out of staging as well.
> 
> You can take a look at the patches sent for that driver.
> They should be find-able on patchwork
> https://patchwork.kernel.org/project/linux-iio/list/?series===*=ad9834=both=
> 
> There are ideas worth borrowing from there.
> 
> The issue with the AD9834 [if i recall correctly] is that it doesn't
> quite fit the classical IIO channel model.
> Meaning, you can only activate the output of one channel at one moment
> in time, and not both.

OK, I'll have a look at it.

> 
> > > The device has to set some internal registers to operate correctly,
> > > AD9832_FREQXHM and AD9832_PHASEXH, would it be feasible to set iio
> > > chanels for this?
> >
> > What are they?  If they correspond to output channels in some sensible
> > way then maybe...
> >
> > > I couldn't understand why checkpatch.pl gave errors on IIO_DEV_ATTR_*
> > > macros. To me they seem to have no problem.
> > > Also it has that platform_data to be moved to include/linux/iio. Is
> > > there any special reason for it not being there already? Which are
> > > the criterions a platform_data need to satisfy to be put there?
> > A driver moving out of staging shouldn't have platform data. It needs
> > to be converted over to more modern mechanisms.   We don't have a problem
> > supporting platform data for devices that have old school device files
> > already in tree, but that shouldn't be the case for a driver in staging.
> >
> > Hence we can clean it up and move forward with just DT bindings.
> > >

Understood. Thanks for the explanation.

> > > I'm sending a patchset with some things I've already done.
> > Cool. I'll look at those later in the week if no one beats me to them.
> >
> > >
> > > Is there something else that could be done in this device driver?
> > > Please, tell if I've forgotten something.
> >
> > I'll take a look, but it may be a little while before I do.
> > Hopefully someone else gets there first!
> >
> > Jonathan
> >
> > >
> > > Any advice is welcome.
> > > Thanks,
> > >
> > > Marcelo
> >
> >

Thanks for the pieces of advice.

Marcelo


Re: [PATCH 2/4] staging: iio: ad9832: add SPDX identifier

2019-04-02 Thread Marcelo Schmitt
On 04/01, Greg KH wrote:
> On Mon, Apr 01, 2019 at 08:36:50PM +0530, Mukesh Ojha wrote:
> > 
> > On 4/1/2019 8:07 PM, Marcelo Schmitt wrote:
> > > Add SPDX identifier of GPL-2.0 for the ad9832 driver.
> > > 
> > > Signed-off-by: Marcelo Schmitt 
> > > ---
> > >   drivers/staging/iio/frequency/ad9832.c | 3 +--
> > >   1 file changed, 1 insertion(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/staging/iio/frequency/ad9832.c 
> > > b/drivers/staging/iio/frequency/ad9832.c
> > > index 50a583020072..d8d4a7936275 100644
> > > --- a/drivers/staging/iio/frequency/ad9832.c
> > > +++ b/drivers/staging/iio/frequency/ad9832.c
> > > @@ -1,9 +1,8 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > 
> > FYI
> > 
> > Use C notations here as per https://lkml.org/lkml/2019/2/13/570.
> > 
> > <https://lkml.org/lkml/2019/2/13/570>

OK, I'll check it out.

> > 
> > Once you fix it then you can take mine
> > Reviewed-by: Mukesh Ojha 
> 
> Did you read the documentation about how to put a proper SPDX line in
> the kernel documentation?  For .c files, you have to use "//", not "/* */"
> 
> Please read:
>   Documentation/process/license-rules.rst
> and see the section "Style" for all of the details.

Thanks, I'll read it to understand the details.

> 
> thanks,
> 
> greg k-h

Thanks for the advises,

Marcelo


[PATCH 4/4] staging: iio: ad9832: add devicetree documentation

2019-04-01 Thread Marcelo Schmitt
Add a devicetree documentation for the ad9832 direct digital
synthesizer, waveform generator.

Signed-off-by: Marcelo Schmitt 
---
 .../bindings/iio/frequency/ad9832.txt | 26 +++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/ad9832.txt

diff --git a/Documentation/devicetree/bindings/iio/frequency/ad9832.txt 
b/Documentation/devicetree/bindings/iio/frequency/ad9832.txt
new file mode 100644
index ..6a35fdff5a48
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/frequency/ad9832.txt
@@ -0,0 +1,26 @@
+Analog Devices AD9832 Direct Digital Synthesizer, Waveform Generator
+
+Data sheet:
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD9832.pdf
+
+Required properties:
+   - compatible : Must be "adi,ad9832"
+   - reg : SPI chip select number for the device
+   - spi-max-frequency = Max SPI frequency to use (< 2500)
+   - clocks : The clock reference for the DDS output
+   - clock-names : Must be "mclk"
+
+Optional properties:
+   - avdd-supply:  Definition of the regulator used as analog supply
+   - dvdd-supply : Definition of the regulator used as digital supply
+
+Example:
+   adi9832-dds@0 {
+   compatible = "adi,ad9832";
+   reg = <0>;
+   spi-max-frequency = <2500>;
+   clocks = <_mclk>;
+   clock-names = "mclk";
+   avdd-suppy = <>;
+   dvdd-suppy = <>;
+   };
-- 
2.20.1



[PATCH 3/4] staging: iio: ad9832: use clock framework for clock reference

2019-04-01 Thread Marcelo Schmitt
Previously external clock were set through platform_data struct.
Now device uses clk struct defined in include/linux/clk.h to handle
external clock source.
It also removes mclk from platform_data struct.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/frequency/ad9832.c | 37 +-
 drivers/staging/iio/frequency/ad9832.h |  1 -
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c 
b/drivers/staging/iio/frequency/ad9832.c
index d8d4a7936275..74308a2e72db 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -7,6 +7,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -95,7 +96,7 @@ struct ad9832_state {
struct spi_device   *spi;
struct regulator*avdd;
struct regulator*dvdd;
-   unsigned long   mclk;
+   struct clk  *mclk;
unsigned short  ctrl_fp;
unsigned short  ctrl_ss;
unsigned short  ctrl_src;
@@ -130,10 +131,10 @@ static int ad9832_write_frequency(struct ad9832_state *st,
 {
unsigned long regval;
 
-   if (fout > (st->mclk / 2))
+   if (fout > (clk_get_rate(st->mclk) / 2))
return -EINVAL;
 
-   regval = ad9832_calc_freqreg(st->mclk, fout);
+   regval = ad9832_calc_freqreg(clk_get_rate(st->mclk), fout);
 
st->freq_data[0] = cpu_to_be16((AD9832_CMD_FRE8BITSW << CMD_SHIFT) |
(addr << ADD_SHIFT) |
@@ -334,7 +335,16 @@ static int ad9832_probe(struct spi_device *spi)
goto error_disable_avdd;
}
 
-   st->mclk = pdata->mclk;
+   st->mclk = devm_clk_get(>dev, "mclk");
+   if (IS_ERR(st->mclk)) {
+   ret = PTR_ERR(st->mclk);
+   goto error_disable_dvdd;
+   }
+
+   ret = clk_prepare_enable(st->mclk);
+   if (ret < 0)
+   goto error_disable_dvdd;
+
st->spi = spi;
mutex_init(>lock);
 
@@ -385,39 +395,41 @@ static int ad9832_probe(struct spi_device *spi)
ret = spi_sync(st->spi, >msg);
if (ret) {
dev_err(>dev, "device init failed\n");
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
}
 
ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
ret = iio_device_register(indio_dev);
if (ret)
-   goto error_disable_dvdd;
+   goto error_unprepare_mclk;
 
return 0;
 
+error_unprepare_mclk:
+   clk_disable_unprepare(st->mclk);
 error_disable_dvdd:
regulator_disable(st->dvdd);
 error_disable_avdd:
@@ -432,6 +444,7 @@ static int ad9832_remove(struct spi_device *spi)
struct ad9832_state *st = iio_priv(indio_dev);
 
iio_device_unregister(indio_dev);
+   clk_disable_unprepare(st->mclk);
regulator_disable(st->dvdd);
regulator_disable(st->avdd);
 
diff --git a/drivers/staging/iio/frequency/ad9832.h 
b/drivers/staging/iio/frequency/ad9832.h
index 39d326cc1af9..032579a2d539 100644
--- a/drivers/staging/iio/frequency/ad9832.h
+++ b/drivers/staging/iio/frequency/ad9832.h
@@ -24,7 +24,6 @@
  */
 
 struct ad9832_platform_data {
-   unsigned long   mclk;
unsigned long   freq0;
unsigned long   freq1;
unsigned short  phase0;
-- 
2.20.1



[PATCH 2/4] staging: iio: ad9832: add SPDX identifier

2019-04-01 Thread Marcelo Schmitt
Add SPDX identifier of GPL-2.0 for the ad9832 driver.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/frequency/ad9832.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c 
b/drivers/staging/iio/frequency/ad9832.c
index 50a583020072..d8d4a7936275 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD9832 SPI DDS driver
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #include 
-- 
2.20.1



[PATCH 1/4] staging: iio: ad9832: organize includes

2019-04-01 Thread Marcelo Schmitt
Organize includes to list them in lexicographic order.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/frequency/ad9832.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/iio/frequency/ad9832.c 
b/drivers/staging/iio/frequency/ad9832.c
index a3ce50427724..50a583020072 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -6,22 +6,24 @@
  * Licensed under the GPL-2.
  */
 
+#include 
+
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
-#include 
 #include 
-#include 
-#include 
-#include 
-#include 
+#include 
 
 #include 
 #include 
-#include "dds.h"
 
 #include "ad9832.h"
 
+#include "dds.h"
+
 /* Registers */
 
 #define AD9832_FREQ0LL 0x0
-- 
2.20.1



[PATCH 0/4] staging: iio: ad9832: use clock framework

2019-04-01 Thread Marcelo Schmitt
This series of patches do minor codestyle ajusts, set SPDX licence
identifier, set use of linux's clock framework to handle external
clock, and add a devicetree documentation.

Marcelo Schmitt (4):
  staging: iio: ad9832: organize includes
  staging: iio: ad9832: add SPDX identifier
  staging: iio: ad9832: use clock framework for clock reference
  staging: iio: ad9832: add devicetree documentation

 .../bindings/iio/frequency/ad9832.txt | 26 +
 drivers/staging/iio/frequency/ad9832.c| 54 ---
 drivers/staging/iio/frequency/ad9832.h|  1 -
 3 files changed, 60 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/frequency/ad9832.txt

-- 
2.20.1



Work on iio: stating: frequency: ad9832

2019-04-01 Thread Marcelo Schmitt
Hello,

I was looking for some work on staging: iio: ad9832 and made some
observations while reading the driver.

Apparently it had no devicetree documentation so I tried to elaborate
one. 
It uses a platform_data variable to load external clock
frequency (I tried to make it use linux's clock framework).
Some device attributes don't seem to be standardized on
Documentation/ABI/testing/sysfs-bus-iio and there's no specific ABI
for ad9832 nearby nor at staging/iio/Documentation. So maybe those
missing ABI could be documented.
The device has to set some internal registers to operate correctly,
AD9832_FREQXHM and AD9832_PHASEXH, would it be feasible to set iio
chanels for this?
I couldn't understand why checkpatch.pl gave errors on IIO_DEV_ATTR_*
macros. To me they seem to have no problem.
Also it has that platform_data to be moved to include/linux/iio. Is
there any special reason for it not being there already? Which are
the criterions a platform_data need to satisfy to be put there?

I'm sending a patchset with some things I've already done.

Is there something else that could be done in this device driver?
Please, tell if I've forgotten something.

Any advice is welcome.
Thanks,

Marcelo


Help on testing ad5933 driver

2019-03-21 Thread Marcelo Schmitt
Hello, would anyone mind helping me test ad5933 driver on actual
hardware?  I went through this
(https://oslongjourney.github.io/linux-kernel/experiment-one-iio-dummy/)
tutorial so I was able to load iio_simple_dummy driver, create and
inspect some dummy devices.  Now, as Jonathan has asked me, I would like
to test ad5933 driver on an EVAL-AD5933 board which was donated to FLUSP
(https://flusp.ime.usp.br/).

So far I've been hesitating to plug this device on my Debian distro
since this
(https://www.analog.com/media/en/technical-documentation/user-guides/UG-364.pdf)
user guide for Windows says not to connect it before driver
installation. Is there something that could harm the board if plugged
on a computer without a proper driver?

I also didn't understand the hardware configuration showed on this
(https://wiki.analog.com/resources/tools-software/linux-drivers/iio-impedance-analyzer/ad5933)
page.

Any advice will be greatly appreciated.
Thanks in advance,

Marcelo


[PATCH v5 1/2] staging: iio: ad5933: change attributes to match ABI

2019-03-21 Thread Marcelo Schmitt
Change device attributes' names to match ABI documentation. Names were
chosen such that they tend to be similar to existing ABI so it should
be easier to standardize them when necessary.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/ad5933.c   | 24 +--
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index d75bdfbf93de..2b0f8f899e3f 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -315,12 +315,12 @@ static ssize_t ad5933_store_frequency(struct device *dev,
return ret ? ret : len;
 }
 
-static IIO_DEVICE_ATTR(out_voltage0_freq_start, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_frequency_start, 0644,
ad5933_show_frequency,
ad5933_store_frequency,
AD5933_REG_FREQ_START);
 
-static IIO_DEVICE_ATTR(out_voltage0_freq_increment, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_frequency_increment, 0644,
ad5933_show_frequency,
ad5933_store_frequency,
AD5933_REG_FREQ_INC);
@@ -443,12 +443,12 @@ static ssize_t ad5933_store(struct device *dev,
return ret ? ret : len;
 }
 
-static IIO_DEVICE_ATTR(out_voltage0_scale, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_raw, 0644,
ad5933_show,
ad5933_store,
AD5933_OUT_RANGE);
 
-static IIO_DEVICE_ATTR(out_voltage0_scale_available, 0444,
+static IIO_DEVICE_ATTR(out_altvoltage0_scale_available, 0444,
ad5933_show,
NULL,
AD5933_OUT_RANGE_AVAIL);
@@ -463,12 +463,12 @@ static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444,
NULL,
AD5933_IN_PGA_GAIN_AVAIL);
 
-static IIO_DEVICE_ATTR(out_voltage0_freq_points, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_frequency_points, 0644,
ad5933_show,
ad5933_store,
AD5933_FREQ_POINTS);
 
-static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_settling_cycles, 0644,
ad5933_show,
ad5933_store,
AD5933_OUT_SETTLING_CYCLES);
@@ -480,12 +480,12 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
  * don't create dedicated sysfs channel attributes for out0 and in0.
  */
 static struct attribute *ad5933_attributes[] = {
-   _dev_attr_out_voltage0_scale.dev_attr.attr,
-   _dev_attr_out_voltage0_scale_available.dev_attr.attr,
-   _dev_attr_out_voltage0_freq_start.dev_attr.attr,
-   _dev_attr_out_voltage0_freq_increment.dev_attr.attr,
-   _dev_attr_out_voltage0_freq_points.dev_attr.attr,
-   _dev_attr_out_voltage0_settling_cycles.dev_attr.attr,
+   _dev_attr_out_altvoltage0_raw.dev_attr.attr,
+   _dev_attr_out_altvoltage0_scale_available.dev_attr.attr,
+   _dev_attr_out_altvoltage0_frequency_start.dev_attr.attr,
+   _dev_attr_out_altvoltage0_frequency_increment.dev_attr.attr,
+   _dev_attr_out_altvoltage0_frequency_points.dev_attr.attr,
+   _dev_attr_out_altvoltage0_settling_cycles.dev_attr.attr,
_dev_attr_in_voltage0_scale.dev_attr.attr,
_dev_attr_in_voltage0_scale_available.dev_attr.attr,
NULL
-- 
2.20.1



[PATCH v5 2/2] staging: iio: ad5933: move out of staging

2019-03-21 Thread Marcelo Schmitt
Move ad5933 impedance-analyzer driver from staging to mainline. The
ad5933 is a high precision impedance converter system solution that
combines an on-board frequency generator with an analog-to-digital
converter (ADC). This driver was designed to be compatible with both
ad5933 and ad5934 chips.

Signed-off-by: Marcelo Schmitt 
---
 drivers/iio/Kconfig   |   1 +
 drivers/iio/Makefile  |   1 +
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 drivers/staging/iio/Kconfig   |   1 -
 drivers/staging/iio/Makefile  |   1 -
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 811 --
 10 files changed, 836 insertions(+), 836 deletions(-)
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 014006d1cbb6..db38e6fb62fe 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -81,6 +81,7 @@ source "drivers/iio/frequency/Kconfig"
 source "drivers/iio/gyro/Kconfig"
 source "drivers/iio/health/Kconfig"
 source "drivers/iio/humidity/Kconfig"
+source "drivers/iio/impedance-analyzer/Kconfig"
 source "drivers/iio/imu/Kconfig"
 source "drivers/iio/light/Kconfig"
 source "drivers/iio/magnetometer/Kconfig"
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index cb5993251381..fae55479356b 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -27,6 +27,7 @@ obj-y += gyro/
 obj-y += frequency/
 obj-y += health/
 obj-y += humidity/
+obj-y += impedance-analyzer/
 obj-y += imu/
 obj-y += light/
 obj-y += magnetometer/
diff --git a/drivers/iio/impedance-analyzer/Kconfig 
b/drivers/iio/impedance-analyzer/Kconfig
new file mode 100644
index ..b9a679cdd146
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Kconfig
@@ -0,0 +1,18 @@
+#
+# Impedance Converter, Network Analyzer drivers
+#
+menu "Network Analyzer, Impedance Converters"
+
+config AD5933
+   tristate "Analog Devices AD5933, AD5934 driver"
+   depends on I2C
+   select IIO_BUFFER
+   select IIO_KFIFO_BUF
+   help
+ Say yes here to build support for Analog Devices Impedance Converter,
+ Network Analyzer, AD5933/4.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad5933.
+
+endmenu
diff --git a/drivers/iio/impedance-analyzer/Makefile 
b/drivers/iio/impedance-analyzer/Makefile
new file mode 100644
index ..7604d786583e
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for Impedance Converter, Network Analyzer drivers
+#
+
+obj-$(CONFIG_AD5933) += ad5933.o
diff --git a/drivers/iio/impedance-analyzer/ad5933.c 
b/drivers/iio/impedance-analyzer/ad5933.c
new file mode 100644
index ..2b0f8f899e3f
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/ad5933.c
@@ -0,0 +1,811 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AD5933 AD5934 Impedance Converter, Network Analyzer
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/* AD5933/AD5934 Registers */
+#define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
+#define AD5933_REG_CONTROL_LB  0x81/* R/W, 1 byte */
+#define AD5933_REG_FREQ_START  0x82/* R/W, 3 bytes */
+#define AD5933_REG_FREQ_INC0x85/* R/W, 3 bytes */
+#define AD5933_REG_INC_NUM 0x88/* R/W, 2 bytes, 9 bit */
+#define AD5933_REG_SETTLING_CYCLES 0x8A/* R/W, 2 bytes */
+#define AD5933_REG_STATUS  0x8F/* R, 1 byte */
+#define AD5933_REG_TEMP_DATA   0x92/* R, 2 bytes*/
+#define AD5933_REG_REAL_DATA   0x94/* R, 2 bytes*/
+#define AD5933_REG_IMAG_DATA   0x96/* R, 2 bytes*/
+
+/* AD5933_REG_CONTROL_HB Bits */
+#define AD5933_CTRL_INIT_START_FREQ(0x1 << 4)
+#define AD5933_CTRL_START_SWEEP(0x2 << 4)
+#define AD5933_CTRL_INC_FREQ   (0x3 << 4)
+#define AD5933_CTRL_REPEAT_FREQ(0x4 << 4)
+#define AD5933_CTRL_MEASURE_TEMP   (0x9 << 4)
+#define AD5933_CTRL_POWER_DOWN (0xA << 4)
+#define AD5933_CTRL_STANDB

[PATCH v5 0/2] staging: iio: ad5933: move out of staging

2019-03-21 Thread Marcelo Schmitt
This series of patches makes device attributes' names equal to ABI
documentation and move ad5933 driver out of staging. More precisely:
It changes device attributes' names to match or be similar to existing
ABI.
It moves the ad5933 driver from staging directory to iio main drivers
directory.

Marcelo Schmitt (2):
  staging: iio: ad5933: change attributes to match ABI
  staging: iio: ad5933: move out of staging

 drivers/iio/Kconfig   |   1 +
 drivers/iio/Makefile  |   1 +
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 drivers/staging/iio/Kconfig   |   1 -
 drivers/staging/iio/Makefile  |   1 -
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 811 --
 10 files changed, 836 insertions(+), 836 deletions(-)
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

-- 
2.20.1



[PATCH v4 6/7] staging: iio: ad5933: change attributes to match ABI

2019-03-16 Thread Marcelo Schmitt
Change device attributes' names to match ABI documentation. Names were
chosen such that they tend to be similar to existing ABI so it should
be easier to standardize them when necessary.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/ad5933.c   | 20 +--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index d75bdfbf93de..262415bc659d 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -315,12 +315,12 @@ static ssize_t ad5933_store_frequency(struct device *dev,
return ret ? ret : len;
 }
 
-static IIO_DEVICE_ATTR(out_voltage0_freq_start, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_frequency_start, 0644,
ad5933_show_frequency,
ad5933_store_frequency,
AD5933_REG_FREQ_START);
 
-static IIO_DEVICE_ATTR(out_voltage0_freq_increment, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_frequency_increment, 0644,
ad5933_show_frequency,
ad5933_store_frequency,
AD5933_REG_FREQ_INC);
@@ -463,12 +463,12 @@ static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444,
NULL,
AD5933_IN_PGA_GAIN_AVAIL);
 
-static IIO_DEVICE_ATTR(out_voltage0_freq_points, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_frequency_points, 0644,
ad5933_show,
ad5933_store,
AD5933_FREQ_POINTS);
 
-static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_settling_cycles, 0644,
ad5933_show,
ad5933_store,
AD5933_OUT_SETTLING_CYCLES);
@@ -480,12 +480,12 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
  * don't create dedicated sysfs channel attributes for out0 and in0.
  */
 static struct attribute *ad5933_attributes[] = {
-   _dev_attr_out_voltage0_scale.dev_attr.attr,
-   _dev_attr_out_voltage0_scale_available.dev_attr.attr,
-   _dev_attr_out_voltage0_freq_start.dev_attr.attr,
-   _dev_attr_out_voltage0_freq_increment.dev_attr.attr,
-   _dev_attr_out_voltage0_freq_points.dev_attr.attr,
-   _dev_attr_out_voltage0_settling_cycles.dev_attr.attr,
+   _dev_attr_out_altvoltage0_raw.dev_attr.attr,
+   _dev_attr_out_altvoltage0_scale_available.dev_attr.attr,
+   _dev_attr_out_altvoltage0_frequency_start.dev_attr.attr,
+   _dev_attr_out_altvoltage0_frequency_increment.dev_attr.attr,
+   _dev_attr_out_altvoltage0_frequency_points.dev_attr.attr,
+   _dev_attr_out_altvoltage0_settling_cycles.dev_attr.attr,
_dev_attr_in_voltage0_scale.dev_attr.attr,
_dev_attr_in_voltage0_scale_available.dev_attr.attr,
NULL
-- 
2.20.1



[PATCH v4 7/7] staging: iio: ad5933: move out of staging

2019-03-16 Thread Marcelo Schmitt
Move ad5933 impedance-analyzer driver from staging to mainline.
The ad5933 is a high precision impedance converter system solution
that combines an on-board frequency generator with an
analog-to-digital converter (ADC). This driver was designed to be
compatible with both ad5933 and ad5934 chips.

Signed-off-by: Marcelo Schmitt 
---
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 811 --
 6 files changed, 834 insertions(+), 834 deletions(-)
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

diff --git a/drivers/iio/impedance-analyzer/Kconfig 
b/drivers/iio/impedance-analyzer/Kconfig
new file mode 100644
index ..b9a679cdd146
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Kconfig
@@ -0,0 +1,18 @@
+#
+# Impedance Converter, Network Analyzer drivers
+#
+menu "Network Analyzer, Impedance Converters"
+
+config AD5933
+   tristate "Analog Devices AD5933, AD5934 driver"
+   depends on I2C
+   select IIO_BUFFER
+   select IIO_KFIFO_BUF
+   help
+ Say yes here to build support for Analog Devices Impedance Converter,
+ Network Analyzer, AD5933/4.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad5933.
+
+endmenu
diff --git a/drivers/iio/impedance-analyzer/Makefile 
b/drivers/iio/impedance-analyzer/Makefile
new file mode 100644
index ..7604d786583e
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for Impedance Converter, Network Analyzer drivers
+#
+
+obj-$(CONFIG_AD5933) += ad5933.o
diff --git a/drivers/iio/impedance-analyzer/ad5933.c 
b/drivers/iio/impedance-analyzer/ad5933.c
new file mode 100644
index ..262415bc659d
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/ad5933.c
@@ -0,0 +1,811 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AD5933 AD5934 Impedance Converter, Network Analyzer
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/* AD5933/AD5934 Registers */
+#define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
+#define AD5933_REG_CONTROL_LB  0x81/* R/W, 1 byte */
+#define AD5933_REG_FREQ_START  0x82/* R/W, 3 bytes */
+#define AD5933_REG_FREQ_INC0x85/* R/W, 3 bytes */
+#define AD5933_REG_INC_NUM 0x88/* R/W, 2 bytes, 9 bit */
+#define AD5933_REG_SETTLING_CYCLES 0x8A/* R/W, 2 bytes */
+#define AD5933_REG_STATUS  0x8F/* R, 1 byte */
+#define AD5933_REG_TEMP_DATA   0x92/* R, 2 bytes*/
+#define AD5933_REG_REAL_DATA   0x94/* R, 2 bytes*/
+#define AD5933_REG_IMAG_DATA   0x96/* R, 2 bytes*/
+
+/* AD5933_REG_CONTROL_HB Bits */
+#define AD5933_CTRL_INIT_START_FREQ(0x1 << 4)
+#define AD5933_CTRL_START_SWEEP(0x2 << 4)
+#define AD5933_CTRL_INC_FREQ   (0x3 << 4)
+#define AD5933_CTRL_REPEAT_FREQ(0x4 << 4)
+#define AD5933_CTRL_MEASURE_TEMP   (0x9 << 4)
+#define AD5933_CTRL_POWER_DOWN (0xA << 4)
+#define AD5933_CTRL_STANDBY(0xB << 4)
+
+#define AD5933_CTRL_RANGE_2000mVpp (0x0 << 1)
+#define AD5933_CTRL_RANGE_200mVpp  (0x1 << 1)
+#define AD5933_CTRL_RANGE_400mVpp  (0x2 << 1)
+#define AD5933_CTRL_RANGE_1000mVpp (0x3 << 1)
+#define AD5933_CTRL_RANGE(x)   ((x) << 1)
+
+#define AD5933_CTRL_PGA_GAIN_1 (0x1 << 0)
+#define AD5933_CTRL_PGA_GAIN_5 (0x0 << 0)
+
+/* AD5933_REG_CONTROL_LB Bits */
+#define AD5933_CTRL_RESET  (0x1 << 4)
+#define AD5933_CTRL_INT_SYSCLK (0x0 << 3)
+#define AD5933_CTRL_EXT_SYSCLK (0x1 << 3)
+
+/* AD5933_REG_STATUS Bits */
+#define AD5933_STAT_TEMP_VALID (0x1 << 0)
+#define AD5933_STAT_DATA_VALID (0x1 << 1)
+#define AD5933_STAT_SWEEP_DONE (0x1 << 2)
+
+/* I2C Block Commands */
+#define AD5933_I2C_BLOCK_WRITE 0xA0
+#define AD5933_I2C_BLOCK_READ  0xA1
+#define AD5933_I2C_ADDR_POINTER0xB0
+
+/* Device Specs */
+#define AD5933_INT_OSC_FREQ_Hz 16776000
+#define AD5933_MAX_OUTPUT_FREQ_Hz  

[PATCH v4 5/7] staging: iio: ad5933: add ABI documentation

2019-03-16 Thread Marcelo Schmitt
Add an ABI documentation for the ad5933 driver.

Signed-off-by: Marcelo Schmitt 
---
 .../sysfs-bus-iio-impedance-analyzer-ad5933   | 35 +++
 .../sysfs-bus-iio-impedance-analyzer-ad5933   | 30 
 2 files changed, 35 insertions(+), 30 deletions(-)
 create mode 100644 
Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933
 delete mode 100644 
drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933 
b/Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933
new file mode 100644
index ..a50aada68e1e
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933
@@ -0,0 +1,35 @@
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency_start
+Date:  March 2019
+KernelVersion: 3.1.0
+Contact:   linux-...@vger.kernel.org
+Description:
+   Frequency sweep start frequency in Hz.
+
+What:  
/sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency_increment
+Date:  March 2019
+KernelVersion: 3.1.0
+Contact:   linux-...@vger.kernel.org
+Description:
+   Frequency increment in Hz (step size) between consecutive
+   frequency points along the sweep.
+
+What:  
/sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency_points
+Date:  March 2019
+KernelVersion: 3.1.0
+Contact:   linux-...@vger.kernel.org
+Description:
+   Number of frequency points (steps) in the frequency sweep.
+   This value, in conjunction with the
+   out_altvoltageY_frequency_start and the 
+   out_altvoltageY_frequency_increment, determines the frequency 
+   sweep range for the sweep operation.
+
+What:  /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_settling_cycles
+Date:  March 2019
+KernelVersion: 3.1.0
+Contact:   linux-...@vger.kernel.org
+Description:
+   Number of output excitation cycles (settling time cycles)
+   that are allowed to pass through the unknown impedance,
+   after each frequency increment, and before the ADC is triggered
+   to perform a conversion sequence of the response signal.
diff --git 
a/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 
b/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933
deleted file mode 100644
index 79c7e88c64cd..
--- a/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933
+++ /dev/null
@@ -1,30 +0,0 @@
-What:  /sys/bus/iio/devices/iio:deviceX/outY_freq_start
-KernelVersion: 3.1.0
-Contact:   linux-...@vger.kernel.org
-Description:
-   Frequency sweep start frequency in Hz.
-
-What:  /sys/bus/iio/devices/iio:deviceX/outY_freq_increment
-KernelVersion: 3.1.0
-Contact:   linux-...@vger.kernel.org
-Description:
-   Frequency increment in Hz (step size) between consecutive
-   frequency points along the sweep.
-
-What:  /sys/bus/iio/devices/iio:deviceX/outY_freq_points
-KernelVersion: 3.1.0
-Contact:   linux-...@vger.kernel.org
-Description:
-   Number of frequency points (steps) in the frequency sweep.
-   This value, in conjunction with the outY_freq_start and the
-   outY_freq_increment, determines the frequency sweep range
-   for the sweep operation.
-
-What:  /sys/bus/iio/devices/iio:deviceX/outY_settling_cycles
-KernelVersion: 3.1.0
-Contact:   linux-...@vger.kernel.org
-Description:
-   Number of output excitation cycles (settling time cycles)
-   that are allowed to pass through the unknown impedance,
-   after each frequency increment, and before the ADC is triggered
-   to perform a conversion sequence of the response signal.
-- 
2.20.1



[PATCH v4 3/7] staging: iio: ad5933: add SPDX identifier

2019-03-16 Thread Marcelo Schmitt
Add SPDX identifier of GPL-2.0 for the ad5933 driver.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index c2a7a59e469c..d75bdfbf93de 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5933 AD5934 Impedance Converter, Network Analyzer
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #include 
-- 
2.20.1



[PATCH v4 4/7] staging: iio: ad5933: change help rule message

2019-03-16 Thread Marcelo Schmitt
Remove the previous comment about direct access via sysfs which would
lead one think ad5933 driver has limitations it actually doesn't.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
b/drivers/staging/iio/impedance-analyzer/Kconfig
index dd97b6bb3fd0..b9a679cdd146 100644
--- a/drivers/staging/iio/impedance-analyzer/Kconfig
+++ b/drivers/staging/iio/impedance-analyzer/Kconfig
@@ -10,7 +10,7 @@ config AD5933
select IIO_KFIFO_BUF
help
  Say yes here to build support for Analog Devices Impedance Converter,
- Network Analyzer, AD5933/4, provides direct access via sysfs.
+ Network Analyzer, AD5933/4.
 
  To compile this driver as a module, choose M here: the
  module will be called ad5933.
-- 
2.20.1



[PATCH v4 1/7] staging: iio: ad5933: change multi-line comment style

2019-03-16 Thread Marcelo Schmitt
Make multi-line comments compliant with the preferred code style.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 3134295f014f..05e2185bfdae 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -474,7 +474,8 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
ad5933_store,
AD5933_OUT_SETTLING_CYCLES);
 
-/* note:
+/*
+ * note:
  * ideally we would handle the scale attributes via the iio_info
  * (read|write)_raw methods, however this part is a untypical since we
  * don't create dedicated sysfs channel attributes for out0 and in0.
@@ -572,7 +573,8 @@ static int ad5933_ring_postenable(struct iio_dev *indio_dev)
 {
struct ad5933_state *st = iio_priv(indio_dev);
 
-   /* AD5933_CTRL_INIT_START_FREQ:
+   /*
+* AD5933_CTRL_INIT_START_FREQ:
 * High Q complex circuits require a long time to reach steady state.
 * To facilitate the measurement of such impedances, this mode allows
 * the user full control of the settling time requirement before
@@ -663,7 +665,8 @@ static void ad5933_work(struct work_struct *work)
}
 
if (status & AD5933_STAT_SWEEP_DONE) {
-   /* last sample received - power down do
+   /*
+* last sample received - power down do
 * nothing until the ring enable is toggled
 */
ad5933_cmd(st, AD5933_CTRL_POWER_DOWN);
-- 
2.20.1



[PATCH v4 2/7] staging: iio: ad5933: organize includes

2019-03-16 Thread Marcelo Schmitt
Organize includes to list them in lexicographic order.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/ad5933.c| 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 05e2185bfdae..c2a7a59e469c 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -6,22 +6,22 @@
  * Licensed under the GPL-2.
  */
 
-#include 
+#include 
+#include 
 #include 
-#include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 
-#include 
-#include 
 #include 
+#include 
 #include 
+#include 
 
 /* AD5933/AD5934 Registers */
 #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
-- 
2.20.1



[PATCH v4 0/7] staging: iio: ad5933: move out of staging

2019-03-16 Thread Marcelo Schmitt


This series of patches make code style adjusts on comments and include
order.
It adds a SPDX license identifier of GPL-2.0.
It makes Kconfig help message more compact and correct.
It adds an ABI documentation for the device attributes.
It changes device attributes' names to match or be similar to existing
ABI.
Finally, it moves the ad5933 driver from staging directory to iio main
drivers directory.

Marcelo Schmitt (7):
  staging: iio: ad5933: change multi-line comment style
  staging: iio: ad5933: organize includes
  staging: iio: ad5933: add SPDX identifier
  staging: iio: ad5933: change help rule message
  staging: iio: ad5933: add ABI documentation
  staging: iio: ad5933: change attributes to match ABI
  staging: iio: ad5933: move out of staging

 .../sysfs-bus-iio-impedance-analyzer-ad5933   |  35 +
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 .../sysfs-bus-iio-impedance-analyzer-ad5933   |  30 -
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 809 -
 8 files changed, 869 insertions(+), 862 deletions(-)
 create mode 100644 
Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 
drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

-- 
2.20.1



Re: [PATCH v3 5/7] staging: iio: ad5933: add ABI documentation

2019-03-12 Thread Marcelo Schmitt
On 03/11, Alexandru Ardelean wrote:
> On Sun, Mar 10, 2019 at 7:47 PM Marcelo Schmitt
>  wrote:
> >
> > Add an ABI documentation for the ad5933 driver.
> 
> There's already an ABI documentation for this driver.
> See:
> https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/tree/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933
> 
> Apologies for not mentioning this sooner.
> 
> Could you check for other references for ad5933 in the kernel (in staging) ?
> I don't think I missed other stuff, but it's good to check.
>

Didn't see any other reference for ad5933 with find and grep inside iio,
neither on general documentation. I'll replace mine ABI doc by yours and
add your sign-off-by on my next patch set. OK?
 
> >
> > Signed-off-by: Marcelo Schmitt 
> > ---
> >  .../ABI/testing/sysfs-bus-iio-ad5933  | 39 +++
> >  1 file changed, 39 insertions(+)
> >  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-ad5933
> >
> > diff --git a/Documentation/ABI/testing/sysfs-bus-iio-ad5933 
> > b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
> > new file mode 100644
> > index ..8a60dd178b1f
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
> > @@ -0,0 +1,39 @@
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_start
> > +Date:  March 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   The start frequency. Set this to define the frequency point 
> > at
> > +   which the device should start the next frequency sweep.
> > +
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_increment
> > +Date:  March 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   The frequency sweep increment. Set this to define the 
> > amount by
> > +   which the frequency is incremented after each scan point. 
> > After
> > +   the measurement at a frequency point is completed, the next
> > +   measurement will be made at a frequency point
> > +   'frequency increment'Hz higher than the previous one unless 
> > a
> > +   repeat frequency command is issued. This behavior will 
> > follow
> > +   until the defined number of frequency points have been 
> > measured
> > +   or frequency sweep is somewhat reset.
> > +
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_points
> > +Date:  March 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   The number of increments. This defines the number of 
> > frequency
> > +   points in the frequency sweep.
> > +
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_settling_cycles
> > +Date:  March 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   Number of settling time cycles. This sets the delay between 
> > a
> > +   start frequency sweep/increment frequency /repeat frequency 
> > to
> > +   be proportional to the excitation signal frequency times the
> > +   number of settling time cycles.
> > --
> > 2.20.1
> >


[PATCH v3 6/7] staging: iio: ad5933: change attributes' ABI call

2019-03-10 Thread Marcelo Schmitt
Change device attributes to use more suitable ABI functions when setting
and displaying AC output excitation voltage. It better complies with
device hardware since these attributes are used to manage DDS
peak-to-peak output voltage.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index d75bdfbf93de..314cb71b1b5a 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -443,12 +443,12 @@ static ssize_t ad5933_store(struct device *dev,
return ret ? ret : len;
 }
 
-static IIO_DEVICE_ATTR(out_voltage0_scale, 0644,
+static IIO_DEVICE_ATTR(out_altvoltage0_raw, 0644,
ad5933_show,
ad5933_store,
AD5933_OUT_RANGE);
 
-static IIO_DEVICE_ATTR(out_voltage0_scale_available, 0444,
+static IIO_DEVICE_ATTR(out_altvoltage0_scale_available, 0444,
ad5933_show,
NULL,
AD5933_OUT_RANGE_AVAIL);
@@ -480,8 +480,8 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
  * don't create dedicated sysfs channel attributes for out0 and in0.
  */
 static struct attribute *ad5933_attributes[] = {
-   _dev_attr_out_voltage0_scale.dev_attr.attr,
-   _dev_attr_out_voltage0_scale_available.dev_attr.attr,
+   _dev_attr_out_altvoltage0_raw.dev_attr.attr,
+   _dev_attr_out_altvoltage0_scale_available.dev_attr.attr,
_dev_attr_out_voltage0_freq_start.dev_attr.attr,
_dev_attr_out_voltage0_freq_increment.dev_attr.attr,
_dev_attr_out_voltage0_freq_points.dev_attr.attr,
-- 
2.20.1



[PATCH v3 7/7] staging: iio: ad5933: move out of staging

2019-03-10 Thread Marcelo Schmitt
Move ad5933 impedance-analyzer driver from staging to mainline.

The ad5933 is a high precision impedance converter system solution that
combines an on-board frequency generator with an analog-to-digital
converter (ADC). This driver was designed to be compatible with both
ad5933 and ad5934 chips.

Signed-off-by: Marcelo Schmitt 
---
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 811 --
 6 files changed, 834 insertions(+), 834 deletions(-)
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

diff --git a/drivers/iio/impedance-analyzer/Kconfig 
b/drivers/iio/impedance-analyzer/Kconfig
new file mode 100644
index ..b9a679cdd146
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Kconfig
@@ -0,0 +1,18 @@
+#
+# Impedance Converter, Network Analyzer drivers
+#
+menu "Network Analyzer, Impedance Converters"
+
+config AD5933
+   tristate "Analog Devices AD5933, AD5934 driver"
+   depends on I2C
+   select IIO_BUFFER
+   select IIO_KFIFO_BUF
+   help
+ Say yes here to build support for Analog Devices Impedance Converter,
+ Network Analyzer, AD5933/4.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad5933.
+
+endmenu
diff --git a/drivers/iio/impedance-analyzer/Makefile 
b/drivers/iio/impedance-analyzer/Makefile
new file mode 100644
index ..7604d786583e
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for Impedance Converter, Network Analyzer drivers
+#
+
+obj-$(CONFIG_AD5933) += ad5933.o
diff --git a/drivers/iio/impedance-analyzer/ad5933.c 
b/drivers/iio/impedance-analyzer/ad5933.c
new file mode 100644
index ..314cb71b1b5a
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/ad5933.c
@@ -0,0 +1,811 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AD5933 AD5934 Impedance Converter, Network Analyzer
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/* AD5933/AD5934 Registers */
+#define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
+#define AD5933_REG_CONTROL_LB  0x81/* R/W, 1 byte */
+#define AD5933_REG_FREQ_START  0x82/* R/W, 3 bytes */
+#define AD5933_REG_FREQ_INC0x85/* R/W, 3 bytes */
+#define AD5933_REG_INC_NUM 0x88/* R/W, 2 bytes, 9 bit */
+#define AD5933_REG_SETTLING_CYCLES 0x8A/* R/W, 2 bytes */
+#define AD5933_REG_STATUS  0x8F/* R, 1 byte */
+#define AD5933_REG_TEMP_DATA   0x92/* R, 2 bytes*/
+#define AD5933_REG_REAL_DATA   0x94/* R, 2 bytes*/
+#define AD5933_REG_IMAG_DATA   0x96/* R, 2 bytes*/
+
+/* AD5933_REG_CONTROL_HB Bits */
+#define AD5933_CTRL_INIT_START_FREQ(0x1 << 4)
+#define AD5933_CTRL_START_SWEEP(0x2 << 4)
+#define AD5933_CTRL_INC_FREQ   (0x3 << 4)
+#define AD5933_CTRL_REPEAT_FREQ(0x4 << 4)
+#define AD5933_CTRL_MEASURE_TEMP   (0x9 << 4)
+#define AD5933_CTRL_POWER_DOWN (0xA << 4)
+#define AD5933_CTRL_STANDBY(0xB << 4)
+
+#define AD5933_CTRL_RANGE_2000mVpp (0x0 << 1)
+#define AD5933_CTRL_RANGE_200mVpp  (0x1 << 1)
+#define AD5933_CTRL_RANGE_400mVpp  (0x2 << 1)
+#define AD5933_CTRL_RANGE_1000mVpp (0x3 << 1)
+#define AD5933_CTRL_RANGE(x)   ((x) << 1)
+
+#define AD5933_CTRL_PGA_GAIN_1 (0x1 << 0)
+#define AD5933_CTRL_PGA_GAIN_5 (0x0 << 0)
+
+/* AD5933_REG_CONTROL_LB Bits */
+#define AD5933_CTRL_RESET  (0x1 << 4)
+#define AD5933_CTRL_INT_SYSCLK (0x0 << 3)
+#define AD5933_CTRL_EXT_SYSCLK (0x1 << 3)
+
+/* AD5933_REG_STATUS Bits */
+#define AD5933_STAT_TEMP_VALID (0x1 << 0)
+#define AD5933_STAT_DATA_VALID (0x1 << 1)
+#define AD5933_STAT_SWEEP_DONE (0x1 << 2)
+
+/* I2C Block Commands */
+#define AD5933_I2C_BLOCK_WRITE 0xA0
+#define AD5933_I2C_BLOCK_READ  0xA1
+#define AD5933_I2C_ADDR_POINTER0xB0
+
+/* Device Specs */
+#define AD5933_INT_OSC_FREQ_Hz 16776000
+#define AD5933_MAX_OUTPUT_FREQ_Hz  

[PATCH v3 5/7] staging: iio: ad5933: add ABI documentation

2019-03-10 Thread Marcelo Schmitt
Add an ABI documentation for the ad5933 driver.

Signed-off-by: Marcelo Schmitt 
---
 .../ABI/testing/sysfs-bus-iio-ad5933  | 39 +++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-ad5933

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-ad5933 
b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
new file mode 100644
index ..8a60dd178b1f
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
@@ -0,0 +1,39 @@
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_start
+Date:  March 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The start frequency. Set this to define the frequency point at
+   which the device should start the next frequency sweep.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_increment
+Date:  March 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The frequency sweep increment. Set this to define the amount by
+   which the frequency is incremented after each scan point. After
+   the measurement at a frequency point is completed, the next
+   measurement will be made at a frequency point 
+   'frequency increment'Hz higher than the previous one unless a
+   repeat frequency command is issued. This behavior will follow
+   until the defined number of frequency points have been measured
+   or frequency sweep is somewhat reset.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_points
+Date:  March 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The number of increments. This defines the number of frequency
+   points in the frequency sweep.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_settling_cycles
+Date:  March 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   Number of settling time cycles. This sets the delay between a
+   start frequency sweep/increment frequency /repeat frequency to
+   be proportional to the excitation signal frequency times the
+   number of settling time cycles.
-- 
2.20.1



[PATCH v3 4/7] staging: iio: ad5933: change help rule message

2019-03-10 Thread Marcelo Schmitt
Remove the previous comment about direct access via sysfs which would
lead one think ad5933 driver has limitations it actually doesn't.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
b/drivers/staging/iio/impedance-analyzer/Kconfig
index dd97b6bb3fd0..b9a679cdd146 100644
--- a/drivers/staging/iio/impedance-analyzer/Kconfig
+++ b/drivers/staging/iio/impedance-analyzer/Kconfig
@@ -10,7 +10,7 @@ config AD5933
select IIO_KFIFO_BUF
help
  Say yes here to build support for Analog Devices Impedance Converter,
- Network Analyzer, AD5933/4, provides direct access via sysfs.
+ Network Analyzer, AD5933/4.
 
  To compile this driver as a module, choose M here: the
  module will be called ad5933.
-- 
2.20.1



[PATCH v3 3/7] staging: iio: ad5933: add SPDX identifier

2019-03-10 Thread Marcelo Schmitt
Add SPDX identifier of GPL-2.0 for the ad5933 driver.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index c2a7a59e469c..d75bdfbf93de 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5933 AD5934 Impedance Converter, Network Analyzer
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
 #include 
-- 
2.20.1



[PATCH v3 1/7] staging: iio: ad5933: change multi-line comment style

2019-03-10 Thread Marcelo Schmitt
Make multi-line comments compliant with the preferred code style.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 3134295f014f..05e2185bfdae 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -474,7 +474,8 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
ad5933_store,
AD5933_OUT_SETTLING_CYCLES);
 
-/* note:
+/*
+ * note:
  * ideally we would handle the scale attributes via the iio_info
  * (read|write)_raw methods, however this part is a untypical since we
  * don't create dedicated sysfs channel attributes for out0 and in0.
@@ -572,7 +573,8 @@ static int ad5933_ring_postenable(struct iio_dev *indio_dev)
 {
struct ad5933_state *st = iio_priv(indio_dev);
 
-   /* AD5933_CTRL_INIT_START_FREQ:
+   /*
+* AD5933_CTRL_INIT_START_FREQ:
 * High Q complex circuits require a long time to reach steady state.
 * To facilitate the measurement of such impedances, this mode allows
 * the user full control of the settling time requirement before
@@ -663,7 +665,8 @@ static void ad5933_work(struct work_struct *work)
}
 
if (status & AD5933_STAT_SWEEP_DONE) {
-   /* last sample received - power down do
+   /*
+* last sample received - power down do
 * nothing until the ring enable is toggled
 */
ad5933_cmd(st, AD5933_CTRL_POWER_DOWN);
-- 
2.20.1



[PATCH v3 2/7] staging: iio: ad5933: organize includes

2019-03-10 Thread Marcelo Schmitt
Organize includes to list them in lexicographic order.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/ad5933.c| 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 05e2185bfdae..c2a7a59e469c 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -6,22 +6,22 @@
  * Licensed under the GPL-2.
  */
 
-#include 
+#include 
+#include 
 #include 
-#include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 
-#include 
-#include 
 #include 
+#include 
 #include 
+#include 
 
 /* AD5933/AD5934 Registers */
 #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
-- 
2.20.1



[PATCH v3 0/7] move out of staging

2019-03-10 Thread Marcelo Schmitt
This series of patches make code style adjusts on comments and include
order.
It adds a SPDX license identifier of GPL-2.0.
It makes Kconfig help message more compact and correct.
It adds an ABI documentation for the device attributes.
It changes device attributes to use more suitable ABI functions.
Finally, it moves the ad5933 driver from staging directory to iio main
drivers directory.


Marcelo Schmitt (7):
  staging: iio: ad5933: change multi-line comment style
  staging: iio: ad5933: organize includes
  staging: iio: ad5933: add SPDX identifier
  staging: iio: ad5933: change help rule message
  staging: iio: ad5933: add ABI documentation
  staging: iio: ad5933: change attributes' ABI call
  staging: iio: ad5933: move out of staging

 .../ABI/testing/sysfs-bus-iio-ad5933  |  39 +
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 809 -
 7 files changed, 873 insertions(+), 832 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-ad5933
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

-- 
2.20.1



Re: [PATCH v2 3/4] staging: iio: ad5933: add ABI documentation

2019-03-03 Thread Marcelo Schmitt
On 03/03, Jonathan Cameron wrote:
> On Thu, 28 Feb 2019 23:53:14 -0300
> Marcelo Schmitt  wrote:
> 
> > Add an ABI documentation for the ad5933 driver.
> > 
> > Signed-off-by: Marcelo Schmitt 
> Hi Marcelo,
> 
> The ABI that you have defined which is actually new is mostly fine,
> however it seems that some of the existing ABI is not used correctly
> and that will need to be fixed.
> 
> Jonathan

Hi Jonathan,

Thanks for the comments.

> 
> > ---
> >  .../ABI/testing/sysfs-bus-iio-ad5933  | 91 +++
> >  1 file changed, 91 insertions(+)
> >  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-ad5933
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-bus-iio-ad5933 
> > b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
> > new file mode 100644
> > index ..81e3d3f6f724
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
> > @@ -0,0 +1,91 @@
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_scale
> > +Date:  February 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   The output peak-to-peak voltage range. Writting 0 sets range
> > +   to 2.0V p-p typical, 1 sets range to 200mV p-p typical, 2 sets
> > +   range to 400mV p-p typical, 3 sets range to 1.0V p-p typical.
> > +   The p-p value of the ac output exitation voltage scales with 
> > +   supply voltage according to the following formula:
> > +   Output Excitation Voltage (V p-p) = normalized_3v3 × [VDD/3.3]
> > +   where normalized_3v3 is one of the four voltage range above and
> > +   VDD is the supply voltage.
> 
> Definitely not. The device must comply with standard ABI and this is not
> using it correctly (see below or the docs).
> 
> > +
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_scale_available
> > +Date:  February 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:   
> > +   Prints available peak-to-peak voltage range to buffer.
> 
> I really hope it doesn't.  Scale is a mulitplier not a range.  It should be
> printing out the value by which the _raw reading should be multiplied to
> get the voltage in the base units for voltage (millivolts)

As the driver is right now I believe that calling this device attribute will
print "1980, 970, 383, 198" which are the mean values of four distributions
(called range1 to range4) of possible actual millivolt values used as the AC
output excitation. Certainly they don't mean "the value by which the _raw
reading should be multiplied to get the voltage in the base units for voltage"
so, as you said, this ABI is probably being misused here. Hence, I guess
I ought to change this attribute's call to something different than 
out_voltage0_scale_available (as well as the out_voltage0_scale above). Maybe
out_voltage0_excit_available or out_voltage0_mean_excit_available, any other
suggestion?

> 
> > +
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_start
> > +Date:  February 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   The start frequency. Set this to define de frequency point at
> > +   which the device should start the next frequency sweep. Default
> > +   start frequency point set to 1Hz.
> 
> No need to specify the default. It's trivial to read and any user of this
> chip should set it to the value they want.

OK, then I will remove these on the next patch.

> 
> > +
> > +What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_increment
> > +Date:  February 2019
> > +KernelVersion: Kernel 4.19
> > +Contact:   linux-...@vger.kernel.org
> > +Description:
> > +   The frequency sweep increment. Set this to define at which rate
> > +   frequency sweep points are incremented. 
> Rate is a temporal term.  Perhaps "step by which the frequency is 
> incremented"?

Maybe

"define the amount by which the frequency is incremented after each scan point."

would it be ok?

> 
> > After the measurement at
> > +   a frequency point is completed, the next measurement will be 
> > +   made with a frequency 'frequency increment'Hz higher than the
> > +   previous point until the defined number of increments has been
> > +   made. Default frequency increment set to 200Hz.
> 
> No need to specify the default

[PATCH v2 4/4] staging: iio: ad5933: move out of staging

2019-02-28 Thread Marcelo Schmitt
Move ad5933 impedance-analyzer driver from staging to mainline.

The ad5933 is a high precision impedance converter system solution that
combines an on-board frequency generator with an analog-to-digital
converter (ADC). This driver was designed to be compatible with both
ad5933 and ad5934 chips.

Signed-off-by: Marcelo Schmitt 
---
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 811 --
 6 files changed, 834 insertions(+), 834 deletions(-)
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

diff --git a/drivers/iio/impedance-analyzer/Kconfig 
b/drivers/iio/impedance-analyzer/Kconfig
new file mode 100644
index ..b9a679cdd146
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Kconfig
@@ -0,0 +1,18 @@
+#
+# Impedance Converter, Network Analyzer drivers
+#
+menu "Network Analyzer, Impedance Converters"
+
+config AD5933
+   tristate "Analog Devices AD5933, AD5934 driver"
+   depends on I2C
+   select IIO_BUFFER
+   select IIO_KFIFO_BUF
+   help
+ Say yes here to build support for Analog Devices Impedance Converter,
+ Network Analyzer, AD5933/4.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad5933.
+
+endmenu
diff --git a/drivers/iio/impedance-analyzer/Makefile 
b/drivers/iio/impedance-analyzer/Makefile
new file mode 100644
index ..7604d786583e
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for Impedance Converter, Network Analyzer drivers
+#
+
+obj-$(CONFIG_AD5933) += ad5933.o
diff --git a/drivers/iio/impedance-analyzer/ad5933.c 
b/drivers/iio/impedance-analyzer/ad5933.c
new file mode 100644
index ..d75bdfbf93de
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/ad5933.c
@@ -0,0 +1,811 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AD5933 AD5934 Impedance Converter, Network Analyzer
+ *
+ * Copyright 2011 Analog Devices Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/* AD5933/AD5934 Registers */
+#define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
+#define AD5933_REG_CONTROL_LB  0x81/* R/W, 1 byte */
+#define AD5933_REG_FREQ_START  0x82/* R/W, 3 bytes */
+#define AD5933_REG_FREQ_INC0x85/* R/W, 3 bytes */
+#define AD5933_REG_INC_NUM 0x88/* R/W, 2 bytes, 9 bit */
+#define AD5933_REG_SETTLING_CYCLES 0x8A/* R/W, 2 bytes */
+#define AD5933_REG_STATUS  0x8F/* R, 1 byte */
+#define AD5933_REG_TEMP_DATA   0x92/* R, 2 bytes*/
+#define AD5933_REG_REAL_DATA   0x94/* R, 2 bytes*/
+#define AD5933_REG_IMAG_DATA   0x96/* R, 2 bytes*/
+
+/* AD5933_REG_CONTROL_HB Bits */
+#define AD5933_CTRL_INIT_START_FREQ(0x1 << 4)
+#define AD5933_CTRL_START_SWEEP(0x2 << 4)
+#define AD5933_CTRL_INC_FREQ   (0x3 << 4)
+#define AD5933_CTRL_REPEAT_FREQ(0x4 << 4)
+#define AD5933_CTRL_MEASURE_TEMP   (0x9 << 4)
+#define AD5933_CTRL_POWER_DOWN (0xA << 4)
+#define AD5933_CTRL_STANDBY(0xB << 4)
+
+#define AD5933_CTRL_RANGE_2000mVpp (0x0 << 1)
+#define AD5933_CTRL_RANGE_200mVpp  (0x1 << 1)
+#define AD5933_CTRL_RANGE_400mVpp  (0x2 << 1)
+#define AD5933_CTRL_RANGE_1000mVpp (0x3 << 1)
+#define AD5933_CTRL_RANGE(x)   ((x) << 1)
+
+#define AD5933_CTRL_PGA_GAIN_1 (0x1 << 0)
+#define AD5933_CTRL_PGA_GAIN_5 (0x0 << 0)
+
+/* AD5933_REG_CONTROL_LB Bits */
+#define AD5933_CTRL_RESET  (0x1 << 4)
+#define AD5933_CTRL_INT_SYSCLK (0x0 << 3)
+#define AD5933_CTRL_EXT_SYSCLK (0x1 << 3)
+
+/* AD5933_REG_STATUS Bits */
+#define AD5933_STAT_TEMP_VALID (0x1 << 0)
+#define AD5933_STAT_DATA_VALID (0x1 << 1)
+#define AD5933_STAT_SWEEP_DONE (0x1 << 2)
+
+/* I2C Block Commands */
+#define AD5933_I2C_BLOCK_WRITE 0xA0
+#define AD5933_I2C_BLOCK_READ  0xA1
+#define AD5933_I2C_ADDR_POINTER0xB0
+
+/* Device Specs */
+#define AD5933_INT_OSC_FREQ_Hz 16776000
+#define AD5933_MAX_OUTPUT_FREQ_Hz  

[PATCH v2 2/4] staging: iio: ad5933: change help rule message

2019-02-28 Thread Marcelo Schmitt
Remove the previous comment about direct access via sysfs which would
lead one think ad5933 driver has limitations it actually doesn't.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
b/drivers/staging/iio/impedance-analyzer/Kconfig
index dd97b6bb3fd0..b9a679cdd146 100644
--- a/drivers/staging/iio/impedance-analyzer/Kconfig
+++ b/drivers/staging/iio/impedance-analyzer/Kconfig
@@ -10,7 +10,7 @@ config AD5933
select IIO_KFIFO_BUF
help
  Say yes here to build support for Analog Devices Impedance Converter,
- Network Analyzer, AD5933/4, provides direct access via sysfs.
+ Network Analyzer, AD5933/4.
 
  To compile this driver as a module, choose M here: the
  module will be called ad5933.
-- 
2.20.1



[PATCH v2 3/4] staging: iio: ad5933: add ABI documentation

2019-02-28 Thread Marcelo Schmitt
Add an ABI documentation for the ad5933 driver.

Signed-off-by: Marcelo Schmitt 
---
 .../ABI/testing/sysfs-bus-iio-ad5933  | 91 +++
 1 file changed, 91 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-ad5933

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-ad5933 
b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
new file mode 100644
index ..81e3d3f6f724
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-ad5933
@@ -0,0 +1,91 @@
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_scale
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The output peak-to-peak voltage range. Writting 0 sets range
+   to 2.0V p-p typical, 1 sets range to 200mV p-p typical, 2 sets
+   range to 400mV p-p typical, 3 sets range to 1.0V p-p typical.
+   The p-p value of the ac output exitation voltage scales with 
+   supply voltage according to the following formula:
+   Output Excitation Voltage (V p-p) = normalized_3v3 × [VDD/3.3]
+   where normalized_3v3 is one of the four voltage range above and
+   VDD is the supply voltage.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_scale_available
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:   
+   Prints available peak-to-peak voltage range to buffer.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_start
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The start frequency. Set this to define de frequency point at
+   which the device should start the next frequency sweep. Default
+   start frequency point set to 1Hz.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_increment
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The frequency sweep increment. Set this to define at which rate
+   frequency sweep points are incremented. After the measurement at
+   a frequency point is completed, the next measurement will be 
+   made with a frequency 'frequency increment'Hz higher than the
+   previous point until the defined number of increments has been
+   made. Default frequency increment set to 200Hz.
+   
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_points
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The number of increments. This defines the number of frequency
+   points in the frequency sweep. Device stores a 9-bit integer
+   number in binary format for this so the maximum number of
+   increments that can be programmed is 511.
+
+What:/sys/bus/iio/devices/iio:deviceX/out_voltage0_settling_cycles
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   Number of settling time cycles. This attribute is a 11 bit field
+   divided in two parts. The 9 least significant bit define the
+   number of output excitation cycles that are passed through the
+   unknown impedance, after the receipt of a start frequency sweep,
+   increment frequency, or repeat frequency command, before the ADC
+   is triggered to perform a conversion of the response signal. The
+   2 most significant bits define a multiplier for the number of
+   cycles obtained from de least significant bits. Let D10 and D9
+   be these two bits, the resulting multiplier is defined as
+   follows.
+   D10 D9 = 0 0 => No. of cycles x 1 (default)
+   D10 D9 = 0 1 => No. of cycles x 2
+   D10 D9 = 1 0 => Reserved
+   D10 D9 = 1 1 => No. of cycles x 4
+
+   See the datasheet for detailed information.
+
+What:/sys/bus/iio/devices/iio:deviceX/in_voltage0_scale
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   The PGA gain amplifier for the response signal. Set this to 0
+   to gain the output of the current-to-voltage amplifier by a
+   factor of 5. Set to 1 (default) to amplify the response signal
+   into the ADC by a multiplication factor of x1.
+
+What:/sys/bus/iio/devices/iio:deviceX/in_voltage0_scale_available
+Date:  February 2019
+KernelVersion: Kernel 4.19
+Contact:   linux-...@vger.kernel.org
+Description:
+   Prints available PGA gain amplifier to buffer.
-- 
2.20.1



[PATCH v2 1/4] staging: iio: ad5933: add SPDX identifier

2019-02-28 Thread Marcelo Schmitt
Add SPDX identifier of GPL-2.0 for the ad5933 driver.
Organize imports.
Make multi-line comments compliant with the preferred code style.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/ad5933.c   | 30 ++-
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 3134295f014f..d75bdfbf93de 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -1,27 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AD5933 AD5934 Impedance Converter, Network Analyzer
  *
  * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
  */
 
-#include 
+#include 
+#include 
 #include 
-#include 
-#include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
-#include 
-#include 
-#include 
-#include 
 
-#include 
-#include 
 #include 
+#include 
 #include 
+#include 
 
 /* AD5933/AD5934 Registers */
 #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
@@ -474,7 +473,8 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644,
ad5933_store,
AD5933_OUT_SETTLING_CYCLES);
 
-/* note:
+/*
+ * note:
  * ideally we would handle the scale attributes via the iio_info
  * (read|write)_raw methods, however this part is a untypical since we
  * don't create dedicated sysfs channel attributes for out0 and in0.
@@ -572,7 +572,8 @@ static int ad5933_ring_postenable(struct iio_dev *indio_dev)
 {
struct ad5933_state *st = iio_priv(indio_dev);
 
-   /* AD5933_CTRL_INIT_START_FREQ:
+   /*
+* AD5933_CTRL_INIT_START_FREQ:
 * High Q complex circuits require a long time to reach steady state.
 * To facilitate the measurement of such impedances, this mode allows
 * the user full control of the settling time requirement before
@@ -663,7 +664,8 @@ static void ad5933_work(struct work_struct *work)
}
 
if (status & AD5933_STAT_SWEEP_DONE) {
-   /* last sample received - power down do
+   /*
+* last sample received - power down do
 * nothing until the ring enable is toggled
 */
ad5933_cmd(st, AD5933_CTRL_POWER_DOWN);
-- 
2.20.1



[PATCH v2 0/4] staging: iio: ad5933: move out of staging

2019-02-28 Thread Marcelo Schmitt
This series of patches add SPDX license identifier for GPL-2.0 along
with minor code style ajusts.
It makes Kconfig help message more compact and correct.
Also it adds an ABI documentation for the devise attributes.
Finally, it moves the ad5933 driver from staging directory to iio main
drivers directory.


Marcelo Schmitt (4):
  staging: iio: ad5933: add SPDX identifier
  staging: iio: ad5933: change help rule message
  staging: iio: ad5933: add ABI documentation
  staging: iio: ad5933: move out of staging

 .../ABI/testing/sysfs-bus-iio-ad5933  |  91 ++
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 811 ++
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 809 -
 7 files changed, 925 insertions(+), 832 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-ad5933
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

-- 
2.20.1



Re: [PATCH] staging: iio: ad5933: move out of staging

2019-02-11 Thread Marcelo Schmitt
On 02/11, Jonathan Cameron wrote:
> On Mon, 11 Feb 2019 13:43:11 -0200
> Marcelo Schmitt  wrote:
> 
> > Move ad5933 impedance-analyzer driver from staging to mainline.
> > 
> > The ad5933 is a high precision impedance converter system
> > solution that combines an on-board frequency generator with an
> > analog-to-digital converter (ADC). This driver was designed to be
> > compatible with both ad5933 and ad5934 chips.
> > 
> > Signed-off-by: Marcelo Schmitt 
> Hi Marcelo,
> 
> Mostly this is fine.  There are a few tweaks inline.  However
> it has a fairly extensive non standard ABI.  That needs documenting
> and discussing before we move this out of staging.
> 
> Please propose a new ABI doc, probably device specific for now...
> 
> Documentation/ABI/testing/sysfs-bus-iio-ad5933
> 
> to document what those elements actually do...
> Superficially they look sensible, but we need units etc to be
> clearly described.  It would also be worth adding some description
> in comments for how the interface works.
> 
> Thanks,
> 
> Jonathan
> 

Hi Jonathan,

Thanks for the advise. I'll work on the requested docs and changes.

Best reguards,

Marcelo

> > ---
> >  drivers/iio/impedance-analyzer/Kconfig|  18 +
> >  drivers/iio/impedance-analyzer/Makefile   |   5 +
> >  drivers/iio/impedance-analyzer/ad5933.c   | 810 ++
> >  .../staging/iio/impedance-analyzer/Kconfig|  18 -
> >  .../staging/iio/impedance-analyzer/Makefile   |   5 -
> >  .../staging/iio/impedance-analyzer/ad5933.c   | 809 -
> >  6 files changed, 833 insertions(+), 832 deletions(-)
> >  create mode 100644 drivers/iio/impedance-analyzer/Kconfig
> >  create mode 100644 drivers/iio/impedance-analyzer/Makefile
> >  create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
> >  delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
> >  delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
> >  delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c
> > 
> > diff --git a/drivers/iio/impedance-analyzer/Kconfig 
> > b/drivers/iio/impedance-analyzer/Kconfig
> > new file mode 100644
> > index ..dd97b6bb3fd0
> > --- /dev/null
> > +++ b/drivers/iio/impedance-analyzer/Kconfig
> > @@ -0,0 +1,18 @@
> > +#
> > +# Impedance Converter, Network Analyzer drivers
> > +#
> > +menu "Network Analyzer, Impedance Converters"
> > +
> > +config AD5933
> > +   tristate "Analog Devices AD5933, AD5934 driver"
> > +   depends on I2C
> > +   select IIO_BUFFER
> > +   select IIO_KFIFO_BUF
> > +   help
> > + Say yes here to build support for Analog Devices Impedance Converter,
> > + Network Analyzer, AD5933/4, provides direct access via sysfs.
> 
> This is rather more limited than the driver actually is.
> Has a chardev based interface for example. I'd just drop
> the last bit about sysfs as it implies false limitations.
> 
> > +
> > + To compile this driver as a module, choose M here: the
> > + module will be called ad5933.
> > +
> > +endmenu
> > diff --git a/drivers/iio/impedance-analyzer/Makefile 
> > b/drivers/iio/impedance-analyzer/Makefile
> > new file mode 100644
> > index ..7604d786583e
> > --- /dev/null
> > +++ b/drivers/iio/impedance-analyzer/Makefile
> > @@ -0,0 +1,5 @@
> > +#
> > +# Makefile for Impedance Converter, Network Analyzer drivers
> > +#
> > +
> > +obj-$(CONFIG_AD5933) += ad5933.o
> > diff --git a/drivers/iio/impedance-analyzer/ad5933.c 
> > b/drivers/iio/impedance-analyzer/ad5933.c
> > new file mode 100644
> > index ..839bc30682e4
> > --- /dev/null
> > +++ b/drivers/iio/impedance-analyzer/ad5933.c
> > @@ -0,0 +1,810 @@
> > +/*
> > + * AD5933 AD5934 Impedance Converter, Network Analyzer
> > + *
> > + * Copyright 2011 Analog Devices Inc.
> > + *
> > + * Licensed under the GPL-2.
> SPDX preferred.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +
> > +/* AD5933/AD5934 Registers */
> > +#define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
> > +#define AD5933_REG_CONTROL_LB  0x81/* R/W, 1 byte */
> > +#define AD5933_REG_

[PATCH] staging: iio: ad5933: move out of staging

2019-02-11 Thread Marcelo Schmitt
Move ad5933 impedance-analyzer driver from staging to mainline.

The ad5933 is a high precision impedance converter system
solution that combines an on-board frequency generator with an
analog-to-digital converter (ADC). This driver was designed to be
compatible with both ad5933 and ad5934 chips.

Signed-off-by: Marcelo Schmitt 
---
 drivers/iio/impedance-analyzer/Kconfig|  18 +
 drivers/iio/impedance-analyzer/Makefile   |   5 +
 drivers/iio/impedance-analyzer/ad5933.c   | 810 ++
 .../staging/iio/impedance-analyzer/Kconfig|  18 -
 .../staging/iio/impedance-analyzer/Makefile   |   5 -
 .../staging/iio/impedance-analyzer/ad5933.c   | 809 -
 6 files changed, 833 insertions(+), 832 deletions(-)
 create mode 100644 drivers/iio/impedance-analyzer/Kconfig
 create mode 100644 drivers/iio/impedance-analyzer/Makefile
 create mode 100644 drivers/iio/impedance-analyzer/ad5933.c
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig
 delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile
 delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c

diff --git a/drivers/iio/impedance-analyzer/Kconfig 
b/drivers/iio/impedance-analyzer/Kconfig
new file mode 100644
index ..dd97b6bb3fd0
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Kconfig
@@ -0,0 +1,18 @@
+#
+# Impedance Converter, Network Analyzer drivers
+#
+menu "Network Analyzer, Impedance Converters"
+
+config AD5933
+   tristate "Analog Devices AD5933, AD5934 driver"
+   depends on I2C
+   select IIO_BUFFER
+   select IIO_KFIFO_BUF
+   help
+ Say yes here to build support for Analog Devices Impedance Converter,
+ Network Analyzer, AD5933/4, provides direct access via sysfs.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad5933.
+
+endmenu
diff --git a/drivers/iio/impedance-analyzer/Makefile 
b/drivers/iio/impedance-analyzer/Makefile
new file mode 100644
index ..7604d786583e
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for Impedance Converter, Network Analyzer drivers
+#
+
+obj-$(CONFIG_AD5933) += ad5933.o
diff --git a/drivers/iio/impedance-analyzer/ad5933.c 
b/drivers/iio/impedance-analyzer/ad5933.c
new file mode 100644
index ..839bc30682e4
--- /dev/null
+++ b/drivers/iio/impedance-analyzer/ad5933.c
@@ -0,0 +1,810 @@
+/*
+ * AD5933 AD5934 Impedance Converter, Network Analyzer
+ *
+ * Copyright 2011 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* AD5933/AD5934 Registers */
+#define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
+#define AD5933_REG_CONTROL_LB  0x81/* R/W, 1 byte */
+#define AD5933_REG_FREQ_START  0x82/* R/W, 3 bytes */
+#define AD5933_REG_FREQ_INC0x85/* R/W, 3 bytes */
+#define AD5933_REG_INC_NUM 0x88/* R/W, 2 bytes, 9 bit */
+#define AD5933_REG_SETTLING_CYCLES 0x8A/* R/W, 2 bytes */
+#define AD5933_REG_STATUS  0x8F/* R, 1 byte */
+#define AD5933_REG_TEMP_DATA   0x92/* R, 2 bytes*/
+#define AD5933_REG_REAL_DATA   0x94/* R, 2 bytes*/
+#define AD5933_REG_IMAG_DATA   0x96/* R, 2 bytes*/
+
+/* AD5933_REG_CONTROL_HB Bits */
+#define AD5933_CTRL_INIT_START_FREQ(0x1 << 4)
+#define AD5933_CTRL_START_SWEEP(0x2 << 4)
+#define AD5933_CTRL_INC_FREQ   (0x3 << 4)
+#define AD5933_CTRL_REPEAT_FREQ(0x4 << 4)
+#define AD5933_CTRL_MEASURE_TEMP   (0x9 << 4)
+#define AD5933_CTRL_POWER_DOWN (0xA << 4)
+#define AD5933_CTRL_STANDBY(0xB << 4)
+
+#define AD5933_CTRL_RANGE_2000mVpp (0x0 << 1)
+#define AD5933_CTRL_RANGE_200mVpp  (0x1 << 1)
+#define AD5933_CTRL_RANGE_400mVpp  (0x2 << 1)
+#define AD5933_CTRL_RANGE_1000mVpp (0x3 << 1)
+#define AD5933_CTRL_RANGE(x)   ((x) << 1)
+
+#define AD5933_CTRL_PGA_GAIN_1 (0x1 << 0)
+#define AD5933_CTRL_PGA_GAIN_5 (0x0 << 0)
+
+/* AD5933_REG_CONTROL_LB Bits */
+#define AD5933_CTRL_RESET  (0x1 << 4)
+#define AD5933_CTRL_INT_SYSCLK (0x0 << 3)
+#define AD5933_CTRL_EXT_SYSCLK (0x1 << 3)
+
+/* AD5933_REG_STATUS Bits */
+#define AD5933_STAT_TEMP_VALID (0x1 << 0)
+#define AD5933_STAT_DATA_VALID (0x1 << 1)
+#define AD5933_STAT_SWEEP_DONE (0x1 << 2)
+
+/* I2C Block Commands */
+#define AD5933_I2C_BLOCK_WRITE 0xA0
+#define AD5933_I2C_BLOCK_READ  0xA1
+#define AD5933_I2C_ADDR_POINTER0xB0
+
+/* Device Specs */
+#define AD5933_INT_OSC_FREQ_Hz 16776000
+#d

Re: [PATCH 0/3] Add devicetree support for ad5933

2018-12-08 Thread Marcelo Schmitt
Parts of this work came from contributions of Alexandru Ardelean and
Dragos Bogdan, I and Gabriel would like to thank for the insights
provided by their previous patches. Maybe it would be the case to add
them as co-authors of this patch set.
We also wanted to thank Jhonatan Cameron for giving us the pieces of
advice needed for this work.

Thanks,
Marcelo

Em sáb, 8 de dez de 2018 às 16:18, Marcelo Schmitt
 escreveu:
>
> This series of patches change voltage regulator error handling for the
> ad5933.
> It also add an option to specify external clock reference using a clock
> framework and remove the old platform data structure.
> Finally it adds binding documentation for devicetree.
>
> Marcelo Schmitt (3):
>   staging: iio: ad5933: change regulator binging for vref
>   staging: iio: ad5933: use clock framework for clock reference
>   staging: iio: ad5933: add binding doc for ad5933
>
>  .../iio/impedance-analyzer/ad5933.txt | 26 +
>  .../staging/iio/impedance-analyzer/ad5933.c   | 57 +--
>  2 files changed, 54 insertions(+), 29 deletions(-)
>  create mode 100644 
> Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
>
> --
> 2.17.1
>


Re: [PATCH 0/3] Add devicetree support for ad5933

2018-12-08 Thread Marcelo Schmitt
Parts of this work came from contributions of Alexandru Ardelean and
Dragos Bogdan, I and Gabriel would like to thank for the insights
provided by their previous patches. Maybe it would be the case to add
them as co-authors of this patch set.
We also wanted to thank Jhonatan Cameron for giving us the pieces of
advice needed for this work.

Thanks,
Marcelo

Em sáb, 8 de dez de 2018 às 16:18, Marcelo Schmitt
 escreveu:
>
> This series of patches change voltage regulator error handling for the
> ad5933.
> It also add an option to specify external clock reference using a clock
> framework and remove the old platform data structure.
> Finally it adds binding documentation for devicetree.
>
> Marcelo Schmitt (3):
>   staging: iio: ad5933: change regulator binging for vref
>   staging: iio: ad5933: use clock framework for clock reference
>   staging: iio: ad5933: add binding doc for ad5933
>
>  .../iio/impedance-analyzer/ad5933.txt | 26 +
>  .../staging/iio/impedance-analyzer/ad5933.c   | 57 +--
>  2 files changed, 54 insertions(+), 29 deletions(-)
>  create mode 100644 
> Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
>
> --
> 2.17.1
>


[PATCH 3/3] staging: iio: ad5933: add binding doc for ad5933

2018-12-08 Thread Marcelo Schmitt
Add a devicetree documentation for the ad5933 and ad5934 impedance
converter, network analyzer.

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
Co-Developed-by: Gabriel Capella 
---
 .../iio/impedance-analyzer/ad5933.txt | 26 +++
 1 file changed, 26 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt

diff --git 
a/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt 
b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
new file mode 100644
index ..5ff38728ff91
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
@@ -0,0 +1,26 @@
+Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer
+
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf
+
+Required properties:
+ - compatible : should be one of
+   "adi,ad5933"
+   "adi,ad5934"
+ - reg : the I2C address.
+ - vdd-supply : The regulator supply for DVDD, AVDD1 and AVDD2 when they
+   are connected together.
+
+Optional properties:
+- clocks : external clock reference.
+- clock-names : must be "mclk" if clocks is set.
+
+Example for a I2C device node:
+
+   impedance-analyzer@0d {
+   compatible = "adi,adxl345";
+   reg = <0x0d>;
+   vdd-supply = <_supply>;
+   clocks = <_clk>;
+   clock-names = "mclk";
+   };
-- 
2.17.1



[PATCH 3/3] staging: iio: ad5933: add binding doc for ad5933

2018-12-08 Thread Marcelo Schmitt
Add a devicetree documentation for the ad5933 and ad5934 impedance
converter, network analyzer.

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
Co-Developed-by: Gabriel Capella 
---
 .../iio/impedance-analyzer/ad5933.txt | 26 +++
 1 file changed, 26 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt

diff --git 
a/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt 
b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
new file mode 100644
index ..5ff38728ff91
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
@@ -0,0 +1,26 @@
+Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer
+
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf
+
+Required properties:
+ - compatible : should be one of
+   "adi,ad5933"
+   "adi,ad5934"
+ - reg : the I2C address.
+ - vdd-supply : The regulator supply for DVDD, AVDD1 and AVDD2 when they
+   are connected together.
+
+Optional properties:
+- clocks : external clock reference.
+- clock-names : must be "mclk" if clocks is set.
+
+Example for a I2C device node:
+
+   impedance-analyzer@0d {
+   compatible = "adi,adxl345";
+   reg = <0x0d>;
+   vdd-supply = <_supply>;
+   clocks = <_clk>;
+   clock-names = "mclk";
+   };
-- 
2.17.1



[PATCH 2/3] staging: iio: ad5933: use clock framework for clock reference

2018-12-08 Thread Marcelo Schmitt
Add the option to specify the external clock (MCLK) using the clock
framework.
Also remove the old platform data structure.

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
Co-Developed-by: Gabriel Capella 
---
 .../staging/iio/impedance-analyzer/ad5933.c   | 43 ++-
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 730bc397a26b..3134295f014f 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -82,20 +83,10 @@
 #define AD5933_POLL_TIME_ms10
 #define AD5933_INIT_EXCITATION_TIME_ms 100
 
-/**
- * struct ad5933_platform_data - platform specific data
- * @ext_clk_hz:the external clock frequency in Hz, if not set
- * the driver uses the internal clock (16.776 MHz)
- * @vref_mv:   the external reference voltage in millivolt
- */
-
-struct ad5933_platform_data {
-   unsigned long   ext_clk_hz;
-};
-
 struct ad5933_state {
struct i2c_client   *client;
struct regulator*reg;
+   struct clk  *mclk;
struct delayed_work work;
struct mutexlock; /* Protect sensor state */
unsigned long   mclk_hz;
@@ -111,9 +102,6 @@ struct ad5933_state {
unsigned intpoll_time_jiffies;
 };
 
-static struct ad5933_platform_data ad5933_default_pdata  = {
-};
-
 #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
_scan_index, _realbits) { \
.type = (_type), \
@@ -690,9 +678,9 @@ static int ad5933_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
int ret;
-   struct ad5933_platform_data *pdata = dev_get_platdata(>dev);
struct ad5933_state *st;
struct iio_dev *indio_dev;
+   unsigned long ext_clk_hz = 0;
 
indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
if (!indio_dev)
@@ -704,9 +692,6 @@ static int ad5933_probe(struct i2c_client *client,
 
mutex_init(>lock);
 
-   if (!pdata)
-   pdata = _default_pdata;
-
st->reg = devm_regulator_get(>dev, "vdd");
if (IS_ERR(st->reg))
return PTR_ERR(st->reg);
@@ -723,8 +708,21 @@ static int ad5933_probe(struct i2c_client *client,
 
st->vref_mv = ret / 1000;
 
-   if (pdata->ext_clk_hz) {
-   st->mclk_hz = pdata->ext_clk_hz;
+   st->mclk = devm_clk_get(>dev, "mclk");
+   if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) {
+   ret = PTR_ERR(st->mclk);
+   goto error_disable_reg;
+   }
+
+   if (!IS_ERR(st->mclk)) {
+   ret = clk_prepare_enable(st->mclk);
+   if (ret < 0)
+   goto error_disable_reg;
+   ext_clk_hz = clk_get_rate(st->mclk);
+   }
+
+   if (ext_clk_hz) {
+   st->mclk_hz = ext_clk_hz;
st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK;
} else {
st->mclk_hz = AD5933_INT_OSC_FREQ_Hz;
@@ -744,7 +742,7 @@ static int ad5933_probe(struct i2c_client *client,
 
ret = ad5933_register_ring_funcs_and_init(indio_dev);
if (ret)
-   goto error_disable_reg;
+   goto error_disable_mclk;
 
ret = ad5933_setup(st);
if (ret)
@@ -758,6 +756,8 @@ static int ad5933_probe(struct i2c_client *client,
 
 error_unreg_ring:
iio_kfifo_free(indio_dev->buffer);
+error_disable_mclk:
+   clk_disable_unprepare(st->mclk);
 error_disable_reg:
regulator_disable(st->reg);
 
@@ -772,6 +772,7 @@ static int ad5933_remove(struct i2c_client *client)
iio_device_unregister(indio_dev);
iio_kfifo_free(indio_dev->buffer);
regulator_disable(st->reg);
+   clk_disable_unprepare(st->mclk);
 
return 0;
 }
-- 
2.17.1



[PATCH 2/3] staging: iio: ad5933: use clock framework for clock reference

2018-12-08 Thread Marcelo Schmitt
Add the option to specify the external clock (MCLK) using the clock
framework.
Also remove the old platform data structure.

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
Co-Developed-by: Gabriel Capella 
---
 .../staging/iio/impedance-analyzer/ad5933.c   | 43 ++-
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 730bc397a26b..3134295f014f 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -82,20 +83,10 @@
 #define AD5933_POLL_TIME_ms10
 #define AD5933_INIT_EXCITATION_TIME_ms 100
 
-/**
- * struct ad5933_platform_data - platform specific data
- * @ext_clk_hz:the external clock frequency in Hz, if not set
- * the driver uses the internal clock (16.776 MHz)
- * @vref_mv:   the external reference voltage in millivolt
- */
-
-struct ad5933_platform_data {
-   unsigned long   ext_clk_hz;
-};
-
 struct ad5933_state {
struct i2c_client   *client;
struct regulator*reg;
+   struct clk  *mclk;
struct delayed_work work;
struct mutexlock; /* Protect sensor state */
unsigned long   mclk_hz;
@@ -111,9 +102,6 @@ struct ad5933_state {
unsigned intpoll_time_jiffies;
 };
 
-static struct ad5933_platform_data ad5933_default_pdata  = {
-};
-
 #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
_scan_index, _realbits) { \
.type = (_type), \
@@ -690,9 +678,9 @@ static int ad5933_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
int ret;
-   struct ad5933_platform_data *pdata = dev_get_platdata(>dev);
struct ad5933_state *st;
struct iio_dev *indio_dev;
+   unsigned long ext_clk_hz = 0;
 
indio_dev = devm_iio_device_alloc(>dev, sizeof(*st));
if (!indio_dev)
@@ -704,9 +692,6 @@ static int ad5933_probe(struct i2c_client *client,
 
mutex_init(>lock);
 
-   if (!pdata)
-   pdata = _default_pdata;
-
st->reg = devm_regulator_get(>dev, "vdd");
if (IS_ERR(st->reg))
return PTR_ERR(st->reg);
@@ -723,8 +708,21 @@ static int ad5933_probe(struct i2c_client *client,
 
st->vref_mv = ret / 1000;
 
-   if (pdata->ext_clk_hz) {
-   st->mclk_hz = pdata->ext_clk_hz;
+   st->mclk = devm_clk_get(>dev, "mclk");
+   if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) {
+   ret = PTR_ERR(st->mclk);
+   goto error_disable_reg;
+   }
+
+   if (!IS_ERR(st->mclk)) {
+   ret = clk_prepare_enable(st->mclk);
+   if (ret < 0)
+   goto error_disable_reg;
+   ext_clk_hz = clk_get_rate(st->mclk);
+   }
+
+   if (ext_clk_hz) {
+   st->mclk_hz = ext_clk_hz;
st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK;
} else {
st->mclk_hz = AD5933_INT_OSC_FREQ_Hz;
@@ -744,7 +742,7 @@ static int ad5933_probe(struct i2c_client *client,
 
ret = ad5933_register_ring_funcs_and_init(indio_dev);
if (ret)
-   goto error_disable_reg;
+   goto error_disable_mclk;
 
ret = ad5933_setup(st);
if (ret)
@@ -758,6 +756,8 @@ static int ad5933_probe(struct i2c_client *client,
 
 error_unreg_ring:
iio_kfifo_free(indio_dev->buffer);
+error_disable_mclk:
+   clk_disable_unprepare(st->mclk);
 error_disable_reg:
regulator_disable(st->reg);
 
@@ -772,6 +772,7 @@ static int ad5933_remove(struct i2c_client *client)
iio_device_unregister(indio_dev);
iio_kfifo_free(indio_dev->buffer);
regulator_disable(st->reg);
+   clk_disable_unprepare(st->mclk);
 
return 0;
 }
-- 
2.17.1



[PATCH 1/3] staging: iio: ad5933: change regulator binging for vref

2018-12-08 Thread Marcelo Schmitt
Set a single voltage regulator for all voltage references.
Remove voltage reference value from default platafrom data struct.

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
Co-Developed-by: Gabriel Capella 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 9e52384f5370..730bc397a26b 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -91,7 +91,6 @@
 
 struct ad5933_platform_data {
unsigned long   ext_clk_hz;
-   unsigned short  vref_mv;
 };
 
 struct ad5933_state {
@@ -113,7 +112,6 @@ struct ad5933_state {
 };
 
 static struct ad5933_platform_data ad5933_default_pdata  = {
-   .vref_mv = 3300,
 };
 
 #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
@@ -691,7 +689,7 @@ static void ad5933_work(struct work_struct *work)
 static int ad5933_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
-   int ret, voltage_uv = 0;
+   int ret;
struct ad5933_platform_data *pdata = dev_get_platdata(>dev);
struct ad5933_state *st;
struct iio_dev *indio_dev;
@@ -718,12 +716,12 @@ static int ad5933_probe(struct i2c_client *client,
dev_err(>dev, "Failed to enable specified VDD 
supply\n");
return ret;
}
-   voltage_uv = regulator_get_voltage(st->reg);
+   ret = regulator_get_voltage(st->reg);
+
+   if (ret < 0)
+   goto error_disable_reg;
 
-   if (voltage_uv)
-   st->vref_mv = voltage_uv / 1000;
-   else
-   st->vref_mv = pdata->vref_mv;
+   st->vref_mv = ret / 1000;
 
if (pdata->ext_clk_hz) {
st->mclk_hz = pdata->ext_clk_hz;
-- 
2.17.1



[PATCH 1/3] staging: iio: ad5933: change regulator binging for vref

2018-12-08 Thread Marcelo Schmitt
Set a single voltage regulator for all voltage references.
Remove voltage reference value from default platafrom data struct.

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
Co-Developed-by: Gabriel Capella 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 9e52384f5370..730bc397a26b 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -91,7 +91,6 @@
 
 struct ad5933_platform_data {
unsigned long   ext_clk_hz;
-   unsigned short  vref_mv;
 };
 
 struct ad5933_state {
@@ -113,7 +112,6 @@ struct ad5933_state {
 };
 
 static struct ad5933_platform_data ad5933_default_pdata  = {
-   .vref_mv = 3300,
 };
 
 #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
@@ -691,7 +689,7 @@ static void ad5933_work(struct work_struct *work)
 static int ad5933_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
-   int ret, voltage_uv = 0;
+   int ret;
struct ad5933_platform_data *pdata = dev_get_platdata(>dev);
struct ad5933_state *st;
struct iio_dev *indio_dev;
@@ -718,12 +716,12 @@ static int ad5933_probe(struct i2c_client *client,
dev_err(>dev, "Failed to enable specified VDD 
supply\n");
return ret;
}
-   voltage_uv = regulator_get_voltage(st->reg);
+   ret = regulator_get_voltage(st->reg);
+
+   if (ret < 0)
+   goto error_disable_reg;
 
-   if (voltage_uv)
-   st->vref_mv = voltage_uv / 1000;
-   else
-   st->vref_mv = pdata->vref_mv;
+   st->vref_mv = ret / 1000;
 
if (pdata->ext_clk_hz) {
st->mclk_hz = pdata->ext_clk_hz;
-- 
2.17.1



[PATCH 0/3] Add devicetree support for ad5933

2018-12-08 Thread Marcelo Schmitt
This series of patches change voltage regulator error handling for the
ad5933.
It also add an option to specify external clock reference using a clock
framework and remove the old platform data structure.
Finally it adds binding documentation for devicetree.

Marcelo Schmitt (3):
  staging: iio: ad5933: change regulator binging for vref
  staging: iio: ad5933: use clock framework for clock reference
  staging: iio: ad5933: add binding doc for ad5933

 .../iio/impedance-analyzer/ad5933.txt | 26 +
 .../staging/iio/impedance-analyzer/ad5933.c   | 57 +--
 2 files changed, 54 insertions(+), 29 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt

-- 
2.17.1



[PATCH 0/3] Add devicetree support for ad5933

2018-12-08 Thread Marcelo Schmitt
This series of patches change voltage regulator error handling for the
ad5933.
It also add an option to specify external clock reference using a clock
framework and remove the old platform data structure.
Finally it adds binding documentation for devicetree.

Marcelo Schmitt (3):
  staging: iio: ad5933: change regulator binging for vref
  staging: iio: ad5933: use clock framework for clock reference
  staging: iio: ad5933: add binding doc for ad5933

 .../iio/impedance-analyzer/ad5933.txt | 26 +
 .../staging/iio/impedance-analyzer/ad5933.c   | 57 +--
 2 files changed, 54 insertions(+), 29 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt

-- 
2.17.1



Re: [PATCH] staging: iio: ad5933: replaced kfifo by triggered_buffer

2018-12-02 Thread Marcelo Schmitt
On 11/25, Jonathan Cameron wrote:
> On Thu, 22 Nov 2018 10:53:47 -0200
> Marcelo Schmitt  wrote:
> 
> > Previously, there was an implicit creation of a kfifo which was replaced
> > by a call to triggered_buffer_setup, which is already implemented in iio
> > infrastructure.
> > 
> > Signed-off-by: Marcelo Schmitt 
> 
> I'm a little surprised that this would work without screaming a lot as 
> it will register an interrupt with no handlers. Do you have this
> device to test?  It's rapidly heading in the direction of too complex
> a driver to fix without test hardware.  Also, semantically this change
> is not sensible as it implies an operating mode which the driver
> is not using.
> 

Thanks for reviewing the patch. I'm not expert at electronics so I'm
still studying the datasheet to understand how the ad5933 works.

> There are fundamental questions about how we handle an autotriggered
> sweep that need answering before this driver can move forwards.
> It needs some concept of a higher level trigger rather than a per
> sample one like we typically use in IIO.
> 

>From what I've read so far it seems that we would need to have two
operation modes: one for the frequency sweep (that need to be
discussed yet) and another for the receive stage (in which ad5933 would
be continuously requested for data through I2C). So my first approach
would be to build up an abstract trigger that would allow switching
between these two operation modes. What do you think about that?

> The main focus in the short term should be around defining that ABI
> as it may fundamentally change the structure of the driver.
> If you want to take this on (and it'll be a big job I think!) then
> it may be possible to source some hardware to support that effort.
> 
> Thanks,
> 
> Jonathan
> 

As a member of the FLOSS group at Universidade de São Paulo I have the
hardware to test the driver though I didn't figure out all the steps to
do it yet. I intend to continue development on this driver so I'm really
thankful for all advise given.

Thanks,

Marcelo

> > ---
> >  .../staging/iio/impedance-analyzer/Kconfig|  2 +-
> >  .../staging/iio/impedance-analyzer/ad5933.c   | 25 ---
> >  2 files changed, 6 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
> > b/drivers/staging/iio/impedance-analyzer/Kconfig
> > index dd97b6bb3fd0..d0af5aa55dc0 100644
> > --- a/drivers/staging/iio/impedance-analyzer/Kconfig
> > +++ b/drivers/staging/iio/impedance-analyzer/Kconfig
> > @@ -7,7 +7,7 @@ config AD5933
> > tristate "Analog Devices AD5933, AD5934 driver"
> > depends on I2C
> > select IIO_BUFFER
> > -   select IIO_KFIFO_BUF
> > +   select IIO_TRIGGERED_BUFFER
> > help
> >   Say yes here to build support for Analog Devices Impedance Converter,
> >   Network Analyzer, AD5933/4, provides direct access via sysfs.
> > diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
> > b/drivers/staging/iio/impedance-analyzer/ad5933.c
> > index f9bcb8310e21..edb8b540bbf1 100644
> > --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> > +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> > @@ -20,7 +20,7 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> > +#include 
> >  
> >  /* AD5933/AD5934 Registers */
> >  #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
> > @@ -615,22 +615,6 @@ static const struct iio_buffer_setup_ops 
> > ad5933_ring_setup_ops = {
> > .postdisable = ad5933_ring_postdisable,
> >  };
> >  
> > -static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
> > -{
> > -   struct iio_buffer *buffer;
> > -
> > -   buffer = iio_kfifo_allocate();
> > -   if (!buffer)
> > -   return -ENOMEM;
> > -
> > -   iio_device_attach_buffer(indio_dev, buffer);
> > -
> > -   /* Ring buffer functions - here trigger setup related */
> > -   indio_dev->setup_ops = _ring_setup_ops;
> > -
> > -   return 0;
> > -}
> > -
> >  static void ad5933_work(struct work_struct *work)
> >  {
> > struct ad5933_state *st = container_of(work,
> > @@ -744,7 +728,8 @@ static int ad5933_probe(struct i2c_client *client,
> > indio_dev->channels = ad5933_channels;
> > indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
> >  
> > -   ret = ad5933_register_ring_funcs_and_init(indio_dev);
> > +   ret = iio_triggered_buffer_setup(indio_dev, NULL, NULL,
> > +_ring_setup_ops

Re: [PATCH] staging: iio: ad5933: replaced kfifo by triggered_buffer

2018-12-02 Thread Marcelo Schmitt
On 11/25, Jonathan Cameron wrote:
> On Thu, 22 Nov 2018 10:53:47 -0200
> Marcelo Schmitt  wrote:
> 
> > Previously, there was an implicit creation of a kfifo which was replaced
> > by a call to triggered_buffer_setup, which is already implemented in iio
> > infrastructure.
> > 
> > Signed-off-by: Marcelo Schmitt 
> 
> I'm a little surprised that this would work without screaming a lot as 
> it will register an interrupt with no handlers. Do you have this
> device to test?  It's rapidly heading in the direction of too complex
> a driver to fix without test hardware.  Also, semantically this change
> is not sensible as it implies an operating mode which the driver
> is not using.
> 

Thanks for reviewing the patch. I'm not expert at electronics so I'm
still studying the datasheet to understand how the ad5933 works.

> There are fundamental questions about how we handle an autotriggered
> sweep that need answering before this driver can move forwards.
> It needs some concept of a higher level trigger rather than a per
> sample one like we typically use in IIO.
> 

>From what I've read so far it seems that we would need to have two
operation modes: one for the frequency sweep (that need to be
discussed yet) and another for the receive stage (in which ad5933 would
be continuously requested for data through I2C). So my first approach
would be to build up an abstract trigger that would allow switching
between these two operation modes. What do you think about that?

> The main focus in the short term should be around defining that ABI
> as it may fundamentally change the structure of the driver.
> If you want to take this on (and it'll be a big job I think!) then
> it may be possible to source some hardware to support that effort.
> 
> Thanks,
> 
> Jonathan
> 

As a member of the FLOSS group at Universidade de São Paulo I have the
hardware to test the driver though I didn't figure out all the steps to
do it yet. I intend to continue development on this driver so I'm really
thankful for all advise given.

Thanks,

Marcelo

> > ---
> >  .../staging/iio/impedance-analyzer/Kconfig|  2 +-
> >  .../staging/iio/impedance-analyzer/ad5933.c   | 25 ---
> >  2 files changed, 6 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
> > b/drivers/staging/iio/impedance-analyzer/Kconfig
> > index dd97b6bb3fd0..d0af5aa55dc0 100644
> > --- a/drivers/staging/iio/impedance-analyzer/Kconfig
> > +++ b/drivers/staging/iio/impedance-analyzer/Kconfig
> > @@ -7,7 +7,7 @@ config AD5933
> > tristate "Analog Devices AD5933, AD5934 driver"
> > depends on I2C
> > select IIO_BUFFER
> > -   select IIO_KFIFO_BUF
> > +   select IIO_TRIGGERED_BUFFER
> > help
> >   Say yes here to build support for Analog Devices Impedance Converter,
> >   Network Analyzer, AD5933/4, provides direct access via sysfs.
> > diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
> > b/drivers/staging/iio/impedance-analyzer/ad5933.c
> > index f9bcb8310e21..edb8b540bbf1 100644
> > --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> > +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> > @@ -20,7 +20,7 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> > +#include 
> >  
> >  /* AD5933/AD5934 Registers */
> >  #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
> > @@ -615,22 +615,6 @@ static const struct iio_buffer_setup_ops 
> > ad5933_ring_setup_ops = {
> > .postdisable = ad5933_ring_postdisable,
> >  };
> >  
> > -static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
> > -{
> > -   struct iio_buffer *buffer;
> > -
> > -   buffer = iio_kfifo_allocate();
> > -   if (!buffer)
> > -   return -ENOMEM;
> > -
> > -   iio_device_attach_buffer(indio_dev, buffer);
> > -
> > -   /* Ring buffer functions - here trigger setup related */
> > -   indio_dev->setup_ops = _ring_setup_ops;
> > -
> > -   return 0;
> > -}
> > -
> >  static void ad5933_work(struct work_struct *work)
> >  {
> > struct ad5933_state *st = container_of(work,
> > @@ -744,7 +728,8 @@ static int ad5933_probe(struct i2c_client *client,
> > indio_dev->channels = ad5933_channels;
> > indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
> >  
> > -   ret = ad5933_register_ring_funcs_and_init(indio_dev);
> > +   ret = iio_triggered_buffer_setup(indio_dev, NULL, NULL,
> > +_ring_setup_ops

[PATCH] staging: iio: ad5933: add binding doc for ad5933

2018-12-02 Thread Marcelo Schmitt
Add a devicetree documentation for the ad5933 and ad5934 impedance
converter, network analyzer.

Co-Developed-by: Gabriel Capella 

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
---
 .../iio/impedance-analyzer/ad5933.txt | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt

diff --git 
a/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt 
b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
new file mode 100644
index ..d9ae2babf016
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
@@ -0,0 +1,23 @@
+Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer
+
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf
+
+Required properties:
+ - compatible : should be one of
+   "adi,ad5933"
+   "adi,ad5934"
+ - reg : the I2C address
+ - vdd-supply : supply reference for the device.
+
+Optional properties:
+ - vref_mv : default voltage reference.
+ - ext_clk_hz : external master clock for the system.
+
+Example:
+
+   impedance-analyzer@0d {
+   compatible = "adi,ad5933";
+   reg = <0x0d>;
+   vdd-supply = <_supply>;
+   };
-- 
2.17.1



[PATCH] staging: iio: ad5933: add binding doc for ad5933

2018-12-02 Thread Marcelo Schmitt
Add a devicetree documentation for the ad5933 and ad5934 impedance
converter, network analyzer.

Co-Developed-by: Gabriel Capella 

Signed-off-by: Marcelo Schmitt 
Signed-off-by: Gabriel Capella 
---
 .../iio/impedance-analyzer/ad5933.txt | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt

diff --git 
a/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt 
b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
new file mode 100644
index ..d9ae2babf016
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
@@ -0,0 +1,23 @@
+Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer
+
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf
+https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf
+
+Required properties:
+ - compatible : should be one of
+   "adi,ad5933"
+   "adi,ad5934"
+ - reg : the I2C address
+ - vdd-supply : supply reference for the device.
+
+Optional properties:
+ - vref_mv : default voltage reference.
+ - ext_clk_hz : external master clock for the system.
+
+Example:
+
+   impedance-analyzer@0d {
+   compatible = "adi,ad5933";
+   reg = <0x0d>;
+   vdd-supply = <_supply>;
+   };
-- 
2.17.1



[PATCH v2] staging: iio: ad5933: add device tree support

2018-11-24 Thread Marcelo Schmitt
Add a of_device_id struct variable and subsequent call to
MODULE_DEVICE_TABLE macro to complete device tree support.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index edb8b540bbf1..6faa2700dc8d 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -771,9 +771,18 @@ static const struct i2c_device_id ad5933_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ad5933_id);
 
+static const struct of_device_id ad5933_of_match[] = {
+   { .compatible = "adi,ad5933" },
+   { .compatible = "adi,ad5934" },
+   { },
+};
+
+MODULE_DEVICE_TABLE(of, ad5933_of_match);
+
 static struct i2c_driver ad5933_driver = {
.driver = {
.name = "ad5933",
+   .of_match_table = ad5933_of_match,
},
.probe = ad5933_probe,
.remove = ad5933_remove,
-- 
2.17.1



[PATCH v2] staging: iio: ad5933: add device tree support

2018-11-24 Thread Marcelo Schmitt
Add a of_device_id struct variable and subsequent call to
MODULE_DEVICE_TABLE macro to complete device tree support.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index edb8b540bbf1..6faa2700dc8d 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -771,9 +771,18 @@ static const struct i2c_device_id ad5933_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ad5933_id);
 
+static const struct of_device_id ad5933_of_match[] = {
+   { .compatible = "adi,ad5933" },
+   { .compatible = "adi,ad5934" },
+   { },
+};
+
+MODULE_DEVICE_TABLE(of, ad5933_of_match);
+
 static struct i2c_driver ad5933_driver = {
.driver = {
.name = "ad5933",
+   .of_match_table = ad5933_of_match,
},
.probe = ad5933_probe,
.remove = ad5933_remove,
-- 
2.17.1



[PATCH] staging: iio: ad5933: finalized device-tree support

2018-11-23 Thread Marcelo Schmitt
Added a of_device_id struct variable and subsequent call to
MODULE_DEVICE_TABLE macro to complete device-tree support for this
driver.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index edb8b540bbf1..19e8b6d2865c 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -771,9 +771,18 @@ static const struct i2c_device_id ad5933_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ad5933_id);
 
+static const struct of_device_id ad5933_of_match[] = {
+   { .compatible = "analog-devices,ad5933" },
+   { .compatible = "analog-devices,ad5934" },
+   { },
+};
+
+MODULE_DEVICE_TABLE(of, ad5933_of_match);
+
 static struct i2c_driver ad5933_driver = {
.driver = {
.name = "ad5933",
+   .of_match_table = ad5933_of_match,
},
.probe = ad5933_probe,
.remove = ad5933_remove,
-- 
2.17.1



[PATCH] staging: iio: ad5933: finalized device-tree support

2018-11-23 Thread Marcelo Schmitt
Added a of_device_id struct variable and subsequent call to
MODULE_DEVICE_TABLE macro to complete device-tree support for this
driver.

Signed-off-by: Marcelo Schmitt 
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index edb8b540bbf1..19e8b6d2865c 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -771,9 +771,18 @@ static const struct i2c_device_id ad5933_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, ad5933_id);
 
+static const struct of_device_id ad5933_of_match[] = {
+   { .compatible = "analog-devices,ad5933" },
+   { .compatible = "analog-devices,ad5934" },
+   { },
+};
+
+MODULE_DEVICE_TABLE(of, ad5933_of_match);
+
 static struct i2c_driver ad5933_driver = {
.driver = {
.name = "ad5933",
+   .of_match_table = ad5933_of_match,
},
.probe = ad5933_probe,
.remove = ad5933_remove,
-- 
2.17.1



[PATCH] staging: iio: ad5933: replaced kfifo by triggered_buffer

2018-11-22 Thread Marcelo Schmitt
Previously, there was an implicit creation of a kfifo which was replaced
by a call to triggered_buffer_setup, which is already implemented in iio
infrastructure.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/Kconfig|  2 +-
 .../staging/iio/impedance-analyzer/ad5933.c   | 25 ---
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
b/drivers/staging/iio/impedance-analyzer/Kconfig
index dd97b6bb3fd0..d0af5aa55dc0 100644
--- a/drivers/staging/iio/impedance-analyzer/Kconfig
+++ b/drivers/staging/iio/impedance-analyzer/Kconfig
@@ -7,7 +7,7 @@ config AD5933
tristate "Analog Devices AD5933, AD5934 driver"
depends on I2C
select IIO_BUFFER
-   select IIO_KFIFO_BUF
+   select IIO_TRIGGERED_BUFFER
help
  Say yes here to build support for Analog Devices Impedance Converter,
  Network Analyzer, AD5933/4, provides direct access via sysfs.
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index f9bcb8310e21..edb8b540bbf1 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /* AD5933/AD5934 Registers */
 #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
@@ -615,22 +615,6 @@ static const struct iio_buffer_setup_ops 
ad5933_ring_setup_ops = {
.postdisable = ad5933_ring_postdisable,
 };
 
-static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
-{
-   struct iio_buffer *buffer;
-
-   buffer = iio_kfifo_allocate();
-   if (!buffer)
-   return -ENOMEM;
-
-   iio_device_attach_buffer(indio_dev, buffer);
-
-   /* Ring buffer functions - here trigger setup related */
-   indio_dev->setup_ops = _ring_setup_ops;
-
-   return 0;
-}
-
 static void ad5933_work(struct work_struct *work)
 {
struct ad5933_state *st = container_of(work,
@@ -744,7 +728,8 @@ static int ad5933_probe(struct i2c_client *client,
indio_dev->channels = ad5933_channels;
indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
 
-   ret = ad5933_register_ring_funcs_and_init(indio_dev);
+   ret = iio_triggered_buffer_setup(indio_dev, NULL, NULL,
+_ring_setup_ops);
if (ret)
goto error_disable_reg;
 
@@ -759,7 +744,7 @@ static int ad5933_probe(struct i2c_client *client,
return 0;
 
 error_unreg_ring:
-   iio_kfifo_free(indio_dev->buffer);
+   iio_triggered_buffer_cleanup(indio_dev);
 error_disable_reg:
regulator_disable(st->reg);
 
@@ -772,7 +757,7 @@ static int ad5933_remove(struct i2c_client *client)
struct ad5933_state *st = iio_priv(indio_dev);
 
iio_device_unregister(indio_dev);
-   iio_kfifo_free(indio_dev->buffer);
+   iio_triggered_buffer_cleanup(indio_dev);
regulator_disable(st->reg);
 
return 0;
-- 
2.17.1



[PATCH] staging: iio: ad5933: replaced kfifo by triggered_buffer

2018-11-22 Thread Marcelo Schmitt
Previously, there was an implicit creation of a kfifo which was replaced
by a call to triggered_buffer_setup, which is already implemented in iio
infrastructure.

Signed-off-by: Marcelo Schmitt 
---
 .../staging/iio/impedance-analyzer/Kconfig|  2 +-
 .../staging/iio/impedance-analyzer/ad5933.c   | 25 ---
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig 
b/drivers/staging/iio/impedance-analyzer/Kconfig
index dd97b6bb3fd0..d0af5aa55dc0 100644
--- a/drivers/staging/iio/impedance-analyzer/Kconfig
+++ b/drivers/staging/iio/impedance-analyzer/Kconfig
@@ -7,7 +7,7 @@ config AD5933
tristate "Analog Devices AD5933, AD5934 driver"
depends on I2C
select IIO_BUFFER
-   select IIO_KFIFO_BUF
+   select IIO_TRIGGERED_BUFFER
help
  Say yes here to build support for Analog Devices Impedance Converter,
  Network Analyzer, AD5933/4, provides direct access via sysfs.
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c 
b/drivers/staging/iio/impedance-analyzer/ad5933.c
index f9bcb8310e21..edb8b540bbf1 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /* AD5933/AD5934 Registers */
 #define AD5933_REG_CONTROL_HB  0x80/* R/W, 1 byte */
@@ -615,22 +615,6 @@ static const struct iio_buffer_setup_ops 
ad5933_ring_setup_ops = {
.postdisable = ad5933_ring_postdisable,
 };
 
-static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
-{
-   struct iio_buffer *buffer;
-
-   buffer = iio_kfifo_allocate();
-   if (!buffer)
-   return -ENOMEM;
-
-   iio_device_attach_buffer(indio_dev, buffer);
-
-   /* Ring buffer functions - here trigger setup related */
-   indio_dev->setup_ops = _ring_setup_ops;
-
-   return 0;
-}
-
 static void ad5933_work(struct work_struct *work)
 {
struct ad5933_state *st = container_of(work,
@@ -744,7 +728,8 @@ static int ad5933_probe(struct i2c_client *client,
indio_dev->channels = ad5933_channels;
indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
 
-   ret = ad5933_register_ring_funcs_and_init(indio_dev);
+   ret = iio_triggered_buffer_setup(indio_dev, NULL, NULL,
+_ring_setup_ops);
if (ret)
goto error_disable_reg;
 
@@ -759,7 +744,7 @@ static int ad5933_probe(struct i2c_client *client,
return 0;
 
 error_unreg_ring:
-   iio_kfifo_free(indio_dev->buffer);
+   iio_triggered_buffer_cleanup(indio_dev);
 error_disable_reg:
regulator_disable(st->reg);
 
@@ -772,7 +757,7 @@ static int ad5933_remove(struct i2c_client *client)
struct ad5933_state *st = iio_priv(indio_dev);
 
iio_device_unregister(indio_dev);
-   iio_kfifo_free(indio_dev->buffer);
+   iio_triggered_buffer_cleanup(indio_dev);
regulator_disable(st->reg);
 
return 0;
-- 
2.17.1



[PATCH v2] Staging iio: adc: Match parenthesis alignment

2018-10-17 Thread Marcelo Schmitt
Change close parenthesis alignment to match respective open parenthesis at
iio/drivers/staging/iio/adc/ad7606.c line 379.
This makes the file more compliant with the preferred coding style for the
linux kernel.

Signed-of-by: Marcelo Schmitt 
---
 drivers/staging/iio/adc/ad7606.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 0b728b6ea135..230faae38c12 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -376,7 +376,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
return 0;
 
st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
-   GPIOD_OUT_LOW);
+   GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(st->gpio_os);
 }
 
-- 
2.17.1



[PATCH v2] Staging iio: adc: Match parenthesis alignment

2018-10-17 Thread Marcelo Schmitt
Change close parenthesis alignment to match respective open parenthesis at
iio/drivers/staging/iio/adc/ad7606.c line 379.
This makes the file more compliant with the preferred coding style for the
linux kernel.

Signed-of-by: Marcelo Schmitt 
---
 drivers/staging/iio/adc/ad7606.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 0b728b6ea135..230faae38c12 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -376,7 +376,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
return 0;
 
st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
-   GPIOD_OUT_LOW);
+   GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(st->gpio_os);
 }
 
-- 
2.17.1



[PATCH] Staging iio/adc: fixes parenthesis alignment

2018-10-16 Thread Marcelo Schmitt
Fixes close parenthesis alignment to match open parenthesis at
iio/drivers/staging/iio/adc/ad7606.c line 379.

Signed-of-by: Marcelo Schmitt 
---
 drivers/staging/iio/adc/ad7606.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 0b728b6ea135..230faae38c12 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -376,7 +376,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
return 0;
 
st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
-   GPIOD_OUT_LOW);
+   GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(st->gpio_os);
 }
 
-- 
2.17.1



[PATCH] Staging iio/adc: fixes parenthesis alignment

2018-10-16 Thread Marcelo Schmitt
Fixes close parenthesis alignment to match open parenthesis at
iio/drivers/staging/iio/adc/ad7606.c line 379.

Signed-of-by: Marcelo Schmitt 
---
 drivers/staging/iio/adc/ad7606.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 0b728b6ea135..230faae38c12 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -376,7 +376,7 @@ static int ad7606_request_gpios(struct ad7606_state *st)
return 0;
 
st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio",
-   GPIOD_OUT_LOW);
+   GPIOD_OUT_LOW);
return PTR_ERR_OR_ZERO(st->gpio_os);
 }
 
-- 
2.17.1