From patchwork Mon Sep 3 21:50:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 145829 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2942626ljw; Mon, 3 Sep 2018 14:50:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZB9kN5AQmuxQRd0sZJBCJr5rJZvr6NAfB6DrrzK4JVH7i5E4VTnDKMDt5VB8N6fjtE84Qi X-Received: by 2002:a17:902:6808:: with SMTP id h8-v6mr30721563plk.27.1536011452425; Mon, 03 Sep 2018 14:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536011452; cv=none; d=google.com; s=arc-20160816; b=kNH558tGnCjIetLYKlpjQjHgOlKR1uq+i11Bw7438B8T9e88g/c1+zgywBAvunJFJ1 Me982t/1oFpCMP1ZIWp4RzywPa7eDLxGa+UshublPSLfW3OLWO/jayBpdcbK17riNsb2 mWpN9EOQnbz+vgF8mk4GCHa8FPiS8iEvjRWpXwgCyY0HYjKsvPw0CSr8vPKXOEmMYUzy YMfj2Lsh2mXFjsOHUhS56nAsoELspKhd9/9za56JQ9yvEdz1Bx6fMuKrpJGhwcV48bge fomL+2BnrkwHpSx4QcGQ6OLc5hngSWsBQIlFpgHSsMk5xVnCMKMC19xoNIxcaSr6uENO vW8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=z0JAMZTPBOk70wPnOcW/n1U02PRHWoOYXYXqO3F0FD0=; b=EUGXpDgpkjTx6hg4ql/EJr9jn7pzmdX6OVq9TwnirTs8h7ZCGEICxJP6mRWx/plyqm RSHfKCzVWWnXNg7IVkeEyEDnhU+WzCIO/eH4UNCriYP2D8N9y3ZnAbaV9m/wN1SzmNRJ vhKPwpSoXPSaUaH9BCqpQDBx9UZPxx98DFlFeWmfndOde32XoL0QWsGfs0TNlRl8B/66 FFXc5NeseELCstZ7pBPrCfjCeQBxo4P6D1FUh5HBTta90kj+2/unlNRKTozQNooC1n27 LWd7i7WitU08hhDwCRhdw6+EQATQ1yaXOMKsjlQw8HFsv9kcOsrSxPGsOcLqp0MUWT8w V1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aHquJOgX; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si18146466plr.488.2018.09.03.14.50.52; Mon, 03 Sep 2018 14:50:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aHquJOgX; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727212AbeIDCM5 (ORCPT + 1 other); Mon, 3 Sep 2018 22:12:57 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:45629 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727100AbeIDCM5 (ORCPT ); Mon, 3 Sep 2018 22:12:57 -0400 Received: by mail-lf1-f68.google.com with SMTP id r4-v6so1319556lff.12 for ; Mon, 03 Sep 2018 14:50:50 -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=z0JAMZTPBOk70wPnOcW/n1U02PRHWoOYXYXqO3F0FD0=; b=aHquJOgXggxxFbce46YP+0HD7iSUp/9NaeGHmZ2MsYFJhU5gYZj1Fy3fKTAoinG4fu 3rY9J/NvopLU15xRvx2y1dcFTjWZQDdDgQkXmYNEKKl0aqv8EZfi47dREiJVA88BWRH/ otGajQAsE+Rt6s+sVHqQnlMj0wnlAB/AfM1wA= 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=z0JAMZTPBOk70wPnOcW/n1U02PRHWoOYXYXqO3F0FD0=; b=ibOasMNyz62+MoFO+XnNhUNjH2VYPqpHjzyqw6u1LXI5V7QciZMEj/sl7rcX7PbwAS 9IWnwC2tYnVRFbT3LY25ke/Puvn2XBWL1qXdKuaVUhcCIA7EdQ+GD5f7RSG85hZn0/0X m/e6fGEXguT5/9WqTirfWO/8fen5WvlTg/b0LXr39ZIHOo4VGzMoYponMiCtMpv9vZSw Osm/+JofWpV0cxpPLPmtZZiMX9gePAHUhSzaTc8P2Hw2qSGyP10nLpxHqO7eKXq4OuGr Jl3Pa5dVqgT+76t0PmaZg0/6/hIhRhgj1uemyKhx5Oc59vgzZolq1e3wUCOEGDOYjgXc BomA== X-Gm-Message-State: APzg51DdPo4TeL3bPiztLtDOoxEpyAIN0Wbyx6ZxH7uyPQ6tPIaFwbTK fwcLh1jTyqisibpFrWShzBklDw== X-Received: by 2002:a19:8c8:: with SMTP id 191-v6mr984383lfi.152.1536011449766; Mon, 03 Sep 2018 14:50:49 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Sep 2018 14:50:48 -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 2/4] spi: gpio: Fix reading for 3WIRE Date: Mon, 3 Sep 2018 23:50:33 +0200 Message-Id: <20180903215035.17265-3-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 If he GPIO bitbanged host is registered using just one line, MISO, naturally the DT parser will flag the host as SPI_MASTER_NO_RX. This makes the GPIO SPI driver assign word transfer functions that enforce the SPI master flags SPI_MASTER_NO_RX (or SPI_MASTER_NO_TX) to the flags on each call down to the inlined bitbang functions such as bitbang_txrx_be_cpha0(). In the 3WIRE case, enforcing this flag is wrong, because the master can then do both TX and RX (albeit not at the same time) using the same line, by just switching the direction of the line and keep clocking in bits. Augment spi_gpio_spec_txrx_word_mode[0123] to account for this. Cc: Andrzej Hajda Cc: Lorenzo Bianconi Signed-off-by: Linus Walleij --- drivers/spi/spi-gpio.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 9f4882f82c3c..6bd692304b92 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -183,33 +183,42 @@ static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, * speed in the generic case (when both MISO and MOSI lines are * available), as optimiser will remove the checks when argument is * constant. + * + * A special kludge is needed for 3WIRE SPI, as this mode can use + * the same line for RX and TX and should not enforce the host + * flag - we will just switch MISO from output to input mode when + * needed. */ static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits, unsigned flags) { - flags = spi->master->flags; + if (!(spi->mode & SPI_3WIRE)) + flags = spi->master->flags; return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); } static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits, unsigned flags) { - flags = spi->master->flags; + if (!(spi->mode & SPI_3WIRE)) + flags = spi->master->flags; return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); } static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits, unsigned flags) { - flags = spi->master->flags; + if (!(spi->mode & SPI_3WIRE)) + flags = spi->master->flags; return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); } static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits, unsigned flags) { - flags = spi->master->flags; + if (!(spi->mode & SPI_3WIRE)) + flags = spi->master->flags; return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); }