dma.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * arch/arm/mach-tegra/include/mach/dma.h
  3. *
  4. * Copyright (c) 2008-2009, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef __MACH_TEGRA_DMA_H
  21. #define __MACH_TEGRA_DMA_H
  22. #include <linux/list.h>
  23. #if defined(CONFIG_TEGRA_SYSTEM_DMA)
  24. struct tegra_dma_req;
  25. struct tegra_dma_channel;
  26. #define TEGRA_DMA_REQ_SEL_CNTR 0
  27. #define TEGRA_DMA_REQ_SEL_I2S_2 1
  28. #define TEGRA_DMA_REQ_SEL_I2S_1 2
  29. #define TEGRA_DMA_REQ_SEL_SPD_I 3
  30. #define TEGRA_DMA_REQ_SEL_UI_I 4
  31. #define TEGRA_DMA_REQ_SEL_MIPI 5
  32. #define TEGRA_DMA_REQ_SEL_I2S2_2 6
  33. #define TEGRA_DMA_REQ_SEL_I2S2_1 7
  34. #define TEGRA_DMA_REQ_SEL_UARTA 8
  35. #define TEGRA_DMA_REQ_SEL_UARTB 9
  36. #define TEGRA_DMA_REQ_SEL_UARTC 10
  37. #define TEGRA_DMA_REQ_SEL_SPI 11
  38. #define TEGRA_DMA_REQ_SEL_AC97 12
  39. #define TEGRA_DMA_REQ_SEL_ACMODEM 13
  40. #define TEGRA_DMA_REQ_SEL_SL4B 14
  41. #define TEGRA_DMA_REQ_SEL_SL2B1 15
  42. #define TEGRA_DMA_REQ_SEL_SL2B2 16
  43. #define TEGRA_DMA_REQ_SEL_SL2B3 17
  44. #define TEGRA_DMA_REQ_SEL_SL2B4 18
  45. #define TEGRA_DMA_REQ_SEL_UARTD 19
  46. #define TEGRA_DMA_REQ_SEL_UARTE 20
  47. #define TEGRA_DMA_REQ_SEL_I2C 21
  48. #define TEGRA_DMA_REQ_SEL_I2C2 22
  49. #define TEGRA_DMA_REQ_SEL_I2C3 23
  50. #define TEGRA_DMA_REQ_SEL_DVC_I2C 24
  51. #define TEGRA_DMA_REQ_SEL_OWR 25
  52. #define TEGRA_DMA_REQ_SEL_INVALID 31
  53. enum tegra_dma_mode {
  54. TEGRA_DMA_SHARED = 1,
  55. TEGRA_DMA_MODE_CONTINOUS = 2,
  56. TEGRA_DMA_MODE_ONESHOT = 4,
  57. };
  58. enum tegra_dma_req_error {
  59. TEGRA_DMA_REQ_SUCCESS = 0,
  60. TEGRA_DMA_REQ_ERROR_ABORTED,
  61. TEGRA_DMA_REQ_INFLIGHT,
  62. };
  63. enum tegra_dma_req_buff_status {
  64. TEGRA_DMA_REQ_BUF_STATUS_EMPTY = 0,
  65. TEGRA_DMA_REQ_BUF_STATUS_HALF_FULL,
  66. TEGRA_DMA_REQ_BUF_STATUS_FULL,
  67. };
  68. struct tegra_dma_req {
  69. struct list_head node;
  70. unsigned int modid;
  71. int instance;
  72. /* Called when the req is complete and from the DMA ISR context.
  73. * When this is called the req structure is no longer queued by
  74. * the DMA channel.
  75. *
  76. * State of the DMA depends on the number of req it has. If there are
  77. * no DMA requests queued up, then it will STOP the DMA. It there are
  78. * more requests in the DMA, then it will queue the next request.
  79. */
  80. void (*complete)(struct tegra_dma_req *req);
  81. /* This is a called from the DMA ISR context when the DMA is still in
  82. * progress and is actively filling same buffer.
  83. *
  84. * In case of continous mode receive, this threshold is 1/2 the buffer
  85. * size. In other cases, this will not even be called as there is no
  86. * hardware support for it.
  87. *
  88. * In the case of continous mode receive, if there is next req already
  89. * queued, DMA programs the HW to use that req when this req is
  90. * completed. If there is no "next req" queued, then DMA ISR doesn't do
  91. * anything before calling this callback.
  92. *
  93. * This is mainly used by the cases, where the clients has queued
  94. * only one req and want to get some sort of DMA threshold
  95. * callback to program the next buffer.
  96. *
  97. */
  98. void (*threshold)(struct tegra_dma_req *req);
  99. /* 1 to copy to memory.
  100. * 0 to copy from the memory to device FIFO */
  101. int to_memory;
  102. void *virt_addr;
  103. unsigned long source_addr;
  104. unsigned long dest_addr;
  105. unsigned long dest_wrap;
  106. unsigned long source_wrap;
  107. unsigned long source_bus_width;
  108. unsigned long dest_bus_width;
  109. unsigned long req_sel;
  110. unsigned int size;
  111. /* Updated by the DMA driver on the conpletion of the request. */
  112. int bytes_transferred;
  113. int status;
  114. /* DMA completion tracking information */
  115. int buffer_status;
  116. /* Client specific data */
  117. void *dev;
  118. };
  119. int tegra_dma_enqueue_req(struct tegra_dma_channel *ch,
  120. struct tegra_dma_req *req);
  121. int tegra_dma_dequeue_req(struct tegra_dma_channel *ch,
  122. struct tegra_dma_req *req);
  123. void tegra_dma_dequeue(struct tegra_dma_channel *ch);
  124. void tegra_dma_flush(struct tegra_dma_channel *ch);
  125. bool tegra_dma_is_req_inflight(struct tegra_dma_channel *ch,
  126. struct tegra_dma_req *req);
  127. bool tegra_dma_is_empty(struct tegra_dma_channel *ch);
  128. struct tegra_dma_channel *tegra_dma_allocate_channel(int mode);
  129. void tegra_dma_free_channel(struct tegra_dma_channel *ch);
  130. int __init tegra_dma_init(void);
  131. #endif
  132. #endif