Skip to contentSkip to conversation

*** Add support for AD485x DAS Family ***

PATCH Superseded Antoniu Miclaus 4 participants 19 messages Nov 11, 2024 – Nov 23, 2024

Subsystems (6)

v6 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Antoniu Miclaus

author reviewer
#0 lore raw

v6 cover *** Add support for AD485x DAS Family ***

Add support for AD485X fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.

Some particularities:
1. softspan - the devices support multiple softspans which are represented in iio through offset/scale. The current handling implies changing both the scale and the offset separately via IIO, therefore in order to properly set the softspan, each time the offset changes the softspan is set to the default value. And only after changing also the scale the desired softspan is set. This is the approach we are suggesting since we need the softspan configurable from userspace and not from devicetree.

2. packet format - Data provided on the CMOS and LVDS conversion data output buses are packaged into eight channel packets. This is currently handled as extended info.

Antoniu Miclaus (8):
iio: backend: add API for interface get
iio: backend: add support for data size set
iio: backend: add API for oversampling
iio: adc: adi-axi-adc: add interface type
iio: adc: adi-axi-adc: set data format
iio: adc: adi-axi-adc: add oversampling
dt-bindings: iio: adc: add ad4851
iio: adc: ad4851: add ad485x driver

 .../bindings/iio/adc/adi,ad4851.yaml          |  103 ++
 drivers/iio/adc/Kconfig                       |   13 +
 drivers/iio/adc/Makefile                      |    1 +
 drivers/iio/adc/ad4851.c                      | 1190 +++++++++++++++++
 drivers/iio/adc/adi-axi-adc.c                 |   63 +
 drivers/iio/industrialio-backend.c            |   59 +
 include/linux/iio/backend.h                   |   17 +
 7 files changed, 1446 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml
 create mode 100644 drivers/iio/adc/ad4851.c
Signature · 1 line
2.47.0
author reviewer
#1 lore raw

PATCH v6 1/8 iio: backend: add API for interface get

Add backend support for obtaining the interface type used.

---
no changes in v6.

 drivers/iio/industrialio-backend.c | 24 ++++++++++++++++++++++++
 include/linux/iio/backend.h        | 11 +++++++++++
 2 files changed, 35 insertions(+)
drivers/iio/industrialio-backend.c +24 -0
index 20b3b5212da7..c792cd1e24e8 100644
@@ -636,6 +636,30 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private,
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_ext_info_set, IIO_BACKEND);
 
