Add Support for ADMA2 in SDHCI
cover Add Support for ADMA2 in SDHCI
The following patches add support for ADMA2 in SDHCI.
Tested with Am65x_evm with some out of tree patches unrelated to MMC.
Faiz Abbas (2):
mmc: sdhci: Move DMA handling to prepare_dma() function
mmc: sdhci: Add Support for ADMA2
drivers/mmc/Kconfig | 14 ++++ drivers/mmc/sdhci.c | 188 +++++++++++++++++++++++++++++++++----------- include/sdhci.h | 44 +++++++++++ 3 files changed, 202 insertions(+), 44 deletions(-)
Signature · 1 line
2.19.2
PATCH 1/2 mmc: sdhci: Move DMA handling to prepare_dma() function
In preparation for addition of ADMA2 support, cleanup SDMA handling by moving it to a new sdhci_prepare_dma() function. Also add a flags field in sdhci_host to indicate if DMA is enabled.
--- drivers/mmc/sdhci.c | 92 ++++++++++++++++++++++++--------------------- include/sdhci.h | 3 ++ 2 files changed, 53 insertions(+), 42 deletions(-)
drivers/mmc/sdhci.c +50 -42
@@ -67,18 +67,52 @@ static void sdhci_transfer_pio(struct sdhci_host *host, struct mmc_data *data)sdhci_writel (host, *(u32 *)offs,SDHCI_BUFFER ); } } - -static int sdhci_transfer_data (struct sdhci_host *host,struct mmc_data *data, -unsigned int start_addr) -{ -unsigned int stat, rdy, mask, timeout, block =0 ; -bool transfer_done = false;#ifdef CONFIG_MMC_SDHCI_SDMA +static void sdhci_prepare_dma (struct sdhci_host *host,struct mmc_data *data, +int *is_aligned,int trans_bytes) +{unsigned char ctrl; + +if (data->flags ==MMC_DATA_READ ) + host->start_addr = (dma_addr_t )data->dest; +else + host->start_addr = (dma_addr_t )data->src; + +if ((host->quirks &SDHCI_QUIRK_32BIT_DMA_ADDR ) && + (host->start_addr &0x7 ) !=0x0 ) { + *is_aligned =0 ; + host->start_addr = (unsigned long )aligned_buffer; +if (data->flags !=MMC_DATA_READ ) +memcpy (aligned_buffer, data->src, trans_bytes); + } + ctrl =sdhci_readb (host,SDHCI_HOST_CONTROL ); ctrl &= ~SDHCI_CTRL_DMA_MASK ;sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL ); + +#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER ) +/* +* Always use this bounce-buffer when +* CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined +*/ + *is_aligned =0 ; + host->start_addr = (unsigned long )aligned_buffer; +if (data->flags !=MMC_DATA_READ ) +memcpy (aligned_buffer, data->src, trans_bytes); +#endif +sdhci_writel (host, host->start_addr,SDHCI_DMA_ADDRESS ); +flush_cache (host->start_addr,ROUND (trans_bytes,ARCH_DMA_MINALIGN )); +} +#else +static void sdhci_prepare_dma (struct sdhci_host *host,struct mmc_data *data, +int *is_aligned,int trans_bytes) +{}#endif +static int sdhci_transfer_data (struct sdhci_host *host,struct mmc_data *data) +{ +dma_addr_t start_addr = host->start_addr; +unsigned int stat, rdy, mask, timeout, block =0 ; +bool transfer_done = false; timeout =1000000 ; rdy =SDHCI_INT_SPACE_AVAIL |SDHCI_INT_DATA_AVAIL ;
@@ -105,14 +139,13 @@ static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data,continue ; } } -#ifdef CONFIG_MMC_SDHCI_SDMA -if (!transfer_done && (stat &SDHCI_INT_DMA_END )) { +if ((host->flags &USE_SDMA ) && !transfer_done && + (stat &SDHCI_INT_DMA_END )) {sdhci_writel (host,SDHCI_INT_DMA_END ,SDHCI_INT_STATUS ); start_addr &= ~(SDHCI_DEFAULT_BOUNDARY_SIZE -1 ); start_addr +=SDHCI_DEFAULT_BOUNDARY_SIZE ;sdhci_writel (host, start_addr,SDHCI_DMA_ADDRESS ); } -#endif if (timeout-- >0 )udelay (10 );else {
@@ -150,10 +183,11 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,int ret =0 ;int trans_bytes =0 , is_aligned =1 ;u32 mask, flags, mode; -unsigned int time =0 , start_addr =0 ; +unsigned int time =0 ;int mmc_dev =mmc_get_blk_desc (mmc)->devnum;ulong start =get_timer (0 ); + host->start_addr =0 ;/* Timeout unit - ms */ static unsigned int cmd_timeout =SDHCI_CMD_DEFAULT_TIMEOUT ;
@@ -219,33 +253,11 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,if (data->flags ==MMC_DATA_READ ) mode |=SDHCI_TRNS_READ ; -#ifdef CONFIG_MMC_SDHCI_SDMA -if (data->flags ==MMC_DATA_READ ) - start_addr = (unsigned long )data->dest; -else - start_addr = (unsigned long )data->src; -if ((host->quirks &SDHCI_QUIRK_32BIT_DMA_ADDR ) && - (start_addr &0x7 ) !=0x0 ) { - is_aligned =0 ; - start_addr = (unsigned long )aligned_buffer; -if (data->flags !=MMC_DATA_READ ) -memcpy (aligned_buffer, data->src, trans_bytes); +if (host->flags &USE_SDMA ) { + mode |=SDHCI_TRNS_DMA ; +sdhci_prepare_dma (host, data, &is_aligned, trans_bytes); } -#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER ) -/* -* Always use this bounce-buffer when -* CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined -*/ - is_aligned =0 ; - start_addr = (unsigned long )aligned_buffer; -if (data->flags !=MMC_DATA_READ ) -memcpy (aligned_buffer, data->src, trans_bytes); -#endif - -sdhci_writel (host, start_addr,SDHCI_DMA_ADDRESS ); - mode |=SDHCI_TRNS_DMA ; -#endif sdhci_writew (host,SDHCI_MAKE_BLKSZ (SDHCI_DEFAULT_BOUNDARY_ARG , data->blocksize),SDHCI_BLOCK_SIZE );
@@ -256,12 +268,6 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, }sdhci_writel (host, cmd->cmdarg,SDHCI_ARGUMENT ); -#ifdef CONFIG_MMC_SDHCI_SDMA -if (data) { - trans_bytes =ALIGN (trans_bytes,CONFIG_SYS_CACHELINE_SIZE ); -flush_cache (start_addr, trans_bytes); - } -#endif sdhci_writew (host,SDHCI_MAKE_CMD (cmd->cmdidx, flags),SDHCI_COMMAND ); start =get_timer (0 ); do {
@@ -287,7 +293,7 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, ret =-1 ;if (!ret && data) - ret =sdhci_transfer_data (host, data, start_addr); + ret =sdhci_transfer_data (host, data);if (host->quirks &SDHCI_QUIRK_WAIT_SEND_CMD )udelay (1000 );
@@ -578,6 +584,8 @@ int sdhci_setup_cfg(struct mmc_config *cfg, struct sdhci_host *host, __func__);return -EINVAL ; } + + host->flags |=USE_SDMA ;#endif if (host->quirks &SDHCI_QUIRK_REG32_RW ) host->version =
include/sdhci.h +3 -0
@@ -272,6 +272,9 @@ struct sdhci_host {uint voltages;struct mmc_config cfg; +dma_addr_t start_addr; +int flags; +#define USE_SDMA (0x1 << 0) };#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
Signature · 1 line
2.19.2
PATCH 2/2 mmc: sdhci: Add Support for ADMA2
In reply to Faiz AbbasThe Standard Host Controller Interface (SDHCI) specification version 3.00 adds support for Advanced DMA (ADMA) for both 64 and 32 bit widths of DMA. ADMA2 uses a table of descriptors for aggregating DMA requests. This significantly improves read and write throughput.
Add Support for the same.
--- drivers/mmc/Kconfig | 14 +++++ drivers/mmc/sdhci.c | 138 ++++++++++++++++++++++++++++++++++++-------- include/sdhci.h | 41 +++++++++++++ 3 files changed, 170 insertions(+), 23 deletions(-)
drivers/mmc/Kconfig +14 -0
@@ -375,6 +375,20 @@ config MMC_SDHCI_SDMA This enables support for the SDMA (Single Operation DMA) defined in the SD Host Controller Standard Specification Version 1.00 . +config MMC_SDHCI_ADMA + bool "Support SDHCI ADMA2" + depends on MMC_SDHCI + help + This enables support for the ADMA (Advanced DMA) defined + in the SD Host Controller Standard Specification Version 3.00 + +config SPL_MMC_SDHCI_ADMA + bool "Support SDHCI ADMA2 in SPL" + depends on MMC_SDHCI + help + This enables support for the ADMA (Advanced DMA) defined + in the SD Host Controller Standard Specification Version 3.00 in SPL. + config MMC_SDHCI_ATMEL bool "Atmel SDHCI controller support" depends on ARCH_AT91
drivers/mmc/sdhci.c +115 -23
176 lines not on this page · raw message
include/sdhci.h +41 -0
59 lines not on this page · raw message
Signature · 1 line
2.19.2