diff options
author | Simon Glass <sjg@chromium.org> | 2012-06-26 16:12:29 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-02 12:24:44 -0700 |
commit | 79353032e02c89b851d2edead6e435caab69c85a (patch) | |
tree | 2701799e08e14d84ab3bf8f24789f18832f60436 | |
parent | 1c0f99d13f8bae1cf25e268364ea2749cee49d01 (diff) | |
download | chrome-ec-79353032e02c89b851d2edead6e435caab69c85a.tar.gz |
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>
-rw-r--r-- | chip/stm32/dma.c | 7 | ||||
-rw-r--r-- | chip/stm32/dma.h | 13 |
2 files changed, 20 insertions, 0 deletions
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 @@ -118,6 +118,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 * * @param chan Channel to start (returned from dma_prepare...()) |