dma.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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(channel, bus) ((bus) * 16 + (channel))
  28. #define MAX_DMA_ADDRESS 0xffffffff
  29. #define MAX_DMA_CHANNELS 32
  30. struct stmp3xxx_dma_command {
  31. u32 next;
  32. u32 cmd;
  33. union {
  34. u32 buf_ptr;
  35. u32 alternate;
  36. };
  37. u32 pio_words[MAX_PIO_WORDS];
  38. };
  39. struct stmp3xxx_dma_descriptor {
  40. struct stmp3xxx_dma_command *command;
  41. dma_addr_t handle;
  42. /* The virtual address of the buffer pointer */
  43. void *virtual_buf_ptr;
  44. /* The next descriptor in a the DMA chain (optional) */
  45. struct stmp3xxx_dma_descriptor *next_descr;
  46. };
  47. struct stmp37xx_circ_dma_chain {
  48. unsigned total_count;
  49. struct stmp3xxx_dma_descriptor *chain;
  50. unsigned free_index;
  51. unsigned free_count;
  52. unsigned active_index;
  53. unsigned active_count;
  54. unsigned cooked_index;
  55. unsigned cooked_count;
  56. int bus;
  57. unsigned channel;
  58. };
  59. static inline struct stmp3xxx_dma_descriptor
  60. *stmp3xxx_dma_circ_get_free_head(struct stmp37xx_circ_dma_chain *chain)
  61. {
  62. return &(chain->chain[chain->free_index]);
  63. }
  64. static inline struct stmp3xxx_dma_descriptor
  65. *stmp3xxx_dma_circ_get_cooked_head(struct stmp37xx_circ_dma_chain *chain)
  66. {
  67. return &(chain->chain[chain->cooked_index]);
  68. }
  69. int stmp3xxx_dma_request(int ch, struct device *dev, const char *name);
  70. int stmp3xxx_dma_release(int ch);
  71. int stmp3xxx_dma_allocate_command(int ch,
  72. struct stmp3xxx_dma_descriptor *descriptor);
  73. int stmp3xxx_dma_free_command(int ch,
  74. struct stmp3xxx_dma_descriptor *descriptor);
  75. void stmp3xxx_dma_continue(int channel, u32 semaphore);
  76. void stmp3xxx_dma_go(int ch, struct stmp3xxx_dma_descriptor *head,
  77. u32 semaphore);
  78. int stmp3xxx_dma_running(int ch);
  79. int stmp3xxx_dma_make_chain(int ch, struct stmp37xx_circ_dma_chain *chain,
  80. struct stmp3xxx_dma_descriptor descriptors[],
  81. unsigned items);
  82. void stmp3xxx_dma_free_chain(struct stmp37xx_circ_dma_chain *chain);
  83. void stmp37xx_circ_clear_chain(struct stmp37xx_circ_dma_chain *chain);
  84. void stmp37xx_circ_advance_free(struct stmp37xx_circ_dma_chain *chain,
  85. unsigned count);
  86. void stmp37xx_circ_advance_active(struct stmp37xx_circ_dma_chain *chain,
  87. unsigned count);
  88. unsigned stmp37xx_circ_advance_cooked(struct stmp37xx_circ_dma_chain *chain);
  89. int stmp3xxx_dma_read_semaphore(int ch);
  90. void stmp3xxx_dma_init(void);
  91. void stmp3xxx_dma_set_alt_target(int ch, int target);
  92. void stmp3xxx_dma_suspend(void);
  93. void stmp3xxx_dma_resume(void);
  94. /*
  95. * STMP37xx and STMP378x have different DMA control
  96. * registers layout
  97. */
  98. void stmp3xxx_arch_dma_freeze(int ch);
  99. void stmp3xxx_arch_dma_unfreeze(int ch);
  100. void stmp3xxx_arch_dma_reset_channel(int ch);
  101. void stmp3xxx_arch_dma_enable_interrupt(int ch);
  102. void stmp3xxx_arch_dma_clear_interrupt(int ch);
  103. int stmp3xxx_arch_dma_is_interrupt(int ch);
  104. static inline void stmp3xxx_dma_reset_channel(int ch)
  105. {
  106. stmp3xxx_arch_dma_reset_channel(ch);
  107. }
  108. static inline void stmp3xxx_dma_freeze(int ch)
  109. {
  110. stmp3xxx_arch_dma_freeze(ch);
  111. }
  112. static inline void stmp3xxx_dma_unfreeze(int ch)
  113. {
  114. stmp3xxx_arch_dma_unfreeze(ch);
  115. }
  116. static inline void stmp3xxx_dma_enable_interrupt(int ch)
  117. {
  118. stmp3xxx_arch_dma_enable_interrupt(ch);
  119. }
  120. static inline void stmp3xxx_dma_clear_interrupt(int ch)
  121. {
  122. stmp3xxx_arch_dma_clear_interrupt(ch);
  123. }
  124. static inline int stmp3xxx_dma_is_interrupt(int ch)
  125. {
  126. return stmp3xxx_arch_dma_is_interrupt(ch);
  127. }
  128. #endif /* __ASM_PLAT_STMP3XXX_DMA_H */