Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support
@ 2024-08-02 14:26 Nuno Sa via B4 Relay
  2024-08-02 14:26 ` [PATCH v2 1/8] iio: backend: introduce struct iio_backend_info Nuno Sa via B4 Relay
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:26 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

This is the second version of the series. I ended up trying the new
directory route and think it does look nice and more future proof.
Biggest change is the first patch where we now pass an info like
structure to devm_iio_backend_register(). Again, this is likely also a more
future proof approach and we would likely need it sooner or later (one
usage I see is for backends to pass in some constant information that
could be consumed from frontends when doing backend_get())  

v1:
 * https://lore.kernel.org/linux-iio/20240709-dev-iio-backend-add-debugfs-v1-0-fb4b8f2373c7@analog.com/

v2:
 * Patch 1:
  - New patch;

 * Patch 2:
  - Added backendY directory with the direct_reg_access and name
    attributes;
  - Get the backend name directly from the backend driver;
  - Get the backend index from backend-names FW property;
  - Added debugfs-iio-backend to the ABI docs. 

---
Nuno Sa (8):
      iio: backend: introduce struct iio_backend_info
      iio: backend: add debugFs interface
      iio: backend: add a modified prbs23 support
      iio: adc: adi-axi-adc: support modified prbs23
      iio: adc: adi-axi-adc: split axi_adc_chan_status()
      iio: adc: adi-axi-adc: implement backend debugfs interface
      iio: adc: ad9467: add backend test mode helpers
      iio: adc: ad9467: add digital interface test to debugfs

 Documentation/ABI/testing/debugfs-iio-backend |  20 ++
 MAINTAINERS                                   |   1 +
 drivers/iio/adc/ad9467.c                      | 255 +++++++++++++++++++++++---
 drivers/iio/adc/adi-axi-adc.c                 |  71 ++++++-
 drivers/iio/dac/adi-axi-dac.c                 |   7 +-
 drivers/iio/industrialio-backend.c            | 155 +++++++++++++++-
 include/linux/iio/backend.h                   |  28 ++-
 7 files changed, 499 insertions(+), 38 deletions(-)
---
base-commit: 168bed989d651794d03638e1f7f7b5a800a6f425
change-id: 20240802-dev-iio-backend-add-debugfs-0b13bb5a5b37
--

Thanks!
- Nuno Sá



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

* [PATCH v2 1/8] iio: backend: introduce struct iio_backend_info
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
@ 2024-08-02 14:26 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 2/8] iio: backend: add debugFs interface Nuno Sa via B4 Relay
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:26 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

Instead of only passing the backend ops when calling
devm_iio_backend_register(), pass an info like structure that will
contains the ops and additional information. Fow now, the backend name
is being added as that will be used by the debugFS interface introduced
in a later patch.

It also opens the door for further customizations passed by backends.

All users of devm_iio_backend_register() were updated accordingly.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/adc/adi-axi-adc.c      |  7 ++++++-
 drivers/iio/dac/adi-axi-dac.c      |  7 ++++++-
 drivers/iio/industrialio-backend.c | 10 +++++-----
 include/linux/iio/backend.h        | 12 +++++++++++-
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 21ce7564e83db..0a9d7433da304 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -273,7 +273,7 @@ static const struct regmap_config axi_adc_regmap_config = {
 	.reg_stride = 4,
 };
 
-static const struct iio_backend_ops adi_axi_adc_generic = {
+static const struct iio_backend_ops adi_axi_adc_ops = {
 	.enable = axi_adc_enable,
 	.disable = axi_adc_disable,
 	.data_format_set = axi_adc_data_format_set,
@@ -287,6 +287,11 @@ static const struct iio_backend_ops adi_axi_adc_generic = {
 	.chan_status = axi_adc_chan_status,
 };
 
+static const struct iio_backend_info adi_axi_adc_generic = {
+	.name = "axi-adc",
+	.ops = &adi_axi_adc_ops,
+};
+
 static int adi_axi_adc_probe(struct platform_device *pdev)
 {
 	const unsigned int *expected_ver;
diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index e44463f48bf5d..9655705b158be 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -507,7 +507,7 @@ static int axi_dac_set_sample_rate(struct iio_backend *back, unsigned int chan,
 	return 0;
 }
 
-static const struct iio_backend_ops axi_dac_generic = {
+static const struct iio_backend_ops axi_dac_generic_ops = {
 	.enable = axi_dac_enable,
 	.disable = axi_dac_disable,
 	.request_buffer = axi_dac_request_buffer,
@@ -519,6 +519,11 @@ static const struct iio_backend_ops axi_dac_generic = {
 	.set_sample_rate = axi_dac_set_sample_rate,
 };
 
+static const struct iio_backend_info axi_dac_generic = {
+	.name = "axi-dac",
+	.ops = &axi_dac_generic_ops,
+};
+
 static const struct regmap_config axi_dac_regmap_config = {
 	.val_bits = 32,
 	.reg_bits = 32,
diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index f9da635cdfeaf..0cf80ffd2e612 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -641,20 +641,20 @@ static void iio_backend_unregister(void *arg)
 /**
  * devm_iio_backend_register - Device managed backend device register
  * @dev: Backend device being registered
- * @ops: Backend ops
+ * @info: Backend info
  * @priv: Device private data
  *
- * @ops is mandatory. Not providing it results in -EINVAL.
+ * @info is mandatory. Not providing it results in -EINVAL.
  *
  * RETURNS:
  * 0 on success, negative error number on failure.
  */
 int devm_iio_backend_register(struct device *dev,
-			      const struct iio_backend_ops *ops, void *priv)
+			      const struct iio_backend_info *info, void *priv)
 {
 	struct iio_backend *back;
 
-	if (!ops)
+	if (!info || !info->ops)
 		return dev_err_probe(dev, -EINVAL, "No backend ops given\n");
 
 	/*
@@ -667,7 +667,7 @@ int devm_iio_backend_register(struct device *dev,
 	if (!back)
 		return -ENOMEM;
 
-	back->ops = ops;
+	back->ops = info->ops;
 	back->owner = dev->driver->owner;
 	back->dev = dev;
 	back->priv = priv;
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index 29c4cf0bd761f..f120fa2e0a434 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -115,6 +115,16 @@ struct iio_backend_ops {
 			    const struct iio_chan_spec *chan, char *buf);
 };
 
+/**
+ * struct iio_backend_info - info structure for an iio_backend
+ * @name: Backend name.
+ * @ops: Backend operations.
+ */
+struct iio_backend_info {
+	const char *name;
+	const struct iio_backend_ops *ops;
+};
+
 int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
 int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan);
 int devm_iio_backend_enable(struct device *dev, struct iio_backend *back);
@@ -151,6 +161,6 @@ __devm_iio_backend_get_from_fwnode_lookup(struct device *dev,
 					  struct fwnode_handle *fwnode);
 
 int devm_iio_backend_register(struct device *dev,
-			      const struct iio_backend_ops *ops, void *priv);
+			      const struct iio_backend_info *info, void *priv);
 
 #endif

-- 
2.45.2



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

* [PATCH v2 2/8] iio: backend: add debugFs interface
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
  2024-08-02 14:26 ` [PATCH v2 1/8] iio: backend: introduce struct iio_backend_info Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 3/8] iio: backend: add a modified prbs23 support Nuno Sa via B4 Relay
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

