ti-edma3.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Enhanced Direct Memory Access (EDMA3) Controller
  4. *
  5. * (C) Copyright 2014
  6. * Texas Instruments Incorporated, <www.ti.com>
  7. *
  8. * Author: Ivan Khoronzhuk <ivan.khoronzhuk@ti.com>
  9. */
  10. #include <asm/cache.h>
  11. #include <asm/io.h>
  12. #include <common.h>
  13. #include <dm.h>
  14. #include <dma-uclass.h>
  15. #include <linux/dma-mapping.h>
  16. #include <asm/omap_common.h>
  17. #include <asm/ti-common/ti-edma3.h>
  18. #define EDMA3_SL_BASE(slot) (0x4000 + ((slot) << 5))
  19. #define EDMA3_SL_MAX_NUM 512
  20. #define EDMA3_SLOPT_FIFO_WIDTH_MASK (0x7 << 8)
  21. #define EDMA3_QCHMAP(ch) 0x0200 + ((ch) << 2)
  22. #define EDMA3_CHMAP_PARSET_MASK 0x1ff
  23. #define EDMA3_CHMAP_PARSET_SHIFT 0x5
  24. #define EDMA3_CHMAP_TRIGWORD_SHIFT 0x2
  25. #define EDMA3_QEMCR 0x314
  26. #define EDMA3_IPR 0x1068
  27. #define EDMA3_IPRH 0x106c
  28. #define EDMA3_ICR 0x1070
  29. #define EDMA3_ICRH 0x1074
  30. #define EDMA3_QEECR 0x1088
  31. #define EDMA3_QEESR 0x108c
  32. #define EDMA3_QSECR 0x1094
  33. #define EDMA_FILL_BUFFER_SIZE 512
  34. struct ti_edma3_priv {
  35. u32 base;
  36. };
  37. static u8 edma_fill_buffer[EDMA_FILL_BUFFER_SIZE] __aligned(ARCH_DMA_MINALIGN);
  38. /**
  39. * qedma3_start - start qdma on a channel
  40. * @base: base address of edma
  41. * @cfg: pinter to struct edma3_channel_config where you can set
  42. * the slot number to associate with, the chnum, which corresponds
  43. * your quick channel number 0-7, complete code - transfer complete code
  44. * and trigger slot word - which has to correspond to the word number in
  45. * edma3_slot_layout struct for generating event.
  46. *
  47. */
  48. void qedma3_start(u32 base, struct edma3_channel_config *cfg)
  49. {
  50. u32 qchmap;
  51. /* Clear the pending int bit */
  52. if (cfg->complete_code < 32)
  53. __raw_writel(1 << cfg->complete_code, base + EDMA3_ICR);
  54. else
  55. __raw_writel(1 << cfg->complete_code, base + EDMA3_ICRH);
  56. /* Map parameter set and trigger word 7 to quick channel */
  57. qchmap = ((EDMA3_CHMAP_PARSET_MASK & cfg->slot)
  58. << EDMA3_CHMAP_PARSET_SHIFT) |
  59. (cfg->trigger_slot_word << EDMA3_CHMAP_TRIGWORD_SHIFT);
  60. __raw_writel(qchmap, base + EDMA3_QCHMAP(cfg->chnum));
  61. /* Clear missed event if set*/
  62. __raw_writel(1 << cfg->chnum, base + EDMA3_QSECR);
  63. __raw_writel(1 << cfg->chnum, base + EDMA3_QEMCR);
  64. /* Enable qdma channel event */
  65. __raw_writel(1 << cfg->chnum, base + EDMA3_QEESR);
  66. }
  67. /**
  68. * edma3_set_dest - set initial DMA destination address in parameter RAM slot
  69. * @base: base address of edma
  70. * @slot: parameter RAM slot being configured
  71. * @dst: physical address of destination (memory, controller FIFO, etc)
  72. * @addressMode: INCR, except in very rare cases
  73. * @width: ignored unless @addressMode is FIFO, else specifies the
  74. * width to use when addressing the fifo (e.g. W8BIT, W32BIT)
  75. *
  76. * Note that the destination address is modified during the DMA transfer
  77. * according to edma3_set_dest_index().
  78. */
  79. void edma3_set_dest(u32 base, int slot, u32 dst, enum edma3_address_mode mode,
  80. enum edma3_fifo_width width)
  81. {
  82. u32 opt;
  83. struct edma3_slot_layout *rg;
  84. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  85. opt = __raw_readl(&rg->opt);
  86. if (mode == FIFO)
  87. opt = (opt & EDMA3_SLOPT_FIFO_WIDTH_MASK) |
  88. (EDMA3_SLOPT_DST_ADDR_CONST_MODE |
  89. EDMA3_SLOPT_FIFO_WIDTH_SET(width));
  90. else
  91. opt &= ~EDMA3_SLOPT_DST_ADDR_CONST_MODE;
  92. __raw_writel(opt, &rg->opt);
  93. __raw_writel(dst, &rg->dst);
  94. }
  95. /**
  96. * edma3_set_dest_index - configure DMA destination address indexing
  97. * @base: base address of edma
  98. * @slot: parameter RAM slot being configured
  99. * @bidx: byte offset between destination arrays in a frame
  100. * @cidx: byte offset between destination frames in a block
  101. *
  102. * Offsets are specified to support either contiguous or discontiguous
  103. * memory transfers, or repeated access to a hardware register, as needed.
  104. * When accessing hardware registers, both offsets are normally zero.
  105. */
  106. void edma3_set_dest_index(u32 base, unsigned slot, int bidx, int cidx)
  107. {
  108. u32 src_dst_bidx;
  109. u32 src_dst_cidx;
  110. struct edma3_slot_layout *rg;
  111. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  112. src_dst_bidx = __raw_readl(&rg->src_dst_bidx);
  113. src_dst_cidx = __raw_readl(&rg->src_dst_cidx);
  114. __raw_writel((src_dst_bidx & 0x0000ffff) | (bidx << 16),
  115. &rg->src_dst_bidx);
  116. __raw_writel((src_dst_cidx & 0x0000ffff) | (cidx << 16),
  117. &rg->src_dst_cidx);
  118. }
  119. /**
  120. * edma3_set_dest_addr - set destination address for slot only
  121. */
  122. void edma3_set_dest_addr(u32 base, int slot, u32 dst)
  123. {
  124. struct edma3_slot_layout *rg;
  125. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  126. __raw_writel(dst, &rg->dst);
  127. }
  128. /**
  129. * edma3_set_src - set initial DMA source address in parameter RAM slot
  130. * @base: base address of edma
  131. * @slot: parameter RAM slot being configured
  132. * @src_port: physical address of source (memory, controller FIFO, etc)
  133. * @mode: INCR, except in very rare cases
  134. * @width: ignored unless @addressMode is FIFO, else specifies the
  135. * width to use when addressing the fifo (e.g. W8BIT, W32BIT)
  136. *
  137. * Note that the source address is modified during the DMA transfer
  138. * according to edma3_set_src_index().
  139. */
  140. void edma3_set_src(u32 base, int slot, u32 src, enum edma3_address_mode mode,
  141. enum edma3_fifo_width width)
  142. {
  143. u32 opt;
  144. struct edma3_slot_layout *rg;
  145. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  146. opt = __raw_readl(&rg->opt);
  147. if (mode == FIFO)
  148. opt = (opt & EDMA3_SLOPT_FIFO_WIDTH_MASK) |
  149. (EDMA3_SLOPT_DST_ADDR_CONST_MODE |
  150. EDMA3_SLOPT_FIFO_WIDTH_SET(width));
  151. else
  152. opt &= ~EDMA3_SLOPT_DST_ADDR_CONST_MODE;
  153. __raw_writel(opt, &rg->opt);
  154. __raw_writel(src, &rg->src);
  155. }
  156. /**
  157. * edma3_set_src_index - configure DMA source address indexing
  158. * @base: base address of edma
  159. * @slot: parameter RAM slot being configured
  160. * @bidx: byte offset between source arrays in a frame
  161. * @cidx: byte offset between source frames in a block
  162. *
  163. * Offsets are specified to support either contiguous or discontiguous
  164. * memory transfers, or repeated access to a hardware register, as needed.
  165. * When accessing hardware registers, both offsets are normally zero.
  166. */
  167. void edma3_set_src_index(u32 base, unsigned slot, int bidx, int cidx)
  168. {
  169. u32 src_dst_bidx;
  170. u32 src_dst_cidx;
  171. struct edma3_slot_layout *rg;
  172. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  173. src_dst_bidx = __raw_readl(&rg->src_dst_bidx);
  174. src_dst_cidx = __raw_readl(&rg->src_dst_cidx);
  175. __raw_writel((src_dst_bidx & 0xffff0000) | bidx,
  176. &rg->src_dst_bidx);
  177. __raw_writel((src_dst_cidx & 0xffff0000) | cidx,
  178. &rg->src_dst_cidx);
  179. }
  180. /**
  181. * edma3_set_src_addr - set source address for slot only
  182. */
  183. void edma3_set_src_addr(u32 base, int slot, u32 src)
  184. {
  185. struct edma3_slot_layout *rg;
  186. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  187. __raw_writel(src, &rg->src);
  188. }
  189. /**
  190. * edma3_set_transfer_params - configure DMA transfer parameters
  191. * @base: base address of edma
  192. * @slot: parameter RAM slot being configured
  193. * @acnt: how many bytes per array (at least one)
  194. * @bcnt: how many arrays per frame (at least one)
  195. * @ccnt: how many frames per block (at least one)
  196. * @bcnt_rld: used only for A-Synchronized transfers; this specifies
  197. * the value to reload into bcnt when it decrements to zero
  198. * @sync_mode: ASYNC or ABSYNC
  199. *
  200. * See the EDMA3 documentation to understand how to configure and link
  201. * transfers using the fields in PaRAM slots. If you are not doing it
  202. * all at once with edma3_write_slot(), you will use this routine
  203. * plus two calls each for source and destination, setting the initial
  204. * address and saying how to index that address.
  205. *
  206. * An example of an A-Synchronized transfer is a serial link using a
  207. * single word shift register. In that case, @acnt would be equal to
  208. * that word size; the serial controller issues a DMA synchronization
  209. * event to transfer each word, and memory access by the DMA transfer
  210. * controller will be word-at-a-time.
  211. *
  212. * An example of an AB-Synchronized transfer is a device using a FIFO.
  213. * In that case, @acnt equals the FIFO width and @bcnt equals its depth.
  214. * The controller with the FIFO issues DMA synchronization events when
  215. * the FIFO threshold is reached, and the DMA transfer controller will
  216. * transfer one frame to (or from) the FIFO. It will probably use
  217. * efficient burst modes to access memory.
  218. */
  219. void edma3_set_transfer_params(u32 base, int slot, int acnt,
  220. int bcnt, int ccnt, u16 bcnt_rld,
  221. enum edma3_sync_dimension sync_mode)
  222. {
  223. u32 opt;
  224. u32 link_bcntrld;
  225. struct edma3_slot_layout *rg;
  226. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  227. link_bcntrld = __raw_readl(&rg->link_bcntrld);
  228. __raw_writel((bcnt_rld << 16) | (0x0000ffff & link_bcntrld),
  229. &rg->link_bcntrld);
  230. opt = __raw_readl(&rg->opt);
  231. if (sync_mode == ASYNC)
  232. __raw_writel(opt & ~EDMA3_SLOPT_AB_SYNC, &rg->opt);
  233. else
  234. __raw_writel(opt | EDMA3_SLOPT_AB_SYNC, &rg->opt);
  235. /* Set the acount, bcount, ccount registers */
  236. __raw_writel((bcnt << 16) | (acnt & 0xffff), &rg->a_b_cnt);
  237. __raw_writel(0xffff & ccnt, &rg->ccnt);
  238. }
  239. /**
  240. * edma3_write_slot - write parameter RAM data for slot
  241. * @base: base address of edma
  242. * @slot: number of parameter RAM slot being modified
  243. * @param: data to be written into parameter RAM slot
  244. *
  245. * Use this to assign all parameters of a transfer at once. This
  246. * allows more efficient setup of transfers than issuing multiple
  247. * calls to set up those parameters in small pieces, and provides
  248. * complete control over all transfer options.
  249. */
  250. void edma3_write_slot(u32 base, int slot, struct edma3_slot_layout *param)
  251. {
  252. int i;
  253. u32 *p = (u32 *)param;
  254. u32 *addr = (u32 *)(base + EDMA3_SL_BASE(slot));
  255. for (i = 0; i < sizeof(struct edma3_slot_layout)/4; i += 4)
  256. __raw_writel(*p++, addr++);
  257. }
  258. /**
  259. * edma3_read_slot - read parameter RAM data from slot
  260. * @base: base address of edma
  261. * @slot: number of parameter RAM slot being copied
  262. * @param: where to store copy of parameter RAM data
  263. *
  264. * Use this to read data from a parameter RAM slot, perhaps to
  265. * save them as a template for later reuse.
  266. */
  267. void edma3_read_slot(u32 base, int slot, struct edma3_slot_layout *param)
  268. {
  269. int i;
  270. u32 *p = (u32 *)param;
  271. u32 *addr = (u32 *)(base + EDMA3_SL_BASE(slot));
  272. for (i = 0; i < sizeof(struct edma3_slot_layout)/4; i += 4)
  273. *p++ = __raw_readl(addr++);
  274. }
  275. void edma3_slot_configure(u32 base, int slot, struct edma3_slot_config *cfg)
  276. {
  277. struct edma3_slot_layout *rg;
  278. rg = (struct edma3_slot_layout *)(base + EDMA3_SL_BASE(slot));
  279. __raw_writel(cfg->opt, &rg->opt);
  280. __raw_writel(cfg->src, &rg->src);
  281. __raw_writel((cfg->bcnt << 16) | (cfg->acnt & 0xffff), &rg->a_b_cnt);
  282. __raw_writel(cfg->dst, &rg->dst);
  283. __raw_writel((cfg->dst_bidx << 16) |
  284. (cfg->src_bidx & 0xffff), &rg->src_dst_bidx);
  285. __raw_writel((cfg->bcntrld << 16) |
  286. (cfg->link & 0xffff), &rg->link_bcntrld);
  287. __raw_writel((cfg->dst_cidx << 16) |
  288. (cfg->src_cidx & 0xffff), &rg->src_dst_cidx);
  289. __raw_writel(0xffff & cfg->ccnt, &rg->ccnt);
  290. }
  291. /**
  292. * edma3_check_for_transfer - check if transfer coplete by checking
  293. * interrupt pending bit. Clear interrupt pending bit if complete.
  294. * @base: base address of edma
  295. * @cfg: pinter to struct edma3_channel_config which was passed
  296. * to qedma3_start when you started qdma channel
  297. *
  298. * Return 0 if complete, 1 if not.
  299. */
  300. int edma3_check_for_transfer(u32 base, struct edma3_channel_config *cfg)
  301. {
  302. u32 inum;
  303. u32 ipr_base;
  304. u32 icr_base;
  305. if (cfg->complete_code < 32) {
  306. ipr_base = base + EDMA3_IPR;
  307. icr_base = base + EDMA3_ICR;
  308. inum = 1 << cfg->complete_code;
  309. } else {
  310. ipr_base = base + EDMA3_IPRH;
  311. icr_base = base + EDMA3_ICRH;
  312. inum = 1 << (cfg->complete_code - 32);
  313. }
  314. /* check complete interrupt */
  315. if (!(__raw_readl(ipr_base) & inum))
  316. return 1;
  317. /* clean up the pending int bit */
  318. __raw_writel(inum, icr_base);
  319. return 0;
  320. }
  321. /**
  322. * qedma3_stop - stops dma on the channel passed
  323. * @base: base address of edma
  324. * @cfg: pinter to struct edma3_channel_config which was passed
  325. * to qedma3_start when you started qdma channel
  326. */
  327. void qedma3_stop(u32 base, struct edma3_channel_config *cfg)
  328. {
  329. /* Disable qdma channel event */
  330. __raw_writel(1 << cfg->chnum, base + EDMA3_QEECR);
  331. /* clean up the interrupt indication */
  332. if (cfg->complete_code < 32)
  333. __raw_writel(1 << cfg->complete_code, base + EDMA3_ICR);
  334. else
  335. __raw_writel(1 << cfg->complete_code, base + EDMA3_ICRH);
  336. /* Clear missed event if set*/
  337. __raw_writel(1 << cfg->chnum, base + EDMA3_QSECR);
  338. __raw_writel(1 << cfg->chnum, base + EDMA3_QEMCR);
  339. /* Clear the channel map */
  340. __raw_writel(0, base + EDMA3_QCHMAP(cfg->chnum));
  341. }
  342. void __edma3_transfer(unsigned long edma3_base_addr, unsigned int edma_slot_num,
  343. dma_addr_t dst, dma_addr_t src, size_t len, size_t s_len)
  344. {
  345. struct edma3_slot_config slot;
  346. struct edma3_channel_config edma_channel;
  347. int b_cnt_value = 1;
  348. int rem_bytes = 0;
  349. int a_cnt_value = len;
  350. unsigned int addr = (unsigned int) (dst);
  351. unsigned int max_acnt = 0x7FFFU;
  352. if (len > s_len) {
  353. b_cnt_value = (len / s_len);
  354. rem_bytes = (len % s_len);
  355. a_cnt_value = s_len;
  356. } else if (len > max_acnt) {
  357. b_cnt_value = (len / max_acnt);
  358. rem_bytes = (len % max_acnt);
  359. a_cnt_value = max_acnt;
  360. }
  361. slot.opt = 0;
  362. slot.src = ((unsigned int) src);
  363. slot.acnt = a_cnt_value;
  364. slot.bcnt = b_cnt_value;
  365. slot.ccnt = 1;
  366. if (len == s_len)
  367. slot.src_bidx = a_cnt_value;
  368. else
  369. slot.src_bidx = 0;
  370. slot.dst_bidx = a_cnt_value;
  371. slot.src_cidx = 0;
  372. slot.dst_cidx = 0;
  373. slot.link = EDMA3_PARSET_NULL_LINK;
  374. slot.bcntrld = 0;
  375. slot.opt = EDMA3_SLOPT_TRANS_COMP_INT_ENB |
  376. EDMA3_SLOPT_COMP_CODE(0) |
  377. EDMA3_SLOPT_STATIC | EDMA3_SLOPT_AB_SYNC;
  378. edma3_slot_configure(edma3_base_addr, edma_slot_num, &slot);
  379. edma_channel.slot = edma_slot_num;
  380. edma_channel.chnum = 0;
  381. edma_channel.complete_code = 0;
  382. /* set event trigger to dst update */
  383. edma_channel.trigger_slot_word = EDMA3_TWORD(dst);
  384. qedma3_start(edma3_base_addr, &edma_channel);
  385. edma3_set_dest_addr(edma3_base_addr, edma_channel.slot, addr);
  386. while (edma3_check_for_transfer(edma3_base_addr, &edma_channel))
  387. ;
  388. qedma3_stop(edma3_base_addr, &edma_channel);
  389. if (rem_bytes != 0) {
  390. slot.opt = 0;
  391. if (len == s_len)
  392. slot.src =
  393. (b_cnt_value * max_acnt) + ((unsigned int) src);
  394. else
  395. slot.src = (unsigned int) src;
  396. slot.acnt = rem_bytes;
  397. slot.bcnt = 1;
  398. slot.ccnt = 1;
  399. slot.src_bidx = rem_bytes;
  400. slot.dst_bidx = rem_bytes;
  401. slot.src_cidx = 0;
  402. slot.dst_cidx = 0;
  403. slot.link = EDMA3_PARSET_NULL_LINK;
  404. slot.bcntrld = 0;
  405. slot.opt = EDMA3_SLOPT_TRANS_COMP_INT_ENB |
  406. EDMA3_SLOPT_COMP_CODE(0) |
  407. EDMA3_SLOPT_STATIC | EDMA3_SLOPT_AB_SYNC;
  408. edma3_slot_configure(edma3_base_addr, edma_slot_num, &slot);
  409. edma_channel.slot = edma_slot_num;
  410. edma_channel.chnum = 0;
  411. edma_channel.complete_code = 0;
  412. /* set event trigger to dst update */
  413. edma_channel.trigger_slot_word = EDMA3_TWORD(dst);
  414. qedma3_start(edma3_base_addr, &edma_channel);
  415. edma3_set_dest_addr(edma3_base_addr, edma_channel.slot, addr +
  416. (max_acnt * b_cnt_value));
  417. while (edma3_check_for_transfer(edma3_base_addr, &edma_channel))
  418. ;
  419. qedma3_stop(edma3_base_addr, &edma_channel);
  420. }
  421. }
  422. void __edma3_fill(unsigned long edma3_base_addr, unsigned int edma_slot_num,
  423. dma_addr_t dst, u8 val, size_t len)
  424. {
  425. int xfer_len;
  426. int max_xfer = EDMA_FILL_BUFFER_SIZE * 65535;
  427. dma_addr_t source;
  428. memset((void *)edma_fill_buffer, val, sizeof(edma_fill_buffer));
  429. source = dma_map_single(edma_fill_buffer, len, DMA_TO_DEVICE);
  430. while (len) {
  431. xfer_len = len;
  432. if (xfer_len > max_xfer)
  433. xfer_len = max_xfer;
  434. __edma3_transfer(edma3_base_addr, edma_slot_num, dst,
  435. source, xfer_len,
  436. EDMA_FILL_BUFFER_SIZE);
  437. len -= xfer_len;
  438. dst += xfer_len;
  439. }
  440. dma_unmap_single(source, len, DMA_FROM_DEVICE);
  441. }
  442. #ifndef CONFIG_DMA
  443. void edma3_transfer(unsigned long edma3_base_addr, unsigned int edma_slot_num,
  444. void *dst, void *src, size_t len)
  445. {
  446. /* Clean the areas, so no writeback into the RAM races with DMA */
  447. dma_addr_t destination = dma_map_single(dst, len, DMA_FROM_DEVICE);
  448. dma_addr_t source = dma_map_single(src, len, DMA_TO_DEVICE);
  449. __edma3_transfer(edma3_base_addr, edma_slot_num, destination, source, len, len);
  450. /* Clean+Invalidate the areas after, so we can see DMA'd data */
  451. dma_unmap_single(destination, len, DMA_FROM_DEVICE);
  452. dma_unmap_single(source, len, DMA_TO_DEVICE);
  453. }
  454. void edma3_fill(unsigned long edma3_base_addr, unsigned int edma_slot_num,
  455. void *dst, u8 val, size_t len)
  456. {
  457. /* Clean the area, so no writeback into the RAM races with DMA */
  458. dma_addr_t destination = dma_map_single(dst, len, DMA_FROM_DEVICE);
  459. __edma3_fill(edma3_base_addr, edma_slot_num, destination, val, len);
  460. /* Clean+Invalidate the area after, so we can see DMA'd data */
  461. dma_unmap_single(destination, len, DMA_FROM_DEVICE);
  462. }
  463. #else
  464. static int ti_edma3_transfer(struct udevice *dev, int direction,
  465. dma_addr_t dst, dma_addr_t src, size_t len)
  466. {
  467. struct ti_edma3_priv *priv = dev_get_priv(dev);
  468. /* enable edma3 clocks */
  469. enable_edma3_clocks();
  470. switch (direction) {
  471. case DMA_MEM_TO_MEM:
  472. __edma3_transfer(priv->base, 1, dst, src, len, len);
  473. break;
  474. default:
  475. pr_err("Transfer type not implemented in DMA driver\n");
  476. break;
  477. }
  478. /* disable edma3 clocks */
  479. disable_edma3_clocks();
  480. return 0;
  481. }
  482. static int ti_edma3_of_to_plat(struct udevice *dev)
  483. {
  484. struct ti_edma3_priv *priv = dev_get_priv(dev);
  485. priv->base = dev_read_addr(dev);
  486. return 0;
  487. }
  488. static int ti_edma3_probe(struct udevice *dev)
  489. {
  490. struct dma_dev_priv *uc_priv = dev_get_uclass_priv(dev);
  491. uc_priv->supported = DMA_SUPPORTS_MEM_TO_MEM;
  492. return 0;
  493. }
  494. static const struct dma_ops ti_edma3_ops = {
  495. .transfer = ti_edma3_transfer,
  496. };
  497. static const struct udevice_id ti_edma3_ids[] = {
  498. { .compatible = "ti,edma3" },
  499. { }
  500. };
  501. U_BOOT_DRIVER(ti_edma3) = {
  502. .name = "ti_edma3",
  503. .id = UCLASS_DMA,
  504. .of_match = ti_edma3_ids,
  505. .ops = &ti_edma3_ops,
  506. .of_to_plat = ti_edma3_of_to_plat,
  507. .probe = ti_edma3_probe,
  508. .priv_auto = sizeof(struct ti_edma3_priv),
  509. };
  510. #endif /* CONFIG_DMA */