Skip to content

Commit 41ecad2

Browse files
dfriesbroonie
authored andcommitted
spi: spidev_test: Warn when the mode is not the requested mode
Print a warning if the device mode doesn't match the requested mode. The user doesn't enter the mode in hex so it isn't obvious when setting the mode succeeds that the mode isn't the requested mode. The kernel logs a message, it will be more visible if the test also prints a warning. I was testing --quad, which is unsupported, but doesn't cause the mode request to fail. Signed-off-by: David Fries <David@Fries.net> Link: https://lore.kernel.org/r/YqbNnSGtWHe/GG7w@spacedout.fries.net Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 845d3fd commit 41ecad2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/spi/spidev_test.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ int main(int argc, char *argv[])
417417
{
418418
int ret = 0;
419419
int fd;
420+
uint32_t request;
420421

421422
parse_opts(argc, argv);
422423

@@ -430,13 +431,23 @@ int main(int argc, char *argv[])
430431
/*
431432
* spi mode
432433
*/
434+
/* WR is make a request to assign 'mode' */
435+
request = mode;
433436
ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode);
434437
if (ret == -1)
435438
pabort("can't set spi mode");
436439

440+
/* RD is read what mode the device actually is in */
437441
ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode);
438442
if (ret == -1)
439443
pabort("can't get spi mode");
444+
/* Drivers can reject some mode bits without returning an error.
445+
* Read the current value to identify what mode it is in, and if it
446+
* differs from the requested mode, warn the user.
447+
*/
448+
if (request != mode)
449+
printf("WARNING device does not support requested mode 0x%x\n",
450+
request);
440451

441452
/*
442453
* bits per word

0 commit comments

Comments
 (0)