msm_vidc_platform.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/of_platform.h>
  7. #include "msm_vidc_platform.h"
  8. #include "msm_vidc_debug.h"
  9. #include "msm_vidc_v4l2.h"
  10. #include "msm_vidc_vb2.h"
  11. #include "msm_vidc_control.h"
  12. #include "msm_vidc_core.h"
  13. #if defined(CONFIG_MSM_VIDC_WAIPIO)
  14. #include "msm_vidc_waipio.h"
  15. #endif
  16. #if defined(CONFIG_MSM_VIDC_KALAMA)
  17. #include "msm_vidc_kalama.h"
  18. #endif
  19. #if defined(CONFIG_MSM_VIDC_DIWALI)
  20. #include "msm_vidc_diwali.h"
  21. #endif
  22. #if defined(CONFIG_MSM_VIDC_IRIS2)
  23. #include "msm_vidc_iris2.h"
  24. #endif
  25. #if defined(CONFIG_MSM_VIDC_IRIS3)
  26. #include "msm_vidc_iris3.h"
  27. #endif
  28. static struct v4l2_file_operations msm_v4l2_file_operations = {
  29. .owner = THIS_MODULE,
  30. .open = msm_v4l2_open,
  31. .release = msm_v4l2_close,
  32. .unlocked_ioctl = video_ioctl2,
  33. .poll = msm_v4l2_poll,
  34. };
  35. static struct v4l2_ioctl_ops msm_v4l2_ioctl_ops_enc = {
  36. .vidioc_querycap = msm_v4l2_querycap,
  37. .vidioc_enum_fmt_vid_cap = msm_v4l2_enum_fmt,
  38. .vidioc_enum_fmt_vid_out = msm_v4l2_enum_fmt,
  39. .vidioc_enum_framesizes = msm_v4l2_enum_framesizes,
  40. .vidioc_enum_frameintervals = msm_v4l2_enum_frameintervals,
  41. .vidioc_try_fmt_vid_cap_mplane = msm_v4l2_try_fmt,
  42. .vidioc_try_fmt_vid_out_mplane = msm_v4l2_try_fmt,
  43. .vidioc_s_fmt_vid_cap = msm_v4l2_s_fmt,
  44. .vidioc_s_fmt_vid_out = msm_v4l2_s_fmt,
  45. .vidioc_s_fmt_vid_cap_mplane = msm_v4l2_s_fmt,
  46. .vidioc_s_fmt_vid_out_mplane = msm_v4l2_s_fmt,
  47. .vidioc_s_fmt_meta_out = msm_v4l2_s_fmt,
  48. .vidioc_s_fmt_meta_cap = msm_v4l2_s_fmt,
  49. .vidioc_g_fmt_vid_cap = msm_v4l2_g_fmt,
  50. .vidioc_g_fmt_vid_out = msm_v4l2_g_fmt,
  51. .vidioc_g_fmt_vid_cap_mplane = msm_v4l2_g_fmt,
  52. .vidioc_g_fmt_vid_out_mplane = msm_v4l2_g_fmt,
  53. .vidioc_g_fmt_meta_out = msm_v4l2_g_fmt,
  54. .vidioc_g_fmt_meta_cap = msm_v4l2_g_fmt,
  55. .vidioc_g_selection = msm_v4l2_g_selection,
  56. .vidioc_s_selection = msm_v4l2_s_selection,
  57. .vidioc_s_parm = msm_v4l2_s_parm,
  58. .vidioc_g_parm = msm_v4l2_g_parm,
  59. .vidioc_reqbufs = msm_v4l2_reqbufs,
  60. .vidioc_querybuf = msm_v4l2_querybuf,
  61. .vidioc_qbuf = msm_v4l2_qbuf,
  62. .vidioc_dqbuf = msm_v4l2_dqbuf,
  63. .vidioc_streamon = msm_v4l2_streamon,
  64. .vidioc_streamoff = msm_v4l2_streamoff,
  65. .vidioc_queryctrl = msm_v4l2_queryctrl,
  66. .vidioc_querymenu = msm_v4l2_querymenu,
  67. .vidioc_subscribe_event = msm_v4l2_subscribe_event,
  68. .vidioc_unsubscribe_event = msm_v4l2_unsubscribe_event,
  69. .vidioc_try_encoder_cmd = msm_v4l2_try_encoder_cmd,
  70. .vidioc_encoder_cmd = msm_v4l2_encoder_cmd,
  71. };
  72. static struct v4l2_ioctl_ops msm_v4l2_ioctl_ops_dec = {
  73. .vidioc_querycap = msm_v4l2_querycap,
  74. .vidioc_enum_fmt_vid_cap = msm_v4l2_enum_fmt,
  75. .vidioc_enum_fmt_vid_out = msm_v4l2_enum_fmt,
  76. .vidioc_enum_framesizes = msm_v4l2_enum_framesizes,
  77. .vidioc_enum_frameintervals = msm_v4l2_enum_frameintervals,
  78. .vidioc_try_fmt_vid_cap_mplane = msm_v4l2_try_fmt,
  79. .vidioc_try_fmt_vid_out_mplane = msm_v4l2_try_fmt,
  80. .vidioc_s_fmt_vid_cap = msm_v4l2_s_fmt,
  81. .vidioc_s_fmt_vid_out = msm_v4l2_s_fmt,
  82. .vidioc_s_fmt_vid_cap_mplane = msm_v4l2_s_fmt,
  83. .vidioc_s_fmt_vid_out_mplane = msm_v4l2_s_fmt,
  84. .vidioc_s_fmt_meta_out = msm_v4l2_s_fmt,
  85. .vidioc_s_fmt_meta_cap = msm_v4l2_s_fmt,
  86. .vidioc_g_fmt_vid_cap = msm_v4l2_g_fmt,
  87. .vidioc_g_fmt_vid_out = msm_v4l2_g_fmt,
  88. .vidioc_g_fmt_vid_cap_mplane = msm_v4l2_g_fmt,
  89. .vidioc_g_fmt_vid_out_mplane = msm_v4l2_g_fmt,
  90. .vidioc_g_fmt_meta_out = msm_v4l2_g_fmt,
  91. .vidioc_g_fmt_meta_cap = msm_v4l2_g_fmt,
  92. .vidioc_g_selection = msm_v4l2_g_selection,
  93. .vidioc_s_selection = msm_v4l2_s_selection,
  94. .vidioc_s_parm = msm_v4l2_s_parm,
  95. .vidioc_g_parm = msm_v4l2_g_parm,
  96. .vidioc_reqbufs = msm_v4l2_reqbufs,
  97. .vidioc_querybuf = msm_v4l2_querybuf,
  98. .vidioc_qbuf = msm_v4l2_qbuf,
  99. .vidioc_dqbuf = msm_v4l2_dqbuf,
  100. .vidioc_streamon = msm_v4l2_streamon,
  101. .vidioc_streamoff = msm_v4l2_streamoff,
  102. .vidioc_queryctrl = msm_v4l2_queryctrl,
  103. .vidioc_querymenu = msm_v4l2_querymenu,
  104. .vidioc_subscribe_event = msm_v4l2_subscribe_event,
  105. .vidioc_unsubscribe_event = msm_v4l2_unsubscribe_event,
  106. .vidioc_try_decoder_cmd = msm_v4l2_try_decoder_cmd,
  107. .vidioc_decoder_cmd = msm_v4l2_decoder_cmd,
  108. };
  109. static struct v4l2_ctrl_ops msm_v4l2_ctrl_ops = {
  110. .s_ctrl = msm_v4l2_op_s_ctrl,
  111. .g_volatile_ctrl = msm_v4l2_op_g_volatile_ctrl,
  112. };
  113. static struct vb2_ops msm_vb2_ops = {
  114. .queue_setup = msm_vidc_queue_setup,
  115. .start_streaming = msm_vidc_start_streaming,
  116. .buf_queue = msm_vidc_buf_queue,
  117. .buf_cleanup = msm_vidc_buf_cleanup,
  118. .stop_streaming = msm_vidc_stop_streaming,
  119. .buf_out_validate = msm_vidc_buf_out_validate,
  120. .buf_request_complete = msm_vidc_buf_request_complete,
  121. };
  122. static struct vb2_mem_ops msm_vb2_mem_ops = {
  123. .get_userptr = msm_vb2_get_userptr,
  124. .put_userptr = msm_vb2_put_userptr,
  125. .attach_dmabuf = msm_vb2_attach_dmabuf,
  126. .detach_dmabuf = msm_vb2_detach_dmabuf,
  127. .map_dmabuf = msm_vb2_map_dmabuf,
  128. .unmap_dmabuf = msm_vb2_unmap_dmabuf,
  129. };
  130. static struct media_device_ops msm_v4l2_media_ops = {
  131. .req_validate = msm_v4l2_request_validate,
  132. .req_queue = msm_v4l2_request_queue,
  133. };
  134. static struct v4l2_m2m_ops msm_v4l2_m2m_ops = {
  135. .device_run = msm_v4l2_m2m_device_run,
  136. .job_abort = msm_v4l2_m2m_job_abort,
  137. };
  138. static int msm_vidc_init_ops(struct msm_vidc_core *core)
  139. {
  140. if (!core) {
  141. d_vpr_e("%s: invalid params\n", __func__);
  142. return -EINVAL;
  143. }
  144. d_vpr_h("%s: initialize ops\n", __func__);
  145. core->v4l2_file_ops = &msm_v4l2_file_operations;
  146. core->v4l2_ioctl_ops_enc = &msm_v4l2_ioctl_ops_enc;
  147. core->v4l2_ioctl_ops_dec = &msm_v4l2_ioctl_ops_dec;
  148. core->v4l2_ctrl_ops = &msm_v4l2_ctrl_ops;
  149. core->vb2_ops = &msm_vb2_ops;
  150. core->vb2_mem_ops = &msm_vb2_mem_ops;
  151. core->media_device_ops = &msm_v4l2_media_ops;
  152. core->v4l2_m2m_ops = &msm_v4l2_m2m_ops;
  153. return 0;
  154. }
  155. static int msm_vidc_deinit_platform_variant(struct msm_vidc_core *core, struct device *dev)
  156. {
  157. int rc = -EINVAL;
  158. if (!core || !dev) {
  159. d_vpr_e("%s: Invalid params\n", __func__);
  160. return -EINVAL;
  161. }
  162. d_vpr_h("%s()\n", __func__);
  163. #if defined(CONFIG_MSM_VIDC_WAIPIO)
  164. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-waipio")) {
  165. rc = msm_vidc_deinit_platform_waipio(core, dev);
  166. if (rc)
  167. d_vpr_e("%s: failed with %d\n", __func__, rc);
  168. return rc;
  169. }
  170. #endif
  171. #if defined(CONFIG_MSM_VIDC_KALAMA)
  172. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-kalama")) {
  173. rc = msm_vidc_deinit_platform_kalama(core, dev);
  174. if (rc)
  175. d_vpr_e("%s: failed with %d\n", __func__, rc);
  176. return rc;
  177. }
  178. #endif
  179. #if defined(CONFIG_MSM_VIDC_DIWALI)
  180. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-diwali")) {
  181. rc = msm_vidc_deinit_platform_diwali(core, dev);
  182. if (rc)
  183. d_vpr_e("%s: failed msm-vidc-diwali with %d\n",
  184. __func__, rc);
  185. return rc;
  186. }
  187. #endif
  188. return rc;
  189. }
  190. static int msm_vidc_init_platform_variant(struct msm_vidc_core *core, struct device *dev)
  191. {
  192. int rc = -EINVAL;
  193. if (!core || !dev) {
  194. d_vpr_e("%s: Invalid params\n", __func__);
  195. return -EINVAL;
  196. }
  197. d_vpr_h("%s()\n", __func__);
  198. #if defined(CONFIG_MSM_VIDC_WAIPIO)
  199. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-waipio")) {
  200. rc = msm_vidc_init_platform_waipio(core, dev);
  201. if (rc)
  202. d_vpr_e("%s: failed with %d\n", __func__, rc);
  203. return rc;
  204. }
  205. #endif
  206. #if defined(CONFIG_MSM_VIDC_KALAMA)
  207. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-kalama")) {
  208. rc = msm_vidc_init_platform_kalama(core, dev);
  209. if (rc)
  210. d_vpr_e("%s: failed with %d\n", __func__, rc);
  211. return rc;
  212. }
  213. #endif
  214. #if defined(CONFIG_MSM_VIDC_DIWALI)
  215. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-diwali")) {
  216. rc = msm_vidc_init_platform_diwali(core, dev);
  217. if (rc)
  218. d_vpr_e("%s: failed msm-vidc-diwali with %d\n",
  219. __func__, rc);
  220. return rc;
  221. }
  222. #endif
  223. return rc;
  224. }
  225. static int msm_vidc_deinit_vpu(struct msm_vidc_core *core, struct device *dev)
  226. {
  227. int rc = -EINVAL;
  228. if (!core || !dev) {
  229. d_vpr_e("%s: Invalid params\n", __func__);
  230. return -EINVAL;
  231. }
  232. d_vpr_h("%s()\n", __func__);
  233. #if defined(CONFIG_MSM_VIDC_IRIS2)
  234. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-iris2")) {
  235. rc = msm_vidc_deinit_iris2(core);
  236. if (rc)
  237. d_vpr_e("%s: failed with %d\n", __func__, rc);
  238. return rc;
  239. }
  240. #endif
  241. #if defined(CONFIG_MSM_VIDC_IRIS3)
  242. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-iris3")) {
  243. rc = msm_vidc_deinit_iris3(core);
  244. if (rc)
  245. d_vpr_e("%s: failed with %d\n", __func__, rc);
  246. return rc;
  247. }
  248. #endif
  249. return rc;
  250. }
  251. static int msm_vidc_init_vpu(struct msm_vidc_core *core, struct device *dev)
  252. {
  253. int rc = -EINVAL;
  254. if (!core || !dev) {
  255. d_vpr_e("%s: Invalid params\n", __func__);
  256. return -EINVAL;
  257. }
  258. #if defined(CONFIG_MSM_VIDC_IRIS2)
  259. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-iris2")) {
  260. rc = msm_vidc_init_iris2(core);
  261. if (rc)
  262. d_vpr_e("%s: failed with %d\n", __func__, rc);
  263. return rc;
  264. }
  265. #endif
  266. #if defined(CONFIG_MSM_VIDC_IRIS3)
  267. if (of_device_is_compatible(dev->of_node, "qcom,msm-vidc-iris3")) {
  268. rc = msm_vidc_init_iris3(core);
  269. if (rc)
  270. d_vpr_e("%s: failed with %d\n", __func__, rc);
  271. return rc;
  272. }
  273. #endif
  274. return rc;
  275. }
  276. int msm_vidc_deinit_platform(struct platform_device *pdev)
  277. {
  278. struct msm_vidc_core *core;
  279. if (!pdev) {
  280. d_vpr_e("%s: invalid params\n", __func__);
  281. return -EINVAL;
  282. }
  283. core = dev_get_drvdata(&pdev->dev);
  284. if (!core) {
  285. d_vpr_e("%s: core not found in device %s",
  286. __func__, dev_name(&pdev->dev));
  287. return -EINVAL;
  288. }
  289. d_vpr_h("%s()\n", __func__);
  290. msm_vidc_deinit_vpu(core, &pdev->dev);
  291. msm_vidc_deinit_platform_variant(core, &pdev->dev);
  292. kfree(core->platform);
  293. return 0;
  294. }
  295. int msm_vidc_init_platform(struct platform_device *pdev)
  296. {
  297. int rc = 0;
  298. struct msm_vidc_platform *platform;
  299. struct msm_vidc_core *core;
  300. if (!pdev) {
  301. d_vpr_e("%s: invalid params\n", __func__);
  302. return -EINVAL;
  303. }
  304. d_vpr_h("%s()\n", __func__);
  305. core = dev_get_drvdata(&pdev->dev);
  306. if (!core) {
  307. d_vpr_e("%s: core not found in device %s",
  308. __func__, dev_name(&pdev->dev));
  309. return -EINVAL;
  310. }
  311. platform = kzalloc(sizeof(struct msm_vidc_platform), GFP_KERNEL);
  312. if (!platform)
  313. return -ENOMEM;
  314. core->platform = platform;
  315. platform->core = core;
  316. /* selected ops can be re-assigned in platform specific file */
  317. rc = msm_vidc_init_ops(core);
  318. if (rc)
  319. return rc;
  320. rc = msm_vidc_init_platform_variant(core, &pdev->dev);
  321. if (rc)
  322. return rc;
  323. rc = msm_vidc_init_vpu(core, &pdev->dev);
  324. if (rc)
  325. return rc;
  326. return rc;
  327. }