From patchwork Mon Sep 3 21:50:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10586397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2383316B1 for ; Mon, 3 Sep 2018 21:50:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1393529183 for ; Mon, 3 Sep 2018 21:50:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05FE8291B6; Mon, 3 Sep 2018 21:50:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6187029183 for ; Mon, 3 Sep 2018 21:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726183AbeIDCMy (ORCPT ); Mon, 3 Sep 2018 22:12:54 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:35124 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727100AbeIDCMy (ORCPT ); Mon, 3 Sep 2018 22:12:54 -0400 Received: by mail-lj1-f196.google.com with SMTP id p10-v6so1454692ljg.2 for ; Mon, 03 Sep 2018 14:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SJuFv+lF2yIIAer5KVTofLqD35pnm/sU6RwnGCbRx2M=; b=CvGlONwHxxbyI6lTsJ4VCTtDyUVP7Q6VQIb00iqfuc64cCo5N893tUTcSRit7GlDoo cwDb7mrs0BeF/wBiZzKnyOZgqb86VY9MKCDAMy8wM9oXiU6XPIDYDfiME4dHHlHIyLdl WRQFCyXFc1WQ9GX3cFieGO6ADjnW3vlXCtk+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SJuFv+lF2yIIAer5KVTofLqD35pnm/sU6RwnGCbRx2M=; b=hI0oxfGLVldSq51NT983bcqz0QbJlax+VJ2rTqh4+mm7woOyNg3cjPO0wHx27nfqxC hfLZ8ymCFM/6cMuHUD6AwL0QnIaPNekhpjBhS7kuU+ZjoHp4M6q24hYwuLqkj0CTwOsH Qf/5BkCnwSArQpQq67N61vXlepx7281Zu12WdNuuWMuStQAFEVqgt7YUBkvnSFyzzocK 0som3uCtZhG7vqEmBzmPS0vIIirOXFG4Rc55gjOGuzagZPc3STOoaN/i0lY1nn88Lek3 2en2k3Czd8gRv+QOWIxIyfkQb1bvxSQj5xqpXnK3K0baDZtw+XcVwejZ2Mb15P2lZSDa Xu6A== X-Gm-Message-State: APzg51BGDF31kZUw2dIMG4YI4FPqIrOkAefGyvc7DNZgWfMelUtrbIt7 MeReqzZmPBJXjovwSV/5/iiiVg== X-Google-Smtp-Source: ANB0VdaFXH38GLKoUZIybTSPe9nU67q6opuqHpfjRpwhgA2iyxxoiDGlsXtI20zFG/+Z3jh4wUJ0iQ== X-Received: by 2002:a2e:291c:: with SMTP id u28-v6mr18207089lje.70.1536011446939; Mon, 03 Sep 2018 14:50:46 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id q128-v6sm3665503ljq.72.2018.09.03.14.50.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 14:50:45 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org, Andrzej Hajda , Lorenzo Bianconi Cc: linux-gpio@vger.kernel.org, Rob Herring , Linus Walleij Subject: [PATCH 1/4] spi: core: Allow both TX and RX transfers in 3WIRE Date: Mon, 3 Sep 2018 23:50:32 +0200 Message-Id: <20180903215035.17265-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903215035.17265-1-linus.walleij@linaro.org> References: <20180903215035.17265-1-linus.walleij@linaro.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SPI message validation code in __spi_validate() is too restrictive on 3WIRE transfers: the core bitbanging code, for example, will gladly switch direction of the line inbetween transfers. Allow 3WIRE messages even if there is both TX and RX transfers in the message. Transfers with TX and RX at the same time will not work however (just one wire after all), so be sure to disallow those. Cc: Andrzej Hajda Cc: Lorenzo Bianconi Signed-off-by: Linus Walleij Acked-by: Lorenzo Bianconi --- drivers/spi/spi.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ec395a6baf9c..f6f9314e9a18 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2841,10 +2841,17 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) list_for_each_entry(xfer, &message->transfers, transfer_list) { if (xfer->rx_buf && xfer->tx_buf) return -EINVAL; - if ((flags & SPI_CONTROLLER_NO_TX) && xfer->tx_buf) - return -EINVAL; - if ((flags & SPI_CONTROLLER_NO_RX) && xfer->rx_buf) - return -EINVAL; + /* + * 3WIRE can indeed do a write message followed by a + * read message, the direction of the line will be + * switched between the two messages. + */ + if (spi->mode & SPI_CONTROLLER_HALF_DUPLEX) { + if ((flags & SPI_CONTROLLER_NO_TX) && xfer->tx_buf) + return -EINVAL; + if ((flags & SPI_CONTROLLER_NO_RX) && xfer->rx_buf) + return -EINVAL; + } } }