This adds a basic debugfs interface for backends. Two new ops are being
added:

 * debugfs_reg_access: Analogous to the core IIO one but for backend
   devices.
 * debugfs_print_chan_status: One useful usecase for this one is for
   testing test tones in a digital interface and "ask" the backend to
   dump more details on why a test tone might have errors.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 Documentation/ABI/testing/debugfs-iio-backend |  20 ++++
 MAINTAINERS                                   |   1 +
 drivers/iio/industrialio-backend.c            | 145 ++++++++++++++++++++++++++
 include/linux/iio/backend.h                   |  14 +++
 4 files changed, 180 insertions(+)

diff --git a/Documentation/ABI/testing/debugfs-iio-backend b/Documentation/ABI/testing/debugfs-iio-backend
new file mode 100644
index 000000000000..01ab94469432
--- /dev/null
+++ b/Documentation/ABI/testing/debugfs-iio-backend
@@ -0,0 +1,20 @@
+What:		/sys/kernel/debug/iio/iio:deviceX/backendY/name
+KernelVersion:	6.11
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Name of Backend Y connected to device X.
+
+What:		/sys/kernel/debug/iio/iio:deviceX/backendY/direct_reg_access
+KernelVersion:	6.11
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Directly access the registers of backend Y. Typical usage is:
+
+		Reading address 0x50
+		echo 0x50 > direct_reg_access
+		cat direct_reg_access
+
+		Writing address 0x50
+		echo 0x50 0x3 > direct_reg_access
+		//readback address 0x50
+		cat direct_reg_access
diff --git a/MAINTAINERS b/MAINTAINERS
index cd677bcc54da..c28bcbc94725 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10885,6 +10885,7 @@ M:	Nuno Sa <nuno.sa@analog.com>
 R:	Olivier Moysan <olivier.moysan@foss.st.com>
 L:	linux-iio@vger.kernel.org
 S:	Maintained
+F:	Documentation/ABI/testing/debugfs-iio-backend
 F:	drivers/iio/industrialio-backend.c
 F:	include/linux/iio/backend.h
 
diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index 0cf80ffd2e61..468eadeaf23d 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -32,6 +32,7 @@
 #define dev_fmt(fmt) "iio-backend: " fmt
 
 #include <linux/cleanup.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/errno.h>