+/**
+ * iio_backend_interface_type_get - get the interface type used.
+ * @back: Backend device
+ * @type: Interface type
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_interface_type_get(struct iio_backend *back,
+				   enum iio_backend_interface_type *type)
+{
+	int ret;
+
+	ret = iio_backend_op_call(back, interface_type_get, type);
+	if (ret)
+		return ret;
+
+	if (*type >= IIO_BACKEND_INTERFACE_MAX)
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_interface_type_get, IIO_BACKEND);
+
 /**
  * iio_backend_extend_chan_spec - Extend an IIO channel
  * @back: Backend device
include/linux/iio/backend.h +11 -0
index 37d56914d485..e5ea90f1c3e0 100644
@@ -68,6 +68,12 @@ enum iio_backend_sample_trigger {
 	IIO_BACKEND_SAMPLE_TRIGGER_MAX
 };
 
+enum iio_backend_interface_type {
+	IIO_BACKEND_INTERFACE_SERIAL_LVDS,
+	IIO_BACKEND_INTERFACE_SERIAL_CMOS,
+	IIO_BACKEND_INTERFACE_MAX
+};
+
 /**
  * struct iio_backend_ops - operations structure for an iio_backend
  * @enable: Enable backend.
@@ -86,6 +92,7 @@ enum iio_backend_sample_trigger {
  * @extend_chan_spec: Extend an IIO channel.
  * @ext_info_set: Extended info setter.
  * @ext_info_get: Extended info getter.
+ * @interface_type_get: Interface type.
  * @read_raw: Read a channel attribute from a backend device
  * @debugfs_print_chan_status: Print channel status into a buffer.
  * @debugfs_reg_access: Read or write register value of backend.
@@ -121,6 +128,8 @@ struct iio_backend_ops {
 			    const char *buf, size_t len);
 	int (*ext_info_get)(struct iio_backend *back, uintptr_t private,
 			    const struct iio_chan_spec *chan, char *buf);
+	int (*interface_type_get)(struct iio_backend *back,
+				  enum iio_backend_interface_type *type);
 	int (*read_raw)(struct iio_backend *back,
 			struct iio_chan_spec const *chan, int *val, int *val2,
 			long mask);
@@ -169,6 +178,8 @@ ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private,
 				 const char *buf, size_t len);
 ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,
 				 const struct iio_chan_spec *chan, char *buf);
+int iio_backend_interface_type_get(struct iio_backend *back,
+				   enum iio_backend_interface_type *type);
 int iio_backend_read_raw(struct iio_backend *back,
 			 struct iio_chan_spec const *chan, int *val, int *val2,
 			 long mask);
Signature · 1 line
2.47.0
author reviewer
#2 lore raw

PATCH v6 2/8 iio: backend: add support for data size set

In reply to Antoniu Miclaus

Add backend support for setting the data size used.
This setting can be adjusted within the IP cores interfacing devices.

---
changes in v6:
- drop size_t

 drivers/iio/industrialio-backend.c | 21 +++++++++++++++++++++
 include/linux/iio/backend.h        |  3 +++
 2 files changed, 24 insertions(+)
drivers/iio/industrialio-backend.c +21 -0
index c792cd1e24e8..ea184fc2c838 100644
@@ -660,6 +660,27 @@ int iio_backend_interface_type_get(struct iio_backend *back,
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_interface_type_get, IIO_BACKEND);
 
+/**
+ * iio_backend_data_size_set - set the data width/size in the data bus.
+ * @back: Backend device
+ * @size: Size in bits
+ *
+ * Some frontend devices can dynamically control the word/data size on the
+ * interface/data bus. Hence, the backend device needs to be aware of it so
+ * data can be correctly transferred.
+ *
+ * Return:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_data_size_set(struct iio_backend *back, unsigned int size)
+{
+	if (!size)
+		return -EINVAL;
+
+	return iio_backend_op_call(back, data_size_set, size);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, IIO_BACKEND);
+
 /**
  * iio_backend_extend_chan_spec - Extend an IIO channel
  * @back: Backend device
include/linux/iio/backend.h +3 -0
index e5ea90f1c3e0..59b6651b7eaf 100644
@@ -93,6 +93,7 @@ enum iio_backend_interface_type {
  * @ext_info_set: Extended info setter.
  * @ext_info_get: Extended info getter.
  * @interface_type_get: Interface type.
+ * @data_size_set: Data size.
  * @read_raw: Read a channel attribute from a backend device
  * @debugfs_print_chan_status: Print channel status into a buffer.
  * @debugfs_reg_access: Read or write register value of backend.
@@ -130,6 +131,7 @@ struct iio_backend_ops {
 			    const struct iio_chan_spec *chan, char *buf);
 	int (*interface_type_get)(struct iio_backend *back,
 				  enum iio_backend_interface_type *type);
+	int (*data_size_set)(struct iio_backend *back, unsigned int size);
 	int (*read_raw)(struct iio_backend *back,
 			struct iio_chan_spec const *chan, int *val, int *val2,
 			long mask);
@@ -180,6 +182,7 @@ ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,
 				 const struct iio_chan_spec *chan, char *buf);
 int iio_backend_interface_type_get(struct iio_backend *back,
 				   enum iio_backend_interface_type *type);
+int iio_backend_data_size_set(struct iio_backend *back, unsigned int size);
 int iio_backend_read_raw(struct iio_backend *back,
 			 struct iio_chan_spec const *chan, int *val, int *val2,
 			 long mask);
Signature · 1 line
2.47.0
author reviewer
#3 lore raw

PATCH v6 3/8 iio: backend: add API for oversampling

In reply to Antoniu Miclaus

Add backend support for enabling/disabling oversampling.

---
changes in v6:
- add iio backend commit for oversampling enable/disable

 drivers/iio/industrialio-backend.c | 14 ++++++++++++++
 include/linux/iio/backend.h        |  3 +++
 2 files changed, 17 insertions(+)
drivers/iio/industrialio-backend.c +14 -0
index ea184fc2c838..6ba445ba3dd0 100644
@@ -681,6 +681,20 @@ int iio_backend_data_size_set(struct iio_backend *back, unsigned int size)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, IIO_BACKEND);
 
+/**
+ * iio_backend_oversampling_en - set the data width/size in the data bus.
+ * @back: Backend device
+ * @en: oversampling enabled/disabled.
+ *
+ * Return:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_oversampling_en(struct iio_backend *back, bool en)
+{
+	return iio_backend_op_call(back, oversampling_en, en);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_en, IIO_BACKEND);
+
 /**
  * iio_backend_extend_chan_spec - Extend an IIO channel
  * @back: Backend device
include/linux/iio/backend.h +3 -0
index 59b6651b7eaf..b8f63823b3db 100644
@@ -94,6 +94,7 @@ enum iio_backend_interface_type {
  * @ext_info_get: Extended info getter.
  * @interface_type_get: Interface type.
  * @data_size_set: Data size.
+ * @oversampling_en: Oversampling.
  * @read_raw: Read a channel attribute from a backend device
  * @debugfs_print_chan_status: Print channel status into a buffer.
  * @debugfs_reg_access: Read or write register value of backend.
@@ -132,6 +133,7 @@ struct iio_backend_ops {
 	int (*interface_type_get)(struct iio_backend *back,
 				  enum iio_backend_interface_type *type);
 	int (*data_size_set)(struct iio_backend *back, unsigned int size);
+	int (*oversampling_en)(struct iio_backend *back, bool en);
 	int (*read_raw)(struct iio_backend *back,
 			struct iio_chan_spec const *chan, int *val, int *val2,
 			long mask);
@@ -183,6 +185,7 @@ ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,
 int iio_backend_interface_type_get(struct iio_backend *back,
 				   enum iio_backend_interface_type *type);
 int iio_backend_data_size_set(struct iio_backend *back, unsigned int size);
+int iio_backend_oversampling_en(struct iio_backend *back, bool en);
 int iio_backend_read_raw(struct iio_backend *back,
 			 struct iio_chan_spec const *chan, int *val, int *val2,
 			 long mask);
Signature · 1 line
2.47.0
#4 lore raw

Re: [PATCH v6 3/8] iio: backend: add API for oversampling

Quoted 19 lines · Antoniu Miclaus

Add backend support for enabling/disabling oversampling.

---
changes in v6:
 - add iio backend commit for oversampling enable/disable drivers/iio/industrialio-backend.c | 14 ++++++++++++++ include/linux/iio/backend.h        |  3 +++

 2 files changed, 17 insertions(+)
drivers/iio/industrialio- renamed from drivers/iio/industrialio-backend.c +0 -0

backend.c
index ea184fc2c838..6ba445ba3dd0 100644

drivers/iio/industrialio-backend.c +0 -0
@@ -681,6 +681,20 @@ int iio_backend_data_size_set(struct iio_backend *back,
 unsigned int size)
  }
  EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, IIO_BACKEND);
Quoted 3 lines


+/**
+ * iio_backend_oversampling_en - set the data width/size in the data bus.

Seems unrelated?

drivers/iio/industrialio-backend.c int iio_backend_data_size_set(struct iio_backend *back, unsigned int size) · line 697

Quoted 12 lines

+ * @back: Backend device
+ * @en: oversampling enabled/disabled.
+ *
+ * Return:
+ * 0 on success, negative error number on failure.
+ */

