Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3694746ybv; Mon, 10 Feb 2020 04:51:51 -0800 (PST) X-Google-Smtp-Source: APXvYqykyBV7giAm3hizlF3iPjfzX2FbX6ALdT448WAIbJMuy0xPY7M3SKjnS/MOdKBmweybZ/mY X-Received: by 2002:aca:1108:: with SMTP id 8mr711516oir.127.1581339110780; Mon, 10 Feb 2020 04:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339110; cv=none; d=google.com; s=arc-20160816; b=GKtPP6ScuCMkWdQ29I4D6VE2Lx1CThHtvIKcDYS3xqk5rrEosn9cJxPVccepdQC4vN TMw1Kmd0IxZ+sWUdHSY8l7lDZJjWAJGHhSVPtch2Bvef4AOxHsfx/k1+4e2igo8iwxui FGcGQYGMWITV9KOwgHvuZNldgCM+v33f6NOZig6c/9o6x0m3BzlzvYs+9dxf6+GMhOdx r8HkpOYKgDXTSP8iS7MzWSi7JGnEPPiDf/aVm6KNqt8Z8DXEhpKL6aN8y9Q6YPzWIWJC nsrlhw9qhjCDYyuN7YRtHOc0kovoK/mceJxEW6xxiPtGqDFr2p1jPp2iyGrbZB/OkaZD WRig== 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=Z6iVNh5v/Vfhu5h+eObRoHZ3MkCWNLou+AI25O2iZSI=; b=mg/2mdVKK+5cp25YS22F7hHjKIh5tZwXhfeFCoI3SwO/VRLRFmfAIDf8CUkJIbaq8b uqouLVMFdFtFmq8LslE6yU7EaYT5ZZaY05XmLOvOWG7105NfILDG0Ax++HbFvj4InKaI P6uj/GjOXoQ+pCxC2tsvwFUSt77sVCGd8CXnhZUObMsFGt3VbrY+1tDU0jaUvyo8xyb9 FQdpnVDA0g/82VbEiq1lBYjJvzfFHIZ+nehKrUzT5SgQ3HMyMUUbeVkFNThlXVGaFWo9 OM/Y31Vl7+XSfMpxTFq+MGtf+4L+aeo70A3iEWfaJpCVutJySXIYZKpp2/lknxJio6rU oJ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="q/OA4twY"; 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 j18si158996otq.275.2020.02.10.04.51.38; Mon, 10 Feb 2020 04:51:50 -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="q/OA4twY"; 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 S1730449AbgBJMnd (ORCPT + 99 others); Mon, 10 Feb 2020 07:43:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:38920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729589AbgBJMj7 (ORCPT ); Mon, 10 Feb 2020 07:39:59 -0500 Received: from localhost (unknown [209.37.97.194]) (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 D03BE2467A; Mon, 10 Feb 2020 12:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338397; bh=HRQkpN1Mvq7ucN4kQwhBOlr26goTcPiQ9hquQc7J3I8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q/OA4twYlMh2K36bbzUwpVU5avMbHiaL9MdqVA6mDzEj3WfzuXP4dYg4bMaDHB5o0 /JGbragqr+qLbTv9dnRpQ+X0IUmBK2qYr1oKlYduPSK6Py6MVCufUJRiYxu3ulj68r XrKdkLQTG9Un7/DnpfPcXVtqUP/wrPWJ2dpOvkGU= 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 5.5 094/367] mmc: spi: Toggle SPI polarity, do not hardcode it Date: Mon, 10 Feb 2020 04:30:07 -0800 Message-Id: <20200210122433.043504041@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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 @@ -1134,17 +1134,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,