From patchwork Wed Oct 31 23:04:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149891 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp97588ljp; Wed, 31 Oct 2018 16:06:41 -0700 (PDT) X-Google-Smtp-Source: AJdET5e2IFtr0eHfa6duKR51+ANdX7mENDCNCCmzooU5FY2fPWWYw47RHLtW9vQ/YI5PznkoAviq X-Received: by 2002:a63:1c64:: with SMTP id c36-v6mr4781132pgm.354.1541027201493; Wed, 31 Oct 2018 16:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027201; cv=none; d=google.com; s=arc-20160816; b=jrch76hXsge9KmN528UajwOv9hH2iiwInsbBmAqZ1Y8N8oBm39WJSdUZw0Dth+q+uq PnjjRXvgeQ/9L1SdKNrMjlp6UR0YGOHmB9FJXjMcHSq/LypJevpirjWx23c/kp2WNiqA s9kWP80wVxTiHA1ACuUe/Be+ocVt1aCF0AeVv07g9A6d1tle6YloVpQmfRaFsrozFtEd dEikUJZg6/xcN71HhvYZV7DClP2zuMkIaGmaHXhIcLiSUfAdD0PhFGil9lMsTkutf1N9 0uMFmD1GOEJP0XqE9tQ8U4rBKI5yLg8f1CY2WJXjiaFFAjMiFjEKnXIe3HZDl84ZfgYx 4Eyw== 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 z11-v6si28545078pgf.66.2018.10.31.16.06.41; Wed, 31 Oct 2018 16:06:41 -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 S1728380AbeKAIGt (ORCPT + 32 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(-) -- 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;