From: Jonas Rebmann <jre@pengutronix.de>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
Marc Kleine-Budde <mkl@pengutronix.de>,
kernel@pengutronix.de, Jonas Rebmann <jre@pengutronix.de>
Subject: [PATCH v7 07/13] spi: spidev_test: add compare mode
Date: Thu, 24 Sep 2026 15:43:57 +0200 [thread overview]
Message-ID: <20260924-spi-sun4i-spidev_test-v7-7-126e31a07fdc@pengutronix.de> (raw)
In-Reply-To: <20260924-spi-sun4i-spidev_test-v7-0-126e31a07fdc@pengutronix.de>
From: Marc Kleine-Budde <mkl@pengutronix.de>
Check whether the received data correspond to the transferred data but
without enabling loopback mode in the controller.
This is for testing with TX physically bridged to RX which is useful if
a loopback mode is unavailable or insufficient.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
tools/spi/spidev_test.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c
index e46eaef4d2ab..7b343803903e 100644
--- a/tools/spi/spidev_test.c
+++ b/tools/spi/spidev_test.c
@@ -44,6 +44,7 @@ static int verbose;
static int transfer_size = -1;
static int iterations;
static int interval = 5; /* interval in seconds for showing transfer rate */
+static int compare;
static int random_input;
static int input_choices;
@@ -174,7 +175,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
if (verbose)
hex_dump(rx, len, 32, "RX");
- if (mode & SPI_LOOP) {
+ if (compare || mode & SPI_LOOP) {
if (memcmp(tx, rx, len)) {
fprintf(stderr, "transfer error !\n");
hex_dump(tx, len, 32, "TX");
@@ -186,13 +187,14 @@ static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t len)
static void print_usage(const char *prog)
{
- printf("Usage: %s [-2348CDFHILMNORSZbdilopsvw]\n", prog);
+ printf("Usage: %s [-2348CDFHILMNORSZbcdilopsvw]\n", prog);
puts("general device settings:\n"
" -D --device device to use (default /dev/spidev1.1)\n"
" -s --speed max speed (Hz)\n"
" -d --delay delay (usec)\n"
" -w --word-delay word delay (usec)\n"
" -l --loop loopback\n"
+ " -c --compare compare RX'ed and TX'ed data\n"
"spi mode:\n"
" -H --cpha clock phase\n"
" -O --cpol clock polarity\n"
@@ -230,6 +232,7 @@ static void parse_opts(int argc, char *argv[])
{ "delay", 1, 0, 'd' },
{ "word-delay", 1, 0, 'w' },
{ "loop", 0, 0, 'l' },
+ { "compare", 0, 0, 'c' },
{ "cpha", 0, 0, 'H' },
{ "cpol", 0, 0, 'O' },
{ "rx-cpha-flip", 0, 0, 'F' },
@@ -253,7 +256,7 @@ static void parse_opts(int argc, char *argv[])
};
int c;
- c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lHOLC3ZFMNR248p:vS:I:",
+ c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lcHOLC3ZFMNR248p:vS:I:",
lopts, NULL);
if (c == -1)
@@ -285,6 +288,9 @@ static void parse_opts(int argc, char *argv[])
case 'l':
mode |= SPI_LOOP;
break;
+ case 'c':
+ compare = 1;
+ break;
case 'H':
mode |= SPI_CPHA;
break;
@@ -466,6 +472,9 @@ int main(int argc, char *argv[])
if (iterations && transfer_size < 0)
pabort("-I (--iter) is only implemented for -S (--size)");
+ if (compare && mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL))
+ pabort("-c (--compare) conflicts with -2 (--dual), -4 (--quad) or -8 (--octal)");
+
fd = open(device, O_RDWR);
if (fd < 0)
pabort("can't open device");
--
2.56.0.rc0.108.gf0ef1b96a0
next prev parent reply other threads:[~2026-09-24 13:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 13:43 [PATCH v7 00/13] spi: spidev_test: new features Jonas Rebmann
2026-09-24 13:43 ` [PATCH v7 01/13] spi: spidev_test: include tools/include Jonas Rebmann
2026-09-24 13:43 ` [PATCH v7 02/13] spi: spidev_test: clarify usage for --size Jonas Rebmann
2026-09-24 13:43 ` [PATCH v7 03/13] spi: spidev_test: make size argument mandatory " Jonas Rebmann
2026-09-24 13:43 ` [PATCH v7 04/13] spi: spidev_test: allow zero-length transfers Jonas Rebmann
2026-09-24 13:43 ` [PATCH v7 05/13] spi: spidev_test: abort when -I is selected without -S Jonas Rebmann
2026-09-24 13:43 ` [PATCH v7 06/13] spi: spidev_test: always compare loopback data Jonas Rebmann
2026-09-24 13:43 ` Jonas Rebmann [this message]
2026-09-24 13:43 ` [PATCH v7 08/13] spi: spidev_test: allow disabling rx or tx buffers Jonas Rebmann
2026-09-24 20:54 ` Mark Brown
2026-09-25 7:12 ` [PATCH] spi: spidev_test: don't mix up rx_rate and tx_rate Jonas Rebmann
2026-09-25 10:24 ` Mark Brown
2026-09-24 13:43 ` [PATCH v7 09/13] spi: spidev_test: don't send 0x0 or 0xff Jonas Rebmann
2026-09-24 13:44 ` [PATCH v7 10/13] spi: spidev_test: send predictable data Jonas Rebmann
2026-09-24 13:44 ` [PATCH v7 11/13] spi: spidev_test: add option to split message into multiple transfers Jonas Rebmann
2026-09-24 13:44 ` [PATCH v7 12/13] spi: spidev_test: print TX on error Jonas Rebmann
2026-09-24 13:44 ` [PATCH v7 13/13] spi: spidev_test: rewrite unescape() to stay in bounds Jonas Rebmann
2026-09-24 20:48 ` [PATCH v7 00/13] spi: spidev_test: new features Mark Brown
2026-09-24 21:00 ` Mark Brown
2026-09-25 10:51 ` Jonas Rebmann
2026-09-25 12:07 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924-spi-sun4i-spidev_test-v7-7-126e31a07fdc@pengutronix.de \
--to=jre@pengutronix.de \
--cc=broonie@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mkl@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®