summaryrefslogtreecommitdiffstats
path: root/drivers/dma/xilinx
diff options
context:
space:
mode:
authorAndrea Merello <andrea.merello@gmail.com>2018-11-20 10:31:45 -0500
committerVinod Koul <vkoul@kernel.org>2019-01-06 23:23:11 -0500
commit616f0f81d857e248a72b5af45ab185196556ae2e (patch)
treeff398f11f99cc86cd14212f6f52332ce11104ba2 /drivers/dma/xilinx
parentbfeffd155283772bbe78c6a05dec7c0128ee500c (diff)
dmaengine: xilinx_dma: commonize DMA copy size calculation
This patch removes a bit of duplicated code by introducing a new function that implements calculations for DMA copy size, and prepares for changes to the copy size calculation that will happen in following patches. Suggested-by: Vinod Koul <vkoul@kernel.org> Signed-off-by: Andrea Merello <andrea.merello@gmail.com> Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
Diffstat (limited to 'drivers/dma/xilinx')
-rw-r--r--drivers/dma/xilinx/xilinx_dma.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c
index 02880963092f..fd9f37bafab0 100644
--- a/drivers/dma/xilinx/xilinx_dma.c
+++ b/drivers/dma/xilinx/xilinx_dma.c
@@ -425,6 +425,7 @@ struct xilinx_dma_config {
425 * @rxs_clk: DMA s2mm stream clock 425 * @rxs_clk: DMA s2mm stream clock
426 * @nr_channels: Number of channels DMA device supports 426 * @nr_channels: Number of channels DMA device supports
427 * @chan_id: DMA channel identifier 427 * @chan_id: DMA channel identifier
428 * @max_buffer_len: Max buffer length
428 */ 429 */
429struct xilinx_dma_device { 430struct xilinx_dma_device {
430 void __iomem *regs; 431 void __iomem *regs;
@@ -444,6 +445,7 @@ struct xilinx_dma_device {
444 struct clk *rxs_clk; 445 struct clk *rxs_clk;
445 u32 nr_channels; 446 u32 nr_channels;
446 u32 chan_id; 447 u32 chan_id;
448 u32 max_buffer_len;
447}; 449};
448 450
449/* Macros */ 451/* Macros */
@@ -960,6 +962,25 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan)
960} 962}
961 963
962/** 964/**
965 * xilinx_dma_calc_copysize - Calculate the amount of data to copy
966 * @chan: Driver specific DMA channel
967 * @size: Total data that needs to be copied
968 * @done: Amount of data that has been already copied
969 *
970 * Return: Amount of data that has to be copied
971 */
972static int xilinx_dma_calc_copysize(struct xilinx_dma_chan *chan,
973 int size, int done)
974{
975 size_t copy;
976
977 copy = min_t(size_t, size - done,
978 chan->xdev->max_buffer_len);
979
980 return copy;
981}
982
983/**
963 * xilinx_dma_tx_status - Get DMA transaction status 984 * xilinx_dma_tx_status - Get DMA transaction status
964 * @dchan: DMA channel 985 * @dchan: DMA channel
965 * @cookie: Transaction identifier 986 * @cookie: Transaction identifier
@@ -992,7 +1013,7 @@ static enum dma_status xilinx_dma_tx_status(struct dma_chan *dchan,
992 list_for_each_entry(segment, &desc->segments, node) { 1013 list_for_each_entry(segment, &desc->segments, node) {
993 hw = &segment->hw; 1014 hw = &segment->hw;
994 residue += (hw->control - hw->status) & 1015 residue += (hw->control - hw->status) &
995 XILINX_DMA_MAX_TRANS_LEN; 1016 chan->xdev->max_buffer_len;
996 } 1017 }
997 } 1018 }
998 spin_unlock_irqrestore(&chan->lock, flags); 1019 spin_unlock_irqrestore(&chan->lock, flags);
@@ -1254,7 +1275,7 @@ static void xilinx_cdma_start_transfer(struct xilinx_dma_chan *chan)
1254 1275
1255 /* Start the transfer */ 1276 /* Start the transfer */
1256 dma_ctrl_write(chan, XILINX_DMA_REG_BTT, 1277 dma_ctrl_write(chan, XILINX_DMA_REG_BTT,
1257 hw->control & XILINX_DMA_MAX_TRANS_LEN); 1278 hw->control & chan->xdev->max_buffer_len);
1258 } 1279 }
1259 1280
1260 list_splice_tail_init(&chan->pending_list, &chan->active_list); 1281 list_splice_tail_init(&chan->pending_list, &chan->active_list);
@@ -1357,7 +1378,7 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan)
1357 1378
1358 /* Start the transfer */ 1379 /* Start the transfer */
1359 dma_ctrl_write(chan, XILINX_DMA_REG_BTT, 1380 dma_ctrl_write(chan, XILINX_DMA_REG_BTT,
1360 hw->control & XILINX_DMA_MAX_TRANS_LEN); 1381 hw->control & chan->xdev->max_buffer_len);
1361 } 1382 }
1362 1383
1363 list_splice_tail_init(&chan->pending_list, &chan->active_list); 1384 list_splice_tail_init(&chan->pending_list, &chan->active_list);
@@ -1718,7 +1739,7 @@ xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst,
1718 struct xilinx_cdma_tx_segment *segment; 1739 struct xilinx_cdma_tx_segment *segment;
1719 struct xilinx_cdma_desc_hw *hw; 1740 struct xilinx_cdma_desc_hw *hw;
1720 1741
1721 if (!len || len > XILINX_DMA_MAX_TRANS_LEN) 1742 if (!len || len > chan->xdev->max_buffer_len)
1722 return NULL; 1743 return NULL;
1723 1744
1724 desc = xilinx_dma_alloc_tx_descriptor(chan); 1745 desc = xilinx_dma_alloc_tx_descriptor(chan);
@@ -1808,8 +1829,8 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg(
1808 * Calculate the maximum number of bytes to transfer, 1829 * Calculate the maximum number of bytes to transfer,
1809 * making sure it is less than the hw limit 1830 * making sure it is less than the hw limit
1810 */ 1831 */
1811 copy = min_t(size_t, sg_dma_len(sg) - sg_used, 1832 copy = xilinx_dma_calc_copysize(chan, sg_dma_len(sg),
1812 XILINX_DMA_MAX_TRANS_LEN); 1833 sg_used);
1813 hw = &segment->hw; 1834 hw = &segment->hw;
1814 1835
1815 /* Fill in the descriptor */ 1836 /* Fill in the descriptor */
@@ -1913,8 +1934,8 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic(
1913 * Calculate the maximum number of bytes to transfer, 1934 * Calculate the maximum number of bytes to transfer,
1914 * making sure it is less than the hw limit 1935 * making sure it is less than the hw limit
1915 */ 1936 */
1916 copy = min_t(size_t, period_len - sg_used, 1937 copy = xilinx_dma_calc_copysize(chan, period_len,
1917 XILINX_DMA_MAX_TRANS_LEN); 1938 sg_used);
1918 hw = &segment->hw; 1939 hw = &segment->hw;
1919 xilinx_axidma_buf(chan, hw, buf_addr, sg_used, 1940 xilinx_axidma_buf(chan, hw, buf_addr, sg_used,
1920 period_len * i); 1941 period_len * i);
@@ -2628,6 +2649,8 @@ static int xilinx_dma_probe(struct platform_device *pdev)
2628 2649
2629 /* Retrieve the DMA engine properties from the device tree */ 2650 /* Retrieve the DMA engine properties from the device tree */
2630 xdev->has_sg = of_property_read_bool(node, "xlnx,include-sg"); 2651 xdev->has_sg = of_property_read_bool(node, "xlnx,include-sg");
2652 xdev->max_buffer_len = XILINX_DMA_MAX_TRANS_LEN;
2653
2631 if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) 2654 if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA)
2632 xdev->mcdma = of_property_read_bool(node, "xlnx,mcdma"); 2655 xdev->mcdma = of_property_read_bool(node, "xlnx,mcdma");
2633 2656