From: Cheng Ming Lin <linchengming884@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, linux-api@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
alvinzhou@mxic.com.tw
Subject: [PATCH v2 2/3] spi: spidev_test: Add an option to request DTR transfers
Date: Tue, 1 Dec 2026 14:52:01 +0800 [thread overview]
Message-ID: <20261201065202.2667609-3-chengminglin@mxic.com.tw> (raw)
In-Reply-To: <20261201065202.2667609-1-chengminglin@mxic.com.tw>
Add a -x/--dtr option setting SPI_IOC_XFER_DTR on every transfer of the
message, so that Double Transfer Rate transfers can be exercised with
spidev_test. Like the bus width options, it applies to all the
transfers. Report it along with the other device settings.
The message is then sent with SPI_IOC_MESSAGE_FLAGS, so that the
request cannot be silently ignored. Kernels without
SPI_IOC_MESSAGE_FLAGS and controllers without DTR support both reject
it, in which case spidev_test reports that the message could not be
sent.
Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
tools/spi/spidev_test.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c
index 5bd3159f6..5eee86131 100644
--- a/tools/spi/spidev_test.c
+++ b/tools/spi/spidev_test.c
@@ -41,6 +41,7 @@ static char *output_file;
static uint32_t speed = 500000;
static uint16_t delay;
static uint16_t word_delay;
+static int dtr;
static int verbose;
static int transfer_size = -1;
static int transfers = 1;
@@ -169,6 +170,7 @@ static void transfer(int fd, uint8_t const * const tx, uint8_t const * const rx,
.word_delay_usecs = word_delay,
.speed_hz = speed,
.bits_per_word = bits,
+ .flags = dtr ? SPI_IOC_XFER_DTR : 0,
};
if (tx_buf)
@@ -199,7 +201,10 @@ static void transfer(int fd, uint8_t const * const tx, uint8_t const * const rx,
}
}
- ret = ioctl(fd, SPI_IOC_MESSAGE(effective_transfers), tr);
+ if (dtr)
+ ret = ioctl(fd, SPI_IOC_MESSAGE_FLAGS(effective_transfers), tr);
+ else
+ ret = ioctl(fd, SPI_IOC_MESSAGE(effective_transfers), tr);
free(tr);
if (ret < 0) {
const size_t dump_len = min_t(size_t, len, 256);
@@ -211,6 +216,8 @@ static void transfer(int fd, uint8_t const * const tx, uint8_t const * const rx,
printf("... (%zu more bytes)\n", len - dump_len);
}
errno = saved_errno;
+ if (dtr && errno == ENOTTY)
+ pabort("this kernel does not support DTR requests");
pabort("can't send spi message");
}
@@ -244,7 +251,7 @@ static void transfer(int fd, uint8_t const * const tx, uint8_t const * const rx,
static void print_usage(const char *prog)
{
- printf("Usage: %s [-2348CDFHILMNOPRSTZbcdiloprstvwz]\n", prog);
+ printf("Usage: %s [-2348CDFHILMNOPRSTZbcdiloprstvwxz]\n", prog);
puts("general device settings:\n"
" -D --device device to use (default /dev/spidev1.1)\n"
" -s --speed max speed (Hz)\n"
@@ -262,6 +269,7 @@ static void print_usage(const char *prog)
" -2 --dual dual transfer\n"
" -4 --quad quad transfer\n"
" -8 --octal octal transfer\n"
+ " -x --dtr double transfer rate\n"
" -3 --3wire SI/SO signals shared\n"
" -Z --3wire-hiz high impedance turnaround\n"
"data:\n"
@@ -318,12 +326,13 @@ static void parse_opts(int argc, char *argv[])
{ "mosi-idle-low", 0, 0, 'M' },
{ "predictable", 1, 0, 'P' },
{ "transfers", 1, 0, 'T' },
+ { "dtr", 0, 0, 'x' },
{ "verbose", 0, 0, 'v' },
{ NULL, 0, 0, 0 },
};
int c;
- c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:P:T:vS:zI:",
+ c = getopt_long(argc, argv, "D:s:d:w:b:i:o:lctrHOLC3ZFMNR248p:P:T:vS:zI:x",
lopts, NULL);
if (c == -1)
@@ -429,6 +438,9 @@ static void parse_opts(int argc, char *argv[])
case 'I':
iterations = atoi(optarg);
break;
+ case 'x':
+ dtr = 1;
+ break;
default:
print_usage(argv[0]);
}
@@ -648,6 +660,8 @@ int main(int argc, char *argv[])
printf("spi mode: 0x%x\n", mode);
printf("bits per word: %u\n", bits);
printf("max speed: %u Hz (%u kHz)\n", speed, speed/1000);
+ if (dtr)
+ printf("dtr: on\n");
if (input_tx)
transfer_escaped_string(fd, input_tx);
--
2.25.1
next prev parent reply other threads:[~2026-12-01 6:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 6:51 [PATCH v2 0/3] spi: spidev: Allow userspace to request DTR transfers Cheng Ming Lin
2026-12-01 6:52 ` [PATCH v2 1/3] " Cheng Ming Lin
2026-12-01 6:52 ` Cheng Ming Lin [this message]
2026-12-01 6:52 ` [PATCH v2 3/3] spi: spidev: Document SPI_IOC_MESSAGE_FLAGS Cheng Ming Lin
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=20261201065202.2667609-3-chengminglin@mxic.com.tw \
--to=linchengming884@gmail.com \
--cc=alvinzhou@mxic.com.tw \
--cc=broonie@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
/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