015-dmaengine-dw-fixed.patch 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  1. From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  2. Subject: [PATCH v6 0/4] Fixes / cleanups in dw_dmac (affects on few subsystems)
  3. Date: Mon, 25 Apr 2016 15:35:05 +0300
  4. This patch series (v3: http://www.spinics.net/lists/kernel/msg2215303.html)
  5. contains a number of mostly minor fixes and cleanups for the DW DMA driver. A
  6. couple of them affect the DT binding so these may need to be updated to
  7. maintain compatibility (old format is still supported though). The rest should
  8. be relatively straight-forward.
  9. This version has been tested on the following bare metal platforms:
  10. - ATNGW100 (avr32 based platform) with dmatest
  11. - Sam460ex (powerpc 44x based platform) with SATA
  12. - Intel Braswell with UART
  13. - Intel Galileo (Intel Quark based platform) with UART
  14. (SATA driver and Intel Galileo UART support are based on this series and just
  15. published recently for a review)
  16. Vinod, there are few patch sets developed on top of this one, so, the idea is
  17. to keep this in an immuutable branch / tag.
  18. Changes since v5:
  19. - fixed an issue found by kbuildbot
  20. Changes since v4:
  21. - send proper set of patches
  22. - add changelog
  23. Changes since v3:
  24. - add patch 1 to check value of dma-masters property
  25. - drop the upstreamed patches
  26. - update patch 2 to keep an array for data-width property as well
  27. Changes since v2:
  28. - add patch 1 to fix master selection which was broken for long time
  29. - remove "use field-by-field initialization" patch since like Mans metioned in
  30. has mostly no value and even might increase error prone
  31. - rebase on top of recent linux-next
  32. - wide testing on several platforms
  33. Changes since v1:
  34. - zeroing struct dw_dma_slave before use
  35. - fall back to old data_width property if data-width is not found
  36. - append tags for few patches
  37. - correct title of cover letter
  38. - rebase on top of recent linux-next
  39. Andy Shevchenko (4):
  40. dmaengine: dw: platform: check nr_masters to be non-zero
  41. dmaengine: dw: revisit data_width property
  42. dmaengine: dw: keep entire platform data in struct dw_dma
  43. dmaengine: dw: pass platform data via struct dw_dma_chip
  44. Documentation/devicetree/bindings/dma/snps-dma.txt | 6 +-
  45. arch/arc/boot/dts/abilis_tb10x.dtsi | 2 +-
  46. arch/arm/boot/dts/spear13xx.dtsi | 4 +-
  47. drivers/ata/sata_dwc_460ex.c | 2 +-
  48. drivers/dma/dw/core.c | 75 ++++++++--------------
  49. drivers/dma/dw/pci.c | 5 +-
  50. drivers/dma/dw/platform.c | 32 +++++----
  51. drivers/dma/dw/regs.h | 5 +-
  52. include/linux/dma/dw.h | 5 +-
  53. include/linux/platform_data/dma-dw.h | 4 +-
  54. sound/soc/intel/common/sst-firmware.c | 2 +-
  55. 11 files changed, 64 insertions(+), 78 deletions(-)
  56. --- a/drivers/dma/dw/core.c
  57. +++ b/drivers/dma/dw/core.c
  58. @@ -45,22 +45,19 @@
  59. DW_DMA_MSIZE_16; \
  60. u8 _dmsize = _is_slave ? _sconfig->dst_maxburst : \
  61. DW_DMA_MSIZE_16; \
  62. + u8 _dms = (_dwc->direction == DMA_MEM_TO_DEV) ? \
  63. + _dwc->p_master : _dwc->m_master; \
  64. + u8 _sms = (_dwc->direction == DMA_DEV_TO_MEM) ? \
  65. + _dwc->p_master : _dwc->m_master; \
  66. \
  67. (DWC_CTLL_DST_MSIZE(_dmsize) \
  68. | DWC_CTLL_SRC_MSIZE(_smsize) \
  69. | DWC_CTLL_LLP_D_EN \
  70. | DWC_CTLL_LLP_S_EN \
  71. - | DWC_CTLL_DMS(_dwc->dst_master) \
  72. - | DWC_CTLL_SMS(_dwc->src_master)); \
  73. + | DWC_CTLL_DMS(_dms) \
  74. + | DWC_CTLL_SMS(_sms)); \
  75. })
  76. -/*
  77. - * Number of descriptors to allocate for each channel. This should be
  78. - * made configurable somehow; preferably, the clients (at least the
  79. - * ones using slave transfers) should be able to give us a hint.
  80. - */
  81. -#define NR_DESCS_PER_CHANNEL 64
  82. -
  83. /* The set of bus widths supported by the DMA controller */
  84. #define DW_DMA_BUSWIDTHS \
  85. BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \
  86. @@ -80,51 +77,65 @@ static struct dw_desc *dwc_first_active(
  87. return to_dw_desc(dwc->active_list.next);
  88. }
  89. -static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc)
  90. +static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx)
  91. {
  92. - struct dw_desc *desc, *_desc;
  93. - struct dw_desc *ret = NULL;
  94. - unsigned int i = 0;
  95. - unsigned long flags;
  96. + struct dw_desc *desc = txd_to_dw_desc(tx);
  97. + struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan);
  98. + dma_cookie_t cookie;
  99. + unsigned long flags;
  100. spin_lock_irqsave(&dwc->lock, flags);
  101. - list_for_each_entry_safe(desc, _desc, &dwc->free_list, desc_node) {
  102. - i++;
  103. - if (async_tx_test_ack(&desc->txd)) {
  104. - list_del(&desc->desc_node);
  105. - ret = desc;
  106. - break;
  107. - }
  108. - dev_dbg(chan2dev(&dwc->chan), "desc %p not ACKed\n", desc);
  109. - }
  110. + cookie = dma_cookie_assign(tx);
  111. +
  112. + /*
  113. + * REVISIT: We should attempt to chain as many descriptors as
  114. + * possible, perhaps even appending to those already submitted
  115. + * for DMA. But this is hard to do in a race-free manner.
  116. + */
  117. +
  118. + list_add_tail(&desc->desc_node, &dwc->queue);
  119. spin_unlock_irqrestore(&dwc->lock, flags);
  120. + dev_vdbg(chan2dev(tx->chan), "%s: queued %u\n",
  121. + __func__, desc->txd.cookie);
  122. - dev_vdbg(chan2dev(&dwc->chan), "scanned %u descriptors on freelist\n", i);
  123. + return cookie;
  124. +}
  125. - return ret;
  126. +static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc)
  127. +{
  128. + struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  129. + struct dw_desc *desc;
  130. + dma_addr_t phys;
  131. +
  132. + desc = dma_pool_zalloc(dw->desc_pool, GFP_ATOMIC, &phys);
  133. + if (!desc)
  134. + return NULL;
  135. +
  136. + dwc->descs_allocated++;
  137. + INIT_LIST_HEAD(&desc->tx_list);
  138. + dma_async_tx_descriptor_init(&desc->txd, &dwc->chan);
  139. + desc->txd.tx_submit = dwc_tx_submit;
  140. + desc->txd.flags = DMA_CTRL_ACK;
  141. + desc->txd.phys = phys;
  142. + return desc;
  143. }
  144. -/*
  145. - * Move a descriptor, including any children, to the free list.
  146. - * `desc' must not be on any lists.
  147. - */
  148. static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc)
  149. {
  150. - unsigned long flags;
  151. + struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  152. + struct dw_desc *child, *_next;
  153. - if (desc) {
  154. - struct dw_desc *child;
  155. + if (unlikely(!desc))
  156. + return;
  157. - spin_lock_irqsave(&dwc->lock, flags);
  158. - list_for_each_entry(child, &desc->tx_list, desc_node)
  159. - dev_vdbg(chan2dev(&dwc->chan),
  160. - "moving child desc %p to freelist\n",
  161. - child);
  162. - list_splice_init(&desc->tx_list, &dwc->free_list);
  163. - dev_vdbg(chan2dev(&dwc->chan), "moving desc %p to freelist\n", desc);
  164. - list_add(&desc->desc_node, &dwc->free_list);
  165. - spin_unlock_irqrestore(&dwc->lock, flags);
  166. + list_for_each_entry_safe(child, _next, &desc->tx_list, desc_node) {
  167. + list_del(&child->desc_node);
  168. + dma_pool_free(dw->desc_pool, child, child->txd.phys);
  169. + dwc->descs_allocated--;
  170. }
  171. +
  172. + dma_pool_free(dw->desc_pool, desc, desc->txd.phys);
  173. + dwc->descs_allocated--;
  174. }
  175. static void dwc_initialize(struct dw_dma_chan *dwc)
  176. @@ -133,7 +144,7 @@ static void dwc_initialize(struct dw_dma
  177. u32 cfghi = DWC_CFGH_FIFO_MODE;
  178. u32 cfglo = DWC_CFGL_CH_PRIOR(dwc->priority);
  179. - if (dwc->initialized == true)
  180. + if (test_bit(DW_DMA_IS_INITIALIZED, &dwc->flags))
  181. return;
  182. cfghi |= DWC_CFGH_DST_PER(dwc->dst_id);
  183. @@ -146,26 +157,11 @@ static void dwc_initialize(struct dw_dma
  184. channel_set_bit(dw, MASK.XFER, dwc->mask);
  185. channel_set_bit(dw, MASK.ERROR, dwc->mask);
  186. - dwc->initialized = true;
  187. + set_bit(DW_DMA_IS_INITIALIZED, &dwc->flags);
  188. }
  189. /*----------------------------------------------------------------------*/
  190. -static inline unsigned int dwc_fast_ffs(unsigned long long v)
  191. -{
  192. - /*
  193. - * We can be a lot more clever here, but this should take care
  194. - * of the most common optimization.
  195. - */
  196. - if (!(v & 7))
  197. - return 3;
  198. - else if (!(v & 3))
  199. - return 2;
  200. - else if (!(v & 1))
  201. - return 1;
  202. - return 0;
  203. -}
  204. -
  205. static inline void dwc_dump_chan_regs(struct dw_dma_chan *dwc)
  206. {
  207. dev_err(chan2dev(&dwc->chan),
  208. @@ -197,12 +193,12 @@ static inline void dwc_do_single_block(s
  209. * Software emulation of LLP mode relies on interrupts to continue
  210. * multi block transfer.
  211. */
  212. - ctllo = desc->lli.ctllo | DWC_CTLL_INT_EN;
  213. + ctllo = lli_read(desc, ctllo) | DWC_CTLL_INT_EN;
  214. - channel_writel(dwc, SAR, desc->lli.sar);
  215. - channel_writel(dwc, DAR, desc->lli.dar);
  216. + channel_writel(dwc, SAR, lli_read(desc, sar));
  217. + channel_writel(dwc, DAR, lli_read(desc, dar));
  218. channel_writel(dwc, CTL_LO, ctllo);
  219. - channel_writel(dwc, CTL_HI, desc->lli.ctlhi);
  220. + channel_writel(dwc, CTL_HI, lli_read(desc, ctlhi));
  221. channel_set_bit(dw, CH_EN, dwc->mask);
  222. /* Move pointer to next descriptor */
  223. @@ -213,6 +209,7 @@ static inline void dwc_do_single_block(s
  224. static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first)
  225. {
  226. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  227. + u8 lms = DWC_LLP_LMS(dwc->m_master);
  228. unsigned long was_soft_llp;
  229. /* ASSERT: channel is idle */
  230. @@ -237,7 +234,7 @@ static void dwc_dostart(struct dw_dma_ch
  231. dwc_initialize(dwc);
  232. - dwc->residue = first->total_len;
  233. + first->residue = first->total_len;
  234. dwc->tx_node_active = &first->tx_list;
  235. /* Submit first block */
  236. @@ -248,9 +245,8 @@ static void dwc_dostart(struct dw_dma_ch
  237. dwc_initialize(dwc);
  238. - channel_writel(dwc, LLP, first->txd.phys);
  239. - channel_writel(dwc, CTL_LO,
  240. - DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  241. + channel_writel(dwc, LLP, first->txd.phys | lms);
  242. + channel_writel(dwc, CTL_LO, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  243. channel_writel(dwc, CTL_HI, 0);
  244. channel_set_bit(dw, CH_EN, dwc->mask);
  245. }
  246. @@ -293,11 +289,7 @@ dwc_descriptor_complete(struct dw_dma_ch
  247. list_for_each_entry(child, &desc->tx_list, desc_node)
  248. async_tx_ack(&child->txd);
  249. async_tx_ack(&desc->txd);
  250. -
  251. - list_splice_init(&desc->tx_list, &dwc->free_list);
  252. - list_move(&desc->desc_node, &dwc->free_list);
  253. -
  254. - dma_descriptor_unmap(txd);
  255. + dwc_desc_put(dwc, desc);
  256. spin_unlock_irqrestore(&dwc->lock, flags);
  257. if (callback)
  258. @@ -368,11 +360,11 @@ static void dwc_scan_descriptors(struct
  259. head = &desc->tx_list;
  260. if (active != head) {
  261. - /* Update desc to reflect last sent one */
  262. - if (active != head->next)
  263. - desc = to_dw_desc(active->prev);
  264. -
  265. - dwc->residue -= desc->len;
  266. + /* Update residue to reflect last sent descriptor */
  267. + if (active == head->next)
  268. + desc->residue -= desc->len;
  269. + else
  270. + desc->residue -= to_dw_desc(active->prev)->len;
  271. child = to_dw_desc(active);
  272. @@ -387,8 +379,6 @@ static void dwc_scan_descriptors(struct
  273. clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
  274. }
  275. - dwc->residue = 0;
  276. -
  277. spin_unlock_irqrestore(&dwc->lock, flags);
  278. dwc_complete_all(dw, dwc);
  279. @@ -396,7 +386,6 @@ static void dwc_scan_descriptors(struct
  280. }
  281. if (list_empty(&dwc->active_list)) {
  282. - dwc->residue = 0;
  283. spin_unlock_irqrestore(&dwc->lock, flags);
  284. return;
  285. }
  286. @@ -411,31 +400,31 @@ static void dwc_scan_descriptors(struct
  287. list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
  288. /* Initial residue value */
  289. - dwc->residue = desc->total_len;
  290. + desc->residue = desc->total_len;
  291. /* Check first descriptors addr */
  292. - if (desc->txd.phys == llp) {
  293. + if (desc->txd.phys == DWC_LLP_LOC(llp)) {
  294. spin_unlock_irqrestore(&dwc->lock, flags);
  295. return;
  296. }
  297. /* Check first descriptors llp */
  298. - if (desc->lli.llp == llp) {
  299. + if (lli_read(desc, llp) == llp) {
  300. /* This one is currently in progress */
  301. - dwc->residue -= dwc_get_sent(dwc);
  302. + desc->residue -= dwc_get_sent(dwc);
  303. spin_unlock_irqrestore(&dwc->lock, flags);
  304. return;
  305. }
  306. - dwc->residue -= desc->len;
  307. + desc->residue -= desc->len;
  308. list_for_each_entry(child, &desc->tx_list, desc_node) {
  309. - if (child->lli.llp == llp) {
  310. + if (lli_read(child, llp) == llp) {
  311. /* Currently in progress */
  312. - dwc->residue -= dwc_get_sent(dwc);
  313. + desc->residue -= dwc_get_sent(dwc);
  314. spin_unlock_irqrestore(&dwc->lock, flags);
  315. return;
  316. }
  317. - dwc->residue -= child->len;
  318. + desc->residue -= child->len;
  319. }
  320. /*
  321. @@ -457,10 +446,14 @@ static void dwc_scan_descriptors(struct
  322. spin_unlock_irqrestore(&dwc->lock, flags);
  323. }
  324. -static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_lli *lli)
  325. +static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_desc *desc)
  326. {
  327. dev_crit(chan2dev(&dwc->chan), " desc: s0x%x d0x%x l0x%x c0x%x:%x\n",
  328. - lli->sar, lli->dar, lli->llp, lli->ctlhi, lli->ctllo);
  329. + lli_read(desc, sar),
  330. + lli_read(desc, dar),
  331. + lli_read(desc, llp),
  332. + lli_read(desc, ctlhi),
  333. + lli_read(desc, ctllo));
  334. }
  335. static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc)
  336. @@ -496,9 +489,9 @@ static void dwc_handle_error(struct dw_d
  337. */
  338. dev_WARN(chan2dev(&dwc->chan), "Bad descriptor submitted for DMA!\n"
  339. " cookie: %d\n", bad_desc->txd.cookie);
  340. - dwc_dump_lli(dwc, &bad_desc->lli);
  341. + dwc_dump_lli(dwc, bad_desc);
  342. list_for_each_entry(child, &bad_desc->tx_list, desc_node)
  343. - dwc_dump_lli(dwc, &child->lli);
  344. + dwc_dump_lli(dwc, child);
  345. spin_unlock_irqrestore(&dwc->lock, flags);
  346. @@ -549,7 +542,7 @@ static void dwc_handle_cyclic(struct dw_
  347. */
  348. if (unlikely(status_err & dwc->mask) ||
  349. unlikely(status_xfer & dwc->mask)) {
  350. - int i;
  351. + unsigned int i;
  352. dev_err(chan2dev(&dwc->chan),
  353. "cyclic DMA unexpected %s interrupt, stopping DMA transfer\n",
  354. @@ -571,7 +564,7 @@ static void dwc_handle_cyclic(struct dw_
  355. dma_writel(dw, CLEAR.XFER, dwc->mask);
  356. for (i = 0; i < dwc->cdesc->periods; i++)
  357. - dwc_dump_lli(dwc, &dwc->cdesc->desc[i]->lli);
  358. + dwc_dump_lli(dwc, dwc->cdesc->desc[i]);
  359. spin_unlock_irqrestore(&dwc->lock, flags);
  360. }
  361. @@ -589,7 +582,7 @@ static void dw_dma_tasklet(unsigned long
  362. u32 status_block;
  363. u32 status_xfer;
  364. u32 status_err;
  365. - int i;
  366. + unsigned int i;
  367. status_block = dma_readl(dw, RAW.BLOCK);
  368. status_xfer = dma_readl(dw, RAW.XFER);
  369. @@ -616,12 +609,17 @@ static void dw_dma_tasklet(unsigned long
  370. static irqreturn_t dw_dma_interrupt(int irq, void *dev_id)
  371. {
  372. struct dw_dma *dw = dev_id;
  373. - u32 status = dma_readl(dw, STATUS_INT);
  374. + u32 status;
  375. +
  376. + /* Check if we have any interrupt from the DMAC which is not in use */
  377. + if (!dw->in_use)
  378. + return IRQ_NONE;
  379. + status = dma_readl(dw, STATUS_INT);
  380. dev_vdbg(dw->dma.dev, "%s: status=0x%x\n", __func__, status);
  381. /* Check if we have any interrupt from the DMAC */
  382. - if (!status || !dw->in_use)
  383. + if (!status)
  384. return IRQ_NONE;
  385. /*
  386. @@ -653,30 +651,6 @@ static irqreturn_t dw_dma_interrupt(int
  387. /*----------------------------------------------------------------------*/
  388. -static dma_cookie_t dwc_tx_submit(struct dma_async_tx_descriptor *tx)
  389. -{
  390. - struct dw_desc *desc = txd_to_dw_desc(tx);
  391. - struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan);
  392. - dma_cookie_t cookie;
  393. - unsigned long flags;
  394. -
  395. - spin_lock_irqsave(&dwc->lock, flags);
  396. - cookie = dma_cookie_assign(tx);
  397. -
  398. - /*
  399. - * REVISIT: We should attempt to chain as many descriptors as
  400. - * possible, perhaps even appending to those already submitted
  401. - * for DMA. But this is hard to do in a race-free manner.
  402. - */
  403. -
  404. - dev_vdbg(chan2dev(tx->chan), "%s: queued %u\n", __func__, desc->txd.cookie);
  405. - list_add_tail(&desc->desc_node, &dwc->queue);
  406. -
  407. - spin_unlock_irqrestore(&dwc->lock, flags);
  408. -
  409. - return cookie;
  410. -}
  411. -
  412. static struct dma_async_tx_descriptor *
  413. dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  414. size_t len, unsigned long flags)
  415. @@ -688,10 +662,12 @@ dwc_prep_dma_memcpy(struct dma_chan *cha
  416. struct dw_desc *prev;
  417. size_t xfer_count;
  418. size_t offset;
  419. + u8 m_master = dwc->m_master;
  420. unsigned int src_width;
  421. unsigned int dst_width;
  422. - unsigned int data_width;
  423. + unsigned int data_width = dw->pdata->data_width[m_master];
  424. u32 ctllo;
  425. + u8 lms = DWC_LLP_LMS(m_master);
  426. dev_vdbg(chan2dev(chan),
  427. "%s: d%pad s%pad l0x%zx f0x%lx\n", __func__,
  428. @@ -704,11 +680,7 @@ dwc_prep_dma_memcpy(struct dma_chan *cha
  429. dwc->direction = DMA_MEM_TO_MEM;
  430. - data_width = min_t(unsigned int, dw->data_width[dwc->src_master],
  431. - dw->data_width[dwc->dst_master]);
  432. -
  433. - src_width = dst_width = min_t(unsigned int, data_width,
  434. - dwc_fast_ffs(src | dest | len));
  435. + src_width = dst_width = __ffs(data_width | src | dest | len);
  436. ctllo = DWC_DEFAULT_CTLLO(chan)
  437. | DWC_CTLL_DST_WIDTH(dst_width)
  438. @@ -726,27 +698,27 @@ dwc_prep_dma_memcpy(struct dma_chan *cha
  439. if (!desc)
  440. goto err_desc_get;
  441. - desc->lli.sar = src + offset;
  442. - desc->lli.dar = dest + offset;
  443. - desc->lli.ctllo = ctllo;
  444. - desc->lli.ctlhi = xfer_count;
  445. + lli_write(desc, sar, src + offset);
  446. + lli_write(desc, dar, dest + offset);
  447. + lli_write(desc, ctllo, ctllo);
  448. + lli_write(desc, ctlhi, xfer_count);
  449. desc->len = xfer_count << src_width;
  450. if (!first) {
  451. first = desc;
  452. } else {
  453. - prev->lli.llp = desc->txd.phys;
  454. - list_add_tail(&desc->desc_node,
  455. - &first->tx_list);
  456. + lli_write(prev, llp, desc->txd.phys | lms);
  457. + list_add_tail(&desc->desc_node, &first->tx_list);
  458. }
  459. prev = desc;
  460. }
  461. if (flags & DMA_PREP_INTERRUPT)
  462. /* Trigger interrupt after last block */
  463. - prev->lli.ctllo |= DWC_CTLL_INT_EN;
  464. + lli_set(prev, ctllo, DWC_CTLL_INT_EN);
  465. prev->lli.llp = 0;
  466. + lli_clear(prev, ctllo, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  467. first->txd.flags = flags;
  468. first->total_len = len;
  469. @@ -768,10 +740,12 @@ dwc_prep_slave_sg(struct dma_chan *chan,
  470. struct dw_desc *prev;
  471. struct dw_desc *first;
  472. u32 ctllo;
  473. + u8 m_master = dwc->m_master;
  474. + u8 lms = DWC_LLP_LMS(m_master);
  475. dma_addr_t reg;
  476. unsigned int reg_width;
  477. unsigned int mem_width;
  478. - unsigned int data_width;
  479. + unsigned int data_width = dw->pdata->data_width[m_master];
  480. unsigned int i;
  481. struct scatterlist *sg;
  482. size_t total_len = 0;
  483. @@ -797,8 +771,6 @@ dwc_prep_slave_sg(struct dma_chan *chan,
  484. ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) :
  485. DWC_CTLL_FC(DW_DMA_FC_D_M2P);
  486. - data_width = dw->data_width[dwc->src_master];
  487. -
  488. for_each_sg(sgl, sg, sg_len, i) {
  489. struct dw_desc *desc;
  490. u32 len, dlen, mem;
  491. @@ -806,17 +778,16 @@ dwc_prep_slave_sg(struct dma_chan *chan,
  492. mem = sg_dma_address(sg);
  493. len = sg_dma_len(sg);
  494. - mem_width = min_t(unsigned int,
  495. - data_width, dwc_fast_ffs(mem | len));
  496. + mem_width = __ffs(data_width | mem | len);
  497. slave_sg_todev_fill_desc:
  498. desc = dwc_desc_get(dwc);
  499. if (!desc)
  500. goto err_desc_get;
  501. - desc->lli.sar = mem;
  502. - desc->lli.dar = reg;
  503. - desc->lli.ctllo = ctllo | DWC_CTLL_SRC_WIDTH(mem_width);
  504. + lli_write(desc, sar, mem);
  505. + lli_write(desc, dar, reg);
  506. + lli_write(desc, ctllo, ctllo | DWC_CTLL_SRC_WIDTH(mem_width));
  507. if ((len >> mem_width) > dwc->block_size) {
  508. dlen = dwc->block_size << mem_width;
  509. mem += dlen;
  510. @@ -826,15 +797,14 @@ slave_sg_todev_fill_desc:
  511. len = 0;
  512. }
  513. - desc->lli.ctlhi = dlen >> mem_width;
  514. + lli_write(desc, ctlhi, dlen >> mem_width);
  515. desc->len = dlen;
  516. if (!first) {
  517. first = desc;
  518. } else {
  519. - prev->lli.llp = desc->txd.phys;
  520. - list_add_tail(&desc->desc_node,
  521. - &first->tx_list);
  522. + lli_write(prev, llp, desc->txd.phys | lms);
  523. + list_add_tail(&desc->desc_node, &first->tx_list);
  524. }
  525. prev = desc;
  526. total_len += dlen;
  527. @@ -854,8 +824,6 @@ slave_sg_todev_fill_desc:
  528. ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) :
  529. DWC_CTLL_FC(DW_DMA_FC_D_P2M);
  530. - data_width = dw->data_width[dwc->dst_master];
  531. -
  532. for_each_sg(sgl, sg, sg_len, i) {
  533. struct dw_desc *desc;
  534. u32 len, dlen, mem;
  535. @@ -863,17 +831,16 @@ slave_sg_todev_fill_desc:
  536. mem = sg_dma_address(sg);
  537. len = sg_dma_len(sg);
  538. - mem_width = min_t(unsigned int,
  539. - data_width, dwc_fast_ffs(mem | len));
  540. + mem_width = __ffs(data_width | mem | len);
  541. slave_sg_fromdev_fill_desc:
  542. desc = dwc_desc_get(dwc);
  543. if (!desc)
  544. goto err_desc_get;
  545. - desc->lli.sar = reg;
  546. - desc->lli.dar = mem;
  547. - desc->lli.ctllo = ctllo | DWC_CTLL_DST_WIDTH(mem_width);
  548. + lli_write(desc, sar, reg);
  549. + lli_write(desc, dar, mem);
  550. + lli_write(desc, ctllo, ctllo | DWC_CTLL_DST_WIDTH(mem_width));
  551. if ((len >> reg_width) > dwc->block_size) {
  552. dlen = dwc->block_size << reg_width;
  553. mem += dlen;
  554. @@ -882,15 +849,14 @@ slave_sg_fromdev_fill_desc:
  555. dlen = len;
  556. len = 0;
  557. }
  558. - desc->lli.ctlhi = dlen >> reg_width;
  559. + lli_write(desc, ctlhi, dlen >> reg_width);
  560. desc->len = dlen;
  561. if (!first) {
  562. first = desc;
  563. } else {
  564. - prev->lli.llp = desc->txd.phys;
  565. - list_add_tail(&desc->desc_node,
  566. - &first->tx_list);
  567. + lli_write(prev, llp, desc->txd.phys | lms);
  568. + list_add_tail(&desc->desc_node, &first->tx_list);
  569. }
  570. prev = desc;
  571. total_len += dlen;
  572. @@ -905,9 +871,10 @@ slave_sg_fromdev_fill_desc:
  573. if (flags & DMA_PREP_INTERRUPT)
  574. /* Trigger interrupt after last block */
  575. - prev->lli.ctllo |= DWC_CTLL_INT_EN;
  576. + lli_set(prev, ctllo, DWC_CTLL_INT_EN);
  577. prev->lli.llp = 0;
  578. + lli_clear(prev, ctllo, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
  579. first->total_len = total_len;
  580. return &first->txd;
  581. @@ -932,8 +899,8 @@ bool dw_dma_filter(struct dma_chan *chan
  582. dwc->src_id = dws->src_id;
  583. dwc->dst_id = dws->dst_id;
  584. - dwc->src_master = dws->src_master;
  585. - dwc->dst_master = dws->dst_master;
  586. + dwc->m_master = dws->m_master;
  587. + dwc->p_master = dws->p_master;
  588. return true;
  589. }
  590. @@ -986,7 +953,7 @@ static int dwc_pause(struct dma_chan *ch
  591. while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY) && count--)
  592. udelay(2);
  593. - dwc->paused = true;
  594. + set_bit(DW_DMA_IS_PAUSED, &dwc->flags);
  595. spin_unlock_irqrestore(&dwc->lock, flags);
  596. @@ -999,7 +966,7 @@ static inline void dwc_chan_resume(struc
  597. channel_writel(dwc, CFG_LO, cfglo & ~DWC_CFGL_CH_SUSP);
  598. - dwc->paused = false;
  599. + clear_bit(DW_DMA_IS_PAUSED, &dwc->flags);
  600. }
  601. static int dwc_resume(struct dma_chan *chan)
  602. @@ -1007,12 +974,10 @@ static int dwc_resume(struct dma_chan *c
  603. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  604. unsigned long flags;
  605. - if (!dwc->paused)
  606. - return 0;
  607. -
  608. spin_lock_irqsave(&dwc->lock, flags);
  609. - dwc_chan_resume(dwc);
  610. + if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags))
  611. + dwc_chan_resume(dwc);
  612. spin_unlock_irqrestore(&dwc->lock, flags);
  613. @@ -1048,16 +1013,37 @@ static int dwc_terminate_all(struct dma_
  614. return 0;
  615. }
  616. -static inline u32 dwc_get_residue(struct dw_dma_chan *dwc)
  617. +static struct dw_desc *dwc_find_desc(struct dw_dma_chan *dwc, dma_cookie_t c)
  618. +{
  619. + struct dw_desc *desc;
  620. +
  621. + list_for_each_entry(desc, &dwc->active_list, desc_node)
  622. + if (desc->txd.cookie == c)
  623. + return desc;
  624. +
  625. + return NULL;
  626. +}
  627. +
  628. +static u32 dwc_get_residue(struct dw_dma_chan *dwc, dma_cookie_t cookie)
  629. {
  630. + struct dw_desc *desc;
  631. unsigned long flags;
  632. u32 residue;
  633. spin_lock_irqsave(&dwc->lock, flags);
  634. - residue = dwc->residue;
  635. - if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue)
  636. - residue -= dwc_get_sent(dwc);
  637. + desc = dwc_find_desc(dwc, cookie);
  638. + if (desc) {
  639. + if (desc == dwc_first_active(dwc)) {
  640. + residue = desc->residue;
  641. + if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue)
  642. + residue -= dwc_get_sent(dwc);
  643. + } else {
  644. + residue = desc->total_len;
  645. + }
  646. + } else {
  647. + residue = 0;
  648. + }
  649. spin_unlock_irqrestore(&dwc->lock, flags);
  650. return residue;
  651. @@ -1078,10 +1064,12 @@ dwc_tx_status(struct dma_chan *chan,
  652. dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
  653. ret = dma_cookie_status(chan, cookie, txstate);
  654. - if (ret != DMA_COMPLETE)
  655. - dma_set_residue(txstate, dwc_get_residue(dwc));
  656. + if (ret == DMA_COMPLETE)
  657. + return ret;
  658. +
  659. + dma_set_residue(txstate, dwc_get_residue(dwc, cookie));
  660. - if (dwc->paused && ret == DMA_IN_PROGRESS)
  661. + if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags) && ret == DMA_IN_PROGRESS)
  662. return DMA_PAUSED;
  663. return ret;
  664. @@ -1102,7 +1090,7 @@ static void dwc_issue_pending(struct dma
  665. static void dw_dma_off(struct dw_dma *dw)
  666. {
  667. - int i;
  668. + unsigned int i;
  669. dma_writel(dw, CFG, 0);
  670. @@ -1116,7 +1104,7 @@ static void dw_dma_off(struct dw_dma *dw
  671. cpu_relax();
  672. for (i = 0; i < dw->dma.chancnt; i++)
  673. - dw->chan[i].initialized = false;
  674. + clear_bit(DW_DMA_IS_INITIALIZED, &dw->chan[i].flags);
  675. }
  676. static void dw_dma_on(struct dw_dma *dw)
  677. @@ -1128,9 +1116,6 @@ static int dwc_alloc_chan_resources(stru
  678. {
  679. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  680. struct dw_dma *dw = to_dw_dma(chan->device);
  681. - struct dw_desc *desc;
  682. - int i;
  683. - unsigned long flags;
  684. dev_vdbg(chan2dev(chan), "%s\n", __func__);
  685. @@ -1161,48 +1146,13 @@ static int dwc_alloc_chan_resources(stru
  686. dw_dma_on(dw);
  687. dw->in_use |= dwc->mask;
  688. - spin_lock_irqsave(&dwc->lock, flags);
  689. - i = dwc->descs_allocated;
  690. - while (dwc->descs_allocated < NR_DESCS_PER_CHANNEL) {
  691. - dma_addr_t phys;
  692. -
  693. - spin_unlock_irqrestore(&dwc->lock, flags);
  694. -
  695. - desc = dma_pool_alloc(dw->desc_pool, GFP_ATOMIC, &phys);
  696. - if (!desc)
  697. - goto err_desc_alloc;
  698. -
  699. - memset(desc, 0, sizeof(struct dw_desc));
  700. -
  701. - INIT_LIST_HEAD(&desc->tx_list);
  702. - dma_async_tx_descriptor_init(&desc->txd, chan);
  703. - desc->txd.tx_submit = dwc_tx_submit;
  704. - desc->txd.flags = DMA_CTRL_ACK;
  705. - desc->txd.phys = phys;
  706. -
  707. - dwc_desc_put(dwc, desc);
  708. -
  709. - spin_lock_irqsave(&dwc->lock, flags);
  710. - i = ++dwc->descs_allocated;
  711. - }
  712. -
  713. - spin_unlock_irqrestore(&dwc->lock, flags);
  714. -
  715. - dev_dbg(chan2dev(chan), "%s: allocated %d descriptors\n", __func__, i);
  716. -
  717. - return i;
  718. -
  719. -err_desc_alloc:
  720. - dev_info(chan2dev(chan), "only allocated %d descriptors\n", i);
  721. -
  722. - return i;
  723. + return 0;
  724. }
  725. static void dwc_free_chan_resources(struct dma_chan *chan)
  726. {
  727. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  728. struct dw_dma *dw = to_dw_dma(chan->device);
  729. - struct dw_desc *desc, *_desc;
  730. unsigned long flags;
  731. LIST_HEAD(list);
  732. @@ -1215,17 +1165,15 @@ static void dwc_free_chan_resources(stru
  733. BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask);
  734. spin_lock_irqsave(&dwc->lock, flags);
  735. - list_splice_init(&dwc->free_list, &list);
  736. - dwc->descs_allocated = 0;
  737. /* Clear custom channel configuration */
  738. dwc->src_id = 0;
  739. dwc->dst_id = 0;
  740. - dwc->src_master = 0;
  741. - dwc->dst_master = 0;
  742. + dwc->m_master = 0;
  743. + dwc->p_master = 0;
  744. - dwc->initialized = false;
  745. + clear_bit(DW_DMA_IS_INITIALIZED, &dwc->flags);
  746. /* Disable interrupts */
  747. channel_clear_bit(dw, MASK.XFER, dwc->mask);
  748. @@ -1239,11 +1187,6 @@ static void dwc_free_chan_resources(stru
  749. if (!dw->in_use)
  750. dw_dma_off(dw);
  751. - list_for_each_entry_safe(desc, _desc, &list, desc_node) {
  752. - dev_vdbg(chan2dev(chan), " freeing descriptor %p\n", desc);
  753. - dma_pool_free(dw->desc_pool, desc, desc->txd.phys);
  754. - }
  755. -
  756. dev_vdbg(chan2dev(chan), "%s: done\n", __func__);
  757. }
  758. @@ -1321,6 +1264,7 @@ struct dw_cyclic_desc *dw_dma_cyclic_pre
  759. struct dw_cyclic_desc *retval = NULL;
  760. struct dw_desc *desc;
  761. struct dw_desc *last = NULL;
  762. + u8 lms = DWC_LLP_LMS(dwc->m_master);
  763. unsigned long was_cyclic;
  764. unsigned int reg_width;
  765. unsigned int periods;
  766. @@ -1374,9 +1318,6 @@ struct dw_cyclic_desc *dw_dma_cyclic_pre
  767. retval = ERR_PTR(-ENOMEM);
  768. - if (periods > NR_DESCS_PER_CHANNEL)
  769. - goto out_err;
  770. -
  771. cdesc = kzalloc(sizeof(struct dw_cyclic_desc), GFP_KERNEL);
  772. if (!cdesc)
  773. goto out_err;
  774. @@ -1392,50 +1333,50 @@ struct dw_cyclic_desc *dw_dma_cyclic_pre
  775. switch (direction) {
  776. case DMA_MEM_TO_DEV:
  777. - desc->lli.dar = sconfig->dst_addr;
  778. - desc->lli.sar = buf_addr + (period_len * i);
  779. - desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan)
  780. - | DWC_CTLL_DST_WIDTH(reg_width)
  781. - | DWC_CTLL_SRC_WIDTH(reg_width)
  782. - | DWC_CTLL_DST_FIX
  783. - | DWC_CTLL_SRC_INC
  784. - | DWC_CTLL_INT_EN);
  785. -
  786. - desc->lli.ctllo |= sconfig->device_fc ?
  787. - DWC_CTLL_FC(DW_DMA_FC_P_M2P) :
  788. - DWC_CTLL_FC(DW_DMA_FC_D_M2P);
  789. + lli_write(desc, dar, sconfig->dst_addr);
  790. + lli_write(desc, sar, buf_addr + period_len * i);
  791. + lli_write(desc, ctllo, (DWC_DEFAULT_CTLLO(chan)
  792. + | DWC_CTLL_DST_WIDTH(reg_width)
  793. + | DWC_CTLL_SRC_WIDTH(reg_width)
  794. + | DWC_CTLL_DST_FIX
  795. + | DWC_CTLL_SRC_INC
  796. + | DWC_CTLL_INT_EN));
  797. +
  798. + lli_set(desc, ctllo, sconfig->device_fc ?
  799. + DWC_CTLL_FC(DW_DMA_FC_P_M2P) :
  800. + DWC_CTLL_FC(DW_DMA_FC_D_M2P));
  801. break;
  802. case DMA_DEV_TO_MEM:
  803. - desc->lli.dar = buf_addr + (period_len * i);
  804. - desc->lli.sar = sconfig->src_addr;
  805. - desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan)
  806. - | DWC_CTLL_SRC_WIDTH(reg_width)
  807. - | DWC_CTLL_DST_WIDTH(reg_width)
  808. - | DWC_CTLL_DST_INC
  809. - | DWC_CTLL_SRC_FIX
  810. - | DWC_CTLL_INT_EN);
  811. -
  812. - desc->lli.ctllo |= sconfig->device_fc ?
  813. - DWC_CTLL_FC(DW_DMA_FC_P_P2M) :
  814. - DWC_CTLL_FC(DW_DMA_FC_D_P2M);
  815. + lli_write(desc, dar, buf_addr + period_len * i);
  816. + lli_write(desc, sar, sconfig->src_addr);
  817. + lli_write(desc, ctllo, (DWC_DEFAULT_CTLLO(chan)
  818. + | DWC_CTLL_SRC_WIDTH(reg_width)
  819. + | DWC_CTLL_DST_WIDTH(reg_width)
  820. + | DWC_CTLL_DST_INC
  821. + | DWC_CTLL_SRC_FIX
  822. + | DWC_CTLL_INT_EN));
  823. +
  824. + lli_set(desc, ctllo, sconfig->device_fc ?
  825. + DWC_CTLL_FC(DW_DMA_FC_P_P2M) :
  826. + DWC_CTLL_FC(DW_DMA_FC_D_P2M));
  827. break;
  828. default:
  829. break;
  830. }
  831. - desc->lli.ctlhi = (period_len >> reg_width);
  832. + lli_write(desc, ctlhi, period_len >> reg_width);
  833. cdesc->desc[i] = desc;
  834. if (last)
  835. - last->lli.llp = desc->txd.phys;
  836. + lli_write(last, llp, desc->txd.phys | lms);
  837. last = desc;
  838. }
  839. /* Let's make a cyclic list */
  840. - last->lli.llp = cdesc->desc[0]->txd.phys;
  841. + lli_write(last, llp, cdesc->desc[0]->txd.phys | lms);
  842. dev_dbg(chan2dev(&dwc->chan),
  843. "cyclic prepared buf %pad len %zu period %zu periods %d\n",
  844. @@ -1466,7 +1407,7 @@ void dw_dma_cyclic_free(struct dma_chan
  845. struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
  846. struct dw_dma *dw = to_dw_dma(dwc->chan.device);
  847. struct dw_cyclic_desc *cdesc = dwc->cdesc;
  848. - int i;
  849. + unsigned int i;
  850. unsigned long flags;
  851. dev_dbg(chan2dev(&dwc->chan), "%s\n", __func__);
  852. @@ -1490,32 +1431,38 @@ void dw_dma_cyclic_free(struct dma_chan
  853. kfree(cdesc->desc);
  854. kfree(cdesc);
  855. + dwc->cdesc = NULL;
  856. +
  857. clear_bit(DW_DMA_IS_CYCLIC, &dwc->flags);
  858. }
  859. EXPORT_SYMBOL(dw_dma_cyclic_free);
  860. /*----------------------------------------------------------------------*/
  861. -int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
  862. +int dw_dma_probe(struct dw_dma_chip *chip)
  863. {
  864. + struct dw_dma_platform_data *pdata;
  865. struct dw_dma *dw;
  866. bool autocfg = false;
  867. unsigned int dw_params;
  868. - unsigned int max_blk_size = 0;
  869. + unsigned int i;
  870. int err;
  871. - int i;
  872. dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL);
  873. if (!dw)
  874. return -ENOMEM;
  875. + dw->pdata = devm_kzalloc(chip->dev, sizeof(*dw->pdata), GFP_KERNEL);
  876. + if (!dw->pdata)
  877. + return -ENOMEM;
  878. +
  879. dw->regs = chip->regs;
  880. chip->dw = dw;
  881. pm_runtime_get_sync(chip->dev);
  882. - if (!pdata) {
  883. - dw_params = dma_read_byaddr(chip->regs, DW_PARAMS);
  884. + if (!chip->pdata) {
  885. + dw_params = dma_readl(dw, DW_PARAMS);
  886. dev_dbg(chip->dev, "DW_PARAMS: 0x%08x\n", dw_params);
  887. autocfg = dw_params >> DW_PARAMS_EN & 1;
  888. @@ -1524,29 +1471,31 @@ int dw_dma_probe(struct dw_dma_chip *chi
  889. goto err_pdata;
  890. }
  891. - pdata = devm_kzalloc(chip->dev, sizeof(*pdata), GFP_KERNEL);
  892. - if (!pdata) {
  893. - err = -ENOMEM;
  894. - goto err_pdata;
  895. - }
  896. + /* Reassign the platform data pointer */
  897. + pdata = dw->pdata;
  898. /* Get hardware configuration parameters */
  899. pdata->nr_channels = (dw_params >> DW_PARAMS_NR_CHAN & 7) + 1;
  900. pdata->nr_masters = (dw_params >> DW_PARAMS_NR_MASTER & 3) + 1;
  901. for (i = 0; i < pdata->nr_masters; i++) {
  902. pdata->data_width[i] =
  903. - (dw_params >> DW_PARAMS_DATA_WIDTH(i) & 3) + 2;
  904. + 4 << (dw_params >> DW_PARAMS_DATA_WIDTH(i) & 3);
  905. }
  906. - max_blk_size = dma_readl(dw, MAX_BLK_SIZE);
  907. + pdata->block_size = dma_readl(dw, MAX_BLK_SIZE);
  908. /* Fill platform data with the default values */
  909. pdata->is_private = true;
  910. pdata->is_memcpy = true;
  911. pdata->chan_allocation_order = CHAN_ALLOCATION_ASCENDING;
  912. pdata->chan_priority = CHAN_PRIORITY_ASCENDING;
  913. - } else if (pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) {
  914. + } else if (chip->pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) {
  915. err = -EINVAL;
  916. goto err_pdata;
  917. + } else {
  918. + memcpy(dw->pdata, chip->pdata, sizeof(*dw->pdata));
  919. +
  920. + /* Reassign the platform data pointer */
  921. + pdata = dw->pdata;
  922. }
  923. dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan),
  924. @@ -1556,11 +1505,6 @@ int dw_dma_probe(struct dw_dma_chip *chi
  925. goto err_pdata;
  926. }
  927. - /* Get hardware configuration parameters */
  928. - dw->nr_masters = pdata->nr_masters;
  929. - for (i = 0; i < dw->nr_masters; i++)
  930. - dw->data_width[i] = pdata->data_width[i];
  931. -
  932. /* Calculate all channel mask before DMA setup */
  933. dw->all_chan_mask = (1 << pdata->nr_channels) - 1;
  934. @@ -1607,7 +1551,6 @@ int dw_dma_probe(struct dw_dma_chip *chi
  935. INIT_LIST_HEAD(&dwc->active_list);
  936. INIT_LIST_HEAD(&dwc->queue);
  937. - INIT_LIST_HEAD(&dwc->free_list);
  938. channel_clear_bit(dw, CH_EN, dwc->mask);
  939. @@ -1615,11 +1558,9 @@ int dw_dma_probe(struct dw_dma_chip *chi
  940. /* Hardware configuration */
  941. if (autocfg) {
  942. - unsigned int dwc_params;
  943. unsigned int r = DW_DMA_MAX_NR_CHANNELS - i - 1;
  944. - void __iomem *addr = chip->regs + r * sizeof(u32);
  945. -
  946. - dwc_params = dma_read_byaddr(addr, DWC_PARAMS);
  947. + void __iomem *addr = &__dw_regs(dw)->DWC_PARAMS[r];
  948. + unsigned int dwc_params = dma_readl_native(addr);
  949. dev_dbg(chip->dev, "DWC_PARAMS[%d]: 0x%08x\n", i,
  950. dwc_params);
  951. @@ -1630,16 +1571,15 @@ int dw_dma_probe(struct dw_dma_chip *chi
  952. * up to 0x0a for 4095.
  953. */
  954. dwc->block_size =
  955. - (4 << ((max_blk_size >> 4 * i) & 0xf)) - 1;
  956. + (4 << ((pdata->block_size >> 4 * i) & 0xf)) - 1;
  957. dwc->nollp =
  958. (dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0;
  959. } else {
  960. dwc->block_size = pdata->block_size;
  961. /* Check if channel supports multi block transfer */
  962. - channel_writel(dwc, LLP, 0xfffffffc);
  963. - dwc->nollp =
  964. - (channel_readl(dwc, LLP) & 0xfffffffc) == 0;
  965. + channel_writel(dwc, LLP, DWC_LLP_LOC(0xffffffff));
  966. + dwc->nollp = DWC_LLP_LOC(channel_readl(dwc, LLP)) == 0;
  967. channel_writel(dwc, LLP, 0);
  968. }
  969. }
  970. --- a/drivers/dma/dw/pci.c
  971. +++ b/drivers/dma/dw/pci.c
  972. @@ -17,8 +17,8 @@
  973. static int dw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
  974. {
  975. + const struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
  976. struct dw_dma_chip *chip;
  977. - struct dw_dma_platform_data *pdata = (void *)pid->driver_data;
  978. int ret;
  979. ret = pcim_enable_device(pdev);
  980. @@ -49,8 +49,9 @@ static int dw_pci_probe(struct pci_dev *
  981. chip->dev = &pdev->dev;
  982. chip->regs = pcim_iomap_table(pdev)[0];
  983. chip->irq = pdev->irq;
  984. + chip->pdata = pdata;
  985. - ret = dw_dma_probe(chip, pdata);
  986. + ret = dw_dma_probe(chip);
  987. if (ret)
  988. return ret;
  989. @@ -108,6 +109,10 @@ static const struct pci_device_id dw_pci
  990. /* Haswell */
  991. { PCI_VDEVICE(INTEL, 0x9c60) },
  992. +
  993. + /* Broadwell */
  994. + { PCI_VDEVICE(INTEL, 0x9ce0) },
  995. +
  996. { }
  997. };
  998. MODULE_DEVICE_TABLE(pci, dw_pci_id_table);
  999. --- a/drivers/dma/dw/platform.c
  1000. +++ b/drivers/dma/dw/platform.c
  1001. @@ -42,13 +42,13 @@ static struct dma_chan *dw_dma_of_xlate(
  1002. slave.src_id = dma_spec->args[0];
  1003. slave.dst_id = dma_spec->args[0];
  1004. - slave.src_master = dma_spec->args[1];
  1005. - slave.dst_master = dma_spec->args[2];
  1006. + slave.m_master = dma_spec->args[1];
  1007. + slave.p_master = dma_spec->args[2];
  1008. if (WARN_ON(slave.src_id >= DW_DMA_MAX_NR_REQUESTS ||
  1009. slave.dst_id >= DW_DMA_MAX_NR_REQUESTS ||
  1010. - slave.src_master >= dw->nr_masters ||
  1011. - slave.dst_master >= dw->nr_masters))
  1012. + slave.m_master >= dw->pdata->nr_masters ||
  1013. + slave.p_master >= dw->pdata->nr_masters))
  1014. return NULL;
  1015. dma_cap_zero(cap);
  1016. @@ -66,8 +66,8 @@ static bool dw_dma_acpi_filter(struct dm
  1017. .dma_dev = dma_spec->dev,
  1018. .src_id = dma_spec->slave_id,
  1019. .dst_id = dma_spec->slave_id,
  1020. - .src_master = 1,
  1021. - .dst_master = 0,
  1022. + .m_master = 0,
  1023. + .p_master = 1,
  1024. };
  1025. return dw_dma_filter(chan, &slave);
  1026. @@ -103,18 +103,28 @@ dw_dma_parse_dt(struct platform_device *
  1027. struct device_node *np = pdev->dev.of_node;
  1028. struct dw_dma_platform_data *pdata;
  1029. u32 tmp, arr[DW_DMA_MAX_NR_MASTERS];
  1030. + u32 nr_masters;
  1031. + u32 nr_channels;
  1032. if (!np) {
  1033. dev_err(&pdev->dev, "Missing DT data\n");
  1034. return NULL;
  1035. }
  1036. + if (of_property_read_u32(np, "dma-masters", &nr_masters))
  1037. + return NULL;
  1038. + if (nr_masters < 1 || nr_masters > DW_DMA_MAX_NR_MASTERS)
  1039. + return NULL;
  1040. +
  1041. + if (of_property_read_u32(np, "dma-channels", &nr_channels))
  1042. + return NULL;
  1043. +
  1044. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  1045. if (!pdata)
  1046. return NULL;
  1047. - if (of_property_read_u32(np, "dma-channels", &pdata->nr_channels))
  1048. - return NULL;
  1049. + pdata->nr_masters = nr_masters;
  1050. + pdata->nr_channels = nr_channels;
  1051. if (of_property_read_bool(np, "is_private"))
  1052. pdata->is_private = true;
  1053. @@ -128,17 +138,13 @@ dw_dma_parse_dt(struct platform_device *
  1054. if (!of_property_read_u32(np, "block_size", &tmp))
  1055. pdata->block_size = tmp;
  1056. - if (!of_property_read_u32(np, "dma-masters", &tmp)) {
  1057. - if (tmp > DW_DMA_MAX_NR_MASTERS)
  1058. - return NULL;
  1059. -
  1060. - pdata->nr_masters = tmp;
  1061. - }
  1062. -
  1063. - if (!of_property_read_u32_array(np, "data_width", arr,
  1064. - pdata->nr_masters))
  1065. - for (tmp = 0; tmp < pdata->nr_masters; tmp++)
  1066. + if (!of_property_read_u32_array(np, "data-width", arr, nr_masters)) {
  1067. + for (tmp = 0; tmp < nr_masters; tmp++)
  1068. pdata->data_width[tmp] = arr[tmp];
  1069. + } else if (!of_property_read_u32_array(np, "data_width", arr, nr_masters)) {
  1070. + for (tmp = 0; tmp < nr_masters; tmp++)
  1071. + pdata->data_width[tmp] = BIT(arr[tmp] & 0x07);
  1072. + }
  1073. return pdata;
  1074. }
  1075. @@ -155,8 +161,7 @@ static int dw_probe(struct platform_devi
  1076. struct dw_dma_chip *chip;
  1077. struct device *dev = &pdev->dev;
  1078. struct resource *mem;
  1079. - const struct acpi_device_id *id;
  1080. - struct dw_dma_platform_data *pdata;
  1081. + const struct dw_dma_platform_data *pdata;
  1082. int err;
  1083. chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
  1084. @@ -179,13 +184,9 @@ static int dw_probe(struct platform_devi
  1085. pdata = dev_get_platdata(dev);
  1086. if (!pdata)
  1087. pdata = dw_dma_parse_dt(pdev);
  1088. - if (!pdata && has_acpi_companion(dev)) {
  1089. - id = acpi_match_device(dev->driver->acpi_match_table, dev);
  1090. - if (id)
  1091. - pdata = (struct dw_dma_platform_data *)id->driver_data;
  1092. - }
  1093. chip->dev = dev;
  1094. + chip->pdata = pdata;
  1095. chip->clk = devm_clk_get(chip->dev, "hclk");
  1096. if (IS_ERR(chip->clk))
  1097. @@ -196,7 +197,7 @@ static int dw_probe(struct platform_devi
  1098. pm_runtime_enable(&pdev->dev);
  1099. - err = dw_dma_probe(chip, pdata);
  1100. + err = dw_dma_probe(chip);
  1101. if (err)
  1102. goto err_dw_dma_probe;
  1103. @@ -239,7 +240,19 @@ static void dw_shutdown(struct platform_
  1104. {
  1105. struct dw_dma_chip *chip = platform_get_drvdata(pdev);
  1106. + /*
  1107. + * We have to call dw_dma_disable() to stop any ongoing transfer. On
  1108. + * some platforms we can't do that since DMA device is powered off.
  1109. + * Moreover we have no possibility to check if the platform is affected
  1110. + * or not. That's why we call pm_runtime_get_sync() / pm_runtime_put()
  1111. + * unconditionally. On the other hand we can't use
  1112. + * pm_runtime_suspended() because runtime PM framework is not fully
  1113. + * used by the driver.
  1114. + */
  1115. + pm_runtime_get_sync(chip->dev);
  1116. dw_dma_disable(chip);
  1117. + pm_runtime_put_sync_suspend(chip->dev);
  1118. +
  1119. clk_disable_unprepare(chip->clk);
  1120. }
  1121. @@ -252,17 +265,8 @@ MODULE_DEVICE_TABLE(of, dw_dma_of_id_tab
  1122. #endif
  1123. #ifdef CONFIG_ACPI
  1124. -static struct dw_dma_platform_data dw_dma_acpi_pdata = {
  1125. - .nr_channels = 8,
  1126. - .is_private = true,
  1127. - .chan_allocation_order = CHAN_ALLOCATION_ASCENDING,
  1128. - .chan_priority = CHAN_PRIORITY_ASCENDING,
  1129. - .block_size = 4095,
  1130. - .nr_masters = 2,
  1131. -};
  1132. -
  1133. static const struct acpi_device_id dw_dma_acpi_id_table[] = {
  1134. - { "INTL9C60", (kernel_ulong_t)&dw_dma_acpi_pdata },
  1135. + { "INTL9C60", 0 },
  1136. { }
  1137. };
  1138. MODULE_DEVICE_TABLE(acpi, dw_dma_acpi_id_table);
  1139. --- a/drivers/dma/dw/regs.h
  1140. +++ b/drivers/dma/dw/regs.h
  1141. @@ -114,10 +114,6 @@ struct dw_dma_regs {
  1142. #define dma_writel_native writel
  1143. #endif
  1144. -/* To access the registers in early stage of probe */
  1145. -#define dma_read_byaddr(addr, name) \
  1146. - dma_readl_native((addr) + offsetof(struct dw_dma_regs, name))
  1147. -
  1148. /* Bitfields in DW_PARAMS */
  1149. #define DW_PARAMS_NR_CHAN 8 /* number of channels */
  1150. #define DW_PARAMS_NR_MASTER 11 /* number of AHB masters */
  1151. @@ -143,6 +139,10 @@ enum dw_dma_msize {
  1152. DW_DMA_MSIZE_256,
  1153. };
  1154. +/* Bitfields in LLP */
  1155. +#define DWC_LLP_LMS(x) ((x) & 3) /* list master select */
  1156. +#define DWC_LLP_LOC(x) ((x) & ~3) /* next lli */
  1157. +
  1158. /* Bitfields in CTL_LO */
  1159. #define DWC_CTLL_INT_EN (1 << 0) /* irqs enabled? */
  1160. #define DWC_CTLL_DST_WIDTH(n) ((n)<<1) /* bytes per element */
  1161. @@ -150,7 +150,7 @@ enum dw_dma_msize {
  1162. #define DWC_CTLL_DST_INC (0<<7) /* DAR update/not */
  1163. #define DWC_CTLL_DST_DEC (1<<7)
  1164. #define DWC_CTLL_DST_FIX (2<<7)
  1165. -#define DWC_CTLL_SRC_INC (0<<7) /* SAR update/not */
  1166. +#define DWC_CTLL_SRC_INC (0<<9) /* SAR update/not */
  1167. #define DWC_CTLL_SRC_DEC (1<<9)
  1168. #define DWC_CTLL_SRC_FIX (2<<9)
  1169. #define DWC_CTLL_DST_MSIZE(n) ((n)<<11) /* burst, #elements */
  1170. @@ -216,6 +216,8 @@ enum dw_dma_msize {
  1171. enum dw_dmac_flags {
  1172. DW_DMA_IS_CYCLIC = 0,
  1173. DW_DMA_IS_SOFT_LLP = 1,
  1174. + DW_DMA_IS_PAUSED = 2,
  1175. + DW_DMA_IS_INITIALIZED = 3,
  1176. };
  1177. struct dw_dma_chan {
  1178. @@ -224,8 +226,6 @@ struct dw_dma_chan {
  1179. u8 mask;
  1180. u8 priority;
  1181. enum dma_transfer_direction direction;
  1182. - bool paused;
  1183. - bool initialized;
  1184. /* software emulation of the LLP transfers */
  1185. struct list_head *tx_node_active;
  1186. @@ -236,8 +236,6 @@ struct dw_dma_chan {
  1187. unsigned long flags;
  1188. struct list_head active_list;
  1189. struct list_head queue;
  1190. - struct list_head free_list;
  1191. - u32 residue;
  1192. struct dw_cyclic_desc *cdesc;
  1193. unsigned int descs_allocated;
  1194. @@ -249,8 +247,8 @@ struct dw_dma_chan {
  1195. /* custom slave configuration */
  1196. u8 src_id;
  1197. u8 dst_id;
  1198. - u8 src_master;
  1199. - u8 dst_master;
  1200. + u8 m_master;
  1201. + u8 p_master;
  1202. /* configuration passed via .device_config */
  1203. struct dma_slave_config dma_sconfig;
  1204. @@ -283,9 +281,8 @@ struct dw_dma {
  1205. u8 all_chan_mask;
  1206. u8 in_use;
  1207. - /* hardware configuration */
  1208. - unsigned char nr_masters;
  1209. - unsigned char data_width[DW_DMA_MAX_NR_MASTERS];
  1210. + /* platform data */
  1211. + struct dw_dma_platform_data *pdata;
  1212. };
  1213. static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw)
  1214. @@ -308,32 +305,51 @@ static inline struct dw_dma *to_dw_dma(s
  1215. return container_of(ddev, struct dw_dma, dma);
  1216. }
  1217. +#ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO
  1218. +typedef __be32 __dw32;
  1219. +#else
  1220. +typedef __le32 __dw32;
  1221. +#endif
  1222. +
  1223. /* LLI == Linked List Item; a.k.a. DMA block descriptor */
  1224. struct dw_lli {
  1225. /* values that are not changed by hardware */
  1226. - u32 sar;
  1227. - u32 dar;
  1228. - u32 llp; /* chain to next lli */
  1229. - u32 ctllo;
  1230. + __dw32 sar;
  1231. + __dw32 dar;
  1232. + __dw32 llp; /* chain to next lli */
  1233. + __dw32 ctllo;
  1234. /* values that may get written back: */
  1235. - u32 ctlhi;
  1236. + __dw32 ctlhi;
  1237. /* sstat and dstat can snapshot peripheral register state.
  1238. * silicon config may discard either or both...
  1239. */
  1240. - u32 sstat;
  1241. - u32 dstat;
  1242. + __dw32 sstat;
  1243. + __dw32 dstat;
  1244. };
  1245. struct dw_desc {
  1246. /* FIRST values the hardware uses */
  1247. struct dw_lli lli;
  1248. +#ifdef CONFIG_DW_DMAC_BIG_ENDIAN_IO
  1249. +#define lli_set(d, reg, v) ((d)->lli.reg |= cpu_to_be32(v))
  1250. +#define lli_clear(d, reg, v) ((d)->lli.reg &= ~cpu_to_be32(v))
  1251. +#define lli_read(d, reg) be32_to_cpu((d)->lli.reg)
  1252. +#define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_be32(v))
  1253. +#else
  1254. +#define lli_set(d, reg, v) ((d)->lli.reg |= cpu_to_le32(v))
  1255. +#define lli_clear(d, reg, v) ((d)->lli.reg &= ~cpu_to_le32(v))
  1256. +#define lli_read(d, reg) le32_to_cpu((d)->lli.reg)
  1257. +#define lli_write(d, reg, v) ((d)->lli.reg = cpu_to_le32(v))
  1258. +#endif
  1259. +
  1260. /* THEN values for driver housekeeping */
  1261. struct list_head desc_node;
  1262. struct list_head tx_list;
  1263. struct dma_async_tx_descriptor txd;
  1264. size_t len;
  1265. size_t total_len;
  1266. + u32 residue;
  1267. };
  1268. #define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node)
  1269. --- a/include/linux/dma/dw.h
  1270. +++ b/include/linux/dma/dw.h
  1271. @@ -27,6 +27,7 @@ struct dw_dma;
  1272. * @regs: memory mapped I/O space
  1273. * @clk: hclk clock
  1274. * @dw: struct dw_dma that is filed by dw_dma_probe()
  1275. + * @pdata: pointer to platform data
  1276. */
  1277. struct dw_dma_chip {
  1278. struct device *dev;
  1279. @@ -34,10 +35,12 @@ struct dw_dma_chip {
  1280. void __iomem *regs;
  1281. struct clk *clk;
  1282. struct dw_dma *dw;
  1283. +
  1284. + const struct dw_dma_platform_data *pdata;
  1285. };
  1286. /* Export to the platform drivers */
  1287. -int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata);
  1288. +int dw_dma_probe(struct dw_dma_chip *chip);
  1289. int dw_dma_remove(struct dw_dma_chip *chip);
  1290. /* DMA API extensions */
  1291. --- a/include/linux/platform_data/dma-dw.h
  1292. +++ b/include/linux/platform_data/dma-dw.h
  1293. @@ -21,15 +21,15 @@
  1294. * @dma_dev: required DMA master device
  1295. * @src_id: src request line
  1296. * @dst_id: dst request line
  1297. - * @src_master: src master for transfers on allocated channel.
  1298. - * @dst_master: dest master for transfers on allocated channel.
  1299. + * @m_master: memory master for transfers on allocated channel
  1300. + * @p_master: peripheral master for transfers on allocated channel
  1301. */
  1302. struct dw_dma_slave {
  1303. struct device *dma_dev;
  1304. u8 src_id;
  1305. u8 dst_id;
  1306. - u8 src_master;
  1307. - u8 dst_master;
  1308. + u8 m_master;
  1309. + u8 p_master;
  1310. };
  1311. /**
  1312. @@ -43,7 +43,7 @@ struct dw_dma_slave {
  1313. * @block_size: Maximum block size supported by the controller
  1314. * @nr_masters: Number of AHB masters supported by the controller
  1315. * @data_width: Maximum data width supported by hardware per AHB master
  1316. - * (0 - 8bits, 1 - 16bits, ..., 5 - 256bits)
  1317. + * (in bytes, power of 2)
  1318. */
  1319. struct dw_dma_platform_data {
  1320. unsigned int nr_channels;
  1321. @@ -55,7 +55,7 @@ struct dw_dma_platform_data {
  1322. #define CHAN_PRIORITY_ASCENDING 0 /* chan0 highest */
  1323. #define CHAN_PRIORITY_DESCENDING 1 /* chan7 highest */
  1324. unsigned char chan_priority;
  1325. - unsigned short block_size;
  1326. + unsigned int block_size;
  1327. unsigned char nr_masters;
  1328. unsigned char data_width[DW_DMA_MAX_NR_MASTERS];
  1329. };