From patchwork Wed Oct 31 23:06:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149899 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp99630ljp; Wed, 31 Oct 2018 16:08:47 -0700 (PDT) X-Google-Smtp-Source: AJdET5eyj4kMQ1+VzehB9eHzYItSh/n26a8WV4T6JtvukktgngwWXGtV0LZvZUFFtvgisSEeD4hE X-Received: by 2002:a17:902:6909:: with SMTP id j9-v6mr5083404plk.221.1541027327052; Wed, 31 Oct 2018 16:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027327; cv=none; d=google.com; s=arc-20160816; b=czaJ6GUvthc9Chv1c55y0DiEWHmqV8+GYZ3/EoaCiScMK/bVRSBsBV/mtuCGUe1uYm yhEgiYbIOX3NAMcJWsBza74KhltJkTORJJhkcHHMTITqiGP5kLvgHP2U120R0ae+x3r6 rTvJPDD04k09f4CqPxnHjE9UX021uA24ElaOyToDYpc+ENb8Fv6A1+3o1wGkQ3pbgDWx NLvz0NvGNxmTaFBuc+Tr17U1ceuOcyWymNnHw1iBDHWwFSyO579ISYfMWmSvXmUoeR0t NxvqwqvRKChiS9Na0v6N2GguPjVcwt5Rv17F45z8abkOCTBxdUgup5qxMDQq2FWF0gxC sAQQ== 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=mCNnRyQhcVrmWRoZI7GkzAwJ9vppFf11EIeCHLfXgFw=; b=YsTuKnZhx4zcL4v4Kn/OwNyBRhlxcFnIgFabyEiC5blAs5PNXjoEUqZ6GCgEUwTwmT lEdVgU6q8Eb0QllhQ9wRGq28jq4DJFNSl99UAU4GHXY4XmY6ipYo6X39dPgVRWKhpFaK T79WfecvtmMklGRx0u8b/7AVu6Om47lnI6Ha5zuLfbczpWjqINCofsuRszVMrNp8cYHc JiMnkBVCf14EqruxesAMhYIwqCVHE0Rqs8qYqdq0MHrch8xBwlqTo4x/Ucq3axGWWTs3 cHPIcAb2sfA6pg4AKRJm9TDHPFdOMt/i6qh+MxseBOVHEHG8VrDoEUVYDQZBmMSMnQ39 crWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cboV/Zrz"; 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 y28-v6si29669411pfk.230.2018.10.31.16.08.46; Wed, 31 Oct 2018 16:08:47 -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="cboV/Zrz"; 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 S1730101AbeKAIIy (ORCPT + 32 others); Thu, 1 Nov 2018 04:08:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:58314 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730085AbeKAIIy (ORCPT ); Thu, 1 Nov 2018 04:08:54 -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 A002F20840; Wed, 31 Oct 2018 23:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027323; bh=0vLOTSa95C260lCg9o/3z1dplJDXNzhfGv3hOOLryuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cboV/ZrzWzqk6HbpHGIH6G9AVAAjk7qYDKRJoxC2SnkMjtcAMSZvHXO1iwIlgbb/o bB08EwqbPachJfGiNyYIpeC0ZTYJkhg+C380A+1KlpwxOlfpUOKUYWsWtFlHQHqm/x W35Vg92sLR0yZ9SGaXxkaHwSJpsLHi2Ddj3Ls95c= 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.18 053/126] spi: gpio: No MISO does not imply no RX Date: Wed, 31 Oct 2018 19:06:41 -0400 Message-Id: <20181031230754.29029-53-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230754.29029-1-sashal@kernel.org> References: <20181031230754.29029-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 3b518ead504e..b82b47152b18 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -282,9 +282,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)) @@ -408,7 +410,7 @@ static int spi_gpio_probe(struct platform_device *pdev) spi_gpio->bitbang.master = master; spi_gpio->bitbang.chipselect = spi_gpio_chipselect; - 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;