omap-dma.c 29 KB

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