1 // SPDX-License-Identifier: GPL-2.0+
3 * SDHCI ADMA2 helper functions.
10 #include <asm/cache.h>
12 static void sdhci_adma_desc(struct sdhci_adma_desc *desc,
13 dma_addr_t addr, u16 len, bool end)
17 attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA;
19 attr |= ADMA_DESC_ATTR_END;
24 desc->addr_lo = lower_32_bits(addr);
25 #ifdef CONFIG_DMA_ADDR_T_64BIT
26 desc->addr_hi = upper_32_bits(addr);
31 * sdhci_prepare_adma_table() - Populate the ADMA table
33 * @table: Pointer to the ADMA table
34 * @data: Pointer to MMC data
35 * @addr: DMA address to write to or read from
37 * Fill the ADMA table according to the MMC data to read from or write to the
39 * Please note, that the table size depends on CONFIG_SYS_MMC_MAX_BLK_COUNT and
40 * we don't have to check for overflow.
42 void sdhci_prepare_adma_table(struct sdhci_adma_desc *table,
43 struct mmc_data *data, dma_addr_t addr)
45 uint trans_bytes = data->blocksize * data->blocks;
46 uint desc_count = DIV_ROUND_UP(trans_bytes, ADMA_MAX_LEN);
47 struct sdhci_adma_desc *desc = table;
51 sdhci_adma_desc(desc, addr, ADMA_MAX_LEN, false);
53 trans_bytes -= ADMA_MAX_LEN;
57 sdhci_adma_desc(desc, addr, trans_bytes, true);
59 flush_cache((dma_addr_t)table,
60 ROUND(desc_count * sizeof(struct sdhci_adma_desc),
65 * sdhci_adma_init() - initialize the ADMA descriptor table
67 * Return: pointer to the allocated descriptor table or NULL in case of an
70 struct sdhci_adma_desc *sdhci_adma_init(void)
72 return memalign(ARCH_DMA_MINALIGN, ADMA_TABLE_SZ);