@@ -53,6 +54,14 @@ struct iio_backend {
 	struct device *dev;
 	struct module *owner;
 	void *priv;
+	const char *name;
+	unsigned int cached_reg_addr;
+	/*
+	 * This index is relative to the frontend. Meaning that for
+	 * frontends with multiple backends, this will be the index of this
+	 * backend. Used for the debugfs directory name.
+	 */
+	u8 idx;
 };
 
 /*
@@ -117,6 +126,138 @@ static DEFINE_MUTEX(iio_back_lock);
 			__stringify(op));			\
 }
 
+static ssize_t iio_backend_debugfs_read_reg(struct file *file,
+					    char __user *userbuf,
+					    size_t count, loff_t *ppos)
+{
+	struct iio_backend *back = file->private_data;
+	char read_buf[20];
+	unsigned int val;
+	int ret, len;
+
+	ret = iio_backend_op_call(back, debugfs_reg_access,
+				  back->cached_reg_addr, 0, &val);
+	if (ret)
+		return ret;
+
+	len = scnprintf(read_buf, sizeof(read_buf), "0x%X\n", val);
+
+	return simple_read_from_buffer(userbuf, count, ppos, read_buf, len);
+}
+
+static ssize_t iio_backend_debugfs_write_reg(struct file *file,
+					     const char __user *userbuf,
+					     size_t count, loff_t *ppos)
+{
+	struct iio_backend *back = file->private_data;
+	unsigned int val;
+	char buf[80];
+	ssize_t rc;
+	int ret;
+
+	rc = simple_write_to_buffer(buf, sizeof(buf), ppos, userbuf, count);
+	if (rc < 0)
+		return rc;
+
+	ret = sscanf(buf, "%i %i", &back->cached_reg_addr, &val);
+
+	switch (ret) {
+	case 1:
+		return count;
+	case 2:
+		ret = iio_backend_op_call(back, debugfs_reg_access,
+					  back->cached_reg_addr, val, NULL);
+		if (ret)
+			return ret;
+		return count;
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct file_operations iio_backend_debugfs_reg_fops = {
+	.open = simple_open,
+	.read = iio_backend_debugfs_read_reg,
+	.write = iio_backend_debugfs_write_reg,
+};
+
+static ssize_t iio_backend_debugfs_read_name(struct file *file,
+					     char __user *userbuf,
+					     size_t count, loff_t *ppos)
+{
+	struct iio_backend *back = file->private_data;
+	char name[128];
+	int len;
+
+	len = scnprintf(name, sizeof(name), "%s\n", back->name);
+
+	return simple_read_from_buffer(userbuf, count, ppos, name, len);
+}
+
+static const struct file_operations iio_backend_debugfs_name_fops = {
+	.open = simple_open,
+	.read = iio_backend_debugfs_read_name,
+};
+
+/**
+ * iio_backend_debugfs_add - Add debugfs interfaces for Backends
+ * @back: Backend device
+ * @indio_dev: IIO device
+ */
+void iio_backend_debugfs_add(struct iio_backend *back,
+			     struct iio_dev *indio_dev)
+{
+	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
+	struct dentry *back_d;
+	char name[128];
+
+	if (!IS_ENABLED(CONFIG_DEBUG_FS) || !d)
+		return;
+	if (!back->ops->debugfs_reg_access && !back->name)
+		return;
+
+	snprintf(name, sizeof(name), "backend%d", back->idx);
+
+	back_d = debugfs_create_dir(name, d);
+	if (!back_d)
+		return;
+
+	if (back->ops->debugfs_reg_access)
+		debugfs_create_file("direct_reg_access", 0600, back_d, back,
+				    &iio_backend_debugfs_reg_fops);
+
+	if (back->name)
+		debugfs_create_file("name", 0400, back_d, back,
+				    &iio_backend_debugfs_name_fops);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_debugfs_add, IIO_BACKEND);
+
+/**
+ * iio_backend_debugfs_print_chan_status - Print channel status
+ * @back: Backend device
+ * @chan: Channel number
+ * @buf: Buffer where to print the status
+ * @len: Available space
+ *
+ * One usecase where this is useful is for testing test tones in a digital
+ * interface and "ask" the backend to dump more details on why a test tone might
+ * have errors.
+ *
+ * RETURNS:
+ * Number of copied bytes on success, negative error code on failure.
+ */
+ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back,
+					      unsigned int chan, char *buf,
+					      size_t len)
+{
+	if (!IS_ENABLED(CONFIG_DEBUG_FS))
+		return -ENODEV;
+
+	return iio_backend_op_call(back, debugfs_print_chan_status, chan, buf,
+				   len);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_debugfs_print_chan_status, IIO_BACKEND);
+
 /**
  * iio_backend_chan_enable - Enable a backend channel
  * @back: Backend device
@@ -577,6 +718,9 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name)
 		if (ret)
 			return ERR_PTR(ret);
 
+		if (name)
+			back->idx = index;
+
 		return back;
 	}
 
@@ -668,6 +812,7 @@ int devm_iio_backend_register(struct device *dev,
 		return -ENOMEM;
 
 	back->ops = info->ops;
+	back->name = info->name;
 	back->owner = dev->driver->owner;
 	back->dev = dev;
 	back->priv = priv;
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index f120fa2e0a43..9d0dba7ab9e7 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -22,6 +22,8 @@ enum iio_backend_data_source {
 	IIO_BACKEND_DATA_SOURCE_MAX
 };
 
+#define iio_backend_debugfs_ptr(ptr)	PTR_IF(IS_ENABLED(CONFIG_DEBUG_FS), ptr)
+
 /**
  * IIO_BACKEND_EX_INFO - Helper for an IIO extended channel attribute
  * @_name: Attribute name
@@ -81,6 +83,8 @@ enum iio_backend_sample_trigger {
  * @extend_chan_spec: Extend an IIO channel.
  * @ext_info_set: Extended info setter.
  * @ext_info_get: Extended info getter.
+ * @debugfs_print_chan_status: Print channel status into a buffer.
+ * @debugfs_reg_access: Read or write register value of backend.
  **/
 struct iio_backend_ops {
 	int (*enable)(struct iio_backend *back);
@@ -113,6 +117,11 @@ 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 (*debugfs_print_chan_status)(struct iio_backend *back,
+					 unsigned int chan, char *buf,
+					 size_t len);
+	int (*debugfs_reg_access)(struct iio_backend *back, unsigned int reg,
+				  unsigned int writeval, unsigned int *readval);
 };
 
 /**
@@ -163,4 +172,9 @@ __devm_iio_backend_get_from_fwnode_lookup(struct device *dev,
 int devm_iio_backend_register(struct device *dev,
 			      const struct iio_backend_info *info, void *priv);
 
+ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back,
+					      unsigned int chan, char *buf,
+					      size_t len);
+void iio_backend_debugfs_add(struct iio_backend *back,
+			     struct iio_dev *indio_dev);
 #endif

-- 
2.45.2



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

* [PATCH v2 3/8] iio: backend: add a modified prbs23 support
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
  2024-08-02 14:26 ` [PATCH v2 1/8] iio: backend: introduce struct iio_backend_info Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 2/8] iio: backend: add debugFs interface Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 4/8] iio: adc: adi-axi-adc: support modified prbs23 Nuno Sa via B4 Relay
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

Support ADI specific prb23 sequence that can be used both for
calibrating or debugging digital interfaces.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 include/linux/iio/backend.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index 9d0dba7ab9e7..2b9d1aa86552 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -56,6 +56,8 @@ enum iio_backend_test_pattern {
 	IIO_BACKEND_NO_TEST_PATTERN,
 	/* modified prbs9 */
 	IIO_BACKEND_ADI_PRBS_9A = 32,
+	/* modified prbs23 */
+	IIO_BACKEND_ADI_PRBS_23A,
 	IIO_BACKEND_TEST_PATTERN_MAX
 };
 

-- 
2.45.2



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

* [PATCH v2 4/8] iio: adc: adi-axi-adc: support modified prbs23
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
                   ` (2 preceding siblings ...)
  2024-08-02 14:27 ` [PATCH v2 3/8] iio: backend: add a modified prbs23 support Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 5/8] iio: adc: adi-axi-adc: split axi_adc_chan_status() Nuno Sa via B4 Relay
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

