tegra20-apb-dma.c 44 KB

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