[U-Boot] [PATCH 3/5] drivers: dma: Factor out dma_get_device from DMA class function
tien.fong.chee at intel.com
tien.fong.chee at intel.com
Thu May 31 08:08:52 UTC 2018
From: Tien Fong Chee <tien.fong.chee at intel.com>
Factor out the dma_get_device from DMA class function so caller can
set some configuration and changes on the DMA device structure which
is return by calling dma_get_device before device instance is processed by
DMA class functions.
Signed-off-by: Tien Fong Chee <tien.fong.chee at intel.com>
---
drivers/dma/dma-uclass.c | 8 +-------
drivers/mtd/spi/spi_flash.c | 9 ++++++++-
include/dma.h | 3 ++-
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c
index cb83c24..5663be8 100644
--- a/drivers/dma/dma-uclass.c
+++ b/drivers/dma/dma-uclass.c
@@ -40,15 +40,9 @@ int dma_get_device(u32 transfer_type, struct udevice **devp)
return ret;
}
-int dma_memcpy(void *dst, void *src, size_t len)
+int dma_memcpy(struct udevice *dev, void *dst, void *src, size_t len)
{
- struct udevice *dev;
const struct dma_ops *ops;
- int ret;
-
- ret = dma_get_device(DMA_SUPPORTS_MEM_TO_MEM, &dev);
- if (ret < 0)
- return ret;
ops = device_get_ops(dev);
if (!ops->transfer)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 2911729..7aa66b6 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -457,7 +457,14 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
void __weak spi_flash_copy_mmap(void *data, void *offset, size_t len)
{
#ifdef CONFIG_DMA
- if (!dma_memcpy(data, offset, len))
+ struct udevice *dev;
+ int ret;
+
+ ret = dma_get_device(DMA_SUPPORTS_MEM_TO_MEM, &dev);
+ if (ret < 0)
+ return;
+
+ if (!dma_memcpy(dev, data, offset, len))
return;
#endif
memcpy(data, offset, len);
diff --git a/include/dma.h b/include/dma.h
index 6bad2264..0a0c9dd 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -75,13 +75,14 @@ int dma_get_device(u32 transfer_type, struct udevice **devp);
* dma_memcpy - try to use DMA to do a mem copy which will be
* much faster than CPU mem copy
*
+ * @dev - The DMA device
* @dst - destination pointer
* @src - souce pointer
* @len - data length to be copied
* @return - on successful transfer returns no of bytes
transferred and on failure return error code.
*/
-int dma_memcpy(void *dst, void *src, size_t len);
+int dma_memcpy(struct udevice *dev, void *dst, void *src, size_t len);
/*
* dma_memcpy_zeroes - Fill up destination with zeros through DMA.
--
2.2.0
More information about the U-Boot
mailing list