Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Mike Frysinger | b03f203 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 2 | * dma.h - Blackfin DMA defines/structures/etc... |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Mike Frysinger | b03f203 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 4 | * Copyright 2004-2008 Analog Devices Inc. |
| 5 | * Licensed under the GPL-2 or later. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _BLACKFIN_DMA_H_ |
| 9 | #define _BLACKFIN_DMA_H_ |
| 10 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 11 | #include <linux/interrupt.h> |
Mike Frysinger | 4c1ed6a | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 12 | #include <mach/dma.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 13 | #include <linux/atomic.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 14 | #include <asm/blackfin.h> |
Mike Frysinger | 4c1ed6a | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 15 | #include <asm/page.h> |
Barry Song | dd3b0e3 | 2009-11-23 03:47:24 +0000 | [diff] [blame] | 16 | #include <asm-generic/dma.h> |
Mike Frysinger | 6c8e75a | 2010-10-25 08:02:30 +0000 | [diff] [blame] | 17 | #include <asm/bfin_dma.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 18 | |
| 19 | /*------------------------- |
| 20 | * config reg bits value |
| 21 | *-------------------------*/ |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 22 | #define DATA_SIZE_8 0 |
| 23 | #define DATA_SIZE_16 1 |
| 24 | #define DATA_SIZE_32 2 |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 25 | #ifdef CONFIG_BF60x |
| 26 | #define DATA_SIZE_64 3 |
| 27 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 28 | |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 29 | #define DMA_FLOW_STOP 0 |
| 30 | #define DMA_FLOW_AUTO 1 |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 31 | #ifdef CONFIG_BF60x |
| 32 | #define DMA_FLOW_LIST 4 |
| 33 | #define DMA_FLOW_ARRAY 5 |
| 34 | #define DMA_FLOW_LIST_DEMAND 6 |
| 35 | #define DMA_FLOW_ARRAY_DEMAND 7 |
| 36 | #else |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 37 | #define DMA_FLOW_ARRAY 4 |
| 38 | #define DMA_FLOW_SMALL 6 |
| 39 | #define DMA_FLOW_LARGE 7 |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 40 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 41 | |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 42 | #define DIMENSION_LINEAR 0 |
| 43 | #define DIMENSION_2D 1 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 44 | |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 45 | #define DIR_READ 0 |
| 46 | #define DIR_WRITE 1 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 47 | |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 48 | #define INTR_DISABLE 0 |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 49 | #ifdef CONFIG_BF60x |
| 50 | #define INTR_ON_PERI 1 |
| 51 | #endif |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 52 | #define INTR_ON_BUF 2 |
| 53 | #define INTR_ON_ROW 3 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 54 | |
Michael Hennerich | 2047e40 | 2008-01-22 15:29:18 +0800 | [diff] [blame] | 55 | #define DMA_NOSYNC_KEEP_DMA_BUF 0 |
Mike Frysinger | 00d2460 | 2009-10-20 17:20:21 +0000 | [diff] [blame] | 56 | #define DMA_SYNC_RESTART 1 |
Michael Hennerich | 2047e40 | 2008-01-22 15:29:18 +0800 | [diff] [blame] | 57 | |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 58 | #ifdef DMA_MMR_SIZE_32 |
| 59 | #define DMA_MMR_SIZE_TYPE long |
| 60 | #define DMA_MMR_READ bfin_read32 |
| 61 | #define DMA_MMR_WRITE bfin_write32 |
| 62 | #else |
| 63 | #define DMA_MMR_SIZE_TYPE short |
| 64 | #define DMA_MMR_READ bfin_read16 |
| 65 | #define DMA_MMR_WRITE bfin_write16 |
| 66 | #endif |
| 67 | |
| 68 | struct dma_desc_array { |
| 69 | unsigned long start_addr; |
| 70 | unsigned DMA_MMR_SIZE_TYPE cfg; |
| 71 | unsigned DMA_MMR_SIZE_TYPE x_count; |
| 72 | DMA_MMR_SIZE_TYPE x_modify; |
| 73 | } __attribute__((packed)); |
| 74 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 75 | struct dmasg { |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 76 | void *next_desc_addr; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 77 | unsigned long start_addr; |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 78 | unsigned DMA_MMR_SIZE_TYPE cfg; |
| 79 | unsigned DMA_MMR_SIZE_TYPE x_count; |
| 80 | DMA_MMR_SIZE_TYPE x_modify; |
| 81 | unsigned DMA_MMR_SIZE_TYPE y_count; |
| 82 | DMA_MMR_SIZE_TYPE y_modify; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 83 | } __attribute__((packed)); |
| 84 | |
| 85 | struct dma_register { |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 86 | void *next_desc_ptr; /* DMA Next Descriptor Pointer register */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 87 | unsigned long start_addr; /* DMA Start address register */ |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 88 | #ifdef CONFIG_BF60x |
| 89 | unsigned long cfg; /* DMA Configuration register */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 90 | |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 91 | unsigned long x_count; /* DMA x_count register */ |
| 92 | |
| 93 | long x_modify; /* DMA x_modify register */ |
| 94 | |
| 95 | unsigned long y_count; /* DMA y_count register */ |
| 96 | |
| 97 | long y_modify; /* DMA y_modify register */ |
| 98 | |
| 99 | unsigned long reserved; |
| 100 | unsigned long reserved2; |
| 101 | |
| 102 | void *curr_desc_ptr; /* DMA Current Descriptor Pointer |
| 103 | register */ |
| 104 | void *prev_desc_ptr; /* DMA previous initial Descriptor Pointer |
| 105 | register */ |
| 106 | unsigned long curr_addr_ptr; /* DMA Current Address Pointer |
| 107 | register */ |
| 108 | unsigned long irq_status; /* DMA irq status register */ |
| 109 | |
| 110 | unsigned long curr_x_count; /* DMA Current x-count register */ |
| 111 | |
| 112 | unsigned long curr_y_count; /* DMA Current y-count register */ |
| 113 | |
| 114 | unsigned long reserved3; |
| 115 | |
| 116 | unsigned long bw_limit_count; /* DMA band width limit count register */ |
| 117 | unsigned long curr_bw_limit_count; /* DMA Current band width limit |
| 118 | count register */ |
| 119 | unsigned long bw_monitor_count; /* DMA band width limit count register */ |
| 120 | unsigned long curr_bw_monitor_count; /* DMA Current band width limit |
| 121 | count register */ |
| 122 | #else |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 123 | unsigned short cfg; /* DMA Configuration register */ |
| 124 | unsigned short dummy1; /* DMA Configuration register */ |
| 125 | |
| 126 | unsigned long reserved; |
| 127 | |
| 128 | unsigned short x_count; /* DMA x_count register */ |
| 129 | unsigned short dummy2; |
| 130 | |
| 131 | short x_modify; /* DMA x_modify register */ |
| 132 | unsigned short dummy3; |
| 133 | |
| 134 | unsigned short y_count; /* DMA y_count register */ |
| 135 | unsigned short dummy4; |
| 136 | |
| 137 | short y_modify; /* DMA y_modify register */ |
| 138 | unsigned short dummy5; |
| 139 | |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 140 | void *curr_desc_ptr; /* DMA Current Descriptor Pointer |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 141 | register */ |
Bryan Wu | 452af71 | 2007-10-22 00:02:14 +0800 | [diff] [blame] | 142 | unsigned long curr_addr_ptr; /* DMA Current Address Pointer |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 143 | register */ |
| 144 | unsigned short irq_status; /* DMA irq status register */ |
| 145 | unsigned short dummy6; |
| 146 | |
| 147 | unsigned short peripheral_map; /* DMA peripheral map register */ |
| 148 | unsigned short dummy7; |
| 149 | |
| 150 | unsigned short curr_x_count; /* DMA Current x-count register */ |
| 151 | unsigned short dummy8; |
| 152 | |
| 153 | unsigned long reserved2; |
| 154 | |
| 155 | unsigned short curr_y_count; /* DMA Current y-count register */ |
| 156 | unsigned short dummy9; |
| 157 | |
| 158 | unsigned long reserved3; |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 159 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 160 | |
| 161 | }; |
| 162 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 163 | struct dma_channel { |
Michael McTernan | 99532fd | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 164 | const char *device_id; |
Mike Frysinger | d2e015d | 2009-10-09 22:18:12 +0000 | [diff] [blame] | 165 | atomic_t chan_status; |
Mike Frysinger | 4ce1873 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 166 | volatile struct dma_register *regs; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 167 | struct dmasg *sg; /* large mode descriptor */ |
Michael Hennerich | a2ba8b1 | 2008-10-28 18:19:29 +0800 | [diff] [blame] | 168 | unsigned int irq; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 169 | void *data; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 170 | #ifdef CONFIG_PM |
| 171 | unsigned short saved_peripheral_map; |
| 172 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 175 | #ifdef CONFIG_PM |
| 176 | int blackfin_dma_suspend(void); |
| 177 | void blackfin_dma_resume(void); |
| 178 | #endif |
| 179 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 180 | /******************************************************************************* |
| 181 | * DMA API's |
| 182 | *******************************************************************************/ |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 183 | extern struct dma_channel dma_ch[MAX_DMA_CHANNELS]; |
Mike Frysinger | 5e3bcf3 | 2010-10-25 18:11:09 +0000 | [diff] [blame] | 184 | extern struct dma_register * const dma_io_base_addr[MAX_DMA_CHANNELS]; |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 185 | extern int channel2irq(unsigned int channel); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 186 | |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 187 | static inline void set_dma_start_addr(unsigned int channel, unsigned long addr) |
| 188 | { |
| 189 | dma_ch[channel].regs->start_addr = addr; |
| 190 | } |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 191 | static inline void set_dma_next_desc_addr(unsigned int channel, void *addr) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 192 | { |
| 193 | dma_ch[channel].regs->next_desc_ptr = addr; |
| 194 | } |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 195 | static inline void set_dma_curr_desc_addr(unsigned int channel, void *addr) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 196 | { |
| 197 | dma_ch[channel].regs->curr_desc_ptr = addr; |
| 198 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 199 | static inline void set_dma_x_count(unsigned int channel, unsigned DMA_MMR_SIZE_TYPE x_count) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 200 | { |
| 201 | dma_ch[channel].regs->x_count = x_count; |
| 202 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 203 | static inline void set_dma_y_count(unsigned int channel, unsigned DMA_MMR_SIZE_TYPE y_count) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 204 | { |
| 205 | dma_ch[channel].regs->y_count = y_count; |
| 206 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 207 | static inline void set_dma_x_modify(unsigned int channel, DMA_MMR_SIZE_TYPE x_modify) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 208 | { |
| 209 | dma_ch[channel].regs->x_modify = x_modify; |
| 210 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 211 | static inline void set_dma_y_modify(unsigned int channel, DMA_MMR_SIZE_TYPE y_modify) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 212 | { |
| 213 | dma_ch[channel].regs->y_modify = y_modify; |
| 214 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 215 | static inline void set_dma_config(unsigned int channel, unsigned DMA_MMR_SIZE_TYPE config) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 216 | { |
| 217 | dma_ch[channel].regs->cfg = config; |
| 218 | } |
| 219 | static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr) |
| 220 | { |
| 221 | dma_ch[channel].regs->curr_addr_ptr = addr; |
| 222 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 223 | |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 224 | #ifdef CONFIG_BF60x |
| 225 | static inline unsigned long |
| 226 | set_bfin_dma_config2(char direction, char flow_mode, char intr_mode, |
| 227 | char dma_mode, char mem_width, char syncmode, char peri_width) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 228 | { |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 229 | unsigned long config = 0; |
| 230 | |
| 231 | switch (intr_mode) { |
| 232 | case INTR_ON_BUF: |
| 233 | if (dma_mode == DIMENSION_2D) |
| 234 | config = DI_EN_Y; |
| 235 | else |
| 236 | config = DI_EN_X; |
| 237 | break; |
| 238 | case INTR_ON_ROW: |
| 239 | config = DI_EN_X; |
| 240 | break; |
| 241 | case INTR_ON_PERI: |
| 242 | config = DI_EN_P; |
| 243 | break; |
| 244 | }; |
| 245 | |
| 246 | return config | (direction << 1) | (mem_width << 8) | (dma_mode << 26) | |
| 247 | (flow_mode << 12) | (syncmode << 2) | (peri_width << 4); |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | static inline unsigned DMA_MMR_SIZE_TYPE |
| 252 | set_bfin_dma_config(char direction, char flow_mode, |
| 253 | char intr_mode, char dma_mode, char mem_width, char syncmode) |
| 254 | { |
| 255 | #ifdef CONFIG_BF60x |
| 256 | return set_bfin_dma_config2(direction, flow_mode, intr_mode, dma_mode, |
| 257 | mem_width, syncmode, mem_width); |
| 258 | #else |
| 259 | return (direction << 1) | (mem_width << 2) | (dma_mode << 4) | |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 260 | (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5); |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 261 | #endif |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 262 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 263 | |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 264 | static inline unsigned DMA_MMR_SIZE_TYPE get_dma_curr_irqstat(unsigned int channel) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 265 | { |
| 266 | return dma_ch[channel].regs->irq_status; |
| 267 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 268 | static inline unsigned DMA_MMR_SIZE_TYPE get_dma_curr_xcount(unsigned int channel) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 269 | { |
| 270 | return dma_ch[channel].regs->curr_x_count; |
| 271 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 272 | static inline unsigned DMA_MMR_SIZE_TYPE get_dma_curr_ycount(unsigned int channel) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 273 | { |
| 274 | return dma_ch[channel].regs->curr_y_count; |
| 275 | } |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 276 | static inline void *get_dma_next_desc_ptr(unsigned int channel) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 277 | { |
| 278 | return dma_ch[channel].regs->next_desc_ptr; |
| 279 | } |
Mike Frysinger | 6ab729d | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 280 | static inline void *get_dma_curr_desc_ptr(unsigned int channel) |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 281 | { |
| 282 | return dma_ch[channel].regs->curr_desc_ptr; |
| 283 | } |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 284 | static inline unsigned DMA_MMR_SIZE_TYPE get_dma_config(unsigned int channel) |
Mike Frysinger | 71f5ca3 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 285 | { |
| 286 | return dma_ch[channel].regs->cfg; |
| 287 | } |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 288 | static inline unsigned long get_dma_curr_addr(unsigned int channel) |
| 289 | { |
| 290 | return dma_ch[channel].regs->curr_addr_ptr; |
| 291 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 292 | |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 293 | static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize) |
| 294 | { |
Sonic Zhang | ea8538a | 2009-06-01 00:49:32 -0400 | [diff] [blame] | 295 | /* Make sure the internal data buffers in the core are drained |
| 296 | * so that the DMA descriptors are completely written when the |
| 297 | * DMA engine goes to fetch them below. |
| 298 | */ |
| 299 | SSYNC(); |
| 300 | |
| 301 | dma_ch[channel].regs->next_desc_ptr = sg; |
Mike Frysinger | d41e800 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 302 | dma_ch[channel].regs->cfg = |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 303 | (dma_ch[channel].regs->cfg & ~NDSIZE) | |
| 304 | ((ndsize << NDSIZE_OFFSET) & NDSIZE); |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static inline int dma_channel_active(unsigned int channel) |
| 308 | { |
Mike Frysinger | d2e015d | 2009-10-09 22:18:12 +0000 | [diff] [blame] | 309 | return atomic_read(&dma_ch[channel].chan_status); |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static inline void disable_dma(unsigned int channel) |
| 313 | { |
| 314 | dma_ch[channel].regs->cfg &= ~DMAEN; |
| 315 | SSYNC(); |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 316 | } |
| 317 | static inline void enable_dma(unsigned int channel) |
| 318 | { |
Steven Miao | ff5ae12 | 2014-05-13 16:49:13 +0800 | [diff] [blame] | 319 | dma_ch[channel].regs->curr_x_count = 0; |
| 320 | dma_ch[channel].regs->curr_y_count = 0; |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 321 | dma_ch[channel].regs->cfg |= DMAEN; |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 322 | } |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 323 | int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data); |
| 324 | |
| 325 | static inline void dma_disable_irq(unsigned int channel) |
| 326 | { |
| 327 | disable_irq(dma_ch[channel].irq); |
| 328 | } |
Barry Song | 4ab069e | 2010-01-22 10:07:30 +0000 | [diff] [blame] | 329 | static inline void dma_disable_irq_nosync(unsigned int channel) |
| 330 | { |
| 331 | disable_irq_nosync(dma_ch[channel].irq); |
| 332 | } |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 333 | static inline void dma_enable_irq(unsigned int channel) |
| 334 | { |
| 335 | enable_irq(dma_ch[channel].irq); |
| 336 | } |
| 337 | static inline void clear_dma_irqstat(unsigned int channel) |
| 338 | { |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 339 | dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR | DMA_PIRQ; |
Mike Frysinger | 9c417a4 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 340 | } |
| 341 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 342 | void *dma_memcpy(void *dest, const void *src, size_t count); |
Michael Hennerich | d1401e1 | 2010-06-16 09:12:10 +0000 | [diff] [blame] | 343 | void *dma_memcpy_nocache(void *dest, const void *src, size_t count); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 344 | void *safe_dma_memcpy(void *dest, const void *src, size_t count); |
Mike Frysinger | dd3dd38 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 345 | void blackfin_dma_early_init(void); |
Robin Getz | fecbd73 | 2009-04-23 20:49:43 +0000 | [diff] [blame] | 346 | void early_dma_memcpy(void *dest, const void *src, size_t count); |
| 347 | void early_dma_memcpy_done(void); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 348 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 349 | #endif |