dma.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Freescale i.MX28 APBH DMA
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * Based on code from LTIB:
  8. * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. #ifndef __DMA_H__
  26. #define __DMA_H__
  27. #include <linux/list.h>
  28. #ifndef CONFIG_ARCH_DMA_PIO_WORDS
  29. #define DMA_PIO_WORDS 15
  30. #else
  31. #define DMA_PIO_WORDS CONFIG_ARCH_DMA_PIO_WORDS
  32. #endif
  33. #define MXS_DMA_ALIGNMENT 32
  34. /*
  35. * MXS DMA channels
  36. */
  37. enum {
  38. MXS_DMA_CHANNEL_AHB_APBH_SSP0 = 0,
  39. MXS_DMA_CHANNEL_AHB_APBH_SSP1,
  40. MXS_DMA_CHANNEL_AHB_APBH_SSP2,
  41. MXS_DMA_CHANNEL_AHB_APBH_SSP3,
  42. MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
  43. MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
  44. MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
  45. MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
  46. MXS_DMA_CHANNEL_AHB_APBH_GPMI4,
  47. MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
  48. MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
  49. MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
  50. MXS_DMA_CHANNEL_AHB_APBH_SSP,
  51. MXS_MAX_DMA_CHANNELS,
  52. };
  53. /*
  54. * MXS DMA hardware command.
  55. *
  56. * This structure describes the in-memory layout of an entire DMA command,
  57. * including space for the maximum number of PIO accesses. See the appropriate
  58. * reference manual for a detailed description of what these fields mean to the
  59. * DMA hardware.
  60. */
  61. #define MXS_DMA_DESC_COMMAND_MASK 0x3
  62. #define MXS_DMA_DESC_COMMAND_OFFSET 0
  63. #define MXS_DMA_DESC_COMMAND_NO_DMAXFER 0x0
  64. #define MXS_DMA_DESC_COMMAND_DMA_WRITE 0x1
  65. #define MXS_DMA_DESC_COMMAND_DMA_READ 0x2
  66. #define MXS_DMA_DESC_COMMAND_DMA_SENSE 0x3
  67. #define MXS_DMA_DESC_CHAIN (1 << 2)
  68. #define MXS_DMA_DESC_IRQ (1 << 3)
  69. #define MXS_DMA_DESC_NAND_LOCK (1 << 4)
  70. #define MXS_DMA_DESC_NAND_WAIT_4_READY (1 << 5)
  71. #define MXS_DMA_DESC_DEC_SEM (1 << 6)
  72. #define MXS_DMA_DESC_WAIT4END (1 << 7)
  73. #define MXS_DMA_DESC_HALT_ON_TERMINATE (1 << 8)
  74. #define MXS_DMA_DESC_TERMINATE_FLUSH (1 << 9)
  75. #define MXS_DMA_DESC_PIO_WORDS_MASK (0xf << 12)
  76. #define MXS_DMA_DESC_PIO_WORDS_OFFSET 12
  77. #define MXS_DMA_DESC_BYTES_MASK (0xffff << 16)
  78. #define MXS_DMA_DESC_BYTES_OFFSET 16
  79. struct mxs_dma_cmd {
  80. unsigned long next;
  81. unsigned long data;
  82. union {
  83. dma_addr_t address;
  84. unsigned long alternate;
  85. };
  86. unsigned long pio_words[DMA_PIO_WORDS];
  87. };
  88. /*
  89. * MXS DMA command descriptor.
  90. *
  91. * This structure incorporates an MXS DMA hardware command structure, along
  92. * with metadata.
  93. */
  94. #define MXS_DMA_DESC_FIRST (1 << 0)
  95. #define MXS_DMA_DESC_LAST (1 << 1)
  96. #define MXS_DMA_DESC_READY (1 << 31)
  97. struct mxs_dma_desc {
  98. struct mxs_dma_cmd cmd;
  99. unsigned int flags;
  100. dma_addr_t address;
  101. void *buffer;
  102. struct list_head node;
  103. };
  104. /**
  105. * MXS DMA channel
  106. *
  107. * This structure represents a single DMA channel. The MXS platform code
  108. * maintains an array of these structures to represent every DMA channel in the
  109. * system (see mxs_dma_channels).
  110. */
  111. #define MXS_DMA_FLAGS_IDLE 0
  112. #define MXS_DMA_FLAGS_BUSY (1 << 0)
  113. #define MXS_DMA_FLAGS_FREE 0
  114. #define MXS_DMA_FLAGS_ALLOCATED (1 << 16)
  115. #define MXS_DMA_FLAGS_VALID (1 << 31)
  116. struct mxs_dma_chan {
  117. const char *name;
  118. unsigned long dev;
  119. struct mxs_dma_device *dma;
  120. unsigned int flags;
  121. unsigned int active_num;
  122. unsigned int pending_num;
  123. struct list_head active;
  124. struct list_head done;
  125. };
  126. /* Hardware management ops */
  127. int mxs_dma_enable(int channel);
  128. int mxs_dma_disable(int channel);
  129. int mxs_dma_reset(int channel);
  130. int mxs_dma_freeze(int channel);
  131. int mxs_dma_unfreeze(int channel);
  132. int mxs_dma_read_semaphore(int channel);
  133. int mxs_dma_enable_irq(int channel, int enable);
  134. int mxs_dma_irq_is_pending(int channel);
  135. int mxs_dma_ack_irq(int channel);
  136. /* Channel management ops */
  137. int mxs_dma_request(int channel);
  138. int mxs_dma_release(int channel);
  139. /* Descriptor management ops */
  140. struct mxs_dma_desc *mxs_dma_desc_alloc(void);
  141. void mxs_dma_desc_free(struct mxs_dma_desc *);
  142. unsigned int mxs_dma_cmd_address(struct mxs_dma_desc *desc);
  143. int mxs_dma_desc_pending(struct mxs_dma_desc *pdesc);
  144. int mxs_dma_desc_append(int channel, struct mxs_dma_desc *pdesc);
  145. int mxs_dma_get_finished(int channel, struct list_head *head);
  146. int mxs_dma_finish(int channel, struct list_head *head);
  147. int mxs_dma_wait_complete(uint32_t timeout, unsigned int chan);
  148. int mxs_dma_go(int chan);
  149. int mxs_dma_init(void);
  150. #endif /* __DMA_H__ */