From patchwork Sun Sep 9 22:28:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 146262 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1992207ljw; Sun, 9 Sep 2018 19:36:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ7Bbkof06/CJD3oYPpb5QjODhhq5wXu38WltQ3dANdf2TBw0VLcG6b+HDpEYMH2JYXFNWv X-Received: by 2002:a63:991a:: with SMTP id d26-v6mr20275672pge.159.1536546972686; Sun, 09 Sep 2018 19:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536546972; cv=none; d=google.com; s=arc-20160816; b=NulYo5vdmidqipASeOMUXV0M4CasFgTIup46jZnf1779AeN8vFBaikgk1cmtW7epLG f9qh+5vhQc9VKGzxqG0VJPhMx+1UMdc+hsbcT7N9iHytOzu3tH2vTwdO8bxfd5gK7WRp y33GxjTwOTwjC4EnloUoejK4wOPeGTfSnk3g78nKualQFwzDb3KF6cvBUXOuAG/2r3yU m4knve25QTCyXrpWziC/ovnCgNXmAcRT3q6i959GR3T6qE/MSTU7QuqOQdEHP/U5pWpV zH8o6cISLYpoMHzPoE23/Qt5Wr9HELwnRROf47DGuZSOKg3T7ennSc8q0XgEYezNeWU0 cf6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=k4WvgQpXpaRBSsSzcmvEQe6PbIeEEdfJdRd074d5+Q8=; b=zSba4XGYxr5vnJj3nikLslpVedXQ9u3CkerFuimW8jpF3aoHSGkRBHSTQWelUO0rD+ Yv/PtH9BAlPo9jZR3LGcGSxpAFgmWtrRQkHKApsZbKTWOnO3IuKNmtpjfr6Yd8c287B1 7M76CGZxZ3RPZTY+ibjnBbqnx8rZi6Qa3aHARU7SUVhMvxgZ/BC2fKCxhR6EWxUTQDmF EhOTP3V+wzZwVnvmZ2zXQ/7P+gs5tROhGSBvR1lHHauflLQcCg1BsPebb/ZkK/VNkFn4 g7oiH8QP3keTbjHYddONzUbZrUe6C+GYv2fccvA+NmsuMNcFtqVSXh33MNqvZm8dPSyc tqpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V+u3rTiV; 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 w16-v6si16167784pgj.61.2018.09.09.19.36.12; Sun, 09 Sep 2018 19:36:12 -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=V+u3rTiV; 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 S1725974AbeIJH1x (ORCPT + 1 other); Mon, 10 Sep 2018 03:27:53 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:33078 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbeIJH1x (ORCPT ); Mon, 10 Sep 2018 03:27:53 -0400 Received: by mail-lf1-f66.google.com with SMTP id m26-v6so16191782lfb.0 for ; Sun, 09 Sep 2018 19:36:10 -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; bh=k4WvgQpXpaRBSsSzcmvEQe6PbIeEEdfJdRd074d5+Q8=; b=V+u3rTiV+pH7WdSgl3zx72eqJHUD/rVe07mXLDRnAaLgr/9uzQ73xTSo23+7mjtlRb x/ZmB5i5ZQeOFgK8acFuU75dNo+Rrt/nvFaLJsqB/EMdDIY+7EcQZ1z7ruEOR6dl5WST /+PA0+coHmcG8vdP7v34kSpaix0eR8RLL5NZE= 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; bh=k4WvgQpXpaRBSsSzcmvEQe6PbIeEEdfJdRd074d5+Q8=; b=AHlvb3cx6/cQzlD07D3eZTGS2b7Bn7OeNzwkId4vgSdOWlHSsqgp3JcvEqnaHcE5Z7 EZKAI3U2LViREL8/m+fqwrqj6d/ubA1O+jzi3tgCReDj0XtZrhqCbTefAYZGVMrtH4SF GK0ahKDXa/qMXvPilKkinPL2UYsLuQupRwtRnQGixSE25U/EAQQ6IlFd1sOOgEn5CWSn LWVNV8ks+P5sZAS19KEH4CgcP1RhvHI6trKPJNqXNKTJdwRPr0/zlRP5Iy0FBsTs0v9T G5ve4Wz6YOsB5VIw9374Ywn4VOPZ2MrklvvZe5ukFSW7ei/iNPkr6Ht8eNmS1jBb7bqV jmPA== X-Gm-Message-State: APzg51B741Y7kcvRDcegjjbFPr8xMkpuWUJdOUX91/pvmINVaKZrGjpx 2RrIxo1J6Nl1d+ewYeFCFHQJjIDDp8DMww== X-Received: by 2002:a19:23c5:: with SMTP id j188-v6mr10268725lfj.137.1536532094941; Sun, 09 Sep 2018 15:28:14 -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 b80-v6sm2384840lfe.83.2018.09.09.15.28.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Sep 2018 15:28:13 -0700 (PDT) From: Linus Walleij To: Mark Brown , linux-spi@vger.kernel.org, Andrzej Hajda , Lorenzo Bianconi Cc: linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH v2] spi: gpio: No MISO does not imply no RX Date: Mon, 10 Sep 2018 00:28:05 +0200 Message-Id: <20180909222805.20805-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org There is a logical problem in spi-gpio with host just assigning a MOSI line and no MISO: this is interpreted as the host cannot do RX and the host is flagged with SPI_MASTER_NO_RX. This is wrong: since GPIO lines can switch direction, in 3WIRE operation the host will simply reverse the direction of the GPIO line and start reading from it, there is even code for doing this in the driver, but it went unnoticed because it was tested by using a master with 4 wires but a device using just 3 wires. Remove the offending flag. Cc: Andrzej Hajda Cc: Lorenzo Bianconi Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Totally changed approach on how to handle this 3wire proble, one simple patch: instead of trying to interpret 3wire as "can't do TX or RX for certain transfers" we interpret 3wire setup with just MOSI as both TX and RX capable. --- drivers/spi/spi-gpio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 421bfc7dda67..088772ebef9b 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -295,9 +295,11 @@ static int spi_gpio_request(struct device *dev, spi_gpio->miso = devm_gpiod_get_optional(dev, "miso", GPIOD_IN); if (IS_ERR(spi_gpio->miso)) return PTR_ERR(spi_gpio->miso); - if (!spi_gpio->miso) - /* HW configuration without MISO pin */ - *mflags |= SPI_MASTER_NO_RX; + /* + * No setting SPI_MASTER_NO_RX here - if there is only a MOSI + * pin connected the host can still do RX by changing the + * direction of the line. + */ spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); if (IS_ERR(spi_gpio->sck)) @@ -423,7 +425,7 @@ static int spi_gpio_probe(struct platform_device *pdev) spi_gpio->bitbang.chipselect = spi_gpio_chipselect; spi_gpio->bitbang.set_line_direction = spi_gpio_set_direction; - if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { + if ((master_flags & SPI_MASTER_NO_TX) == 0) { spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2;