1
2
3
4
5
6#include <common.h>
7#include <cpu_func.h>
8#include <sdhci.h>
9#include <malloc.h>
10#include <asm/cache.h>
11
12static void sdhci_adma_desc(struct sdhci_adma_desc *desc,
13 dma_addr_t addr, u16 len, bool end)
14{
15 u8 attr;
16
17 attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA;
18 if (end)
19 attr |= ADMA_DESC_ATTR_END;
20
21 desc->attr = attr;
22 desc->len = len;
23 desc->reserved = 0;
24 desc->addr_lo = lower_32_bits(addr);
25#ifdef CONFIG_DMA_ADDR_T_64BIT
26 desc->addr_hi = upper_32_bits(addr);
27#endif
28}
29
30
31
32
33
34
35
36
37
38
39
40
41
42void sdhci_prepare_adma_table(struct sdhci_adma_desc *table,
43 struct mmc_data *data, dma_addr_t addr)
44{
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;
48 int i = desc_count;
49
50 while (--i) {
51 sdhci_adma_desc(desc, addr, ADMA_MAX_LEN, false);
52 addr += ADMA_MAX_LEN;
53 trans_bytes -= ADMA_MAX_LEN;
54 desc++;
55 }
56
57 sdhci_adma_desc(desc, addr, trans_bytes, true);
58
59 flush_cache((dma_addr_t)table,
60 ROUND(desc_count * sizeof(struct sdhci_adma_desc),
61 ARCH_DMA_MINALIGN));
62}
63
64
65
66
67
68
69
70struct sdhci_adma_desc *sdhci_adma_init(void)
71{
72 return memalign(ARCH_DMA_MINALIGN, ADMA_TABLE_SZ);
73}
74