msm_vidc_platform.c 11 KB

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