Commit 664ab2c992d1e06c4381f66c93d2e155fc7722e1

Authored by Vignesh R
Committed by Jagan Teki
1 parent 146bad9619

dma: ti-edma3: Add helper function to support edma3 transfer

Signed-off-by: Vignesh R <vigneshr@ti.com>
Reviewed-by: Jagan Teki <jteki@openedev.com>

Showing 2 changed files with 80 additions and 0 deletions Side-by-side Diff

arch/arm/include/asm/ti-common/ti-edma3.h
... ... @@ -117,6 +117,8 @@
117 117 void edma3_set_transfer_params(u32 base, int slot, int acnt,
118 118 int bcnt, int ccnt, u16 bcnt_rld,
119 119 enum edma3_sync_dimension sync_mode);
  120 +void edma3_transfer(unsigned long edma3_base_addr, unsigned int
  121 + edma_slot_num, void *dst, void *src, size_t len);
120 122  
121 123 #endif
drivers/dma/ti-edma3.c
... ... @@ -382,4 +382,82 @@
382 382 /* Clear the channel map */
383 383 __raw_writel(0, base + EDMA3_QCHMAP(cfg->chnum));
384 384 }
  385 +
  386 +void edma3_transfer(unsigned long edma3_base_addr, unsigned int
  387 + edma_slot_num, void *dst, void *src, size_t len)
  388 +{
  389 + struct edma3_slot_config slot;
  390 + struct edma3_channel_config edma_channel;
  391 + int b_cnt_value = 1;
  392 + int rem_bytes = 0;
  393 + int a_cnt_value = len;
  394 + unsigned int addr = (unsigned int) (dst);
  395 + unsigned int max_acnt = 0x7FFFU;
  396 +
  397 + if (len > max_acnt) {
  398 + b_cnt_value = (len / max_acnt);
  399 + rem_bytes = (len % max_acnt);
  400 + a_cnt_value = max_acnt;
  401 + }
  402 +
  403 + slot.opt = 0;
  404 + slot.src = ((unsigned int) src);
  405 + slot.acnt = a_cnt_value;
  406 + slot.bcnt = b_cnt_value;
  407 + slot.ccnt = 1;
  408 + slot.src_bidx = a_cnt_value;
  409 + slot.dst_bidx = a_cnt_value;
  410 + slot.src_cidx = 0;
  411 + slot.dst_cidx = 0;
  412 + slot.link = EDMA3_PARSET_NULL_LINK;
  413 + slot.bcntrld = 0;
  414 + slot.opt = EDMA3_SLOPT_TRANS_COMP_INT_ENB |
  415 + EDMA3_SLOPT_COMP_CODE(0) |
  416 + EDMA3_SLOPT_STATIC | EDMA3_SLOPT_AB_SYNC;
  417 +
  418 + edma3_slot_configure(edma3_base_addr, edma_slot_num, &slot);
  419 + edma_channel.slot = edma_slot_num;
  420 + edma_channel.chnum = 0;
  421 + edma_channel.complete_code = 0;
  422 + /* set event trigger to dst update */
  423 + edma_channel.trigger_slot_word = EDMA3_TWORD(dst);
  424 +
  425 + qedma3_start(edma3_base_addr, &edma_channel);
  426 + edma3_set_dest_addr(edma3_base_addr, edma_channel.slot, addr);
  427 +
  428 + while (edma3_check_for_transfer(edma3_base_addr, &edma_channel))
  429 + ;
  430 + qedma3_stop(edma3_base_addr, &edma_channel);
  431 +
  432 + if (rem_bytes != 0) {
  433 + slot.opt = 0;
  434 + slot.src =
  435 + (b_cnt_value * max_acnt) + ((unsigned int) src);
  436 + slot.acnt = rem_bytes;
  437 + slot.bcnt = 1;
  438 + slot.ccnt = 1;
  439 + slot.src_bidx = rem_bytes;
  440 + slot.dst_bidx = rem_bytes;
  441 + slot.src_cidx = 0;
  442 + slot.dst_cidx = 0;
  443 + slot.link = EDMA3_PARSET_NULL_LINK;
  444 + slot.bcntrld = 0;
  445 + slot.opt = EDMA3_SLOPT_TRANS_COMP_INT_ENB |
  446 + EDMA3_SLOPT_COMP_CODE(0) |
  447 + EDMA3_SLOPT_STATIC | EDMA3_SLOPT_AB_SYNC;
  448 + edma3_slot_configure(edma3_base_addr, edma_slot_num, &slot);
  449 + edma_channel.slot = edma_slot_num;
  450 + edma_channel.chnum = 0;
  451 + edma_channel.complete_code = 0;
  452 + /* set event trigger to dst update */
  453 + edma_channel.trigger_slot_word = EDMA3_TWORD(dst);
  454 +
  455 + qedma3_start(edma3_base_addr, &edma_channel);
  456 + edma3_set_dest_addr(edma3_base_addr, edma_channel.slot, addr +
  457 + (max_acnt * b_cnt_value));
  458 + while (edma3_check_for_transfer(edma3_base_addr, &edma_channel))
  459 + ;
  460 + qedma3_stop(edma3_base_addr, &edma_channel);
  461 + }
  462 +}