Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * OMAP DMAengine support |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 8 | #include <linux/delay.h> |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 9 | #include <linux/dmaengine.h> |
| 10 | #include <linux/dma-mapping.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/omap-dma.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/spinlock.h> |
Jon Hunter | 8d30662 | 2013-02-26 12:27:24 -0600 | [diff] [blame] | 20 | #include <linux/of_dma.h> |
| 21 | #include <linux/of_device.h> |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 22 | |
| 23 | #include "virt-dma.h" |
Tony Lindgren | 7d7e1eb | 2012-08-27 17:43:01 -0700 | [diff] [blame] | 24 | |
Peter Ujfalusi | 341ce71 | 2015-04-09 12:35:50 +0300 | [diff] [blame] | 25 | #define OMAP_SDMA_REQUESTS 127 |
| 26 | #define OMAP_SDMA_CHANNELS 32 |
| 27 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 28 | struct omap_dmadev { |
| 29 | struct dma_device ddev; |
| 30 | spinlock_t lock; |
| 31 | struct tasklet_struct task; |
| 32 | struct list_head pending; |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 33 | void __iomem *base; |
| 34 | const struct omap_dma_reg *reg_map; |
Russell King | 1b416c4 | 2013-11-02 13:00:03 +0000 | [diff] [blame] | 35 | struct omap_system_dma_plat_info *plat; |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 36 | bool legacy; |
Peter Ujfalusi | de50608 | 2015-04-09 12:35:51 +0300 | [diff] [blame] | 37 | unsigned dma_requests; |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 38 | spinlock_t irq_lock; |
| 39 | uint32_t irq_enable_mask; |
Peter Ujfalusi | 341ce71 | 2015-04-09 12:35:50 +0300 | [diff] [blame] | 40 | struct omap_chan *lch_map[OMAP_SDMA_CHANNELS]; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct omap_chan { |
| 44 | struct virt_dma_chan vc; |
| 45 | struct list_head node; |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 46 | void __iomem *channel_base; |
| 47 | const struct omap_dma_reg *reg_map; |
Russell King | aa4c5b9 | 2014-01-14 23:58:10 +0000 | [diff] [blame] | 48 | uint32_t ccr; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 49 | |
| 50 | struct dma_slave_config cfg; |
| 51 | unsigned dma_sig; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 52 | bool cyclic; |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 53 | bool paused; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 54 | |
| 55 | int dma_ch; |
| 56 | struct omap_desc *desc; |
| 57 | unsigned sgidx; |
| 58 | }; |
| 59 | |
| 60 | struct omap_sg { |
| 61 | dma_addr_t addr; |
| 62 | uint32_t en; /* number of elements (24-bit) */ |
| 63 | uint32_t fn; /* number of frames (16-bit) */ |
| 64 | }; |
| 65 | |
| 66 | struct omap_desc { |
| 67 | struct virt_dma_desc vd; |
| 68 | enum dma_transfer_direction dir; |
| 69 | dma_addr_t dev_addr; |
| 70 | |
Russell King | 7c836bc | 2012-06-18 16:45:19 +0100 | [diff] [blame] | 71 | int16_t fi; /* for OMAP_DMA_SYNC_PACKET */ |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 72 | uint8_t es; /* CSDP_DATA_TYPE_xxx */ |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 73 | uint32_t ccr; /* CCR value */ |
Russell King | 965aeb4d | 2013-11-06 17:12:30 +0000 | [diff] [blame] | 74 | uint16_t clnk_ctrl; /* CLNK_CTRL value */ |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 75 | uint16_t cicr; /* CICR value */ |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 76 | uint32_t csdp; /* CSDP value */ |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 77 | |
| 78 | unsigned sglen; |
| 79 | struct omap_sg sg[0]; |
| 80 | }; |
| 81 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 82 | enum { |
| 83 | CCR_FS = BIT(5), |
| 84 | CCR_READ_PRIORITY = BIT(6), |
| 85 | CCR_ENABLE = BIT(7), |
| 86 | CCR_AUTO_INIT = BIT(8), /* OMAP1 only */ |
| 87 | CCR_REPEAT = BIT(9), /* OMAP1 only */ |
| 88 | CCR_OMAP31_DISABLE = BIT(10), /* OMAP1 only */ |
| 89 | CCR_SUSPEND_SENSITIVE = BIT(8), /* OMAP2+ only */ |
| 90 | CCR_RD_ACTIVE = BIT(9), /* OMAP2+ only */ |
| 91 | CCR_WR_ACTIVE = BIT(10), /* OMAP2+ only */ |
| 92 | CCR_SRC_AMODE_CONSTANT = 0 << 12, |
| 93 | CCR_SRC_AMODE_POSTINC = 1 << 12, |
| 94 | CCR_SRC_AMODE_SGLIDX = 2 << 12, |
| 95 | CCR_SRC_AMODE_DBLIDX = 3 << 12, |
| 96 | CCR_DST_AMODE_CONSTANT = 0 << 14, |
| 97 | CCR_DST_AMODE_POSTINC = 1 << 14, |
| 98 | CCR_DST_AMODE_SGLIDX = 2 << 14, |
| 99 | CCR_DST_AMODE_DBLIDX = 3 << 14, |
| 100 | CCR_CONSTANT_FILL = BIT(16), |
| 101 | CCR_TRANSPARENT_COPY = BIT(17), |
| 102 | CCR_BS = BIT(18), |
| 103 | CCR_SUPERVISOR = BIT(22), |
| 104 | CCR_PREFETCH = BIT(23), |
| 105 | CCR_TRIGGER_SRC = BIT(24), |
| 106 | CCR_BUFFERING_DISABLE = BIT(25), |
| 107 | CCR_WRITE_PRIORITY = BIT(26), |
| 108 | CCR_SYNC_ELEMENT = 0, |
| 109 | CCR_SYNC_FRAME = CCR_FS, |
| 110 | CCR_SYNC_BLOCK = CCR_BS, |
| 111 | CCR_SYNC_PACKET = CCR_BS | CCR_FS, |
| 112 | |
| 113 | CSDP_DATA_TYPE_8 = 0, |
| 114 | CSDP_DATA_TYPE_16 = 1, |
| 115 | CSDP_DATA_TYPE_32 = 2, |
| 116 | CSDP_SRC_PORT_EMIFF = 0 << 2, /* OMAP1 only */ |
| 117 | CSDP_SRC_PORT_EMIFS = 1 << 2, /* OMAP1 only */ |
| 118 | CSDP_SRC_PORT_OCP_T1 = 2 << 2, /* OMAP1 only */ |
| 119 | CSDP_SRC_PORT_TIPB = 3 << 2, /* OMAP1 only */ |
| 120 | CSDP_SRC_PORT_OCP_T2 = 4 << 2, /* OMAP1 only */ |
| 121 | CSDP_SRC_PORT_MPUI = 5 << 2, /* OMAP1 only */ |
| 122 | CSDP_SRC_PACKED = BIT(6), |
| 123 | CSDP_SRC_BURST_1 = 0 << 7, |
| 124 | CSDP_SRC_BURST_16 = 1 << 7, |
| 125 | CSDP_SRC_BURST_32 = 2 << 7, |
| 126 | CSDP_SRC_BURST_64 = 3 << 7, |
| 127 | CSDP_DST_PORT_EMIFF = 0 << 9, /* OMAP1 only */ |
| 128 | CSDP_DST_PORT_EMIFS = 1 << 9, /* OMAP1 only */ |
| 129 | CSDP_DST_PORT_OCP_T1 = 2 << 9, /* OMAP1 only */ |
| 130 | CSDP_DST_PORT_TIPB = 3 << 9, /* OMAP1 only */ |
| 131 | CSDP_DST_PORT_OCP_T2 = 4 << 9, /* OMAP1 only */ |
| 132 | CSDP_DST_PORT_MPUI = 5 << 9, /* OMAP1 only */ |
| 133 | CSDP_DST_PACKED = BIT(13), |
| 134 | CSDP_DST_BURST_1 = 0 << 14, |
| 135 | CSDP_DST_BURST_16 = 1 << 14, |
| 136 | CSDP_DST_BURST_32 = 2 << 14, |
| 137 | CSDP_DST_BURST_64 = 3 << 14, |
| 138 | |
| 139 | CICR_TOUT_IE = BIT(0), /* OMAP1 only */ |
| 140 | CICR_DROP_IE = BIT(1), |
| 141 | CICR_HALF_IE = BIT(2), |
| 142 | CICR_FRAME_IE = BIT(3), |
| 143 | CICR_LAST_IE = BIT(4), |
| 144 | CICR_BLOCK_IE = BIT(5), |
| 145 | CICR_PKT_IE = BIT(7), /* OMAP2+ only */ |
| 146 | CICR_TRANS_ERR_IE = BIT(8), /* OMAP2+ only */ |
| 147 | CICR_SUPERVISOR_ERR_IE = BIT(10), /* OMAP2+ only */ |
| 148 | CICR_MISALIGNED_ERR_IE = BIT(11), /* OMAP2+ only */ |
| 149 | CICR_DRAIN_IE = BIT(12), /* OMAP2+ only */ |
| 150 | CICR_SUPER_BLOCK_IE = BIT(14), /* OMAP2+ only */ |
| 151 | |
| 152 | CLNK_CTRL_ENABLE_LNK = BIT(15), |
| 153 | }; |
| 154 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 155 | static const unsigned es_bytes[] = { |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 156 | [CSDP_DATA_TYPE_8] = 1, |
| 157 | [CSDP_DATA_TYPE_16] = 2, |
| 158 | [CSDP_DATA_TYPE_32] = 4, |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Jon Hunter | 8d30662 | 2013-02-26 12:27:24 -0600 | [diff] [blame] | 161 | static struct of_dma_filter_info omap_dma_info = { |
| 162 | .filter_fn = omap_dma_filter_fn, |
| 163 | }; |
| 164 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 165 | static inline struct omap_dmadev *to_omap_dma_dev(struct dma_device *d) |
| 166 | { |
| 167 | return container_of(d, struct omap_dmadev, ddev); |
| 168 | } |
| 169 | |
| 170 | static inline struct omap_chan *to_omap_dma_chan(struct dma_chan *c) |
| 171 | { |
| 172 | return container_of(c, struct omap_chan, vc.chan); |
| 173 | } |
| 174 | |
| 175 | static inline struct omap_desc *to_omap_dma_desc(struct dma_async_tx_descriptor *t) |
| 176 | { |
| 177 | return container_of(t, struct omap_desc, vd.tx); |
| 178 | } |
| 179 | |
| 180 | static void omap_dma_desc_free(struct virt_dma_desc *vd) |
| 181 | { |
| 182 | kfree(container_of(vd, struct omap_desc, vd)); |
| 183 | } |
| 184 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 185 | static void omap_dma_write(uint32_t val, unsigned type, void __iomem *addr) |
| 186 | { |
| 187 | switch (type) { |
| 188 | case OMAP_DMA_REG_16BIT: |
| 189 | writew_relaxed(val, addr); |
| 190 | break; |
| 191 | case OMAP_DMA_REG_2X16BIT: |
| 192 | writew_relaxed(val, addr); |
| 193 | writew_relaxed(val >> 16, addr + 2); |
| 194 | break; |
| 195 | case OMAP_DMA_REG_32BIT: |
| 196 | writel_relaxed(val, addr); |
| 197 | break; |
| 198 | default: |
| 199 | WARN_ON(1); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | static unsigned omap_dma_read(unsigned type, void __iomem *addr) |
| 204 | { |
| 205 | unsigned val; |
| 206 | |
| 207 | switch (type) { |
| 208 | case OMAP_DMA_REG_16BIT: |
| 209 | val = readw_relaxed(addr); |
| 210 | break; |
| 211 | case OMAP_DMA_REG_2X16BIT: |
| 212 | val = readw_relaxed(addr); |
| 213 | val |= readw_relaxed(addr + 2) << 16; |
| 214 | break; |
| 215 | case OMAP_DMA_REG_32BIT: |
| 216 | val = readl_relaxed(addr); |
| 217 | break; |
| 218 | default: |
| 219 | WARN_ON(1); |
| 220 | val = 0; |
| 221 | } |
| 222 | |
| 223 | return val; |
| 224 | } |
| 225 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 226 | static void omap_dma_glbl_write(struct omap_dmadev *od, unsigned reg, unsigned val) |
| 227 | { |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 228 | const struct omap_dma_reg *r = od->reg_map + reg; |
| 229 | |
| 230 | WARN_ON(r->stride); |
| 231 | |
| 232 | omap_dma_write(val, r->type, od->base + r->offset); |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static unsigned omap_dma_glbl_read(struct omap_dmadev *od, unsigned reg) |
| 236 | { |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 237 | const struct omap_dma_reg *r = od->reg_map + reg; |
| 238 | |
| 239 | WARN_ON(r->stride); |
| 240 | |
| 241 | return omap_dma_read(r->type, od->base + r->offset); |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static void omap_dma_chan_write(struct omap_chan *c, unsigned reg, unsigned val) |
| 245 | { |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 246 | const struct omap_dma_reg *r = c->reg_map + reg; |
| 247 | |
| 248 | omap_dma_write(val, r->type, c->channel_base + r->offset); |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static unsigned omap_dma_chan_read(struct omap_chan *c, unsigned reg) |
| 252 | { |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 253 | const struct omap_dma_reg *r = c->reg_map + reg; |
| 254 | |
| 255 | return omap_dma_read(r->type, c->channel_base + r->offset); |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Russell King | 470b23f | 2013-11-02 21:23:06 +0000 | [diff] [blame] | 258 | static void omap_dma_clear_csr(struct omap_chan *c) |
| 259 | { |
| 260 | if (dma_omap1()) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 261 | omap_dma_chan_read(c, CSR); |
Russell King | 470b23f | 2013-11-02 21:23:06 +0000 | [diff] [blame] | 262 | else |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 263 | omap_dma_chan_write(c, CSR, ~0); |
Russell King | 470b23f | 2013-11-02 21:23:06 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 266 | static unsigned omap_dma_get_csr(struct omap_chan *c) |
| 267 | { |
| 268 | unsigned val = omap_dma_chan_read(c, CSR); |
| 269 | |
| 270 | if (!dma_omap1()) |
| 271 | omap_dma_chan_write(c, CSR, val); |
| 272 | |
| 273 | return val; |
| 274 | } |
| 275 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 276 | static void omap_dma_assign(struct omap_dmadev *od, struct omap_chan *c, |
| 277 | unsigned lch) |
| 278 | { |
| 279 | c->channel_base = od->base + od->plat->channel_stride * lch; |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 280 | |
| 281 | od->lch_map[lch] = c; |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 284 | static void omap_dma_start(struct omap_chan *c, struct omap_desc *d) |
| 285 | { |
| 286 | struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 287 | |
| 288 | if (__dma_omap15xx(od->plat->dma_attr)) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 289 | omap_dma_chan_write(c, CPC, 0); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 290 | else |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 291 | omap_dma_chan_write(c, CDAC, 0); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 292 | |
Russell King | 470b23f | 2013-11-02 21:23:06 +0000 | [diff] [blame] | 293 | omap_dma_clear_csr(c); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 294 | |
| 295 | /* Enable interrupts */ |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 296 | omap_dma_chan_write(c, CICR, d->cicr); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 297 | |
Russell King | 45da7b0 | 2013-11-06 17:18:42 +0000 | [diff] [blame] | 298 | /* Enable channel */ |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 299 | omap_dma_chan_write(c, CCR, d->ccr | CCR_ENABLE); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static void omap_dma_stop(struct omap_chan *c) |
| 303 | { |
| 304 | struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); |
| 305 | uint32_t val; |
| 306 | |
| 307 | /* disable irq */ |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 308 | omap_dma_chan_write(c, CICR, 0); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 309 | |
Russell King | 470b23f | 2013-11-02 21:23:06 +0000 | [diff] [blame] | 310 | omap_dma_clear_csr(c); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 311 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 312 | val = omap_dma_chan_read(c, CCR); |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 313 | if (od->plat->errata & DMA_ERRATA_i541 && val & CCR_TRIGGER_SRC) { |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 314 | uint32_t sysconfig; |
| 315 | unsigned i; |
| 316 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 317 | sysconfig = omap_dma_glbl_read(od, OCP_SYSCONFIG); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 318 | val = sysconfig & ~DMA_SYSCONFIG_MIDLEMODE_MASK; |
| 319 | val |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE); |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 320 | omap_dma_glbl_write(od, OCP_SYSCONFIG, val); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 321 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 322 | val = omap_dma_chan_read(c, CCR); |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 323 | val &= ~CCR_ENABLE; |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 324 | omap_dma_chan_write(c, CCR, val); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 325 | |
| 326 | /* Wait for sDMA FIFO to drain */ |
| 327 | for (i = 0; ; i++) { |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 328 | val = omap_dma_chan_read(c, CCR); |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 329 | if (!(val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE))) |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 330 | break; |
| 331 | |
| 332 | if (i > 100) |
| 333 | break; |
| 334 | |
| 335 | udelay(5); |
| 336 | } |
| 337 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 338 | if (val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE)) |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 339 | dev_err(c->vc.chan.device->dev, |
| 340 | "DMA drain did not complete on lch %d\n", |
| 341 | c->dma_ch); |
| 342 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 343 | omap_dma_glbl_write(od, OCP_SYSCONFIG, sysconfig); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 344 | } else { |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 345 | val &= ~CCR_ENABLE; |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 346 | omap_dma_chan_write(c, CCR, val); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | mb(); |
| 350 | |
| 351 | if (!__dma_omap15xx(od->plat->dma_attr) && c->cyclic) { |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 352 | val = omap_dma_chan_read(c, CLNK_CTRL); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 353 | |
| 354 | if (dma_omap1()) |
| 355 | val |= 1 << 14; /* set the STOP_LNK bit */ |
| 356 | else |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 357 | val &= ~CLNK_CTRL_ENABLE_LNK; |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 358 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 359 | omap_dma_chan_write(c, CLNK_CTRL, val); |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 363 | static void omap_dma_start_sg(struct omap_chan *c, struct omap_desc *d, |
| 364 | unsigned idx) |
| 365 | { |
| 366 | struct omap_sg *sg = d->sg + idx; |
Russell King | 893e63e | 2013-11-03 11:17:11 +0000 | [diff] [blame] | 367 | unsigned cxsa, cxei, cxfi; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 368 | |
Peter Ujfalusi | 4ce98c0 | 2015-04-22 10:34:29 +0300 | [diff] [blame] | 369 | if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM) { |
Russell King | 893e63e | 2013-11-03 11:17:11 +0000 | [diff] [blame] | 370 | cxsa = CDSA; |
| 371 | cxei = CDEI; |
| 372 | cxfi = CDFI; |
Russell King | b9e9782 | 2013-11-02 13:26:57 +0000 | [diff] [blame] | 373 | } else { |
Russell King | 893e63e | 2013-11-03 11:17:11 +0000 | [diff] [blame] | 374 | cxsa = CSSA; |
| 375 | cxei = CSEI; |
| 376 | cxfi = CSFI; |
Russell King | b9e9782 | 2013-11-02 13:26:57 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 379 | omap_dma_chan_write(c, cxsa, sg->addr); |
| 380 | omap_dma_chan_write(c, cxei, 0); |
| 381 | omap_dma_chan_write(c, cxfi, 0); |
| 382 | omap_dma_chan_write(c, CEN, sg->en); |
| 383 | omap_dma_chan_write(c, CFN, sg->fn); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 384 | |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 385 | omap_dma_start(c, d); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static void omap_dma_start_desc(struct omap_chan *c) |
| 389 | { |
| 390 | struct virt_dma_desc *vd = vchan_next_desc(&c->vc); |
| 391 | struct omap_desc *d; |
Russell King | 893e63e | 2013-11-03 11:17:11 +0000 | [diff] [blame] | 392 | unsigned cxsa, cxei, cxfi; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 393 | |
| 394 | if (!vd) { |
| 395 | c->desc = NULL; |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | list_del(&vd->node); |
| 400 | |
| 401 | c->desc = d = to_omap_dma_desc(&vd->tx); |
| 402 | c->sgidx = 0; |
| 403 | |
Russell King | 5987190 | 2013-11-06 17:15:16 +0000 | [diff] [blame] | 404 | /* |
| 405 | * This provides the necessary barrier to ensure data held in |
| 406 | * DMA coherent memory is visible to the DMA engine prior to |
| 407 | * the transfer starting. |
| 408 | */ |
| 409 | mb(); |
| 410 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 411 | omap_dma_chan_write(c, CCR, d->ccr); |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 412 | if (dma_omap1()) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 413 | omap_dma_chan_write(c, CCR2, d->ccr >> 16); |
Russell King | b9e9782 | 2013-11-02 13:26:57 +0000 | [diff] [blame] | 414 | |
Peter Ujfalusi | 4ce98c0 | 2015-04-22 10:34:29 +0300 | [diff] [blame] | 415 | if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM) { |
Russell King | 893e63e | 2013-11-03 11:17:11 +0000 | [diff] [blame] | 416 | cxsa = CSSA; |
| 417 | cxei = CSEI; |
| 418 | cxfi = CSFI; |
Russell King | b9e9782 | 2013-11-02 13:26:57 +0000 | [diff] [blame] | 419 | } else { |
Russell King | 893e63e | 2013-11-03 11:17:11 +0000 | [diff] [blame] | 420 | cxsa = CDSA; |
| 421 | cxei = CDEI; |
| 422 | cxfi = CDFI; |
Russell King | b9e9782 | 2013-11-02 13:26:57 +0000 | [diff] [blame] | 423 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 424 | |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 425 | omap_dma_chan_write(c, cxsa, d->dev_addr); |
| 426 | omap_dma_chan_write(c, cxei, 0); |
| 427 | omap_dma_chan_write(c, cxfi, d->fi); |
| 428 | omap_dma_chan_write(c, CSDP, d->csdp); |
| 429 | omap_dma_chan_write(c, CLNK_CTRL, d->clnk_ctrl); |
Russell King | 913a2d0 | 2013-11-02 14:41:42 +0000 | [diff] [blame] | 430 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 431 | omap_dma_start_sg(c, d, 0); |
| 432 | } |
| 433 | |
| 434 | static void omap_dma_callback(int ch, u16 status, void *data) |
| 435 | { |
| 436 | struct omap_chan *c = data; |
| 437 | struct omap_desc *d; |
| 438 | unsigned long flags; |
| 439 | |
| 440 | spin_lock_irqsave(&c->vc.lock, flags); |
| 441 | d = c->desc; |
| 442 | if (d) { |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 443 | if (!c->cyclic) { |
| 444 | if (++c->sgidx < d->sglen) { |
| 445 | omap_dma_start_sg(c, d, c->sgidx); |
| 446 | } else { |
| 447 | omap_dma_start_desc(c); |
| 448 | vchan_cookie_complete(&d->vd); |
| 449 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 450 | } else { |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 451 | vchan_cyclic_callback(&d->vd); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | spin_unlock_irqrestore(&c->vc.lock, flags); |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * This callback schedules all pending channels. We could be more |
| 459 | * clever here by postponing allocation of the real DMA channels to |
| 460 | * this point, and freeing them when our virtual channel becomes idle. |
| 461 | * |
| 462 | * We would then need to deal with 'all channels in-use' |
| 463 | */ |
| 464 | static void omap_dma_sched(unsigned long data) |
| 465 | { |
| 466 | struct omap_dmadev *d = (struct omap_dmadev *)data; |
| 467 | LIST_HEAD(head); |
| 468 | |
| 469 | spin_lock_irq(&d->lock); |
| 470 | list_splice_tail_init(&d->pending, &head); |
| 471 | spin_unlock_irq(&d->lock); |
| 472 | |
| 473 | while (!list_empty(&head)) { |
| 474 | struct omap_chan *c = list_first_entry(&head, |
| 475 | struct omap_chan, node); |
| 476 | |
| 477 | spin_lock_irq(&c->vc.lock); |
| 478 | list_del_init(&c->node); |
| 479 | omap_dma_start_desc(c); |
| 480 | spin_unlock_irq(&c->vc.lock); |
| 481 | } |
| 482 | } |
| 483 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 484 | static irqreturn_t omap_dma_irq(int irq, void *devid) |
| 485 | { |
| 486 | struct omap_dmadev *od = devid; |
| 487 | unsigned status, channel; |
| 488 | |
| 489 | spin_lock(&od->irq_lock); |
| 490 | |
| 491 | status = omap_dma_glbl_read(od, IRQSTATUS_L1); |
| 492 | status &= od->irq_enable_mask; |
| 493 | if (status == 0) { |
| 494 | spin_unlock(&od->irq_lock); |
| 495 | return IRQ_NONE; |
| 496 | } |
| 497 | |
| 498 | while ((channel = ffs(status)) != 0) { |
| 499 | unsigned mask, csr; |
| 500 | struct omap_chan *c; |
| 501 | |
| 502 | channel -= 1; |
| 503 | mask = BIT(channel); |
| 504 | status &= ~mask; |
| 505 | |
| 506 | c = od->lch_map[channel]; |
| 507 | if (c == NULL) { |
| 508 | /* This should never happen */ |
| 509 | dev_err(od->ddev.dev, "invalid channel %u\n", channel); |
| 510 | continue; |
| 511 | } |
| 512 | |
| 513 | csr = omap_dma_get_csr(c); |
| 514 | omap_dma_glbl_write(od, IRQSTATUS_L1, mask); |
| 515 | |
| 516 | omap_dma_callback(channel, csr, c); |
| 517 | } |
| 518 | |
| 519 | spin_unlock(&od->irq_lock); |
| 520 | |
| 521 | return IRQ_HANDLED; |
| 522 | } |
| 523 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 524 | static int omap_dma_alloc_chan_resources(struct dma_chan *chan) |
| 525 | { |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 526 | struct omap_dmadev *od = to_omap_dma_dev(chan->device); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 527 | struct omap_chan *c = to_omap_dma_chan(chan); |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 528 | int ret; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 529 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 530 | if (od->legacy) { |
| 531 | ret = omap_request_dma(c->dma_sig, "DMA engine", |
| 532 | omap_dma_callback, c, &c->dma_ch); |
| 533 | } else { |
| 534 | ret = omap_request_dma(c->dma_sig, "DMA engine", NULL, NULL, |
| 535 | &c->dma_ch); |
| 536 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 537 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 538 | dev_dbg(od->ddev.dev, "allocating channel %u for %u\n", |
| 539 | c->dma_ch, c->dma_sig); |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 540 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 541 | if (ret >= 0) { |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 542 | omap_dma_assign(od, c, c->dma_ch); |
| 543 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 544 | if (!od->legacy) { |
| 545 | unsigned val; |
| 546 | |
| 547 | spin_lock_irq(&od->irq_lock); |
| 548 | val = BIT(c->dma_ch); |
| 549 | omap_dma_glbl_write(od, IRQSTATUS_L1, val); |
| 550 | od->irq_enable_mask |= val; |
| 551 | omap_dma_glbl_write(od, IRQENABLE_L1, od->irq_enable_mask); |
| 552 | |
| 553 | val = omap_dma_glbl_read(od, IRQENABLE_L0); |
| 554 | val &= ~BIT(c->dma_ch); |
| 555 | omap_dma_glbl_write(od, IRQENABLE_L0, val); |
| 556 | spin_unlock_irq(&od->irq_lock); |
| 557 | } |
| 558 | } |
| 559 | |
Russell King | aa4c5b9 | 2014-01-14 23:58:10 +0000 | [diff] [blame] | 560 | if (dma_omap1()) { |
| 561 | if (__dma_omap16xx(od->plat->dma_attr)) { |
| 562 | c->ccr = CCR_OMAP31_DISABLE; |
| 563 | /* Duplicate what plat-omap/dma.c does */ |
| 564 | c->ccr |= c->dma_ch + 1; |
| 565 | } else { |
| 566 | c->ccr = c->dma_sig & 0x1f; |
| 567 | } |
| 568 | } else { |
| 569 | c->ccr = c->dma_sig & 0x1f; |
| 570 | c->ccr |= (c->dma_sig & ~0x1f) << 14; |
| 571 | } |
| 572 | if (od->plat->errata & DMA_ERRATA_IFRAME_BUFFERING) |
| 573 | c->ccr |= CCR_BUFFERING_DISABLE; |
| 574 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 575 | return ret; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static void omap_dma_free_chan_resources(struct dma_chan *chan) |
| 579 | { |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 580 | struct omap_dmadev *od = to_omap_dma_dev(chan->device); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 581 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 582 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 583 | if (!od->legacy) { |
| 584 | spin_lock_irq(&od->irq_lock); |
| 585 | od->irq_enable_mask &= ~BIT(c->dma_ch); |
| 586 | omap_dma_glbl_write(od, IRQENABLE_L1, od->irq_enable_mask); |
| 587 | spin_unlock_irq(&od->irq_lock); |
| 588 | } |
| 589 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 590 | c->channel_base = NULL; |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 591 | od->lch_map[c->dma_ch] = NULL; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 592 | vchan_free_chan_resources(&c->vc); |
| 593 | omap_free_dma(c->dma_ch); |
| 594 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 595 | dev_dbg(od->ddev.dev, "freeing channel for %u\n", c->dma_sig); |
Peter Ujfalusi | eea531e | 2015-04-09 12:35:52 +0300 | [diff] [blame] | 596 | c->dma_sig = 0; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 597 | } |
| 598 | |
Russell King | 3850e22 | 2012-06-21 10:37:35 +0100 | [diff] [blame] | 599 | static size_t omap_dma_sg_size(struct omap_sg *sg) |
| 600 | { |
| 601 | return sg->en * sg->fn; |
| 602 | } |
| 603 | |
| 604 | static size_t omap_dma_desc_size(struct omap_desc *d) |
| 605 | { |
| 606 | unsigned i; |
| 607 | size_t size; |
| 608 | |
| 609 | for (size = i = 0; i < d->sglen; i++) |
| 610 | size += omap_dma_sg_size(&d->sg[i]); |
| 611 | |
| 612 | return size * es_bytes[d->es]; |
| 613 | } |
| 614 | |
| 615 | static size_t omap_dma_desc_size_pos(struct omap_desc *d, dma_addr_t addr) |
| 616 | { |
| 617 | unsigned i; |
| 618 | size_t size, es_size = es_bytes[d->es]; |
| 619 | |
| 620 | for (size = i = 0; i < d->sglen; i++) { |
| 621 | size_t this_size = omap_dma_sg_size(&d->sg[i]) * es_size; |
| 622 | |
| 623 | if (size) |
| 624 | size += this_size; |
| 625 | else if (addr >= d->sg[i].addr && |
| 626 | addr < d->sg[i].addr + this_size) |
| 627 | size += d->sg[i].addr + this_size - addr; |
| 628 | } |
| 629 | return size; |
| 630 | } |
| 631 | |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 632 | /* |
| 633 | * OMAP 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is |
| 634 | * read before the DMA controller finished disabling the channel. |
| 635 | */ |
| 636 | static uint32_t omap_dma_chan_read_3_3(struct omap_chan *c, unsigned reg) |
| 637 | { |
| 638 | struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); |
| 639 | uint32_t val; |
| 640 | |
| 641 | val = omap_dma_chan_read(c, reg); |
| 642 | if (val == 0 && od->plat->errata & DMA_ERRATA_3_3) |
| 643 | val = omap_dma_chan_read(c, reg); |
| 644 | |
| 645 | return val; |
| 646 | } |
| 647 | |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 648 | static dma_addr_t omap_dma_get_src_pos(struct omap_chan *c) |
| 649 | { |
| 650 | struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 651 | dma_addr_t addr, cdac; |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 652 | |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 653 | if (__dma_omap15xx(od->plat->dma_attr)) { |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 654 | addr = omap_dma_chan_read(c, CPC); |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 655 | } else { |
| 656 | addr = omap_dma_chan_read_3_3(c, CSAC); |
| 657 | cdac = omap_dma_chan_read_3_3(c, CDAC); |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 658 | |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 659 | /* |
| 660 | * CDAC == 0 indicates that the DMA transfer on the channel has |
| 661 | * not been started (no data has been transferred so far). |
| 662 | * Return the programmed source start address in this case. |
| 663 | */ |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 664 | if (cdac == 0) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 665 | addr = omap_dma_chan_read(c, CSSA); |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | if (dma_omap1()) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 669 | addr |= omap_dma_chan_read(c, CSSA) & 0xffff0000; |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 670 | |
| 671 | return addr; |
| 672 | } |
| 673 | |
| 674 | static dma_addr_t omap_dma_get_dst_pos(struct omap_chan *c) |
| 675 | { |
| 676 | struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); |
| 677 | dma_addr_t addr; |
| 678 | |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 679 | if (__dma_omap15xx(od->plat->dma_attr)) { |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 680 | addr = omap_dma_chan_read(c, CPC); |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 681 | } else { |
| 682 | addr = omap_dma_chan_read_3_3(c, CDAC); |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 683 | |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 684 | /* |
Russell King | b07fd62 | 2013-11-06 19:26:45 +0000 | [diff] [blame] | 685 | * CDAC == 0 indicates that the DMA transfer on the channel |
| 686 | * has not been started (no data has been transferred so |
| 687 | * far). Return the programmed destination start address in |
| 688 | * this case. |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 689 | */ |
| 690 | if (addr == 0) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 691 | addr = omap_dma_chan_read(c, CDSA); |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | if (dma_omap1()) |
Russell King | c5ed98b | 2013-11-06 17:33:09 +0000 | [diff] [blame] | 695 | addr |= omap_dma_chan_read(c, CDSA) & 0xffff0000; |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 696 | |
| 697 | return addr; |
| 698 | } |
| 699 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 700 | static enum dma_status omap_dma_tx_status(struct dma_chan *chan, |
| 701 | dma_cookie_t cookie, struct dma_tx_state *txstate) |
| 702 | { |
Russell King | 3850e22 | 2012-06-21 10:37:35 +0100 | [diff] [blame] | 703 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 704 | struct virt_dma_desc *vd; |
| 705 | enum dma_status ret; |
| 706 | unsigned long flags; |
| 707 | |
| 708 | ret = dma_cookie_status(chan, cookie, txstate); |
Vinod Koul | 7cce508 | 2013-10-16 20:51:54 +0530 | [diff] [blame] | 709 | if (ret == DMA_COMPLETE || !txstate) |
Russell King | 3850e22 | 2012-06-21 10:37:35 +0100 | [diff] [blame] | 710 | return ret; |
| 711 | |
| 712 | spin_lock_irqsave(&c->vc.lock, flags); |
| 713 | vd = vchan_find_desc(&c->vc, cookie); |
| 714 | if (vd) { |
| 715 | txstate->residue = omap_dma_desc_size(to_omap_dma_desc(&vd->tx)); |
| 716 | } else if (c->desc && c->desc->vd.tx.cookie == cookie) { |
| 717 | struct omap_desc *d = c->desc; |
| 718 | dma_addr_t pos; |
| 719 | |
| 720 | if (d->dir == DMA_MEM_TO_DEV) |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 721 | pos = omap_dma_get_src_pos(c); |
Russell King | 3850e22 | 2012-06-21 10:37:35 +0100 | [diff] [blame] | 722 | else if (d->dir == DMA_DEV_TO_MEM) |
Russell King | 3997cab | 2013-11-02 18:04:17 +0000 | [diff] [blame] | 723 | pos = omap_dma_get_dst_pos(c); |
Russell King | 3850e22 | 2012-06-21 10:37:35 +0100 | [diff] [blame] | 724 | else |
| 725 | pos = 0; |
| 726 | |
| 727 | txstate->residue = omap_dma_desc_size_pos(d, pos); |
| 728 | } else { |
| 729 | txstate->residue = 0; |
| 730 | } |
| 731 | spin_unlock_irqrestore(&c->vc.lock, flags); |
| 732 | |
| 733 | return ret; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | static void omap_dma_issue_pending(struct dma_chan *chan) |
| 737 | { |
| 738 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 739 | unsigned long flags; |
| 740 | |
| 741 | spin_lock_irqsave(&c->vc.lock, flags); |
| 742 | if (vchan_issue_pending(&c->vc) && !c->desc) { |
Peter Ujfalusi | 7650246 | 2013-04-09 16:33:06 +0200 | [diff] [blame] | 743 | /* |
| 744 | * c->cyclic is used only by audio and in this case the DMA need |
| 745 | * to be started without delay. |
| 746 | */ |
| 747 | if (!c->cyclic) { |
| 748 | struct omap_dmadev *d = to_omap_dma_dev(chan->device); |
| 749 | spin_lock(&d->lock); |
| 750 | if (list_empty(&c->node)) |
| 751 | list_add_tail(&c->node, &d->pending); |
| 752 | spin_unlock(&d->lock); |
| 753 | tasklet_schedule(&d->task); |
| 754 | } else { |
| 755 | omap_dma_start_desc(c); |
| 756 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 757 | } |
| 758 | spin_unlock_irqrestore(&c->vc.lock, flags); |
| 759 | } |
| 760 | |
| 761 | static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg( |
| 762 | struct dma_chan *chan, struct scatterlist *sgl, unsigned sglen, |
| 763 | enum dma_transfer_direction dir, unsigned long tx_flags, void *context) |
| 764 | { |
Russell King | 49ae0b2 | 2013-11-02 21:09:18 +0000 | [diff] [blame] | 765 | struct omap_dmadev *od = to_omap_dma_dev(chan->device); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 766 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 767 | enum dma_slave_buswidth dev_width; |
| 768 | struct scatterlist *sgent; |
| 769 | struct omap_desc *d; |
| 770 | dma_addr_t dev_addr; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 771 | unsigned i, j = 0, es, en, frame_bytes; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 772 | u32 burst; |
| 773 | |
| 774 | if (dir == DMA_DEV_TO_MEM) { |
| 775 | dev_addr = c->cfg.src_addr; |
| 776 | dev_width = c->cfg.src_addr_width; |
| 777 | burst = c->cfg.src_maxburst; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 778 | } else if (dir == DMA_MEM_TO_DEV) { |
| 779 | dev_addr = c->cfg.dst_addr; |
| 780 | dev_width = c->cfg.dst_addr_width; |
| 781 | burst = c->cfg.dst_maxburst; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 782 | } else { |
| 783 | dev_err(chan->device->dev, "%s: bad direction?\n", __func__); |
| 784 | return NULL; |
| 785 | } |
| 786 | |
| 787 | /* Bus width translates to the element size (ES) */ |
| 788 | switch (dev_width) { |
| 789 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 790 | es = CSDP_DATA_TYPE_8; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 791 | break; |
| 792 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 793 | es = CSDP_DATA_TYPE_16; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 794 | break; |
| 795 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 796 | es = CSDP_DATA_TYPE_32; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 797 | break; |
| 798 | default: /* not reached */ |
| 799 | return NULL; |
| 800 | } |
| 801 | |
| 802 | /* Now allocate and setup the descriptor. */ |
| 803 | d = kzalloc(sizeof(*d) + sglen * sizeof(d->sg[0]), GFP_ATOMIC); |
| 804 | if (!d) |
| 805 | return NULL; |
| 806 | |
| 807 | d->dir = dir; |
| 808 | d->dev_addr = dev_addr; |
| 809 | d->es = es; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 810 | |
Russell King | aa4c5b9 | 2014-01-14 23:58:10 +0000 | [diff] [blame] | 811 | d->ccr = c->ccr | CCR_SYNC_FRAME; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 812 | if (dir == DMA_DEV_TO_MEM) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 813 | d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 814 | else |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 815 | d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 816 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 817 | d->cicr = CICR_DROP_IE | CICR_BLOCK_IE; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 818 | d->csdp = es; |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 819 | |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 820 | if (dma_omap1()) { |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 821 | d->cicr |= CICR_TOUT_IE; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 822 | |
| 823 | if (dir == DMA_DEV_TO_MEM) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 824 | d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_TIPB; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 825 | else |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 826 | d->csdp |= CSDP_DST_PORT_TIPB | CSDP_SRC_PORT_EMIFF; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 827 | } else { |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 828 | if (dir == DMA_DEV_TO_MEM) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 829 | d->ccr |= CCR_TRIGGER_SRC; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 830 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 831 | d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 832 | } |
Russell King | 965aeb4d | 2013-11-06 17:12:30 +0000 | [diff] [blame] | 833 | if (od->plat->errata & DMA_ERRATA_PARALLEL_CHANNELS) |
| 834 | d->clnk_ctrl = c->dma_ch; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 835 | |
| 836 | /* |
| 837 | * Build our scatterlist entries: each contains the address, |
| 838 | * the number of elements (EN) in each frame, and the number of |
| 839 | * frames (FN). Number of bytes for this entry = ES * EN * FN. |
| 840 | * |
| 841 | * Burst size translates to number of elements with frame sync. |
| 842 | * Note: DMA engine defines burst to be the number of dev-width |
| 843 | * transfers. |
| 844 | */ |
| 845 | en = burst; |
| 846 | frame_bytes = es_bytes[es] * en; |
| 847 | for_each_sg(sgl, sgent, sglen, i) { |
| 848 | d->sg[j].addr = sg_dma_address(sgent); |
| 849 | d->sg[j].en = en; |
| 850 | d->sg[j].fn = sg_dma_len(sgent) / frame_bytes; |
| 851 | j++; |
| 852 | } |
| 853 | |
| 854 | d->sglen = j; |
| 855 | |
| 856 | return vchan_tx_prep(&c->vc, &d->vd, tx_flags); |
| 857 | } |
| 858 | |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 859 | static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic( |
| 860 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
Laurent Pinchart | 31c1e5a | 2014-08-01 12:20:10 +0200 | [diff] [blame] | 861 | size_t period_len, enum dma_transfer_direction dir, unsigned long flags) |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 862 | { |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 863 | struct omap_dmadev *od = to_omap_dma_dev(chan->device); |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 864 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 865 | enum dma_slave_buswidth dev_width; |
| 866 | struct omap_desc *d; |
| 867 | dma_addr_t dev_addr; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 868 | unsigned es; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 869 | u32 burst; |
| 870 | |
| 871 | if (dir == DMA_DEV_TO_MEM) { |
| 872 | dev_addr = c->cfg.src_addr; |
| 873 | dev_width = c->cfg.src_addr_width; |
| 874 | burst = c->cfg.src_maxburst; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 875 | } else if (dir == DMA_MEM_TO_DEV) { |
| 876 | dev_addr = c->cfg.dst_addr; |
| 877 | dev_width = c->cfg.dst_addr_width; |
| 878 | burst = c->cfg.dst_maxburst; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 879 | } else { |
| 880 | dev_err(chan->device->dev, "%s: bad direction?\n", __func__); |
| 881 | return NULL; |
| 882 | } |
| 883 | |
| 884 | /* Bus width translates to the element size (ES) */ |
| 885 | switch (dev_width) { |
| 886 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 887 | es = CSDP_DATA_TYPE_8; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 888 | break; |
| 889 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 890 | es = CSDP_DATA_TYPE_16; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 891 | break; |
| 892 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 893 | es = CSDP_DATA_TYPE_32; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 894 | break; |
| 895 | default: /* not reached */ |
| 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | /* Now allocate and setup the descriptor. */ |
| 900 | d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC); |
| 901 | if (!d) |
| 902 | return NULL; |
| 903 | |
| 904 | d->dir = dir; |
| 905 | d->dev_addr = dev_addr; |
| 906 | d->fi = burst; |
| 907 | d->es = es; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 908 | d->sg[0].addr = buf_addr; |
| 909 | d->sg[0].en = period_len / es_bytes[es]; |
| 910 | d->sg[0].fn = buf_len / period_len; |
| 911 | d->sglen = 1; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 912 | |
Russell King | aa4c5b9 | 2014-01-14 23:58:10 +0000 | [diff] [blame] | 913 | d->ccr = c->ccr; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 914 | if (dir == DMA_DEV_TO_MEM) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 915 | d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 916 | else |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 917 | d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 918 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 919 | d->cicr = CICR_DROP_IE; |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 920 | if (flags & DMA_PREP_INTERRUPT) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 921 | d->cicr |= CICR_FRAME_IE; |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 922 | |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 923 | d->csdp = es; |
| 924 | |
| 925 | if (dma_omap1()) { |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 926 | d->cicr |= CICR_TOUT_IE; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 927 | |
| 928 | if (dir == DMA_DEV_TO_MEM) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 929 | d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_MPUI; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 930 | else |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 931 | d->csdp |= CSDP_DST_PORT_MPUI | CSDP_SRC_PORT_EMIFF; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 932 | } else { |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 933 | if (burst) |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 934 | d->ccr |= CCR_SYNC_PACKET; |
| 935 | else |
| 936 | d->ccr |= CCR_SYNC_ELEMENT; |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 937 | |
Misael Lopez Cruz | 47fac24 | 2015-09-14 15:31:05 +0300 | [diff] [blame] | 938 | if (dir == DMA_DEV_TO_MEM) { |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 939 | d->ccr |= CCR_TRIGGER_SRC; |
Misael Lopez Cruz | 47fac24 | 2015-09-14 15:31:05 +0300 | [diff] [blame] | 940 | d->csdp |= CSDP_DST_PACKED; |
| 941 | } else { |
| 942 | d->csdp |= CSDP_SRC_PACKED; |
| 943 | } |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 944 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 945 | d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 946 | |
Russell King | 9043826 | 2013-11-02 19:57:06 +0000 | [diff] [blame] | 947 | d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64; |
Russell King | 2f0d13b | 2013-11-02 18:51:53 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Russell King | 965aeb4d | 2013-11-06 17:12:30 +0000 | [diff] [blame] | 950 | if (__dma_omap15xx(od->plat->dma_attr)) |
| 951 | d->ccr |= CCR_AUTO_INIT | CCR_REPEAT; |
| 952 | else |
| 953 | d->clnk_ctrl = c->dma_ch | CLNK_CTRL_ENABLE_LNK; |
| 954 | |
Russell King | 3ed4d18 | 2013-11-02 19:16:09 +0000 | [diff] [blame] | 955 | c->cyclic = true; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 956 | |
Peter Ujfalusi | 2dde5b9 | 2012-09-14 15:05:48 +0300 | [diff] [blame] | 957 | return vchan_tx_prep(&c->vc, &d->vd, flags); |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 958 | } |
| 959 | |
Peter Ujfalusi | 4ce98c0 | 2015-04-22 10:34:29 +0300 | [diff] [blame] | 960 | static struct dma_async_tx_descriptor *omap_dma_prep_dma_memcpy( |
| 961 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 962 | size_t len, unsigned long tx_flags) |
| 963 | { |
| 964 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 965 | struct omap_desc *d; |
| 966 | uint8_t data_type; |
| 967 | |
| 968 | d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC); |
| 969 | if (!d) |
| 970 | return NULL; |
| 971 | |
| 972 | data_type = __ffs((src | dest | len)); |
| 973 | if (data_type > CSDP_DATA_TYPE_32) |
| 974 | data_type = CSDP_DATA_TYPE_32; |
| 975 | |
| 976 | d->dir = DMA_MEM_TO_MEM; |
| 977 | d->dev_addr = src; |
| 978 | d->fi = 0; |
| 979 | d->es = data_type; |
| 980 | d->sg[0].en = len / BIT(data_type); |
| 981 | d->sg[0].fn = 1; |
| 982 | d->sg[0].addr = dest; |
| 983 | d->sglen = 1; |
| 984 | d->ccr = c->ccr; |
| 985 | d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_POSTINC; |
| 986 | |
| 987 | d->cicr = CICR_DROP_IE; |
| 988 | if (tx_flags & DMA_PREP_INTERRUPT) |
| 989 | d->cicr |= CICR_FRAME_IE; |
| 990 | |
| 991 | d->csdp = data_type; |
| 992 | |
| 993 | if (dma_omap1()) { |
| 994 | d->cicr |= CICR_TOUT_IE; |
| 995 | d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_EMIFF; |
| 996 | } else { |
| 997 | d->csdp |= CSDP_DST_PACKED | CSDP_SRC_PACKED; |
| 998 | d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE; |
| 999 | d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64; |
| 1000 | } |
| 1001 | |
| 1002 | return vchan_tx_prep(&c->vc, &d->vd, tx_flags); |
| 1003 | } |
| 1004 | |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1005 | static int omap_dma_slave_config(struct dma_chan *chan, struct dma_slave_config *cfg) |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1006 | { |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1007 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 1008 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1009 | if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || |
| 1010 | cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) |
| 1011 | return -EINVAL; |
| 1012 | |
| 1013 | memcpy(&c->cfg, cfg, sizeof(c->cfg)); |
| 1014 | |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1018 | static int omap_dma_terminate_all(struct dma_chan *chan) |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1019 | { |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1020 | struct omap_chan *c = to_omap_dma_chan(chan); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1021 | struct omap_dmadev *d = to_omap_dma_dev(c->vc.chan.device); |
| 1022 | unsigned long flags; |
| 1023 | LIST_HEAD(head); |
| 1024 | |
| 1025 | spin_lock_irqsave(&c->vc.lock, flags); |
| 1026 | |
| 1027 | /* Prevent this channel being scheduled */ |
| 1028 | spin_lock(&d->lock); |
| 1029 | list_del_init(&c->node); |
| 1030 | spin_unlock(&d->lock); |
| 1031 | |
| 1032 | /* |
| 1033 | * Stop DMA activity: we assume the callback will not be called |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 1034 | * after omap_dma_stop() returns (even if it does, it will see |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1035 | * c->desc is NULL and exit.) |
| 1036 | */ |
| 1037 | if (c->desc) { |
Peter Ujfalusi | 02d88b7 | 2015-03-27 13:35:52 +0200 | [diff] [blame] | 1038 | omap_dma_desc_free(&c->desc->vd); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1039 | c->desc = NULL; |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 1040 | /* Avoid stopping the dma twice */ |
| 1041 | if (!c->paused) |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 1042 | omap_dma_stop(c); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 1045 | if (c->cyclic) { |
| 1046 | c->cyclic = false; |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 1047 | c->paused = false; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1050 | vchan_get_all_descriptors(&c->vc, &head); |
| 1051 | spin_unlock_irqrestore(&c->vc.lock, flags); |
| 1052 | vchan_dma_desc_free_list(&c->vc, &head); |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1057 | static int omap_dma_pause(struct dma_chan *chan) |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1058 | { |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1059 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 1060 | |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 1061 | /* Pause/Resume only allowed with cyclic mode */ |
| 1062 | if (!c->cyclic) |
| 1063 | return -EINVAL; |
| 1064 | |
| 1065 | if (!c->paused) { |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 1066 | omap_dma_stop(c); |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 1067 | c->paused = true; |
| 1068 | } |
| 1069 | |
| 1070 | return 0; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1071 | } |
| 1072 | |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1073 | static int omap_dma_resume(struct dma_chan *chan) |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1074 | { |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1075 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 1076 | |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 1077 | /* Pause/Resume only allowed with cyclic mode */ |
| 1078 | if (!c->cyclic) |
| 1079 | return -EINVAL; |
| 1080 | |
| 1081 | if (c->paused) { |
Peter Ujfalusi | b3d09da | 2014-09-16 22:45:56 +0300 | [diff] [blame] | 1082 | mb(); |
| 1083 | |
Peter Ujfalusi | bfb6074 | 2014-09-16 22:45:57 +0300 | [diff] [blame] | 1084 | /* Restore channel link register */ |
| 1085 | omap_dma_chan_write(c, CLNK_CTRL, c->desc->clnk_ctrl); |
| 1086 | |
Russell King | fa3ad86 | 2013-11-02 17:07:09 +0000 | [diff] [blame] | 1087 | omap_dma_start(c, c->desc); |
Peter Ujfalusi | 2dcdf57 | 2012-09-14 15:05:45 +0300 | [diff] [blame] | 1088 | c->paused = false; |
| 1089 | } |
| 1090 | |
| 1091 | return 0; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
Peter Ujfalusi | eea531e | 2015-04-09 12:35:52 +0300 | [diff] [blame] | 1094 | static int omap_dma_chan_init(struct omap_dmadev *od) |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1095 | { |
| 1096 | struct omap_chan *c; |
| 1097 | |
| 1098 | c = kzalloc(sizeof(*c), GFP_KERNEL); |
| 1099 | if (!c) |
| 1100 | return -ENOMEM; |
| 1101 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 1102 | c->reg_map = od->reg_map; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1103 | c->vc.desc_free = omap_dma_desc_free; |
| 1104 | vchan_init(&c->vc, &od->ddev); |
| 1105 | INIT_LIST_HEAD(&c->node); |
| 1106 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | static void omap_dma_free(struct omap_dmadev *od) |
| 1111 | { |
| 1112 | tasklet_kill(&od->task); |
| 1113 | while (!list_empty(&od->ddev.channels)) { |
| 1114 | struct omap_chan *c = list_first_entry(&od->ddev.channels, |
| 1115 | struct omap_chan, vc.chan.device_node); |
| 1116 | |
| 1117 | list_del(&c->vc.chan.device_node); |
| 1118 | tasklet_kill(&c->vc.task); |
| 1119 | kfree(c); |
| 1120 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
Peter Ujfalusi | 80b0e0a | 2014-03-29 19:03:30 +0530 | [diff] [blame] | 1123 | #define OMAP_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \ |
| 1124 | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \ |
| 1125 | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)) |
| 1126 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1127 | static int omap_dma_probe(struct platform_device *pdev) |
| 1128 | { |
| 1129 | struct omap_dmadev *od; |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 1130 | struct resource *res; |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 1131 | int rc, i, irq; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1132 | |
Russell King | 104fce7 | 2013-11-02 12:58:29 +0000 | [diff] [blame] | 1133 | od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1134 | if (!od) |
| 1135 | return -ENOMEM; |
| 1136 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 1137 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1138 | od->base = devm_ioremap_resource(&pdev->dev, res); |
| 1139 | if (IS_ERR(od->base)) |
| 1140 | return PTR_ERR(od->base); |
| 1141 | |
Russell King | 1b416c4 | 2013-11-02 13:00:03 +0000 | [diff] [blame] | 1142 | od->plat = omap_get_plat_info(); |
| 1143 | if (!od->plat) |
| 1144 | return -EPROBE_DEFER; |
| 1145 | |
Russell King | 596c471 | 2013-12-10 11:08:01 +0000 | [diff] [blame] | 1146 | od->reg_map = od->plat->reg_map; |
| 1147 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1148 | dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 1149 | dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask); |
Peter Ujfalusi | 4ce98c0 | 2015-04-22 10:34:29 +0300 | [diff] [blame] | 1150 | dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1151 | od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources; |
| 1152 | od->ddev.device_free_chan_resources = omap_dma_free_chan_resources; |
| 1153 | od->ddev.device_tx_status = omap_dma_tx_status; |
| 1154 | od->ddev.device_issue_pending = omap_dma_issue_pending; |
| 1155 | od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg; |
Russell King | 3a774ea | 2012-06-21 10:40:15 +0100 | [diff] [blame] | 1156 | od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic; |
Peter Ujfalusi | 4ce98c0 | 2015-04-22 10:34:29 +0300 | [diff] [blame] | 1157 | od->ddev.device_prep_dma_memcpy = omap_dma_prep_dma_memcpy; |
Vinod Koul | 6c04cd4 | 2014-12-07 23:12:31 +0530 | [diff] [blame] | 1158 | od->ddev.device_config = omap_dma_slave_config; |
Maxime Ripard | 78ea4fe | 2014-11-17 14:42:28 +0100 | [diff] [blame] | 1159 | od->ddev.device_pause = omap_dma_pause; |
| 1160 | od->ddev.device_resume = omap_dma_resume; |
| 1161 | od->ddev.device_terminate_all = omap_dma_terminate_all; |
Maxime Ripard | 7d15b87 | 2014-11-17 14:42:49 +0100 | [diff] [blame] | 1162 | od->ddev.src_addr_widths = OMAP_DMA_BUSWIDTHS; |
| 1163 | od->ddev.dst_addr_widths = OMAP_DMA_BUSWIDTHS; |
| 1164 | od->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); |
| 1165 | od->ddev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1166 | od->ddev.dev = &pdev->dev; |
| 1167 | INIT_LIST_HEAD(&od->ddev.channels); |
| 1168 | INIT_LIST_HEAD(&od->pending); |
| 1169 | spin_lock_init(&od->lock); |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 1170 | spin_lock_init(&od->irq_lock); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1171 | |
| 1172 | tasklet_init(&od->task, omap_dma_sched, (unsigned long)od); |
| 1173 | |
Peter Ujfalusi | de50608 | 2015-04-09 12:35:51 +0300 | [diff] [blame] | 1174 | od->dma_requests = OMAP_SDMA_REQUESTS; |
| 1175 | if (pdev->dev.of_node && of_property_read_u32(pdev->dev.of_node, |
| 1176 | "dma-requests", |
| 1177 | &od->dma_requests)) { |
| 1178 | dev_info(&pdev->dev, |
| 1179 | "Missing dma-requests property, using %u.\n", |
| 1180 | OMAP_SDMA_REQUESTS); |
| 1181 | } |
| 1182 | |
Peter Ujfalusi | 8a32222 | 2015-04-09 12:35:53 +0300 | [diff] [blame] | 1183 | for (i = 0; i < OMAP_SDMA_CHANNELS; i++) { |
Peter Ujfalusi | eea531e | 2015-04-09 12:35:52 +0300 | [diff] [blame] | 1184 | rc = omap_dma_chan_init(od); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1185 | if (rc) { |
| 1186 | omap_dma_free(od); |
| 1187 | return rc; |
| 1188 | } |
| 1189 | } |
| 1190 | |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 1191 | irq = platform_get_irq(pdev, 1); |
| 1192 | if (irq <= 0) { |
| 1193 | dev_info(&pdev->dev, "failed to get L1 IRQ: %d\n", irq); |
| 1194 | od->legacy = true; |
| 1195 | } else { |
| 1196 | /* Disable all interrupts */ |
| 1197 | od->irq_enable_mask = 0; |
| 1198 | omap_dma_glbl_write(od, IRQENABLE_L1, 0); |
| 1199 | |
| 1200 | rc = devm_request_irq(&pdev->dev, irq, omap_dma_irq, |
| 1201 | IRQF_SHARED, "omap-dma-engine", od); |
| 1202 | if (rc) |
| 1203 | return rc; |
| 1204 | } |
| 1205 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1206 | rc = dma_async_device_register(&od->ddev); |
| 1207 | if (rc) { |
| 1208 | pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n", |
| 1209 | rc); |
| 1210 | omap_dma_free(od); |
Jon Hunter | 8d30662 | 2013-02-26 12:27:24 -0600 | [diff] [blame] | 1211 | return rc; |
| 1212 | } |
| 1213 | |
| 1214 | platform_set_drvdata(pdev, od); |
| 1215 | |
| 1216 | if (pdev->dev.of_node) { |
| 1217 | omap_dma_info.dma_cap = od->ddev.cap_mask; |
| 1218 | |
| 1219 | /* Device-tree DMA controller registration */ |
| 1220 | rc = of_dma_controller_register(pdev->dev.of_node, |
| 1221 | of_dma_simple_xlate, &omap_dma_info); |
| 1222 | if (rc) { |
| 1223 | pr_warn("OMAP-DMA: failed to register DMA controller\n"); |
| 1224 | dma_async_device_unregister(&od->ddev); |
| 1225 | omap_dma_free(od); |
| 1226 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | dev_info(&pdev->dev, "OMAP DMA engine driver\n"); |
| 1230 | |
| 1231 | return rc; |
| 1232 | } |
| 1233 | |
| 1234 | static int omap_dma_remove(struct platform_device *pdev) |
| 1235 | { |
| 1236 | struct omap_dmadev *od = platform_get_drvdata(pdev); |
| 1237 | |
Jon Hunter | 8d30662 | 2013-02-26 12:27:24 -0600 | [diff] [blame] | 1238 | if (pdev->dev.of_node) |
| 1239 | of_dma_controller_free(pdev->dev.of_node); |
| 1240 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1241 | dma_async_device_unregister(&od->ddev); |
Russell King | 6ddeb6d | 2013-12-10 19:05:50 +0000 | [diff] [blame] | 1242 | |
| 1243 | if (!od->legacy) { |
| 1244 | /* Disable all interrupts */ |
| 1245 | omap_dma_glbl_write(od, IRQENABLE_L0, 0); |
| 1246 | } |
| 1247 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1248 | omap_dma_free(od); |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
Jon Hunter | 8d30662 | 2013-02-26 12:27:24 -0600 | [diff] [blame] | 1253 | static const struct of_device_id omap_dma_match[] = { |
| 1254 | { .compatible = "ti,omap2420-sdma", }, |
| 1255 | { .compatible = "ti,omap2430-sdma", }, |
| 1256 | { .compatible = "ti,omap3430-sdma", }, |
| 1257 | { .compatible = "ti,omap3630-sdma", }, |
| 1258 | { .compatible = "ti,omap4430-sdma", }, |
| 1259 | {}, |
| 1260 | }; |
| 1261 | MODULE_DEVICE_TABLE(of, omap_dma_match); |
| 1262 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1263 | static struct platform_driver omap_dma_driver = { |
| 1264 | .probe = omap_dma_probe, |
| 1265 | .remove = omap_dma_remove, |
| 1266 | .driver = { |
| 1267 | .name = "omap-dma-engine", |
Jon Hunter | 8d30662 | 2013-02-26 12:27:24 -0600 | [diff] [blame] | 1268 | .of_match_table = of_match_ptr(omap_dma_match), |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1269 | }, |
| 1270 | }; |
| 1271 | |
| 1272 | bool omap_dma_filter_fn(struct dma_chan *chan, void *param) |
| 1273 | { |
| 1274 | if (chan->device->dev->driver == &omap_dma_driver.driver) { |
Peter Ujfalusi | eea531e | 2015-04-09 12:35:52 +0300 | [diff] [blame] | 1275 | struct omap_dmadev *od = to_omap_dma_dev(chan->device); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1276 | struct omap_chan *c = to_omap_dma_chan(chan); |
| 1277 | unsigned req = *(unsigned *)param; |
| 1278 | |
Peter Ujfalusi | eea531e | 2015-04-09 12:35:52 +0300 | [diff] [blame] | 1279 | if (req <= od->dma_requests) { |
| 1280 | c->dma_sig = req; |
| 1281 | return true; |
| 1282 | } |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1283 | } |
| 1284 | return false; |
| 1285 | } |
| 1286 | EXPORT_SYMBOL_GPL(omap_dma_filter_fn); |
| 1287 | |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1288 | static int omap_dma_init(void) |
| 1289 | { |
Tony Lindgren | be1f948 | 2013-01-11 11:24:19 -0800 | [diff] [blame] | 1290 | return platform_driver_register(&omap_dma_driver); |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1291 | } |
| 1292 | subsys_initcall(omap_dma_init); |
| 1293 | |
| 1294 | static void __exit omap_dma_exit(void) |
| 1295 | { |
Russell King | 7bedaa5 | 2012-04-13 12:10:24 +0100 | [diff] [blame] | 1296 | platform_driver_unregister(&omap_dma_driver); |
| 1297 | } |
| 1298 | module_exit(omap_dma_exit); |
| 1299 | |
| 1300 | MODULE_AUTHOR("Russell King"); |
| 1301 | MODULE_LICENSE("GPL"); |