msm_vidc_platform.c 10 KB

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