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 /**************************************************************************
43 ***************************************************************************/
45 static struct dma_channel dma_ch[MAX_BLACKFIN_DMA_CHANNEL];
47 /*------------------------------------------------------------------------------
48 * Set the Buffer Clear bit in the Configuration register of specific DMA
49 * channel. This will stop the descriptor based DMA operation.
50 *-----------------------------------------------------------------------------*/
51 static void clear_dma_buffer(unsigned int channel)
53 dma_ch[channel].regs->cfg |= RESTART;
55 dma_ch[channel].regs->cfg &= ~RESTART;
59 static int __init blackfin_dma_init(void)
63 printk(KERN_INFO "Blackfin DMA Controller\n");
65 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
66 dma_ch[i].chan_status = DMA_CHANNEL_FREE;
67 dma_ch[i].regs = dma_io_base_addr[i];
68 mutex_init(&(dma_ch[i].dmalock));
70 /* Mark MEMDMA Channel 0 as requested since we're using it internally */
71 dma_ch[CH_MEM_STREAM0_DEST].chan_status = DMA_CHANNEL_REQUESTED;
72 dma_ch[CH_MEM_STREAM0_SRC].chan_status = DMA_CHANNEL_REQUESTED;
74 #if defined(CONFIG_DEB_DMA_URGENT)
75 bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
76 | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
81 arch_initcall(blackfin_dma_init);
83 /*------------------------------------------------------------------------------
84 * Request the specific DMA channel from the system.
85 *-----------------------------------------------------------------------------*/
86 int request_dma(unsigned int channel, char *device_id)
89 pr_debug("request_dma() : BEGIN \n");
91 #if defined(CONFIG_BF561) && ANOMALY_05000182
92 if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
93 if (get_cclk() > 500000000) {
95 "Request IMDMA failed due to ANOMALY 05000182\n");
101 mutex_lock(&(dma_ch[channel].dmalock));
103 if ((dma_ch[channel].chan_status == DMA_CHANNEL_REQUESTED)
104 || (dma_ch[channel].chan_status == DMA_CHANNEL_ENABLED)) {
105 mutex_unlock(&(dma_ch[channel].dmalock));
106 pr_debug("DMA CHANNEL IN USE \n");
109 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
110 pr_debug("DMA CHANNEL IS ALLOCATED \n");
113 mutex_unlock(&(dma_ch[channel].dmalock));
116 if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
117 unsigned int per_map;
118 per_map = dma_ch[channel].regs->peripheral_map & 0xFFF;
119 if (strncmp(device_id, "BFIN_UART", 9) == 0)
120 dma_ch[channel].regs->peripheral_map = per_map |
121 ((channel - CH_UART2_RX + 0xC)<<12);
123 dma_ch[channel].regs->peripheral_map = per_map |
124 ((channel - CH_UART2_RX + 0x6)<<12);
128 dma_ch[channel].device_id = device_id;
129 dma_ch[channel].irq_callback = NULL;
131 /* This is to be enabled by putting a restriction -
132 * you have to request DMA, before doing any operations on
135 pr_debug("request_dma() : END \n");
138 EXPORT_SYMBOL(request_dma);
140 int set_dma_callback(unsigned int channel, dma_interrupt_t callback, void *data)
144 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
145 && channel < MAX_BLACKFIN_DMA_CHANNEL));
147 if (callback != NULL) {
149 ret_irq = channel2irq(channel);
151 dma_ch[channel].data = data;
154 request_irq(ret_irq, (void *)callback, IRQF_DISABLED,
155 dma_ch[channel].device_id, data);
158 "Request irq in DMA engine failed.\n");
161 dma_ch[channel].irq_callback = callback;
165 EXPORT_SYMBOL(set_dma_callback);
167 void free_dma(unsigned int channel)
171 pr_debug("freedma() : BEGIN \n");
172 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
173 && channel < MAX_BLACKFIN_DMA_CHANNEL));
176 disable_dma(channel);
177 clear_dma_buffer(channel);
179 if (dma_ch[channel].irq_callback != NULL) {
180 ret_irq = channel2irq(channel);
181 free_irq(ret_irq, dma_ch[channel].data);
184 /* Clear the DMA Variable in the Channel */
185 mutex_lock(&(dma_ch[channel].dmalock));
186 dma_ch[channel].chan_status = DMA_CHANNEL_FREE;
187 mutex_unlock(&(dma_ch[channel].dmalock));
189 pr_debug("freedma() : END \n");
191 EXPORT_SYMBOL(free_dma);
193 void dma_enable_irq(unsigned int channel)
197 pr_debug("dma_enable_irq() : BEGIN \n");
198 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
199 && channel < MAX_BLACKFIN_DMA_CHANNEL));
201 ret_irq = channel2irq(channel);
204 EXPORT_SYMBOL(dma_enable_irq);
206 void dma_disable_irq(unsigned int channel)
210 pr_debug("dma_disable_irq() : BEGIN \n");
211 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
212 && channel < MAX_BLACKFIN_DMA_CHANNEL));
214 ret_irq = channel2irq(channel);
215 disable_irq(ret_irq);
217 EXPORT_SYMBOL(dma_disable_irq);
219 int dma_channel_active(unsigned int channel)
221 if (dma_ch[channel].chan_status == DMA_CHANNEL_FREE) {
227 EXPORT_SYMBOL(dma_channel_active);
229 /*------------------------------------------------------------------------------
230 * stop the specific DMA channel.
231 *-----------------------------------------------------------------------------*/
232 void disable_dma(unsigned int channel)
234 pr_debug("stop_dma() : BEGIN \n");
236 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
237 && channel < MAX_BLACKFIN_DMA_CHANNEL));
239 dma_ch[channel].regs->cfg &= ~DMAEN; /* Clean the enable bit */
241 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
242 /* Needs to be enabled Later */
243 pr_debug("stop_dma() : END \n");
246 EXPORT_SYMBOL(disable_dma);
248 void enable_dma(unsigned int channel)
250 pr_debug("enable_dma() : BEGIN \n");
252 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
253 && channel < MAX_BLACKFIN_DMA_CHANNEL));
255 dma_ch[channel].chan_status = DMA_CHANNEL_ENABLED;
256 dma_ch[channel].regs->curr_x_count = 0;
257 dma_ch[channel].regs->curr_y_count = 0;
259 dma_ch[channel].regs->cfg |= DMAEN; /* Set the enable bit */
261 pr_debug("enable_dma() : END \n");
264 EXPORT_SYMBOL(enable_dma);
266 /*------------------------------------------------------------------------------
267 * Set the Start Address register for the specific DMA channel
268 * This function can be used for register based DMA,
269 * to setup the start address
270 * addr: Starting address of the DMA Data to be transferred.
271 *-----------------------------------------------------------------------------*/
272 void set_dma_start_addr(unsigned int channel, unsigned long addr)
274 pr_debug("set_dma_start_addr() : BEGIN \n");
276 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
277 && channel < MAX_BLACKFIN_DMA_CHANNEL));
279 dma_ch[channel].regs->start_addr = addr;
281 pr_debug("set_dma_start_addr() : END\n");
283 EXPORT_SYMBOL(set_dma_start_addr);
285 void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
287 pr_debug("set_dma_next_desc_addr() : BEGIN \n");
289 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
290 && channel < MAX_BLACKFIN_DMA_CHANNEL));
292 dma_ch[channel].regs->next_desc_ptr = addr;
294 pr_debug("set_dma_next_desc_addr() : END\n");
296 EXPORT_SYMBOL(set_dma_next_desc_addr);
298 void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
300 pr_debug("set_dma_curr_desc_addr() : BEGIN \n");
302 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
303 && channel < MAX_BLACKFIN_DMA_CHANNEL));
305 dma_ch[channel].regs->curr_desc_ptr = addr;
307 pr_debug("set_dma_curr_desc_addr() : END\n");
309 EXPORT_SYMBOL(set_dma_curr_desc_addr);
311 void set_dma_x_count(unsigned int channel, unsigned short x_count)
313 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
314 && channel < MAX_BLACKFIN_DMA_CHANNEL));
316 dma_ch[channel].regs->x_count = x_count;
319 EXPORT_SYMBOL(set_dma_x_count);
321 void set_dma_y_count(unsigned int channel, unsigned short y_count)
323 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
324 && channel < MAX_BLACKFIN_DMA_CHANNEL));
326 dma_ch[channel].regs->y_count = y_count;
329 EXPORT_SYMBOL(set_dma_y_count);
331 void set_dma_x_modify(unsigned int channel, short x_modify)
333 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
334 && channel < MAX_BLACKFIN_DMA_CHANNEL));
336 dma_ch[channel].regs->x_modify = x_modify;
339 EXPORT_SYMBOL(set_dma_x_modify);
341 void set_dma_y_modify(unsigned int channel, short y_modify)
343 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
344 && channel < MAX_BLACKFIN_DMA_CHANNEL));
346 dma_ch[channel].regs->y_modify = y_modify;
349 EXPORT_SYMBOL(set_dma_y_modify);
351 void set_dma_config(unsigned int channel, unsigned short config)
353 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
354 && channel < MAX_BLACKFIN_DMA_CHANNEL));
356 dma_ch[channel].regs->cfg = config;
359 EXPORT_SYMBOL(set_dma_config);
362 set_bfin_dma_config(char direction, char flow_mode,
363 char intr_mode, char dma_mode, char width, char syncmode)
365 unsigned short config;
368 ((direction << 1) | (width << 2) | (dma_mode << 4) |
369 (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5));
372 EXPORT_SYMBOL(set_bfin_dma_config);
374 void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg)
376 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
377 && channel < MAX_BLACKFIN_DMA_CHANNEL));
379 dma_ch[channel].regs->cfg |= ((nr_sg & 0x0F) << 8);
381 dma_ch[channel].regs->next_desc_ptr = (unsigned int)sg;
385 EXPORT_SYMBOL(set_dma_sg);
387 void set_dma_curr_addr(unsigned int channel, unsigned long addr)
389 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
390 && channel < MAX_BLACKFIN_DMA_CHANNEL));
392 dma_ch[channel].regs->curr_addr_ptr = addr;
395 EXPORT_SYMBOL(set_dma_curr_addr);
397 /*------------------------------------------------------------------------------
398 * Get the DMA status of a specific DMA channel from the system.
399 *-----------------------------------------------------------------------------*/
400 unsigned short get_dma_curr_irqstat(unsigned int channel)
402 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
403 && channel < MAX_BLACKFIN_DMA_CHANNEL));
405 return dma_ch[channel].regs->irq_status;
407 EXPORT_SYMBOL(get_dma_curr_irqstat);
409 /*------------------------------------------------------------------------------
410 * Clear the DMA_DONE bit in DMA status. Stop the DMA completion interrupt.
411 *-----------------------------------------------------------------------------*/
412 void clear_dma_irqstat(unsigned int channel)
414 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
415 && channel < MAX_BLACKFIN_DMA_CHANNEL));
416 dma_ch[channel].regs->irq_status |= 3;
418 EXPORT_SYMBOL(clear_dma_irqstat);
420 /*------------------------------------------------------------------------------
421 * Get current DMA xcount of a specific DMA channel from the system.
422 *-----------------------------------------------------------------------------*/
423 unsigned short get_dma_curr_xcount(unsigned int channel)
425 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
426 && channel < MAX_BLACKFIN_DMA_CHANNEL));
428 return dma_ch[channel].regs->curr_x_count;
430 EXPORT_SYMBOL(get_dma_curr_xcount);
432 /*------------------------------------------------------------------------------
433 * Get current DMA ycount of a specific DMA channel from the system.
434 *-----------------------------------------------------------------------------*/
435 unsigned short get_dma_curr_ycount(unsigned int channel)
437 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
438 && channel < MAX_BLACKFIN_DMA_CHANNEL));
440 return dma_ch[channel].regs->curr_y_count;
442 EXPORT_SYMBOL(get_dma_curr_ycount);
444 unsigned long get_dma_next_desc_ptr(unsigned int channel)
446 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
447 && channel < MAX_BLACKFIN_DMA_CHANNEL));
449 return dma_ch[channel].regs->next_desc_ptr;
451 EXPORT_SYMBOL(get_dma_next_desc_ptr);
453 unsigned long get_dma_curr_desc_ptr(unsigned int channel)
455 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
456 && channel < MAX_BLACKFIN_DMA_CHANNEL));
458 return dma_ch[channel].regs->curr_desc_ptr;
460 EXPORT_SYMBOL(get_dma_curr_desc_ptr);
462 unsigned long get_dma_curr_addr(unsigned int channel)
464 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
465 && channel < MAX_BLACKFIN_DMA_CHANNEL));
467 return dma_ch[channel].regs->curr_addr_ptr;
469 EXPORT_SYMBOL(get_dma_curr_addr);
472 int blackfin_dma_suspend(void)
476 #ifdef CONFIG_BF561 /* IMDMA channels doesn't have a PERIPHERAL_MAP */
477 for (i = 0; i <= CH_MEM_STREAM3_SRC; i++) {
479 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
481 if (dma_ch[i].chan_status == DMA_CHANNEL_ENABLED) {
482 printk(KERN_ERR "DMA Channel %d failed to suspend\n", i);
486 dma_ch[i].saved_peripheral_map = dma_ch[i].regs->peripheral_map;
492 void blackfin_dma_resume(void)
496 #ifdef CONFIG_BF561 /* IMDMA channels doesn't have a PERIPHERAL_MAP */
497 for (i = 0; i <= CH_MEM_STREAM3_SRC; i++)
499 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++)
501 dma_ch[i].regs->peripheral_map = dma_ch[i].saved_peripheral_map;
505 static void *__dma_memcpy(void *dest, const void *src, size_t size)
507 int direction; /* 1 - address decrease, 0 - address increase */
508 int flag_align; /* 1 - address aligned, 0 - address unaligned */
509 int flag_2D; /* 1 - 2D DMA needed, 0 - 1D DMA needed */
515 local_irq_save(flags);
517 if ((unsigned long)src < memory_end)
518 blackfin_dcache_flush_range((unsigned int)src,
519 (unsigned int)(src + size));
521 if ((unsigned long)dest < memory_end)
522 blackfin_dcache_invalidate_range((unsigned int)dest,
523 (unsigned int)(dest + size));
525 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
527 if ((unsigned long)src < (unsigned long)dest)
532 if ((((unsigned long)dest % 2) == 0) && (((unsigned long)src % 2) == 0)
533 && ((size % 2) == 0))
538 if (size > 0x10000) /* size > 64K */
543 /* Setup destination and source start address */
546 bfin_write_MDMA_D0_START_ADDR(dest + size - 2);
547 bfin_write_MDMA_S0_START_ADDR(src + size - 2);
549 bfin_write_MDMA_D0_START_ADDR(dest + size - 1);
550 bfin_write_MDMA_S0_START_ADDR(src + size - 1);
553 bfin_write_MDMA_D0_START_ADDR(dest);
554 bfin_write_MDMA_S0_START_ADDR(src);
557 /* Setup destination and source xcount */
560 bfin_write_MDMA_D0_X_COUNT(1024 / 2);
561 bfin_write_MDMA_S0_X_COUNT(1024 / 2);
563 bfin_write_MDMA_D0_X_COUNT(1024);
564 bfin_write_MDMA_S0_X_COUNT(1024);
566 bfin_write_MDMA_D0_Y_COUNT(size >> 10);
567 bfin_write_MDMA_S0_Y_COUNT(size >> 10);
570 bfin_write_MDMA_D0_X_COUNT(size / 2);
571 bfin_write_MDMA_S0_X_COUNT(size / 2);
573 bfin_write_MDMA_D0_X_COUNT(size);
574 bfin_write_MDMA_S0_X_COUNT(size);
578 /* Setup destination and source xmodify and ymodify */
581 bfin_write_MDMA_D0_X_MODIFY(-2);
582 bfin_write_MDMA_S0_X_MODIFY(-2);
584 bfin_write_MDMA_D0_Y_MODIFY(-2);
585 bfin_write_MDMA_S0_Y_MODIFY(-2);
588 bfin_write_MDMA_D0_X_MODIFY(-1);
589 bfin_write_MDMA_S0_X_MODIFY(-1);
591 bfin_write_MDMA_D0_Y_MODIFY(-1);
592 bfin_write_MDMA_S0_Y_MODIFY(-1);
597 bfin_write_MDMA_D0_X_MODIFY(2);
598 bfin_write_MDMA_S0_X_MODIFY(2);
600 bfin_write_MDMA_D0_Y_MODIFY(2);
601 bfin_write_MDMA_S0_Y_MODIFY(2);
604 bfin_write_MDMA_D0_X_MODIFY(1);
605 bfin_write_MDMA_S0_X_MODIFY(1);
607 bfin_write_MDMA_D0_Y_MODIFY(1);
608 bfin_write_MDMA_S0_Y_MODIFY(1);
613 /* Enable source DMA */
616 bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D | WDSIZE_16);
617 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D | WDSIZE_16);
619 bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D);
620 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D);
624 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
625 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
627 bfin_write_MDMA_S0_CONFIG(DMAEN);
628 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN);
634 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
637 bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() |
638 (DMA_DONE | DMA_ERR));
640 bfin_write_MDMA_S0_CONFIG(0);
641 bfin_write_MDMA_D0_CONFIG(0);
643 local_irq_restore(flags);
648 void *dma_memcpy(void *dest, const void *src, size_t size)
654 bulk = (size >> 16) << 16;
657 __dma_memcpy(dest, src, bulk);
658 addr = __dma_memcpy(dest+bulk, src+bulk, rest);
661 EXPORT_SYMBOL(dma_memcpy);
663 void *safe_dma_memcpy(void *dest, const void *src, size_t size)
666 addr = dma_memcpy(dest, src, size);
669 EXPORT_SYMBOL(safe_dma_memcpy);
671 void dma_outsb(unsigned long addr, const void *buf, unsigned short len)
675 local_irq_save(flags);
677 blackfin_dcache_flush_range((unsigned int)buf,
678 (unsigned int)(buf) + len);
680 bfin_write_MDMA_D0_START_ADDR(addr);
681 bfin_write_MDMA_D0_X_COUNT(len);
682 bfin_write_MDMA_D0_X_MODIFY(0);
683 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
685 bfin_write_MDMA_S0_START_ADDR(buf);
686 bfin_write_MDMA_S0_X_COUNT(len);
687 bfin_write_MDMA_S0_X_MODIFY(1);
688 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
690 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
691 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
695 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
697 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
699 bfin_write_MDMA_S0_CONFIG(0);
700 bfin_write_MDMA_D0_CONFIG(0);
701 local_irq_restore(flags);
704 EXPORT_SYMBOL(dma_outsb);
707 void dma_insb(unsigned long addr, void *buf, unsigned short len)
711 blackfin_dcache_invalidate_range((unsigned int)buf,
712 (unsigned int)(buf) + len);
714 local_irq_save(flags);
715 bfin_write_MDMA_D0_START_ADDR(buf);
716 bfin_write_MDMA_D0_X_COUNT(len);
717 bfin_write_MDMA_D0_X_MODIFY(1);
718 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
720 bfin_write_MDMA_S0_START_ADDR(addr);
721 bfin_write_MDMA_S0_X_COUNT(len);
722 bfin_write_MDMA_S0_X_MODIFY(0);
723 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
725 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
726 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
730 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
732 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
734 bfin_write_MDMA_S0_CONFIG(0);
735 bfin_write_MDMA_D0_CONFIG(0);
736 local_irq_restore(flags);
739 EXPORT_SYMBOL(dma_insb);
741 void dma_outsw(unsigned long addr, const void *buf, unsigned short len)
745 local_irq_save(flags);
747 blackfin_dcache_flush_range((unsigned int)buf,
748 (unsigned int)(buf) + len * sizeof(short));
750 bfin_write_MDMA_D0_START_ADDR(addr);
751 bfin_write_MDMA_D0_X_COUNT(len);
752 bfin_write_MDMA_D0_X_MODIFY(0);
753 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
755 bfin_write_MDMA_S0_START_ADDR(buf);
756 bfin_write_MDMA_S0_X_COUNT(len);
757 bfin_write_MDMA_S0_X_MODIFY(2);
758 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
760 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
761 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
765 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
767 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
769 bfin_write_MDMA_S0_CONFIG(0);
770 bfin_write_MDMA_D0_CONFIG(0);
771 local_irq_restore(flags);
774 EXPORT_SYMBOL(dma_outsw);
776 void dma_insw(unsigned long addr, void *buf, unsigned short len)
780 blackfin_dcache_invalidate_range((unsigned int)buf,
781 (unsigned int)(buf) + len * sizeof(short));
783 local_irq_save(flags);
785 bfin_write_MDMA_D0_START_ADDR(buf);
786 bfin_write_MDMA_D0_X_COUNT(len);
787 bfin_write_MDMA_D0_X_MODIFY(2);
788 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
790 bfin_write_MDMA_S0_START_ADDR(addr);
791 bfin_write_MDMA_S0_X_COUNT(len);
792 bfin_write_MDMA_S0_X_MODIFY(0);
793 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
795 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
796 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
800 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
802 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
804 bfin_write_MDMA_S0_CONFIG(0);
805 bfin_write_MDMA_D0_CONFIG(0);
806 local_irq_restore(flags);
809 EXPORT_SYMBOL(dma_insw);
811 void dma_outsl(unsigned long addr, const void *buf, unsigned short len)
815 local_irq_save(flags);
817 blackfin_dcache_flush_range((unsigned int)buf,
818 (unsigned int)(buf) + len * sizeof(long));
820 bfin_write_MDMA_D0_START_ADDR(addr);
821 bfin_write_MDMA_D0_X_COUNT(len);
822 bfin_write_MDMA_D0_X_MODIFY(0);
823 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
825 bfin_write_MDMA_S0_START_ADDR(buf);
826 bfin_write_MDMA_S0_X_COUNT(len);
827 bfin_write_MDMA_S0_X_MODIFY(4);
828 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
830 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
831 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
835 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
837 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
839 bfin_write_MDMA_S0_CONFIG(0);
840 bfin_write_MDMA_D0_CONFIG(0);
841 local_irq_restore(flags);
844 EXPORT_SYMBOL(dma_outsl);
846 void dma_insl(unsigned long addr, void *buf, unsigned short len)
850 blackfin_dcache_invalidate_range((unsigned int)buf,
851 (unsigned int)(buf) + len * sizeof(long));
853 local_irq_save(flags);
855 bfin_write_MDMA_D0_START_ADDR(buf);
856 bfin_write_MDMA_D0_X_COUNT(len);
857 bfin_write_MDMA_D0_X_MODIFY(4);
858 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
860 bfin_write_MDMA_S0_START_ADDR(addr);
861 bfin_write_MDMA_S0_X_COUNT(len);
862 bfin_write_MDMA_S0_X_MODIFY(0);
863 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
865 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
866 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
870 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
872 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
874 bfin_write_MDMA_S0_CONFIG(0);
875 bfin_write_MDMA_D0_CONFIG(0);
876 local_irq_restore(flags);
879 EXPORT_SYMBOL(dma_insl);