msm_vidc_platform.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/of_platform.h>
  6. #include "msm_vidc_waipio.h"
  7. #include "msm_vidc_platform.h"
  8. #include "msm_vidc_iris2.h"
  9. #include "msm_vidc_debug.h"
  10. #include "msm_vidc_v4l2.h"
  11. #include "msm_vidc_vb2.h"
  12. #include "msm_vidc_control.h"
  13. static struct v4l2_file_operations msm_v4l2_file_operations = {
  14. .owner = THIS_MODULE,
  15. .open = msm_v4l2_open,
  16. .release = msm_v4l2_close,
  17. .unlocked_ioctl = video_ioctl2,
  18. .poll = msm_v4l2_poll,
  19. };
  20. static struct v4l2_ioctl_ops msm_v4l2_ioctl_ops = {
  21. .vidioc_querycap = msm_v4l2_querycap,
  22. .vidioc_enum_fmt_vid_cap = msm_v4l2_enum_fmt,
  23. .vidioc_enum_fmt_vid_out = msm_v4l2_enum_fmt,
  24. .vidioc_enum_framesizes = msm_v4l2_enum_framesizes,
  25. .vidioc_enum_frameintervals = msm_v4l2_enum_frameintervals,
  26. .vidioc_s_fmt_vid_cap = msm_v4l2_s_fmt,
  27. .vidioc_s_fmt_vid_out = msm_v4l2_s_fmt,
  28. .vidioc_s_fmt_vid_cap_mplane = msm_v4l2_s_fmt,
  29. .vidioc_s_fmt_vid_out_mplane = msm_v4l2_s_fmt,
  30. .vidioc_s_fmt_meta_out = msm_v4l2_s_fmt,
  31. .vidioc_s_fmt_meta_cap = msm_v4l2_s_fmt,
  32. .vidioc_g_fmt_vid_cap = msm_v4l2_g_fmt,
  33. .vidioc_g_fmt_vid_out = msm_v4l2_g_fmt,
  34. .vidioc_g_fmt_vid_cap_mplane = msm_v4l2_g_fmt,
  35. .vidioc_g_fmt_vid_out_mplane = msm_v4l2_g_fmt,
  36. .vidioc_g_fmt_meta_out = msm_v4l2_g_fmt,
  37. .vidioc_g_fmt_meta_cap = msm_v4l2_g_fmt,
  38. .vidioc_g_selection = msm_v4l2_g_selection,
  39. .vidioc_s_selection = msm_v4l2_s_selection,
  40. .vidioc_s_parm = msm_v4l2_s_parm,
  41. .vidioc_g_parm = msm_v4l2_g_parm,
  42. .vidioc_reqbufs = msm_v4l2_reqbufs,
  43. .vidioc_qbuf = msm_v4l2_qbuf,
  44. .vidioc_dqbuf = msm_v4l2_dqbuf,
  45. .vidioc_streamon = msm_v4l2_streamon,
  46. .vidioc_streamoff = msm_v4l2_streamoff,
  47. .vidioc_s_ctrl = msm_v4l2_s_ctrl,
  48. .vidioc_g_ctrl = msm_v4l2_g_ctrl,
  49. .vidioc_queryctrl = msm_v4l2_queryctrl,
  50. .vidioc_querymenu = msm_v4l2_querymenu,
  51. .vidioc_subscribe_event = msm_v4l2_subscribe_event,
  52. .vidioc_unsubscribe_event = msm_v4l2_unsubscribe_event,
  53. .vidioc_decoder_cmd = msm_v4l2_decoder_cmd,
  54. .vidioc_encoder_cmd = msm_v4l2_encoder_cmd,
  55. };
  56. static struct v4l2_ctrl_ops msm_v4l2_ctrl_ops = {
  57. .s_ctrl = msm_v4l2_op_s_ctrl,
  58. };
  59. static struct vb2_ops msm_vb2_ops = {
  60. .queue_setup = msm_vidc_queue_setup,
  61. .start_streaming = msm_vidc_start_streaming,
  62. .buf_queue = msm_vidc_buf_queue,
  63. .buf_cleanup = msm_vidc_buf_cleanup,
  64. .stop_streaming = msm_vidc_stop_streaming,
  65. };
  66. static struct vb2_mem_ops msm_vb2_mem_ops = {
  67. .get_userptr = msm_vb2_get_userptr,
  68. .put_userptr = msm_vb2_put_userptr,
  69. .attach_dmabuf = msm_vb2_attach_dmabuf,
  70. .detach_dmabuf = msm_vb2_detach_dmabuf,
  71. .map_dmabuf = msm_vb2_map_dmabuf,
  72. .unmap_dmabuf = msm_vb2_unmap_dmabuf,
  73. };
  74. static int msm_vidc_init_ops(struct msm_vidc_core *core)
  75. {
  76. if (!core) {
  77. d_vpr_e("%s: invalid params\n", __func__);
  78. return -EINVAL;
  79. }
  80. d_vpr_h("%s: initialize ops\n", __func__);
  81. core->v4l2_file_ops = &msm_v4l2_file_operations;
  82. core->v4l2_ioctl_ops = &msm_v4l2_ioctl_ops;
  83. core->v4l2_ctrl_ops = &msm_v4l2_ctrl_ops;
  84. core->vb2_ops = &msm_vb2_ops;
  85. core->vb2_mem_ops = &msm_vb2_mem_ops;
  86. return 0;
  87. }
  88. int msm_vidc_deinit_platform(struct platform_device *pdev)
  89. {
  90. struct msm_vidc_core *core;
  91. if (!pdev) {
  92. d_vpr_e("%s: invalid params\n", __func__);
  93. return -EINVAL;
  94. }
  95. core = dev_get_drvdata(&pdev->dev);
  96. if (!core) {
  97. d_vpr_e("%s: core not found in device %s",
  98. dev_name(&pdev->dev));
  99. return -EINVAL;
  100. }
  101. d_vpr_h("%s()\n", __func__);
  102. if (of_device_is_compatible(pdev->dev.of_node, "qcom,msm-vidc"))
  103. msm_vidc_deinit_iris2(core);
  104. if (of_device_is_compatible(pdev->dev.of_node, "qcom,msm-vidc"))
  105. msm_vidc_deinit_platform_waipio(core);
  106. kfree(core->platform);
  107. return 0;
  108. }
  109. int msm_vidc_init_platform(struct platform_device *pdev)
  110. {
  111. int rc = 0;
  112. struct msm_vidc_platform *platform;
  113. struct msm_vidc_core *core;
  114. if (!pdev) {
  115. d_vpr_e("%s: invalid params\n", __func__);
  116. return -EINVAL;
  117. }
  118. d_vpr_h("%s()\n", __func__);
  119. core = dev_get_drvdata(&pdev->dev);
  120. if (!core) {
  121. d_vpr_e("%s: core not found in device %s",
  122. dev_name(&pdev->dev));
  123. return -EINVAL;
  124. }
  125. platform = kzalloc(sizeof(struct msm_vidc_platform), GFP_KERNEL);
  126. if (!platform)
  127. return -ENOMEM;
  128. core->platform = platform;
  129. platform->core = core;
  130. /* selected ops can be re-assigned in platform specific file */
  131. rc = msm_vidc_init_ops(core);
  132. if (rc)
  133. return rc;
  134. if (of_device_is_compatible(pdev->dev.of_node, "qcom,msm-vidc")) { // "qcom,msm-vidc-waipio"
  135. rc = msm_vidc_init_platform_waipio(core);
  136. if (rc)
  137. return rc;
  138. }
  139. if (of_device_is_compatible(pdev->dev.of_node, "qcom,msm-vidc")) { // "qcom,msm-vidc-iris2"
  140. rc = msm_vidc_init_iris2(core);
  141. if (rc)
  142. return rc;
  143. }
  144. return rc;
  145. }