Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60c64762 authored by Russell King's avatar Russell King Committed by Ulf Hansson
Browse files

mmc: sdhci: factor out sdhci_pre_dma_transfer() from sdhci_adma_table_pre()



In sdhci_prepare_data(), when SDHCI_REQ_USE_DMA is set, there are two
paths that prepare the data buffers for transfer.  One is when
SDHCI_USE_ADMA is set, and is located inside sdhci_adma_table_pre().
The other is when SDHCI_USE_ADMA is clear, in the else clause of the
above.

Factor out the call to sdhci_pre_dma_transfer() along with its error
checking.

Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Tested-by: default avatarGregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 48857d9b
Loading
Loading
Loading
Loading
+23 −39
Original line number Diff line number Diff line
@@ -485,8 +485,8 @@ static void sdhci_adma_mark_end(void *desc)
	dma_desc->cmd |= cpu_to_le16(ADMA2_END);
}

static int sdhci_adma_table_pre(struct sdhci_host *host,
	struct mmc_data *data)
static void sdhci_adma_table_pre(struct sdhci_host *host,
	struct mmc_data *data, int sg_count)
{
	struct scatterlist *sg;
	unsigned long flags;
@@ -500,9 +500,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
	 * We currently guess that it is LE.
	 */

	host->sg_count = sdhci_pre_dma_transfer(host, data);
	if (host->sg_count < 0)
		return -EINVAL;
	host->sg_count = sg_count;

	desc = host->adma_table;
	align = host->align_buffer;
@@ -569,7 +567,6 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
		/* Add a terminating entry - nop, end, valid */
		sdhci_adma_write_desc(host, desc, 0, 0, ADMA2_NOP_END_VALID);
	}
	return 0;
}

static void sdhci_adma_table_post(struct sdhci_host *host,
@@ -710,7 +707,6 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
{
	u8 ctrl;
	struct mmc_data *data = cmd->data;
	int ret;

	WARN_ON(host->data);

@@ -795,41 +791,29 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
	}

	if (host->flags & SDHCI_REQ_USE_DMA) {
		if (host->flags & SDHCI_USE_ADMA) {
			ret = sdhci_adma_table_pre(host, data);
			if (ret) {
		int sg_cnt = sdhci_pre_dma_transfer(host, data);

		if (sg_cnt <= 0) {
			/*
			 * This only happens when someone fed
			 * us an invalid request.
			 */
			WARN_ON(1);
			host->flags &= ~SDHCI_REQ_USE_DMA;
			} else {
				sdhci_writel(host, host->adma_addr,
					SDHCI_ADMA_ADDRESS);
		} else if (host->flags & SDHCI_USE_ADMA) {
			sdhci_adma_table_pre(host, data, sg_cnt);

			sdhci_writel(host, host->adma_addr, SDHCI_ADMA_ADDRESS);
			if (host->flags & SDHCI_USE_64_BIT_DMA)
				sdhci_writel(host,
					     (u64)host->adma_addr >> 32,
					     SDHCI_ADMA_ADDRESS_HI);
			}
		} else {
			int sg_cnt;

			sg_cnt = sdhci_pre_dma_transfer(host, data);
			if (sg_cnt <= 0) {
				/*
				 * This only happens when someone fed
				 * us an invalid request.
				 */
				WARN_ON(1);
				host->flags &= ~SDHCI_REQ_USE_DMA;
		} else {
			WARN_ON(sg_cnt != 1);
			sdhci_writel(host, sg_dma_address(data->sg),
				SDHCI_DMA_ADDRESS);
		}
	}
	}

	/*
	 * Always adjust the DMA selection as some controllers