Skip to content

Commit 427b651

Browse files
Chunyan Zhangstorulf
authored andcommitted
mmc: sdhci: Add Auto CMD Auto Select support
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 <zhang.chunyan@linaro.org> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent e65953d commit 427b651

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

drivers/mmc/host/sdhci.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,43 @@ static inline bool sdhci_auto_cmd12(struct sdhci_host *host,
11041104
!mrq->cap_cmd_during_tfr;
11051105
}
11061106

1107+
static inline void sdhci_auto_cmd_select(struct sdhci_host *host,
1108+
struct mmc_command *cmd,
1109+
u16 *mode)
1110+
{
1111+
bool use_cmd12 = sdhci_auto_cmd12(host, cmd->mrq) &&
1112+
(cmd->opcode != SD_IO_RW_EXTENDED);
1113+
bool use_cmd23 = cmd->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23);
1114+
u16 ctrl2;
1115+
1116+
/*
1117+
* In case of Version 4.10 or later, use of 'Auto CMD Auto
1118+
* Select' is recommended rather than use of 'Auto CMD12
1119+
* Enable' or 'Auto CMD23 Enable'.
1120+
*/
1121+
if (host->version >= SDHCI_SPEC_410 && (use_cmd12 || use_cmd23)) {
1122+
*mode |= SDHCI_TRNS_AUTO_SEL;
1123+
1124+
ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1125+
if (use_cmd23)
1126+
ctrl2 |= SDHCI_CMD23_ENABLE;
1127+
else
1128+
ctrl2 &= ~SDHCI_CMD23_ENABLE;
1129+
sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2);
1130+
1131+
return;
1132+
}
1133+
1134+
/*
1135+
* If we are sending CMD23, CMD12 never gets sent
1136+
* on successful completion (so no Auto-CMD12).
1137+
*/
1138+
if (use_cmd12)
1139+
*mode |= SDHCI_TRNS_AUTO_CMD12;
1140+
else if (use_cmd23)
1141+
*mode |= SDHCI_TRNS_AUTO_CMD23;
1142+
}
1143+
11071144
static void sdhci_set_transfer_mode(struct sdhci_host *host,
11081145
struct mmc_command *cmd)
11091146
{
@@ -1132,17 +1169,9 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
11321169

11331170
if (mmc_op_multi(cmd->opcode) || data->blocks > 1) {
11341171
mode = SDHCI_TRNS_BLK_CNT_EN | SDHCI_TRNS_MULTI;
1135-
/*
1136-
* If we are sending CMD23, CMD12 never gets sent
1137-
* on successful completion (so no Auto-CMD12).
1138-
*/
1139-
if (sdhci_auto_cmd12(host, cmd->mrq) &&
1140-
(cmd->opcode != SD_IO_RW_EXTENDED))
1141-
mode |= SDHCI_TRNS_AUTO_CMD12;
1142-
else if (cmd->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) {
1143-
mode |= SDHCI_TRNS_AUTO_CMD23;
1172+
sdhci_auto_cmd_select(host, cmd, &mode);
1173+
if (cmd->mrq->sbc && (host->flags & SDHCI_AUTO_CMD23))
11441174
sdhci_writel(host, cmd->mrq->sbc->arg, SDHCI_ARGUMENT2);
1145-
}
11461175
}
11471176

11481177
if (data->flags & MMC_DATA_READ)

drivers/mmc/host/sdhci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define SDHCI_TRNS_BLK_CNT_EN 0x02
4343
#define SDHCI_TRNS_AUTO_CMD12 0x04
4444
#define SDHCI_TRNS_AUTO_CMD23 0x08
45+
#define SDHCI_TRNS_AUTO_SEL 0x0C
4546
#define SDHCI_TRNS_READ 0x10
4647
#define SDHCI_TRNS_MULTI 0x20
4748

@@ -185,6 +186,7 @@
185186
#define SDHCI_CTRL_DRV_TYPE_D 0x0030
186187
#define SDHCI_CTRL_EXEC_TUNING 0x0040
187188
#define SDHCI_CTRL_TUNED_CLK 0x0080
189+
#define SDHCI_CMD23_ENABLE 0x0800
188190
#define SDHCI_CTRL_V4_MODE 0x1000
189191
#define SDHCI_CTRL_64BIT_ADDR 0x2000
190192
#define SDHCI_CTRL_PRESET_VAL_ENABLE 0x8000

0 commit comments

Comments
 (0)