2 * File: arch/blackfin/kernel/bfin_dma_5xx.c
7 * Description: This file contains the simple DMA Implementation for Blackfin
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/errno.h>
31 #include <linux/module.h>
32 #include <linux/sched.h>
33 #include <linux/interrupt.h>
34 #include <linux/kernel.h>
35 #include <linux/param.h>
37 #include <asm/blackfin.h>
39 #include <asm/cacheflush.h>
41 /* Remove unused code not exported by symbol or internally called */
42 #define REMOVE_DEAD_CODE
44 /**************************************************************************
46 ***************************************************************************/
48 static struct dma_channel dma_ch[MAX_BLACKFIN_DMA_CHANNEL];
50 /*------------------------------------------------------------------------------
51 * Set the Buffer Clear bit in the Configuration register of specific DMA
52 * channel. This will stop the descriptor based DMA operation.
53 *-----------------------------------------------------------------------------*/
54 static void clear_dma_buffer(unsigned int channel)
56 dma_ch[channel].regs->cfg |= RESTART;
58 dma_ch[channel].regs->cfg &= ~RESTART;
62 static int __init blackfin_dma_init(void)
66 printk(KERN_INFO "Blackfin DMA Controller\n");
68 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
69 dma_ch[i].chan_status = DMA_CHANNEL_FREE;
70 dma_ch[i].regs = dma_io_base_addr[i];
71 mutex_init(&(dma_ch[i].dmalock));
73 /* Mark MEMDMA Channel 0 as requested since we're using it internally */
74 dma_ch[CH_MEM_STREAM0_DEST].chan_status = DMA_CHANNEL_REQUESTED;
75 dma_ch[CH_MEM_STREAM0_SRC].chan_status = DMA_CHANNEL_REQUESTED;
77 #if defined(CONFIG_DEB_DMA_URGENT)
78 bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
79 | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
84 arch_initcall(blackfin_dma_init);
86 /*------------------------------------------------------------------------------
87 * Request the specific DMA channel from the system.
88 *-----------------------------------------------------------------------------*/
89 int request_dma(unsigned int channel, char *device_id)
92 pr_debug("request_dma() : BEGIN \n");
93 mutex_lock(&(dma_ch[channel].dmalock));
95 if ((dma_ch[channel].chan_status == DMA_CHANNEL_REQUESTED)
96 || (dma_ch[channel].chan_status == DMA_CHANNEL_ENABLED)) {
97 mutex_unlock(&(dma_ch[channel].dmalock));
98 pr_debug("DMA CHANNEL IN USE \n");
101 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
102 pr_debug("DMA CHANNEL IS ALLOCATED \n");
105 mutex_unlock(&(dma_ch[channel].dmalock));
108 if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
109 if (strncmp(device_id, "BFIN_UART", 9) == 0) {
110 dma_ch[channel].regs->peripheral_map &= 0x0FFF;
111 dma_ch[channel].regs->peripheral_map |=
112 ((channel - CH_UART2_RX + 0xC)<<12);
114 dma_ch[channel].regs->peripheral_map &= 0x0FFF;
115 dma_ch[channel].regs->peripheral_map |=
116 ((channel - CH_UART2_RX + 0x6)<<12);
121 dma_ch[channel].device_id = device_id;
122 dma_ch[channel].irq_callback = NULL;
124 /* This is to be enabled by putting a restriction -
125 * you have to request DMA, before doing any operations on
128 pr_debug("request_dma() : END \n");
131 EXPORT_SYMBOL(request_dma);
133 int set_dma_callback(unsigned int channel, dma_interrupt_t callback, void *data)
137 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
138 && channel < MAX_BLACKFIN_DMA_CHANNEL));
140 if (callback != NULL) {
142 ret_irq = channel2irq(channel);
144 dma_ch[channel].data = data;
147 request_irq(ret_irq, (void *)callback, IRQF_DISABLED,
148 dma_ch[channel].device_id, data);
151 "Request irq in DMA engine failed.\n");
154 dma_ch[channel].irq_callback = callback;
158 EXPORT_SYMBOL(set_dma_callback);
160 void free_dma(unsigned int channel)
164 pr_debug("freedma() : BEGIN \n");
165 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
166 && channel < MAX_BLACKFIN_DMA_CHANNEL));
169 disable_dma(channel);
170 clear_dma_buffer(channel);
172 if (dma_ch[channel].irq_callback != NULL) {
173 ret_irq = channel2irq(channel);
174 free_irq(ret_irq, dma_ch[channel].data);
177 /* Clear the DMA Variable in the Channel */
178 mutex_lock(&(dma_ch[channel].dmalock));
179 dma_ch[channel].chan_status = DMA_CHANNEL_FREE;
180 mutex_unlock(&(dma_ch[channel].dmalock));
182 pr_debug("freedma() : END \n");
184 EXPORT_SYMBOL(free_dma);
186 void dma_enable_irq(unsigned int channel)
190 pr_debug("dma_enable_irq() : BEGIN \n");
191 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
192 && channel < MAX_BLACKFIN_DMA_CHANNEL));
194 ret_irq = channel2irq(channel);
197 EXPORT_SYMBOL(dma_enable_irq);
199 void dma_disable_irq(unsigned int channel)
203 pr_debug("dma_disable_irq() : BEGIN \n");
204 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
205 && channel < MAX_BLACKFIN_DMA_CHANNEL));
207 ret_irq = channel2irq(channel);
208 disable_irq(ret_irq);
210 EXPORT_SYMBOL(dma_disable_irq);
212 int dma_channel_active(unsigned int channel)
214 if (dma_ch[channel].chan_status == DMA_CHANNEL_FREE) {
220 EXPORT_SYMBOL(dma_channel_active);
222 /*------------------------------------------------------------------------------
223 * stop the specific DMA channel.
224 *-----------------------------------------------------------------------------*/
225 void disable_dma(unsigned int channel)
227 pr_debug("stop_dma() : BEGIN \n");
229 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
230 && channel < MAX_BLACKFIN_DMA_CHANNEL));
232 dma_ch[channel].regs->cfg &= ~DMAEN; /* Clean the enable bit */
234 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
235 /* Needs to be enabled Later */
236 pr_debug("stop_dma() : END \n");
239 EXPORT_SYMBOL(disable_dma);
241 void enable_dma(unsigned int channel)
243 pr_debug("enable_dma() : BEGIN \n");
245 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
246 && channel < MAX_BLACKFIN_DMA_CHANNEL));
248 dma_ch[channel].chan_status = DMA_CHANNEL_ENABLED;
249 dma_ch[channel].regs->curr_x_count = 0;
250 dma_ch[channel].regs->curr_y_count = 0;
252 dma_ch[channel].regs->cfg |= DMAEN; /* Set the enable bit */
254 pr_debug("enable_dma() : END \n");
257 EXPORT_SYMBOL(enable_dma);
259 /*------------------------------------------------------------------------------
260 * Set the Start Address register for the specific DMA channel
261 * This function can be used for register based DMA,
262 * to setup the start address
263 * addr: Starting address of the DMA Data to be transferred.
264 *-----------------------------------------------------------------------------*/
265 void set_dma_start_addr(unsigned int channel, unsigned long addr)
267 pr_debug("set_dma_start_addr() : BEGIN \n");
269 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
270 && channel < MAX_BLACKFIN_DMA_CHANNEL));
272 dma_ch[channel].regs->start_addr = addr;
274 pr_debug("set_dma_start_addr() : END\n");
276 EXPORT_SYMBOL(set_dma_start_addr);
278 void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
280 pr_debug("set_dma_next_desc_addr() : BEGIN \n");
282 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
283 && channel < MAX_BLACKFIN_DMA_CHANNEL));
285 dma_ch[channel].regs->next_desc_ptr = addr;
287 pr_debug("set_dma_next_desc_addr() : END\n");
289 EXPORT_SYMBOL(set_dma_next_desc_addr);
291 void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
293 pr_debug("set_dma_curr_desc_addr() : BEGIN \n");
295 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
296 && channel < MAX_BLACKFIN_DMA_CHANNEL));
298 dma_ch[channel].regs->curr_desc_ptr = addr;
300 pr_debug("set_dma_curr_desc_addr() : END\n");
302 EXPORT_SYMBOL(set_dma_curr_desc_addr);
304 void set_dma_x_count(unsigned int channel, unsigned short x_count)
306 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
307 && channel < MAX_BLACKFIN_DMA_CHANNEL));
309 dma_ch[channel].regs->x_count = x_count;
312 EXPORT_SYMBOL(set_dma_x_count);
314 void set_dma_y_count(unsigned int channel, unsigned short y_count)
316 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
317 && channel < MAX_BLACKFIN_DMA_CHANNEL));
319 dma_ch[channel].regs->y_count = y_count;
322 EXPORT_SYMBOL(set_dma_y_count);
324 void set_dma_x_modify(unsigned int channel, short x_modify)
326 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
327 && channel < MAX_BLACKFIN_DMA_CHANNEL));
329 dma_ch[channel].regs->x_modify = x_modify;
332 EXPORT_SYMBOL(set_dma_x_modify);
334 void set_dma_y_modify(unsigned int channel, short y_modify)
336 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
337 && channel < MAX_BLACKFIN_DMA_CHANNEL));
339 dma_ch[channel].regs->y_modify = y_modify;
342 EXPORT_SYMBOL(set_dma_y_modify);
344 void set_dma_config(unsigned int channel, unsigned short config)
346 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
347 && channel < MAX_BLACKFIN_DMA_CHANNEL));
349 dma_ch[channel].regs->cfg = config;
352 EXPORT_SYMBOL(set_dma_config);
355 set_bfin_dma_config(char direction, char flow_mode,
356 char intr_mode, char dma_mode, char width, char syncmode)
358 unsigned short config;
361 ((direction << 1) | (width << 2) | (dma_mode << 4) |
362 (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5));
365 EXPORT_SYMBOL(set_bfin_dma_config);
367 void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg)
369 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
370 && channel < MAX_BLACKFIN_DMA_CHANNEL));
372 dma_ch[channel].regs->cfg |= ((nr_sg & 0x0F) << 8);
374 dma_ch[channel].regs->next_desc_ptr = (unsigned int)sg;
378 EXPORT_SYMBOL(set_dma_sg);
380 void set_dma_curr_addr(unsigned int channel, unsigned long addr)
382 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
383 && channel < MAX_BLACKFIN_DMA_CHANNEL));
385 dma_ch[channel].regs->curr_addr_ptr = addr;
388 EXPORT_SYMBOL(set_dma_curr_addr);
390 /*------------------------------------------------------------------------------
391 * Get the DMA status of a specific DMA channel from the system.
392 *-----------------------------------------------------------------------------*/
393 unsigned short get_dma_curr_irqstat(unsigned int channel)
395 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
396 && channel < MAX_BLACKFIN_DMA_CHANNEL));
398 return dma_ch[channel].regs->irq_status;
400 EXPORT_SYMBOL(get_dma_curr_irqstat);
402 /*------------------------------------------------------------------------------
403 * Clear the DMA_DONE bit in DMA status. Stop the DMA completion interrupt.
404 *-----------------------------------------------------------------------------*/
405 void clear_dma_irqstat(unsigned int channel)
407 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
408 && channel < MAX_BLACKFIN_DMA_CHANNEL));
409 dma_ch[channel].regs->irq_status |= 3;
411 EXPORT_SYMBOL(clear_dma_irqstat);
413 /*------------------------------------------------------------------------------
414 * Get current DMA xcount of a specific DMA channel from the system.
415 *-----------------------------------------------------------------------------*/
416 unsigned short get_dma_curr_xcount(unsigned int channel)
418 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
419 && channel < MAX_BLACKFIN_DMA_CHANNEL));
421 return dma_ch[channel].regs->curr_x_count;
423 EXPORT_SYMBOL(get_dma_curr_xcount);
425 /*------------------------------------------------------------------------------
426 * Get current DMA ycount of a specific DMA channel from the system.
427 *-----------------------------------------------------------------------------*/
428 unsigned short get_dma_curr_ycount(unsigned int channel)
430 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
431 && channel < MAX_BLACKFIN_DMA_CHANNEL));
433 return dma_ch[channel].regs->curr_y_count;
435 EXPORT_SYMBOL(get_dma_curr_ycount);
437 unsigned long get_dma_next_desc_ptr(unsigned int channel)
439 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
440 && channel < MAX_BLACKFIN_DMA_CHANNEL));
442 return dma_ch[channel].regs->next_desc_ptr;
444 EXPORT_SYMBOL(get_dma_next_desc_ptr);
446 unsigned long get_dma_curr_desc_ptr(unsigned int channel)
448 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
449 && channel < MAX_BLACKFIN_DMA_CHANNEL));
451 return dma_ch[channel].regs->curr_desc_ptr;
453 EXPORT_SYMBOL(get_dma_curr_desc_ptr);
455 unsigned long get_dma_curr_addr(unsigned int channel)
457 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
458 && channel < MAX_BLACKFIN_DMA_CHANNEL));
460 return dma_ch[channel].regs->curr_addr_ptr;
462 EXPORT_SYMBOL(get_dma_curr_addr);
464 static void *__dma_memcpy(void *dest, const void *src, size_t size)
466 int direction; /* 1 - address decrease, 0 - address increase */
467 int flag_align; /* 1 - address aligned, 0 - address unaligned */
468 int flag_2D; /* 1 - 2D DMA needed, 0 - 1D DMA needed */
474 local_irq_save(flags);
476 if ((unsigned long)src < memory_end)
477 blackfin_dcache_flush_range((unsigned int)src,
478 (unsigned int)(src + size));
480 if ((unsigned long)dest < memory_end)
481 blackfin_dcache_invalidate_range((unsigned int)dest,
482 (unsigned int)(dest + size));
484 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
486 if ((unsigned long)src < (unsigned long)dest)
491 if ((((unsigned long)dest % 2) == 0) && (((unsigned long)src % 2) == 0)
492 && ((size % 2) == 0))
497 if (size > 0x10000) /* size > 64K */
502 /* Setup destination and source start address */
505 bfin_write_MDMA_D0_START_ADDR(dest + size - 2);
506 bfin_write_MDMA_S0_START_ADDR(src + size - 2);
508 bfin_write_MDMA_D0_START_ADDR(dest + size - 1);
509 bfin_write_MDMA_S0_START_ADDR(src + size - 1);
512 bfin_write_MDMA_D0_START_ADDR(dest);
513 bfin_write_MDMA_S0_START_ADDR(src);
516 /* Setup destination and source xcount */
519 bfin_write_MDMA_D0_X_COUNT(1024 / 2);
520 bfin_write_MDMA_S0_X_COUNT(1024 / 2);
522 bfin_write_MDMA_D0_X_COUNT(1024);
523 bfin_write_MDMA_S0_X_COUNT(1024);
525 bfin_write_MDMA_D0_Y_COUNT(size >> 10);
526 bfin_write_MDMA_S0_Y_COUNT(size >> 10);
529 bfin_write_MDMA_D0_X_COUNT(size / 2);
530 bfin_write_MDMA_S0_X_COUNT(size / 2);
532 bfin_write_MDMA_D0_X_COUNT(size);
533 bfin_write_MDMA_S0_X_COUNT(size);
537 /* Setup destination and source xmodify and ymodify */
540 bfin_write_MDMA_D0_X_MODIFY(-2);
541 bfin_write_MDMA_S0_X_MODIFY(-2);
543 bfin_write_MDMA_D0_Y_MODIFY(-2);
544 bfin_write_MDMA_S0_Y_MODIFY(-2);
547 bfin_write_MDMA_D0_X_MODIFY(-1);
548 bfin_write_MDMA_S0_X_MODIFY(-1);
550 bfin_write_MDMA_D0_Y_MODIFY(-1);
551 bfin_write_MDMA_S0_Y_MODIFY(-1);
556 bfin_write_MDMA_D0_X_MODIFY(2);
557 bfin_write_MDMA_S0_X_MODIFY(2);
559 bfin_write_MDMA_D0_Y_MODIFY(2);
560 bfin_write_MDMA_S0_Y_MODIFY(2);
563 bfin_write_MDMA_D0_X_MODIFY(1);
564 bfin_write_MDMA_S0_X_MODIFY(1);
566 bfin_write_MDMA_D0_Y_MODIFY(1);
567 bfin_write_MDMA_S0_Y_MODIFY(1);
572 /* Enable source DMA */
575 bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D | WDSIZE_16);
576 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D | WDSIZE_16);
578 bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D);
579 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D);
583 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
584 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
586 bfin_write_MDMA_S0_CONFIG(DMAEN);
587 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN);
593 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
596 bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() |
597 (DMA_DONE | DMA_ERR));
599 bfin_write_MDMA_S0_CONFIG(0);
600 bfin_write_MDMA_D0_CONFIG(0);
602 local_irq_restore(flags);
607 void *dma_memcpy(void *dest, const void *src, size_t size)
613 bulk = (size >> 16) << 16;
616 __dma_memcpy(dest, src, bulk);
617 addr = __dma_memcpy(dest+bulk, src+bulk, rest);
620 EXPORT_SYMBOL(dma_memcpy);
622 void *safe_dma_memcpy(void *dest, const void *src, size_t size)
625 addr = dma_memcpy(dest, src, size);
628 EXPORT_SYMBOL(safe_dma_memcpy);
630 void dma_outsb(unsigned long addr, const void *buf, unsigned short len)
634 local_irq_save(flags);
636 blackfin_dcache_flush_range((unsigned int)buf,
637 (unsigned int)(buf) + len);
639 bfin_write_MDMA_D0_START_ADDR(addr);
640 bfin_write_MDMA_D0_X_COUNT(len);
641 bfin_write_MDMA_D0_X_MODIFY(0);
642 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
644 bfin_write_MDMA_S0_START_ADDR(buf);
645 bfin_write_MDMA_S0_X_COUNT(len);
646 bfin_write_MDMA_S0_X_MODIFY(1);
647 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
649 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
650 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
654 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
656 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
658 bfin_write_MDMA_S0_CONFIG(0);
659 bfin_write_MDMA_D0_CONFIG(0);
660 local_irq_restore(flags);
663 EXPORT_SYMBOL(dma_outsb);
666 void dma_insb(unsigned long addr, void *buf, unsigned short len)
670 blackfin_dcache_invalidate_range((unsigned int)buf,
671 (unsigned int)(buf) + len);
673 local_irq_save(flags);
674 bfin_write_MDMA_D0_START_ADDR(buf);
675 bfin_write_MDMA_D0_X_COUNT(len);
676 bfin_write_MDMA_D0_X_MODIFY(1);
677 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
679 bfin_write_MDMA_S0_START_ADDR(addr);
680 bfin_write_MDMA_S0_X_COUNT(len);
681 bfin_write_MDMA_S0_X_MODIFY(0);
682 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
684 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
685 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
689 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
691 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
693 bfin_write_MDMA_S0_CONFIG(0);
694 bfin_write_MDMA_D0_CONFIG(0);
695 local_irq_restore(flags);
698 EXPORT_SYMBOL(dma_insb);
700 void dma_outsw(unsigned long addr, const void *buf, unsigned short len)
704 local_irq_save(flags);
706 blackfin_dcache_flush_range((unsigned int)buf,
707 (unsigned int)(buf) + len * sizeof(short));
709 bfin_write_MDMA_D0_START_ADDR(addr);
710 bfin_write_MDMA_D0_X_COUNT(len);
711 bfin_write_MDMA_D0_X_MODIFY(0);
712 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
714 bfin_write_MDMA_S0_START_ADDR(buf);
715 bfin_write_MDMA_S0_X_COUNT(len);
716 bfin_write_MDMA_S0_X_MODIFY(2);
717 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
719 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
720 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
724 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
726 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
728 bfin_write_MDMA_S0_CONFIG(0);
729 bfin_write_MDMA_D0_CONFIG(0);
730 local_irq_restore(flags);
733 EXPORT_SYMBOL(dma_outsw);
735 void dma_insw(unsigned long addr, void *buf, unsigned short len)
739 blackfin_dcache_invalidate_range((unsigned int)buf,
740 (unsigned int)(buf) + len * sizeof(short));
742 local_irq_save(flags);
744 bfin_write_MDMA_D0_START_ADDR(buf);
745 bfin_write_MDMA_D0_X_COUNT(len);
746 bfin_write_MDMA_D0_X_MODIFY(2);
747 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
749 bfin_write_MDMA_S0_START_ADDR(addr);
750 bfin_write_MDMA_S0_X_COUNT(len);
751 bfin_write_MDMA_S0_X_MODIFY(0);
752 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
754 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
755 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
759 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
761 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
763 bfin_write_MDMA_S0_CONFIG(0);
764 bfin_write_MDMA_D0_CONFIG(0);
765 local_irq_restore(flags);
768 EXPORT_SYMBOL(dma_insw);
770 void dma_outsl(unsigned long addr, const void *buf, unsigned short len)
774 local_irq_save(flags);
776 blackfin_dcache_flush_range((unsigned int)buf,
777 (unsigned int)(buf) + len * sizeof(long));
779 bfin_write_MDMA_D0_START_ADDR(addr);
780 bfin_write_MDMA_D0_X_COUNT(len);
781 bfin_write_MDMA_D0_X_MODIFY(0);
782 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
784 bfin_write_MDMA_S0_START_ADDR(buf);
785 bfin_write_MDMA_S0_X_COUNT(len);
786 bfin_write_MDMA_S0_X_MODIFY(4);
787 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
789 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
790 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
794 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
796 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
798 bfin_write_MDMA_S0_CONFIG(0);
799 bfin_write_MDMA_D0_CONFIG(0);
800 local_irq_restore(flags);
803 EXPORT_SYMBOL(dma_outsl);
805 void dma_insl(unsigned long addr, void *buf, unsigned short len)
809 blackfin_dcache_invalidate_range((unsigned int)buf,
810 (unsigned int)(buf) + len * sizeof(long));
812 local_irq_save(flags);
814 bfin_write_MDMA_D0_START_ADDR(buf);
815 bfin_write_MDMA_D0_X_COUNT(len);
816 bfin_write_MDMA_D0_X_MODIFY(4);
817 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
819 bfin_write_MDMA_S0_START_ADDR(addr);
820 bfin_write_MDMA_S0_X_COUNT(len);
821 bfin_write_MDMA_S0_X_MODIFY(0);
822 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
824 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
825 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
829 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
831 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
833 bfin_write_MDMA_S0_CONFIG(0);
834 bfin_write_MDMA_D0_CONFIG(0);
835 local_irq_restore(flags);
838 EXPORT_SYMBOL(dma_insl);