dma: Add dma_bytes_done() to return bytes completed in a dma channel

By subtracting the current dma count from the number of bytes originally
requested to be transferred, we can find out how many bytes have been
transferred so far.

BUG=chrome-os-partner:10533
TEST=build and boot on snow

Change-Id: Ideee1ed27c08b56882f5d2095341fe04bbe9c34b
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26167
Reviewed-by: David Hendricks <dhendrix@chromium.org>
This commit is contained in:
Simon Glass
2012-06-26 16:12:29 -07:00
committed by Gerrit
parent 1c0f99d13f
commit 79353032e0
2 changed files with 20 additions and 0 deletions

View File

@@ -97,6 +97,13 @@ int dma_start_rx(unsigned channel, unsigned count, void *periph,
return 0;
}
int dma_bytes_done(struct dma_channel *chan, int orig_count)
{
if (!(REG32(&chan->ccr) & DMA_EN))
return 0;
return orig_count - REG32(&chan->cndtr);
}
/* Hide this code behind an undefined CONFIG for now */
#ifdef CONFIG_DMA_TEST

View File

@@ -117,6 +117,19 @@ int dma_start_rx(unsigned channel, unsigned count, void *periph,
*/
void dma_disable(unsigned channel);
/**
* Get the number of bytes available to read, or number of bytes written
*
* Since the DMA controller counts downwards, if we know the starting value
* we can work out how many bytes have been completed so far.
*
* @param chan DMA channel to check (use dma_get_channel())
* @param orig_count Original number of bytes requested on channel
* @return number of bytes completed on a channel, or 0 if this channel is
* not enabled
*/
int dma_bytes_done(struct dma_channel *chan, int orig_count);
/**
* Start a previously-prepared dma channel
*