blob: 69eb040d3247e61779ccfc13e8709f4c42bd5513 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutf7c752c2011-11-08 23:18:15 +00002/*
3 * Freescale i.MX28 APBH DMA driver
4 *
5 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
6 * on behalf of DENX Software Engineering GmbH
7 *
8 * Based on code from LTIB:
9 * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
Peng Fan128abf42020-05-04 22:09:00 +080010 * Copyright 2017 NXP
11 *
Marek Vasutf7c752c2011-11-08 23:18:15 +000012 */
13
Simon Glass63334482019-11-14 12:57:39 -070014#include <cpu_func.h>
Marek Vasutf7c752c2011-11-08 23:18:15 +000015#include <linux/list.h>
16
17#include <common.h>
18#include <malloc.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090019#include <linux/errno.h>
Marek Vasutf7c752c2011-11-08 23:18:15 +000020#include <asm/io.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/imx-regs.h>
23#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020024#include <asm/mach-imx/dma.h>
25#include <asm/mach-imx/regs-apbh.h>
Marek Vasutf7c752c2011-11-08 23:18:15 +000026
27static struct mxs_dma_chan mxs_dma_channels[MXS_MAX_DMA_CHANNELS];
28
29/*
30 * Test is the DMA channel is valid channel
31 */
32int mxs_dma_validate_chan(int channel)
33{
34 struct mxs_dma_chan *pchan;
35
36 if ((channel < 0) || (channel >= MXS_MAX_DMA_CHANNELS))
37 return -EINVAL;
38
39 pchan = mxs_dma_channels + channel;
40 if (!(pchan->flags & MXS_DMA_FLAGS_ALLOCATED))
41 return -EINVAL;
42
43 return 0;
44}
45
46/*
Marek Vasut4742c262011-11-23 10:59:13 +000047 * Return the address of the command within a descriptor.
48 */
49static unsigned int mxs_dma_cmd_address(struct mxs_dma_desc *desc)
50{
51 return desc->address + offsetof(struct mxs_dma_desc, cmd);
52}
53
54/*
55 * Read a DMA channel's hardware semaphore.
56 *
57 * As used by the MXS platform's DMA software, the DMA channel's hardware
58 * semaphore reflects the number of DMA commands the hardware will process, but
59 * has not yet finished. This is a volatile value read directly from hardware,
60 * so it must be be viewed as immediately stale.
61 *
62 * If the channel is not marked busy, or has finished processing all its
63 * commands, this value should be zero.
64 *
65 * See mxs_dma_append() for details on how DMA command blocks must be configured
66 * to maintain the expected behavior of the semaphore's value.
67 */
68static int mxs_dma_read_semaphore(int channel)
69{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000070 struct mxs_apbh_regs *apbh_regs =
71 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasut4742c262011-11-23 10:59:13 +000072 uint32_t tmp;
73 int ret;
74
75 ret = mxs_dma_validate_chan(channel);
76 if (ret)
77 return ret;
78
79 tmp = readl(&apbh_regs->ch[channel].hw_apbh_ch_sema);
80
81 tmp &= APBH_CHn_SEMA_PHORE_MASK;
82 tmp >>= APBH_CHn_SEMA_PHORE_OFFSET;
83
84 return tmp;
85}
86
Trevor Woerner43ec7e02019-05-03 09:41:00 -040087#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Marek Vasut26427662012-03-15 18:33:18 +000088void mxs_dma_flush_desc(struct mxs_dma_desc *desc)
89{
90 uint32_t addr;
91 uint32_t size;
92
Peng Fan128abf42020-05-04 22:09:00 +080093 addr = (uintptr_t)desc;
Marek Vasut26427662012-03-15 18:33:18 +000094 size = roundup(sizeof(struct mxs_dma_desc), MXS_DMA_ALIGNMENT);
95
96 flush_dcache_range(addr, addr + size);
97}
98#else
99inline void mxs_dma_flush_desc(struct mxs_dma_desc *desc) {}
100#endif
101
Marek Vasut4742c262011-11-23 10:59:13 +0000102/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000103 * Enable a DMA channel.
104 *
105 * If the given channel has any DMA descriptors on its active list, this
106 * function causes the DMA hardware to begin processing them.
107 *
108 * This function marks the DMA channel as "busy," whether or not there are any
109 * descriptors to process.
110 */
Marek Vasut4742c262011-11-23 10:59:13 +0000111static int mxs_dma_enable(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000112{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000113 struct mxs_apbh_regs *apbh_regs =
114 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000115 unsigned int sem;
116 struct mxs_dma_chan *pchan;
117 struct mxs_dma_desc *pdesc;
118 int ret;
119
120 ret = mxs_dma_validate_chan(channel);
121 if (ret)
122 return ret;
123
124 pchan = mxs_dma_channels + channel;
125
126 if (pchan->pending_num == 0) {
127 pchan->flags |= MXS_DMA_FLAGS_BUSY;
128 return 0;
129 }
130
131 pdesc = list_first_entry(&pchan->active, struct mxs_dma_desc, node);
132 if (pdesc == NULL)
133 return -EFAULT;
134
135 if (pchan->flags & MXS_DMA_FLAGS_BUSY) {
136 if (!(pdesc->cmd.data & MXS_DMA_DESC_CHAIN))
137 return 0;
138
139 sem = mxs_dma_read_semaphore(channel);
140 if (sem == 0)
141 return 0;
142
143 if (sem == 1) {
144 pdesc = list_entry(pdesc->node.next,
145 struct mxs_dma_desc, node);
146 writel(mxs_dma_cmd_address(pdesc),
147 &apbh_regs->ch[channel].hw_apbh_ch_nxtcmdar);
148 }
149 writel(pchan->pending_num,
150 &apbh_regs->ch[channel].hw_apbh_ch_sema);
151 pchan->active_num += pchan->pending_num;
152 pchan->pending_num = 0;
153 } else {
154 pchan->active_num += pchan->pending_num;
155 pchan->pending_num = 0;
156 writel(mxs_dma_cmd_address(pdesc),
157 &apbh_regs->ch[channel].hw_apbh_ch_nxtcmdar);
158 writel(pchan->active_num,
159 &apbh_regs->ch[channel].hw_apbh_ch_sema);
160 writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
161 &apbh_regs->hw_apbh_ctrl0_clr);
162 }
163
164 pchan->flags |= MXS_DMA_FLAGS_BUSY;
165 return 0;
166}
167
168/*
169 * Disable a DMA channel.
170 *
171 * This function shuts down a DMA channel and marks it as "not busy." Any
172 * descriptors on the active list are immediately moved to the head of the
173 * "done" list, whether or not they have actually been processed by the
174 * hardware. The "ready" flags of these descriptors are NOT cleared, so they
175 * still appear to be active.
176 *
177 * This function immediately shuts down a DMA channel's hardware, aborting any
178 * I/O that may be in progress, potentially leaving I/O hardware in an undefined
179 * state. It is unwise to call this function if there is ANY chance the hardware
180 * is still processing a command.
181 */
Marek Vasut4742c262011-11-23 10:59:13 +0000182static int mxs_dma_disable(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000183{
184 struct mxs_dma_chan *pchan;
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000185 struct mxs_apbh_regs *apbh_regs =
186 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000187 int ret;
188
189 ret = mxs_dma_validate_chan(channel);
190 if (ret)
191 return ret;
192
193 pchan = mxs_dma_channels + channel;
194
195 if (!(pchan->flags & MXS_DMA_FLAGS_BUSY))
196 return -EINVAL;
197
198 writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
199 &apbh_regs->hw_apbh_ctrl0_set);
200
201 pchan->flags &= ~MXS_DMA_FLAGS_BUSY;
202 pchan->active_num = 0;
203 pchan->pending_num = 0;
204 list_splice_init(&pchan->active, &pchan->done);
205
206 return 0;
207}
208
209/*
210 * Resets the DMA channel hardware.
211 */
Marek Vasut4742c262011-11-23 10:59:13 +0000212static int mxs_dma_reset(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000213{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000214 struct mxs_apbh_regs *apbh_regs =
215 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000216 int ret;
Marek Vasut154af3a2013-01-22 15:01:00 +0000217#if defined(CONFIG_MX23)
218 uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_ctrl0_set);
219 uint32_t offset = APBH_CTRL0_RESET_CHANNEL_OFFSET;
Peng Fan128abf42020-05-04 22:09:00 +0800220#elif defined(CONFIG_MX28) || defined(CONFIG_MX6) || defined(CONFIG_MX7) || \
221 defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
222 u32 setreg = (uintptr_t)(&apbh_regs->hw_apbh_channel_ctrl_set);
223 u32 offset = APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET;
Marek Vasut154af3a2013-01-22 15:01:00 +0000224#endif
Marek Vasutf7c752c2011-11-08 23:18:15 +0000225
226 ret = mxs_dma_validate_chan(channel);
227 if (ret)
228 return ret;
229
Peng Fan128abf42020-05-04 22:09:00 +0800230 writel(1 << (channel + offset), (uintptr_t)setreg);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000231
232 return 0;
233}
234
235/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000236 * Enable or disable DMA interrupt.
237 *
238 * This function enables the given DMA channel to interrupt the CPU.
239 */
Marek Vasut4742c262011-11-23 10:59:13 +0000240static int mxs_dma_enable_irq(int channel, int enable)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000241{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000242 struct mxs_apbh_regs *apbh_regs =
243 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000244 int ret;
245
246 ret = mxs_dma_validate_chan(channel);
247 if (ret)
248 return ret;
249
250 if (enable)
251 writel(1 << (channel + APBH_CTRL1_CH_CMDCMPLT_IRQ_EN_OFFSET),
252 &apbh_regs->hw_apbh_ctrl1_set);
253 else
254 writel(1 << (channel + APBH_CTRL1_CH_CMDCMPLT_IRQ_EN_OFFSET),
255 &apbh_regs->hw_apbh_ctrl1_clr);
256
257 return 0;
258}
259
260/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000261 * Clear DMA interrupt.
262 *
263 * The software that is using the DMA channel must register to receive its
264 * interrupts and, when they arrive, must call this function to clear them.
265 */
Marek Vasut4742c262011-11-23 10:59:13 +0000266static int mxs_dma_ack_irq(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000267{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000268 struct mxs_apbh_regs *apbh_regs =
269 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000270 int ret;
271
272 ret = mxs_dma_validate_chan(channel);
273 if (ret)
274 return ret;
275
276 writel(1 << channel, &apbh_regs->hw_apbh_ctrl1_clr);
277 writel(1 << channel, &apbh_regs->hw_apbh_ctrl2_clr);
278
279 return 0;
280}
281
282/*
283 * Request to reserve a DMA channel
284 */
Marek Vasut4742c262011-11-23 10:59:13 +0000285static int mxs_dma_request(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000286{
287 struct mxs_dma_chan *pchan;
288
289 if ((channel < 0) || (channel >= MXS_MAX_DMA_CHANNELS))
290 return -EINVAL;
291
292 pchan = mxs_dma_channels + channel;
293 if ((pchan->flags & MXS_DMA_FLAGS_VALID) != MXS_DMA_FLAGS_VALID)
294 return -ENODEV;
295
296 if (pchan->flags & MXS_DMA_FLAGS_ALLOCATED)
297 return -EBUSY;
298
299 pchan->flags |= MXS_DMA_FLAGS_ALLOCATED;
300 pchan->active_num = 0;
301 pchan->pending_num = 0;
302
303 INIT_LIST_HEAD(&pchan->active);
304 INIT_LIST_HEAD(&pchan->done);
305
306 return 0;
307}
308
309/*
310 * Release a DMA channel.
311 *
312 * This function releases a DMA channel from its current owner.
313 *
314 * The channel will NOT be released if it's marked "busy" (see
315 * mxs_dma_enable()).
316 */
Marek Vasut93541b42012-04-08 17:34:46 +0000317int mxs_dma_release(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000318{
319 struct mxs_dma_chan *pchan;
320 int ret;
321
322 ret = mxs_dma_validate_chan(channel);
323 if (ret)
324 return ret;
325
326 pchan = mxs_dma_channels + channel;
327
328 if (pchan->flags & MXS_DMA_FLAGS_BUSY)
329 return -EBUSY;
330
331 pchan->dev = 0;
332 pchan->active_num = 0;
333 pchan->pending_num = 0;
334 pchan->flags &= ~MXS_DMA_FLAGS_ALLOCATED;
335
336 return 0;
337}
338
339/*
340 * Allocate DMA descriptor
341 */
342struct mxs_dma_desc *mxs_dma_desc_alloc(void)
343{
344 struct mxs_dma_desc *pdesc;
Marek Vasut26427662012-03-15 18:33:18 +0000345 uint32_t size;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000346
Marek Vasut26427662012-03-15 18:33:18 +0000347 size = roundup(sizeof(struct mxs_dma_desc), MXS_DMA_ALIGNMENT);
348 pdesc = memalign(MXS_DMA_ALIGNMENT, size);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000349
350 if (pdesc == NULL)
351 return NULL;
352
353 memset(pdesc, 0, sizeof(*pdesc));
354 pdesc->address = (dma_addr_t)pdesc;
355
356 return pdesc;
357};
358
359/*
360 * Free DMA descriptor
361 */
362void mxs_dma_desc_free(struct mxs_dma_desc *pdesc)
363{
364 if (pdesc == NULL)
365 return;
366
367 free(pdesc);
368}
369
370/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000371 * Add a DMA descriptor to a channel.
372 *
373 * If the descriptor list for this channel is not empty, this function sets the
374 * CHAIN bit and the NEXTCMD_ADDR fields in the last descriptor's DMA command so
375 * it will chain to the new descriptor's command.
376 *
377 * Then, this function marks the new descriptor as "ready," adds it to the end
378 * of the active descriptor list, and increments the count of pending
379 * descriptors.
380 *
381 * The MXS platform DMA software imposes some rules on DMA commands to maintain
382 * important invariants. These rules are NOT checked, but they must be carefully
383 * applied by software that uses MXS DMA channels.
384 *
385 * Invariant:
386 * The DMA channel's hardware semaphore must reflect the number of DMA
387 * commands the hardware will process, but has not yet finished.
388 *
389 * Explanation:
390 * A DMA channel begins processing commands when its hardware semaphore is
391 * written with a value greater than zero, and it stops processing commands
392 * when the semaphore returns to zero.
393 *
394 * When a channel finishes a DMA command, it will decrement its semaphore if
395 * the DECREMENT_SEMAPHORE bit is set in that command's flags bits.
396 *
397 * In principle, it's not necessary for the DECREMENT_SEMAPHORE to be set,
398 * unless it suits the purposes of the software. For example, one could
399 * construct a series of five DMA commands, with the DECREMENT_SEMAPHORE
400 * bit set only in the last one. Then, setting the DMA channel's hardware
401 * semaphore to one would cause the entire series of five commands to be
402 * processed. However, this example would violate the invariant given above.
403 *
404 * Rule:
405 * ALL DMA commands MUST have the DECREMENT_SEMAPHORE bit set so that the DMA
406 * channel's hardware semaphore will be decremented EVERY time a command is
407 * processed.
408 */
409int mxs_dma_desc_append(int channel, struct mxs_dma_desc *pdesc)
410{
411 struct mxs_dma_chan *pchan;
412 struct mxs_dma_desc *last;
413 int ret;
414
415 ret = mxs_dma_validate_chan(channel);
416 if (ret)
417 return ret;
418
419 pchan = mxs_dma_channels + channel;
420
421 pdesc->cmd.next = mxs_dma_cmd_address(pdesc);
422 pdesc->flags |= MXS_DMA_DESC_FIRST | MXS_DMA_DESC_LAST;
423
424 if (!list_empty(&pchan->active)) {
425 last = list_entry(pchan->active.prev, struct mxs_dma_desc,
426 node);
427
428 pdesc->flags &= ~MXS_DMA_DESC_FIRST;
429 last->flags &= ~MXS_DMA_DESC_LAST;
430
431 last->cmd.next = mxs_dma_cmd_address(pdesc);
432 last->cmd.data |= MXS_DMA_DESC_CHAIN;
Marek Vasut26427662012-03-15 18:33:18 +0000433
434 mxs_dma_flush_desc(last);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000435 }
436 pdesc->flags |= MXS_DMA_DESC_READY;
437 if (pdesc->flags & MXS_DMA_DESC_FIRST)
438 pchan->pending_num++;
439 list_add_tail(&pdesc->node, &pchan->active);
440
Marek Vasut26427662012-03-15 18:33:18 +0000441 mxs_dma_flush_desc(pdesc);
442
Marek Vasutf7c752c2011-11-08 23:18:15 +0000443 return ret;
444}
445
446/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000447 * Clean up processed DMA descriptors.
448 *
449 * This function removes processed DMA descriptors from the "active" list. Pass
450 * in a non-NULL list head to get the descriptors moved to your list. Pass NULL
451 * to get the descriptors moved to the channel's "done" list. Descriptors on
452 * the "done" list can be retrieved with mxs_dma_get_finished().
453 *
454 * This function marks the DMA channel as "not busy" if no unprocessed
455 * descriptors remain on the "active" list.
456 */
Marek Vasut4742c262011-11-23 10:59:13 +0000457static int mxs_dma_finish(int channel, struct list_head *head)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000458{
459 int sem;
460 struct mxs_dma_chan *pchan;
461 struct list_head *p, *q;
462 struct mxs_dma_desc *pdesc;
463 int ret;
464
465 ret = mxs_dma_validate_chan(channel);
466 if (ret)
467 return ret;
468
469 pchan = mxs_dma_channels + channel;
470
471 sem = mxs_dma_read_semaphore(channel);
472 if (sem < 0)
473 return sem;
474
475 if (sem == pchan->active_num)
476 return 0;
477
478 list_for_each_safe(p, q, &pchan->active) {
479 if ((pchan->active_num) <= sem)
480 break;
481
482 pdesc = list_entry(p, struct mxs_dma_desc, node);
483 pdesc->flags &= ~MXS_DMA_DESC_READY;
484
485 if (head)
486 list_move_tail(p, head);
487 else
488 list_move_tail(p, &pchan->done);
489
490 if (pdesc->flags & MXS_DMA_DESC_LAST)
491 pchan->active_num--;
492 }
493
494 if (sem == 0)
495 pchan->flags &= ~MXS_DMA_FLAGS_BUSY;
496
497 return 0;
498}
499
500/*
501 * Wait for DMA channel to complete
502 */
Marek Vasut4742c262011-11-23 10:59:13 +0000503static int mxs_dma_wait_complete(uint32_t timeout, unsigned int chan)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000504{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000505 struct mxs_apbh_regs *apbh_regs =
506 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000507 int ret;
508
509 ret = mxs_dma_validate_chan(chan);
510 if (ret)
511 return ret;
512
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000513 if (mxs_wait_mask_set(&apbh_regs->hw_apbh_ctrl1_reg,
Marek Vasutf7c752c2011-11-08 23:18:15 +0000514 1 << chan, timeout)) {
515 ret = -ETIMEDOUT;
516 mxs_dma_reset(chan);
517 }
518
Wolfram Sang98ee9232011-11-18 01:17:44 +0000519 return ret;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000520}
521
522/*
523 * Execute the DMA channel
524 */
525int mxs_dma_go(int chan)
526{
Marek Vasut0f6f68c2012-08-21 16:17:26 +0000527 uint32_t timeout = 10000000;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000528 int ret;
529
530 LIST_HEAD(tmp_desc_list);
531
532 mxs_dma_enable_irq(chan, 1);
533 mxs_dma_enable(chan);
534
535 /* Wait for DMA to finish. */
536 ret = mxs_dma_wait_complete(timeout, chan);
537
538 /* Clear out the descriptors we just ran. */
539 mxs_dma_finish(chan, &tmp_desc_list);
540
541 /* Shut the DMA channel down. */
542 mxs_dma_ack_irq(chan);
543 mxs_dma_reset(chan);
544 mxs_dma_enable_irq(chan, 0);
545 mxs_dma_disable(chan);
546
547 return ret;
548}
549
550/*
Marek Vasut42917802013-07-30 23:37:51 +0200551 * Execute a continuously running circular DMA descriptor.
552 * NOTE: This is not intended for general use, but rather
553 * for the LCD driver in Smart-LCD mode. It allows
554 * continuous triggering of the RUN bit there.
555 */
556void mxs_dma_circ_start(int chan, struct mxs_dma_desc *pdesc)
557{
558 struct mxs_apbh_regs *apbh_regs =
559 (struct mxs_apbh_regs *)MXS_APBH_BASE;
560
561 mxs_dma_flush_desc(pdesc);
562
563 mxs_dma_enable_irq(chan, 1);
564
565 writel(mxs_dma_cmd_address(pdesc),
566 &apbh_regs->ch[chan].hw_apbh_ch_nxtcmdar);
567 writel(1, &apbh_regs->ch[chan].hw_apbh_ch_sema);
568 writel(1 << (chan + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
569 &apbh_regs->hw_apbh_ctrl0_clr);
570}
571
572/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000573 * Initialize the DMA hardware
574 */
Marek Vasut93541b42012-04-08 17:34:46 +0000575void mxs_dma_init(void)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000576{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000577 struct mxs_apbh_regs *apbh_regs =
578 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000579
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000580 mxs_reset_block(&apbh_regs->hw_apbh_ctrl0_reg);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000581
582#ifdef CONFIG_APBH_DMA_BURST8
583 writel(APBH_CTRL0_AHB_BURST8_EN,
584 &apbh_regs->hw_apbh_ctrl0_set);
585#else
586 writel(APBH_CTRL0_AHB_BURST8_EN,
587 &apbh_regs->hw_apbh_ctrl0_clr);
588#endif
589
590#ifdef CONFIG_APBH_DMA_BURST
591 writel(APBH_CTRL0_APB_BURST_EN,
592 &apbh_regs->hw_apbh_ctrl0_set);
593#else
594 writel(APBH_CTRL0_APB_BURST_EN,
595 &apbh_regs->hw_apbh_ctrl0_clr);
596#endif
Marek Vasut93541b42012-04-08 17:34:46 +0000597}
Marek Vasutf7c752c2011-11-08 23:18:15 +0000598
Marek Vasut93541b42012-04-08 17:34:46 +0000599int mxs_dma_init_channel(int channel)
600{
601 struct mxs_dma_chan *pchan;
602 int ret;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000603
Marek Vasut93541b42012-04-08 17:34:46 +0000604 pchan = mxs_dma_channels + channel;
605 pchan->flags = MXS_DMA_FLAGS_VALID;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000606
Marek Vasut93541b42012-04-08 17:34:46 +0000607 ret = mxs_dma_request(channel);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000608
Marek Vasut93541b42012-04-08 17:34:46 +0000609 if (ret) {
610 printf("MXS DMA: Can't acquire DMA channel %i\n",
611 channel);
612 return ret;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000613 }
614
Marek Vasut93541b42012-04-08 17:34:46 +0000615 mxs_dma_reset(channel);
616 mxs_dma_ack_irq(channel);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000617
Marek Vasut93541b42012-04-08 17:34:46 +0000618 return 0;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000619}