omap-dma.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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. void *context)
  715. {
  716. struct omap_dmadev *od = to_omap_dma_dev(chan->device);
  717. struct omap_chan *c = to_omap_dma_chan(chan);
  718. enum dma_slave_buswidth dev_width;
  719. struct omap_desc *d;
  720. dma_addr_t dev_addr;
  721. unsigned es;
  722. u32 burst;
  723. if (dir == DMA_DEV_TO_MEM) {
  724. dev_addr = c->cfg.src_addr;
  725. dev_width = c->cfg.src_addr_width;
  726. burst = c->cfg.src_maxburst;
  727. } else if (dir == DMA_MEM_TO_DEV) {
  728. dev_addr = c->cfg.dst_addr;
  729. dev_width = c->cfg.dst_addr_width;
  730. burst = c->cfg.dst_maxburst;
  731. } else {
  732. dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  733. return NULL;
  734. }
  735. /* Bus width translates to the element size (ES) */
  736. switch (dev_width) {
  737. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  738. es = CSDP_DATA_TYPE_8;
  739. break;
  740. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  741. es = CSDP_DATA_TYPE_16;
  742. break;
  743. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  744. es = CSDP_DATA_TYPE_32;
  745. break;
  746. default: /* not reached */
  747. return NULL;
  748. }
  749. /* Now allocate and setup the descriptor. */
  750. d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC);
  751. if (!d)
  752. return NULL;
  753. d->dir = dir;
  754. d->dev_addr = dev_addr;
  755. d->fi = burst;
  756. d->es = es;
  757. d->sg[0].addr = buf_addr;
  758. d->sg[0].en = period_len / es_bytes[es];
  759. d->sg[0].fn = buf_len / period_len;
  760. d->sglen = 1;
  761. d->ccr = c->ccr;
  762. if (dir == DMA_DEV_TO_MEM)
  763. d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_CONSTANT;
  764. else
  765. d->ccr |= CCR_DST_AMODE_CONSTANT | CCR_SRC_AMODE_POSTINC;
  766. d->cicr = CICR_DROP_IE;
  767. if (flags & DMA_PREP_INTERRUPT)
  768. d->cicr |= CICR_FRAME_IE;
  769. d->csdp = es;
  770. if (dma_omap1()) {
  771. d->cicr |= CICR_TOUT_IE;
  772. if (dir == DMA_DEV_TO_MEM)
  773. d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_MPUI;
  774. else
  775. d->csdp |= CSDP_DST_PORT_MPUI | CSDP_SRC_PORT_EMIFF;
  776. } else {
  777. if (burst)
  778. d->ccr |= CCR_SYNC_PACKET;
  779. else
  780. d->ccr |= CCR_SYNC_ELEMENT;
  781. if (dir == DMA_DEV_TO_MEM)
  782. d->ccr |= CCR_TRIGGER_SRC;
  783. d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE;
  784. d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64;
  785. }
  786. if (__dma_omap15xx(od->plat->dma_attr))
  787. d->ccr |= CCR_AUTO_INIT | CCR_REPEAT;
  788. else
  789. d->clnk_ctrl = c->dma_ch | CLNK_CTRL_ENABLE_LNK;
  790. c->cyclic = true;
  791. return vchan_tx_prep(&c->vc, &d->vd, flags);
  792. }
  793. static int omap_dma_slave_config(struct omap_chan *c, struct dma_slave_config *cfg)
  794. {
  795. if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
  796. cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
  797. return -EINVAL;
  798. memcpy(&c->cfg, cfg, sizeof(c->cfg));
  799. return 0;
  800. }
  801. static int omap_dma_terminate_all(struct omap_chan *c)
  802. {
  803. struct omap_dmadev *d = to_omap_dma_dev(c->vc.chan.device);
  804. unsigned long flags;
  805. LIST_HEAD(head);
  806. spin_lock_irqsave(&c->vc.lock, flags);
  807. /* Prevent this channel being scheduled */
  808. spin_lock(&d->lock);
  809. list_del_init(&c->node);
  810. spin_unlock(&d->lock);
  811. /*
  812. * Stop DMA activity: we assume the callback will not be called
  813. * after omap_dma_stop() returns (even if it does, it will see
  814. * c->desc is NULL and exit.)
  815. */
  816. if (c->desc) {
  817. c->desc = NULL;
  818. /* Avoid stopping the dma twice */
  819. if (!c->paused)
  820. omap_dma_stop(c);
  821. }
  822. if (c->cyclic) {
  823. c->cyclic = false;
  824. c->paused = false;
  825. }
  826. vchan_get_all_descriptors(&c->vc, &head);
  827. spin_unlock_irqrestore(&c->vc.lock, flags);
  828. vchan_dma_desc_free_list(&c->vc, &head);
  829. return 0;
  830. }
  831. static int omap_dma_pause(struct omap_chan *c)
  832. {
  833. /* Pause/Resume only allowed with cyclic mode */
  834. if (!c->cyclic)
  835. return -EINVAL;
  836. if (!c->paused) {
  837. omap_dma_stop(c);
  838. c->paused = true;
  839. }
  840. return 0;
  841. }
  842. static int omap_dma_resume(struct omap_chan *c)
  843. {
  844. /* Pause/Resume only allowed with cyclic mode */
  845. if (!c->cyclic)
  846. return -EINVAL;
  847. if (c->paused) {
  848. omap_dma_start(c, c->desc);
  849. c->paused = false;
  850. }
  851. return 0;
  852. }
  853. static int omap_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  854. unsigned long arg)
  855. {
  856. struct omap_chan *c = to_omap_dma_chan(chan);
  857. int ret;
  858. switch (cmd) {
  859. case DMA_SLAVE_CONFIG:
  860. ret = omap_dma_slave_config(c, (struct dma_slave_config *)arg);
  861. break;
  862. case DMA_TERMINATE_ALL:
  863. ret = omap_dma_terminate_all(c);
  864. break;
  865. case DMA_PAUSE:
  866. ret = omap_dma_pause(c);
  867. break;
  868. case DMA_RESUME:
  869. ret = omap_dma_resume(c);
  870. break;
  871. default:
  872. ret = -ENXIO;
  873. break;
  874. }
  875. return ret;
  876. }
  877. static int omap_dma_chan_init(struct omap_dmadev *od, int dma_sig)
  878. {
  879. struct omap_chan *c;
  880. c = kzalloc(sizeof(*c), GFP_KERNEL);
  881. if (!c)
  882. return -ENOMEM;
  883. c->reg_map = od->reg_map;
  884. c->dma_sig = dma_sig;
  885. c->vc.desc_free = omap_dma_desc_free;
  886. vchan_init(&c->vc, &od->ddev);
  887. INIT_LIST_HEAD(&c->node);
  888. od->ddev.chancnt++;
  889. return 0;
  890. }
  891. static void omap_dma_free(struct omap_dmadev *od)
  892. {
  893. tasklet_kill(&od->task);
  894. while (!list_empty(&od->ddev.channels)) {
  895. struct omap_chan *c = list_first_entry(&od->ddev.channels,
  896. struct omap_chan, vc.chan.device_node);
  897. list_del(&c->vc.chan.device_node);
  898. tasklet_kill(&c->vc.task);
  899. kfree(c);
  900. }
  901. }
  902. #define OMAP_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  903. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  904. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES))
  905. static int omap_dma_device_slave_caps(struct dma_chan *dchan,
  906. struct dma_slave_caps *caps)
  907. {
  908. caps->src_addr_widths = OMAP_DMA_BUSWIDTHS;
  909. caps->dstn_addr_widths = OMAP_DMA_BUSWIDTHS;
  910. caps->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  911. caps->cmd_pause = true;
  912. caps->cmd_terminate = true;
  913. caps->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  914. return 0;
  915. }
  916. static int omap_dma_probe(struct platform_device *pdev)
  917. {
  918. struct omap_dmadev *od;
  919. struct resource *res;
  920. int rc, i, irq;
  921. od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  922. if (!od)
  923. return -ENOMEM;
  924. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  925. od->base = devm_ioremap_resource(&pdev->dev, res);
  926. if (IS_ERR(od->base))
  927. return PTR_ERR(od->base);
  928. od->plat = omap_get_plat_info();
  929. if (!od->plat)
  930. return -EPROBE_DEFER;
  931. od->reg_map = od->plat->reg_map;
  932. dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  933. dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  934. od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources;
  935. od->ddev.device_free_chan_resources = omap_dma_free_chan_resources;
  936. od->ddev.device_tx_status = omap_dma_tx_status;
  937. od->ddev.device_issue_pending = omap_dma_issue_pending;
  938. od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg;
  939. od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic;
  940. od->ddev.device_control = omap_dma_control;
  941. od->ddev.device_slave_caps = omap_dma_device_slave_caps;
  942. od->ddev.dev = &pdev->dev;
  943. INIT_LIST_HEAD(&od->ddev.channels);
  944. INIT_LIST_HEAD(&od->pending);
  945. spin_lock_init(&od->lock);
  946. spin_lock_init(&od->irq_lock);
  947. tasklet_init(&od->task, omap_dma_sched, (unsigned long)od);
  948. for (i = 0; i < 127; i++) {
  949. rc = omap_dma_chan_init(od, i);
  950. if (rc) {
  951. omap_dma_free(od);
  952. return rc;
  953. }
  954. }
  955. irq = platform_get_irq(pdev, 1);
  956. if (irq <= 0) {
  957. dev_info(&pdev->dev, "failed to get L1 IRQ: %d\n", irq);
  958. od->legacy = true;
  959. } else {
  960. /* Disable all interrupts */
  961. od->irq_enable_mask = 0;
  962. omap_dma_glbl_write(od, IRQENABLE_L1, 0);
  963. rc = devm_request_irq(&pdev->dev, irq, omap_dma_irq,
  964. IRQF_SHARED, "omap-dma-engine", od);
  965. if (rc)
  966. return rc;
  967. }
  968. rc = dma_async_device_register(&od->ddev);
  969. if (rc) {
  970. pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n",
  971. rc);
  972. omap_dma_free(od);
  973. return rc;
  974. }
  975. platform_set_drvdata(pdev, od);
  976. if (pdev->dev.of_node) {
  977. omap_dma_info.dma_cap = od->ddev.cap_mask;
  978. /* Device-tree DMA controller registration */
  979. rc = of_dma_controller_register(pdev->dev.of_node,
  980. of_dma_simple_xlate, &omap_dma_info);
  981. if (rc) {
  982. pr_warn("OMAP-DMA: failed to register DMA controller\n");
  983. dma_async_device_unregister(&od->ddev);
  984. omap_dma_free(od);
  985. }
  986. }
  987. dev_info(&pdev->dev, "OMAP DMA engine driver\n");
  988. return rc;
  989. }
  990. static int omap_dma_remove(struct platform_device *pdev)
  991. {
  992. struct omap_dmadev *od = platform_get_drvdata(pdev);
  993. if (pdev->dev.of_node)
  994. of_dma_controller_free(pdev->dev.of_node);
  995. dma_async_device_unregister(&od->ddev);
  996. if (!od->legacy) {
  997. /* Disable all interrupts */
  998. omap_dma_glbl_write(od, IRQENABLE_L0, 0);
  999. }
  1000. omap_dma_free(od);
  1001. return 0;
  1002. }
  1003. static const struct of_device_id omap_dma_match[] = {
  1004. { .compatible = "ti,omap2420-sdma", },
  1005. { .compatible = "ti,omap2430-sdma", },
  1006. { .compatible = "ti,omap3430-sdma", },
  1007. { .compatible = "ti,omap3630-sdma", },
  1008. { .compatible = "ti,omap4430-sdma", },
  1009. {},
  1010. };
  1011. MODULE_DEVICE_TABLE(of, omap_dma_match);
  1012. static struct platform_driver omap_dma_driver = {
  1013. .probe = omap_dma_probe,
  1014. .remove = omap_dma_remove,
  1015. .driver = {
  1016. .name = "omap-dma-engine",
  1017. .owner = THIS_MODULE,
  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");