blackfin: add bf60x to current framework
[firefly-linux-kernel-4.4.55.git] / arch / blackfin / kernel / bfin_dma.c
1 /*
2  * bfin_dma.c - Blackfin DMA implementation
3  *
4  * Copyright 2004-2008 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2 or later.
7  */
8
9 #include <linux/errno.h>
10 #include <linux/interrupt.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/param.h>
14 #include <linux/proc_fs.h>
15 #include <linux/sched.h>
16 #include <linux/seq_file.h>
17 #include <linux/spinlock.h>
18
19 #include <asm/blackfin.h>
20 #include <asm/cacheflush.h>
21 #include <asm/dma.h>
22 #include <asm/uaccess.h>
23 #include <asm/early_printk.h>
24
25 /*
26  * To make sure we work around 05000119 - we always check DMA_DONE bit,
27  * never the DMA_RUN bit
28  */
29
30 struct dma_channel dma_ch[MAX_DMA_CHANNELS];
31 EXPORT_SYMBOL(dma_ch);
32
33 static int __init blackfin_dma_init(void)
34 {
35         int i;
36
37         printk(KERN_INFO "Blackfin DMA Controller\n");
38
39
40 #if ANOMALY_05000480
41         bfin_write_DMAC_TC_PER(0x0111);
42 #endif
43
44         for (i = 0; i < MAX_DMA_CHANNELS; i++) {
45                 atomic_set(&dma_ch[i].chan_status, 0);
46                 dma_ch[i].regs = dma_io_base_addr[i];
47         }
48 #ifdef CH_MEM_STREAM3_SRC
49         /* Mark MEMDMA Channel 3 as requested since we're using it internally */
50         request_dma(CH_MEM_STREAM3_DEST, "Blackfin dma_memcpy");
51         request_dma(CH_MEM_STREAM3_SRC, "Blackfin dma_memcpy");
52 #else
53         /* Mark MEMDMA Channel 0 as requested since we're using it internally */
54         request_dma(CH_MEM_STREAM0_DEST, "Blackfin dma_memcpy");
55         request_dma(CH_MEM_STREAM0_SRC, "Blackfin dma_memcpy");
56 #endif
57
58 #if defined(CONFIG_DEB_DMA_URGENT)
59         bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
60                          | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
61 #endif
62
63         return 0;
64 }
65 arch_initcall(blackfin_dma_init);
66
67 #ifdef CONFIG_PROC_FS
68 static int proc_dma_show(struct seq_file *m, void *v)
69 {
70         int i;
71
72         for (i = 0; i < MAX_DMA_CHANNELS; ++i)
73                 if (dma_channel_active(i))
74                         seq_printf(m, "%2d: %s\n", i, dma_ch[i].device_id);
75
76         return 0;
77 }
78
79 static int proc_dma_open(struct inode *inode, struct file *file)
80 {
81         return single_open(file, proc_dma_show, NULL);
82 }
83
84 static const struct file_operations proc_dma_operations = {
85         .open           = proc_dma_open,
86         .read           = seq_read,
87         .llseek         = seq_lseek,
88         .release        = single_release,
89 };
90
91 static int __init proc_dma_init(void)
92 {
93         return proc_create("dma", 0, NULL, &proc_dma_operations) != NULL;
94 }
95 late_initcall(proc_dma_init);
96 #endif
97
98 static void set_dma_peripheral_map(unsigned int channel, const char *device_id)
99 {
100 #ifdef CONFIG_BF54x
101         unsigned int per_map;
102
103         switch (channel) {
104                 case CH_UART2_RX: per_map = 0xC << 12; break;
105                 case CH_UART2_TX: per_map = 0xD << 12; break;
106                 case CH_UART3_RX: per_map = 0xE << 12; break;
107                 case CH_UART3_TX: per_map = 0xF << 12; break;
108                 default:          return;
109         }
110
111         if (strncmp(device_id, "BFIN_UART", 9) == 0)
112                 dma_ch[channel].regs->peripheral_map = per_map;
113 #endif
114 }
115
116 /**
117  *      request_dma - request a DMA channel
118  *
119  * Request the specific DMA channel from the system if it's available.
120  */
121 int request_dma(unsigned int channel, const char *device_id)
122 {
123         pr_debug("request_dma() : BEGIN\n");
124
125         if (device_id == NULL)
126                 printk(KERN_WARNING "request_dma(%u): no device_id given\n", channel);
127
128 #if defined(CONFIG_BF561) && ANOMALY_05000182
129         if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
130                 if (get_cclk() > 500000000) {
131                         printk(KERN_WARNING
132                                "Request IMDMA failed due to ANOMALY 05000182\n");
133                         return -EFAULT;
134                 }
135         }
136 #endif
137
138         if (atomic_cmpxchg(&dma_ch[channel].chan_status, 0, 1)) {
139                 pr_debug("DMA CHANNEL IN USE\n");
140                 return -EBUSY;
141         }
142
143         set_dma_peripheral_map(channel, device_id);
144         dma_ch[channel].device_id = device_id;
145         dma_ch[channel].irq = 0;
146
147         /* This is to be enabled by putting a restriction -
148          * you have to request DMA, before doing any operations on
149          * descriptor/channel
150          */
151         pr_debug("request_dma() : END\n");
152         return 0;
153 }
154 EXPORT_SYMBOL(request_dma);
155
156 int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data)
157 {
158         int ret;
159         unsigned int irq;
160
161         BUG_ON(channel >= MAX_DMA_CHANNELS || !callback ||
162                         !atomic_read(&dma_ch[channel].chan_status));
163
164         irq = channel2irq(channel);
165         ret = request_irq(irq, callback, 0, dma_ch[channel].device_id, data);
166         if (ret)
167                 return ret;
168
169         dma_ch[channel].irq = irq;
170         dma_ch[channel].data = data;
171
172         return 0;
173 }
174 EXPORT_SYMBOL(set_dma_callback);
175
176 /**
177  *      clear_dma_buffer - clear DMA fifos for specified channel
178  *
179  * Set the Buffer Clear bit in the Configuration register of specific DMA
180  * channel. This will stop the descriptor based DMA operation.
181  */
182 static void clear_dma_buffer(unsigned int channel)
183 {
184         dma_ch[channel].regs->cfg |= RESTART;
185         SSYNC();
186         dma_ch[channel].regs->cfg &= ~RESTART;
187 }
188
189 void free_dma(unsigned int channel)
190 {
191         pr_debug("freedma() : BEGIN\n");
192         BUG_ON(channel >= MAX_DMA_CHANNELS ||
193                         !atomic_read(&dma_ch[channel].chan_status));
194
195         /* Halt the DMA */
196         disable_dma(channel);
197         clear_dma_buffer(channel);
198
199         if (dma_ch[channel].irq)
200                 free_irq(dma_ch[channel].irq, dma_ch[channel].data);
201
202         /* Clear the DMA Variable in the Channel */
203         atomic_set(&dma_ch[channel].chan_status, 0);
204
205         pr_debug("freedma() : END\n");
206 }
207 EXPORT_SYMBOL(free_dma);
208
209 #ifdef CONFIG_PM
210 # ifndef MAX_DMA_SUSPEND_CHANNELS
211 #  define MAX_DMA_SUSPEND_CHANNELS MAX_DMA_CHANNELS
212 # endif
213 # ifndef CONFIG_BF60x
214 int blackfin_dma_suspend(void)
215 {
216         int i;
217
218         for (i = 0; i < MAX_DMA_CHANNELS; ++i) {
219                 if (dma_ch[i].regs->cfg & DMAEN) {
220                         printk(KERN_ERR "DMA Channel %d failed to suspend\n", i);
221                         return -EBUSY;
222                 }
223                 if (i < MAX_DMA_SUSPEND_CHANNELS)
224                         dma_ch[i].saved_peripheral_map = dma_ch[i].regs->peripheral_map;
225         }
226
227 #if ANOMALY_05000480
228         bfin_write_DMAC_TC_PER(0x0);
229 #endif
230         return 0;
231 }
232
233 void blackfin_dma_resume(void)
234 {
235         int i;
236
237         for (i = 0; i < MAX_DMA_CHANNELS; ++i) {
238                 dma_ch[i].regs->cfg = 0;
239                 if (i < MAX_DMA_SUSPEND_CHANNELS)
240                         dma_ch[i].regs->peripheral_map = dma_ch[i].saved_peripheral_map;
241         }
242 #if ANOMALY_05000480
243         bfin_write_DMAC_TC_PER(0x0111);
244 #endif
245 }
246 # else
247 int blackfin_dma_suspend(void)
248 {
249         return 0;
250 }
251
252 void blackfin_dma_resume(void)
253 {
254 }
255 #endif
256 #endif
257
258 /**
259  *      blackfin_dma_early_init - minimal DMA init
260  *
261  * Setup a few DMA registers so we can safely do DMA transfers early on in
262  * the kernel booting process.  Really this just means using dma_memcpy().
263  */
264 void __init blackfin_dma_early_init(void)
265 {
266         early_shadow_stamp();
267         bfin_write_MDMA_S0_CONFIG(0);
268         bfin_write_MDMA_S1_CONFIG(0);
269 }
270
271 void __init early_dma_memcpy(void *pdst, const void *psrc, size_t size)
272 {
273         unsigned long dst = (unsigned long)pdst;
274         unsigned long src = (unsigned long)psrc;
275         struct dma_register *dst_ch, *src_ch;
276
277         early_shadow_stamp();
278
279         /* We assume that everything is 4 byte aligned, so include
280          * a basic sanity check
281          */
282         BUG_ON(dst % 4);
283         BUG_ON(src % 4);
284         BUG_ON(size % 4);
285
286         src_ch = 0;
287         /* Find an avalible memDMA channel */
288         while (1) {
289                 if (src_ch == (struct dma_register *)MDMA_S0_NEXT_DESC_PTR) {
290                         dst_ch = (struct dma_register *)MDMA_D1_NEXT_DESC_PTR;
291                         src_ch = (struct dma_register *)MDMA_S1_NEXT_DESC_PTR;
292                 } else {
293                         dst_ch = (struct dma_register *)MDMA_D0_NEXT_DESC_PTR;
294                         src_ch = (struct dma_register *)MDMA_S0_NEXT_DESC_PTR;
295                 }
296
297                 if (!DMA_MMR_READ(&src_ch->cfg))
298                         break;
299                 else if (DMA_MMR_READ(&dst_ch->irq_status) & DMA_DONE) {
300                         DMA_MMR_WRITE(&src_ch->cfg, 0);
301                         break;
302                 }
303         }
304
305         /* Force a sync in case a previous config reset on this channel
306          * occurred.  This is needed so subsequent writes to DMA registers
307          * are not spuriously lost/corrupted.
308          */
309         __builtin_bfin_ssync();
310
311         /* Destination */
312         bfin_write32(&dst_ch->start_addr, dst);
313         DMA_MMR_WRITE(&dst_ch->x_count, size >> 2);
314         DMA_MMR_WRITE(&dst_ch->x_modify, 1 << 2);
315         DMA_MMR_WRITE(&dst_ch->irq_status, DMA_DONE | DMA_ERR);
316
317         /* Source */
318         bfin_write32(&src_ch->start_addr, src);
319         DMA_MMR_WRITE(&src_ch->x_count, size >> 2);
320         DMA_MMR_WRITE(&src_ch->x_modify, 1 << 2);
321         DMA_MMR_WRITE(&src_ch->irq_status, DMA_DONE | DMA_ERR);
322
323         /* Enable */
324         DMA_MMR_WRITE(&src_ch->cfg, DMAEN | WDSIZE_32);
325         DMA_MMR_WRITE(&dst_ch->cfg, WNR | DI_EN_X | DMAEN | WDSIZE_32);
326
327         /* Since we are atomic now, don't use the workaround ssync */
328         __builtin_bfin_ssync();
329
330 #ifdef CONFIG_BF60x
331         /* Work around a possible MDMA anomaly. Running 2 MDMA channels to
332          * transfer DDR data to L1 SRAM may corrupt data.
333          * Should be reverted after this issue is root caused.
334          */
335         while (!(DMA_MMR_READ(&dst_ch->irq_status) & DMA_DONE))
336                 continue;
337 #endif
338 }
339
340 void __init early_dma_memcpy_done(void)
341 {
342         early_shadow_stamp();
343
344         while ((bfin_read_MDMA_S0_CONFIG() && !(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)) ||
345                (bfin_read_MDMA_S1_CONFIG() && !(bfin_read_MDMA_D1_IRQ_STATUS() & DMA_DONE)))
346                 continue;
347
348         bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
349         bfin_write_MDMA_D1_IRQ_STATUS(DMA_DONE | DMA_ERR);
350         /*
351          * Now that DMA is done, we would normally flush cache, but
352          * i/d cache isn't running this early, so we don't bother,
353          * and just clear out the DMA channel for next time
354          */
355         bfin_write_MDMA_S0_CONFIG(0);
356         bfin_write_MDMA_S1_CONFIG(0);
357         bfin_write_MDMA_D0_CONFIG(0);
358         bfin_write_MDMA_D1_CONFIG(0);
359
360         __builtin_bfin_ssync();
361 }
362
363 #ifdef CH_MEM_STREAM3_SRC
364 #define bfin_read_MDMA_S_CONFIG bfin_read_MDMA_S3_CONFIG
365 #define bfin_write_MDMA_S_CONFIG bfin_write_MDMA_S3_CONFIG
366 #define bfin_write_MDMA_S_START_ADDR bfin_write_MDMA_S3_START_ADDR
367 #define bfin_write_MDMA_S_IRQ_STATUS bfin_write_MDMA_S3_IRQ_STATUS
368 #define bfin_write_MDMA_S_X_COUNT bfin_write_MDMA_S3_X_COUNT
369 #define bfin_write_MDMA_S_X_MODIFY bfin_write_MDMA_S3_X_MODIFY
370 #define bfin_write_MDMA_S_Y_COUNT bfin_write_MDMA_S3_Y_COUNT
371 #define bfin_write_MDMA_S_Y_MODIFY bfin_write_MDMA_S3_Y_MODIFY
372 #define bfin_write_MDMA_D_CONFIG bfin_write_MDMA_D3_CONFIG
373 #define bfin_write_MDMA_D_START_ADDR bfin_write_MDMA_D3_START_ADDR
374 #define bfin_read_MDMA_D_IRQ_STATUS bfin_read_MDMA_D3_IRQ_STATUS
375 #define bfin_write_MDMA_D_IRQ_STATUS bfin_write_MDMA_D3_IRQ_STATUS
376 #define bfin_write_MDMA_D_X_COUNT bfin_write_MDMA_D3_X_COUNT
377 #define bfin_write_MDMA_D_X_MODIFY bfin_write_MDMA_D3_X_MODIFY
378 #define bfin_write_MDMA_D_Y_COUNT bfin_write_MDMA_D3_Y_COUNT
379 #define bfin_write_MDMA_D_Y_MODIFY bfin_write_MDMA_D3_Y_MODIFY
380 #else
381 #define bfin_read_MDMA_S_CONFIG bfin_read_MDMA_S0_CONFIG
382 #define bfin_write_MDMA_S_CONFIG bfin_write_MDMA_S0_CONFIG
383 #define bfin_write_MDMA_S_START_ADDR bfin_write_MDMA_S0_START_ADDR
384 #define bfin_write_MDMA_S_IRQ_STATUS bfin_write_MDMA_S0_IRQ_STATUS
385 #define bfin_write_MDMA_S_X_COUNT bfin_write_MDMA_S0_X_COUNT
386 #define bfin_write_MDMA_S_X_MODIFY bfin_write_MDMA_S0_X_MODIFY
387 #define bfin_write_MDMA_S_Y_COUNT bfin_write_MDMA_S0_Y_COUNT
388 #define bfin_write_MDMA_S_Y_MODIFY bfin_write_MDMA_S0_Y_MODIFY
389 #define bfin_write_MDMA_D_CONFIG bfin_write_MDMA_D0_CONFIG
390 #define bfin_write_MDMA_D_START_ADDR bfin_write_MDMA_D0_START_ADDR
391 #define bfin_read_MDMA_D_IRQ_STATUS bfin_read_MDMA_D0_IRQ_STATUS
392 #define bfin_write_MDMA_D_IRQ_STATUS bfin_write_MDMA_D0_IRQ_STATUS
393 #define bfin_write_MDMA_D_X_COUNT bfin_write_MDMA_D0_X_COUNT
394 #define bfin_write_MDMA_D_X_MODIFY bfin_write_MDMA_D0_X_MODIFY
395 #define bfin_write_MDMA_D_Y_COUNT bfin_write_MDMA_D0_Y_COUNT
396 #define bfin_write_MDMA_D_Y_MODIFY bfin_write_MDMA_D0_Y_MODIFY
397 #endif
398
399 /**
400  *      __dma_memcpy - program the MDMA registers
401  *
402  * Actually program MDMA0 and wait for the transfer to finish.  Disable IRQs
403  * while programming registers so that everything is fully configured.  Wait
404  * for DMA to finish with IRQs enabled.  If interrupted, the initial DMA_DONE
405  * check will make sure we don't clobber any existing transfer.
406  */
407 static void __dma_memcpy(u32 daddr, s16 dmod, u32 saddr, s16 smod, size_t cnt, u32 conf)
408 {
409         static DEFINE_SPINLOCK(mdma_lock);
410         unsigned long flags;
411
412         spin_lock_irqsave(&mdma_lock, flags);
413
414         /* Force a sync in case a previous config reset on this channel
415          * occurred.  This is needed so subsequent writes to DMA registers
416          * are not spuriously lost/corrupted.  Do it under irq lock and
417          * without the anomaly version (because we are atomic already).
418          */
419         __builtin_bfin_ssync();
420
421         if (bfin_read_MDMA_S_CONFIG())
422                 while (!(bfin_read_MDMA_D_IRQ_STATUS() & DMA_DONE))
423                         continue;
424
425         if (conf & DMA2D) {
426                 /* For larger bit sizes, we've already divided down cnt so it
427                  * is no longer a multiple of 64k.  So we have to break down
428                  * the limit here so it is a multiple of the incoming size.
429                  * There is no limitation here in terms of total size other
430                  * than the hardware though as the bits lost in the shift are
431                  * made up by MODIFY (== we can hit the whole address space).
432                  * X: (2^(16 - 0)) * 1 == (2^(16 - 1)) * 2 == (2^(16 - 2)) * 4
433                  */
434                 u32 shift = abs(dmod) >> 1;
435                 size_t ycnt = cnt >> (16 - shift);
436                 cnt = 1 << (16 - shift);
437                 bfin_write_MDMA_D_Y_COUNT(ycnt);
438                 bfin_write_MDMA_S_Y_COUNT(ycnt);
439                 bfin_write_MDMA_D_Y_MODIFY(dmod);
440                 bfin_write_MDMA_S_Y_MODIFY(smod);
441         }
442
443         bfin_write_MDMA_D_START_ADDR(daddr);
444         bfin_write_MDMA_D_X_COUNT(cnt);
445         bfin_write_MDMA_D_X_MODIFY(dmod);
446         bfin_write_MDMA_D_IRQ_STATUS(DMA_DONE | DMA_ERR);
447
448         bfin_write_MDMA_S_START_ADDR(saddr);
449         bfin_write_MDMA_S_X_COUNT(cnt);
450         bfin_write_MDMA_S_X_MODIFY(smod);
451         bfin_write_MDMA_S_IRQ_STATUS(DMA_DONE | DMA_ERR);
452
453         bfin_write_MDMA_S_CONFIG(DMAEN | conf);
454         if (conf & DMA2D)
455                 bfin_write_MDMA_D_CONFIG(WNR | DI_EN_Y | DMAEN | conf);
456         else
457                 bfin_write_MDMA_D_CONFIG(WNR | DI_EN_X | DMAEN | conf);
458
459         spin_unlock_irqrestore(&mdma_lock, flags);
460
461         SSYNC();
462
463         while (!(bfin_read_MDMA_D_IRQ_STATUS() & DMA_DONE))
464                 if (bfin_read_MDMA_S_CONFIG())
465                         continue;
466                 else
467                         return;
468
469         bfin_write_MDMA_D_IRQ_STATUS(DMA_DONE | DMA_ERR);
470
471         bfin_write_MDMA_S_CONFIG(0);
472         bfin_write_MDMA_D_CONFIG(0);
473 }
474
475 /**
476  *      _dma_memcpy - translate C memcpy settings into MDMA settings
477  *
478  * Handle all the high level steps before we touch the MDMA registers.  So
479  * handle direction, tweaking of sizes, and formatting of addresses.
480  */
481 static void *_dma_memcpy(void *pdst, const void *psrc, size_t size)
482 {
483         u32 conf, shift;
484         s16 mod;
485         unsigned long dst = (unsigned long)pdst;
486         unsigned long src = (unsigned long)psrc;
487
488         if (size == 0)
489                 return NULL;
490
491         if (dst % 4 == 0 && src % 4 == 0 && size % 4 == 0) {
492                 conf = WDSIZE_32;
493                 shift = 2;
494         } else if (dst % 2 == 0 && src % 2 == 0 && size % 2 == 0) {
495                 conf = WDSIZE_16;
496                 shift = 1;
497         } else {
498                 conf = WDSIZE_8;
499                 shift = 0;
500         }
501
502         /* If the two memory regions have a chance of overlapping, make
503          * sure the memcpy still works as expected.  Do this by having the
504          * copy run backwards instead.
505          */
506         mod = 1 << shift;
507         if (src < dst) {
508                 mod *= -1;
509                 dst += size + mod;
510                 src += size + mod;
511         }
512         size >>= shift;
513
514 #ifndef DMA_MMR_SIZE_32
515         if (size > 0x10000)
516                 conf |= DMA2D;
517 #endif
518
519         __dma_memcpy(dst, mod, src, mod, size, conf);
520
521         return pdst;
522 }
523
524 /**
525  *      dma_memcpy - DMA memcpy under mutex lock
526  *
527  * Do not check arguments before starting the DMA memcpy.  Break the transfer
528  * up into two pieces.  The first transfer is in multiples of 64k and the
529  * second transfer is the piece smaller than 64k.
530  */
531 void *dma_memcpy(void *pdst, const void *psrc, size_t size)
532 {
533         unsigned long dst = (unsigned long)pdst;
534         unsigned long src = (unsigned long)psrc;
535
536         if (bfin_addr_dcacheable(src))
537                 blackfin_dcache_flush_range(src, src + size);
538
539         if (bfin_addr_dcacheable(dst))
540                 blackfin_dcache_invalidate_range(dst, dst + size);
541
542         return dma_memcpy_nocache(pdst, psrc, size);
543 }
544 EXPORT_SYMBOL(dma_memcpy);
545
546 /**
547  *      dma_memcpy_nocache - DMA memcpy under mutex lock
548  *      - No cache flush/invalidate
549  *
550  * Do not check arguments before starting the DMA memcpy.  Break the transfer
551  * up into two pieces.  The first transfer is in multiples of 64k and the
552  * second transfer is the piece smaller than 64k.
553  */
554 void *dma_memcpy_nocache(void *pdst, const void *psrc, size_t size)
555 {
556 #ifdef DMA_MMR_SIZE_32
557         _dma_memcpy(pdst, psrc, size);
558 #else
559         size_t bulk, rest;
560
561         bulk = size & ~0xffff;
562         rest = size - bulk;
563         if (bulk)
564                 _dma_memcpy(pdst, psrc, bulk);
565         _dma_memcpy(pdst + bulk, psrc + bulk, rest);
566 #endif
567         return pdst;
568 }
569 EXPORT_SYMBOL(dma_memcpy_nocache);
570
571 /**
572  *      safe_dma_memcpy - DMA memcpy w/argument checking
573  *
574  * Verify arguments are safe before heading to dma_memcpy().
575  */
576 void *safe_dma_memcpy(void *dst, const void *src, size_t size)
577 {
578         if (!access_ok(VERIFY_WRITE, dst, size))
579                 return NULL;
580         if (!access_ok(VERIFY_READ, src, size))
581                 return NULL;
582         return dma_memcpy(dst, src, size);
583 }
584 EXPORT_SYMBOL(safe_dma_memcpy);
585
586 static void _dma_out(unsigned long addr, unsigned long buf, unsigned DMA_MMR_SIZE_TYPE len,
587                      u16 size, u16 dma_size)
588 {
589         blackfin_dcache_flush_range(buf, buf + len * size);
590         __dma_memcpy(addr, 0, buf, size, len, dma_size);
591 }
592
593 static void _dma_in(unsigned long addr, unsigned long buf, unsigned DMA_MMR_SIZE_TYPE len,
594                     u16 size, u16 dma_size)
595 {
596         blackfin_dcache_invalidate_range(buf, buf + len * size);
597         __dma_memcpy(buf, size, addr, 0, len, dma_size);
598 }
599
600 #define MAKE_DMA_IO(io, bwl, isize, dmasize, cnst) \
601 void dma_##io##s##bwl(unsigned long addr, cnst void *buf, unsigned DMA_MMR_SIZE_TYPE len) \
602 { \
603         _dma_##io(addr, (unsigned long)buf, len, isize, WDSIZE_##dmasize); \
604 } \
605 EXPORT_SYMBOL(dma_##io##s##bwl)
606 MAKE_DMA_IO(out, b, 1,  8, const);
607 MAKE_DMA_IO(in,  b, 1,  8, );
608 MAKE_DMA_IO(out, w, 2, 16, const);
609 MAKE_DMA_IO(in,  w, 2, 16, );
610 MAKE_DMA_IO(out, l, 4, 32, const);
611 MAKE_DMA_IO(in,  l, 4, 32, );