1 From 930015dce415e4203daeafb09c24759ac883613e Mon Sep 17 00:00:00 2001
2 From: Martin Sperl <kernel@martin.sperl.org>
3 Date: Wed, 16 Mar 2016 12:25:00 -0700
4 Subject: [PATCH 398/423] dmaengine: bcm2835: limit max length based on channel
7 The bcm2835 dma system has 2 basic types of dma-channels:
11 Lite channels are limited in several aspects:
12 * internal data-structure is 128 bit (not 256)
13 * does not support BCM2835_DMA_TDMODE (2D)
14 * DMA length register is limited to 16 bit.
15 so 0-65535 (not 0-65536 as mentioned in the official datasheet)
16 * BCM2835_DMA_S/D_IGNORE are not supported
18 The detection of the type of mode is implemented by looking at
19 the LITE bit in the DEBUG register for each channel.
20 This allows automatic detection.
22 Based on this the maximum block size is set to (64K - 4) or to 1G
23 and this limit is honored during generation of control block
24 chains. The effect is that when a LITE channel is used more
25 control blocks are used to do the same transfer (compared
28 As there are several sources/target DREQS that are 32 bit wide
29 we need to have the transfer to be a multiple of 4 as this would
30 break the transfer otherwise.
32 This is why the limit of (64K - 4) was chosen over the
33 alternative of (64K - 4K).
35 Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
36 Reviewed-by: Eric Anholt <eric@anholt.net>
37 Signed-off-by: Eric Anholt <eric@anholt.net>
38 Signed-off-by: Vinod Koul <vinod.koul@intel.com>
40 drivers/dma/bcm2835-dma.c | 29 ++++++++++++++++++++++++++---
41 1 file changed, 26 insertions(+), 3 deletions(-)
43 --- a/drivers/dma/bcm2835-dma.c
44 +++ b/drivers/dma/bcm2835-dma.c
45 @@ -81,6 +81,8 @@ struct bcm2835_chan {
47 void __iomem *chan_base;
50 + bool is_lite_channel;
54 @@ -169,6 +171,16 @@ struct bcm2835_desc {
55 #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
56 #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
58 +/* the max dma length for different channels */
59 +#define MAX_DMA_LEN SZ_1G
60 +#define MAX_LITE_DMA_LEN (SZ_64K - 4)
62 +static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c)
64 + /* lite and normal channels have different max frame length */
65 + return c->is_lite_channel ? MAX_LITE_DMA_LEN : MAX_DMA_LEN;
68 /* how many frames of max_len size do we need to transfer len bytes */
69 static inline size_t bcm2835_dma_frames_for_length(size_t len,
71 @@ -217,8 +229,10 @@ static void bcm2835_dma_create_cb_set_le
75 - /* set the length */
76 - control_block->length = len;
77 + size_t max_len = bcm2835_dma_max_frame_length(chan);
79 + /* set the length taking lite-channel limitations into account */
80 + control_block->length = min_t(u32, len, max_len);
82 /* finished if we have no period_length */
84 @@ -544,6 +558,7 @@ static struct dma_async_tx_descriptor *b
86 u32 info = BCM2835_DMA_WAIT_RESP;
87 u32 extra = BCM2835_DMA_INT_EN;
88 + size_t max_len = bcm2835_dma_max_frame_length(c);
91 /* Grab configuration */
92 @@ -586,7 +601,10 @@ static struct dma_async_tx_descriptor *b
95 /* calculate number of frames */
96 - frames = DIV_ROUND_UP(buf_len, period_len);
97 + frames = /* number of periods */
98 + DIV_ROUND_UP(buf_len, period_len) *
99 + /* number of frames per period */
100 + bcm2835_dma_frames_for_length(period_len, max_len);
103 * allocate the CB chain
104 @@ -685,6 +703,11 @@ static int bcm2835_dma_chan_init(struct
108 + /* check in DEBUG register if this is a LITE channel */
109 + if (readl(c->chan_base + BCM2835_DMA_DEBUG) &
110 + BCM2835_DMA_DEBUG_LITE)
111 + c->is_lite_channel = true;