dma.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Freescale STMP37XX/STMP378X DMA helper interface
  3. *
  4. * Embedded Alley Solutions, Inc <source@embeddedalley.com>
  5. *
  6. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  7. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
  8. */
  9. /*
  10. * The code contained herein is licensed under the GNU General Public
  11. * License. You may obtain a copy of the GNU General Public License
  12. * Version 2 or later at the following locations:
  13. *
  14. * http://www.opensource.org/licenses/gpl-license.html
  15. * http://www.gnu.org/copyleft/gpl.html
  16. */
  17. #ifndef __ASM_PLAT_STMP3XXX_DMA_H
  18. #define __ASM_PLAT_STMP3XXX_DMA_H
  19. #include <linux/platform_device.h>
  20. #include <linux/dmapool.h>
  21. #if !defined(MAX_PIO_WORDS)
  22. #define MAX_PIO_WORDS (15)
  23. #endif
  24. #define STMP3XXX_BUS_APBH 0
  25. #define STMP3XXX_BUS_APBX 1
  26. #define STMP3XXX_DMA_MAX_CHANNEL 16
  27. #define STMP3XXX_DMA_BUS(dma) ((dma) / 16)
  28. #define STMP3XXX_DMA_CHANNEL(dma) ((dma) % 16)
  29. #define STMP3XXX_DMA(channel, bus) ((bus) * 16 + (channel))
  30. #define MAX_DMA_ADDRESS 0xffffffff
  31. #define MAX_DMA_CHANNELS 32
  32. struct stmp3xxx_dma_command {
  33. u32 next;
  34. u32 cmd;
  35. union {
  36. u32 buf_ptr;
  37. u32 alternate;
  38. };
  39. u32 pio_words[MAX_PIO_WORDS];
  40. };
  41. struct stmp3xxx_dma_descriptor {
  42. struct stmp3xxx_dma_command *command;
  43. dma_addr_t handle;
  44. /* The virtual address of the buffer pointer */
  45. void *virtual_buf_ptr;
  46. /* The next descriptor in a the DMA chain (optional) */
  47. struct stmp3xxx_dma_descriptor *next_descr;
  48. };
  49. struct stmp37xx_circ_dma_chain {
  50. unsigned total_count;
  51. struct stmp3xxx_dma_descriptor *chain;
  52. unsigned free_index;
  53. unsigned free_count;
  54. unsigned active_index;
  55. unsigned active_count;
  56. unsigned cooked_index;
  57. unsigned cooked_count;
  58. int bus;
  59. unsigned channel;
  60. };
  61. static inline struct stmp3xxx_dma_descriptor
  62. *stmp3xxx_dma_circ_get_free_head(struct stmp37xx_circ_dma_chain *chain)
  63. {
  64. return &(chain->chain[chain->free_index]);
  65. }
  66. static inline struct stmp3xxx_dma_descriptor
  67. *stmp3xxx_dma_circ_get_cooked_head(struct stmp37xx_circ_dma_chain *chain)
  68. {
  69. return &(chain->chain[chain->cooked_index]);
  70. }
  71. int stmp3xxx_dma_request(int ch, struct device *dev, const char *name);
  72. int stmp3xxx_dma_release(int ch);
  73. int stmp3xxx_dma_allocate_command(int ch,
  74. struct stmp3xxx_dma_descriptor *descriptor);
  75. int stmp3xxx_dma_free_command(int ch,
  76. struct stmp3xxx_dma_descriptor *descriptor);
  77. void stmp3xxx_dma_continue(int channel, u32 semaphore);
  78. void stmp3xxx_dma_go(int ch, struct stmp3xxx_dma_descriptor *head,
  79. u32 semaphore);
  80. int stmp3xxx_dma_running(int ch);
  81. int stmp3xxx_dma_make_chain(int ch, struct stmp37xx_circ_dma_chain *chain,
  82. struct stmp3xxx_dma_descriptor descriptors[],
  83. unsigned items);
  84. void stmp3xxx_dma_free_chain(struct stmp37xx_circ_dma_chain *chain);
  85. void stmp37xx_circ_clear_chain(struct stmp37xx_circ_dma_chain *chain);
  86. void stmp37xx_circ_advance_free(struct stmp37xx_circ_dma_chain *chain,
  87. unsigned count);
  88. void stmp37xx_circ_advance_active(struct stmp37xx_circ_dma_chain *chain,
  89. unsigned count);
  90. unsigned stmp37xx_circ_advance_cooked(struct stmp37xx_circ_dma_chain *chain);
  91. int stmp3xxx_dma_read_semaphore(int ch);
  92. void stmp3xxx_dma_init(void);
  93. void stmp3xxx_dma_set_alt_target(int ch, int target);
  94. void stmp3xxx_dma_suspend(void);
  95. void stmp3xxx_dma_resume(void);
  96. /*
  97. * STMP37xx and STMP378x have different DMA control
  98. * registers layout
  99. */
  100. void stmp3xxx_arch_dma_freeze(int ch);
  101. void stmp3xxx_arch_dma_unfreeze(int ch);
  102. void stmp3xxx_arch_dma_reset_channel(int ch);
  103. void stmp3xxx_arch_dma_enable_interrupt(int ch);
  104. void stmp3xxx_arch_dma_clear_interrupt(int ch);
  105. int stmp3xxx_arch_dma_is_interrupt(int ch);
  106. static inline void stmp3xxx_dma_reset_channel(int ch)
  107. {
  108. stmp3xxx_arch_dma_reset_channel(ch);
  109. }
  110. static inline void stmp3xxx_dma_freeze(int ch)
  111. {
  112. stmp3xxx_arch_dma_freeze(ch);
  113. }
  114. static inline void stmp3xxx_dma_unfreeze(int ch)
  115. {
  116. stmp3xxx_arch_dma_unfreeze(ch);
  117. }
  118. static inline void stmp3xxx_dma_enable_interrupt(int ch)
  119. {
  120. stmp3xxx_arch_dma_enable_interrupt(ch);
  121. }
  122. static inline void stmp3xxx_dma_clear_interrupt(int ch)
  123. {
  124. stmp3xxx_arch_dma_clear_interrupt(ch);
  125. }
  126. static inline int stmp3xxx_dma_is_interrupt(int ch)
  127. {
  128. return stmp3xxx_arch_dma_is_interrupt(ch);
  129. }
  130. #endif /* __ASM_PLAT_STMP3XXX_DMA_H */