tegra20-apb-dma.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * DMA driver for Nvidia's Tegra20 APB DMA controller.
  4. *
  5. * Copyright (c) 2012-2013, NVIDIA CORPORATION. All rights reserved.
  6. */
  7. #include <linux/bitops.h>
  8. #include <linux/clk.h>
  9. #include <linux/delay.h>
  10. #include <linux/dmaengine.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/err.h>
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/io.h>
  16. #include <linux/mm.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_dma.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/pm.h>
  22. #include <linux/pm_runtime.h>
  23. #include <linux/reset.h>
  24. #include <linux/slab.h>
  25. #include <linux/wait.h>
  26. #include "dmaengine.h"
  27. #define CREATE_TRACE_POINTS
  28. #include <trace/events/tegra_apb_dma.h>
  29. #define TEGRA_APBDMA_GENERAL 0x0
  30. #define TEGRA_APBDMA_GENERAL_ENABLE BIT(31)
  31. #define TEGRA_APBDMA_CONTROL 0x010
  32. #define TEGRA_APBDMA_IRQ_MASK 0x01c
  33. #define TEGRA_APBDMA_IRQ_MASK_SET 0x020
  34. /* CSR register */
  35. #define TEGRA_APBDMA_CHAN_CSR 0x00
  36. #define TEGRA_APBDMA_CSR_ENB BIT(31)
  37. #define TEGRA_APBDMA_CSR_IE_EOC BIT(30)
  38. #define TEGRA_APBDMA_CSR_HOLD BIT(29)
  39. #define TEGRA_APBDMA_CSR_DIR BIT(28)
  40. #define TEGRA_APBDMA_CSR_ONCE BIT(27)
  41. #define TEGRA_APBDMA_CSR_FLOW BIT(21)
  42. #define TEGRA_APBDMA_CSR_REQ_SEL_SHIFT 16
  43. #define TEGRA_APBDMA_CSR_REQ_SEL_MASK 0x1F
  44. #define TEGRA_APBDMA_CSR_WCOUNT_MASK 0xFFFC
  45. /* STATUS register */
  46. #define TEGRA_APBDMA_CHAN_STATUS 0x004
  47. #define TEGRA_APBDMA_STATUS_BUSY BIT(31)
  48. #define TEGRA_APBDMA_STATUS_ISE_EOC BIT(30)
  49. #define TEGRA_APBDMA_STATUS_HALT BIT(29)
  50. #define TEGRA_APBDMA_STATUS_PING_PONG BIT(28)
  51. #define TEGRA_APBDMA_STATUS_COUNT_SHIFT 2
  52. #define TEGRA_APBDMA_STATUS_COUNT_MASK 0xFFFC
  53. #define TEGRA_APBDMA_CHAN_CSRE 0x00C
  54. #define TEGRA_APBDMA_CHAN_CSRE_PAUSE BIT(31)
  55. /* AHB memory address */
  56. #define TEGRA_APBDMA_CHAN_AHBPTR 0x010
  57. /* AHB sequence register */
  58. #define TEGRA_APBDMA_CHAN_AHBSEQ 0x14
  59. #define TEGRA_APBDMA_AHBSEQ_INTR_ENB BIT(31)
  60. #define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_8 (0 << 28)
  61. #define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_16 (1 << 28)
  62. #define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32 (2 << 28)
  63. #define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_64 (3 << 28)
  64. #define TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_128 (4 << 28)
  65. #define TEGRA_APBDMA_AHBSEQ_DATA_SWAP BIT(27)
  66. #define TEGRA_APBDMA_AHBSEQ_BURST_1 (4 << 24)
  67. #define TEGRA_APBDMA_AHBSEQ_BURST_4 (5 << 24)
  68. #define TEGRA_APBDMA_AHBSEQ_BURST_8 (6 << 24)
  69. #define TEGRA_APBDMA_AHBSEQ_DBL_BUF BIT(19)
  70. #define TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT 16
  71. #define TEGRA_APBDMA_AHBSEQ_WRAP_NONE 0
  72. /* APB address */
  73. #define TEGRA_APBDMA_CHAN_APBPTR 0x018
  74. /* APB sequence register */
  75. #define TEGRA_APBDMA_CHAN_APBSEQ 0x01c
  76. #define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_8 (0 << 28)
  77. #define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_16 (1 << 28)
  78. #define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32 (2 << 28)
  79. #define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_64 (3 << 28)
  80. #define TEGRA_APBDMA_APBSEQ_BUS_WIDTH_128 (4 << 28)
  81. #define TEGRA_APBDMA_APBSEQ_DATA_SWAP BIT(27)
  82. #define TEGRA_APBDMA_APBSEQ_WRAP_WORD_1 (1 << 16)
  83. /* Tegra148 specific registers */
  84. #define TEGRA_APBDMA_CHAN_WCOUNT 0x20
  85. #define TEGRA_APBDMA_CHAN_WORD_TRANSFER 0x24
  86. /*
  87. * If any burst is in flight and DMA paused then this is the time to complete
  88. * on-flight burst and update DMA status register.
  89. */
  90. #define TEGRA_APBDMA_BURST_COMPLETE_TIME 20
  91. /* Channel base address offset from APBDMA base address */
  92. #define TEGRA_APBDMA_CHANNEL_BASE_ADD_OFFSET 0x1000
  93. #define TEGRA_APBDMA_SLAVE_ID_INVALID (TEGRA_APBDMA_CSR_REQ_SEL_MASK + 1)
  94. struct tegra_dma;
  95. /*
  96. * tegra_dma_chip_data Tegra chip specific DMA data
  97. * @nr_channels: Number of channels available in the controller.
  98. * @channel_reg_size: Channel register size/stride.
  99. * @max_dma_count: Maximum DMA transfer count supported by DMA controller.
  100. * @support_channel_pause: Support channel wise pause of dma.
  101. * @support_separate_wcount_reg: Support separate word count register.
  102. */
  103. struct tegra_dma_chip_data {
  104. unsigned int nr_channels;
  105. unsigned int channel_reg_size;
  106. unsigned int max_dma_count;
  107. bool support_channel_pause;
  108. bool support_separate_wcount_reg;
  109. };
  110. /* DMA channel registers */
  111. struct tegra_dma_channel_regs {
  112. u32 csr;
  113. u32 ahb_ptr;
  114. u32 apb_ptr;
  115. u32 ahb_seq;
  116. u32 apb_seq;
  117. u32 wcount;
  118. };
  119. /*
  120. * tegra_dma_sg_req: DMA request details to configure hardware. This
  121. * contains the details for one transfer to configure DMA hw.
  122. * The client's request for data transfer can be broken into multiple
  123. * sub-transfer as per requester details and hw support.
  124. * This sub transfer get added in the list of transfer and point to Tegra
  125. * DMA descriptor which manages the transfer details.
  126. */
  127. struct tegra_dma_sg_req {
  128. struct tegra_dma_channel_regs ch_regs;
  129. unsigned int req_len;
  130. bool configured;
  131. bool last_sg;
  132. struct list_head node;
  133. struct tegra_dma_desc *dma_desc;
  134. unsigned int words_xferred;
  135. };
  136. /*
  137. * tegra_dma_desc: Tegra DMA descriptors which manages the client requests.
  138. * This descriptor keep track of transfer status, callbacks and request
  139. * counts etc.
  140. */
  141. struct tegra_dma_desc {
  142. struct dma_async_tx_descriptor txd;
  143. unsigned int bytes_requested;
  144. unsigned int bytes_transferred;
  145. enum dma_status dma_status;
  146. struct list_head node;
  147. struct list_head tx_list;
  148. struct list_head cb_node;
  149. unsigned int cb_count;
  150. };
  151. struct tegra_dma_channel;
  152. typedef void (*dma_isr_handler)(struct tegra_dma_channel *tdc,
  153. bool to_terminate);
  154. /* tegra_dma_channel: Channel specific information */
  155. struct tegra_dma_channel {
  156. struct dma_chan dma_chan;
  157. char name[12];
  158. bool config_init;
  159. unsigned int id;
  160. void __iomem *chan_addr;
  161. spinlock_t lock;
  162. bool busy;
  163. struct tegra_dma *tdma;
  164. bool cyclic;
  165. /* Different lists for managing the requests */
  166. struct list_head free_sg_req;
  167. struct list_head pending_sg_req;
  168. struct list_head free_dma_desc;
  169. struct list_head cb_desc;
  170. /* ISR handler and tasklet for bottom half of isr handling */
  171. dma_isr_handler isr_handler;
  172. struct tasklet_struct tasklet;
  173. /* Channel-slave specific configuration */
  174. unsigned int slave_id;
  175. struct dma_slave_config dma_sconfig;
  176. struct tegra_dma_channel_regs channel_reg;
  177. struct wait_queue_head wq;
  178. };
  179. /* tegra_dma: Tegra DMA specific information */
  180. struct tegra_dma {
  181. struct dma_device dma_dev;
  182. struct device *dev;
  183. struct clk *dma_clk;
  184. struct reset_control *rst;
  185. spinlock_t global_lock;
  186. void __iomem *base_addr;
  187. const struct tegra_dma_chip_data *chip_data;
  188. /*
  189. * Counter for managing global pausing of the DMA controller.
  190. * Only applicable for devices that don't support individual
  191. * channel pausing.
  192. */
  193. u32 global_pause_count;
  194. /* Last member of the structure */
  195. struct tegra_dma_channel channels[];
  196. };
  197. static inline void tdma_write(struct tegra_dma *tdma, u32 reg, u32 val)
  198. {
  199. writel(val, tdma->base_addr + reg);
  200. }
  201. static inline void tdc_write(struct tegra_dma_channel *tdc,
  202. u32 reg, u32 val)
  203. {
  204. writel(val, tdc->chan_addr + reg);
  205. }
  206. static inline u32 tdc_read(struct tegra_dma_channel *tdc, u32 reg)
  207. {
  208. return readl(tdc->chan_addr + reg);
  209. }
  210. static inline struct tegra_dma_channel *to_tegra_dma_chan(struct dma_chan *dc)
  211. {
  212. return container_of(dc, struct tegra_dma_channel, dma_chan);
  213. }
  214. static inline struct tegra_dma_desc *
  215. txd_to_tegra_dma_desc(struct dma_async_tx_descriptor *td)
  216. {
  217. return container_of(td, struct tegra_dma_desc, txd);
  218. }
  219. static inline struct device *tdc2dev(struct tegra_dma_channel *tdc)
  220. {
  221. return &tdc->dma_chan.dev->device;
  222. }
  223. static dma_cookie_t tegra_dma_tx_submit(struct dma_async_tx_descriptor *tx);
  224. /* Get DMA desc from free list, if not there then allocate it. */
  225. static struct tegra_dma_desc *tegra_dma_desc_get(struct tegra_dma_channel *tdc)
  226. {
  227. struct tegra_dma_desc *dma_desc;
  228. unsigned long flags;
  229. spin_lock_irqsave(&tdc->lock, flags);
  230. /* Do not allocate if desc are waiting for ack */
  231. list_for_each_entry(dma_desc, &tdc->free_dma_desc, node) {
  232. if (async_tx_test_ack(&dma_desc->txd) && !dma_desc->cb_count) {
  233. list_del(&dma_desc->node);
  234. spin_unlock_irqrestore(&tdc->lock, flags);
  235. dma_desc->txd.flags = 0;
  236. return dma_desc;
  237. }
  238. }
  239. spin_unlock_irqrestore(&tdc->lock, flags);
  240. /* Allocate DMA desc */
  241. dma_desc = kzalloc(sizeof(*dma_desc), GFP_NOWAIT);
  242. if (!dma_desc)
  243. return NULL;
  244. dma_async_tx_descriptor_init(&dma_desc->txd, &tdc->dma_chan);
  245. dma_desc->txd.tx_submit = tegra_dma_tx_submit;
  246. dma_desc->txd.flags = 0;
  247. return dma_desc;
  248. }
  249. static void tegra_dma_desc_put(struct tegra_dma_channel *tdc,
  250. struct tegra_dma_desc *dma_desc)
  251. {
  252. unsigned long flags;
  253. spin_lock_irqsave(&tdc->lock, flags);
  254. if (!list_empty(&dma_desc->tx_list))
  255. list_splice_init(&dma_desc->tx_list, &tdc->free_sg_req);
  256. list_add_tail(&dma_desc->node, &tdc->free_dma_desc);
  257. spin_unlock_irqrestore(&tdc->lock, flags);
  258. }
  259. static struct tegra_dma_sg_req *
  260. tegra_dma_sg_req_get(struct tegra_dma_channel *tdc)
  261. {
  262. struct tegra_dma_sg_req *sg_req;
  263. unsigned long flags;
  264. spin_lock_irqsave(&tdc->lock, flags);
  265. if (!list_empty(&tdc->free_sg_req)) {
  266. sg_req = list_first_entry(&tdc->free_sg_req, typeof(*sg_req),
  267. node);
  268. list_del(&sg_req->node);
  269. spin_unlock_irqrestore(&tdc->lock, flags);
  270. return sg_req;
  271. }
  272. spin_unlock_irqrestore(&tdc->lock, flags);
  273. sg_req = kzalloc(sizeof(*sg_req), GFP_NOWAIT);
  274. return sg_req;
  275. }
  276. static int tegra_dma_slave_config(struct dma_chan *dc,
  277. struct dma_slave_config *sconfig)
  278. {
  279. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  280. if (!list_empty(&tdc->pending_sg_req)) {
  281. dev_err(tdc2dev(tdc), "Configuration not allowed\n");
  282. return -EBUSY;
  283. }
  284. memcpy(&tdc->dma_sconfig, sconfig, sizeof(*sconfig));
  285. tdc->config_init = true;
  286. return 0;
  287. }
  288. static void tegra_dma_global_pause(struct tegra_dma_channel *tdc,
  289. bool wait_for_burst_complete)
  290. {
  291. struct tegra_dma *tdma = tdc->tdma;
  292. spin_lock(&tdma->global_lock);
  293. if (tdc->tdma->global_pause_count == 0) {
  294. tdma_write(tdma, TEGRA_APBDMA_GENERAL, 0);
  295. if (wait_for_burst_complete)
  296. udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME);
  297. }
  298. tdc->tdma->global_pause_count++;
  299. spin_unlock(&tdma->global_lock);
  300. }
  301. static void tegra_dma_global_resume(struct tegra_dma_channel *tdc)
  302. {
  303. struct tegra_dma *tdma = tdc->tdma;
  304. spin_lock(&tdma->global_lock);
  305. if (WARN_ON(tdc->tdma->global_pause_count == 0))
  306. goto out;
  307. if (--tdc->tdma->global_pause_count == 0)
  308. tdma_write(tdma, TEGRA_APBDMA_GENERAL,
  309. TEGRA_APBDMA_GENERAL_ENABLE);
  310. out:
  311. spin_unlock(&tdma->global_lock);
  312. }
  313. static void tegra_dma_pause(struct tegra_dma_channel *tdc,
  314. bool wait_for_burst_complete)
  315. {
  316. struct tegra_dma *tdma = tdc->tdma;
  317. if (tdma->chip_data->support_channel_pause) {
  318. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSRE,
  319. TEGRA_APBDMA_CHAN_CSRE_PAUSE);
  320. if (wait_for_burst_complete)
  321. udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME);
  322. } else {
  323. tegra_dma_global_pause(tdc, wait_for_burst_complete);
  324. }
  325. }
  326. static void tegra_dma_resume(struct tegra_dma_channel *tdc)
  327. {
  328. struct tegra_dma *tdma = tdc->tdma;
  329. if (tdma->chip_data->support_channel_pause)
  330. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSRE, 0);
  331. else
  332. tegra_dma_global_resume(tdc);
  333. }
  334. static void tegra_dma_stop(struct tegra_dma_channel *tdc)
  335. {
  336. u32 csr, status;
  337. /* Disable interrupts */
  338. csr = tdc_read(tdc, TEGRA_APBDMA_CHAN_CSR);
  339. csr &= ~TEGRA_APBDMA_CSR_IE_EOC;
  340. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, csr);
  341. /* Disable DMA */
  342. csr &= ~TEGRA_APBDMA_CSR_ENB;
  343. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, csr);
  344. /* Clear interrupt status if it is there */
  345. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  346. if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
  347. dev_dbg(tdc2dev(tdc), "%s():clearing interrupt\n", __func__);
  348. tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
  349. }
  350. tdc->busy = false;
  351. }
  352. static void tegra_dma_start(struct tegra_dma_channel *tdc,
  353. struct tegra_dma_sg_req *sg_req)
  354. {
  355. struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
  356. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, ch_regs->csr);
  357. tdc_write(tdc, TEGRA_APBDMA_CHAN_APBSEQ, ch_regs->apb_seq);
  358. tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, ch_regs->apb_ptr);
  359. tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBSEQ, ch_regs->ahb_seq);
  360. tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, ch_regs->ahb_ptr);
  361. if (tdc->tdma->chip_data->support_separate_wcount_reg)
  362. tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT, ch_regs->wcount);
  363. /* Start DMA */
  364. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
  365. ch_regs->csr | TEGRA_APBDMA_CSR_ENB);
  366. }
  367. static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
  368. struct tegra_dma_sg_req *nsg_req)
  369. {
  370. unsigned long status;
  371. /*
  372. * The DMA controller reloads the new configuration for next transfer
  373. * after last burst of current transfer completes.
  374. * If there is no IEC status then this makes sure that last burst
  375. * has not be completed. There may be case that last burst is on
  376. * flight and so it can complete but because DMA is paused, it
  377. * will not generates interrupt as well as not reload the new
  378. * configuration.
  379. * If there is already IEC status then interrupt handler need to
  380. * load new configuration.
  381. */
  382. tegra_dma_pause(tdc, false);
  383. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  384. /*
  385. * If interrupt is pending then do nothing as the ISR will handle
  386. * the programming for new request.
  387. */
  388. if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
  389. dev_err(tdc2dev(tdc),
  390. "Skipping new configuration as interrupt is pending\n");
  391. tegra_dma_resume(tdc);
  392. return;
  393. }
  394. /* Safe to program new configuration */
  395. tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, nsg_req->ch_regs.apb_ptr);
  396. tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->ch_regs.ahb_ptr);
  397. if (tdc->tdma->chip_data->support_separate_wcount_reg)
  398. tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT,
  399. nsg_req->ch_regs.wcount);
  400. tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
  401. nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB);
  402. nsg_req->configured = true;
  403. nsg_req->words_xferred = 0;
  404. tegra_dma_resume(tdc);
  405. }
  406. static void tdc_start_head_req(struct tegra_dma_channel *tdc)
  407. {
  408. struct tegra_dma_sg_req *sg_req;
  409. sg_req = list_first_entry(&tdc->pending_sg_req, typeof(*sg_req), node);
  410. tegra_dma_start(tdc, sg_req);
  411. sg_req->configured = true;
  412. sg_req->words_xferred = 0;
  413. tdc->busy = true;
  414. }
  415. static void tdc_configure_next_head_desc(struct tegra_dma_channel *tdc)
  416. {
  417. struct tegra_dma_sg_req *hsgreq, *hnsgreq;
  418. hsgreq = list_first_entry(&tdc->pending_sg_req, typeof(*hsgreq), node);
  419. if (!list_is_last(&hsgreq->node, &tdc->pending_sg_req)) {
  420. hnsgreq = list_first_entry(&hsgreq->node, typeof(*hnsgreq),
  421. node);
  422. tegra_dma_configure_for_next(tdc, hnsgreq);
  423. }
  424. }
  425. static inline unsigned int
  426. get_current_xferred_count(struct tegra_dma_channel *tdc,
  427. struct tegra_dma_sg_req *sg_req,
  428. unsigned long status)
  429. {
  430. return sg_req->req_len - (status & TEGRA_APBDMA_STATUS_COUNT_MASK) - 4;
  431. }
  432. static void tegra_dma_abort_all(struct tegra_dma_channel *tdc)
  433. {
  434. struct tegra_dma_desc *dma_desc;
  435. struct tegra_dma_sg_req *sgreq;
  436. while (!list_empty(&tdc->pending_sg_req)) {
  437. sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq),
  438. node);
  439. list_move_tail(&sgreq->node, &tdc->free_sg_req);
  440. if (sgreq->last_sg) {
  441. dma_desc = sgreq->dma_desc;
  442. dma_desc->dma_status = DMA_ERROR;
  443. list_add_tail(&dma_desc->node, &tdc->free_dma_desc);
  444. /* Add in cb list if it is not there. */
  445. if (!dma_desc->cb_count)
  446. list_add_tail(&dma_desc->cb_node,
  447. &tdc->cb_desc);
  448. dma_desc->cb_count++;
  449. }
  450. }
  451. tdc->isr_handler = NULL;
  452. }
  453. static bool handle_continuous_head_request(struct tegra_dma_channel *tdc,
  454. bool to_terminate)
  455. {
  456. struct tegra_dma_sg_req *hsgreq;
  457. /*
  458. * Check that head req on list should be in flight.
  459. * If it is not in flight then abort transfer as
  460. * looping of transfer can not continue.
  461. */
  462. hsgreq = list_first_entry(&tdc->pending_sg_req, typeof(*hsgreq), node);
  463. if (!hsgreq->configured) {
  464. tegra_dma_stop(tdc);
  465. pm_runtime_put(tdc->tdma->dev);
  466. dev_err(tdc2dev(tdc), "DMA transfer underflow, aborting DMA\n");
  467. tegra_dma_abort_all(tdc);
  468. return false;
  469. }
  470. /* Configure next request */
  471. if (!to_terminate)
  472. tdc_configure_next_head_desc(tdc);
  473. return true;
  474. }
  475. static void handle_once_dma_done(struct tegra_dma_channel *tdc,
  476. bool to_terminate)
  477. {
  478. struct tegra_dma_desc *dma_desc;
  479. struct tegra_dma_sg_req *sgreq;
  480. tdc->busy = false;
  481. sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node);
  482. dma_desc = sgreq->dma_desc;
  483. dma_desc->bytes_transferred += sgreq->req_len;
  484. list_del(&sgreq->node);
  485. if (sgreq->last_sg) {
  486. dma_desc->dma_status = DMA_COMPLETE;
  487. dma_cookie_complete(&dma_desc->txd);
  488. if (!dma_desc->cb_count)
  489. list_add_tail(&dma_desc->cb_node, &tdc->cb_desc);
  490. dma_desc->cb_count++;
  491. list_add_tail(&dma_desc->node, &tdc->free_dma_desc);
  492. }
  493. list_add_tail(&sgreq->node, &tdc->free_sg_req);
  494. /* Do not start DMA if it is going to be terminate */
  495. if (to_terminate)
  496. return;
  497. if (list_empty(&tdc->pending_sg_req)) {
  498. pm_runtime_put(tdc->tdma->dev);
  499. return;
  500. }
  501. tdc_start_head_req(tdc);
  502. }
  503. static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc,
  504. bool to_terminate)
  505. {
  506. struct tegra_dma_desc *dma_desc;
  507. struct tegra_dma_sg_req *sgreq;
  508. bool st;
  509. sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node);
  510. dma_desc = sgreq->dma_desc;
  511. /* if we dma for long enough the transfer count will wrap */
  512. dma_desc->bytes_transferred =
  513. (dma_desc->bytes_transferred + sgreq->req_len) %
  514. dma_desc->bytes_requested;
  515. /* Callback need to be call */
  516. if (!dma_desc->cb_count)
  517. list_add_tail(&dma_desc->cb_node, &tdc->cb_desc);
  518. dma_desc->cb_count++;
  519. sgreq->words_xferred = 0;
  520. /* If not last req then put at end of pending list */
  521. if (!list_is_last(&sgreq->node, &tdc->pending_sg_req)) {
  522. list_move_tail(&sgreq->node, &tdc->pending_sg_req);
  523. sgreq->configured = false;
  524. st = handle_continuous_head_request(tdc, to_terminate);
  525. if (!st)
  526. dma_desc->dma_status = DMA_ERROR;
  527. }
  528. }
  529. static void tegra_dma_tasklet(struct tasklet_struct *t)
  530. {
  531. struct tegra_dma_channel *tdc = from_tasklet(tdc, t, tasklet);
  532. struct dmaengine_desc_callback cb;
  533. struct tegra_dma_desc *dma_desc;
  534. unsigned int cb_count;
  535. unsigned long flags;
  536. spin_lock_irqsave(&tdc->lock, flags);
  537. while (!list_empty(&tdc->cb_desc)) {
  538. dma_desc = list_first_entry(&tdc->cb_desc, typeof(*dma_desc),
  539. cb_node);
  540. list_del(&dma_desc->cb_node);
  541. dmaengine_desc_get_callback(&dma_desc->txd, &cb);
  542. cb_count = dma_desc->cb_count;
  543. dma_desc->cb_count = 0;
  544. trace_tegra_dma_complete_cb(&tdc->dma_chan, cb_count,
  545. cb.callback);
  546. spin_unlock_irqrestore(&tdc->lock, flags);
  547. while (cb_count--)
  548. dmaengine_desc_callback_invoke(&cb, NULL);
  549. spin_lock_irqsave(&tdc->lock, flags);
  550. }
  551. spin_unlock_irqrestore(&tdc->lock, flags);
  552. }
  553. static irqreturn_t tegra_dma_isr(int irq, void *dev_id)
  554. {
  555. struct tegra_dma_channel *tdc = dev_id;
  556. u32 status;
  557. spin_lock(&tdc->lock);
  558. trace_tegra_dma_isr(&tdc->dma_chan, irq);
  559. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  560. if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
  561. tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
  562. tdc->isr_handler(tdc, false);
  563. tasklet_schedule(&tdc->tasklet);
  564. wake_up_all(&tdc->wq);
  565. spin_unlock(&tdc->lock);
  566. return IRQ_HANDLED;
  567. }
  568. spin_unlock(&tdc->lock);
  569. dev_info(tdc2dev(tdc), "Interrupt already served status 0x%08x\n",
  570. status);
  571. return IRQ_NONE;
  572. }
  573. static dma_cookie_t tegra_dma_tx_submit(struct dma_async_tx_descriptor *txd)
  574. {
  575. struct tegra_dma_desc *dma_desc = txd_to_tegra_dma_desc(txd);
  576. struct tegra_dma_channel *tdc = to_tegra_dma_chan(txd->chan);
  577. unsigned long flags;
  578. dma_cookie_t cookie;
  579. spin_lock_irqsave(&tdc->lock, flags);
  580. dma_desc->dma_status = DMA_IN_PROGRESS;
  581. cookie = dma_cookie_assign(&dma_desc->txd);
  582. list_splice_tail_init(&dma_desc->tx_list, &tdc->pending_sg_req);
  583. spin_unlock_irqrestore(&tdc->lock, flags);
  584. return cookie;
  585. }
  586. static void tegra_dma_issue_pending(struct dma_chan *dc)
  587. {
  588. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  589. unsigned long flags;
  590. int err;
  591. spin_lock_irqsave(&tdc->lock, flags);
  592. if (list_empty(&tdc->pending_sg_req)) {
  593. dev_err(tdc2dev(tdc), "No DMA request\n");
  594. goto end;
  595. }
  596. if (!tdc->busy) {
  597. err = pm_runtime_resume_and_get(tdc->tdma->dev);
  598. if (err < 0) {
  599. dev_err(tdc2dev(tdc), "Failed to enable DMA\n");
  600. goto end;
  601. }
  602. tdc_start_head_req(tdc);
  603. /* Continuous single mode: Configure next req */
  604. if (tdc->cyclic) {
  605. /*
  606. * Wait for 1 burst time for configure DMA for
  607. * next transfer.
  608. */
  609. udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME);
  610. tdc_configure_next_head_desc(tdc);
  611. }
  612. }
  613. end:
  614. spin_unlock_irqrestore(&tdc->lock, flags);
  615. }
  616. static int tegra_dma_terminate_all(struct dma_chan *dc)
  617. {
  618. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  619. struct tegra_dma_desc *dma_desc;
  620. struct tegra_dma_sg_req *sgreq;
  621. unsigned long flags;
  622. u32 status, wcount;
  623. bool was_busy;
  624. spin_lock_irqsave(&tdc->lock, flags);
  625. if (!tdc->busy)
  626. goto skip_dma_stop;
  627. /* Pause DMA before checking the queue status */
  628. tegra_dma_pause(tdc, true);
  629. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  630. if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
  631. dev_dbg(tdc2dev(tdc), "%s():handling isr\n", __func__);
  632. tdc->isr_handler(tdc, true);
  633. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  634. }
  635. if (tdc->tdma->chip_data->support_separate_wcount_reg)
  636. wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
  637. else
  638. wcount = status;
  639. was_busy = tdc->busy;
  640. tegra_dma_stop(tdc);
  641. if (!list_empty(&tdc->pending_sg_req) && was_busy) {
  642. sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq),
  643. node);
  644. sgreq->dma_desc->bytes_transferred +=
  645. get_current_xferred_count(tdc, sgreq, wcount);
  646. }
  647. tegra_dma_resume(tdc);
  648. pm_runtime_put(tdc->tdma->dev);
  649. wake_up_all(&tdc->wq);
  650. skip_dma_stop:
  651. tegra_dma_abort_all(tdc);
  652. while (!list_empty(&tdc->cb_desc)) {
  653. dma_desc = list_first_entry(&tdc->cb_desc, typeof(*dma_desc),
  654. cb_node);
  655. list_del(&dma_desc->cb_node);
  656. dma_desc->cb_count = 0;
  657. }
  658. spin_unlock_irqrestore(&tdc->lock, flags);
  659. return 0;
  660. }
  661. static bool tegra_dma_eoc_interrupt_deasserted(struct tegra_dma_channel *tdc)
  662. {
  663. unsigned long flags;
  664. u32 status;
  665. spin_lock_irqsave(&tdc->lock, flags);
  666. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  667. spin_unlock_irqrestore(&tdc->lock, flags);
  668. return !(status & TEGRA_APBDMA_STATUS_ISE_EOC);
  669. }
  670. static void tegra_dma_synchronize(struct dma_chan *dc)
  671. {
  672. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  673. int err;
  674. err = pm_runtime_resume_and_get(tdc->tdma->dev);
  675. if (err < 0) {
  676. dev_err(tdc2dev(tdc), "Failed to synchronize DMA: %d\n", err);
  677. return;
  678. }
  679. /*
  680. * CPU, which handles interrupt, could be busy in
  681. * uninterruptible state, in this case sibling CPU
  682. * should wait until interrupt is handled.
  683. */
  684. wait_event(tdc->wq, tegra_dma_eoc_interrupt_deasserted(tdc));
  685. tasklet_kill(&tdc->tasklet);
  686. pm_runtime_put(tdc->tdma->dev);
  687. }
  688. static unsigned int tegra_dma_sg_bytes_xferred(struct tegra_dma_channel *tdc,
  689. struct tegra_dma_sg_req *sg_req)
  690. {
  691. u32 status, wcount = 0;
  692. if (!list_is_first(&sg_req->node, &tdc->pending_sg_req))
  693. return 0;
  694. if (tdc->tdma->chip_data->support_separate_wcount_reg)
  695. wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
  696. status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
  697. if (!tdc->tdma->chip_data->support_separate_wcount_reg)
  698. wcount = status;
  699. if (status & TEGRA_APBDMA_STATUS_ISE_EOC)
  700. return sg_req->req_len;
  701. wcount = get_current_xferred_count(tdc, sg_req, wcount);
  702. if (!wcount) {
  703. /*
  704. * If wcount wasn't ever polled for this SG before, then
  705. * simply assume that transfer hasn't started yet.
  706. *
  707. * Otherwise it's the end of the transfer.
  708. *
  709. * The alternative would be to poll the status register
  710. * until EOC bit is set or wcount goes UP. That's so
  711. * because EOC bit is getting set only after the last
  712. * burst's completion and counter is less than the actual
  713. * transfer size by 4 bytes. The counter value wraps around
  714. * in a cyclic mode before EOC is set(!), so we can't easily
  715. * distinguish start of transfer from its end.
  716. */
  717. if (sg_req->words_xferred)
  718. wcount = sg_req->req_len - 4;
  719. } else if (wcount < sg_req->words_xferred) {
  720. /*
  721. * This case will never happen for a non-cyclic transfer.
  722. *
  723. * For a cyclic transfer, although it is possible for the
  724. * next transfer to have already started (resetting the word
  725. * count), this case should still not happen because we should
  726. * have detected that the EOC bit is set and hence the transfer
  727. * was completed.
  728. */
  729. WARN_ON_ONCE(1);
  730. wcount = sg_req->req_len - 4;
  731. } else {
  732. sg_req->words_xferred = wcount;
  733. }
  734. return wcount;
  735. }
  736. static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
  737. dma_cookie_t cookie,
  738. struct dma_tx_state *txstate)
  739. {
  740. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  741. struct tegra_dma_desc *dma_desc;
  742. struct tegra_dma_sg_req *sg_req;
  743. enum dma_status ret;
  744. unsigned long flags;
  745. unsigned int residual;
  746. unsigned int bytes = 0;
  747. ret = dma_cookie_status(dc, cookie, txstate);
  748. if (ret == DMA_COMPLETE)
  749. return ret;
  750. spin_lock_irqsave(&tdc->lock, flags);
  751. /* Check on wait_ack desc status */
  752. list_for_each_entry(dma_desc, &tdc->free_dma_desc, node) {
  753. if (dma_desc->txd.cookie == cookie) {
  754. ret = dma_desc->dma_status;
  755. goto found;
  756. }
  757. }
  758. /* Check in pending list */
  759. list_for_each_entry(sg_req, &tdc->pending_sg_req, node) {
  760. dma_desc = sg_req->dma_desc;
  761. if (dma_desc->txd.cookie == cookie) {
  762. bytes = tegra_dma_sg_bytes_xferred(tdc, sg_req);
  763. ret = dma_desc->dma_status;
  764. goto found;
  765. }
  766. }
  767. dev_dbg(tdc2dev(tdc), "cookie %d not found\n", cookie);
  768. dma_desc = NULL;
  769. found:
  770. if (dma_desc && txstate) {
  771. residual = dma_desc->bytes_requested -
  772. ((dma_desc->bytes_transferred + bytes) %
  773. dma_desc->bytes_requested);
  774. dma_set_residue(txstate, residual);
  775. }
  776. trace_tegra_dma_tx_status(&tdc->dma_chan, cookie, txstate);
  777. spin_unlock_irqrestore(&tdc->lock, flags);
  778. return ret;
  779. }
  780. static inline unsigned int get_bus_width(struct tegra_dma_channel *tdc,
  781. enum dma_slave_buswidth slave_bw)
  782. {
  783. switch (slave_bw) {
  784. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  785. return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_8;
  786. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  787. return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_16;
  788. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  789. return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32;
  790. case DMA_SLAVE_BUSWIDTH_8_BYTES:
  791. return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_64;
  792. default:
  793. dev_warn(tdc2dev(tdc),
  794. "slave bw is not supported, using 32bits\n");
  795. return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32;
  796. }
  797. }
  798. static inline unsigned int get_burst_size(struct tegra_dma_channel *tdc,
  799. u32 burst_size,
  800. enum dma_slave_buswidth slave_bw,
  801. u32 len)
  802. {
  803. unsigned int burst_byte, burst_ahb_width;
  804. /*
  805. * burst_size from client is in terms of the bus_width.
  806. * convert them into AHB memory width which is 4 byte.
  807. */
  808. burst_byte = burst_size * slave_bw;
  809. burst_ahb_width = burst_byte / 4;
  810. /* If burst size is 0 then calculate the burst size based on length */
  811. if (!burst_ahb_width) {
  812. if (len & 0xF)
  813. return TEGRA_APBDMA_AHBSEQ_BURST_1;
  814. else if ((len >> 4) & 0x1)
  815. return TEGRA_APBDMA_AHBSEQ_BURST_4;
  816. else
  817. return TEGRA_APBDMA_AHBSEQ_BURST_8;
  818. }
  819. if (burst_ahb_width < 4)
  820. return TEGRA_APBDMA_AHBSEQ_BURST_1;
  821. else if (burst_ahb_width < 8)
  822. return TEGRA_APBDMA_AHBSEQ_BURST_4;
  823. else
  824. return TEGRA_APBDMA_AHBSEQ_BURST_8;
  825. }
  826. static int get_transfer_param(struct tegra_dma_channel *tdc,
  827. enum dma_transfer_direction direction,
  828. u32 *apb_addr,
  829. u32 *apb_seq,
  830. u32 *csr,
  831. unsigned int *burst_size,
  832. enum dma_slave_buswidth *slave_bw)
  833. {
  834. switch (direction) {
  835. case DMA_MEM_TO_DEV:
  836. *apb_addr = tdc->dma_sconfig.dst_addr;
  837. *apb_seq = get_bus_width(tdc, tdc->dma_sconfig.dst_addr_width);
  838. *burst_size = tdc->dma_sconfig.dst_maxburst;
  839. *slave_bw = tdc->dma_sconfig.dst_addr_width;
  840. *csr = TEGRA_APBDMA_CSR_DIR;
  841. return 0;
  842. case DMA_DEV_TO_MEM:
  843. *apb_addr = tdc->dma_sconfig.src_addr;
  844. *apb_seq = get_bus_width(tdc, tdc->dma_sconfig.src_addr_width);
  845. *burst_size = tdc->dma_sconfig.src_maxburst;
  846. *slave_bw = tdc->dma_sconfig.src_addr_width;
  847. *csr = 0;
  848. return 0;
  849. default:
  850. dev_err(tdc2dev(tdc), "DMA direction is not supported\n");
  851. break;
  852. }
  853. return -EINVAL;
  854. }
  855. static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc,
  856. struct tegra_dma_channel_regs *ch_regs,
  857. u32 len)
  858. {
  859. u32 len_field = (len - 4) & 0xFFFC;
  860. if (tdc->tdma->chip_data->support_separate_wcount_reg)
  861. ch_regs->wcount = len_field;
  862. else
  863. ch_regs->csr |= len_field;
  864. }
  865. static struct dma_async_tx_descriptor *
  866. tegra_dma_prep_slave_sg(struct dma_chan *dc,
  867. struct scatterlist *sgl,
  868. unsigned int sg_len,
  869. enum dma_transfer_direction direction,
  870. unsigned long flags,
  871. void *context)
  872. {
  873. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  874. struct tegra_dma_sg_req *sg_req = NULL;
  875. u32 csr, ahb_seq, apb_ptr, apb_seq;
  876. enum dma_slave_buswidth slave_bw;
  877. struct tegra_dma_desc *dma_desc;
  878. struct list_head req_list;
  879. struct scatterlist *sg;
  880. unsigned int burst_size;
  881. unsigned int i;
  882. if (!tdc->config_init) {
  883. dev_err(tdc2dev(tdc), "DMA channel is not configured\n");
  884. return NULL;
  885. }
  886. if (sg_len < 1) {
  887. dev_err(tdc2dev(tdc), "Invalid segment length %d\n", sg_len);
  888. return NULL;
  889. }
  890. if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr,
  891. &burst_size, &slave_bw) < 0)
  892. return NULL;
  893. INIT_LIST_HEAD(&req_list);
  894. ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
  895. ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
  896. TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
  897. ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
  898. csr |= TEGRA_APBDMA_CSR_ONCE;
  899. if (tdc->slave_id != TEGRA_APBDMA_SLAVE_ID_INVALID) {
  900. csr |= TEGRA_APBDMA_CSR_FLOW;
  901. csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
  902. }
  903. if (flags & DMA_PREP_INTERRUPT) {
  904. csr |= TEGRA_APBDMA_CSR_IE_EOC;
  905. } else {
  906. WARN_ON_ONCE(1);
  907. return NULL;
  908. }
  909. apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
  910. dma_desc = tegra_dma_desc_get(tdc);
  911. if (!dma_desc) {
  912. dev_err(tdc2dev(tdc), "DMA descriptors not available\n");
  913. return NULL;
  914. }
  915. INIT_LIST_HEAD(&dma_desc->tx_list);
  916. INIT_LIST_HEAD(&dma_desc->cb_node);
  917. dma_desc->cb_count = 0;
  918. dma_desc->bytes_requested = 0;
  919. dma_desc->bytes_transferred = 0;
  920. dma_desc->dma_status = DMA_IN_PROGRESS;
  921. /* Make transfer requests */
  922. for_each_sg(sgl, sg, sg_len, i) {
  923. u32 len, mem;
  924. mem = sg_dma_address(sg);
  925. len = sg_dma_len(sg);
  926. if ((len & 3) || (mem & 3) ||
  927. len > tdc->tdma->chip_data->max_dma_count) {
  928. dev_err(tdc2dev(tdc),
  929. "DMA length/memory address is not supported\n");
  930. tegra_dma_desc_put(tdc, dma_desc);
  931. return NULL;
  932. }
  933. sg_req = tegra_dma_sg_req_get(tdc);
  934. if (!sg_req) {
  935. dev_err(tdc2dev(tdc), "DMA sg-req not available\n");
  936. tegra_dma_desc_put(tdc, dma_desc);
  937. return NULL;
  938. }
  939. ahb_seq |= get_burst_size(tdc, burst_size, slave_bw, len);
  940. dma_desc->bytes_requested += len;
  941. sg_req->ch_regs.apb_ptr = apb_ptr;
  942. sg_req->ch_regs.ahb_ptr = mem;
  943. sg_req->ch_regs.csr = csr;
  944. tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
  945. sg_req->ch_regs.apb_seq = apb_seq;
  946. sg_req->ch_regs.ahb_seq = ahb_seq;
  947. sg_req->configured = false;
  948. sg_req->last_sg = false;
  949. sg_req->dma_desc = dma_desc;
  950. sg_req->req_len = len;
  951. list_add_tail(&sg_req->node, &dma_desc->tx_list);
  952. }
  953. sg_req->last_sg = true;
  954. if (flags & DMA_CTRL_ACK)
  955. dma_desc->txd.flags = DMA_CTRL_ACK;
  956. /*
  957. * Make sure that mode should not be conflicting with currently
  958. * configured mode.
  959. */
  960. if (!tdc->isr_handler) {
  961. tdc->isr_handler = handle_once_dma_done;
  962. tdc->cyclic = false;
  963. } else {
  964. if (tdc->cyclic) {
  965. dev_err(tdc2dev(tdc), "DMA configured in cyclic mode\n");
  966. tegra_dma_desc_put(tdc, dma_desc);
  967. return NULL;
  968. }
  969. }
  970. return &dma_desc->txd;
  971. }
  972. static struct dma_async_tx_descriptor *
  973. tegra_dma_prep_dma_cyclic(struct dma_chan *dc, dma_addr_t buf_addr,
  974. size_t buf_len,
  975. size_t period_len,
  976. enum dma_transfer_direction direction,
  977. unsigned long flags)
  978. {
  979. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  980. struct tegra_dma_sg_req *sg_req = NULL;
  981. u32 csr, ahb_seq, apb_ptr, apb_seq;
  982. enum dma_slave_buswidth slave_bw;
  983. struct tegra_dma_desc *dma_desc;
  984. dma_addr_t mem = buf_addr;
  985. unsigned int burst_size;
  986. size_t len, remain_len;
  987. if (!buf_len || !period_len) {
  988. dev_err(tdc2dev(tdc), "Invalid buffer/period len\n");
  989. return NULL;
  990. }
  991. if (!tdc->config_init) {
  992. dev_err(tdc2dev(tdc), "DMA slave is not configured\n");
  993. return NULL;
  994. }
  995. /*
  996. * We allow to take more number of requests till DMA is
  997. * not started. The driver will loop over all requests.
  998. * Once DMA is started then new requests can be queued only after
  999. * terminating the DMA.
  1000. */
  1001. if (tdc->busy) {
  1002. dev_err(tdc2dev(tdc), "Request not allowed when DMA running\n");
  1003. return NULL;
  1004. }
  1005. /*
  1006. * We only support cycle transfer when buf_len is multiple of
  1007. * period_len.
  1008. */
  1009. if (buf_len % period_len) {
  1010. dev_err(tdc2dev(tdc), "buf_len is not multiple of period_len\n");
  1011. return NULL;
  1012. }
  1013. len = period_len;
  1014. if ((len & 3) || (buf_addr & 3) ||
  1015. len > tdc->tdma->chip_data->max_dma_count) {
  1016. dev_err(tdc2dev(tdc), "Req len/mem address is not correct\n");
  1017. return NULL;
  1018. }
  1019. if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr,
  1020. &burst_size, &slave_bw) < 0)
  1021. return NULL;
  1022. ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
  1023. ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
  1024. TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
  1025. ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
  1026. if (tdc->slave_id != TEGRA_APBDMA_SLAVE_ID_INVALID) {
  1027. csr |= TEGRA_APBDMA_CSR_FLOW;
  1028. csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
  1029. }
  1030. if (flags & DMA_PREP_INTERRUPT) {
  1031. csr |= TEGRA_APBDMA_CSR_IE_EOC;
  1032. } else {
  1033. WARN_ON_ONCE(1);
  1034. return NULL;
  1035. }
  1036. apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
  1037. dma_desc = tegra_dma_desc_get(tdc);
  1038. if (!dma_desc) {
  1039. dev_err(tdc2dev(tdc), "not enough descriptors available\n");
  1040. return NULL;
  1041. }
  1042. INIT_LIST_HEAD(&dma_desc->tx_list);
  1043. INIT_LIST_HEAD(&dma_desc->cb_node);
  1044. dma_desc->cb_count = 0;
  1045. dma_desc->bytes_transferred = 0;
  1046. dma_desc->bytes_requested = buf_len;
  1047. remain_len = buf_len;
  1048. /* Split transfer equal to period size */
  1049. while (remain_len) {
  1050. sg_req = tegra_dma_sg_req_get(tdc);
  1051. if (!sg_req) {
  1052. dev_err(tdc2dev(tdc), "DMA sg-req not available\n");
  1053. tegra_dma_desc_put(tdc, dma_desc);
  1054. return NULL;
  1055. }
  1056. ahb_seq |= get_burst_size(tdc, burst_size, slave_bw, len);
  1057. sg_req->ch_regs.apb_ptr = apb_ptr;
  1058. sg_req->ch_regs.ahb_ptr = mem;
  1059. sg_req->ch_regs.csr = csr;
  1060. tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
  1061. sg_req->ch_regs.apb_seq = apb_seq;
  1062. sg_req->ch_regs.ahb_seq = ahb_seq;
  1063. sg_req->configured = false;
  1064. sg_req->last_sg = false;
  1065. sg_req->dma_desc = dma_desc;
  1066. sg_req->req_len = len;
  1067. list_add_tail(&sg_req->node, &dma_desc->tx_list);
  1068. remain_len -= len;
  1069. mem += len;
  1070. }
  1071. sg_req->last_sg = true;
  1072. if (flags & DMA_CTRL_ACK)
  1073. dma_desc->txd.flags = DMA_CTRL_ACK;
  1074. /*
  1075. * Make sure that mode should not be conflicting with currently
  1076. * configured mode.
  1077. */
  1078. if (!tdc->isr_handler) {
  1079. tdc->isr_handler = handle_cont_sngl_cycle_dma_done;
  1080. tdc->cyclic = true;
  1081. } else {
  1082. if (!tdc->cyclic) {
  1083. dev_err(tdc2dev(tdc), "DMA configuration conflict\n");
  1084. tegra_dma_desc_put(tdc, dma_desc);
  1085. return NULL;
  1086. }
  1087. }
  1088. return &dma_desc->txd;
  1089. }
  1090. static int tegra_dma_alloc_chan_resources(struct dma_chan *dc)
  1091. {
  1092. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  1093. dma_cookie_init(&tdc->dma_chan);
  1094. return 0;
  1095. }
  1096. static void tegra_dma_free_chan_resources(struct dma_chan *dc)
  1097. {
  1098. struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
  1099. struct tegra_dma_desc *dma_desc;
  1100. struct tegra_dma_sg_req *sg_req;
  1101. struct list_head dma_desc_list;
  1102. struct list_head sg_req_list;
  1103. INIT_LIST_HEAD(&dma_desc_list);
  1104. INIT_LIST_HEAD(&sg_req_list);
  1105. dev_dbg(tdc2dev(tdc), "Freeing channel %d\n", tdc->id);
  1106. tegra_dma_terminate_all(dc);
  1107. tasklet_kill(&tdc->tasklet);
  1108. list_splice_init(&tdc->pending_sg_req, &sg_req_list);
  1109. list_splice_init(&tdc->free_sg_req, &sg_req_list);
  1110. list_splice_init(&tdc->free_dma_desc, &dma_desc_list);
  1111. INIT_LIST_HEAD(&tdc->cb_desc);
  1112. tdc->config_init = false;
  1113. tdc->isr_handler = NULL;
  1114. while (!list_empty(&dma_desc_list)) {
  1115. dma_desc = list_first_entry(&dma_desc_list, typeof(*dma_desc),
  1116. node);
  1117. list_del(&dma_desc->node);
  1118. kfree(dma_desc);
  1119. }
  1120. while (!list_empty(&sg_req_list)) {
  1121. sg_req = list_first_entry(&sg_req_list, typeof(*sg_req), node);
  1122. list_del(&sg_req->node);
  1123. kfree(sg_req);
  1124. }
  1125. tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID;
  1126. }
  1127. static struct dma_chan *tegra_dma_of_xlate(struct of_phandle_args *dma_spec,
  1128. struct of_dma *ofdma)
  1129. {
  1130. struct tegra_dma *tdma = ofdma->of_dma_data;
  1131. struct tegra_dma_channel *tdc;
  1132. struct dma_chan *chan;
  1133. if (dma_spec->args[0] > TEGRA_APBDMA_CSR_REQ_SEL_MASK) {
  1134. dev_err(tdma->dev, "Invalid slave id: %d\n", dma_spec->args[0]);
  1135. return NULL;
  1136. }
  1137. chan = dma_get_any_slave_channel(&tdma->dma_dev);
  1138. if (!chan)
  1139. return NULL;
  1140. tdc = to_tegra_dma_chan(chan);
  1141. tdc->slave_id = dma_spec->args[0];
  1142. return chan;
  1143. }
  1144. /* Tegra20 specific DMA controller information */
  1145. static const struct tegra_dma_chip_data tegra20_dma_chip_data = {
  1146. .nr_channels = 16,
  1147. .channel_reg_size = 0x20,
  1148. .max_dma_count = 1024UL * 64,
  1149. .support_channel_pause = false,
  1150. .support_separate_wcount_reg = false,
  1151. };
  1152. /* Tegra30 specific DMA controller information */
  1153. static const struct tegra_dma_chip_data tegra30_dma_chip_data = {
  1154. .nr_channels = 32,
  1155. .channel_reg_size = 0x20,
  1156. .max_dma_count = 1024UL * 64,
  1157. .support_channel_pause = false,
  1158. .support_separate_wcount_reg = false,
  1159. };
  1160. /* Tegra114 specific DMA controller information */
  1161. static const struct tegra_dma_chip_data tegra114_dma_chip_data = {
  1162. .nr_channels = 32,
  1163. .channel_reg_size = 0x20,
  1164. .max_dma_count = 1024UL * 64,
  1165. .support_channel_pause = true,
  1166. .support_separate_wcount_reg = false,
  1167. };
  1168. /* Tegra148 specific DMA controller information */
  1169. static const struct tegra_dma_chip_data tegra148_dma_chip_data = {
  1170. .nr_channels = 32,
  1171. .channel_reg_size = 0x40,
  1172. .max_dma_count = 1024UL * 64,
  1173. .support_channel_pause = true,
  1174. .support_separate_wcount_reg = true,
  1175. };
  1176. static int tegra_dma_init_hw(struct tegra_dma *tdma)
  1177. {
  1178. int err;
  1179. err = reset_control_assert(tdma->rst);
  1180. if (err) {
  1181. dev_err(tdma->dev, "failed to assert reset: %d\n", err);
  1182. return err;
  1183. }
  1184. err = clk_enable(tdma->dma_clk);
  1185. if (err) {
  1186. dev_err(tdma->dev, "failed to enable clk: %d\n", err);
  1187. return err;
  1188. }
  1189. /* reset DMA controller */
  1190. udelay(2);
  1191. reset_control_deassert(tdma->rst);
  1192. /* enable global DMA registers */
  1193. tdma_write(tdma, TEGRA_APBDMA_GENERAL, TEGRA_APBDMA_GENERAL_ENABLE);
  1194. tdma_write(tdma, TEGRA_APBDMA_CONTROL, 0);
  1195. tdma_write(tdma, TEGRA_APBDMA_IRQ_MASK_SET, 0xFFFFFFFF);
  1196. clk_disable(tdma->dma_clk);
  1197. return 0;
  1198. }
  1199. static int tegra_dma_probe(struct platform_device *pdev)
  1200. {
  1201. const struct tegra_dma_chip_data *cdata;
  1202. struct tegra_dma *tdma;
  1203. unsigned int i;
  1204. size_t size;
  1205. int ret;
  1206. cdata = of_device_get_match_data(&pdev->dev);
  1207. size = struct_size(tdma, channels, cdata->nr_channels);
  1208. tdma = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
  1209. if (!tdma)
  1210. return -ENOMEM;
  1211. tdma->dev = &pdev->dev;
  1212. tdma->chip_data = cdata;
  1213. platform_set_drvdata(pdev, tdma);
  1214. tdma->base_addr = devm_platform_ioremap_resource(pdev, 0);
  1215. if (IS_ERR(tdma->base_addr))
  1216. return PTR_ERR(tdma->base_addr);
  1217. tdma->dma_clk = devm_clk_get(&pdev->dev, NULL);
  1218. if (IS_ERR(tdma->dma_clk)) {
  1219. dev_err(&pdev->dev, "Error: Missing controller clock\n");
  1220. return PTR_ERR(tdma->dma_clk);
  1221. }
  1222. tdma->rst = devm_reset_control_get(&pdev->dev, "dma");
  1223. if (IS_ERR(tdma->rst)) {
  1224. dev_err(&pdev->dev, "Error: Missing reset\n");
  1225. return PTR_ERR(tdma->rst);
  1226. }
  1227. spin_lock_init(&tdma->global_lock);
  1228. ret = clk_prepare(tdma->dma_clk);
  1229. if (ret)
  1230. return ret;
  1231. ret = tegra_dma_init_hw(tdma);
  1232. if (ret)
  1233. goto err_clk_unprepare;
  1234. pm_runtime_irq_safe(&pdev->dev);
  1235. pm_runtime_enable(&pdev->dev);
  1236. INIT_LIST_HEAD(&tdma->dma_dev.channels);
  1237. for (i = 0; i < cdata->nr_channels; i++) {
  1238. struct tegra_dma_channel *tdc = &tdma->channels[i];
  1239. int irq;
  1240. tdc->chan_addr = tdma->base_addr +
  1241. TEGRA_APBDMA_CHANNEL_BASE_ADD_OFFSET +
  1242. (i * cdata->channel_reg_size);
  1243. irq = platform_get_irq(pdev, i);
  1244. if (irq < 0) {
  1245. ret = irq;
  1246. goto err_pm_disable;
  1247. }
  1248. snprintf(tdc->name, sizeof(tdc->name), "apbdma.%d", i);
  1249. ret = devm_request_irq(&pdev->dev, irq, tegra_dma_isr, 0,
  1250. tdc->name, tdc);
  1251. if (ret) {
  1252. dev_err(&pdev->dev,
  1253. "request_irq failed with err %d channel %d\n",
  1254. ret, i);
  1255. goto err_pm_disable;
  1256. }
  1257. tdc->dma_chan.device = &tdma->dma_dev;
  1258. dma_cookie_init(&tdc->dma_chan);
  1259. list_add_tail(&tdc->dma_chan.device_node,
  1260. &tdma->dma_dev.channels);
  1261. tdc->tdma = tdma;
  1262. tdc->id = i;
  1263. tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID;
  1264. tasklet_setup(&tdc->tasklet, tegra_dma_tasklet);
  1265. spin_lock_init(&tdc->lock);
  1266. init_waitqueue_head(&tdc->wq);
  1267. INIT_LIST_HEAD(&tdc->pending_sg_req);
  1268. INIT_LIST_HEAD(&tdc->free_sg_req);
  1269. INIT_LIST_HEAD(&tdc->free_dma_desc);
  1270. INIT_LIST_HEAD(&tdc->cb_desc);
  1271. }
  1272. dma_cap_set(DMA_SLAVE, tdma->dma_dev.cap_mask);
  1273. dma_cap_set(DMA_PRIVATE, tdma->dma_dev.cap_mask);
  1274. dma_cap_set(DMA_CYCLIC, tdma->dma_dev.cap_mask);
  1275. tdma->global_pause_count = 0;
  1276. tdma->dma_dev.dev = &pdev->dev;
  1277. tdma->dma_dev.device_alloc_chan_resources =
  1278. tegra_dma_alloc_chan_resources;
  1279. tdma->dma_dev.device_free_chan_resources =
  1280. tegra_dma_free_chan_resources;
  1281. tdma->dma_dev.device_prep_slave_sg = tegra_dma_prep_slave_sg;
  1282. tdma->dma_dev.device_prep_dma_cyclic = tegra_dma_prep_dma_cyclic;
  1283. tdma->dma_dev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
  1284. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
  1285. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
  1286. BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
  1287. tdma->dma_dev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
  1288. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
  1289. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) |
  1290. BIT(DMA_SLAVE_BUSWIDTH_8_BYTES);
  1291. tdma->dma_dev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  1292. tdma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  1293. tdma->dma_dev.device_config = tegra_dma_slave_config;
  1294. tdma->dma_dev.device_terminate_all = tegra_dma_terminate_all;
  1295. tdma->dma_dev.device_synchronize = tegra_dma_synchronize;
  1296. tdma->dma_dev.device_tx_status = tegra_dma_tx_status;
  1297. tdma->dma_dev.device_issue_pending = tegra_dma_issue_pending;
  1298. ret = dma_async_device_register(&tdma->dma_dev);
  1299. if (ret < 0) {
  1300. dev_err(&pdev->dev,
  1301. "Tegra20 APB DMA driver registration failed %d\n", ret);
  1302. goto err_pm_disable;
  1303. }
  1304. ret = of_dma_controller_register(pdev->dev.of_node,
  1305. tegra_dma_of_xlate, tdma);
  1306. if (ret < 0) {
  1307. dev_err(&pdev->dev,
  1308. "Tegra20 APB DMA OF registration failed %d\n", ret);
  1309. goto err_unregister_dma_dev;
  1310. }
  1311. dev_info(&pdev->dev, "Tegra20 APB DMA driver registered %u channels\n",
  1312. cdata->nr_channels);
  1313. return 0;
  1314. err_unregister_dma_dev:
  1315. dma_async_device_unregister(&tdma->dma_dev);
  1316. err_pm_disable:
  1317. pm_runtime_disable(&pdev->dev);
  1318. err_clk_unprepare:
  1319. clk_unprepare(tdma->dma_clk);
  1320. return ret;
  1321. }
  1322. static void tegra_dma_remove(struct platform_device *pdev)
  1323. {
  1324. struct tegra_dma *tdma = platform_get_drvdata(pdev);
  1325. of_dma_controller_free(pdev->dev.of_node);
  1326. dma_async_device_unregister(&tdma->dma_dev);
  1327. pm_runtime_disable(&pdev->dev);
  1328. clk_unprepare(tdma->dma_clk);
  1329. }
  1330. static int __maybe_unused tegra_dma_runtime_suspend(struct device *dev)
  1331. {
  1332. struct tegra_dma *tdma = dev_get_drvdata(dev);
  1333. clk_disable(tdma->dma_clk);
  1334. return 0;
  1335. }
  1336. static int __maybe_unused tegra_dma_runtime_resume(struct device *dev)
  1337. {
  1338. struct tegra_dma *tdma = dev_get_drvdata(dev);
  1339. return clk_enable(tdma->dma_clk);
  1340. }
  1341. static int __maybe_unused tegra_dma_dev_suspend(struct device *dev)
  1342. {
  1343. struct tegra_dma *tdma = dev_get_drvdata(dev);
  1344. unsigned long flags;
  1345. unsigned int i;
  1346. bool busy;
  1347. for (i = 0; i < tdma->chip_data->nr_channels; i++) {
  1348. struct tegra_dma_channel *tdc = &tdma->channels[i];
  1349. tasklet_kill(&tdc->tasklet);
  1350. spin_lock_irqsave(&tdc->lock, flags);
  1351. busy = tdc->busy;
  1352. spin_unlock_irqrestore(&tdc->lock, flags);
  1353. if (busy) {
  1354. dev_err(tdma->dev, "channel %u busy\n", i);
  1355. return -EBUSY;
  1356. }
  1357. }
  1358. return pm_runtime_force_suspend(dev);
  1359. }
  1360. static int __maybe_unused tegra_dma_dev_resume(struct device *dev)
  1361. {
  1362. struct tegra_dma *tdma = dev_get_drvdata(dev);
  1363. int err;
  1364. err = tegra_dma_init_hw(tdma);
  1365. if (err)
  1366. return err;
  1367. return pm_runtime_force_resume(dev);
  1368. }
  1369. static const struct dev_pm_ops tegra_dma_dev_pm_ops = {
  1370. SET_RUNTIME_PM_OPS(tegra_dma_runtime_suspend, tegra_dma_runtime_resume,
  1371. NULL)
  1372. SET_SYSTEM_SLEEP_PM_OPS(tegra_dma_dev_suspend, tegra_dma_dev_resume)
  1373. };
  1374. static const struct of_device_id tegra_dma_of_match[] = {
  1375. {
  1376. .compatible = "nvidia,tegra148-apbdma",
  1377. .data = &tegra148_dma_chip_data,
  1378. }, {
  1379. .compatible = "nvidia,tegra114-apbdma",
  1380. .data = &tegra114_dma_chip_data,
  1381. }, {
  1382. .compatible = "nvidia,tegra30-apbdma",
  1383. .data = &tegra30_dma_chip_data,
  1384. }, {
  1385. .compatible = "nvidia,tegra20-apbdma",
  1386. .data = &tegra20_dma_chip_data,
  1387. }, {
  1388. },
  1389. };
  1390. MODULE_DEVICE_TABLE(of, tegra_dma_of_match);
  1391. static struct platform_driver tegra_dmac_driver = {
  1392. .driver = {
  1393. .name = "tegra-apbdma",
  1394. .pm = &tegra_dma_dev_pm_ops,
  1395. .of_match_table = tegra_dma_of_match,
  1396. },
  1397. .probe = tegra_dma_probe,
  1398. .remove_new = tegra_dma_remove,
  1399. };
  1400. module_platform_driver(tegra_dmac_driver);
  1401. MODULE_DESCRIPTION("NVIDIA Tegra APB DMA Controller driver");
  1402. MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
  1403. MODULE_LICENSE("GPL v2");