Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp175097imd; Wed, 31 Oct 2018 16:50:04 -0700 (PDT) X-Google-Smtp-Source: AJdET5cjuey709hu52Pv/6A4njrFc/OiFkZBKmcVuauuUALxW3tR2F6a775Wu45Q91PNhMuwDw3N X-Received: by 2002:a17:902:9a8b:: with SMTP id w11-v6mr5225255plp.94.1541029804903; Wed, 31 Oct 2018 16:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029804; cv=none; d=google.com; s=arc-20160816; b=tj2Lqn0aVDwzvNyG3MVScGqo6FqGr6JbQo6958vOKbC8/+eW/D/mRi0BGiRGFZYtGc pT4DCdJWlqvgISfZENFrHldTfyeoMN7n7WcqW29za1rsk4OQmLZGajd+RLYvZjA/PYX4 SqozGXK75XSLu5LxSgdg2RqJg0qByLqMjwK44jiFti+9JUP/PU9/DEwECZn0Zb0fEYKL Ih7PAsMVvltW5RkB4u+qmj3jyzmnciwpRd7LtWHPBDuAMgsUwASwf5n+SXA4rsVeM12g M0SM4htB5D5gmgEjEWsJPPAYuQIStpotEuCECmRimQnp7E+dcHmszAEFj5JAu1avZ18a SWAA== 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; bh=JNgTKZnMVltM8xKi8i2i8rOuwxhadt5WKu+HBzvahUQ=; b=fqHQB0nZnG1OuGvHGE3CZGyZ/vDbwA1OEn1iLG4dMTN2WbK9HHy9szC4suFYEnNOim 6WkSEBjgecTMRYH9ufP7sC+J9NUEG93PYYphzJ/TdZnsyApuqvQUFHXFZUG54kq0h0jE IZuP1fUyovSMgR170uHpFp5ZSkfqD9dFnCfA8Iu5TCxtuCb+WzpKOFixAv1zTVpkLYJj GtGhNInbR3jnvYLQPbAWFxaIxnlZG6WeEVNp3v2NWOWqmxLJzme3Lh556CFaGjQ6oTxw qn0k5/Sn4WkquE8Awz6o1zXekZcI/9Edk51tRTvgKrnK/IgvvDPvtM2WjOrUbOTf7LMH KowQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zYGfEk18; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3-v6si14229458plj.372.2018.10.31.16.49.50; Wed, 31 Oct 2018 16:50:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=zYGfEk18; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728374AbeKAIGt (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:54008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728327AbeKAIGs (ORCPT ); Thu, 1 Nov 2018 04:06:48 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 51E0420847; Wed, 31 Oct 2018 23:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027198; bh=WAXB0/E6x4DAvDqq1CJ3xnMFuKPtDE5Y1k20A+UwjEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zYGfEk18zhe4zRVbnNm6ZsacRUg3qW7OHJ+2nLuFOhUKwz8KJq2u0iI5xqbn6oZgs 6WBseVcoKycgZochrehrIQgOKsPjn2RoTJ+26wPDNBQOSy5uUQJRwHFkRPXV/8gm4R eqPtqkCVlfANcT40/9LGg8WDASlvu41ICSuo1DM4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Andrzej Hajda , Lorenzo Bianconi , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 4.19 061/146] spi: gpio: No MISO does not imply no RX Date: Wed, 31 Oct 2018 19:04:16 -0400 Message-Id: <20181031230541.28822-61-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Walleij [ Upstream commit abf5feef3ff0cefade0c76be53b59e55fdd46093 ] 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 Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-gpio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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; -- 2.17.1