2 * Direct Memory Access U-Class driver
5 * Texas Instruments Incorporated, <www.ti.com>
7 * Author: Mugunthan V N <mugunthanvnm@ti.com>
9 * SPDX-License-Identifier: GPL-2.0+
15 #include <dm/uclass-internal.h>
16 #include <dm/device-internal.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 int dma_get_device(u32 transfer_type, struct udevice **devp)
26 for (ret = uclass_first_device(UCLASS_DMA, &dev); dev && !ret;
27 ret = uclass_next_device(&dev)) {
28 struct dma_dev_priv *uc_priv;
30 uc_priv = dev_get_uclass_priv(dev);
31 if (uc_priv->supported & transfer_type)
36 pr_err("No DMA device found that supports %x type\n",
38 return -EPROTONOSUPPORT;
46 int dma_memcpy(void *dst, void *src, size_t len)
49 const struct dma_ops *ops;
52 ret = dma_get_device(DMA_SUPPORTS_MEM_TO_MEM, &dev);
56 ops = device_get_ops(dev);
60 /* Invalidate the area, so no writeback into the RAM races with DMA */
61 invalidate_dcache_range((unsigned long)dst, (unsigned long)dst +
62 roundup(len, ARCH_DMA_MINALIGN));
64 return ops->transfer(dev, DMA_MEM_TO_MEM, dst, src, len);
67 UCLASS_DRIVER(dma) = {
70 .flags = DM_UC_FLAG_SEQ_ALIAS,
71 .per_device_auto_alloc_size = sizeof(struct dma_dev_priv),