Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp396697imm; Thu, 30 Aug 2018 01:24:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZBl97+cxkg1iPevT0F/ocrOQMPJJM3+gYkI0Q8Z7VVp+hwhUjfTuD64efb8GMZGPWTZf8E X-Received: by 2002:a63:6106:: with SMTP id v6-v6mr8970988pgb.100.1535617443006; Thu, 30 Aug 2018 01:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535617442; cv=none; d=google.com; s=arc-20160816; b=lGcLmkq07QnzsAecbpqiuwD1RO4/asDXndbJyo2VGJABSLKvpU2Mbpu8CeS2tBQrLi jR5X7da8FVuCv079ld+RW7onv1NV1qUXHE4fNV0rtY75n8nnwAo7/NXp1Eh5x6uGGEJy j4o3J4N7QDGm6qsmvTGMhoExZQFmB1LRxEwx8e5K8QThv22jqaAuYVD/oca2fsCreONC YQKPM9RUJ8GplMP0+F4mVgy0od0J49iRjc7MsbH6uSLe8uSquM+yGGW7jFnQ1G0IObuQ OQ7va4l5qqS7PkXj8l1uwnF2+ZN6iLlTMOFxkdiLS6vqUtnpm96wqipv927x4Y2hhYFQ Pjfw== 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:arc-authentication-results; bh=wEk8L8aXukkJv1K6t9rubtGOMku4W8yH0JTNZ/Ehvmg=; b=LO4pGmTnvyKbfxqdfyUiYCBpqfz+z2htSZufZNjuuVZ0HHiSY+gPeuDHAUGbAtAUmH 2K0mwxujYltGC1NjLNXvhTwNHOmkWAYkcN5HAx8xGDxFwexcO/6E9IGjrrAkXv1Rqen0 jD6oHcrWEOikuXNM4+kUJ01QtQl6aTac6pLw8hJG67U7nbe0EiRyCAMfO58nkcWIie9e xC7Avgt+f/ZwWETD9c5iHSK7Kj+ZvQgp5Ts2VX4iVlzlA0bvTc3TpoDNMLR2PWdODYty OiGyrFk4v1lSjAyIxQsEC7yhTy7x9ffAVXFWfO7D3tyLcaInLdWjfLTaMED78v+18W2r qmTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LR3hnZwZ; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8-v6si5745924pfo.128.2018.08.30.01.23.47; Thu, 30 Aug 2018 01:24:02 -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=@linaro.org header.s=google header.b=LR3hnZwZ; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728082AbeH3MXX (ORCPT + 99 others); Thu, 30 Aug 2018 08:23:23 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45459 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbeH3MXW (ORCPT ); Thu, 30 Aug 2018 08:23:22 -0400 Received: by mail-pl1-f194.google.com with SMTP id j8-v6so3505420pll.12 for ; Thu, 30 Aug 2018 01:22:24 -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=wEk8L8aXukkJv1K6t9rubtGOMku4W8yH0JTNZ/Ehvmg=; b=LR3hnZwZZEkZzI5hV1ypiw2l3mKEZ19A/ZP0BkAhK6W2995DsTGuLCGpLfACwJFIMp QC1HT2cRxZjjRYzl9EDTMowmO34FS1mKPb5nNM4+Duc5hVJSaWIbR0P4mC+6MtVVg3UU VQXO4qaMd4H1WK9FPwCGYj0R0JTfMbwQ3crMU= 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:in-reply-to :references; bh=wEk8L8aXukkJv1K6t9rubtGOMku4W8yH0JTNZ/Ehvmg=; b=aWdrXAVWFtj9DMpP+aoQrXjLcCgEihDK2j/zxVfNL/YeuHTPF95fybtregVgA4AsN3 Kmqdd2d5NnmrtvqPzZbvjFYHHBIVKoCAsg4OBQyaIQvaBDhbJ+v4gHpKCxIrI762Wqxx wx/M7dH8ztQRVzfFH7we8cGo0bkRyBOmZPiWbDhOiPwyPyY2aJvj/oLqLLrth67Kurx3 iEF7p9hwZX1RSs9O6IgziAURV5kPYYVh1L0jU5pKF73GGZhwJTJRq/oXG96Xm8Tsmn1l IjEpwyM9Wo50rfNWn/L8973v4YrIAvyL+CamHGAWRJN1UsEZQeX9A0g4xiJYVw9XiZv2 m8Ag== X-Gm-Message-State: APzg51D+XzpcaEw4K2nUZflvHm8O0/Nz/KlwSgioVFWhhrAbCRDxJFGd Y+vDMTgcopHitXgZjDqiwS1Onw== X-Received: by 2002:a17:902:722:: with SMTP id 31-v6mr9137959pli.207.1535617344557; Thu, 30 Aug 2018 01:22:24 -0700 (PDT) Received: from ubt.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id j22-v6sm8224885pfh.45.2018.08.30.01.22.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Aug 2018 01:22:23 -0700 (PDT) From: Chunyan Zhang To: Ulf Hansson , Adrian Hunter , Rob Herring Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Orson Zhai , Baolin Wang , Billows Wu , Jason Wu , Chunyan Zhang , Chunyan Zhang Subject: [PATCH V8 6/9] mmc: sdhci: Add Auto CMD Auto Select support Date: Thu, 30 Aug 2018 16:21:42 +0800 Message-Id: <1535617305-16952-7-git-send-email-zhang.chunyan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535617305-16952-1-git-send-email-zhang.chunyan@linaro.org> References: <1535617305-16952-1-git-send-email-zhang.chunyan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As SD Host Controller Specification v4.10 documents: Host Controller Version 4.10 defines this "Auto CMD Auto Select" mode. Selection of Auto CMD depends on setting of CMD23 Enable in the Host Control 2 register which indicates whether card supports CMD23. If CMD23 Enable =1, Auto CMD23 is used and if CMD23 Enable =0, Auto CMD12 is used. In case of Version 4.10 or later, use of Auto CMD Auto Select is recommended rather than use of Auto CMD12 Enable or Auto CMD23 Enable. This patch add this new mode support. Signed-off-by: Chunyan Zhang Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci.c | 49 ++++++++++++++++++++++++++++++++++++++---------- drivers/mmc/host/sdhci.h | 2 ++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 604bf4c..62d843ac90 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1095,6 +1095,43 @@ static inline bool sdhci_auto_cmd12(struct sdhci_host *host, !mrq->cap_cmd_during_tfr; } +static inline void sdhci_auto_cmd_select(struct sdhci_host *host, + struct mmc_command *cmd, + u16 *mode) +{ + bool use_cmd12 = sdhci_auto_cmd12(host, cmd->mrq) && + (cmd->opcode != SD_IO_RW_EXTENDED); + bool use_cmd23 = cmd->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23); + u16 ctrl2; + + /* + * In case of Version 4.10 or later, use of 'Auto CMD Auto + * Select' is recommended rather than use of 'Auto CMD12 + * Enable' or 'Auto CMD23 Enable'. + */ + if (host->version >= SDHCI_SPEC_410 && (use_cmd12 || use_cmd23)) { + *mode |= SDHCI_TRNS_AUTO_SEL; + + ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); + if (use_cmd23) + ctrl2 |= SDHCI_CMD23_ENABLE; + else + ctrl2 &= ~SDHCI_CMD23_ENABLE; + sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); + + return; + } + + /* + * If we are sending CMD23, CMD12 never gets sent + * on successful completion (so no Auto-CMD12). + */ + if (use_cmd12) + *mode |= SDHCI_TRNS_AUTO_CMD12; + else if (use_cmd23) + *mode |= SDHCI_TRNS_AUTO_CMD23; +} + static void sdhci_set_transfer_mode(struct sdhci_host *host, struct mmc_command *cmd) { @@ -1123,17 +1160,9 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host, if (mmc_op_multi(cmd->opcode) || data->blocks > 1) { mode = SDHCI_TRNS_BLK_CNT_EN | SDHCI_TRNS_MULTI; - /* - * If we are sending CMD23, CMD12 never gets sent - * on successful completion (so no Auto-CMD12). - */ - if (sdhci_auto_cmd12(host, cmd->mrq) && - (cmd->opcode != SD_IO_RW_EXTENDED)) - mode |= SDHCI_TRNS_AUTO_CMD12; - else if (cmd->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) { - mode |= SDHCI_TRNS_AUTO_CMD23; + sdhci_auto_cmd_select(host, cmd, &mode); + if (cmd->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) sdhci_writel(host, cmd->mrq->sbc->arg, SDHCI_ARGUMENT2); - } } if (data->flags & MMC_DATA_READ) diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index f7a1079..4a19ff8 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -42,6 +42,7 @@ #define SDHCI_TRNS_BLK_CNT_EN 0x02 #define SDHCI_TRNS_AUTO_CMD12 0x04 #define SDHCI_TRNS_AUTO_CMD23 0x08 +#define SDHCI_TRNS_AUTO_SEL 0x0C #define SDHCI_TRNS_READ 0x10 #define SDHCI_TRNS_MULTI 0x20 @@ -185,6 +186,7 @@ #define SDHCI_CTRL_DRV_TYPE_D 0x0030 #define SDHCI_CTRL_EXEC_TUNING 0x0040 #define SDHCI_CTRL_TUNED_CLK 0x0080 +#define SDHCI_CMD23_ENABLE 0x0800 #define SDHCI_CTRL_V4_MODE 0x1000 #define SDHCI_CTRL_64BIT_ADDR 0x2000 #define SDHCI_CTRL_PRESET_VAL_ENABLE 0x8000 -- 2.7.4