]> Git Repo - J-u-boot.git/blame - drivers/dma/fsl_dma.c
Merge tag 'u-boot-imx-master-20250127' of https://gitlab.denx.de/u-boot/custodians...
[J-u-boot.git] / drivers / dma / fsl_dma.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
017f11f6
PT
2/*
3 * Copyright 2004,2007,2008 Freescale Semiconductor, Inc.
4 * (C) Copyright 2002, 2003 Motorola Inc.
5 * Xianghua Xiao ([email protected])
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, [email protected].
017f11f6
PT
9 */
10
11#include <config.h>
a730393a 12#include <asm/io.h>
017f11f6
PT
13#include <asm/fsl_dma.h>
14
51402ac1
PT
15/* Controller can only transfer 2^26 - 1 bytes at a time */
16#define FSL_DMA_MAX_SIZE (0x3ffffff)
17
e94e460c
PT
18#if defined(CONFIG_MPC83xx)
19#define FSL_DMA_MR_DEFAULT (FSL_DMA_MR_CTM_DIRECT | FSL_DMA_MR_DMSEN)
20#else
21#define FSL_DMA_MR_DEFAULT (FSL_DMA_MR_BWC_DIS | FSL_DMA_MR_CTM_DIRECT)
22#endif
23
e94e460c 24#if defined(CONFIG_MPC83xx)
5155207a 25dma83xx_t *dma_base = (void *)(CFG_SYS_MPC83xx_DMA_ADDR);
e94e460c 26#elif defined(CONFIG_MPC85xx)
5155207a 27ccsr_dma_t *dma_base = (void *)(CFG_SYS_MPC85xx_DMA_ADDR);
017f11f6 28#elif defined(CONFIG_MPC86xx)
a730393a 29ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC86xx_DMA_ADDR);
017f11f6
PT
30#else
31#error "Freescale DMA engine not supported on your processor"
32#endif
33
34static void dma_sync(void)
35{
36#if defined(CONFIG_MPC85xx)
37 asm("sync; isync; msync");
38#elif defined(CONFIG_MPC86xx)
39 asm("sync; isync");
40#endif
41}
42
e94e460c
PT
43static void out_dma32(volatile unsigned *addr, int val)
44{
45#if defined(CONFIG_MPC83xx)
46 out_le32(addr, val);
47#else
48 out_be32(addr, val);
49#endif
50}
51
52static uint in_dma32(volatile unsigned *addr)
53{
54#if defined(CONFIG_MPC83xx)
55 return in_le32(addr);
56#else
57 return in_be32(addr);
58#endif
59}
60
017f11f6
PT
61static uint dma_check(void) {
62 volatile fsl_dma_t *dma = &dma_base->dma[0];
a730393a 63 uint status;
017f11f6
PT
64
65 /* While the channel is busy, spin */
a730393a 66 do {
e94e460c 67 status = in_dma32(&dma->sr);
a730393a 68 } while (status & FSL_DMA_SR_CB);
017f11f6
PT
69
70 /* clear MR[CS] channel start bit */
e94e460c 71 out_dma32(&dma->mr, in_dma32(&dma->mr) & ~FSL_DMA_MR_CS);
017f11f6
PT
72 dma_sync();
73
74 if (status != 0)
75 printf ("DMA Error: status = %x\n", status);
76
77 return status;
78}
79
e94e460c 80#if !defined(CONFIG_MPC83xx)
017f11f6
PT
81void dma_init(void) {
82 volatile fsl_dma_t *dma = &dma_base->dma[0];
83
e94e460c
PT
84 out_dma32(&dma->satr, FSL_DMA_SATR_SREAD_SNOOP);
85 out_dma32(&dma->datr, FSL_DMA_DATR_DWRITE_SNOOP);
86 out_dma32(&dma->sr, 0xffffffff); /* clear any errors */
017f11f6
PT
87 dma_sync();
88}
e94e460c 89#endif
017f11f6 90
7892f619 91int dmacpy(phys_addr_t dest, phys_addr_t src, phys_size_t count) {
017f11f6 92 volatile fsl_dma_t *dma = &dma_base->dma[0];
51402ac1 93 uint xfer_size;
017f11f6 94
51402ac1 95 while (count) {
c79cba37 96 xfer_size = min(FSL_DMA_MAX_SIZE, count);
017f11f6 97
359ec493
YS
98 out_dma32(&dma->dar, (u32) (dest & 0xFFFFFFFF));
99 out_dma32(&dma->sar, (u32) (src & 0xFFFFFFFF));
9a865fff 100#if !defined(CONFIG_MPC83xx)
359ec493
YS
101 out_dma32(&dma->satr,
102 in_dma32(&dma->satr) | (u32)((u64)src >> 32));
103 out_dma32(&dma->datr,
104 in_dma32(&dma->datr) | (u32)((u64)dest >> 32));
9a865fff 105#endif
e94e460c
PT
106 out_dma32(&dma->bcr, xfer_size);
107 dma_sync();
017f11f6 108
e94e460c
PT
109 /* Prepare mode register */
110 out_dma32(&dma->mr, FSL_DMA_MR_DEFAULT);
51402ac1
PT
111 dma_sync();
112
113 /* Start the transfer */
e94e460c 114 out_dma32(&dma->mr, FSL_DMA_MR_DEFAULT | FSL_DMA_MR_CS);
51402ac1
PT
115
116 count -= xfer_size;
117 src += xfer_size;
118 dest += xfer_size;
119
120 dma_sync();
121
122 if (dma_check())
123 return -1;
124 }
017f11f6 125
51402ac1 126 return 0;
017f11f6 127}
0d595f76 128
e94e460c
PT
129/*
130 * 85xx/86xx use dma to initialize SDRAM when !CONFIG_ECC_INIT_VIA_DDRCONTROLLER
e94e460c
PT
131 */
132#if ((!defined CONFIG_MPC83xx && defined(CONFIG_DDR_ECC) && \
8897bf42 133 !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)))
829e9d22 134void dma_meminit(uint size)
0d595f76
PT
135{
136 uint *p = 0;
137 uint i = 0;
138
139 for (*p = 0; p < (uint *)(8 * 1024); p++) {
140 if (((uint)p & 0x1f) == 0)
141 ppcDcbz((ulong)p);
142
829e9d22 143 *p = (uint)0xDEADBEEF;
0d595f76
PT
144
145 if (((uint)p & 0x1c) == 0x1c)
146 ppcDcbf((ulong)p);
147 }
148
149 dmacpy(0x002000, 0, 0x002000); /* 8K */
150 dmacpy(0x004000, 0, 0x004000); /* 16K */
151 dmacpy(0x008000, 0, 0x008000); /* 32K */
152 dmacpy(0x010000, 0, 0x010000); /* 64K */
153 dmacpy(0x020000, 0, 0x020000); /* 128K */
154 dmacpy(0x040000, 0, 0x040000); /* 256K */
155 dmacpy(0x080000, 0, 0x080000); /* 512K */
156 dmacpy(0x100000, 0, 0x100000); /* 1M */
157 dmacpy(0x200000, 0, 0x200000); /* 2M */
158 dmacpy(0x400000, 0, 0x400000); /* 4M */
159
160 for (i = 1; i < size / 0x800000; i++)
161 dmacpy((0x800000 * i), 0, 0x800000);
162}
163#endif
This page took 0.606657 seconds and 4 git commands to generate.