blob: d99ca2b511c4101ce262569106ffe1d3fa5644fb [file] [log] [blame]
Russell King7bedaa52012-04-13 12:10:24 +01001/*
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 Kingfa3ad862013-11-02 17:07:09 +00008#include <linux/delay.h>
Russell King7bedaa52012-04-13 12:10:24 +01009#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 Hunter8d306622013-02-26 12:27:24 -060020#include <linux/of_dma.h>
21#include <linux/of_device.h>
Russell King7bedaa52012-04-13 12:10:24 +010022
23#include "virt-dma.h"
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070024
Peter Ujfalusi341ce712015-04-09 12:35:50 +030025#define OMAP_SDMA_REQUESTS 127
26#define OMAP_SDMA_CHANNELS 32
27
Russell King7bedaa52012-04-13 12:10:24 +010028struct omap_dmadev {
29 struct dma_device ddev;
30 spinlock_t lock;
Russell King596c4712013-12-10 11:08:01 +000031 void __iomem *base;
32 const struct omap_dma_reg *reg_map;
Russell King1b416c42013-11-02 13:00:03 +000033 struct omap_system_dma_plat_info *plat;
Russell King6ddeb6d2013-12-10 19:05:50 +000034 bool legacy;
Peter Ujfaluside506082015-04-09 12:35:51 +030035 unsigned dma_requests;
Russell King6ddeb6d2013-12-10 19:05:50 +000036 spinlock_t irq_lock;
37 uint32_t irq_enable_mask;
Peter Ujfalusi341ce712015-04-09 12:35:50 +030038 struct omap_chan *lch_map[OMAP_SDMA_CHANNELS];
Russell King7bedaa52012-04-13 12:10:24 +010039};
40
41struct omap_chan {
42 struct virt_dma_chan vc;
Russell King596c4712013-12-10 11:08:01 +000043 void __iomem *channel_base;
44 const struct omap_dma_reg *reg_map;
Russell Kingaa4c5b92014-01-14 23:58:10 +000045 uint32_t ccr;
Russell King7bedaa52012-04-13 12:10:24 +010046
47 struct dma_slave_config cfg;
48 unsigned dma_sig;
Russell King3a774ea2012-06-21 10:40:15 +010049 bool cyclic;
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +030050 bool paused;
Peter Ujfalusi689d3c52016-04-05 15:20:20 +030051 bool running;
Russell King7bedaa52012-04-13 12:10:24 +010052
53 int dma_ch;
54 struct omap_desc *desc;
55 unsigned sgidx;
56};
57
58struct omap_sg {
59 dma_addr_t addr;
60 uint32_t en; /* number of elements (24-bit) */
61 uint32_t fn; /* number of frames (16-bit) */
Peter Ujfalusiad524652016-07-12 14:21:14 +030062 int32_t fi; /* for double indexing */
63 int16_t ei; /* for double indexing */
Russell King7bedaa52012-04-13 12:10:24 +010064};
65
66struct omap_desc {
67 struct virt_dma_desc vd;
68 enum dma_transfer_direction dir;
69 dma_addr_t dev_addr;
70
Peter Ujfalusiad524652016-07-12 14:21:14 +030071 int32_t fi; /* for OMAP_DMA_SYNC_PACKET / double indexing */
72 int16_t ei; /* for double indexing */
Russell King90438262013-11-02 19:57:06 +000073 uint8_t es; /* CSDP_DATA_TYPE_xxx */
Russell King3ed4d182013-11-02 19:16:09 +000074 uint32_t ccr; /* CCR value */
Russell King965aeb4d2013-11-06 17:12:30 +000075 uint16_t clnk_ctrl; /* CLNK_CTRL value */
Russell Kingfa3ad862013-11-02 17:07:09 +000076 uint16_t cicr; /* CICR value */
Russell King2f0d13b2013-11-02 18:51:53 +000077 uint32_t csdp; /* CSDP value */
Russell King7bedaa52012-04-13 12:10:24 +010078
79 unsigned sglen;
80 struct omap_sg sg[0];
81};
82
Russell King90438262013-11-02 19:57:06 +000083enum {
84 CCR_FS = BIT(5),
85 CCR_READ_PRIORITY = BIT(6),
86 CCR_ENABLE = BIT(7),
87 CCR_AUTO_INIT = BIT(8), /* OMAP1 only */
88 CCR_REPEAT = BIT(9), /* OMAP1 only */
89 CCR_OMAP31_DISABLE = BIT(10), /* OMAP1 only */
90 CCR_SUSPEND_SENSITIVE = BIT(8), /* OMAP2+ only */
91 CCR_RD_ACTIVE = BIT(9), /* OMAP2+ only */
92 CCR_WR_ACTIVE = BIT(10), /* OMAP2+ only */
93 CCR_SRC_AMODE_CONSTANT = 0 << 12,
94 CCR_SRC_AMODE_POSTINC = 1 << 12,
95 CCR_SRC_AMODE_SGLIDX = 2 << 12,
96 CCR_SRC_AMODE_DBLIDX = 3 << 12,
97 CCR_DST_AMODE_CONSTANT = 0 << 14,
98 CCR_DST_AMODE_POSTINC = 1 << 14,
99 CCR_DST_AMODE_SGLIDX = 2 << 14,
100 CCR_DST_AMODE_DBLIDX = 3 << 14,
101 CCR_CONSTANT_FILL = BIT(16),
102 CCR_TRANSPARENT_COPY = BIT(17),
103 CCR_BS = BIT(18),
104 CCR_SUPERVISOR = BIT(22),
105 CCR_PREFETCH = BIT(23),
106 CCR_TRIGGER_SRC = BIT(24),
107 CCR_BUFFERING_DISABLE = BIT(25),
108 CCR_WRITE_PRIORITY = BIT(26),
109 CCR_SYNC_ELEMENT = 0,
110 CCR_SYNC_FRAME = CCR_FS,
111 CCR_SYNC_BLOCK = CCR_BS,
112 CCR_SYNC_PACKET = CCR_BS | CCR_FS,
113
114 CSDP_DATA_TYPE_8 = 0,
115 CSDP_DATA_TYPE_16 = 1,
116 CSDP_DATA_TYPE_32 = 2,
117 CSDP_SRC_PORT_EMIFF = 0 << 2, /* OMAP1 only */
118 CSDP_SRC_PORT_EMIFS = 1 << 2, /* OMAP1 only */
119 CSDP_SRC_PORT_OCP_T1 = 2 << 2, /* OMAP1 only */
120 CSDP_SRC_PORT_TIPB = 3 << 2, /* OMAP1 only */
121 CSDP_SRC_PORT_OCP_T2 = 4 << 2, /* OMAP1 only */
122 CSDP_SRC_PORT_MPUI = 5 << 2, /* OMAP1 only */
123 CSDP_SRC_PACKED = BIT(6),
124 CSDP_SRC_BURST_1 = 0 << 7,
125 CSDP_SRC_BURST_16 = 1 << 7,
126 CSDP_SRC_BURST_32 = 2 << 7,
127 CSDP_SRC_BURST_64 = 3 << 7,
128 CSDP_DST_PORT_EMIFF = 0 << 9, /* OMAP1 only */
129 CSDP_DST_PORT_EMIFS = 1 << 9, /* OMAP1 only */
130 CSDP_DST_PORT_OCP_T1 = 2 << 9, /* OMAP1 only */
131 CSDP_DST_PORT_TIPB = 3 << 9, /* OMAP1 only */
132 CSDP_DST_PORT_OCP_T2 = 4 << 9, /* OMAP1 only */
133 CSDP_DST_PORT_MPUI = 5 << 9, /* OMAP1 only */
134 CSDP_DST_PACKED = BIT(13),
135 CSDP_DST_BURST_1 = 0 << 14,
136 CSDP_DST_BURST_16 = 1 << 14,
137 CSDP_DST_BURST_32 = 2 << 14,
138 CSDP_DST_BURST_64 = 3 << 14,
139
140 CICR_TOUT_IE = BIT(0), /* OMAP1 only */
141 CICR_DROP_IE = BIT(1),
142 CICR_HALF_IE = BIT(2),
143 CICR_FRAME_IE = BIT(3),
144 CICR_LAST_IE = BIT(4),
145 CICR_BLOCK_IE = BIT(5),
146 CICR_PKT_IE = BIT(7), /* OMAP2+ only */
147 CICR_TRANS_ERR_IE = BIT(8), /* OMAP2+ only */
148 CICR_SUPERVISOR_ERR_IE = BIT(10), /* OMAP2+ only */
149 CICR_MISALIGNED_ERR_IE = BIT(11), /* OMAP2+ only */
150 CICR_DRAIN_IE = BIT(12), /* OMAP2+ only */
151 CICR_SUPER_BLOCK_IE = BIT(14), /* OMAP2+ only */
152
153 CLNK_CTRL_ENABLE_LNK = BIT(15),
154};
155
Russell King7bedaa52012-04-13 12:10:24 +0100156static const unsigned es_bytes[] = {
Russell King90438262013-11-02 19:57:06 +0000157 [CSDP_DATA_TYPE_8] = 1,
158 [CSDP_DATA_TYPE_16] = 2,
159 [CSDP_DATA_TYPE_32] = 4,
Russell King7bedaa52012-04-13 12:10:24 +0100160};
161
Jon Hunter8d306622013-02-26 12:27:24 -0600162static struct of_dma_filter_info omap_dma_info = {
163 .filter_fn = omap_dma_filter_fn,
164};
165
Russell King7bedaa52012-04-13 12:10:24 +0100166static inline struct omap_dmadev *to_omap_dma_dev(struct dma_device *d)
167{
168 return container_of(d, struct omap_dmadev, ddev);
169}
170
171static inline struct omap_chan *to_omap_dma_chan(struct dma_chan *c)
172{
173 return container_of(c, struct omap_chan, vc.chan);
174}
175
176static inline struct omap_desc *to_omap_dma_desc(struct dma_async_tx_descriptor *t)
177{
178 return container_of(t, struct omap_desc, vd.tx);
179}
180
181static void omap_dma_desc_free(struct virt_dma_desc *vd)
182{
183 kfree(container_of(vd, struct omap_desc, vd));
184}
185
Russell King596c4712013-12-10 11:08:01 +0000186static void omap_dma_write(uint32_t val, unsigned type, void __iomem *addr)
187{
188 switch (type) {
189 case OMAP_DMA_REG_16BIT:
190 writew_relaxed(val, addr);
191 break;
192 case OMAP_DMA_REG_2X16BIT:
193 writew_relaxed(val, addr);
194 writew_relaxed(val >> 16, addr + 2);
195 break;
196 case OMAP_DMA_REG_32BIT:
197 writel_relaxed(val, addr);
198 break;
199 default:
200 WARN_ON(1);
201 }
202}
203
204static unsigned omap_dma_read(unsigned type, void __iomem *addr)
205{
206 unsigned val;
207
208 switch (type) {
209 case OMAP_DMA_REG_16BIT:
210 val = readw_relaxed(addr);
211 break;
212 case OMAP_DMA_REG_2X16BIT:
213 val = readw_relaxed(addr);
214 val |= readw_relaxed(addr + 2) << 16;
215 break;
216 case OMAP_DMA_REG_32BIT:
217 val = readl_relaxed(addr);
218 break;
219 default:
220 WARN_ON(1);
221 val = 0;
222 }
223
224 return val;
225}
226
Russell Kingc5ed98b2013-11-06 17:33:09 +0000227static void omap_dma_glbl_write(struct omap_dmadev *od, unsigned reg, unsigned val)
228{
Russell King596c4712013-12-10 11:08:01 +0000229 const struct omap_dma_reg *r = od->reg_map + reg;
230
231 WARN_ON(r->stride);
232
233 omap_dma_write(val, r->type, od->base + r->offset);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000234}
235
236static unsigned omap_dma_glbl_read(struct omap_dmadev *od, unsigned reg)
237{
Russell King596c4712013-12-10 11:08:01 +0000238 const struct omap_dma_reg *r = od->reg_map + reg;
239
240 WARN_ON(r->stride);
241
242 return omap_dma_read(r->type, od->base + r->offset);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000243}
244
245static void omap_dma_chan_write(struct omap_chan *c, unsigned reg, unsigned val)
246{
Russell King596c4712013-12-10 11:08:01 +0000247 const struct omap_dma_reg *r = c->reg_map + reg;
248
249 omap_dma_write(val, r->type, c->channel_base + r->offset);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000250}
251
252static unsigned omap_dma_chan_read(struct omap_chan *c, unsigned reg)
253{
Russell King596c4712013-12-10 11:08:01 +0000254 const struct omap_dma_reg *r = c->reg_map + reg;
255
256 return omap_dma_read(r->type, c->channel_base + r->offset);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000257}
258
Russell King470b23f2013-11-02 21:23:06 +0000259static void omap_dma_clear_csr(struct omap_chan *c)
260{
261 if (dma_omap1())
Russell Kingc5ed98b2013-11-06 17:33:09 +0000262 omap_dma_chan_read(c, CSR);
Russell King470b23f2013-11-02 21:23:06 +0000263 else
Russell Kingc5ed98b2013-11-06 17:33:09 +0000264 omap_dma_chan_write(c, CSR, ~0);
Russell King470b23f2013-11-02 21:23:06 +0000265}
266
Russell King6ddeb6d2013-12-10 19:05:50 +0000267static unsigned omap_dma_get_csr(struct omap_chan *c)
268{
269 unsigned val = omap_dma_chan_read(c, CSR);
270
271 if (!dma_omap1())
272 omap_dma_chan_write(c, CSR, val);
273
274 return val;
275}
276
Russell King596c4712013-12-10 11:08:01 +0000277static void omap_dma_assign(struct omap_dmadev *od, struct omap_chan *c,
278 unsigned lch)
279{
280 c->channel_base = od->base + od->plat->channel_stride * lch;
Russell King6ddeb6d2013-12-10 19:05:50 +0000281
282 od->lch_map[lch] = c;
Russell King596c4712013-12-10 11:08:01 +0000283}
284
Russell Kingfa3ad862013-11-02 17:07:09 +0000285static void omap_dma_start(struct omap_chan *c, struct omap_desc *d)
286{
287 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
Russell Kingfa3ad862013-11-02 17:07:09 +0000288
289 if (__dma_omap15xx(od->plat->dma_attr))
Russell Kingc5ed98b2013-11-06 17:33:09 +0000290 omap_dma_chan_write(c, CPC, 0);
Russell Kingfa3ad862013-11-02 17:07:09 +0000291 else
Russell Kingc5ed98b2013-11-06 17:33:09 +0000292 omap_dma_chan_write(c, CDAC, 0);
Russell Kingfa3ad862013-11-02 17:07:09 +0000293
Russell King470b23f2013-11-02 21:23:06 +0000294 omap_dma_clear_csr(c);
Russell Kingfa3ad862013-11-02 17:07:09 +0000295
296 /* Enable interrupts */
Russell Kingc5ed98b2013-11-06 17:33:09 +0000297 omap_dma_chan_write(c, CICR, d->cicr);
Russell Kingfa3ad862013-11-02 17:07:09 +0000298
Russell King45da7b02013-11-06 17:18:42 +0000299 /* Enable channel */
Russell Kingc5ed98b2013-11-06 17:33:09 +0000300 omap_dma_chan_write(c, CCR, d->ccr | CCR_ENABLE);
Peter Ujfalusi689d3c52016-04-05 15:20:20 +0300301
302 c->running = true;
Russell Kingfa3ad862013-11-02 17:07:09 +0000303}
304
305static void omap_dma_stop(struct omap_chan *c)
306{
307 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
308 uint32_t val;
309
310 /* disable irq */
Russell Kingc5ed98b2013-11-06 17:33:09 +0000311 omap_dma_chan_write(c, CICR, 0);
Russell Kingfa3ad862013-11-02 17:07:09 +0000312
Russell King470b23f2013-11-02 21:23:06 +0000313 omap_dma_clear_csr(c);
Russell Kingfa3ad862013-11-02 17:07:09 +0000314
Russell Kingc5ed98b2013-11-06 17:33:09 +0000315 val = omap_dma_chan_read(c, CCR);
Russell King90438262013-11-02 19:57:06 +0000316 if (od->plat->errata & DMA_ERRATA_i541 && val & CCR_TRIGGER_SRC) {
Russell Kingfa3ad862013-11-02 17:07:09 +0000317 uint32_t sysconfig;
318 unsigned i;
319
Russell Kingc5ed98b2013-11-06 17:33:09 +0000320 sysconfig = omap_dma_glbl_read(od, OCP_SYSCONFIG);
Russell Kingfa3ad862013-11-02 17:07:09 +0000321 val = sysconfig & ~DMA_SYSCONFIG_MIDLEMODE_MASK;
322 val |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000323 omap_dma_glbl_write(od, OCP_SYSCONFIG, val);
Russell Kingfa3ad862013-11-02 17:07:09 +0000324
Russell Kingc5ed98b2013-11-06 17:33:09 +0000325 val = omap_dma_chan_read(c, CCR);
Russell King90438262013-11-02 19:57:06 +0000326 val &= ~CCR_ENABLE;
Russell Kingc5ed98b2013-11-06 17:33:09 +0000327 omap_dma_chan_write(c, CCR, val);
Russell Kingfa3ad862013-11-02 17:07:09 +0000328
329 /* Wait for sDMA FIFO to drain */
330 for (i = 0; ; i++) {
Russell Kingc5ed98b2013-11-06 17:33:09 +0000331 val = omap_dma_chan_read(c, CCR);
Russell King90438262013-11-02 19:57:06 +0000332 if (!(val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE)))
Russell Kingfa3ad862013-11-02 17:07:09 +0000333 break;
334
335 if (i > 100)
336 break;
337
338 udelay(5);
339 }
340
Russell King90438262013-11-02 19:57:06 +0000341 if (val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE))
Russell Kingfa3ad862013-11-02 17:07:09 +0000342 dev_err(c->vc.chan.device->dev,
343 "DMA drain did not complete on lch %d\n",
344 c->dma_ch);
345
Russell Kingc5ed98b2013-11-06 17:33:09 +0000346 omap_dma_glbl_write(od, OCP_SYSCONFIG, sysconfig);
Russell Kingfa3ad862013-11-02 17:07:09 +0000347 } else {
Russell King90438262013-11-02 19:57:06 +0000348 val &= ~CCR_ENABLE;
Russell Kingc5ed98b2013-11-06 17:33:09 +0000349 omap_dma_chan_write(c, CCR, val);
Russell Kingfa3ad862013-11-02 17:07:09 +0000350 }
351
352 mb();
353
354 if (!__dma_omap15xx(od->plat->dma_attr) && c->cyclic) {
Russell Kingc5ed98b2013-11-06 17:33:09 +0000355 val = omap_dma_chan_read(c, CLNK_CTRL);
Russell Kingfa3ad862013-11-02 17:07:09 +0000356
357 if (dma_omap1())
358 val |= 1 << 14; /* set the STOP_LNK bit */
359 else
Russell King90438262013-11-02 19:57:06 +0000360 val &= ~CLNK_CTRL_ENABLE_LNK;
Russell Kingfa3ad862013-11-02 17:07:09 +0000361
Russell Kingc5ed98b2013-11-06 17:33:09 +0000362 omap_dma_chan_write(c, CLNK_CTRL, val);
Russell Kingfa3ad862013-11-02 17:07:09 +0000363 }
Peter Ujfalusi689d3c52016-04-05 15:20:20 +0300364
365 c->running = false;
Russell Kingfa3ad862013-11-02 17:07:09 +0000366}
367
Russell King7bedaa52012-04-13 12:10:24 +0100368static void omap_dma_start_sg(struct omap_chan *c, struct omap_desc *d,
369 unsigned idx)
370{
371 struct omap_sg *sg = d->sg + idx;
Russell King893e63e2013-11-03 11:17:11 +0000372 unsigned cxsa, cxei, cxfi;
Russell King7bedaa52012-04-13 12:10:24 +0100373
Peter Ujfalusi4ce98c02015-04-22 10:34:29 +0300374 if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM) {
Russell King893e63e2013-11-03 11:17:11 +0000375 cxsa = CDSA;
376 cxei = CDEI;
377 cxfi = CDFI;
Russell Kingb9e97822013-11-02 13:26:57 +0000378 } else {
Russell King893e63e2013-11-03 11:17:11 +0000379 cxsa = CSSA;
380 cxei = CSEI;
381 cxfi = CSFI;
Russell Kingb9e97822013-11-02 13:26:57 +0000382 }
383
Russell Kingc5ed98b2013-11-06 17:33:09 +0000384 omap_dma_chan_write(c, cxsa, sg->addr);
Peter Ujfalusiad524652016-07-12 14:21:14 +0300385 omap_dma_chan_write(c, cxei, sg->ei);
386 omap_dma_chan_write(c, cxfi, sg->fi);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000387 omap_dma_chan_write(c, CEN, sg->en);
388 omap_dma_chan_write(c, CFN, sg->fn);
Russell King7bedaa52012-04-13 12:10:24 +0100389
Russell Kingfa3ad862013-11-02 17:07:09 +0000390 omap_dma_start(c, d);
Russell King7bedaa52012-04-13 12:10:24 +0100391}
392
393static void omap_dma_start_desc(struct omap_chan *c)
394{
395 struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
396 struct omap_desc *d;
Russell King893e63e2013-11-03 11:17:11 +0000397 unsigned cxsa, cxei, cxfi;
Russell King7bedaa52012-04-13 12:10:24 +0100398
399 if (!vd) {
400 c->desc = NULL;
401 return;
402 }
403
404 list_del(&vd->node);
405
406 c->desc = d = to_omap_dma_desc(&vd->tx);
407 c->sgidx = 0;
408
Russell King59871902013-11-06 17:15:16 +0000409 /*
410 * This provides the necessary barrier to ensure data held in
411 * DMA coherent memory is visible to the DMA engine prior to
412 * the transfer starting.
413 */
414 mb();
415
Russell Kingc5ed98b2013-11-06 17:33:09 +0000416 omap_dma_chan_write(c, CCR, d->ccr);
Russell King3ed4d182013-11-02 19:16:09 +0000417 if (dma_omap1())
Russell Kingc5ed98b2013-11-06 17:33:09 +0000418 omap_dma_chan_write(c, CCR2, d->ccr >> 16);
Russell Kingb9e97822013-11-02 13:26:57 +0000419
Peter Ujfalusi4ce98c02015-04-22 10:34:29 +0300420 if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM) {
Russell King893e63e2013-11-03 11:17:11 +0000421 cxsa = CSSA;
422 cxei = CSEI;
423 cxfi = CSFI;
Russell Kingb9e97822013-11-02 13:26:57 +0000424 } else {
Russell King893e63e2013-11-03 11:17:11 +0000425 cxsa = CDSA;
426 cxei = CDEI;
427 cxfi = CDFI;
Russell Kingb9e97822013-11-02 13:26:57 +0000428 }
Russell King7bedaa52012-04-13 12:10:24 +0100429
Russell Kingc5ed98b2013-11-06 17:33:09 +0000430 omap_dma_chan_write(c, cxsa, d->dev_addr);
Peter Ujfalusiad524652016-07-12 14:21:14 +0300431 omap_dma_chan_write(c, cxei, d->ei);
Russell Kingc5ed98b2013-11-06 17:33:09 +0000432 omap_dma_chan_write(c, cxfi, d->fi);
433 omap_dma_chan_write(c, CSDP, d->csdp);
434 omap_dma_chan_write(c, CLNK_CTRL, d->clnk_ctrl);
Russell King913a2d02013-11-02 14:41:42 +0000435
Russell King7bedaa52012-04-13 12:10:24 +0100436 omap_dma_start_sg(c, d, 0);
437}
438
439static void omap_dma_callback(int ch, u16 status, void *data)
440{
441 struct omap_chan *c = data;
442 struct omap_desc *d;
443 unsigned long flags;
444
445 spin_lock_irqsave(&c->vc.lock, flags);
446 d = c->desc;
447 if (d) {
Russell King3a774ea2012-06-21 10:40:15 +0100448 if (!c->cyclic) {
449 if (++c->sgidx < d->sglen) {
450 omap_dma_start_sg(c, d, c->sgidx);
451 } else {
452 omap_dma_start_desc(c);
453 vchan_cookie_complete(&d->vd);
454 }
Russell King7bedaa52012-04-13 12:10:24 +0100455 } else {
Russell King3a774ea2012-06-21 10:40:15 +0100456 vchan_cyclic_callback(&d->vd);
Russell King7bedaa52012-04-13 12:10:24 +0100457 }
458 }
459 spin_unlock_irqrestore(&c->vc.lock, flags);
460}
461
Russell King6ddeb6d2013-12-10 19:05:50 +0000462static irqreturn_t omap_dma_irq(int irq, void *devid)
463{
464 struct omap_dmadev *od = devid;
465 unsigned status, channel;
466
467 spin_lock(&od->irq_lock);
468
469 status = omap_dma_glbl_read(od, IRQSTATUS_L1);
470 status &= od->irq_enable_mask;
471 if (status == 0) {
472 spin_unlock(&od->irq_lock);
473 return IRQ_NONE;
474 }
475
476 while ((channel = ffs(status)) != 0) {
477 unsigned mask, csr;
478 struct omap_chan *c;
479
480 channel -= 1;
481 mask = BIT(channel);
482 status &= ~mask;
483
484 c = od->lch_map[channel];
485 if (c == NULL) {
486 /* This should never happen */
487 dev_err(od->ddev.dev, "invalid channel %u\n", channel);
488 continue;
489 }
490
491 csr = omap_dma_get_csr(c);
492 omap_dma_glbl_write(od, IRQSTATUS_L1, mask);
493
494 omap_dma_callback(channel, csr, c);
495 }
496
497 spin_unlock(&od->irq_lock);
498
499 return IRQ_HANDLED;
500}
501
Russell King7bedaa52012-04-13 12:10:24 +0100502static int omap_dma_alloc_chan_resources(struct dma_chan *chan)
503{
Russell King596c4712013-12-10 11:08:01 +0000504 struct omap_dmadev *od = to_omap_dma_dev(chan->device);
Russell King7bedaa52012-04-13 12:10:24 +0100505 struct omap_chan *c = to_omap_dma_chan(chan);
Russell King596c4712013-12-10 11:08:01 +0000506 int ret;
Russell King7bedaa52012-04-13 12:10:24 +0100507
Russell King6ddeb6d2013-12-10 19:05:50 +0000508 if (od->legacy) {
509 ret = omap_request_dma(c->dma_sig, "DMA engine",
510 omap_dma_callback, c, &c->dma_ch);
511 } else {
512 ret = omap_request_dma(c->dma_sig, "DMA engine", NULL, NULL,
513 &c->dma_ch);
514 }
Russell King7bedaa52012-04-13 12:10:24 +0100515
Russell King6ddeb6d2013-12-10 19:05:50 +0000516 dev_dbg(od->ddev.dev, "allocating channel %u for %u\n",
517 c->dma_ch, c->dma_sig);
Russell King596c4712013-12-10 11:08:01 +0000518
Russell King6ddeb6d2013-12-10 19:05:50 +0000519 if (ret >= 0) {
Russell King596c4712013-12-10 11:08:01 +0000520 omap_dma_assign(od, c, c->dma_ch);
521
Russell King6ddeb6d2013-12-10 19:05:50 +0000522 if (!od->legacy) {
523 unsigned val;
524
525 spin_lock_irq(&od->irq_lock);
526 val = BIT(c->dma_ch);
527 omap_dma_glbl_write(od, IRQSTATUS_L1, val);
528 od->irq_enable_mask |= val;
529 omap_dma_glbl_write(od, IRQENABLE_L1, od->irq_enable_mask);
530
531 val = omap_dma_glbl_read(od, IRQENABLE_L0);
532 val &= ~BIT(c->dma_ch);
533 omap_dma_glbl_write(od, IRQENABLE_L0, val);
534 spin_unlock_irq(&od->irq_lock);
535 }
536 }
537
Russell Kingaa4c5b92014-01-14 23:58:10 +0000538 if (dma_omap1()) {
539 if (__dma_omap16xx(od->plat->dma_attr)) {
540 c->ccr = CCR_OMAP31_DISABLE;
541 /* Duplicate what plat-omap/dma.c does */
542 c->ccr |= c->dma_ch + 1;
543 } else {
544 c->ccr = c->dma_sig & 0x1f;
545 }
546 } else {
547 c->ccr = c->dma_sig & 0x1f;
548 c->ccr |= (c->dma_sig & ~0x1f) << 14;
549 }
550 if (od->plat->errata & DMA_ERRATA_IFRAME_BUFFERING)
551 c->ccr |= CCR_BUFFERING_DISABLE;
552
Russell King596c4712013-12-10 11:08:01 +0000553 return ret;
Russell King7bedaa52012-04-13 12:10:24 +0100554}
555
556static void omap_dma_free_chan_resources(struct dma_chan *chan)
557{
Russell King6ddeb6d2013-12-10 19:05:50 +0000558 struct omap_dmadev *od = to_omap_dma_dev(chan->device);
Russell King7bedaa52012-04-13 12:10:24 +0100559 struct omap_chan *c = to_omap_dma_chan(chan);
560
Russell King6ddeb6d2013-12-10 19:05:50 +0000561 if (!od->legacy) {
562 spin_lock_irq(&od->irq_lock);
563 od->irq_enable_mask &= ~BIT(c->dma_ch);
564 omap_dma_glbl_write(od, IRQENABLE_L1, od->irq_enable_mask);
565 spin_unlock_irq(&od->irq_lock);
566 }
567
Russell King596c4712013-12-10 11:08:01 +0000568 c->channel_base = NULL;
Russell King6ddeb6d2013-12-10 19:05:50 +0000569 od->lch_map[c->dma_ch] = NULL;
Russell King7bedaa52012-04-13 12:10:24 +0100570 vchan_free_chan_resources(&c->vc);
571 omap_free_dma(c->dma_ch);
572
Russell King6ddeb6d2013-12-10 19:05:50 +0000573 dev_dbg(od->ddev.dev, "freeing channel for %u\n", c->dma_sig);
Peter Ujfalusieea531e2015-04-09 12:35:52 +0300574 c->dma_sig = 0;
Russell King7bedaa52012-04-13 12:10:24 +0100575}
576
Russell King3850e222012-06-21 10:37:35 +0100577static size_t omap_dma_sg_size(struct omap_sg *sg)
578{
579 return sg->en * sg->fn;
580}
581
582static size_t omap_dma_desc_size(struct omap_desc *d)
583{
584 unsigned i;
585 size_t size;
586
587 for (size = i = 0; i < d->sglen; i++)
588 size += omap_dma_sg_size(&d->sg[i]);
589
590 return size * es_bytes[d->es];
591}
592
593static size_t omap_dma_desc_size_pos(struct omap_desc *d, dma_addr_t addr)
594{
595 unsigned i;
596 size_t size, es_size = es_bytes[d->es];
597
598 for (size = i = 0; i < d->sglen; i++) {
599 size_t this_size = omap_dma_sg_size(&d->sg[i]) * es_size;
600
601 if (size)
602 size += this_size;
603 else if (addr >= d->sg[i].addr &&
604 addr < d->sg[i].addr + this_size)
605 size += d->sg[i].addr + this_size - addr;
606 }
607 return size;
608}
609
Russell Kingb07fd622013-11-06 19:26:45 +0000610/*
611 * OMAP 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
612 * read before the DMA controller finished disabling the channel.
613 */
614static uint32_t omap_dma_chan_read_3_3(struct omap_chan *c, unsigned reg)
615{
616 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
617 uint32_t val;
618
619 val = omap_dma_chan_read(c, reg);
620 if (val == 0 && od->plat->errata & DMA_ERRATA_3_3)
621 val = omap_dma_chan_read(c, reg);
622
623 return val;
624}
625
Russell King3997cab2013-11-02 18:04:17 +0000626static dma_addr_t omap_dma_get_src_pos(struct omap_chan *c)
627{
628 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
Russell Kingb07fd622013-11-06 19:26:45 +0000629 dma_addr_t addr, cdac;
Russell King3997cab2013-11-02 18:04:17 +0000630
Russell Kingb07fd622013-11-06 19:26:45 +0000631 if (__dma_omap15xx(od->plat->dma_attr)) {
Russell Kingc5ed98b2013-11-06 17:33:09 +0000632 addr = omap_dma_chan_read(c, CPC);
Russell Kingb07fd622013-11-06 19:26:45 +0000633 } else {
634 addr = omap_dma_chan_read_3_3(c, CSAC);
635 cdac = omap_dma_chan_read_3_3(c, CDAC);
Russell King3997cab2013-11-02 18:04:17 +0000636
Russell King3997cab2013-11-02 18:04:17 +0000637 /*
638 * CDAC == 0 indicates that the DMA transfer on the channel has
639 * not been started (no data has been transferred so far).
640 * Return the programmed source start address in this case.
641 */
Russell Kingb07fd622013-11-06 19:26:45 +0000642 if (cdac == 0)
Russell Kingc5ed98b2013-11-06 17:33:09 +0000643 addr = omap_dma_chan_read(c, CSSA);
Russell King3997cab2013-11-02 18:04:17 +0000644 }
645
646 if (dma_omap1())
Russell Kingc5ed98b2013-11-06 17:33:09 +0000647 addr |= omap_dma_chan_read(c, CSSA) & 0xffff0000;
Russell King3997cab2013-11-02 18:04:17 +0000648
649 return addr;
650}
651
652static dma_addr_t omap_dma_get_dst_pos(struct omap_chan *c)
653{
654 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
655 dma_addr_t addr;
656
Russell Kingb07fd622013-11-06 19:26:45 +0000657 if (__dma_omap15xx(od->plat->dma_attr)) {
Russell Kingc5ed98b2013-11-06 17:33:09 +0000658 addr = omap_dma_chan_read(c, CPC);
Russell Kingb07fd622013-11-06 19:26:45 +0000659 } else {
660 addr = omap_dma_chan_read_3_3(c, CDAC);
Russell King3997cab2013-11-02 18:04:17 +0000661
Russell King3997cab2013-11-02 18:04:17 +0000662 /*
Russell Kingb07fd622013-11-06 19:26:45 +0000663 * CDAC == 0 indicates that the DMA transfer on the channel
664 * has not been started (no data has been transferred so
665 * far). Return the programmed destination start address in
666 * this case.
Russell King3997cab2013-11-02 18:04:17 +0000667 */
668 if (addr == 0)
Russell Kingc5ed98b2013-11-06 17:33:09 +0000669 addr = omap_dma_chan_read(c, CDSA);
Russell King3997cab2013-11-02 18:04:17 +0000670 }
671
672 if (dma_omap1())
Russell Kingc5ed98b2013-11-06 17:33:09 +0000673 addr |= omap_dma_chan_read(c, CDSA) & 0xffff0000;
Russell King3997cab2013-11-02 18:04:17 +0000674
675 return addr;
676}
677
Russell King7bedaa52012-04-13 12:10:24 +0100678static enum dma_status omap_dma_tx_status(struct dma_chan *chan,
679 dma_cookie_t cookie, struct dma_tx_state *txstate)
680{
Russell King3850e222012-06-21 10:37:35 +0100681 struct omap_chan *c = to_omap_dma_chan(chan);
682 struct virt_dma_desc *vd;
683 enum dma_status ret;
684 unsigned long flags;
685
686 ret = dma_cookie_status(chan, cookie, txstate);
Peter Ujfalusi689d3c52016-04-05 15:20:20 +0300687
688 if (!c->paused && c->running) {
689 uint32_t ccr = omap_dma_chan_read(c, CCR);
690 /*
691 * The channel is no longer active, set the return value
692 * accordingly
693 */
694 if (!(ccr & CCR_ENABLE))
695 ret = DMA_COMPLETE;
696 }
697
Vinod Koul7cce5082013-10-16 20:51:54 +0530698 if (ret == DMA_COMPLETE || !txstate)
Russell King3850e222012-06-21 10:37:35 +0100699 return ret;
700
701 spin_lock_irqsave(&c->vc.lock, flags);
702 vd = vchan_find_desc(&c->vc, cookie);
703 if (vd) {
704 txstate->residue = omap_dma_desc_size(to_omap_dma_desc(&vd->tx));
705 } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
706 struct omap_desc *d = c->desc;
707 dma_addr_t pos;
708
709 if (d->dir == DMA_MEM_TO_DEV)
Russell King3997cab2013-11-02 18:04:17 +0000710 pos = omap_dma_get_src_pos(c);
Peter Ujfalusiadf850b2015-11-11 12:37:55 +0200711 else if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM)
Russell King3997cab2013-11-02 18:04:17 +0000712 pos = omap_dma_get_dst_pos(c);
Russell King3850e222012-06-21 10:37:35 +0100713 else
714 pos = 0;
715
716 txstate->residue = omap_dma_desc_size_pos(d, pos);
717 } else {
718 txstate->residue = 0;
719 }
720 spin_unlock_irqrestore(&c->vc.lock, flags);
721
722 return ret;
Russell King7bedaa52012-04-13 12:10:24 +0100723}
724
725static void omap_dma_issue_pending(struct dma_chan *chan)
726{
727 struct omap_chan *c = to_omap_dma_chan(chan);
728 unsigned long flags;
729
730 spin_lock_irqsave(&c->vc.lock, flags);
Peter Ujfalusi1c1d25f2015-11-11 12:37:57 +0200731 if (vchan_issue_pending(&c->vc) && !c->desc)
732 omap_dma_start_desc(c);
Russell King7bedaa52012-04-13 12:10:24 +0100733 spin_unlock_irqrestore(&c->vc.lock, flags);
734}
735
736static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
737 struct dma_chan *chan, struct scatterlist *sgl, unsigned sglen,
738 enum dma_transfer_direction dir, unsigned long tx_flags, void *context)
739{
Russell King49ae0b22013-11-02 21:09:18 +0000740 struct omap_dmadev *od = to_omap_dma_dev(chan->device);
Russell King7bedaa52012-04-13 12:10:24 +0100741 struct omap_chan *c = to_omap_dma_chan(chan);
742 enum dma_slave_buswidth dev_width;
743 struct scatterlist *sgent;
744 struct omap_desc *d;
745 dma_addr_t dev_addr;
Peter Ujfalusie8a5e792015-11-11 12:37:56 +0200746 unsigned i, es, en, frame_bytes;
Russell King7bedaa52012-04-13 12:10:24 +0100747 u32 burst;
748
749 if (dir == DMA_DEV_TO_MEM) {
750 dev_addr = c->cfg.src_addr;
751 dev_width = c->cfg.src_addr_width;
752 burst = c->cfg.src_maxburst;
Russell King7bedaa52012-04-13 12:10:24 +0100753 } else if (dir == DMA_MEM_TO_DEV) {
754 dev_addr = c->cfg.dst_addr;
755 dev_width = c->cfg.dst_addr_width;
756 burst = c->cfg.dst_maxburst;
Russell King7bedaa52012-04-13 12:10:24 +0100757 } else {
758 dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
759 return NULL;
760 }
761
762 /* Bus width translates to the element size (ES) */
763 switch (dev_width) {
764 case DMA_SLAVE_BUSWIDTH_1_BYTE:
Russell King90438262013-11-02 19:57:06 +0000765 es = CSDP_DATA_TYPE_8;
Russell King7bedaa52012-04-13 12:10:24 +0100766 break;
767 case DMA_SLAVE_BUSWIDTH_2_BYTES:
Russell King90438262013-11-02 19:57:06 +0000768 es = CSDP_DATA_TYPE_16;
Russell King7bedaa52012-04-13 12:10:24 +0100769 break;
770 case DMA_SLAVE_BUSWIDTH_4_BYTES:
Russell King90438262013-11-02 19:57:06 +0000771 es = CSDP_DATA_TYPE_32;
Russell King7bedaa52012-04-13 12:10:24 +0100772 break;
773 default: /* not reached */
774 return NULL;
775 }
776
777 /* Now allocate and setup the descriptor. */
778 d = kzalloc(sizeof(*d) + sglen * sizeof(d->sg[0]), GFP_ATOMIC);
779 if (!d)
780 return NULL;
781
782 d->dir = dir;
783 d->dev_addr = dev_addr;
784 d->es = es;
Russell King3ed4d182013-11-02 19:16:09 +0000785
Russell Kingaa4c5b92014-01-14 23:58:10 +0000786 d->ccr = c->ccr | CCR_SYNC_FRAME;
Russell King3ed4d182013-11-02 19:16:09 +0000787 if (dir == DMA_DEV_TO_MEM)
Russell King90438262013-11-02 19:57:06 +0000788 d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT;
Russell King3ed4d182013-11-02 19:16:09 +0000789 else
Russell King90438262013-11-02 19:57:06 +0000790 d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC;
Russell King3ed4d182013-11-02 19:16:09 +0000791
Russell King90438262013-11-02 19:57:06 +0000792 d->cicr = CICR_DROP_IE | CICR_BLOCK_IE;
Russell King2f0d13b2013-11-02 18:51:53 +0000793 d->csdp = es;
Russell Kingfa3ad862013-11-02 17:07:09 +0000794
Russell King2f0d13b2013-11-02 18:51:53 +0000795 if (dma_omap1()) {
Russell King90438262013-11-02 19:57:06 +0000796 d->cicr |= CICR_TOUT_IE;
Russell King2f0d13b2013-11-02 18:51:53 +0000797
798 if (dir == DMA_DEV_TO_MEM)
Russell King90438262013-11-02 19:57:06 +0000799 d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_TIPB;
Russell King2f0d13b2013-11-02 18:51:53 +0000800 else
Russell King90438262013-11-02 19:57:06 +0000801 d->csdp |= CSDP_DST_PORT_TIPB | CSDP_SRC_PORT_EMIFF;
Russell King2f0d13b2013-11-02 18:51:53 +0000802 } else {
Russell King3ed4d182013-11-02 19:16:09 +0000803 if (dir == DMA_DEV_TO_MEM)
Russell King90438262013-11-02 19:57:06 +0000804 d->ccr |= CCR_TRIGGER_SRC;
Russell King3ed4d182013-11-02 19:16:09 +0000805
Russell King90438262013-11-02 19:57:06 +0000806 d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE;
Russell King2f0d13b2013-11-02 18:51:53 +0000807 }
Russell King965aeb4d2013-11-06 17:12:30 +0000808 if (od->plat->errata & DMA_ERRATA_PARALLEL_CHANNELS)
809 d->clnk_ctrl = c->dma_ch;
Russell King7bedaa52012-04-13 12:10:24 +0100810
811 /*
812 * Build our scatterlist entries: each contains the address,
813 * the number of elements (EN) in each frame, and the number of
814 * frames (FN). Number of bytes for this entry = ES * EN * FN.
815 *
816 * Burst size translates to number of elements with frame sync.
817 * Note: DMA engine defines burst to be the number of dev-width
818 * transfers.
819 */
820 en = burst;
821 frame_bytes = es_bytes[es] * en;
822 for_each_sg(sgl, sgent, sglen, i) {
Peter Ujfalusie8a5e792015-11-11 12:37:56 +0200823 d->sg[i].addr = sg_dma_address(sgent);
824 d->sg[i].en = en;
825 d->sg[i].fn = sg_dma_len(sgent) / frame_bytes;
Russell King7bedaa52012-04-13 12:10:24 +0100826 }
827
Peter Ujfalusie8a5e792015-11-11 12:37:56 +0200828 d->sglen = sglen;
Russell King7bedaa52012-04-13 12:10:24 +0100829
830 return vchan_tx_prep(&c->vc, &d->vd, tx_flags);
831}
832
Russell King3a774ea2012-06-21 10:40:15 +0100833static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic(
834 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
Laurent Pinchart31c1e5a2014-08-01 12:20:10 +0200835 size_t period_len, enum dma_transfer_direction dir, unsigned long flags)
Russell King3a774ea2012-06-21 10:40:15 +0100836{
Russell Kingfa3ad862013-11-02 17:07:09 +0000837 struct omap_dmadev *od = to_omap_dma_dev(chan->device);
Russell King3a774ea2012-06-21 10:40:15 +0100838 struct omap_chan *c = to_omap_dma_chan(chan);
839 enum dma_slave_buswidth dev_width;
840 struct omap_desc *d;
841 dma_addr_t dev_addr;
Russell King3ed4d182013-11-02 19:16:09 +0000842 unsigned es;
Russell King3a774ea2012-06-21 10:40:15 +0100843 u32 burst;
844
845 if (dir == DMA_DEV_TO_MEM) {
846 dev_addr = c->cfg.src_addr;
847 dev_width = c->cfg.src_addr_width;
848 burst = c->cfg.src_maxburst;
Russell King3a774ea2012-06-21 10:40:15 +0100849 } else if (dir == DMA_MEM_TO_DEV) {
850 dev_addr = c->cfg.dst_addr;
851 dev_width = c->cfg.dst_addr_width;
852 burst = c->cfg.dst_maxburst;
Russell King3a774ea2012-06-21 10:40:15 +0100853 } else {
854 dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
855 return NULL;
856 }
857
858 /* Bus width translates to the element size (ES) */
859 switch (dev_width) {
860 case DMA_SLAVE_BUSWIDTH_1_BYTE:
Russell King90438262013-11-02 19:57:06 +0000861 es = CSDP_DATA_TYPE_8;
Russell King3a774ea2012-06-21 10:40:15 +0100862 break;
863 case DMA_SLAVE_BUSWIDTH_2_BYTES:
Russell King90438262013-11-02 19:57:06 +0000864 es = CSDP_DATA_TYPE_16;
Russell King3a774ea2012-06-21 10:40:15 +0100865 break;
866 case DMA_SLAVE_BUSWIDTH_4_BYTES:
Russell King90438262013-11-02 19:57:06 +0000867 es = CSDP_DATA_TYPE_32;
Russell King3a774ea2012-06-21 10:40:15 +0100868 break;
869 default: /* not reached */
870 return NULL;
871 }
872
873 /* Now allocate and setup the descriptor. */
874 d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC);
875 if (!d)
876 return NULL;
877
878 d->dir = dir;
879 d->dev_addr = dev_addr;
880 d->fi = burst;
881 d->es = es;
Russell King3a774ea2012-06-21 10:40:15 +0100882 d->sg[0].addr = buf_addr;
883 d->sg[0].en = period_len / es_bytes[es];
884 d->sg[0].fn = buf_len / period_len;
885 d->sglen = 1;
Russell King3ed4d182013-11-02 19:16:09 +0000886
Russell Kingaa4c5b92014-01-14 23:58:10 +0000887 d->ccr = c->ccr;
Russell King3ed4d182013-11-02 19:16:09 +0000888 if (dir == DMA_DEV_TO_MEM)
Russell King90438262013-11-02 19:57:06 +0000889 d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT;
Russell King3ed4d182013-11-02 19:16:09 +0000890 else
Russell King90438262013-11-02 19:57:06 +0000891 d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC;
Russell King3ed4d182013-11-02 19:16:09 +0000892
Russell King90438262013-11-02 19:57:06 +0000893 d->cicr = CICR_DROP_IE;
Russell Kingfa3ad862013-11-02 17:07:09 +0000894 if (flags & DMA_PREP_INTERRUPT)
Russell King90438262013-11-02 19:57:06 +0000895 d->cicr |= CICR_FRAME_IE;
Russell Kingfa3ad862013-11-02 17:07:09 +0000896
Russell King2f0d13b2013-11-02 18:51:53 +0000897 d->csdp = es;
898
899 if (dma_omap1()) {
Russell King90438262013-11-02 19:57:06 +0000900 d->cicr |= CICR_TOUT_IE;
Russell King2f0d13b2013-11-02 18:51:53 +0000901
902 if (dir == DMA_DEV_TO_MEM)
Russell King90438262013-11-02 19:57:06 +0000903 d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_MPUI;
Russell King2f0d13b2013-11-02 18:51:53 +0000904 else
Russell King90438262013-11-02 19:57:06 +0000905 d->csdp |= CSDP_DST_PORT_MPUI | CSDP_SRC_PORT_EMIFF;
Russell King2f0d13b2013-11-02 18:51:53 +0000906 } else {
Russell King3ed4d182013-11-02 19:16:09 +0000907 if (burst)
Russell King90438262013-11-02 19:57:06 +0000908 d->ccr |= CCR_SYNC_PACKET;
909 else
910 d->ccr |= CCR_SYNC_ELEMENT;
Russell King3ed4d182013-11-02 19:16:09 +0000911
Misael Lopez Cruz47fac242015-09-14 15:31:05 +0300912 if (dir == DMA_DEV_TO_MEM) {
Russell King90438262013-11-02 19:57:06 +0000913 d->ccr |= CCR_TRIGGER_SRC;
Misael Lopez Cruz47fac242015-09-14 15:31:05 +0300914 d->csdp |= CSDP_DST_PACKED;
915 } else {
916 d->csdp |= CSDP_SRC_PACKED;
917 }
Russell King3ed4d182013-11-02 19:16:09 +0000918
Russell King90438262013-11-02 19:57:06 +0000919 d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE;
Russell King3a774ea2012-06-21 10:40:15 +0100920
Russell King90438262013-11-02 19:57:06 +0000921 d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64;
Russell King2f0d13b2013-11-02 18:51:53 +0000922 }
923
Russell King965aeb4d2013-11-06 17:12:30 +0000924 if (__dma_omap15xx(od->plat->dma_attr))
925 d->ccr |= CCR_AUTO_INIT | CCR_REPEAT;
926 else
927 d->clnk_ctrl = c->dma_ch | CLNK_CTRL_ENABLE_LNK;
928
Russell King3ed4d182013-11-02 19:16:09 +0000929 c->cyclic = true;
Russell King3a774ea2012-06-21 10:40:15 +0100930
Peter Ujfalusi2dde5b92012-09-14 15:05:48 +0300931 return vchan_tx_prep(&c->vc, &d->vd, flags);
Russell King3a774ea2012-06-21 10:40:15 +0100932}
933
Peter Ujfalusi4ce98c02015-04-22 10:34:29 +0300934static struct dma_async_tx_descriptor *omap_dma_prep_dma_memcpy(
935 struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
936 size_t len, unsigned long tx_flags)
937{
938 struct omap_chan *c = to_omap_dma_chan(chan);
939 struct omap_desc *d;
940 uint8_t data_type;
941
942 d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC);
943 if (!d)
944 return NULL;
945
946 data_type = __ffs((src | dest | len));
947 if (data_type > CSDP_DATA_TYPE_32)
948 data_type = CSDP_DATA_TYPE_32;
949
950 d->dir = DMA_MEM_TO_MEM;
951 d->dev_addr = src;
952 d->fi = 0;
953 d->es = data_type;
954 d->sg[0].en = len / BIT(data_type);
955 d->sg[0].fn = 1;
956 d->sg[0].addr = dest;
957 d->sglen = 1;
958 d->ccr = c->ccr;
959 d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_POSTINC;
960
Peter Ujfalusib96c0332016-04-05 15:20:21 +0300961 d->cicr = CICR_DROP_IE | CICR_FRAME_IE;
Peter Ujfalusi4ce98c02015-04-22 10:34:29 +0300962
963 d->csdp = data_type;
964
965 if (dma_omap1()) {
966 d->cicr |= CICR_TOUT_IE;
967 d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_EMIFF;
968 } else {
969 d->csdp |= CSDP_DST_PACKED | CSDP_SRC_PACKED;
970 d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE;
971 d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64;
972 }
973
974 return vchan_tx_prep(&c->vc, &d->vd, tx_flags);
975}
976
Peter Ujfalusiad524652016-07-12 14:21:14 +0300977static struct dma_async_tx_descriptor *omap_dma_prep_dma_interleaved(
978 struct dma_chan *chan, struct dma_interleaved_template *xt,
979 unsigned long flags)
980{
981 struct omap_chan *c = to_omap_dma_chan(chan);
982 struct omap_desc *d;
983 struct omap_sg *sg;
984 uint8_t data_type;
985 size_t src_icg, dst_icg;
986
987 /* Slave mode is not supported */
988 if (is_slave_direction(xt->dir))
989 return NULL;
990
991 if (xt->frame_size != 1 || xt->numf == 0)
992 return NULL;
993
994 d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC);
995 if (!d)
996 return NULL;
997
998 data_type = __ffs((xt->src_start | xt->dst_start | xt->sgl[0].size));
999 if (data_type > CSDP_DATA_TYPE_32)
1000 data_type = CSDP_DATA_TYPE_32;
1001
1002 sg = &d->sg[0];
1003 d->dir = DMA_MEM_TO_MEM;
1004 d->dev_addr = xt->src_start;
1005 d->es = data_type;
1006 sg->en = xt->sgl[0].size / BIT(data_type);
1007 sg->fn = xt->numf;
1008 sg->addr = xt->dst_start;
1009 d->sglen = 1;
1010 d->ccr = c->ccr;
1011
1012 src_icg = dmaengine_get_src_icg(xt, &xt->sgl[0]);
1013 dst_icg = dmaengine_get_dst_icg(xt, &xt->sgl[0]);
1014 if (src_icg) {
1015 d->ccr |= CCR_SRC_AMODE_DBLIDX;
1016 d->ei = 1;
1017 d->fi = src_icg;
1018 } else if (xt->src_inc) {
1019 d->ccr |= CCR_SRC_AMODE_POSTINC;
1020 d->fi = 0;
1021 } else {
1022 dev_err(chan->device->dev,
1023 "%s: SRC constant addressing is not supported\n",
1024 __func__);
1025 kfree(d);
1026 return NULL;
1027 }
1028
1029 if (dst_icg) {
1030 d->ccr |= CCR_DST_AMODE_DBLIDX;
1031 sg->ei = 1;
1032 sg->fi = dst_icg;
1033 } else if (xt->dst_inc) {
1034 d->ccr |= CCR_DST_AMODE_POSTINC;
1035 sg->fi = 0;
1036 } else {
1037 dev_err(chan->device->dev,
1038 "%s: DST constant addressing is not supported\n",
1039 __func__);
1040 kfree(d);
1041 return NULL;
1042 }
1043
1044 d->cicr = CICR_DROP_IE | CICR_FRAME_IE;
1045
1046 d->csdp = data_type;
1047
1048 if (dma_omap1()) {
1049 d->cicr |= CICR_TOUT_IE;
1050 d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_EMIFF;
1051 } else {
1052 d->csdp |= CSDP_DST_PACKED | CSDP_SRC_PACKED;
1053 d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE;
1054 d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64;
1055 }
1056
1057 return vchan_tx_prep(&c->vc, &d->vd, flags);
1058}
1059
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001060static int omap_dma_slave_config(struct dma_chan *chan, struct dma_slave_config *cfg)
Russell King7bedaa52012-04-13 12:10:24 +01001061{
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001062 struct omap_chan *c = to_omap_dma_chan(chan);
1063
Russell King7bedaa52012-04-13 12:10:24 +01001064 if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
1065 cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
1066 return -EINVAL;
1067
1068 memcpy(&c->cfg, cfg, sizeof(c->cfg));
1069
1070 return 0;
1071}
1072
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001073static int omap_dma_terminate_all(struct dma_chan *chan)
Russell King7bedaa52012-04-13 12:10:24 +01001074{
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001075 struct omap_chan *c = to_omap_dma_chan(chan);
Russell King7bedaa52012-04-13 12:10:24 +01001076 unsigned long flags;
1077 LIST_HEAD(head);
1078
1079 spin_lock_irqsave(&c->vc.lock, flags);
1080
Russell King7bedaa52012-04-13 12:10:24 +01001081 /*
1082 * Stop DMA activity: we assume the callback will not be called
Russell Kingfa3ad862013-11-02 17:07:09 +00001083 * after omap_dma_stop() returns (even if it does, it will see
Russell King7bedaa52012-04-13 12:10:24 +01001084 * c->desc is NULL and exit.)
1085 */
1086 if (c->desc) {
Peter Ujfalusi02d88b72015-03-27 13:35:52 +02001087 omap_dma_desc_free(&c->desc->vd);
Russell King7bedaa52012-04-13 12:10:24 +01001088 c->desc = NULL;
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +03001089 /* Avoid stopping the dma twice */
1090 if (!c->paused)
Russell Kingfa3ad862013-11-02 17:07:09 +00001091 omap_dma_stop(c);
Russell King7bedaa52012-04-13 12:10:24 +01001092 }
1093
Russell King3a774ea2012-06-21 10:40:15 +01001094 if (c->cyclic) {
1095 c->cyclic = false;
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +03001096 c->paused = false;
Russell King3a774ea2012-06-21 10:40:15 +01001097 }
1098
Russell King7bedaa52012-04-13 12:10:24 +01001099 vchan_get_all_descriptors(&c->vc, &head);
1100 spin_unlock_irqrestore(&c->vc.lock, flags);
1101 vchan_dma_desc_free_list(&c->vc, &head);
1102
1103 return 0;
1104}
1105
Peter Ujfalusi9bef6d82016-02-11 11:08:34 +02001106static void omap_dma_synchronize(struct dma_chan *chan)
1107{
1108 struct omap_chan *c = to_omap_dma_chan(chan);
1109
1110 vchan_synchronize(&c->vc);
1111}
1112
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001113static int omap_dma_pause(struct dma_chan *chan)
Russell King7bedaa52012-04-13 12:10:24 +01001114{
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001115 struct omap_chan *c = to_omap_dma_chan(chan);
1116
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +03001117 /* Pause/Resume only allowed with cyclic mode */
1118 if (!c->cyclic)
1119 return -EINVAL;
1120
1121 if (!c->paused) {
Russell Kingfa3ad862013-11-02 17:07:09 +00001122 omap_dma_stop(c);
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +03001123 c->paused = true;
1124 }
1125
1126 return 0;
Russell King7bedaa52012-04-13 12:10:24 +01001127}
1128
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001129static int omap_dma_resume(struct dma_chan *chan)
Russell King7bedaa52012-04-13 12:10:24 +01001130{
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001131 struct omap_chan *c = to_omap_dma_chan(chan);
1132
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +03001133 /* Pause/Resume only allowed with cyclic mode */
1134 if (!c->cyclic)
1135 return -EINVAL;
1136
1137 if (c->paused) {
Peter Ujfalusib3d09da2014-09-16 22:45:56 +03001138 mb();
1139
Peter Ujfalusibfb60742014-09-16 22:45:57 +03001140 /* Restore channel link register */
1141 omap_dma_chan_write(c, CLNK_CTRL, c->desc->clnk_ctrl);
1142
Russell Kingfa3ad862013-11-02 17:07:09 +00001143 omap_dma_start(c, c->desc);
Peter Ujfalusi2dcdf572012-09-14 15:05:45 +03001144 c->paused = false;
1145 }
1146
1147 return 0;
Russell King7bedaa52012-04-13 12:10:24 +01001148}
1149
Peter Ujfalusieea531e2015-04-09 12:35:52 +03001150static int omap_dma_chan_init(struct omap_dmadev *od)
Russell King7bedaa52012-04-13 12:10:24 +01001151{
1152 struct omap_chan *c;
1153
1154 c = kzalloc(sizeof(*c), GFP_KERNEL);
1155 if (!c)
1156 return -ENOMEM;
1157
Russell King596c4712013-12-10 11:08:01 +00001158 c->reg_map = od->reg_map;
Russell King7bedaa52012-04-13 12:10:24 +01001159 c->vc.desc_free = omap_dma_desc_free;
1160 vchan_init(&c->vc, &od->ddev);
Russell King7bedaa52012-04-13 12:10:24 +01001161
Russell King7bedaa52012-04-13 12:10:24 +01001162 return 0;
1163}
1164
1165static void omap_dma_free(struct omap_dmadev *od)
1166{
Russell King7bedaa52012-04-13 12:10:24 +01001167 while (!list_empty(&od->ddev.channels)) {
1168 struct omap_chan *c = list_first_entry(&od->ddev.channels,
1169 struct omap_chan, vc.chan.device_node);
1170
1171 list_del(&c->vc.chan.device_node);
1172 tasklet_kill(&c->vc.task);
1173 kfree(c);
1174 }
Russell King7bedaa52012-04-13 12:10:24 +01001175}
1176
Peter Ujfalusi80b0e0a2014-03-29 19:03:30 +05301177#define OMAP_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
1178 BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
1179 BIT(DMA_SLAVE_BUSWIDTH_4_BYTES))
1180
Russell King7bedaa52012-04-13 12:10:24 +01001181static int omap_dma_probe(struct platform_device *pdev)
1182{
1183 struct omap_dmadev *od;
Russell King596c4712013-12-10 11:08:01 +00001184 struct resource *res;
Russell King6ddeb6d2013-12-10 19:05:50 +00001185 int rc, i, irq;
Russell King7bedaa52012-04-13 12:10:24 +01001186
Russell King104fce72013-11-02 12:58:29 +00001187 od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
Russell King7bedaa52012-04-13 12:10:24 +01001188 if (!od)
1189 return -ENOMEM;
1190
Russell King596c4712013-12-10 11:08:01 +00001191 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1192 od->base = devm_ioremap_resource(&pdev->dev, res);
1193 if (IS_ERR(od->base))
1194 return PTR_ERR(od->base);
1195
Russell King1b416c42013-11-02 13:00:03 +00001196 od->plat = omap_get_plat_info();
1197 if (!od->plat)
1198 return -EPROBE_DEFER;
1199
Russell King596c4712013-12-10 11:08:01 +00001200 od->reg_map = od->plat->reg_map;
1201
Russell King7bedaa52012-04-13 12:10:24 +01001202 dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
Russell King3a774ea2012-06-21 10:40:15 +01001203 dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
Peter Ujfalusi4ce98c02015-04-22 10:34:29 +03001204 dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask);
Peter Ujfalusiad524652016-07-12 14:21:14 +03001205 dma_cap_set(DMA_INTERLEAVE, od->ddev.cap_mask);
Russell King7bedaa52012-04-13 12:10:24 +01001206 od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources;
1207 od->ddev.device_free_chan_resources = omap_dma_free_chan_resources;
1208 od->ddev.device_tx_status = omap_dma_tx_status;
1209 od->ddev.device_issue_pending = omap_dma_issue_pending;
1210 od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg;
Russell King3a774ea2012-06-21 10:40:15 +01001211 od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic;
Peter Ujfalusi4ce98c02015-04-22 10:34:29 +03001212 od->ddev.device_prep_dma_memcpy = omap_dma_prep_dma_memcpy;
Peter Ujfalusiad524652016-07-12 14:21:14 +03001213 od->ddev.device_prep_interleaved_dma = omap_dma_prep_dma_interleaved;
Vinod Koul6c04cd42014-12-07 23:12:31 +05301214 od->ddev.device_config = omap_dma_slave_config;
Maxime Ripard78ea4fe2014-11-17 14:42:28 +01001215 od->ddev.device_pause = omap_dma_pause;
1216 od->ddev.device_resume = omap_dma_resume;
1217 od->ddev.device_terminate_all = omap_dma_terminate_all;
Peter Ujfalusi9bef6d82016-02-11 11:08:34 +02001218 od->ddev.device_synchronize = omap_dma_synchronize;
Maxime Ripard7d15b872014-11-17 14:42:49 +01001219 od->ddev.src_addr_widths = OMAP_DMA_BUSWIDTHS;
1220 od->ddev.dst_addr_widths = OMAP_DMA_BUSWIDTHS;
1221 od->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
1222 od->ddev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
Russell King7bedaa52012-04-13 12:10:24 +01001223 od->ddev.dev = &pdev->dev;
1224 INIT_LIST_HEAD(&od->ddev.channels);
Russell King7bedaa52012-04-13 12:10:24 +01001225 spin_lock_init(&od->lock);
Russell King6ddeb6d2013-12-10 19:05:50 +00001226 spin_lock_init(&od->irq_lock);
Russell King7bedaa52012-04-13 12:10:24 +01001227
Peter Ujfaluside506082015-04-09 12:35:51 +03001228 od->dma_requests = OMAP_SDMA_REQUESTS;
1229 if (pdev->dev.of_node && of_property_read_u32(pdev->dev.of_node,
1230 "dma-requests",
1231 &od->dma_requests)) {
1232 dev_info(&pdev->dev,
1233 "Missing dma-requests property, using %u.\n",
1234 OMAP_SDMA_REQUESTS);
1235 }
1236
Peter Ujfalusi8a322222015-04-09 12:35:53 +03001237 for (i = 0; i < OMAP_SDMA_CHANNELS; i++) {
Peter Ujfalusieea531e2015-04-09 12:35:52 +03001238 rc = omap_dma_chan_init(od);
Russell King7bedaa52012-04-13 12:10:24 +01001239 if (rc) {
1240 omap_dma_free(od);
1241 return rc;
1242 }
1243 }
1244
Russell King6ddeb6d2013-12-10 19:05:50 +00001245 irq = platform_get_irq(pdev, 1);
1246 if (irq <= 0) {
1247 dev_info(&pdev->dev, "failed to get L1 IRQ: %d\n", irq);
1248 od->legacy = true;
1249 } else {
1250 /* Disable all interrupts */
1251 od->irq_enable_mask = 0;
1252 omap_dma_glbl_write(od, IRQENABLE_L1, 0);
1253
1254 rc = devm_request_irq(&pdev->dev, irq, omap_dma_irq,
1255 IRQF_SHARED, "omap-dma-engine", od);
1256 if (rc)
1257 return rc;
1258 }
1259
Peter Ujfalusi020c62a2015-12-14 22:47:42 +02001260 od->ddev.filter.map = od->plat->slave_map;
1261 od->ddev.filter.mapcnt = od->plat->slavecnt;
1262 od->ddev.filter.fn = omap_dma_filter_fn;
1263
Russell King7bedaa52012-04-13 12:10:24 +01001264 rc = dma_async_device_register(&od->ddev);
1265 if (rc) {
1266 pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n",
1267 rc);
1268 omap_dma_free(od);
Jon Hunter8d306622013-02-26 12:27:24 -06001269 return rc;
1270 }
1271
1272 platform_set_drvdata(pdev, od);
1273
1274 if (pdev->dev.of_node) {
1275 omap_dma_info.dma_cap = od->ddev.cap_mask;
1276
1277 /* Device-tree DMA controller registration */
1278 rc = of_dma_controller_register(pdev->dev.of_node,
1279 of_dma_simple_xlate, &omap_dma_info);
1280 if (rc) {
1281 pr_warn("OMAP-DMA: failed to register DMA controller\n");
1282 dma_async_device_unregister(&od->ddev);
1283 omap_dma_free(od);
1284 }
Russell King7bedaa52012-04-13 12:10:24 +01001285 }
1286
1287 dev_info(&pdev->dev, "OMAP DMA engine driver\n");
1288
1289 return rc;
1290}
1291
1292static int omap_dma_remove(struct platform_device *pdev)
1293{
1294 struct omap_dmadev *od = platform_get_drvdata(pdev);
Vinod Koul898dbbf2016-07-05 09:58:33 +05301295 int irq;
Russell King7bedaa52012-04-13 12:10:24 +01001296
Jon Hunter8d306622013-02-26 12:27:24 -06001297 if (pdev->dev.of_node)
1298 of_dma_controller_free(pdev->dev.of_node);
1299
Vinod Koul898dbbf2016-07-05 09:58:33 +05301300 irq = platform_get_irq(pdev, 1);
1301 devm_free_irq(&pdev->dev, irq, od);
1302
Russell King7bedaa52012-04-13 12:10:24 +01001303 dma_async_device_unregister(&od->ddev);
Russell King6ddeb6d2013-12-10 19:05:50 +00001304
1305 if (!od->legacy) {
1306 /* Disable all interrupts */
1307 omap_dma_glbl_write(od, IRQENABLE_L0, 0);
1308 }
1309
Russell King7bedaa52012-04-13 12:10:24 +01001310 omap_dma_free(od);
1311
1312 return 0;
1313}
1314
Jon Hunter8d306622013-02-26 12:27:24 -06001315static const struct of_device_id omap_dma_match[] = {
1316 { .compatible = "ti,omap2420-sdma", },
1317 { .compatible = "ti,omap2430-sdma", },
1318 { .compatible = "ti,omap3430-sdma", },
1319 { .compatible = "ti,omap3630-sdma", },
1320 { .compatible = "ti,omap4430-sdma", },
1321 {},
1322};
1323MODULE_DEVICE_TABLE(of, omap_dma_match);
1324
Russell King7bedaa52012-04-13 12:10:24 +01001325static struct platform_driver omap_dma_driver = {
1326 .probe = omap_dma_probe,
1327 .remove = omap_dma_remove,
1328 .driver = {
1329 .name = "omap-dma-engine",
Jon Hunter8d306622013-02-26 12:27:24 -06001330 .of_match_table = of_match_ptr(omap_dma_match),
Russell King7bedaa52012-04-13 12:10:24 +01001331 },
1332};
1333
1334bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
1335{
1336 if (chan->device->dev->driver == &omap_dma_driver.driver) {
Peter Ujfalusieea531e2015-04-09 12:35:52 +03001337 struct omap_dmadev *od = to_omap_dma_dev(chan->device);
Russell King7bedaa52012-04-13 12:10:24 +01001338 struct omap_chan *c = to_omap_dma_chan(chan);
1339 unsigned req = *(unsigned *)param;
1340
Peter Ujfalusieea531e2015-04-09 12:35:52 +03001341 if (req <= od->dma_requests) {
1342 c->dma_sig = req;
1343 return true;
1344 }
Russell King7bedaa52012-04-13 12:10:24 +01001345 }
1346 return false;
1347}
1348EXPORT_SYMBOL_GPL(omap_dma_filter_fn);
1349
Russell King7bedaa52012-04-13 12:10:24 +01001350static int omap_dma_init(void)
1351{
Tony Lindgrenbe1f9482013-01-11 11:24:19 -08001352 return platform_driver_register(&omap_dma_driver);
Russell King7bedaa52012-04-13 12:10:24 +01001353}
1354subsys_initcall(omap_dma_init);
1355
1356static void __exit omap_dma_exit(void)
1357{
Russell King7bedaa52012-04-13 12:10:24 +01001358 platform_driver_unregister(&omap_dma_driver);
1359}
1360module_exit(omap_dma_exit);
1361
1362MODULE_AUTHOR("Russell King");
1363MODULE_LICENSE("GPL");