13 #include <linux/list.h>
14 #include <linux/module.h>
17 #include <linux/slab.h>
67 static const unsigned es_bytes[] = {
111 static void omap_dma_start_desc(
struct omap_chan *c)
123 c->
desc = d = to_omap_dma_desc(&vd->
tx);
133 omap_dma_start_sg(c, d, 0);
136 static void omap_dma_callback(
int ch,
u16 status,
void *
data)
147 omap_dma_start_sg(c, d, c->
sgidx);
149 omap_dma_start_desc(c);
150 vchan_cookie_complete(&d->
vd);
153 vchan_cyclic_callback(&d->
vd);
156 spin_unlock_irqrestore(&c->
vc.lock, flags);
166 static void omap_dma_sched(
unsigned long data)
171 spin_lock_irq(&d->
lock);
173 spin_unlock_irq(&d->
lock);
175 while (!list_empty(&
head)) {
179 spin_lock_irq(&c->
vc.lock);
180 list_del_init(&c->
node);
181 omap_dma_start_desc(c);
182 spin_unlock_irq(&c->
vc.lock);
186 static int omap_dma_alloc_chan_resources(
struct dma_chan *
chan)
188 struct omap_chan *c = to_omap_dma_chan(chan);
193 omap_dma_callback, c, &c->
dma_ch);
196 static void omap_dma_free_chan_resources(
struct dma_chan *
chan)
198 struct omap_chan *c = to_omap_dma_chan(chan);
200 vchan_free_chan_resources(&c->
vc);
206 static size_t omap_dma_sg_size(
struct omap_sg *sg)
208 return sg->
en * sg->
fn;
211 static size_t omap_dma_desc_size(
struct omap_desc *d)
216 for (size = i = 0; i < d->
sglen; i++)
217 size += omap_dma_sg_size(&d->
sg[i]);
219 return size * es_bytes[d->
es];
225 size_t size, es_size = es_bytes[d->
es];
227 for (size = i = 0; i < d->
sglen; i++) {
228 size_t this_size = omap_dma_sg_size(&d->
sg[i]) * es_size;
232 else if (addr >= d->
sg[i].addr &&
233 addr < d->sg[i].
addr + this_size)
234 size += d->
sg[
i].addr + this_size -
addr;
242 struct omap_chan *c = to_omap_dma_chan(chan);
247 ret = dma_cookie_status(chan, cookie, txstate);
254 txstate->
residue = omap_dma_desc_size(to_omap_dma_desc(&vd->
tx));
255 }
else if (c->
desc && c->
desc->vd.tx.cookie == cookie) {
266 txstate->
residue = omap_dma_desc_size_pos(d, pos);
270 spin_unlock_irqrestore(&c->
vc.lock, flags);
275 static void omap_dma_issue_pending(
struct dma_chan *chan)
277 struct omap_chan *c = to_omap_dma_chan(chan);
281 if (vchan_issue_pending(&c->
vc) && !c->
desc) {
284 if (list_empty(&c->
node))
286 spin_unlock(&d->
lock);
287 tasklet_schedule(&d->
task);
289 spin_unlock_irqrestore(&c->
vc.lock, flags);
296 struct omap_chan *c = to_omap_dma_chan(chan);
305 dev_addr = c->
cfg.src_addr;
306 dev_width = c->
cfg.src_addr_width;
307 burst = c->
cfg.src_maxburst;
310 dev_addr = c->
cfg.dst_addr;
311 dev_width = c->
cfg.dst_addr_width;
312 burst = c->
cfg.dst_maxburst;
315 dev_err(chan->
device->dev,
"%s: bad direction?\n", __func__);
335 d = kzalloc(
sizeof(*d) + sglen *
sizeof(d->
sg[0]),
GFP_ATOMIC);
356 frame_bytes = es_bytes[
es] * en;
366 return vchan_tx_prep(&c->
vc, &d->
vd, tx_flags);
374 struct omap_chan *c = to_omap_dma_chan(chan);
382 dev_addr = c->
cfg.src_addr;
383 dev_width = c->
cfg.src_addr_width;
384 burst = c->
cfg.src_maxburst;
387 dev_addr = c->
cfg.dst_addr;
388 dev_width = c->
cfg.dst_addr_width;
389 burst = c->
cfg.dst_maxburst;
392 dev_err(chan->
device->dev,
"%s: bad direction?\n", __func__);
427 d->
sg[0].en = period_len / es_bytes[
es];
428 d->
sg[0].fn = buf_len / period_len;
446 return vchan_tx_prep(&c->
vc, &d->
vd, flags);
460 static int omap_dma_terminate_all(
struct omap_chan *c)
470 list_del_init(&c->
node);
471 spin_unlock(&d->
lock);
491 vchan_get_all_descriptors(&c->
vc, &
head);
492 spin_unlock_irqrestore(&c->
vc.lock, flags);
498 static int omap_dma_pause(
struct omap_chan *c)
512 static int omap_dma_resume(
struct omap_chan *c)
529 struct omap_chan *c = to_omap_dma_chan(chan);
538 ret = omap_dma_terminate_all(c);
542 ret = omap_dma_pause(c);
546 ret = omap_dma_resume(c);
566 c->
vc.desc_free = omap_dma_desc_free;
568 INIT_LIST_HEAD(&c->
node);
578 while (!list_empty(&od->
ddev.channels)) {
600 od->
ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources;
601 od->
ddev.device_free_chan_resources = omap_dma_free_chan_resources;
602 od->
ddev.device_tx_status = omap_dma_tx_status;
603 od->
ddev.device_issue_pending = omap_dma_issue_pending;
604 od->
ddev.device_prep_slave_sg = omap_dma_prep_slave_sg;
605 od->
ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic;
606 od->
ddev.device_control = omap_dma_control;
608 INIT_LIST_HEAD(&od->
ddev.channels);
614 for (i = 0; i < 127; i++) {
615 rc = omap_dma_chan_init(od, i);
624 pr_warn(
"OMAP-DMA: failed to register slave DMA engine device: %d\n",
628 platform_set_drvdata(pdev, od);
638 struct omap_dmadev *od = platform_get_drvdata(pdev);
647 .probe = omap_dma_probe,
648 .remove = omap_dma_remove,
650 .name =
"omap-dma-engine",
657 if (chan->
device->dev->driver == &omap_dma_driver.
driver) {
658 struct omap_chan *c = to_omap_dma_chan(chan);
659 unsigned req = *(
unsigned *)param;
670 .name =
"omap-dma-engine",
675 static int omap_dma_init(
void)
690 static void __exit omap_dma_exit(
void)