From patchwork Thu Oct 20 08:19:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 78440 Delivered-To: patches@linaro.org Received: by 10.140.97.247 with SMTP id m110csp657219qge; Thu, 20 Oct 2016 01:19:56 -0700 (PDT) X-Received: by 10.25.29.82 with SMTP id d79mr8383372lfd.52.1476951596481; Thu, 20 Oct 2016 01:19:56 -0700 (PDT) Return-Path: Received: from mail-lf0-x232.google.com (mail-lf0-x232.google.com. [2a00:1450:4010:c07::232]) by mx.google.com with ESMTPS id u186si13134582lja.80.2016.10.20.01.19.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2016 01:19:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) client-ip=2a00:1450:4010:c07::232; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::232 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x232.google.com with SMTP id b81so71605931lfe.1 for ; Thu, 20 Oct 2016 01:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nWQQNJjlAEGR/N8g6kzfTLuAOfFKRPSma3pjgHkKhFk=; b=hHsYhZy+Ddl02eFKhyGulaIERkbaQ36JcVnbzH0zrrVl14afcJ7Sr/fAFqa7RARfdh ACn3bL0tQiADaBjpwKNlwgAaHtt6ONKkPS03cEOoZHRy3mflCY352yZIz0NCjECZlP+M KQhKrpXD1i1tSiuY7N8PO7OrZj3xzwZwbhvAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nWQQNJjlAEGR/N8g6kzfTLuAOfFKRPSma3pjgHkKhFk=; b=il2DtUAamlXXvY8I42hiPBl0sm5XcXpXvWTiTNj/XJQxlsvi7lYFgZbYnwyg1fL5ew ilz36BCrOlN+xkVNSkWdtVYLTcw+B+HyHDqFwBR+rIsd9HT8nRlMJvurdpcwfYEmto6b h9RXWCR1AX7KkTe9G3vr5tAQtPkpxzyHAR5L2/aiXyWng3z0mVWdcfHHvcyTWufexEYL DyqTou+9/JUeQn/WioFdJkc2QrZwLY4JggD1Sdx5G8/nlr8v6iwYlh4clNri197dwkKU aVdEAKDTtmnEYu+vvQlUn6phfwHSB32OpqrKUHQ2tfo5NHHgWz1kNAsXOhfhUKU8ApN+ Sapw== X-Gm-Message-State: AA6/9Rlw9TMeSnUh9VspRbq5FpHBQPCQSfTUa8umTtAqsVulDNaCduDir+uFdRb/2WZIfAwaCic= X-Received: by 10.25.216.3 with SMTP id p3mr9834827lfg.113.1476951595938; Thu, 20 Oct 2016 01:19:55 -0700 (PDT) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id h7sm11672584ljh.21.2016.10.20.01.19.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Oct 2016 01:19:54 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung , Adrian Hunter , Linus Walleij , Chaotian Jing Subject: [PATCH 2/4] mmc: core: Clarify code which deals with polling in __mmc_switch() Date: Thu, 20 Oct 2016 10:19:37 +0200 Message-Id: <1476951579-26125-3-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1476951579-26125-1-git-send-email-ulf.hansson@linaro.org> References: <1476951579-26125-1-git-send-email-ulf.hansson@linaro.org> The __mmc_switch() deserves a clean-up. In this step, let's move some code outside of the do-while loop, which deal deals with the card busy polling. This change simplifies the code in that sense that it becomes easier to follow what is being executed during card busy polling, but it also gives a better understanding for when polling isn't done. Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index f9af1c0..5a77af7 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -535,18 +535,29 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, if (!use_busy_signal) goto out; - /* - * CRC errors shall only be ignored in cases were CMD13 is used to poll - * to detect busy completion. - */ - if ((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) - ignore_crc = false; + /*If SPI or used HW busy detection above, then we don't need to poll. */ + if (((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) || + mmc_host_is_spi(host)) { + if (send_status) + err = mmc_switch_status(card); + goto out; + } /* We have an unspecified cmd timeout, use the fallback value. */ if (!timeout_ms) timeout_ms = MMC_OPS_TIMEOUT_MS; - /* Must check status to be sure of no errors. */ + /* + * In cases when not allowed to poll by using CMD13 or because we aren't + * capable of polling by using ->card_busy(), then rely on waiting the + * stated timeout to be sufficient. + */ + if (!send_status && !host->ops->card_busy) { + mmc_delay(timeout_ms); + goto out; + } + + /* Let's poll to find out when the command is completed. */ timeout = jiffies + msecs_to_jiffies(timeout_ms) + 1; do { /* @@ -560,25 +571,11 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, if (err) goto out; } - if ((host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) - break; if (host->ops->card_busy) { if (!host->ops->card_busy(host)) break; busy = true; } - if (mmc_host_is_spi(host)) - break; - - /* - * We are not allowed to issue a status command and the host - * does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only - * rely on waiting for the stated timeout to be sufficient. - */ - if (!send_status && !host->ops->card_busy) { - mmc_delay(timeout_ms); - goto out; - } /* Timeout if the device never leaves the program state. */ if (expired &&