dma-uclass.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
  4. * Copyright (C) 2015 - 2018 Texas Instruments Incorporated <www.ti.com>
  5. * Written by Mugunthan V N <mugunthanvnm@ti.com>
  6. *
  7. */
  8. #ifndef _DMA_UCLASS_H
  9. #define _DMA_UCLASS_H
  10. /* See dma.h for background documentation. */
  11. #include <dma.h>
  12. struct ofnode_phandle_args;
  13. /*
  14. * struct dma_ops - Driver model DMA operations
  15. *
  16. * The uclass interface is implemented by all DMA devices which use
  17. * driver model.
  18. */
  19. struct dma_ops {
  20. #ifdef CONFIG_DMA_CHANNELS
  21. /**
  22. * of_xlate - Translate a client's device-tree (OF) DMA specifier.
  23. *
  24. * The DMA core calls this function as the first step in implementing
  25. * a client's dma_get_by_*() call.
  26. *
  27. * If this function pointer is set to NULL, the DMA core will use a
  28. * default implementation, which assumes #dma-cells = <1>, and that
  29. * the DT cell contains a simple integer DMA Channel.
  30. *
  31. * At present, the DMA API solely supports device-tree. If this
  32. * changes, other xxx_xlate() functions may be added to support those
  33. * other mechanisms.
  34. *
  35. * @dma: The dma struct to hold the translation result.
  36. * @args: The dma specifier values from device tree.
  37. * @return 0 if OK, or a negative error code.
  38. */
  39. int (*of_xlate)(struct dma *dma,
  40. struct ofnode_phandle_args *args);
  41. /**
  42. * request - Request a translated DMA.
  43. *
  44. * The DMA core calls this function as the second step in
  45. * implementing a client's dma_get_by_*() call, following a successful
  46. * xxx_xlate() call, or as the only step in implementing a client's
  47. * dma_request() call.
  48. *
  49. * @dma: The DMA struct to request; this has been filled in by
  50. * a previoux xxx_xlate() function call, or by the caller of
  51. * dma_request().
  52. * @return 0 if OK, or a negative error code.
  53. */
  54. int (*request)(struct dma *dma);
  55. /**
  56. * free - Free a previously requested dma.
  57. *
  58. * This is the implementation of the client dma_free() API.
  59. *
  60. * @dma: The DMA to free.
  61. * @return 0 if OK, or a negative error code.
  62. */
  63. int (*free)(struct dma *dma);
  64. /**
  65. * enable() - Enable a DMA Channel.
  66. *
  67. * @dma: The DMA Channel to manipulate.
  68. * @return zero on success, or -ve error code.
  69. */
  70. int (*enable)(struct dma *dma);
  71. /**
  72. * disable() - Disable a DMA Channel.
  73. *
  74. * @dma: The DMA Channel to manipulate.
  75. * @return zero on success, or -ve error code.
  76. */
  77. int (*disable)(struct dma *dma);
  78. /**
  79. * prepare_rcv_buf() - Prepare/Add receive DMA buffer.
  80. *
  81. * @dma: The DMA Channel to manipulate.
  82. * @dst: The receive buffer pointer.
  83. * @size: The receive buffer size
  84. * @return zero on success, or -ve error code.
  85. */
  86. int (*prepare_rcv_buf)(struct dma *dma, void *dst, size_t size);
  87. /**
  88. * receive() - Receive a DMA transfer.
  89. *
  90. * @dma: The DMA Channel to manipulate.
  91. * @dst: The destination pointer.
  92. * @metadata: DMA driver's specific data
  93. * @return zero on success, or -ve error code.
  94. */
  95. int (*receive)(struct dma *dma, void **dst, void *metadata);
  96. /**
  97. * send() - Send a DMA transfer.
  98. *
  99. * @dma: The DMA Channel to manipulate.
  100. * @src: The source pointer.
  101. * @len: Length of the data to be sent (number of bytes).
  102. * @metadata: DMA driver's specific data
  103. * @return zero on success, or -ve error code.
  104. */
  105. int (*send)(struct dma *dma, void *src, size_t len, void *metadata);
  106. #endif /* CONFIG_DMA_CHANNELS */
  107. /**
  108. * transfer() - Issue a DMA transfer. The implementation must
  109. * wait until the transfer is done.
  110. *
  111. * @dev: The DMA device
  112. * @direction: direction of data transfer (should be one from
  113. * enum dma_direction)
  114. * @dst: The destination pointer.
  115. * @src: The source pointer.
  116. * @len: Length of the data to be copied (number of bytes).
  117. * @return zero on success, or -ve error code.
  118. */
  119. int (*transfer)(struct udevice *dev, int direction, void *dst,
  120. void *src, size_t len);
  121. };
  122. #endif /* _DMA_UCLASS_H */