[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a0a8b9a1-df9e-0e30-9ce6-36759f707e27@collabora.com>
Date: Mon, 19 Jul 2021 18:22:30 +0200
From: Dafna Hirschfeld <dafna.hirschfeld@...labora.com>
To: Alexandre Courbot <acourbot@...omium.org>,
Tiffany Lin <tiffany.lin@...iatek.com>,
Andrew-CT Chen <andrew-ct.chen@...iatek.com>,
Hans Verkuil <hverkuil-cisco@...all.nl>,
Yunfei Dong <yunfei.dong@...iatek.com>
Cc: Mauro Carvalho Chehab <mchehab@...nel.org>,
linux-media@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mediatek@...ts.infradead.org,
Tzung-Bi Shih <tzungbi@...gle.com>,
Collabora Kernel ML <kernel@...labora.com>,
Enric Balletbo i Serra <enric.balletbo@...labora.com>
Subject: Re: [PATCH v6 12/14] media: mtk-vcodec: vdec: add media device if
using stateless api
On 05.07.21 07:32, Alexandre Courbot wrote:
> From: Yunfei Dong <yunfei.dong@...iatek.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@...iatek.com>
> [acourbot: refactor, cleanup and split]
> Co-developed-by: Alexandre Courbot <acourbot@...omium.org>
> Signed-off-by: Alexandre Courbot <acourbot@...omium.org>
> Reviewed-by: Tzung-Bi Shih <tzungbi@...gle.com>
> ---
> drivers/media/platform/Kconfig | 2 +
> .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 38 +++++++++++++++++++
> .../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 ae1468aa1b4e..aa277a19e275 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -315,6 +315,8 @@ config VIDEO_MEDIATEK_VCODEC
> select VIDEO_MEDIATEK_VCODEC_VPU if VIDEO_MEDIATEK_VPU
> select VIDEO_MEDIATEK_VCODEC_SCP if MTK_SCP
> select V4L2_H264
> + select MEDIA_CONTROLLER
> + select MEDIA_CONTROLLER_REQUEST_API
> help
> Mediatek video codec driver provides HW capability to
> encode and decode in a range of video formats on MT8173
> 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 1460951f302c..c8a84fa11e4a 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"
> @@ -316,6 +317,30 @@ 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);
the media's node minor is not vfd_dec->num
> + }
> ret = video_register_device(vfd_dec, VFL_TYPE_VIDEO, 0);
> if (ret) {
> mtk_v4l2_err("Failed to register video device");
> @@ -328,6 +353,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);
> @@ -360,6 +391,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 8fb333a99a40..d4f840a7bbcb 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> @@ -389,6 +389,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
> @@ -426,6 +427,7 @@ struct mtk_vcodec_enc_pdata {
> struct mtk_vcodec_dev {
This structs has a lot of duplicated fields for enc/dec
Since the device represents either a decoder or an encoder,
I think all those dupliactes can be removed, so for example
instead of having both 'dec_irq' and 'enc_irq' we can have just 'irq'
Thanks,
Dafna
> 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;
>
Powered by blists - more mailing lists