Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp307702imm; Wed, 29 Aug 2018 00:05:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbG51L7MsfRSRbiwzrOdNzNagagK4wXhCQcaUaze8IsH6ihFUsn4XZDAw1PH2h2eejeIxJC X-Received: by 2002:a62:3ac8:: with SMTP id v69-v6mr4634924pfj.164.1535526319996; Wed, 29 Aug 2018 00:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535526319; cv=none; d=google.com; s=arc-20160816; b=ur54IwUhreJ1xcYsKebGaEfukSmzrNuWH03NEIbVzUnnwMB7LF/h6EMR9mFMUNR2uS /BIeDtqsZ6r3lnio7bscpQKpWKTPsQlAbJZI4Fg6HIvFEWGORYiW0XqldAq+1fBGBXA9 x/fiyxQc7sLzKATPfh736eqSCj0rjd64S8P/t8rJUH7K0uIzR+H6f2D1kTDPnTl+qxme YhOkAe4e3qFwrQ9I9nnmOxj6VZZySGzmastnYJbg7rfh+MHCsT6MeZQr0Y7DFiaQNh63 ntCdK3EVGkcGR7Tx/VoHru75PaHD4svxgFvEFH1tDOupjipo+JoLdcevOs4e0Rq+o08d p7Kg== 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=9gO45GPUCiWNoJSPPW5yykw6lOn1on3+rP/v8SuzWGk=; b=aesYZPItCUI9Xsne5iucEPbwy9Pe20KLa7cuURzSpY06Bx2JyNwI9M/6XnhNNGxRBA pdbN39zsWVfnVpI67tZn3szx6FHmo4lGBsJUfRnSsJ5IB5e1KvUCRRIf8FMN/mokRCB4 4ovhmCOHWg9pUfkCDvE23Ql2AzDIqMkoHHnnJGCpGrn2/KMyOF+fte44I2xpTjePbAxH K5X9AQfa1ypTehGLLVn5j1l5k9piy9+KnvES7XxQyVd3x0q7kBDz6+KCgIifiNLdSoTO 6C4WKigAv1I9CbHZmC948V/xhBYyHUgrXU7AOyYiEry0XUn5UQoshBgSUJd55H3nZkFF TWLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QBFWRQX0; 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 u1-v6si3494666plm.143.2018.08.29.00.05.05; Wed, 29 Aug 2018 00:05:19 -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=QBFWRQX0; 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 S1727773AbeH2K7G (ORCPT + 99 others); Wed, 29 Aug 2018 06:59:06 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46926 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727172AbeH2K7F (ORCPT ); Wed, 29 Aug 2018 06:59:05 -0400 Received: by mail-pg1-f194.google.com with SMTP id b129-v6so1903607pga.13 for ; Wed, 29 Aug 2018 00:03:40 -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=9gO45GPUCiWNoJSPPW5yykw6lOn1on3+rP/v8SuzWGk=; b=QBFWRQX0gaMKEq94OiPVi2I1NokcHktXgosg718cMFPkhord4M7chknNgxq8A2jmQj x06VfYu0EJETEi2z/cDBCJCJ0siqFU0S5OPRdYA9iXvj1SgN9zgcWt3HBSVW8vWLILlz 2OvFYmmAM+K2bS4ZEIoUgPzpEeGwH0MVRT/tI= 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=9gO45GPUCiWNoJSPPW5yykw6lOn1on3+rP/v8SuzWGk=; b=F2JhdB7VslOG0Fpf5CpjEZZWUYrMR1Hg0ZufA1L0fXrtuotIF/c5kBrXwdF8xUF3Ew 9cC220mHXuIGtRaw2Jzx7Uk4nk79MPaxzeC/EVMx8D8HPl8CI6GBJ+9V6tcHEmYGXaQn 0onG5r3G7A1pzQm8MhUvmrvkWtf7WsSLoHBHWvLCfhmAXA+l0YfA+3DiipQmkHVqrhKr b1/unn1xp1h+xRQhyKUOWYVA4q9bKziDX42axLYvl/u8HSZFuNYKRWb8oU9YFG4XnaxK QY4FYOOKBZg8Zbwq9dy8/R7o7z2F7RuMB+QvxNM5kEAFAphsDEc99dYkVPviRKLYqbSE dCIA== X-Gm-Message-State: APzg51CpT5Si0bZUiZ8Bao/fxG7ImLLsLMetsXr+Wk+fSxsJLJPrS5nh yAJvHjC2nYbhQSR4Cn2N0ElHJg== X-Received: by 2002:a65:5189:: with SMTP id h9-v6mr4598889pgq.13.1535526220465; Wed, 29 Aug 2018 00:03:40 -0700 (PDT) Received: from ubt.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d81-v6sm4317342pfj.122.2018.08.29.00.03.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Aug 2018 00:03:39 -0700 (PDT) From: Chunyan Zhang To: Ulf Hansson , Adrian Hunter 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 V7 6/9] mmc: sdhci: Add Auto CMD Auto Select support Date: Wed, 29 Aug 2018 15:03:01 +0800 Message-Id: <1535526184-32718-7-git-send-email-zhang.chunyan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535526184-32718-1-git-send-email-zhang.chunyan@linaro.org> References: <1535526184-32718-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 --- 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