omap-dma.c 31 KB

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