tegra20-apb-dma.c 45 KB

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