core.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /*
  2. * Core driver for the Synopsys DesignWare DMA Controller
  3. *
  4. * Copyright (C) 2007-2008 Atmel Corporation
  5. * Copyright (C) 2010-2011 ST Microelectronics
  6. * Copyright (C) 2013 Intel Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/bitops.h>
  13. #include <linux/delay.h>
  14. #include <linux/dmaengine.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/dmapool.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/io.h>
  21. #include <linux/mm.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/pm_runtime.h>
  25. #include "../dmaengine.h"
  26. #include "internal.h"
  27. /*
  28. * This supports the Synopsys "DesignWare AHB Central DMA Controller",
  29. * (DW_ahb_dmac) which is used with various AMBA 2.0 systems (not all
  30. * of which use ARM any more). See the "Databook" from Synopsys for
  31. * information beyond what licensees probably provide.
  32. *
  33. * The driver has been tested with the Atmel AT32AP7000, which does not
  34. * support descriptor writeback.
  35. */
  36. #define DWC_DEFAULT_CTLLO(_chan) ({ \
  37. struct dw_dma_chan *_dwc = to_dw_dma_chan(_chan); \
  38. struct dma_slave_config *_sconfig = &_dwc->dma_sconfig; \
  39. bool _is_slave = is_slave_direction(_dwc->direction); \
  40. u8 _smsize = _is_slave ? _sconfig->src_maxburst : \
  41. DW_DMA_MSIZE_16; \
  42. u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \
  43. DW_DMA_MSIZE_16; \
  44. u8 _dms = (_dwc->direction == DMA_MEM_TO_DEV) ? \
  45. _dwc->dws.p_master : _dwc->dws.m_master; \
  46. u8 _sms = (_dwc->direction == DMA_DEV_TO_MEM) ? \
  47. _dwc->dws.p_master : _dwc->dws.m_master; \
  48. \
  49. (DWC_CTLL_DST_MSIZE(_dmsize) \
  50. | DWC_CTLL_SRC_MSIZE(_smsize) \
  51. | DWC_CTLL_LLP_D_EN \
  52. | DWC_CTLL_LLP_S_EN \
  53. | DWC_CTLL_DMS(_dms) \
  54. | DWC_CTLL_SMS(_sms)); \
  55. })
  56. /* The set of bus widths supported by the DMA controller */
  57. #define DW_DMA_BUSWIDTHS \
  58. BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \
  59. BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  60. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  61. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)
  62. /*----------------------------------------------------------------------*/
  63. static struct device *chan2dev(struct dma_chan *chan)
  64. {
  65. return &chan->dev->device;
  66. }
  67. static struct dw_desc *dwc_first_active(struct dw_dma_chan *dwc)
  68. {
  69. return to_dw_desc(dwc->active_list.next);
  70. }
  71. static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx)
  72. {
  73. struct dw_desc *desc = txd_to_dw_desc(tx);
  74. struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan);
  75. dma_cookie_t cookie;
  76. unsigned long flags;
  77. spin_lock_irqsave(&dwc->lock, flags);
  78. cookie = dma_cookie_assign(tx);
  79. /*
  80. * REVISIT: We should attempt to chain as many descriptors as
  81. * possible, perhaps even appending to those already submitted
  82. * for DMA. But this is hard to do in a race-free manner.
  83. */
  84. list_add_tail(&desc->desc_node, &dwc->queue);
  85. spin_unlock_irqrestore(&dwc->lock, flags);
  86. dev_vdbg(chan2dev(tx->chan), "%s: queued %u\n",
  87. __func__, desc->txd.cookie);
  88. return cookie;
  89. }
  90. static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc)
  91. {
  92. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  93. struct dw_desc *desc;
  94. dma_addr_t phys;
  95. desc = dma_pool_zalloc(dw->desc_pool, GFP_ATOMIC, &phys);
  96. if (!desc)
  97. return NULL;
  98. dwc->descs_allocated++;
  99. INIT_LIST_HEAD(&desc->tx_list);
  100. dma_async_tx_descriptor_init(&desc->txd, &dwc->chan);
  101. desc->txd.tx_submit = dwc_tx_submit;
  102. desc->txd.flags = DMA_CTRL_ACK;
  103. desc->txd.phys = phys;
  104. return desc;
  105. }
  106. static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc)
  107. {
  108. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  109. struct dw_desc *child, *_next;
  110. if (unlikely(!desc))
  111. return;
  112. list_for_each_entry_safe(child, _next, &desc->tx_list, desc_node) {
  113. list_del(&child->desc_node);
  114. dma_pool_free(dw->desc_pool, child, child->txd.phys);
  115. dwc->descs_allocated--;
  116. }
  117. dma_pool_free(dw->desc_pool, desc, desc->txd.phys);
  118. dwc->descs_allocated--;
  119. }
  120. static void dwc_initialize_chan_idma32(struct dw_dma_chan *dwc)
  121. {
  122. u32 cfghi = 0;
  123. u32 cfglo = 0;
  124. /* Set default burst alignment */
  125. cfglo |= IDMA32C_CFGL_DST_BURST_ALIGN | IDMA32C_CFGL_SRC_BURST_ALIGN;
  126. /* Low 4 bits of the request lines */
  127. cfghi |= IDMA32C_CFGH_DST_PER(dwc->dws.dst_id & 0xf);
  128. cfghi |= IDMA32C_CFGH_SRC_PER(dwc->dws.src_id & 0xf);
  129. /* Request line extension (2 bits) */
  130. cfghi |= IDMA32C_CFGH_DST_PER_EXT(dwc->dws.dst_id >> 4 & 0x3);
  131. cfghi |= IDMA32C_CFGH_SRC_PER_EXT(dwc->dws.src_id >> 4 & 0x3);
  132. channel_writel(dwc, CFG_LO, cfglo);
  133. channel_writel(dwc, CFG_HI, cfghi);
  134. }
  135. static void dwc_initialize_chan_dw(struct dw_dma_chan *dwc)
  136. {
  137. u32 cfghi = DWC_CFGH_FIFO_MODE;
  138. u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority);
  139. bool hs_polarity = dwc->dws.hs_polarity;
  140. cfghi |= DWC_CFGH_DST_PER(dwc->dws.dst_id);
  141. cfghi |= DWC_CFGH_SRC_PER(dwc->dws.src_id);
  142. /* Set polarity of handshake interface */
  143. cfglo |= hs_polarity ? DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL : 0;
  144. channel_writel(dwc, CFG_LO, cfglo);
  145. channel_writel(dwc, CFG_HI, cfghi);
  146. }
  147. static void dwc_initialize(struct dw_dma_chan *dwc)
  148. {
  149. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  150. if (test_bit(DW_DMA_IS_INITIALIZED, &dwc->flags))
  151. return;
  152. if (dw->pdata->is_idma32)
  153. dwc_initialize_chan_idma32(dwc);
  154. else
  155. dwc_initialize_chan_dw(dwc);
  156. /* Enable interrupts */
  157. channel_set_bit(dw, MASK.XFER, dwc->mask);
  158. channel_set_bit(dw, MASK.ERROR, dwc->mask);
  159. set_bit(DW_DMA_IS_INITIALIZED, &dwc->flags);
  160. }
  161. /*----------------------------------------------------------------------*/
  162. static inline void dwc_dump_chan_regs(struct dw_dma_chan *dwc)
  163. {
  164. dev_err(chan2dev(&dwc->chan),
  165. " SAR: 0x%x DAR: 0x%x LLP: 0x%x CTL: 0x%x:%08x\n",
  166. channel_readl(dwc, SAR),
  167. channel_readl(dwc, DAR),
  168. channel_readl(dwc, LLP),
  169. channel_readl(dwc, CTL_HI),
  170. channel_readl(dwc, CTL_LO));
  171. }
  172. static inline void dwc_chan_disable(struct dw_dma *dw, struct dw_dma_chan *dwc)
  173. {
  174. channel_clear_bit(dw, CH_EN, dwc->mask);
  175. while (dma_readl(dw, CH_EN) & dwc->mask)
  176. cpu_relax();
  177. }
  178. static u32 bytes2block(struct dw_dma_chan *dwc, size_t bytes,
  179. unsigned int width, size_t *len)
  180. {
  181. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  182. u32 block;
  183. /* Always in bytes for iDMA 32-bit */
  184. if (dw->pdata->is_idma32)
  185. width = 0;
  186. if ((bytes >> width) > dwc->block_size) {
  187. block = dwc->block_size;
  188. *len = block << width;
  189. } else {
  190. block = bytes >> width;
  191. *len = bytes;
  192. }
  193. return block;
  194. }
  195. static size_t block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
  196. {
  197. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  198. if (dw->pdata->is_idma32)
  199. return IDMA32C_CTLH_BLOCK_TS(block);
  200. return DWC_CTLH_BLOCK_TS(block) << width;
  201. }
  202. /*----------------------------------------------------------------------*/
  203. /* Perform single block transfer */
  204. static inline void dwc_do_single_block(struct dw_dma_chan *dwc,
  205. struct dw_desc *desc)
  206. {
  207. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  208. u32 ctllo;
  209. /*
  210. * Software emulation of LLP mode relies on interrupts to continue
  211. * multi block transfer.
  212. */
  213. ctllo = lli_read(desc, ctllo) | DWC_CTLL_INT_EN;
  214. channel_writel(dwc, SAR, lli_read(desc, sar));
  215. channel_writel(dwc, DAR, lli_read(desc, dar));
  216. channel_writel(dwc, CTL_LO, ctllo);
  217. channel_writel(dwc, CTL_HI, lli_read(desc, ctlhi));
  218. channel_set_bit(dw, CH_EN, dwc->mask);
  219. /* Move pointer to next descriptor */
  220. dwc->tx_node_active = dwc->tx_node_active->next;
  221. }
  222. /* Called with dwc->lock held and bh disabled */
  223. static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first)
  224. {
  225. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  226. u8 lms = DWC_LLP_LMS(dwc->dws.m_master);
  227. unsigned long was_soft_llp;
  228. /* ASSERT: channel is idle */
  229. if (dma_readl(dw, CH_EN) & dwc->mask) {
  230. dev_err(chan2dev(&dwc->chan),
  231. "%s: BUG: Attempted to start non-idle channel\n",
  232. __func__);
  233. dwc_dump_chan_regs(dwc);
  234. /* The tasklet will hopefully advance the queue... */
  235. return;
  236. }
  237. if (dwc->nollp) {
  238. was_soft_llp = test_and_set_bit(DW_DMA_IS_SOFT_LLP,
  239. &dwc->flags);
  240. if (was_soft_llp) {
  241. dev_err(chan2dev(&dwc->chan),
  242. "BUG: Attempted to start new LLP transfer inside ongoing one\n");
  243. return;
  244. }
  245. dwc_initialize(dwc);
  246. first->residue = first->total_len;
  247. dwc->tx_node_active = &first->tx_list;
  248. /* Submit first block */
  249. dwc_do_single_block(dwc, first);
  250. return;
  251. }
  252. dwc_initialize(dwc);
  253. channel_writel(dwc, LLP, first->txd.phys | lms);
  254. channel_writel(dwc, CTL_LO, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  255. channel_writel(dwc, CTL_HI, 0);
  256. channel_set_bit(dw, CH_EN, dwc->mask);
  257. }
  258. static void dwc_dostart_first_queued(struct dw_dma_chan *dwc)
  259. {
  260. struct dw_desc *desc;
  261. if (list_empty(&dwc->queue))
  262. return;
  263. list_move(dwc->queue.next, &dwc->active_list);
  264. desc = dwc_first_active(dwc);
  265. dev_vdbg(chan2dev(&dwc->chan), "%s: started %u\n", __func__, desc->txd.cookie);
  266. dwc_dostart(dwc, desc);
  267. }
  268. /*----------------------------------------------------------------------*/
  269. static void
  270. dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,
  271. bool callback_required)
  272. {
  273. struct dma_async_tx_descriptor *txd = &desc->txd;
  274. struct dw_desc *child;
  275. unsigned long flags;
  276. struct dmaengine_desc_callback cb;
  277. dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie);
  278. spin_lock_irqsave(&dwc->lock, flags);
  279. dma_cookie_complete(txd);
  280. if (callback_required)
  281. dmaengine_desc_get_callback(txd, &cb);
  282. else
  283. memset(&cb, 0, sizeof(cb));
  284. /* async_tx_ack */
  285. list_for_each_entry(child, &desc->tx_list, desc_node)
  286. async_tx_ack(&child->txd);
  287. async_tx_ack(&desc->txd);
  288. dwc_desc_put(dwc, desc);
  289. spin_unlock_irqrestore(&dwc->lock, flags);
  290. dmaengine_desc_callback_invoke(&cb, NULL);
  291. }
  292. static void dwc_complete_all(struct dw_dma *dw, struct dw_dma_chan *dwc)
  293. {
  294. struct dw_desc *desc, *_desc;
  295. LIST_HEAD(list);
  296. unsigned long flags;
  297. spin_lock_irqsave(&dwc->lock, flags);
  298. if (dma_readl(dw, CH_EN) & dwc->mask) {
  299. dev_err(chan2dev(&dwc->chan),
  300. "BUG: XFER bit set, but channel not idle!\n");
  301. /* Try to continue after resetting the channel... */
  302. dwc_chan_disable(dw, dwc);
  303. }
  304. /*
  305. * Submit queued descriptors ASAP, i.e. before we go through
  306. * the completed ones.
  307. */
  308. list_splice_init(&dwc->active_list, &list);
  309. dwc_dostart_first_queued(dwc);
  310. spin_unlock_irqrestore(&dwc->lock, flags);
  311. list_for_each_entry_safe(desc, _desc, &list, desc_node)
  312. dwc_descriptor_complete(dwc, desc, true);
  313. }
  314. /* Returns how many bytes were already received from source */
  315. static inline u32 dwc_get_sent(struct dw_dma_chan *dwc)
  316. {
  317. u32 ctlhi = channel_readl(dwc, CTL_HI);
  318. u32 ctllo = channel_readl(dwc, CTL_LO);
  319. return block2bytes(dwc, ctlhi, ctllo >> 4 & 7);
  320. }
  321. static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
  322. {
  323. dma_addr_t llp;
  324. struct dw_desc *desc, *_desc;
  325. struct dw_desc *child;
  326. u32 status_xfer;
  327. unsigned long flags;
  328. spin_lock_irqsave(&dwc->lock, flags);
  329. llp = channel_readl(dwc, LLP);
  330. status_xfer = dma_readl(dw, RAW.XFER);
  331. if (status_xfer & dwc->mask) {
  332. /* Everything we've submitted is done */
  333. dma_writel(dw, CLEAR.XFER, dwc->mask);
  334. if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) {
  335. struct list_head *head, *active = dwc->tx_node_active;
  336. /*
  337. * We are inside first active descriptor.
  338. * Otherwise something is really wrong.
  339. */
  340. desc = dwc_first_active(dwc);
  341. head = &desc->tx_list;
  342. if (active != head) {
  343. /* Update residue to reflect last sent descriptor */
  344. if (active == head->next)
  345. desc->residue -= desc->len;
  346. else
  347. desc->residue -= to_dw_desc(active->prev)->len;
  348. child = to_dw_desc(active);
  349. /* Submit next block */
  350. dwc_do_single_block(dwc, child);
  351. spin_unlock_irqrestore(&dwc->lock, flags);
  352. return;
  353. }
  354. /* We are done here */
  355. clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
  356. }
  357. spin_unlock_irqrestore(&dwc->lock, flags);
  358. dwc_complete_all(dw, dwc);
  359. return;
  360. }
  361. if (list_empty(&dwc->active_list)) {
  362. spin_unlock_irqrestore(&dwc->lock, flags);
  363. return;
  364. }
  365. if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) {
  366. dev_vdbg(chan2dev(&dwc->chan), "%s: soft LLP mode\n", __func__);
  367. spin_unlock_irqrestore(&dwc->lock, flags);
  368. return;
  369. }
  370. dev_vdbg(chan2dev(&dwc->chan), "%s: llp=%pad\n", __func__, &llp);
  371. list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
  372. /* Initial residue value */
  373. desc->residue = desc->total_len;
  374. /* Check first descriptors addr */
  375. if (desc->txd.phys == DWC_LLP_LOC(llp)) {
  376. spin_unlock_irqrestore(&dwc->lock, flags);
  377. return;
  378. }
  379. /* Check first descriptors llp */
  380. if (lli_read(desc, llp) == llp) {
  381. /* This one is currently in progress */
  382. desc->residue -= dwc_get_sent(dwc);
  383. spin_unlock_irqrestore(&dwc->lock, flags);
  384. return;
  385. }
  386. desc->residue -= desc->len;
  387. list_for_each_entry(child, &desc->tx_list, desc_node) {
  388. if (lli_read(child, llp) == llp) {
  389. /* Currently in progress */
  390. desc->residue -= dwc_get_sent(dwc);
  391. spin_unlock_irqrestore(&dwc->lock, flags);
  392. return;
  393. }
  394. desc->residue -= child->len;
  395. }
  396. /*
  397. * No descriptors so far seem to be in progress, i.e.
  398. * this one must be done.
  399. */
  400. spin_unlock_irqrestore(&dwc->lock, flags);
  401. dwc_descriptor_complete(dwc, desc, true);
  402. spin_lock_irqsave(&dwc->lock, flags);
  403. }
  404. dev_err(chan2dev(&dwc->chan),
  405. "BUG: All descriptors done, but channel not idle!\n");
  406. /* Try to continue after resetting the channel... */
  407. dwc_chan_disable(dw, dwc);
  408. dwc_dostart_first_queued(dwc);
  409. spin_unlock_irqrestore(&dwc->lock, flags);
  410. }
  411. static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_desc *desc)
  412. {
  413. dev_crit(chan2dev(&dwc->chan), " desc: s0x%x d0x%x l0x%x c0x%x:%x\n",
  414. lli_read(desc, sar),
  415. lli_read(desc, dar),
  416. lli_read(desc, llp),
  417. lli_read(desc, ctlhi),
  418. lli_read(desc, ctllo));
  419. }
  420. static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc)
  421. {
  422. struct dw_desc *bad_desc;
  423. struct dw_desc *child;
  424. unsigned long flags;
  425. dwc_scan_descriptors(dw, dwc);
  426. spin_lock_irqsave(&dwc->lock, flags);
  427. /*
  428. * The descriptor currently at the head of the active list is
  429. * borked. Since we don't have any way to report errors, we'll
  430. * just have to scream loudly and try to carry on.
  431. */
  432. bad_desc = dwc_first_active(dwc);
  433. list_del_init(&bad_desc->desc_node);
  434. list_move(dwc->queue.next, dwc->active_list.prev);
  435. /* Clear the error flag and try to restart the controller */
  436. dma_writel(dw, CLEAR.ERROR, dwc->mask);
  437. if (!list_empty(&dwc->active_list))
  438. dwc_dostart(dwc, dwc_first_active(dwc));
  439. /*
  440. * WARN may seem harsh, but since this only happens
  441. * when someone submits a bad physical address in a
  442. * descriptor, we should consider ourselves lucky that the
  443. * controller flagged an error instead of scribbling over
  444. * random memory locations.
  445. */
  446. dev_WARN(chan2dev(&dwc->chan), "Bad descriptor submitted for DMA!\n"
  447. " cookie: %d\n", bad_desc->txd.cookie);
  448. dwc_dump_lli(dwc, bad_desc);
  449. list_for_each_entry(child, &bad_desc->tx_list, desc_node)
  450. dwc_dump_lli(dwc, child);
  451. spin_unlock_irqrestore(&dwc->lock, flags);
  452. /* Pretend the descriptor completed successfully */
  453. dwc_descriptor_complete(dwc, bad_desc, true);
  454. }
  455. /* --------------------- Cyclic DMA API extensions -------------------- */
  456. dma_addr_t dw_dma_get_src_addr(struct dma_chan *chan)
  457. {
  458. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  459. return channel_readl(dwc, SAR);
  460. }
  461. EXPORT_SYMBOL(dw_dma_get_src_addr);
  462. dma_addr_t dw_dma_get_dst_addr(struct dma_chan *chan)
  463. {
  464. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  465. return channel_readl(dwc, DAR);
  466. }
  467. EXPORT_SYMBOL(dw_dma_get_dst_addr);
  468. /* Called with dwc->lock held and all DMAC interrupts disabled */
  469. static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc,
  470. u32 status_block, u32 status_err, u32 status_xfer)
  471. {
  472. unsigned long flags;
  473. if (status_block & dwc->mask) {
  474. void (*callback)(void *param);
  475. void *callback_param;
  476. dev_vdbg(chan2dev(&dwc->chan), "new cyclic period llp 0x%08x\n",
  477. channel_readl(dwc, LLP));
  478. dma_writel(dw, CLEAR.BLOCK, dwc->mask);
  479. callback = dwc->cdesc->period_callback;
  480. callback_param = dwc->cdesc->period_callback_param;
  481. if (callback)
  482. callback(callback_param);
  483. }
  484. /*
  485. * Error and transfer complete are highly unlikely, and will most
  486. * likely be due to a configuration error by the user.
  487. */
  488. if (unlikely(status_err & dwc->mask) ||
  489. unlikely(status_xfer & dwc->mask)) {
  490. unsigned int i;
  491. dev_err(chan2dev(&dwc->chan),
  492. "cyclic DMA unexpected %s interrupt, stopping DMA transfer\n",
  493. status_xfer ? "xfer" : "error");
  494. spin_lock_irqsave(&dwc->lock, flags);
  495. dwc_dump_chan_regs(dwc);
  496. dwc_chan_disable(dw, dwc);
  497. /* Make sure DMA does not restart by loading a new list */
  498. channel_writel(dwc, LLP, 0);
  499. channel_writel(dwc, CTL_LO, 0);
  500. channel_writel(dwc, CTL_HI, 0);
  501. dma_writel(dw, CLEAR.BLOCK, dwc->mask);
  502. dma_writel(dw, CLEAR.ERROR, dwc->mask);
  503. dma_writel(dw, CLEAR.XFER, dwc->mask);
  504. for (i = 0; i < dwc->cdesc->periods; i++)
  505. dwc_dump_lli(dwc, dwc->cdesc->desc[i]);
  506. spin_unlock_irqrestore(&dwc->lock, flags);
  507. }
  508. /* Re-enable interrupts */
  509. channel_set_bit(dw, MASK.BLOCK, dwc->mask);
  510. }
  511. /* ------------------------------------------------------------------------- */
  512. static void dw_dma_tasklet(unsigned long data)
  513. {
  514. struct dw_dma *dw = (struct dw_dma *)data;
  515. struct dw_dma_chan *dwc;
  516. u32 status_block;
  517. u32 status_xfer;
  518. u32 status_err;
  519. unsigned int i;
  520. status_block = dma_readl(dw, RAW.BLOCK);
  521. status_xfer = dma_readl(dw, RAW.XFER);
  522. status_err = dma_readl(dw, RAW.ERROR);
  523. dev_vdbg(dw->dma.dev, "%s: status_err=%x\n", __func__, status_err);
  524. for (i = 0; i < dw->dma.chancnt; i++) {
  525. dwc = &dw->chan[i];
  526. if (test_bit(DW_DMA_IS_CYCLIC, &dwc->flags))
  527. dwc_handle_cyclic(dw, dwc, status_block, status_err,
  528. status_xfer);
  529. else if (status_err & (1 << i))
  530. dwc_handle_error(dw, dwc);
  531. else if (status_xfer & (1 << i))
  532. dwc_scan_descriptors(dw, dwc);
  533. }
  534. /* Re-enable interrupts */
  535. channel_set_bit(dw, MASK.XFER, dw->all_chan_mask);
  536. channel_set_bit(dw, MASK.ERROR, dw->all_chan_mask);
  537. }
  538. static irqreturn_t dw_dma_interrupt(int irq, void *dev_id)
  539. {
  540. struct dw_dma *dw = dev_id;
  541. u32 status;
  542. /* Check if we have any interrupt from the DMAC which is not in use */
  543. if (!dw->in_use)
  544. return IRQ_NONE;
  545. status = dma_readl(dw, STATUS_INT);
  546. dev_vdbg(dw->dma.dev, "%s: status=0x%x\n", __func__, status);
  547. /* Check if we have any interrupt from the DMAC */
  548. if (!status)
  549. return IRQ_NONE;
  550. /*
  551. * Just disable the interrupts. We'll turn them back on in the
  552. * softirq handler.
  553. */
  554. channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask);
  555. channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask);
  556. channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask);
  557. status = dma_readl(dw, STATUS_INT);
  558. if (status) {
  559. dev_err(dw->dma.dev,
  560. "BUG: Unexpected interrupts pending: 0x%x\n",
  561. status);
  562. /* Try to recover */
  563. channel_clear_bit(dw, MASK.XFER, (1 << 8) - 1);
  564. channel_clear_bit(dw, MASK.BLOCK, (1 << 8) - 1);
  565. channel_clear_bit(dw, MASK.SRC_TRAN, (1 << 8) - 1);
  566. channel_clear_bit(dw, MASK.DST_TRAN, (1 << 8) - 1);
  567. channel_clear_bit(dw, MASK.ERROR, (1 << 8) - 1);
  568. }
  569. tasklet_schedule(&dw->tasklet);
  570. return IRQ_HANDLED;
  571. }
  572. /*----------------------------------------------------------------------*/
  573. static struct dma_async_tx_descriptor *
  574. dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  575. size_t len, unsigned long flags)
  576. {
  577. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  578. struct dw_dma *dw = to_dw_dma(chan->device);
  579. struct dw_desc *desc;
  580. struct dw_desc *first;
  581. struct dw_desc *prev;
  582. size_t xfer_count;
  583. size_t offset;
  584. u8 m_master = dwc->dws.m_master;
  585. unsigned int src_width;
  586. unsigned int dst_width;
  587. unsigned int data_width = dw->pdata->data_width[m_master];
  588. u32 ctllo;
  589. u8 lms = DWC_LLP_LMS(m_master);
  590. dev_vdbg(chan2dev(chan),
  591. "%s: d%pad s%pad l0x%zx f0x%lx\n", __func__,
  592. &dest, &src, len, flags);
  593. if (unlikely(!len)) {
  594. dev_dbg(chan2dev(chan), "%s: length is zero!\n", __func__);
  595. return NULL;
  596. }
  597. dwc->direction = DMA_MEM_TO_MEM;
  598. src_width = dst_width = __ffs(data_width | src | dest | len);
  599. ctllo = DWC_DEFAULT_CTLLO(chan)
  600. | DWC_CTLL_DST_WIDTH(dst_width)
  601. | DWC_CTLL_SRC_WIDTH(src_width)
  602. | DWC_CTLL_DST_INC
  603. | DWC_CTLL_SRC_INC
  604. | DWC_CTLL_FC_M2M;
  605. prev = first = NULL;
  606. for (offset = 0; offset < len; offset += xfer_count) {
  607. desc = dwc_desc_get(dwc);
  608. if (!desc)
  609. goto err_desc_get;
  610. lli_write(desc, sar, src + offset);
  611. lli_write(desc, dar, dest + offset);
  612. lli_write(desc, ctllo, ctllo);
  613. lli_write(desc, ctlhi, bytes2block(dwc, len - offset, src_width, &xfer_count));
  614. desc->len = xfer_count;
  615. if (!first) {
  616. first = desc;
  617. } else {
  618. lli_write(prev, llp, desc->txd.phys | lms);
  619. list_add_tail(&desc->desc_node, &first->tx_list);
  620. }
  621. prev = desc;
  622. }
  623. if (flags & DMA_PREP_INTERRUPT)
  624. /* Trigger interrupt after last block */
  625. lli_set(prev, ctllo, DWC_CTLL_INT_EN);
  626. prev->lli.llp = 0;
  627. lli_clear(prev, ctllo, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  628. first->txd.flags = flags;
  629. first->total_len = len;
  630. return &first->txd;
  631. err_desc_get:
  632. dwc_desc_put(dwc, first);
  633. return NULL;
  634. }
  635. static struct dma_async_tx_descriptor *
  636. dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
  637. unsigned int sg_len, enum dma_transfer_direction direction,
  638. unsigned long flags, void *context)
  639. {
  640. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  641. struct dw_dma *dw = to_dw_dma(chan->device);
  642. struct dma_slave_config *sconfig = &dwc->dma_sconfig;
  643. struct dw_desc *prev;
  644. struct dw_desc *first;
  645. u32 ctllo;
  646. u8 m_master = dwc->dws.m_master;
  647. u8 lms = DWC_LLP_LMS(m_master);
  648. dma_addr_t reg;
  649. unsigned int reg_width;
  650. unsigned int mem_width;
  651. unsigned int data_width = dw->pdata->data_width[m_master];
  652. unsigned int i;
  653. struct scatterlist *sg;
  654. size_t total_len = 0;
  655. dev_vdbg(chan2dev(chan), "%s\n", __func__);
  656. if (unlikely(!is_slave_direction(direction) || !sg_len))
  657. return NULL;
  658. dwc->direction = direction;
  659. prev = first = NULL;
  660. switch (direction) {
  661. case DMA_MEM_TO_DEV:
  662. reg_width = __ffs(sconfig->dst_addr_width);
  663. reg = sconfig->dst_addr;
  664. ctllo = (DWC_DEFAULT_CTLLO(chan)
  665. | DWC_CTLL_DST_WIDTH(reg_width)
  666. | DWC_CTLL_DST_FIX
  667. | DWC_CTLL_SRC_INC);
  668. ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) :
  669. DWC_CTLL_FC(DW_DMA_FC_D_M2P);
  670. for_each_sg(sgl, sg, sg_len, i) {
  671. struct dw_desc *desc;
  672. u32 len, mem;
  673. size_t dlen;
  674. mem = sg_dma_address(sg);
  675. len = sg_dma_len(sg);
  676. mem_width = __ffs(data_width | mem | len);
  677. slave_sg_todev_fill_desc:
  678. desc = dwc_desc_get(dwc);
  679. if (!desc)
  680. goto err_desc_get;
  681. lli_write(desc, sar, mem);
  682. lli_write(desc, dar, reg);
  683. lli_write(desc, ctlhi, bytes2block(dwc, len, mem_width, &dlen));
  684. lli_write(desc, ctllo, ctllo | DWC_CTLL_SRC_WIDTH(mem_width));
  685. desc->len = dlen;
  686. if (!first) {
  687. first = desc;
  688. } else {
  689. lli_write(prev, llp, desc->txd.phys | lms);
  690. list_add_tail(&desc->desc_node, &first->tx_list);
  691. }
  692. prev = desc;
  693. mem += dlen;
  694. len -= dlen;
  695. total_len += dlen;
  696. if (len)
  697. goto slave_sg_todev_fill_desc;
  698. }
  699. break;
  700. case DMA_DEV_TO_MEM:
  701. reg_width = __ffs(sconfig->src_addr_width);
  702. reg = sconfig->src_addr;
  703. ctllo = (DWC_DEFAULT_CTLLO(chan)
  704. | DWC_CTLL_SRC_WIDTH(reg_width)
  705. | DWC_CTLL_DST_INC
  706. | DWC_CTLL_SRC_FIX);
  707. ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) :
  708. DWC_CTLL_FC(DW_DMA_FC_D_P2M);
  709. for_each_sg(sgl, sg, sg_len, i) {
  710. struct dw_desc *desc;
  711. u32 len, mem;
  712. size_t dlen;
  713. mem = sg_dma_address(sg);
  714. len = sg_dma_len(sg);
  715. slave_sg_fromdev_fill_desc:
  716. desc = dwc_desc_get(dwc);
  717. if (!desc)
  718. goto err_desc_get;
  719. lli_write(desc, sar, reg);
  720. lli_write(desc, dar, mem);
  721. lli_write(desc, ctlhi, bytes2block(dwc, len, reg_width, &dlen));
  722. mem_width = __ffs(data_width | mem | dlen);
  723. lli_write(desc, ctllo, ctllo | DWC_CTLL_DST_WIDTH(mem_width));
  724. desc->len = dlen;
  725. if (!first) {
  726. first = desc;
  727. } else {
  728. lli_write(prev, llp, desc->txd.phys | lms);
  729. list_add_tail(&desc->desc_node, &first->tx_list);
  730. }
  731. prev = desc;
  732. mem += dlen;
  733. len -= dlen;
  734. total_len += dlen;
  735. if (len)
  736. goto slave_sg_fromdev_fill_desc;
  737. }
  738. break;
  739. default:
  740. return NULL;
  741. }
  742. if (flags & DMA_PREP_INTERRUPT)
  743. /* Trigger interrupt after last block */
  744. lli_set(prev, ctllo, DWC_CTLL_INT_EN);
  745. prev->lli.llp = 0;
  746. lli_clear(prev, ctllo, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  747. first->total_len = total_len;
  748. return &first->txd;
  749. err_desc_get:
  750. dev_err(chan2dev(chan),
  751. "not enough descriptors available. Direction %d\n", direction);
  752. dwc_desc_put(dwc, first);
  753. return NULL;
  754. }
  755. bool dw_dma_filter(struct dma_chan *chan, void *param)
  756. {
  757. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  758. struct dw_dma_slave *dws = param;
  759. if (dws->dma_dev != chan->device->dev)
  760. return false;
  761. /* We have to copy data since dws can be temporary storage */
  762. memcpy(&dwc->dws, dws, sizeof(struct dw_dma_slave));
  763. return true;
  764. }
  765. EXPORT_SYMBOL_GPL(dw_dma_filter);
  766. static int dwc_config(struct dma_chan *chan, struct dma_slave_config *sconfig)
  767. {
  768. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  769. struct dma_slave_config *sc = &dwc->dma_sconfig;
  770. struct dw_dma *dw = to_dw_dma(chan->device);
  771. /*
  772. * Fix sconfig's burst size according to dw_dmac. We need to convert
  773. * them as:
  774. * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
  775. *
  776. * NOTE: burst size 2 is not supported by DesignWare controller.
  777. * iDMA 32-bit supports it.
  778. */
  779. u32 s = dw->pdata->is_idma32 ? 1 : 2;
  780. /* Check if chan will be configured for slave transfers */
  781. if (!is_slave_direction(sconfig->direction))
  782. return -EINVAL;
  783. memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig));
  784. dwc->direction = sconfig->direction;
  785. sc->src_maxburst = sc->src_maxburst > 1 ? fls(sc->src_maxburst) - s : 0;
  786. sc->dst_maxburst = sc->dst_maxburst > 1 ? fls(sc->dst_maxburst) - s : 0;
  787. return 0;
  788. }
  789. static void dwc_chan_pause(struct dw_dma_chan *dwc, bool drain)
  790. {
  791. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  792. unsigned int count = 20; /* timeout iterations */
  793. u32 cfglo;
  794. cfglo = channel_readl(dwc, CFG_LO);
  795. if (dw->pdata->is_idma32) {
  796. if (drain)
  797. cfglo |= IDMA32C_CFGL_CH_DRAIN;
  798. else
  799. cfglo &= ~IDMA32C_CFGL_CH_DRAIN;
  800. }
  801. channel_writel(dwc, CFG_LO, cfglo | DWC_CFGL_CH_SUSP);
  802. while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY) && count--)
  803. udelay(2);
  804. set_bit(DW_DMA_IS_PAUSED, &dwc->flags);
  805. }
  806. static int dwc_pause(struct dma_chan *chan)
  807. {
  808. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  809. unsigned long flags;
  810. spin_lock_irqsave(&dwc->lock, flags);
  811. dwc_chan_pause(dwc, false);
  812. spin_unlock_irqrestore(&dwc->lock, flags);
  813. return 0;
  814. }
  815. static inline void dwc_chan_resume(struct dw_dma_chan *dwc)
  816. {
  817. u32 cfglo = channel_readl(dwc, CFG_LO);
  818. channel_writel(dwc, CFG_LO, cfglo & ~DWC_CFGL_CH_SUSP);
  819. clear_bit(DW_DMA_IS_PAUSED, &dwc->flags);
  820. }
  821. static int dwc_resume(struct dma_chan *chan)
  822. {
  823. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  824. unsigned long flags;
  825. spin_lock_irqsave(&dwc->lock, flags);
  826. if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags))
  827. dwc_chan_resume(dwc);
  828. spin_unlock_irqrestore(&dwc->lock, flags);
  829. return 0;
  830. }
  831. static int dwc_terminate_all(struct dma_chan *chan)
  832. {
  833. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  834. struct dw_dma *dw = to_dw_dma(chan->device);
  835. struct dw_desc *desc, *_desc;
  836. unsigned long flags;
  837. LIST_HEAD(list);
  838. spin_lock_irqsave(&dwc->lock, flags);
  839. clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
  840. dwc_chan_pause(dwc, true);
  841. dwc_chan_disable(dw, dwc);
  842. dwc_chan_resume(dwc);
  843. /* active_list entries will end up before queued entries */
  844. list_splice_init(&dwc->queue, &list);
  845. list_splice_init(&dwc->active_list, &list);
  846. spin_unlock_irqrestore(&dwc->lock, flags);
  847. /* Flush all pending and queued descriptors */
  848. list_for_each_entry_safe(desc, _desc, &list, desc_node)
  849. dwc_descriptor_complete(dwc, desc, false);
  850. return 0;
  851. }
  852. static struct dw_desc *dwc_find_desc(struct dw_dma_chan *dwc, dma_cookie_t c)
  853. {
  854. struct dw_desc *desc;
  855. list_for_each_entry(desc, &dwc->active_list, desc_node)
  856. if (desc->txd.cookie == c)
  857. return desc;
  858. return NULL;
  859. }
  860. static u32 dwc_get_residue(struct dw_dma_chan *dwc, dma_cookie_t cookie)
  861. {
  862. struct dw_desc *desc;
  863. unsigned long flags;
  864. u32 residue;
  865. spin_lock_irqsave(&dwc->lock, flags);
  866. desc = dwc_find_desc(dwc, cookie);
  867. if (desc) {
  868. if (desc == dwc_first_active(dwc)) {
  869. residue = desc->residue;
  870. if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue)
  871. residue -= dwc_get_sent(dwc);
  872. } else {
  873. residue = desc->total_len;
  874. }
  875. } else {
  876. residue = 0;
  877. }
  878. spin_unlock_irqrestore(&dwc->lock, flags);
  879. return residue;
  880. }
  881. static enum dma_status
  882. dwc_tx_status(struct dma_chan *chan,
  883. dma_cookie_t cookie,
  884. struct dma_tx_state *txstate)
  885. {
  886. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  887. enum dma_status ret;
  888. ret = dma_cookie_status(chan, cookie, txstate);
  889. if (ret == DMA_COMPLETE)
  890. return ret;
  891. dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
  892. ret = dma_cookie_status(chan, cookie, txstate);
  893. if (ret == DMA_COMPLETE)
  894. return ret;
  895. dma_set_residue(txstate, dwc_get_residue(dwc, cookie));
  896. if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags) && ret == DMA_IN_PROGRESS)
  897. return DMA_PAUSED;
  898. return ret;
  899. }
  900. static void dwc_issue_pending(struct dma_chan *chan)
  901. {
  902. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  903. unsigned long flags;
  904. spin_lock_irqsave(&dwc->lock, flags);
  905. if (list_empty(&dwc->active_list))
  906. dwc_dostart_first_queued(dwc);
  907. spin_unlock_irqrestore(&dwc->lock, flags);
  908. }
  909. /*----------------------------------------------------------------------*/
  910. /*
  911. * Program FIFO size of channels.
  912. *
  913. * By default full FIFO (1024 bytes) is assigned to channel 0. Here we
  914. * slice FIFO on equal parts between channels.
  915. */
  916. static void idma32_fifo_partition(struct dw_dma *dw)
  917. {
  918. u64 value = IDMA32C_FP_PSIZE_CH0(128) | IDMA32C_FP_PSIZE_CH1(128) |
  919. IDMA32C_FP_UPDATE;
  920. u64 fifo_partition = 0;
  921. if (!dw->pdata->is_idma32)
  922. return;
  923. /* Fill FIFO_PARTITION low bits (Channels 0..1, 4..5) */
  924. fifo_partition |= value << 0;
  925. /* Fill FIFO_PARTITION high bits (Channels 2..3, 6..7) */
  926. fifo_partition |= value << 32;
  927. /* Program FIFO Partition registers - 128 bytes for each channel */
  928. idma32_writeq(dw, FIFO_PARTITION1, fifo_partition);
  929. idma32_writeq(dw, FIFO_PARTITION0, fifo_partition);
  930. }
  931. static void dw_dma_off(struct dw_dma *dw)
  932. {
  933. unsigned int i;
  934. dma_writel(dw, CFG, 0);
  935. channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask);
  936. channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask);
  937. channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask);
  938. channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask);
  939. channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask);
  940. while (dma_readl(dw, CFG) & DW_CFG_DMA_EN)
  941. cpu_relax();
  942. for (i = 0; i < dw->dma.chancnt; i++)
  943. clear_bit(DW_DMA_IS_INITIALIZED, &dw->chan[i].flags);
  944. }
  945. static void dw_dma_on(struct dw_dma *dw)
  946. {
  947. dma_writel(dw, CFG, DW_CFG_DMA_EN);
  948. }
  949. static int dwc_alloc_chan_resources(struct dma_chan *chan)
  950. {
  951. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  952. struct dw_dma *dw = to_dw_dma(chan->device);
  953. dev_vdbg(chan2dev(chan), "%s\n", __func__);
  954. /* ASSERT: channel is idle */
  955. if (dma_readl(dw, CH_EN) & dwc->mask) {
  956. dev_dbg(chan2dev(chan), "DMA channel not idle?\n");
  957. return -EIO;
  958. }
  959. dma_cookie_init(chan);
  960. /*
  961. * NOTE: some controllers may have additional features that we
  962. * need to initialize here, like "scatter-gather" (which
  963. * doesn't mean what you think it means), and status writeback.
  964. */
  965. /*
  966. * We need controller-specific data to set up slave transfers.
  967. */
  968. if (chan->private && !dw_dma_filter(chan, chan->private)) {
  969. dev_warn(chan2dev(chan), "Wrong controller-specific data\n");
  970. return -EINVAL;
  971. }
  972. /* Enable controller here if needed */
  973. if (!dw->in_use)
  974. dw_dma_on(dw);
  975. dw->in_use |= dwc->mask;
  976. return 0;
  977. }
  978. static void dwc_free_chan_resources(struct dma_chan *chan)
  979. {
  980. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  981. struct dw_dma *dw = to_dw_dma(chan->device);
  982. unsigned long flags;
  983. LIST_HEAD(list);
  984. dev_dbg(chan2dev(chan), "%s: descs allocated=%u\n", __func__,
  985. dwc->descs_allocated);
  986. /* ASSERT: channel is idle */
  987. BUG_ON(!list_empty(&dwc->active_list));
  988. BUG_ON(!list_empty(&dwc->queue));
  989. BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask);
  990. spin_lock_irqsave(&dwc->lock, flags);
  991. /* Clear custom channel configuration */
  992. memset(&dwc->dws, 0, sizeof(struct dw_dma_slave));
  993. clear_bit(DW_DMA_IS_INITIALIZED, &dwc->flags);
  994. /* Disable interrupts */
  995. channel_clear_bit(dw, MASK.XFER, dwc->mask);
  996. channel_clear_bit(dw, MASK.BLOCK, dwc->mask);
  997. channel_clear_bit(dw, MASK.ERROR, dwc->mask);
  998. spin_unlock_irqrestore(&dwc->lock, flags);
  999. /* Disable controller in case it was a last user */
  1000. dw->in_use &= ~dwc->mask;
  1001. if (!dw->in_use)
  1002. dw_dma_off(dw);
  1003. dev_vdbg(chan2dev(chan), "%s: done\n", __func__);
  1004. }
  1005. /* --------------------- Cyclic DMA API extensions -------------------- */
  1006. /**
  1007. * dw_dma_cyclic_start - start the cyclic DMA transfer
  1008. * @chan: the DMA channel to start
  1009. *
  1010. * Must be called with soft interrupts disabled. Returns zero on success or
  1011. * -errno on failure.
  1012. */
  1013. int dw_dma_cyclic_start(struct dma_chan *chan)
  1014. {
  1015. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  1016. struct dw_dma *dw = to_dw_dma(chan->device);
  1017. unsigned long flags;
  1018. if (!test_bit(DW_DMA_IS_CYCLIC, &dwc->flags)) {
  1019. dev_err(chan2dev(&dwc->chan), "missing prep for cyclic DMA\n");
  1020. return -ENODEV;
  1021. }
  1022. spin_lock_irqsave(&dwc->lock, flags);
  1023. /* Enable interrupts to perform cyclic transfer */
  1024. channel_set_bit(dw, MASK.BLOCK, dwc->mask);
  1025. dwc_dostart(dwc, dwc->cdesc->desc[0]);
  1026. spin_unlock_irqrestore(&dwc->lock, flags);
  1027. return 0;
  1028. }
  1029. EXPORT_SYMBOL(dw_dma_cyclic_start);
  1030. /**
  1031. * dw_dma_cyclic_stop - stop the cyclic DMA transfer
  1032. * @chan: the DMA channel to stop
  1033. *
  1034. * Must be called with soft interrupts disabled.
  1035. */
  1036. void dw_dma_cyclic_stop(struct dma_chan *chan)
  1037. {
  1038. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  1039. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  1040. unsigned long flags;
  1041. spin_lock_irqsave(&dwc->lock, flags);
  1042. dwc_chan_disable(dw, dwc);
  1043. spin_unlock_irqrestore(&dwc->lock, flags);
  1044. }
  1045. EXPORT_SYMBOL(dw_dma_cyclic_stop);
  1046. /**
  1047. * dw_dma_cyclic_prep - prepare the cyclic DMA transfer
  1048. * @chan: the DMA channel to prepare
  1049. * @buf_addr: physical DMA address where the buffer starts
  1050. * @buf_len: total number of bytes for the entire buffer
  1051. * @period_len: number of bytes for each period
  1052. * @direction: transfer direction, to or from device
  1053. *
  1054. * Must be called before trying to start the transfer. Returns a valid struct
  1055. * dw_cyclic_desc if successful or an ERR_PTR(-errno) if not successful.
  1056. */
  1057. struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan,
  1058. dma_addr_t buf_addr, size_t buf_len, size_t period_len,
  1059. enum dma_transfer_direction direction)
  1060. {
  1061. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  1062. struct dma_slave_config *sconfig = &dwc->dma_sconfig;
  1063. struct dw_cyclic_desc *cdesc;
  1064. struct dw_cyclic_desc *retval = NULL;
  1065. struct dw_desc *desc;
  1066. struct dw_desc *last = NULL;
  1067. u8 lms = DWC_LLP_LMS(dwc->dws.m_master);
  1068. unsigned long was_cyclic;
  1069. unsigned int reg_width;
  1070. unsigned int periods;
  1071. unsigned int i;
  1072. unsigned long flags;
  1073. spin_lock_irqsave(&dwc->lock, flags);
  1074. if (dwc->nollp) {
  1075. spin_unlock_irqrestore(&dwc->lock, flags);
  1076. dev_dbg(chan2dev(&dwc->chan),
  1077. "channel doesn't support LLP transfers\n");
  1078. return ERR_PTR(-EINVAL);
  1079. }
  1080. if (!list_empty(&dwc->queue) || !list_empty(&dwc->active_list)) {
  1081. spin_unlock_irqrestore(&dwc->lock, flags);
  1082. dev_dbg(chan2dev(&dwc->chan),
  1083. "queue and/or active list are not empty\n");
  1084. return ERR_PTR(-EBUSY);
  1085. }
  1086. was_cyclic = test_and_set_bit(DW_DMA_IS_CYCLIC, &dwc->flags);
  1087. spin_unlock_irqrestore(&dwc->lock, flags);
  1088. if (was_cyclic) {
  1089. dev_dbg(chan2dev(&dwc->chan),
  1090. "channel already prepared for cyclic DMA\n");
  1091. return ERR_PTR(-EBUSY);
  1092. }
  1093. retval = ERR_PTR(-EINVAL);
  1094. if (unlikely(!is_slave_direction(direction)))
  1095. goto out_err;
  1096. dwc->direction = direction;
  1097. if (direction == DMA_MEM_TO_DEV)
  1098. reg_width = __ffs(sconfig->dst_addr_width);
  1099. else
  1100. reg_width = __ffs(sconfig->src_addr_width);
  1101. periods = buf_len / period_len;
  1102. /* Check for too big/unaligned periods and unaligned DMA buffer. */
  1103. if (period_len > (dwc->block_size << reg_width))
  1104. goto out_err;
  1105. if (unlikely(period_len & ((1 << reg_width) - 1)))
  1106. goto out_err;
  1107. if (unlikely(buf_addr & ((1 << reg_width) - 1)))
  1108. goto out_err;
  1109. retval = ERR_PTR(-ENOMEM);
  1110. cdesc = kzalloc(sizeof(struct dw_cyclic_desc), GFP_KERNEL);
  1111. if (!cdesc)
  1112. goto out_err;
  1113. cdesc->desc = kzalloc(sizeof(struct dw_desc *) * periods, GFP_KERNEL);
  1114. if (!cdesc->desc)
  1115. goto out_err_alloc;
  1116. for (i = 0; i < periods; i++) {
  1117. desc = dwc_desc_get(dwc);
  1118. if (!desc)
  1119. goto out_err_desc_get;
  1120. switch (direction) {
  1121. case DMA_MEM_TO_DEV:
  1122. lli_write(desc, dar, sconfig->dst_addr);
  1123. lli_write(desc, sar, buf_addr + period_len * i);
  1124. lli_write(desc, ctllo, (DWC_DEFAULT_CTLLO(chan)
  1125. | DWC_CTLL_DST_WIDTH(reg_width)
  1126. | DWC_CTLL_SRC_WIDTH(reg_width)
  1127. | DWC_CTLL_DST_FIX
  1128. | DWC_CTLL_SRC_INC
  1129. | DWC_CTLL_INT_EN));
  1130. lli_set(desc, ctllo, sconfig->device_fc ?
  1131. DWC_CTLL_FC(DW_DMA_FC_P_M2P) :
  1132. DWC_CTLL_FC(DW_DMA_FC_D_M2P));
  1133. break;
  1134. case DMA_DEV_TO_MEM:
  1135. lli_write(desc, dar, buf_addr + period_len * i);
  1136. lli_write(desc, sar, sconfig->src_addr);
  1137. lli_write(desc, ctllo, (DWC_DEFAULT_CTLLO(chan)
  1138. | DWC_CTLL_SRC_WIDTH(reg_width)
  1139. | DWC_CTLL_DST_WIDTH(reg_width)
  1140. | DWC_CTLL_DST_INC
  1141. | DWC_CTLL_SRC_FIX
  1142. | DWC_CTLL_INT_EN));
  1143. lli_set(desc, ctllo, sconfig->device_fc ?
  1144. DWC_CTLL_FC(DW_DMA_FC_P_P2M) :
  1145. DWC_CTLL_FC(DW_DMA_FC_D_P2M));
  1146. break;
  1147. default:
  1148. break;
  1149. }
  1150. lli_write(desc, ctlhi, period_len >> reg_width);
  1151. cdesc->desc[i] = desc;
  1152. if (last)
  1153. lli_write(last, llp, desc->txd.phys | lms);
  1154. last = desc;
  1155. }
  1156. /* Let's make a cyclic list */
  1157. lli_write(last, llp, cdesc->desc[0]->txd.phys | lms);
  1158. dev_dbg(chan2dev(&dwc->chan),
  1159. "cyclic prepared buf %pad len %zu period %zu periods %d\n",
  1160. &buf_addr, buf_len, period_len, periods);
  1161. cdesc->periods = periods;
  1162. dwc->cdesc = cdesc;
  1163. return cdesc;
  1164. out_err_desc_get:
  1165. while (i--)
  1166. dwc_desc_put(dwc, cdesc->desc[i]);
  1167. out_err_alloc:
  1168. kfree(cdesc);
  1169. out_err:
  1170. clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags);
  1171. return (struct dw_cyclic_desc *)retval;
  1172. }
  1173. EXPORT_SYMBOL(dw_dma_cyclic_prep);
  1174. /**
  1175. * dw_dma_cyclic_free - free a prepared cyclic DMA transfer
  1176. * @chan: the DMA channel to free
  1177. */
  1178. void dw_dma_cyclic_free(struct dma_chan *chan)
  1179. {
  1180. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  1181. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  1182. struct dw_cyclic_desc *cdesc = dwc->cdesc;
  1183. unsigned int i;
  1184. unsigned long flags;
  1185. dev_dbg(chan2dev(&dwc->chan), "%s\n", __func__);
  1186. if (!cdesc)
  1187. return;
  1188. spin_lock_irqsave(&dwc->lock, flags);
  1189. dwc_chan_disable(dw, dwc);
  1190. dma_writel(dw, CLEAR.BLOCK, dwc->mask);
  1191. dma_writel(dw, CLEAR.ERROR, dwc->mask);
  1192. dma_writel(dw, CLEAR.XFER, dwc->mask);
  1193. spin_unlock_irqrestore(&dwc->lock, flags);
  1194. for (i = 0; i < cdesc->periods; i++)
  1195. dwc_desc_put(dwc, cdesc->desc[i]);
  1196. kfree(cdesc->desc);
  1197. kfree(cdesc);
  1198. dwc->cdesc = NULL;
  1199. clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags);
  1200. }
  1201. EXPORT_SYMBOL(dw_dma_cyclic_free);
  1202. /*----------------------------------------------------------------------*/
  1203. int dw_dma_probe(struct dw_dma_chip *chip)
  1204. {
  1205. struct dw_dma_platform_data *pdata;
  1206. struct dw_dma *dw;
  1207. bool autocfg = false;
  1208. unsigned int dw_params;
  1209. unsigned int i;
  1210. int err;
  1211. dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL);
  1212. if (!dw)
  1213. return -ENOMEM;
  1214. dw->pdata = devm_kzalloc(chip->dev, sizeof(*dw->pdata), GFP_KERNEL);
  1215. if (!dw->pdata)
  1216. return -ENOMEM;
  1217. dw->regs = chip->regs;
  1218. chip->dw = dw;
  1219. pm_runtime_get_sync(chip->dev);
  1220. if (!chip->pdata) {
  1221. dw_params = dma_readl(dw, DW_PARAMS);
  1222. dev_dbg(chip->dev, "DW_PARAMS: 0x%08x\n", dw_params);
  1223. autocfg = dw_params >> DW_PARAMS_EN & 1;
  1224. if (!autocfg) {
  1225. err = -EINVAL;
  1226. goto err_pdata;
  1227. }
  1228. /* Reassign the platform data pointer */
  1229. pdata = dw->pdata;
  1230. /* Get hardware configuration parameters */
  1231. pdata->nr_channels = (dw_params >> DW_PARAMS_NR_CHAN & 7) + 1;
  1232. pdata->nr_masters = (dw_params >> DW_PARAMS_NR_MASTER & 3) + 1;
  1233. for (i = 0; i < pdata->nr_masters; i++) {
  1234. pdata->data_width[i] =
  1235. 4 << (dw_params >> DW_PARAMS_DATA_WIDTH(i) & 3);
  1236. }
  1237. pdata->block_size = dma_readl(dw, MAX_BLK_SIZE);
  1238. /* Fill platform data with the default values */
  1239. pdata->is_private = true;
  1240. pdata->is_memcpy = true;
  1241. pdata->chan_allocation_order = CHAN_ALLOCATION_ASCENDING;
  1242. pdata->chan_priority = CHAN_PRIORITY_ASCENDING;
  1243. } else if (chip->pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) {
  1244. err = -EINVAL;
  1245. goto err_pdata;
  1246. } else {
  1247. memcpy(dw->pdata, chip->pdata, sizeof(*dw->pdata));
  1248. /* Reassign the platform data pointer */
  1249. pdata = dw->pdata;
  1250. }
  1251. dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan),
  1252. GFP_KERNEL);
  1253. if (!dw->chan) {
  1254. err = -ENOMEM;
  1255. goto err_pdata;
  1256. }
  1257. /* Calculate all channel mask before DMA setup */
  1258. dw->all_chan_mask = (1 << pdata->nr_channels) - 1;
  1259. /* Force dma off, just in case */
  1260. dw_dma_off(dw);
  1261. idma32_fifo_partition(dw);
  1262. /* Device and instance ID for IRQ and DMA pool */
  1263. if (pdata->is_idma32)
  1264. snprintf(dw->name, sizeof(dw->name), "idma32:dmac%d", chip->id);
  1265. else
  1266. snprintf(dw->name, sizeof(dw->name), "dw:dmac%d", chip->id);
  1267. /* Create a pool of consistent memory blocks for hardware descriptors */
  1268. dw->desc_pool = dmam_pool_create(dw->name, chip->dev,
  1269. sizeof(struct dw_desc), 4, 0);
  1270. if (!dw->desc_pool) {
  1271. dev_err(chip->dev, "No memory for descriptors dma pool\n");
  1272. err = -ENOMEM;
  1273. goto err_pdata;
  1274. }
  1275. tasklet_init(&dw->tasklet, dw_dma_tasklet, (unsigned long)dw);
  1276. err = request_irq(chip->irq, dw_dma_interrupt, IRQF_SHARED,
  1277. dw->name, dw);
  1278. if (err)
  1279. goto err_pdata;
  1280. INIT_LIST_HEAD(&dw->dma.channels);
  1281. for (i = 0; i < pdata->nr_channels; i++) {
  1282. struct dw_dma_chan *dwc = &dw->chan[i];
  1283. dwc->chan.device = &dw->dma;
  1284. dma_cookie_init(&dwc->chan);
  1285. if (pdata->chan_allocation_order == CHAN_ALLOCATION_ASCENDING)
  1286. list_add_tail(&dwc->chan.device_node,
  1287. &dw->dma.channels);
  1288. else
  1289. list_add(&dwc->chan.device_node, &dw->dma.channels);
  1290. /* 7 is highest priority & 0 is lowest. */
  1291. if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING)
  1292. dwc->priority = pdata->nr_channels - i - 1;
  1293. else
  1294. dwc->priority = i;
  1295. dwc->ch_regs = &__dw_regs(dw)->CHAN[i];
  1296. spin_lock_init(&dwc->lock);
  1297. dwc->mask = 1 << i;
  1298. INIT_LIST_HEAD(&dwc->active_list);
  1299. INIT_LIST_HEAD(&dwc->queue);
  1300. channel_clear_bit(dw, CH_EN, dwc->mask);
  1301. dwc->direction = DMA_TRANS_NONE;
  1302. /* Hardware configuration */
  1303. if (autocfg) {
  1304. unsigned int r = DW_DMA_MAX_NR_CHANNELS - i - 1;
  1305. void __iomem *addr = &__dw_regs(dw)->DWC_PARAMS[r];
  1306. unsigned int dwc_params = dma_readl_native(addr);
  1307. dev_dbg(chip->dev, "DWC_PARAMS[%d]: 0x%08x\n", i,
  1308. dwc_params);
  1309. /*
  1310. * Decode maximum block size for given channel. The
  1311. * stored 4 bit value represents blocks from 0x00 for 3
  1312. * up to 0x0a for 4095.
  1313. */
  1314. dwc->block_size =
  1315. (4 << ((pdata->block_size >> 4 * i) & 0xf)) - 1;
  1316. dwc->nollp =
  1317. (dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0;
  1318. } else {
  1319. dwc->block_size = pdata->block_size;
  1320. dwc->nollp = !pdata->multi_block[i];
  1321. }
  1322. }
  1323. /* Clear all interrupts on all channels. */
  1324. dma_writel(dw, CLEAR.XFER, dw->all_chan_mask);
  1325. dma_writel(dw, CLEAR.BLOCK, dw->all_chan_mask);
  1326. dma_writel(dw, CLEAR.SRC_TRAN, dw->all_chan_mask);
  1327. dma_writel(dw, CLEAR.DST_TRAN, dw->all_chan_mask);
  1328. dma_writel(dw, CLEAR.ERROR, dw->all_chan_mask);
  1329. /* Set capabilities */
  1330. dma_cap_set(DMA_SLAVE, dw->dma.cap_mask);
  1331. if (pdata->is_private)
  1332. dma_cap_set(DMA_PRIVATE, dw->dma.cap_mask);
  1333. if (pdata->is_memcpy)
  1334. dma_cap_set(DMA_MEMCPY, dw->dma.cap_mask);
  1335. dw->dma.dev = chip->dev;
  1336. dw->dma.device_alloc_chan_resources = dwc_alloc_chan_resources;
  1337. dw->dma.device_free_chan_resources = dwc_free_chan_resources;
  1338. dw->dma.device_prep_dma_memcpy = dwc_prep_dma_memcpy;
  1339. dw->dma.device_prep_slave_sg = dwc_prep_slave_sg;
  1340. dw->dma.device_config = dwc_config;
  1341. dw->dma.device_pause = dwc_pause;
  1342. dw->dma.device_resume = dwc_resume;
  1343. dw->dma.device_terminate_all = dwc_terminate_all;
  1344. dw->dma.device_tx_status = dwc_tx_status;
  1345. dw->dma.device_issue_pending = dwc_issue_pending;
  1346. /* DMA capabilities */
  1347. dw->dma.src_addr_widths = DW_DMA_BUSWIDTHS;
  1348. dw->dma.dst_addr_widths = DW_DMA_BUSWIDTHS;
  1349. dw->dma.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV) |
  1350. BIT(DMA_MEM_TO_MEM);
  1351. dw->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  1352. err = dma_async_device_register(&dw->dma);
  1353. if (err)
  1354. goto err_dma_register;
  1355. dev_info(chip->dev, "DesignWare DMA Controller, %d channels\n",
  1356. pdata->nr_channels);
  1357. pm_runtime_put_sync_suspend(chip->dev);
  1358. return 0;
  1359. err_dma_register:
  1360. free_irq(chip->irq, dw);
  1361. err_pdata:
  1362. pm_runtime_put_sync_suspend(chip->dev);
  1363. return err;
  1364. }
  1365. EXPORT_SYMBOL_GPL(dw_dma_probe);
  1366. int dw_dma_remove(struct dw_dma_chip *chip)
  1367. {
  1368. struct dw_dma *dw = chip->dw;
  1369. struct dw_dma_chan *dwc, *_dwc;
  1370. pm_runtime_get_sync(chip->dev);
  1371. dw_dma_off(dw);
  1372. dma_async_device_unregister(&dw->dma);
  1373. free_irq(chip->irq, dw);
  1374. tasklet_kill(&dw->tasklet);
  1375. list_for_each_entry_safe(dwc, _dwc, &dw->dma.channels,
  1376. chan.device_node) {
  1377. list_del(&dwc->chan.device_node);
  1378. channel_clear_bit(dw, CH_EN, dwc->mask);
  1379. }
  1380. pm_runtime_put_sync_suspend(chip->dev);
  1381. return 0;
  1382. }
  1383. EXPORT_SYMBOL_GPL(dw_dma_remove);
  1384. int dw_dma_disable(struct dw_dma_chip *chip)
  1385. {
  1386. struct dw_dma *dw = chip->dw;
  1387. dw_dma_off(dw);
  1388. return 0;
  1389. }
  1390. EXPORT_SYMBOL_GPL(dw_dma_disable);
  1391. int dw_dma_enable(struct dw_dma_chip *chip)
  1392. {
  1393. struct dw_dma *dw = chip->dw;
  1394. idma32_fifo_partition(dw);
  1395. dw_dma_on(dw);
  1396. return 0;
  1397. }
  1398. EXPORT_SYMBOL_GPL(dw_dma_enable);
  1399. MODULE_LICENSE("GPL v2");
  1400. MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller core driver");
  1401. MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
  1402. MODULE_AUTHOR("Viresh Kumar <vireshk@kernel.org>");