Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation
@ 2019-09-02 13:08 Mircea Caprioru
  2019-09-02 13:08 ` [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate Mircea Caprioru
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Mircea Caprioru @ 2019-09-02 13:08 UTC (permalink / raw)
  To: jic23
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt, Mircea Caprioru

Add initial ABI documentation for ad7192 adc sysfs interfaces.

Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
---
Changelog V2:
- no changes here

Changelog V3:
- no changes here

Changelog V4:
- added sysfs ABI documentation

 .../ABI/testing/sysfs-bus-iio-adc-ad7192          | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
new file mode 100644
index 000000000000..74a2873045bf
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
@@ -0,0 +1,15 @@
+What:		/sys/bus/iio/devices/iio:deviceX/ac_excitation_en
+KernelVersion:
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Reading gives the state of AC excitation.
+		Writing '1' enables AC excitation.
+
+What:		/sys/bus/iio/devices/iio:deviceX/bridge_switch_en
+KernelVersion:
+Contact:	linux-iio@vger.kernel.org
+Description:
+		This bridge switch is used to disconnect it when there is a
+		need to minimize the system current consumption.
+		Reading gives the state of the bridge switch.
+		Writing '1' enables the bridge switch.
-- 
2.17.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate
  2019-09-02 13:08 [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Mircea Caprioru
@ 2019-09-02 13:08 ` Mircea Caprioru
  2019-09-08  9:35   ` Jonathan Cameron
  2019-09-02 13:08 ` [PATCH V4 3/4] staging: iio: adc: ad7192: Add system calibration support Mircea Caprioru
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Mircea Caprioru @ 2019-09-02 13:08 UTC (permalink / raw)
  To: jic23
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt, Mircea Caprioru

This patch exports the ad_sd_calibrate function in order to be able to
call it from outside ad_sigma_delta.

There are cases where the option to calibrate one channel at a time is
necessary (ex. system calibration for zero scale and full scale).

Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
---
Changelog V2:
- no changes here

Changelog V3:
- no changes here

Changelog V4:
- no changes here

 drivers/iio/adc/ad_sigma_delta.c       | 3 ++-
 include/linux/iio/adc/ad_sigma_delta.h | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 2640b75fb774..8ba90486c787 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -205,7 +205,7 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
 }
 EXPORT_SYMBOL_GPL(ad_sd_reset);
 
-static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
+int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 	unsigned int mode, unsigned int channel)
 {
 	int ret;
@@ -242,6 +242,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(ad_sd_calibrate);
 
 /**
  * ad_sd_calibrate_all() - Performs channel calibration
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 7716fa0c9fce..8a4e25a7080c 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -119,6 +119,8 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
 
 int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 	const struct iio_chan_spec *chan, int *val);
+int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
+	unsigned int mode, unsigned int channel);
 int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
 	const struct ad_sd_calib_data *cd, unsigned int n);
 int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V4 3/4] staging: iio: adc: ad7192: Add system calibration support
  2019-09-02 13:08 [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Mircea Caprioru
  2019-09-02 13:08 ` [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate Mircea Caprioru
@ 2019-09-02 13:08 ` Mircea Caprioru
  2019-09-08  9:36   ` Jonathan Cameron
  2019-09-02 13:08 ` [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192 Mircea Caprioru
  2019-09-08  9:35 ` [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Jonathan Cameron
  3 siblings, 1 reply; 9+ messages in thread
From: Mircea Caprioru @ 2019-09-02 13:08 UTC (permalink / raw)
  To: jic23
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt, Mircea Caprioru

This patch will add a system calibration attribute for each channel. Using
this option the user will have the ability to calibrate each channel for
zero scale and full scale. It uses the iio_chan_spec_ext_info and IIO_ENUM
to implement the functionality.

Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
---
Changelog V2:
- no changes here

Changelog V3:
- no changes here

Changelog V4:
- add an attribute to start the system calibration
- the mode attribute does not trigger the calibration
- added ABI documentation

 .../ABI/testing/sysfs-bus-iio-adc-ad7192      | 24 ++++++
 drivers/staging/iio/adc/ad7192.c              | 79 ++++++++++++++++++-
 2 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
index 74a2873045bf..7627d3be08f5 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
+++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
@@ -13,3 +13,27 @@ Description:
 		need to minimize the system current consumption.
 		Reading gives the state of the bridge switch.
 		Writing '1' enables the bridge switch.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
+KernelVersion:
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Initiates the system calibration procedure. This is done on a
+		single channel at a time. Write '1' to start the calibration.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration_mode_available
+KernelVersion:
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Reading returns a list with the possible calibration modes.
+		There are two available options:
+		"zero_scale" - calibrate to zero scale
+		"full_scale" - calibrate to full scale
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration_mode
+KernelVersion:
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Sets up the calibration mode used in the system calibration
+		procedure. Reading returns the current calibration mode.
+		Writing sets the system calibration mode.
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index d58ce08f3693..c5106d98c9b3 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -155,6 +155,11 @@
  * The DOUT/RDY output must also be wired to an interrupt capable GPIO.
  */
 
+enum {
+   AD7192_SYSCALIB_ZERO_SCALE,
+   AD7192_SYSCALIB_FULL_SCALE,
+};
+
 struct ad7192_state {
 	struct regulator		*avdd;
 	struct regulator		*dvdd;
@@ -169,10 +174,80 @@ struct ad7192_state {
 	u8				devid;
 	u8				clock_sel;
 	struct mutex			lock;	/* protect sensor state */
+	u8				syscalib_mode[8];
 
 	struct ad_sigma_delta		sd;
 };
 
+static const char * const ad7192_syscalib_modes[] = {
+	[AD7192_SYSCALIB_ZERO_SCALE] = "zero_scale",
+	[AD7192_SYSCALIB_FULL_SCALE] = "full_scale",
+};
+
+static int ad7192_set_syscalib_mode(struct iio_dev *indio_dev,
+				    const struct iio_chan_spec *chan,
+				    unsigned int mode)
+{
+	struct ad7192_state *st = iio_priv(indio_dev);
+
+	st->syscalib_mode[chan->channel] = mode;
+
+	return 0;
+}
+
+static int ad7192_get_syscalib_mode(struct iio_dev *indio_dev,
+				    const struct iio_chan_spec *chan)
+{
+	struct ad7192_state *st = iio_priv(indio_dev);
+
+	return st->syscalib_mode[chan->channel];
+}
+
+static ssize_t ad7192_write_syscalib(struct iio_dev *indio_dev,
+				     uintptr_t private,
+				     const struct iio_chan_spec *chan,
+				     const char *buf, size_t len)
+{
+	struct ad7192_state *st = iio_priv(indio_dev);
+	bool sys_calib;
+	int ret, temp;
+
+	ret = strtobool(buf, &sys_calib);
+	if (ret)
+		return ret;
+
+	temp = st->syscalib_mode[chan->channel];
+	if (sys_calib) {
+		if (temp == AD7192_SYSCALIB_ZERO_SCALE)
+			ret = ad_sd_calibrate(&st->sd, AD7192_MODE_CAL_SYS_ZERO,
+					      chan->address);
+		else
+			ret = ad_sd_calibrate(&st->sd, AD7192_MODE_CAL_SYS_FULL,
+					      chan->address);
+	}
+
+	return ret ? ret : len;
+}
+
+static const struct iio_enum ad7192_syscalib_mode_enum = {
+	.items = ad7192_syscalib_modes,
+	.num_items = ARRAY_SIZE(ad7192_syscalib_modes),
+	.set = ad7192_set_syscalib_mode,
+	.get = ad7192_get_syscalib_mode
+};
+
+static const struct iio_chan_spec_ext_info ad7192_calibsys_ext_info[] = {
+	{
+		.name = "sys_calibration",
+		.write = ad7192_write_syscalib,
+		.shared = IIO_SEPARATE,
+	},
+	IIO_ENUM("sys_calibration_mode", IIO_SEPARATE,
+		 &ad7192_syscalib_mode_enum),
+	IIO_ENUM_AVAILABLE("sys_calibration_mode", &ad7192_syscalib_mode_enum),
+	{}
+};
+
 static struct ad7192_state *ad_sigma_delta_to_ad7192(struct ad_sigma_delta *sd)
 {
 	return container_of(sd, struct ad7192_state, sd);
@@ -769,9 +844,11 @@ static int ad7192_channels_config(struct iio_dev *indio_dev)
 		*chan = channels[i];
 		chan->info_mask_shared_by_all |=
 			BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY);
-		if (chan->type != IIO_TEMP)
+		if (chan->type != IIO_TEMP) {
 			chan->info_mask_shared_by_type_available |=
 				BIT(IIO_CHAN_INFO_SCALE);
+			chan->ext_info = ad7192_calibsys_ext_info;
+		}
 		chan++;
 	}
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192
  2019-09-02 13:08 [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Mircea Caprioru
  2019-09-02 13:08 ` [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate Mircea Caprioru
  2019-09-02 13:08 ` [PATCH V4 3/4] staging: iio: adc: ad7192: Add system calibration support Mircea Caprioru
@ 2019-09-02 13:08 ` Mircea Caprioru
  2019-09-03 17:29   ` Rob Herring
  2019-09-08  9:35 ` [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Jonathan Cameron
  3 siblings, 1 reply; 9+ messages in thread
From: Mircea Caprioru @ 2019-09-02 13:08 UTC (permalink / raw)
  To: jic23
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt, Mircea Caprioru

[-- Warning: decoded text below may be mangled --]
[-- Attachment #0: Type: text/plain; charset="yes", Size: 3829 bytes --]

This patch add device tree binding documentation for AD7192 adc in YAML
format.

Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
---
Changelog V2:
- no changes here

Changelog V3:
- no changes here

Changelog V4:
- remove the const value from avdd and dvdd supply

 .../bindings/iio/adc/adi,ad7192.yaml          | 119 ++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
new file mode 100644
index 000000000000..040af0bcc92e
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
@@ -0,0 +1,119 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2019 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bindings/iio/adc/adi,ad7192.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD7192 ADC device driver
+
+maintainers:
+  - Michael Hennerich <michael.hennerich@analog.com>
+
+description: |
+  Bindings for the Analog Devices AD7192 ADC device. Datasheet can be
+  found here:
+  https://www.analog.com/media/en/technical-documentation/data-sheets/AD7192.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,ad7190
+      - adi,ad7192
+      - adi,ad7193
+      - adi,ad7195
+
+  reg:
+    maxItems: 1
+
+  spi-cpol: true
+
+  spi-cpha: true
+
+  clocks:
+    maxItems: 1
+    description: phandle to the master clock (mclk)
+
+  clock-names:
+    items:
+      - const: mclk
+
+  interrupts:
+    maxItems: 1
+
+  dvdd-supply:
+    description: DVdd voltage supply
+    maxItems: 1
+
+  avdd-supply:
+    description: AVdd voltage supply
+    maxItems: 1
+
+  adi,rejection-60-Hz-enable:
+    description: |
+      This bit enables a notch at 60 Hz when the first notch of the sinc
+      filter is at 50 Hz. When REJ60 is set, a filter notch is placed at
+      60 Hz when the sinc filter first notch is at 50 Hz. This allows
+      simultaneous 50 Hz/ 60 Hz rejection.
+    type: boolean
+
+  adi,refin2-pins-enable:
+    description: |
+      External reference applied between the P1/REFIN2(+) and P0/REFIN2(−) pins.
+    type: boolean
+
+  adi,buffer-enable:
+    description: |
+      Enables the buffer on the analog inputs. If cleared, the analog inputs
+      are unbuffered, lowering the power consumption of the device. If this
+      bit is set, the analog inputs are buffered, allowing the user to place
+      source impedances on the front end without contributing gain errors to
+      the system.
+    type: boolean
+
+  adi,burnout-currents-enable:
+    description: |
+      When this bit is set to 1, the 500 nA current sources in the signal
+      path are enabled. When BURN = 0, the burnout currents are disabled.
+      The burnout currents can be enabled only when the buffer is active
+      and when chop is disabled.
+    type: boolean
+
+  bipolar:
+    description: see Documentation/devicetree/bindings/iio/adc/adc.txt
+    type: boolean
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+  - dvdd-supply
+  - avdd-supply
+  - spi-cpol
+  - spi-cpha
+
+examples:
+  - |
+    spi0 {
+      adc@0 {
+        compatible = "adi,ad7192";
+        reg = <0>;
+        spi-max-frequency = <1000000>;
+        spi-cpol;
+        spi-cpha;
+        clocks = <&ad7192_mclk>;
+        clock-names = "mclk";
+        #interrupt-cells = <2>;
+        interrupts = <25 0x2>;
+        interrupt-parent = <&gpio>;
+        dvdd-supply = <&dvdd>;
+        avdd-supply = <&avdd>;
+
+        adi,refin2-pins-enable;
+        adi,rejection-60-Hz-enable;
+        adi,buffer-enable;
+        adi,burnout-currents-enable;
+        };
+    };
-- 
2.17.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192
  2019-09-02 13:08 ` [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192 Mircea Caprioru
@ 2019-09-03 17:29   ` Rob Herring
  2019-09-08 10:29     ` Jonathan Cameron
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Herring @ 2019-09-03 17:29 UTC (permalink / raw)
  To: Mircea Caprioru
  Cc: jic23, Michael.Hennerich, stefan.popa, lars, gregkh,
	linux-kernel, linux-iio, devicetree, robh+dt, Mircea Caprioru

On Mon, 2 Sep 2019 16:08:31 +0300, Mircea Caprioru wrote:
> This patch add device tree binding documentation for AD7192 adc in YAML
> format.
> 
> Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
> ---
> Changelog V2:
> - no changes here
> 
> Changelog V3:
> - no changes here
> 
> Changelog V4:
> - remove the const value from avdd and dvdd supply
> 
>  .../bindings/iio/adc/adi,ad7192.yaml          | 119 ++++++++++++++++++
>  1 file changed, 119 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation
  2019-09-02 13:08 [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Mircea Caprioru
                   ` (2 preceding siblings ...)
  2019-09-02 13:08 ` [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192 Mircea Caprioru
@ 2019-09-08  9:35 ` Jonathan Cameron
  3 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2019-09-08  9:35 UTC (permalink / raw)
  To: Mircea Caprioru
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt

On Mon, 2 Sep 2019 16:08:28 +0300
Mircea Caprioru <mircea.caprioru@analog.com> wrote:

> Add initial ABI documentation for ad7192 adc sysfs interfaces.
> 
> Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to ignore ;)

Thanks,

Jonathan

> ---
> Changelog V2:
> - no changes here
> 
> Changelog V3:
> - no changes here
> 
> Changelog V4:
> - added sysfs ABI documentation
> 
>  .../ABI/testing/sysfs-bus-iio-adc-ad7192          | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> new file mode 100644
> index 000000000000..74a2873045bf
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> @@ -0,0 +1,15 @@
> +What:		/sys/bus/iio/devices/iio:deviceX/ac_excitation_en
> +KernelVersion:
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Reading gives the state of AC excitation.
> +		Writing '1' enables AC excitation.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/bridge_switch_en
> +KernelVersion:
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		This bridge switch is used to disconnect it when there is a
> +		need to minimize the system current consumption.
> +		Reading gives the state of the bridge switch.
> +		Writing '1' enables the bridge switch.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate
  2019-09-02 13:08 ` [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate Mircea Caprioru
@ 2019-09-08  9:35   ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2019-09-08  9:35 UTC (permalink / raw)
  To: Mircea Caprioru
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt

On Mon, 2 Sep 2019 16:08:29 +0300
Mircea Caprioru <mircea.caprioru@analog.com> wrote:

> This patch exports the ad_sd_calibrate function in order to be able to
> call it from outside ad_sigma_delta.
> 
> There are cases where the option to calibrate one channel at a time is
> necessary (ex. system calibration for zero scale and full scale).
> 
> Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
Applied, Thanks,
> ---
> Changelog V2:
> - no changes here
> 
> Changelog V3:
> - no changes here
> 
> Changelog V4:
> - no changes here
> 
>  drivers/iio/adc/ad_sigma_delta.c       | 3 ++-
>  include/linux/iio/adc/ad_sigma_delta.h | 2 ++
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 2640b75fb774..8ba90486c787 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -205,7 +205,7 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
>  }
>  EXPORT_SYMBOL_GPL(ad_sd_reset);
>  
> -static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
> +int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
>  	unsigned int mode, unsigned int channel)
>  {
>  	int ret;
> @@ -242,6 +242,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
>  
>  	return ret;
>  }
> +EXPORT_SYMBOL_GPL(ad_sd_calibrate);
>  
>  /**
>   * ad_sd_calibrate_all() - Performs channel calibration
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 7716fa0c9fce..8a4e25a7080c 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -119,6 +119,8 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta,
>  
>  int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
>  	const struct iio_chan_spec *chan, int *val);
> +int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
> +	unsigned int mode, unsigned int channel);
>  int ad_sd_calibrate_all(struct ad_sigma_delta *sigma_delta,
>  	const struct ad_sd_calib_data *cd, unsigned int n);
>  int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V4 3/4] staging: iio: adc: ad7192: Add system calibration support
  2019-09-02 13:08 ` [PATCH V4 3/4] staging: iio: adc: ad7192: Add system calibration support Mircea Caprioru
@ 2019-09-08  9:36   ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2019-09-08  9:36 UTC (permalink / raw)
  To: Mircea Caprioru
  Cc: Michael.Hennerich, stefan.popa, lars, gregkh, linux-kernel,
	linux-iio, devicetree, robh+dt

On Mon, 2 Sep 2019 16:08:30 +0300
Mircea Caprioru <mircea.caprioru@analog.com> wrote:

> This patch will add a system calibration attribute for each channel. Using
> this option the user will have the ability to calibrate each channel for
> zero scale and full scale. It uses the iio_chan_spec_ext_info and IIO_ENUM
> to implement the functionality.
> 
> Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>

I can see this may at somepoint become a 'general' interface and I think
your ABI choice is sufficiently flexible to allow that.

Hence applied to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changelog V2:
> - no changes here
> 
> Changelog V3:
> - no changes here
> 
> Changelog V4:
> - add an attribute to start the system calibration
> - the mode attribute does not trigger the calibration
> - added ABI documentation
> 
>  .../ABI/testing/sysfs-bus-iio-adc-ad7192      | 24 ++++++
>  drivers/staging/iio/adc/ad7192.c              | 79 ++++++++++++++++++-
>  2 files changed, 102 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> index 74a2873045bf..7627d3be08f5 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> @@ -13,3 +13,27 @@ Description:
>  		need to minimize the system current consumption.
>  		Reading gives the state of the bridge switch.
>  		Writing '1' enables the bridge switch.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
> +KernelVersion:
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Initiates the system calibration procedure. This is done on a
> +		single channel at a time. Write '1' to start the calibration.
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration_mode_available
> +KernelVersion:
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Reading returns a list with the possible calibration modes.
> +		There are two available options:
> +		"zero_scale" - calibrate to zero scale
> +		"full_scale" - calibrate to full scale
> +
> +What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration_mode
> +KernelVersion:
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Sets up the calibration mode used in the system calibration
> +		procedure. Reading returns the current calibration mode.
> +		Writing sets the system calibration mode.
> diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
> index d58ce08f3693..c5106d98c9b3 100644
> --- a/drivers/staging/iio/adc/ad7192.c
> +++ b/drivers/staging/iio/adc/ad7192.c
> @@ -155,6 +155,11 @@
>   * The DOUT/RDY output must also be wired to an interrupt capable GPIO.
>   */
>  
> +enum {
> +   AD7192_SYSCALIB_ZERO_SCALE,
> +   AD7192_SYSCALIB_FULL_SCALE,
> +};
> +
>  struct ad7192_state {
>  	struct regulator		*avdd;
>  	struct regulator		*dvdd;
> @@ -169,10 +174,80 @@ struct ad7192_state {
>  	u8				devid;
>  	u8				clock_sel;
>  	struct mutex			lock;	/* protect sensor state */
> +	u8				syscalib_mode[8];
>  
>  	struct ad_sigma_delta		sd;
>  };
>  
> +static const char * const ad7192_syscalib_modes[] = {
> +	[AD7192_SYSCALIB_ZERO_SCALE] = "zero_scale",
> +	[AD7192_SYSCALIB_FULL_SCALE] = "full_scale",
> +};
> +
> +static int ad7192_set_syscalib_mode(struct iio_dev *indio_dev,
> +				    const struct iio_chan_spec *chan,
> +				    unsigned int mode)
> +{
> +	struct ad7192_state *st = iio_priv(indio_dev);
> +
> +	st->syscalib_mode[chan->channel] = mode;
> +
> +	return 0;
> +}
> +
> +static int ad7192_get_syscalib_mode(struct iio_dev *indio_dev,
> +				    const struct iio_chan_spec *chan)
> +{
> +	struct ad7192_state *st = iio_priv(indio_dev);
> +
> +	return st->syscalib_mode[chan->channel];
> +}
> +
> +static ssize_t ad7192_write_syscalib(struct iio_dev *indio_dev,
> +				     uintptr_t private,
> +				     const struct iio_chan_spec *chan,
> +				     const char *buf, size_t len)
> +{
> +	struct ad7192_state *st = iio_priv(indio_dev);
> +	bool sys_calib;
> +	int ret, temp;
> +
> +	ret = strtobool(buf, &sys_calib);
> +	if (ret)
> +		return ret;
> +
> +	temp = st->syscalib_mode[chan->channel];
> +	if (sys_calib) {
> +		if (temp == AD7192_SYSCALIB_ZERO_SCALE)
> +			ret = ad_sd_calibrate(&st->sd, AD7192_MODE_CAL_SYS_ZERO,
> +					      chan->address);
> +		else
> +			ret = ad_sd_calibrate(&st->sd, AD7192_MODE_CAL_SYS_FULL,
> +					      chan->address);
> +	}
> +
> +	return ret ? ret : len;
> +}
> +
> +static const struct iio_enum ad7192_syscalib_mode_enum = {
> +	.items = ad7192_syscalib_modes,
> +	.num_items = ARRAY_SIZE(ad7192_syscalib_modes),
> +	.set = ad7192_set_syscalib_mode,
> +	.get = ad7192_get_syscalib_mode
> +};
> +
> +static const struct iio_chan_spec_ext_info ad7192_calibsys_ext_info[] = {
> +	{
> +		.name = "sys_calibration",
> +		.write = ad7192_write_syscalib,
> +		.shared = IIO_SEPARATE,
> +	},
> +	IIO_ENUM("sys_calibration_mode", IIO_SEPARATE,
> +		 &ad7192_syscalib_mode_enum),
> +	IIO_ENUM_AVAILABLE("sys_calibration_mode", &ad7192_syscalib_mode_enum),
> +	{}
> +};
> +
>  static struct ad7192_state *ad_sigma_delta_to_ad7192(struct ad_sigma_delta *sd)
>  {
>  	return container_of(sd, struct ad7192_state, sd);
> @@ -769,9 +844,11 @@ static int ad7192_channels_config(struct iio_dev *indio_dev)
>  		*chan = channels[i];
>  		chan->info_mask_shared_by_all |=
>  			BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY);
> -		if (chan->type != IIO_TEMP)
> +		if (chan->type != IIO_TEMP) {
>  			chan->info_mask_shared_by_type_available |=
>  				BIT(IIO_CHAN_INFO_SCALE);
> +			chan->ext_info = ad7192_calibsys_ext_info;
> +		}
>  		chan++;
>  	}
>  


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192
  2019-09-03 17:29   ` Rob Herring
@ 2019-09-08 10:29     ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2019-09-08 10:29 UTC (permalink / raw)
  To: Rob Herring
  Cc: Mircea Caprioru, Michael.Hennerich, stefan.popa, lars, gregkh,
	linux-kernel, linux-iio, devicetree, robh+dt

On Tue, 3 Sep 2019 18:29:37 +0100
Rob Herring <robh@kernel.org> wrote:

> On Mon, 2 Sep 2019 16:08:31 +0300, Mircea Caprioru wrote:
> > This patch add device tree binding documentation for AD7192 adc in YAML
> > format.
> > 
> > Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
It seems that I messed up before and didn't actually revert the v3 patch.

I'll roll a small fix patch to bring the tree inline with this and send out to the
list.

Sorry about this. One of many things that went wrong in that last pull request!

Jonathan

> > ---
> > Changelog V2:
> > - no changes here
> > 
> > Changelog V3:
> > - no changes here
> > 
> > Changelog V4:
> > - remove the const value from avdd and dvdd supply
> > 
> >  .../bindings/iio/adc/adi,ad7192.yaml          | 119 ++++++++++++++++++
> >  1 file changed, 119 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml
> >   
> 
> Reviewed-by: Rob Herring <robh@kernel.org>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 13:08 [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Mircea Caprioru
2019-09-02 13:08 ` [PATCH V4 2/4] iio: adc: ad_sigma_delta: Export ad_sd_calibrate Mircea Caprioru
2019-09-08  9:35   ` Jonathan Cameron
2019-09-02 13:08 ` [PATCH V4 3/4] staging: iio: adc: ad7192: Add system calibration support Mircea Caprioru
2019-09-08  9:36   ` Jonathan Cameron
2019-09-02 13:08 ` [PATCH V4 4/4] dt-bindings: iio: adc: ad7192: Add binding documentation for AD7192 Mircea Caprioru
2019-09-03 17:29   ` Rob Herring
2019-09-08 10:29     ` Jonathan Cameron
2019-09-08  9:35 ` [PATCH V4 1/4] iio: adc: ad7192: Add sysfs ABI documentation Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox