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");
94 #if defined(CONFIG_BF561) && ANOMALY_05000182
95 if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
96 if (get_cclk() > 500000000) {
98 "Request IMDMA failed due to ANOMALY 05000182\n");
104 mutex_lock(&(dma_ch[channel].dmalock));
106 if ((dma_ch[channel].chan_status == DMA_CHANNEL_REQUESTED)
107 || (dma_ch[channel].chan_status == DMA_CHANNEL_ENABLED)) {
108 mutex_unlock(&(dma_ch[channel].dmalock));
109 pr_debug("DMA CHANNEL IN USE \n");
112 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
113 pr_debug("DMA CHANNEL IS ALLOCATED \n");
116 mutex_unlock(&(dma_ch[channel].dmalock));
119 if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
120 if (strncmp(device_id, "BFIN_UART", 9) == 0) {
121 dma_ch[channel].regs->peripheral_map &= 0x0FFF;
122 dma_ch[channel].regs->peripheral_map |=
123 ((channel - CH_UART2_RX + 0xC)<<12);
125 dma_ch[channel].regs->peripheral_map &= 0x0FFF;
126 dma_ch[channel].regs->peripheral_map |=
127 ((channel - CH_UART2_RX + 0x6)<<12);
132 dma_ch[channel].device_id = device_id;
133 dma_ch[channel].irq_callback = NULL;
135 /* This is to be enabled by putting a restriction -
136 * you have to request DMA, before doing any operations on
139 pr_debug("request_dma() : END \n");
142 EXPORT_SYMBOL(request_dma);
144 int set_dma_callback(unsigned int channel, dma_interrupt_t callback, void *data)
148 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
149 && channel < MAX_BLACKFIN_DMA_CHANNEL));
151 if (callback != NULL) {
153 ret_irq = channel2irq(channel);
155 dma_ch[channel].data = data;
158 request_irq(ret_irq, (void *)callback, IRQF_DISABLED,
159 dma_ch[channel].device_id, data);
162 "Request irq in DMA engine failed.\n");
165 dma_ch[channel].irq_callback = callback;
169 EXPORT_SYMBOL(set_dma_callback);
171 void free_dma(unsigned int channel)
175 pr_debug("freedma() : BEGIN \n");
176 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
177 && channel < MAX_BLACKFIN_DMA_CHANNEL));
180 disable_dma(channel);
181 clear_dma_buffer(channel);
183 if (dma_ch[channel].irq_callback != NULL) {
184 ret_irq = channel2irq(channel);
185 free_irq(ret_irq, dma_ch[channel].data);
188 /* Clear the DMA Variable in the Channel */
189 mutex_lock(&(dma_ch[channel].dmalock));
190 dma_ch[channel].chan_status = DMA_CHANNEL_FREE;
191 mutex_unlock(&(dma_ch[channel].dmalock));
193 pr_debug("freedma() : END \n");
195 EXPORT_SYMBOL(free_dma);
197 void dma_enable_irq(unsigned int channel)
201 pr_debug("dma_enable_irq() : BEGIN \n");
202 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
203 && channel < MAX_BLACKFIN_DMA_CHANNEL));
205 ret_irq = channel2irq(channel);
208 EXPORT_SYMBOL(dma_enable_irq);
210 void dma_disable_irq(unsigned int channel)
214 pr_debug("dma_disable_irq() : BEGIN \n");
215 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
216 && channel < MAX_BLACKFIN_DMA_CHANNEL));
218 ret_irq = channel2irq(channel);
219 disable_irq(ret_irq);
221 EXPORT_SYMBOL(dma_disable_irq);
223 int dma_channel_active(unsigned int channel)
225 if (dma_ch[channel].chan_status == DMA_CHANNEL_FREE) {
231 EXPORT_SYMBOL(dma_channel_active);
233 /*------------------------------------------------------------------------------
234 * stop the specific DMA channel.
235 *-----------------------------------------------------------------------------*/
236 void disable_dma(unsigned int channel)
238 pr_debug("stop_dma() : BEGIN \n");
240 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
241 && channel < MAX_BLACKFIN_DMA_CHANNEL));
243 dma_ch[channel].regs->cfg &= ~DMAEN; /* Clean the enable bit */
245 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
246 /* Needs to be enabled Later */
247 pr_debug("stop_dma() : END \n");
250 EXPORT_SYMBOL(disable_dma);
252 void enable_dma(unsigned int channel)
254 pr_debug("enable_dma() : BEGIN \n");
256 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
257 && channel < MAX_BLACKFIN_DMA_CHANNEL));
259 dma_ch[channel].chan_status = DMA_CHANNEL_ENABLED;
260 dma_ch[channel].regs->curr_x_count = 0;
261 dma_ch[channel].regs->curr_y_count = 0;
263 dma_ch[channel].regs->cfg |= DMAEN; /* Set the enable bit */
265 pr_debug("enable_dma() : END \n");
268 EXPORT_SYMBOL(enable_dma);
270 /*------------------------------------------------------------------------------
271 * Set the Start Address register for the specific DMA channel
272 * This function can be used for register based DMA,
273 * to setup the start address
274 * addr: Starting address of the DMA Data to be transferred.
275 *-----------------------------------------------------------------------------*/
276 void set_dma_start_addr(unsigned int channel, unsigned long addr)
278 pr_debug("set_dma_start_addr() : BEGIN \n");
280 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
281 && channel < MAX_BLACKFIN_DMA_CHANNEL));
283 dma_ch[channel].regs->start_addr = addr;
285 pr_debug("set_dma_start_addr() : END\n");
287 EXPORT_SYMBOL(set_dma_start_addr);
289 void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
291 pr_debug("set_dma_next_desc_addr() : BEGIN \n");
293 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
294 && channel < MAX_BLACKFIN_DMA_CHANNEL));
296 dma_ch[channel].regs->next_desc_ptr = addr;
298 pr_debug("set_dma_next_desc_addr() : END\n");
300 EXPORT_SYMBOL(set_dma_next_desc_addr);
302 void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
304 pr_debug("set_dma_curr_desc_addr() : BEGIN \n");
306 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
307 && channel < MAX_BLACKFIN_DMA_CHANNEL));
309 dma_ch[channel].regs->curr_desc_ptr = addr;
311 pr_debug("set_dma_curr_desc_addr() : END\n");
313 EXPORT_SYMBOL(set_dma_curr_desc_addr);
315 void set_dma_x_count(unsigned int channel, unsigned short x_count)
317 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
318 && channel < MAX_BLACKFIN_DMA_CHANNEL));
320 dma_ch[channel].regs->x_count = x_count;
323 EXPORT_SYMBOL(set_dma_x_count);
325 void set_dma_y_count(unsigned int channel, unsigned short y_count)
327 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
328 && channel < MAX_BLACKFIN_DMA_CHANNEL));
330 dma_ch[channel].regs->y_count = y_count;
333 EXPORT_SYMBOL(set_dma_y_count);
335 void set_dma_x_modify(unsigned int channel, short x_modify)
337 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
338 && channel < MAX_BLACKFIN_DMA_CHANNEL));
340 dma_ch[channel].regs->x_modify = x_modify;
343 EXPORT_SYMBOL(set_dma_x_modify);
345 void set_dma_y_modify(unsigned int channel, short y_modify)
347 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
348 && channel < MAX_BLACKFIN_DMA_CHANNEL));
350 dma_ch[channel].regs->y_modify = y_modify;
353 EXPORT_SYMBOL(set_dma_y_modify);
355 void set_dma_config(unsigned int channel, unsigned short config)
357 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
358 && channel < MAX_BLACKFIN_DMA_CHANNEL));
360 dma_ch[channel].regs->cfg = config;
363 EXPORT_SYMBOL(set_dma_config);
366 set_bfin_dma_config(char direction, char flow_mode,
367 char intr_mode, char dma_mode, char width, char syncmode)
369 unsigned short config;
372 ((direction << 1) | (width << 2) | (dma_mode << 4) |
373 (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5));
376 EXPORT_SYMBOL(set_bfin_dma_config);
378 void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg)
380 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
381 && channel < MAX_BLACKFIN_DMA_CHANNEL));
383 dma_ch[channel].regs->cfg |= ((nr_sg & 0x0F) << 8);
385 dma_ch[channel].regs->next_desc_ptr = (unsigned int)sg;
389 EXPORT_SYMBOL(set_dma_sg);
391 void set_dma_curr_addr(unsigned int channel, unsigned long addr)
393 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
394 && channel < MAX_BLACKFIN_DMA_CHANNEL));
396 dma_ch[channel].regs->curr_addr_ptr = addr;
399 EXPORT_SYMBOL(set_dma_curr_addr);
401 /*------------------------------------------------------------------------------
402 * Get the DMA status of a specific DMA channel from the system.
403 *-----------------------------------------------------------------------------*/
404 unsigned short get_dma_curr_irqstat(unsigned int channel)
406 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
407 && channel < MAX_BLACKFIN_DMA_CHANNEL));
409 return dma_ch[channel].regs->irq_status;
411 EXPORT_SYMBOL(get_dma_curr_irqstat);
413 /*------------------------------------------------------------------------------
414 * Clear the DMA_DONE bit in DMA status. Stop the DMA completion interrupt.
415 *-----------------------------------------------------------------------------*/
416 void clear_dma_irqstat(unsigned int channel)
418 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
419 && channel < MAX_BLACKFIN_DMA_CHANNEL));
420 dma_ch[channel].regs->irq_status |= 3;
422 EXPORT_SYMBOL(clear_dma_irqstat);
424 /*------------------------------------------------------------------------------
425 * Get current DMA xcount of a specific DMA channel from the system.
426 *-----------------------------------------------------------------------------*/
427 unsigned short get_dma_curr_xcount(unsigned int channel)
429 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
430 && channel < MAX_BLACKFIN_DMA_CHANNEL));
432 return dma_ch[channel].regs->curr_x_count;
434 EXPORT_SYMBOL(get_dma_curr_xcount);
436 /*------------------------------------------------------------------------------
437 * Get current DMA ycount of a specific DMA channel from the system.
438 *-----------------------------------------------------------------------------*/
439 unsigned short get_dma_curr_ycount(unsigned int channel)
441 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
442 && channel < MAX_BLACKFIN_DMA_CHANNEL));
444 return dma_ch[channel].regs->curr_y_count;
446 EXPORT_SYMBOL(get_dma_curr_ycount);
448 unsigned long get_dma_next_desc_ptr(unsigned int channel)
450 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
451 && channel < MAX_BLACKFIN_DMA_CHANNEL));
453 return dma_ch[channel].regs->next_desc_ptr;
455 EXPORT_SYMBOL(get_dma_next_desc_ptr);
457 unsigned long get_dma_curr_desc_ptr(unsigned int channel)
459 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
460 && channel < MAX_BLACKFIN_DMA_CHANNEL));
462 return dma_ch[channel].regs->curr_desc_ptr;
464 EXPORT_SYMBOL(get_dma_curr_desc_ptr);
466 unsigned long get_dma_curr_addr(unsigned int channel)
468 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
469 && channel < MAX_BLACKFIN_DMA_CHANNEL));
471 return dma_ch[channel].regs->curr_addr_ptr;
473 EXPORT_SYMBOL(get_dma_curr_addr);
476 int blackfin_dma_suspend(void)
480 #ifdef CONFIG_BF561 /* IMDMA channels doesn't have a PERIPHERAL_MAP */
481 for (i = 0; i <= CH_MEM_STREAM3_SRC; i++) {
483 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
485 if (dma_ch[i].chan_status == DMA_CHANNEL_ENABLED) {
486 printk(KERN_ERR "DMA Channel %d failed to suspend\n", i);
490 dma_ch[i].saved_peripheral_map = dma_ch[i].regs->peripheral_map;
496 void blackfin_dma_resume(void)
500 #ifdef CONFIG_BF561 /* IMDMA channels doesn't have a PERIPHERAL_MAP */
501 for (i = 0; i <= CH_MEM_STREAM3_SRC; i++)
503 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++)
505 dma_ch[i].regs->peripheral_map = dma_ch[i].saved_peripheral_map;
509 static void *__dma_memcpy(void *dest, const void *src, size_t size)
511 int direction; /* 1 - address decrease, 0 - address increase */
512 int flag_align; /* 1 - address aligned, 0 - address unaligned */
513 int flag_2D; /* 1 - 2D DMA needed, 0 - 1D DMA needed */
519 local_irq_save(flags);
521 if ((unsigned long)src < memory_end)
522 blackfin_dcache_flush_range((unsigned int)src,
523 (unsigned int)(src + size));
525 if ((unsigned long)dest < memory_end)
526 blackfin_dcache_invalidate_range((unsigned int)dest,
527 (unsigned int)(dest + size));
529 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
531 if ((unsigned long)src < (unsigned long)dest)
536 if ((((unsigned long)dest % 2) == 0) && (((unsigned long)src % 2) == 0)
537 && ((size % 2) == 0))
542 if (size > 0x10000) /* size > 64K */
547 /* Setup destination and source start address */
550 bfin_write_MDMA_D0_START_ADDR(dest + size - 2);
551 bfin_write_MDMA_S0_START_ADDR(src + size - 2);
553 bfin_write_MDMA_D0_START_ADDR(dest + size - 1);
554 bfin_write_MDMA_S0_START_ADDR(src + size - 1);
557 bfin_write_MDMA_D0_START_ADDR(dest);
558 bfin_write_MDMA_S0_START_ADDR(src);
561 /* Setup destination and source xcount */
564 bfin_write_MDMA_D0_X_COUNT(1024 / 2);
565 bfin_write_MDMA_S0_X_COUNT(1024 / 2);
567 bfin_write_MDMA_D0_X_COUNT(1024);
568 bfin_write_MDMA_S0_X_COUNT(1024);
570 bfin_write_MDMA_D0_Y_COUNT(size >> 10);
571 bfin_write_MDMA_S0_Y_COUNT(size >> 10);
574 bfin_write_MDMA_D0_X_COUNT(size / 2);
575 bfin_write_MDMA_S0_X_COUNT(size / 2);
577 bfin_write_MDMA_D0_X_COUNT(size);
578 bfin_write_MDMA_S0_X_COUNT(size);
582 /* Setup destination and source xmodify and ymodify */
585 bfin_write_MDMA_D0_X_MODIFY(-2);
586 bfin_write_MDMA_S0_X_MODIFY(-2);
588 bfin_write_MDMA_D0_Y_MODIFY(-2);
589 bfin_write_MDMA_S0_Y_MODIFY(-2);
592 bfin_write_MDMA_D0_X_MODIFY(-1);
593 bfin_write_MDMA_S0_X_MODIFY(-1);
595 bfin_write_MDMA_D0_Y_MODIFY(-1);
596 bfin_write_MDMA_S0_Y_MODIFY(-1);
601 bfin_write_MDMA_D0_X_MODIFY(2);
602 bfin_write_MDMA_S0_X_MODIFY(2);
604 bfin_write_MDMA_D0_Y_MODIFY(2);
605 bfin_write_MDMA_S0_Y_MODIFY(2);
608 bfin_write_MDMA_D0_X_MODIFY(1);
609 bfin_write_MDMA_S0_X_MODIFY(1);
611 bfin_write_MDMA_D0_Y_MODIFY(1);
612 bfin_write_MDMA_S0_Y_MODIFY(1);
617 /* Enable source DMA */
620 bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D | WDSIZE_16);
621 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D | WDSIZE_16);
623 bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D);
624 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D);
628 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
629 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
631 bfin_write_MDMA_S0_CONFIG(DMAEN);
632 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN);
638 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
641 bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() |
642 (DMA_DONE | DMA_ERR));
644 bfin_write_MDMA_S0_CONFIG(0);
645 bfin_write_MDMA_D0_CONFIG(0);
647 local_irq_restore(flags);
652 void *dma_memcpy(void *dest, const void *src, size_t size)
658 bulk = (size >> 16) << 16;
661 __dma_memcpy(dest, src, bulk);
662 addr = __dma_memcpy(dest+bulk, src+bulk, rest);
665 EXPORT_SYMBOL(dma_memcpy);
667 void *safe_dma_memcpy(void *dest, const void *src, size_t size)
670 addr = dma_memcpy(dest, src, size);
673 EXPORT_SYMBOL(safe_dma_memcpy);
675 void dma_outsb(unsigned long addr, const void *buf, unsigned short len)
679 local_irq_save(flags);
681 blackfin_dcache_flush_range((unsigned int)buf,
682 (unsigned int)(buf) + len);
684 bfin_write_MDMA_D0_START_ADDR(addr);
685 bfin_write_MDMA_D0_X_COUNT(len);
686 bfin_write_MDMA_D0_X_MODIFY(0);
687 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
689 bfin_write_MDMA_S0_START_ADDR(buf);
690 bfin_write_MDMA_S0_X_COUNT(len);
691 bfin_write_MDMA_S0_X_MODIFY(1);
692 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
694 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
695 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
699 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
701 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
703 bfin_write_MDMA_S0_CONFIG(0);
704 bfin_write_MDMA_D0_CONFIG(0);
705 local_irq_restore(flags);
708 EXPORT_SYMBOL(dma_outsb);
711 void dma_insb(unsigned long addr, void *buf, unsigned short len)
715 blackfin_dcache_invalidate_range((unsigned int)buf,
716 (unsigned int)(buf) + len);
718 local_irq_save(flags);
719 bfin_write_MDMA_D0_START_ADDR(buf);
720 bfin_write_MDMA_D0_X_COUNT(len);
721 bfin_write_MDMA_D0_X_MODIFY(1);
722 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
724 bfin_write_MDMA_S0_START_ADDR(addr);
725 bfin_write_MDMA_S0_X_COUNT(len);
726 bfin_write_MDMA_S0_X_MODIFY(0);
727 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
729 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
730 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
734 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
736 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
738 bfin_write_MDMA_S0_CONFIG(0);
739 bfin_write_MDMA_D0_CONFIG(0);
740 local_irq_restore(flags);
743 EXPORT_SYMBOL(dma_insb);
745 void dma_outsw(unsigned long addr, const void *buf, unsigned short len)
749 local_irq_save(flags);
751 blackfin_dcache_flush_range((unsigned int)buf,
752 (unsigned int)(buf) + len * sizeof(short));
754 bfin_write_MDMA_D0_START_ADDR(addr);
755 bfin_write_MDMA_D0_X_COUNT(len);
756 bfin_write_MDMA_D0_X_MODIFY(0);
757 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
759 bfin_write_MDMA_S0_START_ADDR(buf);
760 bfin_write_MDMA_S0_X_COUNT(len);
761 bfin_write_MDMA_S0_X_MODIFY(2);
762 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
764 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
765 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
769 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
771 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
773 bfin_write_MDMA_S0_CONFIG(0);
774 bfin_write_MDMA_D0_CONFIG(0);
775 local_irq_restore(flags);
778 EXPORT_SYMBOL(dma_outsw);
780 void dma_insw(unsigned long addr, void *buf, unsigned short len)
784 blackfin_dcache_invalidate_range((unsigned int)buf,
785 (unsigned int)(buf) + len * sizeof(short));
787 local_irq_save(flags);
789 bfin_write_MDMA_D0_START_ADDR(buf);
790 bfin_write_MDMA_D0_X_COUNT(len);
791 bfin_write_MDMA_D0_X_MODIFY(2);
792 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
794 bfin_write_MDMA_S0_START_ADDR(addr);
795 bfin_write_MDMA_S0_X_COUNT(len);
796 bfin_write_MDMA_S0_X_MODIFY(0);
797 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
799 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
800 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
804 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
806 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
808 bfin_write_MDMA_S0_CONFIG(0);
809 bfin_write_MDMA_D0_CONFIG(0);
810 local_irq_restore(flags);
813 EXPORT_SYMBOL(dma_insw);
815 void dma_outsl(unsigned long addr, const void *buf, unsigned short len)
819 local_irq_save(flags);
821 blackfin_dcache_flush_range((unsigned int)buf,
822 (unsigned int)(buf) + len * sizeof(long));
824 bfin_write_MDMA_D0_START_ADDR(addr);
825 bfin_write_MDMA_D0_X_COUNT(len);
826 bfin_write_MDMA_D0_X_MODIFY(0);
827 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
829 bfin_write_MDMA_S0_START_ADDR(buf);
830 bfin_write_MDMA_S0_X_COUNT(len);
831 bfin_write_MDMA_S0_X_MODIFY(4);
832 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
834 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
835 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
839 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
841 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
843 bfin_write_MDMA_S0_CONFIG(0);
844 bfin_write_MDMA_D0_CONFIG(0);
845 local_irq_restore(flags);
848 EXPORT_SYMBOL(dma_outsl);
850 void dma_insl(unsigned long addr, void *buf, unsigned short len)
854 blackfin_dcache_invalidate_range((unsigned int)buf,
855 (unsigned int)(buf) + len * sizeof(long));
857 local_irq_save(flags);
859 bfin_write_MDMA_D0_START_ADDR(buf);
860 bfin_write_MDMA_D0_X_COUNT(len);
861 bfin_write_MDMA_D0_X_MODIFY(4);
862 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
864 bfin_write_MDMA_S0_START_ADDR(addr);
865 bfin_write_MDMA_S0_X_COUNT(len);
866 bfin_write_MDMA_S0_X_MODIFY(0);
867 bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
869 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
870 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
874 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
876 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
878 bfin_write_MDMA_S0_CONFIG(0);
879 bfin_write_MDMA_D0_CONFIG(0);
880 local_irq_restore(flags);
883 EXPORT_SYMBOL(dma_insl);