drivers/iio/industrialio-backend.c +6 -0
+int iio_backend_oversampling_en(struct iio_backend *back, bool en)
+{
+	return iio_backend_op_call(back, oversampling_en, en);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_en, IIO_BACKEND);
+

There was some discussion around having APIs with a boolean parameter (actually even improving - in terms of callbacks - further with some generic getter/setter's) or having two callbacks:

iio_backend_oversampling_enable()
iio_backend_oversampling_disable()

I'm guessing you don't really want to do any major conversion/refactoring at this point in your series so I have a slight preference for just keeping the current style of dedicated enable and disable APIs (irrespective of being the better approach or not). Please consider it, if you have to re-spin the series.

- Nuno Sá

maintainer
#5 lore raw

Re: [PATCH v6 3/8] iio: backend: add API for oversampling

Quoted 11 lines · On Mon, 11 Nov 2024 16:41:02 +0100 Nuno Sá <[email protected]> wrote:
Quoted 10 lines · Antoniu Miclaus

Add backend support for enabling/disabling oversampling.

---
changes in v6:
 - add iio backend commit for oversampling enable/disable drivers/iio/industrialio-backend.c | 14 ++++++++++++++ include/linux/iio/backend.h        |  3 +++

 2 files changed, 17 insertions(+)
Quoted 22 lines
Quoted 9 lines
drivers/iio/industrialio- renamed from drivers/iio/industrialio-backend.c +0 -0

backend.c
index ea184fc2c838..6ba445ba3dd0 100644

drivers/iio/industrialio-backend.c +0 -0
@@ -681,6 +681,20 @@ int iio_backend_data_size_set(struct iio_backend *back,
 unsigned int size)
  }
  EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, IIO_BACKEND);