Add support for configuring the prbs23 sequence.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/adc/adi-axi-adc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 0a9d7433da30..f4cdfcca865d 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -199,6 +199,10 @@ static int axi_adc_test_pattern_set(struct iio_backend *back,
 		return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CHAN_CTRL_3(chan),
 					  ADI_AXI_ADC_CHAN_PN_SEL_MASK,
 					  FIELD_PREP(ADI_AXI_ADC_CHAN_PN_SEL_MASK, 0));
+	case IIO_BACKEND_ADI_PRBS_23A:
+		return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CHAN_CTRL_3(chan),
+					  ADI_AXI_ADC_CHAN_PN_SEL_MASK,
+					  FIELD_PREP(ADI_AXI_ADC_CHAN_PN_SEL_MASK, 1));
 	default:
 		return -EINVAL;
 	}

-- 
2.45.2



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

* [PATCH v2 5/8] iio: adc: adi-axi-adc: split axi_adc_chan_status()
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
                   ` (3 preceding siblings ...)
  2024-08-02 14:27 ` [PATCH v2 4/8] iio: adc: adi-axi-adc: support modified prbs23 Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 6/8] iio: adc: adi-axi-adc: implement backend debugfs interface Nuno Sa via B4 Relay
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

Add a new axi_adc_read_chan_status() helper so we get the raw register
value out of it.

This is in preparation of a future change where we really want to look
into dedicated bits of the register.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/adc/adi-axi-adc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index f4cdfcca865d..442a87024e1a 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -208,12 +208,10 @@ static int axi_adc_test_pattern_set(struct iio_backend *back,
 	}
 }
 
-static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan,
-			       bool *error)
+static int axi_adc_read_chan_status(struct adi_axi_adc_state *st, unsigned int chan,
+				    unsigned int *status)
 {
-	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
 	int ret;
-	u32 val;
 
 	guard(mutex)(&st->lock);
 	/* reset test bits by setting them */
@@ -225,7 +223,18 @@ static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan,
 	/* let's give enough time to validate or erroring the incoming pattern */
 	fsleep(1000);
 
-	ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_CHAN_STATUS(chan), &val);
+	return regmap_read(st->regmap, ADI_AXI_ADC_REG_CHAN_STATUS(chan),
+			   status);
+}
+
+static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan,
+			       bool *error)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	u32 val;
+	int ret;
+
+	ret = axi_adc_read_chan_status(st, chan, &val);
 	if (ret)
 		return ret;
 

-- 
2.45.2



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

* [PATCH v2 6/8] iio: adc: adi-axi-adc: implement backend debugfs interface
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
                   ` (4 preceding siblings ...)
  2024-08-02 14:27 ` [PATCH v2 5/8] iio: adc: adi-axi-adc: split axi_adc_chan_status() Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 7/8] iio: adc: ad9467: add backend test mode helpers Nuno Sa via B4 Relay
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

Implement debugfs options to read/write registers and print the channel
status into a buffer (so we may know better the cause for errors) .

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/adc/adi-axi-adc.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 442a87024e1a..5c8c87eb36d1 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -61,6 +61,10 @@
 
 #define ADI_AXI_ADC_REG_CHAN_STATUS(c)		(0x0404 + (c) * 0x40)
 #define   ADI_AXI_ADC_CHAN_STAT_PN_MASK		GENMASK(2, 1)
+/* out of sync */
+#define   ADI_AXI_ADC_CHAN_STAT_PN_OOS		BIT(1)
+/* spurious out of sync */
+#define   ADI_AXI_ADC_CHAN_STAT_PN_ERR		BIT(2)
 
 #define ADI_AXI_ADC_REG_CHAN_CTRL_3(c)		(0x0418 + (c) * 0x40)
 #define   ADI_AXI_ADC_CHAN_PN_SEL_MASK		GENMASK(19, 16)
@@ -246,6 +250,30 @@ static int axi_adc_chan_status(struct iio_backend *back, unsigned int chan,
 	return 0;
 }
 
