brcm2708: update linux 4.4 patches to latest version
[openwrt/staging/lynxis/omap.git] / target / linux / brcm2708 / patches-4.4 / 0398-dmaengine-bcm2835-limit-max-length-based-on-channel-.patch
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
5 type
6
7 The bcm2835 dma system has 2 basic types of dma-channels:
8 * "normal" channels
9 * "light" channels
10
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
17
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.
21
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
26 to a normal channel).
27
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.
31
32 This is why the limit of (64K - 4) was chosen over the
33 alternative of (64K - 4K).
34
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>
39 ---
40 drivers/dma/bcm2835-dma.c | 29 ++++++++++++++++++++++++++---
41 1 file changed, 26 insertions(+), 3 deletions(-)
42
43 --- a/drivers/dma/bcm2835-dma.c
44 +++ b/drivers/dma/bcm2835-dma.c
45 @@ -81,6 +81,8 @@ struct bcm2835_chan {
46
47 void __iomem *chan_base;
48 int irq_number;
49 +
50 + bool is_lite_channel;
51 };
52
53 struct bcm2835_desc {
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))
57
58 +/* the max dma length for different channels */
59 +#define MAX_DMA_LEN SZ_1G
60 +#define MAX_LITE_DMA_LEN (SZ_64K - 4)
61 +
62 +static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c)
63 +{
64 + /* lite and normal channels have different max frame length */
65 + return c->is_lite_channel ? MAX_LITE_DMA_LEN : MAX_DMA_LEN;
66 +}
67 +
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,
70 size_t max_len)
71 @@ -217,8 +229,10 @@ static void bcm2835_dma_create_cb_set_le
72 size_t *total_len,
73 u32 finalextrainfo)
74 {
75 - /* set the length */
76 - control_block->length = len;
77 + size_t max_len = bcm2835_dma_max_frame_length(chan);
78 +
79 + /* set the length taking lite-channel limitations into account */
80 + control_block->length = min_t(u32, len, max_len);
81
82 /* finished if we have no period_length */
83 if (!period_len)
84 @@ -544,6 +558,7 @@ static struct dma_async_tx_descriptor *b
85 dma_addr_t src, dst;
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);
89 size_t frames;
90
91 /* Grab configuration */
92 @@ -586,7 +601,10 @@ static struct dma_async_tx_descriptor *b
93 }
94
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);
101
102 /*
103 * allocate the CB chain
104 @@ -685,6 +703,11 @@ static int bcm2835_dma_chan_init(struct
105 c->ch = chan_id;
106 c->irq_number = irq;
107
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;
112 +
113 return 0;
114 }
115