Commit 40874122 authored by Martin Sperl's avatar Martin Sperl Committed by Vinod Koul

dmaengine: bcm2835: limit max length based on channel type

The bcm2835 dma system has 2 basic types of dma-channels:
* "normal" channels
* "light" channels

Lite channels are limited in several aspects:
* internal data-structure is 128 bit (not 256)
* does not support BCM2835_DMA_TDMODE (2D)
* DMA length register is limited to 16 bit.
  so 0-65535 (not 0-65536 as mentioned in the official datasheet)
* BCM2835_DMA_S/D_IGNORE are not supported

The detection of the type of mode is implemented by looking at
the LITE bit in the DEBUG register for each channel.
This allows automatic detection.

Based on this the maximum block size is set to (64K - 4) or to 1G
and this limit is honored during generation of control block
chains. The effect is that when a LITE channel is used more
control blocks are used to do the same transfer (compared
to a normal channel).

As there are several sources/target DREQS that are 32 bit wide
we need to have the transfer to be a multiple of 4 as this would
break the transfer otherwise.

This is why the limit of (64K - 4) was chosen over the
alternative of (64K - 4K).
Signed-off-by: default avatarMartin Sperl <kernel@martin.sperl.org>
Reviewed-by: default avatarEric Anholt <eric@anholt.net>
Signed-off-by: default avatarEric Anholt <eric@anholt.net>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
parent 92153bb5
...@@ -81,6 +81,8 @@ struct bcm2835_chan { ...@@ -81,6 +81,8 @@ struct bcm2835_chan {
void __iomem *chan_base; void __iomem *chan_base;
int irq_number; int irq_number;
bool is_lite_channel;
}; };
struct bcm2835_desc { struct bcm2835_desc {
...@@ -169,6 +171,16 @@ struct bcm2835_desc { ...@@ -169,6 +171,16 @@ struct bcm2835_desc {
#define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */ #define BCM2835_DMA_CHAN(n) ((n) << 8) /* Base address */
#define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n)) #define BCM2835_DMA_CHANIO(base, n) ((base) + BCM2835_DMA_CHAN(n))
/* the max dma length for different channels */
#define MAX_DMA_LEN SZ_1G
#define MAX_LITE_DMA_LEN (SZ_64K - 4)
static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c)
{
/* lite and normal channels have different max frame length */
return c->is_lite_channel ? MAX_LITE_DMA_LEN : MAX_DMA_LEN;
}
/* how many frames of max_len size do we need to transfer len bytes */ /* how many frames of max_len size do we need to transfer len bytes */
static inline size_t bcm2835_dma_frames_for_length(size_t len, static inline size_t bcm2835_dma_frames_for_length(size_t len,
size_t max_len) size_t max_len)
...@@ -217,8 +229,10 @@ static void bcm2835_dma_create_cb_set_length( ...@@ -217,8 +229,10 @@ static void bcm2835_dma_create_cb_set_length(
size_t *total_len, size_t *total_len,
u32 finalextrainfo) u32 finalextrainfo)
{ {
/* set the length */ size_t max_len = bcm2835_dma_max_frame_length(chan);
control_block->length = len;
/* set the length taking lite-channel limitations into account */
control_block->length = min_t(u32, len, max_len);
/* finished if we have no period_length */ /* finished if we have no period_length */
if (!period_len) if (!period_len)
...@@ -544,6 +558,7 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( ...@@ -544,6 +558,7 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
dma_addr_t src, dst; dma_addr_t src, dst;
u32 info = BCM2835_DMA_WAIT_RESP; u32 info = BCM2835_DMA_WAIT_RESP;
u32 extra = BCM2835_DMA_INT_EN; u32 extra = BCM2835_DMA_INT_EN;
size_t max_len = bcm2835_dma_max_frame_length(c);
size_t frames; size_t frames;
/* Grab configuration */ /* Grab configuration */
...@@ -586,7 +601,10 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic( ...@@ -586,7 +601,10 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
} }
/* calculate number of frames */ /* calculate number of frames */
frames = DIV_ROUND_UP(buf_len, period_len); frames = /* number of periods */
DIV_ROUND_UP(buf_len, period_len) *
/* number of frames per period */
bcm2835_dma_frames_for_length(period_len, max_len);
/* /*
* allocate the CB chain * allocate the CB chain
...@@ -685,6 +703,11 @@ static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq) ...@@ -685,6 +703,11 @@ static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
c->ch = chan_id; c->ch = chan_id;
c->irq_number = irq; c->irq_number = irq;
/* check in DEBUG register if this is a LITE channel */
if (readl(c->chan_base + BCM2835_DMA_DEBUG) &
BCM2835_DMA_DEBUG_LITE)
c->is_lite_channel = true;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment