Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iio: adc: ad7173: add calibration support to chip family
@ 2024-11-27  9:06 Guillaume Ranquet
  2024-11-27  9:06 ` [PATCH v2 1/2] iio: adc: ad7173: add calibration support Guillaume Ranquet
  2024-11-27  9:06 ` [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc Guillaume Ranquet
  0 siblings, 2 replies; 6+ messages in thread
From: Guillaume Ranquet @ 2024-11-27  9:06 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron
  Cc: linux-iio, linux-kernel, Guillaume Ranquet

Calibration on the ad7173 family is the same as on the ad7192 family of
chips and mostly uses the ad_sigma_delta common code.

Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
---
Changes in v2:
- Add a common ad sigma delta ABI documentation to describe calibration
  nodes that are common in the sigma delta family.
- Link to v1: https://lore.kernel.org/r/20241115-ad411x_calibration-v1-1-5f820dfb5c80@baylibre.com

---
Guillaume Ranquet (2):
      iio: adc: ad7173: add calibration support
      iio: adc: ad-sigma-delta: Document ABI for sigma delta adc

 .../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta   |  23 ++++
 Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 |  24 ----
 drivers/iio/adc/ad7173.c                           | 123 +++++++++++++++++++++
 3 files changed, 146 insertions(+), 24 deletions(-)
---
base-commit: 744cf71b8bdfcdd77aaf58395e068b7457634b2c
change-id: 20241115-ad411x_calibration-2c663171d988

Best regards,
-- 
Guillaume Ranquet <granquet@baylibre.com>


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

* [PATCH v2 1/2] iio: adc: ad7173: add calibration support
  2024-11-27  9:06 [PATCH v2 0/2] iio: adc: ad7173: add calibration support to chip family Guillaume Ranquet
@ 2024-11-27  9:06 ` Guillaume Ranquet
  2024-11-30 19:11   ` Jonathan Cameron
  2024-11-27  9:06 ` [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc Guillaume Ranquet
  1 sibling, 1 reply; 6+ messages in thread
From: Guillaume Ranquet @ 2024-11-27  9:06 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron
  Cc: linux-iio, linux-kernel, Guillaume Ranquet

The ad7173 family of chips has up to four calibration modes.

Internal zero scale: removes ADC core offset errors.
Internal full scale: removes ADC core gain errors.
System zero scale: reduces offset error to the order of channel noise.
System full scale: reduces gain error to the order of channel noise.

All voltage channels will undergo an internal zero/full scale
calibration at bootup.

System zero/full scale can be done after bootup using the newly created
iio interface 'sys_calibration' and 'sys_calibration_mode'

Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
---
 drivers/iio/adc/ad7173.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)

diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index a0fca16c3be07534547a5b914d525d05f7425340..11ff148cb5a315d32485acf04b8d6f7d0fb6e5fa 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -150,6 +150,11 @@
 #define AD7173_FILTER_ODR0_MASK		GENMASK(5, 0)
 #define AD7173_MAX_CONFIGS		8
 
+#define AD7173_MODE_CAL_INT_ZERO		0x4 /* Internal Zero-Scale Calibration */
+#define AD7173_MODE_CAL_INT_FULL		0x5 /* Internal Full-Scale Calibration */
+#define AD7173_MODE_CAL_SYS_ZERO		0x6 /* System Zero-Scale Calibration */
+#define AD7173_MODE_CAL_SYS_FULL		0x7 /* System Full-Scale Calibration */
+
 struct ad7173_device_info {
 	const unsigned int *sinc5_data_rates;
 	unsigned int num_sinc5_data_rates;
@@ -175,6 +180,7 @@ struct ad7173_device_info {
 	bool has_input_buf;
 	bool has_int_ref;
 	bool has_ref2;
+	bool has_internal_fs_calibration;
 	bool higher_gpio_bits;
 	u8 num_gpios;
 };
@@ -215,6 +221,7 @@ struct ad7173_state {
 	struct regmap *reg_gpiocon_regmap;
 	struct gpio_regmap *gpio_regmap;
 #endif
+	u8 *syscalib_mode;
 };
 
 static unsigned int ad4115_sinc5_data_rates[] = {
@@ -272,6 +279,7 @@ static const struct ad7173_device_info ad4111_device_info = {
 	.has_input_buf = true,
 	.has_current_inputs = true,
 	.has_int_ref = true,
+	.has_internal_fs_calibration = true,
 	.clock = 2 * HZ_PER_MHZ,
 	.sinc5_data_rates = ad7173_sinc5_data_rates,
 	.num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates),
@@ -291,6 +299,7 @@ static const struct ad7173_device_info ad4112_device_info = {
 	.has_input_buf = true,
 	.has_current_inputs = true,
 	.has_int_ref = true,
+	.has_internal_fs_calibration = true,
 	.clock = 2 * HZ_PER_MHZ,
 	.sinc5_data_rates = ad7173_sinc5_data_rates,
 	.num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates),
@@ -326,6 +335,7 @@ static const struct ad7173_device_info ad4114_device_info = {
 	.has_temp = true,
 	.has_input_buf = true,
 	.has_int_ref = true,
+	.has_internal_fs_calibration = true,
 	.clock = 2 * HZ_PER_MHZ,
 	.sinc5_data_rates = ad7173_sinc5_data_rates,
 	.num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates),
@@ -343,6 +353,7 @@ static const struct ad7173_device_info ad4115_device_info = {
 	.has_temp = true,
 	.has_input_buf = true,
 	.has_int_ref = true,
+	.has_internal_fs_calibration = true,
 	.clock = 8 * HZ_PER_MHZ,
 	.sinc5_data_rates = ad4115_sinc5_data_rates,
 	.num_sinc5_data_rates = ARRAY_SIZE(ad4115_sinc5_data_rates),
@@ -360,6 +371,7 @@ static const struct ad7173_device_info ad4116_device_info = {
 	.has_temp = true,
 	.has_input_buf = true,
 	.has_int_ref = true,
+	.has_internal_fs_calibration = true,
 	.clock = 4 * HZ_PER_MHZ,
 	.sinc5_data_rates = ad4116_sinc5_data_rates,
 	.num_sinc5_data_rates = ARRAY_SIZE(ad4116_sinc5_data_rates),
@@ -505,6 +517,105 @@ static const struct regmap_config ad7173_regmap_config = {
 	.read_flag_mask = BIT(6),
 };
 
+enum {
+	AD7173_SYSCALIB_ZERO_SCALE,
+	AD7173_SYSCALIB_FULL_SCALE,
+};
+
+static const char * const ad7173_syscalib_modes[] = {
+	[AD7173_SYSCALIB_ZERO_SCALE] = "zero_scale",
+	[AD7173_SYSCALIB_FULL_SCALE] = "full_scale",
+};
+
+static int ad7173_set_syscalib_mode(struct iio_dev *indio_dev,
+				    const struct iio_chan_spec *chan,
+				    unsigned int mode)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+
+	st->syscalib_mode[chan->channel] = mode;
+
+	return 0;
+}
+
+static int ad7173_get_syscalib_mode(struct iio_dev *indio_dev,
+				    const struct iio_chan_spec *chan)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+
+	return st->syscalib_mode[chan->channel];
+}
+
+static ssize_t ad7173_write_syscalib(struct iio_dev *indio_dev,
+				     uintptr_t private,
+				     const struct iio_chan_spec *chan,
+				     const char *buf, size_t len)
+{
+	struct ad7173_state *st = iio_priv(indio_dev);
+	bool sys_calib;
+	int ret, mode;
+
+	ret = kstrtobool(buf, &sys_calib);
+	if (ret)
+		return ret;
+
+	mode = st->syscalib_mode[chan->channel];
+	if (sys_calib) {
+		if (mode == AD7173_SYSCALIB_ZERO_SCALE)
+			ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_SYS_ZERO,
+					      chan->address);
+		else
+			ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_SYS_FULL,
+					      chan->address);
+	}
+
+	return ret ? : len;
+}
+
+static const struct iio_enum ad7173_syscalib_mode_enum = {
+	.items = ad7173_syscalib_modes,
+	.num_items = ARRAY_SIZE(ad7173_syscalib_modes),
+	.set = ad7173_set_syscalib_mode,
+	.get = ad7173_get_syscalib_mode
+};
+
+static const struct iio_chan_spec_ext_info ad7173_calibsys_ext_info[] = {
+	{
+		.name = "sys_calibration",
+		.write = ad7173_write_syscalib,
+		.shared = IIO_SEPARATE,
+	},
+	IIO_ENUM("sys_calibration_mode", IIO_SEPARATE,
+		 &ad7173_syscalib_mode_enum),
+	IIO_ENUM_AVAILABLE("sys_calibration_mode", IIO_SHARED_BY_TYPE,
+			   &ad7173_syscalib_mode_enum),
+	{ }
+};
+
+static int ad7173_calibrate_all(struct ad7173_state *st, struct iio_dev *indio_dev)
+{
+	int ret;
+	int i;
+
+	for (i = 0; i < st->num_channels; i++) {
+		if (indio_dev->channels[i].type != IIO_VOLTAGE)
+			continue;
+
+		ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_ZERO, st->channels[i].ain);
+		if (ret < 0)
+			return ret;
+
+		if (st->info->has_internal_fs_calibration) {
+			ret = ad_sd_calibrate(&st->sd, AD7173_MODE_CAL_INT_FULL,
+					      st->channels[i].ain);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
 static int ad7173_mask_xlate(struct gpio_regmap *gpio, unsigned int base,
 			     unsigned int offset, unsigned int *reg,
 			     unsigned int *mask)
@@ -801,6 +912,10 @@ static int ad7173_setup(struct iio_dev *indio_dev)
 	if (!st->config_cnts)
 		return -ENOMEM;
 
+	ret = ad7173_calibrate_all(st, indio_dev);
+	if (ret)
+		return ret;
+
 	/* All channels are enabled by default after a reset */
 	return ad7173_disable_all(&st->sd);
 }
@@ -1023,6 +1138,7 @@ static const struct iio_chan_spec ad7173_channel_template = {
 		.storagebits = 32,
 		.endianness = IIO_BE,
 	},
+	.ext_info = ad7173_calibsys_ext_info,
 };
 
 static const struct iio_chan_spec ad7173_temp_iio_channel_template = {
@@ -1213,6 +1329,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
 	struct iio_chan_spec *chan_arr, *chan;
 	unsigned int ain[AD7173_NO_AINS_PER_CHANNEL], chan_index = 0;
 	int ref_sel, ret, num_channels;
+	u8 *calib_mode;
 
 	num_channels = device_get_child_node_count(dev);
 
@@ -1240,8 +1357,14 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
 	if (!chans_st_arr)
 		return -ENOMEM;
 
+	calib_mode = devm_kcalloc(dev, st->num_channels, sizeof(*st->syscalib_mode),
+				  GFP_KERNEL);
+	if (!calib_mode)
+		return -ENOMEM;
+
 	indio_dev->channels = chan_arr;
 	st->channels = chans_st_arr;
+	st->syscalib_mode = calib_mode;
 
 	if (st->info->has_temp) {
 		chan_arr[chan_index] = ad7173_temp_iio_channel_template;

-- 
2.47.0


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

* [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc
  2024-11-27  9:06 [PATCH v2 0/2] iio: adc: ad7173: add calibration support to chip family Guillaume Ranquet
  2024-11-27  9:06 ` [PATCH v2 1/2] iio: adc: ad7173: add calibration support Guillaume Ranquet
@ 2024-11-27  9:06 ` Guillaume Ranquet
  2024-11-30 19:06   ` Jonathan Cameron
  1 sibling, 1 reply; 6+ messages in thread
From: Guillaume Ranquet @ 2024-11-27  9:06 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron
  Cc: linux-iio, linux-kernel, Guillaume Ranquet

Add common calibration nodes for sigma delta adc.

Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
---
 .../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta   | 23 +++++++++++++++++++++
 Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 24 ----------------------
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
new file mode 100644
index 0000000000000000000000000000000000000000..c2c55a966163736aea8d46fc5089c08dac747b84
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
@@ -0,0 +1,23 @@
+What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
+KernelVersion:
+Contact:	linux-iio@vger.kernel.org
+Description:
+		This attribute, if available, 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:
+		This attribute, if available, 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:
+		This attribute, if available, 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/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
index f8315202c8f0df2bd4b7216f5cf8d3c2780fcf3f..28be1cabf1124ac7593392e17e4759ddfac829e8 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
+++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
@@ -19,33 +19,9 @@ Description:
 		the bridge can be disconnected (when it is not being used
 		using the bridge_switch_en attribute.
 
-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_voltage2-voltage2_shorted_raw
 KernelVersion:
 Contact:	linux-iio@vger.kernel.org
 Description:
 		Measure voltage from AIN2 pin connected to AIN(+)
 		and AIN(-) shorted.
-
-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.

-- 
2.47.0


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

* Re: [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc
  2024-11-27  9:06 ` [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc Guillaume Ranquet
@ 2024-11-30 19:06   ` Jonathan Cameron
  2024-12-02  9:28     ` Guillaume Ranquet
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2024-11-30 19:06 UTC (permalink / raw)
  To: Guillaume Ranquet
  Cc: Lars-Peter Clausen, Michael Hennerich, linux-iio, linux-kernel

On Wed, 27 Nov 2024 10:06:14 +0100
Guillaume Ranquet <granquet@baylibre.com> wrote:

> Add common calibration nodes for sigma delta adc.
> 
> Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
Hi Guillaume.

I think there are some issues with the old docs that should be tidied up whilst
we are here :(

Just fix them up in this patch then mention it in the patch description.
Or if you prefer move and then fix in separate patches.


Jonathan

> ---
>  .../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta   | 23 +++++++++++++++++++++
>  Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 24 ----------------------
>  2 files changed, 23 insertions(+), 24 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
> new file mode 100644
> index 0000000000000000000000000000000000000000..c2c55a966163736aea8d46fc5089c08dac747b84
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
> @@ -0,0 +1,23 @@
> +What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
in_voltageY_sys_calibration

(as indices are capital letters and X is used earlier).


> +KernelVersion:
Make an estimate of this I'll never remember to fill them in whilst applying.

It should make the next merge window I hope!

> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		This attribute, if available, 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:
> +		This attribute, if available, 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:
> +		This attribute, if available, 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/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> index f8315202c8f0df2bd4b7216f5cf8d3c2780fcf3f..28be1cabf1124ac7593392e17e4759ddfac829e8 100644
> --- a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
> @@ -19,33 +19,9 @@ Description:
>  		the bridge can be disconnected (when it is not being used
>  		using the bridge_switch_en attribute.
>  
> -What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
Huh.  That would explain the x above. I assume it is per channel?

> -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_voltage2-voltage2_shorted_raw
>  KernelVersion:
>  Contact:	linux-iio@vger.kernel.org
>  Description:
>  		Measure voltage from AIN2 pin connected to AIN(+)
>  		and AIN(-) shorted.
> -
> -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.
> 


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

* Re: [PATCH v2 1/2] iio: adc: ad7173: add calibration support
  2024-11-27  9:06 ` [PATCH v2 1/2] iio: adc: ad7173: add calibration support Guillaume Ranquet
@ 2024-11-30 19:11   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2024-11-30 19:11 UTC (permalink / raw)
  To: Guillaume Ranquet
  Cc: Lars-Peter Clausen, Michael Hennerich, linux-iio, linux-kernel

On Wed, 27 Nov 2024 10:06:13 +0100
Guillaume Ranquet <granquet@baylibre.com> wrote:

> The ad7173 family of chips has up to four calibration modes.
> 
> Internal zero scale: removes ADC core offset errors.
> Internal full scale: removes ADC core gain errors.
> System zero scale: reduces offset error to the order of channel noise.
> System full scale: reduces gain error to the order of channel noise.
> 
> All voltage channels will undergo an internal zero/full scale
> calibration at bootup.
> 
> System zero/full scale can be done after bootup using the newly created
> iio interface 'sys_calibration' and 'sys_calibration_mode'
> 
> Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>


>  static const struct iio_chan_spec ad7173_temp_iio_channel_template = {
> @@ -1213,6 +1329,7 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
>  	struct iio_chan_spec *chan_arr, *chan;
>  	unsigned int ain[AD7173_NO_AINS_PER_CHANNEL], chan_index = 0;
>  	int ref_sel, ret, num_channels;
> +	u8 *calib_mode;
>  
>  	num_channels = device_get_child_node_count(dev);
>  
> @@ -1240,8 +1357,14 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
>  	if (!chans_st_arr)
>  		return -ENOMEM;
>  
> +	calib_mode = devm_kcalloc(dev, st->num_channels, sizeof(*st->syscalib_mode),
> +				  GFP_KERNEL);
As it is per channel, can we put it in struct ad7173_channel?

This driver already has a lot of small allocations. Avoiding an extra one would nice!

> +	if (!calib_mode)
> +		return -ENOMEM;
> +
>  	indio_dev->channels = chan_arr;
>  	st->channels = chans_st_arr;
> +	st->syscalib_mode = calib_mode;
>  
>  	if (st->info->has_temp) {
>  		chan_arr[chan_index] = ad7173_temp_iio_channel_template;
> 


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

* Re: [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc
  2024-11-30 19:06   ` Jonathan Cameron
@ 2024-12-02  9:28     ` Guillaume Ranquet
  0 siblings, 0 replies; 6+ messages in thread
From: Guillaume Ranquet @ 2024-12-02  9:28 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Michael Hennerich, linux-iio, linux-kernel

On Sat, 30 Nov 2024 20:06, Jonathan Cameron <jic23@kernel.org> wrote:
>On Wed, 27 Nov 2024 10:06:14 +0100
>Guillaume Ranquet <granquet@baylibre.com> wrote:
>
>> Add common calibration nodes for sigma delta adc.
>>
>> Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
>Hi Guillaume.
>
>I think there are some issues with the old docs that should be tidied up whilst
>we are here :(

Hi Jonathan,
No problem, will do :)

>
>Just fix them up in this patch then mention it in the patch description.
>Or if you prefer move and then fix in separate patches.
>
>
>Jonathan
>
>> ---
>>  .../ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta   | 23 +++++++++++++++++++++
>>  Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 | 24 ----------------------
>>  2 files changed, 23 insertions(+), 24 deletions(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..c2c55a966163736aea8d46fc5089c08dac747b84
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad-sigma-delta
>> @@ -0,0 +1,23 @@
>> +What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
>in_voltageY_sys_calibration
>
>(as indices are capital letters and X is used earlier).
>
>
>> +KernelVersion:
>Make an estimate of this I'll never remember to fill them in whilst applying.
>
>It should make the next merge window I hope!
>
>> +Contact:	linux-iio@vger.kernel.org
>> +Description:
>> +		This attribute, if available, 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:
>> +		This attribute, if available, 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:
>> +		This attribute, if available, 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/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
>> index f8315202c8f0df2bd4b7216f5cf8d3c2780fcf3f..28be1cabf1124ac7593392e17e4759ddfac829e8 100644
>> --- a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
>> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192
>> @@ -19,33 +19,9 @@ Description:
>>  		the bridge can be disconnected (when it is not being used
>>  		using the bridge_switch_en attribute.
>>
>> -What:		/sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration
>Huh.  That would explain the x above. I assume it is per channel?
>
Yes, calibration is per channel.

>> -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_voltage2-voltage2_shorted_raw
>>  KernelVersion:
>>  Contact:	linux-iio@vger.kernel.org
>>  Description:
>>  		Measure voltage from AIN2 pin connected to AIN(+)
>>  		and AIN(-) shorted.
>> -
>> -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.
>>

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

end of thread, other threads:[~2024-12-02  9:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-27  9:06 [PATCH v2 0/2] iio: adc: ad7173: add calibration support to chip family Guillaume Ranquet
2024-11-27  9:06 ` [PATCH v2 1/2] iio: adc: ad7173: add calibration support Guillaume Ranquet
2024-11-30 19:11   ` Jonathan Cameron
2024-11-27  9:06 ` [PATCH v2 2/2] iio: adc: ad-sigma-delta: Document ABI for sigma delta adc Guillaume Ranquet
2024-11-30 19:06   ` Jonathan Cameron
2024-12-02  9:28     ` Guillaume Ranquet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox