omap-dma.c revision 893e63e301e37cd3be7afb55c95eb8ef6ead304b
17bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King/* 27bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * OMAP DMAengine support 37bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * 47bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * This program is free software; you can redistribute it and/or modify 57bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * it under the terms of the GNU General Public License version 2 as 67bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * published by the Free Software Foundation. 77bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King */ 8fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King#include <linux/delay.h> 97bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/dmaengine.h> 107bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/dma-mapping.h> 117bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/err.h> 127bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/init.h> 137bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/interrupt.h> 147bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/list.h> 157bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/module.h> 167bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/omap-dma.h> 177bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/platform_device.h> 187bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/slab.h> 197bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include <linux/spinlock.h> 208d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter#include <linux/of_dma.h> 218d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter#include <linux/of_device.h> 227bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 237bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King#include "virt-dma.h" 247d7e1eba7e92c2f9c76db80adc24836e7a114bfbTony Lindgren 257bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstruct omap_dmadev { 267bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct dma_device ddev; 277bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spinlock_t lock; 287bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct tasklet_struct task; 297bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct list_head pending; 301b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King struct omap_system_dma_plat_info *plat; 317bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King}; 327bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 337bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstruct omap_chan { 347bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct virt_dma_chan vc; 357bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct list_head node; 361b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King struct omap_system_dma_plat_info *plat; 377bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 387bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct dma_slave_config cfg; 397bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned dma_sig; 403a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King bool cyclic; 412dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi bool paused; 427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 437bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King int dma_ch; 447bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_desc *desc; 457bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned sgidx; 467bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King}; 477bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 487bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstruct omap_sg { 497bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dma_addr_t addr; 507bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King uint32_t en; /* number of elements (24-bit) */ 517bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King uint32_t fn; /* number of frames (16-bit) */ 527bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King}; 537bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 547bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstruct omap_desc { 557bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct virt_dma_desc vd; 567bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King enum dma_transfer_direction dir; 577bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dma_addr_t dev_addr; 587bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 597c836bc7f9f71d62a8dc50712db122a69b405486Russell King int16_t fi; /* for OMAP_DMA_SYNC_PACKET */ 609043826d88467091543c1d3ab06eb4afeed34789Russell King uint8_t es; /* CSDP_DATA_TYPE_xxx */ 613ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King uint32_t ccr; /* CCR value */ 62fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King uint16_t cicr; /* CICR value */ 632f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King uint32_t csdp; /* CSDP value */ 647bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 657bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned sglen; 667bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_sg sg[0]; 677bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King}; 687bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 699043826d88467091543c1d3ab06eb4afeed34789Russell Kingenum { 709043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_FS = BIT(5), 719043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_READ_PRIORITY = BIT(6), 729043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_ENABLE = BIT(7), 739043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_AUTO_INIT = BIT(8), /* OMAP1 only */ 749043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_REPEAT = BIT(9), /* OMAP1 only */ 759043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_OMAP31_DISABLE = BIT(10), /* OMAP1 only */ 769043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SUSPEND_SENSITIVE = BIT(8), /* OMAP2+ only */ 779043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_RD_ACTIVE = BIT(9), /* OMAP2+ only */ 789043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_WR_ACTIVE = BIT(10), /* OMAP2+ only */ 799043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SRC_AMODE_CONSTANT = 0 << 12, 809043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SRC_AMODE_POSTINC = 1 << 12, 819043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SRC_AMODE_SGLIDX = 2 << 12, 829043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SRC_AMODE_DBLIDX = 3 << 12, 839043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_DST_AMODE_CONSTANT = 0 << 14, 849043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_DST_AMODE_POSTINC = 1 << 14, 859043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_DST_AMODE_SGLIDX = 2 << 14, 869043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_DST_AMODE_DBLIDX = 3 << 14, 879043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_CONSTANT_FILL = BIT(16), 889043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_TRANSPARENT_COPY = BIT(17), 899043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_BS = BIT(18), 909043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SUPERVISOR = BIT(22), 919043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_PREFETCH = BIT(23), 929043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_TRIGGER_SRC = BIT(24), 939043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_BUFFERING_DISABLE = BIT(25), 949043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_WRITE_PRIORITY = BIT(26), 959043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SYNC_ELEMENT = 0, 969043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SYNC_FRAME = CCR_FS, 979043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SYNC_BLOCK = CCR_BS, 989043826d88467091543c1d3ab06eb4afeed34789Russell King CCR_SYNC_PACKET = CCR_BS | CCR_FS, 999043826d88467091543c1d3ab06eb4afeed34789Russell King 1009043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DATA_TYPE_8 = 0, 1019043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DATA_TYPE_16 = 1, 1029043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DATA_TYPE_32 = 2, 1039043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PORT_EMIFF = 0 << 2, /* OMAP1 only */ 1049043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PORT_EMIFS = 1 << 2, /* OMAP1 only */ 1059043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PORT_OCP_T1 = 2 << 2, /* OMAP1 only */ 1069043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PORT_TIPB = 3 << 2, /* OMAP1 only */ 1079043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PORT_OCP_T2 = 4 << 2, /* OMAP1 only */ 1089043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PORT_MPUI = 5 << 2, /* OMAP1 only */ 1099043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_PACKED = BIT(6), 1109043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_BURST_1 = 0 << 7, 1119043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_BURST_16 = 1 << 7, 1129043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_BURST_32 = 2 << 7, 1139043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_SRC_BURST_64 = 3 << 7, 1149043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PORT_EMIFF = 0 << 9, /* OMAP1 only */ 1159043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PORT_EMIFS = 1 << 9, /* OMAP1 only */ 1169043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PORT_OCP_T1 = 2 << 9, /* OMAP1 only */ 1179043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PORT_TIPB = 3 << 9, /* OMAP1 only */ 1189043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PORT_OCP_T2 = 4 << 9, /* OMAP1 only */ 1199043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PORT_MPUI = 5 << 9, /* OMAP1 only */ 1209043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_PACKED = BIT(13), 1219043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_BURST_1 = 0 << 14, 1229043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_BURST_16 = 1 << 14, 1239043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_BURST_32 = 2 << 14, 1249043826d88467091543c1d3ab06eb4afeed34789Russell King CSDP_DST_BURST_64 = 3 << 14, 1259043826d88467091543c1d3ab06eb4afeed34789Russell King 1269043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_TOUT_IE = BIT(0), /* OMAP1 only */ 1279043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_DROP_IE = BIT(1), 1289043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_HALF_IE = BIT(2), 1299043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_FRAME_IE = BIT(3), 1309043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_LAST_IE = BIT(4), 1319043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_BLOCK_IE = BIT(5), 1329043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_PKT_IE = BIT(7), /* OMAP2+ only */ 1339043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_TRANS_ERR_IE = BIT(8), /* OMAP2+ only */ 1349043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_SUPERVISOR_ERR_IE = BIT(10), /* OMAP2+ only */ 1359043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_MISALIGNED_ERR_IE = BIT(11), /* OMAP2+ only */ 1369043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_DRAIN_IE = BIT(12), /* OMAP2+ only */ 1379043826d88467091543c1d3ab06eb4afeed34789Russell King CICR_SUPER_BLOCK_IE = BIT(14), /* OMAP2+ only */ 1389043826d88467091543c1d3ab06eb4afeed34789Russell King 1399043826d88467091543c1d3ab06eb4afeed34789Russell King CLNK_CTRL_ENABLE_LNK = BIT(15), 1409043826d88467091543c1d3ab06eb4afeed34789Russell King}; 1419043826d88467091543c1d3ab06eb4afeed34789Russell King 1427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic const unsigned es_bytes[] = { 1439043826d88467091543c1d3ab06eb4afeed34789Russell King [CSDP_DATA_TYPE_8] = 1, 1449043826d88467091543c1d3ab06eb4afeed34789Russell King [CSDP_DATA_TYPE_16] = 2, 1459043826d88467091543c1d3ab06eb4afeed34789Russell King [CSDP_DATA_TYPE_32] = 4, 1467bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King}; 1477bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 1488d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunterstatic struct of_dma_filter_info omap_dma_info = { 1498d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter .filter_fn = omap_dma_filter_fn, 1508d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter}; 1518d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter 1527bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic inline struct omap_dmadev *to_omap_dma_dev(struct dma_device *d) 1537bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 1547bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return container_of(d, struct omap_dmadev, ddev); 1557bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 1567bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 1577bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic inline struct omap_chan *to_omap_dma_chan(struct dma_chan *c) 1587bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 1597bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return container_of(c, struct omap_chan, vc.chan); 1607bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 1617bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 1627bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic inline struct omap_desc *to_omap_dma_desc(struct dma_async_tx_descriptor *t) 1637bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 1647bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return container_of(t, struct omap_desc, vd.tx); 1657bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 1667bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 1677bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_desc_free(struct virt_dma_desc *vd) 1687bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 1697bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King kfree(container_of(vd, struct omap_desc, vd)); 1707bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 1717bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 172470b23f7308dd2af25bd075d14a724f8ccd93985Russell Kingstatic void omap_dma_clear_csr(struct omap_chan *c) 173470b23f7308dd2af25bd075d14a724f8ccd93985Russell King{ 174470b23f7308dd2af25bd075d14a724f8ccd93985Russell King if (dma_omap1()) 175470b23f7308dd2af25bd075d14a724f8ccd93985Russell King c->plat->dma_read(CSR, c->dma_ch); 176470b23f7308dd2af25bd075d14a724f8ccd93985Russell King else 177470b23f7308dd2af25bd075d14a724f8ccd93985Russell King c->plat->dma_write(~0, CSR, c->dma_ch); 178470b23f7308dd2af25bd075d14a724f8ccd93985Russell King} 179470b23f7308dd2af25bd075d14a724f8ccd93985Russell King 180fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell Kingstatic void omap_dma_start(struct omap_chan *c, struct omap_desc *d) 181fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King{ 182fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); 183fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King uint32_t val; 184fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 185fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (__dma_omap15xx(od->plat->dma_attr)) 186fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(0, CPC, c->dma_ch); 187fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King else 188fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(0, CDAC, c->dma_ch); 189fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 190fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (!__dma_omap15xx(od->plat->dma_attr) && c->cyclic) { 191fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = c->plat->dma_read(CLNK_CTRL, c->dma_ch); 192fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 193fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (dma_omap1()) 194fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val &= ~(1 << 14); 195fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 1969043826d88467091543c1d3ab06eb4afeed34789Russell King val |= c->dma_ch | CLNK_CTRL_ENABLE_LNK; 197fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 198fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(val, CLNK_CTRL, c->dma_ch); 199fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King } else if (od->plat->errata & DMA_ERRATA_PARALLEL_CHANNELS) 200fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(c->dma_ch, CLNK_CTRL, c->dma_ch); 201fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 202470b23f7308dd2af25bd075d14a724f8ccd93985Russell King omap_dma_clear_csr(c); 203fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 204fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King /* Enable interrupts */ 205fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(d->cicr, CICR, c->dma_ch); 206fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 207fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = c->plat->dma_read(CCR, c->dma_ch); 2089043826d88467091543c1d3ab06eb4afeed34789Russell King val |= CCR_ENABLE; 209fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King mb(); 210fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(val, CCR, c->dma_ch); 211fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King} 212fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 213fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell Kingstatic void omap_dma_stop(struct omap_chan *c) 214fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King{ 215fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); 216fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King uint32_t val; 217fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 218fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King /* disable irq */ 219fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(0, CICR, c->dma_ch); 220fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 221470b23f7308dd2af25bd075d14a724f8ccd93985Russell King omap_dma_clear_csr(c); 222fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 223fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = c->plat->dma_read(CCR, c->dma_ch); 2249043826d88467091543c1d3ab06eb4afeed34789Russell King if (od->plat->errata & DMA_ERRATA_i541 && val & CCR_TRIGGER_SRC) { 225fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King uint32_t sysconfig; 226fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King unsigned i; 227fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 228fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King sysconfig = c->plat->dma_read(OCP_SYSCONFIG, c->dma_ch); 229fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = sysconfig & ~DMA_SYSCONFIG_MIDLEMODE_MASK; 230fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE); 231fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(val, OCP_SYSCONFIG, c->dma_ch); 232fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 233fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = c->plat->dma_read(CCR, c->dma_ch); 2349043826d88467091543c1d3ab06eb4afeed34789Russell King val &= ~CCR_ENABLE; 235fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(val, CCR, c->dma_ch); 236fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 237fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King /* Wait for sDMA FIFO to drain */ 238fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King for (i = 0; ; i++) { 239fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = c->plat->dma_read(CCR, c->dma_ch); 2409043826d88467091543c1d3ab06eb4afeed34789Russell King if (!(val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE))) 241fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King break; 242fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 243fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (i > 100) 244fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King break; 245fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 246fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King udelay(5); 247fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King } 248fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 2499043826d88467091543c1d3ab06eb4afeed34789Russell King if (val & (CCR_RD_ACTIVE | CCR_WR_ACTIVE)) 250fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King dev_err(c->vc.chan.device->dev, 251fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King "DMA drain did not complete on lch %d\n", 252fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->dma_ch); 253fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 254fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(sysconfig, OCP_SYSCONFIG, c->dma_ch); 255fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King } else { 2569043826d88467091543c1d3ab06eb4afeed34789Russell King val &= ~CCR_ENABLE; 257fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(val, CCR, c->dma_ch); 258fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King } 259fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 260fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King mb(); 261fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 262fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (!__dma_omap15xx(od->plat->dma_attr) && c->cyclic) { 263fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val = c->plat->dma_read(CLNK_CTRL, c->dma_ch); 264fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 265fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (dma_omap1()) 266fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King val |= 1 << 14; /* set the STOP_LNK bit */ 267fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King else 2689043826d88467091543c1d3ab06eb4afeed34789Russell King val &= ~CLNK_CTRL_ENABLE_LNK; 269fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 270fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King c->plat->dma_write(val, CLNK_CTRL, c->dma_ch); 271fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King } 272fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King} 273fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 2747bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_start_sg(struct omap_chan *c, struct omap_desc *d, 2757bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned idx) 2767bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 2777bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_sg *sg = d->sg + idx; 278893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King unsigned cxsa, cxei, cxfi; 279913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 280913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King if (d->dir == DMA_DEV_TO_MEM) { 281893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxsa = CDSA; 282893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxei = CDEI; 283893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxfi = CDFI; 284913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King } else { 285893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxsa = CSSA; 286893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxei = CSEI; 287893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxfi = CSFI; 288913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King } 289913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 290893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King c->plat->dma_write(sg->addr, cxsa, c->dma_ch); 291893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King c->plat->dma_write(0, cxei, c->dma_ch); 292893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King c->plat->dma_write(0, cxfi, c->dma_ch); 293913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King c->plat->dma_write(sg->en, CEN, c->dma_ch); 294913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King c->plat->dma_write(sg->fn, CFN, c->dma_ch); 295913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 296fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King omap_dma_start(c, d); 297913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King} 298913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 299913a2d0c6952283bc9323cb9152af87f792ff4c4Russell Kingstatic void omap_dma_start_desc(struct omap_chan *c) 300913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King{ 301913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King struct virt_dma_desc *vd = vchan_next_desc(&c->vc); 302913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King struct omap_desc *d; 303893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King unsigned cxsa, cxei, cxfi; 304b9e97822da374f52aaf99cb502f531ff2184b8f5Russell King 305913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King if (!vd) { 306913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King c->desc = NULL; 307913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King return; 308913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King } 309913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 310913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King list_del(&vd->node); 311913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 312913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King c->desc = d = to_omap_dma_desc(&vd->tx); 313913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King c->sgidx = 0; 314913a2d0c6952283bc9323cb9152af87f792ff4c4Russell King 3153ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King c->plat->dma_write(d->ccr, CCR, c->dma_ch); 3163ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (dma_omap1()) 3173ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King c->plat->dma_write(d->ccr >> 16, CCR2, c->dma_ch); 318b9e97822da374f52aaf99cb502f531ff2184b8f5Russell King 3193ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (d->dir == DMA_DEV_TO_MEM) { 320893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxsa = CSSA; 321893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxei = CSEI; 322893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxfi = CSFI; 323b9e97822da374f52aaf99cb502f531ff2184b8f5Russell King } else { 324893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxsa = CDSA; 325893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxei = CDEI; 326893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King cxfi = CDFI; 327b9e97822da374f52aaf99cb502f531ff2184b8f5Russell King } 328b9e97822da374f52aaf99cb502f531ff2184b8f5Russell King 329893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King c->plat->dma_write(d->dev_addr, cxsa, c->dma_ch); 330893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King c->plat->dma_write(0, cxei, c->dma_ch); 331893e63e301e37cd3be7afb55c95eb8ef6ead304bRussell King c->plat->dma_write(d->fi, cxfi, c->dma_ch); 3322f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King c->plat->dma_write(d->csdp, CSDP, c->dma_ch); 333b9e97822da374f52aaf99cb502f531ff2184b8f5Russell King 3347bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_dma_start_sg(c, d, 0); 3357bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 3367bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3377bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_callback(int ch, u16 status, void *data) 3387bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 3397bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = data; 3407bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_desc *d; 3417bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned long flags; 3427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3437bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock_irqsave(&c->vc.lock, flags); 3447bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d = c->desc; 3457bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (d) { 3463a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King if (!c->cyclic) { 3473a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King if (++c->sgidx < d->sglen) { 3483a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King omap_dma_start_sg(c, d, c->sgidx); 3493a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } else { 3503a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King omap_dma_start_desc(c); 3513a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King vchan_cookie_complete(&d->vd); 3523a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } 3537bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } else { 3543a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King vchan_cyclic_callback(&d->vd); 3557bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 3567bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 3577bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_unlock_irqrestore(&c->vc.lock, flags); 3587bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 3597bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3607bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King/* 3617bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * This callback schedules all pending channels. We could be more 3627bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * clever here by postponing allocation of the real DMA channels to 3637bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * this point, and freeing them when our virtual channel becomes idle. 3647bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * 3657bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * We would then need to deal with 'all channels in-use' 3667bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King */ 3677bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_sched(unsigned long data) 3687bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 3697bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_dmadev *d = (struct omap_dmadev *)data; 3707bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King LIST_HEAD(head); 3717bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3727bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock_irq(&d->lock); 3737bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King list_splice_tail_init(&d->pending, &head); 3747bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_unlock_irq(&d->lock); 3757bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3767bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King while (!list_empty(&head)) { 3777bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = list_first_entry(&head, 3787bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan, node); 3797bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3807bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock_irq(&c->vc.lock); 3817bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King list_del_init(&c->node); 3827bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_dma_start_desc(c); 3837bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_unlock_irq(&c->vc.lock); 3847bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 3857bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 3867bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3877bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_alloc_chan_resources(struct dma_chan *chan) 3887bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 3897bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = to_omap_dma_chan(chan); 3907bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3919e2f7d827912609a71a53d625ee27d29dfbf87e0Ezequiel Garcia dev_dbg(c->vc.chan.device->dev, "allocating channel for %u\n", c->dma_sig); 3927bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3937bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return omap_request_dma(c->dma_sig, "DMA engine", 3947bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_dma_callback, c, &c->dma_ch); 3957bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 3967bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 3977bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_free_chan_resources(struct dma_chan *chan) 3987bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 3997bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = to_omap_dma_chan(chan); 4007bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 4017bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King vchan_free_chan_resources(&c->vc); 4027bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_free_dma(c->dma_ch); 4037bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 4049e2f7d827912609a71a53d625ee27d29dfbf87e0Ezequiel Garcia dev_dbg(c->vc.chan.device->dev, "freeing channel for %u\n", c->dma_sig); 4057bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 4067bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 4073850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell Kingstatic size_t omap_dma_sg_size(struct omap_sg *sg) 4083850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King{ 4093850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King return sg->en * sg->fn; 4103850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King} 4113850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4123850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell Kingstatic size_t omap_dma_desc_size(struct omap_desc *d) 4133850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King{ 4143850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King unsigned i; 4153850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King size_t size; 4163850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4173850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King for (size = i = 0; i < d->sglen; i++) 4183850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King size += omap_dma_sg_size(&d->sg[i]); 4193850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4203850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King return size * es_bytes[d->es]; 4213850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King} 4223850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4233850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell Kingstatic size_t omap_dma_desc_size_pos(struct omap_desc *d, dma_addr_t addr) 4243850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King{ 4253850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King unsigned i; 4263850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King size_t size, es_size = es_bytes[d->es]; 4273850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4283850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King for (size = i = 0; i < d->sglen; i++) { 4293850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King size_t this_size = omap_dma_sg_size(&d->sg[i]) * es_size; 4303850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4313850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King if (size) 4323850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King size += this_size; 4333850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King else if (addr >= d->sg[i].addr && 4343850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King addr < d->sg[i].addr + this_size) 4353850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King size += d->sg[i].addr + this_size - addr; 4363850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King } 4373850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King return size; 4383850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King} 4393850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 4403997cab391b38e126f217e36ad7bdc9672c9fb4dRussell Kingstatic dma_addr_t omap_dma_get_src_pos(struct omap_chan *c) 4413997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King{ 4423997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); 4433997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King dma_addr_t addr; 4443997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4453997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (__dma_omap15xx(od->plat->dma_attr)) 4463997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CPC, c->dma_ch); 4473997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King else 4483997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CSAC, c->dma_ch); 4493997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4503997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (od->plat->errata & DMA_ERRATA_3_3 && addr == 0) 4513997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CSAC, c->dma_ch); 4523997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4533997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (!__dma_omap15xx(od->plat->dma_attr)) { 4543997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King /* 4553997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * CDAC == 0 indicates that the DMA transfer on the channel has 4563997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * not been started (no data has been transferred so far). 4573997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * Return the programmed source start address in this case. 4583997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King */ 4593997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (c->plat->dma_read(CDAC, c->dma_ch)) 4603997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CSAC, c->dma_ch); 4613997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King else 4623997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CSSA, c->dma_ch); 4633997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King } 4643997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4653997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (dma_omap1()) 4663997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr |= c->plat->dma_read(CSSA, c->dma_ch) & 0xffff0000; 4673997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4683997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King return addr; 4693997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King} 4703997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4713997cab391b38e126f217e36ad7bdc9672c9fb4dRussell Kingstatic dma_addr_t omap_dma_get_dst_pos(struct omap_chan *c) 4723997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King{ 4733997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device); 4743997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King dma_addr_t addr; 4753997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4763997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (__dma_omap15xx(od->plat->dma_attr)) 4773997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CPC, c->dma_ch); 4783997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King else 4793997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CDAC, c->dma_ch); 4803997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4813997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King /* 4823997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is 4833997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * read before the DMA controller finished disabling the channel. 4843997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King */ 4853997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (!__dma_omap15xx(od->plat->dma_attr) && addr == 0) { 4863997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CDAC, c->dma_ch); 4873997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King /* 4883997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * CDAC == 0 indicates that the DMA transfer on the channel has 4893997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * not been started (no data has been transferred so far). 4903997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King * Return the programmed destination start address in this case. 4913997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King */ 4923997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (addr == 0) 4933997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr = c->plat->dma_read(CDSA, c->dma_ch); 4943997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King } 4953997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4963997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King if (dma_omap1()) 4973997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King addr |= c->plat->dma_read(CDSA, c->dma_ch) & 0xffff0000; 4983997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 4993997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King return addr; 5003997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King} 5013997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King 5027bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic enum dma_status omap_dma_tx_status(struct dma_chan *chan, 5037bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dma_cookie_t cookie, struct dma_tx_state *txstate) 5047bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 5053850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King struct omap_chan *c = to_omap_dma_chan(chan); 5063850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King struct virt_dma_desc *vd; 5073850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King enum dma_status ret; 5083850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King unsigned long flags; 5093850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 5103850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King ret = dma_cookie_status(chan, cookie, txstate); 5117cce5083b738e3e693abe082d9958686bcb88d32Vinod Koul if (ret == DMA_COMPLETE || !txstate) 5123850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King return ret; 5133850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 5143850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King spin_lock_irqsave(&c->vc.lock, flags); 5153850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King vd = vchan_find_desc(&c->vc, cookie); 5163850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King if (vd) { 5173850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King txstate->residue = omap_dma_desc_size(to_omap_dma_desc(&vd->tx)); 5183850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King } else if (c->desc && c->desc->vd.tx.cookie == cookie) { 5193850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King struct omap_desc *d = c->desc; 5203850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King dma_addr_t pos; 5213850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 5223850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King if (d->dir == DMA_MEM_TO_DEV) 5233997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King pos = omap_dma_get_src_pos(c); 5243850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King else if (d->dir == DMA_DEV_TO_MEM) 5253997cab391b38e126f217e36ad7bdc9672c9fb4dRussell King pos = omap_dma_get_dst_pos(c); 5263850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King else 5273850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King pos = 0; 5283850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 5293850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King txstate->residue = omap_dma_desc_size_pos(d, pos); 5303850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King } else { 5313850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King txstate->residue = 0; 5323850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King } 5333850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King spin_unlock_irqrestore(&c->vc.lock, flags); 5343850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King 5353850e22f5146d2ff5b66f1b7460d4720d5f1b6c7Russell King return ret; 5367bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 5377bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 5387bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_issue_pending(struct dma_chan *chan) 5397bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 5407bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = to_omap_dma_chan(chan); 5417bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned long flags; 5427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 5437bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock_irqsave(&c->vc.lock, flags); 5447bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (vchan_issue_pending(&c->vc) && !c->desc) { 545765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi /* 546765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi * c->cyclic is used only by audio and in this case the DMA need 547765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi * to be started without delay. 548765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi */ 549765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi if (!c->cyclic) { 550765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi struct omap_dmadev *d = to_omap_dma_dev(chan->device); 551765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi spin_lock(&d->lock); 552765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi if (list_empty(&c->node)) 553765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi list_add_tail(&c->node, &d->pending); 554765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi spin_unlock(&d->lock); 555765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi tasklet_schedule(&d->task); 556765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi } else { 557765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi omap_dma_start_desc(c); 558765024697807ad1e1cac332aa891253ca4a339daPeter Ujfalusi } 5597bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 5607bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_unlock_irqrestore(&c->vc.lock, flags); 5617bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 5627bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 5637bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic struct dma_async_tx_descriptor *omap_dma_prep_slave_sg( 5647bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct dma_chan *chan, struct scatterlist *sgl, unsigned sglen, 5657bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King enum dma_transfer_direction dir, unsigned long tx_flags, void *context) 5667bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 56749ae0b29439446cff81c32bf01fb7b7cce195373Russell King struct omap_dmadev *od = to_omap_dma_dev(chan->device); 5687bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = to_omap_dma_chan(chan); 5697bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King enum dma_slave_buswidth dev_width; 5707bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct scatterlist *sgent; 5717bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_desc *d; 5727bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dma_addr_t dev_addr; 5733ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King unsigned i, j = 0, es, en, frame_bytes; 5747bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King u32 burst; 5757bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 5767bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (dir == DMA_DEV_TO_MEM) { 5777bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dev_addr = c->cfg.src_addr; 5787bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dev_width = c->cfg.src_addr_width; 5797bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King burst = c->cfg.src_maxburst; 5807bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } else if (dir == DMA_MEM_TO_DEV) { 5817bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dev_addr = c->cfg.dst_addr; 5827bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dev_width = c->cfg.dst_addr_width; 5837bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King burst = c->cfg.dst_maxburst; 5847bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } else { 5857bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dev_err(chan->device->dev, "%s: bad direction?\n", __func__); 5867bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return NULL; 5877bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 5887bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 5897bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King /* Bus width translates to the element size (ES) */ 5907bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King switch (dev_width) { 5917bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_SLAVE_BUSWIDTH_1_BYTE: 5929043826d88467091543c1d3ab06eb4afeed34789Russell King es = CSDP_DATA_TYPE_8; 5937bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 5947bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_SLAVE_BUSWIDTH_2_BYTES: 5959043826d88467091543c1d3ab06eb4afeed34789Russell King es = CSDP_DATA_TYPE_16; 5967bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 5977bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_SLAVE_BUSWIDTH_4_BYTES: 5989043826d88467091543c1d3ab06eb4afeed34789Russell King es = CSDP_DATA_TYPE_32; 5997bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 6007bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King default: /* not reached */ 6017bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return NULL; 6027bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 6037bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 6047bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King /* Now allocate and setup the descriptor. */ 6057bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d = kzalloc(sizeof(*d) + sglen * sizeof(d->sg[0]), GFP_ATOMIC); 6067bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (!d) 6077bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return NULL; 6087bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 6097bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->dir = dir; 6107bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->dev_addr = dev_addr; 6117bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->es = es; 6123ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 6139043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr = CCR_SYNC_FRAME; 6143ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (dir == DMA_DEV_TO_MEM) 6159043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT; 6163ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King else 6179043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC; 6183ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 6199043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr = CICR_DROP_IE | CICR_BLOCK_IE; 6202f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King d->csdp = es; 621fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 6222f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King if (dma_omap1()) { 6233ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (__dma_omap16xx(od->plat->dma_attr)) { 6249043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_OMAP31_DISABLE; 6253ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King /* Duplicate what plat-omap/dma.c does */ 6263ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= c->dma_ch + 1; 6273ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King } else { 6283ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= c->dma_sig & 0x1f; 6293ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King } 6303ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 6319043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr |= CICR_TOUT_IE; 6322f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King 6332f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King if (dir == DMA_DEV_TO_MEM) 6349043826d88467091543c1d3ab06eb4afeed34789Russell King d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_TIPB; 6352f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King else 6369043826d88467091543c1d3ab06eb4afeed34789Russell King d->csdp |= CSDP_DST_PORT_TIPB | CSDP_SRC_PORT_EMIFF; 6372f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King } else { 6383ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= (c->dma_sig & ~0x1f) << 14; 6393ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= c->dma_sig & 0x1f; 6403ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 6413ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (dir == DMA_DEV_TO_MEM) 6429043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_TRIGGER_SRC; 6433ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 6449043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE; 6452f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King } 64649ae0b29439446cff81c32bf01fb7b7cce195373Russell King if (od->plat->errata & DMA_ERRATA_IFRAME_BUFFERING) 64749ae0b29439446cff81c32bf01fb7b7cce195373Russell King d->ccr |= CCR_BUFFERING_DISABLE; 6487bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 6497bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King /* 6507bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * Build our scatterlist entries: each contains the address, 6517bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * the number of elements (EN) in each frame, and the number of 6527bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * frames (FN). Number of bytes for this entry = ES * EN * FN. 6537bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * 6547bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * Burst size translates to number of elements with frame sync. 6557bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * Note: DMA engine defines burst to be the number of dev-width 6567bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * transfers. 6577bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King */ 6587bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King en = burst; 6597bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King frame_bytes = es_bytes[es] * en; 6607bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King for_each_sg(sgl, sgent, sglen, i) { 6617bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->sg[j].addr = sg_dma_address(sgent); 6627bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->sg[j].en = en; 6637bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->sg[j].fn = sg_dma_len(sgent) / frame_bytes; 6647bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King j++; 6657bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 6667bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 6677bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King d->sglen = j; 6687bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 6697bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return vchan_tx_prep(&c->vc, &d->vd, tx_flags); 6707bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 6717bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 6723a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell Kingstatic struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic( 6733a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 674ec8b5e48c03790a68cb875fe5064007a9cbdfdd0Peter Ujfalusi size_t period_len, enum dma_transfer_direction dir, unsigned long flags, 675ec8b5e48c03790a68cb875fe5064007a9cbdfdd0Peter Ujfalusi void *context) 6763a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King{ 677fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King struct omap_dmadev *od = to_omap_dma_dev(chan->device); 6783a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King struct omap_chan *c = to_omap_dma_chan(chan); 6793a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King enum dma_slave_buswidth dev_width; 6803a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King struct omap_desc *d; 6813a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dma_addr_t dev_addr; 6823ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King unsigned es; 6833a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King u32 burst; 6843a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 6853a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King if (dir == DMA_DEV_TO_MEM) { 6863a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dev_addr = c->cfg.src_addr; 6873a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dev_width = c->cfg.src_addr_width; 6883a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King burst = c->cfg.src_maxburst; 6893a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } else if (dir == DMA_MEM_TO_DEV) { 6903a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dev_addr = c->cfg.dst_addr; 6913a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dev_width = c->cfg.dst_addr_width; 6923a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King burst = c->cfg.dst_maxburst; 6933a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } else { 6943a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dev_err(chan->device->dev, "%s: bad direction?\n", __func__); 6953a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King return NULL; 6963a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } 6973a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 6983a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King /* Bus width translates to the element size (ES) */ 6993a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King switch (dev_width) { 7003a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King case DMA_SLAVE_BUSWIDTH_1_BYTE: 7019043826d88467091543c1d3ab06eb4afeed34789Russell King es = CSDP_DATA_TYPE_8; 7023a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King break; 7033a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King case DMA_SLAVE_BUSWIDTH_2_BYTES: 7049043826d88467091543c1d3ab06eb4afeed34789Russell King es = CSDP_DATA_TYPE_16; 7053a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King break; 7063a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King case DMA_SLAVE_BUSWIDTH_4_BYTES: 7079043826d88467091543c1d3ab06eb4afeed34789Russell King es = CSDP_DATA_TYPE_32; 7083a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King break; 7093a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King default: /* not reached */ 7103a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King return NULL; 7113a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } 7123a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 7133a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King /* Now allocate and setup the descriptor. */ 7143a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC); 7153a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King if (!d) 7163a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King return NULL; 7173a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 7183a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->dir = dir; 7193a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->dev_addr = dev_addr; 7203a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->fi = burst; 7213a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->es = es; 7223a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->sg[0].addr = buf_addr; 7233a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->sg[0].en = period_len / es_bytes[es]; 7243a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->sg[0].fn = buf_len / period_len; 7253a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King d->sglen = 1; 7263ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 7273ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr = 0; 7283ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (__dma_omap15xx(od->plat->dma_attr)) 7299043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr = CCR_AUTO_INIT | CCR_REPEAT; 7303ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (dir == DMA_DEV_TO_MEM) 7319043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT; 7323ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King else 7339043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC; 7343ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 7359043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr = CICR_DROP_IE; 736fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King if (flags & DMA_PREP_INTERRUPT) 7379043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr |= CICR_FRAME_IE; 738fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King 7392f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King d->csdp = es; 7402f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King 7412f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King if (dma_omap1()) { 7423ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (__dma_omap16xx(od->plat->dma_attr)) { 7439043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_OMAP31_DISABLE; 7443ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King /* Duplicate what plat-omap/dma.c does */ 7453ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= c->dma_ch + 1; 7463ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King } else { 7473ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= c->dma_sig & 0x1f; 7483ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King } 7493ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 7509043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr |= CICR_TOUT_IE; 7512f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King 7522f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King if (dir == DMA_DEV_TO_MEM) 7539043826d88467091543c1d3ab06eb4afeed34789Russell King d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_MPUI; 7542f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King else 7559043826d88467091543c1d3ab06eb4afeed34789Russell King d->csdp |= CSDP_DST_PORT_MPUI | CSDP_SRC_PORT_EMIFF; 7562f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King } else { 7573ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= (c->dma_sig & ~0x1f) << 14; 7583ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King d->ccr |= c->dma_sig & 0x1f; 7593ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 7603ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (burst) 7619043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_SYNC_PACKET; 7629043826d88467091543c1d3ab06eb4afeed34789Russell King else 7639043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_SYNC_ELEMENT; 7643ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 7653ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King if (dir == DMA_DEV_TO_MEM) 7669043826d88467091543c1d3ab06eb4afeed34789Russell King d->ccr |= CCR_TRIGGER_SRC; 7673ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King 7689043826d88467091543c1d3ab06eb4afeed34789Russell King d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE; 7693a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 7709043826d88467091543c1d3ab06eb4afeed34789Russell King d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64; 7712f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King } 77249ae0b29439446cff81c32bf01fb7b7cce195373Russell King if (od->plat->errata & DMA_ERRATA_IFRAME_BUFFERING) 77349ae0b29439446cff81c32bf01fb7b7cce195373Russell King d->ccr |= CCR_BUFFERING_DISABLE; 7742f0d13bdf6440906bb52fe94681ce7927145f4d7Russell King 7753ed4d18f39bcd8cb8d8218c0a5f89a4d81ba8730Russell King c->cyclic = true; 7763a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 7772dde5b909e117cc95a5e31604f9bfd043e78ad9dPeter Ujfalusi return vchan_tx_prep(&c->vc, &d->vd, flags); 7783a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King} 7793a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 7807bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_slave_config(struct omap_chan *c, struct dma_slave_config *cfg) 7817bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 7827bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || 7837bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) 7847bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return -EINVAL; 7857bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 7867bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King memcpy(&c->cfg, cfg, sizeof(c->cfg)); 7877bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 7887bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return 0; 7897bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 7907bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 7917bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_terminate_all(struct omap_chan *c) 7927bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 7937bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_dmadev *d = to_omap_dma_dev(c->vc.chan.device); 7947bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned long flags; 7957bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King LIST_HEAD(head); 7967bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 7977bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock_irqsave(&c->vc.lock, flags); 7987bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 7997bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King /* Prevent this channel being scheduled */ 8007bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock(&d->lock); 8017bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King list_del_init(&c->node); 8027bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_unlock(&d->lock); 8037bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8047bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King /* 8057bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * Stop DMA activity: we assume the callback will not be called 806fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King * after omap_dma_stop() returns (even if it does, it will see 8077bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King * c->desc is NULL and exit.) 8087bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King */ 8097bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (c->desc) { 8107bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King c->desc = NULL; 8112dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi /* Avoid stopping the dma twice */ 8122dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi if (!c->paused) 813fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King omap_dma_stop(c); 8147bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 8157bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8163a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King if (c->cyclic) { 8173a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King c->cyclic = false; 8182dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi c->paused = false; 8193a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King } 8203a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King 8217bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King vchan_get_all_descriptors(&c->vc, &head); 8227bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_unlock_irqrestore(&c->vc.lock, flags); 8237bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King vchan_dma_desc_free_list(&c->vc, &head); 8247bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8257bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return 0; 8267bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 8277bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8287bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_pause(struct omap_chan *c) 8297bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 8302dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi /* Pause/Resume only allowed with cyclic mode */ 8312dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi if (!c->cyclic) 8322dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi return -EINVAL; 8332dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi 8342dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi if (!c->paused) { 835fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King omap_dma_stop(c); 8362dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi c->paused = true; 8372dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi } 8382dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi 8392dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi return 0; 8407bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 8417bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_resume(struct omap_chan *c) 8437bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 8442dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi /* Pause/Resume only allowed with cyclic mode */ 8452dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi if (!c->cyclic) 8462dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi return -EINVAL; 8472dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi 8482dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi if (c->paused) { 849fa3ad86ae0576b2c721800cc4d46864aa6d31ffdRussell King omap_dma_start(c, c->desc); 8502dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi c->paused = false; 8512dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi } 8522dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi 8532dcdf570936168d488acf90be9b04a3d32dafce7Peter Ujfalusi return 0; 8547bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 8557bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8567bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, 8577bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned long arg) 8587bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 8597bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = to_omap_dma_chan(chan); 8607bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King int ret; 8617bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8627bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King switch (cmd) { 8637bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_SLAVE_CONFIG: 8647bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King ret = omap_dma_slave_config(c, (struct dma_slave_config *)arg); 8657bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 8667bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8677bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_TERMINATE_ALL: 8687bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King ret = omap_dma_terminate_all(c); 8697bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 8707bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8717bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_PAUSE: 8727bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King ret = omap_dma_pause(c); 8737bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 8747bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8757bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King case DMA_RESUME: 8767bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King ret = omap_dma_resume(c); 8777bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 8787bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8797bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King default: 8807bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King ret = -ENXIO; 8817bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King break; 8827bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 8837bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8847bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return ret; 8857bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 8867bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8877bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_chan_init(struct omap_dmadev *od, int dma_sig) 8887bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 8897bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c; 8907bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8917bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King c = kzalloc(sizeof(*c), GFP_KERNEL); 8927bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (!c) 8937bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return -ENOMEM; 8947bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 8951b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King c->plat = od->plat; 8967bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King c->dma_sig = dma_sig; 8977bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King c->vc.desc_free = omap_dma_desc_free; 8987bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King vchan_init(&c->vc, &od->ddev); 8997bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King INIT_LIST_HEAD(&c->node); 9007bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9017bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.chancnt++; 9027bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9037bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return 0; 9047bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 9057bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9067bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void omap_dma_free(struct omap_dmadev *od) 9077bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 9087bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King tasklet_kill(&od->task); 9097bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King while (!list_empty(&od->ddev.channels)) { 9107bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = list_first_entry(&od->ddev.channels, 9117bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan, vc.chan.device_node); 9127bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9137bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King list_del(&c->vc.chan.device_node); 9147bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King tasklet_kill(&c->vc.task); 9157bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King kfree(c); 9167bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 9177bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 9187bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9197bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_probe(struct platform_device *pdev) 9207bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 9217bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_dmadev *od; 9227bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King int rc, i; 9237bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 924104fce73fdbd174eb08a493eeb2920fd59e6d3f4Russell King od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL); 9257bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (!od) 9267bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return -ENOMEM; 9277bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9281b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King od->plat = omap_get_plat_info(); 9291b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King if (!od->plat) 9301b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King return -EPROBE_DEFER; 9311b416c4b41351c3eb8fc42dbb4cd8eba463c0813Russell King 9327bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); 9333a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask); 9347bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources; 9357bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.device_free_chan_resources = omap_dma_free_chan_resources; 9367bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.device_tx_status = omap_dma_tx_status; 9377bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.device_issue_pending = omap_dma_issue_pending; 9387bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg; 9393a774ea91a5d05e7af58db6ae1ba298263c4a3d3Russell King od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic; 9407bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.device_control = omap_dma_control; 9417bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King od->ddev.dev = &pdev->dev; 9427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King INIT_LIST_HEAD(&od->ddev.channels); 9437bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King INIT_LIST_HEAD(&od->pending); 9447bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King spin_lock_init(&od->lock); 9457bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9467bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King tasklet_init(&od->task, omap_dma_sched, (unsigned long)od); 9477bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9487bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King for (i = 0; i < 127; i++) { 9497bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King rc = omap_dma_chan_init(od, i); 9507bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (rc) { 9517bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_dma_free(od); 9527bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return rc; 9537bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 9547bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 9557bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9567bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King rc = dma_async_device_register(&od->ddev); 9577bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (rc) { 9587bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n", 9597bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King rc); 9607bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_dma_free(od); 9618d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter return rc; 9628d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter } 9638d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter 9648d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter platform_set_drvdata(pdev, od); 9658d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter 9668d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter if (pdev->dev.of_node) { 9678d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter omap_dma_info.dma_cap = od->ddev.cap_mask; 9688d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter 9698d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter /* Device-tree DMA controller registration */ 9708d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter rc = of_dma_controller_register(pdev->dev.of_node, 9718d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter of_dma_simple_xlate, &omap_dma_info); 9728d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter if (rc) { 9738d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter pr_warn("OMAP-DMA: failed to register DMA controller\n"); 9748d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter dma_async_device_unregister(&od->ddev); 9758d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter omap_dma_free(od); 9768d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter } 9777bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 9787bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9797bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dev_info(&pdev->dev, "OMAP DMA engine driver\n"); 9807bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9817bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return rc; 9827bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 9837bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9847bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_remove(struct platform_device *pdev) 9857bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 9867bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_dmadev *od = platform_get_drvdata(pdev); 9877bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9888d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter if (pdev->dev.of_node) 9898d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter of_dma_controller_free(pdev->dev.of_node); 9908d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter 9917bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King dma_async_device_unregister(&od->ddev); 9927bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King omap_dma_free(od); 9937bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9947bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return 0; 9957bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 9967bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 9978d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunterstatic const struct of_device_id omap_dma_match[] = { 9988d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter { .compatible = "ti,omap2420-sdma", }, 9998d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter { .compatible = "ti,omap2430-sdma", }, 10008d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter { .compatible = "ti,omap3430-sdma", }, 10018d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter { .compatible = "ti,omap3630-sdma", }, 10028d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter { .compatible = "ti,omap4430-sdma", }, 10038d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter {}, 10048d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter}; 10058d30662aac256eb61bc2f1d9cf1191825ef96328Jon HunterMODULE_DEVICE_TABLE(of, omap_dma_match); 10068d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter 10077bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic struct platform_driver omap_dma_driver = { 10087bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King .probe = omap_dma_probe, 10097bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King .remove = omap_dma_remove, 10107bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King .driver = { 10117bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King .name = "omap-dma-engine", 10127bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King .owner = THIS_MODULE, 10138d30662aac256eb61bc2f1d9cf1191825ef96328Jon Hunter .of_match_table = of_match_ptr(omap_dma_match), 10147bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King }, 10157bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King}; 10167bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 10177bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingbool omap_dma_filter_fn(struct dma_chan *chan, void *param) 10187bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 10197bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King if (chan->device->dev->driver == &omap_dma_driver.driver) { 10207bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King struct omap_chan *c = to_omap_dma_chan(chan); 10217bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King unsigned req = *(unsigned *)param; 10227bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 10237bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return req == c->dma_sig; 10247bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King } 10257bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King return false; 10267bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 10277bedaa5537604f34d1d63c5ec7891e559d2a61edRussell KingEXPORT_SYMBOL_GPL(omap_dma_filter_fn); 10287bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 10297bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic int omap_dma_init(void) 10307bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 1031be1f94812c2cc0aaf696d39fe23104763ea52b5bTony Lindgren return platform_driver_register(&omap_dma_driver); 10327bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 10337bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingsubsys_initcall(omap_dma_init); 10347bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 10357bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingstatic void __exit omap_dma_exit(void) 10367bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King{ 10377bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King platform_driver_unregister(&omap_dma_driver); 10387bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King} 10397bedaa5537604f34d1d63c5ec7891e559d2a61edRussell Kingmodule_exit(omap_dma_exit); 10407bedaa5537604f34d1d63c5ec7891e559d2a61edRussell King 10417bedaa5537604f34d1d63c5ec7891e559d2a61edRussell KingMODULE_AUTHOR("Russell King"); 10427bedaa5537604f34d1d63c5ec7891e559d2a61edRussell KingMODULE_LICENSE("GPL"); 1043