diff options
Diffstat (limited to 'drivers/dma/fsldma.c')
-rw-r--r-- | drivers/dma/fsldma.c | 1177 |
1 files changed, 654 insertions, 523 deletions
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c index 296f9e747fac..bbb4be5a3ff4 100644 --- a/drivers/dma/fsldma.c +++ b/drivers/dma/fsldma.c | |||
@@ -37,19 +37,19 @@ | |||
37 | #include <asm/fsldma.h> | 37 | #include <asm/fsldma.h> |
38 | #include "fsldma.h" | 38 | #include "fsldma.h" |
39 | 39 | ||
40 | static void dma_init(struct fsl_dma_chan *fsl_chan) | 40 | static void dma_init(struct fsldma_chan *chan) |
41 | { | 41 | { |
42 | /* Reset the channel */ | 42 | /* Reset the channel */ |
43 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, 0, 32); | 43 | DMA_OUT(chan, &chan->regs->mr, 0, 32); |
44 | 44 | ||
45 | switch (fsl_chan->feature & FSL_DMA_IP_MASK) { | 45 | switch (chan->feature & FSL_DMA_IP_MASK) { |
46 | case FSL_DMA_IP_85XX: | 46 | case FSL_DMA_IP_85XX: |
47 | /* Set the channel to below modes: | 47 | /* Set the channel to below modes: |
48 | * EIE - Error interrupt enable | 48 | * EIE - Error interrupt enable |
49 | * EOSIE - End of segments interrupt enable (basic mode) | 49 | * EOSIE - End of segments interrupt enable (basic mode) |
50 | * EOLNIE - End of links interrupt enable | 50 | * EOLNIE - End of links interrupt enable |
51 | */ | 51 | */ |
52 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, FSL_DMA_MR_EIE | 52 | DMA_OUT(chan, &chan->regs->mr, FSL_DMA_MR_EIE |
53 | | FSL_DMA_MR_EOLNIE | FSL_DMA_MR_EOSIE, 32); | 53 | | FSL_DMA_MR_EOLNIE | FSL_DMA_MR_EOSIE, 32); |
54 | break; | 54 | break; |
55 | case FSL_DMA_IP_83XX: | 55 | case FSL_DMA_IP_83XX: |
@@ -57,170 +57,146 @@ static void dma_init(struct fsl_dma_chan *fsl_chan) | |||
57 | * EOTIE - End-of-transfer interrupt enable | 57 | * EOTIE - End-of-transfer interrupt enable |
58 | * PRC_RM - PCI read multiple | 58 | * PRC_RM - PCI read multiple |
59 | */ | 59 | */ |
60 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, FSL_DMA_MR_EOTIE | 60 | DMA_OUT(chan, &chan->regs->mr, FSL_DMA_MR_EOTIE |
61 | | FSL_DMA_MR_PRC_RM, 32); | 61 | | FSL_DMA_MR_PRC_RM, 32); |
62 | break; | 62 | break; |
63 | } | 63 | } |
64 | |||
65 | } | 64 | } |
66 | 65 | ||
67 | static void set_sr(struct fsl_dma_chan *fsl_chan, u32 val) | 66 | static void set_sr(struct fsldma_chan *chan, u32 val) |
68 | { | 67 | { |
69 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->sr, val, 32); | 68 | DMA_OUT(chan, &chan->regs->sr, val, 32); |
70 | } | 69 | } |
71 | 70 | ||
72 | static u32 get_sr(struct fsl_dma_chan *fsl_chan) | 71 | static u32 get_sr(struct fsldma_chan *chan) |
73 | { | 72 | { |
74 | return DMA_IN(fsl_chan, &fsl_chan->reg_base->sr, 32); | 73 | return DMA_IN(chan, &chan->regs->sr, 32); |
75 | } | 74 | } |
76 | 75 | ||
77 | static void set_desc_cnt(struct fsl_dma_chan *fsl_chan, | 76 | static void set_desc_cnt(struct fsldma_chan *chan, |
78 | struct fsl_dma_ld_hw *hw, u32 count) | 77 | struct fsl_dma_ld_hw *hw, u32 count) |
79 | { | 78 | { |
80 | hw->count = CPU_TO_DMA(fsl_chan, count, 32); | 79 | hw->count = CPU_TO_DMA(chan, count, 32); |
81 | } | 80 | } |
82 | 81 | ||
83 | static void set_desc_src(struct fsl_dma_chan *fsl_chan, | 82 | static void set_desc_src(struct fsldma_chan *chan, |
84 | struct fsl_dma_ld_hw *hw, dma_addr_t src) | 83 | struct fsl_dma_ld_hw *hw, dma_addr_t src) |
85 | { | 84 | { |
86 | u64 snoop_bits; | 85 | u64 snoop_bits; |
87 | 86 | ||
88 | snoop_bits = ((fsl_chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) | 87 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) |
89 | ? ((u64)FSL_DMA_SATR_SREADTYPE_SNOOP_READ << 32) : 0; | 88 | ? ((u64)FSL_DMA_SATR_SREADTYPE_SNOOP_READ << 32) : 0; |
90 | hw->src_addr = CPU_TO_DMA(fsl_chan, snoop_bits | src, 64); | 89 | hw->src_addr = CPU_TO_DMA(chan, snoop_bits | src, 64); |
91 | } | 90 | } |
92 | 91 | ||
93 | static void set_desc_dest(struct fsl_dma_chan *fsl_chan, | 92 | static void set_desc_dst(struct fsldma_chan *chan, |
94 | struct fsl_dma_ld_hw *hw, dma_addr_t dest) | 93 | struct fsl_dma_ld_hw *hw, dma_addr_t dst) |
95 | { | 94 | { |
96 | u64 snoop_bits; | 95 | u64 snoop_bits; |
97 | 96 | ||
98 | snoop_bits = ((fsl_chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) | 97 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) |
99 | ? ((u64)FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE << 32) : 0; | 98 | ? ((u64)FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE << 32) : 0; |
100 | hw->dst_addr = CPU_TO_DMA(fsl_chan, snoop_bits | dest, 64); | 99 | hw->dst_addr = CPU_TO_DMA(chan, snoop_bits | dst, 64); |
101 | } | 100 | } |
102 | 101 | ||
103 | static void set_desc_next(struct fsl_dma_chan *fsl_chan, | 102 | static void set_desc_next(struct fsldma_chan *chan, |
104 | struct fsl_dma_ld_hw *hw, dma_addr_t next) | 103 | struct fsl_dma_ld_hw *hw, dma_addr_t next) |
105 | { | 104 | { |
106 | u64 snoop_bits; | 105 | u64 snoop_bits; |
107 | 106 | ||
108 | snoop_bits = ((fsl_chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) | 107 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) |
109 | ? FSL_DMA_SNEN : 0; | 108 | ? FSL_DMA_SNEN : 0; |
110 | hw->next_ln_addr = CPU_TO_DMA(fsl_chan, snoop_bits | next, 64); | 109 | hw->next_ln_addr = CPU_TO_DMA(chan, snoop_bits | next, 64); |
111 | } | ||
112 | |||
113 | static void set_cdar(struct fsl_dma_chan *fsl_chan, dma_addr_t addr) | ||
114 | { | ||
115 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->cdar, addr | FSL_DMA_SNEN, 64); | ||
116 | } | 110 | } |
117 | 111 | ||
118 | static dma_addr_t get_cdar(struct fsl_dma_chan *fsl_chan) | 112 | static void set_cdar(struct fsldma_chan *chan, dma_addr_t addr) |
119 | { | 113 | { |
120 | return DMA_IN(fsl_chan, &fsl_chan->reg_base->cdar, 64) & ~FSL_DMA_SNEN; | 114 | DMA_OUT(chan, &chan->regs->cdar, addr | FSL_DMA_SNEN, 64); |
121 | } | 115 | } |
122 | 116 | ||
123 | static void set_ndar(struct fsl_dma_chan *fsl_chan, dma_addr_t addr) | 117 | static dma_addr_t get_cdar(struct fsldma_chan *chan) |
124 | { | 118 | { |
125 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->ndar, addr, 64); | 119 | return DMA_IN(chan, &chan->regs->cdar, 64) & ~FSL_DMA_SNEN; |
126 | } | 120 | } |
127 | 121 | ||
128 | static dma_addr_t get_ndar(struct fsl_dma_chan *fsl_chan) | 122 | static dma_addr_t get_ndar(struct fsldma_chan *chan) |
129 | { | 123 | { |
130 | return DMA_IN(fsl_chan, &fsl_chan->reg_base->ndar, 64); | 124 | return DMA_IN(chan, &chan->regs->ndar, 64); |
131 | } | 125 | } |
132 | 126 | ||
133 | static u32 get_bcr(struct fsl_dma_chan *fsl_chan) | 127 | static u32 get_bcr(struct fsldma_chan *chan) |
134 | { | 128 | { |
135 | return DMA_IN(fsl_chan, &fsl_chan->reg_base->bcr, 32); | 129 | return DMA_IN(chan, &chan->regs->bcr, 32); |
136 | } | 130 | } |
137 | 131 | ||
138 | static int dma_is_idle(struct fsl_dma_chan *fsl_chan) | 132 | static int dma_is_idle(struct fsldma_chan *chan) |
139 | { | 133 | { |
140 | u32 sr = get_sr(fsl_chan); | 134 | u32 sr = get_sr(chan); |
141 | return (!(sr & FSL_DMA_SR_CB)) || (sr & FSL_DMA_SR_CH); | 135 | return (!(sr & FSL_DMA_SR_CB)) || (sr & FSL_DMA_SR_CH); |
142 | } | 136 | } |
143 | 137 | ||
144 | static void dma_start(struct fsl_dma_chan *fsl_chan) | 138 | static void dma_start(struct fsldma_chan *chan) |
145 | { | 139 | { |
146 | u32 mr_set = 0; | 140 | u32 mode; |
147 | 141 | ||
148 | if (fsl_chan->feature & FSL_DMA_CHAN_PAUSE_EXT) { | 142 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
149 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->bcr, 0, 32); | 143 | |
150 | mr_set |= FSL_DMA_MR_EMP_EN; | 144 | if ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) { |
151 | } else if ((fsl_chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_85XX) { | 145 | if (chan->feature & FSL_DMA_CHAN_PAUSE_EXT) { |
152 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 146 | DMA_OUT(chan, &chan->regs->bcr, 0, 32); |
153 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) | 147 | mode |= FSL_DMA_MR_EMP_EN; |
154 | & ~FSL_DMA_MR_EMP_EN, 32); | 148 | } else { |
149 | mode &= ~FSL_DMA_MR_EMP_EN; | ||
150 | } | ||
155 | } | 151 | } |
156 | 152 | ||
157 | if (fsl_chan->feature & FSL_DMA_CHAN_START_EXT) | 153 | if (chan->feature & FSL_DMA_CHAN_START_EXT) |
158 | mr_set |= FSL_DMA_MR_EMS_EN; | 154 | mode |= FSL_DMA_MR_EMS_EN; |
159 | else | 155 | else |
160 | mr_set |= FSL_DMA_MR_CS; | 156 | mode |= FSL_DMA_MR_CS; |
161 | 157 | ||
162 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 158 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
163 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) | ||
164 | | mr_set, 32); | ||
165 | } | 159 | } |
166 | 160 | ||
167 | static void dma_halt(struct fsl_dma_chan *fsl_chan) | 161 | static void dma_halt(struct fsldma_chan *chan) |
168 | { | 162 | { |
163 | u32 mode; | ||
169 | int i; | 164 | int i; |
170 | 165 | ||
171 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 166 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
172 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) | FSL_DMA_MR_CA, | 167 | mode |= FSL_DMA_MR_CA; |
173 | 32); | 168 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
174 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 169 | |
175 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) & ~(FSL_DMA_MR_CS | 170 | mode &= ~(FSL_DMA_MR_CS | FSL_DMA_MR_EMS_EN | FSL_DMA_MR_CA); |
176 | | FSL_DMA_MR_EMS_EN | FSL_DMA_MR_CA), 32); | 171 | DMA_OUT(chan, &chan->regs->mr, mode, 32); |
177 | 172 | ||
178 | for (i = 0; i < 100; i++) { | 173 | for (i = 0; i < 100; i++) { |
179 | if (dma_is_idle(fsl_chan)) | 174 | if (dma_is_idle(chan)) |
180 | break; | 175 | return; |
176 | |||
181 | udelay(10); | 177 | udelay(10); |
182 | } | 178 | } |
183 | if (i >= 100 && !dma_is_idle(fsl_chan)) | 179 | |
184 | dev_err(fsl_chan->dev, "DMA halt timeout!\n"); | 180 | if (!dma_is_idle(chan)) |
181 | dev_err(chan->dev, "DMA halt timeout!\n"); | ||
185 | } | 182 | } |
186 | 183 | ||
187 | static void set_ld_eol(struct fsl_dma_chan *fsl_chan, | 184 | static void set_ld_eol(struct fsldma_chan *chan, |
188 | struct fsl_desc_sw *desc) | 185 | struct fsl_desc_sw *desc) |
189 | { | 186 | { |
190 | u64 snoop_bits; | 187 | u64 snoop_bits; |
191 | 188 | ||
192 | snoop_bits = ((fsl_chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) | 189 | snoop_bits = ((chan->feature & FSL_DMA_IP_MASK) == FSL_DMA_IP_83XX) |
193 | ? FSL_DMA_SNEN : 0; | 190 | ? FSL_DMA_SNEN : 0; |
194 | 191 | ||
195 | desc->hw.next_ln_addr = CPU_TO_DMA(fsl_chan, | 192 | desc->hw.next_ln_addr = CPU_TO_DMA(chan, |
196 | DMA_TO_CPU(fsl_chan, desc->hw.next_ln_addr, 64) | FSL_DMA_EOL | 193 | DMA_TO_CPU(chan, desc->hw.next_ln_addr, 64) | FSL_DMA_EOL |
197 | | snoop_bits, 64); | 194 | | snoop_bits, 64); |
198 | } | 195 | } |
199 | 196 | ||
200 | static void append_ld_queue(struct fsl_dma_chan *fsl_chan, | ||
201 | struct fsl_desc_sw *new_desc) | ||
202 | { | ||
203 | struct fsl_desc_sw *queue_tail = to_fsl_desc(fsl_chan->ld_queue.prev); | ||
204 | |||
205 | if (list_empty(&fsl_chan->ld_queue)) | ||
206 | return; | ||
207 | |||
208 | /* Link to the new descriptor physical address and | ||
209 | * Enable End-of-segment interrupt for | ||
210 | * the last link descriptor. | ||
211 | * (the previous node's next link descriptor) | ||
212 | * | ||
213 | * For FSL_DMA_IP_83xx, the snoop enable bit need be set. | ||
214 | */ | ||
215 | queue_tail->hw.next_ln_addr = CPU_TO_DMA(fsl_chan, | ||
216 | new_desc->async_tx.phys | FSL_DMA_EOSIE | | ||
217 | (((fsl_chan->feature & FSL_DMA_IP_MASK) | ||
218 | == FSL_DMA_IP_83XX) ? FSL_DMA_SNEN : 0), 64); | ||
219 | } | ||
220 | |||
221 | /** | 197 | /** |
222 | * fsl_chan_set_src_loop_size - Set source address hold transfer size | 198 | * fsl_chan_set_src_loop_size - Set source address hold transfer size |
223 | * @fsl_chan : Freescale DMA channel | 199 | * @chan : Freescale DMA channel |
224 | * @size : Address loop size, 0 for disable loop | 200 | * @size : Address loop size, 0 for disable loop |
225 | * | 201 | * |
226 | * The set source address hold transfer size. The source | 202 | * The set source address hold transfer size. The source |
@@ -229,29 +205,30 @@ static void append_ld_queue(struct fsl_dma_chan *fsl_chan, | |||
229 | * read data from SA, SA + 1, SA + 2, SA + 3, then loop back to SA, | 205 | * read data from SA, SA + 1, SA + 2, SA + 3, then loop back to SA, |
230 | * SA + 1 ... and so on. | 206 | * SA + 1 ... and so on. |
231 | */ | 207 | */ |
232 | static void fsl_chan_set_src_loop_size(struct fsl_dma_chan *fsl_chan, int size) | 208 | static void fsl_chan_set_src_loop_size(struct fsldma_chan *chan, int size) |
233 | { | 209 | { |
210 | u32 mode; | ||
211 | |||
212 | mode = DMA_IN(chan, &chan->regs->mr, 32); | ||
213 | |||
234 | switch (size) { | 214 | switch (size) { |
235 | case 0: | 215 | case 0: |
236 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 216 | mode &= ~FSL_DMA_MR_SAHE; |
237 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) & | ||
238 | (~FSL_DMA_MR_SAHE), 32); | ||
239 | break; | 217 | break; |
240 | case 1: | 218 | case 1: |
241 | case 2: | 219 | case 2: |
242 | case 4: | 220 | case 4: |
243 | case 8: | 221 | case 8: |
244 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 222 | mode |= FSL_DMA_MR_SAHE | (__ilog2(size) << 14); |
245 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) | | ||
246 | FSL_DMA_MR_SAHE | (__ilog2(size) << 14), | ||
247 | 32); | ||
248 | break; | 223 | break; |
249 | } | 224 | } |
225 | |||
226 | DMA_OUT(chan, &chan->regs->mr, mode, 32); | ||
250 | } | 227 | } |
251 | 228 | ||
252 | /** | 229 | /** |
253 | * fsl_chan_set_dest_loop_size - Set destination address hold transfer size | 230 | * fsl_chan_set_dst_loop_size - Set destination address hold transfer size |
254 | * @fsl_chan : Freescale DMA channel | 231 | * @chan : Freescale DMA channel |
255 | * @size : Address loop size, 0 for disable loop | 232 | * @size : Address loop size, 0 for disable loop |
256 | * | 233 | * |
257 | * The set destination address hold transfer size. The destination | 234 | * The set destination address hold transfer size. The destination |
@@ -260,29 +237,30 @@ static void fsl_chan_set_src_loop_size(struct fsl_dma_chan *fsl_chan, int size) | |||
260 | * write data to TA, TA + 1, TA + 2, TA + 3, then loop back to TA, | 237 | * write data to TA, TA + 1, TA + 2, TA + 3, then loop back to TA, |
261 | * TA + 1 ... and so on. | 238 | * TA + 1 ... and so on. |
262 | */ | 239 | */ |
263 | static void fsl_chan_set_dest_loop_size(struct fsl_dma_chan *fsl_chan, int size) | 240 | static void fsl_chan_set_dst_loop_size(struct fsldma_chan *chan, int size) |
264 | { | 241 | { |
242 | u32 mode; | ||
243 | |||
244 | mode = DMA_IN(chan, &chan->regs->mr, 32); | ||
245 | |||
265 | switch (size) { | 246 | switch (size) { |
266 | case 0: | 247 | case 0: |
267 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 248 | mode &= ~FSL_DMA_MR_DAHE; |
268 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) & | ||
269 | (~FSL_DMA_MR_DAHE), 32); | ||
270 | break; | 249 | break; |
271 | case 1: | 250 | case 1: |
272 | case 2: | 251 | case 2: |
273 | case 4: | 252 | case 4: |
274 | case 8: | 253 | case 8: |
275 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 254 | mode |= FSL_DMA_MR_DAHE | (__ilog2(size) << 16); |
276 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) | | ||
277 | FSL_DMA_MR_DAHE | (__ilog2(size) << 16), | ||
278 | 32); | ||
279 | break; | 255 | break; |
280 | } | 256 | } |
257 | |||
258 | DMA_OUT(chan, &chan->regs->mr, mode, 32); | ||
281 | } | 259 | } |
282 | 260 | ||
283 | /** | 261 | /** |
284 | * fsl_chan_set_request_count - Set DMA Request Count for external control | 262 | * fsl_chan_set_request_count - Set DMA Request Count for external control |
285 | * @fsl_chan : Freescale DMA channel | 263 | * @chan : Freescale DMA channel |
286 | * @size : Number of bytes to transfer in a single request | 264 | * @size : Number of bytes to transfer in a single request |
287 | * | 265 | * |
288 | * The Freescale DMA channel can be controlled by the external signal DREQ#. | 266 | * The Freescale DMA channel can be controlled by the external signal DREQ#. |
@@ -292,35 +270,38 @@ static void fsl_chan_set_dest_loop_size(struct fsl_dma_chan *fsl_chan, int size) | |||
292 | * | 270 | * |
293 | * A size of 0 disables external pause control. The maximum size is 1024. | 271 | * A size of 0 disables external pause control. The maximum size is 1024. |
294 | */ | 272 | */ |
295 | static void fsl_chan_set_request_count(struct fsl_dma_chan *fsl_chan, int size) | 273 | static void fsl_chan_set_request_count(struct fsldma_chan *chan, int size) |
296 | { | 274 | { |
275 | u32 mode; | ||
276 | |||
297 | BUG_ON(size > 1024); | 277 | BUG_ON(size > 1024); |
298 | DMA_OUT(fsl_chan, &fsl_chan->reg_base->mr, | 278 | |
299 | DMA_IN(fsl_chan, &fsl_chan->reg_base->mr, 32) | 279 | mode = DMA_IN(chan, &chan->regs->mr, 32); |
300 | | ((__ilog2(size) << 24) & 0x0f000000), | 280 | mode |= (__ilog2(size) << 24) & 0x0f000000; |
301 | 32); | 281 | |
282 | DMA_OUT(chan, &chan->regs->mr, mode, 32); | ||
302 | } | 283 | } |
303 | 284 | ||
304 | /** | 285 | /** |
305 | * fsl_chan_toggle_ext_pause - Toggle channel external pause status | 286 | * fsl_chan_toggle_ext_pause - Toggle channel external pause status |
306 | * @fsl_chan : Freescale DMA channel | 287 | * @chan : Freescale DMA channel |
307 | * @enable : 0 is disabled, 1 is enabled. | 288 | * @enable : 0 is disabled, 1 is enabled. |
308 | * | 289 | * |
309 | * The Freescale DMA channel can be controlled by the external signal DREQ#. | 290 | * The Freescale DMA channel can be controlled by the external signal DREQ#. |
310 | * The DMA Request Count feature should be used in addition to this feature | 291 | * The DMA Request Count feature should be used in addition to this feature |
311 | * to set the number of bytes to transfer before pausing the channel. | 292 | * to set the number of bytes to transfer before pausing the channel. |
312 | */ | 293 | */ |
313 | static void fsl_chan_toggle_ext_pause(struct fsl_dma_chan *fsl_chan, int enable) | 294 | static void fsl_chan_toggle_ext_pause(struct fsldma_chan *chan, int enable) |
314 | { | 295 | { |
315 | if (enable) | 296 | if (enable) |
316 | fsl_chan->feature |= FSL_DMA_CHAN_PAUSE_EXT; | 297 | chan->feature |= FSL_DMA_CHAN_PAUSE_EXT; |
317 | else | 298 | else |
318 | fsl_chan->feature &= ~FSL_DMA_CHAN_PAUSE_EXT; | 299 | chan->feature &= ~FSL_DMA_CHAN_PAUSE_EXT; |
319 | } | 300 | } |
320 | 301 | ||
321 | /** | 302 | /** |
322 | * fsl_chan_toggle_ext_start - Toggle channel external start status | 303 | * fsl_chan_toggle_ext_start - Toggle channel external start status |
323 | * @fsl_chan : Freescale DMA channel | 304 | * @chan : Freescale DMA channel |
324 | * @enable : 0 is disabled, 1 is enabled. | 305 | * @enable : 0 is disabled, 1 is enabled. |
325 | * | 306 | * |
326 | * If enable the external start, the channel can be started by an | 307 | * If enable the external start, the channel can be started by an |
@@ -328,141 +309,196 @@ static void fsl_chan_toggle_ext_pause(struct fsl_dma_chan *fsl_chan, int enable) | |||
328 | * transfer immediately. The DMA channel will wait for the | 309 | * transfer immediately. The DMA channel will wait for the |
329 | * control pin asserted. | 310 | * control pin asserted. |
330 | */ | 311 | */ |
331 | static void fsl_chan_toggle_ext_start(struct fsl_dma_chan *fsl_chan, int enable) | 312 | static void fsl_chan_toggle_ext_start(struct fsldma_chan *chan, int enable) |
332 | { | 313 | { |
333 | if (enable) | 314 | if (enable) |
334 | fsl_chan->feature |= FSL_DMA_CHAN_START_EXT; | 315 | chan->feature |= FSL_DMA_CHAN_START_EXT; |
335 | else | 316 | else |
336 | fsl_chan->feature &= ~FSL_DMA_CHAN_START_EXT; | 317 | chan->feature &= ~FSL_DMA_CHAN_START_EXT; |
318 | } | ||
319 | |||
320 | static void append_ld_queue(struct fsldma_chan *chan, | ||
321 | struct fsl_desc_sw *desc) | ||
322 | { | ||
323 | struct fsl_desc_sw *tail = to_fsl_desc(chan->ld_pending.prev); | ||
324 | |||
325 | if (list_empty(&chan->ld_pending)) | ||
326 | goto out_splice; | ||
327 | |||
328 | /* | ||
329 | * Add the hardware descriptor to the chain of hardware descriptors | ||
330 | * that already exists in memory. | ||
331 | * | ||
332 | * This will un-set the EOL bit of the existing transaction, and the | ||
333 | * last link in this transaction will become the EOL descriptor. | ||
334 | */ | ||
335 | set_desc_next(chan, &tail->hw, desc->async_tx.phys); | ||
336 | |||
337 | /* | ||
338 | * Add the software descriptor and all children to the list | ||
339 | * of pending transactions | ||
340 | */ | ||
341 | out_splice: | ||
342 | list_splice_tail_init(&desc->tx_list, &chan->ld_pending); | ||
337 | } | 343 | } |
338 | 344 | ||
339 | static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) | 345 | static dma_cookie_t fsl_dma_tx_submit(struct dma_async_tx_descriptor *tx) |
340 | { | 346 | { |
341 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(tx->chan); | 347 | struct fsldma_chan *chan = to_fsl_chan(tx->chan); |
342 | struct fsl_desc_sw *desc = tx_to_fsl_desc(tx); | 348 | struct fsl_desc_sw *desc = tx_to_fsl_desc(tx); |
343 | struct fsl_desc_sw *child; | 349 | struct fsl_desc_sw *child; |
344 | unsigned long flags; | 350 | unsigned long flags; |
345 | dma_cookie_t cookie; | 351 | dma_cookie_t cookie; |
346 | 352 | ||
347 | /* cookie increment and adding to ld_queue must be atomic */ | 353 | spin_lock_irqsave(&chan->desc_lock, flags); |
348 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | ||
349 | 354 | ||
350 | cookie = fsl_chan->common.cookie; | 355 | /* |
356 | * assign cookies to all of the software descriptors | ||
357 | * that make up this transaction | ||
358 | */ | ||
359 | cookie = chan->common.cookie; | ||
351 | list_for_each_entry(child, &desc->tx_list, node) { | 360 | list_for_each_entry(child, &desc->tx_list, node) { |
352 | cookie++; | 361 | cookie++; |
353 | if (cookie < 0) | 362 | if (cookie < 0) |
354 | cookie = 1; | 363 | cookie = 1; |
355 | 364 | ||
356 | desc->async_tx.cookie = cookie; | 365 | child->async_tx.cookie = cookie; |
357 | } | 366 | } |
358 | 367 | ||
359 | fsl_chan->common.cookie = cookie; | 368 | chan->common.cookie = cookie; |
360 | append_ld_queue(fsl_chan, desc); | 369 | |
361 | list_splice_init(&desc->tx_list, fsl_chan->ld_queue.prev); | 370 | /* put this transaction onto the tail of the pending queue */ |
371 | append_ld_queue(chan, desc); | ||
362 | 372 | ||
363 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 373 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
364 | 374 | ||
365 | return cookie; | 375 | return cookie; |
366 | } | 376 | } |
367 | 377 | ||
368 | /** | 378 | /** |
369 | * fsl_dma_alloc_descriptor - Allocate descriptor from channel's DMA pool. | 379 | * fsl_dma_alloc_descriptor - Allocate descriptor from channel's DMA pool. |
370 | * @fsl_chan : Freescale DMA channel | 380 | * @chan : Freescale DMA channel |
371 | * | 381 | * |
372 | * Return - The descriptor allocated. NULL for failed. | 382 | * Return - The descriptor allocated. NULL for failed. |
373 | */ | 383 | */ |
374 | static struct fsl_desc_sw *fsl_dma_alloc_descriptor( | 384 | static struct fsl_desc_sw *fsl_dma_alloc_descriptor( |
375 | struct fsl_dma_chan *fsl_chan) | 385 | struct fsldma_chan *chan) |
376 | { | 386 | { |
387 | struct fsl_desc_sw *desc; | ||
377 | dma_addr_t pdesc; | 388 | dma_addr_t pdesc; |
378 | struct fsl_desc_sw *desc_sw; | 389 | |
379 | 390 | desc = dma_pool_alloc(chan->desc_pool, GFP_ATOMIC, &pdesc); | |
380 | desc_sw = dma_pool_alloc(fsl_chan->desc_pool, GFP_ATOMIC, &pdesc); | 391 | if (!desc) { |
381 | if (desc_sw) { | 392 | dev_dbg(chan->dev, "out of memory for link desc\n"); |
382 | memset(desc_sw, 0, sizeof(struct fsl_desc_sw)); | 393 | return NULL; |
383 | INIT_LIST_HEAD(&desc_sw->tx_list); | ||
384 | dma_async_tx_descriptor_init(&desc_sw->async_tx, | ||
385 | &fsl_chan->common); | ||
386 | desc_sw->async_tx.tx_submit = fsl_dma_tx_submit; | ||
387 | desc_sw->async_tx.phys = pdesc; | ||
388 | } | 394 | } |
389 | 395 | ||
390 | return desc_sw; | 396 | memset(desc, 0, sizeof(*desc)); |
397 | INIT_LIST_HEAD(&desc->tx_list); | ||
398 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); | ||
399 | desc->async_tx.tx_submit = fsl_dma_tx_submit; | ||
400 | desc->async_tx.phys = pdesc; | ||
401 | |||
402 | return desc; | ||
391 | } | 403 | } |
392 | 404 | ||
393 | 405 | ||
394 | /** | 406 | /** |
395 | * fsl_dma_alloc_chan_resources - Allocate resources for DMA channel. | 407 | * fsl_dma_alloc_chan_resources - Allocate resources for DMA channel. |
396 | * @fsl_chan : Freescale DMA channel | 408 | * @chan : Freescale DMA channel |
397 | * | 409 | * |
398 | * This function will create a dma pool for descriptor allocation. | 410 | * This function will create a dma pool for descriptor allocation. |
399 | * | 411 | * |
400 | * Return - The number of descriptors allocated. | 412 | * Return - The number of descriptors allocated. |
401 | */ | 413 | */ |
402 | static int fsl_dma_alloc_chan_resources(struct dma_chan *chan) | 414 | static int fsl_dma_alloc_chan_resources(struct dma_chan *dchan) |
403 | { | 415 | { |
404 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(chan); | 416 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
405 | 417 | ||
406 | /* Has this channel already been allocated? */ | 418 | /* Has this channel already been allocated? */ |
407 | if (fsl_chan->desc_pool) | 419 | if (chan->desc_pool) |
408 | return 1; | 420 | return 1; |
409 | 421 | ||
410 | /* We need the descriptor to be aligned to 32bytes | 422 | /* |
423 | * We need the descriptor to be aligned to 32bytes | ||
411 | * for meeting FSL DMA specification requirement. | 424 | * for meeting FSL DMA specification requirement. |
412 | */ | 425 | */ |
413 | fsl_chan->desc_pool = dma_pool_create("fsl_dma_engine_desc_pool", | 426 | chan->desc_pool = dma_pool_create("fsl_dma_engine_desc_pool", |
414 | fsl_chan->dev, sizeof(struct fsl_desc_sw), | 427 | chan->dev, |
415 | 32, 0); | 428 | sizeof(struct fsl_desc_sw), |
416 | if (!fsl_chan->desc_pool) { | 429 | __alignof__(struct fsl_desc_sw), 0); |
417 | dev_err(fsl_chan->dev, "No memory for channel %d " | 430 | if (!chan->desc_pool) { |
418 | "descriptor dma pool.\n", fsl_chan->id); | 431 | dev_err(chan->dev, "unable to allocate channel %d " |
419 | return 0; | 432 | "descriptor pool\n", chan->id); |
433 | return -ENOMEM; | ||
420 | } | 434 | } |
421 | 435 | ||
436 | /* there is at least one descriptor free to be allocated */ | ||
422 | return 1; | 437 | return 1; |
423 | } | 438 | } |
424 | 439 | ||
425 | /** | 440 | /** |
426 | * fsl_dma_free_chan_resources - Free all resources of the channel. | 441 | * fsldma_free_desc_list - Free all descriptors in a queue |
427 | * @fsl_chan : Freescale DMA channel | 442 | * @chan: Freescae DMA channel |
443 | * @list: the list to free | ||
444 | * | ||
445 | * LOCKING: must hold chan->desc_lock | ||
428 | */ | 446 | */ |
429 | static void fsl_dma_free_chan_resources(struct dma_chan *chan) | 447 | static void fsldma_free_desc_list(struct fsldma_chan *chan, |
448 | struct list_head *list) | ||
430 | { | 449 | { |
431 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(chan); | ||
432 | struct fsl_desc_sw *desc, *_desc; | 450 | struct fsl_desc_sw *desc, *_desc; |
433 | unsigned long flags; | ||
434 | 451 | ||
435 | dev_dbg(fsl_chan->dev, "Free all channel resources.\n"); | 452 | list_for_each_entry_safe(desc, _desc, list, node) { |
436 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | 453 | list_del(&desc->node); |
437 | list_for_each_entry_safe(desc, _desc, &fsl_chan->ld_queue, node) { | 454 | dma_pool_free(chan->desc_pool, desc, desc->async_tx.phys); |
438 | #ifdef FSL_DMA_LD_DEBUG | 455 | } |
439 | dev_dbg(fsl_chan->dev, | 456 | } |
440 | "LD %p will be released.\n", desc); | 457 | |
441 | #endif | 458 | static void fsldma_free_desc_list_reverse(struct fsldma_chan *chan, |
459 | struct list_head *list) | ||
460 | { | ||
461 | struct fsl_desc_sw *desc, *_desc; | ||
462 | |||
463 | list_for_each_entry_safe_reverse(desc, _desc, list, node) { | ||
442 | list_del(&desc->node); | 464 | list_del(&desc->node); |
443 | /* free link descriptor */ | 465 | dma_pool_free(chan->desc_pool, desc, desc->async_tx.phys); |
444 | dma_pool_free(fsl_chan->desc_pool, desc, desc->async_tx.phys); | ||
445 | } | 466 | } |
446 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 467 | } |
447 | dma_pool_destroy(fsl_chan->desc_pool); | 468 | |
469 | /** | ||
470 | * fsl_dma_free_chan_resources - Free all resources of the channel. | ||
471 | * @chan : Freescale DMA channel | ||
472 | */ | ||
473 | static void fsl_dma_free_chan_resources(struct dma_chan *dchan) | ||
474 | { | ||
475 | struct fsldma_chan *chan = to_fsl_chan(dchan); | ||
476 | unsigned long flags; | ||
477 | |||
478 | dev_dbg(chan->dev, "Free all channel resources.\n"); | ||
479 | spin_lock_irqsave(&chan->desc_lock, flags); | ||
480 | fsldma_free_desc_list(chan, &chan->ld_pending); | ||
481 | fsldma_free_desc_list(chan, &chan->ld_running); | ||
482 | spin_unlock_irqrestore(&chan->desc_lock, flags); | ||
448 | 483 | ||
449 | fsl_chan->desc_pool = NULL; | 484 | dma_pool_destroy(chan->desc_pool); |
485 | chan->desc_pool = NULL; | ||
450 | } | 486 | } |
451 | 487 | ||
452 | static struct dma_async_tx_descriptor * | 488 | static struct dma_async_tx_descriptor * |
453 | fsl_dma_prep_interrupt(struct dma_chan *chan, unsigned long flags) | 489 | fsl_dma_prep_interrupt(struct dma_chan *dchan, unsigned long flags) |
454 | { | 490 | { |
455 | struct fsl_dma_chan *fsl_chan; | 491 | struct fsldma_chan *chan; |
456 | struct fsl_desc_sw *new; | 492 | struct fsl_desc_sw *new; |
457 | 493 | ||
458 | if (!chan) | 494 | if (!dchan) |
459 | return NULL; | 495 | return NULL; |
460 | 496 | ||
461 | fsl_chan = to_fsl_chan(chan); | 497 | chan = to_fsl_chan(dchan); |
462 | 498 | ||
463 | new = fsl_dma_alloc_descriptor(fsl_chan); | 499 | new = fsl_dma_alloc_descriptor(chan); |
464 | if (!new) { | 500 | if (!new) { |
465 | dev_err(fsl_chan->dev, "No free memory for link descriptor\n"); | 501 | dev_err(chan->dev, "No free memory for link descriptor\n"); |
466 | return NULL; | 502 | return NULL; |
467 | } | 503 | } |
468 | 504 | ||
@@ -473,51 +509,50 @@ fsl_dma_prep_interrupt(struct dma_chan *chan, unsigned long flags) | |||
473 | list_add_tail(&new->node, &new->tx_list); | 509 | list_add_tail(&new->node, &new->tx_list); |
474 | 510 | ||
475 | /* Set End-of-link to the last link descriptor of new list*/ | 511 | /* Set End-of-link to the last link descriptor of new list*/ |
476 | set_ld_eol(fsl_chan, new); | 512 | set_ld_eol(chan, new); |
477 | 513 | ||
478 | return &new->async_tx; | 514 | return &new->async_tx; |
479 | } | 515 | } |
480 | 516 | ||
481 | static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( | 517 | static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( |
482 | struct dma_chan *chan, dma_addr_t dma_dest, dma_addr_t dma_src, | 518 | struct dma_chan *dchan, dma_addr_t dma_dst, dma_addr_t dma_src, |
483 | size_t len, unsigned long flags) | 519 | size_t len, unsigned long flags) |
484 | { | 520 | { |
485 | struct fsl_dma_chan *fsl_chan; | 521 | struct fsldma_chan *chan; |
486 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new; | 522 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new; |
487 | struct list_head *list; | ||
488 | size_t copy; | 523 | size_t copy; |
489 | 524 | ||
490 | if (!chan) | 525 | if (!dchan) |
491 | return NULL; | 526 | return NULL; |
492 | 527 | ||
493 | if (!len) | 528 | if (!len) |
494 | return NULL; | 529 | return NULL; |
495 | 530 | ||
496 | fsl_chan = to_fsl_chan(chan); | 531 | chan = to_fsl_chan(dchan); |
497 | 532 | ||
498 | do { | 533 | do { |
499 | 534 | ||
500 | /* Allocate the link descriptor from DMA pool */ | 535 | /* Allocate the link descriptor from DMA pool */ |
501 | new = fsl_dma_alloc_descriptor(fsl_chan); | 536 | new = fsl_dma_alloc_descriptor(chan); |
502 | if (!new) { | 537 | if (!new) { |
503 | dev_err(fsl_chan->dev, | 538 | dev_err(chan->dev, |
504 | "No free memory for link descriptor\n"); | 539 | "No free memory for link descriptor\n"); |
505 | goto fail; | 540 | goto fail; |
506 | } | 541 | } |
507 | #ifdef FSL_DMA_LD_DEBUG | 542 | #ifdef FSL_DMA_LD_DEBUG |
508 | dev_dbg(fsl_chan->dev, "new link desc alloc %p\n", new); | 543 | dev_dbg(chan->dev, "new link desc alloc %p\n", new); |
509 | #endif | 544 | #endif |
510 | 545 | ||
511 | copy = min(len, (size_t)FSL_DMA_BCR_MAX_CNT); | 546 | copy = min(len, (size_t)FSL_DMA_BCR_MAX_CNT); |
512 | 547 | ||
513 | set_desc_cnt(fsl_chan, &new->hw, copy); | 548 | set_desc_cnt(chan, &new->hw, copy); |
514 | set_desc_src(fsl_chan, &new->hw, dma_src); | 549 | set_desc_src(chan, &new->hw, dma_src); |
515 | set_desc_dest(fsl_chan, &new->hw, dma_dest); | 550 | set_desc_dst(chan, &new->hw, dma_dst); |
516 | 551 | ||
517 | if (!first) | 552 | if (!first) |
518 | first = new; | 553 | first = new; |
519 | else | 554 | else |
520 | set_desc_next(fsl_chan, &prev->hw, new->async_tx.phys); | 555 | set_desc_next(chan, &prev->hw, new->async_tx.phys); |
521 | 556 | ||
522 | new->async_tx.cookie = 0; | 557 | new->async_tx.cookie = 0; |
523 | async_tx_ack(&new->async_tx); | 558 | async_tx_ack(&new->async_tx); |
@@ -525,7 +560,7 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( | |||
525 | prev = new; | 560 | prev = new; |
526 | len -= copy; | 561 | len -= copy; |
527 | dma_src += copy; | 562 | dma_src += copy; |
528 | dma_dest += copy; | 563 | dma_dst += copy; |
529 | 564 | ||
530 | /* Insert the link descriptor to the LD ring */ | 565 | /* Insert the link descriptor to the LD ring */ |
531 | list_add_tail(&new->node, &first->tx_list); | 566 | list_add_tail(&new->node, &first->tx_list); |
@@ -535,7 +570,7 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_memcpy( | |||
535 | new->async_tx.cookie = -EBUSY; | 570 | new->async_tx.cookie = -EBUSY; |
536 | 571 | ||
537 | /* Set End-of-link to the last link descriptor of new list*/ | 572 | /* Set End-of-link to the last link descriptor of new list*/ |
538 | set_ld_eol(fsl_chan, new); | 573 | set_ld_eol(chan, new); |
539 | 574 | ||
540 | return &first->async_tx; | 575 | return &first->async_tx; |
541 | 576 | ||
@@ -543,12 +578,7 @@ fail: | |||
543 | if (!first) | 578 | if (!first) |
544 | return NULL; | 579 | return NULL; |
545 | 580 | ||
546 | list = &first->tx_list; | 581 | fsldma_free_desc_list_reverse(chan, &first->tx_list); |
547 | list_for_each_entry_safe_reverse(new, prev, list, node) { | ||
548 | list_del(&new->node); | ||
549 | dma_pool_free(fsl_chan->desc_pool, new, new->async_tx.phys); | ||
550 | } | ||
551 | |||
552 | return NULL; | 582 | return NULL; |
553 | } | 583 | } |
554 | 584 | ||
@@ -565,13 +595,12 @@ fail: | |||
565 | * chan->private variable. | 595 | * chan->private variable. |
566 | */ | 596 | */ |
567 | static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( | 597 | static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( |
568 | struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, | 598 | struct dma_chan *dchan, struct scatterlist *sgl, unsigned int sg_len, |
569 | enum dma_data_direction direction, unsigned long flags) | 599 | enum dma_data_direction direction, unsigned long flags) |
570 | { | 600 | { |
571 | struct fsl_dma_chan *fsl_chan; | 601 | struct fsldma_chan *chan; |
572 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new = NULL; | 602 | struct fsl_desc_sw *first = NULL, *prev = NULL, *new = NULL; |
573 | struct fsl_dma_slave *slave; | 603 | struct fsl_dma_slave *slave; |
574 | struct list_head *tx_list; | ||
575 | size_t copy; | 604 | size_t copy; |
576 | 605 | ||
577 | int i; | 606 | int i; |
@@ -581,14 +610,14 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( | |||
581 | struct fsl_dma_hw_addr *hw; | 610 | struct fsl_dma_hw_addr *hw; |
582 | dma_addr_t dma_dst, dma_src; | 611 | dma_addr_t dma_dst, dma_src; |
583 | 612 | ||
584 | if (!chan) | 613 | if (!dchan) |
585 | return NULL; | 614 | return NULL; |
586 | 615 | ||
587 | if (!chan->private) | 616 | if (!dchan->private) |
588 | return NULL; | 617 | return NULL; |
589 | 618 | ||
590 | fsl_chan = to_fsl_chan(chan); | 619 | chan = to_fsl_chan(dchan); |
591 | slave = chan->private; | 620 | slave = dchan->private; |
592 | 621 | ||
593 | if (list_empty(&slave->addresses)) | 622 | if (list_empty(&slave->addresses)) |
594 | return NULL; | 623 | return NULL; |
@@ -637,14 +666,14 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( | |||
637 | } | 666 | } |
638 | 667 | ||
639 | /* Allocate the link descriptor from DMA pool */ | 668 | /* Allocate the link descriptor from DMA pool */ |
640 | new = fsl_dma_alloc_descriptor(fsl_chan); | 669 | new = fsl_dma_alloc_descriptor(chan); |
641 | if (!new) { | 670 | if (!new) { |
642 | dev_err(fsl_chan->dev, "No free memory for " | 671 | dev_err(chan->dev, "No free memory for " |
643 | "link descriptor\n"); | 672 | "link descriptor\n"); |
644 | goto fail; | 673 | goto fail; |
645 | } | 674 | } |
646 | #ifdef FSL_DMA_LD_DEBUG | 675 | #ifdef FSL_DMA_LD_DEBUG |
647 | dev_dbg(fsl_chan->dev, "new link desc alloc %p\n", new); | 676 | dev_dbg(chan->dev, "new link desc alloc %p\n", new); |
648 | #endif | 677 | #endif |
649 | 678 | ||
650 | /* | 679 | /* |
@@ -671,9 +700,9 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( | |||
671 | } | 700 | } |
672 | 701 | ||
673 | /* Fill in the descriptor */ | 702 | /* Fill in the descriptor */ |
674 | set_desc_cnt(fsl_chan, &new->hw, copy); | 703 | set_desc_cnt(chan, &new->hw, copy); |
675 | set_desc_src(fsl_chan, &new->hw, dma_src); | 704 | set_desc_src(chan, &new->hw, dma_src); |
676 | set_desc_dest(fsl_chan, &new->hw, dma_dst); | 705 | set_desc_dst(chan, &new->hw, dma_dst); |
677 | 706 | ||
678 | /* | 707 | /* |
679 | * If this is not the first descriptor, chain the | 708 | * If this is not the first descriptor, chain the |
@@ -682,7 +711,7 @@ static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( | |||
682 | if (!first) { | 711 | if (!first) { |
683 | first = new; | 712 | first = new; |
684 | } else { | 713 | } else { |
685 | set_desc_next(fsl_chan, &prev->hw, | 714 | set_desc_next(chan, &prev->hw, |
686 | new->async_tx.phys); | 715 | new->async_tx.phys); |
687 | } | 716 | } |
688 | 717 | ||
@@ -708,23 +737,23 @@ finished: | |||
708 | new->async_tx.cookie = -EBUSY; | 737 | new->async_tx.cookie = -EBUSY; |
709 | 738 | ||
710 | /* Set End-of-link to the last link descriptor of new list */ | 739 | /* Set End-of-link to the last link descriptor of new list */ |
711 | set_ld_eol(fsl_chan, new); | 740 | set_ld_eol(chan, new); |
712 | 741 | ||
713 | /* Enable extra controller features */ | 742 | /* Enable extra controller features */ |
714 | if (fsl_chan->set_src_loop_size) | 743 | if (chan->set_src_loop_size) |
715 | fsl_chan->set_src_loop_size(fsl_chan, slave->src_loop_size); | 744 | chan->set_src_loop_size(chan, slave->src_loop_size); |
716 | 745 | ||
717 | if (fsl_chan->set_dest_loop_size) | 746 | if (chan->set_dst_loop_size) |
718 | fsl_chan->set_dest_loop_size(fsl_chan, slave->dst_loop_size); | 747 | chan->set_dst_loop_size(chan, slave->dst_loop_size); |
719 | 748 | ||
720 | if (fsl_chan->toggle_ext_start) | 749 | if (chan->toggle_ext_start) |
721 | fsl_chan->toggle_ext_start(fsl_chan, slave->external_start); | 750 | chan->toggle_ext_start(chan, slave->external_start); |
722 | 751 | ||
723 | if (fsl_chan->toggle_ext_pause) | 752 | if (chan->toggle_ext_pause) |
724 | fsl_chan->toggle_ext_pause(fsl_chan, slave->external_pause); | 753 | chan->toggle_ext_pause(chan, slave->external_pause); |
725 | 754 | ||
726 | if (fsl_chan->set_request_count) | 755 | if (chan->set_request_count) |
727 | fsl_chan->set_request_count(fsl_chan, slave->request_count); | 756 | chan->set_request_count(chan, slave->request_count); |
728 | 757 | ||
729 | return &first->async_tx; | 758 | return &first->async_tx; |
730 | 759 | ||
@@ -741,215 +770,216 @@ fail: | |||
741 | * | 770 | * |
742 | * We're re-using variables for the loop, oh well | 771 | * We're re-using variables for the loop, oh well |
743 | */ | 772 | */ |
744 | tx_list = &first->tx_list; | 773 | fsldma_free_desc_list_reverse(chan, &first->tx_list); |
745 | list_for_each_entry_safe_reverse(new, prev, tx_list, node) { | ||
746 | list_del_init(&new->node); | ||
747 | dma_pool_free(fsl_chan->desc_pool, new, new->async_tx.phys); | ||
748 | } | ||
749 | |||
750 | return NULL; | 774 | return NULL; |
751 | } | 775 | } |
752 | 776 | ||
753 | static void fsl_dma_device_terminate_all(struct dma_chan *chan) | 777 | static void fsl_dma_device_terminate_all(struct dma_chan *dchan) |
754 | { | 778 | { |
755 | struct fsl_dma_chan *fsl_chan; | 779 | struct fsldma_chan *chan; |
756 | struct fsl_desc_sw *desc, *tmp; | ||
757 | unsigned long flags; | 780 | unsigned long flags; |
758 | 781 | ||
759 | if (!chan) | 782 | if (!dchan) |
760 | return; | 783 | return; |
761 | 784 | ||
762 | fsl_chan = to_fsl_chan(chan); | 785 | chan = to_fsl_chan(dchan); |
763 | 786 | ||
764 | /* Halt the DMA engine */ | 787 | /* Halt the DMA engine */ |
765 | dma_halt(fsl_chan); | 788 | dma_halt(chan); |
766 | 789 | ||
767 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | 790 | spin_lock_irqsave(&chan->desc_lock, flags); |
768 | 791 | ||
769 | /* Remove and free all of the descriptors in the LD queue */ | 792 | /* Remove and free all of the descriptors in the LD queue */ |
770 | list_for_each_entry_safe(desc, tmp, &fsl_chan->ld_queue, node) { | 793 | fsldma_free_desc_list(chan, &chan->ld_pending); |
771 | list_del(&desc->node); | 794 | fsldma_free_desc_list(chan, &chan->ld_running); |
772 | dma_pool_free(fsl_chan->desc_pool, desc, desc->async_tx.phys); | ||
773 | } | ||
774 | 795 | ||
775 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 796 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
776 | } | 797 | } |
777 | 798 | ||
778 | /** | 799 | /** |
779 | * fsl_dma_update_completed_cookie - Update the completed cookie. | 800 | * fsl_dma_update_completed_cookie - Update the completed cookie. |
780 | * @fsl_chan : Freescale DMA channel | 801 | * @chan : Freescale DMA channel |
802 | * | ||
803 | * CONTEXT: hardirq | ||
781 | */ | 804 | */ |
782 | static void fsl_dma_update_completed_cookie(struct fsl_dma_chan *fsl_chan) | 805 | static void fsl_dma_update_completed_cookie(struct fsldma_chan *chan) |
783 | { | 806 | { |
784 | struct fsl_desc_sw *cur_desc, *desc; | 807 | struct fsl_desc_sw *desc; |
785 | dma_addr_t ld_phy; | 808 | unsigned long flags; |
809 | dma_cookie_t cookie; | ||
786 | 810 | ||
787 | ld_phy = get_cdar(fsl_chan) & FSL_DMA_NLDA_MASK; | 811 | spin_lock_irqsave(&chan->desc_lock, flags); |
788 | 812 | ||
789 | if (ld_phy) { | 813 | if (list_empty(&chan->ld_running)) { |
790 | cur_desc = NULL; | 814 | dev_dbg(chan->dev, "no running descriptors\n"); |
791 | list_for_each_entry(desc, &fsl_chan->ld_queue, node) | 815 | goto out_unlock; |
792 | if (desc->async_tx.phys == ld_phy) { | 816 | } |
793 | cur_desc = desc; | ||
794 | break; | ||
795 | } | ||
796 | 817 | ||
797 | if (cur_desc && cur_desc->async_tx.cookie) { | 818 | /* Get the last descriptor, update the cookie to that */ |
798 | if (dma_is_idle(fsl_chan)) | 819 | desc = to_fsl_desc(chan->ld_running.prev); |
799 | fsl_chan->completed_cookie = | 820 | if (dma_is_idle(chan)) |
800 | cur_desc->async_tx.cookie; | 821 | cookie = desc->async_tx.cookie; |
801 | else | 822 | else { |
802 | fsl_chan->completed_cookie = | 823 | cookie = desc->async_tx.cookie - 1; |
803 | cur_desc->async_tx.cookie - 1; | 824 | if (unlikely(cookie < DMA_MIN_COOKIE)) |
804 | } | 825 | cookie = DMA_MAX_COOKIE; |
805 | } | 826 | } |
827 | |||
828 | chan->completed_cookie = cookie; | ||
829 | |||
830 | out_unlock: | ||
831 | spin_unlock_irqrestore(&chan->desc_lock, flags); | ||
832 | } | ||
833 | |||
834 | /** | ||
835 | * fsldma_desc_status - Check the status of a descriptor | ||
836 | * @chan: Freescale DMA channel | ||
837 | * @desc: DMA SW descriptor | ||
838 | * | ||
839 | * This function will return the status of the given descriptor | ||
840 | */ | ||
841 | static enum dma_status fsldma_desc_status(struct fsldma_chan *chan, | ||
842 | struct fsl_desc_sw *desc) | ||
843 | { | ||
844 | return dma_async_is_complete(desc->async_tx.cookie, | ||
845 | chan->completed_cookie, | ||
846 | chan->common.cookie); | ||
806 | } | 847 | } |
807 | 848 | ||
808 | /** | 849 | /** |
809 | * fsl_chan_ld_cleanup - Clean up link descriptors | 850 | * fsl_chan_ld_cleanup - Clean up link descriptors |
810 | * @fsl_chan : Freescale DMA channel | 851 | * @chan : Freescale DMA channel |
811 | * | 852 | * |
812 | * This function clean up the ld_queue of DMA channel. | 853 | * This function clean up the ld_queue of DMA channel. |
813 | * If 'in_intr' is set, the function will move the link descriptor to | ||
814 | * the recycle list. Otherwise, free it directly. | ||
815 | */ | 854 | */ |
816 | static void fsl_chan_ld_cleanup(struct fsl_dma_chan *fsl_chan) | 855 | static void fsl_chan_ld_cleanup(struct fsldma_chan *chan) |
817 | { | 856 | { |
818 | struct fsl_desc_sw *desc, *_desc; | 857 | struct fsl_desc_sw *desc, *_desc; |
819 | unsigned long flags; | 858 | unsigned long flags; |
820 | 859 | ||
821 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | 860 | spin_lock_irqsave(&chan->desc_lock, flags); |
822 | 861 | ||
823 | dev_dbg(fsl_chan->dev, "chan completed_cookie = %d\n", | 862 | dev_dbg(chan->dev, "chan completed_cookie = %d\n", chan->completed_cookie); |
824 | fsl_chan->completed_cookie); | 863 | list_for_each_entry_safe(desc, _desc, &chan->ld_running, node) { |
825 | list_for_each_entry_safe(desc, _desc, &fsl_chan->ld_queue, node) { | ||
826 | dma_async_tx_callback callback; | 864 | dma_async_tx_callback callback; |
827 | void *callback_param; | 865 | void *callback_param; |
828 | 866 | ||
829 | if (dma_async_is_complete(desc->async_tx.cookie, | 867 | if (fsldma_desc_status(chan, desc) == DMA_IN_PROGRESS) |
830 | fsl_chan->completed_cookie, fsl_chan->common.cookie) | ||
831 | == DMA_IN_PROGRESS) | ||
832 | break; | 868 | break; |
833 | 869 | ||
834 | callback = desc->async_tx.callback; | 870 | /* Remove from the list of running transactions */ |
835 | callback_param = desc->async_tx.callback_param; | ||
836 | |||
837 | /* Remove from ld_queue list */ | ||
838 | list_del(&desc->node); | 871 | list_del(&desc->node); |
839 | 872 | ||
840 | dev_dbg(fsl_chan->dev, "link descriptor %p will be recycle.\n", | ||
841 | desc); | ||
842 | dma_pool_free(fsl_chan->desc_pool, desc, desc->async_tx.phys); | ||
843 | |||
844 | /* Run the link descriptor callback function */ | 873 | /* Run the link descriptor callback function */ |
874 | callback = desc->async_tx.callback; | ||
875 | callback_param = desc->async_tx.callback_param; | ||
845 | if (callback) { | 876 | if (callback) { |
846 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 877 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
847 | dev_dbg(fsl_chan->dev, "link descriptor %p callback\n", | 878 | dev_dbg(chan->dev, "LD %p callback\n", desc); |
848 | desc); | ||
849 | callback(callback_param); | 879 | callback(callback_param); |
850 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | 880 | spin_lock_irqsave(&chan->desc_lock, flags); |
851 | } | 881 | } |
882 | |||
883 | /* Run any dependencies, then free the descriptor */ | ||
884 | dma_run_dependencies(&desc->async_tx); | ||
885 | dma_pool_free(chan->desc_pool, desc, desc->async_tx.phys); | ||
852 | } | 886 | } |
853 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 887 | |
888 | spin_unlock_irqrestore(&chan->desc_lock, flags); | ||
854 | } | 889 | } |
855 | 890 | ||
856 | /** | 891 | /** |
857 | * fsl_chan_xfer_ld_queue - Transfer link descriptors in channel ld_queue. | 892 | * fsl_chan_xfer_ld_queue - transfer any pending transactions |
858 | * @fsl_chan : Freescale DMA channel | 893 | * @chan : Freescale DMA channel |
894 | * | ||
895 | * This will make sure that any pending transactions will be run. | ||
896 | * If the DMA controller is idle, it will be started. Otherwise, | ||
897 | * the DMA controller's interrupt handler will start any pending | ||
898 | * transactions when it becomes idle. | ||
859 | */ | 899 | */ |
860 | static void fsl_chan_xfer_ld_queue(struct fsl_dma_chan *fsl_chan) | 900 | static void fsl_chan_xfer_ld_queue(struct fsldma_chan *chan) |
861 | { | 901 | { |
862 | struct list_head *ld_node; | 902 | struct fsl_desc_sw *desc; |
863 | dma_addr_t next_dest_addr; | ||
864 | unsigned long flags; | 903 | unsigned long flags; |
865 | 904 | ||
866 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | 905 | spin_lock_irqsave(&chan->desc_lock, flags); |
867 | 906 | ||
868 | if (!dma_is_idle(fsl_chan)) | 907 | /* |
908 | * If the list of pending descriptors is empty, then we | ||
909 | * don't need to do any work at all | ||
910 | */ | ||
911 | if (list_empty(&chan->ld_pending)) { | ||
912 | dev_dbg(chan->dev, "no pending LDs\n"); | ||
869 | goto out_unlock; | 913 | goto out_unlock; |
914 | } | ||
870 | 915 | ||
871 | dma_halt(fsl_chan); | 916 | /* |
917 | * The DMA controller is not idle, which means the interrupt | ||
918 | * handler will start any queued transactions when it runs | ||
919 | * at the end of the current transaction | ||
920 | */ | ||
921 | if (!dma_is_idle(chan)) { | ||
922 | dev_dbg(chan->dev, "DMA controller still busy\n"); | ||
923 | goto out_unlock; | ||
924 | } | ||
872 | 925 | ||
873 | /* If there are some link descriptors | 926 | /* |
874 | * not transfered in queue. We need to start it. | 927 | * TODO: |
928 | * make sure the dma_halt() function really un-wedges the | ||
929 | * controller as much as possible | ||
875 | */ | 930 | */ |
931 | dma_halt(chan); | ||
876 | 932 | ||
877 | /* Find the first un-transfer desciptor */ | 933 | /* |
878 | for (ld_node = fsl_chan->ld_queue.next; | 934 | * If there are some link descriptors which have not been |
879 | (ld_node != &fsl_chan->ld_queue) | 935 | * transferred, we need to start the controller |
880 | && (dma_async_is_complete( | 936 | */ |
881 | to_fsl_desc(ld_node)->async_tx.cookie, | 937 | |
882 | fsl_chan->completed_cookie, | 938 | /* |
883 | fsl_chan->common.cookie) == DMA_SUCCESS); | 939 | * Move all elements from the queue of pending transactions |
884 | ld_node = ld_node->next); | 940 | * onto the list of running transactions |
885 | 941 | */ | |
886 | if (ld_node != &fsl_chan->ld_queue) { | 942 | desc = list_first_entry(&chan->ld_pending, struct fsl_desc_sw, node); |
887 | /* Get the ld start address from ld_queue */ | 943 | list_splice_tail_init(&chan->ld_pending, &chan->ld_running); |
888 | next_dest_addr = to_fsl_desc(ld_node)->async_tx.phys; | 944 | |
889 | dev_dbg(fsl_chan->dev, "xfer LDs staring from 0x%llx\n", | 945 | /* |
890 | (unsigned long long)next_dest_addr); | 946 | * Program the descriptor's address into the DMA controller, |
891 | set_cdar(fsl_chan, next_dest_addr); | 947 | * then start the DMA transaction |
892 | dma_start(fsl_chan); | 948 | */ |
893 | } else { | 949 | set_cdar(chan, desc->async_tx.phys); |
894 | set_cdar(fsl_chan, 0); | 950 | dma_start(chan); |
895 | set_ndar(fsl_chan, 0); | ||
896 | } | ||
897 | 951 | ||
898 | out_unlock: | 952 | out_unlock: |
899 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | 953 | spin_unlock_irqrestore(&chan->desc_lock, flags); |
900 | } | 954 | } |
901 | 955 | ||
902 | /** | 956 | /** |
903 | * fsl_dma_memcpy_issue_pending - Issue the DMA start command | 957 | * fsl_dma_memcpy_issue_pending - Issue the DMA start command |
904 | * @fsl_chan : Freescale DMA channel | 958 | * @chan : Freescale DMA channel |
905 | */ | 959 | */ |
906 | static void fsl_dma_memcpy_issue_pending(struct dma_chan *chan) | 960 | static void fsl_dma_memcpy_issue_pending(struct dma_chan *dchan) |
907 | { | 961 | { |
908 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(chan); | 962 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
909 | 963 | fsl_chan_xfer_ld_queue(chan); | |
910 | #ifdef FSL_DMA_LD_DEBUG | ||
911 | struct fsl_desc_sw *ld; | ||
912 | unsigned long flags; | ||
913 | |||
914 | spin_lock_irqsave(&fsl_chan->desc_lock, flags); | ||
915 | if (list_empty(&fsl_chan->ld_queue)) { | ||
916 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | ||
917 | return; | ||
918 | } | ||
919 | |||
920 | dev_dbg(fsl_chan->dev, "--memcpy issue--\n"); | ||
921 | list_for_each_entry(ld, &fsl_chan->ld_queue, node) { | ||
922 | int i; | ||
923 | dev_dbg(fsl_chan->dev, "Ch %d, LD %08x\n", | ||
924 | fsl_chan->id, ld->async_tx.phys); | ||
925 | for (i = 0; i < 8; i++) | ||
926 | dev_dbg(fsl_chan->dev, "LD offset %d: %08x\n", | ||
927 | i, *(((u32 *)&ld->hw) + i)); | ||
928 | } | ||
929 | dev_dbg(fsl_chan->dev, "----------------\n"); | ||
930 | spin_unlock_irqrestore(&fsl_chan->desc_lock, flags); | ||
931 | #endif | ||
932 | |||
933 | fsl_chan_xfer_ld_queue(fsl_chan); | ||
934 | } | 964 | } |
935 | 965 | ||
936 | /** | 966 | /** |
937 | * fsl_dma_is_complete - Determine the DMA status | 967 | * fsl_dma_is_complete - Determine the DMA status |
938 | * @fsl_chan : Freescale DMA channel | 968 | * @chan : Freescale DMA channel |
939 | */ | 969 | */ |
940 | static enum dma_status fsl_dma_is_complete(struct dma_chan *chan, | 970 | static enum dma_status fsl_dma_is_complete(struct dma_chan *dchan, |
941 | dma_cookie_t cookie, | 971 | dma_cookie_t cookie, |
942 | dma_cookie_t *done, | 972 | dma_cookie_t *done, |
943 | dma_cookie_t *used) | 973 | dma_cookie_t *used) |
944 | { | 974 | { |
945 | struct fsl_dma_chan *fsl_chan = to_fsl_chan(chan); | 975 | struct fsldma_chan *chan = to_fsl_chan(dchan); |
946 | dma_cookie_t last_used; | 976 | dma_cookie_t last_used; |
947 | dma_cookie_t last_complete; | 977 | dma_cookie_t last_complete; |
948 | 978 | ||
949 | fsl_chan_ld_cleanup(fsl_chan); | 979 | fsl_chan_ld_cleanup(chan); |
950 | 980 | ||
951 | last_used = chan->cookie; | 981 | last_used = dchan->cookie; |
952 | last_complete = fsl_chan->completed_cookie; | 982 | last_complete = chan->completed_cookie; |
953 | 983 | ||
954 | if (done) | 984 | if (done) |
955 | *done = last_complete; | 985 | *done = last_complete; |
@@ -960,32 +990,37 @@ static enum dma_status fsl_dma_is_complete(struct dma_chan *chan, | |||
960 | return dma_async_is_complete(cookie, last_complete, last_used); | 990 | return dma_async_is_complete(cookie, last_complete, last_used); |
961 | } | 991 | } |
962 | 992 | ||
963 | static irqreturn_t fsl_dma_chan_do_interrupt(int irq, void *data) | 993 | /*----------------------------------------------------------------------------*/ |
994 | /* Interrupt Handling */ | ||
995 | /*----------------------------------------------------------------------------*/ | ||
996 | |||
997 | static irqreturn_t fsldma_chan_irq(int irq, void *data) | ||
964 | { | 998 | { |
965 | struct fsl_dma_chan *fsl_chan = (struct fsl_dma_chan *)data; | 999 | struct fsldma_chan *chan = data; |
966 | u32 stat; | ||
967 | int update_cookie = 0; | 1000 | int update_cookie = 0; |
968 | int xfer_ld_q = 0; | 1001 | int xfer_ld_q = 0; |
1002 | u32 stat; | ||
969 | 1003 | ||
970 | stat = get_sr(fsl_chan); | 1004 | /* save and clear the status register */ |
971 | dev_dbg(fsl_chan->dev, "event: channel %d, stat = 0x%x\n", | 1005 | stat = get_sr(chan); |
972 | fsl_chan->id, stat); | 1006 | set_sr(chan, stat); |
973 | set_sr(fsl_chan, stat); /* Clear the event register */ | 1007 | dev_dbg(chan->dev, "irq: channel %d, stat = 0x%x\n", chan->id, stat); |
974 | 1008 | ||
975 | stat &= ~(FSL_DMA_SR_CB | FSL_DMA_SR_CH); | 1009 | stat &= ~(FSL_DMA_SR_CB | FSL_DMA_SR_CH); |
976 | if (!stat) | 1010 | if (!stat) |
977 | return IRQ_NONE; | 1011 | return IRQ_NONE; |
978 | 1012 | ||
979 | if (stat & FSL_DMA_SR_TE) | 1013 | if (stat & FSL_DMA_SR_TE) |
980 | dev_err(fsl_chan->dev, "Transfer Error!\n"); | 1014 | dev_err(chan->dev, "Transfer Error!\n"); |
981 | 1015 | ||
982 | /* Programming Error | 1016 | /* |
1017 | * Programming Error | ||
983 | * The DMA_INTERRUPT async_tx is a NULL transfer, which will | 1018 | * The DMA_INTERRUPT async_tx is a NULL transfer, which will |
984 | * triger a PE interrupt. | 1019 | * triger a PE interrupt. |
985 | */ | 1020 | */ |
986 | if (stat & FSL_DMA_SR_PE) { | 1021 | if (stat & FSL_DMA_SR_PE) { |
987 | dev_dbg(fsl_chan->dev, "event: Programming Error INT\n"); | 1022 | dev_dbg(chan->dev, "irq: Programming Error INT\n"); |
988 | if (get_bcr(fsl_chan) == 0) { | 1023 | if (get_bcr(chan) == 0) { |
989 | /* BCR register is 0, this is a DMA_INTERRUPT async_tx. | 1024 | /* BCR register is 0, this is a DMA_INTERRUPT async_tx. |
990 | * Now, update the completed cookie, and continue the | 1025 | * Now, update the completed cookie, and continue the |
991 | * next uncompleted transfer. | 1026 | * next uncompleted transfer. |
@@ -996,208 +1031,296 @@ static irqreturn_t fsl_dma_chan_do_interrupt(int irq, void *data) | |||
996 | stat &= ~FSL_DMA_SR_PE; | 1031 | stat &= ~FSL_DMA_SR_PE; |
997 | } | 1032 | } |
998 | 1033 | ||
999 | /* If the link descriptor segment transfer finishes, | 1034 | /* |
1035 | * If the link descriptor segment transfer finishes, | ||
1000 | * we will recycle the used descriptor. | 1036 | * we will recycle the used descriptor. |
1001 | */ | 1037 | */ |
1002 | if (stat & FSL_DMA_SR_EOSI) { | 1038 | if (stat & FSL_DMA_SR_EOSI) { |
1003 | dev_dbg(fsl_chan->dev, "event: End-of-segments INT\n"); | 1039 | dev_dbg(chan->dev, "irq: End-of-segments INT\n"); |
1004 | dev_dbg(fsl_chan->dev, "event: clndar 0x%llx, nlndar 0x%llx\n", | 1040 | dev_dbg(chan->dev, "irq: clndar 0x%llx, nlndar 0x%llx\n", |
1005 | (unsigned long long)get_cdar(fsl_chan), | 1041 | (unsigned long long)get_cdar(chan), |
1006 | (unsigned long long)get_ndar(fsl_chan)); | 1042 | (unsigned long long)get_ndar(chan)); |
1007 | stat &= ~FSL_DMA_SR_EOSI; | 1043 | stat &= ~FSL_DMA_SR_EOSI; |
1008 | update_cookie = 1; | 1044 | update_cookie = 1; |
1009 | } | 1045 | } |
1010 | 1046 | ||
1011 | /* For MPC8349, EOCDI event need to update cookie | 1047 | /* |
1048 | * For MPC8349, EOCDI event need to update cookie | ||
1012 | * and start the next transfer if it exist. | 1049 | * and start the next transfer if it exist. |
1013 | */ | 1050 | */ |
1014 | if (stat & FSL_DMA_SR_EOCDI) { | 1051 | if (stat & FSL_DMA_SR_EOCDI) { |
1015 | dev_dbg(fsl_chan->dev, "event: End-of-Chain link INT\n"); | 1052 | dev_dbg(chan->dev, "irq: End-of-Chain link INT\n"); |
1016 | stat &= ~FSL_DMA_SR_EOCDI; | 1053 | stat &= ~FSL_DMA_SR_EOCDI; |
1017 | update_cookie = 1; | 1054 | update_cookie = 1; |
1018 | xfer_ld_q = 1; | 1055 | xfer_ld_q = 1; |
1019 | } | 1056 | } |
1020 | 1057 | ||
1021 | /* If it current transfer is the end-of-transfer, | 1058 | /* |
1059 | * If it current transfer is the end-of-transfer, | ||
1022 | * we should clear the Channel Start bit for | 1060 | * we should clear the Channel Start bit for |
1023 | * prepare next transfer. | 1061 | * prepare next transfer. |
1024 | */ | 1062 | */ |
1025 | if (stat & FSL_DMA_SR_EOLNI) { | 1063 | if (stat & FSL_DMA_SR_EOLNI) { |
1026 | dev_dbg(fsl_chan->dev, "event: End-of-link INT\n"); | 1064 | dev_dbg(chan->dev, "irq: End-of-link INT\n"); |
1027 | stat &= ~FSL_DMA_SR_EOLNI; | 1065 | stat &= ~FSL_DMA_SR_EOLNI; |
1028 | xfer_ld_q = 1; | 1066 | xfer_ld_q = 1; |
1029 | } | 1067 | } |
1030 | 1068 | ||
1031 | if (update_cookie) | 1069 | if (update_cookie) |
1032 | fsl_dma_update_completed_cookie(fsl_chan); | 1070 | fsl_dma_update_completed_cookie(chan); |
1033 | if (xfer_ld_q) | 1071 | if (xfer_ld_q) |
1034 | fsl_chan_xfer_ld_queue(fsl_chan); | 1072 | fsl_chan_xfer_ld_queue(chan); |
1035 | if (stat) | 1073 | if (stat) |
1036 | dev_dbg(fsl_chan->dev, "event: unhandled sr 0x%02x\n", | 1074 | dev_dbg(chan->dev, "irq: unhandled sr 0x%02x\n", stat); |
1037 | stat); | ||
1038 | 1075 | ||
1039 | dev_dbg(fsl_chan->dev, "event: Exit\n"); | 1076 | dev_dbg(chan->dev, "irq: Exit\n"); |
1040 | tasklet_schedule(&fsl_chan->tasklet); | 1077 | tasklet_schedule(&chan->tasklet); |
1041 | return IRQ_HANDLED; | 1078 | return IRQ_HANDLED; |
1042 | } | 1079 | } |
1043 | 1080 | ||
1044 | static irqreturn_t fsl_dma_do_interrupt(int irq, void *data) | 1081 | static void dma_do_tasklet(unsigned long data) |
1045 | { | 1082 | { |
1046 | struct fsl_dma_device *fdev = (struct fsl_dma_device *)data; | 1083 | struct fsldma_chan *chan = (struct fsldma_chan *)data; |
1047 | u32 gsr; | 1084 | fsl_chan_ld_cleanup(chan); |
1048 | int ch_nr; | 1085 | } |
1086 | |||
1087 | static irqreturn_t fsldma_ctrl_irq(int irq, void *data) | ||
1088 | { | ||
1089 | struct fsldma_device *fdev = data; | ||
1090 | struct fsldma_chan *chan; | ||
1091 | unsigned int handled = 0; | ||
1092 | u32 gsr, mask; | ||
1093 | int i; | ||
1049 | 1094 | ||
1050 | gsr = (fdev->feature & FSL_DMA_BIG_ENDIAN) ? in_be32(fdev->reg_base) | 1095 | gsr = (fdev->feature & FSL_DMA_BIG_ENDIAN) ? in_be32(fdev->regs) |
1051 | : in_le32(fdev->reg_base); | 1096 | : in_le32(fdev->regs); |
1052 | ch_nr = (32 - ffs(gsr)) / 8; | 1097 | mask = 0xff000000; |
1098 | dev_dbg(fdev->dev, "IRQ: gsr 0x%.8x\n", gsr); | ||
1099 | |||
1100 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { | ||
1101 | chan = fdev->chan[i]; | ||
1102 | if (!chan) | ||
1103 | continue; | ||
1104 | |||
1105 | if (gsr & mask) { | ||
1106 | dev_dbg(fdev->dev, "IRQ: chan %d\n", chan->id); | ||
1107 | fsldma_chan_irq(irq, chan); | ||
1108 | handled++; | ||
1109 | } | ||
1053 | 1110 | ||
1054 | return fdev->chan[ch_nr] ? fsl_dma_chan_do_interrupt(irq, | 1111 | gsr &= ~mask; |
1055 | fdev->chan[ch_nr]) : IRQ_NONE; | 1112 | mask >>= 8; |
1113 | } | ||
1114 | |||
1115 | return IRQ_RETVAL(handled); | ||
1056 | } | 1116 | } |
1057 | 1117 | ||
1058 | static void dma_do_tasklet(unsigned long data) | 1118 | static void fsldma_free_irqs(struct fsldma_device *fdev) |
1059 | { | 1119 | { |
1060 | struct fsl_dma_chan *fsl_chan = (struct fsl_dma_chan *)data; | 1120 | struct fsldma_chan *chan; |
1061 | fsl_chan_ld_cleanup(fsl_chan); | 1121 | int i; |
1122 | |||
1123 | if (fdev->irq != NO_IRQ) { | ||
1124 | dev_dbg(fdev->dev, "free per-controller IRQ\n"); | ||
1125 | free_irq(fdev->irq, fdev); | ||
1126 | return; | ||
1127 | } | ||
1128 | |||
1129 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { | ||
1130 | chan = fdev->chan[i]; | ||
1131 | if (chan && chan->irq != NO_IRQ) { | ||
1132 | dev_dbg(fdev->dev, "free channel %d IRQ\n", chan->id); | ||
1133 | free_irq(chan->irq, chan); | ||
1134 | } | ||
1135 | } | ||
1062 | } | 1136 | } |
1063 | 1137 | ||
1064 | static int __devinit fsl_dma_chan_probe(struct fsl_dma_device *fdev, | 1138 | static int fsldma_request_irqs(struct fsldma_device *fdev) |
1139 | { | ||
1140 | struct fsldma_chan *chan; | ||
1141 | int ret; | ||
1142 | int i; | ||
1143 | |||
1144 | /* if we have a per-controller IRQ, use that */ | ||
1145 | if (fdev->irq != NO_IRQ) { | ||
1146 | dev_dbg(fdev->dev, "request per-controller IRQ\n"); | ||
1147 | ret = request_irq(fdev->irq, fsldma_ctrl_irq, IRQF_SHARED, | ||
1148 | "fsldma-controller", fdev); | ||
1149 | return ret; | ||
1150 | } | ||
1151 | |||
1152 | /* no per-controller IRQ, use the per-channel IRQs */ | ||
1153 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { | ||
1154 | chan = fdev->chan[i]; | ||
1155 | if (!chan) | ||
1156 | continue; | ||
1157 | |||
1158 | if (chan->irq == NO_IRQ) { | ||
1159 | dev_err(fdev->dev, "no interrupts property defined for " | ||
1160 | "DMA channel %d. Please fix your " | ||
1161 | "device tree\n", chan->id); | ||
1162 | ret = -ENODEV; | ||
1163 | goto out_unwind; | ||
1164 | } | ||
1165 | |||
1166 | dev_dbg(fdev->dev, "request channel %d IRQ\n", chan->id); | ||
1167 | ret = request_irq(chan->irq, fsldma_chan_irq, IRQF_SHARED, | ||
1168 | "fsldma-chan", chan); | ||
1169 | if (ret) { | ||
1170 | dev_err(fdev->dev, "unable to request IRQ for DMA " | ||
1171 | "channel %d\n", chan->id); | ||
1172 | goto out_unwind; | ||
1173 | } | ||
1174 | } | ||
1175 | |||
1176 | return 0; | ||
1177 | |||
1178 | out_unwind: | ||
1179 | for (/* none */; i >= 0; i--) { | ||
1180 | chan = fdev->chan[i]; | ||
1181 | if (!chan) | ||
1182 | continue; | ||
1183 | |||
1184 | if (chan->irq == NO_IRQ) | ||
1185 | continue; | ||
1186 | |||
1187 | free_irq(chan->irq, chan); | ||
1188 | } | ||
1189 | |||
1190 | return ret; | ||
1191 | } | ||
1192 | |||
1193 | /*----------------------------------------------------------------------------*/ | ||
1194 | /* OpenFirmware Subsystem */ | ||
1195 | /*----------------------------------------------------------------------------*/ | ||
1196 | |||
1197 | static int __devinit fsl_dma_chan_probe(struct fsldma_device *fdev, | ||
1065 | struct device_node *node, u32 feature, const char *compatible) | 1198 | struct device_node *node, u32 feature, const char *compatible) |
1066 | { | 1199 | { |
1067 | struct fsl_dma_chan *new_fsl_chan; | 1200 | struct fsldma_chan *chan; |
1201 | struct resource res; | ||
1068 | int err; | 1202 | int err; |
1069 | 1203 | ||
1070 | /* alloc channel */ | 1204 | /* alloc channel */ |
1071 | new_fsl_chan = kzalloc(sizeof(struct fsl_dma_chan), GFP_KERNEL); | 1205 | chan = kzalloc(sizeof(*chan), GFP_KERNEL); |
1072 | if (!new_fsl_chan) { | 1206 | if (!chan) { |
1073 | dev_err(fdev->dev, "No free memory for allocating " | 1207 | dev_err(fdev->dev, "no free memory for DMA channels!\n"); |
1074 | "dma channels!\n"); | 1208 | err = -ENOMEM; |
1075 | return -ENOMEM; | 1209 | goto out_return; |
1076 | } | 1210 | } |
1077 | 1211 | ||
1078 | /* get dma channel register base */ | 1212 | /* ioremap registers for use */ |
1079 | err = of_address_to_resource(node, 0, &new_fsl_chan->reg); | 1213 | chan->regs = of_iomap(node, 0); |
1080 | if (err) { | 1214 | if (!chan->regs) { |
1081 | dev_err(fdev->dev, "Can't get %s property 'reg'\n", | 1215 | dev_err(fdev->dev, "unable to ioremap registers\n"); |
1082 | node->full_name); | 1216 | err = -ENOMEM; |
1083 | goto err_no_reg; | 1217 | goto out_free_chan; |
1084 | } | 1218 | } |
1085 | 1219 | ||
1086 | new_fsl_chan->feature = feature; | 1220 | err = of_address_to_resource(node, 0, &res); |
1221 | if (err) { | ||
1222 | dev_err(fdev->dev, "unable to find 'reg' property\n"); | ||
1223 | goto out_iounmap_regs; | ||
1224 | } | ||
1087 | 1225 | ||
1226 | chan->feature = feature; | ||
1088 | if (!fdev->feature) | 1227 | if (!fdev->feature) |
1089 | fdev->feature = new_fsl_chan->feature; | 1228 | fdev->feature = chan->feature; |
1090 | 1229 | ||
1091 | /* If the DMA device's feature is different than its channels', | 1230 | /* |
1092 | * report the bug. | 1231 | * If the DMA device's feature is different than the feature |
1232 | * of its channels, report the bug | ||
1093 | */ | 1233 | */ |
1094 | WARN_ON(fdev->feature != new_fsl_chan->feature); | 1234 | WARN_ON(fdev->feature != chan->feature); |
1095 | 1235 | ||
1096 | new_fsl_chan->dev = fdev->dev; | 1236 | chan->dev = fdev->dev; |
1097 | new_fsl_chan->reg_base = ioremap(new_fsl_chan->reg.start, | 1237 | chan->id = ((res.start - 0x100) & 0xfff) >> 7; |
1098 | new_fsl_chan->reg.end - new_fsl_chan->reg.start + 1); | 1238 | if (chan->id >= FSL_DMA_MAX_CHANS_PER_DEVICE) { |
1099 | 1239 | dev_err(fdev->dev, "too many channels for device\n"); | |
1100 | new_fsl_chan->id = ((new_fsl_chan->reg.start - 0x100) & 0xfff) >> 7; | ||
1101 | if (new_fsl_chan->id >= FSL_DMA_MAX_CHANS_PER_DEVICE) { | ||
1102 | dev_err(fdev->dev, "There is no %d channel!\n", | ||
1103 | new_fsl_chan->id); | ||
1104 | err = -EINVAL; | 1240 | err = -EINVAL; |
1105 | goto err_no_chan; | 1241 | goto out_iounmap_regs; |
1106 | } | 1242 | } |
1107 | fdev->chan[new_fsl_chan->id] = new_fsl_chan; | ||
1108 | tasklet_init(&new_fsl_chan->tasklet, dma_do_tasklet, | ||
1109 | (unsigned long)new_fsl_chan); | ||
1110 | 1243 | ||
1111 | /* Init the channel */ | 1244 | fdev->chan[chan->id] = chan; |
1112 | dma_init(new_fsl_chan); | 1245 | tasklet_init(&chan->tasklet, dma_do_tasklet, (unsigned long)chan); |
1246 | |||
1247 | /* Initialize the channel */ | ||
1248 | dma_init(chan); | ||
1113 | 1249 | ||
1114 | /* Clear cdar registers */ | 1250 | /* Clear cdar registers */ |
1115 | set_cdar(new_fsl_chan, 0); | 1251 | set_cdar(chan, 0); |
1116 | 1252 | ||
1117 | switch (new_fsl_chan->feature & FSL_DMA_IP_MASK) { | 1253 | switch (chan->feature & FSL_DMA_IP_MASK) { |
1118 | case FSL_DMA_IP_85XX: | 1254 | case FSL_DMA_IP_85XX: |
1119 | new_fsl_chan->toggle_ext_pause = fsl_chan_toggle_ext_pause; | 1255 | chan->toggle_ext_pause = fsl_chan_toggle_ext_pause; |
1120 | case FSL_DMA_IP_83XX: | 1256 | case FSL_DMA_IP_83XX: |
1121 | new_fsl_chan->toggle_ext_start = fsl_chan_toggle_ext_start; | 1257 | chan->toggle_ext_start = fsl_chan_toggle_ext_start; |
1122 | new_fsl_chan->set_src_loop_size = fsl_chan_set_src_loop_size; | 1258 | chan->set_src_loop_size = fsl_chan_set_src_loop_size; |
1123 | new_fsl_chan->set_dest_loop_size = fsl_chan_set_dest_loop_size; | 1259 | chan->set_dst_loop_size = fsl_chan_set_dst_loop_size; |
1124 | new_fsl_chan->set_request_count = fsl_chan_set_request_count; | 1260 | chan->set_request_count = fsl_chan_set_request_count; |
1125 | } | 1261 | } |
1126 | 1262 | ||
1127 | spin_lock_init(&new_fsl_chan->desc_lock); | 1263 | spin_lock_init(&chan->desc_lock); |
1128 | INIT_LIST_HEAD(&new_fsl_chan->ld_queue); | 1264 | INIT_LIST_HEAD(&chan->ld_pending); |
1265 | INIT_LIST_HEAD(&chan->ld_running); | ||
1266 | |||
1267 | chan->common.device = &fdev->common; | ||
1129 | 1268 | ||
1130 | new_fsl_chan->common.device = &fdev->common; | 1269 | /* find the IRQ line, if it exists in the device tree */ |
1270 | chan->irq = irq_of_parse_and_map(node, 0); | ||
1131 | 1271 | ||
1132 | /* Add the channel to DMA device channel list */ | 1272 | /* Add the channel to DMA device channel list */ |
1133 | list_add_tail(&new_fsl_chan->common.device_node, | 1273 | list_add_tail(&chan->common.device_node, &fdev->common.channels); |
1134 | &fdev->common.channels); | ||
1135 | fdev->common.chancnt++; | 1274 | fdev->common.chancnt++; |
1136 | 1275 | ||
1137 | new_fsl_chan->irq = irq_of_parse_and_map(node, 0); | 1276 | dev_info(fdev->dev, "#%d (%s), irq %d\n", chan->id, compatible, |
1138 | if (new_fsl_chan->irq != NO_IRQ) { | 1277 | chan->irq != NO_IRQ ? chan->irq : fdev->irq); |
1139 | err = request_irq(new_fsl_chan->irq, | ||
1140 | &fsl_dma_chan_do_interrupt, IRQF_SHARED, | ||
1141 | "fsldma-channel", new_fsl_chan); | ||
1142 | if (err) { | ||
1143 | dev_err(fdev->dev, "DMA channel %s request_irq error " | ||
1144 | "with return %d\n", node->full_name, err); | ||
1145 | goto err_no_irq; | ||
1146 | } | ||
1147 | } | ||
1148 | |||
1149 | dev_info(fdev->dev, "#%d (%s), irq %d\n", new_fsl_chan->id, | ||
1150 | compatible, | ||
1151 | new_fsl_chan->irq != NO_IRQ ? new_fsl_chan->irq : fdev->irq); | ||
1152 | 1278 | ||
1153 | return 0; | 1279 | return 0; |
1154 | 1280 | ||
1155 | err_no_irq: | 1281 | out_iounmap_regs: |
1156 | list_del(&new_fsl_chan->common.device_node); | 1282 | iounmap(chan->regs); |
1157 | err_no_chan: | 1283 | out_free_chan: |
1158 | iounmap(new_fsl_chan->reg_base); | 1284 | kfree(chan); |
1159 | err_no_reg: | 1285 | out_return: |
1160 | kfree(new_fsl_chan); | ||
1161 | return err; | 1286 | return err; |
1162 | } | 1287 | } |
1163 | 1288 | ||
1164 | static void fsl_dma_chan_remove(struct fsl_dma_chan *fchan) | 1289 | static void fsl_dma_chan_remove(struct fsldma_chan *chan) |
1165 | { | 1290 | { |
1166 | if (fchan->irq != NO_IRQ) | 1291 | irq_dispose_mapping(chan->irq); |
1167 | free_irq(fchan->irq, fchan); | 1292 | list_del(&chan->common.device_node); |
1168 | list_del(&fchan->common.device_node); | 1293 | iounmap(chan->regs); |
1169 | iounmap(fchan->reg_base); | 1294 | kfree(chan); |
1170 | kfree(fchan); | ||
1171 | } | 1295 | } |
1172 | 1296 | ||
1173 | static int __devinit of_fsl_dma_probe(struct of_device *dev, | 1297 | static int __devinit fsldma_of_probe(struct of_device *op, |
1174 | const struct of_device_id *match) | 1298 | const struct of_device_id *match) |
1175 | { | 1299 | { |
1176 | int err; | 1300 | struct fsldma_device *fdev; |
1177 | struct fsl_dma_device *fdev; | ||
1178 | struct device_node *child; | 1301 | struct device_node *child; |
1302 | int err; | ||
1179 | 1303 | ||
1180 | fdev = kzalloc(sizeof(struct fsl_dma_device), GFP_KERNEL); | 1304 | fdev = kzalloc(sizeof(*fdev), GFP_KERNEL); |
1181 | if (!fdev) { | 1305 | if (!fdev) { |
1182 | dev_err(&dev->dev, "No enough memory for 'priv'\n"); | 1306 | dev_err(&op->dev, "No enough memory for 'priv'\n"); |
1183 | return -ENOMEM; | 1307 | err = -ENOMEM; |
1308 | goto out_return; | ||
1184 | } | 1309 | } |
1185 | fdev->dev = &dev->dev; | 1310 | |
1311 | fdev->dev = &op->dev; | ||
1186 | INIT_LIST_HEAD(&fdev->common.channels); | 1312 | INIT_LIST_HEAD(&fdev->common.channels); |
1187 | 1313 | ||
1188 | /* get DMA controller register base */ | 1314 | /* ioremap the registers for use */ |
1189 | err = of_address_to_resource(dev->node, 0, &fdev->reg); | 1315 | fdev->regs = of_iomap(op->node, 0); |
1190 | if (err) { | 1316 | if (!fdev->regs) { |
1191 | dev_err(&dev->dev, "Can't get %s property 'reg'\n", | 1317 | dev_err(&op->dev, "unable to ioremap registers\n"); |
1192 | dev->node->full_name); | 1318 | err = -ENOMEM; |
1193 | goto err_no_reg; | 1319 | goto out_free_fdev; |
1194 | } | 1320 | } |
1195 | 1321 | ||
1196 | dev_info(&dev->dev, "Probe the Freescale DMA driver for %s " | 1322 | /* map the channel IRQ if it exists, but don't hookup the handler yet */ |
1197 | "controller at 0x%llx...\n", | 1323 | fdev->irq = irq_of_parse_and_map(op->node, 0); |
1198 | match->compatible, (unsigned long long)fdev->reg.start); | ||
1199 | fdev->reg_base = ioremap(fdev->reg.start, fdev->reg.end | ||
1200 | - fdev->reg.start + 1); | ||
1201 | 1324 | ||
1202 | dma_cap_set(DMA_MEMCPY, fdev->common.cap_mask); | 1325 | dma_cap_set(DMA_MEMCPY, fdev->common.cap_mask); |
1203 | dma_cap_set(DMA_INTERRUPT, fdev->common.cap_mask); | 1326 | dma_cap_set(DMA_INTERRUPT, fdev->common.cap_mask); |
@@ -1210,103 +1333,111 @@ static int __devinit of_fsl_dma_probe(struct of_device *dev, | |||
1210 | fdev->common.device_issue_pending = fsl_dma_memcpy_issue_pending; | 1333 | fdev->common.device_issue_pending = fsl_dma_memcpy_issue_pending; |
1211 | fdev->common.device_prep_slave_sg = fsl_dma_prep_slave_sg; | 1334 | fdev->common.device_prep_slave_sg = fsl_dma_prep_slave_sg; |
1212 | fdev->common.device_terminate_all = fsl_dma_device_terminate_all; | 1335 | fdev->common.device_terminate_all = fsl_dma_device_terminate_all; |
1213 | fdev->common.dev = &dev->dev; | 1336 | fdev->common.dev = &op->dev; |
1214 | 1337 | ||
1215 | fdev->irq = irq_of_parse_and_map(dev->node, 0); | 1338 | dev_set_drvdata(&op->dev, fdev); |
1216 | if (fdev->irq != NO_IRQ) { | ||
1217 | err = request_irq(fdev->irq, &fsl_dma_do_interrupt, IRQF_SHARED, | ||
1218 | "fsldma-device", fdev); | ||
1219 | if (err) { | ||
1220 | dev_err(&dev->dev, "DMA device request_irq error " | ||
1221 | "with return %d\n", err); | ||
1222 | goto err; | ||
1223 | } | ||
1224 | } | ||
1225 | |||
1226 | dev_set_drvdata(&(dev->dev), fdev); | ||
1227 | 1339 | ||
1228 | /* We cannot use of_platform_bus_probe() because there is no | 1340 | /* |
1229 | * of_platform_bus_remove. Instead, we manually instantiate every DMA | 1341 | * We cannot use of_platform_bus_probe() because there is no |
1342 | * of_platform_bus_remove(). Instead, we manually instantiate every DMA | ||
1230 | * channel object. | 1343 | * channel object. |
1231 | */ | 1344 | */ |
1232 | for_each_child_of_node(dev->node, child) { | 1345 | for_each_child_of_node(op->node, child) { |
1233 | if (of_device_is_compatible(child, "fsl,eloplus-dma-channel")) | 1346 | if (of_device_is_compatible(child, "fsl,eloplus-dma-channel")) { |
1234 | fsl_dma_chan_probe(fdev, child, | 1347 | fsl_dma_chan_probe(fdev, child, |
1235 | FSL_DMA_IP_85XX | FSL_DMA_BIG_ENDIAN, | 1348 | FSL_DMA_IP_85XX | FSL_DMA_BIG_ENDIAN, |
1236 | "fsl,eloplus-dma-channel"); | 1349 | "fsl,eloplus-dma-channel"); |
1237 | if (of_device_is_compatible(child, "fsl,elo-dma-channel")) | 1350 | } |
1351 | |||
1352 | if (of_device_is_compatible(child, "fsl,elo-dma-channel")) { | ||
1238 | fsl_dma_chan_probe(fdev, child, | 1353 | fsl_dma_chan_probe(fdev, child, |
1239 | FSL_DMA_IP_83XX | FSL_DMA_LITTLE_ENDIAN, | 1354 | FSL_DMA_IP_83XX | FSL_DMA_LITTLE_ENDIAN, |
1240 | "fsl,elo-dma-channel"); | 1355 | "fsl,elo-dma-channel"); |
1356 | } | ||
1357 | } | ||
1358 | |||
1359 | /* | ||
1360 | * Hookup the IRQ handler(s) | ||
1361 | * | ||
1362 | * If we have a per-controller interrupt, we prefer that to the | ||
1363 | * per-channel interrupts to reduce the number of shared interrupt | ||
1364 | * handlers on the same IRQ line | ||
1365 | */ | ||
1366 | err = fsldma_request_irqs(fdev); | ||
1367 | if (err) { | ||
1368 | dev_err(fdev->dev, "unable to request IRQs\n"); | ||
1369 | goto out_free_fdev; | ||
1241 | } | 1370 | } |
1242 | 1371 | ||
1243 | dma_async_device_register(&fdev->common); | 1372 | dma_async_device_register(&fdev->common); |
1244 | return 0; | 1373 | return 0; |
1245 | 1374 | ||
1246 | err: | 1375 | out_free_fdev: |
1247 | iounmap(fdev->reg_base); | 1376 | irq_dispose_mapping(fdev->irq); |
1248 | err_no_reg: | ||
1249 | kfree(fdev); | 1377 | kfree(fdev); |
1378 | out_return: | ||
1250 | return err; | 1379 | return err; |
1251 | } | 1380 | } |
1252 | 1381 | ||
1253 | static int of_fsl_dma_remove(struct of_device *of_dev) | 1382 | static int fsldma_of_remove(struct of_device *op) |
1254 | { | 1383 | { |
1255 | struct fsl_dma_device *fdev; | 1384 | struct fsldma_device *fdev; |
1256 | unsigned int i; | 1385 | unsigned int i; |
1257 | 1386 | ||
1258 | fdev = dev_get_drvdata(&of_dev->dev); | 1387 | fdev = dev_get_drvdata(&op->dev); |
1259 | |||
1260 | dma_async_device_unregister(&fdev->common); | 1388 | dma_async_device_unregister(&fdev->common); |
1261 | 1389 | ||
1262 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) | 1390 | fsldma_free_irqs(fdev); |
1391 | |||
1392 | for (i = 0; i < FSL_DMA_MAX_CHANS_PER_DEVICE; i++) { | ||
1263 | if (fdev->chan[i]) | 1393 | if (fdev->chan[i]) |
1264 | fsl_dma_chan_remove(fdev->chan[i]); | 1394 | fsl_dma_chan_remove(fdev->chan[i]); |
1395 | } | ||
1265 | 1396 | ||
1266 | if (fdev->irq != NO_IRQ) | 1397 | iounmap(fdev->regs); |
1267 | free_irq(fdev->irq, fdev); | 1398 | dev_set_drvdata(&op->dev, NULL); |
1268 | |||
1269 | iounmap(fdev->reg_base); | ||
1270 | |||
1271 | kfree(fdev); | 1399 | kfree(fdev); |
1272 | dev_set_drvdata(&of_dev->dev, NULL); | ||
1273 | 1400 | ||
1274 | return 0; | 1401 | return 0; |
1275 | } | 1402 | } |
1276 | 1403 | ||
1277 | static struct of_device_id of_fsl_dma_ids[] = { | 1404 | static const struct of_device_id fsldma_of_ids[] = { |
1278 | { .compatible = "fsl,eloplus-dma", }, | 1405 | { .compatible = "fsl,eloplus-dma", }, |
1279 | { .compatible = "fsl,elo-dma", }, | 1406 | { .compatible = "fsl,elo-dma", }, |
1280 | {} | 1407 | {} |
1281 | }; | 1408 | }; |
1282 | 1409 | ||
1283 | static struct of_platform_driver of_fsl_dma_driver = { | 1410 | static struct of_platform_driver fsldma_of_driver = { |
1284 | .name = "fsl-elo-dma", | 1411 | .name = "fsl-elo-dma", |
1285 | .match_table = of_fsl_dma_ids, | 1412 | .match_table = fsldma_of_ids, |
1286 | .probe = of_fsl_dma_probe, | 1413 | .probe = fsldma_of_probe, |
1287 | .remove = of_fsl_dma_remove, | 1414 | .remove = fsldma_of_remove, |
1288 | }; | 1415 | }; |
1289 | 1416 | ||
1290 | static __init int of_fsl_dma_init(void) | 1417 | /*----------------------------------------------------------------------------*/ |
1418 | /* Module Init / Exit */ | ||
1419 | /*----------------------------------------------------------------------------*/ | ||
1420 | |||
1421 | static __init int fsldma_init(void) | ||
1291 | { | 1422 | { |
1292 | int ret; | 1423 | int ret; |
1293 | 1424 | ||
1294 | pr_info("Freescale Elo / Elo Plus DMA driver\n"); | 1425 | pr_info("Freescale Elo / Elo Plus DMA driver\n"); |
1295 | 1426 | ||
1296 | ret = of_register_platform_driver(&of_fsl_dma_driver); | 1427 | ret = of_register_platform_driver(&fsldma_of_driver); |
1297 | if (ret) | 1428 | if (ret) |
1298 | pr_err("fsldma: failed to register platform driver\n"); | 1429 | pr_err("fsldma: failed to register platform driver\n"); |
1299 | 1430 | ||
1300 | return ret; | 1431 | return ret; |
1301 | } | 1432 | } |
1302 | 1433 | ||
1303 | static void __exit of_fsl_dma_exit(void) | 1434 | static void __exit fsldma_exit(void) |
1304 | { | 1435 | { |
1305 | of_unregister_platform_driver(&of_fsl_dma_driver); | 1436 | of_unregister_platform_driver(&fsldma_of_driver); |
1306 | } | 1437 | } |
1307 | 1438 | ||
1308 | subsys_initcall(of_fsl_dma_init); | 1439 | subsys_initcall(fsldma_init); |
1309 | module_exit(of_fsl_dma_exit); | 1440 | module_exit(fsldma_exit); |
1310 | 1441 | ||
1311 | MODULE_DESCRIPTION("Freescale Elo / Elo Plus DMA driver"); | 1442 | MODULE_DESCRIPTION("Freescale Elo / Elo Plus DMA driver"); |
1312 | MODULE_LICENSE("GPL"); | 1443 | MODULE_LICENSE("GPL"); |