From patchwork Wed Dec 4 15:27:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 180801 Delivered-To: patch@linaro.org Received: by 2002:ac9:3d8b:0:0:0:0:0 with SMTP id u11csp773672oce; Wed, 4 Dec 2019 07:29:57 -0800 (PST) X-Google-Smtp-Source: APXvYqzc8vdc/QvqQozqu2p33RYU/E/bZ7pO++kC3MnCsPsV/P9BXoIud9LwkQrJGqMN3eoQLrWi X-Received: by 2002:a05:6808:682:: with SMTP id k2mr2980721oig.66.1575473397641; Wed, 04 Dec 2019 07:29:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575473397; cv=none; d=google.com; s=arc-20160816; b=lzJ7QYtpsQrVZ++xjzyvSuOF0mEjH3vAspiF9i2P23oW3lunduN0PBHYxAtvG/LwR1 bFjWJPRvG6GguLCvpVUqxVSzyxIBIeQqaO4Lwdq99ubfpSXsh7P8riBCCB5hyYaCwXeJ OJAoLRmBteEd4c9wCQbareLSZkmEizwRjJMBvvBQ6j2KvrDtni8Av3X3tPuo2ZBD6H5z xDd0XODDWi05QmgxFfl8dc6CacTdaaPGPZZS+Wv8EZrfDbG/fFCC35sEjCUEw7srAyfA TozUOIMAfcE6ahog6vxOCDXWrATJMMnSJIhugcYCCIRXQ7of35fzyN2cQb5yR2cJmWvC Yvlg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=hh+2OcavXB15OGxTYL4jecF4eOIrv2i3m1HUxqh0x6s=; b=uWYbITxPDeUpsWPi0N5EckpXbo6dbOZz32DkG8jh1VnDMetjbWmP9Vv6EZ3DYy1x4C X95yCZIuJjnyEdqYSL34wg/tm7TdDgwEbj1STf38FSWLp052Bej0BjehgU2zovLmwhOU GFG/rAdbCfQm2hdsQGqkr3SIpz3s+Y1zMQZaR+695+Ermri4gTWu3XiULksmoOjxVQLY VMRHVFIsRUU7R69w4a8f3PGtXi1Q+tHFE65Y5Q0I/hqUIuKAeP0Hutx9AxCPhPma5sDS 8nBSJhE/puDeLlR960OwuW84SPhRMBA868XQEYxNSLJ5nRr1+b/TtgkqW/LcsmTM656U j1ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wieo/eEh"; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t185si2267637oib.39.2019.12.04.07.29.57; Wed, 04 Dec 2019 07:29:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-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=@linaro.org header.s=google header.b="wieo/eEh"; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728469AbfLDP35 (ORCPT + 5 others); Wed, 4 Dec 2019 10:29:57 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33714 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728404AbfLDP34 (ORCPT ); Wed, 4 Dec 2019 10:29:56 -0500 Received: by mail-lj1-f196.google.com with SMTP id 21so8643085ljr.0 for ; Wed, 04 Dec 2019 07:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hh+2OcavXB15OGxTYL4jecF4eOIrv2i3m1HUxqh0x6s=; b=wieo/eEhlMvYs5dl90GYC772puj0todz8UmUA4dxHFb80RN0va4xTredLrqntb6oFp qZ1mcbzC7XaPVkF3kxOleDQPxvX6HbEpSfz1075Y2kK/tKMu6e8LDJ90ipS4kkFrZb/x Sab1ghDVsWYwIJG8qfjP7HvD6XXCUm6IA9qh5XgGVhL4Ro24ViG3KDCa36uquqzJE60t 76hBpikCAQvBtG750EBpq92sStHPSmnNr7rgWEN5+W15v+G7kXhNjGaOqXoC5P42wKD/ rtTUuKq+bmjqX128T/haMQ6J0dQTXNSYcSyYNz4qD7PIkLS4uZlQ9gjQHgva7zihq4yr aunw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hh+2OcavXB15OGxTYL4jecF4eOIrv2i3m1HUxqh0x6s=; b=DvOMsF4qowQcXwzo5doZYPMVhchqmp0rsB+qoDgbNDJ6JjRaxjEkh1+WpqjsMfG7LT Ad3IoL/c+TySl19rscvaEBJc1L7ya1jyHvPnVVaFgh5R+5+5jBvhPgSF1Mz1KAARsa/y s0+KMGPDrwxN7OSelJWTqTxkA2BiWO+AuWutW8+O21GK8JvdXH8hPTGctEtaARCQExpp Tfoeisye2kYAEjkWtFBKUZYHkDJC7Nq0VsxHmhAC2nTD8I0Mfu92qZOzws0FWe+vB5Gf BZ8ginq+Dfr6KJr+ONNkw33DNPTSyV3vVyV7cfntuKJsSQjrSElF1bJWfH+xfstIiB4/ tVzw== X-Gm-Message-State: APjAAAWFDm3ckzZvqk8QTJzZLguTDmrG71uHpc7mNF9ruvOyFiA91Rl0 w3Ks1c16MWoNOsBBITFg9fHOQb5U4VgP9g== X-Received: by 2002:a2e:3312:: with SMTP id d18mr2425332ljc.222.1575473393209; Wed, 04 Dec 2019 07:29:53 -0800 (PST) Received: from localhost.localdomain (c-21cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.33]) by smtp.gmail.com with ESMTPSA id u7sm3516856lfn.31.2019.12.04.07.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 07:29:51 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij , Phil Elwell , Mark Brown Subject: [PATCH] mmc: spi: Toggle SPI polarity, do not hardcode it Date: Wed, 4 Dec 2019 16:27:49 +0100 Message-Id: <20191204152749.12652-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org 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 --- drivers/mmc/host/mmc_spi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) -- 2.23.0 Reviewed-by: Mark Brown diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 74c6cfbf9172..1f02f54f09c0 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -1134,17 +1134,22 @@ static void mmc_spi_initsequence(struct mmc_spi_host *host) * 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,