From patchwork Fri Aug 2 14:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751583 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5A00200101 for ; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=q5+OpdhdC42+wiInAsOJfeSLGkDc4jCDHZOSpmEO3xfXNc/wTHrWXuHSF1JVowyH4U+76zm6fefHXZ93SRPIb3KIsPM1lM/hJLZjLMJl4Wy6a+6KVQ8vO1fMlCw12TdaB8G5HQC5GAjeejPxub8uz5iFdwkmeBOcwzp/XAj7ZGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=hs7Izb2iLc9r5wbQ4KWVZkkGEkQM0G7T7G/q1XG+w+s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gwkGIH9i6zxdS6O+f3pXg2Rp7JjjQ48pb41DePRERgI99FYLJciNqkykkvxSpw2C9ErioojNj5Mz1KFJ2J9TczZIwv52J7zN7m8jTqAYdr34mD5K9lD6DsMOV64DrW64t/+qa/5BzygsZ9GkbZHTKeocRXISuF/dE+16SF1kO5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E9ndI65f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E9ndI65f" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8E969C4AF0A; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=hs7Izb2iLc9r5wbQ4KWVZkkGEkQM0G7T7G/q1XG+w+s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=E9ndI65ffmQxBb+qS9F4lp2BR9FLvRkyuRUImOytd0H4utiwQEgMJKBHbGbe7rEd1 96ENPNo9vviCBfIvK8TS4vGYRTdHTu4ABa1UCr6hcRvZD2mZnEW30Ss97/JHFFua0F wKkmHOSzj5xf0VYqMCR0QKXS3bZ+wASORupkr+uemsLD788YIfc8abDRPka6j2zf/p zrwfNhhPuvlZuHPkrc4w7eAZattSkCDd7S0F471gw4qaWgTemYtUfvrVQMaeTxj+EM VN1mGT/fLYykn3/y81Ko/yBHwf/zvgn1stc3k321d2kkh/GIJBlDXiKZIOfXftp4ro c2kUH0NOvQWRw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 786DCC3DA4A; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:26:59 +0200 Subject: [PATCH v2 1/8] iio: backend: introduce struct iio_backend_info Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-1-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=4840; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=ZXTwWK2rEEm8hHyS9XYhmR8ZiAipT7oHi6CInXjd0c4=; b=GaB0z2pomHke/mGWZXVUpzBZ1FvS+McBCHUj2RLTXqWSkgQYFjb7E7m1OheFmiqK6mzNgWBqX xHJL1VaQAxHABK2u2W4AslYqOUA0ju2xU5un/iF/LUUdI9V18ud5oyc X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa 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 --- 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 From patchwork Fri Aug 2 14:27:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751584 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5A57200102 for ; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=q9TlMBUIK4TLDqx/dHvmNRaDQCmPX2u1GMJz8aSFVqAqRHVKGIfmVVErBHKQphmxaCyGg4+E8bTQsuY2UuqrOgsdP7LRqcqZiUCYVNlK2wl+2qkI13IA28yypf5PtxOZaE1o68GP5OSF9Tr8DUCNWXHoXLjJIUwJxNkb4aS13lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=BZDlAk8Wm2QMWNQDVQ7q+eRUAvHFgtUzJMbUrkJJWKU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I7C9NEFDKWnFaDk3Il2NgULn+PZ9JHoWOPqqniSTbPyKN3T8/luHynvl3YiDIlMIhy7p0LJ6FigL4ODjmQHMVmNFA8w7MkNLYxl2V0sEh6Yq0CqKFuxEAhBzOrzNqnC0GoeAQykkhH5A8vXAULVXrC5ly+sD/M4D9yClyM5HoOg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DQRyTdO7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DQRyTdO7" Received: by smtp.kernel.org (Postfix) with ESMTPS id 964BEC4AF0E; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=BZDlAk8Wm2QMWNQDVQ7q+eRUAvHFgtUzJMbUrkJJWKU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=DQRyTdO7xpsd40pmVpTxuNAXECQ0c9ZC3AxTdw0W4qptQmhazyT5VHwK5o0hm0/e8 Y5khIx4DyingIPM5crC38vZXfdWV7CzSwGQ556O8DAso6MF/TAknPYguVrYrM06m9Z DBUoU+QD+CowLSxyaBEhE3Q2lFRUuJSXWA80l/FSNpYQtfaQzyG7TSU5SAp3PTVscs GMK+Zn1zhE20b6C1ZbqsI4yRppExAVFasHOLhg+N7OzPUpiG4uIi5nx/b+1Yr1kyKF GQIFLLiSKC2uSaucCrlkkViVg7FrlPPSu9j74UIYNyB3EFi53gaJsv14u6IWkqaFif UWc1Lt1uaBEsw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89182C52D71; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:00 +0200 Subject: [PATCH v2 2/8] iio: backend: add debugFs interface Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-2-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=8853; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=fD0/XWI5OHLEOk1nmWEr7V7mRvj+jbAaYeKyy5Sww+c=; b=vLRGTWjitG37eJYi9c+2gDsBmVjd/0XHr5QjvyzsqE0iieJE576PAlQz5wont+KMPvz7f38o2 jc7sI7P3VCgDxfd8lX3+y4M00lDKgHNlKTrIaCPlX3HGBFqfH+t/4U7 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa 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 --- 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 R: Olivier Moysan 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 +#include #include #include #include @@ -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 From patchwork Fri Aug 2 14:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751586 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 121EB1E4F0F for ; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=EeKEZ1Kb8kok+wpi9OyA/hSk7v6lM4Y/69pezAsP+aVKWvkC4eoa4TIp1Dk70cj+Lm5iHdSIl6EzTN9YBMHNJygv+9TIcCOWUn+8+ZCQM26jcGo4dnJ4cUIP4QCKdMkLzD+GsKvXmI0zIebinHSBlRrT5Gnx8PC6rNYZORIzB0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=RyYzrspXZNU3YFGMoHMNkUEhxHeSKfFZlMJQpJUvgoM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TcMnEhZv4X86t22zRYMjl2Pwq7D9nAGac/mYH/F2/Qa5kx9EDhBZl45gW7WoQiZ8gh2IjnDinf3aLzuFx5jYGz7ZwMSZQfhcKH4CurT2Pw/hnnVKrMZN93vVxSD6mLw95Kwh2uwG1ToCm+L6oIfvGrwzf2I1YwMnh9Uu2wbXQNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eA2x9nCN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eA2x9nCN" Received: by smtp.kernel.org (Postfix) with ESMTPS id A9BF6C4AF0F; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=RyYzrspXZNU3YFGMoHMNkUEhxHeSKfFZlMJQpJUvgoM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=eA2x9nCN5TkikJ3PbSCN7ZTHjiGGDJ+dbGRWJ8WHW2bKMvfWiePIldZzwcyzm6j81 8TfUggXA6Kmr5OlKyVyiS7WIYiyz5kLKx/BVVt0/hSPnmcVLkVz68ixBojptMqRpJs 5fEMzFgBNKLMgLBN0p8mz/lCjJzRTeK/4keT18hzgFRROPDblslazj3FJwOw07VHZT wdTqyjhw+GTdV4K0uF0nk7Mx2dtk21cwIxJgm9NWnukMzO1ayMGQU9z0LwL3tS6lyv EMXWY7BwnpRyPnVfaT1dQGzE/smdP+aX9p6bBxMd4uLH5M/FCmV08VoI6biV8saPPM 1HRbIZsvQMMwg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AD66C52D6F; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:01 +0200 Subject: [PATCH v2 3/8] iio: backend: add a modified prbs23 support Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-3-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=666; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=gmG6owXx7+vNZNRlhh8piqNGl0cPxLcyjp7ksNBda48=; b=dSYQG/EOsIvahMNnhWGicaCBOOKBYi/OPeFdnkclAAc6wHGRKDWS8bH2zsTOkHFc+WK7f5fVF xwGDz49zfk4DlXTlFalEl8CKl4DviIW9GnR9iq/HT8Ce9Bzk3LbAK2h X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa Support ADI specific prb23 sequence that can be used both for calibrating or debugging digital interfaces. Signed-off-by: Nuno Sa --- 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 }; From patchwork Fri Aug 2 14:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751585 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12248200104 for ; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=H2X+NfPrhCEEbNY/HWD4wugsXvrlwX/qPB9d772LyUDIN6ocNYLwczpj/jSONcK8Go2ub16nmsIssUHbtD3XPTNqVvnaPsMz3X5ZXQ8IXH10YnkZ1pFwsljb/t+cGe8DR8MzUVkyqJE7R0gpS3Lc5OVR5074PKM/qnT1G2WDhbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=SBfWwwEKEbxhEP03T+hS+zyaiCVkXdIESQqdbANX59E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TIjqeNIbi3n7GA0gkY0af9FMbBttSNvkU1hZgqzDpqfr67Sbc3wwYwglx2y6WE6jiBi1/JEblXHaPG9JymOHIQtL3jGEp80gXHVQ4F+v7ClsreflkSUr6OtkgTl9CXSKpVzwUReOdkbEIfY4+O6ahgE7XMFxNwnj/p/3ri6XyfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YpKIV+Nh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YpKIV+Nh" Received: by smtp.kernel.org (Postfix) with ESMTPS id B746CC4AF11; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=SBfWwwEKEbxhEP03T+hS+zyaiCVkXdIESQqdbANX59E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YpKIV+NhIibIM42KmIIR+Cye/zy+CySSfJbF+o/6GMQodafw1hzGf4ar4G0UDo2U/ XropLOeDVAa/foK4QvZajpQfdlj91ovUxniVTxFnNmZZskValZGXM+KC1Wbh5xScQp 8P1i2nEuHVzo4P7CXGCwNmV70Al3SG7hfHKmJjNKJgSkpRunFMD2K7vqVS4702TsWl qlXTfhElpfj6VCudY2I2VE9Di+aWyUjlq2loH34AgxL1Wod3R0H6draL1Ds7Z3tG+D 0q/S9aNQQa1mhy0OVdfjjnZdX8PKB/MtlIObMKTFoQiK6lvNiz01z6z2UYyBsZczqG LHsjLaoq8lAcA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAEDCC52D72; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:02 +0200 Subject: [PATCH v2 4/8] iio: adc: adi-axi-adc: support modified prbs23 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-4-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=882; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=EQ5g4pJjEx9y5MLKCN3xwUb/Fi6/zxslXRaMN+MVLzQ=; b=j0mb6dHbN5EOar75CK9yfPLWGQhPtPzcVEPFb+edAGwsr3a3LM0k3/a1/hr2/W4xiFy0bCIcA PI9ucU1pRjvBN9NHhZRiz0z2GGxUFJM1ZxUhlGbpicYoFpeCtou8JU3 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa Add support for configuring the prbs23 sequence. Signed-off-by: Nuno Sa --- 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; } From patchwork Fri Aug 2 14:27:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751587 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DD2B20010E for ; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=Rlr6wET/WqT9UcWynlsJFWTut5JtwzDjzLBDJTHr+2nEp9nDFo4OhVD/oqaB9g+12Ihuc5VKt8cixp0TdzI/Eu+KJ14i2slLIMJ0InX++wSA0cqIXjd1RmrDWjRmgnwBYa9sKJGxkyKXRKVksmtZr3sN1hcNQxi7N7XPAtZxPjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=M1MIaenDjeFqdFxVMPAcbmSJNMS6m1sWab9MRs5zFrs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t0sH5vz/D6+zVf1hKJPV8i7stBAyJG59FHuvH8uAMhd3V+d+ZsN82IalvuKgVPwGTqe8oEBnPNo5RCM2VIek0/5bKmBlDRxST0+OzKNF2eXbtdEspjFteg2qeJS+ET9P4CNf/oq8pvDShsaDbXZl1A6z/Va/ECVFO/rhIqmad+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W/9pe9qf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W/9pe9qf" Received: by smtp.kernel.org (Postfix) with ESMTPS id C31CFC4AF12; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=M1MIaenDjeFqdFxVMPAcbmSJNMS6m1sWab9MRs5zFrs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=W/9pe9qfUcYJ9TPqTgRYWgii/hP4zYqwVG9eb3DM/GrJlH83ybvuhHJ+wKRFI3Pkj G/Lr8NebJjS5FwPmmBJYlKUTi9vKVRSsiySFPqHdjoPn+z86tabZld1hDbHbcIJ/yI 7+Z6nHv77umo5HLiIvLr++u5WmA0dkopcFmeJQVdgK6ob+ZKG4sEVmegQUPfpelBHw VvJgd/Ht8UMaNpvDGEFzetja3RnMCged2JdWB9QRDgiH+FNFhrc0XB/to5f5voEdky MJnAY2aj+NoUPP3xvN6o7FmTZMDhaV+uQGbP4V3Z3H9/cBha+5IxNeqOaVKCCGE6ht 9bquHc/Y6MDxQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAAD3C3DA4A; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:03 +0200 Subject: [PATCH v2 5/8] iio: adc: adi-axi-adc: split axi_adc_chan_status() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-5-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=1692; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=V0ifC8BkhpqXxH/+MuvvxC8gC/RczC5y3WDjHB0pmiY=; b=APYikaO/jqUxR4xJ5wdlIuD5H7uWkbeMGiiXyFbxn4srU4q6/3cg7rHtyiiwTqeILeerAwpdP iZkTYxVOCEIA8RYIVWNhWBi3mEDaa10/qcuM7Ii21arDiZJRMLVSQE3 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa 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 --- 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; From patchwork Fri Aug 2 14:27:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751589 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DE3B200111 for ; Fri, 2 Aug 2024 14:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=h9ykZ1gDXtSm9/oGSrt0i/4Z21NAlFOREQd35JwmY1oQbmMHfkXXQXFF9jZwRAxg/JI8T4xD4rUujkfTB887TEHQ/5Pl3+9ahUHjOFvCrdjdqJ3pzIl2JxN/PKlBLSyhuv5lunRDp0fQ9SBHZN0D0I4qScMj2QuMZOr1HnU+aIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=J8ok26nfkL9lYlAtY5uSvNCwyF8TLIbcO37TZrbLh8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nA85wTVMQxDVtHbaW1Utd+Ki6oElrfFe+k0QGKtzSLClBsDzqTRnhbYS2Z+Us3IQnYtD5VW2sa8/l0xdOaw8W1PklpJGlFOJgPV4Th5lTYoEQsjwYzRr1PXrS43LTlhIjXAxmdu0oxTvA6RRzDE/0UQq6clucV4vYlJJvEVYrig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=INrLVJcl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="INrLVJcl" Received: by smtp.kernel.org (Postfix) with ESMTPS id D171BC4AF16; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=J8ok26nfkL9lYlAtY5uSvNCwyF8TLIbcO37TZrbLh8A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=INrLVJclT1vI1EnUyDWOGiuLXUIOePJ98eVsvL7IMefVe2KPyjmrTKROKPOac5smD xDZhCUBshz93R1rtsapN3z3WeeKdH93dkhcidKtcjpEfcbiQm3s1Dss3GRez56E2SV fxAiBtzAgEwEy5DbaStY+mjly6uAOKtpfaWhLGLDXYK1VI3bbDaKodXcDegQlNjki5 TfXeGZ03dl9FJolH7gjpbTZ0AKYxhQ5LMsJjnJoi6PKdfksbklHcwzCC5X3Bwf4Gx8 a5z6m7CP6rHz0H5fG/OmtEa4kfgxPR5H1FinN23iHsxgRgE2ptX7kP73xgVV0IJhog pTytsCzuT+8Gw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8D6EC52D71; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:04 +0200 Subject: [PATCH v2 6/8] iio: adc: adi-axi-adc: implement backend debugfs interface Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-6-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=2891; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=XHFm/DrRZn5PNuj0meI9AmjVqgEfxuUnbOTCPnlHqLs=; b=BOLMKKfjm8oM8fatrNj8iUyr9NjiaeMc6d7lU09nR+41/JNP95EMVIG1/9J/U6IZ/QOUGqO6b lrTT4nuHeOFAQezk82NJ32AOiQ9ZMXnxWvja8WCbQJ5p/Ln+XBdhFvG X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa 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 --- 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 = { From patchwork Fri Aug 2 14:27:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751588 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DD9C20010F for ; Fri, 2 Aug 2024 14:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=DKEjtybE3hMaa9sspADMBitX8bpZmnawpHUDs5T5pbDuAhcWFHqetlXWi+NOdXpN+qFkLVzGuYhAgaMnJCnf+tdoFnC9DHnIcOOK3VqZ11UhTOae+2EmJAUQSSWH4aLTmluXjhwceUmvTQQWxk88LTgzslaeBBwwBpiJv7i/GQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=LBGVtqXy2Dw2aOtRs7LqF/AJmS8OwjJgdy7HRFXLzAg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NnF+x6UlFZ+WLYE4gJdJXCl/fAOtD6+pE/gZ+Sn6X2OZe6v9iTNAhbnsZkuOT42xeC92H0+MUVfWLebOtJHu+P1ctIOiIcdiRR4HTGo218rLjJ2HvrGUfJkmvMpF4qMouMjHV0JRXbft2m5aA+5ZNudIo+Y+w0byL4m5TXSYUJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T3R87ali; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T3R87ali" Received: by smtp.kernel.org (Postfix) with ESMTPS id DC46DC4AF17; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608831; bh=LBGVtqXy2Dw2aOtRs7LqF/AJmS8OwjJgdy7HRFXLzAg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=T3R87alij5qkFhAnd5qtt1E3d9C4akqgbg1DXxMOLQnr1IZGUUqaAEBs+Djm5eJ7R 3JCrY5+EbzkIB1YJlDKJufillkDJZQXhJxVlbWxf75dQKwkqtBcQ2i96ItCBpwMLS9 FH5KbPrH9lOPuxidHT4RODdwVvAK2XRbOkv+Mzr3X11/kDV8MoH9o0hLWm9EPnhKMf bG5PPV/gHHbWN/yZ1j9OlR+2ta2RmFnHT+AB6lhz7NwbEo7L/j8bVPbJFewoMczodt VEaq8kQbpgMY5Cx5OjxKDOcqylSwbaWyuas/854WuuNYabdVylDCFyIVmRka+5F+ff 62fdxjCVPL5jA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D583EC52D6F; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:05 +0200 Subject: [PATCH v2 7/8] iio: adc: ad9467: add backend test mode helpers Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-7-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=3095; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=ORQVhXl18L7QpqOhlMxALCTW9W1adG0MCwa3NMU5bf8=; b=YbIh3Vv04Cv/TGptnpgRaT6I0SbpPmi8JNas51Sr2Ge2o56ND/+ux20I9lJ6+EgCYzA4u+f0u MAF7GhXrK3FA7gJG8aW2wMAeHDCy7k7+wgEUmKn3S6rEznZQmKFe+r5 X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa 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 --- 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; From patchwork Fri Aug 2 14:27:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa via B4 Relay X-Patchwork-Id: 13751590 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DDE6200110 for ; Fri, 2 Aug 2024 14:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; cv=none; b=DNA8RWeE3mMoXPFYcXiH2Us+j87MjGlTpAPy2bnkdL2MA/Z205X4Npt+MvLxCwoR2Yi/yO8+w5Rbil4jarF0Q/Ji+9fXbZeGKY30HZXUlm7hbTWNSpWrN+qMrCkCPPomYUjBP+rXwKjjjAQcSHE+cM9ziWQDaY1KGX8DqUbpWGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722608832; c=relaxed/simple; bh=ImbjH8tckq4jKS+ePXVSd7/obirTGvOQ9YPWj0pNfw0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pg7++Pda0EsbzZpMr4FU5ags8kXVho4CIFeywUeuMatZJG9OniZehTrWocgC10XWVrH/me8BDTA0d8V39BsgSkAAH4qWCO9/0uOA6KgHzjQlhfII/AFIUMMBy90X5//FRXt05QnsljJmD1X4TKYo8juTgqVJ4owc8A3EgHCcWTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m3eCVUWP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m3eCVUWP" Received: by smtp.kernel.org (Postfix) with ESMTPS id E92C5C4AF0B; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722608832; bh=ImbjH8tckq4jKS+ePXVSd7/obirTGvOQ9YPWj0pNfw0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=m3eCVUWP1y6xBP0bDQZnyE4uM80+jWzILDXUsh7X2rOlWoC8+WfSH/stV49bJGr8Y 0lLPUq5hAOoP9IySPs8F8RxNMV966b3uxTEfXSfDvHlAvHVHpH1T81c1q+m2ybM6i8 N0cWNsHe8Pg6yGiwBoiOcKzR/Zu0hbM0HHbr45c6q/9Dbc1lrFoPB+/834/gS7EPCF Fctvs0sIStWPsAA2MC8IHHRbDKr32rxBjDUkU6PAizacCd3VupQNHVrEQsRPdnFhOK Y98qmMaojAqkzOw3zDE5tJKkJRoEdnoH3QEf8PORuCiHpUy+tY0mz1wRqP9ISwAqAh FRE5zCrYWZnJg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1406C3DA4A; Fri, 2 Aug 2024 14:27:11 +0000 (UTC) From: Nuno Sa via B4 Relay Date: Fri, 02 Aug 2024 16:27:06 +0200 Subject: [PATCH v2 8/8] iio: adc: ad9467: add digital interface test to debugfs Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240802-dev-iio-backend-add-debugfs-v2-8-4cb62852f0d0@analog.com> References: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> In-Reply-To: <20240802-dev-iio-backend-add-debugfs-v2-0-4cb62852f0d0@analog.com> To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Olivier Moysan , Dragos Bogdan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722608829; l=10407; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=mIc8cdfVRPXmxVLFiNbyxGXSotI9LgS9R1xB3cY+/mw=; b=Y3qtXMeeJ+C0VrBK9ZCI8YtvWcj+1IRlTyPO3Tnc+56wmMmMXYlvlMxn6Jw9S6zSlgulUdjoL nyT4bAM5kJCBshUgSdlNlUReXQa2IsQo3v1QZ0VBqEonbR3juYeBqbz X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-Endpoint-Received: by B4 Relay for nuno.sa@analog.com/20231116 with auth_id=100 X-Original-From: Nuno Sa Reply-To: nuno.sa@analog.com From: Nuno Sa 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 --- 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 #include #include +#include #include #include #include @@ -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)