+static int axi_adc_debugfs_print_chan_status(struct iio_backend *back,
+					     unsigned int chan, char *buf,
+					     size_t len)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	u32 val;
+	int ret;
+
+	ret = axi_adc_read_chan_status(st, chan, &val);
+	if (ret)
+		return ret;
+
+	/*
+	 * PN_ERR is cleared in case out of sync is set. Hence, no point in
+	 * checking both bits.
+	 */
+	if (val & ADI_AXI_ADC_CHAN_STAT_PN_OOS)
+		return scnprintf(buf, len, "CH%u: Out of Sync.\n", chan);
+	if (val & ADI_AXI_ADC_CHAN_STAT_PN_ERR)
+		return scnprintf(buf, len, "CH%u: Spurious Out of Sync.\n", chan);
+
+	return scnprintf(buf, len, "CH%u: OK.\n", chan);
+}
+
 static int axi_adc_chan_enable(struct iio_backend *back, unsigned int chan)
 {
 	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
@@ -280,6 +308,17 @@ static void axi_adc_free_buffer(struct iio_backend *back,
 	iio_dmaengine_buffer_free(buffer);
 }
 
+static int axi_adc_reg_access(struct iio_backend *back, unsigned int reg,
+			      unsigned int writeval, unsigned int *readval)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	if (readval)
+		return regmap_read(st->regmap, reg, readval);
+
+	return regmap_write(st->regmap, reg, writeval);
+}
+
 static const struct regmap_config axi_adc_regmap_config = {
 	.val_bits = 32,
 	.reg_bits = 32,
@@ -298,6 +337,8 @@ 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,
+	.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),
 };
 
 static const struct iio_backend_info adi_axi_adc_generic = {

-- 
2.45.2



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

* [PATCH v2 7/8] iio: adc: ad9467: add backend test mode helpers
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
                   ` (5 preceding siblings ...)
  2024-08-02 14:27 ` [PATCH v2 6/8] iio: adc: adi-axi-adc: implement backend debugfs interface Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-02 14:27 ` [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs Nuno Sa via B4 Relay
  2024-08-03 13:39 ` [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Jonathan Cameron
  8 siblings, 0 replies; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

Group the backend configurations to be done in preparing and stopping
calibration in two new helpers analogous to ad9467_testmode_set(). This
is in preparation for adding support for debugFS test_mode where
we need similar configurations as in the calibration process.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/adc/ad9467.c | 67 ++++++++++++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 25 deletions(-)

diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index 557d98ca2f25..2f4bbbd5611c 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -494,11 +494,49 @@ static int ad9467_testmode_set(struct ad9467_state *st, unsigned int chan,
 				AN877_ADC_TRANSFER_SYNC);
 }
 
-static int ad9647_calibrate_prepare(struct ad9467_state *st)
+static int ad9467_backend_testmode_on(struct ad9467_state *st,
+				      unsigned int chan,
+				      enum iio_backend_test_pattern pattern)
 {
 	struct iio_backend_data_fmt data = {
 		.enable = false,
 	};
+	int ret;
+
+	ret = iio_backend_data_format_set(st->back, chan, &data);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_test_pattern_set(st->back, chan, pattern);
+	if (ret)
+		return ret;
+
+	return iio_backend_chan_enable(st->back, chan);
+}
+
+static int ad9467_backend_testmode_off(struct ad9467_state *st,
+				       unsigned int chan)
+{
+	struct iio_backend_data_fmt data = {
+		.enable = true,
+		.sign_extend = true,
+	};
+	int ret;
+
+	ret = iio_backend_chan_disable(st->back, chan);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_test_pattern_set(st->back, chan,
+					   IIO_BACKEND_NO_TEST_PATTERN);
+	if (ret)
+		return ret;
+
+	return iio_backend_data_format_set(st->back, chan, &data);
+}
+
+static int ad9647_calibrate_prepare(struct ad9467_state *st)
+{
 	unsigned int c;
 	int ret;
 
@@ -511,16 +549,8 @@ static int ad9647_calibrate_prepare(struct ad9467_state *st)
 		if (ret)
 			return ret;
 
-		ret = iio_backend_data_format_set(st->back, c, &data);
-		if (ret)
-			return ret;
-
-		ret = iio_backend_test_pattern_set(st->back, c,
-						   IIO_BACKEND_ADI_PRBS_9A);
-		if (ret)
-			return ret;
-
-		ret = iio_backend_chan_enable(st->back, c);
+		ret = ad9467_backend_testmode_on(st, c,
+						 IIO_BACKEND_ADI_PRBS_9A);
 		if (ret)
 			return ret;
 	}
@@ -601,24 +631,11 @@ static int ad9467_calibrate_apply(struct ad9467_state *st, unsigned int val)
 
 static int ad9647_calibrate_stop(struct ad9467_state *st)
 {
-	struct iio_backend_data_fmt data = {
-		.sign_extend = true,
-		.enable = true,
-	};
 	unsigned int c, mode;
 	int ret;
 
 	for (c = 0; c < st->info->num_channels; c++) {
-		ret = iio_backend_chan_disable(st->back, c);
-		if (ret)
-			return ret;
-
-		ret = iio_backend_test_pattern_set(st->back, c,
-						   IIO_BACKEND_NO_TEST_PATTERN);
-		if (ret)
-			return ret;
-
-		ret = iio_backend_data_format_set(st->back, c, &data);
+		ret = ad9467_backend_testmode_off(st, c);
 		if (ret)
 			return ret;
 

-- 
2.45.2



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

* [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
                   ` (6 preceding siblings ...)
  2024-08-02 14:27 ` [PATCH v2 7/8] iio: adc: ad9467: add backend test mode helpers Nuno Sa via B4 Relay
@ 2024-08-02 14:27 ` Nuno Sa via B4 Relay
  2024-08-03 13:38   ` Jonathan Cameron
  2024-08-03 13:39 ` [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Jonathan Cameron
  8 siblings, 1 reply; 12+ messages in thread
From: Nuno Sa via B4 Relay @ 2024-08-02 14:27 UTC (permalink / raw)
  To: linux-iio
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Olivier Moysan, Dragos Bogdan

From: Nuno Sa <nuno.sa@analog.com>

One useful thing to do (in case of problems) in this high speed devices
with digital interfaces is to try different test patterns to see if the
interface is working properly (and properly calibrated). Hence add this
to debugfs.

On top of this, for some test patterns, the backend may have a matching
validator block which can be helpful in identifying possible issues. For
the other patterns some test equipment must be used so one can look into
the signal and see how it looks like.

Hence, we also add the backend debugfs interface with
iio_backend_debugfs_add().

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/adc/ad9467.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 188 insertions(+)

diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index 2f4bbbd5611c..ce0bae94aa3a 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -15,6 +15,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
+#include <linux/seq_file.h>
 #include <linux/err.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
@@ -136,6 +137,8 @@ struct ad9467_chip_info {
 	unsigned int num_channels;
 	const unsigned int (*scale_table)[2];
 	int num_scales;
+	unsigned long test_mask;
+	unsigned int test_mask_len;
 	unsigned long max_rate;
 	unsigned int default_output_mode;
 	unsigned int vref_mask;
@@ -147,11 +150,19 @@ struct ad9467_chip_info {
 	bool has_dco_invert;
 };
 
+struct ad9467_chan_test_mode {
+	struct ad9467_state *st;
+	unsigned int idx;
+	u8 mode;
+};
+
 struct ad9467_state {
 	const struct ad9467_chip_info *info;
 	struct iio_backend *back;
 	struct spi_device *spi;
 	struct clk *clk;
+	/* used for debugfs */
+	struct ad9467_chan_test_mode *chan_test;
 	unsigned int output_mode;
 	unsigned int (*scales)[2];
 	/*
@@ -308,6 +319,23 @@ static const struct iio_chan_spec ad9652_channels[] = {
 	AD9467_CHAN(1, BIT(IIO_CHAN_INFO_SCALE), 1, 16, 's'),
 };
 
+static const char * const ad9467_test_modes[] = {
+	[AN877_ADC_TESTMODE_OFF] = "off",
+	[AN877_ADC_TESTMODE_MIDSCALE_SHORT] = "midscale_short",
+	[AN877_ADC_TESTMODE_POS_FULLSCALE] = "pos_fullscale",
+	[AN877_ADC_TESTMODE_NEG_FULLSCALE] = "neg_fullscale",
+	[AN877_ADC_TESTMODE_ALT_CHECKERBOARD] = "checkerboard",
+	[AN877_ADC_TESTMODE_PN23_SEQ] = "prbs23",
+	[AN877_ADC_TESTMODE_PN9_SEQ] = "prbs9",
+	[AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE] = "one_zero_toggle",
+	[AN877_ADC_TESTMODE_USER] = "user",
+	[AN877_ADC_TESTMODE_BIT_TOGGLE] = "bit_toggle",
+	[AN877_ADC_TESTMODE_SYNC] = "sync",
+	[AN877_ADC_TESTMODE_ONE_BIT_HIGH] = "one_bit_high",
+	[AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY] = "mixed_bit_frequency",
+	[AN877_ADC_TESTMODE_RAMP] = "ramp",
+};
+
 static const struct ad9467_chip_info ad9467_chip_tbl = {
 	.name = "ad9467",
 	.id = CHIPID_AD9467,
@@ -317,6 +345,9 @@ static const struct ad9467_chip_info ad9467_chip_tbl = {
 	.channels = ad9467_channels,
 	.num_channels = ARRAY_SIZE(ad9467_channels),
 	.test_points = AD9647_MAX_TEST_POINTS,
+	.test_mask = GENMASK(AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE,
+			     AN877_ADC_TESTMODE_OFF),
+	.test_mask_len = AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE + 1,
 	.default_output_mode = AD9467_DEF_OUTPUT_MODE,
 	.vref_mask = AD9467_REG_VREF_MASK,
 	.num_lanes = 8,
@@ -331,6 +362,8 @@ static const struct ad9467_chip_info ad9434_chip_tbl = {
 	.channels = ad9434_channels,
 	.num_channels = ARRAY_SIZE(ad9434_channels),
 	.test_points = AD9647_MAX_TEST_POINTS,
+	.test_mask = GENMASK(AN877_ADC_TESTMODE_USER, AN877_ADC_TESTMODE_OFF),
+	.test_mask_len = AN877_ADC_TESTMODE_USER + 1,
 	.default_output_mode = AD9434_DEF_OUTPUT_MODE,
 	.vref_mask = AD9434_REG_VREF_MASK,
 	.num_lanes = 6,
@@ -345,6 +378,9 @@ static const struct ad9467_chip_info ad9265_chip_tbl = {
 	.channels = ad9467_channels,
 	.num_channels = ARRAY_SIZE(ad9467_channels),
 	.test_points = AD9647_MAX_TEST_POINTS,
+	.test_mask = GENMASK(AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE,
+			     AN877_ADC_TESTMODE_OFF),
+	.test_mask_len = AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE + 1,
 	.default_output_mode = AD9265_DEF_OUTPUT_MODE,
 	.vref_mask = AD9265_REG_VREF_MASK,
 	.has_dco = true,
@@ -360,6 +396,9 @@ static const struct ad9467_chip_info ad9643_chip_tbl = {
 	.channels = ad9643_channels,
 	.num_channels = ARRAY_SIZE(ad9643_channels),
 	.test_points = AD9647_MAX_TEST_POINTS,
+	.test_mask = BIT(AN877_ADC_TESTMODE_RAMP) |
+		GENMASK(AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY, AN877_ADC_TESTMODE_OFF),
+	.test_mask_len = AN877_ADC_TESTMODE_RAMP + 1,
 	.vref_mask = AD9643_REG_VREF_MASK,
 	.has_dco = true,
 	.has_dco_invert = true,
@@ -375,6 +414,9 @@ static const struct ad9467_chip_info ad9649_chip_tbl = {
 	.channels = ad9649_channels,
 	.num_channels = ARRAY_SIZE(ad9649_channels),
 	.test_points = AD9649_TEST_POINTS,
+	.test_mask = GENMASK(AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY,
+			     AN877_ADC_TESTMODE_OFF),
+	.test_mask_len = AN877_ADC_TESTMODE_MIXED_BIT_FREQUENCY + 1,
 	.has_dco = true,
 	.has_dco_invert = true,
 	.dco_en = AN877_ADC_DCO_DELAY_ENABLE,
@@ -389,6 +431,9 @@ static const struct ad9467_chip_info ad9652_chip_tbl = {
 	.channels = ad9652_channels,
 	.num_channels = ARRAY_SIZE(ad9652_channels),
 	.test_points = AD9647_MAX_TEST_POINTS,
+	.test_mask = GENMASK(AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE,
+			     AN877_ADC_TESTMODE_OFF),
+	.test_mask_len = AN877_ADC_TESTMODE_ONE_ZERO_TOGGLE + 1,
 	.vref_mask = AD9652_REG_VREF_MASK,
 	.has_dco = true,
 };
@@ -933,6 +978,128 @@ static int ad9467_iio_backend_get(struct ad9467_state *st)
 	return -ENODEV;
 }
 
+static int ad9467_test_mode_available_show(struct seq_file *s, void *ignored)
+{
+	struct ad9467_state *st = s->private;
+	unsigned int bit;
+
+	for_each_set_bit(bit, &st->info->test_mask, st->info->test_mask_len)
+		seq_printf(s, "%s\n", ad9467_test_modes[bit]);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(ad9467_test_mode_available);
+
+static ssize_t ad9467_chan_test_mode_read(struct file *file,
+					  char __user *userbuf, size_t count,
+					  loff_t *ppos)
+{
+	struct ad9467_chan_test_mode *chan = file->private_data;
+	struct ad9467_state *st = chan->st;
+	char buf[128] = {0};
+	size_t len;
+	int ret;
+
+	if (chan->mode == AN877_ADC_TESTMODE_PN9_SEQ ||
+	    chan->mode == AN877_ADC_TESTMODE_PN23_SEQ) {
+		len = scnprintf(buf, sizeof(buf), "Running \"%s\" Test:\n\t",
+				ad9467_test_modes[chan->mode]);
+
+		ret = iio_backend_debugfs_print_chan_status(st->back, chan->idx,
+							    buf + len,
+							    sizeof(buf) - len);
+		if (ret < 0)
+			return ret;
+		len += ret;
+	} else if (chan->mode == AN877_ADC_TESTMODE_OFF) {
+		len = scnprintf(buf, sizeof(buf), "No test Running...\n");
+	} else {
+		len = scnprintf(buf, sizeof(buf), "Running \"%s\" Test on CH:%u\n",
+				ad9467_test_modes[chan->mode], chan->idx);
+	}
+
+	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
+}
+
+static ssize_t ad9467_chan_test_mode_write(struct file *file,
+					   const char __user *userbuf,
+					   size_t count, loff_t *ppos)
+{
+	struct ad9467_chan_test_mode *chan = file->private_data;
+	struct ad9467_state *st = chan->st;
+	char test_mode[32] = {0};
+	unsigned int mode;
+	int ret;
+
+	ret = simple_write_to_buffer(test_mode, sizeof(test_mode) - 1, ppos,
+				     userbuf, count);
+	if (ret < 0)
+		return ret;
+
+	for_each_set_bit(mode, &st->info->test_mask, st->info->test_mask_len) {
+		if (sysfs_streq(test_mode, ad9467_test_modes[mode]))
+			break;
+	}
+
+	if (mode == st->info->test_mask_len)
+		return -EINVAL;
+
+	guard(mutex)(&st->lock);
+
+	if (mode == AN877_ADC_TESTMODE_OFF) {
+		unsigned int out_mode;
+
+		if (chan->mode == AN877_ADC_TESTMODE_PN9_SEQ ||
+		    chan->mode == AN877_ADC_TESTMODE_PN23_SEQ) {
+			ret = ad9467_backend_testmode_off(st, chan->idx);
+			if (ret)
+				return ret;
+		}
+
+		ret = ad9467_testmode_set(st, chan->idx, mode);
+		if (ret)
+			return ret;
+
+		out_mode = st->info->default_output_mode | AN877_ADC_OUTPUT_MODE_TWOS_COMPLEMENT;
+		ret = ad9467_outputmode_set(st, out_mode);
+		if (ret)
+			return ret;
+	} else {
+		ret = ad9467_outputmode_set(st, st->info->default_output_mode);
+		if (ret)
+			return ret;
+
+		ret = ad9467_testmode_set(st, chan->idx, mode);
+		if (ret)
+			return ret;
+
+		/*  some patterns have a backend matching monitoring block */
+		if (mode == AN877_ADC_TESTMODE_PN9_SEQ) {
+			ret = ad9467_backend_testmode_on(st, chan->idx,
+							 IIO_BACKEND_ADI_PRBS_9A);
+			if (ret)
+				return ret;
+		} else if (mode == AN877_ADC_TESTMODE_PN23_SEQ) {
+			ret = ad9467_backend_testmode_on(st, chan->idx,
+							 IIO_BACKEND_ADI_PRBS_23A);
+			if (ret)
+				return ret;
+		}
+	}
+
+	chan->mode = mode;
+
+	return count;
+}
+
+static const struct file_operations ad9467_chan_test_mode_fops = {
+	.open = simple_open,
+	.read = ad9467_chan_test_mode_read,
+	.write = ad9467_chan_test_mode_write,
+	.llseek = default_llseek,
+	.owner = THIS_MODULE,
+};
+
 static ssize_t ad9467_dump_calib_table(struct file *file,
 				       char __user *userbuf,
 				       size_t count, loff_t *ppos)
@@ -971,12 +1138,33 @@ static void ad9467_debugfs_init(struct iio_dev *indio_dev)
 {
 	struct dentry *d = iio_get_debugfs_dentry(indio_dev);
 	struct ad9467_state *st = iio_priv(indio_dev);
+	char attr_name[32];
+	unsigned int chan;
 
 	if (!IS_ENABLED(CONFIG_DEBUG_FS))
 		return;
 
+	st->chan_test = devm_kcalloc(&st->spi->dev, st->info->num_channels,
+				     sizeof(*st->chan_test), GFP_KERNEL);
+	if (!st->chan_test)
+		return;
+
 	debugfs_create_file("calibration_table_dump", 0400, d, st,
 			    &ad9467_calib_table_fops);
+
+	for (chan = 0; chan < st->info->num_channels; chan++) {
+		snprintf(attr_name, sizeof(attr_name), "in_voltage%u_test_mode",
+			 chan);
+		st->chan_test[chan].idx = chan;
+		st->chan_test[chan].st = st;
+		debugfs_create_file(attr_name, 0600, d, &st->chan_test[chan],
+				    &ad9467_chan_test_mode_fops);
+	}
+
+	debugfs_create_file("in_voltage_test_mode_available", 0400, d, st,
+			    &ad9467_test_mode_available_fops);
+
+	iio_backend_debugfs_add(st->back, indio_dev);
 }
 
 static int ad9467_probe(struct spi_device *spi)

-- 
2.45.2



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

* Re: [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs
  2024-08-02 14:27 ` [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs Nuno Sa via B4 Relay
@ 2024-08-03 13:38   ` Jonathan Cameron
  2024-08-05  6:39     ` Nuno Sá
  0 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2024-08-03 13:38 UTC (permalink / raw)
  To: Nuno Sa via B4 Relay
  Cc: nuno.sa, linux-iio, Lars-Peter Clausen, Michael Hennerich,
	Olivier Moysan, Dragos Bogdan

On Fri, 02 Aug 2024 16:27:06 +0200
Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:

> From: Nuno Sa <nuno.sa@analog.com>
> 
> One useful thing to do (in case of problems) in this high speed devices
> with digital interfaces is to try different test patterns to see if the
> interface is working properly (and properly calibrated). Hence add this
> to debugfs.
> 
> On top of this, for some test patterns, the backend may have a matching
> validator block which can be helpful in identifying possible issues. For
> the other patterns some test equipment must be used so one can look into
> the signal and see how it looks like.
> 
> Hence, we also add the backend debugfs interface with
> iio_backend_debugfs_add().
> 
> Signed-off-by: Nuno Sa <nuno.sa@analog.com>
I'll apply the series, but I would like a docs update for the
debugfs files this patch adds.  That can be a follow up patch.

Jonathan

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

* Re: [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support
  2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
                   ` (7 preceding siblings ...)
  2024-08-02 14:27 ` [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs Nuno Sa via B4 Relay
@ 2024-08-03 13:39 ` Jonathan Cameron
  8 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2024-08-03 13:39 UTC (permalink / raw)
  To: Nuno Sa via B4 Relay
  Cc: nuno.sa, linux-iio, Lars-Peter Clausen, Michael Hennerich,
	Olivier Moysan, Dragos Bogdan

On Fri, 02 Aug 2024 16:26:58 +0200
Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:

> This is the second version of the series. I ended up trying the new
> directory route and think it does look nice and more future proof.
> Biggest change is the first patch where we now pass an info like
> structure to devm_iio_backend_register(). Again, this is likely also a more
> future proof approach and we would likely need it sooner or later (one
> usage I see is for backends to pass in some constant information that
> could be consumed from frontends when doing backend_get())  
> 
> v1:
>  * https://lore.kernel.org/linux-iio/20240709-dev-iio-backend-add-debugfs-v1-0-fb4b8f2373c7@analog.com/
> 
> v2:
>  * Patch 1:
>   - New patch;
> 
>  * Patch 2:
>   - Added backendY directory with the direct_reg_access and name
>     attributes;
>   - Get the backend name directly from the backend driver;
>   - Get the backend index from backend-names FW property;
>   - Added debugfs-iio-backend to the ABI docs. 
Should also have docs for the ad9467 specific debugfs files.

Please add those in a follow up patch.

Applied to the togreg branch of iio.git and pushed out as
testing for all the normal reasons.

Thanks,

Jonathan

> 
> ---
> Nuno Sa (8):
>       iio: backend: introduce struct iio_backend_info
>       iio: backend: add debugFs interface
>       iio: backend: add a modified prbs23 support
>       iio: adc: adi-axi-adc: support modified prbs23
>       iio: adc: adi-axi-adc: split axi_adc_chan_status()
>       iio: adc: adi-axi-adc: implement backend debugfs interface
>       iio: adc: ad9467: add backend test mode helpers
>       iio: adc: ad9467: add digital interface test to debugfs
> 
>  Documentation/ABI/testing/debugfs-iio-backend |  20 ++
>  MAINTAINERS                                   |   1 +
>  drivers/iio/adc/ad9467.c                      | 255 +++++++++++++++++++++++---
>  drivers/iio/adc/adi-axi-adc.c                 |  71 ++++++-
>  drivers/iio/dac/adi-axi-dac.c                 |   7 +-
>  drivers/iio/industrialio-backend.c            | 155 +++++++++++++++-
>  include/linux/iio/backend.h                   |  28 ++-
>  7 files changed, 499 insertions(+), 38 deletions(-)
> ---
> base-commit: 168bed989d651794d03638e1f7f7b5a800a6f425
> change-id: 20240802-dev-iio-backend-add-debugfs-0b13bb5a5b37
> --
> 
> Thanks!
> - Nuno Sá
> 
> 


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

* Re: [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs
  2024-08-03 13:38   ` Jonathan Cameron
@ 2024-08-05  6:39     ` Nuno Sá
  0 siblings, 0 replies; 12+ messages in thread
From: Nuno Sá @ 2024-08-05  6:39 UTC (permalink / raw)
  To: Jonathan Cameron, Nuno Sa via B4 Relay
  Cc: nuno.sa, linux-iio, Lars-Peter Clausen, Michael Hennerich,
	Olivier Moysan, Dragos Bogdan

On Sat, 2024-08-03 at 14:38 +0100, Jonathan Cameron wrote:
> On Fri, 02 Aug 2024 16:27:06 +0200
> Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:
> 
> > From: Nuno Sa <nuno.sa@analog.com>
> > 
> > One useful thing to do (in case of problems) in this high speed devices
> > with digital interfaces is to try different test patterns to see if the
> > interface is working properly (and properly calibrated). Hence add this
> > to debugfs.
> > 
> > On top of this, for some test patterns, the backend may have a matching
> > validator block which can be helpful in identifying possible issues. For
> > the other patterns some test equipment must be used so one can look into
> > the signal and see how it looks like.
> > 
> > Hence, we also add the backend debugfs interface with
> > iio_backend_debugfs_add().
> > 
> > Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> I'll apply the series, but I would like a docs update for the
> debugfs files this patch adds.  That can be a follow up patch.
> 
> Jonathan

will do

- Nuno Sá

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

end of thread, other threads:[~2024-08-05  6:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 14:26 [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Nuno Sa via B4 Relay
2024-08-02 14:26 ` [PATCH v2 1/8] iio: backend: introduce struct iio_backend_info Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 2/8] iio: backend: add debugFs interface Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 3/8] iio: backend: add a modified prbs23 support Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 4/8] iio: adc: adi-axi-adc: support modified prbs23 Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 5/8] iio: adc: adi-axi-adc: split axi_adc_chan_status() Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 6/8] iio: adc: adi-axi-adc: implement backend debugfs interface Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 7/8] iio: adc: ad9467: add backend test mode helpers Nuno Sa via B4 Relay
2024-08-02 14:27 ` [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs Nuno Sa via B4 Relay
2024-08-03 13:38   ` Jonathan Cameron
2024-08-05  6:39     ` Nuno Sá
2024-08-03 13:39 ` [PATCH v2 0/8] iio: adc: ad9467: add debugFS test mode support Jonathan Cameron

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