msm_vidc_v4l2.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include "msm_vidc_v4l2.h"
  6. #include "msm_vidc_internal.h"
  7. #include "msm_vidc_core.h"
  8. #include "msm_vidc_inst.h"
  9. #include "msm_vidc_debug.h"
  10. #include "msm_vidc.h"
  11. static struct msm_vidc_inst *get_vidc_inst(struct file *filp, void *fh)
  12. {
  13. if (!filp || !filp->private_data)
  14. return NULL;
  15. return container_of(filp->private_data,
  16. struct msm_vidc_inst, event_handler);
  17. }
  18. unsigned int msm_v4l2_poll(struct file *filp, struct poll_table_struct *pt)
  19. {
  20. struct msm_vidc_inst *vidc_inst = get_vidc_inst(filp, NULL);
  21. return msm_vidc_poll((void *)vidc_inst, filp, pt);
  22. }
  23. int msm_v4l2_open(struct file *filp)
  24. {
  25. struct video_device *vdev = video_devdata(filp);
  26. struct msm_video_device *vid_dev =
  27. container_of(vdev, struct msm_video_device, vdev);
  28. struct msm_vidc_core *core = video_drvdata(filp);
  29. struct msm_vidc_inst *vidc_inst;
  30. vidc_inst = msm_vidc_open(core, vid_dev->type);
  31. if (!vidc_inst) {
  32. d_vpr_e("Failed to create instance, type = %d\n",
  33. vid_dev->type);
  34. return -ENOMEM;
  35. }
  36. clear_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags);
  37. filp->private_data = &(vidc_inst->event_handler);
  38. return 0;
  39. }
  40. int msm_v4l2_close(struct file *filp)
  41. {
  42. int rc = 0;
  43. struct msm_vidc_inst *vidc_inst;
  44. vidc_inst = get_vidc_inst(filp, NULL);
  45. rc = msm_vidc_close(vidc_inst);
  46. filp->private_data = NULL;
  47. return rc;
  48. }
  49. int msm_v4l2_querycap(struct file *filp, void *fh,
  50. struct v4l2_capability *cap)
  51. {
  52. struct msm_vidc_inst *vidc_inst = get_vidc_inst(filp, fh);
  53. return msm_vidc_querycap((void *)vidc_inst, cap);
  54. }
  55. int msm_v4l2_enum_fmt(struct file *file, void *fh,
  56. struct v4l2_fmtdesc *f)
  57. {
  58. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  59. return msm_vidc_enum_fmt((void *)vidc_inst, f);
  60. }
  61. int msm_v4l2_s_fmt(struct file *file, void *fh,
  62. struct v4l2_format *f)
  63. {
  64. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  65. return msm_vidc_s_fmt((void *)vidc_inst, f);
  66. }
  67. int msm_v4l2_g_fmt(struct file *file, void *fh,
  68. struct v4l2_format *f)
  69. {
  70. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  71. return msm_vidc_g_fmt((void *)vidc_inst, f);
  72. }
  73. int msm_v4l2_s_selection(struct file* file, void* fh,
  74. struct v4l2_selection* s)
  75. {
  76. struct msm_vidc_inst* vidc_inst = get_vidc_inst(file, fh);
  77. return msm_vidc_s_selection((void*)vidc_inst, s);
  78. }
  79. int msm_v4l2_g_selection(struct file* file, void* fh,
  80. struct v4l2_selection* s)
  81. {
  82. struct msm_vidc_inst* vidc_inst = get_vidc_inst(file, fh);
  83. return msm_vidc_g_selection((void*)vidc_inst, s);
  84. }
  85. int msm_v4l2_s_parm(struct file *file, void *fh,
  86. struct v4l2_streamparm *a)
  87. {
  88. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  89. return msm_vidc_s_param((void *)vidc_inst, a);
  90. }
  91. int msm_v4l2_g_parm(struct file *file, void *fh,
  92. struct v4l2_streamparm *a)
  93. {
  94. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  95. return msm_vidc_g_param((void *)vidc_inst, a);
  96. }
  97. int msm_v4l2_s_ctrl(struct file *file, void *fh,
  98. struct v4l2_control *a)
  99. {
  100. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  101. return msm_vidc_s_ctrl((void *)vidc_inst, a);
  102. }
  103. int msm_v4l2_g_ctrl(struct file *file, void *fh,
  104. struct v4l2_control *a)
  105. {
  106. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  107. return msm_vidc_g_ctrl((void *)vidc_inst, a);
  108. }
  109. int msm_v4l2_reqbufs(struct file *file, void *fh,
  110. struct v4l2_requestbuffers *b)
  111. {
  112. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  113. return msm_vidc_reqbufs((void *)vidc_inst, b);
  114. }
  115. int msm_v4l2_qbuf(struct file *file, void *fh,
  116. struct v4l2_buffer *b)
  117. {
  118. struct video_device *vdev = video_devdata(file);
  119. return msm_vidc_qbuf(get_vidc_inst(file, fh), vdev->v4l2_dev->mdev, b);
  120. }
  121. int msm_v4l2_dqbuf(struct file *file, void *fh,
  122. struct v4l2_buffer *b)
  123. {
  124. return msm_vidc_dqbuf(get_vidc_inst(file, fh), b);
  125. }
  126. int msm_v4l2_streamon(struct file *file, void *fh,
  127. enum v4l2_buf_type i)
  128. {
  129. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  130. return msm_vidc_streamon((void *)vidc_inst, i);
  131. }
  132. int msm_v4l2_streamoff(struct file *file, void *fh,
  133. enum v4l2_buf_type i)
  134. {
  135. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  136. return msm_vidc_streamoff((void *)vidc_inst, i);
  137. }
  138. int msm_v4l2_subscribe_event(struct v4l2_fh *fh,
  139. const struct v4l2_event_subscription *sub)
  140. {
  141. struct msm_vidc_inst *vidc_inst = container_of(fh,
  142. struct msm_vidc_inst, event_handler);
  143. return msm_vidc_subscribe_event((void *)vidc_inst, sub);
  144. }
  145. int msm_v4l2_unsubscribe_event(struct v4l2_fh *fh,
  146. const struct v4l2_event_subscription *sub)
  147. {
  148. struct msm_vidc_inst *vidc_inst = container_of(fh,
  149. struct msm_vidc_inst, event_handler);
  150. return msm_vidc_unsubscribe_event((void *)vidc_inst, sub);
  151. }
  152. int msm_v4l2_decoder_cmd(struct file *file, void *fh,
  153. struct v4l2_decoder_cmd *dec)
  154. {
  155. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  156. return msm_vidc_cmd((void *)vidc_inst, (union msm_v4l2_cmd *)dec);
  157. }
  158. int msm_v4l2_encoder_cmd(struct file *file, void *fh,
  159. struct v4l2_encoder_cmd *enc)
  160. {
  161. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  162. return msm_vidc_cmd((void *)vidc_inst, (union msm_v4l2_cmd *)enc);
  163. }
  164. int msm_v4l2_enum_framesizes(struct file *file, void *fh,
  165. struct v4l2_frmsizeenum *fsize)
  166. {
  167. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  168. return msm_vidc_enum_framesizes((void *)vidc_inst, fsize);
  169. }
  170. int msm_v4l2_enum_frameintervals(struct file *file, void *fh,
  171. struct v4l2_frmivalenum *fival)
  172. {
  173. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  174. return msm_vidc_enum_frameintervals((void *)vidc_inst, fival);
  175. }
  176. int msm_v4l2_queryctrl(struct file *file, void *fh,
  177. struct v4l2_queryctrl *ctrl)
  178. {
  179. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  180. return msm_vidc_query_ctrl((void *)vidc_inst, ctrl);
  181. }
  182. int msm_v4l2_querymenu(struct file *file, void *fh,
  183. struct v4l2_querymenu *qmenu)
  184. {
  185. struct msm_vidc_inst *vidc_inst = get_vidc_inst(file, fh);
  186. return msm_vidc_query_menu((void *)vidc_inst, qmenu);
  187. }