0398-dmaengine-bcm2835-add-dma_memcopy-support-to-bcm2835.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. From 764cf7045e6338c1ca850ef1fce522b31440dab9 Mon Sep 17 00:00:00 2001
  2. From: Martin Sperl <kernel@martin.sperl.org>
  3. Date: Wed, 16 Mar 2016 12:25:02 -0700
  4. Subject: [PATCH] dmaengine: bcm2835: add dma_memcopy support to bcm2835-dma
  5. Also added check for an error condition in bcm2835_dma_create_cb_chain
  6. that showed up during development of this patch.
  7. Tested using dmatest for all enabled channels.
  8. Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
  9. Reviewed-by: Eric Anholt <eric@anholt.net>
  10. Signed-off-by: Eric Anholt <eric@anholt.net>
  11. Signed-off-by: Vinod Koul <vinod.koul@intel.com>
  12. ---
  13. drivers/dma/bcm2835-dma.c | 36 +++++++++++++++++++++++++++++++++++-
  14. 1 file changed, 35 insertions(+), 1 deletion(-)
  15. --- a/drivers/dma/bcm2835-dma.c
  16. +++ b/drivers/dma/bcm2835-dma.c
  17. @@ -310,6 +310,9 @@ static struct bcm2835_desc *bcm2835_dma_
  18. struct bcm2835_cb_entry *cb_entry;
  19. struct bcm2835_dma_cb *control_block;
  20. + if (!frames)
  21. + return NULL;
  22. +
  23. /* allocate and setup the descriptor. */
  24. d = kzalloc(sizeof(*d) + frames * sizeof(struct bcm2835_cb_entry),
  25. gfp);
  26. @@ -597,6 +600,34 @@ static void bcm2835_dma_issue_pending(st
  27. spin_unlock_irqrestore(&c->vc.lock, flags);
  28. }
  29. +struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_memcpy(
  30. + struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
  31. + size_t len, unsigned long flags)
  32. +{
  33. + struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
  34. + struct bcm2835_desc *d;
  35. + u32 info = BCM2835_DMA_D_INC | BCM2835_DMA_S_INC;
  36. + u32 extra = BCM2835_DMA_INT_EN | BCM2835_DMA_WAIT_RESP;
  37. + size_t max_len = bcm2835_dma_max_frame_length(c);
  38. + size_t frames;
  39. +
  40. + /* if src, dst or len is not given return with an error */
  41. + if (!src || !dst || !len)
  42. + return NULL;
  43. +
  44. + /* calculate number of frames */
  45. + frames = bcm2835_dma_frames_for_length(len, max_len);
  46. +
  47. + /* allocate the CB chain - this also fills in the pointers */
  48. + d = bcm2835_dma_create_cb_chain(chan, DMA_MEM_TO_MEM, false,
  49. + info, extra, frames,
  50. + src, dst, len, 0, GFP_KERNEL);
  51. + if (!d)
  52. + return NULL;
  53. +
  54. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  55. +}
  56. +
  57. static struct dma_async_tx_descriptor *bcm2835_dma_prep_slave_sg(
  58. struct dma_chan *chan,
  59. struct scatterlist *sgl, unsigned int sg_len,
  60. @@ -880,17 +911,20 @@ static int bcm2835_dma_probe(struct plat
  61. dma_cap_set(DMA_PRIVATE, od->ddev.cap_mask);
  62. dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  63. dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  64. + dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask);
  65. od->ddev.device_alloc_chan_resources = bcm2835_dma_alloc_chan_resources;
  66. od->ddev.device_free_chan_resources = bcm2835_dma_free_chan_resources;
  67. od->ddev.device_tx_status = bcm2835_dma_tx_status;
  68. od->ddev.device_issue_pending = bcm2835_dma_issue_pending;
  69. od->ddev.device_prep_dma_cyclic = bcm2835_dma_prep_dma_cyclic;
  70. od->ddev.device_prep_slave_sg = bcm2835_dma_prep_slave_sg;
  71. + od->ddev.device_prep_dma_memcpy = bcm2835_dma_prep_dma_memcpy;
  72. od->ddev.device_config = bcm2835_dma_slave_config;
  73. od->ddev.device_terminate_all = bcm2835_dma_terminate_all;
  74. od->ddev.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  75. od->ddev.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
  76. - od->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  77. + od->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV) |
  78. + BIT(DMA_MEM_TO_MEM);
  79. od->ddev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  80. od->ddev.dev = &pdev->dev;
  81. INIT_LIST_HEAD(&od->ddev.channels);