vdin_vf.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * VDIN vframe support
  3. *
  4. * Author: Bobby Yang <bo.yang@amlogic.com>
  5. *
  6. * Copyright (C) 2010 Amlogic Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/amports/vframe.h>
  17. #include <linux/amports/vframe_provider.h>
  18. #include <linux/amports/vframe_receiver.h>
  19. #include "tvin_global.h"
  20. #include "vdin_vf.h"
  21. DEFINE_SPINLOCK(vdin_fifo_lock);
  22. static struct vframe_receiver_op_s* vf_receiver = NULL;
  23. static vframe_t *vdin_vf_peek(void);
  24. static vframe_t *vdin_vf_get(void);
  25. static void vdin_vf_put(vframe_t *vf);
  26. vfq_t newframe_q, display_q, recycle_q;
  27. static struct vframe_s vfpool[BT656IN_VF_POOL_SIZE];
  28. static const struct vframe_operations_s vdin_vf_provider =
  29. {
  30. .peek = vdin_vf_peek,
  31. .get = vdin_vf_get,
  32. .put = vdin_vf_put,
  33. };
  34. #define PROVIDER_NAME "vdin"
  35. static struct vframe_provider_s vdin_vf_prov;
  36. static inline void ptr_atomic_wrap_inc(u32 *ptr)
  37. {
  38. u32 i = *ptr;
  39. i++;
  40. if (i >= BT656IN_VF_POOL_SIZE)
  41. i = 0;
  42. *ptr = i;
  43. }
  44. inline bool vfq_empty(vfq_t *q)
  45. {
  46. return (q->rd_index == q->wr_index);
  47. }
  48. #if 1
  49. inline bool vfq_empty_newframe(void)
  50. {
  51. return vfq_empty(&newframe_q);
  52. }
  53. inline bool vfq_empty_display(void)
  54. {
  55. return vfq_empty(&display_q);
  56. }
  57. inline bool vfq_empty_recycle(void)
  58. {
  59. return vfq_empty(&recycle_q);
  60. }
  61. #endif
  62. inline void vfq_push(vfq_t *q, vframe_t *vf)
  63. {
  64. u32 index = q->wr_index;
  65. q->pool[index] = vf;
  66. ptr_atomic_wrap_inc(&q->wr_index);
  67. }
  68. #if 1
  69. inline void vfq_push_newframe(vframe_t *vf)
  70. {
  71. if(vf == NULL)
  72. return;
  73. spin_lock(&vdin_fifo_lock);
  74. vfq_push(&newframe_q, vf);
  75. spin_unlock(&vdin_fifo_lock);
  76. }
  77. inline void vfq_push_display(vframe_t *vf)
  78. {
  79. if(vf == NULL)
  80. return;
  81. spin_lock(&vdin_fifo_lock);
  82. vfq_push(&display_q, vf);
  83. spin_unlock(&vdin_fifo_lock);
  84. }
  85. inline void vfq_push_recycle(vframe_t *vf)
  86. {
  87. if(vf == NULL)
  88. return;
  89. spin_lock(&vdin_fifo_lock);
  90. vfq_push(&recycle_q, vf);
  91. spin_unlock(&vdin_fifo_lock);
  92. }
  93. #endif
  94. inline vframe_t *vfq_pop(vfq_t *q)
  95. {
  96. vframe_t *vf;
  97. if (vfq_empty(q))
  98. return NULL;
  99. vf = q->pool[q->rd_index];
  100. ptr_atomic_wrap_inc(&q->rd_index);
  101. return vf;
  102. }
  103. #if 1
  104. inline vframe_t *vfq_pop_newframe(void)
  105. {
  106. vframe_t *vf;
  107. spin_lock(&vdin_fifo_lock);
  108. vf = vfq_pop(&newframe_q);
  109. spin_unlock(&vdin_fifo_lock);
  110. return vf;
  111. }
  112. inline vframe_t *vfq_pop_display(void)
  113. {
  114. vframe_t *vf;
  115. spin_lock(&vdin_fifo_lock);
  116. vf = vfq_pop(&display_q);
  117. spin_unlock(&vdin_fifo_lock);
  118. return vf;
  119. }
  120. inline vframe_t *vfq_pop_recycle(void)
  121. {
  122. vframe_t *vf;
  123. spin_lock(&vdin_fifo_lock);
  124. vf = vfq_pop(&recycle_q);
  125. spin_unlock(&vdin_fifo_lock);
  126. return vf;
  127. }
  128. #endif
  129. static inline vframe_t *vfq_peek(vfq_t *q)
  130. {
  131. if (vfq_empty(q))
  132. return NULL;
  133. return q->pool[q->rd_index];
  134. }
  135. static inline void vfq_init(vfq_t *q)
  136. {
  137. q->rd_index = q->wr_index = 0;
  138. }
  139. void vdin_vf_init(void)
  140. {
  141. int i;
  142. vfq_init(&display_q);
  143. vfq_init(&recycle_q);
  144. vfq_init(&newframe_q);
  145. vf_provider_init(&vdin_vf_prov, PROVIDER_NAME ,&vdin_vf_provider, NULL);
  146. for (i = 0; i < (BT656IN_VF_POOL_SIZE ); ++i)
  147. {
  148. vfq_push(&newframe_q, &vfpool[i]);
  149. }
  150. newframe_q.wr_index = BT656IN_VF_POOL_SIZE -1;
  151. }
  152. static vframe_t *vdin_vf_peek(void)
  153. {
  154. return vfq_peek(&display_q);
  155. }
  156. static vframe_t *vdin_vf_get(void)
  157. {
  158. vframe_t *vf;
  159. //spin_lock(&vdin_fifo_lock);
  160. vf = vfq_pop(&display_q);
  161. //spin_unlock(&vdin_fifo_lock);
  162. return vf;
  163. }
  164. static void vdin_vf_put(vframe_t *vf)
  165. {
  166. //spin_lock(&vdin_fifo_lock);
  167. vfq_push(&recycle_q, vf);
  168. //spin_unlock(&vdin_fifo_lock);
  169. }
  170. void vdin_reg_vf_provider(void)
  171. {
  172. #ifdef CONFIG_AMLOGIC_VIDEOIN_MANAGER
  173. vf_reg_provider(&vdin_vf_prov);
  174. #else
  175. vf_reg_provider(&vdin_vf_prov);
  176. #endif /* CONFIG_AMLOGIC_VIDEOIN_MANAGER */
  177. }
  178. void vdin_unreg_vf_provider(void)
  179. {
  180. #ifdef CONFIG_AMLOGIC_VIDEOIN_MANAGER
  181. vf_unreg_provider(&vdin_vf_prov);
  182. #else
  183. vf_unreg_provider(&vdin_vf_prov);
  184. #endif
  185. }
  186. void vdin_notify_receiver(int type, void* data, void* private_data)
  187. {
  188. if(vf_receiver){
  189. //vf_receiver->event_cb(type ,data ,private_data);
  190. }
  191. }