Quoted 3 lines


+/**
+ * iio_backend_oversampling_en - set the data width/size in the data bus.

Seems unrelated?

Quoted 7 lines

+ * @back: Backend device
+ * @en: oversampling enabled/disabled.
+ *
+ * Return:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_oversampling_en(struct iio_backend *back, bool en)

Odd to just be on or off vs a count of how much to oversample by with 1 meaning don't oversample, 2,4,8 etc saying how much to oversample by.

Quoted 10 lines

drivers/iio/industrialio-backend.c int iio_backend_data_size_set(struct iio_backend *back, unsigned int size) · line 697

Quoted 5 lines
drivers/iio/industrialio-backend.c +5 -0
+{
+	return iio_backend_op_call(back, oversampling_en, en);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_en, IIO_BACKEND);
+  

There was some discussion around having APIs with a boolean parameter (actually even improving - in terms of callbacks - further with some generic getter/setter's) or having two callbacks:

Quoted 7 lines

iio_backend_oversampling_enable()
iio_backend_oversampling_disable()

I'm guessing you don't really want to do any major conversion/refactoring at this point in your series so I have a slight preference for just keeping the current style of dedicated enable and disable APIs (irrespective of being the better approach or not). Please consider it, if you have to re-spin the series.

Agreed. Keep it consistent for now. I don't mind a proposal to refactor the lot (though not yet convinced either way on it being a good idea) but I don't want to see it inconsistent.

Quoted 4 lines

- Nuno Sá

maintainer
#6 lore raw

Re: [PATCH v6 3/8] iio: backend: add API for oversampling

Quoted 36 lines · On Sat, 23 Nov 2024 16:02:49 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 11 lines · On Mon, 11 Nov 2024 16:41:02 +0100 Nuno Sá <[email protected]> wrote:
Quoted 10 lines · Antoniu Miclaus

Add backend support for enabling/disabling oversampling.

---
changes in v6:
 - add iio backend commit for oversampling enable/disable drivers/iio/industrialio-backend.c | 14 ++++++++++++++ include/linux/iio/backend.h        |  3 +++

 2 files changed, 17 insertions(+)
Quoted 22 lines
Quoted 9 lines
drivers/iio/industrialio- renamed from drivers/iio/industrialio-backend.c +0 -0

backend.c
index ea184fc2c838..6ba445ba3dd0 100644

drivers/iio/industrialio-backend.c +0 -0
@@ -681,6 +681,20 @@ int iio_backend_data_size_set(struct iio_backend *back,
 unsigned int size)
  }
  EXPORT_SYMBOL_NS_GPL(iio_backend_data_size_set, IIO_BACKEND);
Quoted 3 lines


+/**
+ * iio_backend_oversampling_en - set the data width/size in the data bus.

Seems unrelated?

Quoted 7 lines

+ * @back: Backend device
+ * @en: oversampling enabled/disabled.
+ *
+ * Return:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_oversampling_en(struct iio_backend *back, bool en)

Quoted 2 lines

Odd to just be on or off vs a count of how much to oversample by with 1 meaning don't oversample, 2,4,8 etc saying how much to oversample by.

Looking at the code, why does the backend care? Seems you only set the ratio on the ADC, not the in the FPGA IP. So I don't follow how that is useful

Jonathan

Quoted 28 lines
Quoted 11 lines

drivers/iio/industrialio-backend.c int iio_backend_data_size_set(struct iio_backend *back, unsigned int size) · line 697

Quoted 6 lines
drivers/iio/industrialio-backend.c +5 -0
+{
+	return iio_backend_op_call(back, oversampling_en, en);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_oversampling_en, IIO_BACKEND);
+    

There was some discussion around having APIs with a boolean parameter (actually even improving - in terms of callbacks - further with some generic getter/setter's) or having two callbacks:

Quoted 7 lines

iio_backend_oversampling_enable()
iio_backend_oversampling_disable()

I'm guessing you don't really want to do any major conversion/refactoring at this point in your series so I have a slight preference for just keeping the current style of dedicated enable and disable APIs (irrespective of being the better approach or not). Please consider it, if you have to re-spin the series.

Agreed. Keep it consistent for now. I don't mind a proposal to refactor the lot (though not yet convinced either way on it being a good idea) but I don't want to see it inconsistent.

Quoted 4 lines

- Nuno Sá

author reviewer
#7 lore raw

PATCH v6 4/8 iio: adc: adi-axi-adc: add interface type

In reply to Antoniu Miclaus

Add support for getting the interface (CMOS or LVDS) used by the AXI ADC IP.

---
no changes in v6.

 drivers/iio/adc/adi-axi-adc.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/iio/adc/adi-axi-adc.c +23 -0
index 5c8c87eb36d1..f6475bc93796 100644
@@ -39,6 +39,9 @@
 #define   ADI_AXI_REG_RSTN_MMCM_RSTN		BIT(1)
 #define   ADI_AXI_REG_RSTN_RSTN			BIT(0)
 
+#define ADI_AXI_ADC_REG_CONFIG			0x000c
+#define   ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N	BIT(7)
+
 #define ADI_AXI_ADC_REG_CTRL			0x0044
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
@@ -290,6 +293,25 @@ static int axi_adc_chan_disable(struct iio_backend *back, unsigned int chan)
 				 ADI_AXI_REG_CHAN_CTRL_ENABLE);
 }
 
+static int axi_adc_interface_type_get(struct iio_backend *back,
+				      enum iio_backend_interface_type *type)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_CONFIG, &val);
+	if (ret)
+		return ret;
+
+	if (val & ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N)
+		*type = IIO_BACKEND_INTERFACE_SERIAL_CMOS;
+	else
+		*type = IIO_BACKEND_INTERFACE_SERIAL_LVDS;
+
+	return 0;
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -337,6 +359,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.iodelay_set = axi_adc_iodelays_set,
 	.test_pattern_set = axi_adc_test_pattern_set,
 	.chan_status = axi_adc_chan_status,
+	.interface_type_get = axi_adc_interface_type_get,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
Signature · 1 line
2.47.0
author reviewer
#8 lore raw

PATCH v6 5/8 iio: adc: adi-axi-adc: set data format

In reply to Antoniu Miclaus

Add support for selecting the data format within the AXI ADC ip.

---
changes in v6:
- use switch case
- add macro definition for packet format mask and sizes

 drivers/iio/adc/adi-axi-adc.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/iio/adc/adi-axi-adc.c +30 -0
index f6475bc93796..9bf967d5b730 100644
@@ -45,6 +45,12 @@
 #define ADI_AXI_ADC_REG_CTRL			0x0044
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
+#define ADI_AXI_ADC_REG_CNTRL_3			0x004c
+#define   AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK	GENMASK(1, 0)
+#define   AD485X_PACKET_FORMAT_20BIT		0x0
+#define   AD485X_PACKET_FORMAT_24BIT		0x1
+#define   AD485X_PACKET_FORMAT_32BIT		0x2
+
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
 
@@ -312,6 +318,29 @@ static int axi_adc_interface_type_get(struct iio_backend *back,
 	return 0;
 }
 
+static int axi_adc_data_size_set(struct iio_backend *back, unsigned int size)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	unsigned int val;
+
+	switch (size) {
+	case 20:
+		val = AD485X_PACKET_FORMAT_20BIT;
+		break;
+	case 24:
+		val = AD485X_PACKET_FORMAT_24BIT;
+		break;
+	case 32:
+		val = AD485X_PACKET_FORMAT_32BIT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				  AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK, val);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -360,6 +389,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.test_pattern_set = axi_adc_test_pattern_set,
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
+	.data_size_set = axi_adc_data_size_set,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
Signature · 1 line
2.47.0
reviewer
#9 lore raw

Re: [PATCH v6 5/8] iio: adc: adi-axi-adc: set data format

Quoted 28 lines · Antoniu Miclaus

Add support for selecting the data format within the AXI ADC ip.

---
changes in v6:
- use switch case
- add macro definition for packet format mask and sizes

 drivers/iio/adc/adi-axi-adc.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/iio/adc/adi-axi-adc.c +6 -0
index f6475bc93796..9bf967d5b730 100644
@@ -45,6 +45,12 @@
 #define ADI_AXI_ADC_REG_CTRL			0x0044
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
+#define ADI_AXI_ADC_REG_CNTRL_3			0x004c
+#define   AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK	GENMASK(1, 0)
+#define   AD485X_PACKET_FORMAT_20BIT		0x0
+#define   AD485X_PACKET_FORMAT_24BIT		0x1
+#define   AD485X_PACKET_FORMAT_32BIT		0x2
+
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
 

drivers/iio/adc/adi-axi-adc.c static int axi_adc_interface_type_get(struct iio_backend *back, · line 326

Quoted 9 lines
drivers/iio/adc/adi-axi-adc.c +6 -0
@@ -312,6 +318,29 @@ static int axi_adc_interface_type_get(struct iio_backend *back,
 	return 0;
 }
 
+static int axi_adc_data_size_set(struct iio_backend *back, unsigned int size)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	unsigned int val;
+
+	switch (size) {

What happened to 16 bit for 16-bit chips?

Ideally there should be an identification register we can read or a compatible string from the devicetree that says if the HDL was compiled for a 16-bit or 20-bit chip and we would have two different versions of this function and pick one based on what HDL is being used.

Quoted 28 lines
drivers/iio/adc/adi-axi-adc.c +18 -0
+	case 20:
+		val = AD485X_PACKET_FORMAT_20BIT;
+		break;
+	case 24:
+		val = AD485X_PACKET_FORMAT_24BIT;
+		break;
+	case 32:
+		val = AD485X_PACKET_FORMAT_32BIT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				  AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK, val);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -360,6 +389,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.test_pattern_set = axi_adc_test_pattern_set,
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
+	.data_size_set = axi_adc_data_size_set,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
author reviewer
#10 lore raw

PATCH v6 6/8 iio: adc: adi-axi-adc: add oversampling

In reply to Antoniu Miclaus

Add support for enabling/disabling oversampling.

---
changes in v6:
- add support for oversampling enable/disable.

 drivers/iio/adc/adi-axi-adc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/iio/adc/adi-axi-adc.c +10 -0
index 9bf967d5b730..8ec668f59c88 100644
@@ -46,6 +46,7 @@
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
 #define ADI_AXI_ADC_REG_CNTRL_3			0x004c
+#define   AD485X_CNTRL_3_CUSTOM_CTRL_OS_EN_MSK	BIT(2)
 #define   AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK	GENMASK(1, 0)
 #define   AD485X_PACKET_FORMAT_20BIT		0x0
 #define   AD485X_PACKET_FORMAT_24BIT		0x1
@@ -341,6 +342,14 @@ static int axi_adc_data_size_set(struct iio_backend *back, unsigned int size)
 				  AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK, val);
 }
 
+static int axi_adc_oversampling_en(struct iio_backend *back, bool en)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				  AD485X_CNTRL_3_CUSTOM_CTRL_OS_EN_MSK, en);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -390,6 +399,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
 	.data_size_set = axi_adc_data_size_set,
+	.oversampling_en = axi_adc_oversampling_en,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
Signature · 1 line
2.47.0
reviewer
#11 lore raw

Re: [PATCH v6 6/8] iio: adc: adi-axi-adc: add oversampling

Quoted 22 lines · Antoniu Miclaus

Add support for enabling/disabling oversampling.

---
changes in v6:
- add support for oversampling enable/disable.

 drivers/iio/adc/adi-axi-adc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/iio/adc/adi-axi-adc.c +1 -0
index 9bf967d5b730..8ec668f59c88 100644
@@ -46,6 +46,7 @@
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
 #define ADI_AXI_ADC_REG_CNTRL_3			0x004c
+#define   AD485X_CNTRL_3_CUSTOM_CTRL_OS_EN_MSK	BIT(2)
 #define   AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK	GENMASK(1, 0)
 #define   AD485X_PACKET_FORMAT_20BIT		0x0
 #define   AD485X_PACKET_FORMAT_24BIT		0x1

drivers/iio/adc/adi-axi-adc.c static int axi_adc_data_size_set(struct iio_backend *back, unsigned int size) · line 350

Quoted 9 lines
drivers/iio/adc/adi-axi-adc.c +6 -0
@@ -341,6 +342,14 @@ static int axi_adc_data_size_set(struct iio_backend *back, unsigned int size)
 				  AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK, val);
 }
 
+static int axi_adc_oversampling_en(struct iio_backend *back, bool en)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				  AD485X_CNTRL_3_CUSTOM_CTRL_OS_EN_MSK, en);

This needs FIELD_PREP() to apply the correct shift to en.

Quoted 13 lines
drivers/iio/adc/adi-axi-adc.c +3 -0
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -390,6 +399,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
 	.data_size_set = axi_adc_data_size_set,
+	.oversampling_en = axi_adc_oversampling_en,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
maintainer
#12 lore raw

Re: [PATCH v6 6/8] iio: adc: adi-axi-adc: add oversampling

In reply to Antoniu Miclaus
Quoted 1 line · On Mon, 11 Nov 2024 14:12:01 +0200 Antoniu Miclaus…

Add support for enabling/disabling oversampling.

As earlier, this is usually an oversample by N, not just a boolean. If it is boolean for this device, then I assume there is a fixed ratio. Make the interface controlling between 1 and whatever that ratio is.

Jonathan

Quoted 43 lines

---
changes in v6:
- add support for oversampling enable/disable.

 drivers/iio/adc/adi-axi-adc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/iio/adc/adi-axi-adc.c +10 -0
index 9bf967d5b730..8ec668f59c88 100644
@@ -46,6 +46,7 @@
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
 #define ADI_AXI_ADC_REG_CNTRL_3			0x004c
+#define   AD485X_CNTRL_3_CUSTOM_CTRL_OS_EN_MSK	BIT(2)
 #define   AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK	GENMASK(1, 0)
 #define   AD485X_PACKET_FORMAT_20BIT		0x0
 #define   AD485X_PACKET_FORMAT_24BIT		0x1
@@ -341,6 +342,14 @@ static int axi_adc_data_size_set(struct iio_backend *back, unsigned int size)
 				  AD485X_CNTRL_3_CUSTOM_CTRL_PACKET_FORMAT_MSK, val);
 }
 
+static int axi_adc_oversampling_en(struct iio_backend *back, bool en)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				  AD485X_CNTRL_3_CUSTOM_CTRL_OS_EN_MSK, en);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -390,6 +399,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
 	.data_size_set = axi_adc_data_size_set,
+	.oversampling_en = axi_adc_oversampling_en,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
author reviewer
#13 lore raw

PATCH v6 7/8 dt-bindings: iio: adc: add ad4851

In reply to Antoniu Miclaus

Add devicetree bindings for ad485x family.

---
no changes in v6.

 .../bindings/iio/adc/adi,ad4851.yaml          | 103 ++++++++++++++++++
 1 file changed, 103 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad4851.yaml new file +103 -0
new file mode 100644
index 000000000000..9e9439fed3ef
@@ -0,0 +1,103 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2024 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad4851.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD485X family
+
+maintainers:
+  - Sergiu Cuciurean <[email protected]>
+  - Dragos Bogdan <[email protected]>
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  Analog Devices AD485X fully buffered, 8-channel simultaneous sampling,
+  16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide
+  common-mode range inputs.
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad4855.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad4856.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad4857.pdf
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad4858.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,ad4851
+      - adi,ad4852
+      - adi,ad4853
+      - adi,ad4854
+      - adi,ad4855
+      - adi,ad4856
+      - adi,ad4857
+      - adi,ad4858
+      - adi,ad4858i
+
+  reg:
+    maxItems: 1
+
+  vcc-supply: true
+
+  vee-supply: true
+
+  vdd-supply: true
+
+  vddh-supply: true
+
+  vddl-supply: true
+
+  vio-supply: true
+
+  vrefbuf-supply: true
+
+  vrefio-supply: true
+
+  pwms:
+    description: PWM connected to the CNV pin.
+    maxItems: 1
+
+  io-backends:
+    maxItems: 1
+
+  pd-gpios:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 25000000
+
+required:
+  - compatible
+  - reg
+  - vcc-supply
+  - vee-supply
+  - vdd-supply
+  - vio-supply
+  - pwms
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0{
+            compatible = "adi,ad4858";
+            reg = <0>;
+            spi-max-frequency = <10000000>;
+            vcc-supply = <&vcc>;
+            vdd-supply = <&vdd>;
+            vee-supply = <&vee>;
+            vddh-supply = <&vddh>;
+            vddl-supply = <&vddl>;
+            vio-supply = <&vio>;
+            pwms = <&pwm_gen 0 0>;
+            io-backends = <&iio_backend>;
+        };
+    };
+...
Signature · 1 line
2.47.0
author reviewer
#14 lore raw

PATCH v6 8/8 iio: adc: ad4851: add ad485x driver

In reply to Antoniu Miclaus

Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.

---
changes in v6 (implemented most of the review comments in v5):
- fix zero size array
- remove leftover offset members
- remove unused structure members
- DIV_ROUND_UP_ULL
- check ad4851_osr_to_regval before OS enable.
- user regmap_clear_bits/regmap_set_bits where applicable.
- drop resoluton boost for 16-bit chips
- use mutex in ad4851_get_oversampling_ratio.
- drop GPIOD_OUT_* macros.
- rearrange operations inside ad4851_setup
- drop kmalloc for scales and use array instead.
- drop unreachable return
- add devm_add_action_and_reset to call pwm_disable.
- add comment for the PD sequence.
- lane_num->num_lanes
- add blank line after return ret.
- don't wrap early.
- add structure for scale_table.
- use dev = &spi->dev to shorten code.
- fix regulator messages
- indio_dev->modes = INDIO_DIRECT_MODE;

 drivers/iio/adc/Kconfig  |   13 +
 drivers/iio/adc/Makefile |    1 +
 drivers/iio/adc/ad4851.c | 1190 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1204 insertions(+)
 create mode 100644 drivers/iio/adc/ad4851.c
drivers/iio/adc/Kconfig +13 -0
index 6c4e74420fd2..0d97cd760d90 100644
@@ -61,6 +61,19 @@ config AD4695
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad4695.
 
+config AD4851
+	tristate "Analog Device AD4851 DAS Driver"
+	depends on SPI
+	select REGMAP_SPI
+	select IIO_BACKEND
+	help
+	  Say yes here to build support for Analog Devices AD4851, AD4852,
+	  AD4853, AD4854, AD4855, AD4856, AD4857, AD4858, AD4858I high speed
+	  data acquisition system (DAS).
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ad4851.
+
 config AD7091R
 	tristate
 
drivers/iio/adc/Makefile +1 -0
index 7b91cd98c0e0..d83df8b5925d 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD4000) += ad4000.o
 obj-$(CONFIG_AD4130) += ad4130.o
 obj-$(CONFIG_AD4695) += ad4695.o
+obj-$(CONFIG_AD4851) += ad4851.o
 obj-$(CONFIG_AD7091R) += ad7091r-base.o
 obj-$(CONFIG_AD7091R5) += ad7091r5.o
 obj-$(CONFIG_AD7091R8) += ad7091r8.o
drivers/iio/adc/ad4851.c new file +1190 -0

1,190 lines not on this page · raw message

+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(IIO_BACKEND);

Signature · 1 line
2.47.0
reviewer
#15 lore raw

Re: [PATCH v6 8/8] iio: adc: ad4851: add ad485x driver

Quoted 7 lines · Antoniu Miclaus

Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.

---
changes in v6 (implemented most of the review comments in v5):

What is the plan for addressing the rest of the comments?

I don't want to keep making the same comments over and over again.

author reviewer
#16 lore raw

RE: [PATCH v6 8/8] iio: adc: ad4851: add ad485x driver

Quoted 9 lines · Antoniu Miclaus
Quoted 7 lines

Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.

---
changes in v6 (implemented most of the review comments in v5):

What is the plan for addressing the rest of the comments?

For the rest of the comments I think I replied inline in the previous series.

Quoted 1 line

I don't want to keep making the same comments over and over again.

reviewer
#17 lore raw

Re: [PATCH v6 8/8] iio: adc: ad4851: add ad485x driver

Quoted 11 lines · Antoniu
Quoted 9 lines · Antoniu Miclaus
Quoted 7 lines

Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.

---
changes in v6 (implemented most of the review comments in v5):

What is the plan for addressing the rest of the comments?

For the rest of the comments I think I replied inline in the previous series.

I didn't look very close yet, but at a quick glance, I saw that all scan_type are still only signed, there is no unsigned for when the channels are used as single-ended. And the scan_index ordering is still wrong. This makes me doubt that buffered reads are working correctly for all configurations.

author reviewer
#18 lore raw

RE: [PATCH v6 8/8] iio: adc: ad4851: add ad485x driver

Quoted 10 lines · Antoniu
Quoted 8 lines
Quoted 8 lines · Antoniu Miclaus
Quoted 7 lines

Add support for the AD485X a fully buffered, 8-channel simultaneous sampling, 16/20-bit, 1 MSPS data acquisition system (DAS) with differential, wide common-mode range inputs.

---
changes in v6 (implemented most of the review comments in v5):

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

What is the plan for addressing the rest of the comments?

For the rest of the comments I think I replied inline in the previous series.

I didn't look very close yet, but at a quick glance, I saw that all scan_type are still only signed, there is no unsigned for when the channels are used as single-ended. And the scan_index ordering is still wrong. This makes me doubt that buffered reads are working correctly for all configurations.

Sure, will implement the scan_type as you suggested in the next series.