Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Atmel Corporation |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __ASM_AVR32_DMA_MAPPING_H |
| 7 | #define __ASM_AVR32_DMA_MAPPING_H |
| 8 | |
| 9 | #include <asm/io.h> |
Olav Morken | d8f2aa3 | 2009-01-23 12:56:27 +0100 | [diff] [blame] | 10 | #include <asm/arch/cacheflush.h> |
Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 11 | |
| 12 | enum dma_data_direction { |
| 13 | DMA_BIDIRECTIONAL = 0, |
| 14 | DMA_TO_DEVICE = 1, |
| 15 | DMA_FROM_DEVICE = 2, |
| 16 | }; |
Andreas Bießmann | dbdb5ab | 2015-02-06 23:06:39 +0100 | [diff] [blame] | 17 | |
| 18 | static inline void *dma_alloc_coherent(size_t len, unsigned long *handle) |
| 19 | { |
| 20 | *handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len); |
| 21 | return (void *)*handle; |
| 22 | } |
Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 23 | |
| 24 | static inline unsigned long dma_map_single(volatile void *vaddr, size_t len, |
| 25 | enum dma_data_direction dir) |
| 26 | { |
| 27 | extern void __bad_dma_data_direction(void); |
| 28 | |
| 29 | switch (dir) { |
| 30 | case DMA_BIDIRECTIONAL: |
Andreas Bießmann | 0e05543 | 2014-06-12 22:07:52 +0200 | [diff] [blame] | 31 | flush_dcache_range((unsigned long)vaddr, |
| 32 | (unsigned long)vaddr + len); |
Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 33 | break; |
| 34 | case DMA_TO_DEVICE: |
| 35 | dcache_clean_range(vaddr, len); |
| 36 | break; |
| 37 | case DMA_FROM_DEVICE: |
Andreas Bießmann | 0e05543 | 2014-06-12 22:07:52 +0200 | [diff] [blame] | 38 | invalidate_dcache_range((unsigned long)vaddr, |
| 39 | (unsigned long)vaddr + len); |
Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 40 | break; |
| 41 | default: |
| 42 | /* This will cause a linker error */ |
| 43 | __bad_dma_data_direction(); |
| 44 | } |
| 45 | |
| 46 | return virt_to_phys(vaddr); |
| 47 | } |
| 48 | |
| 49 | static inline void dma_unmap_single(volatile void *vaddr, size_t len, |
| 50 | unsigned long paddr) |
| 51 | { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | #endif /* __ASM_AVR32_DMA_MAPPING_H */ |