xilinx_dma.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783
  1. /*
  2. * DMA driver for Xilinx Video DMA Engine
  3. *
  4. * Copyright (C) 2010-2014 Xilinx, Inc. All rights reserved.
  5. *
  6. * Based on the Freescale DMA driver.
  7. *
  8. * Description:
  9. * The AXI Video Direct Memory Access (AXI VDMA) core is a soft Xilinx IP
  10. * core that provides high-bandwidth direct memory access between memory
  11. * and AXI4-Stream type video target peripherals. The core provides efficient
  12. * two dimensional DMA operations with independent asynchronous read (S2MM)
  13. * and write (MM2S) channel operation. It can be configured to have either
  14. * one channel or two channels. If configured as two channels, one is to
  15. * transmit to the video device (MM2S) and another is to receive from the
  16. * video device (S2MM). Initialization, status, interrupt and management
  17. * registers are accessed through an AXI4-Lite slave interface.
  18. *
  19. * The AXI Direct Memory Access (AXI DMA) core is a soft Xilinx IP core that
  20. * provides high-bandwidth one dimensional direct memory access between memory
  21. * and AXI4-Stream target peripherals. It supports one receive and one
  22. * transmit channel, both of them optional at synthesis time.
  23. *
  24. * The AXI CDMA, is a soft IP, which provides high-bandwidth Direct Memory
  25. * Access (DMA) between a memory-mapped source address and a memory-mapped
  26. * destination address.
  27. *
  28. * This program is free software: you can redistribute it and/or modify
  29. * it under the terms of the GNU General Public License as published by
  30. * the Free Software Foundation, either version 2 of the License, or
  31. * (at your option) any later version.
  32. */
  33. #include <linux/bitops.h>
  34. #include <linux/dmapool.h>
  35. #include <linux/dma/xilinx_dma.h>
  36. #include <linux/init.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/io.h>
  39. #include <linux/iopoll.h>
  40. #include <linux/module.h>
  41. #include <linux/of_address.h>
  42. #include <linux/of_dma.h>
  43. #include <linux/of_platform.h>
  44. #include <linux/of_irq.h>
  45. #include <linux/slab.h>
  46. #include <linux/clk.h>
  47. #include <linux/io-64-nonatomic-lo-hi.h>
  48. #include "../dmaengine.h"
  49. /* Register/Descriptor Offsets */
  50. #define XILINX_DMA_MM2S_CTRL_OFFSET 0x0000
  51. #define XILINX_DMA_S2MM_CTRL_OFFSET 0x0030
  52. #define XILINX_VDMA_MM2S_DESC_OFFSET 0x0050
  53. #define XILINX_VDMA_S2MM_DESC_OFFSET 0x00a0
  54. /* Control Registers */
  55. #define XILINX_DMA_REG_DMACR 0x0000
  56. #define XILINX_DMA_DMACR_DELAY_MAX 0xff
  57. #define XILINX_DMA_DMACR_DELAY_SHIFT 24
  58. #define XILINX_DMA_DMACR_FRAME_COUNT_MAX 0xff
  59. #define XILINX_DMA_DMACR_FRAME_COUNT_SHIFT 16
  60. #define XILINX_DMA_DMACR_ERR_IRQ BIT(14)
  61. #define XILINX_DMA_DMACR_DLY_CNT_IRQ BIT(13)
  62. #define XILINX_DMA_DMACR_FRM_CNT_IRQ BIT(12)
  63. #define XILINX_DMA_DMACR_MASTER_SHIFT 8
  64. #define XILINX_DMA_DMACR_FSYNCSRC_SHIFT 5
  65. #define XILINX_DMA_DMACR_FRAMECNT_EN BIT(4)
  66. #define XILINX_DMA_DMACR_GENLOCK_EN BIT(3)
  67. #define XILINX_DMA_DMACR_RESET BIT(2)
  68. #define XILINX_DMA_DMACR_CIRC_EN BIT(1)
  69. #define XILINX_DMA_DMACR_RUNSTOP BIT(0)
  70. #define XILINX_DMA_DMACR_FSYNCSRC_MASK GENMASK(6, 5)
  71. #define XILINX_DMA_DMACR_DELAY_MASK GENMASK(31, 24)
  72. #define XILINX_DMA_DMACR_FRAME_COUNT_MASK GENMASK(23, 16)
  73. #define XILINX_DMA_DMACR_MASTER_MASK GENMASK(11, 8)
  74. #define XILINX_DMA_REG_DMASR 0x0004
  75. #define XILINX_DMA_DMASR_EOL_LATE_ERR BIT(15)
  76. #define XILINX_DMA_DMASR_ERR_IRQ BIT(14)
  77. #define XILINX_DMA_DMASR_DLY_CNT_IRQ BIT(13)
  78. #define XILINX_DMA_DMASR_FRM_CNT_IRQ BIT(12)
  79. #define XILINX_DMA_DMASR_SOF_LATE_ERR BIT(11)
  80. #define XILINX_DMA_DMASR_SG_DEC_ERR BIT(10)
  81. #define XILINX_DMA_DMASR_SG_SLV_ERR BIT(9)
  82. #define XILINX_DMA_DMASR_EOF_EARLY_ERR BIT(8)
  83. #define XILINX_DMA_DMASR_SOF_EARLY_ERR BIT(7)
  84. #define XILINX_DMA_DMASR_DMA_DEC_ERR BIT(6)
  85. #define XILINX_DMA_DMASR_DMA_SLAVE_ERR BIT(5)
  86. #define XILINX_DMA_DMASR_DMA_INT_ERR BIT(4)
  87. #define XILINX_DMA_DMASR_IDLE BIT(1)
  88. #define XILINX_DMA_DMASR_HALTED BIT(0)
  89. #define XILINX_DMA_DMASR_DELAY_MASK GENMASK(31, 24)
  90. #define XILINX_DMA_DMASR_FRAME_COUNT_MASK GENMASK(23, 16)
  91. #define XILINX_DMA_REG_CURDESC 0x0008
  92. #define XILINX_DMA_REG_TAILDESC 0x0010
  93. #define XILINX_DMA_REG_REG_INDEX 0x0014
  94. #define XILINX_DMA_REG_FRMSTORE 0x0018
  95. #define XILINX_DMA_REG_THRESHOLD 0x001c
  96. #define XILINX_DMA_REG_FRMPTR_STS 0x0024
  97. #define XILINX_DMA_REG_PARK_PTR 0x0028
  98. #define XILINX_DMA_PARK_PTR_WR_REF_SHIFT 8
  99. #define XILINX_DMA_PARK_PTR_WR_REF_MASK GENMASK(12, 8)
  100. #define XILINX_DMA_PARK_PTR_RD_REF_SHIFT 0
  101. #define XILINX_DMA_PARK_PTR_RD_REF_MASK GENMASK(4, 0)
  102. #define XILINX_DMA_REG_VDMA_VERSION 0x002c
  103. /* Register Direct Mode Registers */
  104. #define XILINX_DMA_REG_VSIZE 0x0000
  105. #define XILINX_DMA_REG_HSIZE 0x0004
  106. #define XILINX_DMA_REG_FRMDLY_STRIDE 0x0008
  107. #define XILINX_DMA_FRMDLY_STRIDE_FRMDLY_SHIFT 24
  108. #define XILINX_DMA_FRMDLY_STRIDE_STRIDE_SHIFT 0
  109. #define XILINX_VDMA_REG_START_ADDRESS(n) (0x000c + 4 * (n))
  110. #define XILINX_VDMA_REG_START_ADDRESS_64(n) (0x000c + 8 * (n))
  111. #define XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP 0x00ec
  112. #define XILINX_VDMA_ENABLE_VERTICAL_FLIP BIT(0)
  113. /* HW specific definitions */
  114. #define XILINX_DMA_MAX_CHANS_PER_DEVICE 0x20
  115. #define XILINX_DMA_DMAXR_ALL_IRQ_MASK \
  116. (XILINX_DMA_DMASR_FRM_CNT_IRQ | \
  117. XILINX_DMA_DMASR_DLY_CNT_IRQ | \
  118. XILINX_DMA_DMASR_ERR_IRQ)
  119. #define XILINX_DMA_DMASR_ALL_ERR_MASK \
  120. (XILINX_DMA_DMASR_EOL_LATE_ERR | \
  121. XILINX_DMA_DMASR_SOF_LATE_ERR | \
  122. XILINX_DMA_DMASR_SG_DEC_ERR | \
  123. XILINX_DMA_DMASR_SG_SLV_ERR | \
  124. XILINX_DMA_DMASR_EOF_EARLY_ERR | \
  125. XILINX_DMA_DMASR_SOF_EARLY_ERR | \
  126. XILINX_DMA_DMASR_DMA_DEC_ERR | \
  127. XILINX_DMA_DMASR_DMA_SLAVE_ERR | \
  128. XILINX_DMA_DMASR_DMA_INT_ERR)
  129. /*
  130. * Recoverable errors are DMA Internal error, SOF Early, EOF Early
  131. * and SOF Late. They are only recoverable when C_FLUSH_ON_FSYNC
  132. * is enabled in the h/w system.
  133. */
  134. #define XILINX_DMA_DMASR_ERR_RECOVER_MASK \
  135. (XILINX_DMA_DMASR_SOF_LATE_ERR | \
  136. XILINX_DMA_DMASR_EOF_EARLY_ERR | \
  137. XILINX_DMA_DMASR_SOF_EARLY_ERR | \
  138. XILINX_DMA_DMASR_DMA_INT_ERR)
  139. /* Axi VDMA Flush on Fsync bits */
  140. #define XILINX_DMA_FLUSH_S2MM 3
  141. #define XILINX_DMA_FLUSH_MM2S 2
  142. #define XILINX_DMA_FLUSH_BOTH 1
  143. /* Delay loop counter to prevent hardware failure */
  144. #define XILINX_DMA_LOOP_COUNT 1000000
  145. /* AXI DMA Specific Registers/Offsets */
  146. #define XILINX_DMA_REG_SRCDSTADDR 0x18
  147. #define XILINX_DMA_REG_BTT 0x28
  148. /* AXI DMA Specific Masks/Bit fields */
  149. #define XILINX_DMA_MAX_TRANS_LEN GENMASK(22, 0)
  150. #define XILINX_DMA_CR_COALESCE_MAX GENMASK(23, 16)
  151. #define XILINX_DMA_CR_CYCLIC_BD_EN_MASK BIT(4)
  152. #define XILINX_DMA_CR_COALESCE_SHIFT 16
  153. #define XILINX_DMA_BD_SOP BIT(27)
  154. #define XILINX_DMA_BD_EOP BIT(26)
  155. #define XILINX_DMA_COALESCE_MAX 255
  156. #define XILINX_DMA_NUM_DESCS 255
  157. #define XILINX_DMA_NUM_APP_WORDS 5
  158. /* Multi-Channel DMA Descriptor offsets*/
  159. #define XILINX_DMA_MCRX_CDESC(x) (0x40 + (x-1) * 0x20)
  160. #define XILINX_DMA_MCRX_TDESC(x) (0x48 + (x-1) * 0x20)
  161. /* Multi-Channel DMA Masks/Shifts */
  162. #define XILINX_DMA_BD_HSIZE_MASK GENMASK(15, 0)
  163. #define XILINX_DMA_BD_STRIDE_MASK GENMASK(15, 0)
  164. #define XILINX_DMA_BD_VSIZE_MASK GENMASK(31, 19)
  165. #define XILINX_DMA_BD_TDEST_MASK GENMASK(4, 0)
  166. #define XILINX_DMA_BD_STRIDE_SHIFT 0
  167. #define XILINX_DMA_BD_VSIZE_SHIFT 19
  168. /* AXI CDMA Specific Registers/Offsets */
  169. #define XILINX_CDMA_REG_SRCADDR 0x18
  170. #define XILINX_CDMA_REG_DSTADDR 0x20
  171. /* AXI CDMA Specific Masks */
  172. #define XILINX_CDMA_CR_SGMODE BIT(3)
  173. /**
  174. * struct xilinx_vdma_desc_hw - Hardware Descriptor
  175. * @next_desc: Next Descriptor Pointer @0x00
  176. * @pad1: Reserved @0x04
  177. * @buf_addr: Buffer address @0x08
  178. * @buf_addr_msb: MSB of Buffer address @0x0C
  179. * @vsize: Vertical Size @0x10
  180. * @hsize: Horizontal Size @0x14
  181. * @stride: Number of bytes between the first
  182. * pixels of each horizontal line @0x18
  183. */
  184. struct xilinx_vdma_desc_hw {
  185. u32 next_desc;
  186. u32 pad1;
  187. u32 buf_addr;
  188. u32 buf_addr_msb;
  189. u32 vsize;
  190. u32 hsize;
  191. u32 stride;
  192. } __aligned(64);
  193. /**
  194. * struct xilinx_axidma_desc_hw - Hardware Descriptor for AXI DMA
  195. * @next_desc: Next Descriptor Pointer @0x00
  196. * @next_desc_msb: MSB of Next Descriptor Pointer @0x04
  197. * @buf_addr: Buffer address @0x08
  198. * @buf_addr_msb: MSB of Buffer address @0x0C
  199. * @mcdma_control: Control field for mcdma @0x10
  200. * @vsize_stride: Vsize and Stride field for mcdma @0x14
  201. * @control: Control field @0x18
  202. * @status: Status field @0x1C
  203. * @app: APP Fields @0x20 - 0x30
  204. */
  205. struct xilinx_axidma_desc_hw {
  206. u32 next_desc;
  207. u32 next_desc_msb;
  208. u32 buf_addr;
  209. u32 buf_addr_msb;
  210. u32 mcdma_control;
  211. u32 vsize_stride;
  212. u32 control;
  213. u32 status;
  214. u32 app[XILINX_DMA_NUM_APP_WORDS];
  215. } __aligned(64);
  216. /**
  217. * struct xilinx_cdma_desc_hw - Hardware Descriptor
  218. * @next_desc: Next Descriptor Pointer @0x00
  219. * @next_desc_msb: Next Descriptor Pointer MSB @0x04
  220. * @src_addr: Source address @0x08
  221. * @src_addr_msb: Source address MSB @0x0C
  222. * @dest_addr: Destination address @0x10
  223. * @dest_addr_msb: Destination address MSB @0x14
  224. * @control: Control field @0x18
  225. * @status: Status field @0x1C
  226. */
  227. struct xilinx_cdma_desc_hw {
  228. u32 next_desc;
  229. u32 next_desc_msb;
  230. u32 src_addr;
  231. u32 src_addr_msb;
  232. u32 dest_addr;
  233. u32 dest_addr_msb;
  234. u32 control;
  235. u32 status;
  236. } __aligned(64);
  237. /**
  238. * struct xilinx_vdma_tx_segment - Descriptor segment
  239. * @hw: Hardware descriptor
  240. * @node: Node in the descriptor segments list
  241. * @phys: Physical address of segment
  242. */
  243. struct xilinx_vdma_tx_segment {
  244. struct xilinx_vdma_desc_hw hw;
  245. struct list_head node;
  246. dma_addr_t phys;
  247. } __aligned(64);
  248. /**
  249. * struct xilinx_axidma_tx_segment - Descriptor segment
  250. * @hw: Hardware descriptor
  251. * @node: Node in the descriptor segments list
  252. * @phys: Physical address of segment
  253. */
  254. struct xilinx_axidma_tx_segment {
  255. struct xilinx_axidma_desc_hw hw;
  256. struct list_head node;
  257. dma_addr_t phys;
  258. } __aligned(64);
  259. /**
  260. * struct xilinx_cdma_tx_segment - Descriptor segment
  261. * @hw: Hardware descriptor
  262. * @node: Node in the descriptor segments list
  263. * @phys: Physical address of segment
  264. */
  265. struct xilinx_cdma_tx_segment {
  266. struct xilinx_cdma_desc_hw hw;
  267. struct list_head node;
  268. dma_addr_t phys;
  269. } __aligned(64);
  270. /**
  271. * struct xilinx_dma_tx_descriptor - Per Transaction structure
  272. * @async_tx: Async transaction descriptor
  273. * @segments: TX segments list
  274. * @node: Node in the channel descriptors list
  275. * @cyclic: Check for cyclic transfers.
  276. */
  277. struct xilinx_dma_tx_descriptor {
  278. struct dma_async_tx_descriptor async_tx;
  279. struct list_head segments;
  280. struct list_head node;
  281. bool cyclic;
  282. };
  283. /**
  284. * struct xilinx_dma_chan - Driver specific DMA channel structure
  285. * @xdev: Driver specific device structure
  286. * @ctrl_offset: Control registers offset
  287. * @desc_offset: TX descriptor registers offset
  288. * @lock: Descriptor operation lock
  289. * @pending_list: Descriptors waiting
  290. * @active_list: Descriptors ready to submit
  291. * @done_list: Complete descriptors
  292. * @free_seg_list: Free descriptors
  293. * @common: DMA common channel
  294. * @desc_pool: Descriptors pool
  295. * @dev: The dma device
  296. * @irq: Channel IRQ
  297. * @id: Channel ID
  298. * @direction: Transfer direction
  299. * @num_frms: Number of frames
  300. * @has_sg: Support scatter transfers
  301. * @cyclic: Check for cyclic transfers.
  302. * @genlock: Support genlock mode
  303. * @err: Channel has errors
  304. * @idle: Check for channel idle
  305. * @tasklet: Cleanup work after irq
  306. * @config: Device configuration info
  307. * @flush_on_fsync: Flush on Frame sync
  308. * @desc_pendingcount: Descriptor pending count
  309. * @ext_addr: Indicates 64 bit addressing is supported by dma channel
  310. * @desc_submitcount: Descriptor h/w submitted count
  311. * @residue: Residue for AXI DMA
  312. * @seg_v: Statically allocated segments base
  313. * @seg_p: Physical allocated segments base
  314. * @cyclic_seg_v: Statically allocated segment base for cyclic transfers
  315. * @cyclic_seg_p: Physical allocated segments base for cyclic dma
  316. * @start_transfer: Differentiate b/w DMA IP's transfer
  317. * @stop_transfer: Differentiate b/w DMA IP's quiesce
  318. * @tdest: TDEST value for mcdma
  319. * @has_vflip: S2MM vertical flip
  320. */
  321. struct xilinx_dma_chan {
  322. struct xilinx_dma_device *xdev;
  323. u32 ctrl_offset;
  324. u32 desc_offset;
  325. spinlock_t lock;
  326. struct list_head pending_list;
  327. struct list_head active_list;
  328. struct list_head done_list;
  329. struct list_head free_seg_list;
  330. struct dma_chan common;
  331. struct dma_pool *desc_pool;
  332. struct device *dev;
  333. int irq;
  334. int id;
  335. enum dma_transfer_direction direction;
  336. int num_frms;
  337. bool has_sg;
  338. bool cyclic;
  339. bool genlock;
  340. bool err;
  341. bool idle;
  342. struct tasklet_struct tasklet;
  343. struct xilinx_vdma_config config;
  344. bool flush_on_fsync;
  345. u32 desc_pendingcount;
  346. bool ext_addr;
  347. u32 desc_submitcount;
  348. u32 residue;
  349. struct xilinx_axidma_tx_segment *seg_v;
  350. dma_addr_t seg_p;
  351. struct xilinx_axidma_tx_segment *cyclic_seg_v;
  352. dma_addr_t cyclic_seg_p;
  353. void (*start_transfer)(struct xilinx_dma_chan *chan);
  354. int (*stop_transfer)(struct xilinx_dma_chan *chan);
  355. u16 tdest;
  356. bool has_vflip;
  357. };
  358. /**
  359. * enum xdma_ip_type - DMA IP type.
  360. *
  361. * @XDMA_TYPE_AXIDMA: Axi dma ip.
  362. * @XDMA_TYPE_CDMA: Axi cdma ip.
  363. * @XDMA_TYPE_VDMA: Axi vdma ip.
  364. *
  365. */
  366. enum xdma_ip_type {
  367. XDMA_TYPE_AXIDMA = 0,
  368. XDMA_TYPE_CDMA,
  369. XDMA_TYPE_VDMA,
  370. };
  371. struct xilinx_dma_config {
  372. enum xdma_ip_type dmatype;
  373. int (*clk_init)(struct platform_device *pdev, struct clk **axi_clk,
  374. struct clk **tx_clk, struct clk **txs_clk,
  375. struct clk **rx_clk, struct clk **rxs_clk);
  376. };
  377. /**
  378. * struct xilinx_dma_device - DMA device structure
  379. * @regs: I/O mapped base address
  380. * @dev: Device Structure
  381. * @common: DMA device structure
  382. * @chan: Driver specific DMA channel
  383. * @has_sg: Specifies whether Scatter-Gather is present or not
  384. * @mcdma: Specifies whether Multi-Channel is present or not
  385. * @flush_on_fsync: Flush on frame sync
  386. * @ext_addr: Indicates 64 bit addressing is supported by dma device
  387. * @pdev: Platform device structure pointer
  388. * @dma_config: DMA config structure
  389. * @axi_clk: DMA Axi4-lite interace clock
  390. * @tx_clk: DMA mm2s clock
  391. * @txs_clk: DMA mm2s stream clock
  392. * @rx_clk: DMA s2mm clock
  393. * @rxs_clk: DMA s2mm stream clock
  394. * @nr_channels: Number of channels DMA device supports
  395. * @chan_id: DMA channel identifier
  396. */
  397. struct xilinx_dma_device {
  398. void __iomem *regs;
  399. struct device *dev;
  400. struct dma_device common;
  401. struct xilinx_dma_chan *chan[XILINX_DMA_MAX_CHANS_PER_DEVICE];
  402. bool has_sg;
  403. bool mcdma;
  404. u32 flush_on_fsync;
  405. bool ext_addr;
  406. struct platform_device *pdev;
  407. const struct xilinx_dma_config *dma_config;
  408. struct clk *axi_clk;
  409. struct clk *tx_clk;
  410. struct clk *txs_clk;
  411. struct clk *rx_clk;
  412. struct clk *rxs_clk;
  413. u32 nr_channels;
  414. u32 chan_id;
  415. };
  416. /* Macros */
  417. #define to_xilinx_chan(chan) \
  418. container_of(chan, struct xilinx_dma_chan, common)
  419. #define to_dma_tx_descriptor(tx) \
  420. container_of(tx, struct xilinx_dma_tx_descriptor, async_tx)
  421. #define xilinx_dma_poll_timeout(chan, reg, val, cond, delay_us, timeout_us) \
  422. readl_poll_timeout(chan->xdev->regs + chan->ctrl_offset + reg, val, \
  423. cond, delay_us, timeout_us)
  424. /* IO accessors */
  425. static inline u32 dma_read(struct xilinx_dma_chan *chan, u32 reg)
  426. {
  427. return ioread32(chan->xdev->regs + reg);
  428. }
  429. static inline void dma_write(struct xilinx_dma_chan *chan, u32 reg, u32 value)
  430. {
  431. iowrite32(value, chan->xdev->regs + reg);
  432. }
  433. static inline void vdma_desc_write(struct xilinx_dma_chan *chan, u32 reg,
  434. u32 value)
  435. {
  436. dma_write(chan, chan->desc_offset + reg, value);
  437. }
  438. static inline u32 dma_ctrl_read(struct xilinx_dma_chan *chan, u32 reg)
  439. {
  440. return dma_read(chan, chan->ctrl_offset + reg);
  441. }
  442. static inline void dma_ctrl_write(struct xilinx_dma_chan *chan, u32 reg,
  443. u32 value)
  444. {
  445. dma_write(chan, chan->ctrl_offset + reg, value);
  446. }
  447. static inline void dma_ctrl_clr(struct xilinx_dma_chan *chan, u32 reg,
  448. u32 clr)
  449. {
  450. dma_ctrl_write(chan, reg, dma_ctrl_read(chan, reg) & ~clr);
  451. }
  452. static inline void dma_ctrl_set(struct xilinx_dma_chan *chan, u32 reg,
  453. u32 set)
  454. {
  455. dma_ctrl_write(chan, reg, dma_ctrl_read(chan, reg) | set);
  456. }
  457. /**
  458. * vdma_desc_write_64 - 64-bit descriptor write
  459. * @chan: Driver specific VDMA channel
  460. * @reg: Register to write
  461. * @value_lsb: lower address of the descriptor.
  462. * @value_msb: upper address of the descriptor.
  463. *
  464. * Since vdma driver is trying to write to a register offset which is not a
  465. * multiple of 64 bits(ex : 0x5c), we are writing as two separate 32 bits
  466. * instead of a single 64 bit register write.
  467. */
  468. static inline void vdma_desc_write_64(struct xilinx_dma_chan *chan, u32 reg,
  469. u32 value_lsb, u32 value_msb)
  470. {
  471. /* Write the lsb 32 bits*/
  472. writel(value_lsb, chan->xdev->regs + chan->desc_offset + reg);
  473. /* Write the msb 32 bits */
  474. writel(value_msb, chan->xdev->regs + chan->desc_offset + reg + 4);
  475. }
  476. static inline void dma_writeq(struct xilinx_dma_chan *chan, u32 reg, u64 value)
  477. {
  478. lo_hi_writeq(value, chan->xdev->regs + chan->ctrl_offset + reg);
  479. }
  480. static inline void xilinx_write(struct xilinx_dma_chan *chan, u32 reg,
  481. dma_addr_t addr)
  482. {
  483. if (chan->ext_addr)
  484. dma_writeq(chan, reg, addr);
  485. else
  486. dma_ctrl_write(chan, reg, addr);
  487. }
  488. static inline void xilinx_axidma_buf(struct xilinx_dma_chan *chan,
  489. struct xilinx_axidma_desc_hw *hw,
  490. dma_addr_t buf_addr, size_t sg_used,
  491. size_t period_len)
  492. {
  493. if (chan->ext_addr) {
  494. hw->buf_addr = lower_32_bits(buf_addr + sg_used + period_len);
  495. hw->buf_addr_msb = upper_32_bits(buf_addr + sg_used +
  496. period_len);
  497. } else {
  498. hw->buf_addr = buf_addr + sg_used + period_len;
  499. }
  500. }
  501. /* -----------------------------------------------------------------------------
  502. * Descriptors and segments alloc and free
  503. */
  504. /**
  505. * xilinx_vdma_alloc_tx_segment - Allocate transaction segment
  506. * @chan: Driver specific DMA channel
  507. *
  508. * Return: The allocated segment on success and NULL on failure.
  509. */
  510. static struct xilinx_vdma_tx_segment *
  511. xilinx_vdma_alloc_tx_segment(struct xilinx_dma_chan *chan)
  512. {
  513. struct xilinx_vdma_tx_segment *segment;
  514. dma_addr_t phys;
  515. segment = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &phys);
  516. if (!segment)
  517. return NULL;
  518. segment->phys = phys;
  519. return segment;
  520. }
  521. /**
  522. * xilinx_cdma_alloc_tx_segment - Allocate transaction segment
  523. * @chan: Driver specific DMA channel
  524. *
  525. * Return: The allocated segment on success and NULL on failure.
  526. */
  527. static struct xilinx_cdma_tx_segment *
  528. xilinx_cdma_alloc_tx_segment(struct xilinx_dma_chan *chan)
  529. {
  530. struct xilinx_cdma_tx_segment *segment;
  531. dma_addr_t phys;
  532. segment = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &phys);
  533. if (!segment)
  534. return NULL;
  535. segment->phys = phys;
  536. return segment;
  537. }
  538. /**
  539. * xilinx_axidma_alloc_tx_segment - Allocate transaction segment
  540. * @chan: Driver specific DMA channel
  541. *
  542. * Return: The allocated segment on success and NULL on failure.
  543. */
  544. static struct xilinx_axidma_tx_segment *
  545. xilinx_axidma_alloc_tx_segment(struct xilinx_dma_chan *chan)
  546. {
  547. struct xilinx_axidma_tx_segment *segment = NULL;
  548. unsigned long flags;
  549. spin_lock_irqsave(&chan->lock, flags);
  550. if (!list_empty(&chan->free_seg_list)) {
  551. segment = list_first_entry(&chan->free_seg_list,
  552. struct xilinx_axidma_tx_segment,
  553. node);
  554. list_del(&segment->node);
  555. }
  556. spin_unlock_irqrestore(&chan->lock, flags);
  557. return segment;
  558. }
  559. static void xilinx_dma_clean_hw_desc(struct xilinx_axidma_desc_hw *hw)
  560. {
  561. u32 next_desc = hw->next_desc;
  562. u32 next_desc_msb = hw->next_desc_msb;
  563. memset(hw, 0, sizeof(struct xilinx_axidma_desc_hw));
  564. hw->next_desc = next_desc;
  565. hw->next_desc_msb = next_desc_msb;
  566. }
  567. /**
  568. * xilinx_dma_free_tx_segment - Free transaction segment
  569. * @chan: Driver specific DMA channel
  570. * @segment: DMA transaction segment
  571. */
  572. static void xilinx_dma_free_tx_segment(struct xilinx_dma_chan *chan,
  573. struct xilinx_axidma_tx_segment *segment)
  574. {
  575. xilinx_dma_clean_hw_desc(&segment->hw);
  576. list_add_tail(&segment->node, &chan->free_seg_list);
  577. }
  578. /**
  579. * xilinx_cdma_free_tx_segment - Free transaction segment
  580. * @chan: Driver specific DMA channel
  581. * @segment: DMA transaction segment
  582. */
  583. static void xilinx_cdma_free_tx_segment(struct xilinx_dma_chan *chan,
  584. struct xilinx_cdma_tx_segment *segment)
  585. {
  586. dma_pool_free(chan->desc_pool, segment, segment->phys);
  587. }
  588. /**
  589. * xilinx_vdma_free_tx_segment - Free transaction segment
  590. * @chan: Driver specific DMA channel
  591. * @segment: DMA transaction segment
  592. */
  593. static void xilinx_vdma_free_tx_segment(struct xilinx_dma_chan *chan,
  594. struct xilinx_vdma_tx_segment *segment)
  595. {
  596. dma_pool_free(chan->desc_pool, segment, segment->phys);
  597. }
  598. /**
  599. * xilinx_dma_tx_descriptor - Allocate transaction descriptor
  600. * @chan: Driver specific DMA channel
  601. *
  602. * Return: The allocated descriptor on success and NULL on failure.
  603. */
  604. static struct xilinx_dma_tx_descriptor *
  605. xilinx_dma_alloc_tx_descriptor(struct xilinx_dma_chan *chan)
  606. {
  607. struct xilinx_dma_tx_descriptor *desc;
  608. desc = kzalloc(sizeof(*desc), GFP_KERNEL);
  609. if (!desc)
  610. return NULL;
  611. INIT_LIST_HEAD(&desc->segments);
  612. return desc;
  613. }
  614. /**
  615. * xilinx_dma_free_tx_descriptor - Free transaction descriptor
  616. * @chan: Driver specific DMA channel
  617. * @desc: DMA transaction descriptor
  618. */
  619. static void
  620. xilinx_dma_free_tx_descriptor(struct xilinx_dma_chan *chan,
  621. struct xilinx_dma_tx_descriptor *desc)
  622. {
  623. struct xilinx_vdma_tx_segment *segment, *next;
  624. struct xilinx_cdma_tx_segment *cdma_segment, *cdma_next;
  625. struct xilinx_axidma_tx_segment *axidma_segment, *axidma_next;
  626. if (!desc)
  627. return;
  628. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
  629. list_for_each_entry_safe(segment, next, &desc->segments, node) {
  630. list_del(&segment->node);
  631. xilinx_vdma_free_tx_segment(chan, segment);
  632. }
  633. } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
  634. list_for_each_entry_safe(cdma_segment, cdma_next,
  635. &desc->segments, node) {
  636. list_del(&cdma_segment->node);
  637. xilinx_cdma_free_tx_segment(chan, cdma_segment);
  638. }
  639. } else {
  640. list_for_each_entry_safe(axidma_segment, axidma_next,
  641. &desc->segments, node) {
  642. list_del(&axidma_segment->node);
  643. xilinx_dma_free_tx_segment(chan, axidma_segment);
  644. }
  645. }
  646. kfree(desc);
  647. }
  648. /* Required functions */
  649. /**
  650. * xilinx_dma_free_desc_list - Free descriptors list
  651. * @chan: Driver specific DMA channel
  652. * @list: List to parse and delete the descriptor
  653. */
  654. static void xilinx_dma_free_desc_list(struct xilinx_dma_chan *chan,
  655. struct list_head *list)
  656. {
  657. struct xilinx_dma_tx_descriptor *desc, *next;
  658. list_for_each_entry_safe(desc, next, list, node) {
  659. list_del(&desc->node);
  660. xilinx_dma_free_tx_descriptor(chan, desc);
  661. }
  662. }
  663. /**
  664. * xilinx_dma_free_descriptors - Free channel descriptors
  665. * @chan: Driver specific DMA channel
  666. */
  667. static void xilinx_dma_free_descriptors(struct xilinx_dma_chan *chan)
  668. {
  669. unsigned long flags;
  670. spin_lock_irqsave(&chan->lock, flags);
  671. xilinx_dma_free_desc_list(chan, &chan->pending_list);
  672. xilinx_dma_free_desc_list(chan, &chan->done_list);
  673. xilinx_dma_free_desc_list(chan, &chan->active_list);
  674. spin_unlock_irqrestore(&chan->lock, flags);
  675. }
  676. /**
  677. * xilinx_dma_free_chan_resources - Free channel resources
  678. * @dchan: DMA channel
  679. */
  680. static void xilinx_dma_free_chan_resources(struct dma_chan *dchan)
  681. {
  682. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  683. unsigned long flags;
  684. dev_dbg(chan->dev, "Free all channel resources.\n");
  685. xilinx_dma_free_descriptors(chan);
  686. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  687. spin_lock_irqsave(&chan->lock, flags);
  688. INIT_LIST_HEAD(&chan->free_seg_list);
  689. spin_unlock_irqrestore(&chan->lock, flags);
  690. /* Free memory that is allocated for BD */
  691. dma_free_coherent(chan->dev, sizeof(*chan->seg_v) *
  692. XILINX_DMA_NUM_DESCS, chan->seg_v,
  693. chan->seg_p);
  694. /* Free Memory that is allocated for cyclic DMA Mode */
  695. dma_free_coherent(chan->dev, sizeof(*chan->cyclic_seg_v),
  696. chan->cyclic_seg_v, chan->cyclic_seg_p);
  697. }
  698. if (chan->xdev->dma_config->dmatype != XDMA_TYPE_AXIDMA) {
  699. dma_pool_destroy(chan->desc_pool);
  700. chan->desc_pool = NULL;
  701. }
  702. }
  703. /**
  704. * xilinx_dma_chan_handle_cyclic - Cyclic dma callback
  705. * @chan: Driver specific dma channel
  706. * @desc: dma transaction descriptor
  707. * @flags: flags for spin lock
  708. */
  709. static void xilinx_dma_chan_handle_cyclic(struct xilinx_dma_chan *chan,
  710. struct xilinx_dma_tx_descriptor *desc,
  711. unsigned long *flags)
  712. {
  713. dma_async_tx_callback callback;
  714. void *callback_param;
  715. callback = desc->async_tx.callback;
  716. callback_param = desc->async_tx.callback_param;
  717. if (callback) {
  718. spin_unlock_irqrestore(&chan->lock, *flags);
  719. callback(callback_param);
  720. spin_lock_irqsave(&chan->lock, *flags);
  721. }
  722. }
  723. /**
  724. * xilinx_dma_chan_desc_cleanup - Clean channel descriptors
  725. * @chan: Driver specific DMA channel
  726. */
  727. static void xilinx_dma_chan_desc_cleanup(struct xilinx_dma_chan *chan)
  728. {
  729. struct xilinx_dma_tx_descriptor *desc, *next;
  730. unsigned long flags;
  731. spin_lock_irqsave(&chan->lock, flags);
  732. list_for_each_entry_safe(desc, next, &chan->done_list, node) {
  733. struct dmaengine_desc_callback cb;
  734. if (desc->cyclic) {
  735. xilinx_dma_chan_handle_cyclic(chan, desc, &flags);
  736. break;
  737. }
  738. /* Remove from the list of running transactions */
  739. list_del(&desc->node);
  740. /* Run the link descriptor callback function */
  741. dmaengine_desc_get_callback(&desc->async_tx, &cb);
  742. if (dmaengine_desc_callback_valid(&cb)) {
  743. spin_unlock_irqrestore(&chan->lock, flags);
  744. dmaengine_desc_callback_invoke(&cb, NULL);
  745. spin_lock_irqsave(&chan->lock, flags);
  746. }
  747. /* Run any dependencies, then free the descriptor */
  748. dma_run_dependencies(&desc->async_tx);
  749. xilinx_dma_free_tx_descriptor(chan, desc);
  750. }
  751. spin_unlock_irqrestore(&chan->lock, flags);
  752. }
  753. /**
  754. * xilinx_dma_do_tasklet - Schedule completion tasklet
  755. * @data: Pointer to the Xilinx DMA channel structure
  756. */
  757. static void xilinx_dma_do_tasklet(unsigned long data)
  758. {
  759. struct xilinx_dma_chan *chan = (struct xilinx_dma_chan *)data;
  760. xilinx_dma_chan_desc_cleanup(chan);
  761. }
  762. /**
  763. * xilinx_dma_alloc_chan_resources - Allocate channel resources
  764. * @dchan: DMA channel
  765. *
  766. * Return: '0' on success and failure value on error
  767. */
  768. static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)
  769. {
  770. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  771. int i;
  772. /* Has this channel already been allocated? */
  773. if (chan->desc_pool)
  774. return 0;
  775. /*
  776. * We need the descriptor to be aligned to 64bytes
  777. * for meeting Xilinx VDMA specification requirement.
  778. */
  779. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  780. /* Allocate the buffer descriptors. */
  781. chan->seg_v = dma_zalloc_coherent(chan->dev,
  782. sizeof(*chan->seg_v) *
  783. XILINX_DMA_NUM_DESCS,
  784. &chan->seg_p, GFP_KERNEL);
  785. if (!chan->seg_v) {
  786. dev_err(chan->dev,
  787. "unable to allocate channel %d descriptors\n",
  788. chan->id);
  789. return -ENOMEM;
  790. }
  791. for (i = 0; i < XILINX_DMA_NUM_DESCS; i++) {
  792. chan->seg_v[i].hw.next_desc =
  793. lower_32_bits(chan->seg_p + sizeof(*chan->seg_v) *
  794. ((i + 1) % XILINX_DMA_NUM_DESCS));
  795. chan->seg_v[i].hw.next_desc_msb =
  796. upper_32_bits(chan->seg_p + sizeof(*chan->seg_v) *
  797. ((i + 1) % XILINX_DMA_NUM_DESCS));
  798. chan->seg_v[i].phys = chan->seg_p +
  799. sizeof(*chan->seg_v) * i;
  800. list_add_tail(&chan->seg_v[i].node,
  801. &chan->free_seg_list);
  802. }
  803. } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
  804. chan->desc_pool = dma_pool_create("xilinx_cdma_desc_pool",
  805. chan->dev,
  806. sizeof(struct xilinx_cdma_tx_segment),
  807. __alignof__(struct xilinx_cdma_tx_segment),
  808. 0);
  809. } else {
  810. chan->desc_pool = dma_pool_create("xilinx_vdma_desc_pool",
  811. chan->dev,
  812. sizeof(struct xilinx_vdma_tx_segment),
  813. __alignof__(struct xilinx_vdma_tx_segment),
  814. 0);
  815. }
  816. if (!chan->desc_pool &&
  817. (chan->xdev->dma_config->dmatype != XDMA_TYPE_AXIDMA)) {
  818. dev_err(chan->dev,
  819. "unable to allocate channel %d descriptor pool\n",
  820. chan->id);
  821. return -ENOMEM;
  822. }
  823. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  824. /*
  825. * For cyclic DMA mode we need to program the tail Descriptor
  826. * register with a value which is not a part of the BD chain
  827. * so allocating a desc segment during channel allocation for
  828. * programming tail descriptor.
  829. */
  830. chan->cyclic_seg_v = dma_zalloc_coherent(chan->dev,
  831. sizeof(*chan->cyclic_seg_v),
  832. &chan->cyclic_seg_p, GFP_KERNEL);
  833. if (!chan->cyclic_seg_v) {
  834. dev_err(chan->dev,
  835. "unable to allocate desc segment for cyclic DMA\n");
  836. return -ENOMEM;
  837. }
  838. chan->cyclic_seg_v->phys = chan->cyclic_seg_p;
  839. }
  840. dma_cookie_init(dchan);
  841. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  842. /* For AXI DMA resetting once channel will reset the
  843. * other channel as well so enable the interrupts here.
  844. */
  845. dma_ctrl_set(chan, XILINX_DMA_REG_DMACR,
  846. XILINX_DMA_DMAXR_ALL_IRQ_MASK);
  847. }
  848. if ((chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) && chan->has_sg)
  849. dma_ctrl_set(chan, XILINX_DMA_REG_DMACR,
  850. XILINX_CDMA_CR_SGMODE);
  851. return 0;
  852. }
  853. /**
  854. * xilinx_dma_tx_status - Get DMA transaction status
  855. * @dchan: DMA channel
  856. * @cookie: Transaction identifier
  857. * @txstate: Transaction state
  858. *
  859. * Return: DMA transaction status
  860. */
  861. static enum dma_status xilinx_dma_tx_status(struct dma_chan *dchan,
  862. dma_cookie_t cookie,
  863. struct dma_tx_state *txstate)
  864. {
  865. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  866. struct xilinx_dma_tx_descriptor *desc;
  867. struct xilinx_axidma_tx_segment *segment;
  868. struct xilinx_axidma_desc_hw *hw;
  869. enum dma_status ret;
  870. unsigned long flags;
  871. u32 residue = 0;
  872. ret = dma_cookie_status(dchan, cookie, txstate);
  873. if (ret == DMA_COMPLETE || !txstate)
  874. return ret;
  875. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  876. spin_lock_irqsave(&chan->lock, flags);
  877. desc = list_last_entry(&chan->active_list,
  878. struct xilinx_dma_tx_descriptor, node);
  879. if (chan->has_sg) {
  880. list_for_each_entry(segment, &desc->segments, node) {
  881. hw = &segment->hw;
  882. residue += (hw->control - hw->status) &
  883. XILINX_DMA_MAX_TRANS_LEN;
  884. }
  885. }
  886. spin_unlock_irqrestore(&chan->lock, flags);
  887. chan->residue = residue;
  888. dma_set_residue(txstate, chan->residue);
  889. }
  890. return ret;
  891. }
  892. /**
  893. * xilinx_dma_stop_transfer - Halt DMA channel
  894. * @chan: Driver specific DMA channel
  895. *
  896. * Return: '0' on success and failure value on error
  897. */
  898. static int xilinx_dma_stop_transfer(struct xilinx_dma_chan *chan)
  899. {
  900. u32 val;
  901. dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR, XILINX_DMA_DMACR_RUNSTOP);
  902. /* Wait for the hardware to halt */
  903. return xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMASR, val,
  904. val & XILINX_DMA_DMASR_HALTED, 0,
  905. XILINX_DMA_LOOP_COUNT);
  906. }
  907. /**
  908. * xilinx_cdma_stop_transfer - Wait for the current transfer to complete
  909. * @chan: Driver specific DMA channel
  910. *
  911. * Return: '0' on success and failure value on error
  912. */
  913. static int xilinx_cdma_stop_transfer(struct xilinx_dma_chan *chan)
  914. {
  915. u32 val;
  916. return xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMASR, val,
  917. val & XILINX_DMA_DMASR_IDLE, 0,
  918. XILINX_DMA_LOOP_COUNT);
  919. }
  920. /**
  921. * xilinx_dma_start - Start DMA channel
  922. * @chan: Driver specific DMA channel
  923. */
  924. static void xilinx_dma_start(struct xilinx_dma_chan *chan)
  925. {
  926. int err;
  927. u32 val;
  928. dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, XILINX_DMA_DMACR_RUNSTOP);
  929. /* Wait for the hardware to start */
  930. err = xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMASR, val,
  931. !(val & XILINX_DMA_DMASR_HALTED), 0,
  932. XILINX_DMA_LOOP_COUNT);
  933. if (err) {
  934. dev_err(chan->dev, "Cannot start channel %p: %x\n",
  935. chan, dma_ctrl_read(chan, XILINX_DMA_REG_DMASR));
  936. chan->err = true;
  937. }
  938. }
  939. /**
  940. * xilinx_vdma_start_transfer - Starts VDMA transfer
  941. * @chan: Driver specific channel struct pointer
  942. */
  943. static void xilinx_vdma_start_transfer(struct xilinx_dma_chan *chan)
  944. {
  945. struct xilinx_vdma_config *config = &chan->config;
  946. struct xilinx_dma_tx_descriptor *desc, *tail_desc;
  947. u32 reg, j;
  948. struct xilinx_vdma_tx_segment *tail_segment;
  949. /* This function was invoked with lock held */
  950. if (chan->err)
  951. return;
  952. if (!chan->idle)
  953. return;
  954. if (list_empty(&chan->pending_list))
  955. return;
  956. desc = list_first_entry(&chan->pending_list,
  957. struct xilinx_dma_tx_descriptor, node);
  958. tail_desc = list_last_entry(&chan->pending_list,
  959. struct xilinx_dma_tx_descriptor, node);
  960. tail_segment = list_last_entry(&tail_desc->segments,
  961. struct xilinx_vdma_tx_segment, node);
  962. /*
  963. * If hardware is idle, then all descriptors on the running lists are
  964. * done, start new transfers
  965. */
  966. if (chan->has_sg)
  967. dma_ctrl_write(chan, XILINX_DMA_REG_CURDESC,
  968. desc->async_tx.phys);
  969. /* Configure the hardware using info in the config structure */
  970. if (chan->has_vflip) {
  971. reg = dma_read(chan, XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP);
  972. reg &= ~XILINX_VDMA_ENABLE_VERTICAL_FLIP;
  973. reg |= config->vflip_en;
  974. dma_write(chan, XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP,
  975. reg);
  976. }
  977. reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR);
  978. if (config->frm_cnt_en)
  979. reg |= XILINX_DMA_DMACR_FRAMECNT_EN;
  980. else
  981. reg &= ~XILINX_DMA_DMACR_FRAMECNT_EN;
  982. /*
  983. * With SG, start with circular mode, so that BDs can be fetched.
  984. * In direct register mode, if not parking, enable circular mode
  985. */
  986. if (chan->has_sg || !config->park)
  987. reg |= XILINX_DMA_DMACR_CIRC_EN;
  988. if (config->park)
  989. reg &= ~XILINX_DMA_DMACR_CIRC_EN;
  990. dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg);
  991. j = chan->desc_submitcount;
  992. reg = dma_read(chan, XILINX_DMA_REG_PARK_PTR);
  993. if (chan->direction == DMA_MEM_TO_DEV) {
  994. reg &= ~XILINX_DMA_PARK_PTR_RD_REF_MASK;
  995. reg |= j << XILINX_DMA_PARK_PTR_RD_REF_SHIFT;
  996. } else {
  997. reg &= ~XILINX_DMA_PARK_PTR_WR_REF_MASK;
  998. reg |= j << XILINX_DMA_PARK_PTR_WR_REF_SHIFT;
  999. }
  1000. dma_write(chan, XILINX_DMA_REG_PARK_PTR, reg);
  1001. /* Start the hardware */
  1002. xilinx_dma_start(chan);
  1003. if (chan->err)
  1004. return;
  1005. /* Start the transfer */
  1006. if (chan->has_sg) {
  1007. dma_ctrl_write(chan, XILINX_DMA_REG_TAILDESC,
  1008. tail_segment->phys);
  1009. list_splice_tail_init(&chan->pending_list, &chan->active_list);
  1010. chan->desc_pendingcount = 0;
  1011. } else {
  1012. struct xilinx_vdma_tx_segment *segment, *last = NULL;
  1013. int i = 0;
  1014. if (chan->desc_submitcount < chan->num_frms)
  1015. i = chan->desc_submitcount;
  1016. list_for_each_entry(segment, &desc->segments, node) {
  1017. if (chan->ext_addr)
  1018. vdma_desc_write_64(chan,
  1019. XILINX_VDMA_REG_START_ADDRESS_64(i++),
  1020. segment->hw.buf_addr,
  1021. segment->hw.buf_addr_msb);
  1022. else
  1023. vdma_desc_write(chan,
  1024. XILINX_VDMA_REG_START_ADDRESS(i++),
  1025. segment->hw.buf_addr);
  1026. last = segment;
  1027. }
  1028. if (!last)
  1029. return;
  1030. /* HW expects these parameters to be same for one transaction */
  1031. vdma_desc_write(chan, XILINX_DMA_REG_HSIZE, last->hw.hsize);
  1032. vdma_desc_write(chan, XILINX_DMA_REG_FRMDLY_STRIDE,
  1033. last->hw.stride);
  1034. vdma_desc_write(chan, XILINX_DMA_REG_VSIZE, last->hw.vsize);
  1035. chan->desc_submitcount++;
  1036. chan->desc_pendingcount--;
  1037. list_del(&desc->node);
  1038. list_add_tail(&desc->node, &chan->active_list);
  1039. if (chan->desc_submitcount == chan->num_frms)
  1040. chan->desc_submitcount = 0;
  1041. }
  1042. chan->idle = false;
  1043. }
  1044. /**
  1045. * xilinx_cdma_start_transfer - Starts cdma transfer
  1046. * @chan: Driver specific channel struct pointer
  1047. */
  1048. static void xilinx_cdma_start_transfer(struct xilinx_dma_chan *chan)
  1049. {
  1050. struct xilinx_dma_tx_descriptor *head_desc, *tail_desc;
  1051. struct xilinx_cdma_tx_segment *tail_segment;
  1052. u32 ctrl_reg = dma_read(chan, XILINX_DMA_REG_DMACR);
  1053. if (chan->err)
  1054. return;
  1055. if (!chan->idle)
  1056. return;
  1057. if (list_empty(&chan->pending_list))
  1058. return;
  1059. head_desc = list_first_entry(&chan->pending_list,
  1060. struct xilinx_dma_tx_descriptor, node);
  1061. tail_desc = list_last_entry(&chan->pending_list,
  1062. struct xilinx_dma_tx_descriptor, node);
  1063. tail_segment = list_last_entry(&tail_desc->segments,
  1064. struct xilinx_cdma_tx_segment, node);
  1065. if (chan->desc_pendingcount <= XILINX_DMA_COALESCE_MAX) {
  1066. ctrl_reg &= ~XILINX_DMA_CR_COALESCE_MAX;
  1067. ctrl_reg |= chan->desc_pendingcount <<
  1068. XILINX_DMA_CR_COALESCE_SHIFT;
  1069. dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, ctrl_reg);
  1070. }
  1071. if (chan->has_sg) {
  1072. dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR,
  1073. XILINX_CDMA_CR_SGMODE);
  1074. dma_ctrl_set(chan, XILINX_DMA_REG_DMACR,
  1075. XILINX_CDMA_CR_SGMODE);
  1076. xilinx_write(chan, XILINX_DMA_REG_CURDESC,
  1077. head_desc->async_tx.phys);
  1078. /* Update tail ptr register which will start the transfer */
  1079. xilinx_write(chan, XILINX_DMA_REG_TAILDESC,
  1080. tail_segment->phys);
  1081. } else {
  1082. /* In simple mode */
  1083. struct xilinx_cdma_tx_segment *segment;
  1084. struct xilinx_cdma_desc_hw *hw;
  1085. segment = list_first_entry(&head_desc->segments,
  1086. struct xilinx_cdma_tx_segment,
  1087. node);
  1088. hw = &segment->hw;
  1089. xilinx_write(chan, XILINX_CDMA_REG_SRCADDR, hw->src_addr);
  1090. xilinx_write(chan, XILINX_CDMA_REG_DSTADDR, hw->dest_addr);
  1091. /* Start the transfer */
  1092. dma_ctrl_write(chan, XILINX_DMA_REG_BTT,
  1093. hw->control & XILINX_DMA_MAX_TRANS_LEN);
  1094. }
  1095. list_splice_tail_init(&chan->pending_list, &chan->active_list);
  1096. chan->desc_pendingcount = 0;
  1097. chan->idle = false;
  1098. }
  1099. /**
  1100. * xilinx_dma_start_transfer - Starts DMA transfer
  1101. * @chan: Driver specific channel struct pointer
  1102. */
  1103. static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)
  1104. {
  1105. struct xilinx_dma_tx_descriptor *head_desc, *tail_desc;
  1106. struct xilinx_axidma_tx_segment *tail_segment;
  1107. u32 reg;
  1108. if (chan->err)
  1109. return;
  1110. if (list_empty(&chan->pending_list))
  1111. return;
  1112. if (!chan->idle)
  1113. return;
  1114. head_desc = list_first_entry(&chan->pending_list,
  1115. struct xilinx_dma_tx_descriptor, node);
  1116. tail_desc = list_last_entry(&chan->pending_list,
  1117. struct xilinx_dma_tx_descriptor, node);
  1118. tail_segment = list_last_entry(&tail_desc->segments,
  1119. struct xilinx_axidma_tx_segment, node);
  1120. reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR);
  1121. if (chan->desc_pendingcount <= XILINX_DMA_COALESCE_MAX) {
  1122. reg &= ~XILINX_DMA_CR_COALESCE_MAX;
  1123. reg |= chan->desc_pendingcount <<
  1124. XILINX_DMA_CR_COALESCE_SHIFT;
  1125. dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg);
  1126. }
  1127. if (chan->has_sg && !chan->xdev->mcdma)
  1128. xilinx_write(chan, XILINX_DMA_REG_CURDESC,
  1129. head_desc->async_tx.phys);
  1130. if (chan->has_sg && chan->xdev->mcdma) {
  1131. if (chan->direction == DMA_MEM_TO_DEV) {
  1132. dma_ctrl_write(chan, XILINX_DMA_REG_CURDESC,
  1133. head_desc->async_tx.phys);
  1134. } else {
  1135. if (!chan->tdest) {
  1136. dma_ctrl_write(chan, XILINX_DMA_REG_CURDESC,
  1137. head_desc->async_tx.phys);
  1138. } else {
  1139. dma_ctrl_write(chan,
  1140. XILINX_DMA_MCRX_CDESC(chan->tdest),
  1141. head_desc->async_tx.phys);
  1142. }
  1143. }
  1144. }
  1145. xilinx_dma_start(chan);
  1146. if (chan->err)
  1147. return;
  1148. /* Start the transfer */
  1149. if (chan->has_sg && !chan->xdev->mcdma) {
  1150. if (chan->cyclic)
  1151. xilinx_write(chan, XILINX_DMA_REG_TAILDESC,
  1152. chan->cyclic_seg_v->phys);
  1153. else
  1154. xilinx_write(chan, XILINX_DMA_REG_TAILDESC,
  1155. tail_segment->phys);
  1156. } else if (chan->has_sg && chan->xdev->mcdma) {
  1157. if (chan->direction == DMA_MEM_TO_DEV) {
  1158. dma_ctrl_write(chan, XILINX_DMA_REG_TAILDESC,
  1159. tail_segment->phys);
  1160. } else {
  1161. if (!chan->tdest) {
  1162. dma_ctrl_write(chan, XILINX_DMA_REG_TAILDESC,
  1163. tail_segment->phys);
  1164. } else {
  1165. dma_ctrl_write(chan,
  1166. XILINX_DMA_MCRX_TDESC(chan->tdest),
  1167. tail_segment->phys);
  1168. }
  1169. }
  1170. } else {
  1171. struct xilinx_axidma_tx_segment *segment;
  1172. struct xilinx_axidma_desc_hw *hw;
  1173. segment = list_first_entry(&head_desc->segments,
  1174. struct xilinx_axidma_tx_segment,
  1175. node);
  1176. hw = &segment->hw;
  1177. xilinx_write(chan, XILINX_DMA_REG_SRCDSTADDR, hw->buf_addr);
  1178. /* Start the transfer */
  1179. dma_ctrl_write(chan, XILINX_DMA_REG_BTT,
  1180. hw->control & XILINX_DMA_MAX_TRANS_LEN);
  1181. }
  1182. list_splice_tail_init(&chan->pending_list, &chan->active_list);
  1183. chan->desc_pendingcount = 0;
  1184. chan->idle = false;
  1185. }
  1186. /**
  1187. * xilinx_dma_issue_pending - Issue pending transactions
  1188. * @dchan: DMA channel
  1189. */
  1190. static void xilinx_dma_issue_pending(struct dma_chan *dchan)
  1191. {
  1192. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1193. unsigned long flags;
  1194. spin_lock_irqsave(&chan->lock, flags);
  1195. chan->start_transfer(chan);
  1196. spin_unlock_irqrestore(&chan->lock, flags);
  1197. }
  1198. /**
  1199. * xilinx_dma_complete_descriptor - Mark the active descriptor as complete
  1200. * @chan : xilinx DMA channel
  1201. *
  1202. * CONTEXT: hardirq
  1203. */
  1204. static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan)
  1205. {
  1206. struct xilinx_dma_tx_descriptor *desc, *next;
  1207. /* This function was invoked with lock held */
  1208. if (list_empty(&chan->active_list))
  1209. return;
  1210. list_for_each_entry_safe(desc, next, &chan->active_list, node) {
  1211. list_del(&desc->node);
  1212. if (!desc->cyclic)
  1213. dma_cookie_complete(&desc->async_tx);
  1214. list_add_tail(&desc->node, &chan->done_list);
  1215. }
  1216. }
  1217. /**
  1218. * xilinx_dma_reset - Reset DMA channel
  1219. * @chan: Driver specific DMA channel
  1220. *
  1221. * Return: '0' on success and failure value on error
  1222. */
  1223. static int xilinx_dma_reset(struct xilinx_dma_chan *chan)
  1224. {
  1225. int err;
  1226. u32 tmp;
  1227. dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, XILINX_DMA_DMACR_RESET);
  1228. /* Wait for the hardware to finish reset */
  1229. err = xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMACR, tmp,
  1230. !(tmp & XILINX_DMA_DMACR_RESET), 0,
  1231. XILINX_DMA_LOOP_COUNT);
  1232. if (err) {
  1233. dev_err(chan->dev, "reset timeout, cr %x, sr %x\n",
  1234. dma_ctrl_read(chan, XILINX_DMA_REG_DMACR),
  1235. dma_ctrl_read(chan, XILINX_DMA_REG_DMASR));
  1236. return -ETIMEDOUT;
  1237. }
  1238. chan->err = false;
  1239. chan->idle = true;
  1240. chan->desc_pendingcount = 0;
  1241. chan->desc_submitcount = 0;
  1242. return err;
  1243. }
  1244. /**
  1245. * xilinx_dma_chan_reset - Reset DMA channel and enable interrupts
  1246. * @chan: Driver specific DMA channel
  1247. *
  1248. * Return: '0' on success and failure value on error
  1249. */
  1250. static int xilinx_dma_chan_reset(struct xilinx_dma_chan *chan)
  1251. {
  1252. int err;
  1253. /* Reset VDMA */
  1254. err = xilinx_dma_reset(chan);
  1255. if (err)
  1256. return err;
  1257. /* Enable interrupts */
  1258. dma_ctrl_set(chan, XILINX_DMA_REG_DMACR,
  1259. XILINX_DMA_DMAXR_ALL_IRQ_MASK);
  1260. return 0;
  1261. }
  1262. /**
  1263. * xilinx_dma_irq_handler - DMA Interrupt handler
  1264. * @irq: IRQ number
  1265. * @data: Pointer to the Xilinx DMA channel structure
  1266. *
  1267. * Return: IRQ_HANDLED/IRQ_NONE
  1268. */
  1269. static irqreturn_t xilinx_dma_irq_handler(int irq, void *data)
  1270. {
  1271. struct xilinx_dma_chan *chan = data;
  1272. u32 status;
  1273. /* Read the status and ack the interrupts. */
  1274. status = dma_ctrl_read(chan, XILINX_DMA_REG_DMASR);
  1275. if (!(status & XILINX_DMA_DMAXR_ALL_IRQ_MASK))
  1276. return IRQ_NONE;
  1277. dma_ctrl_write(chan, XILINX_DMA_REG_DMASR,
  1278. status & XILINX_DMA_DMAXR_ALL_IRQ_MASK);
  1279. if (status & XILINX_DMA_DMASR_ERR_IRQ) {
  1280. /*
  1281. * An error occurred. If C_FLUSH_ON_FSYNC is enabled and the
  1282. * error is recoverable, ignore it. Otherwise flag the error.
  1283. *
  1284. * Only recoverable errors can be cleared in the DMASR register,
  1285. * make sure not to write to other error bits to 1.
  1286. */
  1287. u32 errors = status & XILINX_DMA_DMASR_ALL_ERR_MASK;
  1288. dma_ctrl_write(chan, XILINX_DMA_REG_DMASR,
  1289. errors & XILINX_DMA_DMASR_ERR_RECOVER_MASK);
  1290. if (!chan->flush_on_fsync ||
  1291. (errors & ~XILINX_DMA_DMASR_ERR_RECOVER_MASK)) {
  1292. dev_err(chan->dev,
  1293. "Channel %p has errors %x, cdr %x tdr %x\n",
  1294. chan, errors,
  1295. dma_ctrl_read(chan, XILINX_DMA_REG_CURDESC),
  1296. dma_ctrl_read(chan, XILINX_DMA_REG_TAILDESC));
  1297. chan->err = true;
  1298. }
  1299. }
  1300. if (status & XILINX_DMA_DMASR_DLY_CNT_IRQ) {
  1301. /*
  1302. * Device takes too long to do the transfer when user requires
  1303. * responsiveness.
  1304. */
  1305. dev_dbg(chan->dev, "Inter-packet latency too long\n");
  1306. }
  1307. if (status & XILINX_DMA_DMASR_FRM_CNT_IRQ) {
  1308. spin_lock(&chan->lock);
  1309. xilinx_dma_complete_descriptor(chan);
  1310. chan->idle = true;
  1311. chan->start_transfer(chan);
  1312. spin_unlock(&chan->lock);
  1313. }
  1314. tasklet_schedule(&chan->tasklet);
  1315. return IRQ_HANDLED;
  1316. }
  1317. /**
  1318. * append_desc_queue - Queuing descriptor
  1319. * @chan: Driver specific dma channel
  1320. * @desc: dma transaction descriptor
  1321. */
  1322. static void append_desc_queue(struct xilinx_dma_chan *chan,
  1323. struct xilinx_dma_tx_descriptor *desc)
  1324. {
  1325. struct xilinx_vdma_tx_segment *tail_segment;
  1326. struct xilinx_dma_tx_descriptor *tail_desc;
  1327. struct xilinx_axidma_tx_segment *axidma_tail_segment;
  1328. struct xilinx_cdma_tx_segment *cdma_tail_segment;
  1329. if (list_empty(&chan->pending_list))
  1330. goto append;
  1331. /*
  1332. * Add the hardware descriptor to the chain of hardware descriptors
  1333. * that already exists in memory.
  1334. */
  1335. tail_desc = list_last_entry(&chan->pending_list,
  1336. struct xilinx_dma_tx_descriptor, node);
  1337. if (chan->xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
  1338. tail_segment = list_last_entry(&tail_desc->segments,
  1339. struct xilinx_vdma_tx_segment,
  1340. node);
  1341. tail_segment->hw.next_desc = (u32)desc->async_tx.phys;
  1342. } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
  1343. cdma_tail_segment = list_last_entry(&tail_desc->segments,
  1344. struct xilinx_cdma_tx_segment,
  1345. node);
  1346. cdma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys;
  1347. } else {
  1348. axidma_tail_segment = list_last_entry(&tail_desc->segments,
  1349. struct xilinx_axidma_tx_segment,
  1350. node);
  1351. axidma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys;
  1352. }
  1353. /*
  1354. * Add the software descriptor and all children to the list
  1355. * of pending transactions
  1356. */
  1357. append:
  1358. list_add_tail(&desc->node, &chan->pending_list);
  1359. chan->desc_pendingcount++;
  1360. if (chan->has_sg && (chan->xdev->dma_config->dmatype == XDMA_TYPE_VDMA)
  1361. && unlikely(chan->desc_pendingcount > chan->num_frms)) {
  1362. dev_dbg(chan->dev, "desc pendingcount is too high\n");
  1363. chan->desc_pendingcount = chan->num_frms;
  1364. }
  1365. }
  1366. /**
  1367. * xilinx_dma_tx_submit - Submit DMA transaction
  1368. * @tx: Async transaction descriptor
  1369. *
  1370. * Return: cookie value on success and failure value on error
  1371. */
  1372. static dma_cookie_t xilinx_dma_tx_submit(struct dma_async_tx_descriptor *tx)
  1373. {
  1374. struct xilinx_dma_tx_descriptor *desc = to_dma_tx_descriptor(tx);
  1375. struct xilinx_dma_chan *chan = to_xilinx_chan(tx->chan);
  1376. dma_cookie_t cookie;
  1377. unsigned long flags;
  1378. int err;
  1379. if (chan->cyclic) {
  1380. xilinx_dma_free_tx_descriptor(chan, desc);
  1381. return -EBUSY;
  1382. }
  1383. if (chan->err) {
  1384. /*
  1385. * If reset fails, need to hard reset the system.
  1386. * Channel is no longer functional
  1387. */
  1388. err = xilinx_dma_chan_reset(chan);
  1389. if (err < 0)
  1390. return err;
  1391. }
  1392. spin_lock_irqsave(&chan->lock, flags);
  1393. cookie = dma_cookie_assign(tx);
  1394. /* Put this transaction onto the tail of the pending queue */
  1395. append_desc_queue(chan, desc);
  1396. if (desc->cyclic)
  1397. chan->cyclic = true;
  1398. spin_unlock_irqrestore(&chan->lock, flags);
  1399. return cookie;
  1400. }
  1401. /**
  1402. * xilinx_vdma_dma_prep_interleaved - prepare a descriptor for a
  1403. * DMA_SLAVE transaction
  1404. * @dchan: DMA channel
  1405. * @xt: Interleaved template pointer
  1406. * @flags: transfer ack flags
  1407. *
  1408. * Return: Async transaction descriptor on success and NULL on failure
  1409. */
  1410. static struct dma_async_tx_descriptor *
  1411. xilinx_vdma_dma_prep_interleaved(struct dma_chan *dchan,
  1412. struct dma_interleaved_template *xt,
  1413. unsigned long flags)
  1414. {
  1415. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1416. struct xilinx_dma_tx_descriptor *desc;
  1417. struct xilinx_vdma_tx_segment *segment;
  1418. struct xilinx_vdma_desc_hw *hw;
  1419. if (!is_slave_direction(xt->dir))
  1420. return NULL;
  1421. if (!xt->numf || !xt->sgl[0].size)
  1422. return NULL;
  1423. if (xt->frame_size != 1)
  1424. return NULL;
  1425. /* Allocate a transaction descriptor. */
  1426. desc = xilinx_dma_alloc_tx_descriptor(chan);
  1427. if (!desc)
  1428. return NULL;
  1429. dma_async_tx_descriptor_init(&desc->async_tx, &chan->common);
  1430. desc->async_tx.tx_submit = xilinx_dma_tx_submit;
  1431. async_tx_ack(&desc->async_tx);
  1432. /* Allocate the link descriptor from DMA pool */
  1433. segment = xilinx_vdma_alloc_tx_segment(chan);
  1434. if (!segment)
  1435. goto error;
  1436. /* Fill in the hardware descriptor */
  1437. hw = &segment->hw;
  1438. hw->vsize = xt->numf;
  1439. hw->hsize = xt->sgl[0].size;
  1440. hw->stride = (xt->sgl[0].icg + xt->sgl[0].size) <<
  1441. XILINX_DMA_FRMDLY_STRIDE_STRIDE_SHIFT;
  1442. hw->stride |= chan->config.frm_dly <<
  1443. XILINX_DMA_FRMDLY_STRIDE_FRMDLY_SHIFT;
  1444. if (xt->dir != DMA_MEM_TO_DEV) {
  1445. if (chan->ext_addr) {
  1446. hw->buf_addr = lower_32_bits(xt->dst_start);
  1447. hw->buf_addr_msb = upper_32_bits(xt->dst_start);
  1448. } else {
  1449. hw->buf_addr = xt->dst_start;
  1450. }
  1451. } else {
  1452. if (chan->ext_addr) {
  1453. hw->buf_addr = lower_32_bits(xt->src_start);
  1454. hw->buf_addr_msb = upper_32_bits(xt->src_start);
  1455. } else {
  1456. hw->buf_addr = xt->src_start;
  1457. }
  1458. }
  1459. /* Insert the segment into the descriptor segments list. */
  1460. list_add_tail(&segment->node, &desc->segments);
  1461. /* Link the last hardware descriptor with the first. */
  1462. segment = list_first_entry(&desc->segments,
  1463. struct xilinx_vdma_tx_segment, node);
  1464. desc->async_tx.phys = segment->phys;
  1465. return &desc->async_tx;
  1466. error:
  1467. xilinx_dma_free_tx_descriptor(chan, desc);
  1468. return NULL;
  1469. }
  1470. /**
  1471. * xilinx_cdma_prep_memcpy - prepare descriptors for a memcpy transaction
  1472. * @dchan: DMA channel
  1473. * @dma_dst: destination address
  1474. * @dma_src: source address
  1475. * @len: transfer length
  1476. * @flags: transfer ack flags
  1477. *
  1478. * Return: Async transaction descriptor on success and NULL on failure
  1479. */
  1480. static struct dma_async_tx_descriptor *
  1481. xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst,
  1482. dma_addr_t dma_src, size_t len, unsigned long flags)
  1483. {
  1484. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1485. struct xilinx_dma_tx_descriptor *desc;
  1486. struct xilinx_cdma_tx_segment *segment;
  1487. struct xilinx_cdma_desc_hw *hw;
  1488. if (!len || len > XILINX_DMA_MAX_TRANS_LEN)
  1489. return NULL;
  1490. desc = xilinx_dma_alloc_tx_descriptor(chan);
  1491. if (!desc)
  1492. return NULL;
  1493. dma_async_tx_descriptor_init(&desc->async_tx, &chan->common);
  1494. desc->async_tx.tx_submit = xilinx_dma_tx_submit;
  1495. /* Allocate the link descriptor from DMA pool */
  1496. segment = xilinx_cdma_alloc_tx_segment(chan);
  1497. if (!segment)
  1498. goto error;
  1499. hw = &segment->hw;
  1500. hw->control = len;
  1501. hw->src_addr = dma_src;
  1502. hw->dest_addr = dma_dst;
  1503. if (chan->ext_addr) {
  1504. hw->src_addr_msb = upper_32_bits(dma_src);
  1505. hw->dest_addr_msb = upper_32_bits(dma_dst);
  1506. }
  1507. /* Insert the segment into the descriptor segments list. */
  1508. list_add_tail(&segment->node, &desc->segments);
  1509. desc->async_tx.phys = segment->phys;
  1510. hw->next_desc = segment->phys;
  1511. return &desc->async_tx;
  1512. error:
  1513. xilinx_dma_free_tx_descriptor(chan, desc);
  1514. return NULL;
  1515. }
  1516. /**
  1517. * xilinx_dma_prep_slave_sg - prepare descriptors for a DMA_SLAVE transaction
  1518. * @dchan: DMA channel
  1519. * @sgl: scatterlist to transfer to/from
  1520. * @sg_len: number of entries in @scatterlist
  1521. * @direction: DMA direction
  1522. * @flags: transfer ack flags
  1523. * @context: APP words of the descriptor
  1524. *
  1525. * Return: Async transaction descriptor on success and NULL on failure
  1526. */
  1527. static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg(
  1528. struct dma_chan *dchan, struct scatterlist *sgl, unsigned int sg_len,
  1529. enum dma_transfer_direction direction, unsigned long flags,
  1530. void *context)
  1531. {
  1532. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1533. struct xilinx_dma_tx_descriptor *desc;
  1534. struct xilinx_axidma_tx_segment *segment = NULL;
  1535. u32 *app_w = (u32 *)context;
  1536. struct scatterlist *sg;
  1537. size_t copy;
  1538. size_t sg_used;
  1539. unsigned int i;
  1540. if (!is_slave_direction(direction))
  1541. return NULL;
  1542. /* Allocate a transaction descriptor. */
  1543. desc = xilinx_dma_alloc_tx_descriptor(chan);
  1544. if (!desc)
  1545. return NULL;
  1546. dma_async_tx_descriptor_init(&desc->async_tx, &chan->common);
  1547. desc->async_tx.tx_submit = xilinx_dma_tx_submit;
  1548. /* Build transactions using information in the scatter gather list */
  1549. for_each_sg(sgl, sg, sg_len, i) {
  1550. sg_used = 0;
  1551. /* Loop until the entire scatterlist entry is used */
  1552. while (sg_used < sg_dma_len(sg)) {
  1553. struct xilinx_axidma_desc_hw *hw;
  1554. /* Get a free segment */
  1555. segment = xilinx_axidma_alloc_tx_segment(chan);
  1556. if (!segment)
  1557. goto error;
  1558. /*
  1559. * Calculate the maximum number of bytes to transfer,
  1560. * making sure it is less than the hw limit
  1561. */
  1562. copy = min_t(size_t, sg_dma_len(sg) - sg_used,
  1563. XILINX_DMA_MAX_TRANS_LEN);
  1564. hw = &segment->hw;
  1565. /* Fill in the descriptor */
  1566. xilinx_axidma_buf(chan, hw, sg_dma_address(sg),
  1567. sg_used, 0);
  1568. hw->control = copy;
  1569. if (chan->direction == DMA_MEM_TO_DEV) {
  1570. if (app_w)
  1571. memcpy(hw->app, app_w, sizeof(u32) *
  1572. XILINX_DMA_NUM_APP_WORDS);
  1573. }
  1574. sg_used += copy;
  1575. /*
  1576. * Insert the segment into the descriptor segments
  1577. * list.
  1578. */
  1579. list_add_tail(&segment->node, &desc->segments);
  1580. }
  1581. }
  1582. segment = list_first_entry(&desc->segments,
  1583. struct xilinx_axidma_tx_segment, node);
  1584. desc->async_tx.phys = segment->phys;
  1585. /* For the last DMA_MEM_TO_DEV transfer, set EOP */
  1586. if (chan->direction == DMA_MEM_TO_DEV) {
  1587. segment->hw.control |= XILINX_DMA_BD_SOP;
  1588. segment = list_last_entry(&desc->segments,
  1589. struct xilinx_axidma_tx_segment,
  1590. node);
  1591. segment->hw.control |= XILINX_DMA_BD_EOP;
  1592. }
  1593. return &desc->async_tx;
  1594. error:
  1595. xilinx_dma_free_tx_descriptor(chan, desc);
  1596. return NULL;
  1597. }
  1598. /**
  1599. * xilinx_dma_prep_dma_cyclic - prepare descriptors for a DMA_SLAVE transaction
  1600. * @dchan: DMA channel
  1601. * @buf_addr: Physical address of the buffer
  1602. * @buf_len: Total length of the cyclic buffers
  1603. * @period_len: length of individual cyclic buffer
  1604. * @direction: DMA direction
  1605. * @flags: transfer ack flags
  1606. *
  1607. * Return: Async transaction descriptor on success and NULL on failure
  1608. */
  1609. static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic(
  1610. struct dma_chan *dchan, dma_addr_t buf_addr, size_t buf_len,
  1611. size_t period_len, enum dma_transfer_direction direction,
  1612. unsigned long flags)
  1613. {
  1614. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1615. struct xilinx_dma_tx_descriptor *desc;
  1616. struct xilinx_axidma_tx_segment *segment, *head_segment, *prev = NULL;
  1617. size_t copy, sg_used;
  1618. unsigned int num_periods;
  1619. int i;
  1620. u32 reg;
  1621. if (!period_len)
  1622. return NULL;
  1623. num_periods = buf_len / period_len;
  1624. if (!num_periods)
  1625. return NULL;
  1626. if (!is_slave_direction(direction))
  1627. return NULL;
  1628. /* Allocate a transaction descriptor. */
  1629. desc = xilinx_dma_alloc_tx_descriptor(chan);
  1630. if (!desc)
  1631. return NULL;
  1632. chan->direction = direction;
  1633. dma_async_tx_descriptor_init(&desc->async_tx, &chan->common);
  1634. desc->async_tx.tx_submit = xilinx_dma_tx_submit;
  1635. for (i = 0; i < num_periods; ++i) {
  1636. sg_used = 0;
  1637. while (sg_used < period_len) {
  1638. struct xilinx_axidma_desc_hw *hw;
  1639. /* Get a free segment */
  1640. segment = xilinx_axidma_alloc_tx_segment(chan);
  1641. if (!segment)
  1642. goto error;
  1643. /*
  1644. * Calculate the maximum number of bytes to transfer,
  1645. * making sure it is less than the hw limit
  1646. */
  1647. copy = min_t(size_t, period_len - sg_used,
  1648. XILINX_DMA_MAX_TRANS_LEN);
  1649. hw = &segment->hw;
  1650. xilinx_axidma_buf(chan, hw, buf_addr, sg_used,
  1651. period_len * i);
  1652. hw->control = copy;
  1653. if (prev)
  1654. prev->hw.next_desc = segment->phys;
  1655. prev = segment;
  1656. sg_used += copy;
  1657. /*
  1658. * Insert the segment into the descriptor segments
  1659. * list.
  1660. */
  1661. list_add_tail(&segment->node, &desc->segments);
  1662. }
  1663. }
  1664. head_segment = list_first_entry(&desc->segments,
  1665. struct xilinx_axidma_tx_segment, node);
  1666. desc->async_tx.phys = head_segment->phys;
  1667. desc->cyclic = true;
  1668. reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR);
  1669. reg |= XILINX_DMA_CR_CYCLIC_BD_EN_MASK;
  1670. dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg);
  1671. segment = list_last_entry(&desc->segments,
  1672. struct xilinx_axidma_tx_segment,
  1673. node);
  1674. segment->hw.next_desc = (u32) head_segment->phys;
  1675. /* For the last DMA_MEM_TO_DEV transfer, set EOP */
  1676. if (direction == DMA_MEM_TO_DEV) {
  1677. head_segment->hw.control |= XILINX_DMA_BD_SOP;
  1678. segment->hw.control |= XILINX_DMA_BD_EOP;
  1679. }
  1680. return &desc->async_tx;
  1681. error:
  1682. xilinx_dma_free_tx_descriptor(chan, desc);
  1683. return NULL;
  1684. }
  1685. /**
  1686. * xilinx_dma_prep_interleaved - prepare a descriptor for a
  1687. * DMA_SLAVE transaction
  1688. * @dchan: DMA channel
  1689. * @xt: Interleaved template pointer
  1690. * @flags: transfer ack flags
  1691. *
  1692. * Return: Async transaction descriptor on success and NULL on failure
  1693. */
  1694. static struct dma_async_tx_descriptor *
  1695. xilinx_dma_prep_interleaved(struct dma_chan *dchan,
  1696. struct dma_interleaved_template *xt,
  1697. unsigned long flags)
  1698. {
  1699. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1700. struct xilinx_dma_tx_descriptor *desc;
  1701. struct xilinx_axidma_tx_segment *segment;
  1702. struct xilinx_axidma_desc_hw *hw;
  1703. if (!is_slave_direction(xt->dir))
  1704. return NULL;
  1705. if (!xt->numf || !xt->sgl[0].size)
  1706. return NULL;
  1707. if (xt->frame_size != 1)
  1708. return NULL;
  1709. /* Allocate a transaction descriptor. */
  1710. desc = xilinx_dma_alloc_tx_descriptor(chan);
  1711. if (!desc)
  1712. return NULL;
  1713. chan->direction = xt->dir;
  1714. dma_async_tx_descriptor_init(&desc->async_tx, &chan->common);
  1715. desc->async_tx.tx_submit = xilinx_dma_tx_submit;
  1716. /* Get a free segment */
  1717. segment = xilinx_axidma_alloc_tx_segment(chan);
  1718. if (!segment)
  1719. goto error;
  1720. hw = &segment->hw;
  1721. /* Fill in the descriptor */
  1722. if (xt->dir != DMA_MEM_TO_DEV)
  1723. hw->buf_addr = xt->dst_start;
  1724. else
  1725. hw->buf_addr = xt->src_start;
  1726. hw->mcdma_control = chan->tdest & XILINX_DMA_BD_TDEST_MASK;
  1727. hw->vsize_stride = (xt->numf << XILINX_DMA_BD_VSIZE_SHIFT) &
  1728. XILINX_DMA_BD_VSIZE_MASK;
  1729. hw->vsize_stride |= (xt->sgl[0].icg + xt->sgl[0].size) &
  1730. XILINX_DMA_BD_STRIDE_MASK;
  1731. hw->control = xt->sgl[0].size & XILINX_DMA_BD_HSIZE_MASK;
  1732. /*
  1733. * Insert the segment into the descriptor segments
  1734. * list.
  1735. */
  1736. list_add_tail(&segment->node, &desc->segments);
  1737. segment = list_first_entry(&desc->segments,
  1738. struct xilinx_axidma_tx_segment, node);
  1739. desc->async_tx.phys = segment->phys;
  1740. /* For the last DMA_MEM_TO_DEV transfer, set EOP */
  1741. if (xt->dir == DMA_MEM_TO_DEV) {
  1742. segment->hw.control |= XILINX_DMA_BD_SOP;
  1743. segment = list_last_entry(&desc->segments,
  1744. struct xilinx_axidma_tx_segment,
  1745. node);
  1746. segment->hw.control |= XILINX_DMA_BD_EOP;
  1747. }
  1748. return &desc->async_tx;
  1749. error:
  1750. xilinx_dma_free_tx_descriptor(chan, desc);
  1751. return NULL;
  1752. }
  1753. /**
  1754. * xilinx_dma_terminate_all - Halt the channel and free descriptors
  1755. * @dchan: Driver specific DMA Channel pointer
  1756. *
  1757. * Return: '0' always.
  1758. */
  1759. static int xilinx_dma_terminate_all(struct dma_chan *dchan)
  1760. {
  1761. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1762. u32 reg;
  1763. int err;
  1764. if (chan->cyclic)
  1765. xilinx_dma_chan_reset(chan);
  1766. err = chan->stop_transfer(chan);
  1767. if (err) {
  1768. dev_err(chan->dev, "Cannot stop channel %p: %x\n",
  1769. chan, dma_ctrl_read(chan, XILINX_DMA_REG_DMASR));
  1770. chan->err = true;
  1771. }
  1772. /* Remove and free all of the descriptors in the lists */
  1773. xilinx_dma_free_descriptors(chan);
  1774. chan->idle = true;
  1775. if (chan->cyclic) {
  1776. reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR);
  1777. reg &= ~XILINX_DMA_CR_CYCLIC_BD_EN_MASK;
  1778. dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg);
  1779. chan->cyclic = false;
  1780. }
  1781. if ((chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) && chan->has_sg)
  1782. dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR,
  1783. XILINX_CDMA_CR_SGMODE);
  1784. return 0;
  1785. }
  1786. /**
  1787. * xilinx_dma_channel_set_config - Configure VDMA channel
  1788. * Run-time configuration for Axi VDMA, supports:
  1789. * . halt the channel
  1790. * . configure interrupt coalescing and inter-packet delay threshold
  1791. * . start/stop parking
  1792. * . enable genlock
  1793. *
  1794. * @dchan: DMA channel
  1795. * @cfg: VDMA device configuration pointer
  1796. *
  1797. * Return: '0' on success and failure value on error
  1798. */
  1799. int xilinx_vdma_channel_set_config(struct dma_chan *dchan,
  1800. struct xilinx_vdma_config *cfg)
  1801. {
  1802. struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
  1803. u32 dmacr;
  1804. if (cfg->reset)
  1805. return xilinx_dma_chan_reset(chan);
  1806. dmacr = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR);
  1807. chan->config.frm_dly = cfg->frm_dly;
  1808. chan->config.park = cfg->park;
  1809. /* genlock settings */
  1810. chan->config.gen_lock = cfg->gen_lock;
  1811. chan->config.master = cfg->master;
  1812. dmacr &= ~XILINX_DMA_DMACR_GENLOCK_EN;
  1813. if (cfg->gen_lock && chan->genlock) {
  1814. dmacr |= XILINX_DMA_DMACR_GENLOCK_EN;
  1815. dmacr &= ~XILINX_DMA_DMACR_MASTER_MASK;
  1816. dmacr |= cfg->master << XILINX_DMA_DMACR_MASTER_SHIFT;
  1817. }
  1818. chan->config.frm_cnt_en = cfg->frm_cnt_en;
  1819. chan->config.vflip_en = cfg->vflip_en;
  1820. if (cfg->park)
  1821. chan->config.park_frm = cfg->park_frm;
  1822. else
  1823. chan->config.park_frm = -1;
  1824. chan->config.coalesc = cfg->coalesc;
  1825. chan->config.delay = cfg->delay;
  1826. if (cfg->coalesc <= XILINX_DMA_DMACR_FRAME_COUNT_MAX) {
  1827. dmacr &= ~XILINX_DMA_DMACR_FRAME_COUNT_MASK;
  1828. dmacr |= cfg->coalesc << XILINX_DMA_DMACR_FRAME_COUNT_SHIFT;
  1829. chan->config.coalesc = cfg->coalesc;
  1830. }
  1831. if (cfg->delay <= XILINX_DMA_DMACR_DELAY_MAX) {
  1832. dmacr &= ~XILINX_DMA_DMACR_DELAY_MASK;
  1833. dmacr |= cfg->delay << XILINX_DMA_DMACR_DELAY_SHIFT;
  1834. chan->config.delay = cfg->delay;
  1835. }
  1836. /* FSync Source selection */
  1837. dmacr &= ~XILINX_DMA_DMACR_FSYNCSRC_MASK;
  1838. dmacr |= cfg->ext_fsync << XILINX_DMA_DMACR_FSYNCSRC_SHIFT;
  1839. dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, dmacr);
  1840. return 0;
  1841. }
  1842. EXPORT_SYMBOL(xilinx_vdma_channel_set_config);
  1843. /* -----------------------------------------------------------------------------
  1844. * Probe and remove
  1845. */
  1846. /**
  1847. * xilinx_dma_chan_remove - Per Channel remove function
  1848. * @chan: Driver specific DMA channel
  1849. */
  1850. static void xilinx_dma_chan_remove(struct xilinx_dma_chan *chan)
  1851. {
  1852. /* Disable all interrupts */
  1853. dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR,
  1854. XILINX_DMA_DMAXR_ALL_IRQ_MASK);
  1855. if (chan->irq > 0)
  1856. free_irq(chan->irq, chan);
  1857. tasklet_kill(&chan->tasklet);
  1858. list_del(&chan->common.device_node);
  1859. }
  1860. static int axidma_clk_init(struct platform_device *pdev, struct clk **axi_clk,
  1861. struct clk **tx_clk, struct clk **rx_clk,
  1862. struct clk **sg_clk, struct clk **tmp_clk)
  1863. {
  1864. int err;
  1865. *tmp_clk = NULL;
  1866. *axi_clk = devm_clk_get(&pdev->dev, "s_axi_lite_aclk");
  1867. if (IS_ERR(*axi_clk)) {
  1868. err = PTR_ERR(*axi_clk);
  1869. dev_err(&pdev->dev, "failed to get axi_aclk (%d)\n", err);
  1870. return err;
  1871. }
  1872. *tx_clk = devm_clk_get(&pdev->dev, "m_axi_mm2s_aclk");
  1873. if (IS_ERR(*tx_clk))
  1874. *tx_clk = NULL;
  1875. *rx_clk = devm_clk_get(&pdev->dev, "m_axi_s2mm_aclk");
  1876. if (IS_ERR(*rx_clk))
  1877. *rx_clk = NULL;
  1878. *sg_clk = devm_clk_get(&pdev->dev, "m_axi_sg_aclk");
  1879. if (IS_ERR(*sg_clk))
  1880. *sg_clk = NULL;
  1881. err = clk_prepare_enable(*axi_clk);
  1882. if (err) {
  1883. dev_err(&pdev->dev, "failed to enable axi_clk (%d)\n", err);
  1884. return err;
  1885. }
  1886. err = clk_prepare_enable(*tx_clk);
  1887. if (err) {
  1888. dev_err(&pdev->dev, "failed to enable tx_clk (%d)\n", err);
  1889. goto err_disable_axiclk;
  1890. }
  1891. err = clk_prepare_enable(*rx_clk);
  1892. if (err) {
  1893. dev_err(&pdev->dev, "failed to enable rx_clk (%d)\n", err);
  1894. goto err_disable_txclk;
  1895. }
  1896. err = clk_prepare_enable(*sg_clk);
  1897. if (err) {
  1898. dev_err(&pdev->dev, "failed to enable sg_clk (%d)\n", err);
  1899. goto err_disable_rxclk;
  1900. }
  1901. return 0;
  1902. err_disable_rxclk:
  1903. clk_disable_unprepare(*rx_clk);
  1904. err_disable_txclk:
  1905. clk_disable_unprepare(*tx_clk);
  1906. err_disable_axiclk:
  1907. clk_disable_unprepare(*axi_clk);
  1908. return err;
  1909. }
  1910. static int axicdma_clk_init(struct platform_device *pdev, struct clk **axi_clk,
  1911. struct clk **dev_clk, struct clk **tmp_clk,
  1912. struct clk **tmp1_clk, struct clk **tmp2_clk)
  1913. {
  1914. int err;
  1915. *tmp_clk = NULL;
  1916. *tmp1_clk = NULL;
  1917. *tmp2_clk = NULL;
  1918. *axi_clk = devm_clk_get(&pdev->dev, "s_axi_lite_aclk");
  1919. if (IS_ERR(*axi_clk)) {
  1920. err = PTR_ERR(*axi_clk);
  1921. dev_err(&pdev->dev, "failed to get axi_clk (%d)\n", err);
  1922. return err;
  1923. }
  1924. *dev_clk = devm_clk_get(&pdev->dev, "m_axi_aclk");
  1925. if (IS_ERR(*dev_clk)) {
  1926. err = PTR_ERR(*dev_clk);
  1927. dev_err(&pdev->dev, "failed to get dev_clk (%d)\n", err);
  1928. return err;
  1929. }
  1930. err = clk_prepare_enable(*axi_clk);
  1931. if (err) {
  1932. dev_err(&pdev->dev, "failed to enable axi_clk (%d)\n", err);
  1933. return err;
  1934. }
  1935. err = clk_prepare_enable(*dev_clk);
  1936. if (err) {
  1937. dev_err(&pdev->dev, "failed to enable dev_clk (%d)\n", err);
  1938. goto err_disable_axiclk;
  1939. }
  1940. return 0;
  1941. err_disable_axiclk:
  1942. clk_disable_unprepare(*axi_clk);
  1943. return err;
  1944. }
  1945. static int axivdma_clk_init(struct platform_device *pdev, struct clk **axi_clk,
  1946. struct clk **tx_clk, struct clk **txs_clk,
  1947. struct clk **rx_clk, struct clk **rxs_clk)
  1948. {
  1949. int err;
  1950. *axi_clk = devm_clk_get(&pdev->dev, "s_axi_lite_aclk");
  1951. if (IS_ERR(*axi_clk)) {
  1952. err = PTR_ERR(*axi_clk);
  1953. dev_err(&pdev->dev, "failed to get axi_aclk (%d)\n", err);
  1954. return err;
  1955. }
  1956. *tx_clk = devm_clk_get(&pdev->dev, "m_axi_mm2s_aclk");
  1957. if (IS_ERR(*tx_clk))
  1958. *tx_clk = NULL;
  1959. *txs_clk = devm_clk_get(&pdev->dev, "m_axis_mm2s_aclk");
  1960. if (IS_ERR(*txs_clk))
  1961. *txs_clk = NULL;
  1962. *rx_clk = devm_clk_get(&pdev->dev, "m_axi_s2mm_aclk");
  1963. if (IS_ERR(*rx_clk))
  1964. *rx_clk = NULL;
  1965. *rxs_clk = devm_clk_get(&pdev->dev, "s_axis_s2mm_aclk");
  1966. if (IS_ERR(*rxs_clk))
  1967. *rxs_clk = NULL;
  1968. err = clk_prepare_enable(*axi_clk);
  1969. if (err) {
  1970. dev_err(&pdev->dev, "failed to enable axi_clk (%d)\n", err);
  1971. return err;
  1972. }
  1973. err = clk_prepare_enable(*tx_clk);
  1974. if (err) {
  1975. dev_err(&pdev->dev, "failed to enable tx_clk (%d)\n", err);
  1976. goto err_disable_axiclk;
  1977. }
  1978. err = clk_prepare_enable(*txs_clk);
  1979. if (err) {
  1980. dev_err(&pdev->dev, "failed to enable txs_clk (%d)\n", err);
  1981. goto err_disable_txclk;
  1982. }
  1983. err = clk_prepare_enable(*rx_clk);
  1984. if (err) {
  1985. dev_err(&pdev->dev, "failed to enable rx_clk (%d)\n", err);
  1986. goto err_disable_txsclk;
  1987. }
  1988. err = clk_prepare_enable(*rxs_clk);
  1989. if (err) {
  1990. dev_err(&pdev->dev, "failed to enable rxs_clk (%d)\n", err);
  1991. goto err_disable_rxclk;
  1992. }
  1993. return 0;
  1994. err_disable_rxclk:
  1995. clk_disable_unprepare(*rx_clk);
  1996. err_disable_txsclk:
  1997. clk_disable_unprepare(*txs_clk);
  1998. err_disable_txclk:
  1999. clk_disable_unprepare(*tx_clk);
  2000. err_disable_axiclk:
  2001. clk_disable_unprepare(*axi_clk);
  2002. return err;
  2003. }
  2004. static void xdma_disable_allclks(struct xilinx_dma_device *xdev)
  2005. {
  2006. clk_disable_unprepare(xdev->rxs_clk);
  2007. clk_disable_unprepare(xdev->rx_clk);
  2008. clk_disable_unprepare(xdev->txs_clk);
  2009. clk_disable_unprepare(xdev->tx_clk);
  2010. clk_disable_unprepare(xdev->axi_clk);
  2011. }
  2012. /**
  2013. * xilinx_dma_chan_probe - Per Channel Probing
  2014. * It get channel features from the device tree entry and
  2015. * initialize special channel handling routines
  2016. *
  2017. * @xdev: Driver specific device structure
  2018. * @node: Device node
  2019. * @chan_id: DMA Channel id
  2020. *
  2021. * Return: '0' on success and failure value on error
  2022. */
  2023. static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev,
  2024. struct device_node *node, int chan_id)
  2025. {
  2026. struct xilinx_dma_chan *chan;
  2027. bool has_dre = false;
  2028. u32 value, width;
  2029. int err;
  2030. /* Allocate and initialize the channel structure */
  2031. chan = devm_kzalloc(xdev->dev, sizeof(*chan), GFP_KERNEL);
  2032. if (!chan)
  2033. return -ENOMEM;
  2034. chan->dev = xdev->dev;
  2035. chan->xdev = xdev;
  2036. chan->has_sg = xdev->has_sg;
  2037. chan->desc_pendingcount = 0x0;
  2038. chan->ext_addr = xdev->ext_addr;
  2039. /* This variable ensures that descriptors are not
  2040. * Submitted when dma engine is in progress. This variable is
  2041. * Added to avoid polling for a bit in the status register to
  2042. * Know dma state in the driver hot path.
  2043. */
  2044. chan->idle = true;
  2045. spin_lock_init(&chan->lock);
  2046. INIT_LIST_HEAD(&chan->pending_list);
  2047. INIT_LIST_HEAD(&chan->done_list);
  2048. INIT_LIST_HEAD(&chan->active_list);
  2049. INIT_LIST_HEAD(&chan->free_seg_list);
  2050. /* Retrieve the channel properties from the device tree */
  2051. has_dre = of_property_read_bool(node, "xlnx,include-dre");
  2052. chan->genlock = of_property_read_bool(node, "xlnx,genlock-mode");
  2053. err = of_property_read_u32(node, "xlnx,datawidth", &value);
  2054. if (err) {
  2055. dev_err(xdev->dev, "missing xlnx,datawidth property\n");
  2056. return err;
  2057. }
  2058. width = value >> 3; /* Convert bits to bytes */
  2059. /* If data width is greater than 8 bytes, DRE is not in hw */
  2060. if (width > 8)
  2061. has_dre = false;
  2062. if (!has_dre)
  2063. xdev->common.copy_align = fls(width - 1);
  2064. if (of_device_is_compatible(node, "xlnx,axi-vdma-mm2s-channel") ||
  2065. of_device_is_compatible(node, "xlnx,axi-dma-mm2s-channel") ||
  2066. of_device_is_compatible(node, "xlnx,axi-cdma-channel")) {
  2067. chan->direction = DMA_MEM_TO_DEV;
  2068. chan->id = chan_id;
  2069. chan->tdest = chan_id;
  2070. chan->ctrl_offset = XILINX_DMA_MM2S_CTRL_OFFSET;
  2071. if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
  2072. chan->desc_offset = XILINX_VDMA_MM2S_DESC_OFFSET;
  2073. chan->config.park = 1;
  2074. if (xdev->flush_on_fsync == XILINX_DMA_FLUSH_BOTH ||
  2075. xdev->flush_on_fsync == XILINX_DMA_FLUSH_MM2S)
  2076. chan->flush_on_fsync = true;
  2077. }
  2078. } else if (of_device_is_compatible(node,
  2079. "xlnx,axi-vdma-s2mm-channel") ||
  2080. of_device_is_compatible(node,
  2081. "xlnx,axi-dma-s2mm-channel")) {
  2082. chan->direction = DMA_DEV_TO_MEM;
  2083. chan->id = chan_id;
  2084. chan->tdest = chan_id - xdev->nr_channels;
  2085. chan->has_vflip = of_property_read_bool(node,
  2086. "xlnx,enable-vert-flip");
  2087. if (chan->has_vflip) {
  2088. chan->config.vflip_en = dma_read(chan,
  2089. XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP) &
  2090. XILINX_VDMA_ENABLE_VERTICAL_FLIP;
  2091. }
  2092. chan->ctrl_offset = XILINX_DMA_S2MM_CTRL_OFFSET;
  2093. if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
  2094. chan->desc_offset = XILINX_VDMA_S2MM_DESC_OFFSET;
  2095. chan->config.park = 1;
  2096. if (xdev->flush_on_fsync == XILINX_DMA_FLUSH_BOTH ||
  2097. xdev->flush_on_fsync == XILINX_DMA_FLUSH_S2MM)
  2098. chan->flush_on_fsync = true;
  2099. }
  2100. } else {
  2101. dev_err(xdev->dev, "Invalid channel compatible node\n");
  2102. return -EINVAL;
  2103. }
  2104. /* Request the interrupt */
  2105. chan->irq = irq_of_parse_and_map(node, 0);
  2106. err = request_irq(chan->irq, xilinx_dma_irq_handler, IRQF_SHARED,
  2107. "xilinx-dma-controller", chan);
  2108. if (err) {
  2109. dev_err(xdev->dev, "unable to request IRQ %d\n", chan->irq);
  2110. return err;
  2111. }
  2112. if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  2113. chan->start_transfer = xilinx_dma_start_transfer;
  2114. chan->stop_transfer = xilinx_dma_stop_transfer;
  2115. } else if (xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
  2116. chan->start_transfer = xilinx_cdma_start_transfer;
  2117. chan->stop_transfer = xilinx_cdma_stop_transfer;
  2118. } else {
  2119. chan->start_transfer = xilinx_vdma_start_transfer;
  2120. chan->stop_transfer = xilinx_dma_stop_transfer;
  2121. }
  2122. /* Initialize the tasklet */
  2123. tasklet_init(&chan->tasklet, xilinx_dma_do_tasklet,
  2124. (unsigned long)chan);
  2125. /*
  2126. * Initialize the DMA channel and add it to the DMA engine channels
  2127. * list.
  2128. */
  2129. chan->common.device = &xdev->common;
  2130. list_add_tail(&chan->common.device_node, &xdev->common.channels);
  2131. xdev->chan[chan->id] = chan;
  2132. /* Reset the channel */
  2133. err = xilinx_dma_chan_reset(chan);
  2134. if (err < 0) {
  2135. dev_err(xdev->dev, "Reset channel failed\n");
  2136. return err;
  2137. }
  2138. return 0;
  2139. }
  2140. /**
  2141. * xilinx_dma_child_probe - Per child node probe
  2142. * It get number of dma-channels per child node from
  2143. * device-tree and initializes all the channels.
  2144. *
  2145. * @xdev: Driver specific device structure
  2146. * @node: Device node
  2147. *
  2148. * Return: 0 always.
  2149. */
  2150. static int xilinx_dma_child_probe(struct xilinx_dma_device *xdev,
  2151. struct device_node *node)
  2152. {
  2153. int ret, i, nr_channels = 1;
  2154. ret = of_property_read_u32(node, "dma-channels", &nr_channels);
  2155. if ((ret < 0) && xdev->mcdma)
  2156. dev_warn(xdev->dev, "missing dma-channels property\n");
  2157. for (i = 0; i < nr_channels; i++)
  2158. xilinx_dma_chan_probe(xdev, node, xdev->chan_id++);
  2159. xdev->nr_channels += nr_channels;
  2160. return 0;
  2161. }
  2162. /**
  2163. * of_dma_xilinx_xlate - Translation function
  2164. * @dma_spec: Pointer to DMA specifier as found in the device tree
  2165. * @ofdma: Pointer to DMA controller data
  2166. *
  2167. * Return: DMA channel pointer on success and NULL on error
  2168. */
  2169. static struct dma_chan *of_dma_xilinx_xlate(struct of_phandle_args *dma_spec,
  2170. struct of_dma *ofdma)
  2171. {
  2172. struct xilinx_dma_device *xdev = ofdma->of_dma_data;
  2173. int chan_id = dma_spec->args[0];
  2174. if (chan_id >= xdev->nr_channels || !xdev->chan[chan_id])
  2175. return NULL;
  2176. return dma_get_slave_channel(&xdev->chan[chan_id]->common);
  2177. }
  2178. static const struct xilinx_dma_config axidma_config = {
  2179. .dmatype = XDMA_TYPE_AXIDMA,
  2180. .clk_init = axidma_clk_init,
  2181. };
  2182. static const struct xilinx_dma_config axicdma_config = {
  2183. .dmatype = XDMA_TYPE_CDMA,
  2184. .clk_init = axicdma_clk_init,
  2185. };
  2186. static const struct xilinx_dma_config axivdma_config = {
  2187. .dmatype = XDMA_TYPE_VDMA,
  2188. .clk_init = axivdma_clk_init,
  2189. };
  2190. static const struct of_device_id xilinx_dma_of_ids[] = {
  2191. { .compatible = "xlnx,axi-dma-1.00.a", .data = &axidma_config },
  2192. { .compatible = "xlnx,axi-cdma-1.00.a", .data = &axicdma_config },
  2193. { .compatible = "xlnx,axi-vdma-1.00.a", .data = &axivdma_config },
  2194. {}
  2195. };
  2196. MODULE_DEVICE_TABLE(of, xilinx_dma_of_ids);
  2197. /**
  2198. * xilinx_dma_probe - Driver probe function
  2199. * @pdev: Pointer to the platform_device structure
  2200. *
  2201. * Return: '0' on success and failure value on error
  2202. */
  2203. static int xilinx_dma_probe(struct platform_device *pdev)
  2204. {
  2205. int (*clk_init)(struct platform_device *, struct clk **, struct clk **,
  2206. struct clk **, struct clk **, struct clk **)
  2207. = axivdma_clk_init;
  2208. struct device_node *node = pdev->dev.of_node;
  2209. struct xilinx_dma_device *xdev;
  2210. struct device_node *child, *np = pdev->dev.of_node;
  2211. struct resource *io;
  2212. u32 num_frames, addr_width;
  2213. int i, err;
  2214. /* Allocate and initialize the DMA engine structure */
  2215. xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL);
  2216. if (!xdev)
  2217. return -ENOMEM;
  2218. xdev->dev = &pdev->dev;
  2219. if (np) {
  2220. const struct of_device_id *match;
  2221. match = of_match_node(xilinx_dma_of_ids, np);
  2222. if (match && match->data) {
  2223. xdev->dma_config = match->data;
  2224. clk_init = xdev->dma_config->clk_init;
  2225. }
  2226. }
  2227. err = clk_init(pdev, &xdev->axi_clk, &xdev->tx_clk, &xdev->txs_clk,
  2228. &xdev->rx_clk, &xdev->rxs_clk);
  2229. if (err)
  2230. return err;
  2231. /* Request and map I/O memory */
  2232. io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2233. xdev->regs = devm_ioremap_resource(&pdev->dev, io);
  2234. if (IS_ERR(xdev->regs))
  2235. return PTR_ERR(xdev->regs);
  2236. /* Retrieve the DMA engine properties from the device tree */
  2237. xdev->has_sg = of_property_read_bool(node, "xlnx,include-sg");
  2238. if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA)
  2239. xdev->mcdma = of_property_read_bool(node, "xlnx,mcdma");
  2240. if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
  2241. err = of_property_read_u32(node, "xlnx,num-fstores",
  2242. &num_frames);
  2243. if (err < 0) {
  2244. dev_err(xdev->dev,
  2245. "missing xlnx,num-fstores property\n");
  2246. return err;
  2247. }
  2248. err = of_property_read_u32(node, "xlnx,flush-fsync",
  2249. &xdev->flush_on_fsync);
  2250. if (err < 0)
  2251. dev_warn(xdev->dev,
  2252. "missing xlnx,flush-fsync property\n");
  2253. }
  2254. err = of_property_read_u32(node, "xlnx,addrwidth", &addr_width);
  2255. if (err < 0)
  2256. dev_warn(xdev->dev, "missing xlnx,addrwidth property\n");
  2257. if (addr_width > 32)
  2258. xdev->ext_addr = true;
  2259. else
  2260. xdev->ext_addr = false;
  2261. /* Set the dma mask bits */
  2262. dma_set_mask(xdev->dev, DMA_BIT_MASK(addr_width));
  2263. /* Initialize the DMA engine */
  2264. xdev->common.dev = &pdev->dev;
  2265. INIT_LIST_HEAD(&xdev->common.channels);
  2266. if (!(xdev->dma_config->dmatype == XDMA_TYPE_CDMA)) {
  2267. dma_cap_set(DMA_SLAVE, xdev->common.cap_mask);
  2268. dma_cap_set(DMA_PRIVATE, xdev->common.cap_mask);
  2269. }
  2270. xdev->common.device_alloc_chan_resources =
  2271. xilinx_dma_alloc_chan_resources;
  2272. xdev->common.device_free_chan_resources =
  2273. xilinx_dma_free_chan_resources;
  2274. xdev->common.device_terminate_all = xilinx_dma_terminate_all;
  2275. xdev->common.device_tx_status = xilinx_dma_tx_status;
  2276. xdev->common.device_issue_pending = xilinx_dma_issue_pending;
  2277. if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
  2278. dma_cap_set(DMA_CYCLIC, xdev->common.cap_mask);
  2279. xdev->common.device_prep_slave_sg = xilinx_dma_prep_slave_sg;
  2280. xdev->common.device_prep_dma_cyclic =
  2281. xilinx_dma_prep_dma_cyclic;
  2282. xdev->common.device_prep_interleaved_dma =
  2283. xilinx_dma_prep_interleaved;
  2284. /* Residue calculation is supported by only AXI DMA */
  2285. xdev->common.residue_granularity =
  2286. DMA_RESIDUE_GRANULARITY_SEGMENT;
  2287. } else if (xdev->dma_config->dmatype == XDMA_TYPE_CDMA) {
  2288. dma_cap_set(DMA_MEMCPY, xdev->common.cap_mask);
  2289. xdev->common.device_prep_dma_memcpy = xilinx_cdma_prep_memcpy;
  2290. } else {
  2291. xdev->common.device_prep_interleaved_dma =
  2292. xilinx_vdma_dma_prep_interleaved;
  2293. }
  2294. platform_set_drvdata(pdev, xdev);
  2295. /* Initialize the channels */
  2296. for_each_child_of_node(node, child) {
  2297. err = xilinx_dma_child_probe(xdev, child);
  2298. if (err < 0)
  2299. goto disable_clks;
  2300. }
  2301. if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
  2302. for (i = 0; i < xdev->nr_channels; i++)
  2303. if (xdev->chan[i])
  2304. xdev->chan[i]->num_frms = num_frames;
  2305. }
  2306. /* Register the DMA engine with the core */
  2307. dma_async_device_register(&xdev->common);
  2308. err = of_dma_controller_register(node, of_dma_xilinx_xlate,
  2309. xdev);
  2310. if (err < 0) {
  2311. dev_err(&pdev->dev, "Unable to register DMA to DT\n");
  2312. dma_async_device_unregister(&xdev->common);
  2313. goto error;
  2314. }
  2315. if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA)
  2316. dev_info(&pdev->dev, "Xilinx AXI DMA Engine Driver Probed!!\n");
  2317. else if (xdev->dma_config->dmatype == XDMA_TYPE_CDMA)
  2318. dev_info(&pdev->dev, "Xilinx AXI CDMA Engine Driver Probed!!\n");
  2319. else
  2320. dev_info(&pdev->dev, "Xilinx AXI VDMA Engine Driver Probed!!\n");
  2321. return 0;
  2322. disable_clks:
  2323. xdma_disable_allclks(xdev);
  2324. error:
  2325. for (i = 0; i < xdev->nr_channels; i++)
  2326. if (xdev->chan[i])
  2327. xilinx_dma_chan_remove(xdev->chan[i]);
  2328. return err;
  2329. }
  2330. /**
  2331. * xilinx_dma_remove - Driver remove function
  2332. * @pdev: Pointer to the platform_device structure
  2333. *
  2334. * Return: Always '0'
  2335. */
  2336. static int xilinx_dma_remove(struct platform_device *pdev)
  2337. {
  2338. struct xilinx_dma_device *xdev = platform_get_drvdata(pdev);
  2339. int i;
  2340. of_dma_controller_free(pdev->dev.of_node);
  2341. dma_async_device_unregister(&xdev->common);
  2342. for (i = 0; i < xdev->nr_channels; i++)
  2343. if (xdev->chan[i])
  2344. xilinx_dma_chan_remove(xdev->chan[i]);
  2345. xdma_disable_allclks(xdev);
  2346. return 0;
  2347. }
  2348. static struct platform_driver xilinx_vdma_driver = {
  2349. .driver = {
  2350. .name = "xilinx-vdma",
  2351. .of_match_table = xilinx_dma_of_ids,
  2352. },
  2353. .probe = xilinx_dma_probe,
  2354. .remove = xilinx_dma_remove,
  2355. };
  2356. module_platform_driver(xilinx_vdma_driver);
  2357. MODULE_AUTHOR("Xilinx, Inc.");
  2358. MODULE_DESCRIPTION("Xilinx VDMA driver");
  2359. MODULE_LICENSE("GPL v2");