brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0397-dmaengine-bcm2835-limit-max-length-based-on-channel-.patch
1 From 350247e0611f171a3372386e389e24746daff84f 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] dmaengine: bcm2835: limit max length based on channel type
5
6 The bcm2835 dma system has 2 basic types of dma-channels:
7 * "normal" channels
8 * "light" channels
9
10 Lite channels are limited in several aspects:
11 * internal data-structure is 128 bit (not 256)
12 * does not support BCM2835_DMA_TDMODE (2D)
13 * DMA length register is limited to 16 bit.
14 so 0-65535 (not 0-65536 as mentioned in the official datasheet)
15 * BCM2835_DMA_S/D_IGNORE are not supported
16
17 The detection of the type of mode is implemented by looking at
18 the LITE bit in the DEBUG register for each channel.
19 This allows automatic detection.
20
21 Based on this the maximum block size is set to (64K - 4) or to 1G
22 and this limit is honored during generation of control block
23 chains. The effect is that when a LITE channel is used more
24 control blocks are used to do the same transfer (compared
25 to a normal channel).
26
27 As there are several sources/target DREQS that are 32 bit wide
28 we need to have the transfer to be a multiple of 4 as this would
29 break the transfer otherwise.
30
31 This is why the limit of (64K - 4) was chosen over the
32 alternative of (64K - 4K).
33
34 Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
35 Reviewed-by: Eric Anholt <eric@anholt.net>
36 Signed-off-by: Eric Anholt <eric@anholt.net>
37 Signed-off-by: Vinod Koul <vinod.koul@intel.com>
38 ---
39 drivers/dma/bcm2835-dma.c | 29 ++++++++++++++++++++++++++---
40 1 file changed, 26 insertions(+), 3 deletions(-)
41
42 --- a/drivers/dma/bcm2835-dma.c
43 +++ b/drivers/dma/bcm2835-dma.c
44 @@ -81,6 +81,8 @@ struct bcm2835_chan {
45
46 void __iomem *chan_base;
47 int irq_number;
48 +
49 + bool is_lite_channel;
50 };
51
52 struct bcm2835_desc {
53 @@ -169,6 +171,16 @@ struct bcm2835_desc {
54 #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
55 #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
56
57 +/* the max dma length for different channels */
58 +#define MAX_DMA_LEN SZ_1G
59 +#define MAX_LITE_DMA_LEN (SZ_64K - 4)
60 +
61 +static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c)
62 +{
63 + /* lite and normal channels have different max frame length */
64 + return c->is_lite_channel ? MAX_LITE_DMA_LEN : MAX_DMA_LEN;
65 +}
66 +
67 /* how many frames of max_len size do we need to transfer len bytes */
68 static inline size_t bcm2835_dma_frames_for_length(size_t len,
69 size_t max_len)
70 @@ -217,8 +229,10 @@ static void bcm2835_dma_create_cb_set_le
71 size_t *total_len,
72 u32 finalextrainfo)
73 {
74 - /* set the length */
75 - control_block->length = len;
76 + size_t max_len = bcm2835_dma_max_frame_length(chan);
77 +
78 + /* set the length taking lite-channel limitations into account */
79 + control_block->length = min_t(u32, len, max_len);
80
81 /* finished if we have no period_length */
82 if (!period_len)
83 @@ -544,6 +558,7 @@ static struct dma_async_tx_descriptor *b
84 dma_addr_t src, dst;
85 u32 info = BCM2835_DMA_WAIT_RESP;
86 u32 extra = BCM2835_DMA_INT_EN;
87 + size_t max_len = bcm2835_dma_max_frame_length(c);
88 size_t frames;
89
90 /* Grab configuration */
91 @@ -586,7 +601,10 @@ static struct dma_async_tx_descriptor *b
92 }
93
94 /* calculate number of frames */
95 - frames = DIV_ROUND_UP(buf_len, period_len);
96 + frames = /* number of periods */
97 + DIV_ROUND_UP(buf_len, period_len) *
98 + /* number of frames per period */
99 + bcm2835_dma_frames_for_length(period_len, max_len);
100
101 /*
102 * allocate the CB chain
103 @@ -685,6 +703,11 @@ static int bcm2835_dma_chan_init(struct
104 c->ch = chan_id;
105 c->irq_number = irq;
106
107 + /* check in DEBUG register if this is a LITE channel */
108 + if (readl(c->chan_base + BCM2835_DMA_DEBUG) &
109 + BCM2835_DMA_DEBUG_LITE)
110 + c->is_lite_channel = true;
111 +
112 return 0;
113 }
114