bestcomm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Public header for the MPC52xx processor BestComm driver
  3. *
  4. *
  5. * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
  6. * Copyright (C) 2005 Varma Electronics Oy,
  7. * ( by Andrey Volkov <avolkov@varma-el.com> )
  8. * Copyright (C) 2003-2004 MontaVista, Software, Inc.
  9. * ( by Dale Farnsworth <dfarnsworth@mvista.com> )
  10. *
  11. * This file is licensed under the terms of the GNU General Public License
  12. * version 2. This program is licensed "as is" without any warranty of any
  13. * kind, whether express or implied.
  14. */
  15. #ifndef __BESTCOMM_H__
  16. #define __BESTCOMM_H__
  17. struct bcom_bd; /* defined later on ... */
  18. /* ======================================================================== */
  19. /* Generic task management */
  20. /* ======================================================================== */
  21. /**
  22. * struct bcom_task - Structure describing a loaded BestComm task
  23. *
  24. * This structure is never built by the driver it self. It's built and
  25. * filled the intermediate layer of the BestComm API, the task dependent
  26. * support code.
  27. *
  28. * Most likely you don't need to poke around inside this structure. The
  29. * fields are exposed in the header just for the sake of inline functions
  30. */
  31. struct bcom_task {
  32. unsigned int tasknum;
  33. unsigned int flags;
  34. int irq;
  35. struct bcom_bd *bd;
  36. phys_addr_t bd_pa;
  37. void **cookie;
  38. unsigned short index;
  39. unsigned short outdex;
  40. unsigned int num_bd;
  41. unsigned int bd_size;
  42. void* priv;
  43. };
  44. #define BCOM_FLAGS_NONE 0x00000000ul
  45. #define BCOM_FLAGS_ENABLE_TASK (1ul << 0)
  46. /**
  47. * bcom_enable - Enable a BestComm task
  48. * @tsk: The BestComm task structure
  49. *
  50. * This function makes sure the given task is enabled and can be run
  51. * by the BestComm engine as needed
  52. */
  53. extern void bcom_enable(struct bcom_task *tsk);
  54. /**
  55. * bcom_disable - Disable a BestComm task
  56. * @tsk: The BestComm task structure
  57. *
  58. * This function disable a given task, making sure it's not executed
  59. * by the BestComm engine.
  60. */
  61. extern void bcom_disable(struct bcom_task *tsk);
  62. /**
  63. * bcom_get_task_irq - Returns the irq number of a BestComm task
  64. * @tsk: The BestComm task structure
  65. */
  66. static inline int
  67. bcom_get_task_irq(struct bcom_task *tsk) {
  68. return tsk->irq;
  69. }
  70. /* ======================================================================== */
  71. /* BD based tasks helpers */
  72. /* ======================================================================== */
  73. /**
  74. * struct bcom_bd - Structure describing a generic BestComm buffer descriptor
  75. * @status: The current status of this buffer. Exact meaning depends on the
  76. * task type
  77. * @data: An array of u32 whose meaning depends on the task type.
  78. */
  79. struct bcom_bd {
  80. u32 status;
  81. u32 data[1]; /* variable, but at least 1 */
  82. };
  83. #define BCOM_BD_READY 0x40000000ul
  84. /** _bcom_next_index - Get next input index.
  85. * @tsk: pointer to task structure
  86. *
  87. * Support function; Device drivers should not call this
  88. */
  89. static inline int
  90. _bcom_next_index(struct bcom_task *tsk)
  91. {
  92. return ((tsk->index + 1) == tsk->num_bd) ? 0 : tsk->index + 1;
  93. }
  94. /** _bcom_next_outdex - Get next output index.
  95. * @tsk: pointer to task structure
  96. *
  97. * Support function; Device drivers should not call this
  98. */
  99. static inline int
  100. _bcom_next_outdex(struct bcom_task *tsk)
  101. {
  102. return ((tsk->outdex + 1) == tsk->num_bd) ? 0 : tsk->outdex + 1;
  103. }
  104. /**
  105. * bcom_queue_empty - Checks if a BestComm task BD queue is empty
  106. * @tsk: The BestComm task structure
  107. */
  108. static inline int
  109. bcom_queue_empty(struct bcom_task *tsk)
  110. {
  111. return tsk->index == tsk->outdex;
  112. }
  113. /**
  114. * bcom_queue_full - Checks if a BestComm task BD queue is full
  115. * @tsk: The BestComm task structure
  116. */
  117. static inline int
  118. bcom_queue_full(struct bcom_task *tsk)
  119. {
  120. return tsk->outdex == _bcom_next_index(tsk);
  121. }
  122. /**
  123. * bcom_buffer_done - Checks if a BestComm
  124. * @tsk: The BestComm task structure
  125. */
  126. static inline int
  127. bcom_buffer_done(struct bcom_task *tsk)
  128. {
  129. if (bcom_queue_empty(tsk))
  130. return 0;
  131. return !(tsk->bd[tsk->outdex].status & BCOM_BD_READY);
  132. }
  133. /**
  134. * bcom_prepare_next_buffer - clear status of next available buffer.
  135. * @tsk: The BestComm task structure
  136. *
  137. * Returns pointer to next buffer descriptor
  138. */
  139. static inline struct bcom_bd *
  140. bcom_prepare_next_buffer(struct bcom_task *tsk)
  141. {
  142. tsk->bd[tsk->index].status = 0; /* cleanup last status */
  143. return &tsk->bd[tsk->index];
  144. }
  145. static inline void
  146. bcom_submit_next_buffer(struct bcom_task *tsk, void *cookie)
  147. {
  148. tsk->cookie[tsk->index] = cookie;
  149. mb(); /* ensure the bd is really up-to-date */
  150. tsk->bd[tsk->index].status |= BCOM_BD_READY;
  151. tsk->index = _bcom_next_index(tsk);
  152. if (tsk->flags & BCOM_FLAGS_ENABLE_TASK)
  153. bcom_enable(tsk);
  154. }
  155. static inline void *
  156. bcom_retrieve_buffer(struct bcom_task *tsk, u32 *p_status, struct bcom_bd **p_bd)
  157. {
  158. void *cookie = tsk->cookie[tsk->outdex];
  159. if (p_status)
  160. *p_status = tsk->bd[tsk->outdex].status;
  161. if (p_bd)
  162. *p_bd = &tsk->bd[tsk->outdex];
  163. tsk->outdex = _bcom_next_outdex(tsk);
  164. return cookie;
  165. }
  166. #endif /* __BESTCOMM_H__ */