From: Alexandre Courbot <acourbot@chromium.org>
To: Tiffany Lin <tiffany.lin@mediatek.com>,
Andrew-CT Chen <andrew-ct.chen@mediatek.com>,
Rui Wang <gtk_ruiwang@mediatek.com>,
Yunfei Dong <yunfei.dong@mediatek.com>,
Pi-Hsun Shih <pihsun@chromium.org>,
Maoguang Meng <maoguang.meng@mediatek.com>
Cc: linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-kernel@vger.kernel.org,
Alexandre Courbot <acourbot@chromium.org>
Subject: [PATCH 7/9] media: mtk-vcodec: vdec: add media device if using stateless api
Date: Tue, 30 Jun 2020 15:27:09 +0900 [thread overview]
Message-ID: <20200630062711.4169601-8-acourbot@chromium.org> (raw)
In-Reply-To: <20200630062711.4169601-1-acourbot@chromium.org>
From: Yunfei Dong <yunfei.dong@mediatek.com>
The stateless API requires a media device for issuing requests. Add one
if we are being instantiated as a stateless decoder.
Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
[acourbot: refactor, cleanup and split]
Co-developed-by: Alexandre Courbot <acourbot@chromium.org>
Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
---
drivers/media/platform/Kconfig | 1 +
.../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 39 +++++++++++++++++++
.../platform/mtk-vcodec/mtk_vcodec_drv.h | 2 +
3 files changed, 42 insertions(+)
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ff77c6db55db..cb5ffb98dc09 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -258,6 +258,7 @@ config VIDEO_MEDIATEK_VCODEC
select V4L2_H264
select VIDEO_MEDIATEK_VPU
select MTK_SCP
+ select MEDIA_CONTROLLER
help
Mediatek video codec driver provides HW capability to
encode and decode in a range of video formats
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 3d8eaf0746c2..e723f8573322 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -14,6 +14,7 @@
#include <media/v4l2-event.h>
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
+#include <media/v4l2-device.h>
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
@@ -322,6 +323,31 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_event_workq;
}
+ if (dev->vdec_pdata->uses_stateless_api) {
+ dev->mdev_dec.dev = &pdev->dev;
+ strscpy(dev->mdev_dec.model, MTK_VCODEC_DEC_NAME,
+ sizeof(dev->mdev_dec.model));
+
+ media_device_init(&dev->mdev_dec);
+ dev->mdev_dec.ops = &mtk_vcodec_media_ops;
+ dev->v4l2_dev.mdev = &dev->mdev_dec;
+
+ ret = v4l2_m2m_register_media_controller(dev->m2m_dev_dec,
+ dev->vfd_dec, MEDIA_ENT_F_PROC_VIDEO_DECODER);
+ if (ret) {
+ mtk_v4l2_err("Failed to register media controller");
+ goto err_reg_cont;
+ }
+
+ ret = media_device_register(&dev->mdev_dec);
+ if (ret) {
+ mtk_v4l2_err("Failed to register media device");
+ goto err_media_reg;
+ }
+
+ mtk_v4l2_debug(0, "media registered as /dev/media%d",
+ vfd_dec->num);
+ }
ret = video_register_device(vfd_dec, VFL_TYPE_VIDEO, 0);
if (ret) {
mtk_v4l2_err("Failed to register video device");
@@ -334,6 +360,12 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
return 0;
err_dec_reg:
+ if (dev->vdec_pdata->uses_stateless_api)
+ media_device_unregister(&dev->mdev_dec);
+err_media_reg:
+ if (dev->vdec_pdata->uses_stateless_api)
+ v4l2_m2m_unregister_media_controller(dev->m2m_dev_dec);
+err_reg_cont:
destroy_workqueue(dev->decode_workqueue);
err_event_workq:
v4l2_m2m_release(dev->m2m_dev_dec);
@@ -366,6 +398,13 @@ static int mtk_vcodec_dec_remove(struct platform_device *pdev)
flush_workqueue(dev->decode_workqueue);
destroy_workqueue(dev->decode_workqueue);
+
+ if (media_devnode_is_registered(dev->mdev_dec.devnode)) {
+ media_device_unregister(&dev->mdev_dec);
+ v4l2_m2m_unregister_media_controller(dev->m2m_dev_dec);
+ media_device_cleanup(&dev->mdev_dec);
+ }
+
if (dev->m2m_dev_dec)
v4l2_m2m_release(dev->m2m_dev_dec);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 755631d0fe92..7071434b5c5b 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -382,6 +382,7 @@ struct mtk_vcodec_enc_pdata {
* struct mtk_vcodec_dev - driver data
* @v4l2_dev: V4L2 device to register video devices for.
* @vfd_dec: Video device for decoder
+ * @mdev_dec: Media device for decoder
* @vfd_enc: Video device for encoder.
*
* @m2m_dev_dec: m2m device for decoder
@@ -418,6 +419,7 @@ struct mtk_vcodec_enc_pdata {
struct mtk_vcodec_dev {
struct v4l2_device v4l2_dev;
struct video_device *vfd_dec;
+ struct media_device mdev_dec;
struct video_device *vfd_enc;
struct v4l2_m2m_dev *m2m_dev_dec;
--
2.27.0.212.ge8ba1cc988-goog
next prev parent reply other threads:[~2020-06-30 6:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-30 6:27 [PATCH 0/9] media: mtk-vcodec: vdec: support for MT8183 Alexandre Courbot
2020-06-30 6:27 ` [PATCH 1/9] media: mtk-vcodec: vdec: move stateful ops into their own file Alexandre Courbot
2020-06-30 6:27 ` [PATCH 2/9] media: mtk-vcodec: vdec: handle firmware version field Alexandre Courbot
2020-06-30 6:27 ` [PATCH 3/9] media: mtk-vcodec: support version 2 of decoder firmware ABI Alexandre Courbot
2020-06-30 6:27 ` [PATCH 4/9] media: add Mediatek's MM21 format Alexandre Courbot
2020-07-03 8:38 ` Hans Verkuil
2020-07-04 12:36 ` Alexandre Courbot
2020-06-30 6:27 ` [PATCH 5/9] media: mtk-vcodec: vdec: support stateless API Alexandre Courbot
2020-06-30 6:27 ` [PATCH 6/9] media: mtk-vcodec: vdec: support stateless H.264 decoding Alexandre Courbot
2020-06-30 6:27 ` Alexandre Courbot [this message]
2020-06-30 6:27 ` [PATCH 8/9] media: mtk-vcodec: enable MT8183 decoder Alexandre Courbot
2020-06-30 6:27 ` [PATCH 9/9] dt-bindings: media: document mediatek,mt8183-vcodec-dec Alexandre Courbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200630062711.4169601-8-acourbot@chromium.org \
--to=acourbot@chromium.org \
--cc=andrew-ct.chen@mediatek.com \
--cc=gtk_ruiwang@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=maoguang.meng@mediatek.com \
--cc=pihsun@chromium.org \
--cc=tiffany.lin@mediatek.com \
--cc=yunfei.dong@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).