Skip to content

Commit e89d456

Browse files
andreiwcjb
authored andcommitted
mmc: sdhci: Implement MMC_CAP_CMD23 for SDHCI.
Implements support for multiblock transfers bounded by SET_BLOCK_COUNT (CMD23). Signed-off-by: Andrei Warkentin <andreiw@motorola.com> Signed-off-by: Chris Ball <cjb@laptop.org>
1 parent d0c97cf commit e89d456

3 files changed

Lines changed: 49 additions & 17 deletions

File tree

‎drivers/mmc/host/sdhci.c‎

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -838,21 +838,25 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
838838
}
839839

840840
static void sdhci_set_transfer_mode(struct sdhci_host *host,
841-
struct mmc_data *data)
841+
struct mmc_command *cmd)
842842
{
843843
u16 mode;
844+
struct mmc_data *data = cmd->data;
844845

845846
if (data == NULL)
846847
return;
847848

848849
WARN_ON(!host->data);
849850

850851
mode = SDHCI_TRNS_BLK_CNT_EN;
851-
if (data->blocks > 1) {
852-
if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
853-
mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
854-
else
855-
mode |= SDHCI_TRNS_MULTI;
852+
if (mmc_op_multi(cmd->opcode) || data->blocks > 1) {
853+
mode |= SDHCI_TRNS_MULTI;
854+
/*
855+
* If we are sending CMD23, CMD12 never gets sent
856+
* on successful completion (so no Auto-CMD12).
857+
*/
858+
if (!host->mrq->sbc && (host->flags & SDHCI_AUTO_CMD12))
859+
mode |= SDHCI_TRNS_AUTO_CMD12;
856860
}
857861
if (data->flags & MMC_DATA_READ)
858862
mode |= SDHCI_TRNS_READ;
@@ -893,7 +897,15 @@ static void sdhci_finish_data(struct sdhci_host *host)
893897
else
894898
data->bytes_xfered = data->blksz * data->blocks;
895899

896-
if (data->stop) {
900+
/*
901+
* Need to send CMD12 if -
902+
* a) open-ended multiblock transfer (no CMD23)
903+
* b) error in multiblock transfer
904+
*/
905+
if (data->stop &&
906+
(data->error ||
907+
!host->mrq->sbc)) {
908+
897909
/*
898910
* The controller needs a reset of internal state machines
899911
* upon error conditions.
@@ -949,7 +961,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
949961

950962
sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT);
951963

952-
sdhci_set_transfer_mode(host, cmd->data);
964+
sdhci_set_transfer_mode(host, cmd);
953965

954966
if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
955967
printk(KERN_ERR "%s: Unsupported response type!\n",
@@ -1004,13 +1016,21 @@ static void sdhci_finish_command(struct sdhci_host *host)
10041016

10051017
host->cmd->error = 0;
10061018

1007-
if (host->data && host->data_early)
1008-
sdhci_finish_data(host);
1019+
/* Finished CMD23, now send actual command. */
1020+
if (host->cmd == host->mrq->sbc) {
1021+
host->cmd = NULL;
1022+
sdhci_send_command(host, host->mrq->cmd);
1023+
} else {
10091024

1010-
if (!host->cmd->data)
1011-
tasklet_schedule(&host->finish_tasklet);
1025+
/* Processed actual command. */
1026+
if (host->data && host->data_early)
1027+
sdhci_finish_data(host);
10121028

1013-
host->cmd = NULL;
1029+
if (!host->cmd->data)
1030+
tasklet_schedule(&host->finish_tasklet);
1031+
1032+
host->cmd = NULL;
1033+
}
10141034
}
10151035

10161036
static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
@@ -1189,7 +1209,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
11891209
#ifndef SDHCI_USE_LEDS_CLASS
11901210
sdhci_activate_led(host);
11911211
#endif
1192-
if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
1212+
1213+
/*
1214+
* Ensure we don't send the STOP for non-SET_BLOCK_COUNTED
1215+
* requests if Auto-CMD12 is enabled.
1216+
*/
1217+
if (!mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) {
11931218
if (mrq->stop) {
11941219
mrq->data->stop = NULL;
11951220
mrq->stop = NULL;
@@ -1227,7 +1252,10 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
12271252
host->mrq = mrq;
12281253
}
12291254

1230-
sdhci_send_command(host, mrq->cmd);
1255+
if (mrq->sbc)
1256+
sdhci_send_command(host, mrq->sbc);
1257+
else
1258+
sdhci_send_command(host, mrq->cmd);
12311259
}
12321260

12331261
mmiowb();
@@ -2455,7 +2483,10 @@ int sdhci_add_host(struct sdhci_host *host)
24552483
} else
24562484
mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
24572485

2458-
mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE;
2486+
mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE | MMC_CAP_CMD23;
2487+
2488+
if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
2489+
host->flags |= SDHCI_AUTO_CMD12;
24592490

24602491
/*
24612492
* A controller may support 8-bit width, but the board itself

‎drivers/mmc/host/sdhci.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define SDHCI_TRANSFER_MODE 0x0C
3737
#define SDHCI_TRNS_DMA 0x01
3838
#define SDHCI_TRNS_BLK_CNT_EN 0x02
39-
#define SDHCI_TRNS_ACMD12 0x04
39+
#define SDHCI_TRNS_AUTO_CMD12 0x04
4040
#define SDHCI_TRNS_READ 0x10
4141
#define SDHCI_TRNS_MULTI 0x20
4242

‎include/linux/mmc/sdhci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct sdhci_host {
113113
#define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */
114114
#define SDHCI_SDR50_NEEDS_TUNING (1<<4) /* SDR50 needs tuning */
115115
#define SDHCI_NEEDS_RETUNING (1<<5) /* Host needs retuning */
116+
#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
116117

117118
unsigned int version; /* SDHCI spec. version */
118119

0 commit comments

Comments
 (0)