From 79353032e02c89b851d2edead6e435caab69c85a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Jun 2012 16:12:29 -0700 Subject: 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 Reviewed-on: https://gerrit.chromium.org/gerrit/26167 Reviewed-by: David Hendricks --- chip/stm32/dma.c | 7 +++++++ chip/stm32/dma.h | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/chip/stm32/dma.c b/chip/stm32/dma.c index 8325d2edba..fe5bdd55d6 100644 --- a/chip/stm32/dma.c +++ b/chip/stm32/dma.c @@ -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 diff --git a/chip/stm32/dma.h b/chip/stm32/dma.h index 81a4e1edd9..caf6c6228a 100644 --- a/chip/stm32/dma.h +++ b/chip/stm32/dma.h @@ -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 * -- cgit v1.2.1