xref: /rk3399_rockchip-uboot/include/dma.h (revision b625fab7069cab52fd8e0c3dbb25e0d04d020173)
1*a0594cefSMugunthan V N /*
2*a0594cefSMugunthan V N  * (C) Copyright 2015
3*a0594cefSMugunthan V N  *     Texas Instruments Incorporated, <www.ti.com>
4*a0594cefSMugunthan V N  *
5*a0594cefSMugunthan V N  * SPDX-License-Identifier:     GPL-2.0+
6*a0594cefSMugunthan V N  */
7*a0594cefSMugunthan V N 
8*a0594cefSMugunthan V N #ifndef _DMA_H_
9*a0594cefSMugunthan V N #define _DMA_H_
10*a0594cefSMugunthan V N 
11*a0594cefSMugunthan V N /*
12*a0594cefSMugunthan V N  * enum dma_direction - dma transfer direction indicator
13*a0594cefSMugunthan V N  * @DMA_MEM_TO_MEM: Memcpy mode
14*a0594cefSMugunthan V N  * @DMA_MEM_TO_DEV: From Memory to Device
15*a0594cefSMugunthan V N  * @DMA_DEV_TO_MEM: From Device to Memory
16*a0594cefSMugunthan V N  * @DMA_DEV_TO_DEV: From Device to Device
17*a0594cefSMugunthan V N  */
18*a0594cefSMugunthan V N enum dma_direction {
19*a0594cefSMugunthan V N 	DMA_MEM_TO_MEM,
20*a0594cefSMugunthan V N 	DMA_MEM_TO_DEV,
21*a0594cefSMugunthan V N 	DMA_DEV_TO_MEM,
22*a0594cefSMugunthan V N 	DMA_DEV_TO_DEV,
23*a0594cefSMugunthan V N };
24*a0594cefSMugunthan V N 
25*a0594cefSMugunthan V N #define DMA_SUPPORTS_MEM_TO_MEM	BIT(0)
26*a0594cefSMugunthan V N #define DMA_SUPPORTS_MEM_TO_DEV	BIT(1)
27*a0594cefSMugunthan V N #define DMA_SUPPORTS_DEV_TO_MEM	BIT(2)
28*a0594cefSMugunthan V N #define DMA_SUPPORTS_DEV_TO_DEV	BIT(3)
29*a0594cefSMugunthan V N 
30*a0594cefSMugunthan V N /*
31*a0594cefSMugunthan V N  * struct dma_ops - Driver model DMA operations
32*a0594cefSMugunthan V N  *
33*a0594cefSMugunthan V N  * The uclass interface is implemented by all DMA devices which use
34*a0594cefSMugunthan V N  * driver model.
35*a0594cefSMugunthan V N  */
36*a0594cefSMugunthan V N struct dma_ops {
37*a0594cefSMugunthan V N 	/*
38*a0594cefSMugunthan V N 	 * Get the current timer count
39*a0594cefSMugunthan V N 	 *
40*a0594cefSMugunthan V N 	 * @dev: The DMA device
41*a0594cefSMugunthan V N 	 * @direction: direction of data transfer should be one from
42*a0594cefSMugunthan V N 		       enum dma_direction
43*a0594cefSMugunthan V N 	 * @dst: Destination pointer
44*a0594cefSMugunthan V N 	 * @src: Source pointer
45*a0594cefSMugunthan V N 	 * @len: Length of the data to be copied.
46*a0594cefSMugunthan V N 	 * @return: 0 if OK, -ve on error
47*a0594cefSMugunthan V N 	 */
48*a0594cefSMugunthan V N 	int (*transfer)(struct udevice *dev, int direction, void *dst,
49*a0594cefSMugunthan V N 			void *src, size_t len);
50*a0594cefSMugunthan V N };
51*a0594cefSMugunthan V N 
52*a0594cefSMugunthan V N /*
53*a0594cefSMugunthan V N  * struct dma_dev_priv - information about a device used by the uclass
54*a0594cefSMugunthan V N  *
55*a0594cefSMugunthan V N  * @supported: mode of transfers that DMA can support, should be
56*a0594cefSMugunthan V N  *	       one/multiple of DMA_SUPPORTS_*
57*a0594cefSMugunthan V N  */
58*a0594cefSMugunthan V N struct dma_dev_priv {
59*a0594cefSMugunthan V N 	u32 supported;
60*a0594cefSMugunthan V N };
61*a0594cefSMugunthan V N 
62*a0594cefSMugunthan V N /*
63*a0594cefSMugunthan V N  * dma_get_device - get a DMA device which supports transfer
64*a0594cefSMugunthan V N  * type of transfer_type
65*a0594cefSMugunthan V N  *
66*a0594cefSMugunthan V N  * @transfer_type - transfer type should be one/multiple of
67*a0594cefSMugunthan V N  *		    DMA_SUPPORTS_*
68*a0594cefSMugunthan V N  * @devp - udevice pointer to return the found device
69*a0594cefSMugunthan V N  * @return - will return on success and devp will hold the
70*a0594cefSMugunthan V N  *	     pointer to the device
71*a0594cefSMugunthan V N  */
72*a0594cefSMugunthan V N int dma_get_device(u32 transfer_type, struct udevice **devp);
73*a0594cefSMugunthan V N 
74*a0594cefSMugunthan V N /*
75*a0594cefSMugunthan V N  * dma_memcpy - try to use DMA to do a mem copy which will be
76*a0594cefSMugunthan V N  *		much faster than CPU mem copy
77*a0594cefSMugunthan V N  *
78*a0594cefSMugunthan V N  * @dst - destination pointer
79*a0594cefSMugunthan V N  * @src - souce pointer
80*a0594cefSMugunthan V N  * @len - data length to be copied
81*a0594cefSMugunthan V N  * @return - on successful transfer returns no of bytes
82*a0594cefSMugunthan V N 	     transferred and on failure return error code.
83*a0594cefSMugunthan V N  */
84*a0594cefSMugunthan V N int dma_memcpy(void *dst, void *src, size_t len);
85*a0594cefSMugunthan V N 
86*a0594cefSMugunthan V N #endif	/* _DMA_H_ */
87