From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 1C09D313527; Mon, 14 Sep 2026 14:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397467; cv=none; b=WBUmpBe7Zb+/yCe8W9Re5mwM2VZM70Rod0fRIiWjerq7WxQDvvaBqRTTMu0JdIposqdTfnqTVUwV610BIKYohbptlWAobLC4TVCT9yRYT24qEVkC/6bd0BSOu0f/MEQr8Kk+bv7WIFCgH0nwFsFHUmKgAIEu5Vraa6iXitamYnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397467; c=relaxed/simple; bh=NbckwX7zZ+alKdLrtZjAJKzx5Uho4BdrmxJofWgW97k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ip1aYwPWlD4ERq60IiN4aMBSbMcQJWd8T6Ip8K1GfqIXZBFcIRaCy7LpfDXSdQToiOUKBRvaqA+58LLDK3ILp0b0UyNghJ1sZf2Mjilms+Vi3bvVM/vG95RGT0IVIy9kTr8GugZDlpmnCDAEMp5UNzeqUCcQwh5Hvw74B4Zi9X4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 1850E2009B9; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681G-000v8b-3A; Mon, 14 Sep 2026 16:50:54 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:40 +0200 Subject: [PATCH 1/7] spi: spidev_test: include tools/include Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-1-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1262; i=jre@pengutronix.de; h=from:subject:message-id; bh=NbckwX7zZ+alKdLrtZjAJKzx5Uho4BdrmxJofWgW97k=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXlaZcpsz4WMh6dOOfU8de3vE0Hfb6ieNbb86Fm03 vAPR1eoRUcpC4MYF4OsmCJLrJqcgpCx/3WzSrtYmDmsTCBDGLg4BeAizIwM90KMNwmrcrsvqbB/ 4ml94Keiynelff8eOS1tmO95jMfzLMM/jYnrL/N8OpMk9M/dykdQNnZr8bopZg5cG41n7dPIWm/ KAgA= X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 Add tools/include to include paths to allow using macro helpers. Use ARRAY_SIZE() from tools/include/linux/kernel.h instead of maintaining a copy. Signed-off-by: Jonas Rebmann --- tools/spi/Makefile | 2 +- tools/spi/spidev_test.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/spi/Makefile b/tools/spi/Makefile index 7fccd245a535..8cf21ff8cd03 100644 --- a/tools/spi/Makefile +++ b/tools/spi/Makefile @@ -12,7 +12,7 @@ endif # (this improves performance and avoids hard-to-debug behaviour); MAKEFLAGS +=3D -r =20 -CFLAGS +=3D -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include +CFLAGS +=3D -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include -I$(srctree)/too= ls/include =20 ALL_TARGETS :=3D spidev_test spidev_fdx ALL_PROGRAMS :=3D $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index f2135d619a0b..8058a7830b50 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -22,8 +22,7 @@ #include #include #include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#include =20 static void pabort(const char *s) { --=20 2.55.0.806.gb8242b093d From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 0EEF7481255; Mon, 14 Sep 2026 14:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397466; cv=none; b=QwBoRTHdb7K4lO8JMcJZtV+IDcnb53zNARW7c/9MmfvBucah4e9A3iCcJy9OZfsd33OYBS2DkwixIYUWpDWgcRoOKojxbRhcHZDw67PQpTPnQvs3bvc94SRpmYJEhwjunrLxDeRrLpSU7QsEeixMAVsR8GAVFMkt7bjOmK7Av4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397466; c=relaxed/simple; bh=O2mIRbzfyydoVcq6ZD+4eXn2XyRdMD7JsGA2cqw1IW0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D0G6CVS6tYpmWL+/3SO7YrWs2HNtgIH65lfJqC9RH/hQVnRQKMJV14fRfK2AVrwY0ACsnwvWivOi25xPzszYRlN2aS0f+qfND1TjPVQSi0+eP6udyZCfzANinSrL5gDlY3vUMMKrnJm+YRuY7gbdWo2nZNafW+z+Bl7/tKbanYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 24D2F20288B; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681H-000v8b-06; Mon, 14 Sep 2026 16:50:55 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:41 +0200 Subject: [PATCH 2/7] spi: spidev_test: add compare mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-2-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2749; i=jre@pengutronix.de; h=from:subject:message-id; bh=bDTMwUdBsSo0f0ru/t7hZY2vv3h+kAW8HmZqE7fjn+M=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXnGs1qKK+HhqZkPlPd8aJ0ZzDtX4WnrWXXFw/WZz kF9fzUkO0pZGMS4GGTFFFli1eQUhIz9r5tV2sXCzGFlAhnCwMUpABMp3cnwP9Vr47nVudfqpKab TTe7+/Q9a4nQ+Z1uMpOYJLcwKmZW3Gf4H7dlt8Bi9+03/TXvGFyJu6/FdfDqmV/X1Z+Jslgfu1A uyw0A X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde 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 Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 8058a7830b50..05c585ea71b2 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -46,6 +46,7 @@ static int verbose; static int transfer_size; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ +static int compare; =20 static uint8_t default_tx[] =3D { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -173,13 +174,14 @@ static void transfer(int fd, uint8_t const *tx, uint8= _t const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbdilopsvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbdilcopsvw]\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" @@ -217,6 +219,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' }, @@ -240,7 +243,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lHOLC3ZFMNR248p:vS:I:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lcHOLC3ZFMNR248p:vS:I:", lopts, NULL); =20 if (c =3D=3D -1) @@ -270,6 +273,10 @@ static void parse_opts(int argc, char *argv[]) break; case 'l': mode |=3D SPI_LOOP; + compare =3D 1; + break; + case 'c': + compare =3D 1; break; case 'H': mode |=3D SPI_CPHA; @@ -427,7 +434,7 @@ static void transfer_buf(int fd, int len) _write_count +=3D len; _read_count +=3D len; =20 - if (mode & SPI_LOOP) { + if (compare) { if (memcmp(tx, rx, len)) { fprintf(stderr, "transfer error !\n"); hex_dump(tx, len, 32, "TX"); --=20 2.55.0.806.gb8242b093d From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 0AE484749CA; Mon, 14 Sep 2026 14:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397465; cv=none; b=WdeF5PZTBZiV1njy/05GNuOeMU5eyRPUBV2lHXPNLA6Fy8nfjPbiqoiC9kTmTWGP8YUxR/U7hlC1hY5wUcTDccWgPz8zZY5f3NIWf/Jv4zIAekEQnTsW+W6XqpTjluiwfLlFyc0ZB5ynLWRx8UvsUYrHtDdFnl2V7K4IXn7fqmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397465; c=relaxed/simple; bh=xzOM3ZG6BBdAVvei+7OCZ7A1aQ+fKf85l8a8QbuoTAs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rYIKMO1YI+MSvGw5gSgfWH5dhwpald0NxRcKznhGK0QXOfo0CcLaRKclph87CnJjrgshRpE4W0GoHLT1CZFNDiiAZgCXM1JinRh0y71itbuXgeV/BsyxhElxP53UqSIJVrMgksQSxuHgAR5kD3VGqEK+usdwgACADpFkGHwm6Ak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 25BC720288C; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681H-000v8b-0E; Mon, 14 Sep 2026 16:50:55 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:42 +0200 Subject: [PATCH 3/7] spi: spidev_test: allow disabling rx or tx buffers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-3-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4566; i=jre@pengutronix.de; h=from:subject:message-id; bh=IxSynNpkgLnYZ2HICPr4FpfrFG088jeXVjhYis3uIdY=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXlmDlPVS66C9nf+bn//r4naeYtnZkfAmZw1Vq2Cj S21CQvmd5SyMIhxMciKKbLEqskpCBn7XzertIuFmcPKBDKEgYtTACby9wojwzq35jPqb/rfL+vK e2G2fePd9IzpDatzGJ4cEOs2kNU+94WR4U9r990TvulPqqPidsyt87/A9DzM4MjhuJxF5fKhUzh vcgMA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Allow not providing rx or tx buffers. This is useful to check if drivers that don't use SPI_CONTROLLER_MUST_RX (or -TX respectively) handle their operations correctly without a buffer. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 61 ++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 05c585ea71b2..6b0e839e6c33 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -47,6 +47,7 @@ static int transfer_size; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ static int compare; +static int do_tx =3D 1, do_rx =3D 1; =20 static uint8_t default_tx[] =3D { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -153,10 +154,10 @@ static void transfer(int fd, uint8_t const *tx, uint8= _t const *rx, size_t len) if (ret < 1) pabort("can't send spi message"); =20 - if (verbose) + if (verbose && tx) hex_dump(tx, len, 32, "TX"); =20 - if (output_file) { + if (rx && output_file) { out_fd =3D open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (out_fd < 0) pabort("could not open output file"); @@ -168,13 +169,13 @@ static void transfer(int fd, uint8_t const *tx, uint8= _t const *rx, size_t len) close(out_fd); } =20 - if (verbose) + if (verbose && rx) hex_dump(rx, len, 32, "RX"); } =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbdilcopsvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvw]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -182,6 +183,8 @@ static void print_usage(const char *prog) " -w --word-delay word delay (usec)\n" " -l --loop loopback\n" " -c --compare compare RX'ed and TX'ed data\n" + " -t --no-tx don't send data\n" + " -r --no-rx don't receive data\n" "spi mode:\n" " -H --cpha clock phase\n" " -O --cpol clock polarity\n" @@ -220,6 +223,8 @@ static void parse_opts(int argc, char *argv[]) { "word-delay", 1, 0, 'w' }, { "loop", 0, 0, 'l' }, { "compare", 0, 0, 'c' }, + { "no-tx", 0, 0, 't' }, + { "no-rx", 0, 0, 'r' }, { "cpha", 0, 0, 'H' }, { "cpol", 0, 0, 'O' }, { "rx-cpha-flip", 0, 0, 'F' }, @@ -243,7 +248,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lcHOLC3ZFMNR248p:vS:I:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:I:", lopts, NULL); =20 if (c =3D=3D -1) @@ -278,6 +283,12 @@ static void parse_opts(int argc, char *argv[]) case 'c': compare =3D 1; break; + case 't': + do_tx =3D 0; + break; + case 'r': + do_rx =3D 0; + break; case 'H': mode |=3D SPI_CPHA; break; @@ -415,26 +426,31 @@ static void show_transfer_rate(void) =20 static void transfer_buf(int fd, int len) { - uint8_t *tx; - uint8_t *rx; + uint8_t *tx =3D NULL; + uint8_t *rx =3D NULL; int i; =20 - tx =3D malloc(len); - if (!tx) - pabort("can't allocate tx buffer"); - for (i =3D 0; i < len; i++) - tx[i] =3D random(); + if (do_tx) { + tx =3D malloc(len); + if (!tx) + pabort("can't allocate tx buffer"); + for (i =3D 0; i < len; i++) + tx[i] =3D random(); + } =20 - rx =3D malloc(len); - if (!rx) - pabort("can't allocate rx buffer"); + if (do_rx) { + rx =3D malloc(len); + if (!rx) + pabort("can't allocate rx buffer"); + } =20 transfer(fd, tx, rx, len); + if (do_tx) + _write_count +=3D len; + if (do_rx) + _read_count +=3D len; =20 - _write_count +=3D len; - _read_count +=3D len; - - if (compare) { + if (tx && rx && compare) { if (memcmp(tx, rx, len)) { fprintf(stderr, "transfer error !\n"); hex_dump(tx, len, 32, "TX"); @@ -455,8 +471,11 @@ int main(int argc, char *argv[]) =20 parse_opts(argc, argv); =20 - if (input_tx && input_file) - pabort("only one of -p and --input may be selected"); + if (!!input_tx + !!input_file + !do_tx > 0) + pabort("only one of -p, -i (--input), -t (--no-tx) may be selected"); + + if (compare && (!do_tx || !do_rx)) + pabort("-l/-c conflict with -t or -r"); =20 fd =3D open(device, O_RDWR); if (fd < 0) --=20 2.55.0.806.gb8242b093d From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 EC2F53DB322; Mon, 14 Sep 2026 14:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397466; cv=none; b=nm166heCr68mAbajWobv4LrsKvNtZ/98pYYKAPrmsDhIqNmN05QKOi2dcUS+c33FwRQ4Y+AAjmmL5QDFT0Ft/rxxSNzw0a0eGv52F47tcHlW923QrO0T+IaFHfO7eQ9yqvWfTTIb6kt2AvHtDIPnAx0UBc9dtU6ywI6t/yTM7PI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397466; c=relaxed/simple; bh=pLGzksEYxAMowkLCkYjKre8q9DTVGCylcDcx6ArTnDo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qnd/fc2hp6b/gLbdVfkdpEQKFEFZNLjQ6beAmM5dka4/7LPR0d+Pp6cdhaUPKz37ojvNWyFYIF0hfRZ4MrWJ+BnHtguHYCyL6uLkCa75J0ttP3XaemPhfYRSZKfpty4w6HsRv/FXn9TtQrC0ZgTSmZTB4G9yD7dOggK2EPBcYdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 330A2202891; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681H-000v8b-0M; Mon, 14 Sep 2026 16:50:55 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:43 +0200 Subject: [PATCH 4/7] spi: spidev_test: don't send 0x0 or 0xff Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-4-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3470; i=jre@pengutronix.de; h=from:subject:message-id; bh=Mw7mDN17u8DrdK4YWIBU+Wo0Q9q/V1Teq2WQR79/RDk=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXn25tX32z9e2ftiD9dsv818OT90V5QpXF9+X/Tp1 B3ukhwv53SUsjCIcTHIiimyxKrJKQgZ+183q7SLhZnDygQyhIGLUwAm8u86w/+Yo7KXA5NOl74K v/iF/di7w+8TeJJfJAfcke766clzIEaIkeHp132K3C3LZEqmBaYdUPJ2Pj7xnYFp+BuVbydWy02 4cpsdAA== X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Particularly when using compare mode, if the controller fails to transfer any data, asserting on a read of 0x00 or 0xff may lead a false negative test, indicating a byte was successfully transferred when the values simply originate from the pull-up or pull-down of RX. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 6b0e839e6c33..235b267c02f2 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -47,6 +47,7 @@ static int transfer_size; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ static int compare; +static int nonzero; static int do_tx =3D 1, do_rx =3D 1; =20 static uint8_t default_tx[] =3D { @@ -175,7 +176,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvw]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvwz]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -199,6 +200,7 @@ static void print_usage(const char *prog) " -i --input input data from a file (e.g. \"test.bin\")\n" " -o --output output data to a file (e.g. \"results.bin\")\n" " -p Send data (e.g. \"1234\\xde\\xad\")\n" + " -z --nonzero Don't send 0x00 or 0xff bytes\n" " -S --size transfer size\n" " -I --iter iterations\n" "additional parameters:\n" @@ -236,6 +238,7 @@ static void parse_opts(int argc, char *argv[]) { "input", 1, 0, 'i' }, { "output", 1, 0, 'o' }, { "size", 1, 0, 'S' }, + { "nonzero", 0, 0, 'z' }, { "iter", 1, 0, 'I' }, { "bpw", 1, 0, 'b' }, { "lsb", 0, 0, 'L' }, @@ -248,7 +251,7 @@ static void parse_opts(int argc, char *argv[]) }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:I:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:", lopts, NULL); =20 if (c =3D=3D -1) @@ -337,6 +340,9 @@ static void parse_opts(int argc, char *argv[]) case 'S': transfer_size =3D atoi(optarg); break; + case 'z': + nonzero =3D 1; + break; case 'I': iterations =3D atoi(optarg); break; @@ -434,8 +440,11 @@ static void transfer_buf(int fd, int len) tx =3D malloc(len); if (!tx) pabort("can't allocate tx buffer"); - for (i =3D 0; i < len; i++) - tx[i] =3D random(); + for (i =3D 0; i < len; i++) { + do + tx[i] =3D random(); + while (nonzero && (tx[i] =3D=3D 0x0 || tx[i] =3D=3D 0xff)); + } } =20 if (do_rx) { @@ -471,8 +480,8 @@ int main(int argc, char *argv[]) =20 parse_opts(argc, argv); =20 - if (!!input_tx + !!input_file + !do_tx > 0) - pabort("only one of -p, -i (--input), -t (--no-tx) may be selected"); + if (!!input_tx + !!input_file + !do_tx + !!nonzero > 1) + pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero) may b= e selected"); =20 if (compare && (!do_tx || !do_rx)) pabort("-l/-c conflict with -t or -r"); --=20 2.55.0.806.gb8242b093d From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 2E2A34825BF; Mon, 14 Sep 2026 14:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397478; cv=none; b=fbZEBUBln6A6BQmJ0O2Vjg14krf1YVVuYyh4j79bp8vVYWPpdd+pftLw+5a/LmcOaP2y17JBpBram2VzsZwU54y2ACr/HsFhGk85Tn0iAga+G0Ry0tG5nbTL3CEu5txqlmfNOQ6MOcuHKqbaAnQl8gl7wzuOzFz6bSuUA3hvbvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397478; c=relaxed/simple; bh=btyTcGPaP8SY8f7pIEybVB2fgyhjoMTv2WLbDP5WQiI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dtNhnk4r0AaVxH1edXSGFqN0VLGfscSBheeJoxbmT9301QelTEI6pqT3rTFRTBMiTBsio6I2SdSE5AaXXfWZEda6u0HKLOa8SaLU3SJJeZtjb03D1xMeo8um2DUzbLMmP5Qak78Kh5VcNAZgJh9+V+WHyyHfXEtM7eBIdkxj01E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 40993202892; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681H-000v8b-0X; Mon, 14 Sep 2026 16:50:55 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:44 +0200 Subject: [PATCH 5/7] spi: spidev_test: send predictable data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-5-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3393; i=jre@pengutronix.de; h=from:subject:message-id; bh=hyW09/s5603f18FDZkFHpbL0CwnQrbEs+ELS75Vgv7s=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXl2e0pz0895RlPOHY2aqek7d3Pion+f3ub9anLzT Iq+YBR0tqOUhUGMi0FWTJElVk1OQcjY/7pZpV0szBxWJpAhDFycAjCRL58YfrNN60rYlrBf7eO/ RFOJH+8PZTRc/ClZkBYzw+QQq8m0a6oM/5QbQgN6d23JfsGcKbqs7IRmVpaEwpdl/tsvXMx90Xg /lhMA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde Introduce a flag to test on a predictable byte sequence instead of random bytes. This is useful when comparing multiple runs e.g. with an oscilloscope. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 235b267c02f2..4d35ac0d9a48 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -49,6 +49,7 @@ static int interval =3D 5; /* interval in seconds for sho= wing transfer rate */ static int compare; static int nonzero; static int do_tx =3D 1, do_rx =3D 1; +static int predictable; =20 static uint8_t default_tx[] =3D { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -176,7 +177,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvwz]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvwzP]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -201,6 +202,7 @@ static void print_usage(const char *prog) " -o --output output data to a file (e.g. \"results.bin\")\n" " -p Send data (e.g. \"1234\\xde\\xad\")\n" " -z --nonzero Don't send 0x00 or 0xff bytes\n" + " -P --predictable Send a predictable sequence instead of random nu= mbers\n" " -S --size transfer size\n" " -I --iter iterations\n" "additional parameters:\n" @@ -246,12 +248,13 @@ static void parse_opts(int argc, char *argv[]) { "no-cs", 0, 0, 'N' }, { "ready", 0, 0, 'R' }, { "mosi-idle-low", 0, 0, 'M' }, + { "predictable", 0, 0, 'P' }, { "verbose", 0, 0, 'v' }, { NULL, 0, 0, 0 }, }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:vS:zI:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PvS:zI:", lopts, NULL); =20 if (c =3D=3D -1) @@ -328,6 +331,9 @@ static void parse_opts(int argc, char *argv[]) case 'p': input_tx =3D optarg; break; + case 'P': + predictable =3D 1; + break; case '2': mode |=3D SPI_TX_DUAL; break; @@ -441,9 +447,13 @@ static void transfer_buf(int fd, int len) if (!tx) pabort("can't allocate tx buffer"); for (i =3D 0; i < len; i++) { - do - tx[i] =3D random(); - while (nonzero && (tx[i] =3D=3D 0x0 || tx[i] =3D=3D 0xff)); + if (predictable) { + tx[i] =3D i - iterations; + } else { + do + tx[i] =3D random(); + while (nonzero && (tx[i] =3D=3D 0x0 || tx[i] =3D=3D 0xff)); + } } } =20 @@ -480,8 +490,8 @@ int main(int argc, char *argv[]) =20 parse_opts(argc, argv); =20 - if (!!input_tx + !!input_file + !do_tx + !!nonzero > 1) - pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero) may b= e selected"); + if (!!input_tx + !!input_file + !do_tx + !!nonzero + !!predictable > 1) + pabort("only one of -p, -i (--input), -t (--no-tx), -z (--nonzero), -P (= --predictable) may be selected"); =20 if (compare && (!do_tx || !do_rx)) pabort("-l/-c conflict with -t or -r"); --=20 2.55.0.806.gb8242b093d From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 8BE1547A86D; Mon, 14 Sep 2026 14:51:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397477; cv=none; b=K9d5K9VSKSa1bbm9xubXRYpAYj1EkYPwGbFjgxIH30kaH+yuAZZfOHGg0gUxJupL03n7V2y+X/IfkqUTb1p5+9cEleZ7lvMbdooXDLW2Vb3yfvcwxKDPW2fRRH3DObR2azw9In9eV1U6sukImgHvB/GGbeOELEMipNUmJnCB2bE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397477; c=relaxed/simple; bh=l3avz/FqlB79E9kXobJeIMzG6Fvuv1Qeruk6A75D/Ew=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eaw1Duam1DK6tdWKCBnMEKc2sGvCWD5Ytt98gECsIQY+pPrHFlWAGlLccN0l1NoezIuBn4dSA4zn3pAAPyJgcH9nHLNCvWpI2jQakLh+cQCQKvDbNorSVxySTD+7gBxDCq/Ki5IxGqzS4PL4ssdR+PBk0/x0cx5SHSEoXB9pHlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 4AFAE202898; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681H-000v8b-0h; Mon, 14 Sep 2026 16:50:55 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:45 +0200 Subject: [PATCH 6/7] spi: spidev_test: add option to split message into multiple transfers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-6-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5458; i=jre@pengutronix.de; h=from:subject:message-id; bh=cNqtmNrTU9HVG2vg2OJLDqD4ZJlwmlN4/O2gig/M2pA=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXl2J98j812BL+PNgtcZPnSLPLo+769/wR+9jQsyH b/Nay7V7ShlYRDjYpAVU2SJVZNTEDL2v25WaRcLM4eVCWQIAxenAExEcC0jQ4urjdBOZ77dd9nl hObOXaTnvUfBMthxsXHrwZXff7zsnMHwv+yzeL1GyV8X8zlyNbOWnnT+yyjhu3Bn8b77kic3hbL z8gEA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde SPI_IOC_MESSAGE() submits a single SPI message containing one or more transfers. Introduce an option to allow splitting the message into multiple transfers. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 92 ++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 4d35ac0d9a48..a07c05f2d8b8 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 static void pabort(const char *s) { @@ -44,6 +45,7 @@ static uint16_t delay; static uint16_t word_delay; static int verbose; static int transfer_size; +static int transfers =3D 1; static int iterations; static int interval =3D 5; /* interval in seconds for showing transfer rat= e */ static int compare; @@ -119,40 +121,60 @@ static int unescape(char *_dst, char *_src, size_t le= n) return ret; } =20 -static void transfer(int fd, uint8_t const *tx, uint8_t const *rx, size_t = len) +static void transfer(int fd, uint8_t const * const tx, uint8_t const * con= st rx, size_t len) { int ret; int out_fd; - struct spi_ioc_transfer tr =3D { - .tx_buf =3D (unsigned long)tx, - .rx_buf =3D (unsigned long)rx, - .len =3D len, - .delay_usecs =3D delay, - .word_delay_usecs =3D word_delay, - .speed_hz =3D speed, - .bits_per_word =3D bits, - }; - - if (mode & SPI_TX_OCTAL) - tr.tx_nbits =3D 8; - else if (mode & SPI_TX_QUAD) - tr.tx_nbits =3D 4; - else if (mode & SPI_TX_DUAL) - tr.tx_nbits =3D 2; - if (mode & SPI_RX_OCTAL) - tr.rx_nbits =3D 8; - else if (mode & SPI_RX_QUAD) - tr.rx_nbits =3D 4; - else if (mode & SPI_RX_DUAL) - tr.rx_nbits =3D 2; - if (!(mode & SPI_LOOP)) { - if (mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) - tr.rx_buf =3D 0; - else if (mode & (SPI_RX_OCTAL | SPI_RX_QUAD | SPI_RX_DUAL)) - tr.tx_buf =3D 0; + size_t bytes_per_word =3D DIV_ROUND_UP(bits, 8); + int effective_transfers =3D min_t(int, transfers, DIV_ROUND_UP(len, bytes= _per_word)); + struct spi_ioc_transfer tr[effective_transfers]; + size_t len_per_transfer =3D ALIGN(DIV_ROUND_UP(len, effective_transfers),= bytes_per_word); + const uint8_t *tx_buf =3D tx; + const uint8_t *rx_buf =3D rx; + size_t rem =3D len; + + for (int i =3D 0; i < effective_transfers; i++) { + size_t n =3D min(rem, len_per_transfer); + + tr[i] =3D (struct spi_ioc_transfer) { + .tx_buf =3D (unsigned long)tx_buf, + .rx_buf =3D (unsigned long)rx_buf, + .len =3D n, + .delay_usecs =3D delay, + .word_delay_usecs =3D word_delay, + .speed_hz =3D speed, + .bits_per_word =3D bits, + }; + + if (tx_buf) + tx_buf +=3D n; + + if (rx_buf) + rx_buf +=3D n; + + rem -=3D n; + + if (mode & SPI_TX_OCTAL) + tr[i].tx_nbits =3D 8; + else if (mode & SPI_TX_QUAD) + tr[i].tx_nbits =3D 4; + else if (mode & SPI_TX_DUAL) + tr[i].tx_nbits =3D 2; + if (mode & SPI_RX_OCTAL) + tr[i].rx_nbits =3D 8; + else if (mode & SPI_RX_QUAD) + tr[i].rx_nbits =3D 4; + else if (mode & SPI_RX_DUAL) + tr[i].rx_nbits =3D 2; + if (!(mode & SPI_LOOP)) { + if (mode & (SPI_TX_OCTAL | SPI_TX_QUAD | SPI_TX_DUAL)) + tr[i].rx_buf =3D 0; + else if (mode & (SPI_RX_OCTAL | SPI_RX_QUAD | SPI_RX_DUAL)) + tr[i].tx_buf =3D 0; + } } =20 - ret =3D ioctl(fd, SPI_IOC_MESSAGE(1), &tr); + ret =3D ioctl(fd, SPI_IOC_MESSAGE(effective_transfers), &tr); if (ret < 1) pabort("can't send spi message"); =20 @@ -177,7 +199,7 @@ static void transfer(int fd, uint8_t const *tx, uint8_t= const *rx, size_t len) =20 static void print_usage(const char *prog) { - printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvwzP]\n", prog); + printf("Usage: %s [-2348CDFHILMNORSZbdilctropsvwTzP]\n", prog); puts("general device settings:\n" " -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" @@ -212,6 +234,7 @@ static void print_usage(const char *prog) " -N --no-cs no chip select\n" " -R --ready slave pulls low to pause\n" " -M --mosi-idle-low leave mosi line low when idle\n" + " -T --transfers number of transfers\n" "misc:\n" " -v --verbose Verbose (show tx buffer)\n"); exit(1); @@ -249,12 +272,13 @@ static void parse_opts(int argc, char *argv[]) { "ready", 0, 0, 'R' }, { "mosi-idle-low", 0, 0, 'M' }, { "predictable", 0, 0, 'P' }, + { "transfers", 1, 0, 'T' }, { "verbose", 0, 0, 'v' }, { NULL, 0, 0, 0 }, }; int c; =20 - c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PvS:zI:", + c =3D getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:PT:vS:zI= :", lopts, NULL); =20 if (c =3D=3D -1) @@ -319,6 +343,9 @@ static void parse_opts(int argc, char *argv[]) case 'M': mode |=3D SPI_MOSI_IDLE_LOW; break; + case 'T': + transfers =3D atoi(optarg); + break; case 'N': mode |=3D SPI_NO_CS; break; @@ -496,6 +523,9 @@ int main(int argc, char *argv[]) if (compare && (!do_tx || !do_rx)) pabort("-l/-c conflict with -t or -r"); =20 + if (transfers < 1) + pabort("-T (--transfers) must be 1 or above"); + fd =3D open(device, O_RDWR); if (fd < 0) pabort("can't open device"); --=20 2.55.0.806.gb8242b093d From nobody Fri Sep 25 09:26:54 2026 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 05F72480353; Mon, 14 Sep 2026 14:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.200.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397481; cv=none; b=bCB/Dm+KxaiW0rtI3LiqL8M0OMbG1q+TE9E2smn3swDTPIJjVm8Io4HLW0L17Q7Hm0B/dqmcFAaBiJ1NHOTYSchETbZPN8soIxKp5bXnQeIBxGm9kyz79jLMcXaVDQxCA/EOL1spJNCQU5RFPXc4eG0QAtky5lOm8kx9OAan5sQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789397481; c=relaxed/simple; bh=i7nVqLKILpxVpHuKbhfxPrfth93N+P5gXgDMz73NGXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PK3aPK8vDk89h3T9e0Y3RVV9ozSmqBJu4/QysFr8TMAO+EcUklMzEudAm6y1tKwn549poBZx408ocz6W6UP6uIyBNQKDBl1RpAI2XhwSDP86YJ+PsCYw8GmLaz2P+RlLazg9yAu6uiGTlp7I1+n8noSAbOo2sIk8hcWwoK+dSrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.200.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de X-PTX-Original-Recipient: linux-spi@vger.kernel.org X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-PTX-Original-Recipient: broonie@kernel.org X-PTX-Original-Recipient: jre@pengutronix.de X-PTX-Original-Recipient: kernel@pengutronix.de X-PTX-Original-Recipient: mkl@pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de (drehscheibe.grey.stw.pengutronix.de [IPv6:2a0a:edc0:0:c01:1d::a2]) (Authenticated sender: relay-from-drehscheibe.grey.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 5539D202899; Mon, 14 Sep 2026 16:50:55 +0200 (CEST) Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1x681H-000v8b-0s; Mon, 14 Sep 2026 16:50:55 +0200 From: Jonas Rebmann Date: Mon, 14 Sep 2026 16:50:46 +0200 Subject: [PATCH 7/7] spi: spidev_test: print TX on error Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260914-spi-sun4i-spidev_test-v1-7-72d6a3b38cee@pengutronix.de> References: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> In-Reply-To: <20260914-spi-sun4i-spidev_test-v1-0-72d6a3b38cee@pengutronix.de> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde , kernel@pengutronix.de, Jonas Rebmann X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=811; i=jre@pengutronix.de; h=from:subject:message-id; bh=328ZDv35tysIK4Nb8SjHRitkIjJ1rI/eN5uNPgFKQAk=; b=owGbwMvMwCV2ZcYT3onnbjcwnlZLYshawXluzveaLx9efLHZH2V6b+2XL76L45TyWsS3f3W/6 LAqzKXUpKOUhUGMi0FWTJElVk1OQcjY/7pZpV0szBxWJpAhDFycAjAR1+sMf+XClnrPmRZ/sbqc zenMokUTNu+zn9rtlJrssvTGJ8vrK68xMiy8GBqzZG3mzNww/97zLdVdNXm66S3ZvSuDvuvGX3y ZxgUA X-Developer-Key: i=jre@pengutronix.de; a=openpgp; fpr=0B7B750D5D3CD21B3B130DE8B61515E135CD49B5 From: Marc Kleine-Budde If sending an spi message fails, dump it to the console. Signed-off-by: Marc Kleine-Budde Signed-off-by: Jonas Rebmann --- tools/spi/spidev_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index a07c05f2d8b8..7f5b314b9e67 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -175,8 +175,11 @@ static void transfer(int fd, uint8_t const * const tx,= uint8_t const * const rx, } =20 ret =3D ioctl(fd, SPI_IOC_MESSAGE(effective_transfers), &tr); - if (ret < 1) + if (ret < 1) { + if (tx) + hex_dump(tx, len, 32, "TX"); pabort("can't send spi message"); + } =20 if (verbose && tx) hex_dump(tx, len, 32, "TX"); --=20 2.55.0.806.gb8242b093d