blob: da988f6bb6676e8a3fa04db08f2eea92a93c2cf3 [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>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Marek Vasutf7c752c2011-11-08 23:18:15 +000016#include <linux/list.h>
17
18#include <common.h>
19#include <malloc.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090020#include <linux/errno.h>
Marek Vasutf7c752c2011-11-08 23:18:15 +000021#include <asm/io.h>
22#include <asm/arch/clock.h>
23#include <asm/arch/imx-regs.h>
24#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020025#include <asm/mach-imx/dma.h>
26#include <asm/mach-imx/regs-apbh.h>
Marek Vasutf7c752c2011-11-08 23:18:15 +000027
28static struct mxs_dma_chan mxs_dma_channels[MXS_MAX_DMA_CHANNELS];
29
30/*
31 * Test is the DMA channel is valid channel
32 */
33int mxs_dma_validate_chan(int channel)
34{
35 struct mxs_dma_chan *pchan;
36
37 if ((channel < 0) || (channel >= MXS_MAX_DMA_CHANNELS))
38 return -EINVAL;
39
40 pchan = mxs_dma_channels + channel;
41 if (!(pchan->flags & MXS_DMA_FLAGS_ALLOCATED))
42 return -EINVAL;
43
44 return 0;
45}
46
47/*
Marek Vasut4742c262011-11-23 10:59:13 +000048 * Return the address of the command within a descriptor.
49 */
50static unsigned int mxs_dma_cmd_address(struct mxs_dma_desc *desc)
51{
52 return desc->address + offsetof(struct mxs_dma_desc, cmd);
53}
54
55/*
56 * Read a DMA channel's hardware semaphore.
57 *
58 * As used by the MXS platform's DMA software, the DMA channel's hardware
59 * semaphore reflects the number of DMA commands the hardware will process, but
60 * has not yet finished. This is a volatile value read directly from hardware,
61 * so it must be be viewed as immediately stale.
62 *
63 * If the channel is not marked busy, or has finished processing all its
64 * commands, this value should be zero.
65 *
66 * See mxs_dma_append() for details on how DMA command blocks must be configured
67 * to maintain the expected behavior of the semaphore's value.
68 */
69static int mxs_dma_read_semaphore(int channel)
70{
Otavio Salvador22f4ff92012-08-05 09:05:31 +000071 struct mxs_apbh_regs *apbh_regs =
72 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasut4742c262011-11-23 10:59:13 +000073 uint32_t tmp;
74 int ret;
75
76 ret = mxs_dma_validate_chan(channel);
77 if (ret)
78 return ret;
79
80 tmp = readl(&apbh_regs->ch[channel].hw_apbh_ch_sema);
81
82 tmp &= APBH_CHn_SEMA_PHORE_MASK;
83 tmp >>= APBH_CHn_SEMA_PHORE_OFFSET;
84
85 return tmp;
86}
87
Trevor Woerner43ec7e02019-05-03 09:41:00 -040088#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Marek Vasut26427662012-03-15 18:33:18 +000089void mxs_dma_flush_desc(struct mxs_dma_desc *desc)
90{
91 uint32_t addr;
92 uint32_t size;
93
Peng Fan128abf42020-05-04 22:09:00 +080094 addr = (uintptr_t)desc;
Marek Vasut26427662012-03-15 18:33:18 +000095 size = roundup(sizeof(struct mxs_dma_desc), MXS_DMA_ALIGNMENT);
96
97 flush_dcache_range(addr, addr + size);
98}
99#else
100inline void mxs_dma_flush_desc(struct mxs_dma_desc *desc) {}
101#endif
102
Marek Vasut4742c262011-11-23 10:59:13 +0000103/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000104 * Enable a DMA channel.
105 *
106 * If the given channel has any DMA descriptors on its active list, this
107 * function causes the DMA hardware to begin processing them.
108 *
109 * This function marks the DMA channel as "busy," whether or not there are any
110 * descriptors to process.
111 */
Marek Vasut4742c262011-11-23 10:59:13 +0000112static int mxs_dma_enable(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000113{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000114 struct mxs_apbh_regs *apbh_regs =
115 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000116 unsigned int sem;
117 struct mxs_dma_chan *pchan;
118 struct mxs_dma_desc *pdesc;
119 int ret;
120
121 ret = mxs_dma_validate_chan(channel);
122 if (ret)
123 return ret;
124
125 pchan = mxs_dma_channels + channel;
126
127 if (pchan->pending_num == 0) {
128 pchan->flags |= MXS_DMA_FLAGS_BUSY;
129 return 0;
130 }
131
132 pdesc = list_first_entry(&pchan->active, struct mxs_dma_desc, node);
133 if (pdesc == NULL)
134 return -EFAULT;
135
136 if (pchan->flags & MXS_DMA_FLAGS_BUSY) {
137 if (!(pdesc->cmd.data & MXS_DMA_DESC_CHAIN))
138 return 0;
139
140 sem = mxs_dma_read_semaphore(channel);
141 if (sem == 0)
142 return 0;
143
144 if (sem == 1) {
145 pdesc = list_entry(pdesc->node.next,
146 struct mxs_dma_desc, node);
147 writel(mxs_dma_cmd_address(pdesc),
148 &apbh_regs->ch[channel].hw_apbh_ch_nxtcmdar);
149 }
150 writel(pchan->pending_num,
151 &apbh_regs->ch[channel].hw_apbh_ch_sema);
152 pchan->active_num += pchan->pending_num;
153 pchan->pending_num = 0;
154 } else {
155 pchan->active_num += pchan->pending_num;
156 pchan->pending_num = 0;
157 writel(mxs_dma_cmd_address(pdesc),
158 &apbh_regs->ch[channel].hw_apbh_ch_nxtcmdar);
159 writel(pchan->active_num,
160 &apbh_regs->ch[channel].hw_apbh_ch_sema);
161 writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
162 &apbh_regs->hw_apbh_ctrl0_clr);
163 }
164
165 pchan->flags |= MXS_DMA_FLAGS_BUSY;
166 return 0;
167}
168
169/*
170 * Disable a DMA channel.
171 *
172 * This function shuts down a DMA channel and marks it as "not busy." Any
173 * descriptors on the active list are immediately moved to the head of the
174 * "done" list, whether or not they have actually been processed by the
175 * hardware. The "ready" flags of these descriptors are NOT cleared, so they
176 * still appear to be active.
177 *
178 * This function immediately shuts down a DMA channel's hardware, aborting any
179 * I/O that may be in progress, potentially leaving I/O hardware in an undefined
180 * state. It is unwise to call this function if there is ANY chance the hardware
181 * is still processing a command.
182 */
Marek Vasut4742c262011-11-23 10:59:13 +0000183static int mxs_dma_disable(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000184{
185 struct mxs_dma_chan *pchan;
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000186 struct mxs_apbh_regs *apbh_regs =
187 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000188 int ret;
189
190 ret = mxs_dma_validate_chan(channel);
191 if (ret)
192 return ret;
193
194 pchan = mxs_dma_channels + channel;
195
196 if (!(pchan->flags & MXS_DMA_FLAGS_BUSY))
197 return -EINVAL;
198
199 writel(1 << (channel + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
200 &apbh_regs->hw_apbh_ctrl0_set);
201
202 pchan->flags &= ~MXS_DMA_FLAGS_BUSY;
203 pchan->active_num = 0;
204 pchan->pending_num = 0;
205 list_splice_init(&pchan->active, &pchan->done);
206
207 return 0;
208}
209
210/*
211 * Resets the DMA channel hardware.
212 */
Marek Vasut4742c262011-11-23 10:59:13 +0000213static int mxs_dma_reset(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000214{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000215 struct mxs_apbh_regs *apbh_regs =
216 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000217 int ret;
Marek Vasut154af3a2013-01-22 15:01:00 +0000218#if defined(CONFIG_MX23)
219 uint32_t setreg = (uint32_t)(&apbh_regs->hw_apbh_ctrl0_set);
220 uint32_t offset = APBH_CTRL0_RESET_CHANNEL_OFFSET;
Peng Fan128abf42020-05-04 22:09:00 +0800221#elif defined(CONFIG_MX28) || defined(CONFIG_MX6) || defined(CONFIG_MX7) || \
222 defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
223 u32 setreg = (uintptr_t)(&apbh_regs->hw_apbh_channel_ctrl_set);
224 u32 offset = APBH_CHANNEL_CTRL_RESET_CHANNEL_OFFSET;
Marek Vasut154af3a2013-01-22 15:01:00 +0000225#endif
Marek Vasutf7c752c2011-11-08 23:18:15 +0000226
227 ret = mxs_dma_validate_chan(channel);
228 if (ret)
229 return ret;
230
Peng Fan128abf42020-05-04 22:09:00 +0800231 writel(1 << (channel + offset), (uintptr_t)setreg);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000232
233 return 0;
234}
235
236/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000237 * Enable or disable DMA interrupt.
238 *
239 * This function enables the given DMA channel to interrupt the CPU.
240 */
Marek Vasut4742c262011-11-23 10:59:13 +0000241static int mxs_dma_enable_irq(int channel, int enable)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000242{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000243 struct mxs_apbh_regs *apbh_regs =
244 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000245 int ret;
246
247 ret = mxs_dma_validate_chan(channel);
248 if (ret)
249 return ret;
250
251 if (enable)
252 writel(1 << (channel + APBH_CTRL1_CH_CMDCMPLT_IRQ_EN_OFFSET),
253 &apbh_regs->hw_apbh_ctrl1_set);
254 else
255 writel(1 << (channel + APBH_CTRL1_CH_CMDCMPLT_IRQ_EN_OFFSET),
256 &apbh_regs->hw_apbh_ctrl1_clr);
257
258 return 0;
259}
260
261/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000262 * Clear DMA interrupt.
263 *
264 * The software that is using the DMA channel must register to receive its
265 * interrupts and, when they arrive, must call this function to clear them.
266 */
Marek Vasut4742c262011-11-23 10:59:13 +0000267static int mxs_dma_ack_irq(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000268{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000269 struct mxs_apbh_regs *apbh_regs =
270 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000271 int ret;
272
273 ret = mxs_dma_validate_chan(channel);
274 if (ret)
275 return ret;
276
277 writel(1 << channel, &apbh_regs->hw_apbh_ctrl1_clr);
278 writel(1 << channel, &apbh_regs->hw_apbh_ctrl2_clr);
279
280 return 0;
281}
282
283/*
284 * Request to reserve a DMA channel
285 */
Marek Vasut4742c262011-11-23 10:59:13 +0000286static int mxs_dma_request(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000287{
288 struct mxs_dma_chan *pchan;
289
290 if ((channel < 0) || (channel >= MXS_MAX_DMA_CHANNELS))
291 return -EINVAL;
292
293 pchan = mxs_dma_channels + channel;
294 if ((pchan->flags & MXS_DMA_FLAGS_VALID) != MXS_DMA_FLAGS_VALID)
295 return -ENODEV;
296
297 if (pchan->flags & MXS_DMA_FLAGS_ALLOCATED)
298 return -EBUSY;
299
300 pchan->flags |= MXS_DMA_FLAGS_ALLOCATED;
301 pchan->active_num = 0;
302 pchan->pending_num = 0;
303
304 INIT_LIST_HEAD(&pchan->active);
305 INIT_LIST_HEAD(&pchan->done);
306
307 return 0;
308}
309
310/*
311 * Release a DMA channel.
312 *
313 * This function releases a DMA channel from its current owner.
314 *
315 * The channel will NOT be released if it's marked "busy" (see
316 * mxs_dma_enable()).
317 */
Marek Vasut93541b42012-04-08 17:34:46 +0000318int mxs_dma_release(int channel)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000319{
320 struct mxs_dma_chan *pchan;
321 int ret;
322
323 ret = mxs_dma_validate_chan(channel);
324 if (ret)
325 return ret;
326
327 pchan = mxs_dma_channels + channel;
328
329 if (pchan->flags & MXS_DMA_FLAGS_BUSY)
330 return -EBUSY;
331
332 pchan->dev = 0;
333 pchan->active_num = 0;
334 pchan->pending_num = 0;
335 pchan->flags &= ~MXS_DMA_FLAGS_ALLOCATED;
336
337 return 0;
338}
339
340/*
341 * Allocate DMA descriptor
342 */
343struct mxs_dma_desc *mxs_dma_desc_alloc(void)
344{
345 struct mxs_dma_desc *pdesc;
Marek Vasut26427662012-03-15 18:33:18 +0000346 uint32_t size;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000347
Marek Vasut26427662012-03-15 18:33:18 +0000348 size = roundup(sizeof(struct mxs_dma_desc), MXS_DMA_ALIGNMENT);
349 pdesc = memalign(MXS_DMA_ALIGNMENT, size);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000350
351 if (pdesc == NULL)
352 return NULL;
353
354 memset(pdesc, 0, sizeof(*pdesc));
355 pdesc->address = (dma_addr_t)pdesc;
356
357 return pdesc;
358};
359
360/*
361 * Free DMA descriptor
362 */
363void mxs_dma_desc_free(struct mxs_dma_desc *pdesc)
364{
365 if (pdesc == NULL)
366 return;
367
368 free(pdesc);
369}
370
371/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000372 * Add a DMA descriptor to a channel.
373 *
374 * If the descriptor list for this channel is not empty, this function sets the
375 * CHAIN bit and the NEXTCMD_ADDR fields in the last descriptor's DMA command so
376 * it will chain to the new descriptor's command.
377 *
378 * Then, this function marks the new descriptor as "ready," adds it to the end
379 * of the active descriptor list, and increments the count of pending
380 * descriptors.
381 *
382 * The MXS platform DMA software imposes some rules on DMA commands to maintain
383 * important invariants. These rules are NOT checked, but they must be carefully
384 * applied by software that uses MXS DMA channels.
385 *
386 * Invariant:
387 * The DMA channel's hardware semaphore must reflect the number of DMA
388 * commands the hardware will process, but has not yet finished.
389 *
390 * Explanation:
391 * A DMA channel begins processing commands when its hardware semaphore is
392 * written with a value greater than zero, and it stops processing commands
393 * when the semaphore returns to zero.
394 *
395 * When a channel finishes a DMA command, it will decrement its semaphore if
396 * the DECREMENT_SEMAPHORE bit is set in that command's flags bits.
397 *
398 * In principle, it's not necessary for the DECREMENT_SEMAPHORE to be set,
399 * unless it suits the purposes of the software. For example, one could
400 * construct a series of five DMA commands, with the DECREMENT_SEMAPHORE
401 * bit set only in the last one. Then, setting the DMA channel's hardware
402 * semaphore to one would cause the entire series of five commands to be
403 * processed. However, this example would violate the invariant given above.
404 *
405 * Rule:
406 * ALL DMA commands MUST have the DECREMENT_SEMAPHORE bit set so that the DMA
407 * channel's hardware semaphore will be decremented EVERY time a command is
408 * processed.
409 */
410int mxs_dma_desc_append(int channel, struct mxs_dma_desc *pdesc)
411{
412 struct mxs_dma_chan *pchan;
413 struct mxs_dma_desc *last;
414 int ret;
415
416 ret = mxs_dma_validate_chan(channel);
417 if (ret)
418 return ret;
419
420 pchan = mxs_dma_channels + channel;
421
422 pdesc->cmd.next = mxs_dma_cmd_address(pdesc);
423 pdesc->flags |= MXS_DMA_DESC_FIRST | MXS_DMA_DESC_LAST;
424
425 if (!list_empty(&pchan->active)) {
426 last = list_entry(pchan->active.prev, struct mxs_dma_desc,
427 node);
428
429 pdesc->flags &= ~MXS_DMA_DESC_FIRST;
430 last->flags &= ~MXS_DMA_DESC_LAST;
431
432 last->cmd.next = mxs_dma_cmd_address(pdesc);
433 last->cmd.data |= MXS_DMA_DESC_CHAIN;
Marek Vasut26427662012-03-15 18:33:18 +0000434
435 mxs_dma_flush_desc(last);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000436 }
437 pdesc->flags |= MXS_DMA_DESC_READY;
438 if (pdesc->flags & MXS_DMA_DESC_FIRST)
439 pchan->pending_num++;
440 list_add_tail(&pdesc->node, &pchan->active);
441
Marek Vasut26427662012-03-15 18:33:18 +0000442 mxs_dma_flush_desc(pdesc);
443
Marek Vasutf7c752c2011-11-08 23:18:15 +0000444 return ret;
445}
446
447/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000448 * Clean up processed DMA descriptors.
449 *
450 * This function removes processed DMA descriptors from the "active" list. Pass
451 * in a non-NULL list head to get the descriptors moved to your list. Pass NULL
452 * to get the descriptors moved to the channel's "done" list. Descriptors on
453 * the "done" list can be retrieved with mxs_dma_get_finished().
454 *
455 * This function marks the DMA channel as "not busy" if no unprocessed
456 * descriptors remain on the "active" list.
457 */
Marek Vasut4742c262011-11-23 10:59:13 +0000458static int mxs_dma_finish(int channel, struct list_head *head)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000459{
460 int sem;
461 struct mxs_dma_chan *pchan;
462 struct list_head *p, *q;
463 struct mxs_dma_desc *pdesc;
464 int ret;
465
466 ret = mxs_dma_validate_chan(channel);
467 if (ret)
468 return ret;
469
470 pchan = mxs_dma_channels + channel;
471
472 sem = mxs_dma_read_semaphore(channel);
473 if (sem < 0)
474 return sem;
475
476 if (sem == pchan->active_num)
477 return 0;
478
479 list_for_each_safe(p, q, &pchan->active) {
480 if ((pchan->active_num) <= sem)
481 break;
482
483 pdesc = list_entry(p, struct mxs_dma_desc, node);
484 pdesc->flags &= ~MXS_DMA_DESC_READY;
485
486 if (head)
487 list_move_tail(p, head);
488 else
489 list_move_tail(p, &pchan->done);
490
491 if (pdesc->flags & MXS_DMA_DESC_LAST)
492 pchan->active_num--;
493 }
494
495 if (sem == 0)
496 pchan->flags &= ~MXS_DMA_FLAGS_BUSY;
497
498 return 0;
499}
500
501/*
502 * Wait for DMA channel to complete
503 */
Marek Vasut4742c262011-11-23 10:59:13 +0000504static int mxs_dma_wait_complete(uint32_t timeout, unsigned int chan)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000505{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000506 struct mxs_apbh_regs *apbh_regs =
507 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000508 int ret;
509
510 ret = mxs_dma_validate_chan(chan);
511 if (ret)
512 return ret;
513
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000514 if (mxs_wait_mask_set(&apbh_regs->hw_apbh_ctrl1_reg,
Marek Vasutf7c752c2011-11-08 23:18:15 +0000515 1 << chan, timeout)) {
516 ret = -ETIMEDOUT;
517 mxs_dma_reset(chan);
518 }
519
Wolfram Sang98ee9232011-11-18 01:17:44 +0000520 return ret;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000521}
522
523/*
524 * Execute the DMA channel
525 */
526int mxs_dma_go(int chan)
527{
Marek Vasut0f6f68c2012-08-21 16:17:26 +0000528 uint32_t timeout = 10000000;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000529 int ret;
530
531 LIST_HEAD(tmp_desc_list);
532
533 mxs_dma_enable_irq(chan, 1);
534 mxs_dma_enable(chan);
535
536 /* Wait for DMA to finish. */
537 ret = mxs_dma_wait_complete(timeout, chan);
538
539 /* Clear out the descriptors we just ran. */
540 mxs_dma_finish(chan, &tmp_desc_list);
541
542 /* Shut the DMA channel down. */
543 mxs_dma_ack_irq(chan);
544 mxs_dma_reset(chan);
545 mxs_dma_enable_irq(chan, 0);
546 mxs_dma_disable(chan);
547
548 return ret;
549}
550
551/*
Marek Vasut42917802013-07-30 23:37:51 +0200552 * Execute a continuously running circular DMA descriptor.
553 * NOTE: This is not intended for general use, but rather
554 * for the LCD driver in Smart-LCD mode. It allows
555 * continuous triggering of the RUN bit there.
556 */
557void mxs_dma_circ_start(int chan, struct mxs_dma_desc *pdesc)
558{
559 struct mxs_apbh_regs *apbh_regs =
560 (struct mxs_apbh_regs *)MXS_APBH_BASE;
561
562 mxs_dma_flush_desc(pdesc);
563
564 mxs_dma_enable_irq(chan, 1);
565
566 writel(mxs_dma_cmd_address(pdesc),
567 &apbh_regs->ch[chan].hw_apbh_ch_nxtcmdar);
568 writel(1, &apbh_regs->ch[chan].hw_apbh_ch_sema);
569 writel(1 << (chan + APBH_CTRL0_CLKGATE_CHANNEL_OFFSET),
570 &apbh_regs->hw_apbh_ctrl0_clr);
571}
572
573/*
Marek Vasutf7c752c2011-11-08 23:18:15 +0000574 * Initialize the DMA hardware
575 */
Marek Vasut93541b42012-04-08 17:34:46 +0000576void mxs_dma_init(void)
Marek Vasutf7c752c2011-11-08 23:18:15 +0000577{
Otavio Salvador22f4ff92012-08-05 09:05:31 +0000578 struct mxs_apbh_regs *apbh_regs =
579 (struct mxs_apbh_regs *)MXS_APBH_BASE;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000580
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +0000581 mxs_reset_block(&apbh_regs->hw_apbh_ctrl0_reg);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000582
583#ifdef CONFIG_APBH_DMA_BURST8
584 writel(APBH_CTRL0_AHB_BURST8_EN,
585 &apbh_regs->hw_apbh_ctrl0_set);
586#else
587 writel(APBH_CTRL0_AHB_BURST8_EN,
588 &apbh_regs->hw_apbh_ctrl0_clr);
589#endif
590
591#ifdef CONFIG_APBH_DMA_BURST
592 writel(APBH_CTRL0_APB_BURST_EN,
593 &apbh_regs->hw_apbh_ctrl0_set);
594#else
595 writel(APBH_CTRL0_APB_BURST_EN,
596 &apbh_regs->hw_apbh_ctrl0_clr);
597#endif
Marek Vasut93541b42012-04-08 17:34:46 +0000598}
Marek Vasutf7c752c2011-11-08 23:18:15 +0000599
Marek Vasut93541b42012-04-08 17:34:46 +0000600int mxs_dma_init_channel(int channel)
601{
602 struct mxs_dma_chan *pchan;
603 int ret;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000604
Marek Vasut93541b42012-04-08 17:34:46 +0000605 pchan = mxs_dma_channels + channel;
606 pchan->flags = MXS_DMA_FLAGS_VALID;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000607
Marek Vasut93541b42012-04-08 17:34:46 +0000608 ret = mxs_dma_request(channel);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000609
Marek Vasut93541b42012-04-08 17:34:46 +0000610 if (ret) {
611 printf("MXS DMA: Can't acquire DMA channel %i\n",
612 channel);
613 return ret;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000614 }
615
Marek Vasut93541b42012-04-08 17:34:46 +0000616 mxs_dma_reset(channel);
617 mxs_dma_ack_irq(channel);
Marek Vasutf7c752c2011-11-08 23:18:15 +0000618
Marek Vasut93541b42012-04-08 17:34:46 +0000619 return 0;
Marek Vasutf7c752c2011-11-08 23:18:15 +0000620}