From nobody Mon Apr 27 15:22:25 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CE8AC43334 for ; Mon, 13 Jun 2022 05:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232495AbiFMFup (ORCPT ); Mon, 13 Jun 2022 01:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbiFMFud (ORCPT ); Mon, 13 Jun 2022 01:50:33 -0400 X-Greylist: delayed 638 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 12 Jun 2022 22:50:32 PDT Received: from SpacedOut.fries.net (SpacedOut.fries.net [IPv6:2001:470:3832:200::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 525645FE6 for ; Sun, 12 Jun 2022 22:50:32 -0700 (PDT) Received: from SpacedOut.fries.net (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by SpacedOut.fries.net (8.15.2/8.15.2/Debian-22) with ESMTPS id 25D5dfdW3963830 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 13 Jun 2022 00:39:41 -0500 Received: (from david@localhost) by SpacedOut.fries.net (8.15.2/8.15.2/Submit) id 25D5dfhh3963829; Mon, 13 Jun 2022 00:39:41 -0500 Date: Mon, 13 Jun 2022 00:39:41 -0500 From: David Fries To: Mark Brown Cc: linux-kernel@vger.kernel.org Subject: [PATCH] spi: spidev_test: Warn when the mode is not the requested mode Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.2 (SpacedOut.fries.net [IPv6:::1]); Mon, 13 Jun 2022 00:39:41 -0500 (CDT) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- This is the kernel log, I just didn't see it at first. spidev spi1.0: setup: ignoring unsupported mode bits 200 I was testing --quad on a Raspberry Pi where I didn't expect it to work, which the ioctl didn't return an error, it just cleared the bits it didn't support. tools/spi/spidev_test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 83844f8b862a..5629387bfc56 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -417,6 +417,7 @@ int main(int argc, char *argv[]) { int ret =3D 0; int fd; + uint32_t request; =20 parse_opts(argc, argv); =20 @@ -430,13 +431,23 @@ int main(int argc, char *argv[]) /* * spi mode */ + /* WR is make a request to assign 'mode' */ + request =3D mode; ret =3D ioctl(fd, SPI_IOC_WR_MODE32, &mode); if (ret =3D=3D -1) pabort("can't set spi mode"); =20 + /* RD is read what mode the device actually is in */ ret =3D ioctl(fd, SPI_IOC_RD_MODE32, &mode); if (ret =3D=3D -1) pabort("can't get spi mode"); + /* Drivers can reject some mode bits without returning an error. + * Read the current value to identify what mode it is in, and if it + * differs from the requested mode, warn the user. + */ + if(request !=3D mode) + printf("WARNING device does not support requested mode 0x%x\n", + request); =20 /* * bits per word --=20 2.30.2