Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp698726ybv; Thu, 13 Feb 2020 07:59:05 -0800 (PST) X-Google-Smtp-Source: APXvYqzAkA5ZDfeoQHr09Jwsaunezq59Fa+s8jCRpPDNHBExqihQmJ71E4CbLxsGkhlrPKkOs3Xu X-Received: by 2002:a9d:6e8e:: with SMTP id a14mr13234864otr.109.1581609545370; Thu, 13 Feb 2020 07:59:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581609545; cv=none; d=google.com; s=arc-20160816; b=Pv/82bppEYlom40MsSw8OZMMrOEBgwn4zpoiZZ8aDX6NJRbeZEK9uinHOB41XOESQ3 Y9T6hltt+wtl3Szws3vRRtpGIZkVZAXEivAVYuL14hWJ7BCkyVJIRNSkKDumRz0fIe2U daQ0QwDLSnpnlQw4Vn5OZkxSaVHyj/5mP3RJYyte5g4vleyJTM69Zx+0z8fN68CYO1QT tarw6vpA+LGusHgG4XMbSCMTHgsRa1nCuGMywv9nghh7ENefxWWvbPum+mSBMg44E/x7 2L8Coh0n4gvaqFm4JVoQrK0P0HXD0PoFK4eSf4iPBOCL/BRsAhi4usCpa5zPgDbWxN1c 1Fow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kdLVcpupMKqbpewzVo0pCx5bAwZIoZbLGAr+pgq5bzY=; b=JXc4JlvdQkQWkEJY+/Yqlri5azC28wi7lXNRZcyeP8imFcQKB/JOufRqNonst/6HLO iYMI9oGReaCGSyJhbX09+HCijCxWyEsDnhE/s50qsG67HhU3gNGqJpWxCgTQp5mjCQXP PIGxV6vD+JlQ30J3JKh8+FIljWqGkn0mnH+T5AU1bvls/6hkKDw3MJQ1/rPj0p7F2Ka7 +IlawzxLlwGOAQqx09E+mLeE1GbDrvKPco7xxG6zYtsef03zsNqCaHzJig61TCRT/fl5 TYQCemWp9t02nnj0LsdpHqurn1bLymsmgqAxcT7f1tUvvPZmJY6YR5sJ/h+7mpD5hhsd UFdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YLJX1xRn; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z199si1288833oia.192.2020.02.13.07.58.53; Thu, 13 Feb 2020 07:59:05 -0800 (PST) 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=YLJX1xRn; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728455AbgBMPZK (ORCPT + 99 others); Thu, 13 Feb 2020 10:25:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:35264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728442AbgBMPXi (ORCPT ); Thu, 13 Feb 2020 10:23:38 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A878246AD; Thu, 13 Feb 2020 15:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607418; bh=I4BM5jV6fmMz0MB6nVZKLDDCTivXHgSEbj9NYG4nepc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YLJX1xRnclUgmWSm6fdp5eE1DcXQAjto9NXchLRhKZPylQpt1QX/jEZxqxq6JJZZ6 5yDNglyINuHjaOmHRSB8AvYjiWBVIaEIAs5qplSaAvAkiMblnaVIRCPk45PQ0eaVqR FNoZiS04QI2OzBfCc1j6DEsKq9lQiUaJhS0Qes+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Elwell , Mark Brown , Linus Walleij , Ulf Hansson Subject: [PATCH 4.9 026/116] mmc: spi: Toggle SPI polarity, do not hardcode it Date: Thu, 13 Feb 2020 07:19:30 -0800 Message-Id: <20200213151853.066660298@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151842.259660170@linuxfoundation.org> References: <20200213151842.259660170@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Walleij commit af3ed119329cf9690598c5a562d95dfd128e91d6 upstream. The code in mmc_spi_initsequence() tries to send a burst with high chipselect and for this reason hardcodes the device into SPI_CS_HIGH. This is not good because the SPI_CS_HIGH flag indicates logical "asserted" CS not always the physical level. In some cases the signal is inverted in the GPIO library and in that case SPI_CS_HIGH is already set, and enforcing SPI_CS_HIGH again will actually drive it low. Instead of hard-coding this, toggle the polarity so if the default is LOW it goes high to assert chipselect but if it is already high then toggle it low instead. Cc: Phil Elwell Reported-by: Mark Brown Signed-off-by: Linus Walleij Reviewed-by: Mark Brown Link: https://lore.kernel.org/r/20191204152749.12652-1-linus.walleij@linaro.org Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/mmc_spi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -1157,17 +1157,22 @@ static void mmc_spi_initsequence(struct * SPI protocol. Another is that when chipselect is released while * the card returns BUSY status, the clock must issue several cycles * with chipselect high before the card will stop driving its output. + * + * SPI_CS_HIGH means "asserted" here. In some cases like when using + * GPIOs for chip select, SPI_CS_HIGH is set but this will be logically + * inverted by gpiolib, so if we want to ascertain to drive it high + * we should toggle the default with an XOR as we do here. */ - host->spi->mode |= SPI_CS_HIGH; + host->spi->mode ^= SPI_CS_HIGH; if (spi_setup(host->spi) != 0) { /* Just warn; most cards work without it. */ dev_warn(&host->spi->dev, "can't change chip-select polarity\n"); - host->spi->mode &= ~SPI_CS_HIGH; + host->spi->mode ^= SPI_CS_HIGH; } else { mmc_spi_readbytes(host, 18); - host->spi->mode &= ~SPI_CS_HIGH; + host->spi->mode ^= SPI_CS_HIGH; if (spi_setup(host->spi) != 0) { /* Wot, we can't get the same setup we had before? */ dev_err(&host->spi->dev,